[gnote] Update insert timestamp to not use Preferences for it's own settings
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Update insert timestamp to not use Preferences for it's own settings
- Date: Sun, 20 Dec 2020 10:58:50 +0000 (UTC)
commit f8b5905f7ec5fac44f0ef73381845f40992feda2
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Dec 20 12:47:30 2020 +0200
Update insert timestamp to not use Preferences for it's own settings
.../inserttimestamp/inserttimestamp.desktop.in.in | 2 +-
.../inserttimestamp/inserttimestampnoteaddin.cpp | 12 ++++--------
.../inserttimestamp/inserttimestamppreferences.cpp | 22 +++++++++++++++-------
.../inserttimestamp/inserttimestamppreferences.hpp | 7 +++++--
4 files changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/src/addins/inserttimestamp/inserttimestamp.desktop.in.in
b/src/addins/inserttimestamp/inserttimestamp.desktop.in.in
index 730456ea..ecbfb211 100644
--- a/src/addins/inserttimestamp/inserttimestamp.desktop.in.in
+++ b/src/addins/inserttimestamp/inserttimestamp.desktop.in.in
@@ -4,7 +4,7 @@ _Name=Insert Timestamp
_Description=Inserts current date and time at the cursor position.
_Authors=Hubert Figuiere and Tomboy Project
Category=Tools
-Version=0.5
+Version=0.6
DefaultEnabled=false
Module=libinserttimestamp
LibgnoteRelease=@LIBGNOTE_RELEASE@
diff --git a/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
b/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
index 35d28951..a7965169 100644
--- a/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
+++ b/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
@@ -55,10 +55,9 @@ namespace inserttimestamp {
register_main_window_action_callback("inserttimestamp-insert",
sigc::mem_fun(*this, &InsertTimestampNoteAddin::on_menu_item_activated));
- Glib::RefPtr<Gio::Settings> settings =
ignote().preferences().get_schema_settings(SCHEMA_INSERT_TIMESTAMP);
- m_date_format = settings->get_string(INSERT_TIMESTAMP_FORMAT);
- settings->signal_changed().connect(
+ InsertTimestampPreferences::settings()->signal_changed(INSERT_TIMESTAMP_FORMAT).connect(
sigc::mem_fun(*this, &InsertTimestampNoteAddin::on_format_setting_changed));
+ m_date_format = InsertTimestampPreferences::settings()->get_string(INSERT_TIMESTAMP_FORMAT);
}
@@ -81,12 +80,9 @@ namespace inserttimestamp {
}
- void InsertTimestampNoteAddin::on_format_setting_changed(const Glib::ustring & key)
+ void InsertTimestampNoteAddin::on_format_setting_changed(const Glib::ustring &)
{
- if(key == INSERT_TIMESTAMP_FORMAT) {
- m_date_format = ignote().preferences().get_schema_settings(
- SCHEMA_INSERT_TIMESTAMP)->get_string(INSERT_TIMESTAMP_FORMAT);
- }
+ m_date_format = InsertTimestampPreferences::settings()->get_string(INSERT_TIMESTAMP_FORMAT);
}
}
diff --git a/src/addins/inserttimestamp/inserttimestamppreferences.cpp
b/src/addins/inserttimestamp/inserttimestamppreferences.cpp
index 4393d13a..76a709f9 100644
--- a/src/addins/inserttimestamp/inserttimestamppreferences.cpp
+++ b/src/addins/inserttimestamp/inserttimestamppreferences.cpp
@@ -34,6 +34,16 @@ namespace inserttimestamp {
bool InsertTimestampPreferences::s_static_inited = false;
std::vector<Glib::ustring> InsertTimestampPreferences::s_formats;
+ Glib::RefPtr<Gio::Settings> InsertTimestampPreferences::s_settings;
+
+ Glib::RefPtr<Gio::Settings> & InsertTimestampPreferences::settings()
+ {
+ if(!s_settings) {
+ s_settings = Gio::Settings::create(SCHEMA_INSERT_TIMESTAMP);
+ }
+
+ return s_settings;
+ }
void InsertTimestampPreferences::_init_static()
{
@@ -49,8 +59,7 @@ namespace inserttimestamp {
}
- InsertTimestampPreferences::InsertTimestampPreferences(gnote::IGnote &, gnote::Preferences & preferences,
gnote::NoteManager &)
- : m_preferences(preferences)
+ InsertTimestampPreferences::InsertTimestampPreferences(gnote::IGnote &, gnote::Preferences &,
gnote::NoteManager &)
{
_init_static();
@@ -58,8 +67,8 @@ namespace inserttimestamp {
int row = 0;
// Get current values
- Glib::RefPtr<Gio::Settings> settings = preferences.get_schema_settings(SCHEMA_INSERT_TIMESTAMP);
- Glib::ustring dateFormat = settings->get_string(INSERT_TIMESTAMP_FORMAT);
+ auto ts_settings = settings();
+ Glib::ustring dateFormat = ts_settings->get_string(INSERT_TIMESTAMP_FORMAT);
auto now = Glib::DateTime::create_now_local();
@@ -108,8 +117,7 @@ namespace inserttimestamp {
custom_entry = manage(new Gtk::Entry());
customBox->attach(*custom_entry, 1, 0, 1, 1);
- sharp::PropertyEditor * entryEditor = new sharp::PropertyEditor(
- settings, INSERT_TIMESTAMP_FORMAT, *custom_entry);
+ sharp::PropertyEditor *entryEditor = new sharp::PropertyEditor(ts_settings, INSERT_TIMESTAMP_FORMAT,
*custom_entry);
entryEditor->setup ();
// Activate/deactivate widgets
@@ -181,7 +189,7 @@ namespace inserttimestamp {
if (iter) {
Glib::ustring format;
iter->get_value(1, format);
- m_preferences.get_schema_settings(SCHEMA_INSERT_TIMESTAMP)->set_string(INSERT_TIMESTAMP_FORMAT,
format);
+ settings()->set_string(INSERT_TIMESTAMP_FORMAT, format);
}
}
diff --git a/src/addins/inserttimestamp/inserttimestamppreferences.hpp
b/src/addins/inserttimestamp/inserttimestamppreferences.hpp
index 227d0845..ba7d8f6d 100644
--- a/src/addins/inserttimestamp/inserttimestamppreferences.hpp
+++ b/src/addins/inserttimestamp/inserttimestamppreferences.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2013,2017,2019 Aurimas Cernius
+ * Copyright (C) 2013,2017,2019-2020 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -47,6 +47,8 @@ class InsertTimestampPreferences
: public Gtk::Grid
{
public:
+ static Glib::RefPtr<Gio::Settings> & settings();
+
InsertTimestampPreferences(gnote::IGnote &, gnote::Preferences &, gnote::NoteManager &);
private:
static void _init_static();
@@ -65,6 +67,8 @@ private:
static bool s_static_inited;
static std::vector<Glib::ustring> s_formats;
+ static Glib::RefPtr<Gio::Settings> s_settings;
+
FormatColumns m_columns;
Gtk::RadioButton *selected_radio;
Gtk::RadioButton *custom_radio;
@@ -73,7 +77,6 @@ private:
Gtk::TreeView *tv;
Glib::RefPtr<Gtk::ListStore> store;
Gtk::Entry *custom_entry;
- gnote::Preferences & m_preferences;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]