SRC = main.c
SRC += application.c
SRC += window.c
+SRC += store.c
OBJ = $(SRC:%.c=../build/application/%.$(OBJ_EXT))
#include "application.h"
#include "window.h"
+#include "store.h"
void application_startup(UiEvent *event, void *data) {
+ if(init_note_store) {
+ return;
+ }
+
window_create();
}
* 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
extern "C" {
#endif
+#define APP_STATE_NOTE_SELECTED 100
+
+
typedef struct MainWindow {
UiList *notebooks;
UiList *sources;
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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 */
+
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));
}
}
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... "
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"
<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">