[gnote] Remove calls to deprecated gdk_threads_ functions



commit 03db4174228dbde17f92eb90d3a4f44514ccc53b
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sun Jan 20 18:34:41 2013 +0200

    Remove calls to deprecated gdk_threads_ functions
    
    Replace their use by g_main_context_invoke.

 src/main.cpp                        |    7 +--
 src/synchronization/syncdialog.cpp  |  154 +++++++++++------------------------
 src/synchronization/syncdialog.hpp  |   12 ++-
 src/synchronization/syncmanager.cpp |  124 +++++-----------------------
 src/synchronization/syncmanager.hpp |   10 +--
 src/synchronization/syncui.cpp      |   85 ++------------------
 src/synchronization/syncui.hpp      |   16 ++--
 src/utils.cpp                       |   35 ++++++++-
 src/utils.hpp                       |    5 +-
 9 files changed, 133 insertions(+), 315 deletions(-)
---
diff --git a/src/main.cpp b/src/main.cpp
index ad0354d..07bdeff 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -31,11 +31,6 @@ int main(int argc, char **argv)
   bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
   textdomain(GETTEXT_PACKAGE);
 
-  if(!g_thread_supported()) {
-    g_thread_init(NULL);
-  }
-  gdk_threads_init();
-
   Glib::RefPtr<gnote::Gnote> app = gnote::Gnote::create();
   return app->main(argc, argv);
 }
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index 547e9cd..43cf820 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -20,6 +20,7 @@
 
 #include "debug.hpp"
 
+#include <boost/bind.hpp>
 #include <boost/format.hpp>
 #include <boost/lexical_cast.hpp>
 #include <glibmm/i18n.h>
@@ -56,53 +57,6 @@ public:
 };
 
 
