[gnote] Do not use singleton Gnote in sync uis



commit 3a9ce2dbf81265300e057a2f49094ff56058696d
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Wed Nov 13 17:41:01 2019 +0200

    Do not use singleton Gnote in sync uis

 src/gnote.cpp                       |  2 +-
 src/synchronization/silentui.cpp    | 10 +++++-----
 src/synchronization/silentui.hpp    |  4 ++--
 src/synchronization/syncdialog.cpp  | 26 +++++++++++++-------------
 src/synchronization/syncdialog.hpp  |  4 ++--
 src/synchronization/syncmanager.cpp |  2 +-
 src/synchronization/syncui.cpp      |  7 ++++---
 src/synchronization/syncui.hpp      |  6 +++++-
 8 files changed, 33 insertions(+), 28 deletions(-)
---
diff --git a/src/gnote.cpp b/src/gnote.cpp
index a1779bf4..175e006a 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -416,7 +416,7 @@ namespace gnote {
   void Gnote::open_note_sync_window(const Glib::VariantBase&)
   {
     if(m_sync_dlg == 0) {
-      m_sync_dlg = sync::SyncDialog::create(default_note_manager());
+      m_sync_dlg = sync::SyncDialog::create(*this, default_note_manager());
       m_sync_dlg->signal_response().connect(sigc::mem_fun(*this, &Gnote::on_sync_dialog_response));
     }
 
diff --git a/src/synchronization/silentui.cpp b/src/synchronization/silentui.cpp
index ba3dada7..29ea8e31 100644
--- a/src/synchronization/silentui.cpp
+++ b/src/synchronization/silentui.cpp
@@ -27,14 +27,14 @@
 namespace gnote {
 namespace sync {
 
-  SyncUI::Ptr SilentUI::create(NoteManagerBase & nm)
+  SyncUI::Ptr SilentUI::create(IGnote & g, NoteManagerBase & nm)
   {
-    return SyncUI::Ptr(new SilentUI(nm));
+    return std::make_shared<SilentUI>(g, nm);
   }
 
 
-  SilentUI::SilentUI(NoteManagerBase & manager)
-    : SyncUI(manager)
+  SilentUI::SilentUI(IGnote & g, NoteManagerBase & manager)
+    : SyncUI(g, manager)
     , m_ui_disabled(false)
   {
     signal_connecting_connect(sigc::mem_fun(*this, &SilentUI::on_connecting));
@@ -84,7 +84,7 @@ namespace sync {
     if(localConflictNote->id() != remoteNote.m_uuid) {
       m_manager.delete_note(localConflictNote);
     }
-    IGnote::obj().sync_manager().resolve_conflict(OVERWRITE_EXISTING);
+    m_gnote.sync_manager().resolve_conflict(OVERWRITE_EXISTING);
   }
 
 
diff --git a/src/synchronization/silentui.hpp b/src/synchronization/silentui.hpp
index b0a4442c..36858f77 100644
--- a/src/synchronization/silentui.hpp
+++ b/src/synchronization/silentui.hpp
@@ -34,9 +34,9 @@ namespace sync {
     : public SyncUI
   {
   public:
-    static SyncUI::Ptr create(NoteManagerBase &);
+    static SyncUI::Ptr create(IGnote &, NoteManagerBase &);
+    SilentUI(IGnote &, NoteManagerBase &);
   private:
-    explicit SilentUI(NoteManagerBase &);
     virtual void sync_state_changed(SyncState state) override;
     virtual void note_synchronized(const Glib::ustring & noteTitle, NoteSyncType type) override;
     virtual void note_conflict_detected(const Note::Ptr & localConflictNote,
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index cceeca7e..79a23ae8 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -218,14 +218,14 @@ private:
 
 
 
-SyncDialog::Ptr SyncDialog::create(NoteManagerBase & m)
+SyncDialog::Ptr SyncDialog::create(IGnote & g, NoteManagerBase & m)
 {
-  return SyncDialog::Ptr(new SyncDialog(m));
+  return std::make_shared<SyncDialog>(g, m);
 }
 
 
-SyncDialog::SyncDialog(NoteManagerBase & manager)
-  : SyncUI(manager)
+SyncDialog::SyncDialog(IGnote & g, NoteManagerBase & manager)
+  : SyncUI(g, manager)
 {
   m_progress_bar_timeout_id = 0;
 
@@ -245,7 +245,7 @@ SyncDialog::SyncDialog(NoteManagerBase & manager)
   hbox->show();
   outerVBox->attach(*hbox, 0, outerVBoxRow++, 1, 1);
 
-  m_image = manage(new Gtk::Image(IGnote::obj().icon_manager().get_icon(IconManager::GNOTE, 48)));
+  m_image = manage(new Gtk::Image(g.icon_manager().get_icon(IconManager::GNOTE, 48)));
   m_image->set_alignment(0, 0);
   m_image->show();
   hbox->attach(*m_image, 0, 0, 1, 1);
@@ -367,7 +367,7 @@ void SyncDialog::on_realize()
 {
   Gtk::Dialog::on_realize();
 
-  SyncState state = IGnote::obj().sync_manager().state();
+  SyncState state = m_gnote.sync_manager().state();
   if(state == IDLE) {
     // Kick off a timer to keep the progress bar going
     //m_progress_barTimeoutId = GLib.Timeout.Add (500, OnPulseProgressBar);
@@ -376,7 +376,7 @@ void SyncDialog::on_realize()
     timeout->attach();
 
     // Kick off a new synchronization
-    IGnote::obj().sync_manager().perform_synchronization(this->shared_from_this());
+    m_gnote.sync_manager().perform_synchronization(this->shared_from_this());
   }
   else {
     // Adjust the GUI accordingly
@@ -387,7 +387,7 @@ void SyncDialog::on_realize()
 
 bool SyncDialog::on_pulse_progress_bar()
 {
-  if(IGnote::obj().sync_manager().state() == IDLE) {
+  if(m_gnote.sync_manager().state() == IDLE) {
     return false;
   }
 
@@ -596,7 +596,7 @@ void SyncDialog::note_conflict_detected(const Note::Ptr & localConflictNote,
                                         NoteUpdate remoteNote,
                                         const std::vector<Glib::ustring> & noteUpdateTitles)
 {
-  int dlgBehaviorPref = IGnote::obj().preferences()
+  int dlgBehaviorPref = m_gnote.preferences()
     .get_schema_settings(Preferences::SCHEMA_SYNC)->get_int(Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR);
   std::exception *mainThreadException = NULL;
 
@@ -632,7 +632,7 @@ void SyncDialog::note_conflict_detected_(
     SyncTitleConflictDialog conflictDlg(localConflictNote, noteUpdateTitles);
     Gtk::ResponseType reponse = Gtk::RESPONSE_OK;
 
-    bool noteSyncBitsMatch = IGnote::obj().sync_manager().synchronized_note_xml_matches(
+    bool noteSyncBitsMatch = m_gnote.sync_manager().synchronized_note_xml_matches(
       localConflictNote->get_complete_note_xml(), remoteNote.m_xml_content);
 
     // If the synchronized note content is in conflict
@@ -683,13 +683,13 @@ void SyncDialog::note_conflict_detected_(
       }
     }
 
-    IGnote::obj().preferences().get_schema_settings(Preferences::SCHEMA_SYNC)->set_int(
+    m_gnote.preferences().get_schema_settings(Preferences::SCHEMA_SYNC)->set_int(
       Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR, static_cast<int>(savedBehavior)); // TODO: Clean up
 
     conflictDlg.hide();
 
     // Let the SyncManager continue
-    IGnote::obj().sync_manager().resolve_conflict(/*localConflictNote, */resolution);
+    m_gnote.sync_manager().resolve_conflict(/*localConflictNote, */resolution);
   }
   catch(std::exception & e) {
     *mainThreadException = new std::exception(e);
@@ -737,7 +737,7 @@ void SyncDialog::rename_note(const Note::Ptr & note, const Glib::ustring & newTi
 
 void SyncDialog::present_note(const Note::Ptr & note)
 {
-  MainWindow::present_in(IGnote::obj().get_window_for_note(), note);
+  MainWindow::present_in(m_gnote.get_window_for_note(), note);
 }
 
 }
diff --git a/src/synchronization/syncdialog.hpp b/src/synchronization/syncdialog.hpp
index 0b1fd76f..ff787f06 100644
--- a/src/synchronization/syncdialog.hpp
+++ b/src/synchronization/syncdialog.hpp
@@ -41,8 +41,9 @@ namespace sync {
   public:
     typedef std::shared_ptr<SyncDialog> Ptr;
 
-    static Ptr create(NoteManagerBase &);
+    static Ptr create(IGnote &, NoteManagerBase &);
 
+    SyncDialog(IGnote &, NoteManagerBase &);
     virtual void sync_state_changed(SyncState state) override;
     virtual void note_synchronized(const Glib::ustring & noteTitle, NoteSyncType type) override;
     virtual void note_conflict_detected(const Note::Ptr & localConflictNote,
@@ -65,7 +66,6 @@ namespace sync {
                                  SyncTitleConflictResolution resolution,
                                  std::exception **mainThreadException);
 
-    explicit SyncDialog(NoteManagerBase &);
     bool on_pulse_progress_bar();
     void on_row_activated(const Gtk::TreeModel::Path & path, Gtk::TreeViewColumn *column);
     void treeview_col1_data_func(Gtk::CellRenderer *renderer, const Gtk::TreeIter & iter);
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index dcab62bb..79d17803 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -508,7 +508,7 @@ namespace sync {
       if(client_has_updates || server_has_updates) {
         DBG_OUT("Detected that sync would be a good idea now");
         // TODO: Check that it's safe to sync, block other sync UIs
-        perform_synchronization(SilentUI::create(note_mgr()));
+        perform_synchronization(SilentUI::create(m_gnote, note_mgr()));
       }
     }
 
diff --git a/src/synchronization/syncui.cpp b/src/synchronization/syncui.cpp
index b4e184ec..dfb4bac6 100644
--- a/src/synchronization/syncui.cpp
+++ b/src/synchronization/syncui.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2014,2017 Aurimas Cernius
+ * Copyright (C) 2012-2014,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
@@ -25,8 +25,9 @@
 namespace gnote {
 namespace sync {
 
-  SyncUI::SyncUI(NoteManagerBase & manager)
-    : m_manager(manager)
+  SyncUI::SyncUI(IGnote & g, NoteManagerBase & manager)
+    : m_gnote(g)
+    , m_manager(manager)
   {
   }
 
diff --git a/src/synchronization/syncui.hpp b/src/synchronization/syncui.hpp
index 6f05f9ef..65eb04de 100644
--- a/src/synchronization/syncui.hpp
+++ b/src/synchronization/syncui.hpp
@@ -28,6 +28,9 @@
 
 
 namespace gnote {
+
+  class IGnote;
+
 namespace sync {
 
   class SyncUI
@@ -51,8 +54,9 @@ namespace sync {
     sigc::connection signal_idle_connect(const SlotIdle & slot);
     void signal_idle_emit();
   protected:
-    explicit SyncUI(NoteManagerBase & manager);
+    SyncUI(IGnote & g, NoteManagerBase & manager);
 
+    IGnote & m_gnote;
     NoteManagerBase & m_manager;
   private:
     void signal_connecting_emit_()


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