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

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu May 31 19:46:58 EEST 2007
Author: moimart
Date: 2007-05-31 19:46:56 +0300 (Thu, 31 May 2007)
New Revision: 12014

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-05-31  Moises Martinez  <moises.martinez at nokia.com>

        * src/hildon-plugin-config-parser.[ch]:
        - Added first implementation.
        * src/Makefile.am: updated.
	* ChangeLog updated.



Modified: projects/haf/trunk/hildon-plugins-settings/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-plugins-settings/ChangeLog	2007-05-31 15:28:03 UTC (rev 12013)
+++ projects/haf/trunk/hildon-plugins-settings/ChangeLog	2007-05-31 16:46:56 UTC (rev 12014)
@@ -1,5 +1,11 @@
 2007-05-31  Moises Martinez  <moises.martinez at nokia.com>
 
+	* src/hildon-plugin-config-parser.[ch]:
+	- Added first implementation.
+	* src/Makefile.am: updated.
+
+2007-05-31  Moises Martinez  <moises.martinez at nokia.com>
+
 	* ./*:
 	* src/*:
 	- Added initial skeleton.

Modified: projects/haf/trunk/hildon-plugins-settings/src/Makefile.am
===================================================================
--- projects/haf/trunk/hildon-plugins-settings/src/Makefile.am	2007-05-31 15:28:03 UTC (rev 12013)
+++ projects/haf/trunk/hildon-plugins-settings/src/Makefile.am	2007-05-31 16:46:56 UTC (rev 12014)
@@ -20,5 +20,7 @@
 			       $(CP_LIBS) $(OSSO_LIBS) $(GCONF_LIBS) \
 			       $(LIBOSSOHELP_LIBS) $(LIBHILDONMENU_LIBS)
 
-libhildonpluginsettings_la_SOURCES = 
+libhildonpluginsettings_la_SOURCES = \
+	hildon-plugin-config-parser.h \
+	hildon-plugin-config-parser.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-05-31 15:28:03 UTC (rev 12013)
+++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.c	2007-05-31 16:46:56 UTC (rev 12014)
@@ -23,3 +23,249 @@
  *
  */
 
