160
161
g_list_free (list);
164
midori_bookmarks_import_array (KatzeArray* bookmarks,
174
KATZE_ARRAY_FOREACH_ITEM_L (item, array, list)
176
Katze_item_set_meta_integer (item, "parentid", parentid);
177
katze_array_add_item (bookmarks, item);
178
if (KATZE_IS_ARRAY (item))
179
midori_bookmarks_import_array (bookmarks, KATZE_ARRAY (item),
180
katze_item_get_meta_integer(item, "id"));
185
164
static KatzeArray*
186
165
midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks,
190
169
KatzeArray* array;
192
171
if (keyword && *keyword)
193
array = midori_array_query (bookmarks->array,
194
"id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "title LIKE '%%%q%%'", keyword);
172
array = midori_array_query_recursive (bookmarks->array,
173
"id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "title LIKE '%%%q%%'", keyword, FALSE);
197
176
if (parentid > 0)
199
178
gchar* parent_id = g_strdup_printf ("%" G_GINT64_FORMAT, parentid);
200
array = midori_array_query (bookmarks->array,
201
"id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid = %q", parent_id);
179
array = midori_array_query_recursive (bookmarks->array,
180
"id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid = %q", parent_id, FALSE);
203
182
g_free (parent_id);
206
array = midori_array_query (bookmarks->array,
207
"id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid IS NULL", NULL);
185
array = midori_array_query_recursive (bookmarks->array,
186
"id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid IS NULL", NULL, FALSE);
209
188
return array ? array : katze_array_new (KATZE_TYPE_ITEM);
235
214
g_object_unref (item);
239
midori_bookmarks_insert_item_db (sqlite3* db,
245
KatzeItem* old_parent;
248
const gchar* uri = NULL;
249
const gchar* desc = NULL;
252
/* Bookmarks must have a name, import may produce invalid items */
253
g_return_val_if_fail (katze_item_get_name (item), seq);
258
if (katze_item_get_meta_integer (item, "id") > 0)
259
id = g_strdup_printf ("%" G_GINT64_FORMAT, katze_item_get_meta_integer(item, "id"));
261
id = g_strdup_printf ("NULL");
263
if (KATZE_ITEM_IS_BOOKMARK (item))
264
uri = katze_item_get_uri (item);
266
if (katze_item_get_text (item))
267
desc = katze_item_get_text (item);
269
/* Use folder, otherwise fallback to parent folder */
270
old_parent = katze_item_get_parent (item);
272
new_parentid = g_strdup_printf ("%" G_GINT64_FORMAT, parentid);
273
else if (old_parent && katze_item_get_meta_integer (old_parent, "id") > 0)
274
new_parentid = g_strdup_printf ("%" G_GINT64_FORMAT, katze_item_get_meta_integer (old_parent, "id"));
276
new_parentid = g_strdup_printf ("NULL");
278
sqlcmd = sqlite3_mprintf (
279
"INSERT INTO bookmarks (id, parentid, title, uri, desc, toolbar, app) "
280
"VALUES (%q, %q, '%q', '%q', '%q', %d, %d)",
283
katze_item_get_name (item),
284
katze_str_non_null (uri),
285
katze_str_non_null (desc),
286
katze_item_get_meta_boolean (item, "toolbar"),
287
katze_item_get_meta_boolean (item, "app"));
289
if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) == SQLITE_OK)
292
if (g_str_equal (id, "NULL"))
294
KatzeArray* seq_array;
296
sqlite3_free (sqlcmd);
297
sqlcmd = sqlite3_mprintf (
298
"SELECT seq FROM sqlite_sequence WHERE name = 'bookmarks'");
300
seq_array = katze_array_from_sqlite (db, sqlcmd);
301
if (katze_array_get_nth_item (seq_array, 0))
303
KatzeItem* seq_item = katze_array_get_nth_item (seq_array, 0);
305
seq = katze_item_get_meta_integer (seq_item, "seq");
306
katze_item_set_meta_integer (item, "id", seq);
308
g_object_unref (seq_array);
313
g_printerr (_("Failed to add bookmark item: %s\n"), errmsg);
314
sqlite3_free (errmsg);
317
sqlite3_free (sqlcmd);
318
g_free (new_parentid);
325
218
midori_bookmarks_add_item_cb (KatzeArray* array,
594
midori_bookmarks_update_item_db (sqlite3* db,
603
id = g_strdup_printf ("%" G_GINT64_FORMAT,
604
katze_item_get_meta_integer (item, "id"));
606
if (katze_item_get_meta_integer (item, "parentid") > 0)
607
parentid = g_strdup_printf ("%" G_GINT64_FORMAT,
608
katze_item_get_meta_integer (item, "parentid"));
610
parentid = g_strdup_printf ("NULL");
612
sqlcmd = sqlite3_mprintf (
613
"UPDATE bookmarks SET "
614
"parentid=%q, title='%q', uri='%q', desc='%q', toolbar=%d, app=%d "
617
katze_item_get_name (item),
618
katze_str_non_null (katze_item_get_uri (item)),
619
katze_str_non_null (katze_item_get_meta_string (item, "desc")),
620
katze_item_get_meta_boolean (item, "toolbar"),
621
katze_item_get_meta_boolean (item, "app"),
625
if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
628
g_printerr (_("Failed to update bookmark: %s\n"), errmsg);
629
sqlite3_free (errmsg);
632
sqlite3_free (sqlcmd);
640
487
midori_bookmarks_delete_clicked_cb (GtkWidget* toolitem,
641
488
MidoriBookmarks* bookmarks)