Mercurial > audlegacy
annotate Plugins/General/scrobbler/configure.c @ 1176:6549a4c58e15 trunk
[svn] - grr
author | nenolod |
---|---|
date | Sun, 11 Jun 2006 20:29:00 -0700 |
parents | 99382cddf771 |
children | a9ecbf4443d3 |
rev | line source |
---|---|
694 | 1 #ifdef HAVE_CONFIG_H |
2 # include <config.h> | |
3 #endif | |
4 | |
695 | 5 #include "libaudacious/util.h" |
6 #include "libaudacious/configdb.h" | |
7 | |
694 | 8 #include <sys/types.h> |
9 #include <sys/stat.h> | |
10 #include <unistd.h> | |
11 #include <string.h> | |
12 #include <stdio.h> | |
13 | |
695 | 14 #include "md5.h" |
15 | |
694 | 16 #include <glib.h> |
17 #include <glib/gi18n.h> | |
18 | |
19 #include <gdk/gdkkeysyms.h> | |
20 #include <gtk/gtk.h> | |
21 | |
22 #include "configure.h" | |
23 | |
24 #define GLADE_HOOKUP_OBJECT(component,widget,name) \ | |
25 g_object_set_data_full (G_OBJECT (component), name, \ | |
26 gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref) | |
27 | |
28 #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ | |
29 g_object_set_data (G_OBJECT (component), name, widget) | |
30 | |
695 | 31 GtkWidget *entry1, *entry2, *cfgdlg; |
32 | |
33 static char *hexify(char *pass, int len) | |
34 { | |
35 static char buf[33]; | |
36 char *bp = buf; | |
37 char hexchars[] = "0123456789abcdef"; | |
38 int i; | |
39 | |
40 memset(buf, 0, sizeof(buf)); | |
41 | |
42 for(i = 0; i < len; i++) { | |
43 *(bp++) = hexchars[(pass[i] >> 4) & 0x0f]; | |
44 *(bp++) = hexchars[pass[i] & 0x0f]; | |
45 } | |
46 *bp = 0; | |
47 return buf; | |
48 } | |
49 | |
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
|
50 static void saveconfig(GtkWidget *wid __attribute__((unused)), gpointer data) |
695 | 51 { |
52 ConfigDb *cfgfile; | |
53 | |
54 const char *uid = gtk_entry_get_text(GTK_ENTRY(entry1)); | |
55 const char *pwd = gtk_entry_get_text(GTK_ENTRY(entry2)); | |
56 | |
57 if ((cfgfile = bmp_cfg_db_open())) | |
58 { | |
59 md5_state_t md5state; | |
60 unsigned char md5pword[16]; | |
61 | |
62 bmp_cfg_db_set_string(cfgfile, "audioscrobbler", "username", (char *)uid); | |
63 | |
64 if (pwd != NULL && pwd[0] != '\0') | |
65 { | |
66 md5_init(&md5state); | |
67 md5_append(&md5state, (unsigned const char *)pwd, strlen(pwd)); | |
68 md5_finish(&md5state, md5pword); | |
69 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
|
70 hexify((char*)md5pword, sizeof(md5pword))); |
695 | 71 } |
72 bmp_cfg_db_close(cfgfile); | |
73 } | |
74 } | |
75 | |
76 /* Generated by glade, sorta. */ | |
77 GtkWidget * | |
78 create_cfgdlg(void) | |
694 | 79 { |
1176 | 80 ConfigDb *db; |
694 | 81 GtkWidget *window1; |
82 GtkWidget *vbox2; | |
83 GtkWidget *table1; | |
84 GtkWidget *label3; | |
85 GtkWidget *hseparator2; | |
86 GtkWidget *hseparator3; | |
87 GtkWidget *label1; | |
88 GtkWidget *label2; | |
89 GtkWidget *hseparator1; | |
90 GtkWidget *hbuttonbox1; | |
91 GtkWidget *button5; | |
92 GtkWidget *button6; | |
93 | |
1176 | 94 window1 = gtk_alignment_new (12, 12, 0, 0); |
95 | |
96 /* gtk_container_set_border_width (GTK_CONTAINER (window1), 12); */ | |
97 /* gtk_window_set_title (GTK_WINDOW (window1), _("Scrobbler Configuration")); */ | |
694 | 98 |
99 vbox2 = gtk_vbox_new (FALSE, 0); | |
100 gtk_widget_show (vbox2); | |
101 gtk_container_add (GTK_CONTAINER (window1), vbox2); | |
102 | |
103 table1 = gtk_table_new (4, 2, FALSE); | |
104 gtk_widget_show (table1); | |
105 gtk_box_pack_start (GTK_BOX (vbox2), table1, FALSE, FALSE, 0); | |
106 | |
107 entry2 = gtk_entry_new (); | |
108 gtk_widget_show (entry2); | |
109 gtk_table_attach (GTK_TABLE (table1), entry2, 1, 2, 3, 4, | |
110 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), | |
111 (GtkAttachOptions) (0), 0, 0); | |
112 | |
113 label3 = gtk_label_new (_("Password:")); | |
114 gtk_widget_show (label3); | |
115 gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 3, 4, | |
116 (GtkAttachOptions) (GTK_FILL), | |
117 (GtkAttachOptions) (0), 0, 0); | |
118 gtk_label_set_justify (GTK_LABEL (label3), GTK_JUSTIFY_RIGHT); | |
119 gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5); | |
120 | |
121 hseparator2 = gtk_hseparator_new (); | |
122 gtk_widget_show (hseparator2); | |
123 gtk_table_attach (GTK_TABLE (table1), hseparator2, 0, 1, 1, 2, | |
124 (GtkAttachOptions) (GTK_FILL), | |
125 (GtkAttachOptions) (0), 0, 0); | |
126 | |
127 hseparator3 = gtk_hseparator_new (); | |
128 gtk_widget_show (hseparator3); | |
129 gtk_table_attach (GTK_TABLE (table1), hseparator3, 1, 2, 1, 2, | |
130 (GtkAttachOptions) (GTK_FILL), | |
131 (GtkAttachOptions) (0), 0, 0); | |
132 | |
133 label1 = gtk_label_new (_("<b>Scrobbler Preferences</b>")); | |
134 gtk_widget_show (label1); | |
135 gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1, | |
136 (GtkAttachOptions) (GTK_FILL), | |
137 (GtkAttachOptions) (0), 0, 0); | |
138 gtk_label_set_use_markup (GTK_LABEL (label1), TRUE); | |
139 gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5); | |
140 | |
141 label2 = gtk_label_new (_("Username:")); | |
142 gtk_widget_show (label2); | |
143 gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 2, 3, | |
144 (GtkAttachOptions) (GTK_FILL), | |
145 (GtkAttachOptions) (0), 0, 0); | |
146 gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_RIGHT); | |
147 gtk_misc_set_alignment (GTK_MISC (label2), 1, 0.5); | |
148 | |
149 entry1 = gtk_entry_new (); | |
150 gtk_widget_show (entry1); | |
151 gtk_table_attach (GTK_TABLE (table1), entry1, 1, 2, 2, 3, | |
152 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), | |
153 (GtkAttachOptions) (0), 0, 0); | |
154 | |
155 hseparator1 = gtk_hseparator_new (); | |
156 gtk_widget_show (hseparator1); | |
157 gtk_box_pack_start (GTK_BOX (vbox2), hseparator1, FALSE, FALSE, 0); | |
158 | |
159 hbuttonbox1 = gtk_hbutton_box_new (); | |
160 gtk_widget_show (hbuttonbox1); | |
161 gtk_box_pack_start (GTK_BOX (vbox2), hbuttonbox1, FALSE, FALSE, 0); | |
162 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END); | |
163 gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 5); | |
164 | |
165 button5 = gtk_button_new_from_stock ("gtk-ok"); | |
166 gtk_widget_show (button5); | |
167 gtk_container_add (GTK_CONTAINER (hbuttonbox1), button5); | |
168 GTK_WIDGET_SET_FLAGS (button5, GTK_CAN_DEFAULT); | |
169 | |
695 | 170 gtk_signal_connect(GTK_OBJECT(button5), "clicked", |
171 GTK_SIGNAL_FUNC(saveconfig), GTK_OBJECT(window1)); | |
172 | |
694 | 173 button6 = gtk_button_new_from_stock ("gtk-close"); |
174 gtk_widget_show (button6); | |
175 gtk_container_add (GTK_CONTAINER (hbuttonbox1), button6); | |
176 GTK_WIDGET_SET_FLAGS (button6, GTK_CAN_DEFAULT); | |
177 | |
178 /* Store pointers to all widgets, for use by lookup_widget(). */ | |
179 GLADE_HOOKUP_OBJECT_NO_REF (window1, window1, "window1"); | |
180 GLADE_HOOKUP_OBJECT (window1, vbox2, "vbox2"); | |
181 GLADE_HOOKUP_OBJECT (window1, table1, "table1"); | |
182 GLADE_HOOKUP_OBJECT (window1, entry2, "entry2"); | |
183 GLADE_HOOKUP_OBJECT (window1, label3, "label3"); | |
184 GLADE_HOOKUP_OBJECT (window1, hseparator2, "hseparator2"); | |
185 GLADE_HOOKUP_OBJECT (window1, hseparator3, "hseparator3"); | |
186 GLADE_HOOKUP_OBJECT (window1, label1, "label1"); | |
187 GLADE_HOOKUP_OBJECT (window1, label2, "label2"); | |
188 GLADE_HOOKUP_OBJECT (window1, entry1, "entry1"); | |
189 GLADE_HOOKUP_OBJECT (window1, hseparator1, "hseparator1"); | |
190 GLADE_HOOKUP_OBJECT (window1, hbuttonbox1, "hbuttonbox1"); | |
191 GLADE_HOOKUP_OBJECT (window1, button5, "button5"); | |
192 GLADE_HOOKUP_OBJECT (window1, button6, "button6"); | |
193 | |
1176 | 194 gtk_entry_set_text(GTK_ENTRY(entry1), ""); |
195 gtk_entry_set_text(GTK_ENTRY(entry2), ""); | |
196 | |
197 if ((db = bmp_cfg_db_open())) { | |
198 gchar *username = NULL; | |
199 bmp_cfg_db_get_string(db, "audioscrobbler", "username", | |
200 &username); | |
201 if (username) { | |
202 gtk_entry_set_text(GTK_ENTRY(entry1), username); | |
203 g_free(username); | |
204 } | |
205 bmp_cfg_db_close(db); | |
206 } | |
207 | |
694 | 208 return window1; |
209 } | |
210 |