chiark / gitweb /
Disobedience: change filtering window to be a more general-purpose
authorRichard Kettlewell <rjk@terraraq.org.uk>
Sun, 31 Jul 2011 13:07:35 +0000 (14:07 +0100)
committerRichard Kettlewell <rjk@terraraq.org.uk>
Sun, 31 Jul 2011 13:07:35 +0000 (14:07 +0100)
global preferences editor.

disobedience/Makefile.am
disobedience/disobedience.c
disobedience/disobedience.h
disobedience/globals.c [moved from disobedience/filter.c with 53% similarity]
disobedience/menu.c

index 49a0c4e..bf5ea40 100644 (file)
@@ -28,7 +28,7 @@ disobedience_SOURCES=disobedience.h disobedience.c client.c queue.c   \
        control.c properties.c menu.c log.c progress.c login.c rtp.c    \
        help.c ../lib/memgc.c settings.c users.c lookup.c choose.h      \
        popup.h playlists.c multidrag.c multidrag.h autoscroll.c        \
-       autoscroll.h filter.c
+       autoscroll.h globals.c
 disobedience_LDADD=../lib/libdisorder.a $(LIBPCRE) $(LIBGC) $(LIBGCRYPT) \
        $(LIBASOUND) $(COREAUDIO) $(LIBDB) $(LIBICONV)
 disobedience_LDFLAGS=$(GTK_LIBS)
