Little fix and update theme.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Thu, 18 Aug 2011 10:34:36 +0000 (18:34 +0800)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Thu, 18 Aug 2011 10:34:36 +0000 (18:34 +0800)
data/themes/Industrial/gtkrc
src/lightdm-gtk-builder-greeter.c

index 17a4a0c..fcd440e 100644 (file)
@@ -18,4 +18,4 @@ style "bottom"
 
 widget "win.*.time" style "time"
 widget "win.*.prompt" style "prompt"
-widget_class "GtkWindow.*.<GtkLabel>" style "bottom"
+widget "win.*.bottom_hbox.*" style "bottom"
index e3416a2..ec090a1 100644 (file)
@@ -55,6 +55,33 @@ static GOptionEntry option_entries[] =
     { NULL }
 };
 
+static void select_session(const char *session)
+{
+    GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(sessions_combo));
+    GtkTreeIter iter;
+
+    if(!session)
+        session = lightdm_greeter_get_default_session_hint(greeter);
+
+    if(session && gtk_tree_model_get_iter_first(model, &iter))
+    {
+        do
+        {
+            char* key;
+            gtk_tree_model_get(model, &iter, 1, &key, -1);
+            if(g_strcmp0(key, session) == 0)
+            {
+                gtk_combo_box_set_active_iter(GTK_COMBO_BOX(sessions_combo), &iter);
+                g_free(key);
+                break;
+            }
+            g_free(key);
+        }
+        while (gtk_tree_model_iter_next(model, &iter));
+    }
+    g_debug("FIXME: select_session failed to find session named: %s", session);
+}
+
 
 static void on_show_message(LightDMGreeter *greeter, gchar* text,
                            LightDMMessageType type, gpointer user_data)
@@ -65,6 +92,8 @@ static void on_show_message(LightDMGreeter *greeter, gchar* text,
 static void on_show_prompt(LightDMGreeter *greeter, gchar* text,
                            LightDMPromptType type, gpointer user_data)
 {
+    const char* user_name;
+
     gtk_label_set_text(GTK_LABEL(prompt), text);
     gtk_entry_set_text(GTK_ENTRY(login_entry), "");
     gtk_widget_set_sensitive(login_entry, TRUE);
@@ -72,32 +101,17 @@ static void on_show_prompt(LightDMGreeter *greeter, gchar* text,
 
     gtk_entry_set_visibility(GTK_ENTRY(login_entry),
                              type != LIGHTDM_PROMPT_TYPE_SECRET);
-}
 
-static void set_session (const char *session)
-{
-    GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(sessions_combo));
-    GtkTreeIter iter;
-    if(session && gtk_tree_model_get_iter_first(model, &iter))
+    user_name = lightdm_greeter_get_authentication_user(greeter);
+    if(user_name) /* update UI for the user */
     {
-        do
-        {
-            char* key;
-            gtk_tree_model_get(model, &iter, 1, &key, -1);
-            if(g_strcmp0(key, session) == 0)
-            {
-                gtk_combo_box_set_active_iter(GTK_COMBO_BOX(sessions_combo), &iter);
-                g_free(key);
-                break;
-            }
-            g_free(key);
-        }
-        while (gtk_tree_model_iter_next(model, &iter));
+        LightDMUser* user = lightdm_user_list_get_user_by_name(lightdm_user_list_get_instance(),
+                                                               user_name);
+        select_session(user ? lightdm_user_get_session(user) : NULL);
     }
-    g_debug("FIXME: set_session failed to find session named: %s", session);
 }
 
-static const char* get_lang()
+static const char* get_selected_language()
 {
     GtkTreeIter it;
     if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(lang_combo), &it))
@@ -112,7 +126,7 @@ static const char* get_lang()
     return NULL;
 }
 
-static void set_lang(const char *lang)
+static void select_language(const char *lang)
 {
     GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(lang_combo));
     GtkTreeIter iter;
@@ -136,10 +150,14 @@ static void authenticate_user(const gchar *username)
 {
     LightDMUser *user;
     user = lightdm_user_list_get_user_by_name(lightdm_user_list_get_instance(), username);
+    g_debug("authenticate user: %s", user);
     if(user)
-        set_session(lightdm_user_get_session(user));
+    {
+        select_session(lightdm_user_get_session(user));
+        g_debug("user session: %s", lightdm_user_get_session(user));
+    }
     else
-        set_session(NULL);
+        select_session(NULL);
     lightdm_greeter_authenticate(greeter, username);
 }
 
