static void
local_create_user (UmAccountDialog *self)
{
        UmUserManager *manager;
        const gchar *username;
        const gchar *name;
        gint account_type;
        GtkTreeModel *model;
        GtkTreeIter iter;

        begin_action (self);

        name = gtk_entry_get_text (GTK_ENTRY (self->local_name));
        username = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (self->local_username));
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (self->local_account_type));
        gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self->local_account_type), &iter);
        gtk_tree_model_get (model, &iter, 1, &account_type, -1);

        g_debug ("Creating local user: %s", username);

        manager = um_user_manager_ref_default ();
        um_user_manager_create_user (manager,
                                     username,
                                     name,
                                     account_type,
                                     self->cancellable,
                                     (GAsyncReadyCallback)create_user_done,
                                     self,
                                     NULL);
        g_object_unref (manager);
}
Esempio n. 2
0
static void
um_user_panel_init (UmUserPanel *self)
{
        UmUserPanelPrivate *d;
        GError *error;
        volatile GType type G_GNUC_UNUSED;
        const gchar *filename;
        GtkWidget *button;
        GtkStyleContext *context;

        d = self->priv = UM_USER_PANEL_PRIVATE (self);

        /* register types that the builder might need */
        type = cc_strength_bar_get_type ();
        type = um_editable_button_get_type ();
        type = cc_editable_entry_get_type ();
        type = um_editable_combo_get_type ();

        gtk_widget_set_size_request (GTK_WIDGET (self), -1, 350);

        d->builder = gtk_builder_new ();
        d->um = um_user_manager_ref_default ();

        filename = UIDIR "/user-accounts-dialog.ui";
        if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
                filename = "data/user-accounts-dialog.ui";
        }
        error = NULL;
        if (!gtk_builder_add_from_file (d->builder, filename, &error)) {
                g_error ("%s", error->message);
                g_error_free (error);
                return;
        }

        setup_main_window (d);
        d->account_dialog = um_account_dialog_new ();
        d->password_dialog = um_password_dialog_new ();
        button = get_widget (d, "user-icon-button");
        d->photo_dialog = um_photo_dialog_new (button);
        d->main_box = get_widget (d, "accounts-vbox");
        gtk_widget_reparent (d->main_box, GTK_WIDGET (self));

        context = gtk_widget_get_style_context (get_widget (d, "list-scrolledwindow"));
        gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
        context = gtk_widget_get_style_context (get_widget (d, "add-remove-toolbar"));
        gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
}
static void
on_permit_user_login (GObject *source,
                      GAsyncResult *result,
                      gpointer user_data)
{
        UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
        UmRealmCommon *common;
        UmUserManager *manager;
        GError *error = NULL;
        gchar *login;

        common = UM_REALM_COMMON (source);
        um_realm_common_call_change_login_policy_finish (common, result, &error);
        if (error == NULL) {

                /*
                 * Now tell the account service about this user. The account service
                 * should also lookup information about this via the realm and make
                 * sure all that is functional.
                 */
                manager = um_user_manager_ref_default ();
                login = um_realm_calculate_login (common, gtk_entry_get_text (self->enterprise_login));
                g_return_if_fail (login != NULL);

                g_debug ("Caching remote user: %s", login);

                um_user_manager_cache_user (manager, login, self->cancellable,
                                            on_register_user, g_object_ref (self),
                                            g_object_unref);

                g_free (login);
                g_object_unref (manager);

        } else {
                show_error_dialog (self, _("Failed to register account"), error);
                g_message ("Couldn't permit logins on account: %s", error->message);
                finish_action (self);
        }

        g_object_unref (self);
}
void
um_add_user_languages (GtkWidget *combo)
{
        GHashTable *seen;
        GSList *users, *l;
        UmUser *user;
        const char *lang;
        char *name;
        char *language;
        GtkTreeIter iter;
        UmUserManager *manager;
        GtkTreeModel *model;
        GtkListStore *store;

        model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
        store = GTK_LIST_STORE (model);

        gtk_list_store_clear (store);

        seen = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

        manager = um_user_manager_ref_default ();
        users = um_user_manager_list_users (manager);
        g_object_unref (manager);

        for (l = users; l; l = l->next) {
                user = l->data;
                lang = um_user_get_language (user);
                if (!lang || !language_has_font (lang)) {
                        continue;
                }

                name = gdm_normalize_language_name (lang);

                if (g_hash_table_lookup (seen, name)) {
                        g_free (name);
                        continue;
                }

                g_hash_table_insert (seen, name, GINT_TO_POINTER (TRUE));

                language = gdm_get_language_from_name (name, NULL);
                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter, LOCALE_COL, name, DISPLAY_LOCALE_COL, language, -1);

                g_free (language);
        }

        g_slist_free (users);

        /* Make sure the current locale is present */
        lang = (const gchar *) setlocale (LC_MESSAGES, NULL);
        name = gdm_normalize_language_name (lang);

        if (!g_hash_table_lookup (seen, name)) {
                language = gdm_get_language_from_name (name, NULL);
                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter, LOCALE_COL, name, DISPLAY_LOCALE_COL, language, -1);
                g_free (language);
        }

        g_free (name);

        g_hash_table_destroy (seen);

        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter, LOCALE_COL, NULL, DISPLAY_LOCALE_COL, _("Other..."), -1);
}
UmLoginOptions *
um_login_options_new (GtkBuilder *builder)
{
        GtkWidget *widget;
        GtkWidget *box;
        GtkListStore *store;
        GtkTreeIter iter;
        GError *error;
        UmLoginOptions *um;

        /* TODO: get actual login screen options */

        um = g_new0 (UmLoginOptions, 1);

        um->manager = um_user_manager_ref_default ();
        g_signal_connect (um->manager, "users-loaded",
                          G_CALLBACK (users_loaded), um);

        widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-automatic-login-combobox");
        um->autologin_combo = widget;

        store = gtk_list_store_new (2, G_TYPE_STRING, UM_TYPE_USER);
        gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter,
                            AUTOLOGIN_NAME_COL, _("Disabled"),
                            AUTOLOGIN_USER_COL, NULL,
                            -1);

        gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);

        gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store), sort_login_users, NULL, NULL);
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);

        g_signal_connect (widget, "changed",
                          G_CALLBACK (update_autologin), um);

        widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-show-user-list-checkbutton");
        um->userlist_check = widget;
        g_signal_connect (widget, "toggled",
                          G_CALLBACK (update_login_options), um);
        g_object_set_data (G_OBJECT (widget), "gconf-key",
                           "/apps/gdm/simple-greeter/disable_user_list");
        update_boolean_from_gconf (widget, um);

        widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-show-power-buttons-checkbutton");
        um->power_check = widget;
        g_signal_connect(widget, "toggled",
                         G_CALLBACK (update_login_options), um);
        g_object_set_data (G_OBJECT (widget), "gconf-key",
                           "/apps/gdm/simple-greeter/disable_restart_buttons");
        update_boolean_from_gconf (widget, um);

        widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-show-password-hints-checkbutton");
        um->hints_check = widget;
        g_signal_connect (widget, "toggled",
                          G_CALLBACK (update_login_options), um);

        widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-allow-guest-login-checkbutton");
        um->guest_check = widget;
        g_signal_connect (widget, "toggled",
                          G_CALLBACK (update_login_options), um);

        widget = polkit_lock_button_new ("org.freedesktop.accounts.set-login-option");
        gtk_widget_show (widget);
        box = (GtkWidget *)gtk_builder_get_object (builder, "lockbutton-alignment");
        gtk_container_add (GTK_CONTAINER (box), widget);
        g_signal_connect (widget, "changed",
                          G_CALLBACK (lockbutton_changed), um);
        lockbutton_changed (POLKIT_LOCK_BUTTON (widget), um);
        um->lock_button = widget;

        error = NULL;
        um->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
        if (error != NULL) {
                g_warning ("Failed to get system bus connection: %s", error->message);
                g_error_free (error);
        }

        um->proxy = dbus_g_proxy_new_for_name (um->connection,
                                               "org.gnome.GConf.Defaults",
                                               "/",
                                               "org.gnome.GConf.Defaults");

        if (um->proxy == NULL) {
                g_warning ("Cannot connect to GConf defaults mechanism");
        }

        return um;
}
void
um_photo_dialog_set_user (UmPhotoDialog *um,
                          UmUser        *user)
{
        UmUserManager *manager;
        GSList *list, *l;
        UmUser *u;
        GIcon *icon;
        GEmblem *emblem;
        GList *children, *c;

        g_return_if_fail (um != NULL);

        if (um->user) {
                g_object_unref (um->user);
                um->user = NULL;
        }
        um->user = user;

        if (um->user) {
                g_object_ref (um->user);

                children = gtk_container_get_children (GTK_CONTAINER (um->photo_popup));
                g_list_foreach (children, (GFunc) clear_tip, NULL);

                manager = um_user_manager_ref_default ();
                list = um_user_manager_list_users (manager);
                g_object_unref (manager);

                icon = g_themed_icon_new ("avatar-default");
                emblem = g_emblem_new (icon);
                g_object_unref (icon);

                for (l = list; l; l = l->next) {
                        const char *filename;

                        u = l->data;
                        if (u == user)
                                continue;
                        filename = um_user_get_icon_file (u);
                        if (filename  == NULL)
                                continue;
                        for (c = children; c; c = c->next) {
                                const char *f;

                                f = g_object_get_data (G_OBJECT (c->data), "filename");
                                if (f == NULL)
                                        continue;
                                if (strcmp (f, filename) == 0) {
                                        char *tip;

                                        tip = g_strdup_printf (_("Used by %s"),
                                                               um_user_get_real_name (u));
                                        set_tip (GTK_WIDGET (c->data), tip, emblem);
                                        g_free (tip);
                                        break;
                                }
                        }
                }
                g_slist_free (list);

                g_object_unref (emblem);
        }
}