[glade/css: 5/11] Added license property to GladeProject. It gets saved as part of the first comment.



commit c93dc3ffb1642d7264498d417074c5213ea670c5
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Sat Jul 20 00:43:03 2013 -0300

    Added license property to GladeProject.
    It gets saved as part of the first comment.

 gladeui/glade-project.c |   68 +++++++++++++++++++++++++++++++++++++++++-----
 gladeui/glade-project.h |    5 +++
 2 files changed, 65 insertions(+), 8 deletions(-)
---
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 87a1699..77d5737 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -117,6 +117,8 @@ struct _GladeProjectPrivate
 
   GladeWidget *template;        /* The template widget */
 
+  gchar *license;               /* License for this project (will be saved as a comment) */
+
   GList *comments;              /* XML comments, Glade will preserve whatever comment was
                                  * in file before the root element, so users can delete or change it.
                                  */
@@ -190,6 +192,7 @@ enum
   PROP_TRANSLATION_DOMAIN,
   PROP_TEMPLATE,
   PROP_RESOURCE_PATH,
+  PROP_LICENSE,
   N_PROPERTIES
 };
 
@@ -382,6 +385,9 @@ glade_project_get_property (GObject *object,
     case PROP_RESOURCE_PATH:
       g_value_set_string (value, project->priv->resource_path);
       break;
+    case PROP_LICENSE:
+      g_value_set_string (value, project->priv->license);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -408,6 +414,10 @@ glade_project_set_property (GObject *object,
       glade_project_set_resource_path (GLADE_PROJECT (object),
                                       g_value_get_string (value));
       break;
+    case PROP_LICENSE:
+      glade_project_set_license (GLADE_PROJECT (object),
+                                 g_value_get_string (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -947,6 +957,13 @@ glade_project_class_init (GladeProjectClass *klass)
                          _("Path to load images and resources in Glade's runtime"),
                          NULL,
                          G_PARAM_READWRITE);
+  
+  glade_project_props[PROP_LICENSE] =
+    g_param_spec_string ("license",
+                         _("License"),
+                         _("License for this project, it will be added as a document level comment."),
+                         NULL,
+                         G_PARAM_READWRITE);
 
   /* Install all properties */
   g_object_class_install_properties (object_class, N_PROPERTIES, glade_project_props);
@@ -1733,6 +1750,31 @@ glade_project_get_resource_path (GladeProject *project)
   return project->priv->resource_path;
 }
 
+void
+glade_project_set_license (GladeProject *project, const gchar *license)
+{
+  GladeProjectPrivate *priv;
+  
+  g_return_if_fail (GLADE_IS_PROJECT (project));
+  priv = project->priv;
+
+  if ((!license && priv->license) ||
+      (license && g_strcmp0 (priv->license, license) != 0))
+    {
+      g_free (priv->license);
+      priv->license = g_strdup (license);
+      g_object_notify_by_pspec (G_OBJECT (project), glade_project_props[PROP_LICENSE]);
+    }
+}
+
+const gchar *
+glade_project_get_license (GladeProject *project)
+{
+  g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL);
+
+  return project->priv->license;
+}
+
 static void
 glade_project_read_resource_path (GladeProject *project,
                                   GladeXmlNode *root_node)
@@ -1772,6 +1814,11 @@ glade_project_read_comments (GladeProject *project, GladeXmlNode *root)
           /* Do not load generated with glade comment! */
           if (g_str_has_prefix (start, GLADE_XML_COMMENT))
             {
+              gchar *new_line = g_strstr_len (start, -1, "\n");
+
+              if (new_line)
+                glade_project_set_license (project, g_strstrip (new_line));
+
               g_free (comment);
               continue;
             }
@@ -2364,24 +2411,29 @@ sort_project_dependancies (GObject *a, GObject *b)
 
 static inline void
 glade_project_write_comments (GladeProject *project,
-                             GladeXmlDoc  *doc,
-                             GladeXmlNode *root)
+                              GladeXmlDoc  *doc,
+                              GladeXmlNode *root)
 {
   GladeProjectPrivate *priv = project->priv;
-  GladeXmlNode *comment_node;
+  GladeXmlNode *comment_node, *node;
   gchar *glade_comment;
   GList *l;
 
-  glade_comment = glade_project_make_comment ();
+  if (priv->license)
+    {
+      gchar *comment = glade_project_make_comment ();
+      glade_comment = g_strdup_printf ("%s\n\n%s\n\n", comment, priv->license);
+      g_free (comment);
+    }
+  else
+    glade_comment = glade_project_make_comment ();
+
   comment_node = glade_xml_doc_new_comment (doc, glade_comment); 
   comment_node = glade_xml_node_add_prev_sibling (root, comment_node);
   
   for (l = priv->comments; l; l = g_list_next (l))
     {
-      gchar *comment = l->data;
-      GladeXmlNode *node;
-      
-      node = glade_xml_doc_new_comment (doc, comment);
+      node = glade_xml_doc_new_comment (doc, l->data);
       comment_node = glade_xml_node_add_next_sibling (comment_node, node);
     }
 
diff --git a/gladeui/glade-project.h b/gladeui/glade-project.h
index 8a8f52d..f9a9518 100644
--- a/gladeui/glade-project.h
+++ b/gladeui/glade-project.h
@@ -169,6 +169,11 @@ void                glade_project_set_template         (GladeProject       *proj
                                                        GladeWidget        *widget);
 GladeWidget        *glade_project_get_template         (GladeProject       *project);
 
+void                glade_project_set_license          (GladeProject       *project,
+                                                        const gchar        *license);
+
+const gchar        *glade_project_get_license          (GladeProject       *project);
+
 /* Commands */
 void                glade_project_undo                 (GladeProject       *project);
 void                glade_project_redo                 (GladeProject       *project);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]