diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | gplay.c | 68 | ||||
-rw-r--r-- | gplay.includes | 1 |
3 files changed, 61 insertions, 10 deletions
@@ -1,6 +1,6 @@ CFLAGS?=-Wall -ggdb -O2 -gplay_pkgs:=gstreamer-video-1.0 gtk+-2.0 +gplay_pkgs:=gstreamer-video-1.0 gtk+-2.0 unique-1.0 gplay_cflags:=$(shell pkg-config --cflags $(gplay_pkgs)) gplay_libs:=$(shell pkg-config --libs $(gplay_pkgs)) @@ -5,6 +5,7 @@ #include <gdk/gdkx.h> #include <gst/gst.h> #include <gst/video/videooverlay.h> +#include <unique/unique.h> static GtkWindow *main_win = NULL; static GtkWidget *video_widget; @@ -427,6 +428,28 @@ static gboolean main_win_handle_key_press(GtkWidget *widget, GdkEventKey *event, } } +static UniqueResponse app_handle_message_received(UniqueApp *app, gint command, UniqueMessageData *data, guint timestamp, gpointer user_data) +{ + switch (command) { + case UNIQUE_ACTIVATE: + gtk_window_present_with_time(main_win, timestamp); + return UNIQUE_RESPONSE_OK; + case UNIQUE_OPEN: + if (data) { + gchar **uris = unique_message_data_get_uris(data); + if (uris && uris[0]) { + open_media(uris[0]); + play_media(); + return UNIQUE_RESPONSE_OK; + } + } + + /* Fallthrough */ + default: + return UNIQUE_RESPONSE_FAIL; + } +} + static void create_ui() { main_win = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); @@ -493,6 +516,11 @@ static void create_ui() gtk_container_add(GTK_CONTAINER(slider_tool), GTK_WIDGET(slider_widget)); gtk_toolbar_insert(toolbar, slider_tool, -1); + const GtkTargetEntry drop_targets[] = {{ "text/uri-list", 0, 0 }}; + gtk_drag_dest_set(GTK_WIDGET(main_win), GTK_DEST_DEFAULT_ALL, + drop_targets, G_N_ELEMENTS(drop_targets), + GDK_ACTION_DEFAULT); + gtk_window_set_default_size(main_win, 350, 20); gtk_widget_show_all(GTK_WIDGET(vbox)); @@ -521,7 +549,9 @@ int main(int argc, char **argv) { GOptionContext *ctx = g_option_context_new(_(" - simple gtk media player")); gchar **filenames = NULL; + gboolean new_instance = FALSE; const GOptionEntry entries[] = { + { "new", 'n', 0, G_OPTION_ARG_NONE, &new_instance, NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL }, { NULL } }; @@ -541,25 +571,45 @@ int main(int argc, char **argv) g_option_context_free(ctx); - create_ui(); - create_gst(); + UniqueApp *app = unique_app_new("com.javispedro.gplay", NULL); - if (filenames && *filenames) { + gchar *uri = NULL; + if (filenames && filenames[0]) { const char *file = filenames[0]; if (gst_uri_is_valid(file)) { - open_media(file); + uri = g_strdup(file); } else { - char *uri = gst_filename_to_uri(file, &error); - if (uri) { - open_media(uri); - g_free(uri); - } else { + uri = gst_filename_to_uri(file, &error); + if (!uri) { g_printerr("Invalid filename '%s':%s", file, error->message); g_error_free(error); return EXIT_FAILURE; } } + } + + if (unique_app_is_running(app) & !new_instance && uri) { + UniqueMessageData *data = unique_message_data_new(); + gchar *uris[] = { uri, NULL }; + + unique_message_data_set_uris(data, uris); + + if (unique_app_send_message(app, UNIQUE_OPEN, data) == UNIQUE_RESPONSE_OK) { + g_free(uri); + return EXIT_SUCCESS; + } + } + + g_signal_connect(app, "message-received", + G_CALLBACK(app_handle_message_received), NULL); + + create_ui(); + create_gst(); + + if (uri) { + open_media(uri); play_media(); + g_free(uri); } gtk_widget_show(GTK_WIDGET(main_win)); diff --git a/gplay.includes b/gplay.includes index a02f390..8c8284c 100644 --- a/gplay.includes +++ b/gplay.includes @@ -6,3 +6,4 @@ /usr/include/pango-1.0 /usr/include/atk-1.0 /usr/include/cairo +/usr/include/unique-1.0 |