[gnote] Bunch of std::string -> Glib::ustring replacements



commit 3bb24105d0b73afa8c94f127f832a8f5daf28fe5
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Fri Jan 13 20:51:56 2017 +0200

    Bunch of std::string -> Glib::ustring replacements

 src/synchronization/filesystemsyncserver.cpp |   92 +++++++++++++-------------
 src/synchronization/filesystemsyncserver.hpp |   36 +++++-----
 src/synchronization/gnotesyncclient.cpp      |   35 +++++-----
 src/synchronization/gnotesyncclient.hpp      |   20 +++---
 src/synchronization/isyncmanager.cpp         |    2 +-
 src/synchronization/isyncmanager.hpp         |   25 ++++----
 src/synchronization/syncmanager.cpp          |   86 +++++++++++-------------
 src/synchronization/syncmanager.hpp          |   10 ++--
 8 files changed, 149 insertions(+), 157 deletions(-)
---
diff --git a/src/synchronization/filesystemsyncserver.cpp b/src/synchronization/filesystemsyncserver.cpp
index 1cdf22e..fa60185 100644
--- a/src/synchronization/filesystemsyncserver.cpp
+++ b/src/synchronization/filesystemsyncserver.cpp
@@ -36,7 +36,7 @@
 
 namespace {
 
-int str_to_int(const std::string & s)
+int str_to_int(const Glib::ustring & s)
 {
   try {
     return STRING_TO_INT(s);
@@ -52,13 +52,13 @@ int str_to_int(const std::string & s)
 namespace gnote {
 namespace sync {
 
-SyncServer::Ptr FileSystemSyncServer::create(const std::string & path)
+SyncServer::Ptr FileSystemSyncServer::create(const Glib::ustring & path)
 {
   return SyncServer::Ptr(new FileSystemSyncServer(path));
 }
 
 
-FileSystemSyncServer::FileSystemSyncServer(const std::string & localSyncPath)
+FileSystemSyncServer::FileSystemSyncServer(const Glib::ustring & localSyncPath)
   : m_server_path(localSyncPath)
   , m_cache_path(Glib::build_filename(Glib::get_tmp_dir(), Glib::get_user_name(), "gnote"))
 {
@@ -85,7 +85,7 @@ void FileSystemSyncServer::upload_notes(const std::list<Note::Ptr> & notes)
   DBG_OUT("UploadNotes: notes.Count = %d", int(notes.size()));
   for(std::list<Note::Ptr>::const_iterator iter = notes.begin(); iter != notes.end(); ++iter) {
     try {
-      std::string serverNotePath = Glib::build_filename(m_new_revision_path, 
sharp::file_filename((*iter)->file_path()));
+      Glib::ustring serverNotePath = Glib::build_filename(m_new_revision_path, 
sharp::file_filename((*iter)->file_path()));
       sharp::file_copy((*iter)->file_path(), serverNotePath);
       m_updated_notes.push_back(sharp::file_basename((*iter)->file_path()));
     }
@@ -96,15 +96,15 @@ void FileSystemSyncServer::upload_notes(const std::list<Note::Ptr> & notes)
 }
 
 
-void FileSystemSyncServer::delete_notes(const std::list<std::string> & deletedNoteUUIDs)
+void FileSystemSyncServer::delete_notes(const std::list<Glib::ustring> & deletedNoteUUIDs)
 {
   m_deleted_notes.insert(m_deleted_notes.end(), deletedNoteUUIDs.begin(), deletedNoteUUIDs.end());
 }
 
 
-std::list<std::string> FileSystemSyncServer::get_all_note_uuids()
+std::list<Glib::ustring> FileSystemSyncServer::get_all_note_uuids()
 {
-  std::list<std::string> noteUUIDs;
+  std::list<Glib::ustring> noteUUIDs;
 
   if(is_valid_xml_file(m_manifest_path)) {
     // TODO: Permission errors
@@ -128,11 +128,11 @@ bool FileSystemSyncServer::updates_available_since(int revision)
 }
 
 
-std::map<std::string, NoteUpdate> FileSystemSyncServer::get_note_updates_since(int revision)
+std::map<Glib::ustring, NoteUpdate> FileSystemSyncServer::get_note_updates_since(int revision)
 {
-  std::map<std::string, NoteUpdate> noteUpdates;
+  std::map<Glib::ustring, NoteUpdate> noteUpdates;
 
-  std::string tempPath = Glib::build_filename(m_cache_path, "sync_temp");
+  Glib::ustring tempPath = Glib::build_filename(m_cache_path, "sync_temp");
   if(!sharp::directory_exists(tempPath)) {
     sharp::directory_create(tempPath);
   }
@@ -141,8 +141,8 @@ std::map<std::string, NoteUpdate> FileSystemSyncServer::get_note_updates_since(i
     try {
       std::list<std::string> files;
       sharp::directory_get_files(tempPath, files);
-      for(std::list<std::string>::iterator iter = files.begin(); iter != files.end(); ++iter) {
-        sharp::file_delete(*iter);
+      for(auto & iter : files) {
+        sharp::file_delete(iter);
       }
     }
     catch(...) {}
@@ -156,18 +156,18 @@ std::map<std::string, NoteUpdate> FileSystemSyncServer::get_note_updates_since(i
     sharp::XmlNodeSet noteNodes = sharp::xml_node_xpath_find(root_node, xpath.c_str());
     DBG_OUT("get_note_updates_since xpath returned %d nodes", int(noteNodes.size()));
     for(sharp::XmlNodeSet::iterator iter = noteNodes.begin(); iter != noteNodes.end(); ++iter) {
-      std::string note_id = sharp::xml_node_content(sharp::xml_node_xpath_find_single_node(*iter, "@id"));
+      Glib::ustring note_id = sharp::xml_node_content(sharp::xml_node_xpath_find_single_node(*iter, "@id"));
       int rev = str_to_int(sharp::xml_node_content(sharp::xml_node_xpath_find_single_node(*iter, "@rev")));
       if(noteUpdates.find(note_id) == noteUpdates.end()) {
         // Copy the file from the server to the temp directory
-        std::string revDir = get_revision_dir_path(rev);
-        std::string serverNotePath = Glib::build_filename(revDir, note_id + ".note");
-        std::string noteTempPath = Glib::build_filename(tempPath, note_id + ".note");
+        Glib::ustring revDir = get_revision_dir_path(rev);
+        Glib::ustring serverNotePath = Glib::build_filename(revDir, note_id + ".note");
+        Glib::ustring noteTempPath = Glib::build_filename(tempPath, note_id + ".note");
         sharp::file_copy(serverNotePath, noteTempPath);
 
         // Get the title, contents, etc.
-        std::string noteTitle;
-        std::string noteXml;
+        Glib::ustring noteTitle;
+        Glib::ustring noteXml;
         std::ifstream fin(noteTempPath.c_str());
         if(fin.is_open()) {
           do {
@@ -257,19 +257,19 @@ bool FileSystemSyncServer::commit_sync_transaction()
 
   if(m_updated_notes.size() > 0 || m_deleted_notes.size() > 0) {
     // TODO: error-checking, etc
-    std::string manifestFilePath = Glib::build_filename(m_new_revision_path, "manifest.xml");
+    Glib::ustring manifestFilePath = Glib::build_filename(m_new_revision_path, "manifest.xml");
     if(!sharp::directory_exists(m_new_revision_path)) {
       sharp::directory_create(m_new_revision_path);
     }
 
-    std::map<std::string, std::string> notes;
+    std::map<Glib::ustring, Glib::ustring> notes;
     if(is_valid_xml_file(m_manifest_path) == true) {
       xmlDocPtr xml_doc = xmlReadFile(m_manifest_path.c_str(), "UTF-8", 0);
       xmlNodePtr root_node = xmlDocGetRootElement(xml_doc);
       sharp::XmlNodeSet noteNodes = sharp::xml_node_xpath_find(root_node, "//note");
       for(sharp::XmlNodeSet::iterator iter = noteNodes.begin(); iter != noteNodes.end(); ++iter) {
-        std::string note_id = sharp::xml_node_get_attribute(*iter, "id");
-        std::string rev = sharp::xml_node_get_attribute(*iter, "rev");
+        Glib::ustring note_id = sharp::xml_node_get_attribute(*iter, "id");
+        Glib::ustring rev = sharp::xml_node_get_attribute(*iter, "rev");
         notes[note_id] = rev;
       }
       xmlFreeDoc(xml_doc);
@@ -283,7 +283,7 @@ bool FileSystemSyncServer::commit_sync_transaction()
       xml->write_attribute_string("", "revision", "", TO_STRING(m_new_revision));
       xml->write_attribute_string("", "server-id", "", m_server_id);
 
-      for(std::map<std::string, std::string>::iterator iter = notes.begin(); iter != notes.end(); ++iter) {
+      for(std::map<Glib::ustring, Glib::ustring>::iterator iter = notes.begin(); iter != notes.end(); 
++iter) {
         // Don't write out deleted notes
         if(std::find(m_deleted_notes.begin(), m_deleted_notes.end(), iter->first) != m_deleted_notes.end()) {
           continue;
@@ -301,7 +301,7 @@ bool FileSystemSyncServer::commit_sync_transaction()
       }
 
       // Write out all the updated notes
-      for(std::list<std::string>::iterator iter = m_updated_notes.begin(); iter != m_updated_notes.end(); 
++iter) {
+      for(std::list<Glib::ustring>::iterator iter = m_updated_notes.begin(); iter != m_updated_notes.end(); 
++iter) {
         xml->write_start_element("", "note", "");
         xml->write_attribute_string("", "id", "", *iter);
         xml->write_attribute_string("", "rev", "", TO_STRING(m_new_revision));
@@ -321,7 +321,7 @@ bool FileSystemSyncServer::commit_sync_transaction()
 
 
     // Rename original /manifest.xml to /manifest.xml.old
-    std::string oldManifestPath = m_manifest_path + ".old";
+    Glib::ustring oldManifestPath = m_manifest_path + ".old";
     if(sharp::file_exists(m_manifest_path) == true) {
       if(sharp::file_exists(oldManifestPath)) {
         sharp::file_delete(oldManifestPath);
@@ -344,17 +344,17 @@ bool FileSystemSyncServer::commit_sync_transaction()
         sharp::file_delete(oldManifestPath);
       }
 
-      std::string oldManifestFilePath = Glib::build_filename(get_revision_dir_path(m_new_revision - 1), 
"manifest.xml");
+      Glib::ustring oldManifestFilePath = Glib::build_filename(get_revision_dir_path(m_new_revision - 1), 
"manifest.xml");
       if(sharp::file_exists(oldManifestFilePath)) {
         // TODO: Do step #8 as described in http://bugzilla.gnome.org/show_bug.cgi?id=321037#c17
         // Like this?
         std::list<std::string> files;
         sharp::directory_get_files(oldManifestFilePath, files);
-        for(std::list<std::string>::iterator iter = files.begin(); iter != files.end(); ++iter) {
-          std::string fileGuid = sharp::file_basename(*iter);
+        for(auto & iter : files) {
+          Glib::ustring fileGuid = sharp::file_basename(iter);
           if(std::find(m_deleted_notes.begin(), m_deleted_notes.end(), fileGuid) != m_deleted_notes.end()
              || std::find(m_updated_notes.begin(), m_updated_notes.end(), fileGuid) != 
m_updated_notes.end()) {
-            sharp::file_delete(Glib::build_filename(oldManifestFilePath, *iter));
+            sharp::file_delete(Glib::build_filename(oldManifestFilePath, iter));
           }
           // TODO: Need to check *all* revision dirs, not just previous (duh)
           //       Should be a way to cache this from checking earlier.
@@ -395,7 +395,7 @@ int FileSystemSyncServer::latest_revision()
     xml_doc = xmlReadFile(m_manifest_path.c_str(), "UTF-8", 0);
     xmlNodePtr root_node = xmlDocGetRootElement(xml_doc);
     xmlNodePtr syncNode = sharp::xml_node_xpath_find_single_node(root_node, "//sync");
-    std::string latestRevStr = sharp::xml_node_get_attribute(syncNode, "revision");
+    Glib::ustring latestRevStr = sharp::xml_node_get_attribute(syncNode, "revision");
     if(latestRevStr != "") {
       latestRev = str_to_int(latestRevStr);
     }
@@ -407,9 +407,9 @@ int FileSystemSyncServer::latest_revision()
       // Look for the highest revision parent path
       std::list<std::string> directories;
       sharp::directory_get_directories(m_server_path, directories);
-      for(std::list<std::string>::iterator iter = directories.begin(); iter != directories.end(); ++iter) {
+      for(auto & iter : directories) {
         try {
-          int currentRevParentDir = str_to_int(sharp::file_filename(*iter));
+          int currentRevParentDir = str_to_int(sharp::file_filename(iter));
           if(currentRevParentDir > latestRevDir) {
             latestRevDir = currentRevParentDir;
           }
@@ -423,9 +423,9 @@ int FileSystemSyncServer::latest_revision()
         sharp::directory_get_directories(
           Glib::build_filename(m_server_path, TO_STRING(latestRevDir)),
           directories);
-        for(std::list<std::string>::iterator iter = directories.begin(); iter != directories.end(); ++iter) {
+        for(auto & iter : directories) {
           try {
-            int currentRev = str_to_int(*iter);
+            int currentRev = str_to_int(iter);
             if(currentRev > latestRev) {
               latestRev = currentRev;
             }
@@ -438,8 +438,8 @@ int FileSystemSyncServer::latest_revision()
       if(latestRev >= 0) {
         // Validate that the manifest file inside the revision is valid
         // TODO: Should we create the /manifest.xml file with a valid one?
-        std::string revDirPath = get_revision_dir_path(latestRev);
-        std::string revManifestPath = Glib::build_filename(revDirPath, "manifest.xml");
+        Glib::ustring revDirPath = get_revision_dir_path(latestRev);
+        Glib::ustring revManifestPath = Glib::build_filename(revDirPath, "manifest.xml");
         if(is_valid_xml_file(revManifestPath)) {
           foundValidManifest = true;
         }
@@ -473,31 +473,31 @@ SyncLockInfo FileSystemSyncServer::current_sync_lock()
 
     xmlNodePtr node = sharp::xml_node_xpath_find_single_node(root_node, "//transaction-id/text ()");
     if(node != NULL) {
-      std::string transaction_id_txt = sharp::xml_node_content(node);
+      Glib::ustring transaction_id_txt = sharp::xml_node_content(node);
       syncLockInfo.transaction_id = transaction_id_txt;
     }
 
     node = sharp::xml_node_xpath_find_single_node(root_node, "//client-id/text ()");
     if(node != NULL) {
-      std::string client_id_txt = sharp::xml_node_content(node);
+      Glib::ustring client_id_txt = sharp::xml_node_content(node);
       syncLockInfo.client_id = client_id_txt;
     }
 
     node = sharp::xml_node_xpath_find_single_node(root_node, "renew-count/text ()");
     if(node != NULL) {
-      std::string renew_txt = sharp::xml_node_content(node);
+      Glib::ustring renew_txt = sharp::xml_node_content(node);
       syncLockInfo.renew_count = str_to_int(renew_txt);
     }
 
     node = sharp::xml_node_xpath_find_single_node(root_node, "lock-expiration-duration/text ()");
     if(node != NULL) {
-      std::string span_txt = sharp::xml_node_content(node);
+      Glib::ustring span_txt = sharp::xml_node_content(node);
       syncLockInfo.duration = sharp::TimeSpan::parse(span_txt);
     }
 
     node = sharp::xml_node_xpath_find_single_node(root_node, "revision/text ()");
     if(node != NULL) {
-      std::string revision_txt = sharp::xml_node_content(node);
+      Glib::ustring revision_txt = sharp::xml_node_content(node);
       syncLockInfo.revision = str_to_int(revision_txt);
     }
 
@@ -508,7 +508,7 @@ SyncLockInfo FileSystemSyncServer::current_sync_lock()
 }
 
 
-std::string FileSystemSyncServer::id()
+Glib::ustring FileSystemSyncServer::id()
 {
   m_server_id = "";
 
@@ -531,7 +531,7 @@ std::string FileSystemSyncServer::id()
 }
 
 
-std::string FileSystemSyncServer::get_revision_dir_path(int rev)
+Glib::ustring FileSystemSyncServer::get_revision_dir_path(int rev)
 {
   return Glib::build_filename(m_server_path, TO_STRING(rev/100), TO_STRING(rev));
 }
@@ -586,8 +586,8 @@ void FileSystemSyncServer::cleanup_old_sync(const SyncLockInfo &)
     // figure out if there are any previous revisions with valid
     // manifest.xml files around.
     for (; rev >= 0; rev--) {
-      std::string revParentPath = get_revision_dir_path(rev);
-      std::string manPath = Glib::build_filename(revParentPath, "manifest.xml");
+      Glib::ustring revParentPath = get_revision_dir_path(rev);
+      Glib::ustring manPath = Glib::build_filename(revParentPath, "manifest.xml");
 
       if(is_valid_xml_file(manPath) == false) {
         continue;
@@ -610,7 +610,7 @@ void FileSystemSyncServer::cleanup_old_sync(const SyncLockInfo &)
 }
 
 
-bool FileSystemSyncServer::is_valid_xml_file(const std::string & xmlFilePath)
+bool FileSystemSyncServer::is_valid_xml_file(const Glib::ustring & xmlFilePath)
 {
   // Check that file exists
   if(!sharp::file_exists(xmlFilePath)) {
diff --git a/src/synchronization/filesystemsyncserver.hpp b/src/synchronization/filesystemsyncserver.hpp
index 156d689..29f5b79 100644
--- a/src/synchronization/filesystemsyncserver.hpp
+++ b/src/synchronization/filesystemsyncserver.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2013 Aurimas Cernius
+ * Copyright (C) 2012-2013,2017 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
@@ -35,42 +35,42 @@ class FileSystemSyncServer
   : public SyncServer
 {
 public:
-  static SyncServer::Ptr create(const std::string & path);
+  static SyncServer::Ptr create(const Glib::ustring & path);
   virtual bool begin_sync_transaction() override;
   virtual bool commit_sync_transaction() override;
   virtual bool cancel_sync_transaction() override;
-  virtual std::list<std::string> get_all_note_uuids() override;
-  virtual std::map<std::string, NoteUpdate> get_note_updates_since(int revision) override;
-  virtual void delete_notes(const std::list<std::string> & deletedNoteUUIDs) override;
+  virtual std::list<Glib::ustring> get_all_note_uuids() override;
+  virtual std::map<Glib::ustring, NoteUpdate> get_note_updates_since(int revision) override;
+  virtual void delete_notes(const std::list<Glib::ustring> & deletedNoteUUIDs) override;
   virtual void upload_notes(const std::list<Note::Ptr> & notes) override;
   virtual int latest_revision() override; // NOTE: Only reliable during a transaction
   virtual SyncLockInfo current_sync_lock() override;
-  virtual std::string id() override;
+  virtual Glib::ustring id() override;
   virtual bool updates_available_since(int revision) override;
 private:
-  explicit FileSystemSyncServer(const std::string & path);
+  explicit FileSystemSyncServer(const Glib::ustring & path);
 
-  std::string get_revision_dir_path(int rev);
+  Glib::ustring get_revision_dir_path(int rev);
   void cleanup_old_sync(const SyncLockInfo & syncLockInfo);
   void update_lock_file(const SyncLockInfo & syncLockInfo);
-  bool is_valid_xml_file(const std::string & xmlFilePath);
+  bool is_valid_xml_file(const Glib::ustring & xmlFilePath);
   void lock_timeout();
 
-  std::list<std::string> m_updated_notes;
-  std::list<std::string> m_deleted_notes;
+  std::list<Glib::ustring> m_updated_notes;
+  std::list<Glib::ustring> m_deleted_notes;
 
-  std::string m_server_id;
+  Glib::ustring m_server_id;
 
-  std::string m_server_path;
-  std::string m_cache_path;
-  std::string m_lock_path;
-  std::string m_manifest_path;
+  Glib::ustring m_server_path;
+  Glib::ustring m_cache_path;
+  Glib::ustring m_lock_path;
+  Glib::ustring m_manifest_path;
 
   int m_new_revision;
-  std::string m_new_revision_path;
+  Glib::ustring m_new_revision_path;
 
   sharp::DateTime m_initial_sync_attempt;
-  std::string m_last_sync_lock_hash;
+  Glib::ustring m_last_sync_lock_hash;
   utils::InterruptableTimeout m_lock_timeout;
   SyncLockInfo m_sync_lock;
 };
diff --git a/src/synchronization/gnotesyncclient.cpp b/src/synchronization/gnotesyncclient.cpp
index ee216eb..2449e02 100644
--- a/src/synchronization/gnotesyncclient.cpp
+++ b/src/synchronization/gnotesyncclient.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2014 Aurimas Cernius
+ * Copyright (C) 2012-2014,2017 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
@@ -85,7 +85,7 @@ namespace sync {
 
   void GnoteSyncClient::read_updated_note_atts(sharp::XmlReader & reader)
   {
-    std::string guid, rev;
+    Glib::ustring guid, rev;
     while(reader.move_to_next_attribute()) {
       if(reader.get_name() == "guid") {
        guid = reader.get_value();
@@ -107,7 +107,7 @@ namespace sync {
 
   void GnoteSyncClient::read_deleted_note_atts(sharp::XmlReader & reader)
   {
-    std::string guid, title;
+    Glib::ustring guid, title;
     while(reader.move_to_next_attribute()) {
       if(reader.get_name() == "guid") {
        guid = reader.get_value();
@@ -130,7 +130,6 @@ namespace sync {
       }
       if(reader.get_node_type() == XML_READER_TYPE_ELEMENT) {
        if(reader.get_name() == "note") {
-         std::string guid, rev;
          (this->*read_note_atts)(reader);
        }
       }
@@ -138,7 +137,7 @@ namespace sync {
   }
 
 
-  void GnoteSyncClient::parse(const std::string & manifest_path)
+  void GnoteSyncClient::parse(const Glib::ustring & manifest_path)
   {
     // Set defaults before parsing
     m_last_sync_date = sharp::DateTime::now().add_days(-1);
@@ -156,7 +155,7 @@ namespace sync {
     while(reader.read()) {
       if(reader.get_node_type() == XML_READER_TYPE_ELEMENT) {
        if(reader.get_name() == "last-sync-date") {
-         std::string value = reader.read_string();
+         Glib::ustring value = reader.read_string();
          try {
            m_last_sync_date = sharp::DateTime::from_iso8601(value);
          }
@@ -166,7 +165,7 @@ namespace sync {
          }
        }
        else if(reader.get_name() == "last-sync-rev") {
-         std::string value = reader.read_string();
+         Glib::ustring value = reader.read_string();
          try {
            m_last_sync_rev = STRING_TO_INT(value);
          }
@@ -189,7 +188,7 @@ namespace sync {
   }
 
 
-  void GnoteSyncClient::write(const std::string & manifest_path)
+  void GnoteSyncClient::write(const Glib::ustring & manifest_path)
   {
     sharp::XmlWriter xml(manifest_path);
 
@@ -211,11 +210,10 @@ namespace sync {
 
       xml.write_start_element("", "note-revisions", "");
 
-      for(std::map<std::string, int>::iterator noteGuid = m_file_revisions.begin();
-          noteGuid != m_file_revisions.end(); ++noteGuid) {
+      for(auto & noteGuid : m_file_revisions) {
        xml.write_start_element("", "note", "");
-       xml.write_attribute_string("", "guid", "", noteGuid->first);
-       xml.write_attribute_string("", "latest-revision", "", TO_STRING(noteGuid->second));
+       xml.write_attribute_string("", "guid", "", noteGuid.first);
+       xml.write_attribute_string("", "latest-revision", "", TO_STRING(noteGuid.second));
        xml.write_end_element();
       }
 
@@ -223,11 +221,10 @@ namespace sync {
 
       xml.write_start_element("", "note-deletions", "");
 
-      for(std::map<std::string, std::string>::iterator noteGuid = m_deleted_notes.begin();
-          noteGuid != m_deleted_notes.end(); ++noteGuid) {
+      for(auto & noteGuid : m_deleted_notes) {
        xml.write_start_element("", "note", "");
-       xml.write_attribute_string("", "guid", "", noteGuid->first);
-       xml.write_attribute_string("", "title", "", noteGuid->second);
+       xml.write_attribute_string("", "guid", "", noteGuid.first);
+       xml.write_attribute_string("", "title", "", noteGuid.second);
        xml.write_end_element();
       }
 
@@ -261,8 +258,8 @@ namespace sync {
 
   int GnoteSyncClient::get_revision(const NoteBase::Ptr & note)
   {
-    std::string note_guid = note->id();
-    std::map<std::string, int>::const_iterator iter = m_file_revisions.find(note_guid);
+    Glib::ustring note_guid = note->id();
+    auto iter = m_file_revisions.find(note_guid);
     if(iter != m_file_revisions.end()) {
       return iter->second;
     }
@@ -289,7 +286,7 @@ namespace sync {
   }
 
 
-  void GnoteSyncClient::associated_server_id(const std::string & server_id)
+  void GnoteSyncClient::associated_server_id(const Glib::ustring & server_id)
   {
     if(m_server_id != server_id) {
       m_server_id = server_id;
diff --git a/src/synchronization/gnotesyncclient.hpp b/src/synchronization/gnotesyncclient.hpp
index 8ae3265..8a5365a 100644
--- a/src/synchronization/gnotesyncclient.hpp
+++ b/src/synchronization/gnotesyncclient.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2014 Aurimas Cernius
+ * Copyright (C) 2012-2014,2017 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
@@ -46,29 +46,29 @@ namespace sync {
     virtual void last_synchronized_revision(int) override;
     virtual int get_revision(const NoteBase::Ptr & note) override;
     virtual void set_revision(const NoteBase::Ptr & note, int revision) override;
-    virtual std::map<std::string, std::string> deleted_note_titles() override
+    virtual std::map<Glib::ustring, Glib::ustring> deleted_note_titles() override
       {
         return m_deleted_notes;
       }
     virtual void reset() override;
-    virtual std::string associated_server_id() override
+    virtual Glib::ustring associated_server_id() override
       {
         return m_server_id;
       }
-    virtual void associated_server_id(const std::string &) override;
+    virtual void associated_server_id(const Glib::ustring &) override;
   protected:
     GnoteSyncClient();
     void init(NoteManagerBase &);
-    void parse(const std::string & manifest_path);
+    void parse(const Glib::ustring & manifest_path);
 
-    std::string m_local_manifest_file_path;
+    Glib::ustring m_local_manifest_file_path;
   private:
     static const char *LOCAL_MANIFEST_FILE_NAME;
 
     void note_deleted_handler(const NoteBase::Ptr &);
     void on_changed(const Glib::RefPtr<Gio::File>&, const Glib::RefPtr<Gio::File>&,
                     Gio::FileMonitorEvent);
-    void write(const std::string & manifest_path);
+    void write(const Glib::ustring & manifest_path);
     void read_updated_note_atts(sharp::XmlReader & reader);
     void read_deleted_note_atts(sharp::XmlReader & reader);
     void read_notes(sharp::XmlReader & reader, void (GnoteSyncClient::*read_note_atts)(sharp::XmlReader&));
@@ -76,9 +76,9 @@ namespace sync {
     Glib::RefPtr<Gio::FileMonitor> m_file_watcher;
     sharp::DateTime m_last_sync_date;
     int m_last_sync_rev;
-    std::string m_server_id;
-    std::map<std::string, int> m_file_revisions;
-    std::map<std::string, std::string> m_deleted_notes;
+    Glib::ustring m_server_id;
+    std::map<Glib::ustring, int> m_file_revisions;
+    std::map<Glib::ustring, Glib::ustring> m_deleted_notes;
   };
 
 }
diff --git a/src/synchronization/isyncmanager.cpp b/src/synchronization/isyncmanager.cpp
index 1f24143..59fa070 100644
--- a/src/synchronization/isyncmanager.cpp
+++ b/src/synchronization/isyncmanager.cpp
@@ -36,7 +36,7 @@ SyncLockInfo::SyncLockInfo()
 {
 }
 
-std::string SyncLockInfo::hash_string()
+Glib::ustring SyncLockInfo::hash_string()
 {
   return Glib::ustring::compose("%1-%2-%3-%4-%5", transaction_id, client_id, renew_count, duration.string(), 
revision);
 }
diff --git a/src/synchronization/isyncmanager.hpp b/src/synchronization/isyncmanager.hpp
index 72f290d..e14995c 100644
--- a/src/synchronization/isyncmanager.hpp
+++ b/src/synchronization/isyncmanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2014 Aurimas Cernius
+ * Copyright (C) 2012-2014,2017 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
@@ -22,7 +22,6 @@
 #define _SYNCHRONIZATION_ISYNCMANAGER_HPP_
 
 #include <list>
-#include <string>
 
 #include "base/macros.hpp"
 #include "note.hpp"
@@ -35,14 +34,14 @@ namespace sync {
 class SyncLockInfo
 {
 public:
-  std::string client_id;
-  std::string transaction_id;
+  Glib::ustring client_id;
+  Glib::ustring transaction_id;
   int renew_count;
   sharp::TimeSpan duration;
   int revision;
 
   SyncLockInfo();
-  std::string hash_string();
+  Glib::ustring hash_string();
 };
 
 class SyncClient
@@ -58,10 +57,10 @@ public:
   virtual void last_sync_date(const sharp::DateTime &) = 0;
   virtual int get_revision(const NoteBase::Ptr & note) = 0;
   virtual void set_revision(const NoteBase::Ptr & note, int revision) = 0;
-  virtual std::map<std::string, std::string> deleted_note_titles() = 0;
+  virtual std::map<Glib::ustring, Glib::ustring> deleted_note_titles() = 0;
   virtual void reset() = 0;
-  virtual std::string associated_server_id() = 0;
-  virtual void associated_server_id(const std::string &) = 0;
+  virtual Glib::ustring associated_server_id() = 0;
+  virtual void associated_server_id(const Glib::ustring &) = 0;
 };
 
 class ISyncManager
@@ -73,7 +72,7 @@ public:
   virtual void reset_client() = 0;
   virtual void perform_synchronization(const SyncUI::Ptr & sync_ui) = 0;
   virtual void resolve_conflict(SyncTitleConflictResolution resolution) = 0;
-  virtual bool synchronized_note_xml_matches(const std::string & noteXml1, const std::string & noteXml2) = 0;
+  virtual bool synchronized_note_xml_matches(const Glib::ustring & noteXml1, const Glib::ustring & noteXml2) 
= 0;
   virtual SyncState state() const = 0;
 };
 
@@ -87,13 +86,13 @@ public:
   virtual bool begin_sync_transaction() = 0;
   virtual bool commit_sync_transaction() = 0;
   virtual bool cancel_sync_transaction() = 0;
-  virtual std::list<std::string> get_all_note_uuids() = 0;
-  virtual std::map<std::string, NoteUpdate> get_note_updates_since(int revision) = 0;
-  virtual void delete_notes(const std::list<std::string> & deletedNoteUUIDs) = 0;
+  virtual std::list<Glib::ustring> get_all_note_uuids() = 0;
+  virtual std::map<Glib::ustring, NoteUpdate> get_note_updates_since(int revision) = 0;
+  virtual void delete_notes(const std::list<Glib::ustring> & deletedNoteUUIDs) = 0;
   virtual void upload_notes(const std::list<Note::Ptr> & notes) = 0;
   virtual int latest_revision() = 0; // NOTE: Only reliable during a transaction
   virtual SyncLockInfo current_sync_lock() = 0;
-  virtual std::string id() = 0;
+  virtual Glib::ustring id() = 0;
   virtual bool updates_available_since(int revision) = 0;
 };
 
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index 2c6a05c..738a41c 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2014 Aurimas Cernius
+ * Copyright (C) 2012-2014,2017 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
@@ -199,7 +199,7 @@ namespace sync {
       // for some reason, our local manifest is inaccurate and could misguide
       // sync into erroneously deleting local notes, etc.  We reset the client
       // to prevent this situation.
-      std::string serverId = server->id();
+      Glib::ustring serverId = server->id();
       if(m_client->associated_server_id() != serverId) {
         m_client->reset();
         m_client->associated_server_id(serverId);
@@ -209,16 +209,15 @@ namespace sync {
 
       // Handle notes modified or added on server
       DBG_OUT("Sync: GetNoteUpdatesSince rev %d", m_client->last_synchronized_revision());
-      std::map<std::string, NoteUpdate> noteUpdates = 
server->get_note_updates_since(m_client->last_synchronized_revision());
+      std::map<Glib::ustring, NoteUpdate> noteUpdates = 
server->get_note_updates_since(m_client->last_synchronized_revision());
       DBG_OUT("Sync: %d updates since rev %d", int(noteUpdates.size()), 
m_client->last_synchronized_revision());
 
       // Gather list of new/updated note titles
       // for title conflict handling purposes.
       std::list<std::string> noteUpdateTitles;
-      for(std::map<std::string, NoteUpdate>::iterator iter = noteUpdates.begin();
-          iter != noteUpdates.end(); ++iter) {
-        if(iter->second.m_title != "") {
-          noteUpdateTitles.push_back(iter->second.m_title);
+      for(auto & iter : noteUpdates) {
+        if(iter.second.m_title != "") {
+          noteUpdateTitles.push_back(iter.second.m_title);
         }
       }
 
@@ -227,14 +226,13 @@ namespace sync {
       // TODO: Lots of searching here and in the next foreach...
       //       Want this stuff to happen all at once first, but
       //       maybe there's a way to store this info and pass it on?
-      for(std::map<std::string, NoteUpdate>::iterator iter = noteUpdates.begin();
-          iter != noteUpdates.end(); ++iter) {
-        if(!find_note_by_uuid(iter->second.m_uuid) != 0) {
-          NoteBase::Ptr existingNote = note_mgr().find(iter->second.m_title);
-          if(existingNote != 0 && !iter->second.basically_equal_to(static_pointer_cast<Note>(existingNote))) 
{
+      for(auto & iter : noteUpdates) {
+        if(!find_note_by_uuid(iter.second.m_uuid) != 0) {
+          NoteBase::Ptr existingNote = note_mgr().find(iter.second.m_title);
+          if(existingNote != 0 && !iter.second.basically_equal_to(static_pointer_cast<Note>(existingNote))) {
             DBG_OUT("Sync: Early conflict detection for '%s'", iter->second.m_title.c_str());
             if(m_sync_ui != 0) {
-              m_sync_ui->note_conflict_detected(static_pointer_cast<Note>(existingNote), iter->second, 
noteUpdateTitles);
+              m_sync_ui->note_conflict_detected(static_pointer_cast<Note>(existingNote), iter.second, 
noteUpdateTitles);
             }
           }
         }
@@ -246,9 +244,8 @@ namespace sync {
       // TODO: Figure out why GUI doesn't always update smoothly
 
       // Process updates from the server; the bread and butter of sync!
-      for(std::map<std::string, NoteUpdate>::iterator iter = noteUpdates.begin();
-          iter != noteUpdates.end(); ++iter) {
-        NoteBase::Ptr existingNote = find_note_by_uuid(iter->second.m_uuid);
+      for(auto & iter : noteUpdates) {
+        NoteBase::Ptr existingNote = find_note_by_uuid(iter.second.m_uuid);
 
         if(existingNote == 0) {
           // Actually, it's possible to have a conflict here
@@ -256,32 +253,32 @@ namespace sync {
           // template notes (if a note with a new tag syncs
           // before its associated template). So check by
           // title and delete if necessary.
-          existingNote = note_mgr().find(iter->second.m_title);
+          existingNote = note_mgr().find(iter.second.m_title);
           if(existingNote != 0) {
-            DBG_OUT("SyncManager: Deleting auto-generated note: %s", iter->second.m_title.c_str());
+            DBG_OUT("SyncManager: Deleting auto-generated note: %s", iter.second.m_title.c_str());
             delete_note_in_main_thread(static_pointer_cast<Note>(existingNote));
           }
-          create_note_in_main_thread(iter->second);
+          create_note_in_main_thread(iter.second);
         }
         else if(existingNote->metadata_change_date() <= m_client->last_sync_date()
-                || iter->second.basically_equal_to(static_pointer_cast<Note>(existingNote))) {
+                || iter.second.basically_equal_to(static_pointer_cast<Note>(existingNote))) {
           // Existing note hasn't been modified since last sync; simply update it from server
-          update_note_in_main_thread(static_pointer_cast<Note>(existingNote), iter->second);
+          update_note_in_main_thread(static_pointer_cast<Note>(existingNote), iter.second);
         }
         else {
           // Logger.Debug ("Sync: Late conflict detection for '{0}'", noteUpdate.Title);
-          DBG_OUT("SyncManager: Content conflict in note update for note '%s'", 
iter->second.m_title.c_str());
+          DBG_OUT("SyncManager: Content conflict in note update for note '%s'", iter.second.m_title.c_str());
           // Note already exists locally, but has been modified since last sync; prompt user
           if(m_sync_ui != 0) {
-            m_sync_ui->note_conflict_detected(static_pointer_cast<Note>(existingNote), iter->second, 
noteUpdateTitles);
+            m_sync_ui->note_conflict_detected(static_pointer_cast<Note>(existingNote), iter.second, 
noteUpdateTitles);
           }
 
           // Note has been deleted or okay'd for overwrite
-          existingNote = find_note_by_uuid(iter->second.m_uuid);
+          existingNote = find_note_by_uuid(iter.second.m_uuid);
           if(existingNote == 0)
-            create_note_in_main_thread(iter->second);
+            create_note_in_main_thread(iter.second);
           else
-            update_note_in_main_thread(static_pointer_cast<Note>(existingNote), iter->second);
+            update_note_in_main_thread(static_pointer_cast<Note>(existingNote), iter.second);
         }
       }
 
@@ -326,17 +323,16 @@ namespace sync {
       }
 
       // Handle notes deleted on client
-      std::list<std::string> locallyDeletedUUIDs;
-      std::list<std::string> all_note_uuids = server->get_all_note_uuids();
-      for(std::list<std::string>::iterator iter = all_note_uuids.begin();
-          iter != all_note_uuids.end(); ++iter) {
-        if(find_note_by_uuid(*iter) == 0) {
-          locallyDeletedUUIDs.push_back(*iter);
+      std::list<Glib::ustring> locallyDeletedUUIDs;
+      std::list<Glib::ustring> all_note_uuids = server->get_all_note_uuids();
+      for(auto & iter : all_note_uuids) {
+        if(find_note_by_uuid(iter) == 0) {
+          locallyDeletedUUIDs.push_back(iter);
           if(m_sync_ui != 0) {
-            std::string deletedTitle = *iter;
-            std::map<std::string, std::string> deleted_note_titles = m_client->deleted_note_titles();
-            if(deleted_note_titles.find(*iter) != deleted_note_titles.end()) {
-              deletedTitle = deleted_note_titles[*iter];
+            Glib::ustring deletedTitle = iter;
+            auto deleted_note_titles = m_client->deleted_note_titles();
+            if(deleted_note_titles.find(iter) != deleted_note_titles.end()) {
+              deletedTitle = deleted_note_titles[iter];
             }
             m_sync_ui->note_synchronized_th(deletedTitle, DELETE_FROM_SERVER);
           }
@@ -426,7 +422,7 @@ namespace sync {
   void SyncManager::update_sync_action()
   {
     Glib::RefPtr<Gio::Settings> settings = Preferences::obj().get_schema_settings(Preferences::SCHEMA_SYNC);
-    std::string sync_addin_id = settings->get_string(Preferences::SYNC_SELECTED_SERVICE_ADDIN);
+    Glib::ustring sync_addin_id = settings->get_string(Preferences::SYNC_SELECTED_SERVICE_ADDIN);
     IActionManager::obj().get_app_action("sync-notes")->set_enabled(sync_addin_id != "");
 
     int timeoutPref = settings->get_int(Preferences::SYNC_AUTOSYNC_TIMEOUT);
@@ -546,7 +542,7 @@ namespace sync {
   {
     SyncServiceAddin *addin = NULL;
 
-    std::string sync_service_id = Preferences::obj()
+    Glib::ustring sync_service_id = Preferences::obj()
       .get_schema_settings(Preferences::SCHEMA_SYNC)->get_string(Preferences::SYNC_SELECTED_SERVICE_ADDIN);
     if(sync_service_id != "") {
       addin = get_sync_service_addin(sync_service_id);
@@ -556,7 +552,7 @@ namespace sync {
   }
 
 
-  SyncServiceAddin *SyncManager::get_sync_service_addin(const std::string & sync_service_id)
+  SyncServiceAddin *SyncManager::get_sync_service_addin(const Glib::ustring & sync_service_id)
   {
     SyncServiceAddin *addin = NULL;
 
@@ -629,7 +625,7 @@ namespace sync {
   }
 
 
-  NoteBase::Ptr SyncManager::find_note_by_uuid(const std::string & uuid)
+  NoteBase::Ptr SyncManager::find_note_by_uuid(const Glib::ustring & uuid)
   {
     return note_mgr().find_by_uri("note://gnote/" + uuid);
   }
@@ -641,11 +637,11 @@ namespace sync {
   }
 
 
-  bool SyncManager::synchronized_note_xml_matches(const std::string & noteXml1, const std::string & noteXml2)
+  bool SyncManager::synchronized_note_xml_matches(const Glib::ustring & noteXml1, const Glib::ustring & 
noteXml2)
   {
     try {
-      std::string title1, tags1, content1;
-      std::string title2, tags2, content2;
+      Glib::ustring title1, tags1, content1;
+      Glib::ustring title2, tags2, content2;
 
       get_synchronized_xml_bits(noteXml1, title1, tags1, content1);
       get_synchronized_xml_bits(noteXml2, title2, tags2, content2);
@@ -659,7 +655,7 @@ namespace sync {
   }
 
 
-  void SyncManager::get_synchronized_xml_bits(const std::string & noteXml, std::string & title, std::string 
& tags, std::string & content)
+  void SyncManager::get_synchronized_xml_bits(const Glib::ustring & noteXml, Glib::ustring & title, 
Glib::ustring & tags, Glib::ustring & content)
   {
     title = "";
     tags = "";
@@ -694,7 +690,7 @@ namespace sync {
       std::list<NoteBase::Ptr> localNotes = note_mgr().get_notes();
 
       // Get all notes currently on server
-      std::list<std::string> serverNotes = server->get_all_note_uuids();
+      auto serverNotes = server->get_all_note_uuids();
 
       // Delete notes locally that have been deleted on the server
       FOREACH(const NoteBase::Ptr & iter, localNotes) {
diff --git a/src/synchronization/syncmanager.hpp b/src/synchronization/syncmanager.hpp
index f8664e2..9d751fa 100644
--- a/src/synchronization/syncmanager.hpp
+++ b/src/synchronization/syncmanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2014 Aurimas Cernius
+ * Copyright (C) 2012-2014,2017 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
@@ -46,7 +46,7 @@ namespace sync {
     virtual void perform_synchronization(const SyncUI::Ptr & sync_ui) override;
     void synchronization_thread();
     virtual void resolve_conflict(SyncTitleConflictResolution resolution) override;
-    virtual bool synchronized_note_xml_matches(const std::string & noteXml1, const std::string & noteXml2) 
override;
+    virtual bool synchronized_note_xml_matches(const Glib::ustring & noteXml1, const Glib::ustring & 
noteXml2) override;
     virtual SyncState state() const override
       {
         return m_state;
@@ -54,7 +54,7 @@ namespace sync {
   protected:
     virtual void initialize_sync_service_addins(NoteManagerBase &);
     virtual void connect_system_signals();
-    virtual SyncServiceAddin *get_sync_service_addin(const std::string & sync_service_id);
+    virtual SyncServiceAddin *get_sync_service_addin(const Glib::ustring & sync_service_id);
     virtual SyncServiceAddin *get_configured_sync_service();
 
     SyncClient::Ptr m_client;
@@ -75,9 +75,9 @@ namespace sync {
     void update_note_in_main_thread(const Note::Ptr & existingNote, const NoteUpdate & noteUpdate);
     void delete_note_in_main_thread(const Note::Ptr & existingNote);
     void update_local_note(const NoteBase::Ptr & localNote, const NoteUpdate & serverNote, NoteSyncType 
syncType);
-    NoteBase::Ptr find_note_by_uuid(const std::string & uuid);
+    NoteBase::Ptr find_note_by_uuid(const Glib::ustring & uuid);
     NoteManagerBase & note_mgr();
-    void get_synchronized_xml_bits(const std::string & noteXml, std::string & title, std::string & tags, 
std::string & content);
+    void get_synchronized_xml_bits(const Glib::ustring & noteXml, Glib::ustring & title, Glib::ustring & 
tags, Glib::ustring & content);
     void delete_notes(const SyncServer::Ptr & server);
     void create_note(const NoteUpdate & noteUpdate);
     void update_note(const Note::Ptr & existingNote, const NoteUpdate & noteUpdate);



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