/* * Copyright (C) 2015-2020 by Savoir-faire Linux * Author: Edric Ladent Milaret * Author: Andreas Traczyk * Author: Isa Nanic * Author: Mingrui Zhang * Author: Aline Gondim Santos * * 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 . */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef Q_OS_WIN #include #include #undef ERROR #else #define LPCWSTR char * #endif #include "api/account.h" #include "api/contact.h" #include "api/contactmodel.h" #include "api/conversationmodel.h" namespace Utils { /* * App/System */ bool CreateStartupLink(const std::wstring &wstrAppName); void DeleteStartupLink(const std::wstring &wstrAppName); bool CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszPathLink); bool CheckStartupLink(const std::wstring& wstrAppName); const char* WinGetEnv(const char* name); QString GetRingtonePath(); QString GenGUID(); QString GetISODate(); void showSystemNotification(QWidget* widget, const QString& message, long delay = 5000, const QString &triggeredAccountId = ""); void showSystemNotification(QWidget *widget, const QString &sender, const QString &message, long delay = 5000, const QString &triggeredAccountId = ""); QSize getRealSize(QScreen *screen); void forceDeleteAsync(const QString &path); QString getChangeLog(); QString getProjectCredits(); void removeOldVersions(); /* * Updates */ #ifdef BETA static constexpr bool isBeta = true; #else static constexpr bool isBeta = false; #endif void cleanUpdateFiles(); void checkForUpdates(bool withUI, QWidget *parent = nullptr); void applyUpdates(bool updateToBeta, QWidget *parent = nullptr); /* * LRC helpers */ QString bestIdForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model); QString bestIdForAccount(const lrc::api::account::Info& account); QString bestNameForAccount(const lrc::api::account::Info& account); QString bestIdForContact(const lrc::api::contact::Info& contact); QString bestNameForContact(const lrc::api::contact::Info& contact); QString bestNameForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model); QString secondBestNameForAccount(const lrc::api::account::Info& account); lrc::api::profile::Type profileType(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model); std::string formatTimeString(const std::time_t& timestamp); bool isInteractionGenerated(const lrc::api::interaction::Type& interaction); bool isContactValid(const QString& contactUid, const lrc::api::ConversationModel& model); bool getReplyMessageBox(QWidget* widget, const QString& title, const QString& text); /* * Image manipulation */ static const QSize defaultAvatarSize {128, 128}; QString getContactImageString(const QString& accountId, const QString& uid); QImage getCirclePhoto(const QImage original, int sizePhoto); QImage conversationPhoto(const QString &convUid, const lrc::api::account::Info &accountInfo, bool filtered = false); QColor getAvatarColor(const QString& canonicalUri); QImage fallbackAvatar(const QString& canonicalUriStr, const QString& letterStr = QString(), const QSize& size = defaultAvatarSize); QImage fallbackAvatar(const std::string& alias, const std::string& uri, const QSize& size = defaultAvatarSize); QByteArray QImageToByteArray(QImage image); QByteArray QByteArrayFromFile(const QString& filename); QPixmap generateTintedPixmap(const QString& filename, QColor color); QPixmap generateTintedPixmap(const QPixmap& pix, QColor color); QImage scaleAndFrame(const QImage photo, const QSize& size = defaultAvatarSize); QImage accountPhoto(const lrc::api::account::Info& accountInfo, const QSize& size = defaultAvatarSize); QImage cropImage(const QImage& img); QPixmap pixmapFromSvg(const QString& svg_resource, const QSize& size); QImage setupQRCode(QString ringID, int margin); bool isImage(const QString& fileExt); /* * Misc */ QString formattedTime(int seconds); QString humanFileSize(qint64 fileSize); } // namespace Utils