[maemo-commits] [maemo-commits] r12071 - in projects/haf/trunk/hildon-plugins-settings: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Jun 1 18:22:40 EEST 2007
Author: moimart
Date: 2007-06-01 18:22:34 +0300 (Fri, 01 Jun 2007)
New Revision: 12071

Added:
   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
Modified:
   projects/haf/trunk/hildon-plugins-settings/ChangeLog
   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
Log:
2007-06-01  Moises Martinez  <moises.martinez at nokia.com>

        * src/hildon-plugin-config-parser.[ch]:
        - Implemented reading of desktop files to model.
        * src/hildon-plugin-config-settings.c:
        - Initial import of control panel interface.
        * src/hildon-plugin-config-settings-dialog.[ch]:
        - Initial import of GtkDialog child class.
	* src/Makefile.am: updated.
	* ChangeLog updated.



Modified: projects/haf/trunk/hildon-plugins-settings/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-plugins-settings/ChangeLog	2007-06-01 15:01:07 UTC (rev 12070)
+++ projects/haf/trunk/hildon-plugins-settings/ChangeLog	2007-06-01 15:22:34 UTC (rev 12071)
@@ -1,3 +1,12 @@
+2007-06-01  Moises Martinez  <moises.martinez at nokia.com>
+
+	* src/hildon-plugin-config-parser.[ch]:
+	- Implemented reading of desktop files to model.
+	* src/hildon-plugin-config-settings.c:
+	- Initial import of control panel interface.
+	* src/hildon-plugin-config-settings-dialog.[ch]:
+	- Initial import of GtkDialog child class.
+
 2007-05-31  Moises Martinez  <moises.martinez at nokia.com>
 
 	* src/hildon-plugin-config-parser.[ch]:

Modified: projects/haf/trunk/hildon-plugins-settings/src/Makefile.am
===================================================================
--- projects/haf/trunk/hildon-plugins-settings/src/Makefile.am	2007-06-01 15:01:07 UTC (rev 12070)
+++ projects/haf/trunk/hildon-plugins-settings/src/Makefile.am	2007-06-01 15:22:34 UTC (rev 12071)
@@ -22,5 +22,6 @@
 
 libhildonpluginsettings_la_SOURCES = \
 	hildon-plugin-config-parser.h \
-	hildon-plugin-config-parser.c
+	hildon-plugin-config-parser.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-01 15:01:07 UTC (rev 12070)
+++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.c	2007-06-01 15:22:34 UTC (rev 12071)
@@ -50,6 +50,9 @@
 {
   guint n_keys;
 
+  GList *keys;
+  GList *keys_types;
+  
   gchar *path_to_read;
   gchar *path_to_save;
 };
@@ -67,12 +70,17 @@
   parser->priv = HILDON_PLUGIN_CONFIG_PARSER_GET_PRIVATE (parser);
 	
   parser->tm = NULL;
-  parser->keys = NULL;
+  parser->priv->keys = NULL;
 
   parser->priv->n_keys= 0;
 
   parser->priv->path_to_read =
   parser->priv->path_to_save = NULL;
+
+  parser->keys = g_hash_table_new_full (g_str_hash,
+		  			g_str_equal,
+					g_free,
+					g_free);
 }
 
 static void 
@@ -180,7 +188,7 @@
   }	  
 
   g_free (parser->priv->path_to_read);
-  g_free (parser->priv->path_to_save);
+  g_free (parser->priv->path_to_save); 
 }	
 
 static GQuark
@@ -189,6 +197,183 @@
   return g_quark_from_static_string ("hildon-plugin-config-parser-error-quark");
 }
 
