From ed7fe730cb3bb8c7a41fafd5c3c4cce2e1bf9ac3 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 15 Aug 2021 00:53:45 -0500 Subject: [PATCH] Load protocols from any system add-on directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … rather than soley "$APPDIR/protocols/". The vague "protocols/" leaf was also renamed to "cardie/". --- application/ProtocolManager.cpp | 14 +++++----- application/ProtocolManager.h | 2 +- application/TheApp.cpp | 47 +++++++++++++++++++++++++-------- application/TheApp.h | 5 ++++ protocols/irc/Makefile | 2 +- protocols/purple/Makefile | 2 +- protocols/xmpp/Makefile | 2 +- 7 files changed, 52 insertions(+), 22 deletions(-) diff --git a/application/ProtocolManager.cpp b/application/ProtocolManager.cpp index 86f04c0..d57082c 100644 --- a/application/ProtocolManager.cpp +++ b/application/ProtocolManager.cpp @@ -26,11 +26,12 @@ static ProtocolManager* fInstance = NULL; -void +bool ProtocolManager::Init(BDirectory dir, BHandler* target) { BEntry entry; BPath path; + bool ret = false; dir.Rewind(); @@ -42,10 +43,11 @@ ProtocolManager::Init(BDirectory dir, BHandler* target) if (id < 0) continue; - // If add-on's API version fits then load accounts... + // If add-on's API version fits then load accounts… ChatProtocolAddOn* addOn = new ChatProtocolAddOn(id, path.Path()); if (addOn->Version() != APP_VERSION) continue; + ret = true; // If add-on has multiple protocols, also load them for (int32 i = 0; i < addOn->CountProtocols(); i++) { @@ -60,6 +62,7 @@ ProtocolManager::Init(BDirectory dir, BHandler* target) delete proto; } } + return ret; } @@ -158,9 +161,8 @@ ProtocolManager::_LoadAccounts(const char* image_path, ChatProtocolAddOn* addOn, BEntry entry; bool firstDone = false; - while (dir.GetNextEntry(&entry) == B_OK) { - _LoadAccount(addOn, entry, target); - } + while (dir.GetNextEntry(&entry) == B_OK) + _LoadAccount(addOn, entry, target); } @@ -196,5 +198,3 @@ ProtocolManager::_LoadAccount(ChatProtocolAddOn* addOn, BEntry accountEntry, } } } - - diff --git a/application/ProtocolManager.h b/application/ProtocolManager.h index d77a3d3..654bdff 100644 --- a/application/ProtocolManager.h +++ b/application/ProtocolManager.h @@ -20,7 +20,7 @@ class BHandler; class ProtocolManager { public: - void Init(BDirectory dir, BHandler* target); + bool Init(BDirectory dir, BHandler* target); static ProtocolManager* Get(); diff --git a/application/TheApp.cpp b/application/TheApp.cpp index d01519c..7750d22 100644 --- a/application/TheApp.cpp +++ b/application/TheApp.cpp @@ -1,16 +1,19 @@ /* * Copyright 2009-2011, Andrea Anzani. All rights reserved. * Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved. + * Copyright 2021, Jaidyn Levesque. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Andrea Anzani, andrea.anzani@gmail.com * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com + * Jaidyn Levesque, jadedctrl@teknik.io */ #include "TheApp.h" #include +#include #include #include @@ -79,16 +82,16 @@ TheApp::ReadyToRun() } printf("Loaded Emoticons settings from: %s\n", currentPath.Path()); - currentPath = appDir; - currentPath.Append("protocols"); - if (BEntry(currentPath.Path()).Exists()) { - printf("Looking for protocols from: %s\n", currentPath.Path()); + bool win = false; + if (_LoadProtocols(B_SYSTEM_ADDONS_DIRECTORY)) win = true; + if (_LoadProtocols(B_USER_ADDONS_DIRECTORY)) win = true; + if (_LoadProtocols(B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY)) win = true; + if (_LoadProtocols(B_USER_NONPACKAGED_ADDONS_DIRECTORY)) win = true; + if (_LoadProtocols(appDir)) win = true; - ProtocolManager::Get()->Init(BDirectory(currentPath.Path()), - fMainWin); - } else { - BString msg("Can't find protocols in:\n\n%path%"); - msg.ReplaceAll("%path%", currentPath.Path()); + if (win == false) { + BString msg(B_TRANSLATE("No protocols found!\nPlease make sure %app% was installed correctly.")); + msg.ReplaceAll("%app%", APP_NAME); BAlert* alert = new BAlert("", msg.String(), B_TRANSLATE("Ouch!")); alert->Go(); PostMessage(B_QUIT_REQUESTED); @@ -119,8 +122,8 @@ TheApp::AboutRequested() NULL }; - BString extraInfo(B_TRANSLATE("%app% is released under the GNU GPL " - "License.\nSome parts of %app% are available under MIT license.\n" + BString extraInfo(B_TRANSLATE("%app% is released under the MIT License.\n" + "Add-on and library licenses may vary.\n" "Built: %buildDate%")); extraInfo.ReplaceAll("%buildDate", BUILD_DATE); extraInfo.ReplaceAll("%app%", B_TRANSLATE_SYSTEM_NAME(APP_NAME)); @@ -158,3 +161,25 @@ TheApp::MessageReceived(BMessage* message) BLooper::MessageReceived(message); } } + + +bool +TheApp::_LoadProtocols(directory_which finddir) +{ + BPath path; + if (find_directory(finddir, &path) == B_OK) + return _LoadProtocols(path); + return false; +} + + +bool +TheApp::_LoadProtocols(BPath path) +{ + path.Append(BString(APP_NAME).ToLower()); + if (BEntry(path.Path()).Exists()) { + printf("Looking for protocols from: %s\n", path.Path()); + return ProtocolManager::Get()->Init(BDirectory(path.Path()), fMainWin); + } + return false; +} diff --git a/application/TheApp.h b/application/TheApp.h index 9bd3ded..1341b1f 100644 --- a/application/TheApp.h +++ b/application/TheApp.h @@ -1,12 +1,14 @@ /* * Copyright 2009-2011, Andrea Anzani. All rights reserved. * Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved. + * Copyright 2021, Jaidyn Levesque. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _THE_APP_H #define _THE_APP_H #include +#include class MainWindow; @@ -26,6 +28,9 @@ public: MainWindow* GetMainWindow() const; private: + bool _LoadProtocols(directory_which finddir); + bool _LoadProtocols(BPath path); + MainWindow* fMainWin; }; diff --git a/protocols/irc/Makefile b/protocols/irc/Makefile index a943a04..9b7d874 100644 --- a/protocols/irc/Makefile +++ b/protocols/irc/Makefile @@ -8,7 +8,7 @@ ## file:///system/develop/documentation/makefile-engine.html # The name of the binary. -NAME = protocols/irc +NAME = cardie/irc # The type of binary, must be one of: # APP: Application diff --git a/protocols/purple/Makefile b/protocols/purple/Makefile index 6a874f4..c29fada 100644 --- a/protocols/purple/Makefile +++ b/protocols/purple/Makefile @@ -8,7 +8,7 @@ ## file:///system/develop/documentation/makefile-engine.html # The name of the binary. -NAME = protocols/purple +NAME = cardie/purple # The type of binary, must be one of: # APP: Application diff --git a/protocols/xmpp/Makefile b/protocols/xmpp/Makefile index 70dd307..68ad989 100644 --- a/protocols/xmpp/Makefile +++ b/protocols/xmpp/Makefile @@ -8,7 +8,7 @@ ## file:///system/develop/documentation/makefile-engine.html # The name of the binary. -NAME = protocols/jabber +NAME = cardie/jabber # The type of binary, must be one of: # APP: Application