~midori/midori/trunk

« back to all changes in this revision

Viewing changes to panels/midori-bookmarks.c

  • Committer: André Auzi
  • Date: 2013-08-05 19:52:52 UTC
  • mto: This revision was merged to the branch mainline in revision 6406.
  • Revision ID: aauzi@free.fr-20130805195252-89hqx89j37gl7v61
Derive MidoriBookmarksDb from KatzeArray in order to implement update-item signal
Implements, partially, signal redirection to parent KatzeArray after database operations.
On update-item signal, both bookmarkbar and bookmarks panel update themself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    GtkWidget* delete;
46
46
    GtkWidget* treeview;
47
47
    MidoriApp* app;
48
 
    KatzeArray* array;
 
48
    MidoriBookmarksDb* bookmarks_db;
49
49
 
50
50
    gint filter_timeout;
51
51
    gchar* filter;
125
125
    return STOCK_BOOKMARKS;
126
126
}
127
127
 
 
128
#if 0
128
129
/* TODO: Function never used */
129
130
void
130
131
midori_bookmarks_export_array_db (sqlite3*    db,
138
139
    gchar* parent_id;
139
140
 
140
141
    parent_id = g_strdup_printf ("%" G_GINT64_FORMAT, parentid);
141
 
    if (!(root_array = midori_array_query_recursive (array, "*", "parentid = %q", parent_id, FALSE)))
 
142
    if (!(root_array = midori_bookmarks_db_query_recursive (array, "*", "parentid = %q", parent_id, FALSE)))
142
143
    {
143
144
        g_free (parent_id);
144
145
        return;
160
161
    g_free (parent_id);
161
162
    g_list_free (list);
162
163
}
 
164
#endif
163
165
 
164
166
static KatzeArray*
165
167
midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks,
169
171
    KatzeArray* array;
170
172
 
171
173
    if (keyword && *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);
 
174
        array = midori_bookmarks_db_query_recursive (bookmarks->bookmarks_db,
 
175
            "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "title LIKE '%%%q%%'", keyword, FALSE);
174
176
    else
175
177
    {
176
178
        if (parentid > 0)
177
179
        {
178
180
            gchar* parent_id = g_strdup_printf ("%" G_GINT64_FORMAT, parentid);
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);
 
181
            array = midori_bookmarks_db_query_recursive (bookmarks->bookmarks_db,
 
182
                "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid = %q", parent_id, FALSE);
181
183
 
182
184
            g_free (parent_id);
183
185
        }
184
186
        else
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);
 
187
            array = midori_bookmarks_db_query_recursive (bookmarks->bookmarks_db,
 
188
                "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid IS NULL", NULL, FALSE);
187
189
    }
188
190
    return array ? array : katze_array_new (KATZE_TYPE_ITEM);
189
191
}
274
276
    else
275
277
        parentid = 0;
276
278
 
277
 
    katze_array_remove_item (bookmarks->array, item);
278
279
    katze_item_set_meta_integer (item, "parentid", parentid);
279
 
    katze_array_add_item (bookmarks->array, item);
 
280
 
 
281
    midori_bookmarks_db_update_item (bookmarks->bookmarks_db, item);
280
282
 
281
283
    g_object_unref (item);
282
284
    if (new_parent)
416
418
 
417
419
        if (KATZE_ITEM_IS_FOLDER (item))
418
420
        {
419
 
            gint child_folders_count = midori_array_count_recursive (bookmarks->array,
 
421
            gint child_folders_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db,
420
422
                "uri = ''", NULL, item, FALSE);
421
 
            gint child_bookmarks_count = midori_array_count_recursive (bookmarks->array,
 
423
            gint child_bookmarks_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db,
422
424
                "uri <> ''", NULL, item, FALSE);
423
425
            gchar* child_folders_str = midori_bookmarks_statusbar_subfolders_str (child_folders_count);
424
426
            gchar* child_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (child_bookmarks_count);
451
453
    }
452
454
    else
453
455
    {
454
 
        gint child_folders_count = midori_array_count_recursive (bookmarks->array,
 
456
        gint child_folders_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db,
455
457
            "uri = ''", NULL, NULL, FALSE);
456
 
        gint child_bookmarks_count = midori_array_count_recursive (bookmarks->array,
 
458
        gint child_bookmarks_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db,
457
459
            "uri <> ''", NULL, NULL, FALSE);
458
460
        gchar* child_folders_str = midori_bookmarks_statusbar_subfolders_str (child_folders_count);
459
461
        gchar* child_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (child_bookmarks_count);
499
501
 
500
502
        /* Manually remove the iter and block clearing the treeview */
501
503
        gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
502
 
        g_signal_handlers_block_by_func (bookmarks->array,
 
504
        g_signal_handlers_block_by_func (bookmarks->bookmarks_db,
503
505
            midori_bookmarks_remove_item_cb, bookmarks);
504
 
        katze_array_remove_item (bookmarks->array, item);
505
 
        g_signal_handlers_unblock_by_func (bookmarks->array,
 
506
        midori_bookmarks_db_remove_item (bookmarks->bookmarks_db, item);
 
507
        g_signal_handlers_unblock_by_func (bookmarks->bookmarks_db,
506
508
            midori_bookmarks_remove_item_cb, bookmarks);
507
509
        g_object_unref (item);
508
510
    }
585
587
    GtkTreeModel* model;
586
588
 
587
589
    model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
588
 
    if (bookmarks->array)
 
590
    if (bookmarks->bookmarks_db)
589
591
    {
590
 
        g_object_unref (bookmarks->array);
 
592
        g_object_unref (bookmarks->bookmarks_db);
591
593
        gtk_tree_store_clear (GTK_TREE_STORE (model));
592
594
    }
593
595
    katze_assign (bookmarks->app, app);
595
597
        return;
596
598
 
597
599
    g_object_ref (app);
598
 
    bookmarks->array = katze_object_get_object (app, "bookmarks");
 
600
    bookmarks->bookmarks_db = katze_object_get_object (app, "bookmarks");
599
601
    midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), NULL, 0, NULL);
600
 
    g_signal_connect_after (bookmarks->array, "add-item",
601
 
                      G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
602
 
    g_signal_connect (bookmarks->array, "remove-item",
603
 
                      G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks);
604
 
    g_signal_connect (bookmarks->array, "update",
605
 
                      G_CALLBACK (midori_bookmarks_update_cb), bookmarks);
 
602
    g_signal_connect_after (bookmarks->bookmarks_db, "add-item",
 
603
        G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
 
604
    g_signal_connect (bookmarks->bookmarks_db, "remove-item",
 
605
        G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks);
 
606
    g_signal_connect (bookmarks->bookmarks_db, "update",
 
607
        G_CALLBACK (midori_bookmarks_update_cb), bookmarks);
606
608
    g_signal_connect_after (model, "row-changed",
607
 
                            G_CALLBACK (midori_bookmarks_row_changed_cb),
608
 
                            bookmarks);
 
609
        G_CALLBACK (midori_bookmarks_row_changed_cb),
 
610
        bookmarks);
609
611
}
610
612
 
611
613
static void
835
837
    menu = gtk_menu_new ();
836
838
    if (KATZE_ITEM_IS_FOLDER (item))
837
839
    {
838
 
        gint child_bookmarks_count = midori_array_count_recursive (bookmarks->array,
 
840
        gint child_bookmarks_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db,
839
841
            "uri <> ''", NULL, item, FALSE);
840
842
 
841
843
        midori_bookmarks_popup_item (menu,