Fix open directory in tabs in bookmarks sidebar

This commit is contained in:
Alexander Butenko 2010-06-30 20:45:14 -04:00 committed by Christian Dywan
parent 62f5a1c974
commit 791c38ae3e

View file

@ -139,19 +139,15 @@ midori_bookmarks_import_array_db (KatzeArray* array,
}
}
static gboolean
static KatzeArray*
midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks,
GtkTreeStore* model,
GtkTreeIter* parent,
const gchar* folder)
{
sqlite3* db;
sqlite3_stmt* statement;
gint result;
const gchar* sqlcmd;
GtkTreeIter iter;
GtkTreeIter root_iter;
KatzeArray* array;
db = g_object_get_data (G_OBJECT (bookmarks->array), "db");
@ -161,7 +157,9 @@ midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks,
sqlite3_bind_text (statement, 1, g_strdup(folder), -1, g_free);
if (result != SQLITE_OK)
return FALSE;
return NULL;
array = katze_array_new (KATZE_TYPE_ITEM);
while ((result = sqlite3_step (statement)) == SQLITE_ROW)
{
@ -183,24 +181,12 @@ midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks,
katze_item_set_meta_integer (item, "toolbar", toolbar);
/* type 0 -- folder, 1 -- entry */
if (type == 0)
if (type == 1)
{
gtk_tree_store_insert_with_values (model, &root_iter, parent,
0, 0, item, -1);
/* That's an invisible dummy, so we always have an expander */
gtk_tree_store_insert_with_values (model, &iter, &root_iter,
0, 0, NULL, -1);
}
else
{
if (!uri)
continue;
katze_item_set_uri (item, (gchar*)uri);
katze_item_set_meta_integer (item, "app", app);
gtk_tree_store_insert_with_values (model, NULL, parent,
0, 0, item, -1);
}
katze_array_add_item (array, item);
}
if (result != SQLITE_DONE)
@ -208,7 +194,39 @@ midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks,
sqlite3_errmsg (db));
sqlite3_finalize (statement);
return FALSE;
return array;
}
static void
midori_bookmarks_read_from_db_to_model (MidoriBookmarks* bookmarks,
GtkTreeStore* model,
GtkTreeIter* parent,
const gchar* folder)
{
KatzeArray* array;
KatzeItem* child;
GtkTreeIter iter;
GtkTreeIter root_iter;
guint i = 0;
array = midori_bookmarks_read_from_db (bookmarks, folder);
while ((child = katze_array_get_nth_item (KATZE_ARRAY (array), i)))
{
if (ITEM_IS_BOOKMARK (child))
{
gtk_tree_store_insert_with_values (model, NULL, parent,
0, 0, child, -1);
}
else
{
gtk_tree_store_insert_with_values (model, &root_iter, parent,
0, 0, child, -1);
/* That's an invisible dummy, so we always have an expander */
gtk_tree_store_insert_with_values (model, &iter, &root_iter,
0, 0, NULL, -1);
}
i++;
}
}
void
@ -491,7 +509,7 @@ midori_bookmarks_set_app (MidoriBookmarks* bookmarks,
g_object_set_data (G_OBJECT (bookmarks->array), "treeview", bookmarks->treeview);
#if HAVE_SQLITE
midori_bookmarks_read_from_db (bookmarks, GTK_TREE_STORE (model), NULL, "");
midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), NULL, "");
g_signal_connect_after (model, "row-changed",
G_CALLBACK (midori_bookmarks_row_changed_cb),
bookmarks);
@ -666,10 +684,12 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
if (ITEM_IS_FOLDER (item))
{
KatzeItem* child;
KatzeArray* array;
guint i = 0;
g_return_if_fail (KATZE_IS_ARRAY (item));
while ((child = katze_array_get_nth_item (KATZE_ARRAY (item), i)))
array = midori_bookmarks_read_from_db (bookmarks, katze_item_get_name (item));
g_return_if_fail (KATZE_IS_ARRAY (array));
while ((child = katze_array_get_nth_item (KATZE_ARRAY (array), i)))
{
if ((uri = katze_item_get_uri (child)) && *uri)
{
@ -686,9 +706,7 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
i++;
}
}
else
{
if ((uri = katze_item_get_uri (item)) && *uri)
else if ((uri = katze_item_get_uri (item)) && *uri)
{
MidoriBrowser* browser;
MidoriWebSettings* settings;
@ -701,7 +719,6 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
g_object_unref (settings);
}
}
}
static void
midori_bookmarks_open_in_window_activate_cb (GtkWidget* menuitem,
@ -887,7 +904,7 @@ midori_bookmarks_row_expanded_cb (GtkTreeView* treeview,
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
gtk_tree_model_get (model, iter, 0, &item, -1);
#if HAVE_SQLITE
midori_bookmarks_read_from_db (bookmarks, GTK_TREE_STORE (model),
midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model),
iter, katze_item_get_name (item));
#endif
g_object_unref (item);