changeset 695:f3595214b6b9 trunk

[svn] - New configuration UI.
author nenolod
date Sat, 25 Feb 2006 19:14:32 -0800
parents 285ecb44708d
children 997aaad077fb
files Plugins/General/scrobbler/configure.c Plugins/General/scrobbler/configure.h Plugins/General/scrobbler/gtkstuff.c
diffstat 3 files changed, 91 insertions(+), 131 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/General/scrobbler/configure.c	Sat Feb 25 18:40:22 2006 -0800
+++ b/Plugins/General/scrobbler/configure.c	Sat Feb 25 19:14:32 2006 -0800
@@ -2,12 +2,17 @@
 #  include <config.h>
 #endif
 
+#include "libaudacious/util.h"
+#include "libaudacious/configdb.h"
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
 
+#include "md5.h"
+
 #include <glib.h>
 #include <glib/gi18n.h>
 
@@ -23,19 +28,89 @@
 #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
   g_object_set_data (G_OBJECT (component), name, widget)
 
-GtkWidget*
-create_window1 (void)
+GtkWidget *entry1, *entry2, *cfgdlg;
+
+static char *hexify(char *pass, int len)
+{
+        static char buf[33];
+        char *bp = buf;
+        char hexchars[] = "0123456789abcdef";
+        int i;
+
+        memset(buf, 0, sizeof(buf));
+
+        for(i = 0; i < len; i++) {
+                *(bp++) = hexchars[(pass[i] >> 4) & 0x0f];
+                *(bp++) = hexchars[pass[i] & 0x0f];
+        }
+        *bp = 0;
+        return buf;
+}
+
+static void saveconfig(GtkWidget *wid, gpointer data)
+{
+        ConfigDb *cfgfile;
+
+        const char *uid = gtk_entry_get_text(GTK_ENTRY(entry1));
+        const char *pwd = gtk_entry_get_text(GTK_ENTRY(entry2));
+
+        if ((cfgfile = bmp_cfg_db_open()))
+	{
+                md5_state_t md5state;
+                unsigned char md5pword[16];
+
+                bmp_cfg_db_set_string(cfgfile, "audioscrobbler", "username", (char *)uid);
+
+                if (pwd != NULL && pwd[0] != '\0')
+		{
+                        md5_init(&md5state);
+                        md5_append(&md5state, (unsigned const char *)pwd, strlen(pwd));
+                        md5_finish(&md5state, md5pword);
+                        bmp_cfg_db_set_string(cfgfile, "audioscrobbler", "password",
+                                        (char *)hexify(md5pword, sizeof(md5pword)));
+                }
+                bmp_cfg_db_close(cfgfile);
+        }
+
+        gtk_widget_destroy(GTK_WIDGET(data));
+}
+
+void
+configure_dialog(void)
+{
+	ConfigDb *db;
+
+	cfgdlg = create_cfgdlg();
+
+	gtk_entry_set_text(GTK_ENTRY(entry1), "");
+	gtk_entry_set_text(GTK_ENTRY(entry2), "");
+
+        if ((db = bmp_cfg_db_open())) {
+                gchar *username = NULL;
+                bmp_cfg_db_get_string(db, "audioscrobbler", "username",
+                        &username);
+                if (username) {
+                        gtk_entry_set_text(GTK_ENTRY(entry1), username);
+                        g_free(username);
+                }
+                bmp_cfg_db_close(db);
+        }
+
+	gtk_widget_show(GTK_WIDGET(cfgdlg));
+}
+
+/* Generated by glade, sorta. */
+GtkWidget *
+create_cfgdlg(void)
 {
   GtkWidget *window1;
   GtkWidget *vbox2;
   GtkWidget *table1;
-  GtkWidget *entry2;
   GtkWidget *label3;
   GtkWidget *hseparator2;
   GtkWidget *hseparator3;
   GtkWidget *label1;
   GtkWidget *label2;
-  GtkWidget *entry1;
   GtkWidget *hseparator1;
   GtkWidget *hbuttonbox1;
   GtkWidget *button5;
@@ -43,7 +118,7 @@
 
   window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_container_set_border_width (GTK_CONTAINER (window1), 12);
-  gtk_window_set_title (GTK_WINDOW (window1), _("window1"));
+  gtk_window_set_title (GTK_WINDOW (window1), _("Scrobbler Configuration"));
 
   vbox2 = gtk_vbox_new (FALSE, 0);
   gtk_widget_show (vbox2);
@@ -116,11 +191,17 @@
   gtk_container_add (GTK_CONTAINER (hbuttonbox1), button5);
   GTK_WIDGET_SET_FLAGS (button5, GTK_CAN_DEFAULT);
 
+  gtk_signal_connect(GTK_OBJECT(button5), "clicked",
+                     GTK_SIGNAL_FUNC(saveconfig), GTK_OBJECT(window1));
+
   button6 = gtk_button_new_from_stock ("gtk-close");
   gtk_widget_show (button6);
   gtk_container_add (GTK_CONTAINER (hbuttonbox1), button6);
   GTK_WIDGET_SET_FLAGS (button6, GTK_CAN_DEFAULT);
 
+  gtk_signal_connect(GTK_OBJECT(button6), "clicked",
+                     GTK_SIGNAL_FUNC(gtk_widget_destroyed), GTK_OBJECT(window1));
+
   /* Store pointers to all widgets, for use by lookup_widget(). */
   GLADE_HOOKUP_OBJECT_NO_REF (window1, window1, "window1");
   GLADE_HOOKUP_OBJECT (window1, vbox2, "vbox2");
--- a/Plugins/General/scrobbler/configure.h	Sat Feb 25 18:40:22 2006 -0800
+++ b/Plugins/General/scrobbler/configure.h	Sat Feb 25 19:14:32 2006 -0800
@@ -1,5 +1,6 @@
-/*
- * DO NOT EDIT THIS FILE - it is generated by Glade.
- */
+#ifndef _CONFIGURE_H_
+#define _CONFIGURE_H_
 
-GtkWidget* create_window1 (void);
+GtkWidget* create_cfgdlg (void);
+
+#endif
--- a/Plugins/General/scrobbler/gtkstuff.c	Sat Feb 25 18:40:22 2006 -0800
+++ b/Plugins/General/scrobbler/gtkstuff.c	Sat Feb 25 19:14:32 2006 -0800
@@ -9,8 +9,6 @@
 #include "config.h"
 #include "md5.h"
 
-static GtkWidget 	*eduname,
-			*edpwd;
 static int errorbox_done;
 void about_show(void)
 {
@@ -67,123 +65,3 @@
 	gtk_signal_connect(GTK_OBJECT(errorbox), "destroy",
 			GTK_SIGNAL_FUNC(set_errorbox_done), &errorbox);
 }
-
-static char *hexify(char *pass, int len)
-{
-	static char buf[33];
-	char *bp = buf;
-	char hexchars[] = "0123456789abcdef";
-	int i;
-	
-	memset(buf, 0, sizeof(buf));
-	
-	for(i = 0; i < len; i++) {
-		*(bp++) = hexchars[(pass[i] >> 4) & 0x0f];
-		*(bp++) = hexchars[pass[i] & 0x0f];
-	}
-	*bp = 0;
-	return buf;
-}
-
-static void saveconfig(GtkWidget *wid, gpointer data)
-{
-	ConfigDb *cfgfile;
-
-	const char *pwd = gtk_entry_get_text(GTK_ENTRY(edpwd));
-	const char *uid = gtk_entry_get_text(GTK_ENTRY(eduname));
-
-	if ((cfgfile = bmp_cfg_db_open())) {
-	
-		md5_state_t md5state;
-		unsigned char md5pword[16];
-	
-		bmp_cfg_db_set_string(cfgfile, "audioscrobbler", "username", (char *)uid);
-
-		if (pwd != NULL && pwd[0] != '\0') {
-			md5_init(&md5state);
-			md5_append(&md5state, (unsigned const char *)pwd, strlen(pwd));
-			md5_finish(&md5state, md5pword);
-			bmp_cfg_db_set_string(cfgfile, "audioscrobbler", "password",
-					(char *)hexify(md5pword, sizeof(md5pword)));
-		}
-		bmp_cfg_db_close(cfgfile);
-	}
-	gtk_widget_destroy(GTK_WIDGET(data));
-}
-
-void configure_dialog(void)
-{
-	static GtkWidget *cnfdlg;
-	GtkWidget	*btnok,
-			*btncancel,
-			*vbox,
-			*hbox,
-			*unhbox,
-			*pwhbox,
-			*lblun,
-			*lblpw,
-			*frame;
-			
-	ConfigDb 	*cfgfile;
-	
-	if (cnfdlg)
-		return;
-
-	cnfdlg = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	gtk_window_set_type_hint(GTK_WINDOW(cnfdlg),
-			GDK_WINDOW_TYPE_HINT_DIALOG);
-	gtk_window_set_title(GTK_WINDOW(cnfdlg),
-			"Scrobbler configuration");
-
-	gtk_signal_connect(GTK_OBJECT(cnfdlg), "destroy",
-			GTK_SIGNAL_FUNC(gtk_widget_destroyed), &cnfdlg);
-	
-	vbox = gtk_vbox_new(FALSE, 0);
-
-	unhbox = gtk_hbox_new(FALSE, 0);
-	eduname = gtk_entry_new();
-	lblun = gtk_label_new("Username");
-	gtk_box_pack_start(GTK_BOX(unhbox), lblun, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(unhbox), eduname, FALSE, FALSE, 3);
-	
-	pwhbox = gtk_hbox_new(FALSE, 0);
-	edpwd = gtk_entry_new();
-	lblpw = gtk_label_new("Password");
-	gtk_entry_set_visibility(GTK_ENTRY(edpwd), FALSE);
-	gtk_box_pack_start(GTK_BOX(pwhbox), lblpw, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(pwhbox), edpwd, FALSE, FALSE, 3);
-	
-	gtk_box_pack_start(GTK_BOX(vbox), unhbox, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(vbox), pwhbox, FALSE, FALSE, 3);
-	
-	hbox = gtk_hbox_new(FALSE, 0);
-
-	btnok = gtk_button_new_with_label("Ok");
-	gtk_signal_connect(GTK_OBJECT(btnok), "clicked",
-			GTK_SIGNAL_FUNC(saveconfig), GTK_OBJECT(cnfdlg));
-	
-	btncancel = gtk_button_new_with_label("Cancel");
-	gtk_signal_connect_object(GTK_OBJECT(btncancel), "clicked",
-			GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(cnfdlg));
-	gtk_box_pack_start(GTK_BOX(hbox), btnok, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(hbox), btncancel, FALSE, FALSE, 3);
-	
-	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
-
-	frame = gtk_frame_new(" The plugin will have to be restarted for changes to take effect! ");
-	gtk_container_add(GTK_CONTAINER(frame), vbox);
-	gtk_container_add(GTK_CONTAINER(cnfdlg), frame);
-
-	if ((cfgfile = bmp_cfg_db_open())) {
-		gchar *username = NULL;
-		bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "username",
-			&username);
-		if (username) {
-			gtk_entry_set_text(GTK_ENTRY(eduname), username);
-			g_free(username);
-		}
-		bmp_cfg_db_close(cfgfile);
-	}
-	
-	gtk_widget_show_all(cnfdlg);
-}