1 /*
2 * program: Rubrica
3 * file: app.c
4 *
5 *
6 * Copyright (C) 2000-2005 Nicola Fragale <nicolafragale@libero.it>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22
23 #include <gtk/gtk.h>
24 #include <glade/glade.h>
25 #include <gconf/gconf-client.h>
26 #include <gdk/gdkkeysyms.h>
27 #include <glib/gi18n-lib.h>
28 #include <errno.h>
29
30 #include <libnotify/notify.h>
31 #include <libnotify/notification.h>
32
33 #include "types.h"
34
35 #include "app.h"
36 #include "models.h"
37 #include "cards.h"
38 #include "callbacks.h"
39 #include "preferences.h"
40 #include "groups_cb.h"
41 #include "popmenu.h"
42 #include "browse.h"
43 #include "print.h"
44 #include "cards_view.h"
45 #include "trash_view.h"
46 #include "search_view.h"
47 #include "data_view.h"
48 #include "groups_view.h"
49 #include "search_dialog.h"
50 #include "statusbar.h"
51 #include "tab.h"
52
53 #include "utils.h"
54
55
56
57 /* pixmap, name, label */
58 static RubricaDefaultCategories defcats[] = {
59 {"all", "all groups", N_("all groups") },
60
61 {"flame", "hot contacts", N_("hot contacts") },
62 {"system-users", "friends", N_("friends") },
63 {"emblem-favorite", "heart", N_("heart") },
64 {"go-home", "relatives", N_("relatives") },
65
66 {"chat", "chat", N_("chat") },
67
68 {"emblem-photos", "holidays", N_("holidays") },
69 {"applications-multimedia", "hobbies", N_("hobbies") },
70 {"sport", "sport", N_("sport") },
71
72 {"bussines", "bussines", N_("bussines") },
73 {"system-file-manager", "company", N_("company") },
74 {"application-certificate", "legal", N_("legal") },
75 {"applications-office", "office", N_("office") },
76 {"applications-development", "work", N_("work") },
77 {"customer", "customers", N_("customers") },
78 {"strategies", "strategies", N_("strategies") },
79
80 {"gnu", "free software", N_("free software")},
81 {"tux", "programmers", N_("programmers") },
82 {"freebsd", "BSD friends", N_("BSD friends") },
83
84 {"university", "university", N_("university") },
85 {NULL, NULL}
86 };
87
88
89 typedef struct _RubricaMenu {
90 GtkWidget* menubar;
91 GtkWidget* new;
92 GtkWidget* open;
93 GtkWidget* save;
94 GtkWidget* saveas;
95 GtkWidget* quit;
96
97 GtkWidget* cut;
98 GtkWidget* copy;
99 GtkWidget* paste;
100
101 GtkWidget* personal;
102 GtkWidget* company;
103 GtkWidget* modify;
104 GtkWidget* delete;
105
106 GtkWidget* prefer;
107
108 GtkWidget* about;
109 } RubricaMenu;
110
111
112
113 typedef struct _RubricaToolbar {
114 GtkWidget* handle;
115 GtkWidget* toolbar;
116
117 GtkWidget* new;
118 GtkWidget* open;
119 GtkWidget* save;
120 GtkWidget* print;
121 GtkWidget* close;
122
123 GtkWidget* add;
124 GtkWidget* choose;
125 GtkWidget* delete;
126 GtkWidget* modify;
127
128 GtkWidget* next;
129 GtkWidget* previous;
130 GtkWidget* first;
131 GtkWidget* last;
132 GtkWidget* trash;
133 GtkWidget* search;
134 GtkWidget* quit;
135 } RubricaToolbar;
136
137
138
139 struct _RubricaAppPrivate {
140 RGroupBox *groups; // rubrica's groups
141
142 RubricaMenu *menu;
143 RubricaToolbar *toolbar;
144 GtkWidget *statusbar;
145
146 GtkWidget *notebook; // contains addressbooks (CardsView)
147
148 GtkWidget *groups_view;
149 GtkWidget *trash_view; // trash notebook's page (TrashView)
150 GtkWidget *search_view; // search notebook's page (SearchView)
151 GtkWidget *data_view; // dispay card's data (DataView)
152
153 GtkWidget *paned;
154 GtkWidget *group_paned;
155
156 GList *cutted; // stack of cutted cards
157
158 NotifyNotification* notify;
159 gchar *active_plugin;
160 RPluginManager *manager;
161
162 GtkPrintSettings* print_settings;
163
164 gboolean show_card;
165
166 gboolean dispose_has_run;
167 };
168
169
170
171 /* signals enumeration
172 */
173
174 static void rubrica_app_class_init (RubricaAppClass* klass);
175 static void rubrica_app_init (RubricaApp* obj);
176
177 static void rubrica_app_dispose (RubricaApp* obj);
178 static void rubrica_app_finalize (RubricaApp* obj);
179
180
181 /* Private
182 */
183 static void init_group_box (RGroupBox* box);
184 static void add_card_groups2set (RubricaApp* app, RCard* card);
185
186 static RubricaMenu* build_menu (GladeXML* gui, RubricaApp* app);
187 static RubricaToolbar* build_toolbar (GladeXML* gui, RubricaApp* app);
188
189 static GtkWidget* find_addressbook (RubricaApp* app, RAbook* book);
190 static void load_addressbooks (RubricaApp* app);
191 static void save_addressbook (RubricaApp* app, RAbook* book);
192 static void display_cards_list (RubricaApp* app, GList *ids);
193
194 static GtkWidget* get_current_tab (RubricaApp* app);
195 static GtkWidget* get_current_tab_label (RubricaApp* app);
196 static gchar* get_current_tab_label_text (RubricaApp* app);
197
198
199 /* Private callbacks
200 */
201 static gboolean on_cards_event_occurred (GtkTreeView* tree, GdkEvent *event,
202 gpointer data);
203 static void on_trash_event_occurred (GtkTreeView* tree, GdkEvent *event,
204 gpointer data);
205 static void on_search_event_occurred (GtkTreeView* tree, GdkEvent *event,
206 gpointer data);
207 static gboolean on_key_press_event_cb (GtkWidget* w, GdkEventKey* event,
208 gpointer data);
209
210 static void hide_trash_on_click (GtkWidget* button, gpointer data);
211 static void hide_search_on_click (GtkWidget* button, gpointer data);
212
213 static void on_card_added (RAbook* book, gpointer card, gpointer data);
214 static void on_card_destroyed (RAbook* book, gchar* arg, gpointer data);
215 static void on_card_deleted (RAbook* book, gpointer id, gpointer data);
216 static void on_card_recovered (RAbook* book, gpointer card, gpointer data);
217 static void on_card_modified (RAbook* book, gpointer card, gpointer data);
218
219 static void on_show_menu_cb (GtkMenuToolButton *mtbutton, gpointer data);
220 static void on_trash_toggled_cb (GtkToggleToolButton *toggle, gpointer data);
221
222 static void on_addressbook_changed (RAbook* book, gpointer data);
223 static void on_addressbook_saved (RAbook* book, gpointer data);
224 static void on_addressbook_save_fail (RAbook* book, gint err, gpointer data);
225
226 static void on_autosave_changed (GConfClient *client, guint cnxn_id,
227 GConfEntry *entry, gpointer data);
228
229 static void on_launch_cb (GtkWidget* data_view, gpointer link,
230 gpointer data);
231
232 static void on_app_view_changed (GtkWidget* view, gchar* message,
233 gpointer data);
234 static void on_cards_view_changed (GtkWidget* view, gchar* message,
235 gpointer data);
236 static void on_card_marked (RubricaCardsView* view, glong card_id,
237 RubricaCardsViewMark mark,
238 gpointer data);
239
240
241
242 /* Private
243 */
244 static void
init_group_box(RGroupBox * box)245 init_group_box(RGroupBox* box)
246 {
247 RGroup* group;
248 RubricaDefaultCategories* cat = defcats;
249
250 for(; cat->label; cat++)
251 {
252 group = r_group_new();
253
254 g_object_set(group,
255 "group-name", cat->label,
256 "group-label", _(cat->label),
257 "group-owner", "rubrica",
258 "group-pixmap", cat->pixmap,
259 "enabled", FALSE, NULL);
260
261 r_group_box_add_group(box, group);
262 }
263 }
264
265
266 static void
add_card_groups2set(RubricaApp * app,RCard * card)267 add_card_groups2set(RubricaApp* app, RCard* card)
268 {
269 RGroup* group;
270
271 r_card_reset_group(card);
272 group = r_card_get_group(card);
273 for(; group; group = r_card_get_next_group(card))
274 r_group_box_add_group(app->priv->groups, group);
275 }
276
277
278 static void
load_addressbooks(RubricaApp * app)279 load_addressbooks (RubricaApp* app)
280 {
281 GConfClient* client;
282 GSList* files;
283
284 client = gconf_client_get_default();
285 files = gconf_client_get_list(client, RUBRICA_GCONF_FILES,
286 GCONF_VALUE_STRING, NULL);
287
288 // rubrica_app_set_plugin_name(app, "autodetect");
289 for (; files; files = files->next)
290 rubrica_app_load_file(app, (gchar*) files->data);
291
292 g_object_unref(client);
293 }
294
295
296 static void
save_addressbook(RubricaApp * app,RAbook * book)297 save_addressbook(RubricaApp* app, RAbook* book)
298 {
299 GConfClient* client;
300 gboolean backup;
301 gint rate;
302 gchar* filename = NULL;
303
304 if (!book)
305 book = rubrica_app_get_active_addressbook(app);
306
307 client = gconf_client_get_default();
308
309 backup = gconf_client_get_bool(client, RUBRICA_GCONF_BACKUP, NULL);
310 rate = gconf_client_get_int (client, RUBRICA_GCONF_RATE, NULL);
311
312 g_object_get(book, "addressbook-name", &filename, NULL);
313
314 if (!filename || (g_ascii_strcasecmp(_("no name"), filename) == 0))
315 on_saveas_cb(NULL, app);
316 else
317 r_abook_overwrite_file(book, backup, rate);
318
319 g_object_unref(client);
320 }
321
322
323 static GtkWidget*
get_current_tab(RubricaApp * app)324 get_current_tab(RubricaApp* app)
325 {
326 GtkWidget* child;
327 GtkWidget* tab;
328 gint page;
329
330 page = gtk_notebook_get_current_page(GTK_NOTEBOOK(app->priv->notebook));
331 child = gtk_notebook_get_nth_page (GTK_NOTEBOOK(app->priv->notebook), page);
332 g_object_get(child, "view-brother", &tab, NULL);
333
334 return tab;
335 }
336
337
338 static GtkWidget*
get_current_tab_label(RubricaApp * app)339 get_current_tab_label(RubricaApp* app)
340 {
341 GtkWidget* tab;
342 GtkWidget* label = NULL;
343
344 tab = get_current_tab(app);
345 label = rubrica_tab_get_label(RUBRICA_TAB(tab));
346
347 return label;
348 }
349
350
351 static gchar*
get_current_tab_label_text(RubricaApp * app)352 get_current_tab_label_text(RubricaApp* app)
353 {
354 GtkWidget* tab;
355 gchar* text;
356
357 tab = get_current_tab(app);
358 g_object_get(tab, "tab-label", &text, NULL);
359
360 return text;
361 }
362
363
364 static GtkWidget*
find_addressbook(RubricaApp * app,RAbook * book)365 find_addressbook (RubricaApp* app, RAbook* book)
366 {
367 gint n;
368
369 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
370 g_return_val_if_fail(IS_R_ABOOK(book), NULL);
371
372 n = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->priv->notebook));
373 for (; n; n--)
374 {
375 GtkWidget* view;
376 RAbook* adb;
377
378 view = gtk_notebook_get_nth_page(GTK_NOTEBOOK(app->priv->notebook), n);
379 adb = rubrica_cards_view_get_addressbook(RUBRICA_CARDS_VIEW(view));
380 if (adb == book)
381 return view;
382 }
383
384 return NULL;
385 }
386
387
388
389 static void
display_cards_list(RubricaApp * app,GList * ids)390 display_cards_list(RubricaApp* app, GList *ids)
391 {
392 GtkWidget* view;
393 gint cards;
394 gchar* message;
395
396 view = rubrica_app_get_current_view(app);
397 cards = g_list_length(ids);
398
399 rubrica_cards_view_display_results(RUBRICA_CARDS_VIEW(view), ids);
400
401 if (cards > 1)
402 message = g_strdup_printf(_("%d cards found"), cards);
403 else
404 message = g_strdup_printf(_("%d card found"), cards);
405 rubrica_app_notify(app, message);
406
407 g_free(message);
408 }
409
410
411
412 /* Callbacks
413 */
414 static void
on_app_view_changed(GtkWidget * view,gchar * message,gpointer data)415 on_app_view_changed(GtkWidget* view, gchar* message, gpointer data)
416 {
417 RubricaStatusbar* statusbar = RUBRICA_STATUSBAR(data);
418
419 rubrica_statusbar_enable_extra (statusbar, FALSE);
420 rubrica_statusbar_enable_images(statusbar, FALSE);
421 rubrica_statusbar_push_message(statusbar, message);
422 }
423
424
425 static void
on_cards_view_changed(GtkWidget * view,gchar * message,gpointer data)426 on_cards_view_changed(GtkWidget* view, gchar* message, gpointer data)
427 {
428 RubricaStatusbar* statusbar = RUBRICA_STATUSBAR(data);
429
430 rubrica_statusbar_enable_extra (statusbar, TRUE);
431 rubrica_statusbar_enable_images(statusbar, TRUE);
432 rubrica_statusbar_extra_set_text(statusbar, message);
433 }
434
435
436 static void
on_card_added(RAbook * book,gpointer the_card,gpointer data)437 on_card_added (RAbook* book, gpointer the_card, gpointer data)
438 {
439 RubricaApp* app = (RubricaApp*) data;
440 RCard* card = (RCard*) the_card;
441
442 rubrica_app_add_card(app, card);
443 }
444
445
446 static void
on_card_destroyed(RAbook * book,gchar * arg,gpointer data)447 on_card_destroyed (RAbook* book, gchar* arg, gpointer data)
448 {
449 gchar* message;
450 GtkWidget* view;
451
452 view = find_addressbook(RUBRICA_APP(data), book);
453 message = g_strdup_printf(_("Card %s successfully destroyed"), arg);
454 rubrica_app_show_message(RUBRICA_APP(data), message);
455 rubrica_cards_view_update_infos (RUBRICA_CARDS_VIEW(view));
456
457 g_free(message);
458
459 }
460
461
462
463 static void
on_card_deleted(RAbook * book,gpointer card,gpointer data)464 on_card_deleted (RAbook* book, gpointer card, gpointer data)
465 {
466 RubricaApp* app = (RubricaApp*) data;
467 GtkWidget* view;
468 GtkWidget* trash;
469
470 view = rubrica_app_get_current_view(app);
471 trash = rubrica_app_get_trash(app);
472
473 rubrica_trash_view_add_card(RUBRICA_TRASH_VIEW(trash), book, card);
474 rubrica_cards_view_delete_card(RUBRICA_CARDS_VIEW(view), card);
475 }
476
477
478 static void
on_card_recovered(RAbook * book,gpointer card,gpointer data)479 on_card_recovered (RAbook* book, gpointer card, gpointer data)
480 {
481 RubricaApp* app = (RubricaApp*) data;
482 GtkWidget* view = NULL;
483
484 view = find_addressbook(app, book);
485 if (view)
486 rubrica_cards_view_add_card(RUBRICA_CARDS_VIEW(view), R_CARD(card));
487 }
488
489
490 static void
on_card_modified(RAbook * book,gpointer newcard,gpointer data)491 on_card_modified (RAbook* book, gpointer newcard, gpointer data)
492 {
493 RubricaApp *app = (RubricaApp*) data;
494 GtkWidget *view = NULL;
495
496 view = rubrica_app_get_current_view(app);
497 rubrica_cards_view_modify_card(RUBRICA_CARDS_VIEW(view), newcard);
498 rubrica_app_display_card_data(app, R_CARD(newcard));
499 }
500
501
502
503 static void
on_show_menu_cb(GtkMenuToolButton * menutoolbutton,gpointer data)504 on_show_menu_cb (GtkMenuToolButton *menutoolbutton, gpointer data)
505 {
506 GtkMenu* menu = data;
507
508 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 1,
509 gtk_get_current_event_time());
510
511 gtk_widget_show_all(GTK_WIDGET(menu));
512 }
513
514
515 static void
on_trash_toggled_cb(GtkToggleToolButton * toggle,gpointer data)516 on_trash_toggled_cb (GtkToggleToolButton *toggle, gpointer data)
517 {
518 RubricaApp* app = (RubricaApp*) data;
519
520 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(toggle)))
521 gtk_widget_show(app->priv->trash_view);
522 else
523 gtk_widget_hide(app->priv->trash_view);
524 }
525
526
527 static void
hide_trash_on_click(GtkWidget * button,gpointer data)528 hide_trash_on_click (GtkWidget* button, gpointer data)
529 {
530 RubricaApp* app = (RubricaApp*) data;
531 GtkWidget* toggle;
532
533 gtk_widget_hide(GTK_WIDGET(app->priv->trash_view));
534 toggle = app->priv->toolbar->trash;
535 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(toggle)))
536 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON(toggle), FALSE);
537 }
538
539
540 static void
hide_search_on_click(GtkWidget * button,gpointer data)541 hide_search_on_click (GtkWidget* button, gpointer data)
542 {
543 gtk_widget_hide(GTK_WIDGET(data));
544 }
545
546
547 static void
on_addressbook_changed(RAbook * book,gpointer data)548 on_addressbook_changed(RAbook* book, gpointer data)
549 {
550 RubricaApp* app = (RubricaApp*) data;
551 GConfClient* client;
552 GtkWidget* view = NULL;
553 GtkWidget* label;
554 const gchar *text = NULL;
555 gchar *markup;
556
557 client = gconf_client_get_default();
558 view = find_addressbook(app, book);
559
560 if (gconf_client_get_bool(client, RUBRICA_GCONF_AUTOSAVE, NULL))
561 save_addressbook(app, book);
562 else
563 {
564 label = get_current_tab_label(app);
565 // text = gtk_label_get_text(GTK_LABEL(text));
566 text = get_current_tab_label_text(app);
567 markup = g_markup_printf_escaped ("<span style=\"italic\">%s</span>",
568 text);
569
570 g_object_set(view, "has-changed", TRUE, NULL);
571 gtk_label_set_markup (GTK_LABEL (label), markup);
572 g_free (markup);
573 }
574
575 rubrica_cards_view_update_infos(RUBRICA_CARDS_VIEW(view));
576 g_object_unref(client);
577 }
578
579
580 static void
on_addressbook_saved(RAbook * book,gpointer data)581 on_addressbook_saved (RAbook* book, gpointer data)
582 {
583 RubricaApp* app = (RubricaApp*) data;
584 GtkWidget* view = NULL;
585 GtkWidget* tab;
586 gchar *file, *report, *markup, *type = NULL;
587
588 view = rubrica_app_get_current_view(app);
589
590 g_object_get(view, "child-type", &type, NULL);
591 if (!type || (g_ascii_strcasecmp(type, "Addressbook") != 0))
592 view = find_addressbook(app, book);
593
594 file = rubrica_cards_view_get_addressbook_name(RUBRICA_CARDS_VIEW(view));
595 rubrica_cards_view_update_infos(RUBRICA_CARDS_VIEW(view));
596 g_object_get(view, "view-brother", &tab, "view-message", &report, NULL);
597
598 rubrica_statusbar_extra_set_text(RUBRICA_STATUSBAR(app->priv->statusbar),
599 report);
600 markup = g_markup_printf_escaped ("<span style=\"normal\">%s</span>", file);
601 g_object_set(tab, "tab-label", markup, NULL);
602
603 g_free (markup);
604 }
605
606
607 static void
on_addressbook_save_fail(RAbook * book,gint err,gpointer data)608 on_addressbook_save_fail (RAbook* book, gint err, gpointer data)
609 {
610 RubricaApp* app = (RubricaApp*) data;
611 gchar* file;
612 gchar* message = NULL;
613
614 g_object_get(book, "addressbook-name", &file, NULL);
615
616 switch (err)
617 {
618 case WRITING_FILE:
619 case WRITING_XML:
620 message = g_strdup_printf(_("Can't save the file %s"), file);
621 break;
622
623 break;
624
625 case OVERWRITING:
626 message = g_strdup_printf(_("Can't overwrite the file %s"), file);
627 break;
628
629 default:
630 break;
631 }
632
633 rubrica_app_show_message(app, message);
634 g_free(message);
635 }
636
637
638 static void
on_autosave_changed(GConfClient * client,guint cnxn_id,GConfEntry * entry,gpointer data)639 on_autosave_changed(GConfClient *client, guint cnxn_id,
640 GConfEntry *entry, gpointer data)
641 {
642 GtkWidget* button = (GtkWidget* ) data;
643 gboolean autosave;
644
645 autosave = gconf_client_get_bool(client, RUBRICA_GCONF_AUTOSAVE, NULL);
646 gtk_widget_set_sensitive(button, !autosave);
647 }
648
649
650 static void
on_launch_cb(GtkWidget * data_view,gpointer arg1,gpointer data)651 on_launch_cb(GtkWidget* data_view, gpointer arg1, gpointer data)
652 {
653 RubricaApp* app = (RubricaApp*) data;
654 RubricaLink* link = (RubricaLink*) arg1;
655 GConfClient* client;
656 GPid pid;
657 GError *error = NULL;
658 gchar* argv[4];
659 gchar* manager = NULL;
660
661
662 if (link && link->uri)
663 {
664 gchar* arg = NULL;
665 gchar* notify;
666 gchar* message;
667
668 client = gconf_client_get_default();
669
670 switch ((RubricaLinkType) link->type)
671 {
672 case WEB_LINK:
673 manager = gconf_client_get_string(client, RUBRICA_GCONF_BROWSER,
674 NULL);
675 if (g_ascii_strcasecmp(manager, "other") == 0)
676 manager = gconf_client_get_string(client, RUBRICA_GCONF_BROWSER_UD,
677 NULL);
678 arg = g_strdup_printf("%s", link->uri);
679 break;
680
681 case EMAIL_LINK:
682 manager = gconf_client_get_string(client, RUBRICA_GCONF_EMAILS,
683 NULL);
684 if (g_ascii_strcasecmp(manager, "other") == 0)
685 manager = gconf_client_get_string(client, RUBRICA_GCONF_EMAILS_UD,
686 NULL);
687 if (g_ascii_strcasecmp(manager, "balsa") == 0)
688 {
689 arg = g_strdup_printf("--compose=%s", link->uri);
690 break;
691 }
692
693 if (g_ascii_strcasecmp(manager, "seamonkey") == 0)
694 {
695 arg = g_strdup_printf("mailto:%s", link->uri);
696 break;
697 }
698
699 arg = g_strdup_printf("mailto:%s", link->uri);
700 break;
701
702 case IRC_LINK:
703 manager = gconf_client_get_string(client, RUBRICA_GCONF_IRC, NULL);
704
705 if (g_ascii_strcasecmp(manager, "other") == 0)
706 manager = gconf_client_get_string(client, RUBRICA_GCONF_IRC_UD,
707 NULL);
708
709 arg = g_strdup_printf("-l %s", link->uri);
710 break;
711
712 case TELEPHONE_LINK:
713 manager = g_strdup("ekiga");
714 arg = g_strdup_printf("-c %s", link->uri);
715 break;
716
717 default:
718 break;
719 }
720
721 if(!g_find_program_in_path(manager))
722 {
723 message = g_strdup_printf(_("Can't find %s in your path"),
724 manager);
725
726 rubrica_app_show_message (app, message);
727 return;
728 }
729
730 argv[0] = manager;
731 argv[1] = arg;
732 argv[2] = NULL;
733
734 error = NULL;
735 notify = g_strdup_printf(_("Launching %s. Please wait..."),
736 manager);
737 message = g_strdup_printf(_("Launching %s. Please wait..."),
738 manager);
739
740 rubrica_app_notify (app, notify);
741 notify_notification_update(app->priv->notify, _("Rubrica Addressbook"),
742 message, "info");
743 if(!notify_notification_show (app->priv->notify, &error))
744 {
745 g_warning("notification error: %s", error->message);
746 }
747
748 if (g_spawn_async ("/usr/bin",
749 argv,
750 NULL, // inherit parent's environment
751 G_SPAWN_CHILD_INHERITS_STDIN,
752 NULL, // function to run in the child before exec
753 NULL, // user data for child_setup
754 &pid,
755 &error));
756 g_free(notify);
757 g_free(message);
758 }
759 }
760
761
762
763 static gboolean
on_cards_event_occurred(GtkTreeView * tree,GdkEvent * event,gpointer data)764 on_cards_event_occurred (GtkTreeView* tree, GdkEvent *event, gpointer data)
765 {
766 RubricaApp *app = (RubricaApp*) data;
767 GdkEventButton *ev = (GdkEventButton *)event;
768 GtkTreeModel *model;
769 GtkTreeSelection *selection;
770 GtkTreePath *path = NULL;
771 GtkTreeIter iter;
772 RAbook *book;
773 glong id;
774
775 book = rubrica_app_get_active_addressbook (app);
776 model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree));
777 selection = gtk_tree_view_get_selection(tree);
778
779 gtk_tree_selection_unselect_all(selection);
780
781 /* if a card is selected then get card from database
782 */
783 if (gtk_tree_view_get_path_at_pos(tree, ev->x, ev->y, &path,
784 NULL, NULL, NULL))
785 {
786 gpointer card;
787
788 /* Get the selected card
789 */
790 gtk_tree_selection_select_path(selection, path);
791 gtk_tree_model_get_iter(model, &iter, path);
792
793 gtk_tree_model_get(model, &iter, ID_COLUMN, &id, -1);
794 card = r_abook_get_card_by_id(R_ABOOK(book), id);
795
796 /* Do something with the card
797 */
798 /* if rigth button was pressed ==> show popup menu
799 */
800 if ((ev->button == 3) && (ev->type == GDK_BUTTON_PRESS))
801 {
802 GtkMenu* menu;
803
804 menu = (GtkMenu*) rubrica_menu_do_card_popup(RUBRICA_APP(app),
805 tree, event);
806
807 gtk_widget_show_all(GTK_WIDGET(menu));
808 gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
809 ev->button, ev->time);
810 }
811 /* else if the left button was pressed
812 */
813 else
814 {
815 /* update application's window
816 */
817 /* check if next/previous cards are available */
818 rubrica_app_enable_previouses(app, TRUE);
819 rubrica_app_enable_nexts(app, TRUE);
820
821 if (!gtk_tree_path_prev(path))
822 rubrica_app_enable_previouses(app, FALSE);
823 if (!gtk_tree_model_iter_next(model, &iter))
824 rubrica_app_enable_nexts(app, FALSE);
825
826 gtk_tree_path_free(path);
827
828 if (ev->button == 1)
829 {
830 switch(ev->type)
831 {
832 case GDK_BUTTON_PRESS:
833 /* left button clicked once ==> card selected, show it
834 */
835 rubrica_app_display_card_data(RUBRICA_APP(app), card);
836 break;
837
838 case GDK_2BUTTON_PRESS:
839 /* left button clicked twice ==> modify the selected card
840 */
841 cards_modify_card(RUBRICA_APP(app), book, card);
842 break;
843
844 default:
845 break;
846 }
847 }
848 }
849 } // end: if a card is selected
850 else /* rigth button pressed and no cards selected ==> show popup menu */
851 if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 3))
852 {
853 GtkMenu* menu;
854
855 menu = (GtkMenu*) rubrica_menu_do_card_popup(RUBRICA_APP(app),
856 tree, event);
857
858 gtk_widget_show_all(GTK_WIDGET(menu));
859 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, ev->button, ev->time);
860 }
861
862 // returning FALSE it doesn't block signal for other callbacks
863 return FALSE;
864 }
865
866
867 static void
on_trash_event_occurred(GtkTreeView * tree,GdkEvent * event,gpointer data)868 on_trash_event_occurred (GtkTreeView* tree, GdkEvent *event, gpointer data)
869 {
870 RubricaApp* app = (RubricaApp*) data;
871 GtkTreeIter iter;
872 GtkTreeModel* model;
873 GtkTreePath* path = NULL;
874 GtkTreeSelection* selection;
875 GdkEventButton* ev = (GdkEventButton *)event;
876
877 model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree));
878 selection = gtk_tree_view_get_selection(tree);
879
880 /* if a card has been selected */
881 if (gtk_tree_view_get_path_at_pos(tree, ev->x, ev->y, &path,
882 NULL, NULL, NULL))
883 {
884 gtk_tree_selection_select_path(selection, path);
885
886 /* left button pressed ==> show card */
887 if(ev->button == 1)
888 {
889 RAbook* book = NULL;
890 gpointer card = NULL;
891 glong id = 0;
892
893 gtk_tree_model_get_iter(model, &iter, path);
894 gtk_tree_path_free(path);
895
896 gtk_tree_model_get(model, &iter,
897 TRASH_ID, &id,
898 TRASH_ADDRESSBOOK, &book,
899 -1);
900
901 card = r_abook_get_card_by_id(R_ABOOK(book), id);
902 rubrica_app_display_card_data(RUBRICA_APP(app), card);
903 }
904
905 /* rigth button pressed ==> show popup menu */
906 if (ev->button == 3)
907 {
908 GtkMenu* menu;
909
910 menu = (GtkMenu*) rubrica_menu_do_trash_popup(RUBRICA_APP(app),
911 tree, event);
912
913 gtk_widget_show_all(GTK_WIDGET(menu));
914 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, ev->button, ev->time);
915 }
916 }
917 }
918
919
920 static void
on_search_event_occurred(GtkTreeView * tree,GdkEvent * event,gpointer data)921 on_search_event_occurred (GtkTreeView* tree, GdkEvent *event, gpointer data)
922 {
923 RubricaApp* app = (RubricaApp*) data;
924 GtkTreeIter iter;
925 GtkTreeModel* model;
926 GtkTreePath* path = NULL;
927 GtkTreeSelection* selection;
928 GdkEventButton* ev = (GdkEventButton *)event;
929
930 model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree));
931 selection = gtk_tree_view_get_selection(tree);
932
933 /* if a card has been selected */
934 if (gtk_tree_view_get_path_at_pos(tree, ev->x, ev->y, &path,
935 NULL, NULL, NULL))
936 {
937 gtk_tree_selection_select_path(selection, path);
938
939 /* left button pressed ==> show card */
940 if(ev->button == 1)
941 {
942 RAbook* book = NULL;
943 gpointer card = NULL;
944 glong id = 0;
945
946 gtk_tree_model_get_iter(model, &iter, path);
947 gtk_tree_path_free(path);
948
949 gtk_tree_model_get(model, &iter,
950 SEARCH_ID_COLUMN, &id,
951 SEARCH_BOOK_COLUMN, &book,
952 -1);
953
954 card = r_abook_get_card_by_id(R_ABOOK(book), id);
955 rubrica_app_display_card_data(RUBRICA_APP(app), card);
956 }
957
958 /* rigth button pressed ==> show popup menu */
959 if (ev->button == 3)
960 {
961 /*
962 GtkMenu* menu;
963
964 menu = (GtkMenu*) rubrica_menu_do_trash_popup(RUBRICA_APP(app),
965 tree, event);
966
967 gtk_widget_show_all(GTK_WIDGET(menu));
968 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, ev->button, ev->time);
969 */
970 }
971 }
972 }
973
974
975
976 static gboolean
on_key_press_event_cb(GtkWidget * widget,GdkEventKey * event,gpointer data)977 on_key_press_event_cb (GtkWidget* widget, GdkEventKey* event, gpointer data)
978 {
979 RubricaApp* app = (RubricaApp*) data;
980
981 switch (event->keyval)
982 {
983 case GDK_KP_Delete:
984 case GDK_Delete:
985 on_delete_card_cb (NULL, app);
986 break;
987
988 case GDK_Return:
989
990 break;
991
992 case GDK_Home:
993 rubrica_browse_first_card(app);
994 break;
995
996 case GDK_End:
997 rubrica_browse_last_card(app);
998 break;
999
1000 case GDK_Left:
1001 break;
1002
1003 case GDK_Right:
1004 break;
1005
1006 case GDK_Up:
1007 rubrica_browse_previous_card(app);
1008 break;
1009
1010 case GDK_Down:
1011 rubrica_browse_next_card(app);
1012 break;
1013
1014 default :
1015 break;
1016 }
1017
1018 return FALSE;
1019 }
1020
1021
1022 static void
on_card_marked(RubricaCardsView * view,glong card_id,RubricaCardsViewMark mark,gpointer data)1023 on_card_marked (RubricaCardsView* view, glong card_id,
1024 RubricaCardsViewMark mark, gpointer data)
1025 {
1026 RubricaApp* app = (RubricaApp*) data;
1027 RAbook* book;
1028 RCard* card;
1029 gint marked = 0;
1030
1031 book = rubrica_app_get_active_addressbook(app);
1032 card = r_abook_get_card_by_id(book, card_id);
1033 g_object_get(book, "printable-cards", &marked, NULL);
1034
1035 switch(mark)
1036 {
1037 case CARD_MARKED_PRINT:
1038 marked++;
1039 g_object_set(card, "card-printable", TRUE, NULL);
1040 break;
1041
1042 case CARD_UNMARKED_PRINT:
1043 marked--;
1044 g_object_set(card, "card-printable", FALSE, NULL);
1045 break;
1046
1047 default:
1048 break;
1049 }
1050
1051 g_object_set(book, "printable-cards", marked, NULL);
1052 }
1053
1054
1055
1056 RubricaMenu*
build_menu(GladeXML * gui,RubricaApp * app)1057 build_menu(GladeXML* gui, RubricaApp* app)
1058 {
1059
1060 RubricaMenu* menu = NULL;
1061 GConfClient* client;
1062 gboolean autosave;
1063
1064 client = gconf_client_get_default();
1065 menu = g_malloc0(sizeof(RubricaMenu));
1066 if (!menu)
1067 g_error("\nCan't allocate memory");
1068
1069 menu->menubar = glade_xml_get_widget(gui, "menubar");
1070
1071 menu->new = glade_xml_get_widget(gui, "new");
1072 menu->open = glade_xml_get_widget(gui, "open");
1073 menu->save = glade_xml_get_widget(gui, "save");
1074 menu->saveas = glade_xml_get_widget(gui, "saveas");
1075 menu->quit = glade_xml_get_widget(gui, "quit");
1076
1077 menu->cut = glade_xml_get_widget(gui, "cut");
1078 menu->copy = glade_xml_get_widget(gui, "copy");
1079 menu->paste = glade_xml_get_widget(gui, "paste");
1080 menu->personal = glade_xml_get_widget(gui, "personal");
1081 menu->company = glade_xml_get_widget(gui, "company");
1082 menu->delete = glade_xml_get_widget(gui, "delete");
1083 menu->modify = glade_xml_get_widget(gui, "modify");
1084 menu->prefer = glade_xml_get_widget(gui, "prefer");
1085
1086 menu->about = glade_xml_get_widget(gui, "about");
1087
1088 /* menu handler
1089 */
1090 g_signal_connect(G_OBJECT(menu->new), "activate",
1091 G_CALLBACK(on_new_cb), app);
1092
1093 g_signal_connect(G_OBJECT(menu->open), "activate",
1094 G_CALLBACK(on_open_cb), app);
1095
1096 g_signal_connect(G_OBJECT(menu->save), "activate",
1097 G_CALLBACK(on_save_cb), app);
1098
1099 g_signal_connect(G_OBJECT(menu->saveas), "activate",
1100 G_CALLBACK(on_saveas_cb), app);
1101
1102 g_signal_connect(G_OBJECT(menu->cut), "activate",
1103 G_CALLBACK(on_cut_cb), NULL);
1104
1105 g_signal_connect(G_OBJECT(menu->copy), "activate",
1106 G_CALLBACK(on_copy_cb), NULL);
1107
1108 g_signal_connect(G_OBJECT(menu->paste), "activate",
1109 G_CALLBACK(on_paste_cb), NULL);
1110
1111 g_signal_connect(G_OBJECT(menu->personal), "activate",
1112 G_CALLBACK(on_add_personal_cb), app);
1113
1114 g_signal_connect(G_OBJECT(menu->company), "activate",
1115 G_CALLBACK(on_add_company_cb), app);
1116
1117 g_signal_connect(G_OBJECT(menu->delete), "activate",
1118 G_CALLBACK(on_delete_card_cb), app);
1119
1120 g_signal_connect(G_OBJECT(menu->modify), "activate",
1121 G_CALLBACK(on_modify_card_cb), app);
1122
1123 g_signal_connect(G_OBJECT(menu->prefer), "activate",
1124 G_CALLBACK(on_prefenences_cb), app);
1125
1126 g_signal_connect(G_OBJECT(menu->about), "activate",
1127 G_CALLBACK(on_info_cb), NULL);
1128
1129 g_signal_connect(G_OBJECT(menu->quit), "activate",
1130 G_CALLBACK(on_quit_cb), app);
1131
1132 autosave = gconf_client_get_bool(client, RUBRICA_GCONF_AUTOSAVE, NULL);
1133 if (autosave)
1134 gtk_widget_set_sensitive(menu->save, FALSE);
1135
1136 gconf_client_notify_add(client, RUBRICA_GCONF_AUTOSAVE,
1137 on_autosave_changed, menu->save, NULL, NULL);
1138 g_object_unref(client);
1139
1140 return menu;
1141 }
1142
1143
1144
1145 RubricaToolbar*
build_toolbar(GladeXML * gui,RubricaApp * app)1146 build_toolbar(GladeXML* gui, RubricaApp* app)
1147 {
1148 GConfClient* client;
1149 RubricaToolbar* toolbar = NULL;
1150 GtkMenu* menu = NULL;
1151 GtkWidget *personal;
1152 GtkWidget *company;
1153 gboolean autosave;
1154
1155 client = gconf_client_get_default();
1156 toolbar = g_malloc0(sizeof(RubricaToolbar));
1157 if (!toolbar)
1158 g_error("\nCan't allocate memory");
1159
1160 toolbar->handle = glade_xml_get_widget(gui, "handle");
1161 toolbar->toolbar = glade_xml_get_widget(gui, "toolbar");
1162 toolbar->new = glade_xml_get_widget(gui, "new_bt");
1163 toolbar->open = glade_xml_get_widget(gui, "open_bt");
1164 toolbar->save = glade_xml_get_widget(gui, "save_bt");
1165 toolbar->print = glade_xml_get_widget(gui, "print_bt");
1166
1167 toolbar->add = glade_xml_get_widget(gui, "add_bt");
1168 toolbar->delete = glade_xml_get_widget(gui, "delete_bt");
1169 toolbar->modify = glade_xml_get_widget(gui, "modify_bt");
1170
1171 toolbar->previous = glade_xml_get_widget(gui, "previous");
1172 toolbar->next = glade_xml_get_widget(gui, "next");
1173 toolbar->trash = glade_xml_get_widget(gui, "trash");
1174
1175 toolbar->first = glade_xml_get_widget(gui, "first_bt");
1176 toolbar->last = glade_xml_get_widget(gui, "last_bt");
1177 toolbar->search = glade_xml_get_widget(gui, "search_bt");
1178 toolbar->quit = glade_xml_get_widget(gui, "quit_bt");
1179
1180 menu = (GtkMenu*) gtk_menu_new();
1181
1182 personal = gtk_menu_item_new_with_mnemonic (_("_Personal card"));
1183 gtk_widget_show (personal);
1184 gtk_container_add (GTK_CONTAINER (menu), personal);
1185
1186 company = gtk_menu_item_new_with_mnemonic (_("_Company card"));
1187 gtk_widget_show (company);
1188 gtk_container_add (GTK_CONTAINER (menu), company);
1189
1190 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar->add),
1191 (GtkWidget*) menu);
1192
1193 g_signal_connect (G_OBJECT(personal), "activate",
1194 G_CALLBACK (on_add_personal_cb), app);
1195
1196 g_signal_connect (G_OBJECT(company), "activate",
1197 G_CALLBACK (on_add_company_cb), app);
1198
1199 g_signal_connect(G_OBJECT(toolbar->new), "clicked",
1200 G_CALLBACK(on_new_cb), app);
1201
1202 g_signal_connect(G_OBJECT(toolbar->open), "clicked",
1203 G_CALLBACK(on_open_cb), app);
1204
1205 g_signal_connect(G_OBJECT(toolbar->save), "clicked",
1206 G_CALLBACK(on_save_cb), app);
1207
1208 g_signal_connect(G_OBJECT(toolbar->print), "clicked",
1209 G_CALLBACK(on_print_cb), app);
1210
1211 g_signal_connect(G_OBJECT(toolbar->add), "clicked",
1212 G_CALLBACK(on_add_personal_cb), app);
1213
1214 g_signal_connect(G_OBJECT(toolbar->add), "show-menu",
1215 G_CALLBACK(on_show_menu_cb), menu);
1216
1217 g_signal_connect(G_OBJECT(toolbar->delete), "clicked",
1218 G_CALLBACK(on_delete_card_cb), app);
1219
1220 g_signal_connect(G_OBJECT(toolbar->modify), "clicked",
1221 G_CALLBACK(on_modify_card_cb), app);
1222
1223 g_signal_connect(G_OBJECT(toolbar->previous), "clicked",
1224 G_CALLBACK(on_prev_cb), app);
1225
1226 g_signal_connect(G_OBJECT(toolbar->next), "clicked",
1227 G_CALLBACK(on_next_cb), app);
1228
1229 g_signal_connect(G_OBJECT(toolbar->first), "clicked",
1230 G_CALLBACK(on_first_cb), app);
1231
1232 g_signal_connect(G_OBJECT(toolbar->last), "clicked",
1233 G_CALLBACK(on_last_cb), app);
1234
1235 g_signal_connect(G_OBJECT(toolbar->trash), "toggled",
1236 G_CALLBACK(on_trash_toggled_cb), app);
1237
1238 g_signal_connect(G_OBJECT(toolbar->quit), "clicked",
1239 G_CALLBACK(on_quit_cb), app);
1240
1241 autosave = gconf_client_get_bool(client, RUBRICA_GCONF_AUTOSAVE, NULL);
1242
1243 if (autosave)
1244 gtk_widget_set_sensitive(toolbar->save, FALSE);
1245
1246 gconf_client_notify_add(client, RUBRICA_GCONF_AUTOSAVE,
1247 on_autosave_changed, toolbar->save, NULL, NULL);
1248 g_object_unref(client);
1249
1250 return toolbar;
1251 }
1252
1253
1254
1255 GType
rubrica_app_get_type()1256 rubrica_app_get_type()
1257 {
1258 static GType app_type = 0;
1259
1260 if (!app_type)
1261 {
1262 static const GTypeInfo app_info =
1263 {
1264 sizeof(RubricaAppClass),
1265 NULL,
1266 NULL,
1267 (GClassInitFunc) rubrica_app_class_init,
1268 NULL,
1269 NULL,
1270 sizeof(RubricaApp),
1271 0,
1272 (GInstanceInitFunc) rubrica_app_init
1273 };
1274
1275 app_type = g_type_register_static (G_TYPE_OBJECT, "RubricaApp",
1276 &app_info, 0);
1277 }
1278
1279 return app_type;
1280 }
1281
1282
1283
1284 static void
rubrica_app_class_init(RubricaAppClass * klass)1285 rubrica_app_class_init(RubricaAppClass* klass)
1286 {
1287 GObjectClass *class;
1288
1289 class = G_OBJECT_CLASS (klass);
1290 class->dispose = (GObjectFinalizeFunc) rubrica_app_dispose;
1291 class->finalize = (GObjectFinalizeFunc) rubrica_app_finalize;
1292
1293 g_type_class_add_private (klass, sizeof(RubricaAppPrivate));
1294 }
1295
1296
1297 static void
rubrica_app_init(RubricaApp * self)1298 rubrica_app_init(RubricaApp* self)
1299 {
1300 GladeXML* gui;
1301
1302 GtkWidget* groups_box;
1303 GtkWidget* notebook_box;
1304 GtkWidget* data_box;
1305 GtkWidget* statusbar_box;
1306 GtkWidget* tab;
1307 GtkWidget* button;
1308 GtkWidget* tree;
1309
1310 gui = glade_xml_new (RUBRICA_GUI_DIR"/MainWindow.glade", NULL, NULL);
1311 if (!gui)
1312 g_error("Can't load gui");
1313
1314 self->priv = g_new0(RubricaAppPrivate, 1);
1315
1316 // self->priv->groups = r_group_box_new();
1317 self->priv->groups = r_lib_get_group_box();
1318 init_group_box(self->priv->groups);
1319
1320 self->window = glade_xml_get_widget(gui, "RubricaMainWindow");
1321 groups_box = glade_xml_get_widget(gui, "groups_box");
1322 notebook_box = glade_xml_get_widget(gui, "notebook_box");
1323 data_box = glade_xml_get_widget(gui, "data_box");
1324 statusbar_box = glade_xml_get_widget(gui, "statusbar_box");
1325
1326 self->priv->paned = glade_xml_get_widget(gui, "data_paned");
1327 self->priv->group_paned = glade_xml_get_widget(gui, "group_paned");
1328
1329 self->priv->menu = build_menu(gui, self);
1330 self->priv->toolbar = build_toolbar(gui, self);
1331
1332 self->priv->notebook = gtk_notebook_new();
1333 self->priv->groups_view = rubrica_groups_view_new(self->priv->groups,
1334 APP_GROUPS);
1335 self->priv->trash_view = rubrica_trash_view_new();
1336 self->priv->search_view = rubrica_search_view_new();
1337 self->priv->data_view = rubrica_data_view_new();
1338 self->priv->statusbar = rubrica_statusbar_new();
1339
1340 self->priv->cutted = NULL;
1341 self->priv->notify = notify_notification_new("Rubrica Addressbook",
1342 "info", NULL);
1343 self->priv->active_plugin = g_strdup("autodetect");
1344 self->priv->manager = r_lib_get_manager();
1345 self->priv->print_settings = NULL;
1346 self->priv->show_card = TRUE;
1347
1348 g_object_set(self->priv->notebook, "homogeneous", FALSE, NULL);
1349
1350 gtk_box_pack_start(GTK_BOX(groups_box), self->priv->groups_view,
1351 TRUE, TRUE, 0);
1352 gtk_box_pack_start(GTK_BOX(notebook_box), self->priv->notebook,
1353 TRUE, TRUE, 0);
1354 gtk_box_pack_start(GTK_BOX(data_box), self->priv->data_view,
1355 TRUE, TRUE, 0);
1356 gtk_box_pack_start(GTK_BOX(statusbar_box), self->priv->statusbar,
1357 TRUE, TRUE, 0);
1358
1359 gtk_notebook_set_scrollable(GTK_NOTEBOOK(self->priv->notebook), TRUE);
1360
1361 /* Append Trash page in notebook and initialize
1362 */
1363 tab = rubrica_tab_new_with_label(self->priv->trash_view, _("Trash"));
1364 gtk_notebook_append_page(GTK_NOTEBOOK(self->priv->notebook),
1365 self->priv->trash_view, tab);
1366
1367 tree = rubrica_view_get_tree(RUBRICA_VIEW(self->priv->trash_view));
1368 button = rubrica_tab_get_button(RUBRICA_TAB(tab));
1369
1370 g_signal_connect(GTK_OBJECT (tree), "button_press_event",
1371 G_CALLBACK (on_trash_event_occurred), self);
1372 g_signal_connect(button, "clicked", G_CALLBACK(hide_trash_on_click), self);
1373
1374 g_signal_connect(self->priv->trash_view, "view-changed",
1375 G_CALLBACK (on_app_view_changed), self->priv->statusbar);
1376
1377
1378 /* Append Search page in notebook
1379 */
1380 tab = rubrica_tab_new_with_label(self->priv->search_view,
1381 _("Search results"));
1382 gtk_notebook_append_page(GTK_NOTEBOOK(self->priv->notebook),
1383 self->priv->search_view, tab);
1384
1385 tree = rubrica_view_get_tree(RUBRICA_VIEW(self->priv->search_view));
1386 button = rubrica_tab_get_button(RUBRICA_TAB(tab));
1387
1388 g_signal_connect(GTK_OBJECT (tree), "button_press_event",
1389 G_CALLBACK (on_search_event_occurred), self);
1390 g_signal_connect(button, "clicked", G_CALLBACK(hide_search_on_click),
1391 self->priv->search_view);
1392
1393 g_signal_connect(self->priv->search_view, "view-changed",
1394 G_CALLBACK (on_app_view_changed), self->priv->statusbar);
1395
1396 /* Groups view
1397 */
1398 tree = rubrica_view_get_tree(RUBRICA_VIEW(self->priv->groups_view));
1399 g_signal_connect(GTK_OBJECT (tree), "button_press_event",
1400 G_CALLBACK (on_app_group_view_event_occurred), self);
1401
1402 g_signal_connect (GTK_OBJECT (tree), "key_press_event",
1403 G_CALLBACK (on_key_press_event_cb), self);
1404
1405 /* Other Handle callbacks
1406 */
1407 g_signal_connect(G_OBJECT(self->window), "delete_event",
1408 G_CALLBACK(on_delete_event_cb), self);
1409
1410 g_signal_connect(G_OBJECT(self->priv->data_view), "launch",
1411 G_CALLBACK(on_launch_cb), self);
1412
1413 gtk_widget_show(groups_box);
1414 gtk_widget_show(notebook_box);
1415 gtk_widget_show(data_box);
1416 gtk_widget_show(statusbar_box);
1417
1418 self->priv->dispose_has_run = FALSE;
1419 }
1420
1421
1422
1423 static void
rubrica_app_dispose(RubricaApp * self)1424 rubrica_app_dispose (RubricaApp* self)
1425 {
1426 g_return_if_fail(IS_RUBRICA_APP(self));
1427
1428 if (self->priv->dispose_has_run)
1429 return;
1430
1431 g_object_unref(self->window);
1432 g_free(self->priv->menu);
1433 g_free(self->priv->toolbar);
1434
1435 self->priv->dispose_has_run = TRUE;
1436 }
1437
1438
1439 static void
rubrica_app_finalize(RubricaApp * self)1440 rubrica_app_finalize (RubricaApp* self)
1441 {
1442 g_return_if_fail(IS_RUBRICA_APP(self));
1443
1444 g_free(self->priv);
1445 self->priv = NULL;
1446 }
1447
1448
1449
1450
1451 /* Public
1452 */
1453
1454 /**
1455 * rubrica_app_new
1456 *
1457 * create a new #RubricaApp
1458 *
1459 * returns: a new allocated #RubricaApp
1460 */
1461 RubricaApp*
rubrica_app_new(void)1462 rubrica_app_new (void)
1463 {
1464 RubricaApp* app;
1465 GConfClient* client;
1466 gboolean have_files;
1467
1468 #ifdef ENABLE_DEBUG
1469 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "rubrica_app_new");
1470 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Building gui...");
1471 #endif
1472
1473 app = g_object_new(rubrica_app_get_type(), NULL);
1474
1475 client = gconf_client_get_default();
1476 have_files = gconf_client_get_bool(client, RUBRICA_GCONF_LOAD_FILES, NULL);
1477 if (have_files)
1478 load_addressbooks(app);
1479 else
1480 rubrica_app_append_addressbook(app);
1481 // rubrica_app_append_empty_addressbook(app);
1482
1483 g_object_unref(client);
1484
1485 return app;
1486 }
1487
1488
1489 /**
1490 * rubrica_app_free
1491 * @set: a #RubricaApp
1492 *
1493 * free memory owned by a #RubricaApp
1494 */
1495 void
rubrica_app_free(RubricaApp * app)1496 rubrica_app_free(RubricaApp* app)
1497 {
1498 g_return_if_fail(IS_RUBRICA_APP(app));
1499
1500 g_object_unref(app);
1501 }
1502
1503
1504 /* Get
1505 */
1506 GtkWidget*
rubrica_app_get_search(RubricaApp * app)1507 rubrica_app_get_search (RubricaApp* app)
1508 {
1509 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1510
1511 return(GtkWidget*) app->priv->search_view;
1512 }
1513
1514 GtkWidget*
rubrica_app_get_trash(RubricaApp * app)1515 rubrica_app_get_trash (RubricaApp* app)
1516 {
1517 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1518
1519 return (GtkWidget*) app->priv->trash_view;
1520 }
1521
1522
1523 GtkWidget*
rubrica_app_get_notebook(RubricaApp * app)1524 rubrica_app_get_notebook (RubricaApp* app)
1525 {
1526 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1527
1528 return (GtkWidget*) app->priv->notebook;
1529 }
1530
1531
1532
1533 /**
1534 * rubrica_app_get_current_view
1535 * @app: a #RubricaApp
1536 *
1537 * get the current RubricaCardView widget
1538 *
1539 * returns: a *GtkWidget
1540 */
1541 GtkWidget*
rubrica_app_get_current_view(RubricaApp * app)1542 rubrica_app_get_current_view (RubricaApp* app)
1543 {
1544 GtkWidget* child;
1545 gint page;
1546
1547 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1548
1549 page = gtk_notebook_get_current_page(GTK_NOTEBOOK(app->priv->notebook));
1550 child = gtk_notebook_get_nth_page (GTK_NOTEBOOK(app->priv->notebook), page);
1551
1552 return child;
1553 }
1554
1555
1556 RAbook*
rubrica_app_get_active_addressbook(RubricaApp * app)1557 rubrica_app_get_active_addressbook (RubricaApp* app)
1558 {
1559 GtkWidget* child;
1560
1561 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1562
1563 child = rubrica_app_get_current_view(app);
1564
1565 return rubrica_cards_view_get_addressbook(RUBRICA_CARDS_VIEW(child));
1566 }
1567
1568
1569 RGroupBox*
rubrica_app_get_groups(RubricaApp * app)1570 rubrica_app_get_groups (RubricaApp* app)
1571 {
1572 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1573
1574 return app->priv->groups;
1575 }
1576
1577
1578 GtkWidget*
rubrica_app_get_dataview(RubricaApp * app)1579 rubrica_app_get_dataview (RubricaApp* app)
1580 {
1581 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1582
1583 return app->priv->data_view;
1584 }
1585
1586 GtkWidget*
rubrica_app_get_groups_view(RubricaApp * app)1587 rubrica_app_get_groups_view(RubricaApp* app)
1588 {
1589 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1590
1591 return app->priv->groups_view;
1592 }
1593
1594
1595 GtkWidget*
rubrica_app_get_statusbar(RubricaApp * app)1596 rubrica_app_get_statusbar (RubricaApp* app)
1597 {
1598 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1599
1600 return app->priv->statusbar;
1601 }
1602
1603 GtkWidget*
rubrica_app_get_paned(RubricaApp * app)1604 rubrica_app_get_paned (RubricaApp* app)
1605 {
1606 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1607
1608 return app->priv->paned;
1609 }
1610
1611
1612 GtkWidget*
rubrica_app_get_group_paned(RubricaApp * app)1613 rubrica_app_get_group_paned (RubricaApp* app)
1614 {
1615 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1616
1617 return app->priv->group_paned;
1618 }
1619
1620
1621 gchar*
rubrica_app_get_view_report(RubricaApp * app)1622 rubrica_app_get_view_report (RubricaApp* app)
1623 {
1624 GtkWidget* view;
1625 gchar* report;
1626
1627 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1628
1629 view = rubrica_app_get_current_view(app);
1630 g_object_get(view, "report", &report, NULL);
1631
1632 return report;
1633 }
1634
1635
1636 gchar*
rubrica_app_get_plugin_name(RubricaApp * app)1637 rubrica_app_get_plugin_name (RubricaApp* app)
1638 {
1639 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1640
1641 return app->priv->active_plugin;
1642 }
1643
1644
1645 RPluginManager*
rubrica_app_get_plugin_manager(RubricaApp * app)1646 rubrica_app_get_plugin_manager (RubricaApp* app)
1647 {
1648 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1649
1650 return app->priv->manager;
1651 }
1652
1653
1654 RCard*
rubrica_app_get_selected_card(RubricaApp * app)1655 rubrica_app_get_selected_card (RubricaApp* app)
1656 {
1657 RAbook* abook;
1658
1659 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
1660
1661 abook = rubrica_app_get_active_addressbook(app);
1662
1663 return r_abook_get_selected_card(R_ABOOK(abook));
1664 }
1665
1666
1667
1668 void
rubrica_app_run(RubricaApp * app)1669 rubrica_app_run(RubricaApp* app)
1670 {
1671 GConfClient* client;
1672 gint width, height, position, group_pos, style;
1673
1674 g_return_if_fail(IS_RUBRICA_APP(app));
1675
1676 #ifdef ENABLE_DEBUG
1677 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "rubrica_app_run");
1678 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Reading preferences...");
1679 #endif
1680
1681 client = gconf_client_get_default();
1682 gconf_client_add_dir(client, KEY_MISC, GCONF_CLIENT_PRELOAD_NONE, NULL);
1683 gconf_client_add_dir(client, KEY_FILE, GCONF_CLIENT_PRELOAD_NONE, NULL);
1684 gconf_client_add_dir(client, KEY_DISPLAY, GCONF_CLIENT_PRELOAD_NONE, NULL);
1685 gconf_client_add_dir(client, KEY_SEARCH, GCONF_CLIENT_PRELOAD_NONE, NULL);
1686 gconf_client_add_dir(client, KEY_URLS, GCONF_CLIENT_PRELOAD_NONE, NULL);
1687 gconf_client_add_dir(client, KEY_APPEARANCE,
1688 GCONF_CLIENT_PRELOAD_NONE, NULL);
1689
1690 width = gconf_client_get_int(client, RUBRICA_GCONF_WIDTH, NULL);
1691 height = gconf_client_get_int(client, RUBRICA_GCONF_HEIGHT, NULL);
1692 position = gconf_client_get_int(client, RUBRICA_GCONF_PANED_POSITION, NULL);
1693 group_pos = gconf_client_get_int(client, RUBRICA_GCONF_GRP_PANED_POSITION,
1694 NULL);
1695 style = rubrica_preferences_get_toolbar_style();
1696
1697 rubrica_app_set_toolbar_style(app, style);
1698 gtk_window_resize(GTK_WINDOW(app->window), width, height);
1699 gtk_paned_set_position(GTK_PANED(app->priv->paned), position);
1700 gtk_paned_set_position(GTK_PANED(app->priv->group_paned), group_pos);
1701
1702 gtk_widget_show_all(app->window);
1703 gtk_widget_hide(app->priv->search_view);
1704 gtk_widget_hide(app->priv->trash_view);
1705
1706 rubrica_app_enable_previouses(app, FALSE);
1707 rubrica_app_enable_nexts(app, FALSE);
1708
1709 g_object_unref(client);
1710 }
1711
1712 /*
1713 void
1714 rubrica_app_append_empty_addressbook(RubricaApp* app)
1715 {
1716 rubrica_app_append_addressbook(app, NULL);
1717 }
1718 */
1719
1720 GtkWidget*
rubrica_app_append_addressbook(RubricaApp * app)1721 rubrica_app_append_addressbook(RubricaApp* app)
1722 {
1723 GtkWidget *view = NULL;
1724 RAbook *book;
1725 GtkWidget *tab;
1726 GtkWidget *button;
1727 GtkWidget *tree;
1728 gint page;
1729
1730 view = rubrica_cards_view_new(NULL);
1731 tab = rubrica_tab_new_with_label(view, _("no name"));
1732 button = rubrica_tab_get_button(RUBRICA_TAB(tab));
1733 book = rubrica_cards_view_get_addressbook(RUBRICA_CARDS_VIEW(view));
1734 tree = rubrica_view_get_tree(RUBRICA_VIEW(view));
1735 g_object_set(view, "view-brother", tab, NULL);
1736
1737
1738 gtk_widget_show(view); // mostra sempre il widget prima di inserirlo
1739 // nel notebook, se non vuoi diventare pazzo
1740 // a capire perchè non switcha
1741
1742 // set the new addressbook as active and switch notebook to display it
1743 page = gtk_notebook_append_page(GTK_NOTEBOOK(app->priv->notebook),
1744 view, tab);
1745 gtk_notebook_set_current_page(GTK_NOTEBOOK(app->priv->notebook), page);
1746
1747 g_signal_connect(GTK_OBJECT (button), "clicked",
1748 G_CALLBACK (on_close_cb), app);
1749
1750 g_signal_connect(app->priv->notebook, "switch-page",
1751 G_CALLBACK (on_notebook_switch_page), app);
1752
1753 g_signal_connect(view, "view-changed", G_CALLBACK (on_cards_view_changed),
1754 app->priv->statusbar);
1755
1756 g_signal_connect(view, "mark", G_CALLBACK(on_card_marked), app);
1757 // g_signal_connect(view, "unmark", G_CALLBACK(on_card_unmarked), app);
1758
1759 g_signal_connect(GTK_WIDGET(tree), "key-press-event",
1760 G_CALLBACK(on_key_press_event_cb), app);
1761
1762 g_signal_connect(GTK_OBJECT (tree), "button_press_event",
1763 G_CALLBACK (on_cards_event_occurred), app);
1764
1765 g_signal_connect(G_OBJECT(book), "card_added",
1766 G_CALLBACK(on_card_added), app);
1767
1768 g_signal_connect(G_OBJECT(book), "card_deleted",
1769 G_CALLBACK(on_card_deleted), app);
1770
1771 g_signal_connect(G_OBJECT(book), "card_recovered",
1772 G_CALLBACK(on_card_recovered), app);
1773
1774 g_signal_connect(G_OBJECT(book), "card_replaced",
1775 G_CALLBACK(on_card_modified), app);
1776
1777 g_signal_connect(G_OBJECT(book), "card_destroyed",
1778 G_CALLBACK(on_card_destroyed), app);
1779
1780 g_signal_connect(G_OBJECT(book), "addressbook_changed",
1781 G_CALLBACK(on_addressbook_changed), app);
1782
1783 g_signal_connect(G_OBJECT(book), "addressbook_saved",
1784 G_CALLBACK(on_addressbook_saved), app);
1785
1786 g_signal_connect(G_OBJECT(book), "save_fail",
1787 G_CALLBACK(on_addressbook_save_fail), app);
1788
1789 return view;
1790 }
1791
1792
1793 gboolean
rubrica_app_load_file(RubricaApp * app,gchar * file)1794 rubrica_app_load_file(RubricaApp* app, gchar* file/*, const gchar* filter*/)
1795 {
1796 GtkWidget *view = NULL;
1797 GtkWidget *tab;
1798 RAbook *book;
1799 gchar *message;
1800
1801 g_return_val_if_fail(IS_RUBRICA_APP(app), FALSE);
1802 g_return_val_if_fail(file != NULL, FALSE);
1803
1804 view = rubrica_app_append_addressbook(app);
1805 book = rubrica_app_get_active_addressbook(app);
1806 g_object_set(book, "file-filter", /*filter*/app->priv->active_plugin, NULL);
1807
1808 if (r_abook_open_file(book, file))
1809 {
1810 RCard* card;
1811 RubricaStatusbar* bar = RUBRICA_STATUSBAR(app->priv->statusbar);
1812
1813 app->priv->show_card = FALSE;
1814
1815 r_abook_reset_book(book);
1816 card = r_abook_get_card(book);
1817 for (; card; card = r_abook_get_next_card(book))
1818 rubrica_app_add_card(app, card);
1819
1820 g_object_get(view, "view-brother", &tab, "view-message", &message, NULL);
1821 g_object_set(tab, "tab-label", g_path_get_basename(file), NULL);
1822
1823 rubrica_statusbar_enable_extra(bar, TRUE);
1824 rubrica_statusbar_enable_images(bar, TRUE);
1825 rubrica_statusbar_extra_set_text(bar, message);
1826
1827 app->priv->show_card = TRUE;
1828 }
1829 else
1830 {
1831 GtkWidget* notebook;
1832 gint page;
1833
1834 notebook = rubrica_app_get_notebook(app);
1835 page = gtk_notebook_page_num(GTK_NOTEBOOK(notebook), view);
1836 gtk_notebook_remove_page(GTK_NOTEBOOK(notebook), page);
1837
1838 return FALSE;
1839 }
1840
1841 rubrica_browse_nth_card(app, "0", FALSE);
1842 return TRUE;
1843 }
1844
1845
1846 void
rubrica_app_add_card(RubricaApp * app,RCard * card)1847 rubrica_app_add_card(RubricaApp* app, RCard* card)
1848 {
1849 GtkWidget *view = NULL;
1850 gboolean deleted;
1851
1852 g_return_if_fail(IS_RUBRICA_APP(app));
1853 g_return_if_fail(IS_R_CARD(card));
1854
1855 view = rubrica_app_get_current_view(app);
1856
1857 g_object_get(card, "card-deleted", &deleted, NULL);
1858
1859 add_card_groups2set(app, card);
1860
1861 if (deleted)
1862 rubrica_app_move_card_to_trash(app, card);
1863 else
1864 {
1865 rubrica_cards_view_add_card(RUBRICA_CARDS_VIEW(view), card);
1866 if (app->priv->show_card)
1867 rubrica_app_display_card_data(RUBRICA_APP(app), card);
1868 }
1869 }
1870
1871
1872
1873
1874 /* if a loaded card is marked deleted, it is moved to trash
1875 TRASH_ADDRESSBOK - pointer to the original addressbook (card came from)
1876 TRASH_ADB - pointer to the adb (card came from)
1877 */
1878 void
rubrica_app_move_card_to_trash(RubricaApp * app,RCard * card)1879 rubrica_app_move_card_to_trash (RubricaApp* app, RCard* card)
1880 {
1881 RAbook* book;
1882 GtkWidget* trash;
1883
1884 g_return_if_fail(IS_R_CARD(card));
1885
1886 trash = rubrica_app_get_trash(app);
1887 book = rubrica_app_get_active_addressbook(app);
1888
1889 rubrica_trash_view_add_card(RUBRICA_TRASH_VIEW(trash), book, card);
1890 }
1891
1892
1893 void
rubrica_app_display_card_data(RubricaApp * app,RCard * card)1894 rubrica_app_display_card_data (RubricaApp* app, RCard* card)
1895 {
1896 RRate rate;
1897 gboolean locked;
1898 GtkWidget* view;
1899 RubricaPixmap lock;
1900 RubricaStatusbar* bar = RUBRICA_STATUSBAR(app->priv->statusbar);
1901
1902 view = rubrica_app_get_current_view(app);
1903 g_object_set(view, "view-selected", TRUE, NULL);
1904
1905 g_object_get(card, "card-locked", &locked, "card-rate", &rate, NULL);
1906 lock = PIXMAP_UNLOCK + (gint) locked;
1907
1908 rubrica_statusbar_enable_extra(bar, TRUE);
1909 rubrica_statusbar_enable_images(bar, TRUE);
1910 rubrica_statusbar_extra_set_rate(bar, rate);
1911 rubrica_statusbar_extra_set_lock(bar, lock);
1912
1913 rubrica_data_view_show_card(RUBRICA_DATA_VIEW(app->priv->data_view), card);
1914 }
1915
1916 void
rubrica_app_set_plugin_name(RubricaApp * app,const gchar * plugin_name)1917 rubrica_app_set_plugin_name (RubricaApp* app, const gchar* plugin_name)
1918 {
1919 RAbook* abook;
1920
1921 g_return_if_fail(IS_RUBRICA_APP(app));
1922
1923 abook = rubrica_app_get_active_addressbook(app);
1924
1925 g_free(app->priv->active_plugin);
1926 if (!plugin_name || (g_ascii_strcasecmp(plugin_name, "") == 0))
1927 app->priv->active_plugin = NULL;
1928 else
1929 app->priv->active_plugin = g_strdup(plugin_name);
1930
1931 r_abook_load_plugin(abook, app->priv->active_plugin);
1932 }
1933
1934
1935 void
rubrica_app_set_toolbar_style(RubricaApp * app,gint style)1936 rubrica_app_set_toolbar_style (RubricaApp* app, gint style)
1937 {
1938 GtkToolbarStyle gnome_default;
1939
1940 g_return_if_fail(IS_RUBRICA_APP(app));
1941
1942 switch(style)
1943 {
1944 case RUB_ICONS:
1945 gtk_toolbar_set_style(GTK_TOOLBAR(app->priv->toolbar->toolbar),
1946 GTK_TOOLBAR_ICONS);
1947 break;
1948
1949 case RUB_TEXT:
1950 gtk_toolbar_set_style(GTK_TOOLBAR(app->priv->toolbar->toolbar),
1951 GTK_TOOLBAR_TEXT);
1952 break;
1953
1954 case RUB_BOTH:
1955 gtk_toolbar_set_style(GTK_TOOLBAR(app->priv->toolbar->toolbar),
1956 GTK_TOOLBAR_BOTH);
1957 break;
1958
1959 case RUB_GNOME:
1960 gnome_default = rubrica_preferences_get_gnome_default();
1961 gtk_toolbar_set_style(GTK_TOOLBAR(app->priv->toolbar->toolbar),
1962 (GtkToolbarStyle) gnome_default);
1963 break;
1964
1965 default:
1966 break;
1967 }
1968 }
1969
1970 void
rubrica_app_set_font(RubricaApp * app,gchar * font)1971 rubrica_app_set_font (RubricaApp* app, gchar* font)
1972 {
1973 g_return_if_fail(IS_RUBRICA_APP(app));
1974
1975 g_object_set(app->priv->data_view, "data-font", font, NULL);
1976 }
1977
1978
1979 void
rubrica_app_show_page(RubricaApp * app,gint page)1980 rubrica_app_show_page (RubricaApp* app, gint page)
1981 {
1982 GtkWidget* notebook;
1983
1984 g_return_if_fail(IS_RUBRICA_APP(app));
1985
1986 notebook = app->priv->notebook;
1987 gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), page);
1988 }
1989
1990
1991 gint
rubrica_app_get_stack_len(RubricaApp * app)1992 rubrica_app_get_stack_len (RubricaApp* app)
1993 {
1994 g_return_val_if_fail(IS_RUBRICA_APP(app), 0);
1995
1996 return g_list_length(app->priv->cutted);
1997 }
1998
1999
2000 void
rubrica_app_push_card(RubricaApp * app,gpointer data)2001 rubrica_app_push_card (RubricaApp* app, gpointer data)
2002 {
2003 g_return_if_fail(IS_RUBRICA_APP(app));
2004
2005 app->priv->cutted = g_list_append(app->priv->cutted, data);
2006 }
2007
2008
2009 gpointer
rubrica_app_pop_card(RubricaApp * app)2010 rubrica_app_pop_card (RubricaApp* app)
2011 {
2012 GList* link = NULL;
2013 gpointer data = NULL;
2014
2015 g_return_val_if_fail(IS_RUBRICA_APP(app), NULL);
2016
2017 link = g_list_last(app->priv->cutted);
2018
2019 if (link)
2020 {
2021 data = link->data;
2022 app->priv->cutted = g_list_remove_link(app->priv->cutted, link);
2023
2024 g_list_free_1(link);
2025 }
2026
2027 return data;
2028 }
2029
2030
2031 void
rubrica_app_notify(RubricaApp * app,gchar * msg)2032 rubrica_app_notify (RubricaApp* app, gchar* msg)
2033 {
2034 g_return_if_fail(IS_RUBRICA_APP(app));
2035
2036 rubrica_statusbar_push_message(RUBRICA_STATUSBAR(app->priv->statusbar), msg);
2037 }
2038
2039
2040 void
rubrica_app_show_message(RubricaApp * app,gchar * msg)2041 rubrica_app_show_message(RubricaApp* app, gchar* msg)
2042 {
2043 GtkWidget* dialog;
2044
2045 g_return_if_fail(IS_RUBRICA_APP(app));
2046 g_return_if_fail(msg != NULL);
2047
2048 dialog = gtk_message_dialog_new (GTK_WINDOW(app->window),
2049 GTK_DIALOG_DESTROY_WITH_PARENT,
2050 GTK_MESSAGE_WARNING,
2051 GTK_BUTTONS_OK,
2052 msg);
2053
2054 gtk_dialog_run (GTK_DIALOG (dialog));
2055 gtk_widget_destroy (dialog);
2056 }
2057
2058
2059 void
rubrica_app_update_view(RubricaApp * app)2060 rubrica_app_update_view (RubricaApp* app)
2061 {
2062 GtkWidget* view;
2063 GtkTreeView *tree;
2064 GtkTreeSelection *selection;
2065
2066 g_return_if_fail(IS_RUBRICA_APP(app));
2067
2068 view = rubrica_app_get_current_view(app);
2069 tree = GTK_TREE_VIEW(rubrica_view_get_tree(RUBRICA_VIEW(view)));
2070 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
2071
2072 gtk_tree_selection_unselect_all(selection);
2073 }
2074
2075
2076 void
rubrica_app_display_search_results(RubricaApp * app,GList * results)2077 rubrica_app_display_search_results (RubricaApp* app, GList* results)
2078 {
2079 RAbook* book;
2080 RubricaSearchView* search;
2081
2082 g_return_if_fail(IS_RUBRICA_APP(app));
2083
2084 gtk_widget_show(app->priv->search_view);
2085 book = rubrica_app_get_active_addressbook(app);
2086 search = RUBRICA_SEARCH_VIEW(app->priv->search_view);
2087 gtk_notebook_set_current_page (GTK_NOTEBOOK(app->priv->notebook), 1);
2088
2089 rubrica_search_view_set_addressbook(search, book);
2090 rubrica_search_view_display_results(search, results);
2091 }
2092
2093
2094 void
rubrica_app_display_cards_by_group(RubricaApp * app,gchar * group)2095 rubrica_app_display_cards_by_group(RubricaApp* app, gchar* group)
2096 {
2097 RAbook* book;
2098 GList *ids; // id list of cards that belongs to the given group
2099
2100 g_return_if_fail(IS_RUBRICA_APP(app));
2101
2102 book = rubrica_app_get_active_addressbook(app);
2103 ids = r_abook_find_cards_by_group(book, group);
2104
2105 display_cards_list(app, ids);
2106
2107 g_list_free(ids);
2108 }
2109
2110 void
rubrica_app_display_cards_by_type(RubricaApp * app,gchar * type)2111 rubrica_app_display_cards_by_type(RubricaApp* app, gchar* type)
2112 {
2113 RAbook* book;
2114 GList *ids; // id list of cards that belongs to the given type
2115
2116 g_return_if_fail(IS_RUBRICA_APP(app));
2117
2118 book = rubrica_app_get_active_addressbook(app);
2119 ids = r_abook_find_cards_by_type (book, type);
2120
2121 display_cards_list(app, ids);
2122
2123 g_list_free(ids);
2124 }
2125
2126
2127 void
rubrica_app_display_cards_by_genre(RubricaApp * app,gchar * genre)2128 rubrica_app_display_cards_by_genre(RubricaApp* app, gchar* genre)
2129 {
2130 RAbook* book;
2131 GList *ids; // id list of cards that belongs to the given genre
2132
2133 g_return_if_fail(IS_RUBRICA_APP(app));
2134
2135 book = rubrica_app_get_active_addressbook(app);
2136 ids = r_abook_find_cards_by_genre(book, genre);
2137
2138 display_cards_list(app, ids);
2139
2140 g_list_free(ids);
2141 }
2142
2143 void
rubrica_app_display_cards_by_rate(RubricaApp * app,RRate rate)2144 rubrica_app_display_cards_by_rate(RubricaApp* app, RRate rate)
2145 {
2146 RAbook* book;
2147 GList *ids; // id list of cards that belongs to the given rate
2148
2149 g_return_if_fail(IS_RUBRICA_APP(app));
2150
2151 book = rubrica_app_get_active_addressbook(app);
2152 ids = r_abook_find_cards_by_rate(book, rate);
2153
2154 display_cards_list(app, ids);
2155
2156 g_list_free(ids);
2157 }
2158
2159
2160 void
rubrica_app_enable_previouses(RubricaApp * app,gboolean bool)2161 rubrica_app_enable_previouses (RubricaApp* app, gboolean bool)
2162 {
2163 g_return_if_fail(IS_RUBRICA_APP(app));
2164
2165 gtk_widget_set_sensitive(app->priv->toolbar->previous, bool);
2166 gtk_widget_set_sensitive(app->priv->toolbar->first, bool);
2167 }
2168
2169
2170 void
rubrica_app_enable_nexts(RubricaApp * app,gboolean bool)2171 rubrica_app_enable_nexts (RubricaApp* app, gboolean bool)
2172 {
2173 g_return_if_fail(IS_RUBRICA_APP(app));
2174
2175 gtk_widget_set_sensitive(app->priv->toolbar->next, bool);
2176 gtk_widget_set_sensitive(app->priv->toolbar->last, bool);
2177 }
2178
2179
2180 void
rubrica_app_print(RubricaApp * app)2181 rubrica_app_print(RubricaApp* app)
2182 {
2183 RubricaPrint* print;
2184 GtkWidget* dialog;
2185 GtkWidget* view;
2186 RAbook* book;
2187 GList* cards = NULL;
2188 GError* error = NULL;
2189 gchar* font;
2190 gint res;
2191
2192 print = rubrica_print_new();
2193
2194 view = rubrica_app_get_current_view(app);
2195 book = rubrica_app_get_active_addressbook(app);
2196 font = g_strdup("Liberation Sans"); // gconf_get_font
2197 cards = rubrica_cards_view_get_selected_cards(RUBRICA_CARDS_VIEW(view));
2198
2199 g_object_set(print,
2200 "printing-addressbook", book,
2201 "printing-cards", cards,
2202 "printing-font", font,
2203 "printing-font-size", 10, NULL);
2204
2205 if (app->priv->print_settings != NULL)
2206 gtk_print_operation_set_print_settings(print->operation,
2207 app->priv->print_settings);
2208
2209 res = gtk_print_operation_run(print->operation,
2210 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
2211 GTK_WINDOW(app->window), &error);
2212
2213 if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
2214 {
2215 GtkPrintSettings* settings;
2216
2217 if (app->priv->print_settings != NULL)
2218 g_object_unref(app->priv->print_settings);
2219
2220 settings = gtk_print_operation_get_print_settings(print->operation);
2221 app->priv->print_settings = settings;
2222 g_object_ref(settings);
2223 }
2224 else if (error)
2225 {
2226 dialog = gtk_message_dialog_new(GTK_WINDOW(app->window),
2227 GTK_DIALOG_DESTROY_WITH_PARENT,
2228 GTK_MESSAGE_ERROR,
2229 GTK_BUTTONS_CLOSE,
2230 error->message);
2231 g_error_free(error);
2232 gtk_dialog_run(GTK_DIALOG(dialog));
2233 gtk_widget_destroy(dialog);
2234 }
2235
2236 g_object_unref(print->operation);
2237 }
2238