[gnote] Replace std::string by Glib::ustring in WebDavSyncService



commit 8a7dbcc3860c1bbe79c7fae4ef754dbb6594d965
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Feb 12 16:17:07 2017 +0200

    Replace std::string by Glib::ustring in WebDavSyncService

 .../webdavsyncservice/webdavsyncserviceaddin.cpp   |   44 ++++++-------------
 .../webdavsyncservice/webdavsyncserviceaddin.hpp   |   14 +++---
 src/gnome_keyring/ring.cpp                         |   23 +++++-----
 src/gnome_keyring/ring.hpp                         |   17 ++++----
 4 files changed, 41 insertions(+), 57 deletions(-)
---
diff --git a/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp 
b/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp
index f8a031a..540caba 100644
--- a/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp
+++ b/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp
@@ -45,7 +45,7 @@ WebDavSyncServiceModule::WebDavSyncServiceModule()
 
 
 const char *WebDavSyncServiceAddin::KEYRING_ITEM_NAME = "Tomboy sync WebDAV account";
-std::map<std::string, std::string> WebDavSyncServiceAddin::s_request_attributes;
+std::map<Glib::ustring, Glib::ustring> WebDavSyncServiceAddin::s_request_attributes;
 
 WebDavSyncServiceAddin * WebDavSyncServiceAddin::create()
 {
@@ -60,7 +60,7 @@ Gtk::Widget *WebDavSyncServiceAddin::create_preferences_control(EventHandler req
   table->set_col_spacings(10);
 
   // Read settings out of gconf
-  std::string url, username, password;
+  Glib::ustring url, username, password;
   get_config_settings(url, username, password);
 
   m_url_entry = new Gtk::Entry();
@@ -87,14 +87,14 @@ Gtk::Widget *WebDavSyncServiceAddin::create_preferences_control(EventHandler req
 
 bool WebDavSyncServiceAddin::is_configured()
 {
-  std::string url, username, password;
+  Glib::ustring url, username, password;
   return get_config_settings(url, username, password);
 }
 
 
 bool WebDavSyncServiceAddin::are_settings_valid()
 {
-  std::string url, username, password;
+  Glib::ustring url, username, password;
   return get_pref_widget_settings(url, username, password);
 }
 
@@ -119,7 +119,7 @@ Glib::ustring WebDavSyncServiceAddin::fuse_mount_directory_error()
 
 std::vector<Glib::ustring> WebDavSyncServiceAddin::get_fuse_mount_exe_args(const Glib::ustring & mountPath, 
bool fromStoredValues)
 {
-  std::string url, username, password;
+  Glib::ustring url, username, password;
   if(fromStoredValues) {
     get_config_settings(url, username, password);
   }
@@ -132,24 +132,8 @@ std::vector<Glib::ustring> WebDavSyncServiceAddin::get_fuse_mount_exe_args(const
 
 Glib::ustring WebDavSyncServiceAddin::get_fuse_mount_exe_args_for_display(const Glib::ustring & mountPath, 
bool fromStoredValues)
 {
-  /*std::string url, username, password;
-  if(fromStoredValues) {
-    get_config_settings(url, username, password);
-  }
-  else {
-    get_pref_widget_settings(url, username, password);
-  }
-  
-  // Mask password
-  std::string acceptSsl;
-  if(accept_ssl_cert()) {
-    acceptSsl = "-ac";
-  }
-
-  return str(boost::format("%1% -a %2% -u %3% -p %4% %5% -o fsname=gnotewdfs")
-             % mountPath % url % username % password % acceptSsl);*/
   std::vector<Glib::ustring> args = get_fuse_mount_exe_args(mountPath, fromStoredValues);
-  std::string result;
+  Glib::ustring result;
   for(auto iter : args) {
     result += iter + " ";
   }
@@ -164,7 +148,7 @@ Glib::ustring WebDavSyncServiceAddin::fuse_mount_exe_name()
 
 bool WebDavSyncServiceAddin::verify_configuration()
 {
-  std::string url, username, password;
+  Glib::ustring url, username, password;
 
   if(!get_pref_widget_settings(url, username, password)) {
     // TODO: Figure out a way to send the error back to the client
@@ -177,7 +161,7 @@ bool WebDavSyncServiceAddin::verify_configuration()
 
 void WebDavSyncServiceAddin::save_configuration_values()
 {
-  std::string url, username, password;
+  Glib::ustring url, username, password;
   get_pref_widget_settings(url, username, password);
 
   save_config_settings(url, username, password);
@@ -190,8 +174,8 @@ void WebDavSyncServiceAddin::reset_configuration_values()
   // TODO: Unmount the FUSE mount!
 }
 
-std::vector<Glib::ustring> WebDavSyncServiceAddin::get_fuse_mount_exe_args(const std::string & mountPath, 
const std::string & url,
-    const std::string & username, const std::string & password, bool acceptSsl)
+std::vector<Glib::ustring> WebDavSyncServiceAddin::get_fuse_mount_exe_args(const Glib::ustring & mountPath, 
const Glib::ustring & url,
+    const Glib::ustring & username, const Glib::ustring & password, bool acceptSsl)
 {
   std::vector<Glib::ustring> args;
   args.reserve(12);
@@ -212,7 +196,7 @@ std::vector<Glib::ustring> WebDavSyncServiceAddin::get_fuse_mount_exe_args(const
   return args;
 }
 
-bool WebDavSyncServiceAddin::get_config_settings(std::string & url, std::string & username, std::string & 
password)
+bool WebDavSyncServiceAddin::get_config_settings(Glib::ustring & url, Glib::ustring & username, 
Glib::ustring & password)
 {
   // Retrieve configuration from the GNOME Keyring and GSettings
   url = "";
@@ -235,7 +219,7 @@ bool WebDavSyncServiceAddin::get_config_settings(std::string & url, std::string
   return url != "" && username != "" && password != "";
 }
 
-void WebDavSyncServiceAddin::save_config_settings(const std::string & url, const std::string & username, 
const std::string & password)
+void WebDavSyncServiceAddin::save_config_settings(const Glib::ustring & url, const Glib::ustring & username, 
const Glib::ustring & password)
 {
   // Save configuration into the GNOME Keyring and GSettings
   try {
@@ -267,7 +251,7 @@ void WebDavSyncServiceAddin::save_config_settings(const std::string & url, const
   }
 }
 
-bool WebDavSyncServiceAddin::get_pref_widget_settings(std::string & url, std::string & username, std::string 
& password)
+bool WebDavSyncServiceAddin::get_pref_widget_settings(Glib::ustring & url, Glib::ustring & username, 
Glib::ustring & password)
 {
   url = sharp::string_trim(m_url_entry->get_text());
   username = sharp::string_trim(m_username_entry->get_text());
@@ -287,7 +271,7 @@ bool WebDavSyncServiceAddin::accept_ssl_cert()
   }
 }
 
-void WebDavSyncServiceAddin::add_row(Gtk::Table *table, Gtk::Widget *widget, const std::string & labelText, 
uint row)
+void WebDavSyncServiceAddin::add_row(Gtk::Table *table, Gtk::Widget *widget, const Glib::ustring & 
labelText, uint row)
 {
   Gtk::Label *l = new Gtk::Label(labelText);
   l->set_use_underline(true);
diff --git a/src/addins/webdavsyncservice/webdavsyncserviceaddin.hpp 
b/src/addins/webdavsyncservice/webdavsyncserviceaddin.hpp
index ac99291..5c2a08a 100644
--- a/src/addins/webdavsyncservice/webdavsyncserviceaddin.hpp
+++ b/src/addins/webdavsyncservice/webdavsyncserviceaddin.hpp
@@ -91,20 +91,20 @@ protected:
   /// </summary>
   virtual void reset_configuration_values() override;
 private:
-  std::vector<Glib::ustring> get_fuse_mount_exe_args(const std::string & mountPath, const std::string & url,
-      const std::string & username, const std::string & password, bool acceptSsl);
-  bool get_config_settings(std::string & url, std::string & username, std::string & password);
-  void save_config_settings(const std::string & url, const std::string & username, const std::string & 
password);
-  bool get_pref_widget_settings(std::string & url, std::string & username, std::string & password);
+  std::vector<Glib::ustring> get_fuse_mount_exe_args(const Glib::ustring & mountPath, const Glib::ustring & 
url,
+      const Glib::ustring & username, const Glib::ustring & password, bool acceptSsl);
+  bool get_config_settings(Glib::ustring & url, Glib::ustring & username, Glib::ustring & password);
+  void save_config_settings(const Glib::ustring & url, const Glib::ustring & username, const Glib::ustring & 
password);
+  bool get_pref_widget_settings(Glib::ustring & url, Glib::ustring & username, Glib::ustring & password);
   bool accept_ssl_cert();
-  void add_row(Gtk::Table *table, Gtk::Widget *widget, const std::string & labelText, uint row);
+  void add_row(Gtk::Table *table, Gtk::Widget *widget, const Glib::ustring & labelText, uint row);
 
   Gtk::Entry *m_url_entry;
   Gtk::Entry *m_username_entry;
   Gtk::Entry *m_password_entry;
 
   static const char *KEYRING_ITEM_NAME;
-  static std::map<std::string, std::string> s_request_attributes;
+  static std::map<Glib::ustring, Glib::ustring> s_request_attributes;
 };
 
 }
diff --git a/src/gnome_keyring/ring.cpp b/src/gnome_keyring/ring.cpp
index 277a1da..154e0fa 100644
--- a/src/gnome_keyring/ring.cpp
+++ b/src/gnome_keyring/ring.cpp
@@ -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
@@ -44,7 +44,7 @@ SecretSchema Ring::s_schema = {
 #pragma GCC diagnostic pop
 
 
-std::string Ring::find_password(const std::map<std::string, std::string> & atts)
+Glib::ustring Ring::find_password(const std::map<Glib::ustring, Glib::ustring> & atts)
 {
   GHashTable *attributes = keyring_attributes(atts);
   GError *error = NULL;
@@ -56,7 +56,7 @@ std::string Ring::find_password(const std::map<std::string, std::string> & atts)
     throw e;
   }
 
-  std::string res;
+  Glib::ustring res;
   if(result) {
     res = result;
     secret_password_free(result);
@@ -64,14 +64,14 @@ std::string Ring::find_password(const std::map<std::string, std::string> & atts)
   return res;
 }
 
-std::string Ring::default_keyring()
+Glib::ustring Ring::default_keyring()
 {
   return SECRET_COLLECTION_DEFAULT;
 }
 
-void Ring::create_password(const std::string & keyring, const std::string & displayName,
-                          const std::map<std::string, std::string> & attributes,
-                          const std::string & secret)
+void Ring::create_password(const Glib::ustring & keyring, const Glib::ustring & displayName,
+                          const std::map<Glib::ustring, Glib::ustring> & attributes,
+                          const Glib::ustring & secret)
 {
   GHashTable *atts = keyring_attributes(attributes);
   GError *error = NULL;
@@ -85,7 +85,7 @@ void Ring::create_password(const std::string & keyring, const std::string & disp
   }
 }
 
-void Ring::clear_password(const std::map<std::string, std::string> & attributes)
+void Ring::clear_password(const std::map<Glib::ustring, Glib::ustring> & attributes)
 {
   GHashTable *atts = keyring_attributes(attributes);
   GError *error = NULL;
@@ -98,12 +98,11 @@ void Ring::clear_password(const std::map<std::string, std::string> & attributes)
   }
 }
 
-GHashTable *Ring::keyring_attributes(const std::map<std::string, std::string> & atts)
+GHashTable *Ring::keyring_attributes(const std::map<Glib::ustring, Glib::ustring> & atts)
 {
   GHashTable *result = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
-  for(std::map<std::string, std::string>::const_iterator iter = atts.begin();
-      iter != atts.end(); ++iter) {
-    g_hash_table_insert(result, strdup(iter->first.c_str()), strdup(iter->second.c_str()));
+  for(auto attribute : atts) {
+    g_hash_table_insert(result, strdup(attribute.first.c_str()), strdup(attribute.second.c_str()));
   }
   return result;
 }
diff --git a/src/gnome_keyring/ring.hpp b/src/gnome_keyring/ring.hpp
index 4995200..11327fa 100644
--- a/src/gnome_keyring/ring.hpp
+++ b/src/gnome_keyring/ring.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012,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
@@ -24,6 +24,7 @@
 #include <vector>
 #include <map>
 
+#include <glibmm/ustring.h>
 #include <libsecret/secret.h>
 
 
@@ -34,14 +35,14 @@ namespace keyring {
 class Ring
 {
 public:
-  static std::string find_password(const std::map<std::string, std::string> & atts);
-  static std::string default_keyring();
-  static void create_password(const std::string & keyring, const std::string & displayName,
-                              const std::map<std::string, std::string> & attributes,
-                              const std::string & secret);
-  static void clear_password(const std::map<std::string, std::string> & attributes);
+  static Glib::ustring find_password(const std::map<Glib::ustring, Glib::ustring> & atts);
+  static Glib::ustring default_keyring();
+  static void create_password(const Glib::ustring & keyring, const Glib::ustring & displayName,
+                              const std::map<Glib::ustring, Glib::ustring> & attributes,
+                              const Glib::ustring & secret);
+  static void clear_password(const std::map<Glib::ustring, Glib::ustring> & attributes);
 private:
-  static GHashTable *keyring_attributes(const std::map<std::string, std::string> & atts);
+  static GHashTable *keyring_attributes(const std::map<Glib::ustring, Glib::ustring> & atts);
 
   static SecretSchema s_schema;
 };


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