[Xfce4-commits] <midori:master> Always use proper accessors for KatzeItem

Christian Dywan noreply at xfce.org
Tue Mar 26 08:18:04 CET 2013


Updating branch refs/heads/master
         to eff6e0c33703b2ff7cc12eb9954239b47358669a (commit)
       from 0979301a577b2181c0866ad0c9960437b75dbf83 (commit)

commit eff6e0c33703b2ff7cc12eb9954239b47358669a
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Mar 25 09:17:42 2013 +0100

    Always use proper accessors for KatzeItem

 extensions/feed-panel/feed-panel.c |    6 +-
 midori/midori-array.c              |   73 ++++++++++++++++++++++++-----------
 midori/midori-browser.c            |   24 ++++--------
 midori/midori-searchaction.c       |   10 ++--
 midori/midori-session.c            |    2 +-
 midori/midori-view.c               |    2 +-
 6 files changed, 68 insertions(+), 49 deletions(-)

diff --git a/extensions/feed-panel/feed-panel.c b/extensions/feed-panel/feed-panel.c
index 9c22340..dcb049f 100644
--- a/extensions/feed-panel/feed-panel.c
+++ b/extensions/feed-panel/feed-panel.c
@@ -376,15 +376,15 @@ feed_panel_cursor_or_row_changed_cb (GtkTreeView* treeview,
                     text = g_strdup_printf (
                             "<html><head><title>feed</title></head>"
                             "<body><h3>%s</h3><p />%s</body></html>",
-                            parent->uri, last_updated);
+                            katze_item_get_uri (KATZE_ITEM (parent)), last_updated);
                     g_free (pretty);
                     g_free (last_updated);
                 }
                 else
                 {
                     text = g_strdup_printf (
-                            "<html><head><title>feed</title></head>"
-                            "<body><h3>%s</h3></body></html>", parent->uri);
+                        "<html><head><title>feed</title></head>"
+                        "<body><h3>%s</h3></body></html>", katze_item_get_uri (KATZE_ITEM (parent)));
                 }
             }
             webkit_web_view_load_html_string (
diff --git a/midori/midori-array.c b/midori/midori-array.c
index 5d7d5ff..4911c89 100644
--- a/midori/midori-array.c
+++ b/midori/midori-array.c
@@ -51,9 +51,17 @@ katze_item_from_xmlNodePtr (xmlNodePtr cur)
     while (cur)
     {
         if (katze_str_equal ((gchar*)cur->name, "title"))
-            item->name = g_strstrip ((gchar*)xmlNodeGetContent (cur));
+        {
+            gchar* value = g_strstrip ((gchar*)xmlNodeGetContent (cur));
+            katze_item_set_name (item, value);
+            xmlFree (value);
+        }
         else if (katze_str_equal ((gchar*)cur->name, "desc"))
-            item->text = g_strstrip ((gchar*)xmlNodeGetContent (cur));
+        {
+            gchar* value = g_strstrip ((gchar*)xmlNodeGetContent (cur));
+            katze_item_set_text (item, value);
+            xmlFree (value);
+        }
         else if (katze_str_equal ((gchar*)cur->name, "info"))
             katze_xbel_parse_info (item, cur);
         cur = cur->next;
@@ -87,9 +95,17 @@ katze_array_from_xmlNodePtr (xmlNodePtr cur)
     while (cur)
     {
         if (katze_str_equal ((gchar*)cur->name, "title"))
-            ((KatzeItem*)array)->name = g_strstrip ((gchar*)xmlNodeGetContent (cur));
+        {
+            gchar* value = g_strstrip ((gchar*)xmlNodeGetContent (cur));
+            katze_item_set_text (KATZE_ITEM (array), value);
+            xmlFree (value);
+        }
         else if (katze_str_equal ((gchar*)cur->name, "desc"))
-            ((KatzeItem*)array)->text = g_strstrip ((gchar*)xmlNodeGetContent (cur));
+        {
+            gchar* value = g_strstrip ((gchar*)xmlNodeGetContent (cur));
+            katze_item_set_name (KATZE_ITEM (array), value);
+            xmlFree (value);
+        }
         else if (katze_str_equal ((gchar*)cur->name, "info"))
             katze_xbel_parse_info ((KatzeItem*)array, cur);
         else if (katze_str_equal ((gchar*)cur->name, "folder"))
@@ -209,15 +225,15 @@ katze_array_from_xmlDocPtr (KatzeArray* array,
         value = (gchar*)xmlGetProp (cur, (xmlChar*)"version");
         if (!tiny_xbel && (!value || !katze_str_equal (value, "1.0")))
             g_warning ("XBEL version is not 1.0.");
-        g_free (value);
+        xmlFree (value);
 
         value = (gchar*)xmlGetProp (cur, (xmlChar*)"title");
         katze_item_set_name (KATZE_ITEM (array), value);
-        g_free (value);
+        xmlFree (value);
 
         value = (gchar*)xmlGetProp (cur, (xmlChar*)"desc");
         katze_item_set_text (KATZE_ITEM (array), value);
-        g_free (value);
+        xmlFree (value);
     }
     else if (katze_str_equal ((gchar*)cur->name, "RDF"))
     {
@@ -229,21 +245,28 @@ katze_array_from_xmlDocPtr (KatzeArray* array,
             if (katze_str_equal ((gchar*)cur->name, "item"))
             {
                 xmlNodePtr cur_item;
-
                 item = katze_item_new ();
 
                 cur_item = cur->xmlChildrenNode;
                 while (cur_item)
                 {
                     if (katze_str_equal ((gchar*)cur_item->name, "title"))
-                        item->name = g_strstrip ((gchar*)xmlNodeGetContent (cur_item));
+                    {
+                        gchar* value = g_strstrip ((gchar*)xmlNodeGetContent (cur_item));
+                        katze_item_set_name (item, value);
+                        xmlFree (value);
+                    }
                     else if (katze_str_equal ((gchar*)cur_item->name, "link"))
-                        item->uri = g_strstrip ((gchar*)xmlNodeGetContent (cur_item));
+                    {
+                        gchar* value = g_strstrip ((gchar*)xmlNodeGetContent (cur_item));
+                        katze_item_set_uri (item, value);
+                        xmlFree (value);
+                    }
                     else if (katze_str_equal ((gchar*)cur_item->name, "subject"))
                     {
                         gchar* value = g_strstrip ((gchar*)xmlNodeGetContent (cur_item));
                         /* FIXME: Create a folder according to the tag */
-                        g_free (value);
+                        xmlFree (value);
                     }
                     cur_item = cur_item->next;
                 }
@@ -380,7 +403,11 @@ katze_array_from_netscape_file (KatzeArray* array,
             if (item && katze_str_equal (element[1], "DD"))
             {
                 if (element[2])
-                    item->text = katze_unescape_html (element[2]);
+                {
+                    gchar* text = katze_unescape_html (element[2]);
+                    katze_item_set_text (item, text);
+                    g_free (text);
+                }
                 item = NULL;
             }
             /* end of current folder, level-up */
@@ -461,16 +488,16 @@ katze_array_from_opera_file (KatzeArray* array,
             if (parts && parts[0] && parts[1])
             {
                 if (katze_str_equal (parts[0], "NAME"))
-                    item->name = g_strdup (parts[1]);
+                    katze_item_set_name (item, parts[1]);
                 else if (katze_str_equal (parts[0], "URL"))
-                    item->uri = g_strdup (parts[1]);
+                    katze_item_set_uri (item, parts[1]);
                 else if (katze_str_equal (parts[0], "DESCRIPTION"))
-                    item->text = g_strdup (parts[1]);
+                    katze_item_set_text (item, parts[1]);
                 else if (katze_str_equal (parts[0], "CREATED"))
-                    item->added = g_ascii_strtoull (parts[1], NULL, 10);
+                    katze_item_set_added (item, g_ascii_strtoull (parts[1], NULL, 10));
                 /* FIXME: Implement visited time
                 else if (katze_str_equal (parts[0], "VISITED"))
-                    item->visited = g_ascii_strtoull (parts[1], NULL, 10); */
+                    katze_item_set_visited (item, g_ascii_strtoull (parts[1], NULL, 10)); */
                 else if (katze_str_equal (parts[0], "ON PERSONALBAR"))
                     katze_item_set_meta_integer (item, "toolbar",
                         katze_str_equal (parts[1], "YES") ? 1 : -1);
@@ -781,7 +808,7 @@ string_append_netscape_item (GString*   string,
         string_append_escaped (string, katze_item_get_name (item));
         g_string_append (string, "</A>\n");
 
-        if (item->text && g_strcmp0 (item->text, ""))
+        if (g_strcmp0 (katze_str_non_null (katze_item_get_text (item)), ""))
         {
             g_string_append (string, "\t<DD>");
             string_append_escaped (string, katze_item_get_text (item));
@@ -976,19 +1003,19 @@ katze_item_set_value_from_column (sqlite3_stmt* stmt,
         const unsigned char* uri;
         uri = sqlite3_column_text (stmt, column);
         if (uri && uri[0] && uri[0] != '(')
-            item->uri = g_strdup ((gchar*)uri);
+            katze_item_set_uri (item, (gchar*)uri);
     }
     else if (g_str_equal (name, "title") || g_str_equal (name, "name"))
     {
         const unsigned char* title;
         title = sqlite3_column_text (stmt, column);
-        item->name = g_strdup ((gchar*)title);
+        katze_item_set_name (item, (gchar*)title);
     }
     else if (g_str_equal (name, "date") || g_str_equal (name, "created"))
     {
         gint date;
         date = sqlite3_column_int64 (stmt, column);
-        item->added = date;
+        katze_item_set_added (item, date);
     }
     else if (g_str_equal (name, "day") || g_str_equal (name, "app")
           || g_str_equal (name, "toolbar") || g_str_equal (name, "id")
@@ -1004,7 +1031,7 @@ katze_item_set_value_from_column (sqlite3_stmt* stmt,
     {
         const unsigned char* text;
         text = sqlite3_column_text (stmt, column);
-        item->text =  g_strdup ((gchar*)text);
+        katze_item_set_text (item, (gchar*)text);
     }
     else if (g_str_equal (name, "nick"))
     {
@@ -1135,7 +1162,7 @@ midori_array_query_recursive (KatzeArray*  bookmarks,
                 katze_item_get_meta_integer (item, "id"));
             KatzeArray* subarray = midori_array_query_recursive (bookmarks,
                 fields, "parentid=%q", parentid, TRUE);
-            katze_item_set_name (KATZE_ITEM (subarray), item->name);
+            katze_item_set_name (KATZE_ITEM (subarray), katze_item_get_name (item));
             katze_array_add_item (array, subarray);
 
             g_free (parentid);
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index fef0009..96baceb 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -490,10 +490,10 @@ midori_browser_update_history (KatzeItem*   item,
         zeitgeist_event_new_full (inter, ZEITGEIST_ZG_USER_ACTIVITY,
                                   "application://midori.desktop",
                                   zeitgeist_subject_new_full (
-            item->uri,
+            katze_item_get_uri (item),
             strstr (type, "bookmark") ? ZEITGEIST_NFO_BOOKMARK : ZEITGEIST_NFO_WEBSITE,
-            zeitgeist_manifestation_for_uri (item->uri),
-            katze_item_get_meta_string (item, "mime-type"), NULL, item->name, NULL),
+            zeitgeist_manifestation_for_uri (katze_item_get_uri (item)),
+            katze_item_get_meta_string (item, "mime-type"), NULL, katze_item_get_name (item), NULL),
                                   NULL),
         NULL);
     #endif
@@ -912,7 +912,7 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
     entry_title = gtk_entry_new ();
     gtk_entry_set_activates_default (GTK_ENTRY (entry_title), TRUE);
     value = katze_item_get_name (bookmark);
-    gtk_entry_set_text (GTK_ENTRY (entry_title), value ? value : "");
+    gtk_entry_set_text (GTK_ENTRY (entry_title), katze_str_non_null (value));
     midori_browser_edit_bookmark_title_changed_cb (GTK_ENTRY (entry_title),
                                                    GTK_DIALOG (dialog));
     g_signal_connect (entry_title, "changed",
@@ -6796,13 +6796,9 @@ _midori_browser_update_settings (MidoriBrowser* browser)
             midori_search_action_set_current_item (MIDORI_SEARCH_ACTION (
                 _action_by_name (browser, "Search")), item);
 
-        KATZE_ARRAY_FOREACH_ITEM (item, browser->search_engines)
-            if (!g_strcmp0 (item->uri, default_search))
-            {
-                midori_search_action_set_default_item (MIDORI_SEARCH_ACTION (
+        if ((item = katze_array_find_uri (browser->search_engines, default_search)))
+            midori_search_action_set_default_item (MIDORI_SEARCH_ACTION (
                 _action_by_name (browser, "Search")), item);
-                break;
-            }
     }
 
     g_object_set (browser->panel, "show-titles", !compact_sidepanel,
@@ -7132,13 +7128,9 @@ midori_browser_set_property (GObject*      object,
             midori_search_action_set_current_item (MIDORI_SEARCH_ACTION (
                 _action_by_name (browser, "Search")), item);
 
-            KATZE_ARRAY_FOREACH_ITEM (item, browser->search_engines)
-                if (!g_strcmp0 (item->uri, default_search))
-                {
-                    midori_search_action_set_default_item (MIDORI_SEARCH_ACTION (
+            if ((item = katze_array_find_uri (browser->search_engines, default_search)))
+                midori_search_action_set_default_item (MIDORI_SEARCH_ACTION (
                     _action_by_name (browser, "Search")), item);
-                    break;
-                }
         }
         break;
     }
diff --git a/midori/midori-searchaction.c b/midori/midori-searchaction.c
index dc98def..6857e07 100644
--- a/midori/midori-searchaction.c
+++ b/midori/midori-searchaction.c
@@ -1000,18 +1000,18 @@ midori_search_action_get_engine_for_form (WebKitWebView*     web_view,
         /* See midori_view_set_title: title can be first or last */
         if (ellipsize == PANGO_ELLIPSIZE_END)
         {
-            item->name = g_strdup (parts[0]);
-            item->text = g_strdup (parts[1]);
+            katze_item_set_name (item, parts[0]);
+            katze_item_set_text (item, parts[1]);
         }
         else
         {
-            item->name = g_strdup (parts[1]);
-            item->text = g_strdup (parts[2]);
+            katze_item_set_name (item, parts[1]);
+            katze_item_set_text (item, parts[2]);
         }
         g_strfreev (parts);
     }
     else
-        item->name = g_strdup (title);
+        katze_item_set_name (item, title);
 
     g_free (token_element);
     return item;
diff --git a/midori/midori-session.c b/midori/midori-session.c
index b2273ef..1e42371 100644
--- a/midori/midori-session.c
+++ b/midori/midori-session.c
@@ -488,7 +488,7 @@ midori_load_session (gpointer data)
         if (load_on_startup == MIDORI_STARTUP_BLANK_PAGE)
             katze_item_set_uri (item, "about:new");
         else
-            item->uri = g_strdup ("about:home");
+            katze_item_set_uri (item, "about:home");
         katze_array_add_item (saved_session, item);
         g_object_unref (item);
     }
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 3f63a5a..b8094c3 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -3451,7 +3451,7 @@ midori_view_new_with_item (KatzeItem*         item,
                            MidoriWebSettings* settings)
 {
     MidoriView* view = g_object_new (MIDORI_TYPE_VIEW,
-                                     "title", item ? item->name : NULL,
+                                     "title", item ? katze_item_get_name (item) : NULL,
                                      NULL);
     if (settings)
         _midori_view_set_settings (view, settings);


More information about the Xfce4-commits mailing list