[gnome-initial-setup] gnome-initial-setup: Add a page skip mechanism
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup] gnome-initial-setup: Add a page skip mechanism
- Date: Fri, 18 Jan 2013 02:19:00 +0000 (UTC)
commit 4c2b1d461b672220ff4f536df739095b1e5b0876
Author: Michael Wood <michael g wood intel com>
Date: Thu Jan 10 14:06:15 2013 +0000
gnome-initial-setup: Add a page skip mechanism
Add skip pages mechanism, e.g. those which require higher privileges.
A new mode --session has been added which will skip those pages.
Any page can be skipped by adding it to the skip_pages file.
gnome-initial-setup/gnome-initial-setup.c | 132 ++++++++++++++++++++--
gnome-initial-setup/pages/eulas/gis-eula-pages.c | 2 +-
gnome-initial-setup/pages/eulas/gis-eula-pages.h | 2 +-
3 files changed, 123 insertions(+), 13 deletions(-)
---
diff --git a/gnome-initial-setup/gnome-initial-setup.c b/gnome-initial-setup/gnome-initial-setup.c
index e63584d..eff5168 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -26,6 +26,7 @@
#include "gnome-initial-setup.h"
#include <stdlib.h>
+#include <glib/gi18n.h>
#ifdef HAVE_CLUTTER
#include <clutter-gtk/clutter-gtk.h>
@@ -48,18 +49,108 @@
/* main {{{1 */
+
+static gboolean session_setup_mode;
+static const gchar *system_setup_pages[] = {
+ "account",
+ "location"
+};
+
+typedef void (*PreparePage) (GisDriver *driver);
+
+typedef struct {
+ const gchar *page_id;
+ PreparePage prepare_page_func;
+} PageData;
+
+
+#define ADD_PAGE(pages, NAME) \
+ page_data = g_slice_new0 (PageData); \
+ page_data->page_id = #NAME; \
+ page_data->prepare_page_func = gis_prepare_ ## NAME ## _page; \
+ pages = g_list_append (pages, page_data);
+
+static GList*
+new_pages_table (void)
+{
+ GList *pages = NULL;
+
+ PageData *page_data;
+
+ ADD_PAGE (pages, language);
+ ADD_PAGE (pages, keyboard);
+ ADD_PAGE (pages, eula);
+ ADD_PAGE (pages, network);
+ ADD_PAGE (pages, account);
+ ADD_PAGE (pages, location);
+ ADD_PAGE (pages, goa);
+ ADD_PAGE (pages, summary);
+
+ return pages;
+}
+
+static gboolean
+should_skip_page (const gchar *page_id, gchar **skip_pages)
+{
+ guint i = 0;
+ /* check through our skip pages list for pages we don't want */
+ if (skip_pages) {
+ while (skip_pages[i]) {
+ if (g_strcmp0 (skip_pages[i], page_id) == 0)
+ return TRUE;
+ i++;
+ }
+ }
+
+ if (session_setup_mode) {
+ i = 0;
+ while (i < G_N_ELEMENTS (system_setup_pages)) {
+ if (g_strcmp0 (system_setup_pages[i], page_id) == 0)
+ return TRUE;
+ i++;
+ }
+ }
+
+ return FALSE;
+}
+
+static gchar **
+pages_to_skip_from_file (void)
+{
+ GKeyFile *skip_pages_file;
+ gchar **skip_pages;
+
+ skip_pages_file = g_key_file_new ();
+ /* TODO: put the skipfile somewhere sensible */
+ if (g_key_file_load_from_file (skip_pages_file, "/tmp/skip_pages_file",
+ G_KEY_FILE_NONE,
+ NULL)) {
+ skip_pages = g_key_file_get_string_list (skip_pages_file, "pages", "skip",
+ NULL, NULL);
+ g_key_file_free (skip_pages_file);
+
+ return skip_pages;
+ }
+
+ return NULL;
+}
+
static void
-rebuild_pages_cb (GisDriver *driver)
+rebuild_pages_cb (GisDriver *driver, GList *pages)
{
- gis_assistant_destroy_all_pages (gis_driver_get_assistant (driver));
- gis_prepare_language_page (driver);
- gis_prepare_keyboard_page (driver);
- gis_prepare_eula_pages (driver);
- gis_prepare_network_page (driver);
- gis_prepare_account_page (driver);
- gis_prepare_location_page (driver);
- gis_prepare_goa_page (driver);
- gis_prepare_summary_page (driver);
+ GList *pages_itr = NULL;
+ gchar **skip_pages;
+
+ skip_pages = pages_to_skip_from_file ();
+
+ for (pages_itr = pages; pages_itr != NULL; pages_itr = pages_itr->next) {
+ PageData *page_data = pages_itr->data;
+
+ if (!should_skip_page (page_data->page_id, skip_pages))
+ page_data->prepare_page_func (driver);
+ }
+
+ g_strfreev (skip_pages);
}
int
@@ -67,6 +158,22 @@ main (int argc, char *argv[])
{
GisDriver *driver;
int status;
+ GOptionContext *context;
+ GList *pages;
+
+ pages = new_pages_table ();
+
+ GOptionEntry entries[] =
+ {
+ { "session", 'u', 0, G_OPTION_ARG_NONE, &session_setup_mode,
+ _("Session setup mode"), NULL },
+ { NULL }
+ };
+
+ context = g_option_context_new ("- GNOME initial setup");
+ g_option_context_add_main_entries (context, entries, NULL);
+
+ g_option_context_parse (context, &argc, &argv, NULL);
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -88,9 +195,12 @@ main (int argc, char *argv[])
g_type_ensure (EGG_TYPE_LIST_BOX);
driver = gis_driver_new ();
- g_signal_connect (driver, "rebuild-pages", G_CALLBACK (rebuild_pages_cb), NULL);
+ g_signal_connect (driver, "rebuild-pages", G_CALLBACK (rebuild_pages_cb), pages);
status = g_application_run (G_APPLICATION (driver), argc, argv);
+
g_object_unref (driver);
+ g_option_context_free (context);
+ g_list_free (pages);
return status;
}
diff --git a/gnome-initial-setup/pages/eulas/gis-eula-pages.c b/gnome-initial-setup/pages/eulas/gis-eula-pages.c
index f9cbb33..0524b0f 100644
--- a/gnome-initial-setup/pages/eulas/gis-eula-pages.c
+++ b/gnome-initial-setup/pages/eulas/gis-eula-pages.c
@@ -375,7 +375,7 @@ gis_eula_page_init (GisEulaPage *page)
}
void
-gis_prepare_eula_pages (GisDriver *driver)
+gis_prepare_eula_page (GisDriver *driver)
{
gchar *eulas_dir_path;
GFile *eulas_dir;
diff --git a/gnome-initial-setup/pages/eulas/gis-eula-pages.h b/gnome-initial-setup/pages/eulas/gis-eula-pages.h
index 063f8db..d87f05f 100644
--- a/gnome-initial-setup/pages/eulas/gis-eula-pages.h
+++ b/gnome-initial-setup/pages/eulas/gis-eula-pages.h
@@ -55,7 +55,7 @@ struct _GisEulaPageClass
GType gis_eula_page_get_type (void);
-void gis_prepare_eula_pages (GisDriver *driver);
+void gis_prepare_eula_page (GisDriver *driver);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]