1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-08-13 03:05:40 +02:00
jami-client-qt/src/libclient/pluginmodel.cpp
Amin Bandali e0b3b4adec misc: vendor libjamiclient into 'src/libclient/'
This is libjamiclient from the jami-libclient.git repository as of
767c45b8b09806ac05cbada720864df93588c047, with the following changes:

* src/libclient/newaccountmodel.cpp:
(NewAccountModelPimpl::removeFromAccounts): The lock wait inside
'#ifdef CHK_FREEABLE_BEFORE_ERASE_ACCOUNT' was not updated when the
type of 'accounts' was changed over the years from this:
std::map<std::string, account::Info>
to this:
std::map<QString, std::pair<account::Info, std::shared_ptr<Database>>>
Basically we need to get the 'first' of the pair for 'account::Info'.
So we now do that.

* src/libclient/avmodel.cpp:
* src/libclient/callbackshandler.cpp:
* src/libclient/contactmodel.cpp:
* src/libclient/conversationmodel.cpp:
* src/libclient/database.cpp:
* src/libclient/namedirectory.cpp:
* src/libclient/newaccountmodel.cpp:
* src/libclient/newcallmodel.cpp:
* src/libclient/newdevicemodel.cpp:
* src/libclient/peerdiscoverymodel.cpp:
* src/libclient/pluginmodel.cpp:
* src/libclient/smartinfohub.cpp:
* src/libclient/vcard.h:
* src/libclient/authority/storagehelper.cpp:  Replace Qt's 'foreach'
with 'Q_FOREACH' and its 'emit' with 'Q_EMIT' because in the client-qt
code base we have '-DQT_NO_KEYWORDS' to avoid conflicts with other
libraries we use.

* cmake/FindLibJami.cmake: Import cmake/FindRing.cmake from the
jami-libclient.git repository.  Then, rename RING_BUILD_DIR to
LIBJAMI_BUILD_DIR (though the old name is still supported for now).
Also update other references of Ring to Jami.  Further, add additional
calls to 'find_library' to make sure specified local paths for libjami
are checked before system-wide ones (in case of older/obsolete libjami
being available system-wide, which might happen on GNU/Linux systems).

* translations/lrc_*.ts: Import translation files from the libclient
repository.  The message location paths were corrected by running
"sed -i 's|../src|&/libclient|g' lrc_*.ts" in 'translations/'.

.tx/config: Add section for the newly-imported libclient translations.

* CMakeLists.txt: Reformat, plus various fixes and cleanups, such as
changing indentation to 2 spaces and wrapping lines at 70 characters,
renaming the parent directory of translations from 'ring' to 'jami',
and using all lowercase function calls.  Also add copyright headers.

* src/app/appsettingsmanager.cpp:
(AppSettingsManager::loadTranslations):
* src/app/utilsadapter.cpp (UtilsAdapter::supportedLang): Update to
adapt to the renaming of the parent directory of translations from
'ring' to 'jami'.

GitLab: #748
Change-Id: I86e3b0fb30e554755023e7b858b6a0d132cd59ab
2022-06-08 16:28:57 -04:00

254 lines
6.9 KiB
C++

