Mercurial > audlegacy
annotate Plugins/General/scrobbler/configure.c @ 1181:a9ecbf4443d3 trunk
[svn] - cleanups
author | nenolod |
---|---|
date | Sun, 11 Jun 2006 21:41:37 -0700 |
parents | 6549a4c58e15 |
children | 84169cc8cb2d |
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 | |
695 | 24 GtkWidget *entry1, *entry2, *cfgdlg; |
25 | |
26 static char *hexify(char *pass, int len) | |
27 { | |
28 static char buf[33]; | |
29 char *bp = buf; | |
30 char hexchars[] = "0123456789abcdef"; | |
31 int i; | |
32 | |
33 memset(buf, 0, sizeof(buf)); | |
34 | |
35 for(i = 0; i < len; i++) { | |
36 *(bp++) = hexchars[(pass[i] >> 4) & 0x0f]; | |
37 *(bp++) = hexchars[pass[i] & 0x0f]; | |
38 } | |
39 *bp = 0; | |
40 return buf; | |
41 } | |
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 | 44 { |
45 ConfigDb *cfgfile; | |
46 | |
47 const char *uid = gtk_entry_get_text(GTK_ENTRY(entry1)); | |
48 const char *pwd = gtk_entry_get_text(GTK_ENTRY(entry2)); | |
49 | |
50 if ((cfgfile = bmp_cfg_db_open())) | |
51 { | |
52 md5_state_t md5state; | |
53 unsigned char md5pword[16]; | |
54 | |
55 bmp_cfg_db_set_string(cfgfile, "audioscrobbler", "username", (char *)uid); | |
56 | |
57 if (pwd != NULL && pwd[0] != '\0') | |
58 { | |
59 md5_init(&md5state); | |
60 md5_append(&md5state, (unsigned const char *)pwd, strlen(pwd)); | |
61 md5_finish(&md5state, md5pword); | |
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 | 64 } |
65 bmp_cfg_db_close(cfgfile); | |
66 } | |
67 } | |
68 | |
69 /* Generated by glade, sorta. */ | |
70 GtkWidget * | |
71 create_cfgdlg(void) | |
694 | 72 { |
1176 | 73 ConfigDb *db; |
694 | 74 GtkWidget *vbox2; |
75 GtkWidget *table1; | |
76 GtkWidget *label3; | |
77 GtkWidget *hseparator2; | |
78 GtkWidget *hseparator3; | |
79 GtkWidget *label1; | |
80 GtkWidget *label2; | |
81 GtkWidget *hseparator1; | |
82 GtkWidget *hbuttonbox1; | |
83 GtkWidget *button5; | |
84 GtkWidget *button6; | |
85 | |
86 vbox2 = gtk_vbox_new (FALSE, 0); | |
87 | |
88 table1 = gtk_table_new (4, 2, FALSE); | |
89 gtk_widget_show (table1); | |
90 gtk_box_pack_start (GTK_BOX (vbox2), table1, FALSE, FALSE, 0); | |
91 | |
92 entry2 = gtk_entry_new (); | |
93 gtk_widget_show (entry2); | |
94 gtk_table_attach (GTK_TABLE (table1), entry2, 1, 2, 3, 4, | |
95 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), | |
96 (GtkAttachOptions) (0), 0, 0); | |
97 | |
98 label3 = gtk_label_new (_("Password:")); | |
99 gtk_widget_show (label3); | |
100 gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 3, 4, | |
101 (GtkAttachOptions) (GTK_FILL), | |
102 (GtkAttachOptions) (0), 0, 0); | |
103 gtk_label_set_justify (GTK_LABEL (label3), GTK_JUSTIFY_RIGHT); | |
104 gtk_misc_set_alignment (GTK_MISC (label3), 1, 0.5); | |
105 | |
106 hseparator2 = gtk_hseparator_new (); | |
107 gtk_widget_show (hseparator2); | |
108 gtk_table_attach (GTK_TABLE (table1), hseparator2, 0, 1, 1, 2, | |
109 (GtkAttachOptions) (GTK_FILL), | |
110 (GtkAttachOptions) (0), 0, 0); | |
111 | |
112 hseparator3 = gtk_hseparator_new (); | |
113 gtk_widget_show (hseparator3); | |
114 gtk_table_attach (GTK_TABLE (table1), hseparator3, 1, 2, 1, 2, | |
115 (GtkAttachOptions) (GTK_FILL), | |
116 (GtkAttachOptions) (0), 0, 0); | |
117 | |
118 label1 = gtk_label_new (_("<b>Scrobbler Preferences</b>")); | |
119 gtk_widget_show (label1); | |
120 gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1, | |
121 (GtkAttachOptions) (GTK_FILL), | |
122 (GtkAttachOptions) (0), 0, 0); | |
123 gtk_label_set_use_markup (GTK_LABEL (label1), TRUE); | |
124 gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5); | |
125 | |
126 label2 = gtk_label_new (_("Username:")); | |
127 gtk_widget_show (label2); | |
128 gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 2, 3, | |
129 (GtkAttachOptions) (GTK_FILL), | |
130 (GtkAttachOptions) (0), 0, 0); | |
131 gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_RIGHT); | |
132 gtk_misc_set_alignment (GTK_MISC (label2), 1, 0.5); | |
133 | |
134 entry1 = gtk_entry_new (); | |
135 gtk_widget_show (entry1); | |
136 gtk_table_attach (GTK_TABLE (table1), entry1, 1, 2, 2, 3, | |
137 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), | |
138 (GtkAttachOptions) (0), 0, 0); | |
139 | |
140 hseparator1 = gtk_hseparator_new (); | |
141 gtk_widget_show (hseparator1); | |
142 gtk_box_pack_start (GTK_BOX (vbox2), hseparator1, FALSE, FALSE, 0); | |
143 | |
144 hbuttonbox1 = gtk_hbutton_box_new (); | |
145 gtk_widget_show (hbuttonbox1); | |
146 gtk_box_pack_start (GTK_BOX (vbox2), hbuttonbox1, FALSE, FALSE, 0); | |
147 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END); | |
148 gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 5); | |
149 | |
150 button5 = gtk_button_new_from_stock ("gtk-ok"); | |
151 gtk_widget_show (button5); | |
152 gtk_container_add (GTK_CONTAINER (hbuttonbox1), button5); | |
153 GTK_WIDGET_SET_FLAGS (button5, GTK_CAN_DEFAULT); | |
154 | |
695 | 155 gtk_signal_connect(GTK_OBJECT(button5), "clicked", |
1181 | 156 GTK_SIGNAL_FUNC(saveconfig), NULL); |
695 | 157 |
694 | 158 button6 = gtk_button_new_from_stock ("gtk-close"); |
159 gtk_widget_show (button6); | |
160 gtk_container_add (GTK_CONTAINER (hbuttonbox1), button6); | |
161 GTK_WIDGET_SET_FLAGS (button6, GTK_CAN_DEFAULT); | |
162 | |
1176 | 163 gtk_entry_set_text(GTK_ENTRY(entry1), ""); |
164 gtk_entry_set_text(GTK_ENTRY(entry2), ""); | |
165 | |
166 if ((db = bmp_cfg_db_open())) { | |
167 gchar *username = NULL; | |
168 bmp_cfg_db_get_string(db, "audioscrobbler", "username", | |
169 &username); | |
170 if (username) { | |
171 gtk_entry_set_text(GTK_ENTRY(entry1), username); | |
172 g_free(username); | |
173 } | |
174 bmp_cfg_db_close(db); | |
175 } | |
176 | |
1181 | 177 return vbox2; |
694 | 178 } |
179 |