[gnote] Make NoteArchiver non-singleton
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Make NoteArchiver non-singleton
- Date: Tue, 8 Oct 2019 20:04:21 +0000 (UTC)
commit 1cb28b12ed01079d678ff3a980b177e1cb9755e2
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Oct 6 21:39:59 2019 +0300
Make NoteArchiver non-singleton
src/gnote.cpp | 4 ++--
src/note.cpp | 4 ++--
src/notebase.cpp | 21 ++++-----------------
src/notebase.hpp | 12 ++++++------
src/notemanager.cpp | 1 +
src/notemanager.hpp | 6 ++++++
src/notemanagerbase.hpp | 4 +++-
src/synchronization/syncdialog.cpp | 4 ++--
src/synchronization/syncutils.cpp | 5 +++--
9 files changed, 29 insertions(+), 32 deletions(-)
---
diff --git a/src/gnote.cpp b/src/gnote.cpp
index a8a6b50a..0a475bb9 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -675,7 +675,7 @@ namespace gnote {
}
if (!noteXml.empty()) {
- noteTitle = NoteArchiver::obj().get_title_from_note_xml (noteXml);
+ noteTitle = m_manager->note_archiver().get_title_from_note_xml (noteXml);
if (!noteTitle.empty()) {
// Check for conflicting titles
Glib::ustring baseTitle = noteTitle;
@@ -686,7 +686,7 @@ namespace gnote {
Glib::ustring note_uri = remote->CreateNamedNote(noteTitle);
// Update title in the note XML
- noteXml = NoteArchiver::obj().get_renamed_note_xml (noteXml, baseTitle, noteTitle);
+ noteXml = m_manager->note_archiver().get_renamed_note_xml (noteXml, baseTitle, noteTitle);
if (!note_uri.empty()) {
// Load in the XML contents of the note file
diff --git a/src/note.cpp b/src/note.cpp
index c2cf9c66..321d9499 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -349,7 +349,7 @@ namespace gnote {
Note::Ptr Note::load(const Glib::ustring & read_file, NoteManager & manager)
{
NoteData *data = new NoteData(url_from_path(read_file));
- NoteArchiver::read(read_file, *data);
+ manager.note_archiver().read_file(read_file, *data);
return create_existing_note(data, read_file, manager);
}
@@ -369,7 +369,7 @@ namespace gnote {
DBG_OUT("Saving '%s'...", m_data.data().title().c_str());
try {
- NoteArchiver::write(file_path(), m_data.synchronized_data());
+ manager().note_archiver().write_file(file_path(), m_data.synchronized_data());
}
catch (const sharp::Exception & e) {
// Probably IOException or UnauthorizedAccessException?
diff --git a/src/notebase.cpp b/src/notebase.cpp
index 89331313..dcebcca5 100644
--- a/src/notebase.cpp
+++ b/src/notebase.cpp
@@ -189,7 +189,7 @@ void NoteBase::set_change_type(ChangeType c)
void NoteBase::save()
{
try {
- NoteArchiver::write(m_file_path, data_synchronizer().data());
+ m_manager.note_archiver().write_file(m_file_path, data_synchronizer().data());
}
catch (const sharp::Exception & e) {
// Probably IOException or UnauthorizedAccessException?
@@ -280,7 +280,7 @@ bool NoteBase::contains_tag(const Tag::Ptr & tag) const
Glib::ustring NoteBase::get_complete_note_xml()
{
- return NoteArchiver::write_string(data_synchronizer().synchronized_data());
+ return m_manager.note_archiver().write_string(data_synchronizer().synchronized_data());
}
void NoteBase::set_xml_content(const Glib::ustring & xml)
@@ -413,14 +413,6 @@ void NoteBase::enabled(bool is_enabled)
const char *NoteArchiver::CURRENT_VERSION = "0.3";
-//instance
-NoteArchiver NoteArchiver::s_obj;
-
-void NoteArchiver::read(const Glib::ustring & read_file, NoteData & data)
-{
- return obj().read_file(read_file, data);
-}
-
void NoteArchiver::read_file(const Glib::ustring & file, NoteData & data)
{
Glib::ustring version;
@@ -431,7 +423,7 @@ void NoteArchiver::read_file(const Glib::ustring & file, NoteData & data)
// Note has old format, so rewrite it. No need
// to reread, since we are not adding anything.
DBG_OUT("Updating note XML from %s to newest format...", version.c_str());
- NoteArchiver::write(file, data);
+ write_file(file, data);
}
catch(sharp::Exception & e) {
// write failure, but not critical
@@ -516,18 +508,13 @@ Glib::ustring NoteArchiver::write_string(const NoteData & note)
{
Glib::ustring str;
sharp::XmlWriter xml;
- obj().write(xml, note);
+ write(xml, note);
xml.close();
str = xml.to_string();
return str;
}
-void NoteArchiver::write(const Glib::ustring & write_file, const NoteData & data)
-{
- obj().write_file(write_file, data);
-}
-
void NoteArchiver::write_file(const Glib::ustring & _write_file, const NoteData & data)
{
try {
diff --git a/src/notebase.hpp b/src/notebase.hpp
index 398f16e0..d6ce579a 100644
--- a/src/notebase.hpp
+++ b/src/notebase.hpp
@@ -273,16 +273,16 @@ private:
class NoteArchiver
- : public base::Singleton<NoteArchiver>
{
public:
static const char *CURRENT_VERSION;
- static void read(const Glib::ustring & read_file, NoteData & data);
- static Glib::ustring write_string(const NoteData & data);
- static void write(const Glib::ustring & write_file, const NoteData & data);
+ explicit NoteArchiver(NoteManagerBase & manager)
+ : m_manager(manager)
+ {}
void read_file(const Glib::ustring & file, NoteData & data);
void read(sharp::XmlReader & xml, NoteData & data);
+ Glib::ustring write_string(const NoteData & data);
void write_file(const Glib::ustring & write_file, const NoteData & data);
void write(sharp::XmlWriter & xml, const NoteData & data);
@@ -290,8 +290,8 @@ public:
Glib::ustring get_title_from_note_xml(const Glib::ustring & noteXml) const;
protected:
void _read(sharp::XmlReader & xml, NoteData & data, Glib::ustring & version);
-
- static NoteArchiver s_obj;
+private:
+ NoteManagerBase & m_manager;
};
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index 7f345ad6..a9749d13 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -40,6 +40,7 @@ namespace gnote {
NoteManager::NoteManager(const Glib::ustring & directory)
: NoteManagerBase(directory)
+ , m_note_archiver(*this)
{
Glib::ustring backup = directory + "/Backup";
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index f6f7cbab..0adc6bf8 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -40,6 +40,11 @@ namespace gnote {
NoteManager(const Glib::ustring &);
~NoteManager();
+ virtual NoteArchiver & note_archiver() override
+ {
+ return m_note_archiver;
+ }
+
void on_setting_changed(const Glib::ustring & key);
AddinManager & get_addin_manager()
@@ -71,6 +76,7 @@ namespace gnote {
void on_exiting_event();
AddinManager *m_addin_mgr;
+ NoteArchiver m_note_archiver;
};
diff --git a/src/notemanagerbase.hpp b/src/notemanagerbase.hpp
index 95e9da51..d378e7ea 100644
--- a/src/notemanagerbase.hpp
+++ b/src/notemanagerbase.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2014,2017 Aurimas Cernius
+ * Copyright (C) 2010-2014,2017,2019 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -45,6 +45,8 @@ public:
size_t trie_max_length();
TrieHit<NoteBase::WeakPtr>::ListPtr find_trie_matches(const Glib::ustring &);
+ virtual NoteArchiver & note_archiver() = 0;
+
void read_only(bool ro)
{
m_read_only = ro;
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index 14fca1e2..58c1ddac 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -712,9 +712,9 @@ void SyncDialog::rename_note(const Note::Ptr & note, const Glib::ustring & newTi
note->save(); // Write to file
bool noteOpen = note->is_opened();
Glib::ustring newContent = //note.XmlContent;
- NoteArchiver::obj().get_renamed_note_xml(note->xml_content(), oldTitle, newTitle);
+ m_manager.note_archiver().get_renamed_note_xml(note->xml_content(), oldTitle, newTitle);
Glib::ustring newCompleteContent = //note.GetCompleteNoteXml ();
- NoteArchiver::obj().get_renamed_note_xml(note->get_complete_note_xml(), oldTitle, newTitle);
+ m_manager.note_archiver().get_renamed_note_xml(note->get_complete_note_xml(), oldTitle, newTitle);
//Logger.Debug ("RenameNote: newContent: " + newContent);
//Logger.Debug ("RenameNote: newCompleteContent: " + newCompleteContent);
diff --git a/src/synchronization/syncutils.cpp b/src/synchronization/syncutils.cpp
index 6f5661e5..b1737b5d 100644
--- a/src/synchronization/syncutils.cpp
+++ b/src/synchronization/syncutils.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2012-2014,2016-2017 Aurimas Cernius
+ * Copyright (C) 2012-2014,2016-2017,2019 Aurimas Cernius
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
#include <glibmm/regex.h>
#include "debug.hpp"
+#include "notemanagerbase.hpp"
#include "syncutils.hpp"
#include "utils.hpp"
#include "sharp/files.hpp"
@@ -67,7 +68,7 @@ namespace sync {
sharp::XmlReader xml;
xml.load_buffer(m_xml_content);
NoteData *data = new NoteData(m_uuid);
- NoteArchiver::obj().read(xml, *data);
+ existing_note->manager().note_archiver().read(xml, *data);
std::unique_ptr<NoteData> update_data(data);
xml.close();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]