@@ -184,6 +202,9 @@ static void start_session(void)
     g_key_file_free(dmrc);
 #endif
 
+    /* const char* language = get_selected_language();
+     * We can do nothing here as LightDM does not support changing language. */
+
     if(!lightdm_greeter_start_session_sync(greeter, session, &err))
     {
         // set_message_label (_("Failed to start session"));
@@ -281,7 +302,7 @@ static void load_sessions()
     g_object_unref(store);
 }
 
-static void load_langs()
+static void load_languages()
 {
     GtkTreeIter it, active_it = {0};
     const LightDMLanguage* default_lang = lightdm_get_language();
@@ -353,15 +374,11 @@ static void load_exit_btn()
 
 static void on_login_entry_activate(GtkEntry* entry, gpointer user_data)
 {
-    gtk_widget_set_sensitive (GTK_WIDGET(entry), FALSE);
+    gtk_widget_set_sensitive(GTK_WIDGET(entry), FALSE);
     // set_message_label ("");
 
-    if (lightdm_greeter_get_is_authenticated(greeter))
-        start_session();
-    else if(lightdm_greeter_get_in_authentication (greeter))
+    if(G_LIKELY(lightdm_greeter_get_in_authentication(greeter)))
         lightdm_greeter_respond(greeter, gtk_entry_get_text(entry));
-    else
-        authenticate_user(lightdm_greeter_get_authentication_user(greeter));
 }
 
 static gboolean show_ui()
@@ -370,6 +387,7 @@ static gboolean show_ui()
     GdkScreen* scr;
     GtkWidget* w;
     GdkCursor* cursor;
+    GSList* objects, *l;
 
     /* we don't want to use the theme mechanism provided by lightdm. */
     GtkBuilder* builder = gtk_builder_new();
@@ -381,6 +399,19 @@ static gboolean show_ui()
         return FALSE;
     }
 
+    /* set widget names for theming */
+    objects = gtk_builder_get_objects(builder);
+    for(l = objects; l; l=l->next)
+    {
+        if(GTK_IS_WIDGET(l->data))
+        {
+            GtkWidget* widget = (GtkWidget*)l->data;
+            gtk_widget_set_name(widget,
+                                gtk_buildable_get_name(GTK_BUILDABLE(widget)));
+        }
+    }
+    g_slist_free(objects);
+
     win = GTK_WIDGET (gtk_builder_get_object(builder, "win"));
     scr = gtk_widget_get_screen(win);
     g_signal_connect(scr, "size-changed", G_CALLBACK(on_screen_size_changed), win);
@@ -408,14 +439,12 @@ static gboolean show_ui()
 #endif
 
     sessions_combo = (GtkWidget*)gtk_builder_get_object(builder, "sessions");
-    gtk_widget_set_name(sessions_combo, "sessions");
     fix_combobox_entry(sessions_combo);
     load_sessions();
 
     lang_combo = (GtkWidget*)gtk_builder_get_object(builder, "lang");
-    gtk_widget_set_name(lang_combo, "lang_combo");
     fix_combobox_entry(lang_combo);
-    load_langs();
+    load_languages();
 
     if( w = (GtkWidget*)gtk_builder_get_object(builder, "time") )
     {
@@ -423,7 +452,6 @@ static gboolean show_ui()
         g_signal_connect_swapped(w, "destroy",
             G_CALLBACK(g_source_remove), GUINT_TO_POINTER(timeout));
         on_timeout((GtkLabel*)w);
-        gtk_widget_set_name(w, "time");
     }
 
     exit_btn = (GtkWidget*)gtk_builder_get_object(builder, "exit_btn");
@@ -432,7 +460,13 @@ static gboolean show_ui()
     g_object_unref(builder);
 
     gtk_window_set_decorated(GTK_WINDOW(win), FALSE);
-    gtk_window_set_default_size( GTK_WINDOW(win), gdk_screen_get_width(scr), gdk_screen_get_height(scr) );
+    gtk_window_set_default_size(GTK_WINDOW(win),
+                                gdk_screen_get_width(scr),
+                                gdk_screen_get_height(scr) );
+#if GTK_CHECK_VERSION(3, 0, 0)
+    gtk_window_set_has_resize_grip(GTK_WINDOW(win), FALSE);
+#endif
+    gtk_window_fullscreen(GTK_WINDOW(win));
 
     gtk_window_present( GTK_WINDOW(win) );