Introduce ITEM_IS_BOOKMARK|FOLDER|SEPARATOR in bookmark panel

The implicit logic for differentiating items is not easy to
read, so we introduce macros for that.
This commit is contained in:
Christian Dywan 2010-07-01 00:13:18 +02:00
parent b0191b69b0
commit 62f5a1c974

View file

@ -24,6 +24,10 @@
#include <gdk/gdkkeysyms.h>
#define ITEM_IS_BOOKMARK(item) (item && katze_item_get_uri (item))
#define ITEM_IS_FOLDER(item) (item && !katze_item_get_uri (item))
#define ITEM_IS_SEPARATOR(item) (item == NULL)
void
midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
KatzeItem* bookmark,
@ -217,7 +221,7 @@ midori_bookmarks_insert_item_db (sqlite3* db,
int type = 0;
gchar* parent;
if (katze_item_get_uri (item))
if (ITEM_IS_BOOKMARK (item))
type = 1;
if (folder)
@ -257,7 +261,7 @@ midori_bookmarks_remove_item_from_db (sqlite3* db,
gchar* sqlcmd;
char* errmsg = NULL;
if (katze_item_get_uri (item))
if (ITEM_IS_BOOKMARK (item))
sqlcmd = sqlite3_mprintf (
"DELETE FROM bookmarks WHERE uri = '%q'",
katze_item_get_uri (item));
@ -326,16 +330,15 @@ midori_bookmarks_edit_clicked_cb (GtkWidget* toolitem,
&model, &iter))
{
KatzeItem* item;
gboolean is_separator;
MidoriBrowser* browser;
gtk_tree_model_get (model, &iter, 0, &item, -1);
is_separator = item && !katze_item_get_uri (item);
if (!is_separator)
{
MidoriBrowser* browser = midori_browser_get_for_widget (toolitem);
midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
}
g_assert (!ITEM_IS_SEPARATOR (item));
browser = midori_browser_get_for_widget (toolitem);
midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
g_object_unref (item);
}
}
@ -381,16 +384,13 @@ midori_bookmarks_cursor_or_row_changed_cb (GtkTreeView* treeview,
if (katze_tree_view_get_selected_iter (treeview, &model, &iter))
{
gboolean is_separator;
gtk_tree_model_get (model, &iter, 0, &item, -1);
if (!item)
return;
is_separator = !katze_item_get_uri (item);
gtk_widget_set_sensitive (bookmarks->edit, !is_separator);
gtk_widget_set_sensitive (bookmarks->edit, !ITEM_IS_SEPARATOR (item));
gtk_widget_set_sensitive (bookmarks->delete, TRUE);
g_object_unref (item);
if (item != NULL)
g_object_unref (item);
}
else
{
@ -550,10 +550,10 @@ midori_bookmarks_treeview_render_icon_cb (GtkTreeViewColumn* column,
/* TODO: Would it be better to not do this on every redraw? */
pixbuf = NULL;
if (item && !katze_item_get_uri (item) && katze_item_get_name (item))
if (ITEM_IS_FOLDER (item))
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
GTK_ICON_SIZE_MENU, NULL);
else if (item && katze_item_get_uri (item))
else if (ITEM_IS_BOOKMARK (item))
pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
g_object_set (renderer, "pixbuf", pixbuf, NULL);
@ -621,7 +621,7 @@ midori_bookmarks_popup_item (GtkWidget* menu,
const gchar* uri;
GtkWidget* menuitem;
uri = katze_item_get_uri (item);
uri = ITEM_IS_BOOKMARK (item) ? katze_item_get_uri (item) : NULL;
menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
if (label)
@ -629,8 +629,8 @@ midori_bookmarks_popup_item (GtkWidget* menu,
GTK_BIN (menuitem))), label);
if (!strcmp (stock_id, GTK_STOCK_EDIT))
gtk_widget_set_sensitive (menuitem,
KATZE_IS_ARRAY (item) || uri != NULL);
else if (!KATZE_IS_ARRAY (item) && strcmp (stock_id, GTK_STOCK_DELETE))
!ITEM_IS_SEPARATOR (item));
else if (!ITEM_IS_FOLDER (item) && strcmp (stock_id, GTK_STOCK_DELETE))
gtk_widget_set_sensitive (menuitem, uri != NULL);
g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
g_signal_connect (menuitem, "activate", G_CALLBACK (callback), bookmarks);
@ -646,9 +646,8 @@ midori_bookmarks_open_activate_cb (GtkWidget* menuitem,
const gchar* uri;
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
uri = katze_item_get_uri (item);
if (uri && *uri)
if ((uri = katze_item_get_uri (item)) && *uri)
{
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
midori_browser_set_current_uri (browser, uri);
@ -664,11 +663,12 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
guint n;
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
if (KATZE_IS_ARRAY (item))
if (ITEM_IS_FOLDER (item))
{
KatzeItem* child;
guint i = 0;
g_return_if_fail (KATZE_IS_ARRAY (item));
while ((child = katze_array_get_nth_item (KATZE_ARRAY (item), i)))
{
if ((uri = katze_item_get_uri (child)) && *uri)
@ -727,16 +727,13 @@ midori_bookmarks_edit_activate_cb (GtkWidget* menuitem,
MidoriBookmarks* bookmarks)
{
KatzeItem* item;
gboolean is_separator;
MidoriBrowser* browser;
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
is_separator = !KATZE_IS_ARRAY (item) && !katze_item_get_uri (item);
g_assert (!ITEM_IS_SEPARATOR (item));
if (!is_separator)
{
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
}
browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
midori_browser_edit_bookmark_dialog_new (browser, item, FALSE, FALSE);
}
static void
@ -772,7 +769,7 @@ midori_bookmarks_popup (GtkWidget* widget,
GtkWidget* menuitem;
menu = gtk_menu_new ();
if (KATZE_IS_ARRAY (item))
if (ITEM_IS_FOLDER (item))
midori_bookmarks_popup_item (menu,
STOCK_TAB_NEW, _("Open all in _Tabs"),
item, midori_bookmarks_open_in_tab_activate_cb, bookmarks);
@ -815,9 +812,8 @@ midori_bookmarks_button_release_event_cb (GtkWidget* widget,
if (event->button == 2)
{
const gchar* uri = katze_item_get_uri (item);
if (uri && *uri)
const gchar* uri;
if (ITEM_IS_BOOKMARK (item) && (uri = katze_item_get_uri (item)) && *uri)
{
MidoriBrowser* browser;
gint n;
@ -830,7 +826,8 @@ midori_bookmarks_button_release_event_cb (GtkWidget* widget,
else
midori_bookmarks_popup (widget, event, item, bookmarks);
g_object_unref (item);
if (item != NULL)
g_object_unref (item);
return TRUE;
}
return FALSE;