commit 8d9190ce986fe678358ed1e20fc60be018ccf650
Author: phantomjinx <[email protected]>
Date: Wed Oct 13 20:35:35 2010 +0100
Set preference for show exec command popup menu
* If more than one track exec command has been registered then a popup menu
must be displayed. This can be avoided by setting a preference in the
track display preferences.
* gtkpod_app_iface.*
* plumbing for executing a command identified in the
DEFAULT_TRACK_COMMAND_PREFERENCE.
* track_command_iface.h
* TrackCommandInterface needs an id and display text
* track_display.glade
* track_display_preferences
* preferred track command preference implementation
libgtkpod/gtkpod_app_iface.c | 69 +++++++++++++++++++--
libgtkpod/gtkpod_app_iface.h | 1 +
libgtkpod/track_command_iface.h | 4 +
plugins/media_player/plugin.c | 2 +
plugins/track_display/track_display.glade | 36 +++++++++++
plugins/track_display/track_display_preferences.c | 48 ++++++++++++++
6 files changed, 154 insertions(+), 6 deletions(-)
---
diff --git a/libgtkpod/gtkpod_app_iface.c b/libgtkpod/gtkpod_app_iface.c
index fa0dc9e..7c6f9cf 100644
--- a/libgtkpod/gtkpod_app_iface.c
+++ b/libgtkpod/gtkpod_app_iface.c
@@ -34,6 +34,8 @@
#include "gtkpod_app_iface.h"
#include "gtkpod_app-marshallers.h"
#include "misc.h"
+#include "context_menus.h"
+#include "prefs.h"
static void gtkpod_app_base_init(GtkPodAppInterface* klass) {
static gboolean initialized = FALSE;
@@ -576,6 +578,44 @@ void gtkpod_unregister_track_command(TrackCommandInterface
*command) {
gp_iface->track_commands = g_list_remove(gp_iface->track_commands,
command);
}
+static void execute_track_command(GtkMenuItem *mi, gpointer data) {
+ GPtrArray *pairarr = (GPtrArray *) data;
+
+ TrackCommandInterface *cmd = g_ptr_array_index(pairarr, 0);
+ GList *tracks = g_ptr_array_index(pairarr, 1);
+
+ cmd->execute(tracks);
+ g_ptr_array_free(pairarr, FALSE);
+}
+
+static void gtkpod_display_command_ctx_menu(GList *track_cmds, GList *tracks) {
+ GtkWidget *menu = NULL;
+ GList *cmds;
+
+ if (!track_cmds)
+ return;
+
+ if (!tracks)
+ return;
+
+ if (widgets_blocked)
+ return;
+
+ menu = gtk_menu_new();
+ cmds = track_cmds;
+
+ while(cmds != NULL) {
+ TrackCommandInterface *cmd = cmds->data;
+ GPtrArray *pairarr = g_ptr_array_new ();
+ g_ptr_array_add (pairarr, cmd);
+ g_ptr_array_add (pairarr, tracks);
+ hookup_menu_item(menu, cmd->text, GTK_STOCK_EXECUTE, G_CALLBACK
(execute_track_command), pairarr);
+ cmds = cmds->next;
+ }
+
+ gtk_menu_popup(GTK_MENU (menu), NULL, NULL, NULL, NULL, 0,
gtk_get_current_event_time());
+}
+
void gtkpod_execute_track_command(GList *tracks) {
g_return_if_fail(GTKPOD_IS_APP(gtkpod_app));
GtkPodAppInterface *gp_iface = GTKPOD_APP_GET_INTERFACE (gtkpod_app);
@@ -590,13 +630,30 @@ void gtkpod_execute_track_command(GList *tracks) {
break;
case 1:
;
- TrackCommandInterface *command =
g_list_nth_data(gp_iface->track_commands, 0);
- command->execute(tracks);
+ TrackCommandInterface *cmd = g_list_nth_data(gp_iface->track_commands,
0);
+ cmd->execute(tracks);
break;
default:
- // Show menu
- // TODO
- // FIXME - seems cannot play the vixen files with the parantheses in
- g_warning("Display context menu of options");
+ ;
+ // More than one so see if there is a preference set
+ gchar *cmdpref = NULL;
+ if (prefs_get_string_value(DEFAULT_TRACK_COMMAND_PREF_KEY, &cmdpref)) {
+ for (gint i = 0; i < g_list_length(gp_iface->track_commands); ++i)
{
+ TrackCommandInterface *cmd =
g_list_nth_data(gp_iface->track_commands, i);
+ if (cmdpref && g_str_equal(cmdpref, cmd->id)) {
+ cmd->execute(tracks);
+ return;
+ }
+ }
+ }
+
+ // Otherwise show the menu
+ gtkpod_display_command_ctx_menu(gp_iface->track_commands, tracks);
}
}
+
+GList *gtkpod_get_registered_track_commands() {
+ g_return_val_if_fail(GTKPOD_IS_APP(gtkpod_app), NULL);
+ GtkPodAppInterface *gp_iface = GTKPOD_APP_GET_INTERFACE (gtkpod_app);
+ return g_list_copy(gp_iface->track_commands);
+}
diff --git a/libgtkpod/gtkpod_app_iface.h b/libgtkpod/gtkpod_app_iface.h
index 7a077c0..cc1a565 100644
--- a/libgtkpod/gtkpod_app_iface.h
+++ b/libgtkpod/gtkpod_app_iface.h
@@ -234,6 +234,7 @@ void gtkpod_edit_photos(iTunesDB *itdb);
void gtkpod_register_track_command(TrackCommandInterface *command);
void gtkpod_unregister_track_command(TrackCommandInterface *command);
void gtkpod_execute_track_command(GList *tracks);
+GList *gtkpod_get_registered_track_commands();
GtkPodApp *gtkpod_app;
guint gtkpod_app_signals[LAST_SIGNAL];
diff --git a/libgtkpod/track_command_iface.h b/libgtkpod/track_command_iface.h
index 154fd5a..8fc7935 100644
--- a/libgtkpod/track_command_iface.h
+++ b/libgtkpod/track_command_iface.h
@@ -36,12 +36,16 @@
#include <gtk/gtk.h>
#include "itdb.h"
+#define DEFAULT_TRACK_COMMAND_PREF_KEY "default_track_display_track_command"
+
typedef struct _TrackCommand TrackCommand;
typedef struct _TrackCommandInterface TrackCommandInterface;
struct _TrackCommandInterface {
GTypeInterface g_iface;
+ gchar *id;
+ gchar *text;
void (*execute)(GList *tracks);
};
diff --git a/plugins/media_player/plugin.c b/plugins/media_player/plugin.c
index 9d2c477..f2a2bf9 100644
--- a/plugins/media_player/plugin.c
+++ b/plugins/media_player/plugin.c
@@ -165,6 +165,8 @@ static void media_player_plugin_class_init(GObjectClass
*klass) {
//}
static void track_command_iface_init(TrackCommandInterface *iface) {
+ iface->id = "media_player_play_track_command";
+ iface->text = _("Play");
iface->execute = media_player_play_tracks;
}
diff --git a/plugins/track_display/track_display.glade
b/plugins/track_display/track_display.glade
index 1f9835f..faf0578 100644
--- a/plugins/track_display/track_display.glade
+++ b/plugins/track_display/track_display.glade
@@ -1306,6 +1306,7 @@
<widget class="GtkVBox" id="vbox5">
<property name="visible">True</property>
<property name="border_width">12</property>
+ <property name="orientation">vertical</property>
<property name="spacing">18</property>
<child>
<widget class="GtkFrame" id="frame4">
@@ -1321,6 +1322,7 @@
<widget class="GtkVBox" id="vbox46">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
+ <property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<widget class="GtkHBox" id="hbox3">
@@ -1350,6 +1352,7 @@
<child>
<widget class="GtkVButtonBox" id="vbuttonbox2">
<property name="visible">True</property>
+ <property
name="orientation">vertical</property>
<property name="spacing">6</property>
<property name="layout_style">spread</property>
<child>
@@ -1486,6 +1489,39 @@
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <widget class="GtkFrame" id="frame1">
+ <property name="visible">True</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <widget class="GtkAlignment" id="alignment1">
+ <property name="visible">True</property>
+ <property name="left_padding">12</property>
+ <child>
+ <widget class="GtkComboBox" id="track_exec_cmd_combo">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="label"
translatable="yes"><b>Preferred Track Execution
Command</b></property>
+ <property name="use_markup">True</property>
+ </widget>
+ <packing>
+ <property name="type">label_item</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
</child>
<child>
diff --git a/plugins/track_display/track_display_preferences.c
b/plugins/track_display/track_display_preferences.c
index 26a85f5..2cf372a 100644
--- a/plugins/track_display/track_display_preferences.c
+++ b/plugins/track_display/track_display_preferences.c
@@ -230,12 +230,58 @@ G_MODULE_EXPORT void on_horizontal_scrollbar_toggled
(GtkToggleButton *sender, g
tm_show_preferred_columns ();
}
+static void trkcmd_combobox_changed(GtkComboBox *combo) {
+ gint activeindex = gtk_combo_box_get_active(combo);
+
+ if (activeindex > -1) {
+ GList *cmds = g_object_get_data(G_OBJECT(combo), "cmds");
+ TrackCommandInterface *cmd = g_list_nth_data(cmds, activeindex);
+ prefs_set_string(DEFAULT_TRACK_COMMAND_PREF_KEY, cmd->id);
+ }
+}
+
+static void populate_track_cmd_combo(GtkComboBox *combo) {
+ GtkListStore *store;
+ GtkCellRenderer *cell;
+ GList *trkcmds = gtkpod_get_registered_track_commands();
+ gint i = 0, activeindex = -1;
+
+ g_object_set_data(G_OBJECT(combo), "cmds", trkcmds);
+
+ store = gtk_list_store_new(1, G_TYPE_STRING);
+ gtk_combo_box_set_model(combo, GTK_TREE_MODEL (store));
+ g_object_unref(store);
+
+ cell = gtk_cell_renderer_text_new();
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (combo), cell, TRUE);
+ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT (combo), cell, "text", 0,
NULL);
+
+ gchar *cmdpref = NULL;
+ prefs_get_string_value(DEFAULT_TRACK_COMMAND_PREF_KEY, &cmdpref);
+
+ for (i = 0; i < g_list_length(trkcmds); ++i) {
+ TrackCommandInterface *cmd = g_list_nth_data(trkcmds, i);
+ gtk_combo_box_append_text(combo, _(cmd->text));
+ if (cmdpref && g_str_equal(cmdpref, cmd->id))
+ activeindex = i;
+ }
+
+ if (activeindex > -1)
+ gtk_combo_box_set_active(combo, activeindex);
+
+ g_signal_connect (combo, "changed",
+ G_CALLBACK (trkcmd_combobox_changed),
+ NULL);
+}
+
GtkWidget *init_track_display_preferences() {
GladeXML *pref_xml;
+ GtkComboBox *cmd_combo;
gchar *glade_path = g_build_filename(get_glade_dir(),
"track_display.glade", NULL);
pref_xml = gtkpod_xml_new(glade_path, "track_settings_notebook");
notebook = gtkpod_xml_get_widget(pref_xml, "track_settings_notebook");
+ cmd_combo = GTK_COMBO_BOX(gtkpod_xml_get_widget(pref_xml,
"track_exec_cmd_combo"));
displayed_columns_view = gtkpod_xml_get_widget(pref_xml,
"displayed_columns");
g_object_ref(notebook);
g_free(glade_path);
@@ -244,5 +290,7 @@ GtkWidget *init_track_display_preferences() {
glade_xml_signal_autoconnect(pref_xml);
+ populate_track_cmd_combo(cmd_combo);
+
return notebook;
}
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2