comparison src/scrobbler/configure.c @ 3109:5a11abf0075c

scrobbler: add support for custom audioscrobbler servers. (closes #23)
author William Pitcock <nenolod@atheme.org>
date Fri, 01 May 2009 12:28:48 -0500
parents 3134a0987162
children 062f42c3737e
comparison
equal deleted inserted replaced
3108:9978be206b93 3109:5a11abf0075c
17 #include <gtk/gtk.h> 17 #include <gtk/gtk.h>
18 18
19 #include "configure.h" 19 #include "configure.h"
20 #include "plugin.h" 20 #include "plugin.h"
21 21
22 GtkWidget *entry1, *entry2, *ge_entry1, *ge_entry2, *cfgdlg; 22 #define LASTFM_HS_URL "http://post.audioscrobbler.com"
23
24 GtkWidget *entry1, *entry2, *entry3, *ge_entry1, *ge_entry2, *cfgdlg;
23 static GdkColor disabled_color; 25 static GdkColor disabled_color;
24 guint apply_timeout = 0; /* ID of timeout to save new config */ 26 guint apply_timeout = 0; /* ID of timeout to save new config */
25 gboolean running = TRUE; /* if plugin threads are running */ 27 gboolean running = TRUE; /* if plugin threads are running */
26 28
27 static char *hexify(char *pass, int len) 29 static char *hexify(char *pass, int len)
47 static void saveconfig(void) 49 static void saveconfig(void)
48 { 50 {
49 mcs_handle_t *cfgfile; 51 mcs_handle_t *cfgfile;
50 52
51 const char *uid = gtk_entry_get_text(GTK_ENTRY(entry1)); 53 const char *uid = gtk_entry_get_text(GTK_ENTRY(entry1));
54 const char *url = gtk_entry_get_text(GTK_ENTRY(entry3));
52 const char *ge_uid = gtk_entry_get_text(GTK_ENTRY(ge_entry1)); 55 const char *ge_uid = gtk_entry_get_text(GTK_ENTRY(ge_entry1));
53 56
54 if ((cfgfile = aud_cfg_db_open())) { 57 if ((cfgfile = aud_cfg_db_open())) {
55 aud_md5state_t md5state; 58 aud_md5state_t md5state;
56 unsigned char md5pword[16], ge_md5pword[16]; 59 unsigned char md5pword[16], ge_md5pword[16];
66 hexify((char*)md5pword, sizeof(md5pword))); 69 hexify((char*)md5pword, sizeof(md5pword)));
67 } else if (!uid || uid[0] == '\0') { 70 } else if (!uid || uid[0] == '\0') {
68 aud_cfg_db_set_string(cfgfile, "audioscrobbler", "username", ""); 71 aud_cfg_db_set_string(cfgfile, "audioscrobbler", "username", "");
69 aud_cfg_db_set_string(cfgfile, "audioscrobbler", "password", ""); 72 aud_cfg_db_set_string(cfgfile, "audioscrobbler", "password", "");
70 } 73 }
74
75 if (url != NULL && url[0] != '\0' && strlen(url))
76 aud_cfg_db_set_string(cfgfile, "audioscrobbler", "sc_url", (char *)url);
77 else if (!url || url[0] == '\0')
78 aud_cfg_db_set_string(cfgfile, "audioscrobbler", "sc_url", LASTFM_HS_URL);
71 79
72 if (ge_uid != NULL && ge_uid[0] != '\0' && strlen(ge_uid) && 80 if (ge_uid != NULL && ge_uid[0] != '\0' && strlen(ge_uid) &&
73 ge_pwd != NULL && ge_pwd[0] != '\0' && strlen(ge_pwd)) 81 ge_pwd != NULL && ge_pwd[0] != '\0' && strlen(ge_pwd))
74 { 82 {
75 aud_cfg_db_set_string(cfgfile, "audioscrobbler", "ge_username", (char *)ge_uid); 83 aud_cfg_db_set_string(cfgfile, "audioscrobbler", "ge_username", (char *)ge_uid);
152 GtkWidget *vbox2; 160 GtkWidget *vbox2;
153 GtkWidget *table1; 161 GtkWidget *table1;
154 GtkWidget *label3; 162 GtkWidget *label3;
155 GtkWidget *label1; 163 GtkWidget *label1;
156 GtkWidget *label2; 164 GtkWidget *label2;
165 GtkWidget *label4;
157 GtkWidget *himage1; 166 GtkWidget *himage1;
158 GtkWidget *align1; 167 GtkWidget *align1;
159 GtkWidget *notebook1; 168 GtkWidget *notebook1;
160 GtkStyle *style; 169 GtkStyle *style;
161 170
194 gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 3, 4, 203 gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 3, 4,
195 (GtkAttachOptions) (GTK_FILL), 204 (GtkAttachOptions) (GTK_FILL),
196 (GtkAttachOptions) (0), 0, 0); 205 (GtkAttachOptions) (0), 0, 0);
197 gtk_label_set_justify (GTK_LABEL (label3), GTK_JUSTIFY_RIGHT); 206 gtk_label_set_justify (GTK_LABEL (label3), GTK_JUSTIFY_RIGHT);
198 gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5); 207 gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5);
208
209 label4 = gtk_label_new (_("Scrobbler URL:"));
210 gtk_widget_show (label4);
211 gtk_table_attach (GTK_TABLE (table1), label4, 0, 1, 4, 5,
212 (GtkAttachOptions) (GTK_FILL),
213 (GtkAttachOptions) (0), 0, 0);
214 gtk_label_set_justify (GTK_LABEL (label4), GTK_JUSTIFY_RIGHT);
215 gtk_misc_set_alignment (GTK_MISC (label4), 1, 0.5);
199 216
200 entry1 = gtk_entry_new (); 217 entry1 = gtk_entry_new ();
201 gtk_widget_show (entry1); 218 gtk_widget_show (entry1);
202 gtk_table_attach_defaults (GTK_TABLE (table1), entry1, 1, 2, 2, 3); 219 gtk_table_attach_defaults (GTK_TABLE (table1), entry1, 1, 2, 2, 3);
203 220
214 g_signal_connect(G_OBJECT(entry2), "focus-out-event", 231 g_signal_connect(G_OBJECT(entry2), "focus-out-event",
215 G_CALLBACK(entry_focus_out), 232 G_CALLBACK(entry_focus_out),
216 NULL); 233 NULL);
217 gtk_widget_show (entry2); 234 gtk_widget_show (entry2);
218 gtk_table_attach_defaults (GTK_TABLE (table1), entry2, 1, 2, 3, 4); 235 gtk_table_attach_defaults (GTK_TABLE (table1), entry2, 1, 2, 3, 4);
236
237 entry3 = gtk_entry_new ();
238 gtk_widget_show (entry3);
239 gtk_table_attach_defaults (GTK_TABLE (table1), entry3, 1, 2, 4, 5);
219 240
220 label1 = gtk_label_new (_("<b>Last.FM</b>")); 241 label1 = gtk_label_new (_("<b>Last.FM</b>"));
221 gtk_label_set_use_markup (GTK_LABEL (label1), TRUE); 242 gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);
222 gtk_notebook_append_page(GTK_NOTEBOOK(notebook1), GTK_WIDGET(align1), label1); 243 gtk_notebook_append_page(GTK_NOTEBOOK(notebook1), GTK_WIDGET(align1), label1);
223 244
280 gtk_entry_set_text(GTK_ENTRY(entry1), ""); 301 gtk_entry_set_text(GTK_ENTRY(entry1), "");
281 gtk_entry_set_text(GTK_ENTRY(ge_entry1), ""); 302 gtk_entry_set_text(GTK_ENTRY(ge_entry1), "");
282 303
283 if ((db = aud_cfg_db_open())) { 304 if ((db = aud_cfg_db_open())) {
284 gchar *username = NULL; 305 gchar *username = NULL;
306 gchar *sc_url = NULL;
285 // last fm 307 // last fm
286 aud_cfg_db_get_string(db, "audioscrobbler", "username", 308 aud_cfg_db_get_string(db, "audioscrobbler", "username",
287 &username); 309 &username);
288 if (username) { 310 if (username) {
289 gtk_entry_set_text(GTK_ENTRY(entry1), username); 311 gtk_entry_set_text(GTK_ENTRY(entry1), username);
290 g_free(username); 312 g_free(username);
291 username = NULL; 313 username = NULL;
292 } 314 }
315
316 aud_cfg_db_get_string(db, "audioscrobbler", "sc_url", &sc_url);
317 if (sc_url) {
318 gtk_entry_set_text(GTK_ENTRY(entry3), sc_url);
319 g_free(sc_url);
320 sc_url = NULL;
321 }
322
293 // gerpok 323 // gerpok
294 aud_cfg_db_get_string(db, "audioscrobbler", "ge_username", 324 aud_cfg_db_get_string(db, "audioscrobbler", "ge_username",
295 &username); 325 &username);
296 if (username) { 326 if (username) {
297 gtk_entry_set_text(GTK_ENTRY(ge_entry1), username); 327 gtk_entry_set_text(GTK_ENTRY(ge_entry1), username);
301 331
302 aud_cfg_db_close(db); 332 aud_cfg_db_close(db);
303 } 333 }
304 334
305 g_signal_connect(entry1, "changed", G_CALLBACK(entry_changed), NULL); 335 g_signal_connect(entry1, "changed", G_CALLBACK(entry_changed), NULL);
336 g_signal_connect(entry3, "changed", G_CALLBACK(entry_changed), NULL);
306 g_signal_connect(ge_entry1, "changed", G_CALLBACK(entry_changed), NULL); 337 g_signal_connect(ge_entry1, "changed", G_CALLBACK(entry_changed), NULL);
307 338
308 return vbox2; 339 return vbox2;
309 } 340 }
310 341