]> uap-core.de Git - note.git/commitdiff
init dbutils
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 5 Feb 2025 22:38:27 +0000 (23:38 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 5 Feb 2025 22:38:27 +0000 (23:38 +0100)
application/Makefile
application/application.c
application/application.h
application/store.c [new file with mode: 0644]
application/store.h [new file with mode: 0644]
application/window.c
configure
make/project.xml

index 5617a5c2594b81646a803ab89ae58b6d2ec395c1..65c372a6e8e2aa8315c0acbd1d17d96edd5c543f 100644 (file)
@@ -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))
        
index d78e430284c636095af88613162f4cab18c7bcbc..bd6dd4f2c2485266994d3aac7b40aa52f57925bc 100644 (file)
 
 #include "application.h"
 #include "window.h"
+#include "store.h"
 
 void application_startup(UiEvent *event, void *data) {
+    if(init_note_store) {
+        return;
+    }
+    
     window_create();
 }
index 601157a74917c537d6b60dbb81bc9f8d3374e8f2..7046b8fac2dac388719ae8e90fd82aa254bc7d9c 100644 (file)
@@ -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 (file)
index 0000000..1682541
--- /dev/null
@@ -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 <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#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 (file)
index 0000000..2459c21
--- /dev/null
@@ -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 */
+
index 4e97ed9dcc2613536757261deb4b623c8ad5f407..b904b8bf32a4fe2f595540ed3daaebd15289a654 100644 (file)
@@ -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));
         }
     }
     
index 23153623c2f0419a32796fa204fe8644464ae859..27e4652a55f9b873916ccc47d771c5703a80e96e 100755 (executable)
--- 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"
index ff7275137d3c791e03112678bf125cae2d9e62bc..606f29dd4b27ddb4bddae91f7c3311c0ef1f106e 100644 (file)
                <ldflags exec="true">curl-config --libs</ldflags>
        </dependency>
        
+       <dependency name="sqlite">
+               <pkgconfig>sqlite3</pkgconfig>
+               <cflags>-DDBU_SQLITE</cflags>
+       </dependency>
+       
        <dependency name="libxml2" platform="windows">
                <cflags exec="true">xml2-config --cflags</cflags>
                <ldflags exec="true">xml2-config --libs</ldflags>
                <dependencies>curl,libxml2,openssl</dependencies>
        </target>
        
+       <target name="dbu">
+               <dependencies>sqlite</dependencies>
+       </target>
+       
        <target name="tk">
                <option arg="toolkit">
                        <value str="libadwaita">