]> spindle.queued.net Git - midori/commitdiff
Implement adding and removing of adblock URIs
authorChristian Dywan <christian@twotoasts.de>
Fri, 17 Jul 2009 20:05:20 +0000 (22:05 +0200)
committerChristian Dywan <christian@twotoasts.de>
Fri, 17 Jul 2009 20:05:20 +0000 (22:05 +0200)
extensions/adblock.c

index 0bd15cb8f940f4af2a2dc57c4629b74553a2a855..447a6f04e4129b51b7d1d17257c71ceaea94737b 100644 (file)
@@ -69,6 +69,33 @@ adblock_preferences_model_row_changed_cb (GtkTreeModel*    model,
     midori_extension_set_string_list (extension, "filters", filters, length);
 }
 
+static void
+adblock_preferences_model_row_deleted_cb (GtkTreeModel*    model,
+                                          GtkTreePath*     path,
+                                          MidoriExtension* extension)
+{
+    GtkTreeIter iter;
+    adblock_preferences_model_row_changed_cb (model, path, &iter, extension);
+}
+
+static void
+adblock_preferences_add_clicked_cb (GtkWidget*    button,
+                                    GtkTreeModel* model)
+{
+    gtk_list_store_insert_with_values (GTK_LIST_STORE (model),
+        NULL, 0, 0, "", -1);
+}
+
+static void
+adblock_preferences_remove_clicked_cb (GtkWidget*   button,
+                                       GtkTreeView* treeview)
+{
+    GtkTreeModel* model;
+    GtkTreeIter iter;
+    if (katze_tree_view_get_selected_iter (treeview, &model, &iter))
+        gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+}
+
 static GtkWidget*
 adblock_get_preferences_dialog (MidoriExtension* extension)
 {
@@ -122,8 +149,14 @@ adblock_get_preferences_dialog (MidoriExtension* extension)
     gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
                                  TRUE, TRUE, 12);
     liststore = gtk_list_store_new (1, G_TYPE_STRING);
-    g_signal_connect (liststore, "row-changed",
-        G_CALLBACK (adblock_preferences_model_row_changed_cb), extension);
+    g_object_connect (liststore,
+        "signal::row-inserted",
+        adblock_preferences_model_row_changed_cb, extension,
+        "signal::row-changed",
+        adblock_preferences_model_row_changed_cb, extension,
+        "signal::row-deleted",
+        adblock_preferences_model_row_deleted_cb, extension,
+        NULL);
     treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (liststore));
     gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
     column = gtk_tree_view_column_new ();
@@ -159,18 +192,16 @@ adblock_get_preferences_dialog (MidoriExtension* extension)
     vbox = gtk_vbox_new (FALSE, 4);
     gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 4);
     button = gtk_button_new_from_stock (GTK_STOCK_ADD);
-    /* g_signal_connect (button, "clicked",
-        G_CALLBACK (adblock_preferences_add_cb), extension); */
+    g_signal_connect (button, "clicked",
+        G_CALLBACK (adblock_preferences_add_clicked_cb), liststore);
     gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-    gtk_widget_set_sensitive (button, FALSE);
     button = gtk_button_new_from_stock (GTK_STOCK_EDIT);
     gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
     gtk_widget_set_sensitive (button, FALSE);
     button = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
-    /* g_signal_connect (button, "clicked",
-        G_CALLBACK (adblock_preferences_remove_cb), extension); */
+    g_signal_connect (button, "clicked",
+        G_CALLBACK (adblock_preferences_remove_clicked_cb), treeview);
     gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
-    gtk_widget_set_sensitive (button, FALSE);
     button = gtk_label_new (""); /* This is an invisible separator */
     gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 8);
     gtk_widget_set_sensitive (button, FALSE);