1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /* e-shortcuts-view.c |
---|
3 | * |
---|
4 | * Copyright (C) 2000, 2001 Ximian, Inc. |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of version 2 of the GNU General Public |
---|
8 | * License as published by the Free Software Foundation. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | * General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public |
---|
16 | * License along with this program; if not, write to the |
---|
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
18 | * Boston, MA 02111-1307, USA. |
---|
19 | * |
---|
20 | * Author: Ettore Perazzoli |
---|
21 | */ |
---|
22 | |
---|
23 | #ifdef HAVE_CONFIG_H |
---|
24 | #include <config.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | #include "e-shortcuts-view.h" |
---|
28 | |
---|
29 | #include "e-folder-dnd-bridge.h" |
---|
30 | #include "e-shell-constants.h" |
---|
31 | #include "e-shortcuts-view-model.h" |
---|
32 | |
---|
33 | #include "e-util/e-request.h" |
---|
34 | |
---|
35 | #include <glib.h> |
---|
36 | #include <gtk/gtkcheckmenuitem.h> |
---|
37 | #include <gtk/gtkentry.h> |
---|
38 | #include <gtk/gtklabel.h> |
---|
39 | #include <libgnome/gnome-defs.h> |
---|
40 | #include <libgnome/gnome-i18n.h> |
---|
41 | #include <libgnomeui/gnome-app.h> |
---|
42 | #include <libgnomeui/gnome-app-helper.h> |
---|
43 | #include <libgnomeui/gnome-dialog.h> |
---|
44 | #include <libgnomeui/gnome-messagebox.h> |
---|
45 | #include <libgnomeui/gnome-popup-menu.h> |
---|
46 | #include <libgnomeui/gnome-stock.h> |
---|
47 | #include <libgnomeui/gnome-uidefs.h> |
---|
48 | #include <gal/util/e-util.h> |
---|
49 | #include <gal/widgets/e-unicode.h> |
---|
50 | |
---|
51 | |
---|
52 | #define PARENT_TYPE E_TYPE_SHORTCUT_BAR |
---|
53 | static EShortcutBarClass *parent_class = NULL; |
---|
54 | |
---|
55 | struct _EShortcutsViewPrivate { |
---|
56 | EShortcuts *shortcuts; |
---|
57 | }; |
---|
58 | |
---|
59 | enum { |
---|
60 | ACTIVATE_SHORTCUT, |
---|
61 | HIDE_REQUESTED, |
---|
62 | LAST_SIGNAL |
---|
63 | }; |
---|
64 | |
---|
65 | static guint signals[LAST_SIGNAL] = { 0 }; |
---|
66 | |
---|
67 | |
---|
68 | /* Utility functions. */ |
---|
69 | |
---|
70 | static void |
---|
71 | show_new_group_dialog (EShortcutsView *view) |
---|
72 | { |
---|
73 | char *group_name; |
---|
74 | |
---|
75 | group_name = e_request_string (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))), |
---|
76 | _("Create new shortcut group"), |
---|
77 | _("Group name:"), |
---|
78 | NULL); |
---|
79 | |
---|
80 | if (group_name == NULL) |
---|
81 | return; |
---|
82 | |
---|
83 | e_shortcuts_add_group (view->priv->shortcuts, -1, group_name); |
---|
84 | |
---|
85 | g_free (group_name); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | /* Shortcut bar right-click menu. */ |
---|
90 | |
---|
91 | struct _RightClickMenuData { |
---|
92 | EShortcutsView *shortcuts_view; |
---|
93 | int group_num; |
---|
94 | }; |
---|
95 | typedef struct _RightClickMenuData RightClickMenuData; |
---|
96 | |
---|
97 | static void |
---|
98 | toggle_large_icons_cb (GtkWidget *widget, |
---|
99 | void *data) |
---|
100 | { |
---|
101 | RightClickMenuData *menu_data; |
---|
102 | |
---|
103 | menu_data = (RightClickMenuData *) data; |
---|
104 | |
---|
105 | if (menu_data == NULL) |
---|
106 | return; |
---|
107 | |
---|
108 | if (! GTK_CHECK_MENU_ITEM (widget)->active) |
---|
109 | return; |
---|
110 | |
---|
111 | e_shortcuts_set_group_uses_small_icons (menu_data->shortcuts_view->priv->shortcuts, menu_data->group_num, FALSE); |
---|
112 | } |
---|
113 | |
---|
114 | static void |
---|
115 | toggle_small_icons_cb (GtkWidget *widget, |
---|
116 | void *data) |
---|
117 | { |
---|
118 | RightClickMenuData *menu_data; |
---|
119 | |
---|
120 | menu_data = (RightClickMenuData *) data; |
---|
121 | if (menu_data == NULL) |
---|
122 | return; |
---|
123 | |
---|
124 | if (! GTK_CHECK_MENU_ITEM (widget)->active) |
---|
125 | return; |
---|
126 | |
---|
127 | e_shortcuts_set_group_uses_small_icons (menu_data->shortcuts_view->priv->shortcuts, menu_data->group_num, TRUE); |
---|
128 | } |
---|
129 | |
---|
130 | static void |
---|
131 | hide_shortcut_bar_cb (GtkWidget *widget, |
---|
132 | void *data) |
---|
133 | { |
---|
134 | RightClickMenuData *menu_data; |
---|
135 | EShortcutsView *shortcut_view; |
---|
136 | |
---|
137 | menu_data = (RightClickMenuData *) data; |
---|
138 | |
---|
139 | shortcut_view = E_SHORTCUTS_VIEW (menu_data->shortcuts_view); |
---|
140 | |
---|
141 | gtk_signal_emit (GTK_OBJECT (shortcut_view), signals[HIDE_REQUESTED]); |
---|
142 | } |
---|
143 | |
---|
144 | static void |
---|
145 | create_new_group_cb (GtkWidget *widget, |
---|
146 | void *data) |
---|
147 | { |
---|
148 | RightClickMenuData *menu_data; |
---|
149 | |
---|
150 | menu_data = (RightClickMenuData *) data; |
---|
151 | |
---|
152 | show_new_group_dialog (menu_data->shortcuts_view); |
---|
153 | } |
---|
154 | |
---|
155 | static void |
---|
156 | destroy_group_cb (GtkWidget *widget, |
---|
157 | void *data) |
---|
158 | { |
---|
159 | RightClickMenuData *menu_data; |
---|
160 | EShortcuts *shortcuts; |
---|
161 | EShortcutsView *shortcuts_view; |
---|
162 | EShortcutsViewPrivate *priv; |
---|
163 | GtkWidget *message_box; |
---|
164 | char *question, *title; |
---|
165 | |
---|
166 | menu_data = (RightClickMenuData *) data; |
---|
167 | shortcuts_view = menu_data->shortcuts_view; |
---|
168 | priv = shortcuts_view->priv; |
---|
169 | shortcuts = priv->shortcuts; |
---|
170 | |
---|
171 | title = e_utf8_to_locale_string (e_shortcuts_get_group_title ( |
---|
172 | shortcuts, menu_data->group_num)); |
---|
173 | question = g_strdup_printf (_("Do you really want to remove group\n" |
---|
174 | "`%s' from the shortcut bar?"), title); |
---|
175 | g_free (title); |
---|
176 | |
---|
177 | message_box = gnome_message_box_new (question, GNOME_MESSAGE_BOX_QUESTION, |
---|
178 | _("Remove"), _("Don't remove"), NULL); |
---|
179 | gnome_dialog_set_parent (GNOME_DIALOG (message_box), |
---|
180 | GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (shortcuts_view)))); |
---|
181 | g_free (question); |
---|
182 | |
---|
183 | if (gnome_dialog_run_and_close (GNOME_DIALOG (message_box)) != 0) |
---|
184 | return; |
---|
185 | |
---|
186 | e_shortcuts_remove_group (shortcuts, menu_data->group_num); |
---|
187 | } |
---|
188 | |
---|
189 | static void |
---|
190 | rename_group_cb (GtkWidget *widget, |
---|
191 | void *data) |
---|
192 | { |
---|
193 | RightClickMenuData *menu_data; |
---|
194 | EShortcuts *shortcuts; |
---|
195 | EShortcutsView *shortcuts_view; |
---|
196 | EIconBarViewType original_view_type; |
---|
197 | const char *old_name; |
---|
198 | char *new_name; |
---|
199 | int group; |
---|
200 | |
---|
201 | menu_data = (RightClickMenuData *) data; |
---|
202 | shortcuts_view = menu_data->shortcuts_view; |
---|
203 | shortcuts = shortcuts_view->priv->shortcuts; |
---|
204 | |
---|
205 | old_name = e_shortcuts_get_group_title (shortcuts, menu_data->group_num); |
---|
206 | |
---|
207 | new_name = e_request_string (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (shortcuts_view))), |
---|
208 | _("Rename Shortcut Group"), |
---|
209 | _("Rename selected shortcut group to:"), |
---|
210 | old_name); |
---|
211 | |
---|
212 | if (new_name == NULL) |
---|
213 | return; |
---|
214 | |
---|
215 | /* Remember the group and flip back to it. FIXME: This is a workaround |
---|
216 | to an actual ShortcutBar bug. */ |
---|
217 | |
---|
218 | group = e_group_bar_get_current_group_num (E_GROUP_BAR (shortcuts_view)); |
---|
219 | original_view_type = e_shortcut_bar_get_view_type (E_SHORTCUT_BAR (menu_data->shortcuts_view), group); |
---|
220 | e_shortcuts_rename_group (shortcuts, menu_data->group_num, new_name); |
---|
221 | |
---|
222 | g_free (new_name); |
---|
223 | e_group_bar_set_current_group_num (E_GROUP_BAR (shortcuts_view), group, FALSE); |
---|
224 | e_shortcut_bar_set_view_type (E_SHORTCUT_BAR (menu_data->shortcuts_view), group, original_view_type); |
---|
225 | } |
---|
226 | |
---|
227 | static void |
---|
228 | create_default_shortcuts_cb (GtkWidget *widget, |
---|
229 | void *data) |
---|
230 | { |
---|
231 | RightClickMenuData *menu_data; |
---|
232 | EShortcutsView *shortcuts_view; |
---|
233 | |
---|
234 | menu_data = (RightClickMenuData *) data; |
---|
235 | shortcuts_view = menu_data->shortcuts_view; |
---|
236 | e_shortcuts_add_default_shortcuts (shortcuts_view->priv->shortcuts, |
---|
237 | e_group_bar_get_current_group_num (E_GROUP_BAR (shortcuts_view))); |
---|
238 | } |
---|
239 | |
---|
240 | static GnomeUIInfo icon_size_radio_group_uiinfo[] = { |
---|
241 | { GNOME_APP_UI_ITEM, N_("_Small Icons"), |
---|
242 | N_("Show the shortcuts as small icons"), toggle_small_icons_cb, NULL, |
---|
243 | NULL, 0, 0, 0, 0 }, |
---|
244 | { GNOME_APP_UI_ITEM, N_("_Large Icons"), |
---|
245 | N_("Show the shortcuts as large icons"), toggle_large_icons_cb, NULL, |
---|
246 | NULL, 0, 0, 0, 0 }, |
---|
247 | |
---|
248 | GNOMEUIINFO_END |
---|
249 | }; |
---|
250 | |
---|
251 | static GnomeUIInfo right_click_menu_uiinfo[] = { |
---|
252 | GNOMEUIINFO_RADIOLIST (icon_size_radio_group_uiinfo), |
---|
253 | |
---|
254 | GNOMEUIINFO_SEPARATOR, |
---|
255 | |
---|
256 | { GNOME_APP_UI_ITEM, N_("_New Group..."), |
---|
257 | N_("Create a new shortcut group"), create_new_group_cb, NULL, |
---|
258 | NULL, 0, 0, 0, 0 }, |
---|
259 | { GNOME_APP_UI_ITEM, N_("_Remove this Group..."), |
---|
260 | N_("Remove this shortcut group"), destroy_group_cb, NULL, |
---|
261 | NULL, 0, 0, 0, 0 }, |
---|
262 | { GNOME_APP_UI_ITEM, N_("Re_name this Group..."), |
---|
263 | N_("Rename this shortcut group"), rename_group_cb, NULL, |
---|
264 | NULL, 0, 0, 0, 0 }, |
---|
265 | |
---|
266 | GNOMEUIINFO_SEPARATOR, |
---|
267 | |
---|
268 | { GNOME_APP_UI_ITEM, N_("_Hide the Shortcut Bar"), |
---|
269 | N_("Hide the shortcut bar"), hide_shortcut_bar_cb, NULL, |
---|
270 | NULL, 0, 0, 0, 0 }, |
---|
271 | |
---|
272 | GNOMEUIINFO_SEPARATOR, |
---|
273 | |
---|
274 | { GNOME_APP_UI_ITEM, N_("Create _Default Shortcuts"), |
---|
275 | N_("Create Default Shortcuts"), create_default_shortcuts_cb, NULL, |
---|
276 | NULL, 0, 0, 0, 0 }, |
---|
277 | |
---|
278 | GNOMEUIINFO_END |
---|
279 | }; |
---|
280 | |
---|
281 | static void |
---|
282 | pop_up_right_click_menu_for_group (EShortcutsView *shortcuts_view, |
---|
283 | GdkEventButton *event, |
---|
284 | int group_num) |
---|
285 | { |
---|
286 | RightClickMenuData *menu_data; |
---|
287 | GtkWidget *popup_menu; |
---|
288 | |
---|
289 | menu_data = g_new (RightClickMenuData, 1); |
---|
290 | menu_data->shortcuts_view = shortcuts_view; |
---|
291 | menu_data->group_num = group_num; |
---|
292 | |
---|
293 | popup_menu = gnome_popup_menu_new (right_click_menu_uiinfo); |
---|
294 | |
---|
295 | if (e_shortcut_bar_get_view_type (E_SHORTCUT_BAR (shortcuts_view), group_num) |
---|
296 | == E_ICON_BAR_SMALL_ICONS) |
---|
297 | gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (icon_size_radio_group_uiinfo[0].widget), |
---|
298 | TRUE); |
---|
299 | else |
---|
300 | gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (icon_size_radio_group_uiinfo[1].widget), |
---|
301 | TRUE); |
---|
302 | |
---|
303 | if (group_num == 0) |
---|
304 | gtk_widget_set_sensitive (right_click_menu_uiinfo[3].widget, FALSE); |
---|
305 | |
---|
306 | gnome_popup_menu_do_popup_modal (popup_menu, NULL, NULL, event, menu_data); |
---|
307 | |
---|
308 | g_free (menu_data); |
---|
309 | gtk_widget_unref (popup_menu); |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | /* Data to be passed around for the shortcut right-click menu items. */ |
---|
314 | |
---|
315 | struct _ShortcutRightClickMenuData { |
---|
316 | EShortcutsView *shortcuts_view; |
---|
317 | int group_num; |
---|
318 | int item_num; |
---|
319 | }; |
---|
320 | typedef struct _ShortcutRightClickMenuData ShortcutRightClickMenuData; |
---|
321 | |
---|
322 | |
---|
323 | /* "Open Shortcut" and "Open Shortcut in New Window" commands. */ |
---|
324 | |
---|
325 | static void |
---|
326 | open_shortcut_helper (ShortcutRightClickMenuData *menu_data, |
---|
327 | gboolean in_new_window) |
---|
328 | { |
---|
329 | EShortcutsView *shortcuts_view; |
---|
330 | EShortcuts *shortcuts; |
---|
331 | const EShortcutItem *shortcut_item; |
---|
332 | |
---|
333 | shortcuts_view = menu_data->shortcuts_view; |
---|
334 | shortcuts = shortcuts_view->priv->shortcuts; |
---|
335 | |
---|
336 | shortcut_item = e_shortcuts_get_shortcut (shortcuts, menu_data->group_num, menu_data->item_num); |
---|
337 | if (shortcut_item == NULL) |
---|
338 | return; |
---|
339 | |
---|
340 | gtk_signal_emit (GTK_OBJECT (shortcuts_view), signals[ACTIVATE_SHORTCUT], |
---|
341 | shortcuts, shortcut_item->uri, in_new_window); |
---|
342 | } |
---|
343 | |
---|
344 | static void |
---|
345 | open_shortcut_cb (GtkWidget *widget, |
---|
346 | void *data) |
---|
347 | { |
---|
348 | open_shortcut_helper ((ShortcutRightClickMenuData *) data, FALSE); |
---|
349 | } |
---|
350 | |
---|
351 | static void |
---|
352 | open_shortcut_in_new_window_cb (GtkWidget *widget, |
---|
353 | void *data) |
---|
354 | { |
---|
355 | open_shortcut_helper ((ShortcutRightClickMenuData *) data, TRUE); |
---|
356 | } |
---|
357 | |
---|
358 | |
---|
359 | static void |
---|
360 | remove_shortcut_cb (GtkWidget *widget, |
---|
361 | void *data) |
---|
362 | { |
---|
363 | ShortcutRightClickMenuData *menu_data; |
---|
364 | EShortcutsView *shortcuts_view; |
---|
365 | EShortcuts *shortcuts; |
---|
366 | |
---|
367 | menu_data = (ShortcutRightClickMenuData *) data; |
---|
368 | shortcuts_view = menu_data->shortcuts_view; |
---|
369 | shortcuts = shortcuts_view->priv->shortcuts; |
---|
370 | |
---|
371 | e_shortcuts_remove_shortcut (shortcuts, menu_data->group_num, menu_data->item_num); |
---|
372 | } |
---|
373 | |
---|
374 | |
---|
375 | /* "Rename Shortcut" command. */ |
---|
376 | |
---|
377 | static void |
---|
378 | rename_shortcut_cb (GtkWidget *widget, |
---|
379 | void *data) |
---|
380 | { |
---|
381 | ShortcutRightClickMenuData *menu_data; |
---|
382 | EShortcutsView *shortcuts_view; |
---|
383 | EShortcuts *shortcuts; |
---|
384 | const EShortcutItem *shortcut_item; |
---|
385 | char *new_name; |
---|
386 | |
---|
387 | menu_data = (ShortcutRightClickMenuData *) data; |
---|
388 | shortcuts_view = menu_data->shortcuts_view; |
---|
389 | shortcuts = shortcuts_view->priv->shortcuts; |
---|
390 | |
---|
391 | shortcut_item = e_shortcuts_get_shortcut (shortcuts, menu_data->group_num, menu_data->item_num); |
---|
392 | |
---|
393 | new_name = e_request_string (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (shortcuts_view))), |
---|
394 | _("Rename shortcut"), |
---|
395 | _("Rename selected shortcut to:"), |
---|
396 | shortcut_item->name); |
---|
397 | |
---|
398 | if (new_name == NULL) |
---|
399 | return; |
---|
400 | |
---|
401 | e_shortcuts_update_shortcut (shortcuts, menu_data->group_num, menu_data->item_num, |
---|
402 | shortcut_item->uri, new_name, shortcut_item->unread_count, |
---|
403 | shortcut_item->type, shortcut_item->custom_icon_name); |
---|
404 | g_free (new_name); |
---|
405 | } |
---|
406 | |
---|
407 | static GnomeUIInfo shortcut_right_click_menu_uiinfo[] = { |
---|
408 | GNOMEUIINFO_ITEM_STOCK (N_("_Open"), N_("Open the folder linked to this shortcut"), |
---|
409 | open_shortcut_cb, GNOME_STOCK_MENU_OPEN), |
---|
410 | GNOMEUIINFO_ITEM_NONE (N_("Open in New _Window"), N_("Open the folder linked to this shortcut in a new window"), |
---|
411 | open_shortcut_in_new_window_cb), |
---|
412 | GNOMEUIINFO_SEPARATOR, |
---|
413 | GNOMEUIINFO_ITEM_NONE (N_("_Rename"), N_("Rename this shortcut"), |
---|
414 | rename_shortcut_cb), |
---|
415 | GNOMEUIINFO_ITEM_STOCK (N_("Re_move"), N_("Remove this shortcut from the shortcut bar"), |
---|
416 | remove_shortcut_cb, GNOME_STOCK_MENU_TRASH), |
---|
417 | GNOMEUIINFO_END |
---|
418 | }; |
---|
419 | |
---|
420 | static void |
---|
421 | pop_up_right_click_menu_for_shortcut (EShortcutsView *shortcuts_view, |
---|
422 | GdkEventButton *event, |
---|
423 | int group_num, |
---|
424 | int item_num) |
---|
425 | { |
---|
426 | ShortcutRightClickMenuData *menu_data; |
---|
427 | GtkWidget *popup_menu; |
---|
428 | |
---|
429 | menu_data = g_new (ShortcutRightClickMenuData, 1); |
---|
430 | menu_data->shortcuts_view = shortcuts_view; |
---|
431 | menu_data->group_num = group_num; |
---|
432 | menu_data->item_num = item_num; |
---|
433 | |
---|
434 | popup_menu = gnome_popup_menu_new (shortcut_right_click_menu_uiinfo); |
---|
435 | |
---|
436 | gnome_popup_menu_do_popup_modal (popup_menu, NULL, NULL, event, menu_data); |
---|
437 | |
---|
438 | g_free (menu_data); |
---|
439 | gtk_widget_destroy (popup_menu); |
---|
440 | } |
---|
441 | |
---|
442 | |
---|
443 | /* View callbacks. This part exists mostly because of breakage in the |
---|
444 | EShortcutBar design. */ |
---|
445 | |
---|
446 | static void |
---|
447 | group_change_icon_size_callback (EShortcuts *shortucts, |
---|
448 | int group_num, |
---|
449 | gboolean use_small_icons, |
---|
450 | void *data) |
---|
451 | { |
---|
452 | EShortcutsView *view; |
---|
453 | |
---|
454 | view = E_SHORTCUTS_VIEW (data); |
---|
455 | |
---|
456 | if (use_small_icons) |
---|
457 | e_shortcut_bar_set_view_type (E_SHORTCUT_BAR (view), group_num, E_ICON_BAR_SMALL_ICONS); |
---|
458 | else |
---|
459 | e_shortcut_bar_set_view_type (E_SHORTCUT_BAR (view), group_num, E_ICON_BAR_LARGE_ICONS); |
---|
460 | } |
---|
461 | |
---|
462 | |
---|
463 | /* GtkObject methods. */ |
---|
464 | |
---|
465 | static void |
---|
466 | destroy (GtkObject *object) |
---|
467 | { |
---|
468 | EShortcutsViewPrivate *priv; |
---|
469 | EShortcutsView *shortcuts_view; |
---|
470 | |
---|
471 | shortcuts_view = E_SHORTCUTS_VIEW (object); |
---|
472 | |
---|
473 | priv = shortcuts_view->priv; |
---|
474 | |
---|
475 | gtk_object_unref (GTK_OBJECT (priv->shortcuts)); |
---|
476 | |
---|
477 | g_free (priv); |
---|
478 | |
---|
479 | (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); |
---|
480 | } |
---|
481 | |
---|
482 | |
---|
483 | /* EShortcutBar methods. */ |
---|
484 | |
---|
485 | static void |
---|
486 | item_selected (EShortcutBar *shortcut_bar, |
---|
487 | GdkEvent *event, |
---|
488 | int group_num, |
---|
489 | int item_num) |
---|
490 | { |
---|
491 | EShortcuts *shortcuts; |
---|
492 | EShortcutsView *shortcuts_view; |
---|
493 | const EShortcutItem *shortcut_item; |
---|
494 | |
---|
495 | shortcuts_view = E_SHORTCUTS_VIEW (shortcut_bar); |
---|
496 | shortcuts = shortcuts_view->priv->shortcuts; |
---|
497 | |
---|
498 | if (event->button.button == 3) { |
---|
499 | if (item_num < 0) |
---|
500 | pop_up_right_click_menu_for_group (shortcuts_view, &event->button, |
---|
501 | group_num); |
---|
502 | else |
---|
503 | pop_up_right_click_menu_for_shortcut (shortcuts_view, &event->button, |
---|
504 | group_num, item_num); |
---|
505 | return; |
---|
506 | } else if (event->button.button != 1) { |
---|
507 | return; |
---|
508 | } |
---|
509 | |
---|
510 | if (item_num < 0) |
---|
511 | return; |
---|
512 | |
---|
513 | shortcut_item = e_shortcuts_get_shortcut (shortcuts, group_num, item_num); |
---|
514 | if (shortcut_item == NULL) |
---|
515 | return; |
---|
516 | |
---|
517 | gtk_signal_emit (GTK_OBJECT (shortcuts_view), signals[ACTIVATE_SHORTCUT], |
---|
518 | shortcuts, shortcut_item->uri, FALSE); |
---|
519 | } |
---|
520 | |
---|
521 | static void |
---|
522 | get_shortcut_info (EShortcutsView *shortcuts_view, |
---|
523 | const char *item_uri, |
---|
524 | int *unread_count_return, |
---|
525 | const char **type_return, |
---|
526 | const char **custom_icon_name_return) |
---|
527 | { |
---|
528 | EShortcutsViewPrivate *priv; |
---|
529 | EStorageSet *storage_set; |
---|
530 | EFolder *folder; |
---|
531 | EShell *shell; |
---|
532 | char *path; |
---|
533 | |
---|
534 | priv = shortcuts_view->priv; |
---|
535 | |
---|
536 | shell = e_shortcuts_get_shell (priv->shortcuts); |
---|
537 | |
---|
538 | if (! e_shell_parse_uri (shell, item_uri, &path, NULL)) { |
---|
539 | *unread_count_return = 0; |
---|
540 | *type_return = NULL; |
---|
541 | *custom_icon_name_return = NULL; |
---|
542 | return; |
---|
543 | } |
---|
544 | |
---|
545 | storage_set = e_shell_get_storage_set (shell); |
---|
546 | |
---|
547 | folder = e_storage_set_get_folder (storage_set, path); |
---|
548 | if (folder != NULL) { |
---|
549 | *unread_count_return = e_folder_get_unread_count (folder); |
---|
550 | *type_return = e_folder_get_type_string (folder); |
---|
551 | *custom_icon_name_return = e_folder_get_custom_icon_name (folder); |
---|
552 | } else { |
---|
553 | *unread_count_return = 0; |
---|
554 | *type_return = NULL; |
---|
555 | *custom_icon_name_return = NULL; |
---|
556 | } |
---|
557 | |
---|
558 | g_free (path); |
---|
559 | } |
---|
560 | |
---|
561 | static void |
---|
562 | impl_shortcut_dropped (EShortcutBar *shortcut_bar, |
---|
563 | int group_num, |
---|
564 | int position, |
---|
565 | const char *item_url, |
---|
566 | const char *item_name) |
---|
567 | { |
---|
568 | EShortcutsView *shortcuts_view; |
---|
569 | EShortcutsViewPrivate *priv; |
---|
570 | int unread_count; |
---|
571 | const char *type; |
---|
572 | const char *custom_icon_name; |
---|
573 | char *tmp; |
---|
574 | char *tp; |
---|
575 | char *name_without_unread; |
---|
576 | |
---|
577 | shortcuts_view = E_SHORTCUTS_VIEW (shortcut_bar); |
---|
578 | priv = shortcuts_view->priv; |
---|
579 | |
---|
580 | get_shortcut_info (shortcuts_view, item_url, &unread_count, &type, &custom_icon_name); |
---|
581 | |
---|
582 | /* Looks funny, but keeps it from adding the unread count |
---|
583 | repeatedly when dragging folders around */ |
---|
584 | tmp = g_strdup_printf (" (%d)", unread_count); |
---|
585 | if ((tp = strstr (item_name, tmp)) != NULL) |
---|
586 | name_without_unread = g_strndup (item_name, strlen (item_name) - strlen (tp)); |
---|
587 | else |
---|
588 | name_without_unread = g_strdup (item_name); |
---|
589 | |
---|
590 | e_shortcuts_add_shortcut (priv->shortcuts, |
---|
591 | group_num, position, |
---|
592 | item_url, |
---|
593 | name_without_unread, |
---|
594 | unread_count, |
---|
595 | type, |
---|
596 | custom_icon_name); |
---|
597 | |
---|
598 | g_free (tmp); |
---|
599 | g_free (name_without_unread); |
---|
600 | } |
---|
601 | |
---|
602 | static void |
---|
603 | impl_shortcut_dragged (EShortcutBar *shortcut_bar, |
---|
604 | gint group_num, |
---|
605 | gint item_num) |
---|
606 | { |
---|
607 | EShortcutsView *shortcuts_view; |
---|
608 | EShortcutsViewPrivate *priv; |
---|
609 | |
---|
610 | shortcuts_view = E_SHORTCUTS_VIEW (shortcut_bar); |
---|
611 | priv = shortcuts_view->priv; |
---|
612 | |
---|
613 | e_shortcuts_remove_shortcut (priv->shortcuts, group_num, item_num); |
---|
614 | } |
---|
615 | |
---|
616 | static gboolean |
---|
617 | impl_shortcut_drag_motion (EShortcutBar *shortcut_bar, |
---|
618 | GtkWidget *widget, |
---|
619 | GdkDragContext *context, |
---|
620 | guint time, |
---|
621 | gint group_num, |
---|
622 | gint item_num) |
---|
623 | { |
---|
624 | EShortcutsView *view; |
---|
625 | EShortcutsViewPrivate *priv; |
---|
626 | const EShortcutItem *shortcut; |
---|
627 | |
---|
628 | view = E_SHORTCUTS_VIEW (shortcut_bar); |
---|
629 | priv = view->priv; |
---|
630 | |
---|
631 | shortcut = e_shortcuts_get_shortcut (priv->shortcuts, group_num, item_num); |
---|
632 | if (shortcut == NULL) |
---|
633 | return FALSE; |
---|
634 | if (strncmp (shortcut->uri, E_SHELL_URI_PREFIX, E_SHELL_URI_PREFIX_LEN) != 0) |
---|
635 | return FALSE; |
---|
636 | |
---|
637 | if (! e_folder_dnd_bridge_motion (widget, context, time, |
---|
638 | e_shell_get_storage_set (e_shortcuts_get_shell (priv->shortcuts)), |
---|
639 | shortcut->uri + E_SHELL_URI_PREFIX_LEN)) |
---|
640 | gdk_drag_status (context, 0, time); |
---|
641 | |
---|
642 | return TRUE; |
---|
643 | } |
---|
644 | |
---|
645 | static gboolean |
---|
646 | impl_shortcut_drag_data_received (EShortcutBar *shortcut_bar, |
---|
647 | GtkWidget *widget, |
---|
648 | GdkDragContext *context, |
---|
649 | GtkSelectionData *selection_data, |
---|
650 | guint time, |
---|
651 | gint group_num, |
---|
652 | gint item_num) |
---|
653 | { |
---|
654 | EShortcutsView *view; |
---|
655 | EShortcutsViewPrivate *priv; |
---|
656 | const EShortcutItem *shortcut; |
---|
657 | |
---|
658 | view = E_SHORTCUTS_VIEW (shortcut_bar); |
---|
659 | priv = view->priv; |
---|
660 | |
---|
661 | shortcut = e_shortcuts_get_shortcut (priv->shortcuts, group_num, item_num); |
---|
662 | if (shortcut == NULL) |
---|
663 | return FALSE; |
---|
664 | if (strncmp (shortcut->uri, E_SHELL_URI_PREFIX, E_SHELL_URI_PREFIX_LEN) != 0) |
---|
665 | return FALSE; |
---|
666 | |
---|
667 | e_folder_dnd_bridge_data_received (widget, context, selection_data, time, |
---|
668 | e_shell_get_storage_set (e_shortcuts_get_shell (priv->shortcuts)), |
---|
669 | shortcut->uri + E_SHELL_URI_PREFIX_LEN); |
---|
670 | return TRUE; |
---|
671 | } |
---|
672 | |
---|
673 | |
---|
674 | static void |
---|
675 | class_init (EShortcutsViewClass *klass) |
---|
676 | { |
---|
677 | GtkObjectClass *object_class; |
---|
678 | EShortcutBarClass *shortcut_bar_class; |
---|
679 | |
---|
680 | object_class = GTK_OBJECT_CLASS (klass); |
---|
681 | object_class->destroy = destroy; |
---|
682 | |
---|
683 | shortcut_bar_class = E_SHORTCUT_BAR_CLASS (klass); |
---|
684 | shortcut_bar_class->item_selected = item_selected; |
---|
685 | shortcut_bar_class->shortcut_dropped = impl_shortcut_dropped; |
---|
686 | shortcut_bar_class->shortcut_dragged = impl_shortcut_dragged; |
---|
687 | shortcut_bar_class->shortcut_drag_motion = impl_shortcut_drag_motion; |
---|
688 | shortcut_bar_class->shortcut_drag_data_received = impl_shortcut_drag_data_received; |
---|
689 | |
---|
690 | parent_class = gtk_type_class (e_shortcut_bar_get_type ()); |
---|
691 | |
---|
692 | signals[ACTIVATE_SHORTCUT] = |
---|
693 | gtk_signal_new ("activate_shortcut", |
---|
694 | GTK_RUN_LAST | GTK_RUN_ACTION, |
---|
695 | object_class->type, |
---|
696 | GTK_SIGNAL_OFFSET (EShortcutsViewClass, activate_shortcut), |
---|
697 | e_marshal_NONE__POINTER_POINTER_INT, |
---|
698 | GTK_TYPE_NONE, 3, |
---|
699 | GTK_TYPE_POINTER, |
---|
700 | GTK_TYPE_STRING, |
---|
701 | GTK_TYPE_BOOL); |
---|
702 | |
---|
703 | signals[HIDE_REQUESTED] = |
---|
704 | gtk_signal_new ("hide_requested", |
---|
705 | GTK_RUN_LAST, |
---|
706 | object_class->type, |
---|
707 | GTK_SIGNAL_OFFSET (EShortcutsViewClass, |
---|
708 | hide_requested), |
---|
709 | gtk_marshal_NONE__NONE, |
---|
710 | GTK_TYPE_NONE, 0); |
---|
711 | |
---|
712 | gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); |
---|
713 | } |
---|
714 | |
---|
715 | static void |
---|
716 | init (EShortcutsView *shortcuts_view) |
---|
717 | { |
---|
718 | EShortcutsViewPrivate *priv; |
---|
719 | |
---|
720 | priv = g_new (EShortcutsViewPrivate, 1); |
---|
721 | priv->shortcuts = NULL; |
---|
722 | |
---|
723 | shortcuts_view->priv = priv; |
---|
724 | } |
---|
725 | |
---|
726 | |
---|
727 | void |
---|
728 | e_shortcuts_view_construct (EShortcutsView *shortcuts_view, |
---|
729 | EShortcuts *shortcuts) |
---|
730 | { |
---|
731 | EShortcutsViewPrivate *priv; |
---|
732 | int i, num_groups; |
---|
733 | |
---|
734 | g_return_if_fail (shortcuts != NULL); |
---|
735 | g_return_if_fail (E_IS_SHORTCUTS (shortcuts)); |
---|
736 | |
---|
737 | priv = shortcuts_view->priv; |
---|
738 | |
---|
739 | priv->shortcuts = shortcuts; |
---|
740 | gtk_object_ref (GTK_OBJECT (priv->shortcuts)); |
---|
741 | |
---|
742 | e_shortcut_bar_set_model (E_SHORTCUT_BAR (shortcuts_view), |
---|
743 | E_SHORTCUT_MODEL (e_shortcuts_view_model_new (shortcuts))); |
---|
744 | |
---|
745 | gtk_signal_connect_while_alive (GTK_OBJECT (shortcuts), "group_change_icon_size", |
---|
746 | GTK_SIGNAL_FUNC (group_change_icon_size_callback), |
---|
747 | shortcuts_view, GTK_OBJECT (shortcuts_view)); |
---|
748 | |
---|
749 | num_groups = e_shortcuts_get_num_groups (shortcuts); |
---|
750 | for (i = 0; i < num_groups; i ++) { |
---|
751 | if (e_shortcuts_get_group_uses_small_icons (shortcuts, i)) |
---|
752 | e_shortcut_bar_set_view_type (E_SHORTCUT_BAR (shortcuts_view), i, E_ICON_BAR_SMALL_ICONS); |
---|
753 | else |
---|
754 | e_shortcut_bar_set_view_type (E_SHORTCUT_BAR (shortcuts_view), i, E_ICON_BAR_LARGE_ICONS); |
---|
755 | } |
---|
756 | } |
---|
757 | |
---|
758 | GtkWidget * |
---|
759 | e_shortcuts_view_new (EShortcuts *shortcuts) |
---|
760 | { |
---|
761 | GtkWidget *new; |
---|
762 | |
---|
763 | g_return_val_if_fail (shortcuts != NULL, NULL); |
---|
764 | g_return_val_if_fail (E_IS_SHORTCUTS (shortcuts), NULL); |
---|
765 | |
---|
766 | new = gtk_type_new (e_shortcuts_view_get_type ()); |
---|
767 | e_shortcuts_view_construct (E_SHORTCUTS_VIEW (new), shortcuts); |
---|
768 | |
---|
769 | return new; |
---|
770 | } |
---|
771 | |
---|
772 | |
---|
773 | E_MAKE_TYPE (e_shortcuts_view, "EShortcutsView", EShortcutsView, class_init, init, PARENT_TYPE) |
---|