changeset 2318:d7c321957be8

apply username/password changes 10 seconds after last keystroke in config editboxes
author Tomasz Mon <desowin@gmail.com>
date Tue, 15 Jan 2008 20:26:27 +0100
parents 447dce6f59f3
children 146381a317df
files src/scrobbler/configure.c src/scrobbler/plugin.c
diffstat 2 files changed, 37 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/scrobbler/configure.c	Tue Jan 15 19:54:19 2008 +0100
+++ b/src/scrobbler/configure.c	Tue Jan 15 20:26:27 2008 +0100
@@ -21,8 +21,10 @@
 #include <gtk/gtk.h>
 
 #include "configure.h"
+#include "plugin.h"
 
 GtkWidget *entry1, *entry2, *ge_entry1, *ge_entry2, *cfgdlg;
+guint apply_timeout = 0; /* ID of timeout to save new config */
 
 static char *hexify(char *pass, int len)
 {
@@ -41,7 +43,7 @@
         return buf;
 }
 
-static void saveconfig(GtkWidget *wid __attribute__((unused)), gpointer data)
+static gboolean saveconfig(gpointer data)
 {
         ConfigDb *cfgfile;
 
@@ -78,6 +80,20 @@
 
                 aud_cfg_db_close(cfgfile);
         }
+
+    apply_timeout = 0;
+    stop();
+    start();
+    return FALSE;
+}
+
+static void
+entry_changed(GtkWidget *widget, gpointer data)
+{
+    if (apply_timeout)
+        g_source_remove(apply_timeout);
+
+    apply_timeout = g_timeout_add_seconds(10, (GSourceFunc) saveconfig, NULL);
 }
 
 /* Generated by glade, sorta. */
@@ -140,7 +156,6 @@
   gtk_entry_set_visibility(GTK_ENTRY(entry2), FALSE);
   gtk_widget_show (entry2);
   gtk_table_attach_defaults (GTK_TABLE (table1), entry2, 1, 2, 3, 4);
-  g_signal_connect(entry2, "changed", (GCallback) saveconfig, NULL);
 
   label1 = gtk_label_new (_("<b>Last.FM</b>"));
   gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);
@@ -180,7 +195,6 @@
   gtk_entry_set_visibility(GTK_ENTRY(ge_entry2), FALSE);
   gtk_widget_show (ge_entry2);
   gtk_table_attach_defaults (GTK_TABLE (table1), ge_entry2, 1, 2, 3, 4);
-  g_signal_connect(ge_entry2, "changed", (GCallback) saveconfig, NULL);
 
   label1 = gtk_label_new (_("<b>Gerpok</b>"));
   gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);
@@ -219,6 +233,11 @@
                 aud_cfg_db_close(db);
         }
 
+  g_signal_connect(entry1, "changed", G_CALLBACK(entry_changed), NULL);
+  g_signal_connect(entry2, "changed", G_CALLBACK(entry_changed), NULL);
+  g_signal_connect(ge_entry1, "changed", G_CALLBACK(entry_changed), NULL);
+  g_signal_connect(ge_entry2, "changed", G_CALLBACK(entry_changed), NULL);
+
   return vbox2;
 }
 
--- a/src/scrobbler/plugin.c	Tue Jan 15 19:54:19 2008 +0100
+++ b/src/scrobbler/plugin.c	Tue Jan 15 20:26:27 2008 +0100
@@ -100,17 +100,13 @@
     }
 }
 
-static void init(void)
-{
+void start(void) {
 	char *username = NULL, *password = NULL;
 	char *ge_username = NULL, *ge_password = NULL;
 	ConfigDb *cfgfile;
 	sc_going = 1;
 	ge_going = 1;
 	GError **moo = NULL;
-	cfgdlg = create_cfgdlg();
-
-        aud_prefswin_page_new(cfgdlg, "Scrobbler", DATA_DIR "/images/audioscrobbler.png");
 
 	if ((cfgfile = aud_cfg_db_open()) != NULL) {
 		aud_cfg_db_get_string(cfgfile, "audioscrobbler", "username",
@@ -180,10 +176,7 @@
 	pdebug("plugin started", DEBUG);
 }
 
-static void cleanup(void)
-{
-        aud_prefswin_page_destroy(cfgdlg);
-
+void stop(void) {
 	if (!sc_going && !ge_going)
 		return;
 	pdebug("about to lock mutex", DEBUG);
@@ -219,6 +212,19 @@
 	aud_hook_dissociate("playback end", aud_hook_playback_end);
 }
 
+static void init(void)
+{
+    start();
+    cfgdlg = create_cfgdlg();
+    aud_prefswin_page_new(cfgdlg, "Scrobbler", DATA_DIR "/images/audioscrobbler.png");
+}
+
+static void cleanup(void)
+{
+    stop();
+    aud_prefswin_page_destroy(cfgdlg);
+}
+
 static void *xs_thread(void *data __attribute__((unused)))
 {
 	int run = 1;