921b51087c2324bcbbdc9786f5d4024fcc201194
[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
320 static void
321 connect_signals (ModestMainWindow *self)
322 {       
323         ModestWindowPrivate *parent_priv;
324         ModestMainWindowPrivate *priv;
325         TnyDevice *device;
326         ModestTnyAccountStore *account_store;
327         
328         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
329         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
330
331         account_store = modest_runtime_get_account_store ();
332         device        = tny_account_store_get_device(TNY_ACCOUNT_STORE(account_store));
333         
334         /* folder view */
335         g_signal_connect (G_OBJECT(self->folder_view), "folder_selection_changed",
336                           G_CALLBACK(modest_ui_actions_on_folder_selection_changed), self);
337         g_signal_connect (G_OBJECT(self->folder_view), "folder_moved",
338                           G_CALLBACK(modest_ui_actions_on_folder_moved), NULL);
339         g_signal_connect (G_OBJECT(self->folder_view), "button-press-event",
340                           G_CALLBACK (on_folder_view_button_press_event),self);
341         g_signal_connect (self->folder_view,"popup-menu",
342                           G_CALLBACK (on_folder_view_button_press_event),self);
343
344         /* header view */
345         g_signal_connect (G_OBJECT(self->header_view), "status_update",
346                           G_CALLBACK(modest_ui_actions_on_header_status_update), self);
347         g_signal_connect (G_OBJECT(self->header_view), "header_selected",
348                           G_CALLBACK(modest_ui_actions_on_header_selected), self);
349         g_signal_connect (G_OBJECT(self->header_view), "header_activated",
350                           G_CALLBACK(modest_ui_actions_on_header_activated), self);
351         g_signal_connect (G_OBJECT(self->header_view), "item_not_found",
352                           G_CALLBACK(modest_ui_actions_on_item_not_found), self);
353         g_signal_connect (G_OBJECT(self->header_view), "button-press-event",
354                           G_CALLBACK (on_header_view_button_press_event), self);
355         g_signal_connect (G_OBJECT(self->header_view),"popup-menu",
356                           G_CALLBACK (on_header_view_button_press_event), self);
357                 
358         /* msg preview */
359         g_signal_connect (G_OBJECT(self->msg_preview), "link_clicked",
360                           G_CALLBACK(modest_ui_actions_on_msg_link_clicked), self);
361         g_signal_connect (G_OBJECT(self->msg_preview), "link_hover",
362                           G_CALLBACK(modest_ui_actions_on_msg_link_hover), self);
363         g_signal_connect (G_OBJECT(self->msg_preview), "attachment_clicked",
364                           G_CALLBACK(modest_ui_actions_on_msg_attachment_clicked), self);
365
366         /* Account store */
367         g_signal_connect (G_OBJECT (modest_runtime_get_account_store()), "accounts_reloaded",
368                           G_CALLBACK (modest_ui_actions_on_accounts_reloaded), self);
369         
370         /* Device */
371         g_signal_connect (G_OBJECT(device), "connection_changed",
372                           G_CALLBACK(on_connection_changed), self);
373         g_signal_connect (G_OBJECT(priv->online_toggle), "toggled",
374                           G_CALLBACK(on_online_toggle_toggled), NULL);
375         
376         /* window */
377         //g_signal_connect (G_OBJECT(self), "destroy", G_CALLBACK(on_main_window_destroy), NULL);
378         g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
379 }
380
381
382 static GtkWidget*
383 wrapped_in_scrolled_window (GtkWidget *widget, gboolean needs_viewport)
384 {
385         GtkWidget *win;
386
387         win = gtk_scrolled_window_new (NULL, NULL);
388         gtk_scrolled_window_set_policy
389                 (GTK_SCROLLED_WINDOW (win),GTK_POLICY_NEVER,
390                  GTK_POLICY_AUTOMATIC);
391         
392         if (needs_viewport)
393                 gtk_scrolled_window_add_with_viewport
394                         (GTK_SCROLLED_WINDOW(win), widget);
395         else
396                 gtk_container_add (GTK_CONTAINER(win),
397                                    widget);
398
399         return win;
400 }
401
402
403
404
405 ModestWindow *
406 modest_main_window_new (void)
407 {
408         GObject *obj;
409         ModestMainWindow *self;
410         ModestMainWindowPrivate *priv;
411         ModestWindowPrivate *parent_priv;
412         GtkWidget *main_vbox;
413         GtkWidget *status_hbox;
414         GtkWidget *header_win, *folder_win;
415         GtkActionGroup *action_group;
416         GError *error = NULL;
417                 
418         obj  = g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL);
419         self = MODEST_MAIN_WINDOW(obj);
420         
421         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
422         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
423         
424         /* ***************** */
425         parent_priv->ui_manager = gtk_ui_manager_new();
426         action_group = gtk_action_group_new ("ModestMainWindowActions");
427         
428         /* Add common actions */
429         gtk_action_group_add_actions (action_group,
430                                       modest_action_entries,
431                                       G_N_ELEMENTS (modest_action_entries),
432                                       obj);
433
434         gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
435         g_object_unref (action_group);
436
437         /* Load the UI definition */
438         gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager,
439                                          MODEST_UIDIR "modest-main-window-ui.xml", &error);
440         if (error != NULL) {
441                 g_printerr ("modest: could not merge modest-main-window-ui.xml: %s", error->message);
442                 g_error_free (error);
443                 error = NULL;
444         }
445         /* *************** */
446
447         /* Add accelerators */
448         gtk_window_add_accel_group (GTK_WINDOW (obj), 
449                                     gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
450
451         /* Toolbar / Menubar */
452         parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
453         parent_priv->menubar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar");
454
455         gtk_toolbar_set_tooltips (GTK_TOOLBAR (parent_priv->toolbar), TRUE);    
456         folder_win = wrapped_in_scrolled_window (GTK_WIDGET(self->folder_view), FALSE);
457         header_win = wrapped_in_scrolled_window (GTK_WIDGET(self->header_view), FALSE);                    
458
459         /* paned */
460         priv->folder_paned = gtk_vpaned_new ();
461         priv->msg_paned = gtk_vpaned_new ();
462         priv->main_paned = gtk_hpaned_new ();
463         gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win);
464         gtk_paned_add2 (GTK_PANED(priv->main_paned), priv->msg_paned);
465         gtk_paned_add1 (GTK_PANED(priv->msg_paned), header_win);
466         gtk_paned_add2 (GTK_PANED(priv->msg_paned), GTK_WIDGET(self->msg_preview));
467
468         gtk_widget_show (GTK_WIDGET(self->header_view));
469         
470         /* status bar / progress */
471         status_hbox = gtk_hbox_new (FALSE, 0);
472         gtk_box_pack_start (GTK_BOX(status_hbox), priv->folder_info_label, FALSE,FALSE, 6);
473         gtk_box_pack_start (GTK_BOX(status_hbox), self->status_bar, TRUE, TRUE, 0);
474         gtk_box_pack_start (GTK_BOX(status_hbox), self->progress_bar,FALSE, FALSE, 0);
475         gtk_box_pack_start (GTK_BOX(status_hbox), priv->online_toggle,FALSE, FALSE, 0);
476
477         /* putting it all together... */
478         main_vbox = gtk_vbox_new (FALSE, 6);
479         gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->menubar, FALSE, FALSE, 0);
480         gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->toolbar, FALSE, FALSE, 0);
481         gtk_box_pack_start (GTK_BOX(main_vbox), priv->main_paned, TRUE, TRUE,0);
482         gtk_box_pack_start (GTK_BOX(main_vbox), status_hbox, FALSE, FALSE, 0);
483         
484         gtk_container_add (GTK_CONTAINER(obj), main_vbox);
485         restore_sizes (MODEST_MAIN_WINDOW(obj));        
486
487         gtk_window_set_title (GTK_WINDOW(obj), _("Modest"));
488         gtk_window_set_icon_from_file  (GTK_WINDOW(obj), MODEST_APP_ICON, NULL);        
489         gtk_widget_show_all (main_vbox);
490         
491         /* Init toggle in correct state */
492         //modest_ui_actions_on_connection_changed (device, tny_device_is_online (device), self);
493
494         connect_signals (MODEST_MAIN_WINDOW(obj));
495         return (ModestWindow *) obj;
496 }
497
498 static gboolean 
499 on_header_view_button_press_event (ModestHeaderView *header_view,
500                                    GdkEventButton   *event,
501                                    ModestMainWindow *self)
502 {
503         if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
504                 GtkWidget *menu;
505                 ModestWindowPrivate *parent_priv;
506         
507                 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
508                 menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/HeaderViewContextMenu");
509
510                 return show_context_popup_menu (self,
511                                                 GTK_TREE_VIEW (header_view), 
512                                                 event, 
513                                                 menu);
514         }
515
516         return FALSE;
517 }
518
519 static gboolean 
520 on_folder_view_button_press_event (ModestFolderView *folder_view,
521                                    GdkEventButton   *event,
522                                    ModestMainWindow *self)
523 {
524         if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
525                 GtkWidget *menu;
526                 ModestWindowPrivate *parent_priv;
527         
528                 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
529                 menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewContextMenu");
530
531                 return show_context_popup_menu (self,
532                                                 GTK_TREE_VIEW (folder_view), 
533                                                 event, 
534                                                 menu);
535         }
536
537         return FALSE;
538 }
539
540 static gboolean 
541 show_context_popup_menu (ModestMainWindow *window,
542                          GtkTreeView *tree_view,
543                          GdkEventButton   *event,                        
544                          GtkWidget *menu)
545 {
546         g_return_val_if_fail (menu, FALSE);
547
548         if (event != NULL) {
549                 /* Ensure that the header is selected */
550                 GtkTreeSelection *selection;
551
552                 selection = gtk_tree_view_get_selection (tree_view);
553         
554                 if (gtk_tree_selection_count_selected_rows (selection) <= 1) {
555                         GtkTreePath *path;
556                 
557                         /* Get tree path for row that was clicked */
558                         if (gtk_tree_view_get_path_at_pos (tree_view,
559                                                            (gint) event->x, 
560                                                            (gint) event->y,
561                                                            &path, 
562                                                            NULL, NULL, NULL)) {
563                                 gtk_tree_selection_unselect_all (selection);
564                                 gtk_tree_selection_select_path (selection, path);
565                                 gtk_tree_path_free (path);
566                         }
567                 }
568
569                 /* Show popup */
570                 if (gtk_tree_selection_count_selected_rows(selection) == 1)
571                         gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
572                                         NULL, NULL,
573                                         event->button, event->time);
574         }
575         return TRUE;
576 }