1.2.47
by Didier Roche
Import upstream version 2.25.3 |
1 |
/*
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
5 |
* (at your option) any later version.
|
|
6 |
*
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
* GNU General Public License for more details.
|
|
11 |
*
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
13 |
* along with this program; if not, write to the Free Software
|
|
14 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
15 |
*
|
|
16 |
* The Totem project hereby grant permission for non-gpl compatible GStreamer
|
|
17 |
* plugins to be used and distributed together with GStreamer and Totem. This
|
|
18 |
* permission are above and beyond the permissions granted by the GPL license
|
|
19 |
* Totem is covered by.
|
|
20 |
*/
|
|
21 |
||
22 |
#include "config.h" |
|
23 |
||
24 |
#include <glib/gi18n.h> |
|
25 |
#include <gtk/gtk.h> |
|
26 |
#include <glib.h> |
|
27 |
#include <gdk/gdkkeysyms.h> |
|
28 |
||
29 |
#include "totem-dnd-menu.h" |
|
30 |
||
31 |
typedef struct |
|
32 |
{
|
|
33 |
GMainLoop *loop; |
|
34 |
GdkDragAction ch; |
|
35 |
} DragData; |
|
36 |
||
37 |
static void |
|
38 |
drag_menu_deactivate_callback (GtkWidget *menu, |
|
39 |
DragData *dt) |
|
40 |
{
|
|
41 |
dt->ch = GDK_ACTION_DEFAULT; |
|
42 |
if (g_main_loop_is_running (dt->loop)) |
|
43 |
g_main_loop_quit (dt->loop); |
|
44 |
}
|
|
45 |
||
46 |
static void |
|
47 |
drag_drop_action_activated_callback (GtkWidget *menu_item, |
|
48 |
DragData *dt) |
|
49 |
{
|
|
50 |
dt->ch = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "action")); |
|
51 |
if (g_main_loop_is_running (dt->loop)) |
|
52 |
g_main_loop_quit (dt->loop); |
|
53 |
}
|
|
54 |
||
55 |
static void |
|
56 |
drag_append_drop_action_menu_item (GtkWidget *menu, |
|
57 |
const char *text, |
|
58 |
const char *icon, |
|
59 |
GdkDragAction action, |
|
60 |
DragData *dt) |
|
61 |
{
|
|
62 |
GtkWidget *menu_item; |
|
63 |
||
64 |
menu_item = gtk_image_menu_item_new_with_mnemonic (text); |
|
65 |
gtk_widget_set_sensitive (menu_item, TRUE); |
|
66 |
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); |
|
67 |
||
68 |
if (icon != NULL) { |
|
69 |
GtkWidget *image; |
|
70 |
||
71 |
image = gtk_image_new_from_stock (icon, GTK_ICON_SIZE_MENU); |
|
72 |
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image); |
|
73 |
}
|
|
74 |
||
75 |
g_object_set_data (G_OBJECT (menu_item), "action", GINT_TO_POINTER (action)); |
|
76 |
||
77 |
g_signal_connect (menu_item, "activate", |
|
78 |
G_CALLBACK (drag_drop_action_activated_callback), dt); |
|
79 |
||
80 |
gtk_widget_show (menu_item); |
|
81 |
}
|
|
82 |
||
83 |
GdkDragAction
|
|
84 |
totem_drag_ask (gboolean show_add_to) |
|
85 |
{
|
|
86 |
GtkWidget *menu; |
|
87 |
GtkWidget *menu_item; |
|
88 |
DragData dt; |
|
89 |
||
90 |
dt.ch = 0; |
|
91 |
||
92 |
menu = gtk_menu_new (); |
|
93 |
||
1.4.6
by Raphaël Hertzog
Import upstream version 3.0.0 |
94 |
drag_append_drop_action_menu_item (menu, _("_Play Now"), "media-playback-start-symbolic", GDK_ACTION_MOVE, &dt); |
1.2.47
by Didier Roche
Import upstream version 2.25.3 |
95 |
|
96 |
if (show_add_to != FALSE) |
|
97 |
drag_append_drop_action_menu_item (menu, _("_Add to Playlist"), "gtk-add", GDK_ACTION_COPY, &dt); |
|
98 |
||
99 |
menu_item = gtk_separator_menu_item_new (); |
|
100 |
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); |
|
101 |
gtk_widget_show (menu_item); |
|
102 |
||
103 |
drag_append_drop_action_menu_item (menu, _("Cancel"), NULL, GDK_ACTION_DEFAULT, &dt); |
|
104 |
||
105 |
g_signal_connect (menu, "deactivate", |
|
106 |
G_CALLBACK (drag_menu_deactivate_callback), &dt); |
|
107 |
||
108 |
gtk_grab_add (menu); |
|
109 |
||
110 |
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, |
|
111 |
3, gtk_get_current_event_time ()); |
|
112 |
||
113 |
dt.loop = g_main_loop_new (NULL, FALSE); |
|
114 |
g_main_loop_run (dt.loop); |
|
115 |
gtk_grab_remove (menu); |
|
116 |
g_main_loop_unref (dt.loop); |
|
117 |
||
118 |
gtk_widget_destroy (menu); |
|
119 |
||
120 |
return dt.ch; |
|
121 |
}
|