[Xfce4-commits] <midori:master> Log bookmarks, history and downloads to zeitgeist

Christian Dywan noreply at xfce.org
Mon Aug 6 00:34:01 CEST 2012


Updating branch refs/heads/master
         to 4cd88d574648220e6c6242dae43bc486185af5c3 (commit)
       from eb0238328e70097743fe4d3ea2b1c97db38a2f78 (commit)

commit 4cd88d574648220e6c6242dae43bc486185af5c3
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Aug 5 22:20:13 2012 +0200

    Log bookmarks, history and downloads to zeitgeist
    
    Fixes: https://bugs.launchpad.net/midori/+bug/783588

 midori/midori-browser.c       |   70 +++++++++++++++++++++++++++++++++++-----
 midori/midori-browser.h       |    5 +++
 midori/midori-view.c          |    4 ++-
 midori/wscript_build          |    2 +-
 tests/wscript_build           |    2 +-
 toolbars/midori-transferbar.c |    8 ++++-
 wscript                       |    1 +
 7 files changed, 79 insertions(+), 13 deletions(-)

diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index c4cbe60..d5b9540 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -38,6 +38,10 @@
     #include <granite.h>
 #endif
 
+#if HAVE_ZEITGEIST
+    #include <zeitgeist.h>
+#endif
+
 #ifdef HAVE_UNISTD_H
     #include <unistd.h>
 #endif
@@ -460,6 +464,46 @@ _midori_browser_update_progress (MidoriBrowser* browser,
     midori_location_action_set_progress (action, progress);
 }
 
+/**
+ * midori_browser_update_history:
+ * @item: a #KatzeItem
+ * @type: "website", "bookmark" or "download"
+ * @event: "access", "leave", "modify", "delete"
+ *
+ * Since: 0.4.7
+ **/
+void
+midori_browser_update_history (KatzeItem*   item,
+                               const gchar* type,
+                               const gchar* event)
+{
+    #if HAVE_ZEITGEIST
+    const gchar* inter;
+    if (strstr (event, "access"))
+        inter = ZEITGEIST_ZG_ACCESS_EVENT;
+    else if (strstr (event, "leave"))
+        inter = ZEITGEIST_ZG_LEAVE_EVENT;
+    else if (strstr (event, "modify"))
+        inter = ZEITGEIST_ZG_MODIFY_EVENT;
+    else if (strstr (event, "create"))
+        inter = ZEITGEIST_ZG_CREATE_EVENT;
+    else if (strstr (event, "delete"))
+        inter = ZEITGEIST_ZG_DELETE_EVENT;
+    else
+        g_assert_not_reached ();
+    zeitgeist_log_insert_events_no_reply (zeitgeist_log_get_default (),
+        zeitgeist_event_new_full (inter, ZEITGEIST_ZG_USER_ACTIVITY,
+                                  "application://midori.desktop",
+                                  zeitgeist_subject_new_full (
+            item->uri,
+            strstr (type, "bookmark") ? ZEITGEIST_NFO_BOOKMARK : ZEITGEIST_NFO_WEBSITE,
+            zeitgeist_manifestation_for_uri (item->uri),
+            katze_item_get_meta_string (item, "mime-type"), NULL, item->name, NULL),
+                                  NULL),
+        NULL);
+    #endif
+}
+
 static void
 midori_browser_update_history_title (MidoriBrowser* browser,
                                      KatzeItem*     item)
@@ -486,6 +530,8 @@ midori_browser_update_history_title (MidoriBrowser* browser,
         g_printerr (_("Failed to update title: %s\n"), sqlite3_errmsg (db));
     sqlite3_reset (stmt);
     sqlite3_clear_bindings (stmt);
+
+    midori_browser_update_history (item, "website", "access");
 }
 
 static void
