2 * This file is part of maemopad+
5 * This software is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
10 * This software is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this software; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 #include <ui/callbacks.h>
23 #include <ui/interface.h>
25 #include <gdk/gdkkeysyms.h>
29 * strlen needed from string.h
32 #include <sys/types.h>
40 #include <hildon/hildon-banner.h>
41 #include <hildon/hildon-note.h>
42 #include <hildon/hildon-font-selection-dialog.h>
43 #include <tablet-browser-interface.h>
45 #include <hildon-widgets/hildon-banner.h>
46 #include <hildon-widgets/hildon-note.h>
47 #include <hildon-widgets/hildon-font-selection-dialog.h>
48 #include <osso-browser-interface.h>
50 #include <libgnomevfs/gnome-vfs.h>
56 gboolean
read_file_to_buffer(MainView
* mainview
);
57 void write_buffer_to_file(MainView
* mainview
);
58 void new_node_dialog(nodeType typ
, MainView
* mainview
);
59 gboolean
foreach_func_update_ord (GtkTreeModel
*model
,GtkTreePath
*path
,GtkTreeIter
*iter
, MainView
*mainview
);
60 void move_nodes_up(GtkTreeModel
* model
, GtkTreeRowReference
* topnode
, GtkTreeRowReference
* newtop
);
61 GtkTreeRowReference
*iter2ref(GtkTreeModel
* model
, GtkTreeIter
* iter
);
62 gboolean
exec_command_on_db(MainView
*mainview
,char sql_string
[]);
63 int get_node_id_on_tmp_db(GtkTreeModel
*model
,GtkTreeIter
*iter
);
64 gint
get_branch_node_index(GtkTreePath
*path
);
65 gboolean
move_node(MainView
*mainview
,GtkTreeIter
*new_parent
,GtkTreeIter
*item_to_move
,GtkTreeIter
*item_befor
);
66 gboolean
tree_model_iter_prev(GtkTreeModel
*tree_model
,GtkTreeIter
*iter
);
69 st==0: turn off/zero refcount
70 st==1: turn on/increase ref
71 st==2: decrease refcount and turn off if necessary
73 void setBusy(MainView
*mainview
, gchar st
)
75 if (st
==0) mainview
->busyrefcount
=0;
76 else if (st
==1) mainview
->busyrefcount
++;
77 else if (st
==2 && mainview
->busyrefcount
>0) mainview
->busyrefcount
--;
78 gdk_window_set_cursor(GTK_WIDGET(mainview
->data
->main_view
)->window
, (mainview
->busyrefcount
>0)?mainview
->cursorBusy
:NULL
);
81 gboolean
isBusy(MainView
*mainview
)
83 if (mainview
->busyrefcount
>0) return(TRUE
);
87 void prepareUIforNodeChange(MainView
* mainview
, nodeType typ
)
89 gtk_widget_set_sensitive(GTK_WIDGET(mainview
->undo_tb
), TRUE
);
90 gtk_widget_set_sensitive(GTK_WIDGET(mainview
->redo_tb
), TRUE
);
94 gtk_widget_show(GTK_WIDGET(mainview
->font_tb
));
95 gtk_widget_show(GTK_WIDGET(mainview
->bold_tb
));
96 gtk_widget_show(GTK_WIDGET(mainview
->italic_tb
));
97 gtk_widget_show(GTK_WIDGET(mainview
->underline_tb
));
98 gtk_widget_show(GTK_WIDGET(mainview
->bullet_tb
));
99 gtk_widget_show(mainview
->tools_font
);
100 gtk_widget_show(mainview
->tools_wordwrap
);
104 gtk_widget_hide(GTK_WIDGET(mainview
->font_tb
));
105 gtk_widget_hide(GTK_WIDGET(mainview
->bold_tb
));
106 gtk_widget_hide(GTK_WIDGET(mainview
->italic_tb
));
107 gtk_widget_hide(GTK_WIDGET(mainview
->underline_tb
));
108 gtk_widget_hide(GTK_WIDGET(mainview
->bullet_tb
));
109 gtk_widget_hide(mainview
->tools_font
);
110 gtk_widget_hide(mainview
->tools_wordwrap
);
113 if (typ
== NODE_SKETCH
)
115 /* gtk_widget_show(GTK_WIDGET(mainview->colorbutton_tb));*/
116 gtk_widget_show(GTK_WIDGET(mainview
->eraser_tb
));
117 gtk_widget_show(GTK_WIDGET(mainview
->brushsize_tb
));
118 gtk_widget_show(GTK_WIDGET(mainview
->sketchlines_tb
));
119 gtk_widget_show(GTK_WIDGET(mainview
->shape_tb
));
120 gtk_widget_show(mainview
->tools_color
);
121 gtk_widget_show(mainview
->tools_brushsize
);
122 gtk_widget_show(mainview
->tools_pagestyle
);
123 gtk_widget_show(mainview
->tools_shape
);
124 gtk_widget_show(mainview
->tools_pressure
);
128 /* gtk_widget_hide(GTK_WIDGET(mainview->colorbutton_tb));*/
129 gtk_widget_hide(GTK_WIDGET(mainview
->eraser_tb
));
130 gtk_widget_hide(GTK_WIDGET(mainview
->brushsize_tb
));
131 gtk_widget_hide(GTK_WIDGET(mainview
->sketchlines_tb
));
132 gtk_widget_hide(GTK_WIDGET(mainview
->shape_tb
));
133 gtk_widget_hide(mainview
->tools_color
);
134 gtk_widget_hide(mainview
->tools_brushsize
);
135 gtk_widget_hide(mainview
->tools_pagestyle
);
136 gtk_widget_hide(mainview
->tools_shape
);
137 gtk_widget_hide(mainview
->tools_pressure
);
140 if (typ
== NODE_CHECKLIST
)
142 gtk_widget_show(GTK_WIDGET(mainview
->bold_tb
));
143 gtk_widget_show(GTK_WIDGET(mainview
->strikethru_tb
));
144 gtk_widget_show(GTK_WIDGET(mainview
->check_tb
));
145 gtk_widget_show(GTK_WIDGET(mainview
->checkadd_tb
));
146 gtk_widget_show(GTK_WIDGET(mainview
->checkdel_tb
));
147 gtk_widget_hide(GTK_WIDGET(mainview
->undo_tb
));
148 gtk_widget_hide(GTK_WIDGET(mainview
->redo_tb
));
152 gtk_widget_hide(GTK_WIDGET(mainview
->strikethru_tb
));
153 gtk_widget_hide(GTK_WIDGET(mainview
->check_tb
));
154 gtk_widget_hide(GTK_WIDGET(mainview
->checkadd_tb
));
155 gtk_widget_hide(GTK_WIDGET(mainview
->checkdel_tb
));
156 gtk_widget_show(GTK_WIDGET(mainview
->undo_tb
));
157 gtk_widget_show(GTK_WIDGET(mainview
->redo_tb
));
160 if (typ
== NODE_TEXT
)
162 gtk_widget_hide(GTK_WIDGET(mainview
->colorbutton_tb
));
163 gtk_widget_hide(sketchwidget_get_mainwidget(mainview
->sk
));
164 gtk_widget_hide(mainview
->listscroll
);
165 gtk_widget_show(GTK_WIDGET(mainview
->scrolledwindow
));
166 gtk_widget_show(mainview
->tools_item
);
168 else if (typ
== NODE_SKETCH
)
170 gtk_widget_show(GTK_WIDGET(mainview
->colorbutton_tb
));
171 gtk_widget_hide(GTK_WIDGET(mainview
->scrolledwindow
));
172 gtk_widget_hide(mainview
->listscroll
);
173 gtk_widget_show(sketchwidget_get_mainwidget(mainview
->sk
));
174 gtk_widget_show(mainview
->tools_item
);
176 else if (typ
== NODE_CHECKLIST
)
178 gtk_widget_show(GTK_WIDGET(mainview
->colorbutton_tb
));
179 gtk_widget_hide(GTK_WIDGET(mainview
->scrolledwindow
));
180 gtk_widget_hide(sketchwidget_get_mainwidget(mainview
->sk
));
181 gtk_widget_hide(mainview
->tools_item
);
182 gtk_widget_show(mainview
->listscroll
);
186 gtk_widget_hide(GTK_WIDGET(mainview
->colorbutton_tb
));
187 gtk_widget_hide(GTK_WIDGET(mainview
->scrolledwindow
));
188 gtk_widget_hide(sketchwidget_get_mainwidget(mainview
->sk
));
189 gtk_widget_hide(mainview
->tools_item
);
190 gtk_widget_hide(mainview
->listscroll
);
194 nodeData
*getSelectedNode(MainView
* mainview
)
201 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
203 if (!gtk_tree_selection_get_selected(selection
, &model
, &iter
))
206 gtk_tree_model_get(model
, &iter
, NODE_DATA
, &nd
, -1);
211 void saveCurrentData(MainView
* mainview
)
213 nodeData
*selnode
= getSelectedNode(mainview
);
214 saveDataToNode(mainview
, selnode
);
217 void saveDataToNode(MainView
* mainview
, nodeData
*selnode
)
223 (selnode
->typ
== NODE_SKETCH
&& sketchwidget_get_edited(mainview
->sk
) == FALSE
) ||
224 (selnode
->typ
== NODE_TEXT
&& wp_text_buffer_is_modified(mainview
->buffer
)==FALSE
) ||
225 (selnode
->typ
== NODE_CHECKLIST
&& gtk_object_get_data(GTK_OBJECT(mainview
->listview
), "edited")==FALSE
)
228 fprintf(stderr
, "node not edited, not saving\n");
232 mainview
->file_edited
= TRUE
;
234 setBusy(mainview
, 1);
235 fprintf(stderr
, "savecurrentdata!\n");
237 gboolean goterr
= TRUE
;
238 gchar
*textdata
= NULL
;
239 GdkPixbuf
*pixbuf
= NULL
;
240 gchar
*sketchdata
= NULL
;
244 if (selnode
->typ
== NODE_TEXT
)
247 GtkTextIter start
, end
;
248 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(mainview
->buffer
), &start
, &end
);
249 textdata
= gtk_text_buffer_serialize_rich_text(GTK_TEXT_BUFFER(mainview
->buffer
), &start
, &end
, &datalen
);
252 GString
*gstr
=g_string_sized_new(4096);
253 wp_text_buffer_save_document(mainview
->buffer
, (WPDocumentSaveCallback
)(wp_savecallback
), gstr
);
256 textdata
=g_string_free(gstr
, FALSE
);
257 /*fprintf(stderr, "*%s*\n", textdata);*/
259 /* snprintf(tq, sizeof(tq), "UPDATE %s SET bodytype=%d, bodyblob=NULL, body=?, flags=%d WHERE nodeid=%d", datatable_tmpname, selnode->typ, selnode->flags, selnode->sql3id);*/
260 snprintf(tq
, sizeof(tq
), "UPDATE %s SET bodytype=%d, bodyblob=?, body=NULL, flags=%d WHERE nodeid=%d", datatable_tmpname
, selnode
->typ
, selnode
->flags
, selnode
->sql3id
);
262 else if (selnode
->typ
== NODE_SKETCH
)
265 GdkPixmap
*skpix
= sketchwidget_get_Pixmap(mainview
->sk
);
266 GtkWidget
*skdr
= sketchwidget_get_drawingarea(mainview
->sk
);
268 pixbuf
= gdk_pixbuf_get_from_drawable(NULL
, GDK_DRAWABLE(skpix
), NULL
, 0, 0, 0, 0, skdr
->allocation
.width
, skdr
->allocation
.height
);
271 fprintf(stderr
, "Error saving: pixbuf is null\n");
276 GdkPixbuf
*pixbuf2
= sketchwidget_trim_image(pixbuf
, skdr
->allocation
.width
, skdr
->allocation
.height
, &w
, &h
, FALSE
);
280 if (gdk_pixbuf_save_to_buffer(pixbuf2
, &sketchdata
, &datalen
, "png", &err
, NULL
) == FALSE
)
284 fprintf(stderr
, "Error saving sketch! %s\n", err
->message
);
287 gdk_pixbuf_unref(pixbuf2
);
290 snprintf(tq
, sizeof(tq
), "UPDATE %s SET bodytype=%d, body=NULL, bodyblob=?, flags=%d WHERE nodeid=%d", datatable_tmpname
, selnode
->typ
, selnode
->flags
, selnode
->sql3id
);
291 fprintf(stderr
, "datalen:%d\n", datalen
);
292 if (skpix
&& G_IS_OBJECT(skpix
)) g_object_unref(skpix
);
294 else if (selnode
->typ
== NODE_CHECKLIST
)
296 snprintf(tq
, sizeof(tq
), "UPDATE %s SET bodytype=%d, body=NULL, bodyblob=NULL, flags=%d WHERE nodeid=%d", datatable_tmpname
, selnode
->typ
, selnode
->flags
, selnode
->sql3id
);
299 /*fprintf(stderr, "query is *%s*\n", tq); */
303 sqlite3_stmt
*stmt
= NULL
;
305 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
309 fprintf(stderr
, "Error updating: %s\n", sqlite3_errmsg(mainview
->db
));
312 if (selnode
->typ
== NODE_TEXT
)
313 sqlite3_bind_text(stmt
, 1, textdata
, datalen
, /*strlen(textdata),*/ SQLITE_TRANSIENT
);
314 else if (selnode
->typ
== NODE_SKETCH
)
315 sqlite3_bind_blob(stmt
, 1, sketchdata
, datalen
, SQLITE_TRANSIENT
);
318 while(rc
== SQLITE_BUSY
)
320 rc
= sqlite3_step(stmt
);
321 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
324 sqlite3_finalize(stmt
);
326 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
328 fprintf(stderr
, "Error saving node: %s\n", sqlite3_errmsg(mainview
->db
));
332 if (selnode
->typ
== NODE_TEXT
)
333 gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(mainview
->buffer
), FALSE
);
334 else if (selnode
->typ
== NODE_SKETCH
)
335 sketchwidget_set_edited(mainview
->sk
, FALSE
);
336 else if (selnode
->typ
== NODE_CHECKLIST
)
337 gtk_object_set_data(GTK_OBJECT(mainview
->listview
), "edited", FALSE
);
342 while(goterr
==FALSE
&& selnode
->typ
== NODE_CHECKLIST
)
344 GtkTreeModel
*model
=gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
347 snprintf(tq
, sizeof(tq
), "DELETE FROM %s WHERE nodeid=%d", checklisttable_tmpname
, selnode
->sql3id
);
348 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
351 if (gtk_tree_model_get_iter_first(model
, &iter
)==FALSE
) break;
355 gint styletoset_weight
;
356 gboolean styletoset_strike
;
362 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, CHECKNODE_BOLD
, &styletoset_weight
, CHECKNODE_STRIKE
, &styletoset_strike
, CHECKNODE_CHECKED
, &ischecked
, CHECKNODE_TEXT
, &text
, CHECKNODE_COLOR
, &color
, -1);
365 if (color
!=NULL
&& strcmp(color
, "(null)")!=0 && gdk_color_parse(color
, &tmpcol
))
367 col
=((tmpcol
.red
>>8)<<16)|((tmpcol
.green
>>8)<<8)|(tmpcol
.blue
>>8);
368 /* fprintf(stderr, "calculated color for node is *%lu*\n", col);*/
372 if (ischecked
) style
|=CHECKSTYLE_CHECKED
;
373 if (styletoset_weight
==PANGO_WEIGHT_BOLD
) style
|=CHECKSTYLE_BOLD
;
374 if (styletoset_strike
) style
|=CHECKSTYLE_STRIKE
;
376 snprintf(tq
, sizeof(tq
), "INSERT INTO %s (nodeid, name, style, color, ord) VALUES(%d, ?, %d, %lu, 0)", checklisttable_tmpname
, selnode
->sql3id
, style
, col
);
377 sqlite3_stmt
*stmt
= NULL
;
379 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
384 fprintf(stderr
, "Error while saving checklist: %s\n", sqlite3_errmsg(mainview
->db
));
387 sqlite3_bind_text(stmt
, 1, text
, strlen(text
), SQLITE_TRANSIENT
);
390 while(rc
== SQLITE_BUSY
)
392 rc
= sqlite3_step(stmt
);
393 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
396 sqlite3_finalize(stmt
);
398 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
401 fprintf(stderr
, "Error while saving checklist (2): %s\n", sqlite3_errmsg(mainview
->db
));
407 }while(gtk_tree_model_iter_next(model
, &iter
)==TRUE
);
418 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Error saving memo"));
420 setBusy(mainview
, 2);
423 void callback_treeview_celldatafunc(GtkTreeViewColumn
* tree_column
, GtkCellRenderer
* cell
, GtkTreeModel
* tree_model
, GtkTreeIter
* iter
, gpointer data
)
425 MainView
*mainview
= ( MainView
* ) data
;
426 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
430 gtk_tree_model_get(tree_model
, iter
, NODE_DATA
, &nd
, -1);
434 if (nd
->namepix
== NULL
)
436 g_object_set(cell
, "visible", FALSE
, NULL
);
440 g_object_set(cell
, "visible", TRUE
, NULL
);
441 g_object_set(cell
, "width", SKETCHNODE_RX
, NULL
);
442 g_object_set(cell
, "height", SKETCHNODE_RY
, NULL
);
447 gboolean
callback_treeview_testcollapse(GtkTreeView
* treeview
, GtkTreeIter
* arg1
, GtkTreePath
* arg2
, gpointer user_data
)
452 void callback_treeview_change(GtkTreeSelection
* selection
, gpointer data
)
454 MainView
*mainview
= (MainView
*) data
;
455 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
457 nodeData
*nd
= getSelectedNode(mainview
);
461 fprintf(stderr, "changed called but no selectednode\n");
463 fprintf(stderr, "changed called, selectednode is %d\n", nd->sql3id);
467 if (mainview
->cansel_time
>0 && mainview
->cansel_time
+1.0<tm
) mainview
->cansel_node
=NULL
;
471 if (mainview
->cansel_node
!=NULL
)
473 fprintf(stderr
, "[SELLOGIC] saving %d to unselect all nodes\n", (mainview
->cansel_node
)->sql3id
);
474 saveDataToNode(mainview
, (mainview
->cansel_node
));
475 mainview
->cansel_node
=NULL
;
480 if (mainview
->cansel_node
!=NULL
)
482 if (nd
->sql3id
== (mainview
->cansel_node
)->sql3id
)
484 mainview
->cansel_node
=NULL
;
485 fprintf(stderr
, "[SELLOGIC] doubly selected %d, doing nothing\n", nd
->sql3id
);
490 fprintf(stderr
, "[SELLOGIC] saving %d to load new node\n", (mainview
->cansel_node
)->sql3id
);
491 saveDataToNode(mainview
, (mainview
->cansel_node
));
492 mainview
->cansel_node
=NULL
;
497 if (nd
== NULL
) return;
499 setBusy(mainview
, 1);
501 gboolean goterr
= TRUE
;
502 char *textdata
= NULL
;
504 int blobsize
= 0, textsize
= 0;
508 snprintf(tq
, sizeof(tq
), "SELECT bodytype, body, bodyblob, flags FROM %s WHERE nodeid=%d", datatable_tmpname
, nd
->sql3id
);
509 sqlite3_stmt
*stmt
= NULL
;
511 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
515 fprintf(stderr
, "Error reading (1) %s\n", sqlite3_errmsg(mainview
->db
));
520 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
522 rc
= sqlite3_step(stmt
);
523 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
525 else if (rc
== SQLITE_ROW
)
527 nd
->typ
= sqlite3_column_int(stmt
, 0);
528 nd
->flags
= sqlite3_column_int(stmt
, 3);
530 prepareUIforNodeChange(mainview
, nd
->typ
);
531 if (nd
->typ
== NODE_TEXT
)
533 gboolean file_edited_backup
= mainview
->file_edited
;
535 blobsize
= sqlite3_column_bytes(stmt
, 2);
536 blob
= (char *)sqlite3_column_blob(stmt
, 2);
538 textdata
= (char *)sqlite3_column_text(stmt
, 1);
539 textsize
= sqlite3_column_bytes(stmt
, 1);
541 /* gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mainview->buffer), "", -1);*/
542 wp_text_buffer_reset_buffer(mainview
->buffer
, TRUE
);
544 gboolean richtext
=FALSE
;
549 gboolean oldway
=FALSE
;
553 strncpy(tst
, blob
, 8);
555 if (strcmp(tst
, "RICHTEXT")==0) oldway
=TRUE
;
561 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(mainview
->buffer
), &iter
);
562 gtk_text_buffer_deserialize_rich_text(GTK_TEXT_BUFFER(mainview
->buffer
), &iter
, blob
, blobsize
, TRUE
, &err
);
565 fprintf(stderr
, "Error loading text memo with richtext parser! %s\n", err
->message
);
577 wp_text_buffer_load_document_begin(mainview
->buffer
, TRUE
);
578 wp_text_buffer_load_document_write(mainview
->buffer
, blob
, blobsize
);
579 wp_text_buffer_load_document_end(mainview
->buffer
);
583 if (richtext
==FALSE
&& !(textdata
== NULL
|| g_utf8_validate(textdata
, textsize
, NULL
) == FALSE
))
585 /* gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mainview->buffer), textdata, textsize);*/
586 wp_text_buffer_load_document_begin(mainview
->buffer
, FALSE
);
587 wp_text_buffer_load_document_write(mainview
->buffer
, textdata
, textsize
);
588 wp_text_buffer_load_document_end(mainview
->buffer
);
591 wp_text_buffer_enable_rich_text(mainview
->buffer
, TRUE
);
592 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->tools_wordwrap
), ((nd
->flags
& NODEFLAG_WORDWRAP
) > 0)?TRUE
:FALSE
);
593 callback_wordwrap(NULL
, mainview
); /*FIXME:ugly (do we need this? gotta test) */
595 gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(mainview
->buffer
), FALSE
); /*we probably don't need this*/
597 callback_undotoggle((gpointer
)mainview
->buffer
, FALSE
, mainview
); /*we need these*/
598 callback_redotoggle((gpointer
)mainview
->buffer
, FALSE
, mainview
);
600 if (file_edited_backup
==FALSE
) mainview
->file_edited
=FALSE
; /*textview changed event toggles this?*/
603 else if (nd
->typ
== NODE_SKETCH
)
605 sketchwidget_wipe_undo(mainview
->sk
);
606 sketchwidget_set_fillmode(mainview
->sk
, FALSE
);
607 sketchwidget_set_shift(mainview
->sk
, FALSE
);
608 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->shapemenuitems
[1]), TRUE
);
609 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->shapemenuitems
[0]), TRUE
);
611 blobsize
= sqlite3_column_bytes(stmt
, 2);
612 blob
= (char *)sqlite3_column_blob(stmt
, 2);
613 gboolean clear
= TRUE
;
619 fprintf(stderr
, "blobsize:%d\n", blobsize
);
620 GdkPixbufLoader
*pl
= gdk_pixbuf_loader_new_with_type("png", NULL
);
623 gdk_pixbuf_loader_write(pl
, (guchar
*) blob
, blobsize
, &err
);
626 fprintf(stderr
, "Error loading sketch! %s\n", err
->message
);
630 gdk_pixbuf_loader_close(pl
, NULL
);
631 GdkPixbuf
*pixbuf
= gdk_pixbuf_loader_get_pixbuf(pl
);
633 if (GDK_IS_PIXBUF(pixbuf
))
635 GtkWidget
*skdr
= sketchwidget_get_drawingarea(mainview
->sk
);
636 GtkPixmap
*skpix
= (GtkPixmap
*) sketchwidget_get_Pixmap(mainview
->sk
);
638 int w
=gdk_pixbuf_get_width(pixbuf
);
639 int h
=gdk_pixbuf_get_height(pixbuf
);
640 if (w
!=skdr
->allocation
.width
|| h
!=skdr
->allocation
.height
)
642 if (w
>skdr
->allocation
.width
) w
=skdr
->allocation
.width
;
643 if (h
>skdr
->allocation
.height
) h
=skdr
->allocation
.height
;
644 sketchwidget_clear_real(mainview
->sk
);
646 gdk_draw_pixbuf(GDK_DRAWABLE(skpix
), NULL
, pixbuf
, 0, 0, 0, 0, w
, h
, GDK_RGB_DITHER_NONE
, 0, 0);
651 if (skpix
&& G_IS_OBJECT(skpix
)) g_object_unref(skpix
);
655 fprintf(stderr
, "error loading pixbuf\n");
661 fprintf(stderr
, "clearing pix area\n");
662 sketchwidget_clear_real(mainview
->sk
);
664 gtk_widget_queue_draw(sketchwidget_get_drawingarea(mainview
->sk
));
666 else if (nd
->typ
== NODE_CHECKLIST
)
668 gtk_object_set_data(GTK_OBJECT(mainview
->listview
), "edited", FALSE
);
669 GtkTreeModel
*model
=gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
671 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->listview
), NULL
);
672 gtk_list_store_clear(GTK_LIST_STORE(model
));
674 snprintf(tq
, sizeof(tq
), "SELECT name, style, color FROM %s WHERE nodeid=%d ORDER BY ord, idx", checklisttable_tmpname
, nd
->sql3id
);
675 sqlite3_stmt
*stmt2
= NULL
;
677 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt2
, &dum
);
680 fprintf(stderr
, "Error reading checklist (1) %s\n", sqlite3_errmsg(mainview
->db
));
686 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
688 rc
= sqlite3_step(stmt2
);
689 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
691 else if (rc
== SQLITE_ROW
)
693 char *textdata
= (char *)sqlite3_column_text(stmt2
, 0);
694 int style
= sqlite3_column_int(stmt2
, 1);
695 unsigned long col
= sqlite3_column_int(stmt2
, 2);
697 GtkTreeIter toplevel
;
698 gtk_list_store_append(GTK_LIST_STORE(model
), &toplevel
);
699 gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_TEXT
, textdata
, CHECKNODE_CHECKED
, FALSE
, -1);
700 if ((style
& CHECKSTYLE_CHECKED
)>0) gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_CHECKED
, TRUE
, -1);
701 if ((style
& CHECKSTYLE_BOLD
)>0) gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_BOLD
, PANGO_WEIGHT_BOLD
, -1);
702 if ((style
& CHECKSTYLE_STRIKE
)>0) gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_STRIKE
, TRUE
, -1);
707 snprintf(tmp
, sizeof(tmp
), "#%02x%02x%02x", ((col
& 0xFF0000) >> 16), ((col
& 0xFF00) >> 8), (col
& 0xFF));
708 /* fprintf(stderr, "read color for node is *%s*\n", tmp);*/
709 gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_COLOR
, tmp
, -1);
714 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
716 fprintf(stderr
, "Error reading checklist (2) %s\n", sqlite3_errmsg(mainview
->db
));
720 sqlite3_finalize(stmt2
);
723 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->listview
), model
);
724 g_object_unref(model
);
727 if ((nd
->flags
& NODEFLAG_SKETCHLINES
) > 0)
728 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->sketchlinesmenuitems
[1]), TRUE
);
729 else if ((nd
->flags
& NODEFLAG_SKETCHGRAPH
) > 0)
730 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->sketchlinesmenuitems
[2]), TRUE
);
733 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->sketchlinesmenuitems
[0]), TRUE
);
734 callback_sketchlines(NULL
, mainview
->sketchlinesmenuitems
[0]); /*FIXME:ugly */
736 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->tools_pressure
), TRUE
);
741 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
742 fprintf(stderr
, "Error reading (2) %s\n", sqlite3_errmsg(mainview
->db
));
744 sqlite3_finalize(stmt
);
747 setBusy(mainview
, 2);
751 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Error loading memo"));
755 gboolean
treeview_canselect(GtkTreeSelection
* selection
, GtkTreeModel
* model
, GtkTreePath
* path
, gboolean path_currently_selected
, gpointer userdata
)
757 MainView
*mainview
= (MainView
*) userdata
;
758 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
760 if (mainview
->loading
==FALSE
)
762 #ifndef EXPANDING_ROWS
763 if (path_currently_selected
)
767 #ifndef NEW_SEL_LOGIC
768 saveCurrentData(mainview
);
770 if (path_currently_selected
)
773 gtk_tree_model_get_iter(model
, &iter
, path
);
775 gtk_tree_model_get(model
, &iter
, NODE_DATA
, &(mainview
->cansel_node
), -1);
776 mainview
->cansel_time
=time(NULL
);
777 /* fprintf(stderr, "[SELLOGIC] canselect called for node %d\n", nd->sql3id);*/
784 gboolean
newnodedlg_key_press_cb(GtkWidget
* widget
, GdkEventKey
* event
, GtkWidget
* dlg
)
786 SketchWidget
*s
= gtk_object_get_data(GTK_OBJECT(dlg
), "sk");
788 switch (event
->keyval
)
791 sketchwidget_redo(s
);
794 sketchwidget_undo(s
);
801 void new_node_dialog(nodeType typ
, MainView
* mainview
)
803 GtkWidget
*dialog
, *label
, *entry
, *but_ok
, *but_cancel
, *vbox
, *hbox
, *al
, *cb
, *rb1
, *rb2
, *rb3
;
805 dialog
= gtk_dialog_new();
807 g_signal_connect(G_OBJECT(dialog
), "key_press_event", G_CALLBACK(newnodedlg_key_press_cb
), dialog
);
809 GtkWidget
*notebook
= gtk_notebook_new();
811 vbox
= gtk_vbox_new(FALSE
, 0);
812 gtk_container_border_width(GTK_CONTAINER(vbox
), 15);
814 hbox
= gtk_hbox_new(FALSE
, 0);
816 rb1
=gtk_radio_button_new_with_label(NULL
, _("Text memo"));
817 gtk_box_pack_start(GTK_BOX(hbox
), rb1
, FALSE
, FALSE
, 0);
818 gtk_object_set_data(GTK_OBJECT(dialog
), "rbt", rb1
); /*FIXME: not pretty*/
820 rb2
=gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(rb1
)), _("Sketch memo"));
821 gtk_box_pack_start(GTK_BOX(hbox
), rb2
, FALSE
, FALSE
, 0);
822 gtk_object_set_data(GTK_OBJECT(dialog
), "rbs", rb2
); /*FIXME: not pretty*/
824 rb3
=gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(rb1
)), _("Checklist"));
825 gtk_box_pack_start(GTK_BOX(hbox
), rb3
, FALSE
, FALSE
, 0);
826 gtk_object_set_data(GTK_OBJECT(dialog
), "rbc", rb3
); /*FIXME: not pretty*/
828 if (typ
==NODE_TEXT
) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb1
), TRUE
);
829 else if (typ
==NODE_SKETCH
) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb2
), TRUE
);
830 else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb3
), TRUE
);
832 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), hbox
);
834 label
= gtk_label_new(_("Text name"));
835 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), vbox
, label
);
836 label
= gtk_label_new(_("Please name the memo:"));
837 entry
= gtk_entry_new_with_max_length(64);
838 gtk_entry_set_text(GTK_ENTRY(entry
), _("New memo"));
839 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
841 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
842 gtk_box_pack_start(GTK_BOX(vbox
), entry
, FALSE
, FALSE
, 0);
844 vbox
= gtk_vbox_new(FALSE
, 0);
845 gtk_container_border_width(GTK_CONTAINER(vbox
), 15);
846 label
= gtk_label_new(_("Sketch name"));
847 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), vbox
, label
);
849 label
= gtk_label_new(_("Please name the memo:"));
851 al
= gtk_alignment_new(0.5, 0.5, 0, 0);
853 SketchWidget
*s
= sketchwidget_new(SKETCHNODE_X
, SKETCHNODE_Y
, TRUE
);
855 sketchwidget_set_brushsize(s
, 2);
856 sketchwidget_set_backstyle(s
, SKETCHBACK_GRAPH
);
858 gtk_widget_set_size_request(sketchwidget_get_mainwidget(s
), SKETCHNODE_X
, SKETCHNODE_Y
);
859 gtk_container_add(GTK_CONTAINER(al
), sketchwidget_get_mainwidget(s
));
861 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
862 gtk_box_pack_start(GTK_BOX(vbox
), al
, FALSE
, FALSE
, 0);
864 but_ok
= gtk_button_new_with_label(_("Create"));
865 but_cancel
= gtk_button_new_with_label(_("Cancel"));
866 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), but_ok
);
867 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), but_cancel
);
869 gtk_object_set_user_data(GTK_OBJECT(dialog
), entry
);
870 gtk_object_set_data(GTK_OBJECT(dialog
), "m", mainview
);
871 gtk_object_set_data(GTK_OBJECT(dialog
), "sk", s
);
872 gtk_object_set_data(GTK_OBJECT(dialog
), "n", notebook
);
874 nodeType
*tmp
= g_malloc(sizeof(nodeType
)); /*FIXME memleak:not freed on widget_destroy */
876 gtk_object_set_data(GTK_OBJECT(dialog
), "t", tmp
);
878 gtk_signal_connect_object(GTK_OBJECT(but_cancel
), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy
), dialog
);
879 g_signal_connect(G_OBJECT(but_ok
), "clicked", G_CALLBACK(callback_new_node_real
), dialog
);
881 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), notebook
);
883 cb
= gtk_check_button_new_with_label(_("Create as childnode"));
884 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb
), mainview
->newnodedialog_createchild
);
885 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), cb
);
886 gtk_object_set_data(GTK_OBJECT(dialog
), "cb", cb
);
888 gtk_widget_grab_focus(entry
);
890 gtk_widget_show_all(dialog
);
891 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
894 void add_new_node(nodeData
* node
, MainView
* mainview
, gboolean ischild
)
896 GtkTreeIter parentiter
, newiter
;
900 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
902 if (gtk_tree_selection_get_selected(selection
, &model
, &parentiter
))
905 GtkTreePath
*path
= NULL
;
907 unsigned int parentnodeid
= 0;
911 path
= gtk_tree_model_get_path(model
, &parentiter
);
913 if (ischild
== FALSE
)
915 gtk_tree_path_up(path
);
917 if (gtk_tree_path_get_depth(path
) == 0)
919 /* Selected node is a root node */
920 ptr
= NULL
; /* New node can not have a Parent node */
921 gtk_tree_path_down(path
); /*restore path so expand() works */
923 else if (gtk_tree_path_get_depth(path
) > 0)
925 /* Selected node is a child node */
926 if (gtk_tree_model_get_iter(model
, &parentiter
, path
))
936 gtk_tree_model_get(model
, ptr
, NODE_DATA
, &nd
, -1);
938 parentnodeid
= nd
->sql3id
;
944 sqlite3_stmt
*stmt
= NULL
;
951 snprintf(tq
, sizeof(tq
), "INSERT INTO %s (parent, bodytype, name, nameblob, ord) VALUES (%d, %d, ?, ?, 0);", datatable_tmpname
, parentnodeid
, node
->typ
);
952 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
956 fprintf(stderr
, "Error inserting(1): %s\n", sqlite3_errmsg(mainview
->db
));
959 if (node
->name
!= NULL
)
960 sqlite3_bind_text(stmt
, 1, node
->name
, strlen(node
->name
), SQLITE_TRANSIENT
);
962 sqlite3_bind_text(stmt
, 1, NULL
, 0, SQLITE_TRANSIENT
);
964 if (node
->namepix
!= NULL
)
966 gchar
*namepixdata
= NULL
;
971 if (gdk_pixbuf_save_to_buffer(node
->namepix
, &namepixdata
, &datalen
, "png", &err
, NULL
) == FALSE
)
975 fprintf(stderr
, "Error saving name! %s\n", err
->message
);
978 sqlite3_bind_blob(stmt
, 2, namepixdata
, datalen
, SQLITE_TRANSIENT
);
981 sqlite3_bind_blob(stmt
, 2, NULL
, 0, SQLITE_TRANSIENT
);
984 while(rc
== SQLITE_BUSY
)
986 rc
= sqlite3_step(stmt
);
987 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
990 sqlite3_finalize(stmt
);
991 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
993 fprintf(stderr
, "Error inserting(2): %s\n", sqlite3_errmsg(mainview
->db
));
996 node
->sql3id
= sqlite3_last_insert_rowid(mainview
->db
);
1000 if (node
->sql3id
== 0)
1005 g_object_unref(node
->namepix
);
1008 gtk_tree_path_free(path
);
1009 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, "Error creating node");
1013 gtk_tree_store_append(GTK_TREE_STORE(model
), &newiter
, ptr
);
1015 gtk_tree_store_set(GTK_TREE_STORE(model
), &newiter
, NODE_NAME
, node
->name
, NODE_PIXBUF
, node
->namepix
, NODE_DATA
, node
, -1);
1019 mainview
->loading
=TRUE
; /*only when we have a valid parent*/
1020 gtk_tree_view_expand_row(GTK_TREE_VIEW(mainview
->treeview
), path
, FALSE
);
1021 gtk_tree_path_free(path
);
1024 gtk_tree_selection_select_iter(selection
, &newiter
);
1026 mainview
->loading
=FALSE
;
1029 void callback_new_node_real(GtkAction
* action
, gpointer data
)
1033 GtkWidget
*dialog
= data
;
1034 GtkWidget
*entry
= gtk_object_get_user_data(GTK_OBJECT(dialog
));
1036 mainview
= gtk_object_get_data(GTK_OBJECT(dialog
), "m");
1037 SketchWidget
*s
= gtk_object_get_data(GTK_OBJECT(dialog
), "sk");
1038 GtkWidget
*notebook
= gtk_object_get_data(GTK_OBJECT(dialog
), "n");
1039 GtkWidget
*cb
= gtk_object_get_data(GTK_OBJECT(dialog
), "cb");
1040 /* nodeType *typ = gtk_object_get_data(GTK_OBJECT(dialog), "t");*/
1042 nodeType typ
= NODE_TEXT
;
1044 /* GtkWidget *rbt = gtk_object_get_data(GTK_OBJECT(dialog), "rbt");*/
1045 GtkWidget
*rbs
= gtk_object_get_data(GTK_OBJECT(dialog
), "rbs");
1046 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rbs
))) typ
=NODE_SKETCH
;
1048 GtkWidget
*rbc
= gtk_object_get_data(GTK_OBJECT(dialog
), "rbc");
1049 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rbc
))) typ
=NODE_CHECKLIST
;
1051 gint t
= gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook
));
1054 GdkPixbuf
*pixbuf
= NULL
;
1058 txt
= g_strdup(gtk_entry_get_text(GTK_ENTRY(entry
)));
1059 if (strcmp(txt
, "") == 0)
1067 GtkWidget
*sdr
= sketchwidget_get_drawingarea(s
);
1069 GdkPixmap
*spix
= sketchwidget_get_Pixmap(s
);
1071 pixbuf
= gdk_pixbuf_get_from_drawable(NULL
, GDK_DRAWABLE(spix
), NULL
, 0, 0, 0, 0, sdr
->allocation
.width
, sdr
->allocation
.height
);
1072 g_object_unref(spix
);
1074 GdkPixbuf
*pixbuf2
= sketchwidget_trim_image(pixbuf
, SKETCHNODE_X
, SKETCHNODE_Y
, &w
,
1076 if (pixbuf2
==NULL
) return;
1078 GdkPixbuf
*pixbuf3
= gdk_pixbuf_new(GDK_COLORSPACE_RGB
, FALSE
, 8, SKETCHNODE_RX
,
1081 gdk_pixbuf_fill(pixbuf3
, 0xffffffff);
1083 if (w
<= SKETCHNODE_RX
&& h
<= SKETCHNODE_RY
)
1085 gdk_pixbuf_copy_area(pixbuf2
, 0, 0, w
, h
, pixbuf3
, 0, (SKETCHNODE_RY
- h
) / 2);
1093 neww
= SKETCHNODE_RX
;
1094 newh
= (h
/ w
) * SKETCHNODE_RX
;
1098 newh
= SKETCHNODE_RY
;
1099 neww
= (w
/ h
) * SKETCHNODE_RY
;
1101 if (newh
> SKETCHNODE_RY
)
1102 newh
= SKETCHNODE_RY
; /*FIXME: newh exceeds SKETCHNODE_RY sometimes */
1104 GdkPixbuf
*tmpbuf
= gdk_pixbuf_scale_simple(pixbuf2
, neww
, newh
,
1105 GDK_INTERP_BILINEAR
);
1107 gdk_pixbuf_copy_area(tmpbuf
, 0, 0, neww
, newh
, pixbuf3
, 0, (SKETCHNODE_RY
- newh
) / 2);
1109 gdk_pixbuf_unref(tmpbuf
);
1113 gdk_pixbuf_unref(pixbuf2
);
1118 node
= g_malloc(sizeof(nodeData
));
1120 /* node->typ = *typ;
1123 node
->namepix
= NULL
;
1131 node
->namepix
= pixbuf
;
1138 mainview
->newnodedialog_createchild
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cb
));
1139 add_new_node(node
, mainview
, mainview
->newnodedialog_createchild
);
1141 sketchwidget_destroy(s
);
1142 gtk_widget_destroy(dialog
);
1143 mainview
->file_edited
= TRUE
;
1149 void callback_file_delete_node(GtkAction
* action
, gpointer data
)
1151 MainView
*mainview
= (MainView
*) data
;
1152 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1154 if (getSelectedNode(mainview
) == NULL
)
1156 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Select a node first"));
1160 GtkWidget
*dialog
, *label
, *but_ok
, *but_cancel
;
1162 dialog
= gtk_dialog_new();
1164 label
= gtk_label_new(_("Delete current memo?"));
1166 but_ok
= gtk_button_new_with_label(_("Yes, Delete"));
1167 but_cancel
= gtk_button_new_with_label(_("Cancel"));
1169 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), but_ok
);
1170 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), but_cancel
);
1172 gtk_object_set_user_data(GTK_OBJECT(dialog
), mainview
);
1174 gtk_signal_connect_object(GTK_OBJECT(but_cancel
), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy
), dialog
);
1175 g_signal_connect(G_OBJECT(but_ok
), "clicked", G_CALLBACK(callback_delete_node_real
), dialog
);
1177 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), label
);
1179 gtk_widget_show_all(dialog
);
1180 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
1184 * Callback for Rename Menuitem
1186 void callback_file_rename_node(GtkAction
* action
, gpointer data
)
1188 MainView
*mainview
= (MainView
*) data
;
1189 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1191 /* Get the selected node */
1192 nodeData
*sel_node
= getSelectedNode(mainview
);
1195 /* Do nothing, if no node has been selected */
1196 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Select a node first"));
1200 if (sel_node
->namepix
!= NULL
)
1202 /* the memo has a graphical label, cannot edit! */
1203 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Cannot rename memos with sketch name"));
1207 /* Create dialog box */
1208 GtkWidget
*dialog
, *label
, *entry
, *but_ok
, *but_cancel
;
1210 dialog
= gtk_dialog_new();
1212 label
= gtk_label_new(_("New Memo name:"));
1214 entry
= gtk_entry_new_with_max_length(64);
1215 gtk_entry_set_text (GTK_ENTRY(entry
), sel_node
->name
);
1216 gtk_editable_select_region (GTK_EDITABLE(entry
), 0, -1);
1218 but_ok
= gtk_button_new_with_label(_("OK"));
1219 but_cancel
= gtk_button_new_with_label(_("Cancel"));
1221 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), but_ok
);
1222 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), but_cancel
);
1224 g_object_set_data(G_OBJECT(dialog
), "m", mainview
);
1225 g_object_set_data(G_OBJECT(dialog
), "e", entry
);
1227 gtk_signal_connect_object(GTK_OBJECT(but_cancel
), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy
), dialog
);
1228 g_signal_connect(G_OBJECT(but_ok
), "clicked", G_CALLBACK(callback_rename_node_real
), dialog
);
1230 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), label
);
1231 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), entry
);
1233 gtk_box_set_spacing (GTK_DIALOG(dialog
)->vbox
, 10);
1235 gtk_widget_show_all(dialog
);
1236 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
1240 * Callback for Rename Dialog
1242 void callback_rename_node_real (GtkAction
*action
, gpointer data
)
1247 GtkTreeModel
*model
;
1248 nodeData
*nd
= NULL
;
1250 GtkWidget
*dialog
= data
;
1252 mainview
= g_object_get_data (G_OBJECT(dialog
), "m");
1253 entry
= g_object_get_data (G_OBJECT(dialog
), "e");
1255 /* Checking whether the entry is empty */
1256 gchar
*new_node_name
= gtk_entry_get_text (GTK_ENTRY(entry
));
1257 if (strcmp (new_node_name
, "") == 0) {
1258 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Name can not be empty"));
1262 /* Get the selected node */
1263 GtkTreeSelection
*selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW(mainview
->treeview
));
1265 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
))
1268 gtk_tree_model_get (model
, &iter
, NODE_DATA
, &nd
, -1);
1272 /* If we reach here, all checkings are done */
1273 /* Update the database */
1275 unsigned int sql3id
= nd
->sql3id
;
1276 sqlite3_stmt
*stmt
= NULL
;
1278 gboolean db_query_result
= FALSE
;
1280 /* Update the noteData */
1284 nd
->name
= g_strdup(new_node_name
);
1287 snprintf (tq
, sizeof(tq
), "UPDATE %s SET name=\"%s\" WHERE nodeid=%d",
1288 datatable_tmpname
, new_node_name
, sql3id
);
1289 int rc
= sqlite3_prepare (mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
1292 fprintf (stderr
, "Error preparing db update query: %s\n", sqlite3_errmsg(mainview
->db
));
1296 while (rc
== SQLITE_BUSY
) {
1297 rc
= sqlite3_step (stmt
);
1298 if (rc
== SQLITE_DONE
) {
1299 db_query_result
= TRUE
;
1302 else if(rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
) {
1303 fprintf (stderr
, "Error updating node: %s\n", sqlite3_errmsg(mainview
->db
));
1306 sqlite3_finalize(stmt
);
1310 /* Update the tree */
1311 if (db_query_result
)
1312 gtk_tree_store_set (GTK_TREE_STORE(model
), &iter
, NODE_NAME
, new_node_name
, -1);
1314 mainview
->file_edited
= TRUE
;
1316 /* Destroy the dialog */
1317 gtk_widget_destroy (dialog
);
1320 void callback_file_expand_collapse_node(GtkAction
* action
, gpointer data
)
1322 MainView
*mainview
= (MainView
*) data
;
1323 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1326 GtkTreeModel
*model
;
1328 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1330 if (!gtk_tree_selection_get_selected(selection
, &model
, &iter
))
1332 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Select a node first"));
1336 GtkTreePath
*path
= gtk_tree_model_get_path(model
, &iter
);
1337 if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(mainview
->treeview
), path
)==FALSE
)
1339 gtk_tree_view_expand_row(GTK_TREE_VIEW(mainview
->treeview
), path
, FALSE
);
1343 gtk_tree_view_collapse_row(GTK_TREE_VIEW(mainview
->treeview
), path
);
1346 gtk_tree_path_free(path
);
1349 void callback_file_export_node(GtkAction
* action
, gpointer data
)
1351 MainView
*mainview
= (MainView
*) data
;
1352 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1354 nodeData
*nd
=getSelectedNode(mainview
);
1357 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Select a memo first"));
1361 gchar
*nodename
=nd
->name
;
1362 if (nodename
==NULL
) nodename
=_("saved memo");
1364 if (nd
->typ
== NODE_TEXT
)
1367 GtkTextIter begin, end;
1368 gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER(mainview->buffer), &begin, &end);
1369 gchar *text = gtk_text_buffer_get_slice(GTK_TEXT_BUFFER(mainview->buffer), &begin, &end, TRUE);
1371 GString
*gstr
=g_string_sized_new(4096);
1372 wp_text_buffer_save_document(mainview
->buffer
, (WPDocumentSaveCallback
)(wp_savecallback
), gstr
);
1373 gint textlen
=gstr
->len
;
1374 gchar
*text
=g_string_free(gstr
, FALSE
);
1376 if (text
==NULL
|| !strcmp(text
, ""))
1378 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Memo is empty"));
1382 gchar
*fn
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, nodename
, "html");
1385 GnomeVFSResult vfs_result
;
1386 GnomeVFSHandle
*handle
= NULL
;
1387 GnomeVFSFileSize out_bytes
;
1388 vfs_result
= gnome_vfs_create(&handle
, fn
, GNOME_VFS_OPEN_WRITE
, 0, 0600);
1389 if ( vfs_result
!= GNOME_VFS_OK
) {
1390 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Export failed"));
1394 gnome_vfs_write(handle
, text
, textlen
, &out_bytes
);
1395 gnome_vfs_close(handle
);
1396 if (out_bytes
==strlen(text
)) hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Exported"));
1397 else hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Export incomplete"));
1404 else if (nd
->typ
== NODE_SKETCH
)
1406 GdkPixmap
*skpix
= sketchwidget_get_Pixmap(mainview
->sk
);
1407 GtkWidget
*skdr
= sketchwidget_get_drawingarea(mainview
->sk
);
1408 GdkPixbuf
*pixbuf
= gdk_pixbuf_get_from_drawable(NULL
, GDK_DRAWABLE(skpix
), NULL
, 0, 0, 0, 0, skdr
->allocation
.width
, skdr
->allocation
.height
);
1411 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Memo is empty"));
1415 gchar
*fn
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, nodename
, "png");
1418 if (gdk_pixbuf_save(pixbuf
, fn
, "png", NULL
, NULL
)==FALSE
)
1420 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Export failed"));
1424 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Exported"));
1429 g_object_unref(skpix
);
1431 else if (nd
->typ
== NODE_CHECKLIST
)
1433 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Unimplemented"));
1438 * callback from menu item
1439 * move selected node down (switch node with next sibling), don't change level of node
1441 void callback_move_down_node(GtkAction
* action
, gpointer data
)
1444 GtkTreeModel
*model
;
1446 MainView
*mainview
= (MainView
*) data
;
1447 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1449 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1450 gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1452 GtkTreeIter old_iter
= iter
;/*save pointer to old iter, we will need it during swap nodes*/
1454 if (gtk_tree_model_iter_next(model
,&iter
)==FALSE
)/*get next node*/
1457 GtkTreeStore
*treeStore
= GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
)));
1458 gtk_tree_store_swap(treeStore
,&iter
,&old_iter
);
1460 mainview
->file_edited
= TRUE
;/*we have made changes , if required show "save changes?" dialog in future*/
1464 * callback from menu item
1465 * move selected node down (switch node with prev sibling), don't change level of node
1467 void callback_move_up_node(GtkAction
* action
, gpointer data
)
1470 GtkTreeModel
*model
;
1472 MainView
*mainview
= (MainView
*) data
;
1473 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1475 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1476 gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1478 GtkTreeIter old_iter
=iter
;/*save pointer to old iter, we will need it during swap nodes*/
1480 if (tree_model_iter_prev(model
,&iter
)==FALSE
)/*get previous node*/
1483 GtkTreeStore
*treeStore
= GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
)));
1484 gtk_tree_store_swap(treeStore
,&old_iter
,&iter
);/*do move*/
1486 mainview
->file_edited
= TRUE
;/*we have made changes , if required show "save changes?" dialog in future*/
1490 * callback from menu item
1491 * we change level of actual node with direction to top
1493 void callback_move_to_top_level_node(GtkAction
* action
, gpointer data
)
1495 GtkTreeIter iter
,new_parent
;
1496 GtkTreeIter
*p_new_parent
;
1498 GtkTreeModel
*model
;
1500 MainView
*mainview
= (MainView
*) data
;
1501 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1503 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1504 gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1506 /*at first we need actual parent of selected node*/
1507 if (gtk_tree_model_iter_parent(model
,&parent
,&iter
)==FALSE
)
1509 /*if parent of selected node is ROOT we can't go higher*/
1512 /*we need also new parent, it's parent of actual parent*/
1513 if (gtk_tree_model_iter_parent(model
,&new_parent
,&parent
)==FALSE
)
1515 /*if our new parent is ROOT we got filled new_parent with invalid value,
1516 so we need set NULL value to p_new_parent (root item)*/
1521 p_new_parent
=&new_parent
;/*we only redirect pointer to treeiter*/
1524 saveCurrentData(mainview
);/*we save changes in node befor move*/
1526 /*this move function provide move item with all his children, be careful iter value will change!*/
1527 if (move_node(mainview
,p_new_parent
,&iter
,&parent
)==TRUE
){
1529 gint id_parent
= get_node_id_on_tmp_db(model
,p_new_parent
);
1530 gint id_node
= get_node_id_on_tmp_db(model
,&iter
);
1531 /*we need also update parent id of moved item*/
1533 snprintf (tq
, sizeof(tq
), "UPDATE %s SET parent=%d WHERE nodeid=%d",datatable_tmpname
,id_parent
,id_node
);
1534 exec_command_on_db(mainview
,tq
);
1536 /*select new created iter*/
1537 gtk_tree_selection_select_iter(selection
,&iter
);
1539 mainview
->file_edited
= TRUE
;/*we have made changes , if required show "save changes?" dialog in future*/
1544 * callback from menu item
1545 * we change level of actual node with direction to bottom
1546 * previous node will be parent of our actual node
1548 void callback_move_to_bottom_level_node(GtkAction
* action
, gpointer data
)
1551 GtkTreeModel
*model
;
1553 MainView
*mainview
= (MainView
*) data
;
1554 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1556 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1557 gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1559 GtkTreeIter move_iter
=iter
;/*save pointer to old iter*/
1561 /*we try to get previous node*/
1562 if (tree_model_iter_prev(model
,&iter
)==FALSE
)
1563 return;/*if previous node on the same level doesn't exist we will exit*/
1565 saveCurrentData(mainview
);/*we save changes in node befor move*/
1567 /*this move function provide move item with all his children, be careful move_iter value will change!*/
1568 if (move_node(mainview
,&iter
,&move_iter
,NULL
)==TRUE
)
1570 gint id_parent
= get_node_id_on_tmp_db(model
,&iter
);
1571 gint id_node
= get_node_id_on_tmp_db(model
,&move_iter
);
1573 /*we need also update parent id of moved item*/
1575 snprintf (tq
, sizeof(tq
), "UPDATE %s SET parent=%d WHERE nodeid=%d",datatable_tmpname
,id_parent
,id_node
);
1576 exec_command_on_db(mainview
,tq
);
1578 GtkTreePath
*path
= gtk_tree_model_get_path(model
, &iter
);
1579 gtk_tree_view_expand_row(GTK_TREE_VIEW(mainview
->treeview
), path
, FALSE
);/*expand parent node*/
1580 gtk_tree_path_free(path
);
1582 /*select new created iter*/
1583 gtk_tree_selection_select_iter(selection
,&move_iter
);
1585 mainview
->file_edited
= TRUE
;/*we have made changes , if required show "save changes?" dialog in future*/
1590 * move item_to_move to new_parent with his children, this function is designed for change level of node
1591 * we copy item_to_move with his children to new position (after item_befor if is not NULL) and then we
1592 * destroy old node with his children, so ! item_to_move is set with new iter, be careful on this!
1594 gboolean
move_node(MainView
*mainview
,GtkTreeIter
*new_parent
,GtkTreeIter
*item_to_move
,GtkTreeIter
*item_befor
)
1596 GtkTreeModel
*model
;
1598 model
=gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
));
1599 GtkTreeStore
*treeStore
= GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
)));
1602 gtk_tree_model_get(model
, item_to_move
, NODE_DATA
, &node
, -1);/*get data from actual iter*/
1605 GtkTreeIter new_iter
;/*create new iter*/
1606 gtk_tree_store_append(treeStore
,&new_iter
,new_parent
);/*append new iter to new parent*/
1608 if (item_befor
!=NULL
)
1609 gtk_tree_store_move_after(treeStore
,&new_iter
,item_befor
);/*sometimes we need set position*/
1611 gtk_tree_store_set(treeStore
, &new_iter
, NODE_NAME
, node
->name
,NODE_PIXBUF
, node
->namepix
, NODE_DATA
, node
, -1);/*set data from old iter*/
1614 while (gtk_tree_model_iter_children(model
, &child
, item_to_move
)==TRUE
)/*move all childrens while some exits*/
1616 if (move_node(mainview
,&new_iter
,&child
,NULL
)==FALSE
)/*use recursion on children*/
1620 gtk_tree_store_set(treeStore
, item_to_move
, NODE_DATA
, NULL
, -1);
1621 gtk_tree_store_remove(treeStore
, item_to_move
);/*remove node, data need't remove, they are stored in new node*/
1623 /*we need return new value of moved item, so we need assign new_iter to item_to_move*/
1624 /*this code is ugly : new_iter to path and back to item_to_move*/
1625 GtkTreePath
*path
=gtk_tree_model_get_path(model
,&new_iter
);
1626 gtk_tree_model_get_iter(model
,item_to_move
,path
);
1627 gtk_tree_path_free(path
);
1631 fprintf(stderr
,"Get data node failed!\n");
1639 * simple execute of sql command which is stored in sql_string[]
1641 gboolean
exec_command_on_db(MainView
*mainview
,char sql_string
[])
1643 sqlite3_stmt
*stmt
= NULL
;
1645 gboolean db_query_result
= FALSE
;
1647 int rc
= sqlite3_prepare (mainview
->db
, sql_string
, strlen(sql_string
), &stmt
, &dum
);
1650 fprintf (stderr
, "Error preparing db update query: %s\n", sqlite3_errmsg(mainview
->db
));
1655 while (rc
== SQLITE_BUSY
) {
1656 rc
= sqlite3_step (stmt
);
1657 if (rc
== SQLITE_DONE
) {
1658 db_query_result
= TRUE
;
1661 else if(rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
) {
1662 fprintf (stderr
, "Error updating node: %s\n", sqlite3_errmsg(mainview
->db
));
1665 sqlite3_finalize(stmt
);
1671 * it is used in gtk_tree_model_foreach function to update ord value for all nodes (it's usefull for move up, move down node)
1673 gboolean
foreach_func_update_ord (GtkTreeModel
*model
,GtkTreePath
*path
,GtkTreeIter
*iter
, MainView
*mainview
)
1676 gtk_tree_model_get(model
, iter
, NODE_DATA
, &node
, -1);
1677 /*we need index of node on actual level*/
1678 gint index
=get_branch_node_index(path
);
1680 /*prepare to execute update command,and exec it*/
1681 char sql_command
[512];
1682 snprintf (sql_command
, sizeof(sql_command
), "UPDATE %s SET ord=\"%d\" WHERE nodeid=%d",datatable_tmpname
, index
, node
->sql3id
);
1683 exec_command_on_db(mainview
,sql_command
);
1685 /*we don't want break gtk_tree_model_foreach function,until we call this func on each node - so we return always FALSE*/
1690 * return id number of iter (id number which is used to identify in sql database of nodes)
1692 int get_node_id_on_tmp_db(GtkTreeModel
*model
,GtkTreeIter
*iter
)
1695 return 0;/*we got ROOT parent here*/
1698 gtk_tree_model_get(model
, iter
, NODE_DATA
, &node
, -1);
1699 return node
->sql3id
;
1703 * get index of node in current branch
1705 gint
get_branch_node_index(GtkTreePath
*path
)
1707 int depth
=gtk_tree_path_get_depth(path
);
1708 gint
*indicies
= gtk_tree_path_get_indices(path
);
1710 return indicies
[depth
-1];
1714 * similiar with gtk_tree_model_iter_next (), but opposite
1716 gboolean
tree_model_iter_prev(GtkTreeModel
*tree_model
,GtkTreeIter
*iter
)
1718 GtkTreePath
*path
= gtk_tree_model_get_path(tree_model
, iter
);
1721 fprintf(stderr
,"Error: path is null\n");
1725 if (gtk_tree_path_prev(path
)==FALSE
)
1728 gtk_tree_model_get_iter(tree_model
, iter
,path
);
1733 gboolean
ref2iter(GtkTreeModel
* model
, GtkTreeRowReference
* ref
, GtkTreeIter
* iter
)
1735 gboolean res
= FALSE
;
1736 GtkTreePath
*path
= gtk_tree_row_reference_get_path(ref
);
1738 if (gtk_tree_model_get_iter(model
, iter
, path
))
1742 gtk_tree_path_free(path
);
1746 GtkTreeRowReference
*iter2ref(GtkTreeModel
* model
, GtkTreeIter
* iter
)
1748 GtkTreeRowReference
*ref
;
1750 GtkTreePath
*path
= gtk_tree_model_get_path(model
, iter
);
1752 ref
= gtk_tree_row_reference_new(model
, path
);
1753 gtk_tree_path_free(path
);
1757 void move_nodes_up(GtkTreeModel
* model
, GtkTreeRowReference
* topnode
, GtkTreeRowReference
* newtop
)
1759 GtkTreeIter topiter
;
1761 fprintf(stderr
, "here2\n");
1763 if (ref2iter(model
, topnode
, &topiter
) == FALSE
)
1766 fprintf(stderr
, "here3\n");
1770 if (gtk_tree_model_iter_children(model
, &child
, &topiter
))
1772 fprintf(stderr
, "here4\n");
1773 GtkTreeRowReference
*ref
;
1774 GList
*rr_list
= NULL
, *node
;
1778 ref
= iter2ref(model
, &child
);
1779 rr_list
= g_list_append(rr_list
, ref
);
1781 while(gtk_tree_model_iter_next(model
, &child
));
1784 * got a reflist for all children
1787 fprintf(stderr
, "here5\n");
1788 for(node
= rr_list
; node
; node
= node
->next
)
1790 ref
= (GtkTreeRowReference
*) (node
->data
);
1791 if (ref2iter(model
, ref
, &child
))
1793 GtkTreeIter newtopiter
, newiter
;
1794 GtkTreeIter
*newtopiterptr
;
1796 if (ref2iter(model
, newtop
, &newtopiter
))
1797 newtopiterptr
= &newtopiter
;
1799 newtopiterptr
= NULL
;
1803 gtk_tree_model_get(model
, &child
, NODE_DATA
, &node
, -1);
1805 gtk_tree_store_append(GTK_TREE_STORE(model
), &newiter
, newtopiterptr
);
1806 gtk_tree_store_set(GTK_TREE_STORE(model
), &newiter
, NODE_NAME
, node
->name
, NODE_PIXBUF
, node
->namepix
, NODE_DATA
, node
, -1);
1808 GtkTreeRowReference
*newref
= iter2ref(model
, &newiter
);
1810 move_nodes_up(model
, ref
, newref
);
1811 gtk_tree_row_reference_free(newref
);
1813 gtk_tree_store_remove(GTK_TREE_STORE(model
), &child
);
1815 gtk_tree_row_reference_free(ref
);
1817 fprintf(stderr
, "here6\n");
1819 g_list_free(rr_list
);
1822 fprintf(stderr
, "here7\n");
1826 void callback_delete_node_real(GtkAction
* action
, gpointer data
)
1830 GtkWidget
*dialog
= data
;
1832 mainview
= gtk_object_get_user_data(GTK_OBJECT(dialog
));
1835 GtkTreeModel
*model
;
1837 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1839 if (!gtk_tree_selection_get_selected(selection
, &model
, &iter
))
1844 gtk_tree_model_get(model
, &iter
, NODE_DATA
, &nd
, -1);
1848 mainview
->file_edited
= TRUE
;
1850 unsigned int sql3id
= nd
->sql3id
;
1857 * if (nd->pix) g_object_unref(nd->pix);
1861 fprintf(stderr
, "here1\n");
1862 GtkTreeRowReference
*upref
= NULL
, *ref
= NULL
;
1864 GtkTreePath
*path
= gtk_tree_model_get_path(model
, &iter
);
1866 ref
= gtk_tree_row_reference_new(model
, path
);
1867 if (gtk_tree_path_up(path
))
1868 upref
= gtk_tree_row_reference_new(model
, path
);
1869 gtk_tree_path_free(path
);
1871 g_object_ref(model
);
1872 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), NULL
);
1874 fprintf(stderr
, "here! 1\n");
1875 move_nodes_up(model
, ref
, upref
);
1877 fprintf(stderr
, "here! 2\n");
1878 if (ref2iter(model
, ref
, &iter
))
1882 snprintf(tq
, sizeof(tq
), "SELECT parent FROM %s WHERE nodeid=%d", datatable_tmpname
, sql3id
);
1883 sqlite3_stmt
*stmt
= NULL
;
1885 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
1886 unsigned int sql3parentid
= 0;
1890 fprintf(stderr
, "Error %s\n", sqlite3_errmsg(mainview
->db
));
1895 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
1897 rc
= sqlite3_step(stmt
);
1898 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
1900 else if (rc
== SQLITE_ROW
)
1902 sql3parentid
= sqlite3_column_int(stmt
, 0);
1906 sqlite3_finalize(stmt
);
1908 snprintf(tq
, sizeof(tq
), "UPDATE %s SET parent=%d WHERE parent=%d;", datatable_tmpname
, sql3parentid
, sql3id
);
1909 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
1910 fprintf(stderr
, "ERROR moving nodes up!\n");
1913 snprintf(tq
, sizeof(tq
), "DELETE FROM %s WHERE nodeid=%d;", datatable_tmpname
, sql3id
);
1914 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
1915 fprintf(stderr
, "ERROR deleting node!\n");
1917 /* Delete all checklist items that do not have
1918 * a node anymore (= orphaned checklist items) */
1919 snprintf(tq
, sizeof(tq
), "DELETE FROM %s WHERE nodeid NOT IN (SELECT nodeid FROM %s);", checklisttable_tmpname
, datatable_tmpname
);
1920 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
1921 fprintf(stderr
, "ERROR deleting orphaned checklist items!\n");
1924 gtk_tree_store_remove(GTK_TREE_STORE(model
), &iter
);
1927 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), model
);
1928 g_object_unref(model
);
1930 fprintf(stderr
, "here! 3\n");
1931 gtk_tree_row_reference_free(ref
);
1932 gtk_tree_row_reference_free(upref
);
1934 gtk_tree_view_expand_all(GTK_TREE_VIEW(mainview
->treeview
));
1936 fprintf(stderr
, "here10\n");
1937 gtk_widget_destroy(dialog
);
1940 void callback_edit_clear(GtkAction
* action
, gpointer data
)
1942 MainView
*mainview
= (MainView
*) data
;
1943 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1945 nodeData
*nd
= getSelectedNode(mainview
);
1947 if (nd
->typ
== NODE_TEXT
) gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mainview
->buffer
), "", 0);
1948 else if (nd
->typ
== NODE_SKETCH
) sketchwidget_clear(mainview
->sk
);
1949 else if (nd
->typ
== NODE_CHECKLIST
) gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
))));
1955 void callback_edit_cut(GtkAction
* action
, gpointer data
)
1957 MainView
*mainview
= (MainView
*) data
;
1958 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1960 nodeData
*nd
= getSelectedNode(mainview
);
1962 if (nd
->typ
== NODE_TEXT
)
1963 gtk_text_buffer_cut_clipboard(GTK_TEXT_BUFFER(mainview
->buffer
), mainview
->clipboard
, TRUE
);
1964 else if (nd
->typ
== NODE_SKETCH
)
1966 if (sketchwidget_cut(mainview
->sk
, mainview
->clipboard
)==FALSE
)
1967 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Error cutting"));
1969 else if (nd
->typ
== NODE_CHECKLIST
)
1970 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Unimplemented"));
1977 void callback_edit_copy(GtkAction
* action
, gpointer data
)
1979 MainView
*mainview
= (MainView
*) data
;
1980 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1982 nodeData
*nd
= getSelectedNode(mainview
);
1984 if (nd
->typ
== NODE_TEXT
)
1985 gtk_text_buffer_copy_clipboard(GTK_TEXT_BUFFER(mainview
->buffer
), mainview
->clipboard
);
1986 else if (nd
->typ
== NODE_SKETCH
)
1988 if (sketchwidget_copy(mainview
->sk
, mainview
->clipboard
)==FALSE
)
1989 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Error copying"));
1991 else if (nd
->typ
== NODE_CHECKLIST
)
1992 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Unimplemented"));
1998 void callback_edit_paste(GtkAction
* action
, gpointer data
)
2000 MainView
*mainview
= (MainView
*) data
;
2001 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2003 nodeData
*nd
= getSelectedNode(mainview
);
2005 if (nd
->typ
== NODE_TEXT
)
2006 gtk_text_buffer_paste_clipboard(GTK_TEXT_BUFFER(mainview
->buffer
), mainview
->clipboard
, NULL
, TRUE
);
2007 else if (nd
->typ
== NODE_SKETCH
)
2009 if (sketchwidget_paste(mainview
->sk
, mainview
->clipboard
)==FALSE
)
2010 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Error pasting"));
2012 else if (nd
->typ
== NODE_CHECKLIST
) {
2013 /* Paste string from clipboard as new item */
2014 callback_checklist_paste(mainview
);
2017 mainview
->file_edited
= TRUE
;
2020 gint
cb_popup(GtkWidget
* widget
, GdkEvent
* event
)
2023 GdkEventButton
*event_button
;
2026 * The "widget" is the menu that was supplied when
2027 * * g_signal_connect_swapped() was called.
2029 menu
= GTK_MENU(widget
);
2030 event_button
= (GdkEventButton
*) event
;
2031 if (event
->type
== GDK_BUTTON_PRESS
&& event_button
->button
== 3)
2033 gtk_menu_popup(menu
, NULL
, NULL
, NULL
, NULL
, event_button
->button
, event_button
->time
);
2042 gboolean
closefile(MainView
* mainview
)
2044 saveCurrentData(mainview
);
2046 if (mainview
->file_edited
)
2048 HildonNote
*hn
= HILDON_NOTE(hildon_note_new_confirmation_add_buttons(GTK_WINDOW(mainview
->data
->main_view
), _("Save changes?"), _("Yes"), CONFRESP_YES
, _("No"), CONFRESP_NO
, _("Cancel"), CONFRESP_CANCEL
, NULL
, NULL
));
2049 gint answer
= gtk_dialog_run(GTK_DIALOG(hn
));
2050 gtk_widget_destroy(GTK_WIDGET(hn
));
2052 if (answer
== CONFRESP_CANCEL
)
2054 else if (answer
== CONFRESP_YES
)
2056 if (mainview
->file_name
== NULL
)
2058 mainview
->file_name
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, "maemopaddata", "db");
2060 write_buffer_to_file(mainview
);
2065 sqlite3_close(mainview
->db
);
2066 mainview
->db
= NULL
;
2070 gboolean
callback_file_close(GtkAction
* action
, gpointer data
)
2073 MainView
*mainview
= (MainView
*) data
;
2074 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2075 if (closefile(mainview
) == FALSE
)
2082 void callback_file_new_node(GtkAction
* action
, gpointer data
)
2084 MainView
*mainview
= (MainView
*) data
;
2085 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2087 nodeType typ
= NODE_SKETCH
;
2089 nodeData
*nd
= getSelectedNode(mainview
);
2094 new_node_dialog(typ
, mainview
);
2100 void callback_file_new(GtkAction
* action
, gpointer data
)
2102 MainView
*mainview
= (MainView
*) data
;
2103 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2105 gchar
*filename
= NULL
;
2107 if (closefile(mainview
) == FALSE
)
2110 filename
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, "memos", "db");
2111 if (filename
== NULL
)
2118 setBusy(mainview
, 1);
2122 rc
= sqlite3_open(filename
, &mainview
->db
);
2125 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Error 1"));
2126 fprintf(stderr
, "Can't create database %s: %s\n", filename
, sqlite3_errmsg(mainview
->db
));
2130 sqlite3_exec(mainview
->db
, "PRAGMA synchronous = OFF;", NULL
, NULL
, NULL
);
2134 snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", misctable_name
, misctable
);
2135 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
2137 snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", datatable_name
, datatable
);
2138 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
2140 fprintf(stderr
, "ERROR creating data table\n");
2141 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Error 2"));
2145 snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", checklisttable_name
, checklisttable
);
2146 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
2148 fprintf(stderr
, "ERROR creating checklist table\n");
2149 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Error 3"));
2154 sqlite3_close(mainview
->db
);
2155 mainview
->db
= NULL
;
2157 mainview
->file_name
= filename
;
2158 mainview
->file_edited
= FALSE
;
2159 read_file_to_buffer(mainview
);
2161 /*add a starter memo*/
2163 node
= g_malloc(sizeof(nodeData
));
2164 node
->typ
= NODE_SKETCH
;
2165 node
->name
= _("My first memo");
2166 node
->namepix
= NULL
;
2170 add_new_node(node
, mainview
, TRUE
);
2171 gtk_paned_set_position(GTK_PANED(mainview
->hpaned
), 180);
2172 mainview
->viewflags
= 3;
2173 callback_setview(mainview
, 1);
2174 write_buffer_to_file(mainview
);
2177 setBusy(mainview
, 0);
2180 gboolean
reset_ctree(GtkTreeModel
* model
, GtkTreePath
* path
, GtkTreeIter
* iter
, gpointer data
)
2184 gtk_tree_model_get(model
, iter
, NODE_DATA
, &node
, -1);
2190 g_object_unref(node
->namepix
);
2193 gtk_tree_store_set(GTK_TREE_STORE(model
), iter
, NODE_DATA
, NULL
, -1);
2198 void new_file(MainView
* mainview
)
2200 setBusy(mainview
, 1);
2202 * clear buffer, filename and free buffer text
2204 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mainview
->buffer
), "", -1);
2205 mainview
->file_name
= NULL
;
2206 mainview
->file_edited
= FALSE
;
2207 mainview
->newnodedialog_createchild
= TRUE
;
2209 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
));
2211 g_object_ref(model
);
2212 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), NULL
);
2214 gtk_tree_model_foreach(model
, (GtkTreeModelForeachFunc
) reset_ctree
, (gpointer
) mainview
);
2218 * gtk_tree_store_clear(GTK_TREE_STORE(model));
2220 GtkTreePath
*path
= gtk_tree_path_new_from_indices(0, -1);
2223 if (gtk_tree_model_get_iter(model
, &iter
, path
))
2227 gtk_tree_store_remove(GTK_TREE_STORE(model
), &iter
);
2229 while(gtk_tree_store_iter_is_valid(GTK_TREE_STORE(model
), &iter
));
2231 gtk_tree_path_free(path
);
2233 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), model
);
2234 g_object_unref(model
);
2236 prepareUIforNodeChange(mainview
, NODE_UNKNOWN
);
2237 setBusy(mainview
, 2);
2243 void callback_file_open(GtkAction
* action
, gpointer data
)
2245 gchar
*filename
= NULL
;
2246 MainView
*mainview
= (MainView
*) data
;
2247 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2249 if (closefile(mainview
) == FALSE
)
2255 filename
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_OPEN
, NULL
, NULL
);
2258 * if we got a file name from chooser -> open file
2260 open_file(filename
, mainview
);
2264 gboolean
open_file(gchar
* filename
, MainView
* mainview
)
2268 setBusy(mainview
, 1);
2270 while(filename
!= NULL
)
2274 if (stat(filename
, &s
) == -1) break;
2276 mainview
->file_name
= g_strdup(filename
);
2277 gboolean res
= read_file_to_buffer(mainview
);
2281 g_free(mainview
->file_name
);
2282 mainview
->file_name
= NULL
;
2285 mainview
->file_edited
= FALSE
;
2290 setBusy(mainview
, 2);
2294 void callback_about_link(GtkAboutDialog
*about
, const gchar
*link
, gpointer data
)
2296 MainView
*mainview
= (MainView
*) data
;
2297 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2298 osso_rpc_run_with_defaults(mainview
->data
->osso
, "osso_browser", OSSO_BROWSER_OPEN_NEW_WINDOW_REQ
, NULL
,
2299 DBUS_TYPE_STRING
, link
, DBUS_TYPE_INVALID
);
2302 void callback_about(GtkAction
* action
, gpointer data
)
2304 MainView
*mainview
=(MainView
*)data
;
2306 const char *authors
[] = {
2315 gtk_about_dialog_set_url_hook(callback_about_link
, mainview
, NULL
);
2317 gtk_show_about_dialog(GTK_WINDOW(mainview
->data
->main_view
),
2318 "name", "Maemopad+",
2320 "copyright", "(c) 2006-2008 Kemal Hadimli and the Maemopad+ Team",
2321 "license", "GNU LGPL version 2.1 or later\n\nSee http://www.gnu.org/licenses/lgpl.html",
2323 "website", "http://maemopadplus.garage.maemo.org/",
2331 void callback_file_save(GtkAction
* action
, gpointer data
)
2333 gchar
*filename
= NULL
;
2334 MainView
*mainview
= (MainView
*) data
;
2335 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2338 * check is we had a new file
2340 if (mainview
->file_name
!= NULL
)
2342 write_buffer_to_file(mainview
);
2346 filename
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, "maemopaddata", "db");
2348 * if we got a file name from chooser -> save file
2350 if (filename
!= NULL
)
2352 mainview
->file_name
= filename
;
2353 write_buffer_to_file(mainview
);
2354 mainview
->file_edited
= FALSE
;
2359 void callback_shapemenu(GtkAction
* action
, GtkWidget
* wid
)
2361 int style
= (int)gtk_object_get_user_data(GTK_OBJECT(wid
));
2362 MainView
*mainview
= gtk_object_get_data(GTK_OBJECT(wid
), "m");
2364 g_assert(mainview
!= NULL
);
2366 if (style
==0) sketchwidget_set_shape(mainview
->sk
, SKETCHSHAPE_FREEHAND
);
2367 else if (style
==1) sketchwidget_set_shape(mainview
->sk
, SKETCHSHAPE_LINE
);
2368 else if (style
==2) sketchwidget_set_shape(mainview
->sk
, SKETCHSHAPE_RECT
);
2369 else if (style
==3) sketchwidget_set_shape(mainview
->sk
, SKETCHSHAPE_ELLIPSE
);
2374 void callback_eraser(GtkAction
* action
, MainView
* mainview
)
2376 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2378 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->eraser_tb
)) == TRUE
)
2386 mainview
->sk
->pressuresensitivity
=FALSE
;
2388 sketchwidget_set_brushcolor(mainview
->sk
, c2
);
2389 mainview
->brushsize_backup
= sketchwidget_get_brushsize(mainview
->sk
);
2390 guint ers
=(mainview
->brushsize_backup
*4)+4;
2391 sk_set_brushsize(mainview
, ers
);
2392 sketchwidget_set_brushsize(mainview
->sk
, ers
); /*fixme:to override max brush size, not pretty*/
2399 hildon_color_button_get_color(HILDON_COLOR_BUTTON(mainview
->colorbutton
), &c2
);
2401 GdkColor
*col
= hildon_color_button_get_color(HILDON_COLOR_BUTTON(mainview
->colorbutton
));
2403 c2
.green
= col
->green
;
2404 c2
.blue
= col
->blue
;
2407 mainview
->sk
->pressuresensitivity
=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(mainview
->tools_pressure
));
2409 sketchwidget_set_brushcolor(mainview
->sk
, c2
);
2410 sk_set_brushsize(mainview
, mainview
->brushsize_backup
);
2414 void callback_toggletree(GtkAction
* action
, MainView
* mainview
)
2416 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2418 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->viewmenuitems
[0]), gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->toggletree_tb
)));
2420 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->toggletree_tb
))==TRUE
)
2421 mainview
->viewflags
|= 1;
2423 mainview
->viewflags
&= ~1;
2425 callback_setview(mainview
, 0);
2428 void callback_menu(GtkAction
* action
, GtkWidget
* menu
)
2430 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
, NULL
, NULL
, 0, GDK_CURRENT_TIME
);
2433 void callback_brushsizetb(GtkAction
* action
, MainView
*mainview
)
2435 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2437 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->eraser_tb
)) == TRUE
)
2439 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->eraser_tb
), FALSE
);
2443 callback_menu(NULL
, mainview
->brushsizemenu
);
2447 void callback_brushsize(GtkAction
* action
, GtkWidget
* wid
)
2449 int bsize
= (int)gtk_object_get_user_data(GTK_OBJECT(wid
));
2450 MainView
*mainview
= gtk_object_get_data(GTK_OBJECT(wid
), "m");
2452 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2454 sketchwidget_set_brushsize(mainview
->sk
, bsize
);
2456 GtkWidget
*pix
= gtk_object_get_data(GTK_OBJECT(wid
), "i");
2458 gtk_widget_show(pix
);
2459 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(mainview
->brushsize_tb
), pix
);
2462 void callback_sketchlines(GtkAction
* action
, GtkWidget
* wid
)
2464 int style
= (int)gtk_object_get_user_data(GTK_OBJECT(wid
));
2465 MainView
*mainview
= gtk_object_get_data(GTK_OBJECT(wid
), "m");
2467 g_assert(mainview
!= NULL
);
2469 nodeData
*nd
= getSelectedNode(mainview
);
2470 gboolean doit
= FALSE
;
2472 if (nd
!= NULL
&& nd
->typ
== NODE_SKETCH
)
2474 nd
->flags
&= ~NODEFLAG_SKETCHLINES
;
2475 nd
->flags
&= ~NODEFLAG_SKETCHGRAPH
;
2476 /* sketchwidget_set_edited(mainview->sk, TRUE);*/ /*we call this on openfile, so this messes things up*/
2482 sketchwidget_set_backstyle(mainview
->sk
, SKETCHBACK_NONE
);
2484 else if (style
== 1)
2486 sketchwidget_set_backstyle(mainview
->sk
, SKETCHBACK_LINES
);
2488 nd
->flags
|= NODEFLAG_SKETCHLINES
;
2490 else if (style
== 2)
2492 sketchwidget_set_backstyle(mainview
->sk
, SKETCHBACK_GRAPH
);
2494 nd
->flags
|= NODEFLAG_SKETCHGRAPH
;
2497 GtkWidget
*pix
= gtk_object_get_data(GTK_OBJECT(wid
), "i");
2499 gtk_widget_show(pix
);
2500 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(mainview
->sketchlines_tb
), pix
);
2503 void callback_color(HildonColorButton
* colorButton
, MainView
* mainview
)
2505 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2507 nodeData
*nd
= getSelectedNode(mainview
);
2508 if (nd
== NULL
) return;
2512 hildon_color_button_get_color(colorButton
, &c2
);
2514 GdkColor
*col
= hildon_color_button_get_color(colorButton
);
2516 c2
.green
= col
->green
;
2517 c2
.blue
= col
->blue
;
2520 if (nd
->typ
== NODE_SKETCH
)
2522 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->eraser_tb
), FALSE
);
2523 sketchwidget_set_brushcolor(mainview
->sk
, c2
);
2525 else if (nd
->typ
== NODE_CHECKLIST
)
2527 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
2528 GList
* l
=gtk_tree_selection_get_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
)), NULL
);
2531 snprintf(tmp
, sizeof(tmp
), "#%02x%02x%02x", c2
.red
>>8, c2
.green
>>8, c2
.blue
>>8);
2536 GtkTreePath
*path
=cur
->data
;
2539 if (gtk_tree_model_get_iter(model
, &iter
, path
))
2541 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_COLOR
, tmp
, -1);
2543 gtk_tree_path_free(path
);
2550 void callback_color_invoke(GtkAction
* action
, gpointer data
)
2552 MainView
*mainview
= (MainView
*) data
;
2553 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2556 gtk_button_clicked(GTK_BUTTON(mainview
->colorbutton
));
2558 HildonColorButton
*hc
= HILDON_COLOR_BUTTON(mainview
->colorbutton
);
2559 gtk_button_clicked(GTK_BUTTON(&hc
->button
));
2565 void callback_pressure(GtkAction
* action
, MainView
*mainview
)
2567 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2569 nodeData
*nd
= getSelectedNode(mainview
);
2573 if (nd
->typ
!= NODE_SKETCH
)
2576 mainview
->sk
->pressuresensitivity
=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(mainview
->tools_pressure
));
2580 void callback_wordwrap(GtkAction
* action
, MainView
*mainview
)
2582 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2584 nodeData
*nd
= getSelectedNode(mainview
);
2588 if (nd
->typ
!= NODE_TEXT
)
2591 gboolean act
=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(mainview
->tools_wordwrap
));
2592 if (act
==TRUE
) nd
->flags
|= NODEFLAG_WORDWRAP
;
2593 else nd
->flags
&= ~NODEFLAG_WORDWRAP
;
2595 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(mainview
->textview
), (act
==TRUE
)?GTK_WRAP_WORD
:GTK_WRAP_NONE
);
2599 void callback_font(GtkAction
* action
, gpointer data
)
2601 MainView
*mainview
= (MainView
*) data
;
2602 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2604 nodeData
*nd
= getSelectedNode(mainview
);
2608 if (nd
->typ
!= NODE_TEXT
)
2611 HildonFontSelectionDialog
*dialog
= HILDON_FONT_SELECTION_DIALOG(hildon_font_selection_dialog_new(NULL
, NULL
));
2613 gboolean gotsel
=wp_text_buffer_has_selection(mainview
->buffer
);
2616 WPTextBufferFormat fmt
;
2617 wp_text_buffer_get_attributes(mainview
->buffer
, &fmt
, gotsel
);
2620 if (fmt
.text_position
==TEXT_POSITION_SUPERSCRIPT
) ri
=1;
2621 else if (fmt
.text_position
==TEXT_POSITION_SUBSCRIPT
) ri
=-1;
2623 g_object_set(G_OBJECT(dialog
),
2624 "family-set", fmt
.cs
.font
,
2625 "family", wp_get_font_name(fmt
.font
),
2626 "size-set", fmt
.cs
.font_size
,
2627 "size", wp_font_size
[fmt
.font_size
],
2628 "color-set", fmt
.cs
.color
,
2629 "color", &fmt
.color
,
2630 "bold-set", fmt
.cs
.bold
,
2632 "italic-set", fmt
.cs
.italic
,
2633 "italic", fmt
.italic
,
2634 "underline-set", fmt
.cs
.underline
,
2635 "underline", fmt
.underline
,
2636 "strikethrough-set", fmt
.cs
.strikethrough
,
2637 "strikethrough", fmt
.strikethrough
,
2638 "position-set", fmt
.cs
.text_position
,
2642 gtk_widget_show_all(GTK_WIDGET(dialog
));
2643 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_OK
)
2645 gboolean bold
, italic
, underline
, strikethrough
;
2646 gchar
*family
= NULL
;
2647 gint size
, position
;
2648 GdkColor
*color
=NULL
;
2649 gboolean set_family
, set_size
, set_bold
, set_italic
, set_underline
, set_strikethrough
, set_color
, set_position
;
2651 g_object_get(G_OBJECT(dialog
), "family", &family
, "size", &size
, "bold", &bold
, "italic", &italic
,
2652 "underline", &underline
, "strikethrough", &strikethrough
,
2653 "family-set", &set_family
, "size-set", &set_size
, "bold-set", &set_bold
, "italic-set", &set_italic
,
2654 "underline-set", &set_underline
, "strikethrough-set", &set_strikethrough
,
2655 "color", &color
, "color-set", &set_color
, "position", &position
, "position-set", &set_position
,
2658 wp_text_buffer_get_attributes(mainview
->buffer
, &fmt
, FALSE
);
2659 fmt
.cs
.font
=fmt
.cs
.font_size
=fmt
.cs
.strikethrough
=fmt
.cs
.color
=fmt
.cs
.bold
=fmt
.cs
.italic
=fmt
.cs
.underline
=fmt
.cs
.text_position
=0;
2661 if (set_family
) { fmt
.font
=wp_get_font_index(family
, 1); fmt
.cs
.font
=1; }
2662 if (set_size
) { fmt
.font_size
=wp_get_font_size_index(size
, 16); fmt
.cs
.font_size
=1; }
2664 if (set_strikethrough
)
2666 fmt
.cs
.strikethrough
=1;
2667 fmt
.strikethrough
=strikethrough
;
2673 GLIB WARNING ** GLib-GObject - IA__g_object_set_valist: object class `GtkTextTag' has no property named `'
2676 fmt
.color
.pixel
=color
->pixel
;
2677 fmt
.color
.red
=color
->red
;
2678 fmt
.color
.green
=color
->green
;
2679 fmt
.color
.blue
=color
->blue
;
2684 if (position
==1) ri
=TEXT_POSITION_SUPERSCRIPT
;
2685 else if (position
==-1) ri
=TEXT_POSITION_SUBSCRIPT
;
2686 else ri
=TEXT_POSITION_NORMAL
;
2688 fmt
.cs
.text_position
=1;
2689 fmt
.text_position
=ri
;
2705 fmt
.underline
=underline
;
2708 wp_text_buffer_set_format(mainview
->buffer
, &fmt
);
2711 gtk_widget_destroy(GTK_WIDGET(dialog
));
2714 void callback_fontstyle(GtkAction
* action
, GtkWidget
* wid
)
2716 MainView
*mainview
= gtk_object_get_data(GTK_OBJECT(wid
), "m");
2717 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2719 nodeData
*nd
= getSelectedNode(mainview
);
2723 if (nd
->typ
== NODE_TEXT
)
2725 gboolean act
=gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(wid
));
2727 gint style
= (gint
)gtk_object_get_data(GTK_OBJECT(wid
), "s");
2728 wp_text_buffer_set_attribute(mainview
->buffer
, style
, (gpointer
)act
);
2730 else if (nd
->typ
== NODE_CHECKLIST
)
2732 gboolean act
=gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(wid
));
2733 gint style
= (gint
)gtk_object_get_data(GTK_OBJECT(wid
), "s");
2734 if (style
!=WPT_BOLD
&& style
!=WPT_STRIKE
&& style
!=WPT_LEFT
) return;
2736 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
2737 GList
* l
=gtk_tree_selection_get_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
)), NULL
);
2739 gint styletoset_weight
=PANGO_WEIGHT_NORMAL
;
2740 gboolean styletoset_strike
=FALSE
;
2741 gboolean checkit
=FALSE
;
2743 if (style
==WPT_BOLD
&& act
==TRUE
) styletoset_weight
=PANGO_WEIGHT_BOLD
;
2744 else if (style
==WPT_STRIKE
&& act
==TRUE
) styletoset_strike
=TRUE
;
2745 else if (style
==WPT_LEFT
&& act
==TRUE
) checkit
=TRUE
;
2750 GtkTreePath
*path
=cur
->data
;
2753 if (gtk_tree_model_get_iter(model
, &iter
, path
))
2755 if (style
==WPT_BOLD
) gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_BOLD
, styletoset_weight
, -1);
2756 else if (style
==WPT_STRIKE
) gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_STRIKE
, styletoset_strike
, -1);
2757 else if (style
==WPT_LEFT
) gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_CHECKED
, checkit
, -1);
2759 gtk_tree_path_free(path
);
2764 gtk_object_set_data(GTK_OBJECT(mainview
->listview
), "edited", TRUE
);
2769 void callback_textbuffer_move(WPTextBuffer
*textbuffer
, MainView
*mainview
)
2771 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2774 gboolean gotsel=wp_text_buffer_has_selection(mainview->buffer);
2776 _toggle_tool_button_set_inconsistent(GTK_TOGGLE_TOOL_BUTTON(mainview->bold_tb), gotsel);
2777 _toggle_tool_button_set_inconsistent(GTK_TOGGLE_TOOL_BUTTON(mainview->italic_tb), gotsel);
2778 _toggle_tool_button_set_inconsistent(GTK_TOGGLE_TOOL_BUTTON(mainview->underline_tb), gotsel);
2779 _toggle_tool_button_set_inconsistent(GTK_TOGGLE_TOOL_BUTTON(mainview->bullet_tb), gotsel);
2781 WPTextBufferFormat fmt
;
2782 wp_text_buffer_get_attributes(mainview
->buffer
, &fmt
, FALSE
/*gotsel*/);
2784 g_signal_handlers_block_by_func(mainview
->bold_tb
, callback_fontstyle
, mainview
->bold_tb
);
2785 g_signal_handlers_block_by_func(mainview
->italic_tb
, callback_fontstyle
, mainview
->italic_tb
);
2786 g_signal_handlers_block_by_func(mainview
->underline_tb
, callback_fontstyle
, mainview
->underline_tb
);
2787 g_signal_handlers_block_by_func(mainview
->bullet_tb
, callback_fontstyle
, mainview
->bullet_tb
);
2789 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->bold_tb
), fmt
.bold
);
2790 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->italic_tb
), fmt
.italic
);
2791 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->underline_tb
), fmt
.underline
);
2792 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->bullet_tb
), fmt
.bullet
);
2794 g_signal_handlers_unblock_by_func(mainview
->bold_tb
, callback_fontstyle
, mainview
->bold_tb
);
2795 g_signal_handlers_unblock_by_func(mainview
->italic_tb
, callback_fontstyle
, mainview
->italic_tb
);
2796 g_signal_handlers_unblock_by_func(mainview
->underline_tb
, callback_fontstyle
, mainview
->underline_tb
);
2797 g_signal_handlers_unblock_by_func(mainview
->bullet_tb
, callback_fontstyle
, mainview
->bullet_tb
);
2800 gint
wp_savecallback(const gchar
*buffer
, GString
* gstr
)
2802 gstr
=g_string_append(gstr
, buffer
);
2806 void callback_undo(GtkAction
* action
, MainView
* mainview
)
2808 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2810 nodeData
*nd
= getSelectedNode(mainview
);
2812 if (nd
== NULL
) return;
2814 if (nd
->typ
== NODE_SKETCH
) sketchwidget_undo(mainview
->sk
);
2815 else if (nd
->typ
== NODE_TEXT
) wp_text_buffer_undo(mainview
->buffer
);
2818 void callback_redo(GtkAction
* action
, MainView
* mainview
)
2820 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2822 nodeData
*nd
= getSelectedNode(mainview
);
2824 if (nd
== NULL
) return;
2826 if (nd
->typ
== NODE_SKETCH
) sketchwidget_redo(mainview
->sk
);
2827 else if (nd
->typ
== NODE_TEXT
) wp_text_buffer_redo(mainview
->buffer
);
2830 void callback_undotoggle(gpointer widget
, gboolean st
, MainView
* mainview
)
2832 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2834 gtk_widget_set_sensitive(GTK_WIDGET(mainview
->undo_tb
), st
);
2837 void callback_redotoggle(gpointer widget
, gboolean st
, MainView
* mainview
)
2839 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2841 gtk_widget_set_sensitive(GTK_WIDGET(mainview
->redo_tb
), st
);
2844 void callback_finger(SketchWidget
* sk
, gint x
, gint y
, gdouble pressure
, MainView
* mainview
)
2846 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2848 if ((mainview
->viewflags
& 2) == 0) mainview
->viewflags
|= 2;
2849 else mainview
->viewflags
&= ~2;
2850 callback_setview(mainview
, 1);
2853 gboolean
close_cb(GtkWidget
* widget
, GdkEventAny
* event
, MainView
* mainview
)
2855 callback_file_close(NULL
, mainview
);
2859 gboolean
key_press_cb(GtkWidget
* widget
, GdkEventKey
* event
, MainView
* mainview
)
2861 switch (event
->keyval
)
2866 * gtk_infoprint(GTK_WINDOW(app), "Navigation Key Up");
2870 * gtk_infoprint(GTK_WINDOW(app), "Navigation Key Down");
2874 * gtk_infoprint(GTK_WINDOW(app), "Navigation Key Left");
2878 * gtk_infoprint(GTK_WINDOW(app), "Navigation Key Right");
2882 * gtk_infoprint(GTK_WINDOW(app), "Navigation Key select");
2885 /*code below messes up when you have a textview*/
2890 gtk_widget_child_focus(widget, event->keyval==GDK_Left?GTK_DIR_TAB_BACKWARD:GTK_DIR_TAB_FORWARD);
2896 nodeData
*selnode
= getSelectedNode(mainview
);
2897 if (selnode
!=NULL
&& selnode
->typ
==NODE_SKETCH
)
2899 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Squared shapes ON"));
2900 sketchwidget_set_shift(mainview
->sk
, TRUE
);
2907 nodeData
*selnode
= getSelectedNode(mainview
);
2908 if (selnode
!=NULL
&& selnode
->typ
==NODE_SKETCH
)
2910 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Squared shapes OFF"));
2911 sketchwidget_set_shift(mainview
->sk
, FALSE
);
2918 nodeData
*selnode
= getSelectedNode(mainview
);
2919 if (selnode
!=NULL
&& selnode
->typ
==NODE_SKETCH
)
2921 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Filled shapes OFF"));
2922 sketchwidget_set_fillmode(mainview
->sk
, FALSE
);
2929 nodeData
*selnode
= getSelectedNode(mainview
);
2930 if (selnode
!=NULL
&& selnode
->typ
==NODE_SKETCH
)
2932 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Filled shapes ON"));
2933 sketchwidget_set_fillmode(mainview
->sk
, TRUE
);
2940 if ((mainview
->viewflags
& 4) == 0) mainview
->viewflags
|= 4;
2941 else mainview
->viewflags
&= ~4;
2942 callback_setview(mainview
, 1);
2947 callback_redo(NULL
, mainview
);
2952 callback_undo(NULL
, mainview
);
2957 if ((mainview
->viewflags
& 1) == 0) mainview
->viewflags
|= 1;
2958 else mainview
->viewflags
&= ~1;
2959 callback_setview(mainview
, 1);
2966 if ((mainview->viewflags & 2) == 0) mainview->viewflags |= 2;
2967 else mainview->viewflags &= ~2;
2968 callback_setview(mainview, 1);
2977 void callback_viewmenu(GtkAction
* action
, GtkWidget
* wid
)
2979 int flag
= (int)gtk_object_get_user_data(GTK_OBJECT(wid
));
2980 MainView
*mainview
= gtk_object_get_data(GTK_OBJECT(wid
), "m");
2982 g_assert(mainview
!= NULL
);
2984 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(wid
))) mainview
->viewflags
|= flag
;
2985 else mainview
->viewflags
&= ~flag
;
2989 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->toggletree_tb
), gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(wid
)));
2993 callback_setview(mainview
, 0);
2997 void callback_setview(MainView
*mainview
, int setmenu
)
3001 if ((mainview
->viewflags
&4)>0)
3002 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->viewmenuitems
[2]), TRUE
);
3004 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->viewmenuitems
[2]), FALSE
);
3006 if ((mainview
->viewflags
&2)>0)
3007 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->viewmenuitems
[1]), TRUE
);
3009 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->viewmenuitems
[1]), FALSE
);
3011 if ((mainview
->viewflags
&1)>0)
3013 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->viewmenuitems
[0]), TRUE
);
3014 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->toggletree_tb
), TRUE
);
3018 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->viewmenuitems
[0]), FALSE
);
3019 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->toggletree_tb
), FALSE
);
3025 setBusy(mainview
, 1);
3027 if ((mainview
->viewflags
&4)>0)
3028 gtk_window_fullscreen(GTK_WINDOW(mainview
->data
->main_view
));
3030 gtk_window_unfullscreen(GTK_WINDOW(mainview
->data
->main_view
));
3032 if ((mainview
->viewflags
&2)>0)
3033 gtk_widget_show(mainview
->toolbar
);
3035 gtk_widget_hide(mainview
->toolbar
);
3037 if ((mainview
->viewflags
&1)>0)
3038 gtk_widget_show(mainview
->scrolledtree
);
3040 gtk_widget_hide(mainview
->scrolledtree
);
3042 if (mainview
->viewflags
==4)
3043 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sketchwidget_get_mainwidget(mainview
->sk
)), GTK_POLICY_NEVER
, GTK_POLICY_NEVER
);
3045 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sketchwidget_get_mainwidget(mainview
->sk
)), GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
3047 setBusy(mainview
, 2);
3051 void callback_buffer_modified(GtkAction
* action
, gpointer data
)
3053 MainView
*mainview
= (MainView
*) data
;
3054 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3056 mainview
->file_edited
= TRUE
;
3060 * Callback for exit D-BUS event
3062 void exit_event_handler(gboolean die_now
, gpointer data
)
3064 MainView
*mainview
= (MainView
*) data
;
3065 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3069 if (callback_file_close(NULL
, mainview
)==FALSE
) gtk_main_quit(); /*make sure we call gtk_main_quit*/
3076 * application_exit(mainview->data);
3081 * Callback for hardware D-BUS events
3083 void hw_event_handler(osso_hw_state_t
* state
, gpointer data
)
3085 MainView
*mainview
= (MainView
*) data
;
3086 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3089 * if (state->shutdown_ind)
3091 * gtk_infoprint(GTK_WINDOW(mainview->data->app),
3092 * "Shutdown event!");
3094 * if (state->memory_low_ind)
3096 * gtk_infoprint(GTK_WINDOW(mainview->data->app),
3097 * "Memory low event!");
3100 if (state
->save_unsaved_data_ind
)
3102 fprintf(stderr
, "Saving unsaved data!\n");
3103 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, "Saving unsaved data!");
3104 callback_file_save(NULL
, mainview
);
3108 * if (state->system_inactivity_ind)
3110 * gtk_infoprint(GTK_WINDOW(mainview->data->app),
3111 * "Minimize application inactivity event!");
3116 GtkTreeRowReference
*read_sqlite3_data(MainView
* mainview
, unsigned int parentid
, GtkTreeRowReference
* parenttree
, unsigned int selected
, GtkTreeStore
* model
)
3118 GtkTreeRowReference
*resref
= NULL
;
3122 snprintf(q
, sizeof(q
), "SELECT nodeid, bodytype, name, nameblob, lastmodified, flags FROM %s WHERE parent=%d ORDER BY ord", datatable_tmpname
, parentid
);
3124 sqlite3_stmt
*stmt
= NULL
;
3126 int rc
= sqlite3_prepare(mainview
->db
, q
, strlen(q
), &stmt
, &dum
);
3130 fprintf(stderr
, "Error %s\n", sqlite3_errmsg(mainview
->db
));
3135 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
3137 rc
= sqlite3_step(stmt
);
3138 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
3140 else if (rc
== SQLITE_ROW
)
3142 int nodeid
= sqlite3_column_int(stmt
, 0);
3143 int typ
= sqlite3_column_int(stmt
, 1);
3144 const unsigned char *name
= sqlite3_column_text(stmt
, 2);
3145 const unsigned char *nameblob
= sqlite3_column_text(stmt
, 3);
3146 int lastmod
= sqlite3_column_int(stmt
, 4);
3147 int flags
= sqlite3_column_int(stmt
, 5);
3150 * fprintf(stderr, "CARD=%s TYPE=%d\n", name, typ);
3152 if ((typ
!= NODE_TEXT
&& typ
!= NODE_SKETCH
&& typ
!= NODE_CHECKLIST
) || (name
== NULL
&& nameblob
== NULL
))
3156 * fprintf(stderr, "invalid card, skipping\n");
3161 nodeData
*node
= g_malloc(sizeof(nodeData
));
3163 node
->sql3id
= nodeid
;
3165 node
->flags
= flags
;
3167 node
->namepix
= NULL
;
3169 node
->name
= g_strdup((char *)name
);
3170 if (nameblob
!= NULL
)
3172 int blobsize
= sqlite3_column_bytes(stmt
, 3);
3174 GdkPixbufLoader
*pl
= gdk_pixbuf_loader_new_with_type("png", NULL
);
3177 gdk_pixbuf_loader_write(pl
, (guchar
*) nameblob
, blobsize
, &err
);
3180 fprintf(stderr
, "Error loading nodename! %s\n", err
->message
);
3184 gdk_pixbuf_loader_close(pl
, NULL
);
3185 GdkPixbuf
*pixbuf
= gdk_pixbuf_loader_get_pixbuf(pl
);
3187 if (GDK_IS_PIXBUF(pixbuf
))
3188 node
->namepix
= pixbuf
;
3190 node
->lastMod
= lastmod
;
3192 GtkTreeIter parentiter
, newiter
;
3195 if (parenttree
!= NULL
)
3197 GtkTreePath
*pa
= gtk_tree_row_reference_get_path(parenttree
);
3199 gtk_tree_model_get_iter(GTK_TREE_MODEL(model
), &parentiter
, pa
);
3200 gtk_tree_path_free(pa
);
3204 gtk_tree_store_append(model
, &newiter
, par
);
3205 gtk_tree_store_set(model
, &newiter
, NODE_NAME
, node
->name
, NODE_PIXBUF
, node
->namepix
, NODE_DATA
, node
, -1);
3207 GtkTreePath
*pa
= gtk_tree_model_get_path(GTK_TREE_MODEL(model
), &newiter
);
3209 GtkTreeRowReference
*newref
= gtk_tree_row_reference_new(GTK_TREE_MODEL(model
), pa
);
3211 if (selected
== nodeid
)
3214 gtk_tree_path_free(pa
);
3215 GtkTreeRowReference
*r
= read_sqlite3_data(mainview
, nodeid
, newref
, selected
,
3218 if (resref
!= newref
)
3219 gtk_tree_row_reference_free(newref
);
3226 gtk_tree_row_reference_free(r
); /*safeguard */
3232 sqlite3_finalize(stmt
);
3234 return (resref
); /*ref to supposed-to-be-selected treeitem */
3240 gboolean
read_file_to_buffer(MainView
* mainview
)
3244 g_assert(mainview
!= NULL
);
3245 gboolean res
= FALSE
;
3247 gchar
*filename
= mainview
->file_name
;
3250 mainview
->file_name
= filename
;
3251 mainview
->loading
=TRUE
;
3253 fprintf(stderr
, "read:*%s*\n", filename
);
3256 sqlite3_stmt
*stmt
= NULL
;
3258 rc
= sqlite3_open(filename
, &mainview
->db
);
3263 fprintf(stderr
, "Can't open database %s: %s\n", filename
, sqlite3_errmsg(mainview
->db
));
3267 sqlite3_exec(mainview
->db
, "PRAGMA synchronous = OFF;", NULL
, NULL
, NULL
);
3269 char *q
= "SELECT skey, sval FROM settings";
3272 rc
= sqlite3_prepare(mainview
->db
, q
, strlen(q
), &stmt
, &dum
);
3275 fprintf(stderr
, "Error %s\n", sqlite3_errmsg(mainview
->db
));
3279 unsigned int selectedCard
= 0;
3282 * fprintf(stderr, "start config\n");
3284 unsigned int curDataVersion
= 0;
3285 unsigned int curChecklistVersion
= 0;
3288 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
3290 rc
= sqlite3_step(stmt
);
3291 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
3293 else if (rc
== SQLITE_ROW
)
3295 const unsigned char *col_key
= sqlite3_column_text(stmt
, 0);
3296 const unsigned char *col_val
= sqlite3_column_text(stmt
, 1);
3299 * fprintf(stderr, "%s=%s\n", col_key, col_val);
3301 if (!strcmp(col_key
, "leftPanedPos"))
3303 gint panedPos
= atoi((char *)col_val
);
3306 gtk_paned_set_position(GTK_PANED(mainview
->hpaned
), panedPos
);
3308 if (!strcmp(col_key
, "selectedNode"))
3310 gint tmp
= atoi((char *)col_val
);
3315 if (!strcmp(col_key
, "dataVersion"))
3317 gint tmp
= atoi((char *)col_val
);
3320 curDataVersion
= tmp
;
3322 if (!strcmp(col_key
, "checklistVersion"))
3324 gint tmp
= atoi((char *)col_val
);
3327 curChecklistVersion
= tmp
;
3329 if (!strcmp(col_key
, "newNodeDlgCreateChild"))
3331 gint tmp
= atoi((char *)col_val
);
3333 mainview
->newnodedialog_createchild
= TRUE
;
3335 mainview
->newnodedialog_createchild
= FALSE
;
3337 if (!strcmp(col_key
, "fullScreen"))
3339 gint tmp
= atoi((char *)col_val
);
3340 if (tmp
<0 || tmp
>4) tmp
=0;
3344 else if (tmp
==1) tmp
=2;
3345 else if (tmp
==2) tmp
=7;
3346 else if (tmp
==3) tmp
=6;
3347 else if (tmp
==4) tmp
=4;
3348 mainview
->viewflags
=tmp
;
3349 callback_setview(mainview
, TRUE
);
3351 if (!strcmp(col_key
, "viewFlags"))
3353 gint tmp
= atoi((char *)col_val
);
3355 mainview
->viewflags
=tmp
;
3356 callback_setview(mainview
, TRUE
);
3358 if (!strcmp(col_key
, "brushSize"))
3360 gint tmp
= atoi((char *)col_val
);
3361 if (tmp
>0) sk_set_brushsize(mainview
, tmp
);
3363 if (!strcmp(col_key
, "brushColor"))
3365 unsigned long tmp
= atol((char *)col_val
);
3368 c2
.red
= ((tmp
& 0xFF0000) >> 16) << 8;
3369 c2
.green
= ((tmp
& 0xFF00) >> 8) << 8;
3370 c2
.blue
= (tmp
& 0xFF) << 8;
3371 /* fprintf(stderr, "READ BRUSHCOLOR is %ul (%d,%d,%d)\n", tmp, c2.red, c2.green, c2.blue);*/
3373 sketchwidget_set_brushcolor(mainview
->sk
, c2
);
3374 hildon_color_button_set_color(HILDON_COLOR_BUTTON(mainview
->colorbutton
), &c2
);
3379 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
3381 fprintf(stderr
, "Error2 %s\n", sqlite3_errmsg(mainview
->db
));
3386 * fprintf(stderr, "end config\n");
3389 sqlite3_finalize(stmt
);
3391 gboolean resback
= FALSE
;
3393 while(curDataVersion
< datatableversion
)
3395 if (curDataVersion
== 0)
3397 snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_backupname
);
3398 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3400 snprintf(tq
, sizeof(tq
), "ALTER TABLE %s RENAME TO %s", datatable_name
, datatable_backupname
);
3401 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3403 fprintf(stderr
, "ERROR backing up table!\n");
3408 snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", datatable_name
, datatable
);
3409 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3411 fprintf(stderr
, "ERROR creating table!\n");
3414 snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT nodeid, parent, bodytype, name, body, nameblob, bodyblob, lastmodified, ord, 0 FROM %s", datatable_name
, datatable_backupname
);
3415 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3417 fprintf(stderr
, "ERROR copying data!\n");
3421 snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_backupname
);
3422 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3424 curDataVersion
= datatableversion
;
3429 if (curDataVersion
!= datatableversion
)
3431 fprintf(stderr
, "Data version mismatch\n");
3433 if (resback
== TRUE
)
3435 snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_name
);
3436 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3437 snprintf(tq
, sizeof(tq
), "ALTER TABLE %s RENAME TO %s", datatable_backupname
, datatable_name
);
3438 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3445 while(curChecklistVersion
< checklisttableversion
)
3447 if (curChecklistVersion
== 0) /*no checklisttable at all*/
3449 snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", checklisttable_name
, checklisttable
);
3450 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3452 fprintf(stderr
, "ERROR creating checklist table!\n");
3455 curChecklistVersion
= checklisttableversion
;
3461 GtkTreeStore
*model
= GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
)));
3463 g_object_ref(model
);
3464 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), NULL
);
3470 snprintf(tq
, sizeof(tq
), "CREATE%s TABLE %s%s", TEMPTABLE_KEYWORD
, datatable_tmpname
, datatable
);
3471 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3473 fprintf(stderr
, "ERROR creating temp table!\n");
3476 snprintf(tq
, sizeof(tq
), "CREATE INDEX %s_index ON %s %s", datatable_tmpname
, datatable_tmpname
, dataindex
);
3477 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3479 fprintf(stderr
, "ERROR creating temp index!\n");
3482 snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", datatable_tmpname
, datatable_name
);
3483 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3485 fprintf(stderr
, "ERROR copying data to temp table!\n");
3489 snprintf(tq
, sizeof(tq
), "CREATE%s TABLE %s%s", TEMPTABLE_KEYWORD
, checklisttable_tmpname
, checklisttable
);
3490 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3492 fprintf(stderr
, "ERROR creating temp table! (checklist)\n");
3495 snprintf(tq
, sizeof(tq
), "CREATE INDEX %s_index ON %s %s", checklisttable_tmpname
, checklisttable_tmpname
, checklistindex
);
3496 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3498 fprintf(stderr
, "ERROR creating temp index! (checklist)\n");
3501 snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", checklisttable_tmpname
, checklisttable_name
);
3502 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3504 fprintf(stderr
, "ERROR copying data to temp table! (checklist)\n");
3510 GtkTreeRowReference
*selectedRef
= read_sqlite3_data(mainview
, 0, NULL
, selectedCard
, model
);
3512 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), GTK_TREE_MODEL(model
));
3513 g_object_unref(model
);
3514 gtk_tree_view_expand_all(GTK_TREE_VIEW(mainview
->treeview
));
3516 if (selectedRef
!= NULL
)
3518 GtkTreeIter seliter
;
3520 if (ref2iter(GTK_TREE_MODEL(model
), selectedRef
, &seliter
) == TRUE
)
3522 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
3523 gtk_tree_selection_select_iter(selection
, &seliter
);
3526 gtk_tree_row_reference_free(selectedRef
);
3533 sqlite3_finalize(stmt
);
3536 mainview
->loading
=FALSE
;
3544 void write_buffer_to_file(MainView
* mainview
)
3546 fprintf(stderr
, "write:*%s*\n", mainview
->file_name
);
3547 saveCurrentData(mainview
);
3549 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
));
3550 /*update ord value in database for all nodes*/
3551 gtk_tree_model_foreach(GTK_TREE_MODEL(model
),(GtkTreeModelForeachFunc
) foreach_func_update_ord
,mainview
);
3553 setBusy(mainview
, 1);
3557 snprintf(tq
, sizeof(tq
), "DROP TABLE %s", misctable_name
);
3558 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3560 snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", misctable_name
, misctable
);
3561 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3563 gint panedPos
= gtk_paned_get_position(GTK_PANED(mainview
->hpaned
));
3565 snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('leftPanedPos', '%d');", misctable_name
, panedPos
);
3566 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3570 if (mainview
->newnodedialog_createchild
== FALSE
)
3572 snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('newNodeDlgCreateChild', '%d');", misctable_name
, nndcc
);
3573 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3575 snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('viewFlags', '%d');", misctable_name
, mainview
->viewflags
);
3576 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3578 nodeData
*node
= getSelectedNode(mainview
);
3582 snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('selectedNode', '%d');", misctable_name
, node
->sql3id
);
3583 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3587 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->eraser_tb
)) == TRUE
)
3589 bsize
=mainview
->brushsize_backup
;
3593 bsize
=sketchwidget_get_brushsize(mainview
->sk
);
3595 snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('brushSize', '%d');", misctable_name
, bsize
);
3596 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3600 hildon_color_button_get_color(HILDON_COLOR_BUTTON(mainview
->colorbutton
), &col
);
3601 unsigned long bcol
=((col
.red
>> 8) << 16) | ((col
.green
>> 8) << 8) | (col
.blue
>> 8);
3603 GdkColor
*col
= hildon_color_button_get_color(HILDON_COLOR_BUTTON(mainview
->colorbutton
));
3604 unsigned long bcol
=((col
->red
>> 8) << 16) | ((col
->green
>> 8) << 8) | (col
->blue
>> 8);
3607 /* fprintf(stderr, "BRUSHCOLOR is %d (%d,%d,%d)\n", bcol, col->red, col->green, col->blue);*/
3608 snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('brushColor', '%lu');", misctable_name
, bcol
);
3609 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3611 snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('dataVersion', '%d');", misctable_name
, datatableversion
);
3612 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3614 snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('checklistVersion', '%d');", misctable_name
, checklisttableversion
);
3615 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3617 snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_backupname
);
3618 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3619 snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", datatable_backupname
, datatable
);
3620 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3622 fprintf(stderr
, "ERROR creating backup table!\n");
3623 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, "Error 1");
3625 setBusy(mainview
, 2);
3628 snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", datatable_backupname
, datatable_name
);
3629 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3631 fprintf(stderr
, "ERROR backing up table!\n");
3632 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, "Error 2");
3634 setBusy(mainview
, 2);
3637 snprintf(tq
, sizeof(tq
), "DELETE FROM %s", datatable_name
);
3638 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3640 snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", datatable_name
, datatable_tmpname
);
3641 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3643 fprintf(stderr
, "ERROR saving table!\n");
3644 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, "Error 3");
3646 snprintf(tq
, sizeof(tq
), "DELETE FROM %s", datatable_name
);
3647 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3649 snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", datatable_name
, datatable_backupname
);
3650 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3652 fprintf(stderr
, "ERROR restoring backup! data lost!\n");
3655 setBusy(mainview
, 2);
3659 snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_backupname
);
3660 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3663 snprintf(tq
, sizeof(tq
), "DROP TABLE %s", checklisttable_backupname
);
3664 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3665 snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", checklisttable_backupname
, checklisttable
);
3666 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3668 fprintf(stderr
, "ERROR creating backup table! (checklist)\n");
3669 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, "Error 4");
3671 setBusy(mainview
, 2);
3675 snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", checklisttable_backupname
, checklisttable_name
);
3676 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3678 fprintf(stderr
, "ERROR backing up table! (checklist)\n");
3679 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, "Error 5");
3681 setBusy(mainview
, 2);
3684 snprintf(tq
, sizeof(tq
), "DELETE FROM %s", checklisttable_name
);
3685 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3687 snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", checklisttable_name
, checklisttable_tmpname
);
3688 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3690 fprintf(stderr
, "ERROR saving table! (checklist)\n");
3691 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, "Error 6");
3693 snprintf(tq
, sizeof(tq
), "DELETE FROM %s", checklisttable_name
);
3694 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3696 snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", checklisttable_name
, checklisttable_backupname
);
3697 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3699 fprintf(stderr
, "ERROR restoring backup! data lost! (checklist)\n");
3701 setBusy(mainview
, 2);
3705 snprintf(tq
, sizeof(tq
), "DROP TABLE %s", checklisttable_backupname
);
3706 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3708 mainview
->file_edited
= FALSE
;
3709 setBusy(mainview
, 2);
3710 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), GTK_STOCK_SAVE
, _("Saved"));
3714 void callback_checklist_toggled(GtkCellRendererToggle
*cell_renderer
, gchar
*path
, GtkWidget
*source
)
3716 gtk_object_set_data(GTK_OBJECT(source
), "edited", TRUE
);
3719 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(source
));
3720 GtkTreePath
*treepath
= gtk_tree_path_new_from_string(path
);
3721 if(gtk_tree_model_get_iter(model
, &iter
, treepath
))
3724 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, CHECKNODE_CHECKED
, &val
, -1);
3725 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_CHECKED
, !val
, -1);
3727 gtk_tree_path_free(treepath
);
3730 void callback_checklist_edited(GtkCellRendererToggle
*cell_renderer
, gchar
*arg1
, gchar
*arg2
, GtkWidget
*source
)
3732 gtk_object_set_data(GTK_OBJECT(source
), "edited", TRUE
);
3735 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(source
));
3736 GtkTreePath
*treepath
= gtk_tree_path_new_from_string(arg1
);
3737 if(gtk_tree_model_get_iter(model
, &iter
, treepath
))
3739 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_TEXT
, arg2
, -1);
3741 gtk_tree_path_free(treepath
);
3744 void callback_checklist_change(GtkTreeSelection
*selection
, MainView
*mainview
)
3746 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3748 g_signal_handlers_block_by_func(mainview
->bold_tb
, callback_fontstyle
, mainview
->bold_tb
);
3749 g_signal_handlers_block_by_func(mainview
->strikethru_tb
, callback_fontstyle
, mainview
->strikethru_tb
);
3750 g_signal_handlers_block_by_func(mainview
->check_tb
, callback_fontstyle
, mainview
->check_tb
);
3752 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->bold_tb
), FALSE
);
3753 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->strikethru_tb
), FALSE
);
3754 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->check_tb
), FALSE
);
3756 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
3757 GList
* l
=gtk_tree_selection_get_selected_rows(selection
, NULL
);
3759 gboolean gotit
=FALSE
;
3764 GtkTreePath
*path
=cur
->data
;
3769 if (gtk_tree_model_get_iter(model
, &iter
, path
))
3771 gint styletoset_weight
;
3772 gboolean styletoset_strike
;
3775 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, CHECKNODE_BOLD
, &styletoset_weight
, CHECKNODE_STRIKE
, &styletoset_strike
, CHECKNODE_CHECKED
, &ischecked
, -1);
3776 if (styletoset_weight
==PANGO_WEIGHT_BOLD
) gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->bold_tb
), TRUE
);
3777 if (styletoset_strike
==TRUE
) gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->strikethru_tb
), TRUE
);
3778 if (ischecked
==TRUE
) gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->check_tb
), TRUE
);
3782 gtk_tree_path_free(path
);
3788 g_signal_handlers_unblock_by_func(mainview
->bold_tb
, callback_fontstyle
, mainview
->bold_tb
);
3789 g_signal_handlers_unblock_by_func(mainview
->strikethru_tb
, callback_fontstyle
, mainview
->strikethru_tb
);
3790 g_signal_handlers_unblock_by_func(mainview
->check_tb
, callback_fontstyle
, mainview
->check_tb
);
3793 void callback_checklist_paste(MainView
*mainview
)
3795 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3797 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
3798 GtkTreeIter toplevel
;
3799 gchar
*pasted_text
= gtk_clipboard_wait_for_text(mainview
->clipboard
);
3801 gtk_list_store_append(GTK_LIST_STORE(model
), &toplevel
);
3802 gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_CHECKED
, FALSE
, CHECKNODE_TEXT
, pasted_text
, -1);
3803 gtk_object_set_data(GTK_OBJECT(mainview
->listview
), "edited", TRUE
);
3804 g_free(pasted_text
);
3807 void callback_checklist_add(GtkAction
*action
, MainView
*mainview
)
3809 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3811 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
3812 GtkTreeIter toplevel
;
3813 gtk_list_store_append(GTK_LIST_STORE(model
), &toplevel
);
3815 gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_CHECKED
, FALSE
, CHECKNODE_TEXT
, "", -1);
3816 GtkTreePath
*path
= gtk_tree_model_get_path(model
, &toplevel
);
3819 gtk_tree_view_set_cursor(GTK_TREE_VIEW(mainview
->listview
), path
, mainview
->listtextcol
, TRUE
);
3820 gtk_tree_path_free(path
);
3823 gtk_object_set_data(GTK_OBJECT(mainview
->listview
), "edited", TRUE
);
3826 void callback_checklist_delete(GtkAction
*action
, MainView
*mainview
)
3828 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3830 if (gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
)))==0)
3832 hildon_banner_show_information(GTK_WIDGET(mainview
->data
->main_view
), NULL
, _("Select items first"));
3836 GtkWidget
*dialog
, *label
, *but_ok
, *but_cancel
;
3838 dialog
= gtk_dialog_new();
3840 label
= gtk_label_new(_("Delete selected items?"));
3842 but_ok
= gtk_button_new_with_label(_("Yes, Delete"));
3843 but_cancel
= gtk_button_new_with_label(_("Cancel"));
3845 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), but_ok
);
3846 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->action_area
), but_cancel
);
3848 gtk_object_set_user_data(GTK_OBJECT(dialog
), mainview
);
3850 gtk_signal_connect_object(GTK_OBJECT(but_cancel
), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy
), dialog
);
3851 g_signal_connect(G_OBJECT(but_ok
), "clicked", G_CALLBACK(callback_checklist_delete_real
), dialog
);
3853 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), label
);
3855 gtk_widget_show_all(dialog
);
3856 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
3859 void callback_checklist_delete_real(GtkAction
*action
, gpointer data
)
3861 GtkWidget
*dialog
= data
;
3862 MainView
*mainview
= gtk_object_get_user_data(GTK_OBJECT(dialog
));
3863 gtk_widget_destroy(dialog
);
3865 GtkTreeModel
*model
=gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
3866 GList
* l
=gtk_tree_selection_get_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
)), NULL
);
3868 GList
* rowrefs
=NULL
;
3872 GtkTreePath
*path
=cur
->data
;
3875 if (gtk_tree_model_get_iter(model
, &iter
, path
))
3877 GtkTreeRowReference
*rowref
= gtk_tree_row_reference_new(model
, path
);
3878 rowrefs
=g_list_append(rowrefs
, rowref
);
3880 gtk_tree_path_free(path
);
3885 g_object_ref(model
);
3886 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->listview
), NULL
);
3891 GtkTreeRowReference
*rowref
=cur
->data
;
3892 GtkTreePath
*path
= gtk_tree_row_reference_get_path(rowref
);
3896 if (gtk_tree_model_get_iter(model
, &iter
, path
)) gtk_list_store_remove(GTK_LIST_STORE(model
), &iter
);
3897 gtk_tree_path_free(path
);
3899 gtk_tree_row_reference_free(rowref
);
3902 g_list_free(rowrefs
);
3904 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->listview
), model
);
3905 g_object_unref(model
);
3906 gtk_object_set_data(GTK_OBJECT(mainview
->listview
), "edited", TRUE
);