summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2011-06-22 20:22:19 +0200
committerGravatar waker <wakeroid@gmail.com>2011-06-22 20:22:19 +0200
commitbb81b0d2ad0192e241a3c4b6f57e6bc2a28de781 (patch)
tree459dbf9b4e1072b4842c6389a2322e31d26e55dc /plugins
parent520f157ea7dee6dc129893fc950ee9a18616eaad (diff)
added selection properties widget
Diffstat (limited to 'plugins')
-rw-r--r--plugins/gtkui/ddblistview.c1
-rw-r--r--plugins/gtkui/gtkui.c4
-rw-r--r--plugins/gtkui/mainplaylist.c1
-rw-r--r--plugins/gtkui/trkproperties.c44
-rw-r--r--plugins/gtkui/trkproperties.h8
-rw-r--r--plugins/gtkui/widgets.c96
-rw-r--r--plugins/gtkui/widgets.h7
7 files changed, 137 insertions, 24 deletions
diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c
index 33017adb..bc2ded0a 100644
--- a/plugins/gtkui/ddblistview.c
+++ b/plugins/gtkui/ddblistview.c
@@ -1427,6 +1427,7 @@ ddb_listview_click_selection (DdbListview *ps, int ex, int ey, DdbListviewGroup
UNREF (it);
}
deadbeef->pl_unlock ();
+ deadbeef->sendmessage (DB_EV_SELCHANGED, 0, deadbeef->plt_get_curr_idx (), PL_MAIN);
}
// {{{ expected behaviour for mouse1 without modifiers:
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index aa7da8b7..a9f643fd 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -989,6 +989,7 @@ gtkui_thread (void *ctx) {
w_reg_widget ("tabs", _("Tabs"), w_tabs_create);
w_reg_widget ("tabstrip", _("Playlist tabs"), w_tabstrip_create);
w_reg_widget ("playlist", _("Playlist"), w_playlist_create);
+ w_reg_widget ("selproperties", _("Selection properties"), w_selproperties_create);
mainwin = create_mainwin ();
@@ -1086,9 +1087,6 @@ gtkui_thread (void *ctx) {
gtk_main ();
w_free ();
-// w_unreg_widget ("tabbed_playlist");
-// w_unreg_widget ("box");
-// w_unreg_widget ("vsplitter");
if (refresh_timeout) {
g_source_remove (refresh_timeout);
diff --git a/plugins/gtkui/mainplaylist.c b/plugins/gtkui/mainplaylist.c
index 78db579f..f42d91db 100644
--- a/plugins/gtkui/mainplaylist.c
+++ b/plugins/gtkui/mainplaylist.c
@@ -157,6 +157,7 @@ void main_selection_changed (DdbListviewIter it, int idx) {
else {
ddb_listview_draw_row (search, search_get_idx ((DB_playItem_t *)it), it);
}
+ deadbeef->sendmessage (DB_EV_SELCHANGED, 0, deadbeef->plt_get_curr_idx (), PL_MAIN);
}
void main_draw_group_title (DdbListview *listview, GdkDrawable *drawable, DdbListviewIter it, int x, int y, int width, int height) {
diff --git a/plugins/gtkui/trkproperties.c b/plugins/gtkui/trkproperties.c
index 8dc5302d..81a90ae1 100644
--- a/plugins/gtkui/trkproperties.c
+++ b/plugins/gtkui/trkproperties.c
@@ -52,8 +52,8 @@ static int numtracks;
static GtkWidget *progressdlg;
static int progress_aborted;
-static int
-build_key_list (const char ***pkeys, int props) {
+int
+build_key_list (const char ***pkeys, int props, DB_playItem_t **tracks, int numtracks) {
int sz = 20;
const char **keys = malloc (sizeof (const char *) * sz);
if (!keys) {
@@ -100,7 +100,7 @@ equals_ptr (const char *a, const char *b) {
}
static int
-get_field_value (char *out, int size, const char *key, const char *(*getter)(DB_playItem_t *it, const char *key), int (*equals)(const char *a, const char *b)) {
+get_field_value (char *out, int size, const char *key, const char *(*getter)(DB_playItem_t *it, const char *key), int (*equals)(const char *a, const char *b), DB_playItem_t **tracks, int numtracks) {
int multiple = 0;
*out = 0;
if (numtracks == 0) {
@@ -249,13 +249,13 @@ static const char *hc_props[] = {
};
void
-add_field (GtkListStore *store, const char *key, const char *title, int is_prop) {
+add_field (GtkListStore *store, const char *key, const char *title, int is_prop, DB_playItem_t **tracks, int numtracks) {
// get value to edit
const char *mult = is_prop ? "" : _("[Multiple values] ");
char val[1000];
size_t ml = strlen (mult);
memcpy (val, mult, ml+1);
- int n = get_field_value (val + ml, sizeof (val) - ml, key, deadbeef->pl_find_meta, equals_ptr);
+ int n = get_field_value (val + ml, sizeof (val) - ml, key, deadbeef->pl_find_meta, equals_ptr, tracks, numtracks);
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
@@ -279,23 +279,17 @@ add_field (GtkListStore *store, const char *key, const char *title, int is_prop)
}
void
-trkproperties_fill_metadata (void) {
- if (!trackproperties) {
- return;
- }
- trkproperties_modified = 0;
+trkproperties_fill_meta (GtkListStore *store, DB_playItem_t **tracks, int numtracks) {
gtk_list_store_clear (store);
- gtk_list_store_clear (propstore);
- deadbeef->pl_lock ();
const char **keys = NULL;
- int nkeys = build_key_list (&keys, 0);
+ int nkeys = build_key_list (&keys, 0, tracks, numtracks);
int k;
// add "standard" fields
for (int i = 0; types[i]; i += 2) {
- add_field (store, types[i], _(types[i+1]), 0);
+ add_field (store, types[i], _(types[i+1]), 0, tracks, numtracks);
}
// add all other fields
@@ -314,19 +308,31 @@ trkproperties_fill_metadata (void) {
if (!types[i]) {
snprintf (title, sizeof (title), "<%s>", keys[k]);
}
- add_field (store, keys[k], title, 0);
+ add_field (store, keys[k], title, 0, tracks, numtracks);
}
if (keys) {
free (keys);
}
+}
+
+void
+trkproperties_fill_metadata (void) {
+ if (!trackproperties) {
+ return;
+ }
+ trkproperties_modified = 0;
+ deadbeef->pl_lock ();
+
+ trkproperties_fill_meta (store, tracks, numtracks);
+ gtk_list_store_clear (propstore);
// hardcoded properties
for (int i = 0; hc_props[i]; i += 2) {
- add_field (propstore, hc_props[i], _(hc_props[i+1]), 1);
+ add_field (propstore, hc_props[i], _(hc_props[i+1]), 1, tracks, numtracks);
}
// properties
- keys = NULL;
- nkeys = build_key_list (&keys, 1);
+ const char **keys = NULL;
+ int nkeys = build_key_list (&keys, 1, tracks, numtracks);
for (int k = 0; k < nkeys; k++) {
int i;
for (i = 0; hc_props[i]; i += 2) {
@@ -339,7 +345,7 @@ trkproperties_fill_metadata (void) {
}
char title[1000];
snprintf (title, sizeof (title), "<%s>", keys[k]+1);
- add_field (propstore, keys[k], title, 1);
+ add_field (propstore, keys[k], title, 1, tracks, numtracks);
}
if (keys) {
free (keys);
diff --git a/plugins/gtkui/trkproperties.h b/plugins/gtkui/trkproperties.h
index ccdaa69f..3604cccc 100644
--- a/plugins/gtkui/trkproperties.h
+++ b/plugins/gtkui/trkproperties.h
@@ -19,6 +19,8 @@
#ifndef __TRKPROPERTIES_H
#define __TRKPROPERTIES_H
+#include "../../deadbeef.h"
+
struct DB_playItem_s;
void
@@ -30,4 +32,10 @@ trkproperties_destroy (void);
void
trkproperties_fill_metadata (void);
+int
+build_key_list (const char ***pkeys, int props, DB_playItem_t **tracks, int numtracks);
+
+void
+trkproperties_fill_meta (GtkListStore *store, DB_playItem_t **tracks, int numtracks);
+
#endif
diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c
index 549ec9fe..f914dd8f 100644
--- a/plugins/gtkui/widgets.c
+++ b/plugins/gtkui/widgets.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "gtkui.h"
#include "widgets.h"
#include "ddbtabstrip.h"
@@ -26,6 +27,7 @@
#include "mainplaylist.h"
#include "../../gettext.h"
#include "parser.h"
+#include "trkproperties.h"
typedef struct w_creator_s {
const char *type;
@@ -66,6 +68,11 @@ typedef struct {
ddb_gtkui_widget_t base;
} w_tabs_t;
+typedef struct {
+ ddb_gtkui_widget_t base;
+ GtkWidget *tree;
+} w_selproperties_t;
+
static int design_mode;
static ddb_gtkui_widget_t *rootwidget;
@@ -973,3 +980,92 @@ w_playlist_create (void) {
w->base.message = w_tabbed_playlist_message;
return (ddb_gtkui_widget_t*)w;
}
+
+////// selection properties widget
+
+gboolean
+fill_selproperties_cb (gpointer data) {
+ w_selproperties_t *w = data;
+ DB_playItem_t **tracks = NULL;
+ int numtracks = 0;
+ deadbeef->pl_lock ();
+ int nsel = deadbeef->pl_getselcount ();
+ if (0 < nsel) {
+ tracks = malloc (sizeof (DB_playItem_t *) * nsel);
+ if (tracks) {
+ int n = 0;
+ DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN);
+ while (it) {
+ if (deadbeef->pl_is_selected (it)) {
+ assert (n < nsel);
+ deadbeef->pl_item_ref (it);
+ tracks[n++] = it;
+ }
+ DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN);
+ deadbeef->pl_item_unref (it);
+ it = next;
+ }
+ numtracks = nsel;
+ }
+ else {
+ deadbeef->pl_unlock ();
+ return FALSE;
+ }
+ }
+ GtkListStore *store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (w->tree)));
+ trkproperties_fill_meta (store, tracks, numtracks);
+ if (tracks) {
+ for (int i = 0; i < numtracks; i++) {
+ deadbeef->pl_item_unref (tracks[i]);
+ }
+ free (tracks);
+ tracks = NULL;
+ numtracks = 0;
+ }
+ deadbeef->pl_unlock ();
+ return FALSE;
+}
+
+static int
+selproperties_message (ddb_gtkui_widget_t *w, uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
+ w_tabbed_playlist_t *tp = (w_tabbed_playlist_t *)w;
+ switch (id) {
+ case DB_EV_PLAYLISTCHANGED:
+ case DB_EV_SELCHANGED:
+ {
+ g_idle_add (fill_selproperties_cb, w);
+ }
+ break;
+ }
+ return 0;
+}
+
+ddb_gtkui_widget_t *
+w_selproperties_create (void) {
+ w_selproperties_t *w = malloc (sizeof (w_selproperties_t));
+ memset (w, 0, sizeof (w_selproperties_t));
+
+ w->base.widget = gtk_scrolled_window_new (NULL, NULL);
+ w->tree = gtk_tree_view_new ();
+ gtk_widget_show (w->tree);
+ gtk_container_add (GTK_CONTAINER (w->base.widget), w->tree);
+ w->base.message = selproperties_message;
+
+ GtkListStore *store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (w->tree), GTK_TREE_MODEL (store));
+ gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (w->tree), TRUE);
+
+ GtkCellRenderer *rend1 = gtk_cell_renderer_text_new ();
+ GtkCellRenderer *rend2 = gtk_cell_renderer_text_new ();
+ GtkTreeViewColumn *col1 = gtk_tree_view_column_new_with_attributes (_("Key"), rend1, "text", 0, NULL);
+ gtk_tree_view_column_set_resizable (col1, TRUE);
+ GtkTreeViewColumn *col2 = gtk_tree_view_column_new_with_attributes (_("Value"), rend2, "text", 1, NULL);
+ gtk_tree_view_column_set_resizable (col2, TRUE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (w->tree), col1);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (w->tree), col2);
+ GtkCellRenderer *rend_propkey = gtk_cell_renderer_text_new ();
+ GtkCellRenderer *rend_propvalue = gtk_cell_renderer_text_new ();
+ gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (w->tree), TRUE);
+
+ return (ddb_gtkui_widget_t *)w;
+}
diff --git a/plugins/gtkui/widgets.h b/plugins/gtkui/widgets.h
index 0d7eb21a..c690e168 100644
--- a/plugins/gtkui/widgets.h
+++ b/plugins/gtkui/widgets.h
@@ -42,6 +42,9 @@ w_unreg_widget (const char *type);
ddb_gtkui_widget_t *
w_create (const char *type);
+const char *
+w_create_from_string (const char *s, ddb_gtkui_widget_t **parent);
+
void
w_destroy (ddb_gtkui_widget_t *w);
@@ -75,7 +78,7 @@ w_placeholder_create (void);
ddb_gtkui_widget_t *
w_tabs_create (void);
-const char *
-w_create_from_string (const char *s, ddb_gtkui_widget_t **parent);
+ddb_gtkui_widget_t *
+w_selproperties_create (void);
#endif