annotate Plugins/General/scrobbler/configure.c @ 1637:5261e37b4d55 trunk

[svn] - fully working CoreAudio plugin, based on the OSS plugin and an incomplete xmms coreaudio plugin (fink)
author nenolod
date Thu, 07 Sep 2006 11:32:59 -0700
parents 84169cc8cb2d
children a8f3d8db01a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
1 #ifdef HAVE_CONFIG_H
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
2 # include <config.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
3 #endif
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
4
695
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
5 #include "libaudacious/util.h"
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
6 #include "libaudacious/configdb.h"
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
7
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
8 #include <sys/types.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
9 #include <sys/stat.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
10 #include <unistd.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
11 #include <string.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
12 #include <stdio.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
13
695
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
14 #include "md5.h"
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
15
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
16 #include <glib.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
17 #include <glib/gi18n.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
18
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
19 #include <gdk/gdkkeysyms.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
20 #include <gtk/gtk.h>
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
21
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
22 #include "configure.h"
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
23
695
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
24 GtkWidget *entry1, *entry2, *cfgdlg;
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
25
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
26 static char *hexify(char *pass, int len)
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
27 {
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
28 static char buf[33];
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
29 char *bp = buf;
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
30 char hexchars[] = "0123456789abcdef";
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
31 int i;
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
32
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
33 memset(buf, 0, sizeof(buf));
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
34
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
35 for(i = 0; i < len; i++) {
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
36 *(bp++) = hexchars[(pass[i] >> 4) & 0x0f];
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
37 *(bp++) = hexchars[pass[i] & 0x0f];
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
38 }
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
39 *bp = 0;
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
40 return buf;
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
41 }
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
42
700
99382cddf771 [svn] Fixes for all warnings (except 3 spurious GCC 4.0 ones, upgrade to 4.1 if you see them) and a performance increase. By external contributor Diego "FlameEyes" Petteno (Gentoo).
chainsaw
parents: 698
diff changeset
43 static void saveconfig(GtkWidget *wid __attribute__((unused)), gpointer data)
695
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
44 {
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
45 ConfigDb *cfgfile;
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
46
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
47 const char *uid = gtk_entry_get_text(GTK_ENTRY(entry1));
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
48 const char *pwd = gtk_entry_get_text(GTK_ENTRY(entry2));
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
49
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
50 if ((cfgfile = bmp_cfg_db_open()))
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
51 {
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
52 md5_state_t md5state;
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
53 unsigned char md5pword[16];
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
54
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
55 bmp_cfg_db_set_string(cfgfile, "audioscrobbler", "username", (char *)uid);
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
56
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
57 if (pwd != NULL && pwd[0] != '\0')
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
58 {
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
59 md5_init(&md5state);
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
60 md5_append(&md5state, (unsigned const char *)pwd, strlen(pwd));
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
61 md5_finish(&md5state, md5pword);
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
62 bmp_cfg_db_set_string(cfgfile, "audioscrobbler", "password",
700
99382cddf771 [svn] Fixes for all warnings (except 3 spurious GCC 4.0 ones, upgrade to 4.1 if you see them) and a performance increase. By external contributor Diego "FlameEyes" Petteno (Gentoo).
chainsaw
parents: 698
diff changeset
63 hexify((char*)md5pword, sizeof(md5pword)));
695
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
64 }
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
65 bmp_cfg_db_close(cfgfile);
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
66 }
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
67 }
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
68
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
69 /* Generated by glade, sorta. */
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
70 GtkWidget *
f3595214b6b9 [svn] - New configuration UI.
nenolod
parents: 694
diff changeset
71 create_cfgdlg(void)
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
72 {
1176
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
73 ConfigDb *db;
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
74 GtkWidget *vbox2;
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
75 GtkWidget *table1;
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
76 GtkWidget *label3;
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
77 GtkWidget *label1;
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
78 GtkWidget *label2;
1190
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
79 GtkWidget *himage1;
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
80 GtkWidget *align1;
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
81
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
82 vbox2 = gtk_vbox_new (FALSE, 0);
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
83
1190
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
84 label1 = gtk_label_new (_("<b>Scrobbler Preferences</b>"));
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
85 gtk_widget_show (label1);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
86 gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
87 gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
88
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
89 gtk_box_pack_start (GTK_BOX (vbox2), label1, FALSE, FALSE, 0);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
90
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
91 align1 = gtk_alignment_new(0, 0, 0, 0);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
92 gtk_widget_show (align1);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
93 gtk_alignment_set_padding(GTK_ALIGNMENT(align1), 0, 0, 12, 0);
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
94
1190
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
95 table1 = gtk_table_new (2, 2, FALSE);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
96 gtk_widget_show (table1);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
97 gtk_container_add(GTK_CONTAINER(align1), table1);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
98 gtk_box_pack_start (GTK_BOX (vbox2), align1, TRUE, TRUE, 0);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
99 gtk_table_set_row_spacings (GTK_TABLE(table1), 6);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
100 gtk_table_set_col_spacings (GTK_TABLE(table1), 6);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
101
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
102 label2 = gtk_label_new (_("Username:"));
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
103 gtk_widget_show (label2);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
104 gtk_table_attach_defaults (GTK_TABLE (table1), label2, 0, 1, 2, 3);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
105 gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_RIGHT);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
106 gtk_misc_set_alignment (GTK_MISC (label2), 1, 0.5);
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
107
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
108 label3 = gtk_label_new (_("Password:"));
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
109 gtk_widget_show (label3);
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
110 gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 3, 4,
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
111 (GtkAttachOptions) (GTK_FILL),
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
112 (GtkAttachOptions) (0), 0, 0);
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
113 gtk_label_set_justify (GTK_LABEL (label3), GTK_JUSTIFY_RIGHT);
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
114 gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5);
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
115
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
116 entry1 = gtk_entry_new ();
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
117 gtk_widget_show (entry1);
1190
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
118 gtk_table_attach_defaults (GTK_TABLE (table1), entry1, 1, 2, 2, 3);
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
119
1190
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
120 entry2 = gtk_entry_new ();
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
121 gtk_widget_show (entry2);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
122 gtk_table_attach_defaults (GTK_TABLE (table1), entry2, 1, 2, 3, 4);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
123 g_signal_connect(entry2, "changed", (GCallback) saveconfig, NULL);
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
124
1190
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
125 himage1 = gtk_image_new_from_file (DATA_DIR "/images/audioscrobbler_badge.png");
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
126 gtk_widget_show (himage1);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
127 gtk_box_pack_start (GTK_BOX (vbox2), himage1, FALSE, FALSE, 0);
84169cc8cb2d [svn] - new UI for scrobbler configuration UI
nenolod
parents: 1181
diff changeset
128 gtk_misc_set_alignment (GTK_MISC (himage1), 1, 0.5);
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
129
1176
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
130 gtk_entry_set_text(GTK_ENTRY(entry1), "");
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
131 gtk_entry_set_text(GTK_ENTRY(entry2), "");
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
132
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
133 if ((db = bmp_cfg_db_open())) {
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
134 gchar *username = NULL;
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
135 bmp_cfg_db_get_string(db, "audioscrobbler", "username",
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
136 &username);
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
137 if (username) {
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
138 gtk_entry_set_text(GTK_ENTRY(entry1), username);
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
139 g_free(username);
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
140 }
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
141 bmp_cfg_db_close(db);
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
142 }
6549a4c58e15 [svn] - grr
nenolod
parents: 700
diff changeset
143
1181
a9ecbf4443d3 [svn] - cleanups
nenolod
parents: 1176
diff changeset
144 return vbox2;
694
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
145 }
285ecb44708d [svn] Import new GUI code. Not yet hooked up really.
nenolod
parents:
diff changeset
146