paperbox r130 - in trunk: . src



Author: markoa
Date: Thu Apr 24 15:09:35 2008
New Revision: 130
URL: http://svn.gnome.org/viewvc/paperbox?rev=130&view=rev

Log:
Async document URI retrieval

Modified:
   trunk/ChangeLog
   trunk/src/browser.cc
   trunk/src/browser.hh
   trunk/src/tracker-phone.cc
   trunk/src/tracker-phone.hh

Modified: trunk/src/browser.cc
==============================================================================
--- trunk/src/browser.cc	(original)
+++ trunk/src/browser.cc	Thu Apr 24 15:09:35 2008
@@ -68,20 +68,35 @@
     {
         tracker_client_.reset(new TrackerPhone()); // let exception propagate
 
-        tracker_client_->get_all_document_uris(uri_queue_);
+        connect_to_tracker_signals();
+        tracker_client_->request_all_documents();
+    }
+
+    Browser::~Browser()
+    {
+    }
+
+    void
+    Browser::connect_to_tracker_signals()
+    {
+        tracker_client_->signal_documents_request_completed().connect(
+            sigc::mem_fun(*this, &Browser::on_documents));
 
         tracker_client_->signal_add_tags_request_completed().connect(
             sigc::mem_fun(*this, &Browser::on_add_tags_request_completed));
 
         tracker_client_->signal_remove_tags_request_completed().connect(
             sigc::mem_fun(*this, &Browser::on_remove_tags_request_completed));
-
-        Glib::signal_idle().connect(
-            sigc::mem_fun(*this, &Browser::on_idle_initial_document_retrieval));
     }
 
-    Browser::~Browser()
+    void
+    Browser::on_documents(const std::queue<ustring>& uris)
     {
+        uri_queue_ = uris;
+
+        // begin retrieving information
+        Glib::signal_idle().connect(
+            sigc::mem_fun(*this, &Browser::on_idle_initial_document_retrieval));
     }
 
     void
@@ -107,7 +122,7 @@
             return false; // idle function done
         }
 