/**
* Copyright (C) 2020-2022 Savoir-faire Linux Inc.
* Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser 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 "api/pluginmodel.h"
// Std
#include <algorithm> // std::sort
#include <chrono>
#include <csignal>
#include <iomanip> // for std::put_time
#include <fstream>
#include <mutex>
#include <thread>
#include <string>
#include <sstream>
// Qt
#include <QtCore/QStandardPaths>
#include <QtCore/QDir>
#include <QUrl>
// Ring daemon
// LRC
#include "dbus/pluginmanager.h"
namespace lrc {
using namespace api;
PluginModel::PluginModel()
: QObject()
{}
PluginModel::~PluginModel() {}
void
PluginModel::setPluginsEnabled(bool enable)
{
PluginManager::instance().setPluginsEnabled(enable);
if (!enable)
Q_EMIT chatHandlerStatusUpdated(false);
else
Q_EMIT chatHandlerStatusUpdated(getChatHandlers().size() > 0);
Q_EMIT modelUpdated();
}
bool
PluginModel::getPluginsEnabled() const
{
return PluginManager::instance().getPluginsEnabled();
}
VectorString
PluginModel::getInstalledPlugins() const
{
return VectorString::fromList(PluginManager::instance().getInstalledPlugins());
}
VectorString
PluginModel::getLoadedPlugins() const
{
return VectorString::fromList(PluginManager::instance().getLoadedPlugins());
}
plugin::PluginDetails
PluginModel::getPluginDetails(const QString& path)
{
if (path.isEmpty()) {
return plugin::PluginDetails();
}
MapStringString details = PluginManager::instance().getPluginDetails(path);
plugin::PluginDetails result;
if (!details.empty()) {
result.name = details["name"];
result.path = path;
result.iconPath = details["iconPath"];
}
VectorString loadedPlugins = getLoadedPlugins();
if (std::find(loadedPlugins.begin(), loadedPlugins.end(), result.path) != loadedPlugins.end()) {
result.loaded = true;
}
return result;
}
bool
PluginModel::installPlugin(const QString& jplPath, bool force)
{
if (getPluginsEnabled()) {
auto result = PluginManager::instance().installPlugin(jplPath, force);
Q_EMIT modelUpdated();
return result;
}
return false;
}
bool
PluginModel::uninstallPlugin(const QString& rootPath)
{
auto result = PluginManager::instance().uninstallPlugin(rootPath);
Q_EMIT modelUpdated();
return result;
}
bool
PluginModel::loadPlugin(const QString& path)
{
bool status = PluginManager::instance().loadPlugin(path);
Q_EMIT modelUpdated();
if (getChatHandlers().size() > 0)
Q_EMIT chatHandlerStatusUpdated(getPluginsEnabled());
return status;
}
bool
PluginModel::unloadPlugin(const QString& path)
{
bool status = PluginManager::instance().unloadPlugin(path);
Q_EMIT modelUpdated();
if (getChatHandlers().size() <= 0)
Q_EMIT chatHandlerStatusUpdated(false);
return status;
}
VectorString
PluginModel::getCallMediaHandlers() const
{
return VectorString::fromList(PluginManager::instance().getCallMediaHandlers());
}
void
PluginModel::toggleCallMediaHandler(const QString& mediaHandlerId,
const QString& callId,
bool toggle)
{
PluginManager::instance().toggleCallMediaHandler(mediaHandlerId, callId, toggle);
Q_EMIT modelUpdated();
}
VectorString
PluginModel::getChatHandlers() const
{
return VectorString::fromList(PluginManager::instance().getChatHandlers());
}
void
PluginModel::toggleChatHandler(const QString& chatHandlerId,
const QString& accountId,
const QString& peerId,
bool toggle)
{
PluginManager::instance().toggleChatHandler(chatHandlerId, accountId, peerId, toggle);
Q_EMIT modelUpdated();
}
VectorString
PluginModel::getCallMediaHandlerStatus(const QString& callId)
{
return VectorString::fromList(PluginManager::instance().getCallMediaHandlerStatus(callId));
}
plugin::PluginHandlerDetails
PluginModel::getCallMediaHandlerDetails(const QString& mediaHandlerId)
{
if (mediaHandlerId.isEmpty()) {
return plugin::PluginHandlerDetails();
}
MapStringString mediaHandlerDetails = PluginManager::instance().getCallMediaHandlerDetails(
mediaHandlerId);
plugin::PluginHandlerDetails result;
if (!mediaHandlerDetails.empty()) {
result.id = mediaHandlerId;
result.iconPath = mediaHandlerDetails["iconPath"];
result.name = mediaHandlerDetails["name"];
result.pluginId = mediaHandlerDetails["pluginId"];
}
return result;
}
VectorString
PluginModel::getChatHandlerStatus(const QString& accountId, const QString& peerId)
{
return VectorString::fromList(PluginManager::instance().getChatHandlerStatus(accountId, peerId));
}
plugin::PluginHandlerDetails
PluginModel::getChatHandlerDetails(const QString& chatHandlerId)
{
if (chatHandlerId.isEmpty()) {
return plugin::PluginHandlerDetails();
}
MapStringString chatHandlerDetails = PluginManager::instance().getChatHandlerDetails(
chatHandlerId);
plugin::PluginHandlerDetails result;
if (!chatHandlerDetails.empty()) {
result.id = chatHandlerId;
result.iconPath = chatHandlerDetails["iconPath"];
result.name = chatHandlerDetails["name"];
result.pluginId = chatHandlerDetails["pluginId"];
}
return result;
}
VectorMapStringString
PluginModel::getPluginPreferences(const QString& path, const QString& accountId)
{
return PluginManager::instance().getPluginPreferences(path, accountId);
}
bool
PluginModel::setPluginPreference(const QString& path,
const QString& accountId,
const QString& key,
const QString& value)
{
auto result = PluginManager::instance().setPluginPreference(path, accountId, key, value);
Q_EMIT modelUpdated();
return result;
}
MapStringString
PluginModel::getPluginPreferencesValues(const QString& path, const QString& accountId)
{
return PluginManager::instance().getPluginPreferencesValues(path, accountId);
}
bool
PluginModel::resetPluginPreferencesValues(const QString& path, const QString& accountId)
{
auto result = PluginManager::instance().resetPluginPreferencesValues(path, accountId);
Q_EMIT modelUpdated();
return result;
}
} // namespace lrc