changeset 2943:d3e42ee17c93

added password prompt
author Andrew O. Shadoura <bugzilla@tut.by>
date Sun, 28 Sep 2008 19:12:11 +0300
parents 233cb5dffbf7
children d93a97ce253d
files src/scrobbler/configure.c
diffstat 1 files changed, 55 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/scrobbler/configure.c	Sat Sep 27 19:04:32 2008 +0200
+++ b/src/scrobbler/configure.c	Sun Sep 28 19:12:11 2008 +0300
@@ -20,6 +20,7 @@
 #include "plugin.h"
 
 GtkWidget *entry1, *entry2, *ge_entry1, *ge_entry2, *cfgdlg;
+static GdkColor disabled_color;
 guint apply_timeout = 0; /* ID of timeout to save new config */
 gboolean running = TRUE; /* if plugin threads are running */
 
@@ -40,14 +41,15 @@
         return buf;
 }
 
+static char *pwd = NULL;
+static char *ge_pwd = NULL;
+
 static void saveconfig(void)
 {
     mcs_handle_t *cfgfile;
 
     const char *uid = gtk_entry_get_text(GTK_ENTRY(entry1));
-    const char *pwd = gtk_entry_get_text(GTK_ENTRY(entry2));
     const char *ge_uid = gtk_entry_get_text(GTK_ENTRY(ge_entry1));
-    const char *ge_pwd = gtk_entry_get_text(GTK_ENTRY(ge_entry2));
 
     if ((cfgfile = aud_cfg_db_open())) {
         aud_md5state_t md5state;
@@ -99,6 +101,8 @@
         apply_timeout = 0;
         saveconfig();
     }
+    g_free(pwd);
+    g_free(ge_pwd);
 }
 
 static void
@@ -115,6 +119,31 @@
     apply_timeout = g_timeout_add_seconds(10, (GSourceFunc) apply_config_changes, NULL);
 }
 
+static void entry_focus_in(GtkWidget *widget, gpointer data)
+{
+  gtk_entry_set_text(GTK_ENTRY(widget), "");
+  gtk_entry_set_visibility(GTK_ENTRY(widget), FALSE);
+  gtk_widget_modify_text(widget, GTK_STATE_NORMAL, NULL);
+}
+
+static void entry_focus_out(GtkWidget *widget, gpointer data)
+{
+  if (widget == entry2)
+  {
+    g_free(pwd);
+    pwd = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry2)));
+  }
+  if (widget == ge_entry2)
+  {
+    g_free(ge_pwd);
+    ge_pwd = g_strdup(gtk_entry_get_text(GTK_ENTRY(ge_entry2)));
+  }
+  entry_changed(widget, data);
+  gtk_entry_set_text(GTK_ENTRY(widget), "Change password");
+  gtk_widget_modify_text(widget, GTK_STATE_NORMAL, &disabled_color);
+  gtk_entry_set_visibility(GTK_ENTRY(widget), TRUE);
+}
+
 /* Generated by glade, sorta. */
 GtkWidget *
 create_cfgdlg(void)
@@ -128,6 +157,7 @@
   GtkWidget *himage1;
   GtkWidget *align1;
   GtkWidget *notebook1;
+  GtkStyle *style;
 
   vbox2 = gtk_vbox_new (FALSE, 0);
 
@@ -172,7 +202,18 @@
   gtk_table_attach_defaults (GTK_TABLE (table1), entry1, 1, 2, 2, 3);
 
   entry2 = gtk_entry_new ();
-  gtk_entry_set_visibility(GTK_ENTRY(entry2), FALSE);
+
+  style = gtk_widget_get_style(entry2);
+  memcpy(&disabled_color, &(style->text[GTK_STATE_INSENSITIVE]), sizeof(GdkColor));
+  gtk_widget_modify_text(entry2, GTK_STATE_NORMAL, &disabled_color);
+
+  gtk_entry_set_text(GTK_ENTRY(entry2), "Change password");
+  g_signal_connect(G_OBJECT(entry2), "focus-in-event",
+                   G_CALLBACK(entry_focus_in),
+                   NULL);
+  g_signal_connect(G_OBJECT(entry2), "focus-out-event",
+                   G_CALLBACK(entry_focus_out),
+                   NULL);
   gtk_widget_show (entry2);
   gtk_table_attach_defaults (GTK_TABLE (table1), entry2, 1, 2, 3, 4);
 
@@ -211,7 +252,16 @@
   gtk_table_attach_defaults (GTK_TABLE (table1), ge_entry1, 1, 2, 2, 3);
 
   ge_entry2 = gtk_entry_new ();
-  gtk_entry_set_visibility(GTK_ENTRY(ge_entry2), FALSE);
+  gtk_widget_modify_text(ge_entry2, GTK_STATE_NORMAL, &disabled_color);
+
+  gtk_entry_set_text(GTK_ENTRY(ge_entry2), "Change password");
+  g_signal_connect(G_OBJECT(ge_entry2), "focus-in-event",
+                   G_CALLBACK(entry_focus_in),
+                   NULL);
+  g_signal_connect(G_OBJECT(ge_entry2), "focus-out-event",
+                   G_CALLBACK(entry_focus_out),
+                   NULL);
+
   gtk_widget_show (ge_entry2);
   gtk_table_attach_defaults (GTK_TABLE (table1), ge_entry2, 1, 2, 3, 4);
 
@@ -228,7 +278,7 @@
   gtk_misc_set_alignment (GTK_MISC (himage1), 1, 0.5);
 
 	gtk_entry_set_text(GTK_ENTRY(entry1), "");
-	gtk_entry_set_text(GTK_ENTRY(entry2), "");
+	gtk_entry_set_text(GTK_ENTRY(ge_entry), "");
 
         if ((db = aud_cfg_db_open())) {
                 gchar *username = NULL;
@@ -253,9 +303,7 @@
         }
 
   g_signal_connect(entry1, "changed", G_CALLBACK(entry_changed), NULL);
-  g_signal_connect(entry2, "changed", G_CALLBACK(entry_changed), NULL);
   g_signal_connect(ge_entry1, "changed", G_CALLBACK(entry_changed), NULL);
-  g_signal_connect(ge_entry2, "changed", G_CALLBACK(entry_changed), NULL);
 
   return vbox2;
 }