[maemo-commits] [maemo-commits] r12092 - in projects/haf/trunk/hildon-plugins-settings: . src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Mon Jun 4 19:39:12 EEST 2007
- Previous message: [maemo-commits] r12091 - in projects/haf/trunk/hildon-desktop: . debian libhildondesktop src
- Next message: [maemo-commits] r12093 - in projects/haf/trunk/hildon-plugins-settings: . src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: moimart Date: 2007-06-04 19:38:46 +0300 (Mon, 04 Jun 2007) New Revision: 12092 Modified: projects/haf/trunk/hildon-plugins-settings/ChangeLog projects/haf/trunk/hildon-plugins-settings/configure.ac projects/haf/trunk/hildon-plugins-settings/src/Makefile.am projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.c projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.h projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.c projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.h projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings.c Log: 2007-06-04 Moises Martinez <moises.martinez at nokia.com> * configure.ac: Look for hildon-desktop headers. * src/hildon-plugin-settings-dialog.[ch]: - First implementation of dialog. * src/hildon-plugin-config-parser.[ch]: - Fixed several bugs. * src/hildon-plugin-settings.c: - Use the new dialog, not a unit test anymore. * src/Makefile.am: - Added new dialog to build batch. * ChangeLog updated. Modified: projects/haf/trunk/hildon-plugins-settings/ChangeLog =================================================================== --- projects/haf/trunk/hildon-plugins-settings/ChangeLog 2007-06-04 15:41:03 UTC (rev 12091) +++ projects/haf/trunk/hildon-plugins-settings/ChangeLog 2007-06-04 16:38:46 UTC (rev 12092) @@ -1,3 +1,24 @@ +2007-06-04 Moises Martinez <moises.martinez at nokia.com> + + * configure.ac: Look for hildon-desktop headers. + * src/hildon-plugin-settings-dialog.[ch]: + - First implementation of dialog. + * src/hildon-plugin-config-parser.[ch]: + - Fixed several bugs. + * src/hildon-plugin-settings.c: + - Use the new dialog, not a unit test anymore. + * src/Makefile.am: + - Added new dialog to build batch. + +2007-06-04 Moises Martinez <moises.martinez at nokia.com> + + * src/hildon-plugin-config-parser.[ch]: + - Implemented _save method. + - Implemented _compare_with file methos to know what plugins are + loaded. + * src/hildon-plugin-settings.c: + - Still unit test. + 2007-06-01 Moises Martinez <moises.martinez at nokia.com> * configure.ac: Updated. Modified: projects/haf/trunk/hildon-plugins-settings/configure.ac =================================================================== --- projects/haf/trunk/hildon-plugins-settings/configure.ac 2007-06-04 15:41:03 UTC (rev 12091) +++ projects/haf/trunk/hildon-plugins-settings/configure.ac 2007-06-04 16:38:46 UTC (rev 12092) @@ -58,6 +58,9 @@ AC_SUBST(OSSO_LIBS) AC_SUBST(OSSO_CFLAGS) +PKG_CHECK_MODULES(HILDONDESKTOP, hildon-desktop >= 0.0.1) +AC_SUBST(HILDONDESKTOP_CFLAGS) + PKG_CHECK_MODULES(CP,hildon-control-panel >= 0.8.3) AC_SUBST(CP_LIBS) AC_SUBST(CP_CFLAGS) Modified: projects/haf/trunk/hildon-plugins-settings/src/Makefile.am =================================================================== --- projects/haf/trunk/hildon-plugins-settings/src/Makefile.am 2007-06-04 15:41:03 UTC (rev 12091) +++ projects/haf/trunk/hildon-plugins-settings/src/Makefile.am 2007-06-04 16:38:46 UTC (rev 12092) @@ -5,6 +5,7 @@ $(CP_CFLAGS) $(OSSO_CFLAGS) $(GCONF_CFLAGS) \ $(LIBOSSOHELP_CFLAGS) \ $(LIBHILDONMENU_CFLAGS) \ + $(HILDONDESKTOP_CFLAGS) \ -DLOCALEDIR=\"$(localedir)\" \ -DPREFIXDIR=\"$(prefix)\" \ $$(xml2-config --cflags) @@ -22,5 +23,7 @@ libhildonpluginsettings_la_SOURCES = \ hildon-plugin-config-parser.h \ hildon-plugin-config-parser.c \ + hildon-plugin-settings-dialog.h \ + hildon-plugin-settings-dialog.c \ hildon-plugin-settings.c Modified: projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.c =================================================================== --- projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.c 2007-06-04 15:41:03 UTC (rev 12091) +++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.c 2007-06-04 16:38:46 UTC (rev 12092) @@ -30,9 +30,12 @@ #include <glib/gi18n.h> +#include <hildon-desktop/hd-config.h> + #define HP_DESKTOP_GROUP "Desktop Entry" #define HP_PREDEFINED_COLS 3 + #define HILDON_PLUGIN_CONFIG_PARSER_GET_PRIVATE(object) \ (G_TYPE_INSTANCE_GET_PRIVATE ((object), HILDON_PLUGIN_TYPE_CONFIG_PARSER, HildonPluginConfigParserPrivate)) @@ -43,7 +46,7 @@ { HILDON_PLUGIN_CONFIG_PARSER_ERROR_UNKNOWN = 0, HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOKEYS, - HILDON_PLUGIN_CONFIG_PARSER_ERROR_PATHNOEXIST, + HILDON_PLUGIN_CONFIG_PARSER_ERROR_PATHNOEXISTS, HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOFILESINPATH, HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOPATHTOSAVE } @@ -66,14 +69,17 @@ gchar *path_to_save; GtkIconTheme *icon_theme; + + GHashTable *keys_loaded; }; -enum + +typedef struct { - HP_COL_DESKTOP_FILE, - HP_COL_CHECKBOX, - HP_COL_POSITION -}; + guint position; + gboolean loaded; +} +HPCPData; static void hildon_plugin_config_parser_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static void hildon_plugin_config_parser_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); @@ -82,6 +88,8 @@ static GQuark hildon_plugin_config_parser_error_quark (void); +static HPCPData *hildon_plugin_config_parser_new_data (guint position, gboolean loaded); + static void hildon_plugin_config_parser_init (HildonPluginConfigParser *parser) { @@ -102,6 +110,11 @@ g_free, g_free); + parser->priv->keys_loaded = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_free); + parser->priv->icon_theme = gtk_icon_theme_get_default (); } @@ -207,6 +220,7 @@ g_list_free (parser->priv->keys_types); g_hash_table_destroy (parser->keys); + g_hash_table_destroy (parser->priv->keys_loaded); g_free (parser->priv->path_to_read); g_free (parser->priv->path_to_save); @@ -220,6 +234,17 @@ return g_quark_from_static_string ("hildon-plugin-config-parser-error-quark"); } +static HPCPData * +hildon_plugin_config_parser_new_data (guint position, gboolean loaded) +{ + HPCPData *data = g_new (HPCPData,1); + + data->position = position; + data->loaded = loaded; + + return data; +} + static GdkPixbuf * hildon_plugin_config_parser_get_icon (HildonPluginConfigParser *parser, const gchar *icon_name, @@ -286,6 +311,12 @@ HP_COL_POSITION,0, -1); + HPCPData *data = hildon_plugin_config_parser_new_data (0,FALSE); + + g_hash_table_insert (parser->priv->keys_loaded, + g_strdup (filename), + data); + for (l = parser->priv->keys; l != NULL; l = g_list_next (l)) { gchar *_string = NULL; @@ -532,7 +563,7 @@ { g_set_error (error, hildon_plugin_config_parser_error_quark (), - HILDON_PLUGIN_CONFIG_PARSER_ERROR_PATHNOEXIST, + HILDON_PLUGIN_CONFIG_PARSER_ERROR_PATHNOEXISTS, external_error->message); g_error_free (external_error); @@ -572,6 +603,12 @@ hildon_plugin_config_parser_save (HildonPluginConfigParser *parser, GError **error) { + GKeyFile *keyfile; + gchar *keyfile_data; + GtkTreeIter iter; + gsize length; + GError *external_error = NULL; + if (!parser->priv->keys) { g_set_error (error, @@ -592,7 +629,180 @@ return FALSE; } + keyfile = g_key_file_new (); + + gtk_tree_model_get_iter_first (parser->tm, &iter); + + do + { + gchar *desktop_file; + gboolean loaded; + + gtk_tree_model_get (parser->tm, &iter, + HP_COL_DESKTOP_FILE, + &desktop_file, + HP_COL_CHECKBOX, + &loaded, + -1); + + g_key_file_set_boolean (keyfile, + desktop_file, + HD_DESKTOP_CONFIG_KEY_LOAD, + loaded); + + g_free (desktop_file); + } + while (gtk_tree_model_iter_next (parser->tm, &iter)); + + keyfile_data = g_key_file_to_data (keyfile, + &length, + &external_error); + + if (external_error || keyfile_data == NULL) + { + g_set_error (error, + hildon_plugin_config_parser_error_quark (), + HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOKEYS, + external_error->message); + + g_key_file_free (keyfile); + g_error_free (external_error); + + return FALSE; + } + + g_file_set_contents (parser->priv->path_to_save, + keyfile_data, + length, + &external_error); + + if (external_error) + { + g_set_error (error, + hildon_plugin_config_parser_error_quark (), + HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOPATHTOSAVE, + external_error->message); + + g_key_file_free (keyfile); + g_error_free (external_error); + + return FALSE; + } + + g_key_file_free (keyfile); + return TRUE; } +gboolean +hildon_plugin_config_parser_compare_with (HildonPluginConfigParser *parser, + const gchar *filename, + GError **error) +{ + GKeyFile *keyfile; + GError *external_error = NULL; + gsize n_groups; + gchar **groups; + register int i; + GtkTreeIter iter; + if (!filename || !g_file_test (filename, G_FILE_TEST_EXISTS)) + { + g_set_error (error, + hildon_plugin_config_parser_error_quark (), + HILDON_PLUGIN_CONFIG_PARSER_ERROR_PATHNOEXISTS, + "You need to set a valid filename to be compared with the model"); + + return FALSE; + } + + keyfile = g_key_file_new (); + + if (!g_key_file_load_from_file + (keyfile,filename,G_KEY_FILE_NONE,&external_error)) + { + g_set_error (error, + hildon_plugin_config_parser_error_quark (), + HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOKEYS, + external_error->message); + + g_error_free (external_error); + return FALSE; + } + + groups = g_key_file_get_groups (keyfile, + &n_groups); + + if (!groups) + { + g_set_error (error, + hildon_plugin_config_parser_error_quark (), + HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOKEYS, + "I couldn't find valid groups in the file"); + return FALSE; + } + + for (i=0; i < n_groups && groups[i]; i++) + { + GError *error_key = NULL; + gboolean is_to_load = TRUE; + + is_to_load = g_key_file_get_boolean (keyfile, + groups[i], + HD_DESKTOP_CONFIG_KEY_LOAD, + &error_key); + + if (error_key) + { + g_error_free (error_key); + is_to_load = TRUE; + } + + if (is_to_load) + { + HPCPData *data = hildon_plugin_config_parser_new_data (i,TRUE); + + g_hash_table_replace (parser->priv->keys_loaded, + g_strdup (groups[i]), + data); + } + } + + if (gtk_tree_model_get_iter_first (parser->tm, &iter)) + { + do + { + gchar *desktop_file = NULL; + HPCPData *data = NULL; + + gtk_tree_model_get (parser->tm, + &iter, + HP_COL_DESKTOP_FILE, + &desktop_file, + -1); + + data = g_hash_table_lookup (parser->priv->keys_loaded, + desktop_file); + + if (data && data->loaded) + { + gtk_list_store_set (GTK_LIST_STORE (parser->tm), + &iter, + HP_COL_CHECKBOX, + TRUE, + HP_COL_POSITION, + data->position, + -1); + } + + if (desktop_file) + g_free (desktop_file); + } + while (gtk_tree_model_iter_next (parser->tm, &iter)); + } + + g_strfreev (groups); + + return TRUE; +} + Modified: projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.h =================================================================== --- projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.h 2007-06-04 15:41:03 UTC (rev 12091) +++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.h 2007-06-04 16:38:46 UTC (rev 12092) @@ -35,6 +35,14 @@ typedef struct _HildonPluginConfigParserClass HildonPluginConfigParserClass; typedef struct _HildonPluginConfigParserPrivate HildonPluginConfigParserPrivate; +typedef enum +{ + HP_COL_DESKTOP_FILE, + HP_COL_CHECKBOX, + HP_COL_POSITION +} +HildonPluginConfigParserCols; + #define HILDON_PLUGIN_TYPE_CONFIG_PARSER ( hildon_plugin_config_parser_get_type() ) #define HILDON_PLUGIN_CONFIG_PARSER(obj) (GTK_CHECK_CAST (obj, HILDON_PLUGIN_TYPE_CONFIG_PARSER, HildonPluginConfigParser)) #define HILDON_PLUGIN_CONFIG_PARSER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), HILDON_PLUGIN_TYPE_CONFIG_PARSER, HildonPluginConfigParserClass)) @@ -78,6 +86,9 @@ gboolean hildon_plugin_config_parser_save (HildonPluginConfigParser *parser, GError **error); +gboolean +hildon_plugin_config_parser_compare_with (HildonPluginConfigParser *parser, const gchar *filename, GError **error); + G_END_DECLS #endif/*__HILDON_PLUGIN_CONFIG_PARSER_H__*/ Modified: projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.c =================================================================== --- projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.c 2007-06-04 15:41:03 UTC (rev 12091) +++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.c 2007-06-04 16:38:46 UTC (rev 12092) @@ -23,3 +23,427 @@ * */ +#include "hildon-plugin-settings-dialog.h" +#include "hildon-plugin-config-parser.h" + +#include <gtk/gtktreemodelfilter.h> +#include <gtk/gtktreeview.h> +#include <gtk/gtk.h> + +#include <hildon-desktop/hd-config.h> + +#define HPSD_OK "Ok" +#define HPSD_CANCEL "Cancel" + +#define HPSD_TAB_SB "Statusbar" +#define HPSD_TAB_TN "Task Navigator" + +#define HPSD_TITLE "Plugin's Settings" + +#ifndef HP_PATH_TN +#define HP_PATH_TN "/usr/share/applications/hildon-navigator" +#endif + +#ifndef HP_PATH_SB +#define HP_PATH_SB "/usr/share/applications/hildon-status-bar" +#endif + +/* TODO: FIXME: + * This should read /etc/hildon-desktop/desktop.conf and look for panels + * and create as many pages as necessary */ + +#define HP_CONFIG_SB "statusbar.conf" +#define HP_CONFIG_TN "tasknavigator.conf" +#define HP_CONFIG_DESKTOP "desktop.conf" + +#define HP_CONFIG_DEFAULT_PATH "/etc/hildon-desktop" +#define HP_CONFIG_USER_PATH ".osso/hildon-desktop" + +#define HD_DESKTOP_CONFIG_USER_PATH ".osso/hildon-desktop" +#define HD_DESKTOP_CONFIG_PATH "/etc/hildon-desktop" + +#define HILDON_PLUGIN_SETTINGS_DIALOG_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), HILDON_PLUGIN_TYPE_SETTINGS_DIALOG, HildonPluginSettingsDialogPrivate)) + +G_DEFINE_TYPE (HildonPluginSettingsDialog, hildon_plugin_settings_dialog, GTK_TYPE_DIALOG); + +typedef struct +{ + gchar *name; + HildonPluginConfigParser *parser; +} +HPSDTab; + +struct _HildonPluginSettingsDialogPrivate +{ + GList *tabs; + + GtkTreeModelFilter *sb_filter; + GtkTreeModelFilter *tn_filter; +}; + +static GObject *hildon_plugin_settings_dialog_constructor (GType gtype, + guint n_params, + GObjectConstructParam *params); + +static void hildon_plugin_settings_dialog_finalize (GObject *object); + + +static void hildon_plugin_settings_dialog_response (GtkDialog *dialog, gint response_id); + +static void hildon_plugin_settings_dialog_fill_treeview (HildonPluginSettingsDialog *settings, GtkTreeView *tw); + +static gboolean hildon_plugin_settings_parse_desktop_conf (HildonPluginSettingsDialog *settings); + +static void hildon_plugin_settings_dialog_tab_free (HPSDTab *tab); + +static void +hildon_plugin_settings_dialog_init (HildonPluginSettingsDialog *settings) +{ + settings->priv = HILDON_PLUGIN_SETTINGS_DIALOG_GET_PRIVATE (settings); + + settings->sbtm = + settings->tntm = NULL; + + settings->priv->sb_filter = + settings->priv->tn_filter = NULL; + + settings->priv->tabs = NULL; +} + +static void +hildon_plugin_settings_dialog_class_init (HildonPluginSettingsDialogClass *settings_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (settings_class); + GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (settings_class); + + object_class->constructor = hildon_plugin_settings_dialog_constructor; + object_class->finalize = hildon_plugin_settings_dialog_finalize; + + dialog_class->response = hildon_plugin_settings_dialog_response; + + g_type_class_add_private (object_class, sizeof (HildonPluginSettingsDialogPrivate)); + +} + +static GObject * +hildon_plugin_settings_dialog_constructor (GType gtype, + guint n_params, + GObjectConstructParam *params) +{ + GObject *object; + GtkDialog *dialog; + GtkWidget *button_up, + *button_down, + *notebook, + *scrolled_window; + GList *l; + + GError *error = NULL; + HildonPluginSettingsDialog *settings; + + object = + G_OBJECT_CLASS (hildon_plugin_settings_dialog_parent_class)->constructor (gtype, + n_params, + params); + dialog = GTK_DIALOG (object); + settings = HILDON_PLUGIN_SETTINGS_DIALOG (object); + + gtk_window_set_title (GTK_WINDOW (dialog), HPSD_TITLE); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); + gtk_dialog_set_has_separator (dialog, FALSE); + + gtk_widget_set_size_request (GTK_WIDGET (dialog), -1, 300); + + gtk_widget_push_composite_child (); + + gtk_dialog_add_button (dialog, + HPSD_OK, + GTK_RESPONSE_OK); + + button_down = + gtk_dialog_add_button (dialog, + "Up", + GTK_RESPONSE_APPLY); + + button_up = + gtk_dialog_add_button (dialog, + "Down", + GTK_RESPONSE_APPLY); + + gtk_dialog_add_button (dialog, + HPSD_CANCEL, + GTK_RESPONSE_CANCEL); + + notebook = gtk_notebook_new (); + + hildon_plugin_settings_parse_desktop_conf (settings); + + for (l = settings->priv->tabs; l != NULL; l = g_list_next (l)) + { + GtkWidget *tw; + gchar *path_to_save; + gchar *basename; + + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_NEVER, + GTK_POLICY_AUTOMATIC); + + hildon_plugin_config_parser_load (((HPSDTab *)l->data)->parser, &error); + + if (error) + { + tw = gtk_tree_view_new (); + g_error_free (error); + } + else + tw = gtk_tree_view_new_with_model (((HPSDTab *)l->data)->parser->tm); + + hildon_plugin_settings_dialog_fill_treeview (settings, GTK_TREE_VIEW (tw)); + + gtk_container_add (GTK_CONTAINER (scrolled_window), tw); + + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), + scrolled_window, + gtk_label_new (((HPSDTab *)l->data)->name)); + + g_object_get (G_OBJECT (((HPSDTab *)l->data)->parser), + "filename", &path_to_save, + NULL); + + if (!g_file_test (path_to_save, G_FILE_TEST_EXISTS)) + { + basename = g_path_get_basename (path_to_save); + + g_free (path_to_save); + + path_to_save = g_build_filename (HD_DESKTOP_CONFIG_PATH, + basename, + NULL); + g_free (basename); + } + + if (path_to_save) + { + GError *error_comparing = NULL; + hildon_plugin_config_parser_compare_with + (((HPSDTab *)l->data)->parser, path_to_save, &error_comparing); + + if (error_comparing) + { + g_warning ("I couldn't compare files: %s %s", path_to_save, error_comparing->message); + g_error_free (error_comparing); + } + } + } + + gtk_container_add (GTK_CONTAINER (dialog->vbox), notebook); + gtk_widget_show_all (notebook); + + gtk_widget_pop_composite_child (); + + return object; +} + +static void +hildon_plugin_settings_dialog_finalize (GObject *object) +{ + HildonPluginSettingsDialog *settings = + HILDON_PLUGIN_SETTINGS_DIALOG (object); + + g_list_foreach (settings->priv->tabs, + (GFunc)hildon_plugin_settings_dialog_tab_free, + NULL); + + g_list_free (settings->priv->tabs); +} + +static void +hildon_plugin_settings_dialog_response (GtkDialog *dialog, gint response_id) +{ + GList *l; + HildonPluginSettingsDialog *settings = + HILDON_PLUGIN_SETTINGS_DIALOG (dialog); + + GError *error = NULL; + + if (response_id == GTK_RESPONSE_OK) + { + + for (l = settings->priv->tabs; l != NULL; l = g_list_next (l)) + { + hildon_plugin_config_parser_save (((HPSDTab *)l->data)->parser, &error); + + if (error) + { + g_warning ("Error saving... %s",error->message); + g_error_free (error); + } + } + } +} + +static void +hildon_plugin_settings_dialog_fill_treeview (HildonPluginSettingsDialog *settings, GtkTreeView *tw) +{ + GtkCellRenderer *renderer_pixbuf = gtk_cell_renderer_pixbuf_new (), + *renderer_toggle = gtk_cell_renderer_toggle_new (), + *renderer_text = gtk_cell_renderer_text_new (), + *renderer_button = NULL; + + GtkTreeViewColumn *column_pb, + *column_toggle, + *column_text, + *column_button; + + column_pb = + gtk_tree_view_column_new_with_attributes + (NULL, renderer_pixbuf, "pixbuf", 4, NULL); + + column_toggle = + gtk_tree_view_column_new_with_attributes + (NULL, renderer_toggle, "active", HP_COL_CHECKBOX, NULL); + + column_text = + gtk_tree_view_column_new_with_attributes + (NULL, renderer_text, "text", 3, NULL); + + renderer_button = NULL; /*TODO: NOTE: To make compiler happy */ + column_button = NULL; + + gtk_tree_view_append_column (GTK_TREE_VIEW (tw), column_pb); + gtk_tree_view_append_column (GTK_TREE_VIEW (tw), column_toggle); + gtk_tree_view_append_column (GTK_TREE_VIEW (tw), column_text); + /*gtk_tree_view_append_column (GTK_TREE_VIEW (tw), column_button);*/ +} + +static gboolean +hildon_plugin_settings_parse_desktop_conf (HildonPluginSettingsDialog *settings) +{ + GKeyFile *keyfile; + gchar *config_file_path; + gchar **panels; + gsize n_panels; + register gint i; + + config_file_path = g_build_filename (g_get_home_dir (), + HD_DESKTOP_CONFIG_USER_PATH, + HP_CONFIG_DESKTOP, + NULL); + + if (!g_file_test (config_file_path, G_FILE_TEST_EXISTS)) + { + g_free (config_file_path); + + config_file_path = g_build_filename (HD_DESKTOP_CONFIG_PATH, + HP_CONFIG_DESKTOP, + NULL); + + if (!g_file_test (config_file_path, G_FILE_TEST_EXISTS)) + { + g_free (config_file_path); + config_file_path = NULL; + } + } + + if (!config_file_path) + return FALSE; + + keyfile = g_key_file_new (); + + if (!g_key_file_load_from_file + (keyfile,config_file_path,G_KEY_FILE_NONE,NULL)) + { + g_key_file_free (keyfile); + return FALSE; + } + + panels = g_key_file_get_groups (keyfile, &n_panels); + + if (!panels) + { + g_key_file_free (keyfile); + return FALSE; + } + + for (i=0; i < n_panels; i++) + { + HPSDTab *tab; + gchar *config_file = NULL, + *plugin_dir = NULL, + *type = NULL; + + plugin_dir = + g_key_file_get_string (keyfile, + panels[i], + HD_DESKTOP_CONFIG_KEY_PLUGIN_DIR, + NULL); + + type = + g_key_file_get_string (keyfile, + panels[i], + HD_DESKTOP_CONFIG_KEY_TYPE, + NULL); + + config_file = + g_key_file_get_string (keyfile, + panels[i], + HD_DESKTOP_CONFIG_KEY_CONFIG_FILE, + NULL); + + if (!plugin_dir || + !type || + !config_file || + g_str_equal (type,HD_CONTAINER_TYPE_HOME)) + { + goto cleanup; + } + + tab = g_new0 (HPSDTab,1); + + tab->name = g_strdup (panels[i]); + tab->parser = + HILDON_PLUGIN_CONFIG_PARSER + (hildon_plugin_config_parser_new + (plugin_dir,g_build_filename (g_get_home_dir (), + HD_DESKTOP_CONFIG_USER_PATH, + config_file))); + + hildon_plugin_config_parser_set_keys (tab->parser, + "Name", G_TYPE_STRING, + "Icon", GDK_TYPE_PIXBUF, + "Mandatory", G_TYPE_BOOLEAN, + NULL); + + settings->priv->tabs = g_list_append (settings->priv->tabs, tab); + +cleanup: + g_free (plugin_dir); + g_free (type); + g_free (config_file); + } + + g_strfreev (panels); + g_key_file_free (keyfile); + + return TRUE; +} + +static void +hildon_plugin_settings_dialog_tab_free (HPSDTab *tab) +{ + g_free (tab->name); + g_object_unref (tab->parser); +} + +GtkWidget * +hildon_plugin_settings_dialog_new (void) +{ + return + GTK_WIDGET + (g_object_new (HILDON_PLUGIN_TYPE_SETTINGS_DIALOG,NULL)); +} + Modified: projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.h =================================================================== --- projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.h 2007-06-04 15:41:03 UTC (rev 12091) +++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.h 2007-06-04 16:38:46 UTC (rev 12092) @@ -23,3 +23,47 @@ * */ +#ifndef __HILDON_PLUGIN_SETTINGS_DIALOG_H__ +#define __HILDON_PLUGIN_SETTINGS_DIALOG_H__ + +#include <gtk/gtkdialog.h> +#include <gtk/gtktreemodel.h> + +G_BEGIN_DECLS + +typedef struct _HildonPluginSettingsDialog HildonPluginSettingsDialog; +typedef struct _HildonPluginSettingsDialogClass HildonPluginSettingsDialogClass; +typedef struct _HildonPluginSettingsDialogPrivate HildonPluginSettingsDialogPrivate; + +#define HILDON_PLUGIN_TYPE_SETTINGS_DIALOG ( hildon_plugin_settings_dialog_get_type() ) +#define HILDON_PLUGIN_SETTINGS_DIALOG(obj) (GTK_CHECK_CAST (obj, HILDON_PLUGIN_TYPE_SETTINGS_DIALOG, HildonPluginSettingsDialog)) +#define HILDON_PLUGIN_SETTINGS_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), HILDON_PLUGIN_TYPE_SETTINGS_DIALOG, HildonPluginSettingsDialogClass)) +#define HILDON_PLUGIN_IS_SETTINGS_DIALOG(obj) (GTK_CHECK_TYPE (obj, HILDON_PLUGIN_TYPE_SETTINGS_DIALOG)) +#define HILDON_PLUGIN_IS_SETTINGS_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), HILDON_PLUGIN_TYPE_SETTINGS_DIALOG)) + +struct _HildonPluginSettingsDialog +{ + GtkDialog parent; + + GtkTreeModel *sbtm; + GtkTreeModel *tntm; + + HildonPluginSettingsDialogPrivate *priv; +}; + +struct _HildonPluginSettingsDialogClass +{ + GtkDialogClass parent_class; + + /* */ +}; + +GType +hildon_plugin_settings_dialog_get_type (void); + +GtkWidget * +hildon_plugin_settings_dialog_new (void); + +G_END_DECLS + +#endif/*__HILDON_PLUGIN_SETTINGS_DIALOG_H__*/ Modified: projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings.c =================================================================== --- projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings.c 2007-06-04 15:41:03 UTC (rev 12091) +++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings.c 2007-06-04 16:38:46 UTC (rev 12092) @@ -26,7 +26,7 @@ #include <hildon-cp-plugin/hildon-cp-plugin-interface.h> #include <gtk/gtk.h> -#include "hildon-plugin-config-parser.h" +#include "hildon-plugin-settings-dialog.h" #include <libintl.h> #define _(a) dgettext(PACKAGE, a) @@ -36,59 +36,16 @@ gpointer user_data, gboolean user_activated) { - GError *error = NULL; gint ret; - GtkCellRenderer *renderer_pb = gtk_cell_renderer_pixbuf_new(); - GtkCellRenderer *renderer_text = gtk_cell_renderer_text_new(); - GtkTreeViewColumn *text_column; - GtkTreeViewColumn *pixbuf_column; + GtkWidget *dialog = hildon_plugin_settings_dialog_new (); - GtkWidget *dialog = gtk_dialog_new (); - - gtk_dialog_add_button (GTK_DIALOG (dialog), - "Ok", - GTK_RESPONSE_OK); - - HildonPluginConfigParser *cp = - HILDON_PLUGIN_CONFIG_PARSER - (hildon_plugin_config_parser_new ("/usr/share/applications/hildon-status-bar","/tmp/hello.tmp")); - - hildon_plugin_config_parser_set_keys (cp, - "Name", G_TYPE_STRING, - "Icon", GDK_TYPE_PIXBUF, - "Mandatory", G_TYPE_BOOLEAN, - NULL); - - hildon_plugin_config_parser_load (cp,&error); - - if (!error) - { - GtkWidget *tw = gtk_tree_view_new_with_model (cp->tm); - - text_column = - gtk_tree_view_column_new_with_attributes - (NULL, renderer_text, "text", 3, NULL); - - pixbuf_column = - gtk_tree_view_column_new_with_attributes - (NULL, renderer_pb,"pixbuf", 4, NULL); - - gtk_tree_view_append_column(GTK_TREE_VIEW (tw), pixbuf_column); - gtk_tree_view_append_column(GTK_TREE_VIEW (tw), text_column); - - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), - tw); - gtk_widget_show (tw); - } - gtk_widget_show (dialog); ret = gtk_dialog_run (GTK_DIALOG (dialog)); if (ret == GTK_RESPONSE_OK) { - g_object_unref (G_OBJECT (cp)); gtk_widget_destroy (dialog); return OSSO_OK; }
- Previous message: [maemo-commits] r12091 - in projects/haf/trunk/hildon-desktop: . debian libhildondesktop src
- Next message: [maemo-commits] r12093 - in projects/haf/trunk/hildon-plugins-settings: . src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]