@@ -590,9 +636,6 @@ midori_view_notify_title_cb (GtkWidget*     widget,
                              MidoriBrowser* browser)
 {
     MidoriView* view = MIDORI_VIEW (widget);
-    const gchar* title;
-
-    title = midori_view_get_display_title (view);
 
     if (midori_view_get_load_status (view) == MIDORI_LOAD_COMMITTED)
     {
@@ -622,7 +665,7 @@ midori_view_notify_title_cb (GtkWidget*     widget,
     }
 
     if (widget == midori_browser_get_current_tab (browser))
-        midori_browser_set_title (browser, title);
+        midori_browser_set_title (browser, midori_view_get_display_title (view));
 }
 
 static void
@@ -933,6 +976,7 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
             katze_array_add_item (browser->bookmarks, bookmark);
         else
             midori_bookmarks_update_item_db (db, bookmark);
+        midori_browser_update_history (bookmark, "bookmark", "modify");
 
         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_toolbar)))
             if (!gtk_widget_get_visible (browser->bookmarkbar))
@@ -1659,9 +1703,16 @@ midori_browser_tab_destroy_cb (MidoriView*    view,
     if (browser->proxy_array)
     {
         KatzeItem* item = midori_view_get_proxy_item (view);
-        if (browser->trash && !midori_view_is_blank (view))
-            katze_array_add_item (browser->trash, item);
-        katze_array_remove_item (browser->proxy_array, item);
+        if (katze_array_get_item_index (browser->proxy_array, item) != -1)
+        {
+            if (!midori_view_is_blank (view))
+            {
+                if (browser->trash)
+                    katze_array_add_item (browser->trash, item);
+                midori_browser_update_history (item, "website", "leave");
+            }
+            katze_array_remove_item (browser->proxy_array, item);
+        }
 
     /* We don't ever want to be in a situation with no tabs,
        so just create an empty one if the last one is closed.
@@ -2719,10 +2770,11 @@ _action_print_activate (GtkAction*     action,
     gchar* blacklisted_contracts[] = { "print", NULL }; */
     /* FIXME: granite: should return GtkWidget* like GTK+ */
     GtkWidget* dialog = (GtkWidget*)granite_widgets_pop_over_new ();
-    gchar* mime_type = katze_object_get_string (view, "mime-type");
     GtkWidget* content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
     /* FIXME: granite: should return GtkWidget* like GTK+ */
     gchar* filename = midori_view_save_source (MIDORI_VIEW (view), NULL, NULL);
+    const gchar* mime_type = katze_item_get_meta_string (
+        midori_view_get_proxy_item (MIDORI_VIEW (view)), "mime-type");
     GtkWidget* contractor = (GtkWidget*)granite_widgets_contractor_view_new (
         filename, mime_type, 32, TRUE);
     /* granite_widgets_contractor_view_add_item (GRANITE_WIDGETS_CONTRACTOR_VIEW (
@@ -2731,7 +2783,6 @@ _action_print_activate (GtkAction*     action,
     granite_widgets_contractor_view_name_blacklist (GRANITE_WIDGETS_CONTRACTOR_VIEW (
         contractor), blacklisted_contracts, -1); */
     g_free (filename);
-    g_free (mime_type);
     gtk_container_add (GTK_CONTAINER (content_area), contractor);
     gtk_widget_show (contractor);
     gtk_widget_show (dialog);
@@ -7317,6 +7368,7 @@ midori_bookmarkbar_remove_item_cb (KatzeArray*    bookmarks,
 {
     if (gtk_widget_get_visible (browser->bookmarkbar))
         midori_bookmarkbar_populate (browser);
+    midori_browser_update_history (item, "bookmark", "delete");
 }
 
 static void
diff --git a/midori/midori-browser.h b/midori/midori-browser.h
index bedbacf..320006a 100644
--- a/midori/midori-browser.h
+++ b/midori/midori-browser.h
@@ -180,6 +180,11 @@ midori_browser_get_toolbar_actions    (MidoriBrowser*     browser);
 MidoriWebSettings*
 midori_browser_get_settings           (MidoriBrowser*     browser);
 
+void
+midori_browser_update_history         (KatzeItem*         item,
+                                       const gchar*       type,
+                                       const gchar*       event);
+
 G_END_DECLS
 
 #endif /* __MIDORI_BROWSER_H__ */
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 6110b11..6d77319 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -3150,6 +3150,7 @@ webkit_web_view_mime_type_decision_cb (GtkWidget*               web_view,
         if (web_frame == webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)))
         {
             katze_assign (view->mime_type, g_strdup (mime_type));
+            katze_item_set_meta_string (view->item, "mime-type", mime_type);
             midori_view_unset_icon (view);
             g_object_notify (G_OBJECT (view), "mime-type");
         }
@@ -4387,6 +4388,7 @@ midori_view_set_uri (MidoriView*  view,
 
             katze_assign (view->uri, NULL);
             katze_assign (view->mime_type, NULL);
+            katze_item_set_meta_string (view->item, "mime-type", NULL);
             katze_item_set_meta_integer (view->item, "delay", -1);
 
             if (speeddial_markup == NULL)
@@ -5455,7 +5457,7 @@ midori_view_item_meta_data_changed (KatzeItem*   item,
  * Retrieves a proxy item that can be used for bookmark storage as
  * well as session management.
  *
- * The item reflects changes to the title and uri automatically.
+ * The item reflects changes to title (name), URI and MIME type (mime-type).
  *
  * Return value: the proxy #KatzeItem
  **/
diff --git a/midori/wscript_build b/midori/wscript_build
index 62ea674..697d36e 100644
--- a/midori/wscript_build
+++ b/midori/wscript_build
@@ -8,7 +8,7 @@ import platform
 progressive = True
 libs = 'M UNIQUE LIBSOUP GMODULE GTHREAD LIBIDN GIO GTK SQLITE ' \
        'LIBNOTIFY WEBKIT JAVASCRIPTCOREGTK LIBXML X11 XSS WS2_32 HILDON' \
-       'HILDON_FM GCR GRANITE'
+       'HILDON_FM GCR GRANITE ZEITGEIST'
 
 if progressive or Options.commands['check']:
     obj = bld.new_task_gen ('cc', 'staticlib')
diff --git a/tests/wscript_build b/tests/wscript_build
index 66735ae..3ed6eec 100644
--- a/tests/wscript_build
+++ b/tests/wscript_build
@@ -39,6 +39,6 @@ for test in tests:
         obj.packages += ' gtk+-3.0 webkitgtk-3.0'
     else:
         obj.packages += ' gtk+-2.0 webkit-1.0'
-    obj.uselib = 'UNIQUE LIBSOUP GIO GTK SQLITE WEBKIT LIBXML GRANITE'
+    obj.uselib = 'UNIQUE LIBSOUP GIO GTK SQLITE WEBKIT LIBXML GRANITE ZEITGEIST'
     obj.uselib_local = 'midori-core'
     obj.unit_test = 1
diff --git a/toolbars/midori-transferbar.c b/toolbars/midori-transferbar.c
index 5ab4ca9..52113c7 100644
--- a/toolbars/midori-transferbar.c
+++ b/toolbars/midori-transferbar.c
@@ -122,10 +122,16 @@ midori_transferbar_download_notify_status_cb (WebKitDownload* download,
                 gchar* filename = g_strrstr (path, "/") + 1;
                 gchar* msg = g_strdup_printf (
                     _("The file '<b>%s</b>' has been downloaded."), filename);
-                g_free (path);
+                KatzeItem* item = katze_item_new ();
+                item->uri = (gchar*)uri;
+                item->name = filename;
                 g_signal_emit_by_name (browser, "send-notification",
                                        _("Transfer completed"), msg);
                 g_free (msg);
+                midori_browser_update_history (item, "download", "create");
+                item->uri = item->name = NULL;
+                g_object_unref (item);
+                g_free (path);
             }
 
             /* Link Fingerprint */
diff --git a/wscript b/wscript
index 1a3b61f..e6c0d49 100644
--- a/wscript
+++ b/wscript
@@ -237,6 +237,7 @@ def configure (conf):
         granite = 'no '
         conf.define ('GRANITE_VERSION', 'No')
 
+    check_pkg ('zeitgeist-1.0', '0.3.14', mandatory=False)
     conf.check (lib='m', mandatory=True)
     check_pkg ('gmodule-2.0', '2.8.0', False)
     check_pkg ('gthread-2.0', '2.8.0', False)


More information about the Xfce4-commits mailing list