-typedef GObject GnoteSyncDialog;
-typedef GObjectClass GnoteSyncDialogClass;
-
-G_DEFINE_TYPE(GnoteSyncDialog, gnote_sync_dialog, G_TYPE_OBJECT)
-
-void gnote_sync_dialog_init(GnoteSyncDialog*)
-{}
-
-void gnote_sync_dialog_class_init(GnoteSyncDialogClass *klass)
-{
-  g_signal_new("sync-state-changed", G_TYPE_FROM_CLASS(klass),
-                   GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS),
-                   0, NULL, NULL, g_cclosure_marshal_VOID__INT,
-                   G_TYPE_NONE, 1, G_TYPE_INT, NULL);
-  g_signal_new("note-conflict-detected", G_TYPE_FROM_CLASS(klass),
-                   GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS),
-                   0, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
-                   G_TYPE_NONE, 1, G_TYPE_POINTER, NULL);
-}
-
-GObject *gnote_sync_dialog_new()
-{
-  g_type_init();
-  return G_OBJECT(g_object_new(gnote_sync_dialog_get_type(), NULL));
-}
-
-
-struct NoteConflictDetectedArgs
-{
-  NoteManager *manager;
-  Note::Ptr localConflictNote;
-  NoteUpdate *remoteNote;
-  std::list<std::string> noteUpdateTitles;
-  SyncTitleConflictResolution savedBehavior;
-  SyncTitleConflictResolution resolution;
-  std::exception *mainThreadException;
-
-  NoteConflictDetectedArgs() : mainThreadException(NULL) {}
-  ~NoteConflictDetectedArgs()
-    {
-      if(mainThreadException) {
-        delete mainThreadException;
-      }
-    }
-};
-
-
 class SyncTitleConflictDialog
   : public Gtk::Dialog
 {
@@ -272,9 +226,6 @@ SyncDialog::Ptr SyncDialog::create(NoteManager & m)
 SyncDialog::SyncDialog(NoteManager & manager)
   : m_manager(manager)
 {
-  m_obj = gnote_sync_dialog_new();
-  g_signal_connect(m_obj, "sync-state-changed", G_CALLBACK(on_sync_state_changed), this);
-  g_signal_connect(m_obj, "note-conflict-detected", G_CALLBACK(on_note_conflict_detected), this);
   m_progress_bar_timeout_id = 0;
 
   set_size_request(400, -1);
@@ -403,12 +354,6 @@ void SyncDialog::treeview_col2_data_func(Gtk::CellRenderer *renderer, const Gtk:
 }
 
 
-SyncDialog::~SyncDialog()
-{
-  g_object_unref(m_obj);
-}
-
-
 void SyncDialog::on_realize()
 {
   Gtk::Dialog::on_realize();
@@ -516,20 +461,8 @@ void SyncDialog::add_update_item(const std::string & title, std::string & status
 void SyncDialog::sync_state_changed(SyncState state)
 {
   // This event handler will be called by the synchronization thread
-  gdk_threads_enter();
-  g_signal_emit_by_name(m_obj, "sync-state-changed", static_cast<int>(state));
-  gdk_threads_leave();
-}
-
-
-void SyncDialog::on_sync_state_changed(GObject*, int state, gpointer data)
-{
-  try {
-    static_cast<SyncDialog*>(data)->sync_state_changed_(static_cast<SyncState>(state));
-  }
-  catch(...) {
-    DBG_OUT("Exception caught in %s\n", __func__);
-  }
+  utils::main_context_invoke(boost::bind(
+    sigc::mem_fun(*this, &SyncDialog::sync_state_changed_), state));
 }
 
 
@@ -656,85 +589,90 @@ void SyncDialog::note_conflict_detected(NoteManager & manager,
                                         NoteUpdate remoteNote,
                                         const std::list<std::string> & noteUpdateTitles)
 {
-  NoteConflictDetectedArgs *args = new NoteConflictDetectedArgs;
-  args->savedBehavior = CANCEL;
   int dlgBehaviorPref = Preferences::obj()
     .get_schema_settings(Preferences::SCHEMA_SYNC)->get_int(Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR);
-  // TODO: Check range of this int
-  args->savedBehavior = static_cast<SyncTitleConflictResolution>(dlgBehaviorPref);
-
-  args->resolution = OVERWRITE_EXISTING;
-  args->manager = &manager;
-  args->localConflictNote = localConflictNote;
-  args->remoteNote = &remoteNote;
-  args->noteUpdateTitles = noteUpdateTitles;
+  std::exception *mainThreadException = NULL;
+
   // This event handler will be called by the synchronization thread
   // so we have to use the delegate here to manipulate the GUI.
   // To be consistent, any exceptions in the delgate will be caught
   // and then rethrown in the synchronization thread.
-  gdk_threads_enter();
-  g_signal_emit_by_name(m_obj, "note-conflict-detected", args);
-  gdk_threads_leave();
-  if(args->mainThreadException != NULL) {
-    std::auto_ptr<NoteConflictDetectedArgs> for_deletion(args);
-    throw *for_deletion->mainThreadException;
+  utils::main_context_call(boost::bind(
+    sigc::mem_fun(*this, &SyncDialog::note_conflict_detected_),
+    manager,
+    localConflictNote,
+    remoteNote,
+    noteUpdateTitles,
+    static_cast<SyncTitleConflictResolution>(dlgBehaviorPref),
+    OVERWRITE_EXISTING,
+    &mainThreadException
+  ));
+
+  if(mainThreadException) {
+    std::exception e(*mainThreadException);
+    delete mainThreadException;
+    throw e;
   }
 }
 
 
-void SyncDialog::on_note_conflict_detected(GObject*, gpointer data, gpointer this__)
+void SyncDialog::note_conflict_detected_(NoteManager & manager,
+  const Note::Ptr & localConflictNote,
+  NoteUpdate remoteNote,
+  const std::list<std::string> & noteUpdateTitles,
+  SyncTitleConflictResolution savedBehavior,
+  SyncTitleConflictResolution resolution,
+  std::exception **mainThreadException)
 {
-  NoteConflictDetectedArgs *args = static_cast<NoteConflictDetectedArgs*>(data);
-  SyncDialog *this_ = static_cast<SyncDialog*>(this__);
   try {
-    SyncTitleConflictDialog conflictDlg(args->localConflictNote, args->noteUpdateTitles);
+    SyncTitleConflictDialog conflictDlg(localConflictNote, noteUpdateTitles);
     Gtk::ResponseType reponse = Gtk::RESPONSE_OK;
 
     bool noteSyncBitsMatch = ISyncManager::obj().synchronized_note_xml_matches(
-      args->localConflictNote->get_complete_note_xml(), args->remoteNote->m_xml_content);
+      localConflictNote->get_complete_note_xml(), remoteNote.m_xml_content);
 
     // If the synchronized note content is in conflict
     // and there is no saved conflict handling behavior, show the dialog
-    if(!noteSyncBitsMatch && args->savedBehavior == 0) {
+    if(!noteSyncBitsMatch && savedBehavior == 0) {
       reponse = static_cast<Gtk::ResponseType>(conflictDlg.run());
     }
 
 
     if(reponse == Gtk::RESPONSE_CANCEL) {
-      args->resolution = CANCEL;
+      resolution = CANCEL;
     }
     else {
       if(noteSyncBitsMatch) {
-        args->resolution = OVERWRITE_EXISTING;
+        resolution = OVERWRITE_EXISTING;
       }
-      else if(args->savedBehavior == 0) {
-        args->resolution = conflictDlg.resolution();
+      else if(savedBehavior == 0) {
+        resolution = conflictDlg.resolution();
       }
       else {
-        args->resolution = args->savedBehavior;
+        resolution = savedBehavior;
       }
 
-      switch(args->resolution) {
+      switch(resolution) {
       case OVERWRITE_EXISTING:
         if(conflictDlg.always_perform_this_action()) {
-          args->savedBehavior = args->resolution;
+          savedBehavior = resolution;
         }
         // No need to delete if sync will overwrite
-        if(args->localConflictNote->id() != args->remoteNote->m_uuid) {
-          args->manager->delete_note(args->localConflictNote);
+        if(localConflictNote->id() != remoteNote.m_uuid) {
+          manager.delete_note(localConflictNote);
         }
         break;
       case RENAME_EXISTING_AND_UPDATE:
         if(conflictDlg.always_perform_this_action()) {
-          args->savedBehavior = args->resolution;
+          savedBehavior = resolution;
         }
-        this_->rename_note(args->localConflictNote, conflictDlg.renamed_title(), true);
+        rename_note(localConflictNote, conflictDlg.renamed_title(), true);
         break;
       case RENAME_EXISTING_NO_UPDATE:
         if(conflictDlg.always_perform_this_action()) {
-          args->savedBehavior = args->resolution;
+          savedBehavior = resolution;
         }
-        this_->rename_note(args->localConflictNote, conflictDlg.renamed_title(), false);
+        rename_note(localConflictNote, conflictDlg.renamed_title(), false);
         break;
       case CANCEL:
         break;
@@ -742,15 +680,15 @@ void SyncDialog::on_note_conflict_detected(GObject*, gpointer data, gpointer thi
     }
 
     Preferences::obj().get_schema_settings(Preferences::SCHEMA_SYNC)->set_int(
-      Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR, static_cast<int>(args->savedBehavior)); // TODO: Clean up
+      Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR, static_cast<int>(savedBehavior)); // TODO: Clean up
 
     conflictDlg.hide();
 
     // Let the SyncManager continue
-    ISyncManager::obj().resolve_conflict(/*localConflictNote, */args->resolution);
+    ISyncManager::obj().resolve_conflict(/*localConflictNote, */resolution);
   }
   catch(std::exception & e) {
-    args->mainThreadException = new std::exception(e);
+    *mainThreadException = new std::exception(e);
   }
 }
 
diff --git a/src/synchronization/syncdialog.hpp b/src/synchronization/syncdialog.hpp
index 661a01c..99e3814 100644
--- a/src/synchronization/syncdialog.hpp
+++ b/src/synchronization/syncdialog.hpp
@@ -43,8 +43,6 @@ namespace sync {
 
     static Ptr create(NoteManager &);
 
-    virtual ~SyncDialog();
-
     virtual void sync_state_changed(SyncState state);
     virtual void note_synchronized(const std::string & noteTitle, NoteSyncType type);
     virtual void note_conflict_detected(NoteManager & manager,
@@ -61,8 +59,13 @@ namespace sync {
     virtual void on_realize();
   private:
     static void on_expander_activated(GtkExpander*, gpointer);
-    static void on_sync_state_changed(GObject*, int, gpointer);
-    static void on_note_conflict_detected(GObject*, gpointer, gpointer);
+    void note_conflict_detected_(NoteManager & manager,
+                                 const Note::Ptr & localConflictNote,
+                                 NoteUpdate remoteNote,
+                                 const std::list<std::string> & noteUpdateTitles,
+                                 SyncTitleConflictResolution savedBehavior,
+                                 SyncTitleConflictResolution resolution,
+                                 std::exception **mainThreadException);
 
     SyncDialog(NoteManager &);
     bool on_pulse_progress_bar();
@@ -85,7 +88,6 @@ namespace sync {
     unsigned m_progress_bar_timeout_id;
 
     Glib::RefPtr<Gtk::TreeStore> m_model;
-    GObject *m_obj;
   };
 
 }
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index 14f531e..bf38236 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -20,6 +20,7 @@
 
 #include "config.h"
 
+#include <boost/bind.hpp>
 #include <glibmm/i18n.h>
 #include <gtkmm/actiongroup.h>
 #include <sigc++/sigc++.h>
@@ -41,85 +42,12 @@
 namespace gnote {
 namespace sync {
 
-  namespace {
-
-    typedef GObject SyncHelper;
-    typedef GObjectClass SyncHelperClass;
-
-    G_DEFINE_TYPE(SyncHelper, sync_helper, G_TYPE_OBJECT)
-
-    void sync_helper_init(SyncHelper*)
-    {}
-
-    void sync_helper_class_init(SyncHelperClass * klass)
-    {
-      g_signal_new("delete-notes", G_TYPE_FROM_CLASS(klass),
-                   GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS),
-                   0, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
-                   G_TYPE_NONE, 1, G_TYPE_POINTER, NULL);
-      g_signal_new("create-note", G_TYPE_FROM_CLASS(klass),
-                   GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS),
-                   0, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
-                   G_TYPE_NONE, 1, G_TYPE_POINTER, NULL);
-      g_signal_new("update-note", G_TYPE_FROM_CLASS(klass),
-                   GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS),
-                   0, NULL, NULL, g_cclosure_marshal_generic,
-                   G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER, NULL);
-      g_signal_new("delete-note", G_TYPE_FROM_CLASS(klass),
-                   GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS),
-                   0, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
-                   G_TYPE_NONE, 1, G_TYPE_POINTER, NULL);
-    }
-
-    GObject * sync_helper_new()
-    {
-      g_type_init();
-      return G_OBJECT(g_object_new(sync_helper_get_type(), NULL));
-    }
-
-    void sync_helper_delete_notes(GObject * helper, gpointer server)
-    {
-      gdk_threads_enter();
-      g_signal_emit_by_name(helper, "delete-notes", server);
-      gdk_threads_leave();
-    }
-
-    void sync_helper_create_note(GObject * helper, gpointer note_update)
-    {
-      gdk_threads_enter();
-      g_signal_emit_by_name(helper, "create-note", note_update);
-      gdk_threads_leave();
-    }
-
-    void sync_helper_update_note(GObject * helper, gpointer existing_note, gpointer note_update)
-    {
-      gdk_threads_enter();
-      g_signal_emit_by_name(helper, "update-note", existing_note, note_update);
-      gdk_threads_leave();
-    }
-
-    void sync_helper_delete_note(GObject * helper, gpointer existing_note)
-    {
-      gdk_threads_enter();
-      g_signal_emit_by_name(helper, "delete-note", existing_note);
-      gdk_threads_leave();
-    }
-
-  }
-
-
   SyncManager::SyncManager(NoteManager & m)
     : m_note_manager(m)
   {
   }
 
 
-  SyncManager::~SyncManager()
-  {
-    g_object_unref(m_sync_helper);
-  }
-
-
   void SyncManager::init(NoteManager & m)
   {
     SyncManager *manager = new SyncManager(m);
@@ -129,11 +57,6 @@ namespace sync {
 
   void SyncManager::_init(NoteManager & manager)
   {
-    m_sync_helper = sync_helper_new();
-    g_signal_connect(m_sync_helper, "delete-notes", G_CALLBACK(SyncManager::on_delete_notes), NULL);
-    g_signal_connect(m_sync_helper, "create-note", G_CALLBACK(SyncManager::on_create_note), NULL);
-    g_signal_connect(m_sync_helper, "update-note", G_CALLBACK(SyncManager::on_update_note), NULL);
-    g_signal_connect(m_sync_helper, "delete-note", G_CALLBACK(SyncManager::on_delete_note), NULL);
     m_client = SyncClient::Ptr(new GnoteSyncClient(manager));
     // Add a "Synchronize Notes" to Gnote's Application Menu
     IActionManager & am(IActionManager::obj());
@@ -346,7 +269,8 @@ namespace sync {
       // delegate to run in the main gtk thread.
       // To be consistent, any exceptions in the delgate will be caught
       // and then rethrown in the synchronization thread.
-      sync_helper_delete_notes(m_sync_helper, &server);
+      utils::main_context_call(boost::bind(
+        sigc::mem_fun(*this, &SyncManager::delete_notes), server));
 
       // TODO: Add following updates to syncDialog treeview
 
@@ -635,7 +559,8 @@ namespace sync {
     // delegate to run in the main gtk thread.
     // To be consistent, any exceptions in the delgate will be caught
     // and then rethrown in the synchronization thread.
-    sync_helper_create_note(m_sync_helper, const_cast<NoteUpdate*>(&noteUpdate));
+    utils::main_context_call(boost::bind(
+      sigc::mem_fun(*this, &SyncManager::create_note), noteUpdate));
   }
 
 
@@ -645,7 +570,8 @@ namespace sync {
     // delegate to run in the main gtk thread.
     // To be consistent, any exceptions in the delgate will be caught
     // and then rethrown in the synchronization thread.
-    sync_helper_update_note(m_sync_helper, const_cast<Note::Ptr*>(&existingNote), const_cast<NoteUpdate*>(&noteUpdate));
+    utils::main_context_call(boost::bind(
+      sigc::mem_fun(*this, &SyncManager::update_note), existingNote, noteUpdate));
   }
 
 
@@ -655,7 +581,8 @@ namespace sync {
     // delegate to run in the main gtk thread.
     // To be consistent, any exceptions in the delgate will be caught
     // and then rethrown in the synchronization thread.
-    sync_helper_delete_note(m_sync_helper, const_cast<Note::Ptr*>(&existingNote));
+    utils::main_context_call(boost::bind(
+      sigc::mem_fun(*this, &SyncManager::delete_note), existingNote));
   }
 
 
@@ -734,12 +661,11 @@ namespace sync {
   }
 
 
-  void SyncManager::on_delete_notes(GObject*, gpointer serv, gpointer)
+  void SyncManager::delete_notes(const SyncServer::Ptr & server)
   {
     try {
-      SyncServer::Ptr & server = *static_cast<SyncServer::Ptr*>(serv);
       // Make list of all local notes
-      std::list<Note::Ptr> localNotes = SyncManager::_obj().note_mgr().get_notes();
+      std::list<Note::Ptr> localNotes = note_mgr().get_notes();
 
       // Get all notes currently on server
       std::list<std::string> serverNotes = server->get_all_note_uuids();
@@ -748,10 +674,10 @@ namespace sync {
       for(std::list<Note::Ptr>::iterator iter = localNotes.begin(); iter != localNotes.end(); ++iter) {
 	if(SyncManager::_obj().m_client->get_revision(*iter) != -1
 	   && std::find(serverNotes.begin(), serverNotes.end(), (*iter)->id()) == serverNotes.end()) {
-	  if(SyncManager::_obj().m_sync_ui != 0) {
-	    SyncManager::_obj().m_sync_ui->note_synchronized((*iter)->get_title(), DELETE_FROM_CLIENT);
+	  if(m_sync_ui != 0) {
+	    m_sync_ui->note_synchronized((*iter)->get_title(), DELETE_FROM_CLIENT);
 	  }
-	  SyncManager::_obj().note_mgr().delete_note(*iter);
+	  note_mgr().delete_note(*iter);
 	}
       }
     }
@@ -764,12 +690,11 @@ namespace sync {
   }
 
 
-  void SyncManager::on_create_note(GObject*, gpointer note_update, gpointer)
+  void SyncManager::create_note(const NoteUpdate & noteUpdate)
   {
     try {
-      NoteUpdate & noteUpdate = *static_cast<NoteUpdate*>(note_update);
-      Note::Ptr existingNote = SyncManager::_obj().note_mgr().create_with_guid(noteUpdate.m_title, noteUpdate.m_uuid);
-      SyncManager::_obj().update_local_note(existingNote, noteUpdate, DOWNLOAD_NEW);
+      Note::Ptr existingNote = note_mgr().create_with_guid(noteUpdate.m_title, noteUpdate.m_uuid);
+      update_local_note(existingNote, noteUpdate, DOWNLOAD_NEW);
     }
     catch(std::exception & e) {
       DBG_OUT("Exception caught in %s: %s\n", __func__, e.what());
@@ -780,12 +705,10 @@ namespace sync {
   }
 
 
-  void SyncManager::on_update_note(GObject*, gpointer existing_note, gpointer note_update, gpointer)
+  void SyncManager::update_note(const Note::Ptr & existingNote, const NoteUpdate & noteUpdate)
   {
     try {
-      Note::Ptr *existingNote = static_cast<Note::Ptr*>(existing_note);
-      NoteUpdate & noteUpdate = *static_cast<NoteUpdate*>(note_update);
-      SyncManager::_obj().update_local_note(*existingNote, noteUpdate, DOWNLOAD_MODIFIED);
+      update_local_note(existingNote, noteUpdate, DOWNLOAD_MODIFIED);
     }
     catch(std::exception & e) {
       DBG_OUT("Exception caught in %s: %s\n", __func__, e.what());
@@ -796,11 +719,10 @@ namespace sync {
   }
 
 
-  void SyncManager::on_delete_note(GObject*, gpointer existing_note, gpointer)
+  void SyncManager::delete_note(const Note::Ptr & existingNote)
   {
     try {
-      Note::Ptr *existingNote = static_cast<Note::Ptr*>(existing_note);
-      SyncManager::_obj().note_mgr().delete_note(*existingNote);
+      note_mgr().delete_note(existingNote);
     }
     catch(std::exception & e) {
       DBG_OUT("Exception caught in %s: %s\n", __func__, e.what());
@@ -813,9 +735,7 @@ namespace sync {
 
   void SyncManager::note_save(const Note::Ptr & note)
   {
-    gdk_threads_enter();
-    note->save();
-    gdk_threads_leave();
+    utils::main_context_call(sigc::mem_fun(*note, &Note::save));
   }
 
 
diff --git a/src/synchronization/syncmanager.hpp b/src/synchronization/syncmanager.hpp
index 11f8a24..4eb6a59 100644
--- a/src/synchronization/syncmanager.hpp
+++ b/src/synchronization/syncmanager.hpp
@@ -40,7 +40,6 @@ namespace sync {
   {
   public:
     SyncManager(NoteManager &);
-    ~SyncManager();
     static void init(NoteManager &);
     virtual void reset_client();
     virtual void perform_synchronization(const std::tr1::shared_ptr<SyncUI> & sync_ui);
@@ -72,10 +71,10 @@ namespace sync {
     Note::Ptr find_note_by_uuid(const std::string & uuid);
     NoteManager & note_mgr();
     void get_synchronized_xml_bits(const std::string & noteXml, std::string & title, std::string & tags, std::string & content);
-    static void on_delete_notes(GObject*, gpointer, gpointer);
-    static void on_create_note(GObject*, gpointer, gpointer);
-    static void on_update_note(GObject*, gpointer, gpointer, gpointer);
-    static void on_delete_note(GObject*, gpointer, gpointer);
+    void delete_notes(const SyncServer::Ptr & server);
+    void create_note(const NoteUpdate & noteUpdate);
+    void update_note(const Note::Ptr & existingNote, const NoteUpdate & noteUpdate);
+    void delete_note(const Note::Ptr & existingNote);
     static void note_save(const Note::Ptr & note);
 
     NoteManager & m_note_manager;
@@ -88,7 +87,6 @@ namespace sync {
     int m_autosync_timeout_pref_minutes;
     int m_current_autosync_timeout_minutes;
     sharp::DateTime m_last_background_check;
-    GObject *m_sync_helper;
   };
 
 
diff --git a/src/synchronization/syncui.cpp b/src/synchronization/syncui.cpp
index ce0cc6e..6d03fb7 100644
--- a/src/synchronization/syncui.cpp
+++ b/src/synchronization/syncui.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 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
@@ -18,86 +18,19 @@
  */
 
 
+#include <boost/bind.hpp>
+
 #include "debug.hpp"
 #include "syncui.hpp"
 
 
-namespace {
-
-  typedef GObject GnoteSyncUI;
-  typedef GObjectClass GnoteSyncUIClass;
-
-  G_DEFINE_TYPE(GnoteSyncUI, gnote_sync_ui, G_TYPE_OBJECT)
-
-  void gnote_sync_ui_init(GnoteSyncUI*)
-  {
-  }
-
-  void gnote_sync_ui_class_init(GnoteSyncUIClass * klass)
-  {
-    g_signal_new("connecting", G_TYPE_FROM_CLASS(klass),
-                 GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS),
-                 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
-                 G_TYPE_NONE, 0, NULL);
-    g_signal_new("idle", G_TYPE_FROM_CLASS(klass),
-                 GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS),
-                 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
-                 G_TYPE_NONE, 0, NULL);
-    g_signal_new("note-synchronized", G_TYPE_FROM_CLASS(klass),
-                 GSignalFlags(G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS),
-                 0, NULL, NULL, g_cclosure_marshal_generic,
-                 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT, NULL);
-  }
-
-  GnoteSyncUI * gnote_sync_ui_new()
-  {
-    g_type_init();
-    return static_cast<GnoteSyncUI*>(g_object_new(gnote_sync_ui_get_type(), NULL));
-  }
-
-}
-
-
 namespace gnote {
 namespace sync {
 
-  SyncUI::SyncUI()
-    : m_obj(gnote_sync_ui_new())
-  {
-    g_signal_connect(m_obj, "connecting", G_CALLBACK(SyncUI::on_signal_connecting), this);
-    g_signal_connect(m_obj, "idle", G_CALLBACK(SyncUI::on_signal_idle), this);
-    g_signal_connect(m_obj, "note-synchronized", G_CALLBACK(SyncUI::on_signal_note_synchronized), this);
-  }
-
-
-  void SyncUI::on_signal_connecting(GObject*, gpointer data)
-  {
-    static_cast<SyncUI*>(data)->m_signal_connecting.emit();
-  }
-
-
-  void SyncUI::on_signal_idle(GObject*, gpointer data)
-  {
-    static_cast<SyncUI*>(data)->m_signal_idle.emit();
-  }
-
-
-  void SyncUI::on_signal_note_synchronized(GObject*, const char *noteTitle, int type, gpointer data)
-  {
-    try {
-      static_cast<SyncUI*>(data)->note_synchronized(noteTitle, static_cast<NoteSyncType>(type));
-    }
-    catch(...) {
-      DBG_OUT("Exception caught in %s\n", __func__);
-    }
-  }
-
-
   void SyncUI::note_synchronized_th(const std::string & noteTitle, NoteSyncType type)
   {
-    gdk_threads_enter();
-    g_signal_emit_by_name(m_obj, "note-synchronized", noteTitle.c_str(), static_cast<int>(type));
-    gdk_threads_leave();
+    utils::main_context_invoke(boost::bind(
+      sigc::mem_fun(*this, &SyncUI::note_synchronized), noteTitle, type));
   }
 
 
@@ -109,9 +42,7 @@ namespace sync {
 
   void SyncUI::signal_connecting_emit()
   {
-    gdk_threads_enter();
-    g_signal_emit_by_name(m_obj, "connecting");
-    gdk_threads_leave();
+    utils::main_context_invoke(sigc::mem_fun(*this, &SyncUI::signal_connecting_emit_));
   }
 
 
@@ -123,9 +54,7 @@ namespace sync {
 
   void SyncUI::signal_idle_emit()
   {
-    gdk_threads_enter();
-    g_signal_emit_by_name(m_obj, "idle");
-    gdk_threads_leave();
+    utils::main_context_invoke(sigc::mem_fun(*this, &SyncUI::signal_idle_emit_));
   }
 
 }
diff --git a/src/synchronization/syncui.hpp b/src/synchronization/syncui.hpp
index 7ffa882..f25bf54 100644
--- a/src/synchronization/syncui.hpp
+++ b/src/synchronization/syncui.hpp
@@ -26,8 +26,6 @@
 #include <string>
 #include <tr1/memory>
 
-#include <glib-object.h>
-
 #include "syncutils.hpp"
 
 
@@ -55,16 +53,18 @@ namespace sync {
     void signal_connecting_emit();
     sigc::connection signal_idle_connect(const SlotIdle & slot);
     void signal_idle_emit();
-  protected:
-    SyncUI();
   private:
-    static void on_signal_connecting(GObject*, gpointer);
-    static void on_signal_idle(GObject*, gpointer);
-    static void on_signal_note_synchronized(GObject*, const char*, int, gpointer);
+    void signal_connecting_emit_()
+      {
+        m_signal_connecting.emit();
+      }
+    void signal_idle_emit_()
+      {
+        m_signal_idle.emit();
+      }
 
     sigc::signal<void> m_signal_connecting;
     sigc::signal<void> m_signal_idle;
-    GObject *m_obj;
   };
 
 }
diff --git a/src/utils.cpp b/src/utils.cpp
index 662b14f..b383b55 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2012 Aurimas Cernius
+ * Copyright (C) 2010-2013 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -34,6 +34,7 @@
 
 #include <glibmm/i18n.h>
 #include <glibmm/stringutils.h>
+#include <glibmm/threads.h>
 #include <gtkmm/icontheme.h>
 #include <gtkmm/image.h>
 #include <gtkmm/label.h>
@@ -89,6 +90,20 @@ namespace gnote {
           menu->get_attach_widget()->set_state(Gtk::STATE_NORMAL);
         }
       }
+
+      gboolean main_context_invoke_func(gpointer data)
+      {
+        sigc::slot<void> *slot = static_cast<sigc::slot<void>*>(data);
+        (*slot)();
+        delete slot;
+        return FALSE;
+      }
+
+      void main_context_call_func(const sigc::slot<void> & slot, Glib::Threads::Cond * cond)
+      {
+        slot();
+        cond->signal();
+      }
     }
 
 
@@ -240,6 +255,24 @@ namespace gnote {
       return pretty_str;
     }
 
+    void main_context_invoke(const sigc::slot<void> & slot)
+    {
+      sigc::slot<void> *data = new sigc::slot<void>(slot);
+      g_main_context_invoke(NULL, main_context_invoke_func, data);
+    }
+
+
+    void main_context_call(const sigc::slot<void> & slot)
+    {
+      Glib::Threads::Mutex mutex;
+      Glib::Threads::Cond cond;
+
+      mutex.lock();
+      main_context_invoke(boost::bind(
+        sigc::ptr_fun(main_context_call_func), slot, &cond));
+      cond.wait(mutex);
+    }
+
 
     void GlobalKeybinder::add_accelerator(const sigc::slot<void> & handler, guint key, 
                                           Gdk::ModifierType modifiers, Gtk::AccelFlags flags)
diff --git a/src/utils.hpp b/src/utils.hpp
index 4e235f9..4c6c316 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2012 Aurimas Cernius
+ * Copyright (C) 2011-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -58,6 +58,9 @@ namespace gnote {
                                      const std::string & error);
     std::string get_pretty_print_date(const sharp::DateTime &, bool show_time);
 
+    void main_context_invoke(const sigc::slot<void> & slot);
+    void main_context_call(const sigc::slot<void> & slot);
+
     class GlobalKeybinder
     {
     public:



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