paperbox r200 - in trunk: . src



Author: markoa
Date: Tue Oct 14 00:11:48 2008
New Revision: 200
URL: http://svn.gnome.org/viewvc/paperbox?rev=200&view=rev

Log:
First three sort options

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

Modified: trunk/src/browser.cc
==============================================================================
--- trunk/src/browser.cc	(original)
+++ trunk/src/browser.cc	Tue Oct 14 00:11:48 2008
@@ -38,6 +38,49 @@
 
     ///
 
+    int
+    cmp_nocase(const ustring& s, const ustring& s2)
+    {
+        ustring::const_iterator p = s.begin();
+        ustring::const_iterator p2 = s2.begin();
+
+        while (p != s.end() && p2 != s2.end()) {
+            if (toupper(*p) != toupper(*p2)) {
+                return (toupper(*p) < toupper(*p2)) ? -1 : 1;
+            }
+            ++p;
+            ++p2;
+        }
+
+        return (s2.size() == s.size()) ? 0 : (s.size() < s2.size()) ? -1 : 1;
+    }
+
+    struct doc_az_compare
+        : public std::binary_function<shared_ptr<Document>,
+                                      shared_ptr<Document>,
+                                      bool>
+    {
+        bool
+        operator()(const shared_ptr<Document>& lhs,
+                   const shared_ptr<Document>& rhs) const
+            {
+                return cmp_nocase(lhs->get_subject(), rhs->get_subject()) == -1;
+            }
+    };
+
+    struct doc_mtime_compare_asc
+        : public std::binary_function<shared_ptr<Document>,
+                                      shared_ptr<Document>,
+                                      bool>
+    {
+        bool
+        operator()(const shared_ptr<Document>& lhs,
+                   const shared_ptr<Document>& rhs) const
+            {
+                return (lhs->get_mtime() < rhs->get_mtime());
+            }
+    };
+
     struct doc_mtime_compare_desc
         : public std::binary_function<shared_ptr<Document>,
                                       shared_ptr<Document>,
@@ -315,8 +358,10 @@
             docs.push_back(it->second);
 
         if (sorting == DOCUMENT_SORTING_ALPHABETICAL) {
-            //
-        } else if (sorting == DOCUMENT_SORTING_BY_DATE) {
+            sort(docs.begin(), docs.end(), doc_az_compare());
+        } else if (sorting == DOCUMENT_SORTING_BY_DATE_ASC) {
+            sort(docs.begin(), docs.end(), doc_mtime_compare_asc());
+        } else if (sorting == DOCUMENT_SORTING_BY_DATE_DESC) {
             sort(docs.begin(), docs.end(), doc_mtime_compare_desc());
         }
     }

Modified: trunk/src/browser.hh
==============================================================================
--- trunk/src/browser.hh	(original)
+++ trunk/src/browser.hh	Tue Oct 14 00:11:48 2008
@@ -40,7 +40,8 @@
     enum DocumentSorting {
         DOCUMENT_SORTING_NONE,
         DOCUMENT_SORTING_ALPHABETICAL,
-        DOCUMENT_SORTING_BY_DATE,
+        DOCUMENT_SORTING_BY_DATE_ASC,
+        DOCUMENT_SORTING_BY_DATE_DESC
     };
 
     class Browser : public sigc::trackable, private boost::noncopyable

Modified: trunk/src/main-window.cc
==============================================================================
--- trunk/src/main-window.cc	(original)
+++ trunk/src/main-window.cc	Tue Oct 14 00:11:48 2008
@@ -98,7 +98,8 @@
     
     enum BROWSING_MODE {
         BROWSING_ALPHABETICAL,
-        BROWSING_BY_DATE,
+        BROWSING_BY_DATE_ASC,
+        BROWSING_BY_DATE_DESC,
         BROWSING_DAY_BY_DAY
     };
 
@@ -268,11 +269,13 @@
     void
     MainWindow::init_sorting_area()
     {
-        sorting_label_.set_text("Browsing mode");
+        sorting_label_.set_text("Browse");
 
-        sorting_combo_.append_text("Alphabetical");
-        sorting_combo_.append_text("By date");
-        sorting_combo_.append_text("Day by day");
+        sorting_combo_.append_text("alphabetically");
+        sorting_combo_.append_text("by date, oldest first");
+        sorting_combo_.append_text("by date, newest first");
+
+        sorting_combo_.append_text("day by day");
         sorting_combo_.signal_changed().connect(
                 sigc::mem_fun(*this, &MainWindow::on_sorting_changed));
 
@@ -552,12 +555,23 @@
     MainWindow::on_sorting_changed()
     {
         int sorting = sorting_combo_.get_active_row_number();
-        
-        if (sorting == BROWSING_BY_DATE) {
-            doc_vector docs;
-            browser_->get_all_documents(docs, DOCUMENT_SORTING_BY_DATE);
-            render_documents(docs);
+        doc_vector docs;
+
+        if (sorting == BROWSING_ALPHABETICAL) {
+            browser_->get_all_documents(docs,
+                                        DOCUMENT_SORTING_ALPHABETICAL);
+        } else if (sorting == BROWSING_BY_DATE_ASC) {
+            browser_->get_all_documents(docs,
+                                        DOCUMENT_SORTING_BY_DATE_ASC);
+        } else if (sorting == BROWSING_BY_DATE_DESC) {
+            browser_->get_all_documents(docs,
+                                        DOCUMENT_SORTING_BY_DATE_DESC);
+        } else if (sorting == BROWSING_DAY_BY_DAY) {
+            //TODO
+            return;
         }
+
+        render_documents(docs);
     }
 
     void

Modified: trunk/src/tracker-phone.cc
==============================================================================
--- trunk/src/tracker-phone.cc	(original)
+++ trunk/src/tracker-phone.cc	Tue Oct 14 00:11:48 2008
@@ -23,6 +23,7 @@
 #include <sys/time.h>
 #include <iostream>
 #include <vector>
+#include <glibmm/convert.h>
 #include <glibmm/fileutils.h>
 #include <glibmm-utils/log-stream-utils.h>
 #include "file-utils.hh"
@@ -377,6 +378,10 @@
         if (! is_empty_string(keys[SUBJECT])) {
             Glib::ustring subject(keys[SUBJECT]);
             document->set_subject(subject);
+        } else {
+            document->set_subject(
+                    Glib::filename_display_basename(
+                        Glib::filename_to_uri(uri)));
         }
 
         if (! is_empty_string(keys[AUTHOR])) {



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