[gnote] Handle command line argument --version and --search



commit 820e9d8b41c98b0d2290ab061e50a17b6dc8e8b2
Author: Hubert Figuiere <hub figuiere net>
Date:   Wed May 6 00:25:23 2009 -0400

    Handle command line argument --version and --search
---
 NEWS          |    3 +-
 src/gnote.cpp |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 src/gnote.hpp |    9 +++++--
 3 files changed, 66 insertions(+), 12 deletions(-)

diff --git a/NEWS b/NEWS
index b6530d4..7828891 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+  * Handle command line argument --version and --search
+
 0.3.2 -
 
 Fixes:
@@ -18,7 +20,6 @@ Translations:
     - German (de)
     - Japanese (ja)
     
-
 0.3.1 "Five-One-Four" - 2009/05/05
 
 Fixes:
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 6c70fcf..073d800 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -23,6 +23,10 @@
 
 #include <stdlib.h>
 
+#include <iostream>
+
+#include <boost/format.hpp>
+
 #include <glibmm/thread.h>
 #include <glibmm/i18n.h>
 #include <glibmm/optionentry.h>
@@ -85,9 +89,6 @@ namespace gnote {
     {
     }
 
-    if(cmd_line.needs_execute()) {
-      cmd_line.execute();
-    }
 
     m_icon_theme = Gtk::IconTheme::get_default();
     m_icon_theme->append_search_path(DATADIR"/icons");
@@ -112,6 +113,10 @@ namespace gnote {
       (*iter)->initialize();
     }
 
+    if(cmd_line.needs_execute()) {
+      cmd_line.execute();
+    }
+
     if(cmd_line.use_panel_applet()) {
       DBG_OUT("starting applet");
       s_tray_icon_showing = true;
@@ -342,30 +347,75 @@ namespace gnote {
   GnoteCommandLine::GnoteCommandLine()
     : Glib::OptionGroup("Gnote", _("A note taking application"))
     , m_new_note(false)
-    , m_open_search(false)
     , m_open_start_here(false)
     , m_use_panel(false)
+    , m_show_version(false)
   {
     Glib::OptionEntry entry;
     entry.set_long_name("panel-applet");
-    entry.set_description(_("Run Gnote as a GNOME panel applet"));
+    entry.set_description(_("Run Gnote as a GNOME panel applet."));
     add_entry(entry, m_use_panel);
+
+    Glib::OptionEntry entry2;
+    entry2.set_long_name("note-path");
+    entry2.set_description(_("Specify the path of the directory containing the notes."));
+    add_entry(entry2, m_note_path);
+
+    Glib::OptionEntry entry3;
+    entry3.set_long_name("search");
+    entry3.set_description(_("Open the search all notes window with the search text."));
+    add_entry(entry3, m_search);
+
+    Glib::OptionEntry entry4;
+    entry4.set_long_name("version");
+    entry4.set_description(_("Print version information."));
+    add_entry(entry4, m_show_version);
   }
 
   int GnoteCommandLine::execute()
+
   {
-    // TODO
+    bool quit = false;
+#ifndef ENABLE_DBUS
+      // as long as we don't have the DBus support.
+    if(!m_search.empty()) {
+      NoteRecentChanges * recent_changes
+        = NoteRecentChanges::get_instance(
+          Gnote::obj().default_note_manager());
+
+      recent_changes->set_search_text(m_search);
+
+      recent_changes->present ();
+    }
+#endif
+    if(m_show_version) {
+      print_version();
+      quit = true;
+    }
+
+    if(quit) {
+      exit(0);
+    }
     return 0;
   }
 
+  void GnoteCommandLine::print_version()
+  {
+    Glib::ustring version = str(boost::format(_("Version %1%"))
+                                % VERSION);
+    std::cerr << version << std::endl;
+  }
+
+
   bool GnoteCommandLine::needs_execute() const
   {
     return m_new_note ||
       !m_open_note_name.empty() ||
       !m_open_note_uri.empty() ||
-      m_open_search ||
+      !m_search.empty() ||
       m_open_start_here ||
-      !m_open_external_note_path.empty();
+      !m_open_external_note_path.empty() ||
+      m_show_version;
   }
 
 
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 51ad0a1..c2f21ae 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -26,6 +26,7 @@
 #include <string>
 
 #include <glibmm/optioncontext.h>
+#include <glibmm/ustring.h>
 #include <gtkmm/icontheme.h>
 #include <gtkmm/statusicon.h>
 
@@ -101,7 +102,7 @@ public:
   GnoteCommandLine();
   int execute();
 
-  const std::string & note_path() const
+  const Glib::ustring & note_path() const
     {
       return m_note_path;
     }
@@ -112,15 +113,17 @@ public:
     }
 
 private:
+  void        print_version();
 
   bool        m_new_note;
-  bool        m_open_search;
   bool        m_open_start_here;
   bool        m_use_panel;
+  bool        m_show_version;
   std::string m_open_note_name;
   std::string m_open_note_uri;
   std::string m_open_external_note_path;
-  std::string m_note_path;
+  Glib::ustring m_search;
+  Glib::ustring m_note_path;
 };
 
 }



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