[gnote] Make status icon presence configurable



commit d5f2c8b1cd8159a2898bce1cefa2c1e1bc03d2d8
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Mon Jun 27 22:18:15 2011 +0300

    Make status icon presence configurable
    
    Add option for status icon and show it only when set so.
    Otherwise use Search All Notes window as main window.
    Fixes bug 632000.

 data/org.gnome.gnote.gschema.xml.in |    5 ++++
 src/gnote.cpp                       |   36 ++++++++++++++++++++++++++++++++--
 src/gnote.hpp                       |    3 +-
 src/preferences.cpp                 |    1 +
 src/preferences.hpp                 |    1 +
 5 files changed, 42 insertions(+), 4 deletions(-)
---
diff --git a/data/org.gnome.gnote.gschema.xml.in b/data/org.gnome.gnote.gschema.xml.in
index a0afa69..57f2195 100644
--- a/data/org.gnome.gnote.gschema.xml.in
+++ b/data/org.gnome.gnote.gschema.xml.in
@@ -115,6 +115,11 @@
       <_summary>Enable closing notes with escape</_summary>
       <_description>If enabled, an opened note can be closed by hitting the escape key.</_description>
     </key>
+    <key name="use-status-icon" type="b">
+      <default>false</default>
+      <_summary>Use status icon, when started as an application</_summary>
+      <_description>Has affect only when started as an application. When set to TRUE, shows a status icon. If set to FALSE, Search All Notes window is used as main application window, closing which makes application to exit.</_description>
+    </key>
     <child name="global-keybindings" schema="org.gnome.gnote.global-keybindings" />
     <child name="export-html" schema="org.gnome.gnote.export-html" />
     <child name="sync" schema="org.gnome.gnote.sync" />
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 3b951fa..6074575 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -133,9 +133,18 @@ namespace gnote {
 #endif
     }
     else {
-      DBG_OUT("starting tray icon");
-      //register session manager restart
-      start_tray_icon();
+      Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
+        .get_schema_settings(Preferences::SCHEMA_GNOTE);
+      settings->signal_changed()
+        .connect(sigc::mem_fun(*this, &Gnote::on_setting_changed));
+      if(settings->get_boolean(Preferences::USE_STATUS_ICON)) {
+        DBG_OUT("starting tray icon");
+        start_tray_icon();
+      }
+      else {
+        am["ShowSearchAllNotesAction"]->activate();
+        Gtk::Main::run();
+      }
     }
 
     signal_quit();
@@ -238,6 +247,27 @@ namespace gnote {
   }
 
 
+  void Gnote::on_setting_changed(const Glib::ustring & key)
+  {
+    if(key != Preferences::USE_STATUS_ICON) {
+      return;
+    }
+
+    bool use_status_icon = Preferences::obj()
+      .get_schema_settings(Preferences::SCHEMA_GNOTE)->get_boolean(key);
+    if(use_status_icon) {
+      if(!m_tray_icon) {
+        m_tray_icon = Glib::RefPtr<TrayIcon>(new TrayIcon(default_note_manager()));
+      }
+      m_tray_icon->set_visible(true);
+    }
+    else {
+      if(m_tray_icon)
+        m_tray_icon->set_visible(false);
+      ActionManager::obj()["ShowSearchAllNotesAction"]->activate();
+    }
+  }
+
 
   void Gnote::setup_global_actions()
   {
diff --git a/src/gnote.hpp b/src/gnote.hpp
index d111bec..4dc1ee2 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010 Aurimas Cernius
+ * Copyright (C) 2010-2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -94,6 +94,7 @@ private:
   void start_note_created(const Note::Ptr & start_note);
   std::string get_note_path(const std::string & override_path);
   void register_remote_control(NoteManager & manager);
+  void on_setting_changed(const Glib::ustring & key);
 
   NoteManager *m_manager;
   IKeybinder  *m_keybinder;
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 4487396..c395f11 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -58,6 +58,7 @@ namespace gnote {
   const char * Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR = "sync-conflict-behavior";
 
   const char * Preferences::NOTE_RENAME_BEHAVIOR = "note-rename-behavior";
+  const char * Preferences::USE_STATUS_ICON = "use-status-icon";
 
   const char * Preferences::SEARCH_WINDOW_X_POS = "search-window-x-pos";
   const char * Preferences::SEARCH_WINDOW_Y_POS = "search-window-y-pos";
diff --git a/src/preferences.hpp b/src/preferences.hpp
index 24cf86f..7372a1e 100644
--- a/src/preferences.hpp
+++ b/src/preferences.hpp
@@ -57,6 +57,7 @@ namespace gnote {
     static const char *MENU_PINNED_NOTES;
 
     static const char *NOTE_RENAME_BEHAVIOR;
+    static const char *USE_STATUS_ICON;
 
     static const char *SEARCH_WINDOW_X_POS;
     static const char *SEARCH_WINDOW_Y_POS;



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