2020-04-03 22:28:15 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* 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 SHARED_GLOBAL_H
|
|
|
|
#define SHARED_GLOBAL_H
|
|
|
|
|
|
|
|
#include "enums.h"
|
|
|
|
#include "message.h"
|
2020-04-04 16:40:32 +00:00
|
|
|
#include "exception.h"
|
2020-04-03 22:28:15 +00:00
|
|
|
|
|
|
|
#include <map>
|
2020-04-13 19:57:23 +00:00
|
|
|
#include <set>
|
|
|
|
#include <deque>
|
2020-04-03 22:28:15 +00:00
|
|
|
|
2022-01-21 19:02:50 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QStyle>
|
2020-04-03 22:28:15 +00:00
|
|
|
#include <QDebug>
|
2021-04-20 21:56:47 +00:00
|
|
|
#include <QMimeType>
|
|
|
|
#include <QMimeDatabase>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QImage>
|
2021-05-15 22:07:49 +00:00
|
|
|
#include <QMovie>
|
2021-04-20 21:56:47 +00:00
|
|
|
#include <QSize>
|
2021-05-06 14:44:43 +00:00
|
|
|
#include <QUrl>
|
|
|
|
#include <QLibrary>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QRegularExpression>
|
2023-01-12 17:56:01 +00:00
|
|
|
#include <QFont>
|
|
|
|
#include <QFontMetrics>
|
2020-04-03 22:28:15 +00:00
|
|
|
|
|
|
|
namespace Shared {
|
|
|
|
|
|
|
|
class Global {
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(Global)
|
|
|
|
public:
|
2021-04-20 21:56:47 +00:00
|
|
|
struct FileInfo {
|
|
|
|
enum class Preview {
|
|
|
|
none,
|
|
|
|
picture,
|
2021-05-15 22:07:49 +00:00
|
|
|
animation
|
2021-04-20 21:56:47 +00:00
|
|
|
};
|
|
|
|
|
2022-01-09 14:32:23 +00:00
|
|
|
QString path;
|
2021-04-20 21:56:47 +00:00
|
|
|
QString name;
|
|
|
|
QSize size;
|
|
|
|
QMimeType mime;
|
|
|
|
Preview preview;
|
|
|
|
};
|
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
Global();
|
2022-04-18 16:54:42 +00:00
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
static Global* getInstance();
|
|
|
|
static QString getName(Availability av);
|
|
|
|
static QString getName(ConnectionState cs);
|
|
|
|
static QString getName(SubscriptionState ss);
|
|
|
|
static QString getName(Affiliation af);
|
|
|
|
static QString getName(Role rl);
|
|
|
|
static QString getName(Message::State rl);
|
2020-04-04 16:40:32 +00:00
|
|
|
static QString getName(AccountPassword ap);
|
2020-04-03 22:28:15 +00:00
|
|
|
|
2020-04-10 22:15:08 +00:00
|
|
|
static QString getDescription(AccountPassword ap);
|
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
const std::deque<QString> availability;
|
|
|
|
const std::deque<QString> connectionState;
|
|
|
|
const std::deque<QString> subscriptionState;
|
|
|
|
const std::deque<QString> affiliation;
|
|
|
|
const std::deque<QString> role;
|
|
|
|
const std::deque<QString> messageState;
|
2020-04-04 16:40:32 +00:00
|
|
|
const std::deque<QString> accountPassword;
|
2020-04-03 22:28:15 +00:00
|
|
|
|
2020-04-10 22:15:08 +00:00
|
|
|
const std::deque<QString> accountPasswordDescription;
|
2022-01-21 19:02:50 +00:00
|
|
|
|
|
|
|
const QString defaultSystemStyle;
|
2022-01-27 17:44:32 +00:00
|
|
|
const QPalette defaultSystemPalette;
|
2020-04-10 22:15:08 +00:00
|
|
|
|
|
|
|
static bool supported(const QString& pluginName);
|
|
|
|
static void setSupported(const QString& pluginName, bool support);
|
|
|
|
|
2020-04-13 19:57:23 +00:00
|
|
|
static const std::set<QString> supportedImagesExts;
|
|
|
|
|
2021-04-20 21:56:47 +00:00
|
|
|
static FileInfo getFileInfo(const QString& path);
|
2021-05-06 14:44:43 +00:00
|
|
|
static void highlightInFileManager(const QString& path);
|
2022-01-26 20:53:44 +00:00
|
|
|
static QIcon createThemePreview(const QString& path);
|
2022-01-27 17:44:32 +00:00
|
|
|
static QString getColorSchemeName(const QString& path);
|
|
|
|
static void setTheme(const QString& path);
|
|
|
|
static void setStyle(const QString& style);
|
2022-12-28 22:41:59 +00:00
|
|
|
const bool omemoSupport;
|
2023-01-12 17:56:01 +00:00
|
|
|
QFont defaultFont;
|
|
|
|
QFont smallFont;
|
|
|
|
QFont headerFont;
|
|
|
|
QFont titleFont;
|
|
|
|
QFontMetrics defaultFontMetrics;
|
|
|
|
QFontMetrics smallFontMetrics;
|
|
|
|
QFontMetrics headerFontMetrics;
|
|
|
|
QFontMetrics titleFontMetrics;
|
2021-04-20 21:56:47 +00:00
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
template<typename T>
|
|
|
|
static T fromInt(int src);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static T fromInt(unsigned int src);
|
|
|
|
|
2020-04-04 16:40:32 +00:00
|
|
|
class EnumOutOfRange:
|
|
|
|
public Utils::Exception
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EnumOutOfRange(const std::string& p_name):Exception(), name(p_name) {}
|
|
|
|
|
|
|
|
std::string getMessage() const{
|
|
|
|
return "An attempt to get enum " + name + " from integer out of range of that enum";
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
private:
|
|
|
|
static Global* instance;
|
2020-04-10 22:15:08 +00:00
|
|
|
|
|
|
|
std::map<QString, bool> pluginSupport;
|
2021-04-20 21:56:47 +00:00
|
|
|
std::map<QString, FileInfo> fileCache;
|
2021-05-06 14:44:43 +00:00
|
|
|
|
|
|
|
#ifdef WITH_KIO
|
|
|
|
static QLibrary openFileManagerWindowJob;
|
|
|
|
|
|
|
|
typedef void (*HighlightInFileManager)(const QUrl &);
|
|
|
|
|
|
|
|
static HighlightInFileManager hfm;
|
|
|
|
#endif
|
2022-01-26 20:53:44 +00:00
|
|
|
|
|
|
|
#ifdef WITH_KCONFIG
|
|
|
|
static QLibrary colorSchemeTools;
|
|
|
|
|
|
|
|
typedef QIcon* (*CreatePreview)(const QString&);
|
|
|
|
typedef void (*DeletePreview)(QIcon*);
|
2022-01-27 17:44:32 +00:00
|
|
|
typedef void (*ColorSchemeName)(const QString&, QString&);
|
|
|
|
typedef void (*CreatePalette)(const QString&, QPalette&);
|
2022-01-26 20:53:44 +00:00
|
|
|
|
|
|
|
static CreatePreview createPreview;
|
|
|
|
static DeletePreview deletePreview;
|
2022-01-27 17:44:32 +00:00
|
|
|
static ColorSchemeName colorSchemeName;
|
|
|
|
static CreatePalette createPalette;
|
2022-01-26 20:53:44 +00:00
|
|
|
#endif
|
2020-04-03 22:28:15 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SHARED_GLOBAL_H
|