~ubuntu-branches/ubuntu/saucy/totem/saucy-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
 *
 * The Totem project hereby grant permission for non-gpl compatible GStreamer
 * plugins to be used and distributed together with GStreamer and Totem. This
 * permission are above and beyond the permissions granted by the GPL license
 * Totem is covered by.
 */

#include "config.h"

#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gdk/gdkkeysyms.h>

#include "totem-dnd-menu.h"

typedef struct
{
	GMainLoop *loop;
	GdkDragAction ch;
} DragData;

static void
drag_menu_deactivate_callback (GtkWidget *menu,
			       DragData *dt)
{
	dt->ch = GDK_ACTION_DEFAULT;
	if (g_main_loop_is_running (dt->loop))
		g_main_loop_quit (dt->loop);
}

static void
drag_drop_action_activated_callback (GtkWidget  *menu_item,
				     DragData       *dt)
{
	dt->ch = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "action"));
	if (g_main_loop_is_running (dt->loop))
		g_main_loop_quit (dt->loop);
}

static void
drag_append_drop_action_menu_item (GtkWidget          *menu,
				   const char    *text,
				   const char    *icon,
				   GdkDragAction action,
				   DragData       *dt)
{
	GtkWidget *menu_item;

	menu_item = gtk_image_menu_item_new_with_mnemonic (text);
	gtk_widget_set_sensitive (menu_item, TRUE);
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

	if (icon != NULL) {
		GtkWidget *image;

		image = gtk_image_new_from_stock (icon, GTK_ICON_SIZE_MENU);
		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
	}

	g_object_set_data (G_OBJECT (menu_item), "action", GINT_TO_POINTER (action));

	g_signal_connect (menu_item, "activate",
			  G_CALLBACK (drag_drop_action_activated_callback), dt);

	gtk_widget_show (menu_item);
}

GdkDragAction
totem_drag_ask (gboolean show_add_to)
{
	GtkWidget *menu;
	GtkWidget *menu_item;
	DragData dt;

	dt.ch = 0;

	menu = gtk_menu_new ();

	drag_append_drop_action_menu_item (menu, _("_Play Now"), "media-playback-start-symbolic", GDK_ACTION_MOVE, &dt);

	if (show_add_to != FALSE)
		drag_append_drop_action_menu_item (menu, _("_Add to Playlist"), "gtk-add", GDK_ACTION_COPY, &dt);

	menu_item = gtk_separator_menu_item_new ();
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
	gtk_widget_show (menu_item);

	drag_append_drop_action_menu_item (menu, _("Cancel"), NULL, GDK_ACTION_DEFAULT, &dt);

	g_signal_connect (menu, "deactivate",
			  G_CALLBACK (drag_menu_deactivate_callback), &dt);

	gtk_grab_add (menu);

	gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
			3, gtk_get_current_event_time ());

	dt.loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (dt.loop);
	gtk_grab_remove (menu);
	g_main_loop_unref (dt.loop);

	gtk_widget_destroy (menu);

	return dt.ch;
}