diff --git a/CMakeLists.txt b/CMakeLists.txt index 8709bae371..3c86b9bb48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -448,8 +448,6 @@ set(${PROJECT_NAME}_SOURCES src/widget/genericchatroomwidget.h src/widget/groupwidget.cpp src/widget/groupwidget.h - src/widget/gui.cpp - src/widget/gui.h src/widget/loginscreen.cpp src/widget/loginscreen.h src/widget/maskablepixmapwidget.cpp @@ -470,6 +468,10 @@ set(${PROJECT_NAME}_SOURCES src/widget/tool/activatedialog.h src/widget/tool/adjustingscrollarea.cpp src/widget/tool/adjustingscrollarea.h + src/widget/tool/imessageboxmanager.h + src/widget/tool/imessageboxmanager.cpp + src/widget/tool/messageboxmanager.cpp + src/widget/tool/messageboxmanager.h src/widget/tool/callconfirmwidget.cpp src/widget/tool/callconfirmwidget.h src/widget/tool/chattextedit.cpp diff --git a/doc/coding_standards.md b/doc/coding_standards.md index 5aae3d5d22..0acf88be54 100644 --- a/doc/coding_standards.md +++ b/doc/coding_standards.md @@ -395,7 +395,6 @@ The following example demonstrates the above include rules: #include "persistence/profile.h" #include "persistence/profilelocker.h" #include "persistence/settings.h" -#include "widget/gui.h" #include #include diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index a6481e390c..1f3c4a706d 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -173,10 +173,10 @@ ChatMessage::Ptr ChatMessage::createChatInfoMessage(const QString& rawMessage, return msg; } -ChatMessage::Ptr ChatMessage::createFileTransferMessage(const QString& sender, CoreFile& coreFile, - ToxFile file, bool isMe, const QDateTime& date, - DocumentCache& documentCache, - Settings& settings, Style& style) +ChatMessage::Ptr ChatMessage::createFileTransferMessage( + const QString& sender, CoreFile& coreFile, ToxFile file, bool isMe, + const QDateTime& date, DocumentCache& documentCache, Settings& settings, + Style& style, IMessageBoxManager& messageBoxManager) { ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings, style)); @@ -189,7 +189,7 @@ ChatMessage::Ptr ChatMessage::createFileTransferMessage(const QString& sender, C msg->addColumn(new Text(documentCache, settings, style, sender, authorFont, true), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right)); msg->addColumn(new ChatLineContentProxy(new FileTransferWidget( - nullptr, coreFile, file, settings, style), 320, 0.6f), + nullptr, coreFile, file, settings, style, messageBoxManager), 320, 0.6f), ColumnFormat(1.0, ColumnFormat::VariableSize)); msg->addColumn(new Timestamp(date, settings.getTimestampFormat(), baseFont, documentCache, settings, style), diff --git a/src/chatlog/chatmessage.h b/src/chatlog/chatmessage.h index ed3ee16842..37034fa92d 100644 --- a/src/chatlog/chatmessage.h +++ b/src/chatlog/chatmessage.h @@ -31,6 +31,7 @@ class DocumentCache; class SmileyPack; class Settings; class Style; +class IMessageBoxManager; class ChatMessage : public ChatLine { @@ -65,7 +66,7 @@ class ChatMessage : public ChatLine Style& style); static ChatMessage::Ptr createFileTransferMessage(const QString& sender, CoreFile& coreFile, ToxFile file, bool isMe, const QDateTime& date, - DocumentCache& documentCache, Settings& settings, Style& style); + DocumentCache& documentCache, Settings& settings, Style& style, IMessageBoxManager& messageBoxManager); static ChatMessage::Ptr createTypingNotification(DocumentCache& documentCache, Settings& settings, Style& style); static ChatMessage::Ptr createBusyNotification(DocumentCache& documentCache, Settings& settings, Style& style); diff --git a/src/chatlog/chatwidget.cpp b/src/chatlog/chatwidget.cpp index d6748b9bb3..f38b281cc7 100644 --- a/src/chatlog/chatwidget.cpp +++ b/src/chatlog/chatwidget.cpp @@ -23,7 +23,6 @@ #include "chatmessage.h" #include "content/filetransferwidget.h" #include "content/text.h" -#include "src/widget/gui.h" #include "src/widget/translator.h" #include "src/widget/style.h" #include "src/persistence/settings.h" @@ -211,7 +210,8 @@ ChatLogIdx clampedAdd(ChatLogIdx idx, int val, IChatLog& chatLog) ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& documentCache_, - SmileyPack& smileyPack_, Settings& settings_, Style& style_, QWidget* parent) + SmileyPack& smileyPack_, Settings& settings_, Style& style_, + IMessageBoxManager& messageBoxManager_, QWidget* parent) : QGraphicsView(parent) , selectionRectColor{style_.getColor(Style::ColorPalette::SelectText)} , chatLog(chatLog_) @@ -221,6 +221,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& doc , smileyPack{smileyPack_} , settings(settings_) , style{style_} + , messageBoxManager{messageBoxManager_} { // Create the scene busyScene = new QGraphicsScene(this); @@ -1460,7 +1461,7 @@ void ChatWidget::renderFile(QString displayName, ToxFile file, bool isSelf, QDat CoreFile* coreFile = core.getCoreFile(); assert(coreFile); chatMessage = ChatMessage::createFileTransferMessage(displayName, *coreFile, - file, isSelf, timestamp, documentCache, settings, style); + file, isSelf, timestamp, documentCache, settings, style, messageBoxManager); } else { auto proxy = static_cast(chatMessage->getContent(1)); assert(proxy->getWidgetType() == ChatLineContentProxy::FileTransferWidgetType); diff --git a/src/chatlog/chatwidget.h b/src/chatlog/chatwidget.h index a7c1bcba33..da09c85561 100644 --- a/src/chatlog/chatwidget.h +++ b/src/chatlog/chatwidget.h @@ -37,6 +37,7 @@ class SmileyPack; class Settings; class Style; class ChatLineStorage; +class IMessageBoxManager; static const size_t DEF_NUM_MSG_TO_LOAD = 100; class ChatWidget : public QGraphicsView @@ -44,7 +45,8 @@ class ChatWidget : public QGraphicsView Q_OBJECT public: ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& documentCache, - SmileyPack& smileyPack, Settings& settings, Style& style, QWidget* parent = nullptr); + SmileyPack& smileyPack, Settings& settings, Style& style, + IMessageBoxManager& messageBoxManager, QWidget* parent = nullptr); virtual ~ChatWidget(); void insertChatlines(std::map chatLines); @@ -220,4 +222,5 @@ private slots: SmileyPack& smileyPack; Settings& settings; Style& style; + IMessageBoxManager& messageBoxManager; }; diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index 6bb98dcba1..fd517ca70e 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -22,9 +22,9 @@ #include "src/core/corefile.h" #include "src/persistence/settings.h" -#include "src/widget/gui.h" #include "src/widget/style.h" #include "src/widget/widget.h" +#include "src/widget/tool/imessageboxmanager.h" #include "src/model/exiftransform.h" #include "util/display.h" @@ -49,7 +49,7 @@ // downloaded to. FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, - ToxFile file, Settings& settings_, Style& style_) + ToxFile file, Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_) : QWidget(parent) , coreFile{_coreFile} , ui(new Ui::FileTransferWidget) @@ -60,6 +60,7 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, , active(true) , settings(settings_) , style{style_} + , messageBoxManager{messageBoxManager_} { ui->setupUi(this); @@ -140,7 +141,7 @@ void FileTransferWidget::acceptTransfer(const QString& filepath) // test if writable if (!tryRemoveFile(filepath)) { - GUI::showWarning(tr("Location not writable", "Title of permissions popup"), + messageBoxManager.showWarning(tr("Location not writable", "Title of permissions popup"), tr("You do not have permission to write that location. Choose another, or " "cancel the save dialog.", "text of permissions popup")); @@ -477,7 +478,7 @@ void FileTransferWidget::handleButton(QPushButton* btn) } if (btn->objectName() == "ok" || btn->objectName() == "previewButton") { - Widget::confirmExecutableOpen(QFileInfo(fileInfo.filePath)); + messageBoxManager.confirmExecutableOpen(QFileInfo(fileInfo.filePath)); } else if (btn->objectName() == "dir") { QString dirPath = QFileInfo(fileInfo.filePath).dir().path(); QDesktopServices::openUrl(QUrl::fromLocalFile(dirPath)); diff --git a/src/chatlog/content/filetransferwidget.h b/src/chatlog/content/filetransferwidget.h index f27536cc8f..217ffe14c2 100644 --- a/src/chatlog/content/filetransferwidget.h +++ b/src/chatlog/content/filetransferwidget.h @@ -35,6 +35,7 @@ class QVariantAnimation; class QPushButton; class Settings; class Style; +class IMessageBoxManager; class FileTransferWidget : public QWidget { @@ -42,7 +43,7 @@ class FileTransferWidget : public QWidget public: FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file, - Settings& settings, Style& style); + Settings& settings, Style& style, IMessageBoxManager& messageBoxManager); virtual ~FileTransferWidget(); bool isActive() const; void onFileTransferUpdate(ToxFile file); @@ -93,4 +94,5 @@ private slots: ToxFile::FileStatus lastStatus = ToxFile::INITIALIZING; Settings& settings; Style& style; + IMessageBoxManager& messageBoxManager; }; diff --git a/src/main.cpp b/src/main.cpp index a0bbde80ad..fc8c6a8708 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ #include "src/video/camerasource.h" #include "src/widget/loginscreen.h" #include "src/widget/translator.h" +#include "src/widget/tool/messageboxmanager.h" #include "widget/widget.h" #include #include @@ -57,6 +58,7 @@ QMutex* logBufferMutex = new QMutex(); std::unique_ptr settings; std::unique_ptr toxSave; +std::unique_ptr messageBoxManager; void cleanup() { @@ -236,7 +238,8 @@ int main(int argc, char* argv[]) qWarning() << "Couldn't load font"; } - settings = std::unique_ptr(new Settings()); + messageBoxManager = std::unique_ptr(new MessageBoxManager()); + settings = std::unique_ptr(new Settings(*messageBoxManager)); QString locale = settings->getTranslation(); // We need to init the resources in the translations_library explicitely. @@ -406,13 +409,14 @@ int main(int argc, char* argv[]) // note: Because Settings is shouldering global settings as well as model specific ones it // cannot be integrated into a central model object yet nexus.setSettings(settings.get()); + nexus.setMessageBoxManager(messageBoxManager.get()); auto& cameraSource = Nexus::getCameraSource(); // Autologin // TODO (kriby): Shift responsibility of linking views to model objects from nexus // Further: generate view instances separately (loginScreen, mainGUI, audio) Profile* profile = nullptr; if (autoLogin && Profile::exists(profileName, settings->getPaths()) && !Profile::isEncrypted(profileName, settings->getPaths())) { - profile = Profile::loadProfile(profileName, QString(), *settings, &parser, cameraSource); + profile = Profile::loadProfile(profileName, QString(), *settings, &parser, cameraSource, *messageBoxManager); if (!profile) { QMessageBox::information(nullptr, QObject::tr("Error"), QObject::tr("Failed to load profile automatically.")); @@ -429,7 +433,7 @@ int main(int argc, char* argv[]) profile = nexus.getProfile(); } - uriDialog = std::unique_ptr(new ToxURIDialog(nullptr, profile->getCore())); + uriDialog = std::unique_ptr(new ToxURIDialog(nullptr, profile->getCore(), *messageBoxManager)); if (ipc.isAttached()) { // Start to accept Inter-process communication diff --git a/src/net/toxuri.cpp b/src/net/toxuri.cpp index f95e0ab669..97f5d3c9a0 100644 --- a/src/net/toxuri.cpp +++ b/src/net/toxuri.cpp @@ -19,7 +19,7 @@ #include "src/net/toxuri.h" #include "src/core/core.h" -#include "src/widget/gui.h" +#include "src/widget/tool/imessageboxmanager.h" #include #include #include @@ -52,7 +52,7 @@ bool ToxURIDialog::handleToxURI(const QString& toxURI) } if (!error.isEmpty()) { - GUI::showWarning(QMessageBox::tr("Couldn't add friend"), error); + messageBoxManager.showWarning(QMessageBox::tr("Couldn't add friend"), error); return false; } @@ -72,9 +72,10 @@ void ToxURIDialog::setUserId(const QString& userId) userIdEdit->setText(userId); } -ToxURIDialog::ToxURIDialog(QWidget* parent, Core& _core) +ToxURIDialog::ToxURIDialog(QWidget* parent, Core& core_, IMessageBoxManager& messageBoxManager_) : QDialog(parent) - , core{_core} + , core{core_} + , messageBoxManager{messageBoxManager_} { const QString defaultMessage = QObject::tr("%1 here! Tox me maybe?", diff --git a/src/net/toxuri.h b/src/net/toxuri.h index d51d872343..4108eb0819 100644 --- a/src/net/toxuri.h +++ b/src/net/toxuri.h @@ -28,11 +28,12 @@ class QByteArray; class QLabel; class QLineEdit; class QPlainTextEdit; +class IMessageBoxManager; class ToxURIDialog : public QDialog { Q_OBJECT public: - explicit ToxURIDialog(QWidget* parent, Core& _core); + ToxURIDialog(QWidget* parent, Core& core, IMessageBoxManager& messageBoxManager); QString getRequestMessage(); bool handleToxURI(const QString& toxURI); @@ -44,4 +45,5 @@ class ToxURIDialog : public QDialog QLabel* friendsLabel; QLineEdit* userIdEdit; Core& core; + IMessageBoxManager& messageBoxManager; }; diff --git a/src/nexus.cpp b/src/nexus.cpp index b077ce8e36..eff23fd4ec 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -28,8 +28,8 @@ #include "src/widget/widget.h" #include "src/widget/style.h" #include "video/camerasource.h" -#include "widget/gui.h" #include "widget/loginscreen.h" +#include "src/widget/tool/messageboxmanager.h" #include "audio/audio.h" #include @@ -235,11 +235,10 @@ void Nexus::showMainGUI() assert(profile); // Create GUI - widget = new Widget(*profile, *audioControl, *cameraSource, *settings, *style); + widget = new Widget(*profile, *audioControl, *cameraSource, *settings, *style, *messageBoxManager); // Start GUI widget->init(); - GUI::getInstance(); // Zetok protection // There are small instants on startup during which no @@ -308,7 +307,8 @@ Profile* Nexus::getProfile() */ void Nexus::onCreateNewProfile(const QString& name, const QString& pass) { - setProfile(Profile::createProfile(name, pass, *settings, parser, *cameraSource)); + setProfile(Profile::createProfile(name, pass, *settings, parser, *cameraSource, + *messageBoxManager)); parser = nullptr; // only apply cmdline proxy settings once } @@ -317,7 +317,8 @@ void Nexus::onCreateNewProfile(const QString& name, const QString& pass) */ void Nexus::onLoadProfile(const QString& name, const QString& pass) { - setProfile(Profile::loadProfile(name, pass, *settings, parser, *cameraSource)); + setProfile(Profile::loadProfile(name, pass, *settings, parser, *cameraSource, + *messageBoxManager)); parser = nullptr; // only apply cmdline proxy settings once } /** @@ -356,6 +357,11 @@ CameraSource& Nexus::getCameraSource() return *getInstance().cameraSource; } +void Nexus::setMessageBoxManager(IMessageBoxManager* messageBoxManager_) +{ + messageBoxManager = messageBoxManager_; +} + #ifdef Q_OS_MAC void Nexus::retranslateUi() { diff --git a/src/nexus.h b/src/nexus.h index e53e892395..c96b4b37e9 100644 --- a/src/nexus.h +++ b/src/nexus.h @@ -34,6 +34,7 @@ class Core; class QCommandLineParser; class CameraSource; class Style; +class IMessageBoxManager; #ifdef Q_OS_MAC class QMenuBar; @@ -51,6 +52,7 @@ class Nexus : public QObject void start(); void showMainGUI(); void setSettings(Settings* settings_); + void setMessageBoxManager(IMessageBoxManager* messageBoxManager); void setParser(QCommandLineParser* parser_); static Nexus& getInstance(); static void destroyInstance(); @@ -111,4 +113,5 @@ public slots: QCommandLineParser* parser = nullptr; std::unique_ptr cameraSource; std::unique_ptr