+#include "hildon-plugin-config-parser.h"
+
+#define HILDON_PLUGIN_CONFIG_PARSER_GET_PRIVATE(object) \
+	                (G_TYPE_INSTANCE_GET_PRIVATE ((object), HILDON_PLUGIN_TYPE_CONFIG_PARSER, HildonPluginConfigParserPrivate))
+
+G_DEFINE_TYPE (HildonPluginConfigParser, hildon_plugin_config_parser, G_TYPE_OBJECT);
+
+typedef enum 
+{
+  HILDON_PLUGIN_CONFIG_PARSER_ERROR_UNKNOWN = 0,
+  HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOKEYS,
+  HILDON_PLUGIN_CONFIG_PARSER_ERROR_PATHNOEXIST,
+  HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOFILESINPATH,
+  HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOPATHTOSAVE
+}
+HildonPluginConfigParserErrorCodes;
+
+enum
+{
+  PROP_PATH_TO_READ=1,
+  PROP_PATH_TO_SAVE
+};
+
+struct _HildonPluginConfigParserPrivate
+{
+  guint n_keys;
+
+  gchar *path_to_read;
+  gchar *path_to_save;
+};
+
+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);
+
+static void hildon_plugin_config_parser_finalize (GObject *object);
+
+static GQuark hildon_plugin_config_parser_error_quark (void);
+
+static void 
+hildon_plugin_config_parser_init (HildonPluginConfigParser *parser)
+{
+  parser->priv = HILDON_PLUGIN_CONFIG_PARSER_GET_PRIVATE (parser);
+	
+  parser->tm = NULL;
+  parser->keys = NULL;
+
+  parser->priv->n_keys= 0;
+
+  parser->priv->path_to_read =
+  parser->priv->path_to_save = NULL;
+}
+
+static void 
+hildon_plugin_config_parser_class_init (HildonPluginConfigParserClass *parser_class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (parser_class);
+
+  object_class->set_property = hildon_plugin_config_set_property;
+  object_class->get_property = hildon_plugin_config_get_propery;
+
+  object_class->finalize = hildon_plugin_config_parser_finalize;
+
+  g_type_class_add_private (object_class, sizeof (HildonPluginConfigParserPrivate));
+
+  g_object_class_install_property (object_class,
+                                   PROP_PATH_TO_READ,
+                                   g_param_spec_string("path",
+                                                       "path-to-read",
+                                                       "Path of the folder to read .desktop files",
+                                                       NULL,
+                                                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_PATH_TO_SAVE,
+                                   g_param_spec_string("filename",
+                                                       "filename to save",
+                                                       "Filename to save configuration file",
+                                                       NULL,
+                                                       G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+}
+
+tatic void
+hildon_plugin_config_parser_set_property (GObject *object,
+                           		  guint prop_id,
+                                  	  const GValue *value,
+                                  	  GParamSpec *pspec)
+{
+  HildonPluginConfigParser *parser;
+
+  g_assert (object && HILDON_PLUGIN_IS_CONFIG_PARSER (object));
+
+  parser = HILDON_PLUGIN_CONFIG_PARSER (object);
+
+  switch (prop_id)
+  {
+    case PROP_PATH_TO_READ:
+      g_free (parser->path_to_read);
+      parser->path_to_read = g_strdup (g_value_get_string (value));
+      break;
+
+    case PROP_PATH_TO_SAVE:
+      g_free (parser->path_to_save);
+      parser->path_to_save = g_strdup (g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+hildon_plugin_config_parser_get_property (GObject *object,
+                                  	  guint prop_id,
+                                  	  GValue *value,
+                                  	  GParamSpec *pspec)
+{
+  HildonPluginConfigParser *parser;
+
+  g_assert (object && HILDON_PLUGIN_IS_CONFIG_PARSER (object));
+
+  parser = HILDON_PLUGIN_CONFIG_PARSER (object);
+
+  switch (prop_id)
+  {
+    case PROP_PATH_TO_READ:
+      g_value_set_string (value, parser->path_to_read);
+      break;
+
+    case PROP_PATH_TO_SAVE:
+      g_value_set_string (value, parser->path_to_save);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void 
+hildon_plugin_config_parser_finalize (GObject *object)
+{
+  HildonPluginConfigParser *parser = G_OBJECT (object);
+
+  if (parser->tm)
+    gtk_widget_destroy (parser->tm);
+
+  if (parser->keys)
+  {
+    g_list_foreach (parser->keys,
+		    (GFunc)g_free,
+		    NULL);
+
+    g_list_free (parser->keys);
+  }	  
+
+  g_free (parser->priv->path_to_read);
+  g_free (parser->priv->path_to_save);
+}	
+
+static GQuark
+hildon_plugin_config_parser_error_quark (void)
+{
+  return g_quark_from_static_string ("hildon-plugin-config-parser-error-quark");
+}
+
+GObject * 
+hildon_plugin_config_parser_new (const gchar *path, const gchar *path_to_save)
+{
+  return g_object_new (HILDON_PLUGIN_TYPE_CONFIG_PARSER,
+		       "path", path,
+		       "filename", path_to_save,
+		       NULL);
+}	
+
+void
+hildon_plugin_config_parser_set_keys (HildonPluginConfigParser *parser, ...)
+{
+  va_list keys;
+
+  va_start(keys,log);
+
+  while ((key = va_arg(keys,gchar *)) != NULL)
+  {
+    parser->keys = g_list_append (parser->keys,key);
+    parser->priv->n_keys++;
+  }
+
+  va_end (keys);
+}
+
+gint
+hildon_plugin_config_parser_get_key_id (HildonPluginConfigParser *parser, 
+					const gchar *key)
+{
+  return g_list_index (parser->keys, key); 
+}
+
+gboolean
+hildon_plugin_config_parser_load (HildonPluginConfigParser *parser, 
+				  GError **error)
+{
+  if (!parser->keys)
+  {
+    g_set_error (error,
+                 hildon_plugin_config_parser_error_quark (),
+                 HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOKEYS,
+                 "You need to set keys in order to create the model");
+
+    return FALSE;
+  }
+
+  if (parser->tm)
+    gtk_widget_destroy (parser->tm);
+
+  return TRUE;
+}
+
+gboolean
+hildon_plugin_config_parser_save (HildonPluginConfigParser *parser, 
+				  GError **error)
+{
+  if (!parser->keys)
+  {
+    g_set_error (error,
+                 hildon_plugin_config_parser_error_quark (),
+                 HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOKEYS,
+                 "You need to set keys in order to create the model");
+
+    return FALSE;
+  }
+
+  if (!parser->priv->path_to_save)
+  {
+    g_set_error (error,
+                 hildon_plugin_config_parser_error_quark (),
+                 HILDON_PLUGIN_CONFIG_PARSER_ERROR_NOPATHTOSAVE,
+                 "You need to set a valid filename in order to save the model");
+
+    return FALSE;
+  }
+
+  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-05-31 15:28:03 UTC (rev 12013)
+++ projects/haf/trunk/hildon-plugins-settings/src/hildon-plugin-config-parser.h	2007-05-31 16:46:56 UTC (rev 12014)
@@ -23,3 +23,59 @@
  *
  */
 
+#ifndef __HILDON_PLUGIN_CONFIG_PARSER_H__
+#define __HILDON_PLUGIN_CONFIG_PARSER_H__
+#include <gtk/gtkliststore.h>
+
+BEGIN_DECLS
+
+typedef struct _HildonPluginConfigParser HildonPluginConfigParser;
+typedef struct _HildonPluginConfigParserClass HildonPluginConfigParserClass;
+typedef struct _HildonPluginConfigParserPrivate HildonPluginConfigParserPrivate;
+
+#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))
+#define HILDON_PLUGIN_IS_CONFIG_PARSER(obj) (GTK_CHECK_TYPE (obj, HILDON_PLUGIN_TYPE_CONFIG_PARSER))
+#define HILDON_PLUGIN_IS_CONFIG_PARSER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), HILDON_PLUGIN_TYPE_CONFIG_PARSER))
+
+struct _HildonPluginConfigParser
+{
+  GObject	parent;
+
+  GtkTreeModel  *tm;
+  GList		*keys;
+
+  HildonPluginConfigParserPrivate *priv;
+};
+
+struct _HildonPluginConfigParserClass
+{
+  GObjectClass  parent_class;
+
+  /* */
+};
+
+
+GType 
+hildon_plugin_config_parser_get_type (void);
+
+
+GObject *
+hildon_plugin_config_parser_new (const gchar *path, const gchar *path_to_save);
+
+void 
+hildon_plugin_config_parser_set_keys (HildonPluginConfigParser *parser, ...);
+
+gint
+hildon_plugin_config_parser_get_key_id (HildonPluginConfigParser *parser, const gchar *key);
+
+gboolean 
+hildon_plugin_config_parser_load (HildonPluginConfigParser *parser, GError **error);
+
+gboolean 
+hildon_plugin_config_parser_save (HildonPluginConfigParser *parser, GError **error);
+
+END_DECLS
+
+#endif/*__HILDON_PLUGIN_CONFIG_PARSER_H__


More information about the maemo-commits mailing list