2 * This file is part of MaePad
3 * Copyright (c) 2010 Thomas Perl <thp@thpinfo.com>
4 * http://thpinfo.com/2010/maepad/
7 * Copyright (c) 2006-2008 Kemal Hadimli
8 * Copyright (c) 2008 Thomas Perl
10 * This software is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1 of
13 * the License, or (at your option) any later version.
15 * This software is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this software; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 #include <ui/callbacks.h>
28 #include <ui/interface.h>
30 #include <gdk/gdkkeysyms.h>
36 * strlen needed from string.h
39 #include <sys/types.h>
47 #include <hildon/hildon.h>
48 #include <hildon/hildon-banner.h>
49 #include <hildon/hildon-note.h>
50 #include <hildon/hildon-font-selection-dialog.h>
51 #include <tablet-browser-interface.h>
53 #include <libgnomevfs/gnome-vfs.h>
55 #include <sharingdialog/sharing-dialog.h>
57 #include "sketchwidget.h"
59 #include "../he/he-about-dialog.h"
60 #include "../he/he-simple-color-dialog.h"
63 * "Busy" status handling
65 * Use "busy_reset" to reset the busy status (turn off)
66 * Use "busy_enter" when starting time-consuming processing
67 * Use "busy_leave" when processing has been finished
75 /* Don't use this directly, but make use of the macros defined below */
76 void set_busy(MainView
* mainview
, SetBusyType update
);
78 #define busy_reset(mainview) set_busy(mainview, BUSY_RESET)
79 #define busy_enter(mainview) set_busy(mainview, BUSY_INCREMENT)
80 #define busy_leave(mainview) set_busy(mainview, BUSY_DECREMENT)
86 void checklist_abort_longpress(MainView
* mainview
);
87 gboolean
read_file_to_buffer(MainView
* mainview
);
88 void write_buffer_to_file(MainView
* mainview
);
89 void new_node_dialog(nodeType typ
, MainView
* mainview
);
90 gboolean
foreach_func_update_ord (GtkTreeModel
*model
,GtkTreePath
*path
,GtkTreeIter
*iter
, MainView
*mainview
);
91 void move_nodes_up(GtkTreeModel
* model
, GtkTreeRowReference
* topnode
, GtkTreeRowReference
* newtop
);
92 GtkTreeRowReference
*iter2ref(GtkTreeModel
* model
, GtkTreeIter
* iter
);
93 gboolean
exec_command_on_db(MainView
*mainview
,char sql_string
[]);
94 int get_node_id_on_tmp_db(GtkTreeModel
*model
,GtkTreeIter
*iter
);
95 gint
get_branch_node_index(GtkTreePath
*path
);
96 gboolean
move_node(MainView
*mainview
,GtkTreeIter
*new_parent
,GtkTreeIter
*item_to_move
,GtkTreeIter
*item_befor
);
97 gboolean
tree_model_iter_prev(GtkTreeModel
*tree_model
,GtkTreeIter
*iter
);
98 gboolean
show_confirmation(MainView
* mainview
, gchar
* question
);
102 gboolean
callback_node_view_window_state(GtkWidget
* window
,
103 GdkEventWindowState
* event
, gpointer user_data
)
105 MainView
* mainview
= (MainView
*)user_data
;
106 GtkWidget
* sketch_scroll
= NULL
;
108 if (mainview
->toolbar
== NULL
|| mainview
->sk
== NULL
) {
112 sketch_scroll
= GTK_WIDGET(sketchwidget_get_mainwidget(mainview
->sk
));
114 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
) {
115 if (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) {
116 gtk_widget_hide(mainview
->toolbar
);
117 gtk_scrolled_window_set_policy(
118 GTK_SCROLLED_WINDOW(sketch_scroll
),
122 gtk_widget_show(mainview
->toolbar
);
123 gtk_scrolled_window_set_policy(
124 GTK_SCROLLED_WINDOW(sketch_scroll
),
125 GTK_POLICY_AUTOMATIC
,
126 GTK_POLICY_AUTOMATIC
);
133 void set_busy(MainView
* mainview
, SetBusyType update
)
137 mainview
->busyrefcount
= 0;
140 mainview
->busyrefcount
++;
143 if (mainview
->busyrefcount
> 0) {
144 mainview
->busyrefcount
--;
148 g_assert_not_reached();
152 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(mainview
->data
->main_view
), (mainview
->busyrefcount
> 0));
153 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(mainview
->data
->node_view
), (mainview
->busyrefcount
> 0));
156 void prepareUIforNodeChange(MainView
* mainview
, nodeType typ
)
158 gtk_widget_set_sensitive(GTK_WIDGET(mainview
->undo_tb
), TRUE
);
159 gtk_widget_set_sensitive(GTK_WIDGET(mainview
->redo_tb
), TRUE
);
161 if (typ
== NODE_TEXT
)
163 gtk_widget_show(GTK_WIDGET(mainview
->font_tb
));
164 gtk_widget_show(GTK_WIDGET(mainview
->bold_tb
));
165 gtk_widget_show(GTK_WIDGET(mainview
->italic_tb
));
166 gtk_widget_show(GTK_WIDGET(mainview
->underline_tb
));
167 gtk_widget_show(GTK_WIDGET(mainview
->bullet_tb
));
168 gtk_widget_show(mainview
->tools_font
);
172 gtk_widget_hide(GTK_WIDGET(mainview
->font_tb
));
173 gtk_widget_hide(GTK_WIDGET(mainview
->bold_tb
));
174 gtk_widget_hide(GTK_WIDGET(mainview
->italic_tb
));
175 gtk_widget_hide(GTK_WIDGET(mainview
->underline_tb
));
176 gtk_widget_hide(GTK_WIDGET(mainview
->bullet_tb
));
177 gtk_widget_hide(mainview
->tools_font
);
180 if (typ
== NODE_SKETCH
)
182 /* gtk_widget_show(GTK_WIDGET(mainview->colorbutton_tb));*/
183 gtk_widget_show(GTK_WIDGET(mainview
->eraser_tb
));
184 gtk_widget_show(GTK_WIDGET(mainview
->brushsize_tb
));
185 gtk_widget_show(GTK_WIDGET(mainview
->sketchlines_tb
));
186 gtk_widget_show(GTK_WIDGET(mainview
->shape_tb
));
187 gtk_widget_show(GTK_WIDGET(mainview
->sharing_tb
));
188 gtk_widget_show(mainview
->tools_color
);
189 gtk_widget_show(mainview
->tools_brushsize
);
190 gtk_widget_show(mainview
->tools_pagestyle
);
191 gtk_widget_show(mainview
->tools_shape
);
192 gtk_widget_show(mainview
->tools_pressure
);
196 /* gtk_widget_hide(GTK_WIDGET(mainview->colorbutton_tb));*/
197 gtk_widget_hide(GTK_WIDGET(mainview
->eraser_tb
));
198 gtk_widget_hide(GTK_WIDGET(mainview
->brushsize_tb
));
199 gtk_widget_hide(GTK_WIDGET(mainview
->sketchlines_tb
));
200 gtk_widget_hide(GTK_WIDGET(mainview
->shape_tb
));
201 gtk_widget_hide(GTK_WIDGET(mainview
->sharing_tb
));
202 gtk_widget_hide(mainview
->tools_color
);
203 gtk_widget_hide(mainview
->tools_brushsize
);
204 gtk_widget_hide(mainview
->tools_pagestyle
);
205 gtk_widget_hide(mainview
->tools_shape
);
206 gtk_widget_hide(mainview
->tools_pressure
);
209 if (typ
== NODE_CHECKLIST
)
211 gtk_widget_show(GTK_WIDGET(mainview
->bold_tb
));
212 gtk_widget_show(GTK_WIDGET(mainview
->strikethru_tb
));
213 gtk_widget_show(GTK_WIDGET(mainview
->check_tb
));
214 gtk_widget_show(GTK_WIDGET(mainview
->checkadd_tb
));
215 gtk_widget_show(GTK_WIDGET(mainview
->checkedit_tb
));
216 gtk_widget_show(GTK_WIDGET(mainview
->checkdel_tb
));
217 gtk_widget_hide(GTK_WIDGET(mainview
->undo_tb
));
218 gtk_widget_hide(GTK_WIDGET(mainview
->redo_tb
));
222 gtk_widget_hide(GTK_WIDGET(mainview
->strikethru_tb
));
223 gtk_widget_hide(GTK_WIDGET(mainview
->check_tb
));
224 gtk_widget_hide(GTK_WIDGET(mainview
->checkadd_tb
));
225 gtk_widget_hide(GTK_WIDGET(mainview
->checkedit_tb
));
226 gtk_widget_hide(GTK_WIDGET(mainview
->checkdel_tb
));
227 gtk_widget_show(GTK_WIDGET(mainview
->undo_tb
));
228 gtk_widget_show(GTK_WIDGET(mainview
->redo_tb
));
231 if (typ
== NODE_TEXT
)
233 gtk_widget_hide(GTK_WIDGET(mainview
->colorbutton_tb
));
234 gtk_widget_hide(sketchwidget_get_mainwidget(mainview
->sk
));
235 gtk_widget_hide(mainview
->listscroll
);
236 gtk_widget_show(GTK_WIDGET(mainview
->scrolledwindow
));
237 gtk_widget_show(mainview
->tools_item
);
239 else if (typ
== NODE_SKETCH
)
241 gtk_widget_show(GTK_WIDGET(mainview
->colorbutton_tb
));
242 gtk_widget_hide(GTK_WIDGET(mainview
->scrolledwindow
));
243 gtk_widget_hide(mainview
->listscroll
);
244 gtk_widget_show(sketchwidget_get_mainwidget(mainview
->sk
));
245 gtk_widget_show(mainview
->tools_item
);
247 else if (typ
== NODE_CHECKLIST
)
249 gtk_widget_show(GTK_WIDGET(mainview
->colorbutton_tb
));
250 gtk_widget_hide(GTK_WIDGET(mainview
->scrolledwindow
));
251 gtk_widget_hide(sketchwidget_get_mainwidget(mainview
->sk
));
252 gtk_widget_hide(mainview
->tools_item
);
253 gtk_widget_show(mainview
->listscroll
);
257 gtk_widget_hide(GTK_WIDGET(mainview
->colorbutton_tb
));
258 gtk_widget_hide(GTK_WIDGET(mainview
->scrolledwindow
));
259 gtk_widget_hide(sketchwidget_get_mainwidget(mainview
->sk
));
260 gtk_widget_hide(mainview
->tools_item
);
261 gtk_widget_hide(mainview
->listscroll
);
265 nodeData
*getSelectedNode(MainView
* mainview
)
272 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
274 if (!gtk_tree_selection_get_selected(selection
, &model
, &iter
))
277 gtk_tree_model_get(model
, &iter
, NODE_DATA
, &nd
, -1);
282 void saveCurrentData(MainView
* mainview
)
284 nodeData
*selnode
= getSelectedNode(mainview
);
285 saveDataToNode(mainview
, selnode
);
288 void saveDataToNode(MainView
* mainview
, nodeData
*selnode
)
294 (selnode
->typ
== NODE_SKETCH
&& sketchwidget_get_edited(mainview
->sk
) == FALSE
) ||
295 (selnode
->typ
== NODE_TEXT
&& wp_text_buffer_is_modified(mainview
->buffer
)==FALSE
) ||
296 (selnode
->typ
== NODE_CHECKLIST
&& mainview
->checklist_edited
==FALSE
)
299 maepad_message("node not edited, not saving");
303 mainview
->file_edited
= TRUE
;
305 busy_enter(mainview
);
306 maepad_debug("saveDataToNode working");
308 gboolean goterr
= TRUE
;
309 gchar
*textdata
= NULL
;
310 GdkPixbuf
*pixbuf
= NULL
;
311 gchar
*sketchdata
= NULL
;
315 if (selnode
->typ
== NODE_TEXT
)
318 GtkTextIter start
, end
;
319 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(mainview
->buffer
), &start
, &end
);
320 textdata
= gtk_text_buffer_serialize_rich_text(GTK_TEXT_BUFFER(mainview
->buffer
), &start
, &end
, &datalen
);
323 GString
*gstr
=g_string_sized_new(4096);
324 wp_text_buffer_save_document(mainview
->buffer
, (WPDocumentSaveCallback
)(wp_savecallback
), gstr
);
327 textdata
=g_string_free(gstr
, FALSE
);
329 /* g_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);*/
330 g_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
);
332 else if (selnode
->typ
== NODE_SKETCH
)
335 GdkPixmap
*skpix
= sketchwidget_get_Pixmap(mainview
->sk
);
336 GtkWidget
*skdr
= sketchwidget_get_drawingarea(mainview
->sk
);
338 pixbuf
= gdk_pixbuf_get_from_drawable(NULL
, GDK_DRAWABLE(skpix
), NULL
, 0, 0, 0, 0, skdr
->allocation
.width
, skdr
->allocation
.height
);
341 maepad_warning("error saving: pixbuf is null");
346 GdkPixbuf
*pixbuf2
= sketchwidget_trim_image(pixbuf
, skdr
->allocation
.width
, skdr
->allocation
.height
, &w
, &h
, FALSE
);
350 if (gdk_pixbuf_save_to_buffer(pixbuf2
, &sketchdata
, &datalen
, "png", &err
, NULL
) == FALSE
)
354 maepad_warning("Error saving sketch: %s", err
->message
);
357 gdk_pixbuf_unref(pixbuf2
);
360 g_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
);
361 maepad_debug("storing sketch in db: %d bytes", datalen
);
362 if (skpix
&& G_IS_OBJECT(skpix
)) g_object_unref(skpix
);
364 else if (selnode
->typ
== NODE_CHECKLIST
)
366 g_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
);
371 sqlite3_stmt
*stmt
= NULL
;
373 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
377 maepad_warning("Error updating: %s", sqlite3_errmsg(mainview
->db
));
380 if (selnode
->typ
== NODE_TEXT
)
381 sqlite3_bind_text(stmt
, 1, textdata
, datalen
, /*strlen(textdata),*/ SQLITE_TRANSIENT
);
382 else if (selnode
->typ
== NODE_SKETCH
)
383 sqlite3_bind_blob(stmt
, 1, sketchdata
, datalen
, SQLITE_TRANSIENT
);
386 while(rc
== SQLITE_BUSY
)
388 rc
= sqlite3_step(stmt
);
389 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
392 sqlite3_finalize(stmt
);
394 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
396 maepad_warning("Error saving node: %s", sqlite3_errmsg(mainview
->db
));
400 if (selnode
->typ
== NODE_TEXT
)
401 gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(mainview
->buffer
), FALSE
);
402 else if (selnode
->typ
== NODE_SKETCH
)
403 sketchwidget_set_edited(mainview
->sk
, FALSE
);
404 else if (selnode
->typ
== NODE_CHECKLIST
)
405 mainview
->checklist_edited
= FALSE
;
410 while(goterr
==FALSE
&& selnode
->typ
== NODE_CHECKLIST
)
412 GtkTreeModel
*model
=gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
415 g_snprintf(tq
, sizeof(tq
), "DELETE FROM %s WHERE nodeid=%d", checklisttable_tmpname
, selnode
->sql3id
);
416 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
419 if (gtk_tree_model_get_iter_first(model
, &iter
)==FALSE
) break;
423 gint styletoset_weight
;
424 gboolean styletoset_strike
;
430 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);
433 if (color
!=NULL
&& strcmp(color
, "(null)")!=0 && gdk_color_parse(color
, &tmpcol
))
435 col
=((tmpcol
.red
>>8)<<16)|((tmpcol
.green
>>8)<<8)|(tmpcol
.blue
>>8);
439 if (ischecked
) style
|=CHECKSTYLE_CHECKED
;
440 if (styletoset_weight
==PANGO_WEIGHT_BOLD
) style
|=CHECKSTYLE_BOLD
;
441 if (styletoset_strike
) style
|=CHECKSTYLE_STRIKE
;
443 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s (nodeid, name, style, color, ord) VALUES(%d, ?, %d, %lu, 0)", checklisttable_tmpname
, selnode
->sql3id
, style
, col
);
444 sqlite3_stmt
*stmt
= NULL
;
446 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
451 maepad_warning("Error while saving checklist: %s", sqlite3_errmsg(mainview
->db
));
454 sqlite3_bind_text(stmt
, 1, text
, strlen(text
), SQLITE_TRANSIENT
);
457 while(rc
== SQLITE_BUSY
)
459 rc
= sqlite3_step(stmt
);
460 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
463 sqlite3_finalize(stmt
);
465 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
468 maepad_warning("Error while saving checklist (2): %s", sqlite3_errmsg(mainview
->db
));
474 }while(gtk_tree_model_iter_next(model
, &iter
)==TRUE
);
485 show_banner(mainview
, _("Error saving memo"));
487 busy_leave(mainview
);
490 gboolean
callback_treeview_button_press(GtkTreeView
* treeview
, GdkEventButton
* event
, gpointer user_data
)
492 MainView
* mainview
= (MainView
*)user_data
;
495 if (mainview
->node_list_longpress_path
!= NULL
) {
496 /* Forget old, remembered tree path for longpress */
497 gtk_tree_path_free(mainview
->node_list_longpress_path
);
498 mainview
->node_list_longpress_path
= NULL
;
501 if (gtk_tree_view_get_path_at_pos(treeview
,
502 event
->x
, event
->y
, &path
, NULL
, NULL
, NULL
)) {
504 * Save this path in case we open the longpress menu to
505 * set the cursor in the treeview to the correct row.
507 * See on_node_menu_show() on how this is further used.
509 mainview
->node_list_longpress_path
= path
;
512 mainview
->can_show_node_view
= TRUE
;
517 void callback_treeview_celldatafunc(GtkTreeViewColumn
* tree_column
, GtkCellRenderer
* cell
, GtkTreeModel
* tree_model
, GtkTreeIter
* iter
, gpointer data
)
519 MainView
*mainview
= ( MainView
* ) data
;
520 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
524 gtk_tree_model_get(tree_model
, iter
, NODE_DATA
, &nd
, -1);
528 if (nd
->namepix
== NULL
)
530 g_object_set(cell
, "visible", FALSE
, NULL
);
534 g_object_set(cell
, "visible", TRUE
, NULL
);
535 g_object_set(cell
, "width", SKETCHNODE_RX
, NULL
);
536 g_object_set(cell
, "height", SKETCHNODE_RY
, NULL
);
540 void callback_treeview_change(GtkTreeSelection
* selection
, gpointer data
)
542 MainView
*mainview
= (MainView
*) data
;
543 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
545 nodeData
*nd
= getSelectedNode(mainview
);
547 gchar
* nodeName
= _("View memo");
549 if (nd
!= NULL
&& nd
->name
!= NULL
) {
553 /* Show node view with selected node */
554 gtk_window_set_title(GTK_WINDOW(mainview
->data
->node_view
),
557 if (mainview
->can_show_node_view
) {
558 gtk_widget_show(GTK_WIDGET(mainview
->data
->node_view
));
561 /* Make sure we don't accidentally collapse any nodes */
562 gtk_tree_view_expand_all(GTK_TREE_VIEW(mainview
->treeview
));
565 if (mainview
->cansel_time
>0 && mainview
->cansel_time
+1.0<tm
) mainview
->cansel_node
=NULL
;
569 if (mainview
->cansel_node
!=NULL
)
571 maepad_debug("[SELLOGIC] saving %d to unselect all nodes", (mainview
->cansel_node
)->sql3id
);
572 saveDataToNode(mainview
, (mainview
->cansel_node
));
573 mainview
->cansel_node
=NULL
;
578 if (mainview
->cansel_node
!=NULL
)
580 if (nd
->sql3id
== (mainview
->cansel_node
)->sql3id
)
582 mainview
->cansel_node
=NULL
;
583 maepad_debug("[SELLOGIC] doubly selected %d, doing nothing", nd
->sql3id
);
584 prepareUIforNodeChange(mainview
, nd
->typ
);
589 maepad_debug("[SELLOGIC] saving %d to load new node", (mainview
->cansel_node
)->sql3id
);
590 saveDataToNode(mainview
, (mainview
->cansel_node
));
591 mainview
->cansel_node
=NULL
;
595 if (nd
== NULL
) return;
597 busy_enter(mainview
);
599 gboolean goterr
= TRUE
;
600 char *textdata
= NULL
;
602 int blobsize
= 0, textsize
= 0;
606 g_snprintf(tq
, sizeof(tq
), "SELECT bodytype, body, bodyblob, flags FROM %s WHERE nodeid=%d", datatable_tmpname
, nd
->sql3id
);
607 sqlite3_stmt
*stmt
= NULL
;
609 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
613 maepad_warning("Error reading (1): %s", sqlite3_errmsg(mainview
->db
));
618 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
620 rc
= sqlite3_step(stmt
);
621 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
623 else if (rc
== SQLITE_ROW
)
625 nd
->typ
= sqlite3_column_int(stmt
, 0);
626 nd
->flags
= sqlite3_column_int(stmt
, 3);
628 prepareUIforNodeChange(mainview
, nd
->typ
);
629 if (nd
->typ
== NODE_TEXT
)
631 gboolean file_edited_backup
= mainview
->file_edited
;
633 blobsize
= sqlite3_column_bytes(stmt
, 2);
634 blob
= (char *)sqlite3_column_blob(stmt
, 2);
636 textdata
= (char *)sqlite3_column_text(stmt
, 1);
637 textsize
= sqlite3_column_bytes(stmt
, 1);
639 /* gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mainview->buffer), "", -1);*/
640 wp_text_buffer_reset_buffer(mainview
->buffer
, TRUE
);
642 gboolean richtext
=FALSE
;
647 gboolean oldway
=FALSE
;
651 strncpy(tst
, blob
, 8);
653 if (strcmp(tst
, "RICHTEXT")==0) oldway
=TRUE
;
659 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(mainview
->buffer
), &iter
);
660 gtk_text_buffer_deserialize_rich_text(GTK_TEXT_BUFFER(mainview
->buffer
), &iter
, blob
, blobsize
, TRUE
, &err
);
674 wp_text_buffer_load_document_begin(mainview
->buffer
, TRUE
);
675 wp_text_buffer_load_document_write(mainview
->buffer
, blob
, blobsize
);
676 wp_text_buffer_load_document_end(mainview
->buffer
);
680 if (richtext
==FALSE
&& !(textdata
== NULL
|| g_utf8_validate(textdata
, textsize
, NULL
) == FALSE
))
682 /* gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mainview->buffer), textdata, textsize);*/
683 wp_text_buffer_load_document_begin(mainview
->buffer
, FALSE
);
684 wp_text_buffer_load_document_write(mainview
->buffer
, textdata
, textsize
);
685 wp_text_buffer_load_document_end(mainview
->buffer
);
688 wp_text_buffer_enable_rich_text(mainview
->buffer
, TRUE
);
689 hildon_check_button_set_active(HILDON_CHECK_BUTTON(mainview
->menu_button_wordwrap
),
690 (nd
->flags
& NODEFLAG_WORDWRAP
)?(TRUE
):(FALSE
));
692 gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(mainview
->buffer
), FALSE
); /*we probably don't need this*/
694 callback_undotoggle((gpointer
)mainview
->buffer
, FALSE
, mainview
); /*we need these*/
695 callback_redotoggle((gpointer
)mainview
->buffer
, FALSE
, mainview
);
697 if (file_edited_backup
==FALSE
) mainview
->file_edited
=FALSE
; /*textview changed event toggles this?*/
700 else if (nd
->typ
== NODE_SKETCH
)
702 sketchwidget_wipe_undo(mainview
->sk
);
704 /* Disable squared and filled mode when opening a sketch */
705 hildon_check_button_set_active(HILDON_CHECK_BUTTON(mainview
->menu_button_square
), FALSE
);
706 hildon_check_button_set_active(HILDON_CHECK_BUTTON(mainview
->menu_button_filled
), FALSE
);
708 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->shapemenuitems
[1]), TRUE
);
709 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->shapemenuitems
[0]), TRUE
);
711 blobsize
= sqlite3_column_bytes(stmt
, 2);
712 blob
= (char *)sqlite3_column_blob(stmt
, 2);
713 gboolean clear
= TRUE
;
719 maepad_debug("blob size: %d", blobsize
);
720 GdkPixbufLoader
*pl
= gdk_pixbuf_loader_new_with_type("png", NULL
);
723 gdk_pixbuf_loader_write(pl
, (guchar
*) blob
, blobsize
, &err
);
726 maepad_warning("Error loading sketch: %s", err
->message
);
730 gdk_pixbuf_loader_close(pl
, NULL
);
731 GdkPixbuf
*pixbuf
= gdk_pixbuf_loader_get_pixbuf(pl
);
733 if (GDK_IS_PIXBUF(pixbuf
))
735 GtkWidget
*skdr
= sketchwidget_get_drawingarea(mainview
->sk
);
736 GtkPixmap
*skpix
= (GtkPixmap
*) sketchwidget_get_Pixmap(mainview
->sk
);
738 int w
=gdk_pixbuf_get_width(pixbuf
);
739 int h
=gdk_pixbuf_get_height(pixbuf
);
740 if (w
!=skdr
->allocation
.width
|| h
!=skdr
->allocation
.height
)
742 if (w
>skdr
->allocation
.width
) w
=skdr
->allocation
.width
;
743 if (h
>skdr
->allocation
.height
) h
=skdr
->allocation
.height
;
744 sketchwidget_clear_real(mainview
->sk
);
746 gdk_draw_pixbuf(GDK_DRAWABLE(skpix
), NULL
, pixbuf
, 0, 0, 0, 0, w
, h
, GDK_RGB_DITHER_NONE
, 0, 0);
751 if (skpix
&& G_IS_OBJECT(skpix
)) g_object_unref(skpix
);
755 maepad_warning("Error loading pixbuf");
761 maepad_message("Clearing sketch widget");
762 sketchwidget_clear_real(mainview
->sk
);
764 gtk_widget_queue_draw(sketchwidget_get_drawingarea(mainview
->sk
));
766 else if (nd
->typ
== NODE_CHECKLIST
)
768 mainview
->checklist_edited
= FALSE
;
769 GtkTreeModel
*model
=gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
771 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->listview
), NULL
);
772 gtk_list_store_clear(GTK_LIST_STORE(model
));
774 g_snprintf(tq
, sizeof(tq
), "SELECT name, style, color FROM %s WHERE nodeid=%d ORDER BY ord, idx", checklisttable_tmpname
, nd
->sql3id
);
775 sqlite3_stmt
*stmt2
= NULL
;
777 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt2
, &dum
);
780 maepad_warning("Error reading checklist (1) %s", sqlite3_errmsg(mainview
->db
));
786 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
788 rc
= sqlite3_step(stmt2
);
789 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
791 else if (rc
== SQLITE_ROW
)
793 char *textdata
= (char *)sqlite3_column_text(stmt2
, 0);
794 int style
= sqlite3_column_int(stmt2
, 1);
795 unsigned long col
= sqlite3_column_int(stmt2
, 2);
797 GtkTreeIter toplevel
;
798 gtk_list_store_append(GTK_LIST_STORE(model
), &toplevel
);
799 gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_TEXT
, textdata
, CHECKNODE_CHECKED
, FALSE
, -1);
800 if ((style
& CHECKSTYLE_CHECKED
)>0) {
801 gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_CHECKED
, TRUE
, -1);
802 gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_ICON_NAME
, "widgets_tickmark_list", -1);
804 if ((style
& CHECKSTYLE_BOLD
)>0) gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_BOLD
, PANGO_WEIGHT_BOLD
, -1);
805 if ((style
& CHECKSTYLE_STRIKE
)>0) gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_STRIKE
, TRUE
, -1);
810 g_snprintf(tmp
, sizeof(tmp
), "#%02lx%02lx%02lx", ((col
& 0xFF0000) >> 16), ((col
& 0xFF00) >> 8), (col
& 0xFF));
811 gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_COLOR
, tmp
, -1);
816 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
818 maepad_warning("Error reading checklist (2): %s", sqlite3_errmsg(mainview
->db
));
822 sqlite3_finalize(stmt2
);
825 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->listview
), model
);
826 g_object_unref(model
);
829 if ((nd
->flags
& NODEFLAG_SKETCHLINES
) > 0)
830 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->sketchlinesmenuitems
[1]), TRUE
);
831 else if ((nd
->flags
& NODEFLAG_SKETCHGRAPH
) > 0)
832 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->sketchlinesmenuitems
[2]), TRUE
);
835 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->sketchlinesmenuitems
[0]), TRUE
);
836 callback_sketchlines(NULL
, mainview
->sketchlinesmenuitems
[0]); /*FIXME:ugly */
838 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mainview
->tools_pressure
), TRUE
);
843 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
) {
844 maepad_warning("Error reading (2): %s", sqlite3_errmsg(mainview
->db
));
847 sqlite3_finalize(stmt
);
850 busy_leave(mainview
);
852 /* Show / hide the sketch-related menu widgets */
853 if (nd
->typ
== NODE_SKETCH
) {
854 gtk_widget_show(mainview
->menu_button_square
);
855 gtk_widget_show(mainview
->menu_button_filled
);
857 gtk_widget_hide(mainview
->menu_button_square
);
858 gtk_widget_hide(mainview
->menu_button_filled
);
861 /* Show/hide the rich text-related menu widgets */
862 if (nd
->typ
== NODE_TEXT
) {
863 gtk_widget_show(mainview
->menu_button_wordwrap
);
865 gtk_widget_hide(mainview
->menu_button_wordwrap
);
868 /* Show/hide the checklist-related menu widgets */
869 if (nd
->typ
== NODE_CHECKLIST
) {
870 gtk_widget_show(mainview
->menu_button_remove_checked
);
872 gtk_widget_hide(mainview
->menu_button_remove_checked
);
877 show_banner(mainview
, _("Error loading memo"));
881 gboolean
treeview_canselect(GtkTreeSelection
* selection
, GtkTreeModel
* model
, GtkTreePath
* path
, gboolean path_currently_selected
, gpointer userdata
)
883 MainView
*mainview
= (MainView
*) userdata
;
884 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
886 if (path_currently_selected
)
889 gtk_tree_model_get_iter(model
, &iter
, path
);
891 gtk_tree_model_get(model
, &iter
, NODE_DATA
, &(mainview
->cansel_node
), -1);
892 mainview
->cansel_time
=time(NULL
);
898 gboolean
newnodedlg_key_press_cb(GtkWidget
* widget
, GdkEventKey
* event
, GtkWidget
* dlg
)
900 SketchWidget
*s
= gtk_object_get_data(GTK_OBJECT(dlg
), "sk");
902 switch (event
->keyval
)
905 sketchwidget_redo(s
);
908 sketchwidget_undo(s
);
915 /* This struct will hold all our toggle buttons, so we can
916 * only allow one to be active at a time (i.e. radio buttons) */
917 typedef struct _newNodeToggleButtons newNodeToggleButtons
;
918 struct _newNodeToggleButtons
920 GtkWidget
*rbt
; /* Text */
921 GtkWidget
*rbs
; /* Sketch */
922 GtkWidget
*rbc
; /* Checklist */
925 void show_sketch_widget(GtkWidget
*widget
, gpointer user_data
)
927 GtkWidget
*dialog
= (GtkWidget
*)user_data
;
929 /* Show the sketch widget and hide the entry + draw button */
930 gtk_widget_show(gtk_object_get_data(GTK_OBJECT(dialog
), "al"));
931 gtk_widget_hide(gtk_object_get_data(GTK_OBJECT(dialog
), "draw_button"));
932 gtk_widget_hide(gtk_object_get_user_data(GTK_OBJECT(dialog
)));
935 void new_node_dialog(nodeType typ
, MainView
* mainview
)
937 GtkWidget
*dialog
, *entry
, *but_ok
, *vbox
, *hbox
, *al
, *cb
;
938 GtkWidget
*rb1
, *rb2
, *rb3
;
940 gchar datetime_str
[200];
943 gboolean datetime_written
= FALSE
;
946 tm_now
= localtime(&t_now
);
948 if (tm_now
!= NULL
) {
949 if (strftime(datetime_str
, sizeof(datetime_str
), "%y-%m-%d %H:%M", tm_now
) != 0) {
950 datetime_written
= TRUE
;
954 if (datetime_written
== FALSE
) {
955 /* Was not able to determine a datetime string - use default */
956 maepad_warning("Cannot determine current time");
957 strncpy(datetime_str
, _("New memo"), sizeof(datetime_str
));
958 datetime_str
[sizeof(datetime_str
)-1] = '\0';
961 newNodeToggleButtons
*nntb
= g_malloc(sizeof(newNodeToggleButtons
));
963 dialog
= gtk_dialog_new();
964 gtk_window_set_title(GTK_WINDOW(dialog
), _("Add new memo"));
965 gtk_window_set_transient_for(GTK_WINDOW(dialog
), mainview_get_dialog_parent(mainview
));
966 gtk_dialog_set_has_separator(GTK_DIALOG(dialog
), FALSE
);
968 g_signal_connect(G_OBJECT(dialog
), "key_press_event", G_CALLBACK(newnodedlg_key_press_cb
), dialog
);
970 vbox
= gtk_vbox_new(FALSE
, 0);
972 hbox
= gtk_hbox_new(TRUE
, 0);
974 /* Text note toggle button */
975 rb1
= hildon_gtk_radio_button_new(HILDON_SIZE_FINGER_HEIGHT
, NULL
);
976 gtk_button_set_label(GTK_BUTTON(rb1
), _("Rich text"));
977 gtk_button_set_image(GTK_BUTTON(rb1
), gtk_image_new_from_file(PIXMAPDIR
"/text.png"));
978 gtk_box_pack_start(GTK_BOX(hbox
), GTK_WIDGET(rb1
), TRUE
, TRUE
, 0);
981 /* Sketch toggle button */
982 rb2
= hildon_gtk_radio_button_new_from_widget(HILDON_SIZE_FINGER_HEIGHT
, GTK_RADIO_BUTTON(rb1
));
983 gtk_button_set_label(GTK_BUTTON(rb2
), _("Sketch"));
984 gtk_button_set_image(GTK_BUTTON(rb2
), gtk_image_new_from_file(PIXMAPDIR
"/sketch.png"));
985 gtk_box_pack_start(GTK_BOX(hbox
), GTK_WIDGET(rb2
), TRUE
, TRUE
, 0);
988 /* Checklist toggle button */
989 rb3
= hildon_gtk_radio_button_new_from_widget(HILDON_SIZE_FINGER_HEIGHT
, GTK_RADIO_BUTTON(rb1
));
990 gtk_button_set_label(GTK_BUTTON(rb3
), _("Checklist"));
991 gtk_button_set_image(GTK_BUTTON(rb3
), gtk_image_new_from_file(PIXMAPDIR
"/checklist.png"));
992 gtk_box_pack_start(GTK_BOX(hbox
), GTK_WIDGET(rb3
), TRUE
, TRUE
, 0);
995 /* Set mode to 0 to get correct styling */
996 gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(rb1
), FALSE
);
997 gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(rb2
), FALSE
);
998 gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(rb3
), FALSE
);
1000 /* Remember "new note toggle buttons" list */
1001 gtk_object_set_data(GTK_OBJECT(dialog
), "nntb", nntb
);
1003 if (typ
== NODE_TEXT
) {
1004 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb1
), TRUE
);
1005 } else if (typ
== NODE_SKETCH
) {
1006 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb2
), TRUE
);
1008 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb3
), TRUE
);
1011 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
1013 but_ok
= gtk_dialog_add_button(GTK_DIALOG(dialog
), _("Add"), GTK_RESPONSE_OK
);
1014 gtk_dialog_set_default_response(GTK_DIALOG(dialog
), GTK_RESPONSE_OK
);
1015 g_signal_connect(G_OBJECT(but_ok
), "clicked", G_CALLBACK(callback_new_node_real
), dialog
);
1017 gtk_object_set_data(GTK_OBJECT(dialog
), "m", mainview
);
1019 hb
= gtk_hbox_new(FALSE
, 10);
1020 gtk_box_pack_start(GTK_BOX(hb
), gtk_label_new(_("Name:")), FALSE
, FALSE
, 0);
1021 entry
= hildon_entry_new(HILDON_SIZE_AUTO
);
1022 gtk_entry_set_activates_default(GTK_ENTRY(entry
), TRUE
);
1023 gtk_object_set_user_data(GTK_OBJECT(dialog
), entry
);
1024 gtk_entry_set_text(GTK_ENTRY(entry
), datetime_str
);
1025 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1026 gtk_box_pack_start(GTK_BOX(hb
), entry
, TRUE
, TRUE
, 0);
1028 /* Sketch widget, hidden by default */
1029 al
= gtk_alignment_new(0.5, 0.5, 0, 0);
1030 SketchWidget
*s
= sketchwidget_new(SKETCHNODE_X
, SKETCHNODE_Y
, TRUE
);
1031 gtk_object_set_data(GTK_OBJECT(dialog
), "sk", s
);
1032 gtk_object_set_data(GTK_OBJECT(dialog
), "al", al
);
1033 sketchwidget_set_brushsize(s
, 2);
1034 sketchwidget_set_backstyle(s
, SKETCHBACK_GRAPH
);
1035 gtk_widget_set_size_request(sketchwidget_get_mainwidget(s
), SKETCHNODE_X
, SKETCHNODE_Y
);
1036 gtk_container_add(GTK_CONTAINER(al
), sketchwidget_get_mainwidget(s
));
1037 gtk_box_pack_start(GTK_BOX(hb
), al
, FALSE
, FALSE
, 0);
1039 /*but_sketch = hildon_button_new_with_text(
1040 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,
1041 HILDON_BUTTON_ARRANGEMENT_VERTICAL,
1042 _("Use sketch label"), NULL);
1044 gtk_object_set_data(GTK_OBJECT(dialog), "draw_button", but_sketch);
1045 gtk_signal_connect(GTK_OBJECT(but_sketch), "clicked", G_CALLBACK(show_sketch_widget), dialog);
1046 gtk_box_pack_start(GTK_BOX(hb), but_sketch, FALSE, TRUE, 0);*/
1047 gtk_box_pack_start(GTK_BOX(vbox
), hb
, TRUE
, FALSE
, 0);
1049 cb
= hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT
| HILDON_SIZE_AUTO_WIDTH
);
1050 gtk_button_set_label(GTK_BUTTON(cb
), _("Add as child of selected memo"));
1051 hildon_check_button_set_active(HILDON_CHECK_BUTTON(cb
), mainview
->newnodedialog_createchild
);
1052 gtk_box_pack_start(GTK_BOX(vbox
), cb
, FALSE
, FALSE
, 0);
1054 gtk_object_set_data(GTK_OBJECT(dialog
), "cb", cb
);
1056 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), vbox
);
1058 gtk_widget_grab_focus(entry
);
1060 gtk_widget_show_all(dialog
);
1062 /* Hide the sketch widget at first */
1063 gtk_widget_hide(al
);
1064 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
1067 void add_new_node(nodeData
* node
, MainView
* mainview
, gboolean ischild
)
1069 GtkTreeIter parentiter
, newiter
;
1070 GtkTreeModel
*model
;
1073 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1075 if (gtk_tree_selection_get_selected(selection
, &model
, &parentiter
))
1078 GtkTreePath
*path
= NULL
;
1080 unsigned int parentnodeid
= 0;
1084 path
= gtk_tree_model_get_path(model
, &parentiter
);
1086 if (ischild
== FALSE
)
1088 gtk_tree_path_up(path
);
1090 if (gtk_tree_path_get_depth(path
) == 0)
1092 /* Selected node is a root node */
1093 ptr
= NULL
; /* New node can not have a Parent node */
1094 gtk_tree_path_down(path
); /*restore path so expand() works */
1096 else if (gtk_tree_path_get_depth(path
) > 0)
1098 /* Selected node is a child node */
1099 if (gtk_tree_model_get_iter(model
, &parentiter
, path
))
1109 gtk_tree_model_get(model
, ptr
, NODE_DATA
, &nd
, -1);
1111 parentnodeid
= nd
->sql3id
;
1117 sqlite3_stmt
*stmt
= NULL
;
1124 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s (parent, bodytype, name, nameblob, ord) VALUES (%d, %d, ?, ?, 0);", datatable_tmpname
, parentnodeid
, node
->typ
);
1125 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
1129 maepad_warning("Error inserting (1): %s", sqlite3_errmsg(mainview
->db
));
1132 if (node
->name
!= NULL
)
1133 sqlite3_bind_text(stmt
, 1, node
->name
, strlen(node
->name
), SQLITE_TRANSIENT
);
1135 sqlite3_bind_text(stmt
, 1, NULL
, 0, SQLITE_TRANSIENT
);
1137 if (node
->namepix
!= NULL
)
1139 gchar
*namepixdata
= NULL
;
1144 if (gdk_pixbuf_save_to_buffer(node
->namepix
, &namepixdata
, &datalen
, "png", &err
, NULL
) == FALSE
)
1148 maepad_warning("Error saving name: %s", err
->message
);
1151 sqlite3_bind_blob(stmt
, 2, namepixdata
, datalen
, SQLITE_TRANSIENT
);
1154 sqlite3_bind_blob(stmt
, 2, NULL
, 0, SQLITE_TRANSIENT
);
1157 while(rc
== SQLITE_BUSY
)
1159 rc
= sqlite3_step(stmt
);
1160 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
1163 sqlite3_finalize(stmt
);
1164 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
1166 maepad_warning("Error inserting (2): %s", sqlite3_errmsg(mainview
->db
));
1169 node
->sql3id
= sqlite3_last_insert_rowid(mainview
->db
);
1173 if (node
->sql3id
== 0)
1178 g_object_unref(node
->namepix
);
1181 gtk_tree_path_free(path
);
1182 show_banner(mainview
, _("Error creating memo"));
1186 gtk_tree_store_append(GTK_TREE_STORE(model
), &newiter
, ptr
);
1188 gtk_tree_store_set(GTK_TREE_STORE(model
), &newiter
, NODE_NAME
, node
->name
, NODE_PIXBUF
, node
->namepix
, NODE_DATA
, node
, -1);
1192 mainview
->loading
=TRUE
; /*only when we have a valid parent*/
1193 gtk_tree_view_expand_row(GTK_TREE_VIEW(mainview
->treeview
), path
, FALSE
);
1194 gtk_tree_path_free(path
);
1197 gtk_tree_selection_select_iter(selection
, &newiter
);
1199 mainview
->loading
=FALSE
;
1202 void callback_new_node_real(GtkAction
* action
, gpointer data
)
1206 GtkWidget
*dialog
= data
;
1207 GtkWidget
*entry
= gtk_object_get_user_data(GTK_OBJECT(dialog
));
1209 mainview
= gtk_object_get_data(GTK_OBJECT(dialog
), "m");
1210 SketchWidget
*s
= gtk_object_get_data(GTK_OBJECT(dialog
), "sk");
1211 GtkWidget
*cb
= gtk_object_get_data(GTK_OBJECT(dialog
), "cb");
1212 newNodeToggleButtons
*nntb
= gtk_object_get_data(GTK_OBJECT(dialog
), "nntb");
1214 nodeType typ
= NODE_TEXT
;
1215 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nntb
->rbs
))) {
1217 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(nntb
->rbc
))) {
1218 typ
= NODE_CHECKLIST
;
1224 /*if (GTK_WIDGET_VISIBLE(entry))
1226 txt
= g_strdup(gtk_entry_get_text(GTK_ENTRY(entry
)));
1227 if (strcmp(txt
, "") == 0)
1235 GtkWidget *sdr = sketchwidget_get_drawingarea(s);
1237 GdkPixmap *spix = sketchwidget_get_Pixmap(s);
1239 pixbuf = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE(spix), NULL, 0, 0, 0, 0, sdr->allocation.width, sdr->allocation.height);
1240 g_object_unref(spix);
1242 GdkPixbuf *pixbuf2 = sketchwidget_trim_image(pixbuf, SKETCHNODE_X, SKETCHNODE_Y, &w,
1244 if (pixbuf2==NULL) return;
1246 GdkPixbuf *pixbuf3 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, SKETCHNODE_RX,
1249 gdk_pixbuf_fill(pixbuf3, 0xffffffff);
1251 if (w <= SKETCHNODE_RX && h <= SKETCHNODE_RY)
1253 gdk_pixbuf_copy_area(pixbuf2, 0, 0, w, h, pixbuf3, 0, (SKETCHNODE_RY - h) / 2);
1261 neww = SKETCHNODE_RX;
1262 newh = (h / w) * SKETCHNODE_RX;
1266 newh = SKETCHNODE_RY;
1267 neww = (w / h) * SKETCHNODE_RY;
1269 if (newh > SKETCHNODE_RY)
1270 newh = SKETCHNODE_RY;
1272 GdkPixbuf *tmpbuf = gdk_pixbuf_scale_simple(pixbuf2, neww, newh,
1273 GDK_INTERP_BILINEAR);
1275 gdk_pixbuf_copy_area(tmpbuf, 0, 0, neww, newh, pixbuf3, 0, (SKETCHNODE_RY - newh) / 2);
1277 gdk_pixbuf_unref(tmpbuf);
1281 gdk_pixbuf_unref(pixbuf2);
1286 node
= g_malloc(sizeof(nodeData
));
1289 node
->namepix
= NULL
;
1291 /*if (GTK_WIDGET_VISIBLE(entry))
1297 node->namepix = pixbuf;
1304 mainview
->newnodedialog_createchild
= hildon_check_button_get_active(HILDON_CHECK_BUTTON(cb
));
1305 add_new_node(node
, mainview
, mainview
->newnodedialog_createchild
);
1307 sketchwidget_destroy(s
);
1308 gtk_widget_destroy(dialog
);
1309 mainview
->file_edited
= TRUE
;
1315 void callback_file_delete_node(GtkAction
* action
, gpointer data
)
1317 MainView
*mainview
= (MainView
*) data
;
1318 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1320 if (getSelectedNode(mainview
) == NULL
) {
1321 show_banner(mainview
, _("Select a memo first"));
1325 if (show_confirmation(mainview
, _("Delete selected memo?"))) {
1326 mainview
->can_show_node_view
= FALSE
;
1327 callback_delete_node_real(mainview
);
1328 gtk_widget_hide(GTK_WIDGET(mainview
->data
->node_view
));
1333 * Callback for Rename Menuitem
1335 void callback_file_rename_node(GtkAction
* action
, gpointer data
)
1337 MainView
*mainview
= (MainView
*)data
;
1338 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1340 /* Get the selected node */
1341 nodeData
*sel_node
= getSelectedNode(mainview
);
1342 if (sel_node
== NULL
) {
1343 /* Do nothing, if no node has been selected */
1344 show_banner(mainview
, _("Select a memo first"));
1348 if (sel_node
->namepix
!= NULL
) {
1349 /* the memo has a graphical label, cannot edit! */
1350 show_banner(mainview
, _("Cannot rename memos with sketch name"));
1354 gchar
* new_name
= show_line_edit_dialog(mainview
, _("Rename memo"), _("New name:"), _("Rename"), sel_node
->name
);
1356 /* Only rename node when user accepted the new name */
1357 if (new_name
!= NULL
) {
1358 callback_rename_node_real(mainview
, new_name
);
1363 void callback_rename_node_real(MainView
* mainview
, gchar
* new_name
)
1366 GtkTreeModel
*model
;
1367 nodeData
*nd
= NULL
;
1369 /* Get the selected node */
1370 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1372 if (!gtk_tree_selection_get_selected(selection
, &model
, &iter
)) {
1376 gtk_tree_model_get (model
, &iter
, NODE_DATA
, &nd
, -1);
1382 /* Update the database */
1383 sqlite3_stmt
*stmt
= NULL
;
1385 char* sql
= sqlite3_mprintf("UPDATE %s SET name='%q' WHERE nodeid=%d", datatable_tmpname
, new_name
, nd
->sql3id
);
1387 int rc
= sqlite3_prepare(mainview
->db
, sql
, strlen(sql
), &stmt
, NULL
);
1388 if (rc
== SQLITE_OK
) {
1390 while (rc
== SQLITE_BUSY
) {
1391 rc
= sqlite3_step(stmt
);
1392 if (rc
== SQLITE_DONE
) {
1393 /* Update in the database was successful - now update the rest */
1395 /* Update the noteData */
1397 nd
->name
= g_strdup(new_name
);
1399 /* Update the window title of node_view */
1400 gtk_window_set_title(GTK_WINDOW(mainview
->data
->node_view
), nd
->name
);
1402 /* Update the value in the tree store */
1403 gtk_tree_store_set (GTK_TREE_STORE(model
), &iter
, NODE_NAME
, new_name
, -1);
1406 } else if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
) {
1407 maepad_warning("Error updating node: %s", sqlite3_errmsg(mainview
->db
));
1411 sqlite3_finalize(stmt
);
1413 maepad_warning("Error preparing DB update query: %s", sqlite3_errmsg(mainview
->db
));
1418 mainview
->file_edited
= TRUE
;
1421 void callback_file_export_node(GtkAction
* action
, gpointer data
)
1423 MainView
*mainview
= (MainView
*) data
;
1424 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1426 nodeData
*nd
=getSelectedNode(mainview
);
1429 show_banner(mainview
, _("Select a memo first"));
1433 gchar
*nodename
=nd
->name
;
1434 if (nodename
==NULL
) nodename
=_("saved memo");
1436 if (nd
->typ
== NODE_TEXT
)
1439 GtkTextIter begin, end;
1440 gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER(mainview->buffer), &begin, &end);
1441 gchar *text = gtk_text_buffer_get_slice(GTK_TEXT_BUFFER(mainview->buffer), &begin, &end, TRUE);
1443 GString
*gstr
=g_string_sized_new(4096);
1444 wp_text_buffer_save_document(mainview
->buffer
, (WPDocumentSaveCallback
)(wp_savecallback
), gstr
);
1445 gint textlen
=gstr
->len
;
1446 gchar
*text
=g_string_free(gstr
, FALSE
);
1448 if (text
==NULL
|| !strcmp(text
, ""))
1450 show_banner(mainview
, _("Memo is empty"));
1454 gchar
*fn
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, nodename
, "html");
1457 GnomeVFSResult vfs_result
;
1458 GnomeVFSHandle
*handle
= NULL
;
1459 GnomeVFSFileSize out_bytes
;
1460 vfs_result
= gnome_vfs_create(&handle
, fn
, GNOME_VFS_OPEN_WRITE
, 0, 0600);
1461 if ( vfs_result
!= GNOME_VFS_OK
) {
1462 show_banner(mainview
, _("Export failed"));
1466 gnome_vfs_write(handle
, text
, textlen
, &out_bytes
);
1467 gnome_vfs_close(handle
);
1468 if (out_bytes
==strlen(text
)) show_banner(mainview
, _("Exported"));
1469 else show_banner(mainview
, _("Export incomplete"));
1476 else if (nd
->typ
== NODE_SKETCH
)
1478 GdkPixmap
*skpix
= sketchwidget_get_Pixmap(mainview
->sk
);
1479 GtkWidget
*skdr
= sketchwidget_get_drawingarea(mainview
->sk
);
1480 GdkPixbuf
*pixbuf
= gdk_pixbuf_get_from_drawable(NULL
, GDK_DRAWABLE(skpix
), NULL
, 0, 0, 0, 0, skdr
->allocation
.width
, skdr
->allocation
.height
);
1483 show_banner(mainview
, _("Memo is empty"));
1487 gchar
*fn
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, nodename
, "png");
1490 if (gdk_pixbuf_save(pixbuf
, fn
, "png", NULL
, NULL
)==FALSE
)
1492 show_banner(mainview
, _("Export failed"));
1496 show_banner(mainview
, _("Exported"));
1501 g_object_unref(skpix
);
1503 else if (nd
->typ
== NODE_CHECKLIST
)
1505 show_banner(mainview
, _("Export of checklists not possible yet"));
1510 * callback from menu item
1511 * move selected node down (switch node with next sibling), don't change level of node
1513 void callback_move_down_node(GtkAction
* action
, gpointer data
)
1516 GtkTreeModel
*model
;
1518 MainView
*mainview
= (MainView
*) data
;
1519 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1521 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1522 gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1524 GtkTreeIter old_iter
= iter
;/*save pointer to old iter, we will need it during swap nodes*/
1526 if (gtk_tree_model_iter_next(model
,&iter
)==FALSE
)/*get next node*/
1529 GtkTreeStore
*treeStore
= GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
)));
1530 gtk_tree_store_swap(treeStore
,&iter
,&old_iter
);
1532 mainview
->file_edited
= TRUE
;/*we have made changes , if required show "save changes?" dialog in future*/
1536 * callback from menu item
1537 * move selected node down (switch node with prev sibling), don't change level of node
1539 void callback_move_up_node(GtkAction
* action
, gpointer data
)
1542 GtkTreeModel
*model
;
1544 MainView
*mainview
= (MainView
*) data
;
1545 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1547 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1548 gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1550 GtkTreeIter old_iter
=iter
;/*save pointer to old iter, we will need it during swap nodes*/
1552 if (tree_model_iter_prev(model
,&iter
)==FALSE
)/*get previous node*/
1555 GtkTreeStore
*treeStore
= GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
)));
1556 gtk_tree_store_swap(treeStore
,&old_iter
,&iter
);/*do move*/
1558 mainview
->file_edited
= TRUE
;/*we have made changes , if required show "save changes?" dialog in future*/
1562 * callback from menu item
1563 * we change level of actual node with direction to top
1565 void callback_move_to_top_level_node(GtkAction
* action
, gpointer data
)
1567 GtkTreeIter iter
,new_parent
;
1568 GtkTreeIter
*p_new_parent
;
1570 GtkTreeModel
*model
;
1572 MainView
*mainview
= (MainView
*) data
;
1573 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1575 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1576 gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1578 /*at first we need actual parent of selected node*/
1579 if (gtk_tree_model_iter_parent(model
,&parent
,&iter
)==FALSE
)
1581 /*if parent of selected node is ROOT we can't go higher*/
1584 /*we need also new parent, it's parent of actual parent*/
1585 if (gtk_tree_model_iter_parent(model
,&new_parent
,&parent
)==FALSE
)
1587 /*if our new parent is ROOT we got filled new_parent with invalid value,
1588 so we need set NULL value to p_new_parent (root item)*/
1593 p_new_parent
=&new_parent
;/*we only redirect pointer to treeiter*/
1596 saveCurrentData(mainview
);/*we save changes in node befor move*/
1598 /*this move function provide move item with all his children, be careful iter value will change!*/
1599 if (move_node(mainview
,p_new_parent
,&iter
,&parent
)==TRUE
){
1601 gint id_parent
= get_node_id_on_tmp_db(model
,p_new_parent
);
1602 gint id_node
= get_node_id_on_tmp_db(model
,&iter
);
1603 /*we need also update parent id of moved item*/
1605 g_snprintf (tq
, sizeof(tq
), "UPDATE %s SET parent=%d WHERE nodeid=%d",datatable_tmpname
,id_parent
,id_node
);
1606 exec_command_on_db(mainview
,tq
);
1608 /*select new created iter*/
1609 gtk_tree_selection_select_iter(selection
,&iter
);
1611 mainview
->file_edited
= TRUE
;/*we have made changes , if required show "save changes?" dialog in future*/
1616 * callback from menu item
1617 * we change level of actual node with direction to bottom
1618 * previous node will be parent of our actual node
1620 void callback_move_to_bottom_level_node(GtkAction
* action
, gpointer data
)
1623 GtkTreeModel
*model
;
1625 MainView
*mainview
= (MainView
*) data
;
1626 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1628 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1629 gtk_tree_selection_get_selected(selection
, &model
, &iter
);
1631 GtkTreeIter move_iter
=iter
;/*save pointer to old iter*/
1633 /*we try to get previous node*/
1634 if (tree_model_iter_prev(model
,&iter
)==FALSE
)
1635 return;/*if previous node on the same level doesn't exist we will exit*/
1637 saveCurrentData(mainview
);/*we save changes in node befor move*/
1639 /*this move function provide move item with all his children, be careful move_iter value will change!*/
1640 if (move_node(mainview
,&iter
,&move_iter
,NULL
)==TRUE
)
1642 gint id_parent
= get_node_id_on_tmp_db(model
,&iter
);
1643 gint id_node
= get_node_id_on_tmp_db(model
,&move_iter
);
1645 /*we need also update parent id of moved item*/
1647 g_snprintf (tq
, sizeof(tq
), "UPDATE %s SET parent=%d WHERE nodeid=%d",datatable_tmpname
,id_parent
,id_node
);
1648 exec_command_on_db(mainview
,tq
);
1650 GtkTreePath
*path
= gtk_tree_model_get_path(model
, &iter
);
1651 gtk_tree_view_expand_row(GTK_TREE_VIEW(mainview
->treeview
), path
, FALSE
);/*expand parent node*/
1652 gtk_tree_path_free(path
);
1654 /*select new created iter*/
1655 gtk_tree_selection_select_iter(selection
,&move_iter
);
1657 mainview
->file_edited
= TRUE
;/*we have made changes , if required show "save changes?" dialog in future*/
1662 * move item_to_move to new_parent with his children, this function is designed for change level of node
1663 * we copy item_to_move with his children to new position (after item_befor if is not NULL) and then we
1664 * destroy old node with his children, so ! item_to_move is set with new iter, be careful on this!
1666 gboolean
move_node(MainView
*mainview
,GtkTreeIter
*new_parent
,GtkTreeIter
*item_to_move
,GtkTreeIter
*item_befor
)
1668 GtkTreeModel
*model
;
1670 model
=gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
));
1671 GtkTreeStore
*treeStore
= GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
)));
1674 gtk_tree_model_get(model
, item_to_move
, NODE_DATA
, &node
, -1);/*get data from actual iter*/
1677 GtkTreeIter new_iter
;/*create new iter*/
1678 gtk_tree_store_append(treeStore
,&new_iter
,new_parent
);/*append new iter to new parent*/
1680 if (item_befor
!=NULL
)
1681 gtk_tree_store_move_after(treeStore
,&new_iter
,item_befor
);/*sometimes we need set position*/
1683 gtk_tree_store_set(treeStore
, &new_iter
, NODE_NAME
, node
->name
,NODE_PIXBUF
, node
->namepix
, NODE_DATA
, node
, -1);/*set data from old iter*/
1686 while (gtk_tree_model_iter_children(model
, &child
, item_to_move
)==TRUE
)/*move all childrens while some exits*/
1688 if (move_node(mainview
,&new_iter
,&child
,NULL
)==FALSE
)/*use recursion on children*/
1692 gtk_tree_store_set(treeStore
, item_to_move
, NODE_DATA
, NULL
, -1);
1693 gtk_tree_store_remove(treeStore
, item_to_move
);/*remove node, data need't remove, they are stored in new node*/
1695 /*we need return new value of moved item, so we need assign new_iter to item_to_move*/
1696 /*this code is ugly : new_iter to path and back to item_to_move*/
1697 GtkTreePath
*path
=gtk_tree_model_get_path(model
,&new_iter
);
1698 gtk_tree_model_get_iter(model
,item_to_move
,path
);
1699 gtk_tree_path_free(path
);
1703 fprintf(stderr
,"Get data node failed!\n");
1711 * simple execute of sql command which is stored in sql_string[]
1713 gboolean
exec_command_on_db(MainView
*mainview
,char sql_string
[])
1715 sqlite3_stmt
*stmt
= NULL
;
1717 gboolean db_query_result
= FALSE
;
1719 int rc
= sqlite3_prepare (mainview
->db
, sql_string
, strlen(sql_string
), &stmt
, &dum
);
1722 maepad_warning("Error preparing DB update query: %s", sqlite3_errmsg(mainview
->db
));
1727 while (rc
== SQLITE_BUSY
) {
1728 rc
= sqlite3_step (stmt
);
1729 if (rc
== SQLITE_DONE
) {
1730 db_query_result
= TRUE
;
1733 else if(rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
) {
1734 maepad_warning("Error updating node: %s", sqlite3_errmsg(mainview
->db
));
1737 sqlite3_finalize(stmt
);
1743 * 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)
1745 gboolean
foreach_func_update_ord (GtkTreeModel
*model
,GtkTreePath
*path
,GtkTreeIter
*iter
, MainView
*mainview
)
1748 gtk_tree_model_get(model
, iter
, NODE_DATA
, &node
, -1);
1749 /*we need index of node on actual level*/
1750 gint index
=get_branch_node_index(path
);
1752 /*prepare to execute update command,and exec it*/
1753 char sql_command
[512];
1754 g_snprintf (sql_command
, sizeof(sql_command
), "UPDATE %s SET ord=\"%d\" WHERE nodeid=%d",datatable_tmpname
, index
, node
->sql3id
);
1755 exec_command_on_db(mainview
,sql_command
);
1757 /*we don't want break gtk_tree_model_foreach function,until we call this func on each node - so we return always FALSE*/
1762 * return id number of iter (id number which is used to identify in sql database of nodes)
1764 int get_node_id_on_tmp_db(GtkTreeModel
*model
,GtkTreeIter
*iter
)
1767 return 0;/*we got ROOT parent here*/
1770 gtk_tree_model_get(model
, iter
, NODE_DATA
, &node
, -1);
1771 return node
->sql3id
;
1775 * get index of node in current branch
1777 gint
get_branch_node_index(GtkTreePath
*path
)
1779 int depth
=gtk_tree_path_get_depth(path
);
1780 gint
*indicies
= gtk_tree_path_get_indices(path
);
1782 return indicies
[depth
-1];
1786 * similiar with gtk_tree_model_iter_next (), but opposite
1788 gboolean
tree_model_iter_prev(GtkTreeModel
*tree_model
,GtkTreeIter
*iter
)
1790 GtkTreePath
*path
= gtk_tree_model_get_path(tree_model
, iter
);
1793 fprintf(stderr
,"Error: path is null\n");
1797 if (gtk_tree_path_prev(path
)==FALSE
)
1800 gtk_tree_model_get_iter(tree_model
, iter
,path
);
1805 gboolean
ref2iter(GtkTreeModel
* model
, GtkTreeRowReference
* ref
, GtkTreeIter
* iter
)
1807 gboolean res
= FALSE
;
1808 GtkTreePath
*path
= gtk_tree_row_reference_get_path(ref
);
1810 if (gtk_tree_model_get_iter(model
, iter
, path
))
1814 gtk_tree_path_free(path
);
1818 GtkTreeRowReference
*iter2ref(GtkTreeModel
* model
, GtkTreeIter
* iter
)
1820 GtkTreeRowReference
*ref
;
1822 GtkTreePath
*path
= gtk_tree_model_get_path(model
, iter
);
1824 ref
= gtk_tree_row_reference_new(model
, path
);
1825 gtk_tree_path_free(path
);
1829 void move_nodes_up(GtkTreeModel
* model
, GtkTreeRowReference
* topnode
, GtkTreeRowReference
* newtop
)
1831 GtkTreeIter topiter
;
1833 if (ref2iter(model
, topnode
, &topiter
) == FALSE
)
1838 if (gtk_tree_model_iter_children(model
, &child
, &topiter
))
1840 GtkTreeRowReference
*ref
;
1841 GList
*rr_list
= NULL
, *node
;
1845 ref
= iter2ref(model
, &child
);
1846 rr_list
= g_list_append(rr_list
, ref
);
1848 while(gtk_tree_model_iter_next(model
, &child
));
1851 * got a reflist for all children
1854 for(node
= rr_list
; node
; node
= node
->next
)
1856 ref
= (GtkTreeRowReference
*) (node
->data
);
1857 if (ref2iter(model
, ref
, &child
))
1859 GtkTreeIter newtopiter
, newiter
;
1860 GtkTreeIter
*newtopiterptr
;
1862 if (ref2iter(model
, newtop
, &newtopiter
))
1863 newtopiterptr
= &newtopiter
;
1865 newtopiterptr
= NULL
;
1869 gtk_tree_model_get(model
, &child
, NODE_DATA
, &node
, -1);
1871 gtk_tree_store_append(GTK_TREE_STORE(model
), &newiter
, newtopiterptr
);
1872 gtk_tree_store_set(GTK_TREE_STORE(model
), &newiter
, NODE_NAME
, node
->name
, NODE_PIXBUF
, node
->namepix
, NODE_DATA
, node
, -1);
1874 GtkTreeRowReference
*newref
= iter2ref(model
, &newiter
);
1876 move_nodes_up(model
, ref
, newref
);
1877 gtk_tree_row_reference_free(newref
);
1879 gtk_tree_store_remove(GTK_TREE_STORE(model
), &child
);
1881 gtk_tree_row_reference_free(ref
);
1884 g_list_free(rr_list
);
1889 void callback_delete_node_real(MainView
* mainview
)
1892 GtkTreeModel
*model
;
1894 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
1896 if (!gtk_tree_selection_get_selected(selection
, &model
, &iter
))
1901 gtk_tree_model_get(model
, &iter
, NODE_DATA
, &nd
, -1);
1905 mainview
->file_edited
= TRUE
;
1907 unsigned int sql3id
= nd
->sql3id
;
1914 * if (nd->pix) g_object_unref(nd->pix);
1918 GtkTreeRowReference
*upref
= NULL
, *ref
= NULL
;
1920 GtkTreePath
*path
= gtk_tree_model_get_path(model
, &iter
);
1922 ref
= gtk_tree_row_reference_new(model
, path
);
1923 if (gtk_tree_path_up(path
))
1924 upref
= gtk_tree_row_reference_new(model
, path
);
1925 gtk_tree_path_free(path
);
1927 g_object_ref(model
);
1928 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), NULL
);
1930 move_nodes_up(model
, ref
, upref
);
1932 if (ref2iter(model
, ref
, &iter
))
1936 g_snprintf(tq
, sizeof(tq
), "SELECT parent FROM %s WHERE nodeid=%d", datatable_tmpname
, sql3id
);
1937 sqlite3_stmt
*stmt
= NULL
;
1939 int rc
= sqlite3_prepare(mainview
->db
, tq
, strlen(tq
), &stmt
, &dum
);
1940 unsigned int sql3parentid
= 0;
1944 maepad_warning("Error finding children for delete: %s", sqlite3_errmsg(mainview
->db
));
1949 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
1951 rc
= sqlite3_step(stmt
);
1952 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
1954 else if (rc
== SQLITE_ROW
)
1956 sql3parentid
= sqlite3_column_int(stmt
, 0);
1960 sqlite3_finalize(stmt
);
1962 g_snprintf(tq
, sizeof(tq
), "UPDATE %s SET parent=%d WHERE parent=%d;", datatable_tmpname
, sql3parentid
, sql3id
);
1963 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
1964 maepad_warning("Error moving nodes up one level");
1967 g_snprintf(tq
, sizeof(tq
), "DELETE FROM %s WHERE nodeid=%d;", datatable_tmpname
, sql3id
);
1968 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
1969 maepad_warning("Error deleting node");
1972 /* Delete all checklist items that do not have
1973 * a node anymore (= orphaned checklist items) */
1974 g_snprintf(tq
, sizeof(tq
), "DELETE FROM %s WHERE nodeid NOT IN (SELECT nodeid FROM %s);", checklisttable_tmpname
, datatable_tmpname
);
1975 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
1976 maepad_warning("Error deleting orphaned checklist items");
1980 gtk_tree_store_remove(GTK_TREE_STORE(model
), &iter
);
1983 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), model
);
1984 g_object_unref(model
);
1986 gtk_tree_row_reference_free(ref
);
1987 gtk_tree_row_reference_free(upref
);
1989 gtk_tree_view_expand_all(GTK_TREE_VIEW(mainview
->treeview
));
1993 void callback_edit_clear(GtkAction
* action
, gpointer data
)
1995 MainView
*mainview
= (MainView
*) data
;
1996 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
1997 nodeData
*nd
= getSelectedNode(mainview
);
1999 if (show_confirmation(mainview
, _("Remove all contents of this memo?"))) {
2002 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mainview
->buffer
), "", 0);
2005 sketchwidget_clear(mainview
->sk
);
2007 case NODE_CHECKLIST
:
2008 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
))));
2011 g_assert_not_reached();
2019 void callback_edit_cut(GtkAction
* action
, gpointer data
)
2021 MainView
*mainview
= (MainView
*) data
;
2022 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2024 nodeData
*nd
= getSelectedNode(mainview
);
2026 if (nd
->typ
== NODE_TEXT
)
2027 gtk_text_buffer_cut_clipboard(GTK_TEXT_BUFFER(mainview
->buffer
), mainview
->clipboard
, TRUE
);
2028 else if (nd
->typ
== NODE_SKETCH
)
2030 if (sketchwidget_cut(mainview
->sk
, mainview
->clipboard
)==FALSE
)
2031 show_banner(mainview
, _("Error cutting"));
2033 else if (nd
->typ
== NODE_CHECKLIST
)
2034 show_banner(mainview
, _("Unimplemented"));
2041 void callback_edit_copy(GtkAction
* action
, gpointer data
)
2043 MainView
*mainview
= (MainView
*) data
;
2044 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2046 nodeData
*nd
= getSelectedNode(mainview
);
2048 if (nd
->typ
== NODE_TEXT
)
2049 gtk_text_buffer_copy_clipboard(GTK_TEXT_BUFFER(mainview
->buffer
), mainview
->clipboard
);
2050 else if (nd
->typ
== NODE_SKETCH
)
2052 if (sketchwidget_copy(mainview
->sk
, mainview
->clipboard
)==FALSE
)
2053 show_banner(mainview
, _("Error copying"));
2055 else if (nd
->typ
== NODE_CHECKLIST
)
2057 /* Copy all selected entries as multiline text (1 line per entry) */
2058 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
2059 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
));
2061 gint selected_rows
= gtk_tree_selection_count_selected_rows(selection
);
2062 GList
* l
= gtk_tree_selection_get_selected_rows(selection
, NULL
);
2067 gchar
**entries
= g_malloc0(sizeof(gchar
*)*selected_rows
+1);
2068 gint entries_idx
= 0;
2072 GtkTreePath
*path
= cur
->data
;
2074 if (gtk_tree_model_get_iter(model
, &iter
, path
)) {
2075 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, CHECKNODE_TEXT
, &(entries
[entries_idx
++]), -1);
2077 gtk_tree_path_free(path
);
2083 str_data
= g_strjoinv("\n", entries
);
2084 g_strfreev(entries
);
2085 gtk_clipboard_set_text(mainview
->clipboard
, str_data
, -1);
2088 str_data
= g_strdup_printf(_("Copied %d entries"), selected_rows
);
2089 show_banner(mainview
, str_data
);
2098 void callback_edit_paste(GtkAction
* action
, gpointer data
)
2100 MainView
*mainview
= (MainView
*) data
;
2101 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2103 nodeData
*nd
= getSelectedNode(mainview
);
2105 if (nd
->typ
== NODE_TEXT
)
2106 gtk_text_buffer_paste_clipboard(GTK_TEXT_BUFFER(mainview
->buffer
), mainview
->clipboard
, NULL
, TRUE
);
2107 else if (nd
->typ
== NODE_SKETCH
)
2109 if (sketchwidget_paste(mainview
->sk
, mainview
->clipboard
)==FALSE
)
2110 show_banner(mainview
, _("Error pasting"));
2112 else if (nd
->typ
== NODE_CHECKLIST
) {
2113 /* Paste string from clipboard as new item */
2114 callback_checklist_paste(mainview
);
2115 checklist_select(mainview
, TREEVIEW_SELECT_LAST
);
2118 mainview
->file_edited
= TRUE
;
2121 gint
cb_popup(GtkWidget
* widget
, GdkEvent
* event
)
2124 GdkEventButton
*event_button
;
2127 * The "widget" is the menu that was supplied when
2128 * * g_signal_connect_swapped() was called.
2130 menu
= GTK_MENU(widget
);
2131 event_button
= (GdkEventButton
*) event
;
2132 if (event
->type
== GDK_BUTTON_PRESS
&& event_button
->button
== 3)
2134 gtk_menu_popup(menu
, NULL
, NULL
, NULL
, NULL
, event_button
->button
, event_button
->time
);
2142 * on_node_menu_show(GtkWidget*, gpointer)
2144 * This is called when the longpress menu is shown in the main
2145 * window. In the Hildon UI mode that we are using, this does
2146 * not automatically select the touched node, so we need to set
2147 * the cursor here so that the functions in the menu operate on
2148 * the node that the user touched (i.e. the expected one).
2150 * The value of mainview->node_list_longpress_path has been set
2151 * by callback_treeview_button_press on the buttn press event.
2154 on_node_menu_show(GtkWidget
* nodemenu
, gpointer user_data
)
2156 MainView
* mainview
= (MainView
*)user_data
;
2158 if (mainview
->node_list_longpress_path
!= NULL
) {
2159 /* Set the cursor, but don't open the node view */
2160 mainview
->can_show_node_view
= FALSE
;
2161 gtk_tree_view_set_cursor(GTK_TREE_VIEW(mainview
->treeview
),
2162 mainview
->node_list_longpress_path
, NULL
, FALSE
);
2164 /* Dispose the path (we don't need it anymore) */
2165 gtk_tree_path_free(mainview
->node_list_longpress_path
);
2166 mainview
->node_list_longpress_path
= NULL
;
2173 gboolean
closefile(MainView
* mainview
)
2175 saveCurrentData(mainview
);
2177 if (mainview
->file_edited
)
2179 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
));
2180 gint answer
= gtk_dialog_run(GTK_DIALOG(hn
));
2181 gtk_widget_destroy(GTK_WIDGET(hn
));
2183 if (answer
== CONFRESP_CANCEL
)
2185 else if (answer
== CONFRESP_YES
)
2187 if (mainview
->file_name
== NULL
)
2189 mainview
->file_name
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, "maemopaddata", "db");
2191 write_buffer_to_file(mainview
);
2196 sqlite3_close(mainview
->db
);
2197 mainview
->db
= NULL
;
2201 gboolean
callback_file_close(GtkAction
* action
, gpointer data
)
2204 MainView
*mainview
= (MainView
*) data
;
2205 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2206 if (closefile(mainview
) == FALSE
)
2213 void callback_file_new_node(GtkAction
* action
, gpointer data
)
2215 MainView
*mainview
= (MainView
*) data
;
2216 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2218 nodeType typ
= NODE_SKETCH
;
2220 nodeData
*nd
= getSelectedNode(mainview
);
2225 new_node_dialog(typ
, mainview
);
2231 void callback_file_new(GtkAction
* action
, gpointer data
)
2233 MainView
*mainview
= (MainView
*) data
;
2234 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2236 gchar
*filename
= NULL
;
2238 filename
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, "memos", "db");
2239 if (filename
== NULL
) {
2243 if (closefile(mainview
) == FALSE
) {
2251 busy_enter(mainview
);
2255 rc
= sqlite3_open(filename
, &mainview
->db
);
2258 show_banner(mainview
, _("Cannot create database"));
2259 maepad_warning("Can't create database %s: %s", filename
, sqlite3_errmsg(mainview
->db
));
2263 sqlite3_exec(mainview
->db
, "PRAGMA synchronous = OFF;", NULL
, NULL
, NULL
);
2267 g_snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", misctable_name
, misctable
);
2268 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
2270 g_snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", datatable_name
, datatable
);
2271 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
2273 maepad_warning("Cannot create data table");
2274 show_banner(mainview
, _("Error creating data table"));
2278 g_snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", checklisttable_name
, checklisttable
);
2279 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
2281 maepad_warning("Cannot create checklist table");
2282 show_banner(mainview
, _("Error creating checklist table"));
2287 sqlite3_close(mainview
->db
);
2288 mainview
->db
= NULL
;
2290 mainview
->file_name
= filename
;
2291 mainview
->file_edited
= FALSE
;
2292 read_file_to_buffer(mainview
);
2294 /*add a starter memo*/
2296 node
= g_malloc(sizeof(nodeData
));
2297 node
->typ
= NODE_SKETCH
;
2298 node
->name
= _("My first memo");
2299 node
->namepix
= NULL
;
2303 add_new_node(node
, mainview
, TRUE
);
2304 /*gtk_paned_set_position(GTK_PANED(mainview->hpaned), 180);*/
2305 write_buffer_to_file(mainview
);
2308 busy_reset(mainview
);
2311 gboolean
reset_ctree(GtkTreeModel
* model
, GtkTreePath
* path
, GtkTreeIter
* iter
, gpointer data
)
2315 gtk_tree_model_get(model
, iter
, NODE_DATA
, &node
, -1);
2321 g_object_unref(node
->namepix
);
2324 gtk_tree_store_set(GTK_TREE_STORE(model
), iter
, NODE_DATA
, NULL
, -1);
2329 void new_file(MainView
* mainview
)
2331 busy_enter(mainview
);
2333 * clear buffer, filename and free buffer text
2335 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mainview
->buffer
), "", -1);
2336 mainview
->file_name
= NULL
;
2337 mainview
->file_edited
= FALSE
;
2338 mainview
->newnodedialog_createchild
= TRUE
;
2340 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
));
2342 g_object_ref(model
);
2343 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), NULL
);
2345 gtk_tree_model_foreach(model
, (GtkTreeModelForeachFunc
) reset_ctree
, (gpointer
) mainview
);
2349 * gtk_tree_store_clear(GTK_TREE_STORE(model));
2351 GtkTreePath
*path
= gtk_tree_path_new_from_indices(0, -1);
2354 if (gtk_tree_model_get_iter(model
, &iter
, path
))
2358 gtk_tree_store_remove(GTK_TREE_STORE(model
), &iter
);
2360 while(gtk_tree_store_iter_is_valid(GTK_TREE_STORE(model
), &iter
));
2362 gtk_tree_path_free(path
);
2364 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), model
);
2365 g_object_unref(model
);
2367 busy_leave(mainview
);
2373 void callback_file_open(GtkAction
* action
, gpointer data
)
2375 gchar
*filename
= NULL
;
2376 MainView
*mainview
= (MainView
*) data
;
2377 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2379 filename
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_OPEN
, NULL
, NULL
);
2380 if (filename
== NULL
) {
2384 if (closefile(mainview
) == FALSE
) {
2388 open_file(filename
, mainview
);
2392 gboolean
open_file(gchar
* filename
, MainView
* mainview
)
2396 /* Don't open nodes when opening a file */
2397 mainview
->can_show_node_view
= FALSE
;
2399 busy_enter(mainview
);
2401 while(filename
!= NULL
)
2405 if (stat(filename
, &s
) == -1) break;
2407 mainview
->file_name
= g_strdup(filename
);
2408 gboolean res
= read_file_to_buffer(mainview
);
2412 g_free(mainview
->file_name
);
2413 mainview
->file_name
= NULL
;
2416 mainview
->file_edited
= FALSE
;
2421 busy_leave(mainview
);
2425 void callback_about_link(GtkAboutDialog
*about
, const gchar
*link
, gpointer data
)
2427 MainView
*mainview
= (MainView
*) data
;
2428 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2429 osso_rpc_run_with_defaults(mainview
->data
->osso
, "osso_browser", OSSO_BROWSER_OPEN_NEW_WINDOW_REQ
, NULL
,
2430 DBUS_TYPE_STRING
, link
, DBUS_TYPE_INVALID
);
2433 void callback_about(GtkAction
* action
, gpointer data
)
2435 MainView
* mainview
= (MainView
*)data
;
2436 he_about_dialog_present(mainview_get_dialog_parent(mainview
),
2437 NULL
/* auto-detect app name */,
2440 _("A node-based memory pad for Maemo"),
2441 _("(c) 2010 Thomas Perl"),
2442 "http://thpinfo.com/2010/maepad/",
2443 "https://garage.maemo.org/tracker/?group_id=1291",
2444 "http://thpinfo.com/2010/maepad/donate");
2450 void callback_file_save(GtkAction
* action
, gpointer data
)
2452 gchar
*filename
= NULL
;
2453 MainView
*mainview
= (MainView
*) data
;
2454 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2457 * check is we had a new file
2459 if (mainview
->file_name
!= NULL
)
2461 write_buffer_to_file(mainview
);
2465 filename
= interface_file_chooser(mainview
, GTK_FILE_CHOOSER_ACTION_SAVE
, "maemopaddata", "db");
2467 * if we got a file name from chooser -> save file
2469 if (filename
!= NULL
)
2471 mainview
->file_name
= filename
;
2472 write_buffer_to_file(mainview
);
2473 mainview
->file_edited
= FALSE
;
2478 void callback_shapemenu(GtkAction
* action
, GtkWidget
* wid
)
2480 gint style
= GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(wid
)));
2481 MainView
* mainview
= gtk_object_get_data(GTK_OBJECT(wid
), "m");
2482 g_assert(mainview
!= NULL
);
2484 if (style
>= 0 && style
< SKETCHSHAPE_COUNT
) {
2485 /* We use the sketch widget's enum for available styles */
2486 sketchwidget_set_shape(mainview
->sk
, style
);
2488 /* Draw the correct indicator for the current shape */
2489 GtkWidget
* pix
= GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(wid
), "i"));
2490 g_assert(pix
!= NULL
);
2491 gtk_widget_show(pix
);
2492 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(mainview
->shape_tb
), pix
);
2494 /* Fail. We shouldn't get here at all! */
2495 g_error("Invalid style ID from shape menu: %d", style
);
2501 void callback_eraser(GtkAction
* action
, MainView
* mainview
)
2503 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2505 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->eraser_tb
))) {
2506 /* Eraser on: Set pen color to white */
2507 GdkColor white
= { 0, 0xFFFF, 0xFFFF, 0xFFFF };
2508 sketchwidget_set_brushcolor(mainview
->sk
, white
);
2510 /* Eraser off: Set default color again (or black) */
2511 GdkColor black
= {0, 0, 0, 0};
2512 if (mainview
->current_color
== NULL
) {
2513 mainview
->current_color
= gdk_color_copy(&black
);
2515 sketchwidget_set_brushcolor(mainview
->sk
, *(mainview
->current_color
));
2519 void callback_menu(GtkAction
* action
, GtkWidget
* menu
)
2521 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
, NULL
, NULL
, 0, GDK_CURRENT_TIME
);
2524 void callback_brushsizetb(GtkAction
* action
, MainView
*mainview
)
2526 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2527 callback_menu(NULL
, mainview
->brushsizemenu
);
2530 void callback_brushsize(GtkAction
* action
, GtkWidget
* wid
)
2532 int bsize
= (int)gtk_object_get_user_data(GTK_OBJECT(wid
));
2533 MainView
*mainview
= gtk_object_get_data(GTK_OBJECT(wid
), "m");
2535 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2537 sketchwidget_set_brushsize(mainview
->sk
, bsize
);
2539 GtkWidget
*pix
= gtk_object_get_data(GTK_OBJECT(wid
), "i");
2541 gtk_widget_show(pix
);
2542 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(mainview
->brushsize_tb
), pix
);
2545 void callback_sketchlines(GtkAction
* action
, GtkWidget
* wid
)
2547 int style
= (int)gtk_object_get_user_data(GTK_OBJECT(wid
));
2548 MainView
*mainview
= gtk_object_get_data(GTK_OBJECT(wid
), "m");
2550 g_assert(mainview
!= NULL
);
2552 nodeData
*nd
= getSelectedNode(mainview
);
2553 gboolean doit
= FALSE
;
2555 if (nd
!= NULL
&& nd
->typ
== NODE_SKETCH
)
2557 nd
->flags
&= ~NODEFLAG_SKETCHLINES
;
2558 nd
->flags
&= ~NODEFLAG_SKETCHGRAPH
;
2559 /* sketchwidget_set_edited(mainview->sk, TRUE);*/ /*we call this on openfile, so this messes things up*/
2565 sketchwidget_set_backstyle(mainview
->sk
, SKETCHBACK_NONE
);
2567 else if (style
== 1)
2569 sketchwidget_set_backstyle(mainview
->sk
, SKETCHBACK_LINES
);
2571 nd
->flags
|= NODEFLAG_SKETCHLINES
;
2573 else if (style
== 2)
2575 sketchwidget_set_backstyle(mainview
->sk
, SKETCHBACK_GRAPH
);
2577 nd
->flags
|= NODEFLAG_SKETCHGRAPH
;
2580 GtkWidget
*pix
= gtk_object_get_data(GTK_OBJECT(wid
), "i");
2582 gtk_widget_show(pix
);
2583 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(mainview
->sketchlines_tb
), pix
);
2586 void callback_color(GtkAction
* action
, MainView
* mainview
)
2588 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2590 nodeData
*nd
= getSelectedNode(mainview
);
2591 if (nd
== NULL
) return;
2593 HeSimpleColorDialog
* dialog
= HE_SIMPLE_COLOR_DIALOG(he_simple_color_dialog_new());
2594 gtk_window_set_transient_for(GTK_WINDOW(dialog
), mainview_get_dialog_parent(mainview
));
2596 if (mainview
->current_color
) {
2597 he_simple_color_dialog_set_color(dialog
, mainview
->current_color
);
2600 if (gtk_dialog_run(GTK_DIALOG(dialog
)) != GTK_RESPONSE_OK
) {
2601 gtk_widget_destroy(GTK_WIDGET(dialog
));
2605 gdk_color_free(mainview
->current_color
);
2606 mainview
->current_color
= he_simple_color_dialog_get_color(dialog
);
2608 gtk_widget_destroy(GTK_WIDGET(dialog
));
2612 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->eraser_tb
), FALSE
);
2613 sketchwidget_set_brushcolor(mainview
->sk
, *(mainview
->current_color
));
2615 case NODE_CHECKLIST
:
2616 { /* Put in a separate block to allow new local variables */
2617 GtkTreeModel
* model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
2618 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
));
2619 GList
* selected
= gtk_tree_selection_get_selected_rows(selection
, NULL
);
2621 gchar
* color_string
= g_strdup_printf("#%02x%02x%02x",
2622 mainview
->current_color
->red
>> 8,
2623 mainview
->current_color
->green
>> 8,
2624 mainview
->current_color
->blue
>> 8);
2626 GList
* cur
= selected
;
2627 while (cur
!= NULL
) {
2628 GtkTreePath
* path
= cur
->data
;
2630 if (gtk_tree_model_get_iter(model
, &iter
, path
)) {
2631 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_COLOR
, color_string
, -1);
2633 gtk_tree_path_free(path
);
2637 g_list_free(selected
);
2638 g_free(color_string
);
2642 g_assert_not_reached();
2646 void callback_color_invoke(GtkAction
* action
, gpointer data
)
2648 MainView
*mainview
= (MainView
*) data
;
2649 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2650 gtk_button_clicked(GTK_BUTTON(mainview
->colorbutton_tb
));
2655 void callback_pressure(GtkAction
* action
, MainView
*mainview
)
2657 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2659 nodeData
*nd
= getSelectedNode(mainview
);
2663 if (nd
->typ
!= NODE_SKETCH
)
2666 /* pressure sensitivity disabled for now...
2667 mainview->sk->pressuresensitivity=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(mainview->tools_pressure));*/
2671 void callback_wordwrap(GtkWidget
* widget
, gpointer user_data
)
2673 MainView
* mainview
= (MainView
*)user_data
;
2674 nodeData
* nd
= getSelectedNode(mainview
);
2675 GtkWrapMode wrap_mode
;
2677 if (nd
== NULL
|| nd
->typ
!= NODE_TEXT
) {
2681 if (hildon_check_button_get_active(HILDON_CHECK_BUTTON(mainview
->menu_button_wordwrap
))) {
2682 nd
->flags
|= NODEFLAG_WORDWRAP
;
2683 wrap_mode
= GTK_WRAP_WORD_CHAR
;
2685 nd
->flags
&= ~NODEFLAG_WORDWRAP
;
2686 wrap_mode
= GTK_WRAP_NONE
;
2689 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(mainview
->textview
), wrap_mode
);
2693 void callback_font(GtkAction
* action
, gpointer data
)
2695 MainView
*mainview
= (MainView
*) data
;
2696 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2698 nodeData
*nd
= getSelectedNode(mainview
);
2702 if (nd
->typ
!= NODE_TEXT
)
2705 HildonFontSelectionDialog
*dialog
= HILDON_FONT_SELECTION_DIALOG(hildon_font_selection_dialog_new(NULL
, NULL
));
2707 gboolean gotsel
=wp_text_buffer_has_selection(mainview
->buffer
);
2710 WPTextBufferFormat fmt
;
2711 wp_text_buffer_get_attributes(mainview
->buffer
, &fmt
, gotsel
);
2714 if (fmt
.text_position
==TEXT_POSITION_SUPERSCRIPT
) ri
=1;
2715 else if (fmt
.text_position
==TEXT_POSITION_SUBSCRIPT
) ri
=-1;
2717 g_object_set(G_OBJECT(dialog
),
2718 "family-set", fmt
.cs
.font
,
2719 "family", wp_get_font_name(fmt
.font
),
2720 "size-set", fmt
.cs
.font_size
,
2721 "size", wp_font_size
[fmt
.font_size
],
2722 "color-set", fmt
.cs
.color
,
2723 "color", &fmt
.color
,
2724 "bold-set", fmt
.cs
.bold
,
2726 "italic-set", fmt
.cs
.italic
,
2727 "italic", fmt
.italic
,
2728 "underline-set", fmt
.cs
.underline
,
2729 "underline", fmt
.underline
,
2730 "strikethrough-set", fmt
.cs
.strikethrough
,
2731 "strikethrough", fmt
.strikethrough
,
2732 "position-set", fmt
.cs
.text_position
,
2736 gtk_widget_show_all(GTK_WIDGET(dialog
));
2737 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_OK
)
2739 gboolean bold
, italic
, underline
, strikethrough
;
2740 gchar
*family
= NULL
;
2741 gint size
, position
;
2742 GdkColor
*color
=NULL
;
2743 gboolean set_family
, set_size
, set_bold
, set_italic
, set_underline
, set_strikethrough
, set_color
, set_position
;
2745 g_object_get(G_OBJECT(dialog
), "family", &family
, "size", &size
, "bold", &bold
, "italic", &italic
,
2746 "underline", &underline
, "strikethrough", &strikethrough
,
2747 "family-set", &set_family
, "size-set", &set_size
, "bold-set", &set_bold
, "italic-set", &set_italic
,
2748 "underline-set", &set_underline
, "strikethrough-set", &set_strikethrough
,
2749 "color", &color
, "color-set", &set_color
, "position", &position
, "position-set", &set_position
,
2752 wp_text_buffer_get_attributes(mainview
->buffer
, &fmt
, FALSE
);
2753 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;
2755 if (set_family
) { fmt
.font
=wp_get_font_index(family
, 1); fmt
.cs
.font
=1; }
2756 if (set_size
) { fmt
.font_size
=wp_get_font_size_index(size
, 16); fmt
.cs
.font_size
=1; }
2758 if (set_strikethrough
)
2760 fmt
.cs
.strikethrough
=1;
2761 fmt
.strikethrough
=strikethrough
;
2767 GLIB WARNING ** GLib-GObject - IA__g_object_set_valist: object class `GtkTextTag' has no property named `'
2770 fmt
.color
.pixel
=color
->pixel
;
2771 fmt
.color
.red
=color
->red
;
2772 fmt
.color
.green
=color
->green
;
2773 fmt
.color
.blue
=color
->blue
;
2778 if (position
==1) ri
=TEXT_POSITION_SUPERSCRIPT
;
2779 else if (position
==-1) ri
=TEXT_POSITION_SUBSCRIPT
;
2780 else ri
=TEXT_POSITION_NORMAL
;
2782 fmt
.cs
.text_position
=1;
2783 fmt
.text_position
=ri
;
2799 fmt
.underline
=underline
;
2802 wp_text_buffer_set_format(mainview
->buffer
, &fmt
);
2805 gtk_widget_destroy(GTK_WIDGET(dialog
));
2808 void callback_fontstyle(GtkAction
* action
, GtkWidget
* wid
)
2810 MainView
*mainview
= gtk_object_get_data(GTK_OBJECT(wid
), "m");
2811 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2813 nodeData
*nd
= getSelectedNode(mainview
);
2817 if (nd
->typ
== NODE_TEXT
)
2819 gboolean act
=gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(wid
));
2821 gint style
= (gint
)gtk_object_get_data(GTK_OBJECT(wid
), "s");
2822 wp_text_buffer_set_attribute(mainview
->buffer
, style
, (gpointer
)act
);
2824 else if (nd
->typ
== NODE_CHECKLIST
)
2826 gboolean act
=gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(wid
));
2827 gint style
= (gint
)gtk_object_get_data(GTK_OBJECT(wid
), "s");
2828 if (style
!=WPT_BOLD
&& style
!=WPT_STRIKE
&& style
!=WPT_LEFT
) return;
2830 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
2831 GList
* l
=gtk_tree_selection_get_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
)), NULL
);
2833 gint styletoset_weight
=PANGO_WEIGHT_NORMAL
;
2834 gboolean styletoset_strike
=FALSE
;
2835 gboolean checkit
=FALSE
;
2837 if (style
==WPT_BOLD
&& act
==TRUE
) styletoset_weight
=PANGO_WEIGHT_BOLD
;
2838 else if (style
==WPT_STRIKE
&& act
==TRUE
) styletoset_strike
=TRUE
;
2839 else if (style
==WPT_LEFT
&& act
==TRUE
) checkit
=TRUE
;
2844 GtkTreePath
*path
=cur
->data
;
2847 if (gtk_tree_model_get_iter(model
, &iter
, path
))
2849 if (style
==WPT_BOLD
) gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_BOLD
, styletoset_weight
, -1);
2850 else if (style
==WPT_STRIKE
) gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_STRIKE
, styletoset_strike
, -1);
2851 else if (style
==WPT_LEFT
) {
2852 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_CHECKED
, checkit
, -1);
2854 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_ICON_NAME
, "widgets_tickmark_list", -1);
2856 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_ICON_NAME
, NULL
, -1);
2860 gtk_tree_path_free(path
);
2865 mainview
->checklist_edited
= TRUE
;
2870 callback_sharing(GtkWidget
* widget
, gpointer user_data
)
2872 MainView
* mainview
= (MainView
*)user_data
;
2873 nodeData
* nd
= getSelectedNode(mainview
);
2874 gchar
* filename
= g_strdup("/tmp/untitled.png");
2877 if (nd
== NULL
|| nd
->typ
!= NODE_SKETCH
) {
2878 show_banner(mainview
, _("Only sketches can be shared"));
2882 if (nd
->name
!= NULL
) {
2884 filename
= g_strdup_printf("/tmp/%s.png", nd
->name
);
2887 busy_enter(mainview
);
2888 GdkPixmap
* skpix
= sketchwidget_get_Pixmap(mainview
->sk
);
2889 GtkWidget
* skdr
= sketchwidget_get_drawingarea(mainview
->sk
);
2890 GdkPixbuf
* pixbuf
= gdk_pixbuf_get_from_drawable(NULL
,
2891 GDK_DRAWABLE(skpix
), NULL
, 0, 0, 0, 0,
2892 skdr
->allocation
.width
, skdr
->allocation
.height
);
2894 if (pixbuf
== NULL
) {
2895 show_banner(mainview
, _("Memo is empty"));
2899 if (!gdk_pixbuf_save(pixbuf
, filename
, "png", NULL
, NULL
)) {
2900 show_banner(mainview
, _("File export failed"));
2904 uri
= g_strdup_printf("file://%s", filename
);
2906 sharing_dialog_with_file(mainview
->data
->osso
,
2907 mainview_get_dialog_parent(mainview
),
2911 g_object_unref(skpix
);
2914 busy_leave(mainview
);
2918 callback_remove_checked(GtkWidget
* widget
, gpointer user_data
)
2920 MainView
* mainview
= (MainView
*)user_data
;
2921 nodeData
* nd
= getSelectedNode(mainview
);
2923 GtkTreeModel
* model
= NULL
;
2924 GList
* checked_items
= NULL
;
2925 gchar
* question
= NULL
;
2928 if (nd
== NULL
|| nd
->typ
!= NODE_CHECKLIST
) {
2932 /* Get a list of checked items */
2933 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
2934 if (!gtk_tree_model_get_iter_first(model
, &iter
)) {
2938 busy_enter(mainview
);
2940 gboolean checked
= FALSE
;
2941 gtk_tree_model_get(model
, &iter
, CHECKNODE_CHECKED
, &checked
, -1);
2944 GtkTreePath
* path
= gtk_tree_model_get_path(model
, &iter
);
2946 checked_items
= g_list_append(checked_items
,
2947 gtk_tree_row_reference_new(model
, path
));
2950 gtk_tree_path_free(path
);
2952 } while (gtk_tree_model_iter_next(model
, &iter
));
2953 busy_leave(mainview
);
2955 if (checked_items
== NULL
) {
2956 show_banner(mainview
, _("No checked items in checklist"));
2960 question
= g_strdup_printf(N_("Remove %d checked item?", "Remove %d checked items?", count
), count
);
2961 if (show_confirmation(mainview
, question
)) {
2962 /* Remove the checklist items from the list */
2963 checklist_remove_rowrefs(mainview
, checked_items
, TRUE
);
2965 /* Free the allocated row references + list */
2966 GList
* cur
= checked_items
;
2967 while (cur
!= NULL
) {
2968 GtkTreeRowReference
* rowref
= cur
->data
;
2969 gtk_tree_row_reference_free(rowref
);
2972 g_list_free(checked_items
);
2977 void callback_textbuffer_move(WPTextBuffer
*textbuffer
, MainView
*mainview
)
2979 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
2982 gboolean gotsel=wp_text_buffer_has_selection(mainview->buffer);
2984 _toggle_tool_button_set_inconsistent(GTK_TOGGLE_TOOL_BUTTON(mainview->bold_tb), gotsel);
2985 _toggle_tool_button_set_inconsistent(GTK_TOGGLE_TOOL_BUTTON(mainview->italic_tb), gotsel);
2986 _toggle_tool_button_set_inconsistent(GTK_TOGGLE_TOOL_BUTTON(mainview->underline_tb), gotsel);
2987 _toggle_tool_button_set_inconsistent(GTK_TOGGLE_TOOL_BUTTON(mainview->bullet_tb), gotsel);
2989 WPTextBufferFormat fmt
;
2990 wp_text_buffer_get_attributes(mainview
->buffer
, &fmt
, FALSE
/*gotsel*/);
2992 g_signal_handlers_block_by_func(mainview
->bold_tb
, callback_fontstyle
, mainview
->bold_tb
);
2993 g_signal_handlers_block_by_func(mainview
->italic_tb
, callback_fontstyle
, mainview
->italic_tb
);
2994 g_signal_handlers_block_by_func(mainview
->underline_tb
, callback_fontstyle
, mainview
->underline_tb
);
2995 g_signal_handlers_block_by_func(mainview
->bullet_tb
, callback_fontstyle
, mainview
->bullet_tb
);
2997 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->bold_tb
), fmt
.bold
);
2998 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->italic_tb
), fmt
.italic
);
2999 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->underline_tb
), fmt
.underline
);
3000 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->bullet_tb
), fmt
.bullet
);
3002 g_signal_handlers_unblock_by_func(mainview
->bold_tb
, callback_fontstyle
, mainview
->bold_tb
);
3003 g_signal_handlers_unblock_by_func(mainview
->italic_tb
, callback_fontstyle
, mainview
->italic_tb
);
3004 g_signal_handlers_unblock_by_func(mainview
->underline_tb
, callback_fontstyle
, mainview
->underline_tb
);
3005 g_signal_handlers_unblock_by_func(mainview
->bullet_tb
, callback_fontstyle
, mainview
->bullet_tb
);
3008 gint
wp_savecallback(const gchar
*buffer
, GString
* gstr
)
3010 gstr
=g_string_append(gstr
, buffer
);
3014 void callback_undo(GtkAction
* action
, MainView
* mainview
)
3016 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3018 nodeData
*nd
= getSelectedNode(mainview
);
3020 if (nd
== NULL
) return;
3022 if (nd
->typ
== NODE_SKETCH
) sketchwidget_undo(mainview
->sk
);
3023 else if (nd
->typ
== NODE_TEXT
) wp_text_buffer_undo(mainview
->buffer
);
3026 void callback_redo(GtkAction
* action
, MainView
* mainview
)
3028 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3030 nodeData
*nd
= getSelectedNode(mainview
);
3032 if (nd
== NULL
) return;
3034 if (nd
->typ
== NODE_SKETCH
) sketchwidget_redo(mainview
->sk
);
3035 else if (nd
->typ
== NODE_TEXT
) wp_text_buffer_redo(mainview
->buffer
);
3038 void callback_undotoggle(gpointer widget
, gboolean st
, MainView
* mainview
)
3040 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3042 gtk_widget_set_sensitive(GTK_WIDGET(mainview
->undo_tb
), st
);
3045 void callback_redotoggle(gpointer widget
, gboolean st
, MainView
* mainview
)
3047 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3049 gtk_widget_set_sensitive(GTK_WIDGET(mainview
->redo_tb
), st
);
3052 gboolean
close_cb(GtkWidget
* widget
, GdkEventAny
* event
, MainView
* mainview
)
3054 callback_file_close(NULL
, mainview
);
3059 mainview_click_on_current_node(MainView
* mainview
)
3061 GtkTreeSelection
* selection
= NULL
;
3062 GtkTreeModel
* model
= NULL
;
3065 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
3066 if (gtk_tree_selection_get_selected(selection
, &model
, &iter
)) {
3067 GtkTreePath
* path
= gtk_tree_model_get_path(model
, &iter
);
3069 mainview
->can_show_node_view
= TRUE
;
3070 gtk_tree_view_set_cursor(GTK_TREE_VIEW(mainview
->treeview
),
3073 gtk_tree_path_free(path
);
3078 on_main_view_key_press(GtkWidget
* widget
, GdkEventKey
* event
, gpointer user_data
)
3080 MainView
* mainview
= (MainView
*)user_data
;
3081 gboolean result
= FALSE
;
3083 switch (event
->keyval
) {
3088 /* Open selected memo in node view */
3089 mainview_click_on_current_node(mainview
);
3094 /* Save changes to file ("write buffer") */
3095 callback_file_save(NULL
, mainview
);
3099 /* Delete selected node (with confirmation) */
3100 callback_file_delete_node(NULL
, mainview
);
3105 /* Add new memo to list */
3106 callback_file_new_node(NULL
, mainview
);
3111 /* Replace (edit) name of selected memo */
3112 callback_file_rename_node(NULL
, mainview
);
3116 if (mainview
->main_view_prev_keyval
== GDK_g
) {
3117 /* Goto (=select) first memo */
3118 mainview
->can_show_node_view
= FALSE
;
3119 nodelist_select(mainview
, TREEVIEW_SELECT_FIRST
);
3121 /* Don't remember this key for the next keypress */
3122 mainview
->main_view_prev_keyval_reset
= TRUE
;
3128 /* Goto (=select) last memo */
3129 mainview
->can_show_node_view
= FALSE
;
3130 nodelist_select(mainview
, TREEVIEW_SELECT_LAST
);
3136 /* Goto (=select) next memo */
3137 mainview
->can_show_node_view
= FALSE
;
3138 nodelist_select(mainview
, TREEVIEW_SELECT_NEXT
);
3144 /* Goto (=select) previous memo */
3145 mainview
->can_show_node_view
= FALSE
;
3146 nodelist_select(mainview
, TREEVIEW_SELECT_PREVIOUS
);
3158 on_node_view_key_press(GtkWidget
* widget
, GdkEventKey
* event
, gpointer user_data
)
3160 MainView
* mainview
= (MainView
*)user_data
;
3161 nodeData
* nd
= getSelectedNode(mainview
);
3162 gboolean result
= FALSE
;
3168 switch (event
->keyval
) {
3171 if (nd
->typ
!= NODE_TEXT
) {
3172 /* Save changes to file ("write buffer") */
3173 callback_file_save(NULL
, mainview
);
3178 if (event
->state
& GDK_SHIFT_MASK
) {
3179 /* Remove current memo (with confirmation) */
3180 callback_file_delete_node(NULL
, mainview
);
3182 } else if (nd
->typ
== NODE_CHECKLIST
) {
3183 /* Remove current item (with confirmation) */
3184 callback_checklist_delete(NULL
, mainview
);
3186 } else if (nd
->typ
== NODE_SKETCH
) {
3187 /* Undo last sketch action */
3188 callback_undo(NULL
, mainview
);
3193 if (nd
->typ
== NODE_CHECKLIST
) {
3194 /* Toggle check of current item */
3195 maepad_toggle_gtk_toggle_tool_button(mainview
->check_tb
);
3197 } else if (nd
->typ
== NODE_SKETCH
) {
3198 /* Toggle eraser tool */
3199 maepad_toggle_gtk_toggle_tool_button(mainview
->eraser_tb
);
3205 if (nd
->typ
!= NODE_TEXT
) {
3206 /* Toggle fullscreen mode */
3207 callback_fullscreen(NULL
, mainview
);
3213 if (nd
->typ
!= NODE_TEXT
) {
3214 /* Hide node view, go to main view ("left") */
3215 gtk_widget_hide(GTK_WIDGET(mainview
->data
->node_view
));
3221 if (nd
->typ
== NODE_CHECKLIST
) {
3222 /* Insert new checklist item */
3223 callback_checklist_add(NULL
, mainview
);
3228 if (nd
->typ
== NODE_CHECKLIST
) {
3229 if (mainview
->node_view_prev_keyval
== GDK_d
) {
3230 /* Yank selected items, then remove them silently */
3231 callback_edit_copy(NULL
, mainview
);
3232 callback_checklist_delete_real(mainview
);
3233 show_banner(mainview
, _("Item yanked to clipboard"));
3235 /* Don't remember this key for the next keypress */
3236 mainview
->node_view_prev_keyval_reset
= TRUE
;
3243 if (nd
->typ
== NODE_CHECKLIST
) {
3244 if (mainview
->node_view_prev_keyval
== GDK_y
) {
3245 /* Non-destructive yanking of items */
3246 callback_edit_copy(NULL
, mainview
);
3247 show_banner(mainview
, _("Item yanked to clipboard"));
3249 /* Don't remember this key for the next keypress */
3250 mainview
->node_view_prev_keyval_reset
= TRUE
;
3258 if (nd
->typ
== NODE_CHECKLIST
) {
3259 /* Paste text in clipboard as items */
3260 callback_edit_paste(NULL
, mainview
);
3265 if (nd
->typ
== NODE_CHECKLIST
) {
3266 if (mainview
->node_view_prev_keyval
== GDK_g
) {
3267 /* Goto (=select) first item */
3268 checklist_select(mainview
, TREEVIEW_SELECT_FIRST
);
3270 /* Don't remember this key for the next keypress */
3271 mainview
->node_view_prev_keyval_reset
= TRUE
;
3278 if (nd
->typ
== NODE_CHECKLIST
) {
3279 /* Goto (=select) last item */
3280 checklist_select(mainview
, TREEVIEW_SELECT_LAST
);
3287 if (nd
->typ
== NODE_CHECKLIST
) {
3288 /* Goto (=select) next item */
3289 checklist_select(mainview
, TREEVIEW_SELECT_NEXT
);
3291 } else if (nd
->typ
== NODE_SKETCH
) {
3292 /* Undo last sketch operation */
3293 callback_undo(NULL
, mainview
);
3300 if (nd
->typ
== NODE_CHECKLIST
) {
3301 /* Goto (=select) previous item */
3302 checklist_select(mainview
, TREEVIEW_SELECT_PREVIOUS
);
3304 } else if (nd
->typ
== NODE_SKETCH
) {
3305 /* Redo last sketch operation */
3306 callback_redo(NULL
, mainview
);
3312 if (nd
->typ
== NODE_CHECKLIST
) {
3313 /* Append text to current node */
3314 checklist_edit_selected(mainview
, LINE_EDIT_MODE_APPEND
);
3322 if (nd
->typ
== NODE_CHECKLIST
) {
3323 /* Replace (edit) text of current node */
3324 checklist_edit_selected(mainview
, LINE_EDIT_MODE_DEFAULT
);
3330 if (nd
->typ
== NODE_CHECKLIST
) {
3331 /* Prepend (insert) text to current node */
3332 checklist_edit_selected(mainview
, LINE_EDIT_MODE_PREPEND
);
3345 on_main_view_key_release(GtkWidget
* widget
, GdkEventKey
* event
, gpointer user_data
)
3347 MainView
* mainview
= (MainView
*)user_data
;
3349 if (mainview
->main_view_prev_keyval_reset
) {
3350 /* Forget last-pressed key value */
3351 mainview
->main_view_prev_keyval
= GDK_VoidSymbol
;
3352 mainview
->main_view_prev_keyval_reset
= FALSE
;
3354 /* Remember last keyval for double-press bindings */
3355 mainview
->main_view_prev_keyval
= event
->keyval
;
3362 on_node_view_key_release(GtkWidget
* widget
, GdkEventKey
* event
, gpointer user_data
)
3364 MainView
* mainview
= (MainView
*)user_data
;
3366 if (mainview
->node_view_prev_keyval_reset
) {
3367 /* Forget last-pressed key value */
3368 mainview
->node_view_prev_keyval
= GDK_VoidSymbol
;
3369 mainview
->node_view_prev_keyval_reset
= FALSE
;
3371 /* Remember last keyval for double-press bindings */
3372 mainview
->node_view_prev_keyval
= event
->keyval
;
3379 on_checklist_longpress_timeout(gpointer user_data
)
3381 MainView
* mainview
= (MainView
*)user_data
;
3382 callback_checklist_edit(NULL
, mainview
);
3383 mainview
->checklist_longpress_source_id
= 0;
3388 on_checklist_button_press(GtkWidget
* widget
, GdkEventButton
* event
, gpointer user_data
)
3390 MainView
* mainview
= (MainView
*)user_data
;
3392 GtkTreeViewColumn
* column
;
3393 GtkTreeSelection
* selection
;
3395 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget
),
3402 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(widget
));
3404 if (gtk_tree_selection_path_is_selected(selection
, path
)) {
3405 if (column
== mainview
->checklist_column_check
) {
3406 /* Check column touched - toggle checklist item */
3407 maepad_toggle_gtk_toggle_tool_button(mainview
->check_tb
);
3408 } else if (column
== mainview
->checklist_column_text
) {
3409 mainview
->checklist_longpress_source_id
= g_timeout_add(
3410 CHECKLIST_LONGPRESS_EDIT_DELAY
,
3411 on_checklist_longpress_timeout
,
3417 gtk_tree_path_free(path
);
3424 checklist_abort_longpress(MainView
* mainview
)
3426 /* Abort the longpress action on the checklist */
3427 if (mainview
->checklist_longpress_source_id
!= 0) {
3428 g_source_remove(mainview
->checklist_longpress_source_id
);
3429 mainview
->checklist_longpress_source_id
= 0;
3434 on_checklist_button_release(GtkWidget
* widget
, GdkEventButton
* event
, gpointer user_data
)
3436 MainView
* mainview
= (MainView
*)user_data
;
3437 checklist_abort_longpress(mainview
);
3442 on_checklist_start_panning(HildonPannableArea
* area
, gpointer user_data
)
3444 MainView
* mainview
= (MainView
*)user_data
;
3445 checklist_abort_longpress(mainview
);
3449 void callback_fullscreen(GtkToolButton
* tool_button
, gpointer user_data
)
3451 MainView
* mainview
= (MainView
*)user_data
;
3452 gtk_window_fullscreen(GTK_WINDOW(mainview
->data
->node_view
));
3456 callback_sketch_button_toggled(HildonCheckButton
* button
, gpointer user_data
)
3458 MainView
* mainview
= (MainView
*)user_data
;
3459 gboolean active
= hildon_check_button_get_active(button
);
3461 if (GTK_WIDGET(button
) == GTK_WIDGET(mainview
->menu_button_square
)) {
3462 sketchwidget_set_shift(mainview
->sk
, active
);
3463 } else if (GTK_WIDGET(button
) == GTK_WIDGET(mainview
->menu_button_filled
)) {
3464 sketchwidget_set_fillmode(mainview
->sk
, active
);
3468 void callback_buffer_modified(GtkAction
* action
, gpointer data
)
3470 MainView
*mainview
= (MainView
*) data
;
3471 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
3473 mainview
->file_edited
= TRUE
;
3476 GtkTreeRowReference
*read_sqlite3_data(MainView
* mainview
, unsigned int parentid
, GtkTreeRowReference
* parenttree
, unsigned int selected
, GtkTreeStore
* model
)
3478 GtkTreeRowReference
*resref
= NULL
;
3482 g_snprintf(q
, sizeof(q
), "SELECT nodeid, bodytype, name, nameblob, lastmodified, flags FROM %s WHERE parent=%d ORDER BY ord", datatable_tmpname
, parentid
);
3484 sqlite3_stmt
*stmt
= NULL
;
3486 int rc
= sqlite3_prepare(mainview
->db
, q
, strlen(q
), &stmt
, &dum
);
3490 maepad_warning("Error reading SQLite3 data: %s", sqlite3_errmsg(mainview
->db
));
3495 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
3497 rc
= sqlite3_step(stmt
);
3498 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
3500 else if (rc
== SQLITE_ROW
)
3502 int nodeid
= sqlite3_column_int(stmt
, 0);
3503 int typ
= sqlite3_column_int(stmt
, 1);
3504 const unsigned char *name
= sqlite3_column_text(stmt
, 2);
3505 const unsigned char *nameblob
= sqlite3_column_text(stmt
, 3);
3506 int lastmod
= sqlite3_column_int(stmt
, 4);
3507 int flags
= sqlite3_column_int(stmt
, 5);
3509 if ((typ
!= NODE_TEXT
&& typ
!= NODE_SKETCH
&& typ
!= NODE_CHECKLIST
) || (name
== NULL
&& nameblob
== NULL
)) {
3510 maepad_warning("Unknown node type in database: %d (skipping)", typ
);
3514 nodeData
*node
= g_malloc(sizeof(nodeData
));
3516 node
->sql3id
= nodeid
;
3518 node
->flags
= flags
;
3520 node
->namepix
= NULL
;
3522 node
->name
= g_strdup((char *)name
);
3524 node
->name
= g_strdup(_("Unnamed memo"));
3526 /*if (nameblob != NULL)
3528 int blobsize = sqlite3_column_bytes(stmt, 3);
3530 GdkPixbufLoader *pl = gdk_pixbuf_loader_new_with_type("png", NULL);
3533 gdk_pixbuf_loader_write(pl, (guchar *) nameblob, blobsize, &err);
3536 fprintf(stderr, "Error loading nodename! %s\n", err->message);
3540 gdk_pixbuf_loader_close(pl, NULL);
3541 GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf(pl);
3543 if (GDK_IS_PIXBUF(pixbuf))
3544 node->namepix = pixbuf;
3546 node
->lastMod
= lastmod
;
3548 GtkTreeIter parentiter
, newiter
;
3551 if (parenttree
!= NULL
)
3553 GtkTreePath
*pa
= gtk_tree_row_reference_get_path(parenttree
);
3555 gtk_tree_model_get_iter(GTK_TREE_MODEL(model
), &parentiter
, pa
);
3556 gtk_tree_path_free(pa
);
3560 gtk_tree_store_append(model
, &newiter
, par
);
3561 gtk_tree_store_set(model
, &newiter
, NODE_NAME
, node
->name
, NODE_PIXBUF
, node
->namepix
, NODE_DATA
, node
, -1);
3563 GtkTreePath
*pa
= gtk_tree_model_get_path(GTK_TREE_MODEL(model
), &newiter
);
3565 GtkTreeRowReference
*newref
= gtk_tree_row_reference_new(GTK_TREE_MODEL(model
), pa
);
3567 if (selected
== nodeid
)
3570 gtk_tree_path_free(pa
);
3571 GtkTreeRowReference
*r
= read_sqlite3_data(mainview
, nodeid
, newref
, selected
,
3574 if (resref
!= newref
)
3575 gtk_tree_row_reference_free(newref
);
3582 gtk_tree_row_reference_free(r
); /*safeguard */
3588 sqlite3_finalize(stmt
);
3590 return (resref
); /*ref to supposed-to-be-selected treeitem */
3596 gboolean
read_file_to_buffer(MainView
* mainview
)
3600 g_assert(mainview
!= NULL
);
3601 gboolean res
= FALSE
;
3603 gchar
*filename
= mainview
->file_name
;
3606 mainview
->file_name
= filename
;
3607 mainview
->loading
=TRUE
;
3609 maepad_message("Reading database file: %s", filename
);
3612 sqlite3_stmt
*stmt
= NULL
;
3614 rc
= sqlite3_open(filename
, &mainview
->db
);
3619 maepad_warning("Cannot open database %s: %s", filename
, sqlite3_errmsg(mainview
->db
));
3623 sqlite3_exec(mainview
->db
, "PRAGMA synchronous = OFF;", NULL
, NULL
, NULL
);
3625 char *q
= "SELECT skey, sval FROM settings";
3628 rc
= sqlite3_prepare(mainview
->db
, q
, strlen(q
), &stmt
, &dum
);
3631 maepad_warning("Error reading settings: %s", sqlite3_errmsg(mainview
->db
));
3635 unsigned int selectedCard
= 0;
3636 unsigned int curDataVersion
= 0;
3637 unsigned int curChecklistVersion
= 0;
3640 while(rc
== SQLITE_BUSY
|| rc
== SQLITE_ROW
)
3642 rc
= sqlite3_step(stmt
);
3643 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
|| rc
== SQLITE_DONE
)
3645 else if (rc
== SQLITE_ROW
)
3647 const gchar
* col_key
= (const gchar
*)sqlite3_column_text(stmt
, 0);
3648 const gchar
* col_val
= (const gchar
*)sqlite3_column_text(stmt
, 1);
3649 if (!strcmp(col_key
, "selectedNode"))
3651 gint tmp
= atoi((char *)col_val
);
3656 if (!strcmp(col_key
, "dataVersion"))
3658 gint tmp
= atoi((char *)col_val
);
3661 curDataVersion
= tmp
;
3663 if (!strcmp(col_key
, "checklistVersion"))
3665 gint tmp
= atoi((char *)col_val
);
3668 curChecklistVersion
= tmp
;
3670 if (!strcmp(col_key
, "newNodeDlgCreateChild"))
3672 gint tmp
= atoi((char *)col_val
);
3674 mainview
->newnodedialog_createchild
= TRUE
;
3676 mainview
->newnodedialog_createchild
= FALSE
;
3678 if (!strcmp(col_key
, "brushSize"))
3680 gint tmp
= atoi((char *)col_val
);
3681 if (tmp
>0) sk_set_brushsize(mainview
, tmp
);
3683 if (!strcmp(col_key
, "brushColor"))
3685 unsigned long tmp
= atol((char *)col_val
);
3688 c2
.red
= ((tmp
& 0xFF0000) >> 16) << 8;
3689 c2
.green
= ((tmp
& 0xFF00) >> 8) << 8;
3690 c2
.blue
= (tmp
& 0xFF) << 8;
3691 sketchwidget_set_brushcolor(mainview
->sk
, c2
);
3693 if (mainview
->current_color
!= NULL
) {
3694 gdk_color_free(mainview
->current_color
);
3696 mainview
->current_color
= gdk_color_copy(&c2
);
3701 if (rc
== SQLITE_ERROR
|| rc
== SQLITE_MISUSE
)
3703 maepad_warning("Error reading data: %s", sqlite3_errmsg(mainview
->db
));
3708 sqlite3_finalize(stmt
);
3712 gboolean resback
= FALSE
;
3714 while(curDataVersion
< datatableversion
)
3716 if (curDataVersion
== 0)
3718 g_snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_backupname
);
3719 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3721 g_snprintf(tq
, sizeof(tq
), "ALTER TABLE %s RENAME TO %s", datatable_name
, datatable_backupname
);
3722 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3723 maepad_warning("Error backing up table %s to %s", datatable_name
, datatable_backupname
);
3728 g_snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", datatable_name
, datatable
);
3729 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3730 maepad_warning("Error creating table: %s", datatable_name
);
3733 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT nodeid, parent, bodytype, name, body, nameblob, bodyblob, lastmodified, ord, 0 FROM %s", datatable_name
, datatable_backupname
);
3734 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3735 maepad_warning("Error copying data from %s to %s", datatable_name
, datatable_backupname
);
3739 g_snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_backupname
);
3740 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3742 curDataVersion
= datatableversion
;
3747 if (curDataVersion
!= datatableversion
)
3749 maepad_warning("Data table version mismatch: %d <=> %d", curDataVersion
, datatableversion
);
3751 if (resback
== TRUE
)
3753 g_snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_name
);
3754 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3755 g_snprintf(tq
, sizeof(tq
), "ALTER TABLE %s RENAME TO %s", datatable_backupname
, datatable_name
);
3756 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3763 while(curChecklistVersion
< checklisttableversion
)
3765 if (curChecklistVersion
== 0) /*no checklisttable at all*/
3767 g_snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", checklisttable_name
, checklisttable
);
3768 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3769 maepad_warning("Error creating checklist table during schema upgrade");
3772 curChecklistVersion
= checklisttableversion
;
3778 GtkTreeStore
*model
= GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
)));
3780 g_object_ref(model
);
3781 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), NULL
);
3787 g_snprintf(tq
, sizeof(tq
), "CREATE%s TABLE %s%s", TEMPTABLE_KEYWORD
, datatable_tmpname
, datatable
);
3788 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3789 maepad_warning("Error creating temp table: %s", datatable_tmpname
);
3792 g_snprintf(tq
, sizeof(tq
), "CREATE INDEX %s_index ON %s %s", datatable_tmpname
, datatable_tmpname
, dataindex
);
3793 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3794 maepad_warning("Error creating temp index for %s", datatable_tmpname
);
3797 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", datatable_tmpname
, datatable_name
);
3798 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3799 maepad_warning("Error copying data from %s to %s", datatable_name
, datatable_tmpname
);
3803 g_snprintf(tq
, sizeof(tq
), "CREATE%s TABLE %s%s", TEMPTABLE_KEYWORD
, checklisttable_tmpname
, checklisttable
);
3804 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3805 maepad_warning("Error creating temp table: %s", checklisttable_tmpname
);
3808 g_snprintf(tq
, sizeof(tq
), "CREATE INDEX %s_index ON %s %s", checklisttable_tmpname
, checklisttable_tmpname
, checklistindex
);
3809 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3810 maepad_warning("Error creating temp index for %s", checklisttable_tmpname
);
3813 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", checklisttable_tmpname
, checklisttable_name
);
3814 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3815 maepad_warning("Error copying data from %s to %s", checklisttable_name
, checklisttable_tmpname
);
3821 GtkTreeRowReference
*selectedRef
= read_sqlite3_data(mainview
, 0, NULL
, selectedCard
, model
);
3823 gtk_tree_view_set_model(GTK_TREE_VIEW(mainview
->treeview
), GTK_TREE_MODEL(model
));
3824 g_object_unref(model
);
3825 gtk_tree_view_expand_all(GTK_TREE_VIEW(mainview
->treeview
));
3827 if (selectedRef
!= NULL
)
3829 GtkTreeIter seliter
;
3831 if (ref2iter(GTK_TREE_MODEL(model
), selectedRef
, &seliter
) == TRUE
)
3833 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->treeview
));
3834 gtk_tree_selection_select_iter(selection
, &seliter
);
3837 gtk_tree_row_reference_free(selectedRef
);
3844 sqlite3_finalize(stmt
);
3848 mainview
->loading
=FALSE
;
3856 void write_buffer_to_file(MainView
* mainview
)
3858 maepad_message("Writing database to file: %s", mainview
->file_name
);
3859 saveCurrentData(mainview
);
3861 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->treeview
));
3862 /*update ord value in database for all nodes*/
3863 gtk_tree_model_foreach(GTK_TREE_MODEL(model
),(GtkTreeModelForeachFunc
) foreach_func_update_ord
,mainview
);
3865 busy_enter(mainview
);
3869 g_snprintf(tq
, sizeof(tq
), "DROP TABLE %s", misctable_name
);
3870 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3872 g_snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", misctable_name
, misctable
);
3873 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3877 if (mainview
->newnodedialog_createchild
== FALSE
)
3879 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('newNodeDlgCreateChild', '%d');", misctable_name
, nndcc
);
3880 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3882 nodeData
*node
= getSelectedNode(mainview
);
3886 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('selectedNode', '%d');", misctable_name
, node
->sql3id
);
3887 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3890 guint bsize
= sketchwidget_get_brushsize(mainview
->sk
);
3891 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('brushSize', '%d');", misctable_name
, bsize
);
3892 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3894 if (mainview
->current_color
== NULL
) {
3895 GdkColor color
= {0, 0, 0, 0};
3896 mainview
->current_color
= gdk_color_copy(&color
);
3898 unsigned long bcol
= ((mainview
->current_color
->red
>> 8) << 16) |
3899 ((mainview
->current_color
->green
>> 8) << 8) |
3900 ((mainview
->current_color
->blue
) >> 8);
3902 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('brushColor', '%lu');", misctable_name
, bcol
);
3903 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3905 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('dataVersion', '%d');", misctable_name
, datatableversion
);
3906 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3908 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s VALUES('checklistVersion', '%d');", misctable_name
, checklisttableversion
);
3909 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3911 g_snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_backupname
);
3912 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3913 g_snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", datatable_backupname
, datatable
);
3914 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3916 maepad_warning("Error creating backup table: %s", datatable_backupname
);
3917 show_banner(mainview
, _("Error creating backup table"));
3919 busy_leave(mainview
);
3922 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", datatable_backupname
, datatable_name
);
3923 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3925 maepad_warning("Error backing up table %s to %s", datatable_name
, datatable_backupname
);
3926 show_banner(mainview
, _("Error creating backup table"));
3928 busy_leave(mainview
);
3931 g_snprintf(tq
, sizeof(tq
), "DELETE FROM %s", datatable_name
);
3932 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3934 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", datatable_name
, datatable_tmpname
);
3935 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3937 maepad_warning("Error saving table %s to %s", datatable_tmpname
, datatable_name
);
3938 show_banner(mainview
, _("Error saving table"));
3940 g_snprintf(tq
, sizeof(tq
), "DELETE FROM %s", datatable_name
);
3941 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3943 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", datatable_name
, datatable_backupname
);
3944 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3945 maepad_warning("Error restoring backup. Data lost :(");
3948 busy_leave(mainview
);
3952 g_snprintf(tq
, sizeof(tq
), "DROP TABLE %s", datatable_backupname
);
3953 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3956 g_snprintf(tq
, sizeof(tq
), "DROP TABLE %s", checklisttable_backupname
);
3957 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3958 g_snprintf(tq
, sizeof(tq
), "CREATE TABLE %s%s", checklisttable_backupname
, checklisttable
);
3959 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3961 maepad_warning("Error creating backup table: %s", checklisttable_backupname
);
3962 show_banner(mainview
, _("Error creating checklist backup table"));
3964 busy_leave(mainview
);
3968 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", checklisttable_backupname
, checklisttable_name
);
3969 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3971 maepad_warning("Error backing up table %s to %s", checklisttable_name
, checklisttable_backupname
);
3972 show_banner(mainview
, _("Error creating checklist backup table"));
3974 busy_leave(mainview
);
3977 g_snprintf(tq
, sizeof(tq
), "DELETE FROM %s", checklisttable_name
);
3978 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3980 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", checklisttable_name
, checklisttable_tmpname
);
3981 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0)
3983 maepad_warning("Error saving table %s to %s", checklisttable_tmpname
, checklisttable_name
);
3984 show_banner(mainview
, _("Error saving checklist table"));
3986 g_snprintf(tq
, sizeof(tq
), "DELETE FROM %s", checklisttable_name
);
3987 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
3989 g_snprintf(tq
, sizeof(tq
), "INSERT INTO %s SELECT * FROM %s", checklisttable_name
, checklisttable_backupname
);
3990 if (sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
) != 0) {
3991 maepad_warning("Error restoring backup. Data lost :(");
3993 busy_leave(mainview
);
3997 g_snprintf(tq
, sizeof(tq
), "DROP TABLE %s", checklisttable_backupname
);
3998 sqlite3_exec(mainview
->db
, tq
, NULL
, NULL
, NULL
);
4000 mainview
->file_edited
= FALSE
;
4001 busy_leave(mainview
);
4002 show_banner(mainview
, _("Changes saved"));
4005 void callback_checklist_change(GtkTreeSelection
*selection
, MainView
*mainview
)
4007 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
4009 g_signal_handlers_block_by_func(mainview
->bold_tb
, callback_fontstyle
, mainview
->bold_tb
);
4010 g_signal_handlers_block_by_func(mainview
->strikethru_tb
, callback_fontstyle
, mainview
->strikethru_tb
);
4011 g_signal_handlers_block_by_func(mainview
->check_tb
, callback_fontstyle
, mainview
->check_tb
);
4013 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->bold_tb
), FALSE
);
4014 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->strikethru_tb
), FALSE
);
4015 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->check_tb
), FALSE
);
4017 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
4018 GList
* l
=gtk_tree_selection_get_selected_rows(selection
, NULL
);
4020 gboolean gotit
=FALSE
;
4025 GtkTreePath
*path
=cur
->data
;
4030 if (gtk_tree_model_get_iter(model
, &iter
, path
))
4032 gint styletoset_weight
;
4033 gboolean styletoset_strike
;
4036 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
, CHECKNODE_BOLD
, &styletoset_weight
, CHECKNODE_STRIKE
, &styletoset_strike
, CHECKNODE_CHECKED
, &ischecked
, -1);
4037 if (styletoset_weight
==PANGO_WEIGHT_BOLD
) gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->bold_tb
), TRUE
);
4038 if (styletoset_strike
==TRUE
) gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->strikethru_tb
), TRUE
);
4039 if (ischecked
==TRUE
) gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(mainview
->check_tb
), TRUE
);
4043 gtk_tree_path_free(path
);
4049 g_signal_handlers_unblock_by_func(mainview
->bold_tb
, callback_fontstyle
, mainview
->bold_tb
);
4050 g_signal_handlers_unblock_by_func(mainview
->strikethru_tb
, callback_fontstyle
, mainview
->strikethru_tb
);
4051 g_signal_handlers_unblock_by_func(mainview
->check_tb
, callback_fontstyle
, mainview
->check_tb
);
4054 void callback_checklist_paste(MainView
*mainview
)
4056 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
4060 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
4061 GtkTreeIter toplevel
;
4062 gchar
*pasted_text
= gtk_clipboard_wait_for_text(mainview
->clipboard
);
4064 entries
= g_strsplit(pasted_text
, "\n", 0);
4065 length
= g_strv_length(entries
);
4067 for (i
=0; i
<length
; i
++) {
4068 gtk_list_store_append(GTK_LIST_STORE(model
), &toplevel
);
4069 gtk_list_store_set(GTK_LIST_STORE(model
), &toplevel
, CHECKNODE_CHECKED
, FALSE
, CHECKNODE_TEXT
, entries
[i
], -1);
4072 mainview
->checklist_edited
= TRUE
;
4073 g_free(pasted_text
);
4074 g_strfreev(entries
);
4077 void callback_checklist_add(GtkAction
*action
, MainView
*mainview
)
4079 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
4081 gchar
* text
= show_line_edit_dialog(mainview
, _("Add new checklist item"), _("Name:"), _("Add"), "");
4084 GtkTreeModel
* model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
4085 GtkTreeIter toplevel
;
4086 gtk_list_store_append(GTK_LIST_STORE(model
), &toplevel
);
4088 gtk_list_store_set(GTK_LIST_STORE(model
),
4090 CHECKNODE_CHECKED
, FALSE
,
4091 CHECKNODE_TEXT
, text
,
4094 GtkTreePath
*path
= gtk_tree_model_get_path(model
, &toplevel
);
4096 gtk_tree_view_set_cursor(GTK_TREE_VIEW(mainview
->listview
), path
, mainview
->checklist_column_text
, FALSE
);
4097 gtk_tree_path_free(path
);
4100 mainview
->checklist_edited
= TRUE
;
4105 checklist_edit_selected(MainView
* mainview
, LineEditMode mode
)
4107 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
));
4109 if (gtk_tree_selection_count_selected_rows(selection
) == 0) {
4110 show_banner(mainview
, _("Select items first"));
4114 GtkTreeModel
* model
;
4117 if (gtk_tree_selection_get_selected(selection
, &model
, &iter
)) {
4118 gchar
* old_text
= NULL
;
4119 gtk_tree_model_get(model
, &iter
, CHECKNODE_TEXT
, &old_text
, -1);
4121 gchar
* new_text
= show_line_edit_dialog_full(mainview
, _("Edit checklist item"), _("New name:"), _("Save"), old_text
, mode
);
4123 if (new_text
!= NULL
) {
4124 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, CHECKNODE_TEXT
, new_text
, -1);
4125 mainview
->checklist_edited
= TRUE
;
4133 void callback_checklist_edit(GtkAction
*action
, MainView
*mainview
)
4135 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
4136 checklist_edit_selected(mainview
, LINE_EDIT_MODE_DEFAULT
);
4139 void callback_checklist_delete(GtkAction
*action
, MainView
*mainview
)
4141 g_assert(mainview
!= NULL
&& mainview
->data
!= NULL
);
4143 if (gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
)))==0) {
4144 show_banner(mainview
, _("Select items first"));
4148 if (show_confirmation(mainview
, _("Delete selected checklist item?"))) {
4149 callback_checklist_delete_real(mainview
);
4153 void callback_checklist_delete_real(MainView
* mainview
)
4155 GtkTreeModel
*model
=gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
4156 GList
* l
=gtk_tree_selection_get_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
)), NULL
);
4158 /* Select the item after the selection */
4159 checklist_select(mainview
, TREEVIEW_SELECT_NEXT
);
4161 GList
* rowrefs
=NULL
;
4165 GtkTreePath
*path
=cur
->data
;
4168 if (gtk_tree_model_get_iter(model
, &iter
, path
))
4170 GtkTreeRowReference
*rowref
= gtk_tree_row_reference_new(model
, path
);
4171 rowrefs
=g_list_append(rowrefs
, rowref
);
4173 gtk_tree_path_free(path
);
4177 checklist_remove_rowrefs(mainview
, rowrefs
, FALSE
);
4181 checklist_remove_rowrefs(MainView
* mainview
, GList
* rowrefs
, gboolean show_result
)
4183 GtkTreeModel
* model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
4184 GList
* cur
= rowrefs
;
4187 busy_enter(mainview
);
4190 GtkTreeRowReference
* rowref
= cur
->data
;
4191 GtkTreePath
* path
= gtk_tree_row_reference_get_path(rowref
);
4194 if (gtk_tree_model_get_iter(model
, &iter
, path
)) {
4195 gtk_list_store_remove(GTK_LIST_STORE(model
), &iter
);
4198 gtk_tree_path_free(path
);
4200 gtk_tree_row_reference_free(rowref
);
4203 g_list_free(rowrefs
);
4205 busy_leave(mainview
);
4207 if (count
&& show_result
) {
4208 gchar
* message
= g_strdup_printf(N_("%d item removed", "%d items removed", count
), count
);
4209 show_banner(mainview
, message
);
4213 mainview
->checklist_edited
= TRUE
;
4216 /* Private callback for show_confirmation() - handle keyboard input */
4218 on_confirmation_key_press_event(GtkWidget
* widget
, GdkEventKey
* event
, gpointer user_data
)
4220 GtkDialog
* dialog
= GTK_DIALOG(widget
);
4222 switch (event
->keyval
) {
4223 /* Positive response - Enter, Return or y */
4228 gtk_dialog_response(dialog
, GTK_RESPONSE_OK
);
4231 /* Negative response - Backspace, Escape or n */
4236 gtk_dialog_response(dialog
, GTK_RESPONSE_CANCEL
);
4239 /* Don't handle the rest of the keys */
4246 /* Ask the user for confirmation of a specific action */
4248 show_confirmation(MainView
* mainview
, gchar
* question
)
4250 GtkDialog
* dialog
= GTK_DIALOG(hildon_note_new_confirmation(
4251 GTK_WINDOW(mainview
->data
->main_view
), question
));
4252 gtk_window_set_transient_for(GTK_WINDOW(dialog
), mainview_get_dialog_parent(mainview
));
4253 g_signal_connect(G_OBJECT(dialog
), "key-press-event",
4254 G_CALLBACK(on_confirmation_key_press_event
), NULL
);
4256 gint response
= gtk_dialog_run(dialog
);
4257 gtk_widget_destroy(GTK_WIDGET(dialog
));
4259 return (response
== GTK_RESPONSE_OK
);
4262 /* Show a information banner to the user (non-modal) */
4264 show_banner(MainView
* mainview
, const gchar
* text
)
4266 hildon_banner_show_information(GTK_WIDGET(mainview_get_dialog_parent(mainview
)), NULL
, text
);
4271 gboolean can_close_window
;
4272 } LineEditDialogData
;
4274 /* Helper function to close line edit dialog on Backspace */
4276 line_edit_dialog_key_press(GtkWidget
* w
, GdkEventKey
* event
, gpointer user_data
)
4278 LineEditDialogData
* dialogdata
= (LineEditDialogData
*)user_data
;
4279 GtkEntry
* entry
= GTK_ENTRY(w
);
4281 if (event
->keyval
== GDK_BackSpace
&&
4282 dialogdata
->can_close_window
&&
4283 strcmp(gtk_entry_get_text(entry
), "") == 0) {
4284 gtk_dialog_response(GTK_DIALOG(dialogdata
->dialog
), GTK_RESPONSE_CANCEL
);
4291 /* Let the user enter or edit a line of text */
4293 show_line_edit_dialog_full(MainView
* mainview
, const gchar
* title
,
4294 const gchar
* label_text
, const gchar
* action
, const gchar
* text
,
4297 GtkWidget
* edit_dialog
;
4301 gchar
* result
= NULL
;
4302 LineEditDialogData dialogdata
;
4304 edit_dialog
= GTK_WIDGET(gtk_dialog_new());
4305 gtk_window_set_title(GTK_WINDOW(edit_dialog
), title
);
4306 gtk_window_set_transient_for(GTK_WINDOW(edit_dialog
), mainview_get_dialog_parent(mainview
));
4308 label
= GTK_WIDGET(gtk_label_new(label_text
));
4310 entry
= hildon_entry_new(HILDON_SIZE_AUTO
);
4311 gtk_entry_set_text(GTK_ENTRY(entry
), text
);
4312 gtk_entry_set_activates_default(GTK_ENTRY(entry
), TRUE
);
4314 case LINE_EDIT_MODE_DEFAULT
:
4315 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
4317 case LINE_EDIT_MODE_APPEND
:
4318 gtk_editable_select_region(GTK_EDITABLE(entry
), -1, -1);
4320 case LINE_EDIT_MODE_PREPEND
:
4321 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, 0);
4327 gtk_dialog_add_button(GTK_DIALOG(edit_dialog
), action
, GTK_RESPONSE_OK
);
4328 gtk_dialog_set_default_response(GTK_DIALOG(edit_dialog
), GTK_RESPONSE_OK
);
4330 dialogdata
.dialog
= edit_dialog
;
4331 dialogdata
.can_close_window
= (strcmp(text
, "") == 0);
4332 g_signal_connect(G_OBJECT(entry
), "key-press-event", G_CALLBACK(line_edit_dialog_key_press
), &dialogdata
);
4334 hbox
= GTK_WIDGET(gtk_hbox_new(FALSE
, 10));
4336 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(edit_dialog
))), GTK_WIDGET(hbox
));
4337 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
4338 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 0);
4340 gtk_widget_show_all(GTK_WIDGET(hbox
));
4343 if (gtk_dialog_run(GTK_DIALOG(edit_dialog
)) == GTK_RESPONSE_OK
) {
4344 result
= g_strdup(gtk_entry_get_text(GTK_ENTRY(entry
)));
4345 if (strcmp(result
, "") != 0) {
4348 show_banner(mainview
, _("Please enter a non-empty text"));
4358 gtk_widget_destroy(GTK_WIDGET(edit_dialog
));
4363 treeview_scroll_to_selection(MainView
* mainview
, TreeViewType type
)
4365 GtkTreeView
* treeview
= NULL
;
4366 HildonPannableArea
* pannable_area
= NULL
;
4367 GtkTreeModel
* model
= NULL
;
4368 GtkTreeSelection
* selection
= NULL
;
4369 GtkTreePath
* path
= NULL
;
4375 case TREEVIEW_MAINVIEW
:
4376 treeview
= GTK_TREE_VIEW(mainview
->treeview
);
4377 pannable_area
= HILDON_PANNABLE_AREA(mainview
->scrolledtree
);
4379 case TREEVIEW_CHECKLIST
:
4380 treeview
= GTK_TREE_VIEW(mainview
->listview
);
4381 pannable_area
= HILDON_PANNABLE_AREA(mainview
->listscroll
);
4384 g_assert_not_reached();
4388 /* Let the view scroll so that the selected item is visible */
4389 selection
= gtk_tree_view_get_selection(treeview
);
4390 if (gtk_tree_selection_get_selected(selection
, &model
, &iter
)) {
4391 path
= gtk_tree_model_get_path(model
, &iter
);
4393 gtk_tree_view_get_background_area(treeview
, path
, NULL
, &rect
);
4394 gtk_tree_view_convert_bin_window_to_tree_coords(treeview
,
4395 0, rect
.y
, NULL
, &y
);
4396 hildon_pannable_area_scroll_to(pannable_area
, -1, y
);
4398 gtk_tree_path_free(path
);
4403 checklist_scroll_to_selection(gpointer user_data
)
4405 MainView
* mainview
= (MainView
*)user_data
;
4406 treeview_scroll_to_selection(mainview
, TREEVIEW_CHECKLIST
);
4411 nodelist_scroll_to_selection(gpointer user_data
)
4413 MainView
* mainview
= (MainView
*)user_data
;
4414 treeview_scroll_to_selection(mainview
, TREEVIEW_MAINVIEW
);
4419 checklist_select(MainView
* mainview
, TreeviewSelectType type
)
4421 GtkTreeModel
* model
= gtk_tree_view_get_model(GTK_TREE_VIEW(mainview
->listview
));
4422 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview
->listview
));
4428 case TREEVIEW_SELECT_FIRST
:
4429 if (gtk_tree_model_get_iter_first(model
, &iter
)) {
4430 path
= gtk_tree_model_get_path(model
, &iter
);
4431 gtk_tree_selection_select_path(selection
, path
);
4432 gtk_tree_path_free(path
);
4435 case TREEVIEW_SELECT_LAST
:
4436 if (gtk_tree_model_get_iter_first(model
, &iter
)) {
4439 } while (gtk_tree_model_iter_next(model
, &iter
));
4440 path
= gtk_tree_model_get_path(model
, &last
);
4441 gtk_tree_selection_select_path(selection
, path
);
4442 gtk_tree_path_free(path
);
4445 case TREEVIEW_SELECT_PREVIOUS
:
4446 if (gtk_tree_selection_get_selected(selection
, NULL
, &iter
)) {
4447 path
= gtk_tree_model_get_path(model
, &iter
);
4448 if (gtk_tree_path_prev(path
)) {
4449 gtk_tree_selection_select_path(selection
, path
);
4451 gtk_tree_path_free(path
);
4454 case TREEVIEW_SELECT_NEXT
:
4455 if (gtk_tree_selection_get_selected(selection
, NULL
, &iter
)) {
4456 path
= gtk_tree_model_get_path(model
, &iter
);
4457 gtk_tree_path_next(path
);
4458 gtk_tree_selection_select_path(selection
, path
);
4459 gtk_tree_path_free(path
);
4463 g_assert_not_reached();
4467 checklist_scroll_to_selection(mainview
);
4470 * This is a workaround: The HildonPannableArea does not seem to
4471 * scroll to the right position (especially when going to the first
4472 * or last item in the list), so we simply scroll again after 500ms.
4474 g_timeout_add(500, checklist_scroll_to_selection
, mainview
);
4478 nodelist_select(MainView
* mainview
, TreeviewSelectType type
)
4480 GtkTreeView
* treeview
= GTK_TREE_VIEW(mainview
->treeview
);
4481 GtkTreeModel
* model
= gtk_tree_view_get_model(treeview
);
4482 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(treeview
);
4489 case TREEVIEW_SELECT_FIRST
:
4490 if (gtk_tree_model_get_iter_first(model
, &iter
)) {
4491 path
= gtk_tree_model_get_path(model
, &iter
);
4492 gtk_tree_selection_select_path(selection
, path
);
4493 gtk_tree_path_free(path
);
4496 case TREEVIEW_SELECT_LAST
:
4497 if (gtk_tree_model_get_iter_first(model
, &iter
)) {
4500 if (gtk_tree_model_iter_children(model
, &child
, &last
)) {
4503 } while (gtk_tree_model_iter_next(model
, &child
));
4505 } while (gtk_tree_model_iter_next(model
, &iter
));
4506 path
= gtk_tree_model_get_path(model
, &last
);
4507 gtk_tree_selection_select_path(selection
, path
);
4508 gtk_tree_path_free(path
);
4511 case TREEVIEW_SELECT_PREVIOUS
:
4512 if (gtk_tree_selection_get_selected(selection
, NULL
, &iter
)) {
4513 path
= gtk_tree_model_get_path(model
, &iter
);
4514 if (gtk_tree_path_prev(path
)) {
4515 gtk_tree_selection_select_path(selection
, path
);
4516 } else if (gtk_tree_path_up(path
)) {
4517 gtk_tree_selection_select_path(selection
, path
);
4519 gtk_tree_path_free(path
);
4522 case TREEVIEW_SELECT_NEXT
:
4523 if (gtk_tree_selection_get_selected(selection
, NULL
, &iter
)) {
4524 path
= gtk_tree_model_get_path(model
, &iter
);
4525 gtk_tree_path_down(path
);
4526 while (!gtk_tree_model_get_iter(model
, &iter
, path
)) {
4527 /* Child item does not exist - bubble up to next item */
4528 gtk_tree_path_up(path
);
4529 gtk_tree_path_next(path
);
4531 if (gtk_tree_path_get_depth(path
) == 0) {
4532 /* avoid infinite loops */
4537 if (gtk_tree_model_get_iter(model
, &iter
, path
)) {
4538 gtk_tree_selection_select_path(selection
, path
);
4541 gtk_tree_path_free(path
);
4545 g_assert_not_reached();
4549 nodelist_scroll_to_selection(mainview
);
4552 * This is a workaround: The HildonPannableArea does not seem to
4553 * scroll to the right position (especially when going to the first
4554 * or last item in the list), so we simply scroll again after 500ms.
4556 g_timeout_add(500, nodelist_scroll_to_selection
, mainview
);