index 7fcfc3c..0b6e099 100644 (file)
@@ -569,7 +569,7 @@ int main(int argc, char **argv) {
   event_register("log-connected", check_rtp_address, 0);
   suppress_actions = 0;
   playlists_init();
-  filtering_init();
+  globals_init();
   /* If no password is set yet pop up a login box */
   if(!config->password)
     login_box();
index ce79bb0..0ff76d3 100644 (file)
@@ -239,8 +239,8 @@ void popup_help(const char *what);
 
 /* Filtering */
 
-void popup_filtering(void);
-void filtering_init(void);
+void popup_globals(void);
+void globals_init(void);
 
 /* RTP */
 
similarity index 53%
rename from disobedience/filter.c
rename to disobedience/globals.c
index 9d16a7f..7f853fd 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-/** @file disobedience/filter.c
- * @brief Track filtering
+/** @file disobedience/globals.c
+ * @brief Track global preferences
  */
 
 #include "disobedience.h"
 
-static GtkWidget *filtering_window;
-static void filter_close(GtkButton attribute((unused)) *button,
+static GtkWidget *globals_window;
+static void globals_close(GtkButton attribute((unused)) *button,
                         gpointer attribute((unused)) userdata);
 
-static struct filter_row {
+static struct globals_row {
   const char *label;
   const char *pref;
   GtkWidget *entry;
-} filter_rows[] = {
+} globals_rows[] = {
   { "Required tags", "required-tags", NULL },
   { "Prohibited tags", "prohibited-tags", NULL },
+  { "Plating", "playing", NULL },
+  { "Random play", "random-play", NULL },
 };
-#define NFILTER (sizeof filter_rows / sizeof *filter_rows)
+#define NGLOBALS (sizeof globals_rows / sizeof *globals_rows)
 
-/** @brief Buttons for filtering popup */
-static struct button filter_buttons[] = {
+/** @brief Buttons for globals popup */
+static struct button globals_buttons[] = {
   {
     .stock = GTK_STOCK_CLOSE,
-    .clicked = filter_close,
+    .clicked = globals_close,
     .tip = "Close window",
     .pack = gtk_box_pack_end,
   },
 };
-#define NFILTER_BUTTONS (sizeof filter_buttons / sizeof *filter_buttons)
+#define NGLOBALS_BUTTONS (sizeof globals_buttons / sizeof *globals_buttons)
 
-static void filter_close(GtkButton attribute((unused)) *button,
+static void globals_close(GtkButton attribute((unused)) *button,
                         gpointer attribute((unused)) userdata) {
-  gtk_widget_destroy(filtering_window);
+  gtk_widget_destroy(globals_window);
 }
 
 /** @brief Called with the latest setting for a row */
-static void filter_get_completed(void *v, const char *err,
+static void globals_get_completed(void *v, const char *err,
                                 const char *value) {
   if(err)
     popup_protocol_error(0, err);
-  else if(filtering_window) {
-    struct filter_row *row = v;
+  else if(globals_window) {
+    struct globals_row *row = v;
     /* Identify unset and empty lists */
     if(!value)
       value = "";
@@ -69,13 +71,13 @@ static void filter_get_completed(void *v, const char *err,
 }
 
 /** @brief Retrieve the latest setting for @p row */
-static void filter_get(struct filter_row *row) {
-  disorder_eclient_get_global(client, filter_get_completed, row->pref, row);
+static void globals_get(struct globals_row *row) {
+  disorder_eclient_get_global(client, globals_get_completed, row->pref, row);
 }
 
 /** @brief Called when the user changes the contents of some entry */
-static void filter_entry_changed(GtkEditable *editable, gpointer user_data) {
-  struct filter_row *row = user_data;
+static void globals_entry_changed(GtkEditable *editable, gpointer user_data) {
+  struct globals_row *row = user_data;
   const char *new_value = gtk_entry_get_text(GTK_ENTRY(editable));
   if(*new_value)
     disorder_eclient_set_global(client, NULL, row->pref, new_value, row);
@@ -83,27 +85,27 @@ static void filter_entry_changed(GtkEditable *editable, gpointer user_data) {
     disorder_eclient_unset_global(client, NULL, row->pref, row);
 }
 
-/** @brief Display the filtering window */
-void popup_filtering(void) {
+/** @brief Display the globals window */
+void popup_globals(void) {
   GtkWidget *label, *table, *hbox;
   /* Pop up the window if it already exists */
-  if(filtering_window) {
-    gtk_window_present(GTK_WINDOW(filtering_window));
+  if(globals_window) {
+    gtk_window_present(GTK_WINDOW(globals_window));
     return;
   }
   /* Create the window */
   /* TODO loads of this is very similar to (copied from!) users.c - can we
    * de-dupe? */
-  filtering_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-  gtk_widget_set_style(filtering_window, tool_style);
-  gtk_window_set_title(GTK_WINDOW(filtering_window), "Filtering");
-  g_signal_connect(filtering_window, "destroy",
-                  G_CALLBACK(gtk_widget_destroyed), &filtering_window);
-  table = gtk_table_new(NFILTER + 1/*rows*/, 2/*cols*/, FALSE/*homogeneous*/);
+  globals_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+  gtk_widget_set_style(globals_window, tool_style);
+  gtk_window_set_title(GTK_WINDOW(globals_window), "Globals");
+  g_signal_connect(globals_window, "destroy",
+                  G_CALLBACK(gtk_widget_destroyed), &globals_window);
+  table = gtk_table_new(NGLOBALS + 1/*rows*/, 2/*cols*/, FALSE/*homogeneous*/);
   gtk_widget_set_style(table, tool_style);\
 
-  for(size_t n = 0; n < NFILTER; ++n) {
-    label = gtk_label_new(filter_rows[n].label);
+  for(size_t n = 0; n < NGLOBALS; ++n) {
+    label = gtk_label_new(globals_rows[n].label);
     gtk_widget_set_style(label, tool_style);
     gtk_misc_set_alignment(GTK_MISC(label), 1/*right*/, 0/*bottom*/);
     gtk_table_attach(GTK_TABLE(table), label,
@@ -111,42 +113,42 @@ void popup_filtering(void) {
                     n, n+1,              /* top/bottom_attach */
                     GTK_FILL, 0,         /* x/yoptions */
                     1, 1);               /* x/ypadding */
-    filter_rows[n].entry = gtk_entry_new();
-    gtk_widget_set_style(filter_rows[n].entry, tool_style);
-    gtk_table_attach(GTK_TABLE(table), filter_rows[n].entry,
+    globals_rows[n].entry = gtk_entry_new();
+    gtk_widget_set_style(globals_rows[n].entry, tool_style);
+    gtk_table_attach(GTK_TABLE(table), globals_rows[n].entry,
                     1, 2,                /* left/right_attach */
                     n, n+1,              /* top/bottom_attach */
                     GTK_FILL, 0,         /* x/yoptions */
                     1, 1);               /* x/ypadding */
-    g_signal_connect(filter_rows[n].entry, "changed",
-                    G_CALLBACK(filter_entry_changed), &filter_rows[n]);
-    filter_get(&filter_rows[n]);
+    g_signal_connect(globals_rows[n].entry, "changed",
+                    G_CALLBACK(globals_entry_changed), &globals_rows[n]);
+    globals_get(&globals_rows[n]);
   }
-  hbox = create_buttons_box(filter_buttons,
-                           NFILTER_BUTTONS,
+  hbox = create_buttons_box(globals_buttons,
+                           NGLOBALS_BUTTONS,
                            gtk_hbox_new(FALSE, 1));
   gtk_table_attach_defaults(GTK_TABLE(table), hbox,
                            0, 2,                /* left/right_attach */
-                           NFILTER, NFILTER+1); /* top/bottom_attach */
+                           NGLOBALS, NGLOBALS+1); /* top/bottom_attach */
 
-  gtk_container_add(GTK_CONTAINER(filtering_window), frame_widget(table, NULL));
-  gtk_widget_show_all(filtering_window);
+  gtk_container_add(GTK_CONTAINER(globals_window), frame_widget(table, NULL));
+  gtk_widget_show_all(globals_window);
 }
 
 /** @brief Called when any global pref changes */
-static void filtering_global_pref_changed(const char *event,
-                                         void *eventdata,
-                                         void *callbackdata) {
+static void globals_pref_changed(const char *event,
+                                void *eventdata,
+                                void *callbackdata) {
   const char *pref = eventdata;
-  if(!filtering_window)
+  if(!globals_window)
     return;                    /* not paying attention */
-  for(size_t n = 0; n < NFILTER; ++n) {
-    if(!strcmp(pref, filter_rows[n].pref))
-      filter_get(&filter_rows[n]);
+  for(size_t n = 0; n < NGLOBALS; ++n) {
+    if(!strcmp(pref, globals_rows[n].pref))
+      globals_get(&globals_rows[n]);
   }
 }
 
-/** @brief Initialize filtering infrastructure */
-void filtering_init() {
-  event_register("global-pref", filtering_global_pref_changed, NULL);
+/** @brief Initialize globals infrastructure */
+void globals_init() {
+  event_register("global-pref", globals_pref_changed, NULL);
 }
index 946361d..435aeb4 100644 (file)
@@ -361,9 +361,9 @@ GtkWidget *menubar(GtkWidget *w) {
       0                                 /* extra_data */
     },
     {
-      (char *)"/Control/Filtering",     /* path */
-      (char *)"<CTRL>F",                /* accelerator */
-      popup_filtering,                  /* callback */
+      (char *)"/Control/Global Preferences", /* path */
+      (char *)"<CTRL>G",                /* accelerator */
+      popup_globals,                    /* callback */
       0,                                /* callback_action */
       0,                                /* item_type */
       0                                 /* extra_data */