* all:
[modest] / src / gtk / modest-main-window.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <glib/gi18n.h>
31 #include <gtk/gtktreeviewcolumn.h>
32 #include <modest-runtime.h>
33
34 #include <widgets/modest-main-window.h>
35 #include <widgets/modest-window-priv.h>
36 #include <widgets/modest-msg-edit-window.h>
37 #include "modest-account-view-window.h"
38
39
40 #include "modest-widget-memory.h"
41 #include "modest-ui-actions.h"
42 #include "modest-main-window-ui.h"
43 #include "modest-account-mgr.h"
44 #include "modest-conf.h"
45 #include <modest-tny-msg.h>
46 #include "modest-mail-operation.h"
47 #include "modest-icon-names.h"
48
49 /* 'private'/'protected' functions */
50 static void modest_main_window_class_init    (ModestMainWindowClass *klass);
51 static void modest_main_window_init          (ModestMainWindow *obj);
52 static void modest_main_window_finalize      (GObject *obj);
53
54 static void restore_sizes (ModestMainWindow *self);
55 static void save_sizes (ModestMainWindow *self);
56
57 static gboolean     on_header_view_button_press_event   (ModestHeaderView *header_view,
58                                                          GdkEventButton   *event,
59                                                          ModestMainWindow *self);
60
61 static gboolean     on_folder_view_button_press_event   (ModestFolderView *folder_view,
62                                                          GdkEventButton   *event,
63                                                          ModestMainWindow *self);
64
65 static gboolean     show_context_popup_menu             (ModestMainWindow *window,
66                                                          GtkTreeView      *tree_view,
67                                                          GdkEventButton   *event,
68                                                          GtkWidget        *menu);
69
70 static void         connect_signals                      (ModestMainWindow *self);
71
72
73 /* list my signals */
74 enum {
75         /* MY_SIGNAL_1, */
76         /* MY_SIGNAL_2, */
77         LAST_SIGNAL
78 };
79
80 typedef struct _ModestMainWindowPrivate ModestMainWindowPrivate;
81 struct _ModestMainWindowPrivate {
82
83         GtkWidget *folder_paned;
84         GtkWidget *msg_paned;
85         GtkWidget *main_paned;
86         
87         GtkWidget *online_toggle;
88         GtkWidget *folder_info_label;
89 };
90
91
92 #define MODEST_MAIN_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
93                                                 MODEST_TYPE_MAIN_WINDOW, \
94                                                 ModestMainWindowPrivate))
95
96 typedef struct _GetMsgAsyncHelper {
97         ModestMainWindowPrivate *main_window_private;
98         guint action;
99         ModestMailOperationReplyType reply_type;
100         ModestMailOperationForwardType forward_type;
101         gchar *from;
102         TnyIterator *iter;
103 } GetMsgAsyncHelper;
104
105 /* globals */
106 static GtkWindowClass *parent_class = NULL;
107
108 /* uncomment the following if you have defined any signals */
109 /* static guint signals[LAST_SIGNAL] = {0}; */
110
111 GType
112 modest_main_window_get_type (void)
113 {
114         static GType my_type = 0;
115         if (!my_type) {
116                 static const GTypeInfo my_info = {
117                         sizeof(ModestMainWindowClass),
118                         NULL,           /* base init */
119                         NULL,           /* base finalize */
120                         (GClassInitFunc) modest_main_window_class_init,
121                         NULL,           /* class finalize */
122                         NULL,           /* class data */
123                         sizeof(ModestMainWindow),
124                         1,              /* n_preallocs */
125                         (GInstanceInitFunc) modest_main_window_init,
126                         NULL
127                 };
128                 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
129                                                   "ModestMainWindow",
130                                                   &my_info, 0);
131         }
132         return my_type;
133 }
134
135 static void
136 modest_main_window_class_init (ModestMainWindowClass *klass)
137 {
138         GObjectClass *gobject_class;
139         gobject_class = (GObjectClass*) klass;
140
141         parent_class            = g_type_class_peek_parent (klass);
142         gobject_class->finalize = modest_main_window_finalize;
143
144         g_type_class_add_private (gobject_class, sizeof(ModestMainWindowPrivate));
145 }
146
147 static void
148 modest_main_window_init (ModestMainWindow *obj)
149 {
150         ModestMainWindowPrivate *priv;
151         TnyFolderStoreQuery     *query;
152         
153         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
154         
155         priv->folder_paned = NULL;
156         priv->msg_paned    = NULL;
157         priv->main_paned   = NULL;      
158
159         /* folder view */
160         query = tny_folder_store_query_new ();
161         tny_folder_store_query_add_item (query, NULL,
162                                          TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED);
163
164         obj->folder_view =
165                 MODEST_FOLDER_VIEW(modest_folder_view_new (modest_runtime_get_account_store(),
166                                                            query));
167         if (!obj->folder_view)
168                 g_printerr ("modest: cannot instantiate folder view\n");        
169         g_object_unref (G_OBJECT (query));
170
171         /* header view */
172         obj->header_view  =
173                 MODEST_HEADER_VIEW(modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_DETAILS));
174         if (!obj->header_view)
175                 g_printerr ("modest: cannot instantiate header view\n");
176
177         /* msg preview */
178         obj->msg_preview = MODEST_MSG_VIEW(modest_msg_view_new (NULL));
179         if (!obj->msg_preview)
180                 g_printerr ("modest: cannot instantiate msgpreiew\n");
181
182         /* online/offline combo */
183         priv->online_toggle = gtk_toggle_button_new ();
184
185         /* label with number of items, unread items for 
186            the current folder */
187         priv->folder_info_label = gtk_label_new (NULL);
188
189         /* status bar */
190         obj->status_bar   = gtk_statusbar_new ();
191         gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR(obj->status_bar),
192                                            FALSE);
193
194         /* progress bar */
195         obj->progress_bar = gtk_progress_bar_new ();
196         gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(obj->progress_bar), 1.0);
197         gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR(obj->progress_bar),
198                                         PANGO_ELLIPSIZE_END);
199 }
200
201 static void
202 modest_main_window_finalize (GObject *obj)
203 {
204         G_OBJECT_CLASS(parent_class)->finalize (obj);
205 }
206
207
208 static void
209 restore_sizes (ModestMainWindow *self)
210 {
211         ModestConf *conf;
212         ModestMainWindowPrivate *priv;
213         ModestWindowPrivate *parent_priv;
214         
215         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
216         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
217
218         conf = modest_runtime_get_conf ();
219         
220         modest_widget_memory_restore (conf, G_OBJECT(priv->folder_paned),
221                                       "modest-folder-paned");
222         modest_widget_memory_restore (conf, G_OBJECT(priv->msg_paned),
223                                       "modest-msg-paned");
224         modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
225                                       "modest-main-paned");
226         modest_widget_memory_restore (conf, G_OBJECT(self->header_view),"header-view");
227         modest_widget_memory_restore (conf,G_OBJECT(self), "modest-main-window");
228 }
229
230
231 static void
232 save_sizes (ModestMainWindow *self)
233 {
234         ModestWindowPrivate *parent_priv;
235         ModestMainWindowPrivate *priv;
236         ModestConf *conf;
237         
238         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
239         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
240
241         conf = modest_runtime_get_conf ();
242         
243         modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window");
244         modest_widget_memory_save (conf, G_OBJECT(priv->folder_paned),
245                                    "modest-folder-paned");
246         modest_widget_memory_save (conf, G_OBJECT(priv->msg_paned),
247                                    "modest-msg-paned");
248         modest_widget_memory_save (conf, G_OBJECT(priv->main_paned),
249                                    "modest-main-paned");
250         modest_widget_memory_save (conf, G_OBJECT(self->header_view), "header-view");
251 }
252
253
254 static void
255 on_connection_changed (TnyDevice *device, gboolean online, ModestMainWindow *self)
256 {
257         GtkWidget *icon;
258         const gchar *icon_name;
259         ModestMainWindowPrivate *priv;
260         
261         g_return_if_fail (device);
262         g_return_if_fail (self);
263
264         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
265
266         icon_name = online ? GTK_STOCK_CONNECT : GTK_STOCK_DISCONNECT;
267         icon      = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
268
269         /* Block handlers in order to avoid unnecessary calls */
270         //g_signal_handler_block (G_OBJECT (priv->online_toggle), priv->toggle_button_signal);
271         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(priv->online_toggle), online);
272         //g_signal_handler_unblock (G_OBJECT (online_toggle), priv->toggle_button_signal);
273
274         gtk_button_set_image (GTK_BUTTON(priv->online_toggle), icon);
275         //statusbar_push (widget_factory, 0, online ? _("Modest went online") : _("Modest went offline"));
276         
277         /* If Modest has became online and the header view has a
278            header selected then show it */
279         /* FIXME: there is a race condition if some account needs to
280            ask the user for a password */
281
282 /*      if (online) { */
283 /*              GtkTreeSelection *selected; */
284
285 /*              selected = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view)); */
286 /*              _modest_header_view_change_selection (selected, header_view); */
287 /*      } */
288 }
289
290 void
291 on_online_toggle_toggled (GtkToggleButton *toggle, ModestMainWindow *self)
292 {
293         gboolean online;
294         TnyDevice *device;
295         ModestMainWindowPrivate *priv;
296
297         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
298
299         device = tny_account_store_get_device
300                 (TNY_ACCOUNT_STORE(modest_runtime_get_account_store()));
301
302         online  = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(priv->online_toggle));
303
304         if (online)
305                 tny_device_force_online (device);
306         else
307                 tny_device_force_offline (device);
308
309         g_object_unref (G_OBJECT (device));
310 }
311
312 static gboolean
313 on_delete_event (GtkWidget *widget, GdkEvent  *event, ModestMainWindow *self)
314 {
315         save_sizes (self);
316         return FALSE;
317 }
318
319 static void
320 on_destroy (GtkWidget *widget, GdkEvent  *event, ModestMainWindow *self)
321 {
322         gtk_main_quit();
323 }
324
325
326
327 static void
328 connect_signals (ModestMainWindow *self)
329 {       
330         ModestWindowPrivate *parent_priv;
331         ModestMainWindowPrivate *priv;
332         TnyDevice *device;
333         ModestTnyAccountStore *account_store;
334         
335         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
336         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
337
338         account_store = modest_runtime_get_account_store ();
339         device        = tny_account_store_get_device(TNY_ACCOUNT_STORE(account_store));
340         
341         /* folder view */
342         g_signal_connect (G_OBJECT(self->folder_view), "folder_selection_changed",
343                           G_CALLBACK(modest_ui_actions_on_folder_selection_changed), self);
344         g_signal_connect (G_OBJECT(self->folder_view), "folder_moved",
345                           G_CALLBACK(modest_ui_actions_on_folder_moved), NULL);
346         g_signal_connect (G_OBJECT(self->folder_view), "button-press-event",
347                           G_CALLBACK (on_folder_view_button_press_event),self);
348         g_signal_connect (self->folder_view,"popup-menu",
349                           G_CALLBACK (on_folder_view_button_press_event),self);
350
351         /* header view */
352         g_signal_connect (G_OBJECT(self->header_view), "status_update",
353                           G_CALLBACK(modest_ui_actions_on_header_status_update), self);
354         g_signal_connect (G_OBJECT(self->header_view), "header_selected",
355                           G_CALLBACK(modest_ui_actions_on_header_selected), self);
356         g_signal_connect (G_OBJECT(self->header_view), "header_activated",
357                           G_CALLBACK(modest_ui_actions_on_header_activated), self);
358         g_signal_connect (G_OBJECT(self->header_view), "item_not_found",
359                           G_CALLBACK(modest_ui_actions_on_item_not_found), self);
360         g_signal_connect (G_OBJECT(self->header_view), "button-press-event",
361                           G_CALLBACK (on_header_view_button_press_event), self);
362         g_signal_connect (G_OBJECT(self->header_view),"popup-menu",
363                           G_CALLBACK (on_header_view_button_press_event), self);
364                 
365         /* msg preview */
366         g_signal_connect (G_OBJECT(self->msg_preview), "link_clicked",
367                           G_CALLBACK(modest_ui_actions_on_msg_link_clicked), self);
368         g_signal_connect (G_OBJECT(self->msg_preview), "link_hover",
369                           G_CALLBACK(modest_ui_actions_on_msg_link_hover), self);
370         g_signal_connect (G_OBJECT(self->msg_preview), "attachment_clicked",
371                           G_CALLBACK(modest_ui_actions_on_msg_attachment_clicked), self);
372
373         /* Account store */
374         g_signal_connect (G_OBJECT (modest_runtime_get_account_store()), "accounts_reloaded",
375                           G_CALLBACK (modest_ui_actions_on_accounts_reloaded), self);
376         
377         /* Device */
378         g_signal_connect (G_OBJECT(device), "connection_changed",
379                           G_CALLBACK(on_connection_changed), self);
380         g_signal_connect (G_OBJECT(priv->online_toggle), "toggled",
381                           G_CALLBACK(on_online_toggle_toggled), NULL);
382         
383         /* window */
384         g_signal_connect (G_OBJECT(self), "destroy", G_CALLBACK(on_destroy), NULL);
385         g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
386 }
387
388
389 static GtkWidget*
390 wrapped_in_scrolled_window (GtkWidget *widget, gboolean needs_viewport)
391 {
392         GtkWidget *win;
393
394         win = gtk_scrolled_window_new (NULL, NULL);
395         gtk_scrolled_window_set_policy
396                 (GTK_SCROLLED_WINDOW (win),GTK_POLICY_NEVER,
397                  GTK_POLICY_AUTOMATIC);
398         
399         if (needs_viewport)
400                 gtk_scrolled_window_add_with_viewport
401                         (GTK_SCROLLED_WINDOW(win), widget);
402         else
403                 gtk_container_add (GTK_CONTAINER(win),
404                                    widget);
405
406         return win;
407 }
408
409
410
411
412 ModestWindow *
413 modest_main_window_new (void)
414 {
415         GObject *obj;
416         ModestMainWindow *self;
417         ModestMainWindowPrivate *priv;
418         ModestWindowPrivate *parent_priv;
419         GtkWidget *main_vbox;
420         GtkWidget *status_hbox;
421         GtkWidget *header_win, *folder_win;
422         GtkActionGroup *action_group;
423         GError *error = NULL;
424                 
425         obj  = g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL);
426         self = MODEST_MAIN_WINDOW(obj);
427         
428         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
429         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
430         
431         /* ***************** */
432         parent_priv->ui_manager = gtk_ui_manager_new();
433         action_group = gtk_action_group_new ("ModestMainWindowActions");
434         
435         /* Add common actions */
436         gtk_action_group_add_actions (action_group,
437                                       modest_action_entries,
438                                       G_N_ELEMENTS (modest_action_entries),
439                                       obj);
440
441         gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
442         g_object_unref (action_group);
443
444         /* Load the UI definition */
445         gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager,
446                                          MODEST_UIDIR "modest-main-window-ui.xml", &error);
447         if (error != NULL) {
448                 g_printerr ("modest: could not merge modest-main-window-ui.xml: %s", error->message);
449                 g_error_free (error);
450                 error = NULL;
451         }
452         /* *************** */
453
454         /* Add accelerators */
455         gtk_window_add_accel_group (GTK_WINDOW (obj), 
456                                     gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
457
458         /* Toolbar / Menubar */
459         parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
460         parent_priv->menubar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar");
461
462         gtk_toolbar_set_tooltips (GTK_TOOLBAR (parent_priv->toolbar), TRUE);    
463         folder_win = wrapped_in_scrolled_window (GTK_WIDGET(self->folder_view), FALSE);
464         header_win = wrapped_in_scrolled_window (GTK_WIDGET(self->header_view), FALSE);                    
465
466         /* paned */
467         priv->folder_paned = gtk_vpaned_new ();
468         priv->msg_paned = gtk_vpaned_new ();
469         priv->main_paned = gtk_hpaned_new ();
470         gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win);
471         gtk_paned_add2 (GTK_PANED(priv->main_paned), priv->msg_paned);
472         gtk_paned_add1 (GTK_PANED(priv->msg_paned), header_win);
473         gtk_paned_add2 (GTK_PANED(priv->msg_paned), GTK_WIDGET(self->msg_preview));
474
475         gtk_widget_show (GTK_WIDGET(self->header_view));
476         
477         /* status bar / progress */
478         status_hbox = gtk_hbox_new (FALSE, 0);
479         gtk_box_pack_start (GTK_BOX(status_hbox), priv->folder_info_label, FALSE,FALSE, 6);
480         gtk_box_pack_start (GTK_BOX(status_hbox), self->status_bar, TRUE, TRUE, 0);
481         gtk_box_pack_start (GTK_BOX(status_hbox), self->progress_bar,FALSE, FALSE, 0);
482         gtk_box_pack_start (GTK_BOX(status_hbox), priv->online_toggle,FALSE, FALSE, 0);
483
484         /* putting it all together... */
485         main_vbox = gtk_vbox_new (FALSE, 6);
486         gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->menubar, FALSE, FALSE, 0);
487         gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->toolbar, FALSE, FALSE, 0);
488         gtk_box_pack_start (GTK_BOX(main_vbox), priv->main_paned, TRUE, TRUE,0);
489         gtk_box_pack_start (GTK_BOX(main_vbox), status_hbox, FALSE, FALSE, 0);
490         
491         gtk_container_add (GTK_CONTAINER(obj), main_vbox);
492         restore_sizes (MODEST_MAIN_WINDOW(obj));        
493
494         gtk_window_set_title (GTK_WINDOW(obj), _("Modest"));
495         gtk_window_set_icon_from_file  (GTK_WINDOW(obj), MODEST_APP_ICON, NULL);        
496         gtk_widget_show_all (main_vbox);
497         
498         /* Init toggle in correct state */
499         //modest_ui_actions_on_connection_changed (device, tny_device_is_online (device), self);
500
501         connect_signals (MODEST_MAIN_WINDOW(obj));
502         return (ModestWindow *) obj;
503 }
504
505 static gboolean 
506 on_header_view_button_press_event (ModestHeaderView *header_view,
507                                    GdkEventButton   *event,
508                                    ModestMainWindow *self)
509 {
510         if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
511                 GtkWidget *menu;
512                 ModestWindowPrivate *parent_priv;
513         
514                 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
515                 menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/HeaderViewContextMenu");
516
517                 return show_context_popup_menu (self,
518                                                 GTK_TREE_VIEW (header_view), 
519                                                 event, 
520                                                 menu);
521         }
522
523         return FALSE;
524 }
525
526 static gboolean 
527 on_folder_view_button_press_event (ModestFolderView *folder_view,
528                                    GdkEventButton   *event,
529                                    ModestMainWindow *self)
530 {
531         if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
532                 GtkWidget *menu;
533                 ModestWindowPrivate *parent_priv;
534         
535                 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
536                 menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewContextMenu");
537
538                 return show_context_popup_menu (self,
539                                                 GTK_TREE_VIEW (folder_view), 
540                                                 event, 
541                                                 menu);
542         }
543
544         return FALSE;
545 }
546
547 static gboolean 
548 show_context_popup_menu (ModestMainWindow *window,
549                          GtkTreeView *tree_view,
550                          GdkEventButton   *event,                        
551                          GtkWidget *menu)
552 {
553         g_return_val_if_fail (menu, FALSE);
554
555         if (event != NULL) {
556                 /* Ensure that the header is selected */
557                 GtkTreeSelection *selection;
558
559                 selection = gtk_tree_view_get_selection (tree_view);
560         
561                 if (gtk_tree_selection_count_selected_rows (selection) <= 1) {
562                         GtkTreePath *path;
563                 
564                         /* Get tree path for row that was clicked */
565                         if (gtk_tree_view_get_path_at_pos (tree_view,
566                                                            (gint) event->x, 
567                                                            (gint) event->y,
568                                                            &path, 
569                                                            NULL, NULL, NULL)) {
570                                 gtk_tree_selection_unselect_all (selection);
571                                 gtk_tree_selection_select_path (selection, path);
572                                 gtk_tree_path_free (path);
573                         }
574                 }
575
576                 /* Show popup */
577                 if (gtk_tree_selection_count_selected_rows(selection) == 1)
578                         gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
579                                         NULL, NULL,
580                                         event->button, event->time);
581         }
582         return TRUE;
583 }