-
Notifications
You must be signed in to change notification settings - Fork 2
/
kiss-front-jessie.c
4127 lines (3300 loc) · 157 KB
/
kiss-front-jessie.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>
#include "kisslib.h" // read_pdf, read_mobi, read_chm, read_epub
// GTK3
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gio/gio.h>
#include <glib.h>
//SQLite3
#include <sqlite3.h>
//GNU
#include <dirent.h> // readdir, closedir
#include <unistd.h> // access, fork, execlp
#include <sys/stat.h>
// gettext
#include <locale.h>
#include <libintl.h>
//------------------------------------------------------------------------------
enum {
STARTUP_COLUMN,
FORMAT_COLUMN,
AUTHOR_COLUMN,
TITLE_COLUMN,
CATEGORY_COLUMN,
TAGS_COLUMN,
FILENAME_COLUMN,
PRIORITY_COLUMN,
READ_COLUMN,
N_COLUMNS
};
enum {
SEARCH_AUTHOR_TITLE,
SEARCH_FORMAT,
SEARCH_AUTHORS,
SEARCH_TITLE,
SEARCH_CATEGORY,
SEARCH_TAGS,
SEARCH_FILENAME
};
typedef struct dbHandlingData {
GtkTreeModel *model;
GtkListStore *store;
GtkTreeIter *iter;
gchar **data;
} dbHandlingData;
typedef struct dbAnswer {
unsigned int count;
char **data;
char **columnNames;
} dbAnswer;
typedef struct argumentStore {
unsigned int count;
char **arguments;
} argumentStore;
typedef struct radioGroup {
int key;
int count;
GtkWidget **items;
} radioGroup;
typedef struct dimensions {
int width;
int height;
} dimensions;
//------------------------------------------------------------------------------
void run(GtkApplication*, gpointer);
void handle_resize(GtkWidget*, GdkRectangle*, gpointer);
void ask_setup_window(sqlite3*);
void ask_setup_window_open(GtkButton*, gpointer);
void ask_setup_window_close(GtkButton*, gpointer);
void ask_reader_window_close(GtkButton*, gpointer);
void ask_reader_window_save(GtkButton*, gpointer);
void menuhandle_setup_dialog(GtkMenuItem*, gpointer);
void open_setup_reader_dialog(GObject*);
void handle_launchCommand(GtkWidget*);
void handle_column_change(GtkTreeView*, gpointer);
gboolean handle_drag_data(GtkWidget*, GdkDragContext*, gint, gint, GtkSelectionData*, guint, gpointer);
gboolean handle_key_press(GtkWidget*, GdkEventKey*, gpointer);
gboolean handle_editing_author(GtkCellRendererText*, gchar*, gchar*, gpointer);
gboolean handle_editing_title(GtkCellRendererText*, gchar*, gchar*, gpointer);
gboolean handle_editing_category(GtkCellRendererText*, gchar*, gchar*, gpointer);
gboolean handle_editing_tags(GtkCellRendererText*, gchar*, gchar*, gpointer);
void handle_editing_priority_value(GtkAdjustment*, gpointer);
void handle_editing_priority(GtkAdjustment*, gpointer);
void handle_toggle_read(GtkCellRendererToggle*, gchar*, gpointer);
void delete_selected_entry_from_db_and_store(GtkWidget*);
void handle_row_activated(GtkTreeView*, GtkTreePath*, GtkTreeViewColumn*, gpointer);
void handle_sort_column(GtkTreeViewColumn*, gpointer);
void search_icon_click(GtkEntry*, GtkEntryIconPosition, GdkEvent*, gpointer);
void search_handle_search(GtkEntry*, gpointer);
bool read_and_add_file_to_model(char*, bool, GtkWidget*, unsigned int, bool, GtkWidget*, unsigned int, unsigned int, bool, GtkTreeModel*, sqlite3*, bool);
int read_out_path(char*, GtkWidget*, unsigned int, GtkWidget*, unsigned int, unsigned int, GtkTreeModel*, sqlite3*, bool);
bool retrieve_handler_arguments(struct argumentStore*, const char *);
void free_handler_arguments(struct argumentStore*);
void menuhandle_meQuit(GtkMenuItem*, gpointer);
void menuhandle_meImportFiles(GtkMenuItem*, gpointer);
void open_importFiles_window(GObject*);
void menuhandle_meSetLauncher(GtkMenuItem*, gpointer);
void open_launcher_window(GObject*);
void menuhandle_meEditEntry(GtkMenuItem*, gpointer);
void open_edit_window(GObject*);
void edit_entry_close(GtkButton*, gpointer);
void edit_entry_save_data(GtkButton*, gpointer);
void menuhandle_meToggleColumn(GtkCheckMenuItem*, gpointer);
void menuhandle_meResetColumns(GtkMenuItem*, gpointer);
void menuhandle_mOptions(GtkMenuItem*, gpointer);
void open_options_window(GObject*, gpointer);
void options_toggle_column(GtkToggleButton*, gpointer);
void optionsWindow_close(GtkButton*, gpointer);
void optionsWindow_save(GtkButton*, gpointer);
void launcherWindow_save_data(GtkButton*, gpointer);
void launcherWindow_close(GtkButton*, gpointer);
void fileChooser_close(GtkButton*, gpointer);
void fileChooser_importFiles(GtkButton*, gpointer);
// Db related
int trim(const char*, char**, bool);
int add_db_data_to_store(void*, int, char**, char**);
void clearAndUpdateDataStore(GtkListStore*, sqlite3*);
int fill_db_answer(void*, int, char**, char**);
void free_db_answer(struct dbAnswer*);
bool get_db_answer_value(struct dbAnswer*, const char[], char**);
//------------------------------------------------------------------------------
int main(int argc, char *argv[]) {
setlocale(LC_ALL, "");
// NOTE: Translations have to be placed in + "translations/de_DE/LC_MESSAGES/KISSebook.mo" for german de_DE translation
char *localPath = malloc(2560 * sizeof(char));
getcwd(localPath, 2048);
sprintf(localPath, "%s/translations/", localPath);
bindtextdomain("KISSebook", localPath);
textdomain("KISSebook");
free(localPath);
char homePath[512];
sprintf(homePath, "%s/.kissebook", getenv("HOME"));
mkdir(homePath, S_IRWXU);
if (chdir(homePath) != 0) {
fprintf(stderr, "Cannot set application working directory to \"%s\", quitting.\n\n", homePath);
return -1;
}
GtkApplication *app;
int status;
// SQLite3 code
sqlite3 *db;
char *dbErrorMsg = NULL;
char *dbStmt = NULL;
int rc = sqlite3_open("kisslib.db", &db);
if (rc) {
sqlite3_close(db);
fprintf(stderr, "Error opening sqlite3 database \"kisslib.db\" file. Exiting.");
return 1;
} else {
char columnOrder[64];
char indexString[3];
columnOrder[0] = '\0';
for (int i = 0; i < N_COLUMNS; ++i) {
sprintf(indexString, "%d,", i);
strcat(columnOrder, indexString);
}
dbStmt = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS ebook_collection ( \
'id' INTEGER PRIMARY KEY ASC, \
'format' INTEGER, \
'author' TEXT, \
'title' TEXT, \
'path' TEXT, \
'filename' TEXT, \
'read' INTEGER DEFAULT 0, \
'priority' INTEGER DEFAULT 0, \
'category' TEXT DEFAULT NULL, \
'tags' TEXT DEFAULT NULL \
); \
CREATE TABLE IF NOT EXISTS launcher_applications ( \
'id' INTEGER PRIMARY KEY ASC, \
'format' INTEGER, \
'program' TEXT DEFAULT NULL, \
'args' TEXT DEFAULT NULL \
); \
CREATE TABLE IF NOT EXISTS options ( \
'id' INTEGER PRIMARY KEY ASC, \
'option' TEXT, \
'type' TEXT, \
'value' TEXT \
); \
INSERT OR IGNORE INTO options VALUES(1, 'visible_columns', 'text', 'format,author'); \
INSERT OR IGNORE INTO options VALUES(2, 'overwrite_on_import', 'bool', 'true'); \
INSERT OR IGNORE INTO options VALUES(3, 'first_startup', 'bool', 'true'); \
INSERT OR IGNORE INTO options VALUES(4, 'sort_on_startup', 'int', -1); \
INSERT OR IGNORE INTO options VALUES(5, 'column_order', 'text', '%s'); \
INSERT OR IGNORE INTO options VALUES(6, 'window_dimensions', 'text', '640;400;'); \
", columnOrder);
if (dbStmt != NULL) {
rc = sqlite3_exec(db, dbStmt, NULL, NULL, &dbErrorMsg);
sqlite3_free(dbStmt);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error: %s\n", dbErrorMsg);
sqlite3_free(dbErrorMsg);
sqlite3_close(db);
if (rc == SQLITE_READONLY) {
fprintf(stderr, "Error opening sqlite3 database for writing. Exiting.\n");
}
return 1;
}
} else {
fprintf(stderr, "SQL out of memory error, cant setup the database. Exiting.\n");
return 1;
}
}
//----------------------------------------------------------------------------
// Read out window sizes;
struct dimensions *window_dimensions = malloc(sizeof(dimensions));
//----------------------------------------------------------------------------
struct dbAnswer receiveFromDb = { 0, NULL, NULL };
rc = sqlite3_exec(db, "SELECT value FROM options WHERE option == 'window_dimensions' LIMIT 0,1;", fill_db_answer, (void*) &receiveFromDb, &dbErrorMsg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error, could not save 'window_dimensions', error: %s\n", dbErrorMsg);
sqlite3_free(dbErrorMsg);
} else {
char *sizeString = NULL;
if (get_db_answer_value(&receiveFromDb, "value", &sizeString)) {
char *width = strtok(sizeString, ";");
char *height = strtok(NULL, ";");
window_dimensions->width = atoi(width);
window_dimensions->height = atoi(height);
free(sizeString);
}
free_db_answer(&receiveFromDb);
}
//----------------------------------------------------------------------------
app = gtk_application_new("net.dwrox.kiss", G_APPLICATION_HANDLES_OPEN);
g_signal_connect(app, "activate", G_CALLBACK(run), NULL);
g_object_set_data(G_OBJECT(app), "db", db);
g_object_set_data(G_OBJECT(app), "window_dimensions", window_dimensions);
status = g_application_run(G_APPLICATION(app), argc, argv);
int *columnIds = g_object_get_data(G_OBJECT(app), "columnIds");
free(columnIds);
g_object_unref(g_object_get_data(G_OBJECT(app), "dataStore"));
g_object_unref(app);
// Save window sizes;
dbStmt = sqlite3_mprintf("UPDATE options SET value='%d;%d;' WHERE option == 'window_dimensions'", window_dimensions->width, window_dimensions->height);
if (dbStmt != NULL) {
rc = sqlite3_exec(db, dbStmt, NULL, NULL, &dbErrorMsg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error, could not save 'window_dimensions', error: %s\n", dbErrorMsg);
sqlite3_free(dbErrorMsg);
}
}
sqlite3_free(dbStmt);
// Close db
rc = sqlite3_exec(db, "VACUUM", NULL, NULL, &dbErrorMsg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error, could not run 'vacuum', error: %s\n", dbErrorMsg);
sqlite3_free(dbErrorMsg);
}
sqlite3_close(db);
free(window_dimensions);
return status;
}
//------------------------------------------------------------------------------
int fill_db_answer(void* dbAnswerData, int argc, char **argv, char **columnNames) {
/*
typedef struct dbAnswer {
unsigned int count;
char **data;
char **columnNames;
} dbAnswer;
*/
dbAnswer *answerData = (dbAnswer*) dbAnswerData;
for (int i = 0; i < argc; ++i) {
if (argv[i] != NULL) {
answerData->data = (char**) realloc(answerData->data, sizeof(char*) * (answerData->count + 1));
answerData->data[i] = malloc(sizeof(char) * (strlen(argv[i]) + 1));
strcpy(answerData->data[i], argv[i]);
answerData->columnNames = (char**) realloc(answerData->columnNames, sizeof(char*) * (answerData->count + 1));
answerData->columnNames[i] = malloc(sizeof(char) * (strlen(columnNames[i]) + 1));
strcpy(answerData->columnNames[i], columnNames[i]);
++answerData->count;
}
}
return 0;
}
//------------------------------------------------------------------------------
bool get_db_answer_value(struct dbAnswer* answerData, const char columnName[], char** data) {
for (int i = 0; i < answerData->count; ++i) {
if (strcmp(answerData->columnNames[i], columnName) == 0) {
*data = malloc(sizeof(char) * (strlen(answerData->data[i]) + 1));
strcpy(*data, answerData->data[i]);
return true;
}
}
return false;
}
//------------------------------------------------------------------------------
void free_db_answer(struct dbAnswer *answerData) {
/*
typedef struct dbAnswer {
unsigned int count;
char **data;
char **columnNames;
} dbAnswer;
*/
for (int i = 0; i < answerData->count; ++i) {
free(answerData->data[i]);
free(answerData->columnNames[i]);
}
free(answerData->data);
free(answerData->columnNames);
answerData->count = 0;
answerData->data = NULL;
answerData->columnNames = NULL;
}
//------------------------------------------------------------------------------
int add_db_data_to_store(void* dataStore, int argc, char **argv, char **columnNames) {
GtkListStore *store = GTK_LIST_STORE(dataStore);
GtkTreeIter iter;
char formatString[5];
char *author = NULL;
char *title = NULL;
char *category = NULL;
char *tags = NULL;
char *filename = NULL;
bool read = false;
int priority = 0;
for(int i = 0; i < argc; i++) {
if (strcmp(columnNames[i], "format") == 0) {
switch(atoi(argv[i])) {
case 1:
strcpy(formatString, "pdf");
break;
case 2:
strcpy(formatString, "epub");
break;
case 3:
strcpy(formatString, "mobi");
break;
case 4:
strcpy(formatString, "chm");
break;
default:
break;
}
} else if (strcmp(columnNames[i], "author") == 0) {
author = calloc((strlen(argv[i]) + 1), sizeof(char));
strcpy(author, argv[i]);
} else if (strcmp(columnNames[i], "title") == 0) {
title = calloc((strlen(argv[i]) + 1), sizeof(char));
strcpy(title, argv[i]);
} else if (strcmp(columnNames[i], "category") == 0) {
if (argv[i] != NULL) {
category = calloc((strlen(argv[i]) + 1), sizeof(char));
strcpy(category, argv[i]);
}
} else if (strcmp(columnNames[i], "tags") == 0) {
if (argv[i] != NULL) {
tags = calloc((strlen(argv[i]) + 1), sizeof(char));
strcpy(tags, argv[i]);
}
} else if (strcmp(columnNames[i], "filename") == 0) {
filename = calloc((strlen(argv[i]) + 1), sizeof(char));
strcpy(filename, argv[i]);
} else if (strcmp(columnNames[i], "priority") == 0) {
priority = atoi(argv[i]);
} else if (strcmp(columnNames[i], "read") == 0) {
read = (gboolean) atoi(argv[i]);
}
}
gtk_list_store_insert_with_values(store, &iter, -1,
FORMAT_COLUMN, formatString,
AUTHOR_COLUMN, author == NULL ? "Unknown" : author,
TITLE_COLUMN, title,
CATEGORY_COLUMN, category == NULL ? "" : category,
TAGS_COLUMN, tags == NULL ? "" : tags,
FILENAME_COLUMN, filename,
PRIORITY_COLUMN, priority,
READ_COLUMN, read,
-1
);
free(author);
free(title);
free(category);
free(tags);
free(filename);
return 0;
}
void run(GtkApplication *app, gpointer user_data) {
GtkWidget *window = gtk_application_window_new(app);
g_signal_connect(G_OBJECT(window), "size-allocate", G_CALLBACK(handle_resize), app);
gtk_window_set_title(GTK_WINDOW(window), gettext("KISS Ebook Starter"));
struct dimensions *window_dimensions = g_object_get_data(G_OBJECT(app), "window_dimensions");
gtk_window_set_default_size(GTK_WINDOW(window), window_dimensions->width, window_dimensions->height);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
GtkWidget *grid = gtk_grid_new();
gtk_container_add(GTK_CONTAINER(window), grid);
//----------------------------------------------------------------------------
GtkListStore *dataStore = gtk_list_store_new(
N_COLUMNS,
GDK_TYPE_PIXBUF,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_INT,
G_TYPE_BOOLEAN
);
//----------------------------------------------------------------------------
// Read entries from db into list store
//----------------------------------------------------------------------------
sqlite3* db = g_object_get_data(G_OBJECT(app), "db");
char *dbErrorMsg = NULL;
int rc = sqlite3_exec(db, "SELECT format, author, title, category, tags, priority, filename, read FROM ebook_collection;", add_db_data_to_store, (void*) dataStore, &dbErrorMsg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error: %s\n", dbErrorMsg);
sqlite3_free(dbErrorMsg);
}
//----------------------------------------------------------------------------
GtkWidget *menuBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
g_object_set(G_OBJECT(menuBox), "margin", 10, "margin-top", 5, "margin-bottom", 5, NULL);
gtk_grid_attach(GTK_GRID(grid), menuBox, 0, 0, 10, 1);
//----------------------------------------------------------------------------
GtkWidget *ebookList = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dataStore));
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ebookList), true);
gtk_widget_set_hexpand(ebookList, true);
gtk_widget_set_vexpand(ebookList, true);
gtk_window_set_focus(GTK_WINDOW(window), ebookList);
gtk_tree_view_set_search_column(GTK_TREE_VIEW(ebookList), TITLE_COLUMN);
gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(ebookList), GTK_TREE_VIEW_GRID_LINES_BOTH);
gtk_drag_dest_set(ebookList, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY);
gtk_drag_dest_add_uri_targets(ebookList);
GtkAdjustment *vadjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(ebookList));
GtkAdjustment *hadjustment = gtk_scrollable_get_hadjustment(GTK_SCROLLABLE(ebookList));
GtkWidget *scrollWin = gtk_scrolled_window_new(hadjustment, vadjustment);
g_object_set(G_OBJECT(scrollWin), "margin-left", 10, "margin-right", 10, NULL);
gtk_grid_attach(GTK_GRID(grid), scrollWin, 0, 2, 10, 1);
gtk_container_add(GTK_CONTAINER(scrollWin), ebookList);
gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(scrollWin), 800);
gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scrollWin), 400);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollWin), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
//gtk_scrolled_window_set_overlay_scrolling(GTK_SCROLLED_WINDOW(scrollWin), false);
GtkWidget* progressRevealer = gtk_revealer_new();
gtk_revealer_set_transition_duration(GTK_REVEALER(progressRevealer), 2250);
gtk_revealer_set_transition_type(GTK_REVEALER(progressRevealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);
gtk_grid_attach(GTK_GRID(grid), progressRevealer, 0, 3, 10, 1);
GtkWidget *progressBar = gtk_progress_bar_new();
g_object_set(G_OBJECT(progressBar), "margin-top", 8, "margin-bottom", 5, "margin-left", 15, "margin-right", 15, NULL);
gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(progressBar), true);
gtk_container_add(GTK_CONTAINER(progressRevealer), progressBar);
GtkWidget *statusBar = gtk_statusbar_new();
gtk_grid_attach(GTK_GRID(grid), statusBar, 0, 4, 10, 1);
guint contextId = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusBar), "Welcome");
gtk_statusbar_push(GTK_STATUSBAR(statusBar), contextId, gettext("Welcome to KISS Ebook"));
g_signal_connect(G_OBJECT(ebookList), "row-activated", G_CALLBACK (handle_row_activated), NULL);
g_signal_connect(G_OBJECT(ebookList), "key_press_event", G_CALLBACK (handle_key_press), NULL);
g_signal_connect(G_OBJECT(ebookList), "drag_data_received", G_CALLBACK(handle_drag_data), NULL);
g_object_set_data(G_OBJECT(ebookList), "app", app);
g_object_set_data(G_OBJECT(ebookList), "appWindow", window);
g_object_set_data(G_OBJECT(ebookList), "db", db);
g_object_set_data(G_OBJECT(ebookList), "dataStore", dataStore);
g_object_set_data(G_OBJECT(ebookList), "status", statusBar);
g_object_set_data(G_OBJECT(ebookList), "progress", progressBar);
g_object_set_data(G_OBJECT(ebookList), "progressRevealer", progressRevealer);
g_object_set_data(G_OBJECT(ebookList), "treeview", ebookList);
//----------------------------------------------------------------------------
GtkWidget *searchSelection = gtk_combo_box_text_new();
g_object_set(G_OBJECT(searchSelection), "margin", 10, "margin-top", 0, NULL);
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(searchSelection), gettext("Author and title"));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(searchSelection), gettext("Format"));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(searchSelection), gettext("Authors"));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(searchSelection), gettext("Title"));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(searchSelection), gettext("Category"));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(searchSelection), gettext("Tags"));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(searchSelection), gettext("Filename"));
gtk_combo_box_set_active(GTK_COMBO_BOX(searchSelection), 0);
gtk_grid_attach(GTK_GRID(grid), searchSelection, 0, 1, 1, 1);
g_object_set_data(G_OBJECT(ebookList), "searchSelection", searchSelection);
GtkWidget *searchEntry = gtk_entry_new();
g_object_set(G_OBJECT(searchEntry), "margin", 10, "margin-top", 0, NULL);
gtk_entry_set_placeholder_text(GTK_ENTRY(searchEntry), gettext("Search inside ebook list..."));
gtk_entry_set_max_length(GTK_ENTRY(searchEntry), 64);
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(searchEntry), GTK_ENTRY_ICON_PRIMARY, "system-search");
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(searchEntry), GTK_ENTRY_ICON_SECONDARY, "edit-clear");
gtk_entry_set_icon_activatable(GTK_ENTRY(searchEntry), GTK_ENTRY_ICON_PRIMARY, true);
gtk_entry_set_icon_activatable(GTK_ENTRY(searchEntry), GTK_ENTRY_ICON_SECONDARY, true);
gtk_entry_set_icon_tooltip_text(GTK_ENTRY(searchEntry), GTK_ENTRY_ICON_PRIMARY, gettext("Start search using input"));
gtk_entry_set_icon_tooltip_text(GTK_ENTRY(searchEntry), GTK_ENTRY_ICON_SECONDARY, gettext("Clear search and restore entries to default."));
gtk_grid_attach(GTK_GRID(grid), searchEntry, 1, 1, 9, 1);
g_signal_connect(G_OBJECT(searchEntry), "icon-press", G_CALLBACK(search_icon_click), ebookList);
g_signal_connect(G_OBJECT(searchEntry), "activate", G_CALLBACK(search_handle_search), ebookList);
//----------------------------------------------------------------------------
GtkIconTheme *iconTheme = gtk_icon_theme_get_default();
GError *iconError = NULL;
GtkIconInfo *infoOpenIcon = gtk_icon_theme_lookup_icon(iconTheme, "document-open", 24, GTK_ICON_LOOKUP_NO_SVG);
GdkPixbuf *infoIcon = NULL;
if (infoOpenIcon != NULL) {
infoIcon = gtk_icon_info_load_icon(infoOpenIcon, &iconError);
}
//----------------------------------------------------------------------------
int *columnIds = malloc(sizeof(int) * N_COLUMNS);
for (int i = 0; i < N_COLUMNS; ++i) {
columnIds[i] = i;
}
g_object_set_data(G_OBJECT(window), "columnIds", columnIds);
g_object_set_data(G_OBJECT(app), "treeview", ebookList);
g_object_set_data(G_OBJECT(app), "columnIds", columnIds);
g_object_set_data(G_OBJECT(app), "dataStore", dataStore);
//----------------------------------------------------------------------------
GtkCellRenderer *imageRenderer = NULL;
if (infoIcon != NULL) {
imageRenderer = gtk_cell_renderer_pixbuf_new();
g_object_set(G_OBJECT(imageRenderer), "pixbuf", infoIcon, NULL);
gtk_cell_renderer_set_padding(imageRenderer, 5, 8);
} else {
imageRenderer = gtk_cell_renderer_toggle_new();
gtk_cell_renderer_set_padding(imageRenderer, 5, 8);
}
GtkTreeViewColumn *columnOpen = gtk_tree_view_column_new_with_attributes(gettext("Open"), imageRenderer, NULL, STARTUP_COLUMN, NULL);
g_object_set_data(G_OBJECT(columnOpen), "id", &columnIds[0]);
gtk_tree_view_column_set_min_width(columnOpen, 40);
gtk_tree_view_column_set_resizable(columnOpen, false);
gtk_tree_view_append_column(GTK_TREE_VIEW(ebookList), columnOpen);
GtkCellRenderer *ebookListFormat = gtk_cell_renderer_text_new();
gtk_cell_renderer_set_padding(ebookListFormat, 5, 8);
GtkTreeViewColumn *columnFormat = gtk_tree_view_column_new_with_attributes(gettext("Format"), ebookListFormat, "text", FORMAT_COLUMN, NULL);
gtk_tree_view_column_set_resizable(columnFormat, false);
gtk_tree_view_column_set_min_width(columnFormat, 80);
g_object_set_data(G_OBJECT(columnFormat), "id", &columnIds[1]);
gtk_tree_view_append_column(GTK_TREE_VIEW(ebookList), columnFormat);
GtkCellRenderer *ebookListAuthor = gtk_cell_renderer_text_new();
g_object_set(G_OBJECT(ebookListAuthor), "editable", true, NULL);
g_signal_connect(G_OBJECT(ebookListAuthor), "edited", G_CALLBACK(handle_editing_author), ebookList);
GtkTreeViewColumn *columnAuthor = gtk_tree_view_column_new_with_attributes(gettext("Author"), ebookListAuthor, "text", AUTHOR_COLUMN, NULL);
gtk_tree_view_column_set_min_width(columnAuthor, 110);
gtk_tree_view_column_set_resizable(columnAuthor, true);
g_object_set_data(G_OBJECT(columnAuthor), "id", &columnIds[2]);
gtk_cell_renderer_set_padding(ebookListAuthor, 5, 8);
gtk_tree_view_append_column(GTK_TREE_VIEW(ebookList), columnAuthor);
GtkCellRenderer *ebookListTitle = gtk_cell_renderer_text_new();
g_object_set(G_OBJECT(ebookListTitle), "editable", true, NULL);
g_signal_connect(G_OBJECT(ebookListTitle), "edited", G_CALLBACK(handle_editing_title), ebookList);
GtkTreeViewColumn *columnTitle = gtk_tree_view_column_new_with_attributes(gettext("Title"), ebookListTitle, "text", TITLE_COLUMN, NULL);
gtk_tree_view_column_set_min_width(columnTitle, 240);
gtk_tree_view_column_set_expand(columnTitle, true);
gtk_tree_view_column_set_resizable(columnTitle, true);
g_object_set_data(G_OBJECT(columnTitle), "id", &columnIds[3]);
gtk_cell_renderer_set_padding(ebookListTitle, 5, 8);
gtk_tree_view_append_column(GTK_TREE_VIEW(ebookList), columnTitle);
//----------------------------------------------------------------------------
GtkCellRenderer *ebookListCategory = gtk_cell_renderer_text_new();
g_object_set(G_OBJECT(ebookListCategory), "editable", true, NULL);
g_signal_connect(G_OBJECT(ebookListCategory), "edited", G_CALLBACK(handle_editing_category), ebookList);
GtkTreeViewColumn *columnCategory = gtk_tree_view_column_new_with_attributes(gettext("Category"), ebookListCategory, "text", CATEGORY_COLUMN, NULL);
gtk_tree_view_column_set_min_width(columnCategory, 180);
gtk_tree_view_column_set_resizable(columnCategory, true);
g_object_set_data(G_OBJECT(columnCategory), "id", &columnIds[4]);
gtk_cell_renderer_set_padding(ebookListCategory, 5, 8);
gtk_tree_view_append_column(GTK_TREE_VIEW(ebookList), columnCategory);
GtkCellRenderer *ebookListTags = gtk_cell_renderer_text_new();
g_object_set(G_OBJECT(ebookListTags), "editable", true, NULL);
g_signal_connect(G_OBJECT(ebookListTags), "edited", G_CALLBACK(handle_editing_tags), ebookList);
GtkTreeViewColumn *columnTags = gtk_tree_view_column_new_with_attributes(gettext("Tags"), ebookListTags, "text", TAGS_COLUMN, NULL);
gtk_tree_view_column_set_min_width(columnTags, 180);
gtk_tree_view_column_set_resizable(columnTags, true);
g_object_set_data(G_OBJECT(columnTags), "id", &columnIds[5]);
gtk_cell_renderer_set_padding(ebookListTags, 5, 8);
gtk_tree_view_append_column(GTK_TREE_VIEW(ebookList), columnTags);
GtkCellRenderer *ebookListFilename = gtk_cell_renderer_text_new();
GtkTreeViewColumn *columnFilename = gtk_tree_view_column_new_with_attributes(gettext("Filename"), ebookListFilename, "text", FILENAME_COLUMN, NULL);
gtk_tree_view_column_set_min_width(columnFilename, 180);
gtk_tree_view_column_set_resizable(columnFilename, true);
g_object_set_data(G_OBJECT(columnFilename), "id", &columnIds[6]);
gtk_cell_renderer_set_padding(ebookListFilename, 5, 8);
gtk_tree_view_append_column(GTK_TREE_VIEW(ebookList), columnFilename);
GtkAdjustment *priorityAdjustment = gtk_adjustment_new(0, -10, 10, 1, 5, 0);
GtkCellRenderer *ebookListPriority = gtk_cell_renderer_spin_new();
g_object_set(G_OBJECT(ebookListPriority), "editable", true, NULL);
g_object_set(G_OBJECT(ebookListPriority), "digits", 0, NULL);
g_object_set(G_OBJECT(ebookListPriority), "adjustment", priorityAdjustment, NULL);
GtkTreeViewColumn *columnPriority = gtk_tree_view_column_new_with_attributes(gettext("Priority"), ebookListPriority, "text", PRIORITY_COLUMN, NULL);
gtk_tree_view_column_set_min_width(columnPriority, 100);
g_object_set_data(G_OBJECT(columnPriority), "id", &columnIds[7]);
gtk_cell_renderer_set_padding(ebookListPriority, 5, 8);
gtk_tree_view_append_column(GTK_TREE_VIEW(ebookList), columnPriority);
g_signal_connect(G_OBJECT(priorityAdjustment), "value-changed", G_CALLBACK(handle_editing_priority_value), ebookList);
g_signal_connect(G_OBJECT(priorityAdjustment), "changed", G_CALLBACK(handle_editing_priority), ebookList);
GtkCellRenderer *ebookListRead = gtk_cell_renderer_toggle_new();
GtkTreeViewColumn *columnRead = gtk_tree_view_column_new_with_attributes(gettext("Read"), ebookListRead, "active", READ_COLUMN, NULL);
gtk_cell_renderer_toggle_set_activatable(GTK_CELL_RENDERER_TOGGLE(ebookListRead), true);
g_signal_connect(G_OBJECT(ebookListRead), "toggled", G_CALLBACK(handle_toggle_read), ebookList);
gtk_tree_view_column_set_fixed_width(columnRead, 60);
g_object_set_data(G_OBJECT(columnRead), "id", &columnIds[8]);
gtk_cell_renderer_set_padding(ebookListRead, 5, 8);
gtk_tree_view_append_column(GTK_TREE_VIEW(ebookList), columnRead);
//----------------------------------------------------------------------------
// Sorting of columns or highlight enabled
gtk_tree_view_column_set_clickable(columnOpen, true);
gtk_tree_view_column_set_clickable(columnFormat, true);
gtk_tree_view_column_set_clickable(columnAuthor, true);
gtk_tree_view_column_set_clickable(columnTitle, true);
gtk_tree_view_column_set_clickable(columnCategory, true);
gtk_tree_view_column_set_clickable(columnTags, true);
gtk_tree_view_column_set_clickable(columnFilename, true);
gtk_tree_view_column_set_clickable(columnPriority, true);
gtk_tree_view_column_set_clickable(columnRead, true);
// Reorderable
gtk_tree_view_column_set_reorderable(columnOpen, true);
gtk_tree_view_column_set_reorderable(columnFormat, true);
gtk_tree_view_column_set_reorderable(columnAuthor, true);
gtk_tree_view_column_set_reorderable(columnTitle, true);
gtk_tree_view_column_set_reorderable(columnCategory, true);
gtk_tree_view_column_set_reorderable(columnTags, true);
gtk_tree_view_column_set_reorderable(columnFilename, true);
gtk_tree_view_column_set_reorderable(columnPriority, true);
gtk_tree_view_column_set_reorderable(columnRead, true);
// Column and table signals
g_signal_connect(G_OBJECT(columnFormat), "clicked", G_CALLBACK(handle_sort_column), ebookList);
g_signal_connect(G_OBJECT(columnAuthor), "clicked", G_CALLBACK(handle_sort_column), ebookList);
g_signal_connect(G_OBJECT(columnTitle), "clicked", G_CALLBACK(handle_sort_column), ebookList);
g_signal_connect(G_OBJECT(columnCategory), "clicked", G_CALLBACK(handle_sort_column), ebookList);
g_signal_connect(G_OBJECT(columnTags), "clicked", G_CALLBACK(handle_sort_column), ebookList);
g_signal_connect(G_OBJECT(columnFilename), "clicked", G_CALLBACK(handle_sort_column), ebookList);
g_signal_connect(G_OBJECT(columnPriority), "clicked", G_CALLBACK(handle_sort_column), ebookList);
g_signal_connect(G_OBJECT(columnRead), "clicked", G_CALLBACK(handle_sort_column), ebookList);
g_signal_connect(G_OBJECT(ebookList), "columns-changed", G_CALLBACK(handle_column_change), NULL);
// The main menu -------------------------------------------------------------
// TODO: Should the main menu use images?
// NOTE: https://developer.gnome.org/gtk3/stable/GtkImageMenuItem.html#GtkImageMenuItem--image
GtkWidget *menu = gtk_menu_bar_new();
GtkWidget *mainMenu = gtk_menu_new();
GtkWidget *mMain = gtk_menu_item_new_with_label(gettext("Main"));
GtkWidget *meQuit = gtk_menu_item_new_with_label(gettext("Quit"));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(mMain), mainMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(mainMenu), meQuit);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mMain);
g_object_set_data(G_OBJECT(meQuit), "app", app);
g_object_set_data(G_OBJECT(meQuit), "appWindow", window);
g_signal_connect(G_OBJECT(meQuit), "activate", G_CALLBACK(menuhandle_meQuit), NULL);
GtkWidget *opMenu = gtk_menu_new();
GtkWidget *mOp = gtk_menu_item_new_with_label(gettext("Operations"));
GtkWidget *seperator = gtk_separator_menu_item_new();
GtkWidget *meSetupLauncher = gtk_menu_item_new_with_label(gettext("Setup launcher applications"));
GtkWidget *meSetLauncher = gtk_menu_item_new_with_label(gettext("Set launcher applications and parameters"));
GtkWidget *meImportFiles = gtk_menu_item_new_with_label(gettext("Import files and folders"));
GtkWidget *meEditEntry = gtk_menu_item_new_with_label(gettext("Edit ebook details"));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(mOp), opMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(opMenu), meSetupLauncher);
gtk_menu_shell_append(GTK_MENU_SHELL(opMenu), meSetLauncher);
gtk_menu_shell_append(GTK_MENU_SHELL(opMenu), seperator);
gtk_menu_shell_append(GTK_MENU_SHELL(opMenu), meImportFiles);
gtk_menu_shell_append(GTK_MENU_SHELL(opMenu), meEditEntry);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mOp);
g_object_set_data(G_OBJECT(meSetupLauncher), "db", db);
g_signal_connect(G_OBJECT(meSetupLauncher), "activate", G_CALLBACK(menuhandle_setup_dialog), NULL);
g_object_set_data(G_OBJECT(meSetLauncher), "appWindow", window);
g_object_set_data(G_OBJECT(meSetLauncher), "db", db);
g_signal_connect(G_OBJECT(meSetLauncher), "activate", G_CALLBACK(menuhandle_meSetLauncher), NULL);
g_object_set_data(G_OBJECT(meEditEntry), "appWindow", window);
g_object_set_data(G_OBJECT(meEditEntry), "treeview", ebookList);
g_object_set_data(G_OBJECT(meEditEntry), "db", db);
g_signal_connect(G_OBJECT(meEditEntry), "activate", G_CALLBACK(menuhandle_meEditEntry), NULL);
g_object_set_data(G_OBJECT(meImportFiles), "appWindow", window);
g_object_set_data(G_OBJECT(meImportFiles), "status", statusBar);
g_object_set_data(G_OBJECT(meImportFiles), "progressRevealer", progressRevealer);
g_object_set_data(G_OBJECT(meImportFiles), "progress", progressBar);
g_object_set_data(G_OBJECT(meImportFiles), "treeview", ebookList);
g_object_set_data(G_OBJECT(meImportFiles), "db", db);
g_signal_connect(G_OBJECT(meImportFiles), "activate", G_CALLBACK(menuhandle_meImportFiles), NULL);
g_object_set_data(G_OBJECT(window), "menuSetLauncher", GTK_MENU_ITEM(meSetLauncher));
g_object_set_data(G_OBJECT(window), "menuImportFiles", GTK_MENU_ITEM(meImportFiles));
GtkWidget *viewMenu = gtk_menu_new();
GtkWidget *mView = gtk_menu_item_new_with_label(gettext("View"));
GtkWidget *viewColumns = gtk_menu_new();
GtkWidget *meSubColumns = gtk_menu_item_new_with_label(gettext("Show or hide columns..."));
GtkWidget *meShowFormat = gtk_check_menu_item_new_with_label(gettext("Format"));
GtkWidget *meShowAuthor = gtk_check_menu_item_new_with_label(gettext("Author"));
GtkWidget *meShowCategory = gtk_check_menu_item_new_with_label(gettext("Category"));
GtkWidget *meShowTags = gtk_check_menu_item_new_with_label(gettext("Tags"));
GtkWidget *meShowFilename = gtk_check_menu_item_new_with_label(gettext("Filename"));
GtkWidget *meShowPriority = gtk_check_menu_item_new_with_label(gettext("Priority"));
GtkWidget *meShowRead = gtk_check_menu_item_new_with_label(gettext("Read state"));
GtkWidget *seperator_two = gtk_separator_menu_item_new();
GtkWidget *meResetColumns = gtk_menu_item_new_with_label(gettext("Reset column order"));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(mView), viewMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(viewMenu), meSubColumns);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(meSubColumns), viewColumns);
gtk_menu_shell_append(GTK_MENU_SHELL(viewColumns), meShowFormat);
gtk_menu_shell_append(GTK_MENU_SHELL(viewColumns), meShowAuthor);
gtk_menu_shell_append(GTK_MENU_SHELL(viewColumns), meShowCategory);
gtk_menu_shell_append(GTK_MENU_SHELL(viewColumns), meShowTags);
gtk_menu_shell_append(GTK_MENU_SHELL(viewColumns), meShowFilename);
gtk_menu_shell_append(GTK_MENU_SHELL(viewColumns), meShowPriority);
gtk_menu_shell_append(GTK_MENU_SHELL(viewColumns), meShowRead);
gtk_menu_shell_append(GTK_MENU_SHELL(viewMenu), seperator_two);
gtk_menu_shell_append(GTK_MENU_SHELL(viewMenu), meResetColumns);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mView);
g_object_set_data(G_OBJECT(meShowFormat), "db", db);
g_object_set_data(G_OBJECT(meShowAuthor), "db", db);
g_object_set_data(G_OBJECT(meShowCategory), "db", db);
g_object_set_data(G_OBJECT(meShowTags), "db", db);
g_object_set_data(G_OBJECT(meShowFilename), "db", db);
g_object_set_data(G_OBJECT(meShowPriority), "db", db);
g_object_set_data(G_OBJECT(meShowRead), "db", db);
g_signal_connect(G_OBJECT(meShowFormat), "toggled", G_CALLBACK(menuhandle_meToggleColumn), columnFormat);
g_signal_connect(G_OBJECT(meShowAuthor), "toggled", G_CALLBACK(menuhandle_meToggleColumn), columnAuthor);
g_signal_connect(G_OBJECT(meShowCategory), "toggled", G_CALLBACK(menuhandle_meToggleColumn), columnCategory);
g_signal_connect(G_OBJECT(meShowFilename), "toggled", G_CALLBACK(menuhandle_meToggleColumn), columnFilename);
g_signal_connect(G_OBJECT(meShowPriority), "toggled", G_CALLBACK(menuhandle_meToggleColumn), columnPriority);
g_signal_connect(G_OBJECT(meShowTags), "toggled", G_CALLBACK(menuhandle_meToggleColumn), columnTags);
g_signal_connect(G_OBJECT(meShowRead), "toggled", G_CALLBACK(menuhandle_meToggleColumn), columnRead);
g_signal_connect(G_OBJECT(meResetColumns), "activate", G_CALLBACK(menuhandle_meResetColumns), ebookList);
GtkWidget *optionsMenu = gtk_menu_new();
GtkWidget *mOptions = gtk_menu_item_new_with_label(gettext("Options"));
GtkWidget *mEditOptions = gtk_menu_item_new_with_label(gettext("Edit options"));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(mOptions), optionsMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(optionsMenu), mEditOptions);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mOptions);
g_object_set_data(G_OBJECT(mEditOptions), "meShowFormat", meShowFormat);
g_object_set_data(G_OBJECT(mEditOptions), "meShowAuthor", meShowAuthor);
g_object_set_data(G_OBJECT(mEditOptions), "meShowCategory", meShowCategory);
g_object_set_data(G_OBJECT(mEditOptions), "meShowTags", meShowTags);
g_object_set_data(G_OBJECT(mEditOptions), "meShowFilename", meShowFilename);
g_object_set_data(G_OBJECT(mEditOptions), "meShowPriority", meShowPriority);
g_object_set_data(G_OBJECT(mEditOptions), "meShowRead", meShowRead);
g_signal_connect(G_OBJECT(mEditOptions), "activate", G_CALLBACK(menuhandle_mOptions), db);
g_object_set(G_OBJECT(menu), "margin-bottom", 12, NULL);
gtk_container_add(GTK_CONTAINER(menuBox), menu);
// Menu code end -------------------------------------------------------------
//----------------------------------------------------------------------------
// Retrieve which columns are shown
gtk_tree_view_column_set_visible(columnFormat, false);
gtk_tree_view_column_set_visible(columnAuthor, false);
gtk_tree_view_column_set_visible(columnCategory, false);
gtk_tree_view_column_set_visible(columnTags, false);
gtk_tree_view_column_set_visible(columnPriority, false);
gtk_tree_view_column_set_visible(columnFilename, false);
gtk_tree_view_column_set_visible(columnRead, false);
struct dbAnswer receiveFromDb = { 0, NULL, NULL };
rc = sqlite3_exec(db, "SELECT value FROM options WHERE option='visible_columns' LIMIT 0,1;", fill_db_answer, (void*) &receiveFromDb, &dbErrorMsg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error, cannot read out column setting: %s\n", dbErrorMsg);
sqlite3_free(dbErrorMsg);
} else {
char *visibleColumnsString = NULL;
char *columnNames[] = {
"format",
"author",
"category",
"tags",
"filename",
"priority",
"read"
};
if (get_db_answer_value(&receiveFromDb, "value", &visibleColumnsString)) {
char *stringPart = NULL;
stringPart = strtok(visibleColumnsString, ",");
while (stringPart != NULL) {
for (int i = 0; i < N_COLUMNS; ++i) {
if (strncmp(stringPart, columnNames[i], strlen(columnNames[i])) == 0) {
switch (i) {
case 0:
gtk_tree_view_column_set_visible(columnFormat, true);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(meShowFormat), true);
break;
case 1:
gtk_tree_view_column_set_visible(columnAuthor, true);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(meShowAuthor), true);
break;
case 2:
gtk_tree_view_column_set_visible(columnCategory, true);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(meShowCategory), true);
break;
case 3:
gtk_tree_view_column_set_visible(columnTags, true);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(meShowTags), true);
break;
case 4:
gtk_tree_view_column_set_visible(columnFilename, true);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(meShowFilename), true);
break;
case 5:
gtk_tree_view_column_set_visible(columnPriority, true);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(meShowPriority), true);
break;
case 6:
gtk_tree_view_column_set_visible(columnRead, true);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(meShowRead), true);
break;
default:
break;
}
break;
}
}
stringPart = strtok(NULL, ",");
}
free(visibleColumnsString);
}
}
free_db_answer(&receiveFromDb);
//----------------------------------------------------------------------------
gtk_widget_show_all(window);
//"first_startup" check
rc = sqlite3_exec(db, "SELECT value FROM options WHERE option='first_startup' LIMIT 0,1;", fill_db_answer, (void*) &receiveFromDb, &dbErrorMsg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error, cannot read out startup setting: %s\n", dbErrorMsg);
sqlite3_free(dbErrorMsg);
} else {
char *startupValue = NULL;
if (get_db_answer_value(&receiveFromDb, "value", &startupValue)) {
if (strcmp(startupValue, "true") == 0) {
ask_setup_window(db);
}
}
free(startupValue);
}
free_db_answer(&receiveFromDb);
//----------------------------------------------------------------------------
//"sort_on_startup" check
rc = sqlite3_exec(db, "SELECT value FROM options WHERE option='sort_on_startup' LIMIT 0,1;", fill_db_answer, (void*) &receiveFromDb, &dbErrorMsg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error, cannot read out sort on startup setting: %s\n", dbErrorMsg);
sqlite3_free(dbErrorMsg);
} else {
char *sortOnStartup = NULL;