From: Olaf Wintermann Date: Wed, 5 Feb 2025 22:38:27 +0000 (+0100) Subject: init dbutils X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=d0b730221b0d9ab1c8001a49162d38820916835c;p=note.git init dbutils --- diff --git a/application/Makefile b/application/Makefile index 5617a5c..65c372a 100644 --- a/application/Makefile +++ b/application/Makefile @@ -34,6 +34,7 @@ CFLAGS += -I../ui/ -I../ucx -I.. SRC = main.c SRC += application.c SRC += window.c +SRC += store.c OBJ = $(SRC:%.c=../build/application/%.$(OBJ_EXT)) diff --git a/application/application.c b/application/application.c index d78e430..bd6dd4f 100644 --- a/application/application.c +++ b/application/application.c @@ -28,7 +28,12 @@ #include "application.h" #include "window.h" +#include "store.h" void application_startup(UiEvent *event, void *data) { + if(init_note_store) { + return; + } + window_create(); } diff --git a/application/application.h b/application/application.h index 601157a..7046b8f 100644 --- a/application/application.h +++ b/application/application.h @@ -25,6 +25,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + #ifndef APPLICATION_H #define APPLICATION_H @@ -34,6 +35,9 @@ extern "C" { #endif +#define APP_STATE_NOTE_SELECTED 100 + + typedef struct MainWindow { UiList *notebooks; UiList *sources; diff --git a/application/store.c b/application/store.c new file mode 100644 index 0000000..1682541 --- /dev/null +++ b/application/store.c @@ -0,0 +1,63 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2025 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "store.h" + +#include +#include +#include +#include +#include + +#include "../dbutils/dbutils/db.h" +#include "../dbutils/dbutils/sqlite.h" + +static DBUConnection *connection; + +int init_note_store() { + char *sqlite_db_file = ui_configfile(NOTES_DB_FILE); + + int init_db = 0; + struct stat s; + if(stat(sqlite_db_file, &s)) { + if(errno != ENOENT) { + return 1; + } + + // file not found: first run + init_db = 1; + } + connection = dbuSQLiteConnection(sqlite_db_file); + free(sqlite_db_file); + + if(!connection) { + return 1; + } + + return 0; +} diff --git a/application/store.h b/application/store.h new file mode 100644 index 0000000..2459c21 --- /dev/null +++ b/application/store.h @@ -0,0 +1,48 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2025 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef STORE_H +#define STORE_H + +#include "application.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define NOTES_DB_FILE "notes.db" + +int init_note_store(); + + +#ifdef __cplusplus +} +#endif + +#endif /* STORE_H */ + diff --git a/application/window.c b/application/window.c index 4e97ed9..b904b8b 100644 --- a/application/window.c +++ b/application/window.c @@ -48,15 +48,16 @@ void window_create() { ui_hsplitpane(obj, .initial_position = 200) { // splitpane left: table UiModel* model = ui_model(obj->ctx, UI_STRING, "Name", UI_STRING_FREE, "Last Modified", -1); + model->columnsize[0] = -1; ui_table(obj, .model = model, .varname = "notes"); // splitpane right: content ui_grid(obj, .columnspacing = 10, .rowspacing = 10) { ui_label(obj, .label = "Title"); - ui_textfield(obj, .varname = "note_title", .hexpand = TRUE); + ui_textfield(obj, .varname = "note_title", .hexpand = TRUE, .groups = UI_GROUPS(APP_STATE_NOTE_SELECTED)); ui_newline(obj); - ui_textarea(obj, .varname = "note_content", .vfill = TRUE, .hfill = TRUE, .hexpand = TRUE, .vexpand = TRUE, .colspan = 2); + ui_textarea(obj, .varname = "note_content", .vfill = TRUE, .hfill = TRUE, .hexpand = TRUE, .vexpand = TRUE, .colspan = 2, .groups = UI_GROUPS(APP_STATE_NOTE_SELECTED)); } } diff --git a/configure b/configure index 2315362..27e4652 100755 --- a/configure +++ b/configure @@ -393,6 +393,31 @@ dependency_error_gtk2() dep_checked_gtk2=1 return 0 } +dependency_error_sqlite() +{ + print_check_msg "$dep_checked_sqlite" "checking for sqlite... " + # dependency sqlite + while true + do + if [ -z "$PKG_CONFIG" ]; then + break + fi + if test_pkg_config "sqlite3" "" "" "" ; then + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags sqlite3`" + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs sqlite3`" + else + break + fi + TEMP_CFLAGS="$TEMP_CFLAGS -DDBU_SQLITE" + print_check_msg "$dep_checked_sqlite" "yes\n" + dep_checked_sqlite=1 + return 1 + done + + print_check_msg "$dep_checked_sqlite" "no\n" + dep_checked_sqlite=1 + return 0 +} dependency_error_gtk3() { print_check_msg "$dep_checked_gtk3" "checking for gtk3... " @@ -904,6 +929,47 @@ if [ -n "${TEMP_LDFLAGS}" ]; then echo "DAV_LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" fi +echo >> "$TEMP_DIR/flags.mk" +echo "configuring target: dbu" +echo "# flags for target dbu" >> "$TEMP_DIR/flags.mk" +TEMP_CFLAGS= +TEMP_CXXFLAGS= +TEMP_LDFLAGS= + +if dependency_error_sqlite; then + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sqlite " + ERROR=1 +fi + +# Features + + +if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then + echo "DBU_CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" +fi +if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then + echo "DBU_CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" +fi +if [ "$BUILD_TYPE" = "debug" ]; then + if [ -n "$lang_c" ]; then + echo 'DBU_CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" + fi + if [ -n "$lang_cpp" ]; then + echo 'DBU_CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" + fi +fi +if [ "$BUILD_TYPE" = "release" ]; then + if [ -n "$lang_c" ]; then + echo 'DBU_CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" + fi + if [ -n "$lang_cpp" ]; then + echo 'DBU_CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" + fi +fi +if [ -n "${TEMP_LDFLAGS}" ]; then + echo "DBU_LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" +fi + echo >> "$TEMP_DIR/flags.mk" echo "configuring target: tk" echo "# flags for target tk" >> "$TEMP_DIR/flags.mk" diff --git a/make/project.xml b/make/project.xml index ff72751..606f29d 100644 --- a/make/project.xml +++ b/make/project.xml @@ -16,6 +16,11 @@ curl-config --libs + + sqlite3 + -DDBU_SQLITE + + xml2-config --cflags xml2-config --libs @@ -125,6 +130,10 @@ curl,libxml2,openssl + + sqlite + +