[gnote] Add auto-sync options to preferences dialog



commit 29b5df0ba4cad04cdd5401480402a11f7f809914
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Thu Dec 13 21:11:18 2012 +0200

    Add auto-sync options to preferences dialog

 src/preferencesdialog.cpp |   64 ++++++++++++++++++++++++++++++++++++++++++--
 src/preferencesdialog.hpp |    5 +++
 2 files changed, 66 insertions(+), 3 deletions(-)
---
diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp
index f9761f4..413aa4b 100644
--- a/src/preferencesdialog.cpp
+++ b/src/preferencesdialog.cpp
@@ -551,9 +551,6 @@ namespace gnote {
       active_iter = m_sync_addin_iters [addin_id];
       m_sync_addin_combo->set_active(active_iter);
     }
-    /*else {
-      m_sync_addin_combo->set_active(0);
-    }*/
 
     m_sync_addin_combo->signal_changed().connect(
       sigc::mem_fun(*this, &PreferencesDialog::on_sync_addin_combo_changed));
@@ -590,6 +587,38 @@ namespace gnote {
     m_sync_addin_prefs_container->show();
     vbox->pack_start(*m_sync_addin_prefs_container, true, true, 0);
 
+    // Autosync preference
+    int timeout = Preferences::obj().get_schema_settings(
+        Preferences::SCHEMA_SYNC)->get_int(Preferences::SYNC_AUTOSYNC_TIMEOUT);
+    if(timeout > 0 && timeout < 5) {
+      timeout = 5;
+      Preferences::obj().get_schema_settings(
+          Preferences::SCHEMA_SYNC)->set_int(Preferences::SYNC_AUTOSYNC_TIMEOUT, 5);
+    }
+    Gtk::HBox *autosyncBox = manage(new Gtk::HBox(false, 5));
+    // Translators: This is and the next string go together.
+    // Together they look like "Automatically Sync in Background Every [_] Minutes",
+    // where "[_]" is a GtkSpinButton.
+    m_autosync_check = manage(new Gtk::CheckButton(_("Automaticall_y Sync in Background Every"), true));
+    m_autosync_spinner = manage(new Gtk::SpinButton(1));
+    m_autosync_spinner->set_range(5, 1000);
+    m_autosync_spinner->set_value(timeout >= 5 ? timeout : 10);
+    m_autosync_spinner->set_increments(1, 5);
+    // Translators: See above comment for details on
+    // this string.
+    Gtk::Label *autosyncExtraText = manage(new Gtk::Label(_("Minutes")));
+    m_autosync_check->set_active(timeout >= 5);
+    m_autosync_spinner->set_sensitive(timeout >= 5);
+    m_autosync_check->signal_toggled()
+      .connect(sigc::mem_fun(*this, &PreferencesDialog::on_autosync_check_toggled));
+    m_autosync_spinner->signal_value_changed()
+      .connect(sigc::mem_fun(*this, &PreferencesDialog::update_timeout_pref));
+
+    autosyncBox->pack_start(*m_autosync_check);
+    autosyncBox->pack_start(*m_autosync_spinner);
+    autosyncBox->pack_start(*autosyncExtraText);
+    vbox->pack_start(*autosyncBox, false, true, 0);
+
     Gtk::HButtonBox *bbox = manage(new Gtk::HButtonBox());
     bbox->set_spacing(4);
     bbox->property_layout_style().set_value(Gtk::BUTTONBOX_END);
@@ -1027,6 +1056,22 @@ namespace gnote {
         m_rename_behavior_combo->set_active(rename_behavior);
       }
     }
+    else if(key == Preferences::SYNC_AUTOSYNC_TIMEOUT) {
+      int timeout = Preferences::obj().get_schema_settings(
+          Preferences::SCHEMA_SYNC)->get_int(Preferences::SYNC_AUTOSYNC_TIMEOUT);
+      if(timeout <= 0 && m_autosync_check->get_active()) {
+        m_autosync_check->set_active(false);
+      }
+      else if(timeout > 0) {
+        timeout = (timeout >= 5 && timeout < 1000) ? timeout : 5;
+        if(!m_autosync_check->get_active()) {
+          m_autosync_check->set_active(true);
+        }
+        if(static_cast<int>(m_autosync_spinner->get_value()) != timeout) {
+          m_autosync_spinner->set_value(timeout);
+        }
+      }
+    }
   }
 
 
@@ -1431,5 +1476,18 @@ DBG_OUT("no addin");
     }
   }
 
+  void PreferencesDialog::on_autosync_check_toggled()
+  {
+    m_autosync_spinner->set_sensitive(m_autosync_check->get_active());
+    update_timeout_pref();
+  }
+
+  void PreferencesDialog::update_timeout_pref()
+  {
+    Preferences::obj().get_schema_settings(Preferences::SCHEMA_SYNC)->set_int(
+        Preferences::SYNC_AUTOSYNC_TIMEOUT,
+        m_autosync_check->get_active() ? static_cast<int>(m_autosync_spinner->get_value()) : -1);
+  }
+
 }
 
diff --git a/src/preferencesdialog.hpp b/src/preferencesdialog.hpp
index 19f8a02..b7f849f 100644
--- a/src/preferencesdialog.hpp
+++ b/src/preferencesdialog.hpp
@@ -32,6 +32,7 @@
 #include <gtkmm/liststore.h>
 #include <gtkmm/combobox.h>
 #include <gtkmm/comboboxtext.h>
+#include <gtkmm/spinbutton.h>
 
 #include "sharp/addinstreemodel.hpp"
 
@@ -89,6 +90,8 @@ private:
   void on_conflict_option_toggle();
   void combo_box_text_data_func(const Gtk::TreeIter & iter);
   void update_sync_services();
+  void update_timeout_pref();
+  void on_autosync_check_toggled();
 ////
 
   class SyncStoreModel
@@ -112,6 +115,8 @@ private:
   Gtk::Widget *m_sync_addin_prefs_widget;
   Gtk::Button *m_reset_sync_addin_button;
   Gtk::Button *m_save_sync_addin_button;
+  Gtk::CheckButton *m_autosync_check;
+  Gtk::SpinButton *m_autosync_spinner;
   Gtk::ComboBoxText *m_rename_behavior_combo;
   AddinManager &m_addin_manager;
     



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