+static GdkPixbuf *
+hildon_plugin_config_parser_get_icon (parser, const gchar *icon_name)
+{
+  GtkIconTheme *icon_theme;
+  GdkPixbuf *pixbuf = NULL;
+  GError *error = NULL;
+
+  gint icon_size = 32; /* FIXME: NOOOOOOOO! */
+
+  if (icon_name)
+  {
+    icon_theme = gtk_icon_theme_get_default();
+
+    pixbuf = 
+      gtk_icon_theme_load_icon 
+        (icon_theme,
+         icon_name,
+         icon_size,
+         GTK_ICON_LOOKUP_NO_SVG, &error);
+
+   if (error)
+   {
+     g_warning 
+       ("Error loading icon '%s': %s\n",
+        icon_name, error->message);
+
+     g_error_free(error);
+     error = NULL;
+   }
+   else
+     g_warning("Error loading icon: no icon name\n");
+ 
+   return pixbuf;
+}
+
+static gboolean 
+hildon_plugin_config_parser_desktop_file (HildonPluginConfigParser *parser, 
+					  const gchar *filename,
+					  GError **error)
+{
+  GKeyFile *keyfile = NULL;
+  GError *external_error = NULL;
+  GtkTreeIter iter;
+  GList *l;
+
+  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_free_error (external_error);
+    return FALSE;
+  }
+
+  gtk_list_store_append (GTK_LIST_STORE (parser->nm), &iter);
+  gtk_list_store_set (GTK_LIST_STORE (parser->nm), &iter,
+		      HP_COL_DESKTOP_FILE, &filename,
+		      HP_COL_CHECKBOX, FALSE, -1);
+
+  for (l = parser->priv->keys; l != NULL; l = g_list_next (l))
+  {
+    gchar *_string = NULL;
+    gint _integer;
+    gboolean _boolean;
+    GdkPixbuf *_pixbuf = NULL;
+
+    GType *type = 
+      (GType *)g_hash_table_lookup (parser->keys, (gchar *)l->data);
+
+    if (!type)
+      continue;
+  
+    switch (type)
+    {
+      case G_TYPE_STRING:
+	_string = 
+	  g_key_file_get_string 
+           (keyfile,
+            HP_DESKTOP_GROUP,
+	    (gchar *)l->data,
+	    &external_error);
+        
+        if (!external_error)
+        {
+          gtk_list_store_set 
+            (GTK_LIST_STORE (parser->nm), &iter,
+	     hildon_plugin_config_parser_get_key_id (parser,(const gchar *)l->data)+2,
+	     &_string,
+	    -1);
+        }
+	else
+          g_free (_string);
+        break;
+
+      case G_TYPE_INTEGER:
+        _integer = 
+          g_key_file_get_integer 
+           (keyfile,
+            HP_DESKTOP_GROUP,
+            (gchar *)l->data,
+	    &external_error);
+       
+	if (!external_error)
+        {
+          gtk_list_store_set 
+            (GTK_LIST_STORE (parser->nm), &iter,
+	     hildon_plugin_config_parser_get_key_id (parser,(const gchar *)l->data)+2,
+	     &_integer,
+	    -1);
+        } 
+        break;
+
+      case G_TYPE_BOOLEAN:
+	_boolean = 
+          g_key_file_get_boolean
+           (keyfile,
+            HP_DESKTOP_GROUP,
+	    (gchar *)l->data,
+	    &external_error);
+       
+	if (!external_error)
+        {
+          gtk_list_store_set 
+            (GTK_LIST_STORE (parser->nm), &iter,
+	     hildon_plugin_config_parser_get_key_id (parser,(const gchar *)l->data)+2,
+	     &_boolean,
+	    -1);
+        } 
+        break;
+
+     case GDK_TYPE_PIXBUF:
+	_string =
+          g_key_file_get_string
+           (keyfile,
+            HP_DESKTOP_GROUP,
+            (gchar *)l->data,
+            &external_error);
+
+        
+	if (!external_error) 
+        {
+  	  pixbuf = hildon_plugin_config_parser_get_icon (parser, _string);
+
+	  if (!pixbuf)
+            continue;
+
+          gtk_list_store_set 
+            (GTK_LIST_STORE (parser->nm), &iter,
+	     hildon_plugin_config_parser_get_key_id (parser,(const gchar *)l->data)+2,
+	     &_pixbuf,
+	    -1);
+        }	
+	else
+	  g_free (_string);
+        break;
+  
+      default:
+        g_assert_not_reached (); 
+    }
+   
+    if (external_error)
+    {
+      g_warning ("Error reading .desktop file: %s",external_error->message);
+
+      g_error_free (external_error);
+      external_error = NULL;
+    }
+  }
+
+  g_key_file_free (keyfile);
+  
+  return TRUE;
+}
+
 GObject * 
 hildon_plugin_config_parser_new (const gchar *path, const gchar *path_to_save)
 {
@@ -202,13 +387,39 @@
 hildon_plugin_config_parser_set_keys (HildonPluginConfigParser *parser, ...)
 {
   va_list keys;
+  gboolean flag = FALSE;
+  gchar *key, *last_key = NULL;
+  GType key_type = 0;
 
-  va_start(keys,log);
+  va_start (keys,parser);
 
-  while ((key = va_arg(keys,gchar *)) != NULL)
+  while (1)
   {
-    parser->keys = g_list_append (parser->keys,key);
-    parser->priv->n_keys++;
+    if (!flag)
+    {	   
+      key = va_arg (keys,gchar *);
+
+      if (!key) break;
+	    
+      parser->priv->keys = 
+        g_list_append (parser->priv->keys,key);
+      last_key = key;
+    }
+    else
+    {	   
+      key_type = va_arg (keys, GType);
+
+      if (!key_type) break;/* This shouldn't happen */
+	    
+      g_hash_table_insert (parser->keys,
+		      	   last_key,
+			   key_type);
+
+      parser->priv->keys_types = 
+        g_list_append (parser->priv->keys_type, key_type);
+      
+      parser->priv->n_keys++;
+    }
   }
 
   va_end (keys);
@@ -218,14 +429,21 @@
 hildon_plugin_config_parser_get_key_id (HildonPluginConfigParser *parser, 
 					const gchar *key)
 {
-  return g_list_index (parser->keys, key); 
+  return g_list_index (parser->priv->keys, key); 
 }
 
 gboolean
 hildon_plugin_config_parser_load (HildonPluginConfigParser *parser, 
 				  GError **error)
 {
-  if (!parser->keys)
+  GDir *path;
+  gconst gchar *dir_entry;
+  GType *_keys;
+  GList *l;
+  register gint i=0;
+  GError *external_error = NULL;
+	
+  if (!parser->priv->keys)
   {
     g_set_error (error,
                  hildon_plugin_config_parser_error_quark (),
@@ -238,6 +456,57 @@
   if (parser->tm)
     gtk_widget_destroy (parser->tm);
 
+  _keys = g_new0 (GType,parser->priv->n_keys+1);
+
+  _keys [i++] = G_TYPE_STRING; /* Desktop file name */
+  _keys [i++] = G_TYPE_BOOLEAN; /* Checkbox */
+
+  for (l = parser->priv->keys_types;
+       l != NULL || i < parser->priv->n_keys;
+       i++, l = g_list_next (l))
+  {	  
+    _keys[i] = (GType) l->data;  	  
+  }
+  
+  parser->tm = 
+    GTK_TREE_MODEL (gtk_list_store_newv (parser->priv->n_keys,_keys));
+  
+  if ((path = g_dir_open (parser->priv->path_to_read, 0, &external_error)) == NULL) 
+  {
+    g_set_error (error,
+                 hildon_plugin_config_parser_error_quark (),
+		 HILDON_PLUGIN_CONFIG_PARSER_ERROR_PATHNOEXIST,
+		 external_error->message);
+
+    g_error_free (external_error);
+
+    return FALSE;
+  }
+
+  while ((dir_entry = g_dir_read_name (path)) != NULL)
+  {
+    gchar *file = 
+      g_strconcat (path, "/",dir_entry, NULL);
+
+    if (!g_str_has_suffix(indexfile, ".desktop"))
+      continue;
+
+    /*NOTE: Redundant safety :D*/
+
+    if (g_file_test (file, G_FILE_TEST_EXISTS))
+    {
+      if (!hildon_plugin_config_parser_desktop_file (parser, file, error));
+      {
+        g_free (file);
+        return FALSE;
+      }
+    }
+
+    g_free (file);
+  }
+
+  g_dir_close (path);
+
   return TRUE;
 }
 
@@ -245,7 +514,7 @@
 hildon_plugin_config_parser_save (HildonPluginConfigParser *parser, 
 				  GError **error)
 {
-  if (!parser->keys)
+  if (!parser->priv->keys)
   {
     g_set_error (error,
                  hildon_plugin_config_parser_error_quark (),

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-01 15:01:07 UTC (rev 12070)
+++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.h	2007-06-01 15:22:34 UTC (rev 12071)
@@ -44,7 +44,7 @@
   GObject	parent;
 
   GtkTreeModel  *tm;
-  GList		*keys;
+  GHashTable    *keys;
 
   HildonPluginConfigParserPrivate *priv;
 };

Added: 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-01 15:01:07 UTC (rev 12070)
+++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.c	2007-06-01 15:22:34 UTC (rev 12071)
@@ -0,0 +1,25 @@
+/*
+ * This file is part of maemo-af-desktop
+ *
+ * Copyright (C) 2007 Nokia Corporation.
+ *
+ * Author:  Moises Martinez <moises.martinez at nokia.com>
+ * Contact: Karoliina Salminen <karoliina.t.salminen at nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+

Added: 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-01 15:01:07 UTC (rev 12070)
+++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings-dialog.h	2007-06-01 15:22:34 UTC (rev 12071)
@@ -0,0 +1,25 @@
+/*
+ * This file is part of maemo-af-desktop
+ *
+ * Copyright (C) 2007 Nokia Corporation.
+ *
+ * Author:  Moises Martinez <moises.martinez at nokia.com>
+ * Contact: Karoliina Salminen <karoliina.t.salminen at nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+

Added: projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings.c
===================================================================
--- projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings.c	2007-06-01 15:01:07 UTC (rev 12070)
+++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-settings.c	2007-06-01 15:22:34 UTC (rev 12071)
@@ -0,0 +1,49 @@
+/*
+ * This file is part of maemo-af-desktop
+ *
+ * Copyright (C) 2007 Nokia Corporation.
+ *
+ * Author:  Moises Martinez <moises.martinez at nokia.com>
+ * Contact: Karoliina Salminen <karoliina.t.salminen at nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
+#include <gtk/gtk.h>
+
+#include "hildon-plugin-config-parser.h"
+
+#include <libintl.h>
+#define _(a) dgettext(PACKAGE, a)
+
+osso_return_t 
+execute (osso_context_t *osso,
+	 gpointer user_data,
+	 gboolean user_activated)
+{
+  GError *error = NULL;
+  gint ret;
+
+
+
+  if (ret == GTK_RESPONSE_OK)
+    return OSSO_OK;
+    
+  return OSSO_ERROR;  
+}
+


More information about the maemo-commits mailing list