aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2003-08-22 19:02:10 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2003-08-22 19:02:10 +0800
commit3e3d3961a8db405b5717cd0c02d67aa8abb8842b (patch)
tree0ba2fc9002d9227b7d33417a489addc9f6875dd5
parent17ebc02eeb18c2084823ef8555705087588719f3 (diff)
downloadgsoc2013-epiphany-3e3d3961a8db405b5717cd0c02d67aa8abb8842b.tar
gsoc2013-epiphany-3e3d3961a8db405b5717cd0c02d67aa8abb8842b.tar.gz
gsoc2013-epiphany-3e3d3961a8db405b5717cd0c02d67aa8abb8842b.tar.bz2
gsoc2013-epiphany-3e3d3961a8db405b5717cd0c02d67aa8abb8842b.tar.lz
gsoc2013-epiphany-3e3d3961a8db405b5717cd0c02d67aa8abb8842b.tar.xz
gsoc2013-epiphany-3e3d3961a8db405b5717cd0c02d67aa8abb8842b.tar.zst
gsoc2013-epiphany-3e3d3961a8db405b5717cd0c02d67aa8abb8842b.zip
Make it NULL safe
2003-08-22 Marco Pesenti Gritti <marco@gnome.org> * lib/widgets/ephy-node-view.c: (compare_string_values), (ephy_node_view_sort_func): * src/bookmarks/ephy-bookmarks-menu.c: (sort_topics), (sort_bookmarks): * src/bookmarks/ephy-topic-action.c: (sort_bookmarks), (sort_topics): Make it NULL safe * src/ephy-toolbars-model.c: (impl_get_item_id): When creating bookmark, if the title is unknown, use untitled.
-rw-r--r--ChangeLog15
-rw-r--r--lib/widgets/ephy-node-view.c42
-rw-r--r--src/bookmarks/ephy-bookmarks-menu.c51
-rw-r--r--src/bookmarks/ephy-topic-action.c65
-rwxr-xr-xsrc/ephy-toolbars-model.c10
5 files changed, 133 insertions, 50 deletions
diff --git a/ChangeLog b/ChangeLog
index 417de648b..71926cbdf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2003-08-22 Marco Pesenti Gritti <marco@gnome.org>
+
+ * lib/widgets/ephy-node-view.c: (compare_string_values),
+ (ephy_node_view_sort_func):
+ * src/bookmarks/ephy-bookmarks-menu.c: (sort_topics),
+ (sort_bookmarks):
+ * src/bookmarks/ephy-topic-action.c: (sort_bookmarks),
+ (sort_topics):
+
+ Make it NULL safe
+
+ * src/ephy-toolbars-model.c: (impl_get_item_id):
+
+ When creating bookmark, if the title is unknown, use untitled.
+
2003-08-21 Christian Persch <chpe@cvs.gnome.org>
* lib/widgets/ephy-node-view.c: (drag_data_received_cb):
diff --git a/lib/widgets/ephy-node-view.c b/lib/widgets/ephy-node-view.c
index 3baac583a..5bd528fcc 100644
--- a/lib/widgets/ephy-node-view.c
+++ b/lib/widgets/ephy-node-view.c
@@ -1041,6 +1041,38 @@ cell_renderer_edited (GtkCellRendererText *cell,
}
static int
+compare_string_values (const GValue *a_value, const GValue *b_value)
+{
+ const char *str1, *str2;
+ int retval;
+
+ str1 = g_value_get_string (a_value);
+ str2 = g_value_get_string (b_value);
+
+ if (str1 == NULL)
+ {
+ retval = -1;
+ }
+ else if (str2 == NULL)
+ {
+ retval = 1;
+ }
+ else
+ {
+ char *str_a;
+ char *str_b;
+
+ str_a = g_utf8_casefold (str1, -1);
+ str_b = g_utf8_casefold (str2, -1);
+ retval = g_utf8_collate (str_a, str_b);
+ g_free (str_a);
+ g_free (str_b);
+ }
+
+ return retval;
+}
+
+static int
ephy_node_view_sort_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
@@ -1061,20 +1093,14 @@ ephy_node_view_sort_func (GtkTreeModel *model,
GType type = gtk_tree_model_get_column_type (model, column);
GValue a_value = {0, };
GValue b_value = {0, };
- gchar *stra, *strb;
+
gtk_tree_model_get_value (model, a, column, &a_value);
gtk_tree_model_get_value (model, b, column, &b_value);
switch (G_TYPE_FUNDAMENTAL (type))
{
case G_TYPE_STRING:
- /* FIXME: this is horribly inefficient */
- stra = g_utf8_casefold (g_value_get_string (&a_value), -1);
- strb = g_utf8_casefold (g_value_get_string (&b_value), -1);
- g_return_val_if_fail (stra != NULL && strb != NULL, 0);
- retval = g_utf8_collate (stra, strb);
- g_free (stra);
- g_free (strb);
+ retval = compare_string_values (&a_value, &b_value);
break;
case G_TYPE_INT:
if (g_value_get_int (&a_value) < g_value_get_int (&b_value))
diff --git a/src/bookmarks/ephy-bookmarks-menu.c b/src/bookmarks/ephy-bookmarks-menu.c
index 3e32e7493..9231d7a4c 100644
--- a/src/bookmarks/ephy-bookmarks-menu.c
+++ b/src/bookmarks/ephy-bookmarks-menu.c
@@ -119,28 +119,26 @@ sort_topics (gconstpointer a, gconstpointer b)
{
EphyNode *node_a = (EphyNode *)a;
EphyNode *node_b = (EphyNode *)b;
- EphyNodePriority priority_a, priority_b;
- char *str_a = NULL;
- char *str_b = NULL;
+ const char *title1, *title2;
int retval;
- priority_a = ephy_node_get_property_int (node_a, EPHY_NODE_KEYWORD_PROP_PRIORITY);
- priority_b = ephy_node_get_property_int (node_b, EPHY_NODE_KEYWORD_PROP_PRIORITY);
+ title1 = ephy_node_get_property_string (node_a, EPHY_NODE_KEYWORD_PROP_NAME);
+ title2 = ephy_node_get_property_string (node_b, EPHY_NODE_KEYWORD_PROP_NAME);
- if (priority_a < priority_b)
+ if (title1 == NULL)
{
retval = -1;
}
- else if (priority_a > priority_b)
+ else if (title2 == NULL)
{
retval = 1;
}
else
{
- str_a = g_utf8_casefold (ephy_node_get_property_string (node_a, EPHY_NODE_KEYWORD_PROP_NAME),
- -1);
- str_b = g_utf8_casefold (ephy_node_get_property_string (node_b, EPHY_NODE_KEYWORD_PROP_NAME),
- -1);
+ char *str_a, *str_b;
+
+ str_a = g_utf8_casefold (title1, -1);
+ str_b = g_utf8_casefold (title2, -1);
retval = g_utf8_collate (str_a, str_b);
g_free (str_a);
g_free (str_b);
@@ -154,17 +152,30 @@ sort_bookmarks (gconstpointer a, gconstpointer b)
{
EphyNode *node_a = (EphyNode *)a;
EphyNode *node_b = (EphyNode *)b;
- char *str_a = NULL;
- char *str_b = NULL;
+ const char *title1, *title2;
int retval;
- str_a = g_utf8_casefold (ephy_node_get_property_string (node_a, EPHY_NODE_BMK_PROP_TITLE),
- -1);
- str_b = g_utf8_casefold (ephy_node_get_property_string (node_b, EPHY_NODE_BMK_PROP_TITLE),
- -1);
- retval = g_utf8_collate (str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ title1 = ephy_node_get_property_string (node_a, EPHY_NODE_BMK_PROP_TITLE);
+ title2 = ephy_node_get_property_string (node_b, EPHY_NODE_BMK_PROP_TITLE);
+
+ if (title1 == NULL)
+ {
+ retval = -1;
+ }
+ else if (title2 == NULL)
+ {
+ retval = 1;
+ }
+ else
+ {
+ char *str_a, *str_b;
+
+ str_a = g_utf8_casefold (title1, -1);
+ str_b = g_utf8_casefold (title2, -1);
+ retval = g_utf8_collate (str_a, str_b);
+ g_free (str_a);
+ g_free (str_b);
+ }
return retval;
}
diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c
index b594bf6aa..7fa6ab705 100644
--- a/src/bookmarks/ephy-topic-action.c
+++ b/src/bookmarks/ephy-topic-action.c
@@ -174,17 +174,30 @@ sort_bookmarks (gconstpointer a, gconstpointer b)
{
EphyNode *node_a = (EphyNode *)a;
EphyNode *node_b = (EphyNode *)b;
- char *str_a = NULL;
- char *str_b = NULL;
+ const char *title1, *title2;
int retval;
- str_a = g_utf8_casefold (ephy_node_get_property_string (node_a, EPHY_NODE_BMK_PROP_TITLE),
- -1);
- str_b = g_utf8_casefold (ephy_node_get_property_string (node_b, EPHY_NODE_BMK_PROP_TITLE),
- -1);
- retval = g_utf8_collate (str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ title1 = ephy_node_get_property_string (node_a, EPHY_NODE_BMK_PROP_TITLE);
+ title2 = ephy_node_get_property_string (node_b, EPHY_NODE_BMK_PROP_TITLE);
+
+ if (title1 == NULL)
+ {
+ retval = -1;
+ }
+ else if (title2 == NULL)
+ {
+ retval = 1;
+ }
+ else
+ {
+ char *str_a, *str_b;
+
+ str_a = g_utf8_casefold (title1, -1);
+ str_b = g_utf8_casefold (title2, -1);
+ retval = g_utf8_collate (str_a, str_b);
+ g_free (str_a);
+ g_free (str_b);
+ }
return retval;
}
@@ -290,20 +303,30 @@ sort_topics (gconstpointer a, gconstpointer b)
{
EphyNode *node_a = (EphyNode *)a;
EphyNode *node_b = (EphyNode *)b;
- EphyNodePriority priority_a, priority_b;
- char *str_a = NULL;
- char *str_b = NULL;
+ const char *title1, *title2;
int retval;
- priority_a = ephy_node_get_property_int (node_a, EPHY_NODE_KEYWORD_PROP_PRIORITY);
- priority_b = ephy_node_get_property_int (node_b, EPHY_NODE_KEYWORD_PROP_PRIORITY);
- str_a = g_utf8_casefold (ephy_node_get_property_string (node_a, EPHY_NODE_KEYWORD_PROP_NAME),
- -1);
- str_b = g_utf8_casefold (ephy_node_get_property_string (node_b, EPHY_NODE_KEYWORD_PROP_NAME),
- -1);
- retval = g_utf8_collate (str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ title1 = ephy_node_get_property_string (node_a, EPHY_NODE_KEYWORD_PROP_NAME);
+ title2 = ephy_node_get_property_string (node_b, EPHY_NODE_KEYWORD_PROP_NAME);
+
+ if (title1 == NULL)
+ {
+ retval = -1;
+ }
+ else if (title2 == NULL)
+ {
+ retval = 1;
+ }
+ else
+ {
+ char *str_a, *str_b;
+
+ str_a = g_utf8_casefold (title1, -1);
+ str_b = g_utf8_casefold (title2, -1);
+ retval = g_utf8_collate (str_a, str_b);
+ g_free (str_a);
+ g_free (str_b);
+ }
return retval;
}
diff --git a/src/ephy-toolbars-model.c b/src/ephy-toolbars-model.c
index 3933be965..6384b06e5 100755
--- a/src/ephy-toolbars-model.c
+++ b/src/ephy-toolbars-model.c
@@ -28,6 +28,7 @@
#include "ephy-string.h"
#include <string.h>
+#include <bonobo/bonobo-i18n.h>
static void ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass);
static void ephy_toolbars_model_init (EphyToolbarsModel *t);
@@ -188,8 +189,15 @@ impl_get_item_id (EggToolbarsModel *t,
/* Create the bookmark, it does not exist */
EphyHistory *gh;
const char *icon;
+ const char *title;
- node = ephy_bookmarks_add (bookmarks, netscape_url[NAME], netscape_url[URL]);
+ title = netscape_url[NAME];
+ if (title == NULL || *title == '\0')
+ {
+ title = _("Untitled");
+ }
+
+ node = ephy_bookmarks_add (bookmarks, title, netscape_url[URL]);
g_return_val_if_fail (node != NULL, NULL);
gh = ephy_embed_shell_get_global_history (EPHY_EMBED_SHELL (ephy_shell));