[gnote/gdrive: 49/50] Add GVFS sync addin
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote/gdrive: 49/50] Add GVFS sync addin
- Date: Sat, 6 Apr 2019 16:54:49 +0000 (UTC)
commit 5a3f34d597289a373240b62bf4182d4d136b761e
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sat Apr 6 19:50:45 2019 +0300
Add GVFS sync addin
configure.ac | 2 +
data/org.gnome.gnote.gschema.xml.in | 8 +
src/addins/Makefile.am | 1 +
src/addins/gvfssyncservice/Makefile.am | 18 ++
.../gvfssyncservice/gvfssyncservice.desktop.in.in | 11 +
.../gvfssyncservice/gvfssyncserviceaddin.cpp | 237 +++++++++++++++++++++
.../gvfssyncservice/gvfssyncserviceaddin.hpp | 76 +++++++
src/preferences.cpp | 5 +-
src/preferences.hpp | 5 +-
9 files changed, 361 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a9d99caa..4d503637 100644
--- a/configure.ac
+++ b/configure.ac
@@ -164,6 +164,8 @@ src/addins/filesystemsyncservice/Makefile
src/addins/filesystemsyncservice/filesystemsyncservice.desktop.in
src/addins/fixedwidth/Makefile
src/addins/fixedwidth/fixedwidth.desktop.in
+src/addins/gvfssyncservice/Makefile
+src/addins/gvfssyncservice/gvfssyncservice.desktop.in
src/addins/inserttimestamp/Makefile
src/addins/inserttimestamp/inserttimestamp.desktop.in
src/addins/notedirectorywatcher/Makefile
diff --git a/data/org.gnome.gnote.gschema.xml.in b/data/org.gnome.gnote.gschema.xml.in
index d0ec7d16..ad6d63f3 100644
--- a/data/org.gnome.gnote.gschema.xml.in
+++ b/data/org.gnome.gnote.gschema.xml.in
@@ -144,6 +144,7 @@
<child name="global-keybindings" schema="org.gnome.gnote.global-keybindings" />
<child name="export-html" schema="org.gnome.gnote.export-html" />
<child name="sync" schema="org.gnome.gnote.sync" />
+ <child name="sync-gvfs" schema="org.gnome.gnote.sync.gvfs" />
<child name="insert-timestamp" schema="org.gnome.gnote.insert-timestamp" />
<child name="note-directory-watcher" schema="org.gnome.gnote.note-directory-watcher" />
</schema>
@@ -219,6 +220,13 @@
</key>
<child name="wdfs" schema="org.gnome.gnote.sync.wdfs" />
</schema>
+ <schema id="org.gnome.gnote.sync.gvfs" path="/org/gnome/gnote/sync/gvfs/">
+ <key name="uri" type="s">
+ <default>''</default>
+ <_summary>Online directory URI</_summary>
+ <_description>URI to online directory where notes are synchronized to.</_description>
+ </key>
+ </schema>
<schema id="org.gnome.gnote.sync.wdfs" path="/org/gnome/gnote/sync/wdfs/">
<key name="accept-sslcert" type="b">
<default>false</default>
diff --git a/src/addins/Makefile.am b/src/addins/Makefile.am
index c7d00ce2..544c3695 100644
--- a/src/addins/Makefile.am
+++ b/src/addins/Makefile.am
@@ -7,6 +7,7 @@ SUBDIRS = backlinks \
exporttohtml \
filesystemsyncservice \
fixedwidth \
+ gvfssyncservice \
inserttimestamp \
notedirectorywatcher \
noteoftheday \
diff --git a/src/addins/gvfssyncservice/Makefile.am b/src/addins/gvfssyncservice/Makefile.am
new file mode 100644
index 00000000..73ded188
--- /dev/null
+++ b/src/addins/gvfssyncservice/Makefile.am
@@ -0,0 +1,18 @@
+
+include $(builddir)/../addins.mk
+
+@INTLTOOL_DESKTOP_RULE@
+
+desktop_in_files = gvfssyncservice.desktop.in
+desktop_files = $(desktop_in_files:.desktop.in=.desktop)
+
+addinsdir = $(ADDINSDIR)
+addins_LTLIBRARIES = libgvfssyncservice.la
+addins_DATA = $(desktop_files)
+
+
+libgvfssyncservice_la_SOURCES = gvfssyncserviceaddin.hpp gvfssyncserviceaddin.cpp \
+ $(NULL)
+
+EXTRA_DIST = $(desktop_in_files)
+DISTCLEANFILES = $(desktop_files)
diff --git a/src/addins/gvfssyncservice/gvfssyncservice.desktop.in.in
b/src/addins/gvfssyncservice/gvfssyncservice.desktop.in.in
new file mode 100644
index 00000000..b31fb589
--- /dev/null
+++ b/src/addins/gvfssyncservice/gvfssyncservice.desktop.in.in
@@ -0,0 +1,11 @@
+[AddinInfo]
+Id=GvfsSyncServiceAddin
+_Name=Online Directory Sync Service Plugin
+_Description=Synchronize Gnote Notes to an online directory
+_Authors=Aurimas Černius
+Category=Synchronization
+Version=0.1
+DefaultEnabled=true
+Module=libgvfssyncservice
+LibgnoteRelease=@LIBGNOTE_RELEASE@
+LibgnoteVersionInfo=@LIBGNOTE_VERSION_INFO@
diff --git a/src/addins/gvfssyncservice/gvfssyncserviceaddin.cpp
b/src/addins/gvfssyncservice/gvfssyncserviceaddin.cpp
new file mode 100644
index 00000000..84b9dee4
--- /dev/null
+++ b/src/addins/gvfssyncservice/gvfssyncserviceaddin.cpp
@@ -0,0 +1,237 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <glibmm/i18n.h>
+#include <glibmm/miscutils.h>
+#include <gtkmm/entry.h>
+#include <gtkmm/label.h>
+#include <gtkmm/table.h>
+
+#include "debug.hpp"
+#include "gvfssyncserviceaddin.hpp"
+#include "preferences.hpp"
+#include "sharp/directory.hpp"
+#include "sharp/files.hpp"
+#include "synchronization/filesystemsyncserver.hpp"
+
+
+namespace gvfssyncservice {
+
+GvfsSyncServiceModule::GvfsSyncServiceModule()
+{
+ ADD_INTERFACE_IMPL(GvfsSyncServiceAddin);
+}
+
+
+
+
+GvfsSyncServiceAddin::GvfsSyncServiceAddin()
+ : m_uri_entry(nullptr)
+ , m_initialized(false)
+ , m_enabled(false)
+{
+}
+
+void GvfsSyncServiceAddin::initialize()
+{
+ m_initialized = true;
+ m_enabled = true;
+}
+
+void GvfsSyncServiceAddin::shutdown()
+{
+ m_enabled = false;
+}
+
+gnote::sync::SyncServer::Ptr GvfsSyncServiceAddin::create_sync_server()
+{
+ gnote::sync::SyncServer::Ptr server;
+
+ Glib::ustring sync_uri;
+ if(get_config_settings(sync_uri)) {
+ m_uri = sync_uri;
+ if(sharp::directory_exists(m_uri) == false) {
+ sharp::directory_create(m_uri);
+ }
+
+ auto path = Gio::File::create_for_uri(m_uri);
+ server = gnote::sync::FileSystemSyncServer::create(path);
+ }
+ else {
+ throw std::logic_error("GvfsSyncServiceAddin.create_sync_server() called without being configured");
+ }
+
+ return server;
+}
+
+
+void GvfsSyncServiceAddin::post_sync_cleanup()
+{
+ // Nothing to do
+}
+
+
+Gtk::Widget *GvfsSyncServiceAddin::create_preferences_control(EventHandler required_pref_changed)
+{
+ Gtk::Table *table = manage(new Gtk::Table(1, 1, false));
+ table->set_row_spacings(5);
+ table->set_col_spacings(10);
+
+ // Read settings out of gconf
+ Glib::ustring sync_path;
+ if(get_config_settings(sync_path) == false) {
+ sync_path = "";
+ }
+
+ auto l = manage(new Gtk::Label(_("_Folder Path:"), true));
+ l->property_xalign() = 1;
+ table->attach(*l, 0, 1, 0, 1,
+ Gtk::FILL,
+ Gtk::EXPAND | Gtk::FILL,
+ 0, 0);
+
+ m_uri_entry = manage(new Gtk::Entry);
+ m_uri_entry->get_buffer()->signal_inserted_text().connect([required_pref_changed](guint, const gchar*,
guint) { required_pref_changed(); });
+ m_uri_entry->get_buffer()->signal_deleted_text().connect([required_pref_changed](guint, guint) {
required_pref_changed(); });
+ l->set_mnemonic_widget(*m_uri_entry);
+
+ table->attach(*m_uri_entry, 1, 2, 0, 1,
+ Gtk::EXPAND | Gtk::FILL,
+ Gtk::EXPAND | Gtk::FILL,
+ 0, 0);
+
+ table->set_hexpand(true);
+ table->set_vexpand(false);
+ table->show_all();
+ return table;
+}
+
+
+bool GvfsSyncServiceAddin::save_configuration()
+{
+ Glib::ustring sync_uri = m_uri_entry->get_text();
+
+ if(sync_uri == "") {
+ ERR_OUT(_("The URI is empty"));
+ throw gnote::sync::GnoteSyncException(_("URI field is empty."));
+ }
+
+ auto path = Gio::File::create_for_uri(sync_uri);
+ if(sharp::directory_exists(path) == false) {
+ if(!sharp::directory_create(path)) {
+ DBG_OUT("Could not create \"%s\"", sync_uri.c_str());
+ throw gnote::sync::GnoteSyncException(_("Specified folder path does not exist, and Gnote was unable to
create it."));
+ }
+ }
+ else {
+ // Test creating/writing/deleting a file
+ Glib::ustring test_path_base = Glib::build_filename(sync_uri, "test");
+ Glib::ustring test_path = test_path_base;
+ int count = 0;
+
+ // Get unique new file name
+ while(sharp::file_exists(test_path)) {
+ test_path = test_path_base + TO_STRING(++count);
+ }
+
+ // Test ability to create and write
+ Glib::ustring test_line = "Testing write capabilities.";
+ sharp::file_write_all_text(test_path, test_line);
+
+ // Test ability to read
+ bool test_file_found = false;
+ std::vector<Glib::RefPtr<Gio::File>> files;
+ sharp::directory_get_files(path, files);
+ for(auto & file : files) {
+ if(file->get_uri() == test_path) {
+ test_file_found = true;
+ break;
+ }
+ }
+ if(!test_file_found) {
+ throw sharp::Exception("Failure writing test file");
+ }
+ Glib::ustring line = sharp::file_read_all_text(test_path);
+ if(line != test_line) {
+ throw sharp::Exception("Failure when checking test file contents");
+ }
+
+ // Test ability to delete
+ sharp::file_delete(test_path);
+ }
+
+ m_uri = sync_uri;
+
+ // TODO: Try to create and delete a file. If it fails, this should fail
+ gnote::Preferences::obj().get_schema_settings(
+ gnote::Preferences::SCHEMA_SYNC_GVFS)->set_string(gnote::Preferences::SYNC_GVFS_URI, m_uri);
+
+ return true;
+}
+
+
+void GvfsSyncServiceAddin::reset_configuration()
+{
+ gnote::Preferences::obj().get_schema_settings(
+ gnote::Preferences::SCHEMA_SYNC_GVFS)->set_string(gnote::Preferences::SYNC_GVFS_URI, "");
+}
+
+
+bool GvfsSyncServiceAddin::is_configured()
+{
+ return gnote::Preferences::obj().get_schema_settings(
+ gnote::Preferences::SCHEMA_SYNC_GVFS)->get_string(gnote::Preferences::SYNC_GVFS_URI) != "";
+}
+
+
+Glib::ustring GvfsSyncServiceAddin::name()
+{
+ char *res = _("Online Folder");
+ return res ? res : "";
+}
+
+
+Glib::ustring GvfsSyncServiceAddin::id()
+{
+ return "gvfs";
+}
+
+
+bool GvfsSyncServiceAddin::is_supported()
+{
+ return true;
+}
+
+
+bool GvfsSyncServiceAddin::initialized()
+{
+ return m_initialized && m_enabled;
+}
+
+
+bool GvfsSyncServiceAddin::get_config_settings(Glib::ustring & sync_path)
+{
+ sync_path = gnote::Preferences::obj().get_schema_settings(
+ gnote::Preferences::SCHEMA_SYNC_GVFS)->get_string(gnote::Preferences::SYNC_GVFS_URI);
+
+ return sync_path != "";
+}
+
+}
diff --git a/src/addins/gvfssyncservice/gvfssyncserviceaddin.hpp
b/src/addins/gvfssyncservice/gvfssyncserviceaddin.hpp
new file mode 100644
index 00000000..8a97f13e
--- /dev/null
+++ b/src/addins/gvfssyncservice/gvfssyncserviceaddin.hpp
@@ -0,0 +1,76 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GVFS_SYNC_SERVICE_ADDIN_
+#define _GVFS_SYNC_SERVICE_ADDIN_
+
+#include "sharp/dynamicmodule.hpp"
+#include "synchronization/syncserviceaddin.hpp"
+
+
+
+namespace gvfssyncservice {
+
+class GvfsSyncServiceModule
+ : public sharp::DynamicModule
+{
+public:
+ GvfsSyncServiceModule();
+};
+
+
+DECLARE_MODULE(GvfsSyncServiceModule)
+
+
+class GvfsSyncServiceAddin
+ : public gnote::sync::SyncServiceAddin
+{
+public:
+ static GvfsSyncServiceAddin *create()
+ {
+ return new GvfsSyncServiceAddin;
+ }
+ GvfsSyncServiceAddin();
+
+ virtual void initialize() override;
+ virtual void shutdown() override;
+
+ virtual gnote::sync::SyncServer::Ptr create_sync_server() override;
+ virtual void post_sync_cleanup() override;
+ virtual Gtk::Widget *create_preferences_control(EventHandler requiredPrefChanged) override;
+ virtual bool save_configuration() override;
+ virtual void reset_configuration() override;
+ virtual bool is_configured() override;
+ virtual Glib::ustring name() override;
+ virtual Glib::ustring id() override;
+ virtual bool is_supported() override;
+ virtual bool initialized() override;
+private:
+ bool get_config_settings(Glib::ustring & sync_path);
+
+ Glib::ustring m_uri;
+ Gtk::Entry *m_uri_entry;
+ bool m_initialized;
+ bool m_enabled;
+};
+
+}
+
+#endif
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 6bc5baf1..7de910f7 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011-2015,2017 Aurimas Cernius
+ * Copyright (C) 2011-2015,2017,2019 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -30,6 +30,7 @@ namespace gnote {
const char * Preferences::SCHEMA_GNOTE = "org.gnome.gnote";
const char * Preferences::SCHEMA_KEYBINDINGS = "org.gnome.gnote.global-keybindings";
const char * Preferences::SCHEMA_SYNC = "org.gnome.gnote.sync";
+ const char * Preferences::SCHEMA_SYNC_GVFS = "org.gnome.gnote.sync.gvfs";
const char * Preferences::SCHEMA_SYNC_WDFS = "org.gnome.gnote.sync.wdfs";
const char * Preferences::SCHEMA_DESKTOP_GNOME_INTERFACE = "org.gnome.desktop.interface";
@@ -72,6 +73,8 @@ namespace gnote {
const char * Preferences::SEARCH_WINDOW_SPLITTER_POS = "search-window-splitter-pos";
const char * Preferences::SEARCH_SORTING = "search-sorting";
+ const char * Preferences::SYNC_GVFS_URI = "uri";
+
const char * Preferences::SYNC_FUSE_MOUNT_TIMEOUT = "sync-fuse-mount-timeout-ms";
const char * Preferences::SYNC_FUSE_WDFS_ACCEPT_SSLCERT = "accept-sslcert";
const char * Preferences::SYNC_FUSE_WDFS_URL = "url";
diff --git a/src/preferences.hpp b/src/preferences.hpp
index a2707bed..c0b4a81c 100644
--- a/src/preferences.hpp
+++ b/src/preferences.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011-2015,2017 Aurimas Cernius
+ * Copyright (C) 2011-2015,2017,2019 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -39,6 +39,7 @@ namespace gnote {
static const char *SCHEMA_GNOTE;
static const char *SCHEMA_KEYBINDINGS;
static const char *SCHEMA_SYNC;
+ static const char *SCHEMA_SYNC_GVFS;
static const char *SCHEMA_SYNC_WDFS;
static const char *SCHEMA_DESKTOP_GNOME_INTERFACE;
@@ -81,6 +82,8 @@ namespace gnote {
static const char *SYNC_CONFIGURED_CONFLICT_BEHAVIOR;
static const char *SYNC_AUTOSYNC_TIMEOUT;
+ static const char *SYNC_GVFS_URI;
+
static const char *SYNC_FUSE_MOUNT_TIMEOUT;
static const char *SYNC_FUSE_WDFS_ACCEPT_SSLCERT;
static const char *SYNC_FUSE_WDFS_URL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]