From d883c23d181f36be6365da1c593ff3a50df98c2a Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Wed, 30 Jun 2021 20:29:30 -0500 Subject: [PATCH] Reorganize settings directory, custom purple paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The settings file-hierarchy has been changed a bit: * Cardie/ * preferences * Accounts/ * Cache/ * Accounts/ * Add-Ons/ `Cardie/Protocols` is now `Cardie/Accounts`, and the cache directory has been split into two. `Cache/Accounts/` is for account-specific cached data (e.g., cached roster icons, data, etc.), and `Cache/Protocols` is for protocol-wide settings/data. For purple, this will be used as the user's libpurple directory, which has been moved from the default of `~/.purple` (yikes!) Some plugin search-paths have been given to purple, too― lib directories + "/purple2/", and Cardie/Cache/Add-Ons/purple/plugins/. --- application/Utils.cpp | 38 +++++++++-------------------- application/Utils.h | 1 - protocols/purple/Purple.h | 1 + protocols/purple/PurpleApp.cpp | 36 +++++++++++++++++++++++++-- protocols/purple/PurpleApp.h | 4 +++ protocols/purple/PurpleProtocol.cpp | 2 +- protocols/xmpp/JabberHandler.cpp | 3 +-- 7 files changed, 52 insertions(+), 33 deletions(-) diff --git a/application/Utils.cpp b/application/Utils.cpp index f523ee9..d852d50 100644 --- a/application/Utils.cpp +++ b/application/Utils.cpp @@ -118,25 +118,7 @@ AccountsPath() if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return NULL; - path.Append(APP_NAME "/Protocols"); - if (create_directory(path.Path(), 0755) != B_OK) - return NULL; - - return path.Path(); -} - - -const char* -AccountPath(const char* signature) -{ - if (!signature) - return NULL; - - BPath path(AccountsPath()); - if (path.InitCheck() != B_OK) - return NULL; - - path.Append(signature); + path.Append(APP_NAME "/Accounts"); if (create_directory(path.Path(), 0755) != B_OK) return NULL; @@ -147,16 +129,17 @@ AccountPath(const char* signature) const char* AccountPath(const char* signature, const char* subsignature) { - if (BString(signature) == BString(subsignature) - || BString(subsignature).IsEmpty() == true) - return AccountPath(signature); - - BPath path(AccountPath(signature)); - - path.Append(subsignature); - if (create_directory(path.Path(), 0755) != B_OK) + BPath path(AccountsPath()); + if (path.InitCheck() != B_OK) return NULL; + path.Append(signature); + if (BString(signature) != BString(subsignature) + && BString(subsignature).IsEmpty() == false) + path.Append(subsignature); + + if (create_directory(path.Path(), 0755) != B_OK) + return NULL; return path.Path(); } @@ -178,6 +161,7 @@ const char* AccountCachePath(const char* accountName) { BPath path(CachePath()); + path.Append("Accounts"); if (path.InitCheck() != B_OK) return NULL; path.Append(accountName); diff --git a/application/Utils.h b/application/Utils.h index beb2c3c..7c5f9a3 100644 --- a/application/Utils.h +++ b/application/Utils.h @@ -31,7 +31,6 @@ BMenu* CreateAccountMenu(AccountInstances accounts, BMessage msg, BMessage* allMsg = NULL); const char* AccountsPath(); -const char* AccountPath(const char* signature); const char* AccountPath(const char* signature, const char* subsignature); const char* CachePath(); diff --git a/protocols/purple/Purple.h b/protocols/purple/Purple.h index d34963e..f8f831f 100644 --- a/protocols/purple/Purple.h +++ b/protocols/purple/Purple.h @@ -20,5 +20,6 @@ #define _PURPLE_H #define PURPLE_SIGNATURE "application/x-vnd.cardie.purple" +#define PURPLE_ADDON "purple" #endif // _PURPLE_H diff --git a/protocols/purple/PurpleApp.cpp b/protocols/purple/PurpleApp.cpp index 9b69219..7d44c19 100644 --- a/protocols/purple/PurpleApp.cpp +++ b/protocols/purple/PurpleApp.cpp @@ -26,7 +26,9 @@ #include #include +#include #include +#include #include #include @@ -85,7 +87,6 @@ PurpleApp::MessageReceived(BMessage* msg) protocolInfo.AddString("name", info->name); protocolInfo.AddString("id", info->id); SendMessage(thread_id, protocolInfo); - break; } case PURPLE_CONNECT_ACCOUNT: @@ -495,6 +496,14 @@ init_libpurple() { init_ui_ops(); + purple_util_set_user_dir(purple_cache()); + + + BString cachePlugin = BString(purple_cache()).Append("/plugins/"); + purple_plugins_add_search_path(cachePlugin.String()); + purple_plugins_add_finddir(B_USER_NONPACKAGED_LIB_DIRECTORY); + purple_plugins_add_finddir(B_SYSTEM_NONPACKAGED_LIB_DIRECTORY); + if (!purple_core_init(PURPLE_UI_ID)) return B_ERROR; @@ -643,7 +652,6 @@ signal_sent_im_msg(PurpleAccount* account, const char* receiver, sent.AddString("chat_id", receiver); sent.AddString("user_id", purple_account_get_username(account)); sent.AddString("body", message); - sent.PrintToStream(); ((PurpleApp*)be_app)->SendMessage(account, sent); } @@ -718,6 +726,30 @@ purple_status_to_cardie(PurpleStatus* status) } +const char* +purple_cache() +{ + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) + return NULL; + path.Append(APP_NAME "/Cache/Add-Ons/" PURPLE_ADDON); + if (create_directory(path.Path(), 0755) != B_OK) + return NULL; + return path.Path(); +} + + +void +purple_plugins_add_finddir(directory_which finddir) +{ + BPath path; + if (find_directory(finddir, &path) == B_OK) { + path.Append("purple2"); + purple_plugins_add_search_path(path.Path()); + } +} + + static guint _purple_glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data) { diff --git a/protocols/purple/PurpleApp.h b/protocols/purple/PurpleApp.h index 9f7c56c..82ad66a 100644 --- a/protocols/purple/PurpleApp.h +++ b/protocols/purple/PurpleApp.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -128,6 +129,9 @@ private: PurpleStatusPrimitive cardie_status_to_purple(UserStatus status); UserStatus purple_status_to_cardie(PurpleStatus* status); + const char* purple_cache(); + void purple_plugins_add_finddir(directory_which finddir); + static guint _purple_glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data); diff --git a/protocols/purple/PurpleProtocol.cpp b/protocols/purple/PurpleProtocol.cpp index 97dc97e..46bb474 100644 --- a/protocols/purple/PurpleProtocol.cpp +++ b/protocols/purple/PurpleProtocol.cpp @@ -66,7 +66,7 @@ protocol_count() const char* signature() { - return "purple"; + return PURPLE_ADDON; } diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index 94e2da7..08e3ad3 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -936,8 +936,7 @@ JabberHandler::_SetupAvatarCache() if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return B_ERROR; - path.Append("Caya"); - path.Append("Cache"); + path.Append("Cardie/Cache/Accounts"); path.Append(GetName()); if (create_directory(path.Path(), 0755) != B_OK)