-        Glib::ustring uri = uri_queue_.front();
+        ustring uri = uri_queue_.front();
 
         // get metadata, emit for new documents
         try {
@@ -207,8 +222,8 @@
 
     // Does the validation work and forwards the remove request to TrackerPhone
     void
-    Browser::remove_tags(const Glib::ustring& uri,
-                         const std::vector<Glib::ustring>& tags)
+    Browser::remove_tags(const ustring& uri,
+                         const std::vector<ustring>& tags)
     {
         doc_map::iterator doc_iter = docs_.find(uri.raw());
 
@@ -237,9 +252,9 @@
     }
 
     void
-    Browser::rename_tag(const Glib::ustring& /*uri*/,
-                        const Glib::ustring& /*from_tag*/,
-                        const Glib::ustring& /*to_tag*/)
+    Browser::rename_tag(const ustring& /*uri*/,
+                        const ustring& /*from_tag*/,
+                        const ustring& /*to_tag*/)
     {
         //TODO later as a high-level functionality, in UI it should
         // not be strictly bound to one document. It should rather be
@@ -300,7 +315,7 @@
     }
 
     void
-    Browser::get_documents_for_tag(const Glib::ustring& tag,
+    Browser::get_documents_for_tag(const ustring& tag,
                                    doc_vector& docs_ret)
     {
         doc_map::iterator it(docs_.begin());
@@ -314,7 +329,7 @@
     }
 
     void
-    Browser::get_documents_for_tag_bundle(const vector<Glib::ustring>& tags,
+    Browser::get_documents_for_tag_bundle(const vector<ustring>& tags,
                                           doc_vector& docs_ret)
     {
         doc_map::iterator it(docs_.begin());
@@ -323,8 +338,8 @@
         for ( ; it != end; ++it) {
             shared_ptr<Document> doc = it->second;
 
-            vector<Glib::ustring>::const_iterator tit(tags.begin());
-            vector<Glib::ustring>::const_iterator tend(tags.end());
+            vector<ustring>::const_iterator tit(tags.begin());
+            vector<ustring>::const_iterator tend(tags.end());
             for ( ; tit != tend; ++tit) {
                 if (doc->contains_tag(*tit)) {
                     docs_ret.push_back(doc);

Modified: trunk/src/browser.hh
==============================================================================
--- trunk/src/browser.hh	(original)
+++ trunk/src/browser.hh	Thu Apr 24 15:09:35 2008
@@ -95,6 +95,10 @@
 
         explicit Browser();
 
+        void connect_to_tracker_signals();
+
+        void on_documents(const std::queue<Glib::ustring>& uris);
+
         bool on_idle_initial_document_retrieval();
 
         void on_add_tags_request_completed(

Modified: trunk/src/tracker-phone.cc
==============================================================================
--- trunk/src/tracker-phone.cc	(original)
+++ trunk/src/tracker-phone.cc	Thu Apr 24 15:09:35 2008
@@ -3,7 +3,7 @@
 /*
  *  PaperBox - tracker-client.cc
  *
- *  Copyright (C) 2007 Marko Anastasov
+ *  Copyright (C) 2007-2008 Marko Anastasov
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -120,6 +120,39 @@
 namespace {
 
     void
+    on_tracker_documents_reply(char** results,
+                               GError* error,
+                               paperbox::TrackerPhone* phone)
+    {
+        LOG_DD("got a list of documents by mime type");
+
+        if (error) {
+            LOG_ERROR("Ha! No documents: " << error->message);
+            g_clear_error(&error);
+            return;
+        }
+
+        if (! results) {
+            LOG_DD("Tracker returned zero documents");
+            return;
+        }
+
+        char** res_p = 0;
+        std::queue<Glib::ustring> uris;
+
+        LOG_DD("iterating over results");
+
+        for (res_p = results; *res_p; res_p++) {
+            Glib::ustring found_uri(*res_p);
+            uris.push(found_uri);
+        }
+
+        phone->signal_documents_request_completed().emit(uris);
+
+        g_strfreev(results);
+    }
+
+    void
     on_tracker_void_reply(GError* error, paperbox::AsyncTagPack* pack)
     {
         bool success = true;
@@ -174,13 +207,19 @@
         tracker_disconnect(tracker_connection_);
     }
 
-    TrackerPhone::SignalTagRequestCompleted&
+    TrackerPhone::SignalDocuments&
+    TrackerPhone::signal_documents_request_completed()
+    {
+        return signal_documents_;
+    }
+
+    TrackerPhone::SignalTagRequest&
     TrackerPhone::signal_add_tags_request_completed()
     {
         return signal_add_completed_;
     }
 
-    TrackerPhone::SignalTagRequestCompleted&
+    TrackerPhone::SignalTagRequest&
     TrackerPhone::signal_remove_tags_request_completed()
     {
         return signal_remove_completed_;
@@ -198,48 +237,22 @@
     }
 
     void
-    TrackerPhone::get_all_document_uris(std::queue<Glib::ustring>& uris)
+    TrackerPhone::request_all_documents()
     {
-        LOG_FUNCTION_SCOPE_NORMAL_DD;
-
         int live_query_id = -1;
         int offset = 0;
         int max_hits = DOC_RETRIEVAL_LIMIT;
 
-        char** results = 0;
-        GError* error = 0;
-
         LOG_DD("sending request for document URIs");
 
-        results = tracker_files_get_by_mime_type(tracker_connection_,
-                                                 live_query_id,
-                                                 doc_types,
-                                                 offset,
-                                                 max_hits,
-                                                 &error);
-
-        if (error) {
-            LOG_ERROR("Ha! No documents for you: "
-                      << error->message);
-            g_clear_error(&error);
-            return;
-        }
-
-        if (! results) {
-            LOG_DD("Tracker returned *0* documents");
-            return;
-        }
-
-        char** res_p = 0;
-
-        LOG_DD("iterating over results");
-
-        for (res_p = results; *res_p; res_p++) {
-            Glib::ustring found_uri(*res_p);
-            uris.push(found_uri);
-        }
-
-        g_strfreev (results);
+        tracker_files_get_by_mime_type_async (tracker_connection_,
+                                              live_query_id,
+                                              doc_types,
+                                              offset,
+                                              max_hits,
+                                              (TrackerArrayReply)
+                                              on_tracker_documents_reply,
+                                              this);
     }
 
     void

Modified: trunk/src/tracker-phone.hh
==============================================================================
--- trunk/src/tracker-phone.hh	(original)
+++ trunk/src/tracker-phone.hh	Thu Apr 24 15:09:35 2008
@@ -3,7 +3,7 @@
 /*
  *  PaperBox - tracker-phone.hh
  *
- *  Copyright (C) 2007 Marko Anastasov
+ *  Copyright (C) 2007-2008 Marko Anastasov
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@
 
 #include <queue>
 #include <stdexcept>
+#include <vector>
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
 #include <glibmm/ustring.h>
@@ -41,17 +42,21 @@
     {
     public:
         typedef sigc::signal<void,
+                             const std::queue<Glib::ustring>& >
+        SignalDocuments;
+
+        typedef sigc::signal<void,
                              bool,                               // success
                              const Glib::ustring&,               // uri
-                             const std::vector<Glib::ustring> >  // tags
-        SignalTagRequestCompleted;
+                             const std::vector<Glib::ustring>& > // tags
+        SignalTagRequest;
 
         explicit TrackerPhone() throw (std::runtime_error);
         virtual ~TrackerPhone();
 
         static bool ping_tracker();
 
-        void get_all_document_uris(std::queue<Glib::ustring>& uris);
+        void request_all_documents();
 
         void get_document(const Glib::ustring& uri,
                           boost::shared_ptr<Document>& document);
@@ -59,13 +64,15 @@
         void add_tags(const Glib::ustring& uri,
                       const std::vector<Glib::ustring> tags);
 
-        SignalTagRequestCompleted& signal_add_tags_request_completed();
-
-        SignalTagRequestCompleted& signal_remove_tags_request_completed();
-
         void remove_tags(const Glib::ustring& uri,
                          const std::vector<Glib::ustring> tags);
 
+        SignalDocuments& signal_documents_request_completed();
+
+        SignalTagRequest& signal_add_tags_request_completed();
+
+        SignalTagRequest& signal_remove_tags_request_completed();
+
     protected:
         void prepare_document(const Glib::ustring& uri,
                               char** keys,
@@ -75,8 +82,9 @@
 
         TrackerClient* tracker_connection_;
 
-        SignalTagRequestCompleted signal_add_completed_;
-        SignalTagRequestCompleted signal_remove_completed_;
+        SignalDocuments  signal_documents_;
+        SignalTagRequest signal_add_completed_;
+        SignalTagRequest signal_remove_completed_;
     };
 
 } // namespace paperbox



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]