diff --git a/plugins/share/Instapaper/CMakeLists.txt b/plugins/share/Instapaper/CMakeLists.txt index 201d8510c..1eaabe90b 100644 --- a/plugins/share/Instapaper/CMakeLists.txt +++ b/plugins/share/Instapaper/CMakeLists.txt @@ -37,4 +37,5 @@ add_dependencies(${NAME} ${UI_NAME} ${DAEMON_NAME}) install(TARGETS ${NAME} DESTINATION ${PKGLIBDIR}/pluginsShare) install(FILES ${NAME}.plugin DESTINATION ${PKGLIBDIR}/pluginsShare) +add_schema ("org.gnome.feedreader.share.instapaper.gschema.xml") diff --git a/plugins/share/Instapaper/InstapaperAPI.vala b/plugins/share/Instapaper/InstapaperAPI.vala index c48cb4914..669affaa4 100644 --- a/plugins/share/Instapaper/InstapaperAPI.vala +++ b/plugins/share/Instapaper/InstapaperAPI.vala @@ -128,9 +128,9 @@ public class FeedReader.InstaAPI : ShareAccountInterface, Peas.ExtensionBase { settings.set_string("username", username); settings.set_string("user-id", userID); - var array = Settings.share().get_strv("instapaper"); + var array = Settings.share("instapaper").get_strv("account-ids"); array += id; - Settings.share().set_strv("instapaper", array); + Settings.share("instapaper").set_strv("account-ids", array); var pwSchema = new Secret.Schema ("org.gnome.feedreader.instapaper.password", Secret.SchemaFlags.NONE, "userID", Secret.SchemaAttributeType.STRING); @@ -223,7 +223,7 @@ public class FeedReader.InstaAPI : ShareAccountInterface, Peas.ExtensionBase { settings.reset(key); } - var array = Settings.share().get_strv("instapaper"); + var array = Settings.share("instapaper").get_strv("account-ids"); string[] array2 = {}; foreach(string i in array) @@ -231,7 +231,7 @@ public class FeedReader.InstaAPI : ShareAccountInterface, Peas.ExtensionBase { if(i != id) array2 += i; } - Settings.share().set_strv("instapaper", array2); + Settings.share("instapaper").set_strv("account-ids", array2); deleteAccount(id); return true; diff --git a/plugins/share/Instapaper/InstapaperSetup.vala b/plugins/share/Instapaper/InstapaperSetup.vala index 0812d994f..874e0f398 100644 --- a/plugins/share/Instapaper/InstapaperSetup.vala +++ b/plugins/share/Instapaper/InstapaperSetup.vala @@ -77,7 +77,7 @@ public class FeedReader.InstapaperSetup : ServiceSetup { { m_spinner.start(); m_iconStack.set_visible_child_name("spinner"); - string id = Share.generateNewID(); + string id = Share.get_default().generateNewID(); string username = m_userEntry.get_text(); string password = m_passEntry.get_text(); diff --git a/plugins/share/Instapaper/org.gnome.feedreader.share.instapaper.gschema.xml b/plugins/share/Instapaper/org.gnome.feedreader.share.instapaper.gschema.xml new file mode 100644 index 000000000..4a559cf57 --- /dev/null +++ b/plugins/share/Instapaper/org.gnome.feedreader.share.instapaper.gschema.xml @@ -0,0 +1,13 @@ + + + + + [] + instapaper accounts + + all the instapaper account ids + + + + + diff --git a/plugins/share/Pocket/CMakeLists.txt b/plugins/share/Pocket/CMakeLists.txt index d339b2d96..684e099aa 100644 --- a/plugins/share/Pocket/CMakeLists.txt +++ b/plugins/share/Pocket/CMakeLists.txt @@ -43,4 +43,5 @@ add_dependencies(${NAME} ${UI_NAME} ${DAEMON_NAME}) install(TARGETS ${NAME} DESTINATION ${PKGLIBDIR}/pluginsShare) install(FILES ${NAME}.plugin DESTINATION ${PKGLIBDIR}/pluginsShare) +add_schema ("org.gnome.feedreader.share.pocket.gschema.xml") diff --git a/plugins/share/Pocket/PocketAPI.vala b/plugins/share/Pocket/PocketAPI.vala index aad5c16fb..e3b11f1eb 100644 --- a/plugins/share/Pocket/PocketAPI.vala +++ b/plugins/share/Pocket/PocketAPI.vala @@ -112,9 +112,9 @@ public class FeedReader.PocketAPI : ShareAccountInterface, Peas.ExtensionBase { settings.set_string("oauth-access-token", accessToken); settings.set_string("username", user); - var array = Settings.share().get_strv("pocket"); + var array = Settings.share("pocket").get_strv("account-ids"); array += id; - Settings.share().set_strv("pocket", array); + Settings.share("pocket").set_strv("account-ids", array); return true; } @@ -194,7 +194,7 @@ public class FeedReader.PocketAPI : ShareAccountInterface, Peas.ExtensionBase { settings.reset(key); } - var array = Settings.share().get_strv("pocket"); + var array = Settings.share("pocket").get_strv("account-ids"); string[] array2 = {}; foreach(string i in array) @@ -202,7 +202,7 @@ public class FeedReader.PocketAPI : ShareAccountInterface, Peas.ExtensionBase { if(i != id) array2 += i; } - Settings.share().set_strv("pocket", array2); + Settings.share("pocket").set_strv("account-ids", array2); deleteAccount(id); return true; diff --git a/plugins/share/Pocket/PocketSetup.vala b/plugins/share/Pocket/PocketSetup.vala index 04c0cf966..fd931178c 100644 --- a/plugins/share/Pocket/PocketSetup.vala +++ b/plugins/share/Pocket/PocketSetup.vala @@ -34,7 +34,7 @@ public class FeedReader.PocketSetup : ServiceSetup { public override void login() { - string id = Share.generateNewID(); + string id = Share.get_default().generateNewID(); string requestToken = m_api.getRequestToken(); string url = m_api.getURL(requestToken); m_spinner.start(); diff --git a/plugins/share/Pocket/org.gnome.feedreader.share.pocket.gschema.xml b/plugins/share/Pocket/org.gnome.feedreader.share.pocket.gschema.xml new file mode 100644 index 000000000..230652463 --- /dev/null +++ b/plugins/share/Pocket/org.gnome.feedreader.share.pocket.gschema.xml @@ -0,0 +1,13 @@ + + + + + [] + pocket accounts + + all the pocket account ids + + + + + diff --git a/plugins/share/Telegram/CMakeLists.txt b/plugins/share/Telegram/CMakeLists.txt index 709a0cdb9..9046020f7 100644 --- a/plugins/share/Telegram/CMakeLists.txt +++ b/plugins/share/Telegram/CMakeLists.txt @@ -36,4 +36,5 @@ add_dependencies(${NAME} ${UI_NAME} ${DAEMON_NAME}) install(TARGETS ${NAME} DESTINATION ${PKGLIBDIR}/pluginsShare) install(FILES ${NAME}.plugin DESTINATION ${PKGLIBDIR}/pluginsShare) +add_schema ("org.gnome.feedreader.share.telegram.gschema.xml") diff --git a/plugins/share/Telegram/Telegram.vala b/plugins/share/Telegram/Telegram.vala index 4eb64fc35..138e78efd 100644 --- a/plugins/share/Telegram/Telegram.vala +++ b/plugins/share/Telegram/Telegram.vala @@ -20,9 +20,9 @@ public class FeedReader.Telegram : ShareAccountInterface, Peas.ExtensionBase { public bool addTelegram(string id, string username) { - var settings = new GLib.Settings.with_path("org.gnome.feedreader.share.account", "/org/gnome/feedreader/share/telegram/%s/".printf(id)); + var settings = new GLib.Settings.with_path("org.gnome.feedreader.share.account", "/org/gnome/feedreader/share/telegram/%s/".printf(id)); settings.set_string("username", username); - var array = Settings.share().get_strv("telegram"); + var array = Settings.share("telegram").get_strv("account-ids"); foreach(string i in array) { if(i == id) @@ -31,8 +31,9 @@ public class FeedReader.Telegram : ShareAccountInterface, Peas.ExtensionBase { return false; } } - array += id; - Settings.share().set_strv("telegram", array); + + array += id; + Settings.share("telegram").set_strv("account-ids", array); return true; } @@ -62,29 +63,29 @@ public class FeedReader.Telegram : ShareAccountInterface, Peas.ExtensionBase { { Logger.debug(@"Telegram.remove($id)"); var settings = new GLib.Settings.with_path("org.gnome.feedreader.share.account", "/org/gnome/feedreader/share/telegram/%s/".printf(id)); - var keys = settings.list_keys(); + var keys = settings.list_keys(); foreach(string key in keys) { settings.reset(key); } - var array = Settings.share().get_strv("telegram"); - string[] array2 = {}; + var array = Settings.share("telegram").get_strv("account-ids"); + string[] array2 = {}; - foreach(string i in array) + foreach(string i in array) { if(i != id) array2 += i; } - Settings.share().set_strv("telegram", array2); + Settings.share("telegram").set_strv("account-ids", array2); deleteAccount(id); return true; } public string getIconName() - { - return "feed-share-telegram"; - } + { + return "feed-share-telegram"; + } public string getUsername(string id) { @@ -97,14 +98,14 @@ public class FeedReader.Telegram : ShareAccountInterface, Peas.ExtensionBase { } public bool useSystemAccounts() - { - return false; - } + { + return false; + } public string pluginID() - { - return "telegram"; - } + { + return "telegram"; + } public string pluginName() { @@ -112,14 +113,14 @@ public class FeedReader.Telegram : ShareAccountInterface, Peas.ExtensionBase { } public ServiceSetup? newSetup_withID(string id, string username) - { - return new TelegramSetup(id, this, username); - } - - public ServiceSetup? newSetup() - { - return new TelegramSetup(null, this); - } + { + return new TelegramSetup(id, this, username); + } + + public ServiceSetup? newSetup() + { + return new TelegramSetup(null, this); + } public ServiceSetup? newSystemAccount(string id, string username) { diff --git a/plugins/share/Telegram/TelegramForm.vala b/plugins/share/Telegram/TelegramForm.vala index 657575c6e..98e6d4b8f 100644 --- a/plugins/share/Telegram/TelegramForm.vala +++ b/plugins/share/Telegram/TelegramForm.vala @@ -16,7 +16,6 @@ public class FeedReader.TelegramForm : ShareForm { - private Gtk.Entry m_entry; private Gtk.TextView m_textView; public TelegramForm() diff --git a/plugins/share/Telegram/TelegramSetup.vala b/plugins/share/Telegram/TelegramSetup.vala index 2893527ed..dd5c46478 100644 --- a/plugins/share/Telegram/TelegramSetup.vala +++ b/plugins/share/Telegram/TelegramSetup.vala @@ -24,7 +24,7 @@ public class FeedReader.TelegramSetup : ServiceSetup { loggedIN = true; base("Telegram", "feed-share-telegram", loggedIN, username); - + m_tg = tg; //no login, so change the labels m_login_button.set_label(_("Add")); @@ -37,7 +37,7 @@ public class FeedReader.TelegramSetup : ServiceSetup { public override void login() { - showInfoBar(_("Telegram needs to be installed on your system!.")); + showInfoBar(_("Telegram needs to be installed on your system.")); //use static id to determin if already added string id = "X-URL-SCHEME-TELEGRAM"; string username = m_tg.getUsername(id); diff --git a/plugins/share/Telegram/org.gnome.feedreader.share.telegram.gschema.xml b/plugins/share/Telegram/org.gnome.feedreader.share.telegram.gschema.xml new file mode 100644 index 000000000..a0107dc23 --- /dev/null +++ b/plugins/share/Telegram/org.gnome.feedreader.share.telegram.gschema.xml @@ -0,0 +1,13 @@ + + + + + [] + Telegram accounts + + all the telegram account ids + + + + + diff --git a/plugins/share/Twitter/CMakeLists.txt b/plugins/share/Twitter/CMakeLists.txt index 344aa0847..6f5ef3732 100644 --- a/plugins/share/Twitter/CMakeLists.txt +++ b/plugins/share/Twitter/CMakeLists.txt @@ -38,4 +38,5 @@ add_dependencies(${NAME} ${UI_NAME} ${DAEMON_NAME}) install(TARGETS ${NAME} DESTINATION ${PKGLIBDIR}/pluginsShare) install(FILES ${NAME}.plugin DESTINATION ${PKGLIBDIR}/pluginsShare) +add_schema ("org.gnome.feedreader.share.twitter.gschema.xml") diff --git a/plugins/share/Twitter/TwitterAPI.vala b/plugins/share/Twitter/TwitterAPI.vala index 1909515c7..542932fa8 100644 --- a/plugins/share/Twitter/TwitterAPI.vala +++ b/plugins/share/Twitter/TwitterAPI.vala @@ -116,9 +116,9 @@ public class FeedReader.TwitterAPI : ShareAccountInterface, Peas.ExtensionBase { - var array = Settings.share().get_strv("twitter"); + var array = Settings.share("twitter").get_strv("account-ids"); array += id; - Settings.share().set_strv("twitter", array); + Settings.share("twitter").set_strv("account-ids", array); return true; } @@ -165,7 +165,7 @@ public class FeedReader.TwitterAPI : ShareAccountInterface, Peas.ExtensionBase { settings.reset(key); } - var array = Settings.share().get_strv("twitter"); + var array = Settings.share("twitter").get_strv("account-ids"); string[] array2 = {}; foreach(string i in array) @@ -173,7 +173,7 @@ public class FeedReader.TwitterAPI : ShareAccountInterface, Peas.ExtensionBase { if(i != id) array2 += i; } - Settings.share().set_strv("twitter", array2); + Settings.share("twitter").set_strv("account-ids", array2); deleteAccount(id); return true; @@ -250,7 +250,7 @@ public class FeedReader.TwitterAPI : ShareAccountInterface, Peas.ExtensionBase { if(m_urlLength > 0) return m_urlLength; - var array = Settings.share().get_strv("twitter"); + var array = Settings.share("twitter").get_strv("account-ids"); string id = array[0]; var settings = new GLib.Settings.with_path("org.gnome.feedreader.share.account", "/org/gnome/feedreader/share/twitter/%s/".printf(id)); diff --git a/plugins/share/Twitter/TwitterSetup.vala b/plugins/share/Twitter/TwitterSetup.vala index 715009101..e8314bb82 100644 --- a/plugins/share/Twitter/TwitterSetup.vala +++ b/plugins/share/Twitter/TwitterSetup.vala @@ -34,7 +34,7 @@ public class FeedReader.TwitterSetup : ServiceSetup { public override void login() { - string id = Share.generateNewID(); + string id = Share.get_default().generateNewID(); string requestToken = m_api.getRequestToken(); string url = m_api.getURL(requestToken); m_spinner.start(); diff --git a/plugins/share/Twitter/org.gnome.feedreader.share.twitter.gschema.xml b/plugins/share/Twitter/org.gnome.feedreader.share.twitter.gschema.xml new file mode 100644 index 000000000..0ffab7e67 --- /dev/null +++ b/plugins/share/Twitter/org.gnome.feedreader.share.twitter.gschema.xml @@ -0,0 +1,13 @@ + + + + + [] + twitter accounts + + all the twitter account ids + + + + + diff --git a/plugins/share/Wallabag/CMakeLists.txt b/plugins/share/Wallabag/CMakeLists.txt index d073db048..1150e04a1 100644 --- a/plugins/share/Wallabag/CMakeLists.txt +++ b/plugins/share/Wallabag/CMakeLists.txt @@ -37,4 +37,5 @@ add_dependencies(${NAME} ${UI_NAME} ${DAEMON_NAME}) install(TARGETS ${NAME} DESTINATION ${PKGLIBDIR}/pluginsShare) install(FILES ${NAME}.plugin DESTINATION ${PKGLIBDIR}/pluginsShare) +add_schema ("org.gnome.feedreader.share.wallabag.gschema.xml") diff --git a/plugins/share/Wallabag/WallabagAPI.vala b/plugins/share/Wallabag/WallabagAPI.vala index 87d2bd057..6b2622999 100644 --- a/plugins/share/Wallabag/WallabagAPI.vala +++ b/plugins/share/Wallabag/WallabagAPI.vala @@ -95,7 +95,7 @@ public class FeedReader.WallabagAPI : ShareAccountInterface, Peas.ExtensionBase settings.set_string("client-secret", clientSecret); - var array = Settings.share().get_strv("wallabag"); + var array = Settings.share("wallabag").get_strv("wallabag"); foreach(string i in array) { if(i == id) @@ -105,7 +105,7 @@ public class FeedReader.WallabagAPI : ShareAccountInterface, Peas.ExtensionBase } } array += id; - Settings.share().set_strv("wallabag", array); + Settings.share("wallabag").set_strv("wallabag", array); var pwSchema = new Secret.Schema ("org.gnome.feedreader.wallabag.password", Secret.SchemaFlags.NONE, @@ -180,7 +180,7 @@ public class FeedReader.WallabagAPI : ShareAccountInterface, Peas.ExtensionBase settings.reset(key); } - var array = Settings.share().get_strv("wallabag"); + var array = Settings.share("wallabag").get_strv("wallabag"); string[] array2 = {}; foreach(string i in array) @@ -188,7 +188,7 @@ public class FeedReader.WallabagAPI : ShareAccountInterface, Peas.ExtensionBase if(i != id) array2 += i; } - Settings.share().set_strv("wallabag", array2); + Settings.share("wallabag").set_strv("wallabag", array2); deleteAccount(id); return true; diff --git a/plugins/share/Wallabag/WallabagSetup.vala b/plugins/share/Wallabag/WallabagSetup.vala index e3124fec7..7ed7d45e8 100644 --- a/plugins/share/Wallabag/WallabagSetup.vala +++ b/plugins/share/Wallabag/WallabagSetup.vala @@ -111,7 +111,7 @@ public class FeedReader.WallabagSetup : ServiceSetup { { if(m_login_revealer.get_child_revealed()) { - string id = Share.generateNewID(); + string id = Share.get_default().generateNewID(); string username = m_userEntry.get_text(); string password = m_passEntry.get_text(); string clientID = m_idEntry.get_text(); diff --git a/plugins/share/Wallabag/org.gnome.feedreader.share.wallabag.gschema.xml b/plugins/share/Wallabag/org.gnome.feedreader.share.wallabag.gschema.xml new file mode 100644 index 000000000..eea11d4ad --- /dev/null +++ b/plugins/share/Wallabag/org.gnome.feedreader.share.wallabag.gschema.xml @@ -0,0 +1,13 @@ + + + + + [] + wallabag accounts + + all the wallabag account ids + + + + + diff --git a/schemas/org.gnome.feedreader.share.gschema.xml b/schemas/org.gnome.feedreader.share.gschema.xml index 957260dcc..5f4eca5bd 100644 --- a/schemas/org.gnome.feedreader.share.gschema.xml +++ b/schemas/org.gnome.feedreader.share.gschema.xml @@ -1,49 +1,4 @@ - - - - [] - instapaper accounts - - all the instapaper account ids - - - - - [] - Telegram accounts - - all the telegram account ids - - - - - [] - pocket accounts - - all the pocket account ids - - - - - [] - wallabag accounts - - all the wallabag account ids - - - - - [] - twitter accounts - - all the twitter account ids - - - - - - diff --git a/src/Settings.vala b/src/Settings.vala index 026b857ef..03aa5b74a 100644 --- a/src/Settings.vala +++ b/src/Settings.vala @@ -19,7 +19,7 @@ public class FeedReader.Settings : GLib.Object { private static GLib.Settings? m_tweaks = null; private static GLib.Settings? m_state = null; private static GLib.Settings? m_keys = null; - private static GLib.Settings? m_share = null; + private static Gee.HashMap? m_share = null; public static GLib.Settings general() { @@ -53,12 +53,19 @@ public class FeedReader.Settings : GLib.Object { return m_keys; } - public static GLib.Settings share() + public static GLib.Settings? share(string pluginName) { if(m_share == null) - m_share = new GLib.Settings("org.gnome.feedreader.share"); + m_share = new Gee.HashMap(); - return m_share; + if(m_share.has_key(pluginName)) + return m_share.get(pluginName); + else + { + var settings = new GLib.Settings(@"org.gnome.feedreader.share.$pluginName"); + m_share.set(pluginName, settings); + return settings; + } } private Settings() diff --git a/src/Share/share.vala b/src/Share/share.vala index 90f314213..6dca95bd6 100644 --- a/src/Share/share.vala +++ b/src/Share/share.vala @@ -65,14 +65,15 @@ public class FeedReader.Share : GLib.Object { plugin.setupSystemAccounts(m_accounts); if(plugin.needSetup()) { - var accounts = Settings.share().get_strv(plugin.pluginID()); - foreach(string id in accounts) + var plugID = plugin.pluginID(); + var accounts = Settings.share(plugID).get_strv("account-ids"); + foreach(string accountID in accounts) { m_accounts.add( new ShareAccount( - id, + accountID, plugin.pluginID(), - plugin.getUsername(id), + plugin.getUsername(accountID), plugin.getIconName(), plugin.pluginName() ) @@ -135,24 +136,30 @@ public class FeedReader.Share : GLib.Object { return m_accounts; } - public static string generateNewID() + public string generateNewID() { string id = Utils.string_random(12); + bool unique = true; - - string[] keys = Settings.share().list_keys(); - - foreach(string key in keys) - { - string[] ids = Settings.share().get_strv(key); - foreach(string i in ids) + m_plugins.foreach((@set, info, exten) => { + var plugin = (exten as ShareAccountInterface); + var plugID = plugin.pluginID(); + if(plugin.needSetup()) { - if(i == id) + string[] ids = Settings.share(plugID).get_strv("account-ids"); + foreach(string i in ids) { - return generateNewID(); + if(i == id) + { + unique = false; + return; + } } } - } + }); + + if(!unique) + return generateNewID(); return id; }