mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Use GUI instead of Widget for common GUI tasks
This commit is contained in:
parent
46bba3f2f1
commit
331baa7447
|
@ -19,6 +19,7 @@
|
||||||
#include "src/misc/serialize.h"
|
#include "src/misc/serialize.h"
|
||||||
#include "src/misc/settings.h"
|
#include "src/misc/settings.h"
|
||||||
#include "src/widget/widget.h"
|
#include "src/widget/widget.h"
|
||||||
|
#include "src/widget/gui.h"
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
@ -490,7 +491,7 @@ void AutoUpdater::checkUpdatesAsyncInteractiveWorker()
|
||||||
QDir updateDir(updateDirStr);
|
QDir updateDir(updateDirStr);
|
||||||
|
|
||||||
if ((updateDir.exists() && QFile(updateDirStr+"flist").exists())
|
if ((updateDir.exists() && QFile(updateDirStr+"flist").exists())
|
||||||
|| Widget::getInstance()->askQuestion(QObject::tr("Update", "The title of a message box"),
|
|| GUI::askQuestion(QObject::tr("Update", "The title of a message box"),
|
||||||
QObject::tr("An update is available, do you want to download it now?\nIt will be installed when qTox restarts."), true, false))
|
QObject::tr("An update is available, do you want to download it now?\nIt will be installed when qTox restarts."), true, false))
|
||||||
{
|
{
|
||||||
downloadUpdate();
|
downloadUpdate();
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "misc/cdata.h"
|
#include "misc/cdata.h"
|
||||||
#include "misc/cstring.h"
|
#include "misc/cstring.h"
|
||||||
#include "misc/settings.h"
|
#include "misc/settings.h"
|
||||||
#include "widget/widget.h"
|
#include "widget/gui.h"
|
||||||
#include "historykeeper.h"
|
#include "historykeeper.h"
|
||||||
#include "src/audio.h"
|
#include "src/audio.h"
|
||||||
|
|
||||||
|
@ -259,7 +259,6 @@ void Core::start()
|
||||||
{
|
{
|
||||||
setStatusMessage(tr("Toxing on qTox")); // this also solves the not updating issue
|
setStatusMessage(tr("Toxing on qTox")); // this also solves the not updating issue
|
||||||
setUsername(tr("qTox User"));
|
setUsername(tr("qTox User"));
|
||||||
QMetaObject::invokeMethod(Widget::getInstance(), "onSettingsClicked"); // update ui with new profile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tox_callback_friend_request(tox, onFriendRequest, this);
|
tox_callback_friend_request(tox, onFriendRequest, this);
|
||||||
|
@ -1284,7 +1283,7 @@ void Core::switchConfiguration(const QString& profile)
|
||||||
saveCurrentInformation(); // part of a hack, see core.h
|
saveCurrentInformation(); // part of a hack, see core.h
|
||||||
|
|
||||||
ready = false;
|
ready = false;
|
||||||
Widget::getInstance()->setEnabledThreadsafe(false);
|
GUI::setEnabled(false);
|
||||||
clearPassword(ptMain);
|
clearPassword(ptMain);
|
||||||
clearPassword(ptHistory);
|
clearPassword(ptHistory);
|
||||||
|
|
||||||
|
@ -1304,7 +1303,7 @@ void Core::switchConfiguration(const QString& profile)
|
||||||
|
|
||||||
start();
|
start();
|
||||||
if (isReady())
|
if (isReady())
|
||||||
Widget::getInstance()->setEnabledThreadsafe(true);
|
GUI::setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::loadFriends()
|
void Core::loadFriends()
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
/* was permanently moved here to handle encryption */
|
/* was permanently moved here to handle encryption */
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "src/widget/widget.h"
|
#include "src/widget/gui.h"
|
||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
#include <tox/toxencryptsave.h>
|
#include <tox/toxencryptsave.h>
|
||||||
#include "src/misc/settings.h"
|
#include "src/misc/settings.h"
|
||||||
|
@ -165,7 +165,7 @@ QByteArray Core::getSaltFromFile(QString filename)
|
||||||
bool Core::loadEncryptedSave(QByteArray& data)
|
bool Core::loadEncryptedSave(QByteArray& data)
|
||||||
{
|
{
|
||||||
if (!Settings::getInstance().getEncryptTox())
|
if (!Settings::getInstance().getEncryptTox())
|
||||||
Widget::getInstance()->showWarningMsgBox(tr("Encryption error"), tr("The .tox file is encrypted, but encryption was not checked, continuing regardless."));
|
GUI::showWarning(tr("Encryption error"), tr("The .tox file is encrypted, but encryption was not checked, continuing regardless."));
|
||||||
|
|
||||||
int error = -1;
|
int error = -1;
|
||||||
QString a(tr("Please enter the password for the %1 profile.", "used in load() when no pw is already set").arg(Settings::getInstance().getCurrentProfile()));
|
QString a(tr("Please enter the password for the %1 profile.", "used in load() when no pw is already set").arg(Settings::getInstance().getCurrentProfile()));
|
||||||
|
@ -190,7 +190,7 @@ bool Core::loadEncryptedSave(QByteArray& data)
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
QString pw = Widget::getInstance()->passwordDialog(tr("Change profile"), dialogtxt);
|
QString pw = GUI::passwordDialog(tr("Change profile"), dialogtxt);
|
||||||
|
|
||||||
if (pw.isEmpty())
|
if (pw.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -216,7 +216,7 @@ void Core::checkEncryptedHistory()
|
||||||
QByteArray salt = getSaltFromFile(path);
|
QByteArray salt = getSaltFromFile(path);
|
||||||
if (exists && salt.size() == 0)
|
if (exists && salt.size() == 0)
|
||||||
{ // maybe we should handle this better
|
{ // maybe we should handle this better
|
||||||
Widget::getInstance()->showWarningMsgBox(tr("Encrypted chat history"), tr("No encrypted chat history file found, or it was corrupted.\nHistory will be disabled!"));
|
GUI::showWarning(tr("Encrypted chat history"), tr("No encrypted chat history file found, or it was corrupted.\nHistory will be disabled!"));
|
||||||
Settings::getInstance().setEncryptLogs(false);
|
Settings::getInstance().setEncryptLogs(false);
|
||||||
Settings::getInstance().setEnableLogging(false);
|
Settings::getInstance().setEnableLogging(false);
|
||||||
HistoryKeeper::resetInstance();
|
HistoryKeeper::resetInstance();
|
||||||
|
@ -252,7 +252,7 @@ void Core::checkEncryptedHistory()
|
||||||
bool error = true;
|
bool error = true;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
QString pw = Widget::getInstance()->passwordDialog(tr("Disable chat history"), dialogtxt);
|
QString pw = GUI::passwordDialog(tr("Disable chat history"), dialogtxt);
|
||||||
|
|
||||||
if (pw.isEmpty())
|
if (pw.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -303,7 +303,7 @@ void Core::saveConfiguration(const QString& path)
|
||||||
if (!pwsaltedkeys[ptMain])
|
if (!pwsaltedkeys[ptMain])
|
||||||
{
|
{
|
||||||
// probably zero chance event
|
// probably zero chance event
|
||||||
Widget::getInstance()->showWarningMsgBox(tr("NO Password"), tr("Encryption is enabled, but there is no password! Encryption will be disabled."));
|
GUI::showWarning(tr("NO Password"), tr("Encryption is enabled, but there is no password! Encryption will be disabled."));
|
||||||
Settings::getInstance().setEncryptTox(false);
|
Settings::getInstance().setEncryptTox(false);
|
||||||
tox_save(tox, data);
|
tox_save(tox, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include "friendlist.h"
|
#include "friendlist.h"
|
||||||
#include "widget/friendwidget.h"
|
#include "widget/friendwidget.h"
|
||||||
#include "widget/form/chatform.h"
|
#include "widget/form/chatform.h"
|
||||||
#include "widget/widget.h"
|
#include "widget/gui.h"
|
||||||
#include "src/core.h"
|
#include "src/core.h"
|
||||||
#include "src/misc/settings.h"
|
#include "src/misc/settings.h"
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ void Friend::setName(QString name)
|
||||||
chatForm->setName(name);
|
chatForm->setName(name);
|
||||||
|
|
||||||
if (widget->isActive())
|
if (widget->isActive())
|
||||||
Widget::getInstance()->setWindowTitle(name);
|
GUI::setWindowTitle(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ void Friend::setAlias(QString name)
|
||||||
chatForm->setName(dispName);
|
chatForm->setName(dispName);
|
||||||
|
|
||||||
if (widget->isActive())
|
if (widget->isActive())
|
||||||
Widget::getInstance()->setWindowTitle(dispName);
|
GUI::setWindowTitle(dispName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Friend::setStatusMessage(QString message)
|
void Friend::setStatusMessage(QString message)
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "friendlist.h"
|
#include "friendlist.h"
|
||||||
#include "friend.h"
|
#include "friend.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "widget/widget.h"
|
#include "widget/gui.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ void Group::setName(const QString& name)
|
||||||
chatForm->setName(name);
|
chatForm->setName(name);
|
||||||
|
|
||||||
if (widget->isActive())
|
if (widget->isActive())
|
||||||
Widget::getInstance()->setWindowTitle(name);
|
GUI::setWindowTitle(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Group::regeneratePeerList()
|
void Group::regeneratePeerList()
|
||||||
|
|
|
@ -16,10 +16,7 @@
|
||||||
|
|
||||||
#include "style.h"
|
#include "style.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "src/widget/gui.h"
|
||||||
#include "src/widget/widget.h"
|
|
||||||
#include "ui_mainwindow.h"
|
|
||||||
#include "src/widget/genericchatroomwidget.h"
|
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -198,11 +195,9 @@ void Style::setThemeColor(QColor color)
|
||||||
dict["@themeMediumDark"] = getColor(ThemeMediumDark).name();
|
dict["@themeMediumDark"] = getColor(ThemeMediumDark).name();
|
||||||
dict["@themeMedium"] = getColor(ThemeMedium).name();
|
dict["@themeMedium"] = getColor(ThemeMedium).name();
|
||||||
dict["@themeLight"] = getColor(ThemeLight).name();
|
dict["@themeLight"] = getColor(ThemeLight).name();
|
||||||
|
|
||||||
applyTheme();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Style::applyTheme()
|
void Style::applyTheme()
|
||||||
{
|
{
|
||||||
Widget::getInstance()->reloadTheme();
|
GUI::reloadTheme();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "misc/settings.h"
|
#include "misc/settings.h"
|
||||||
#include "video/camera.h"
|
#include "video/camera.h"
|
||||||
|
#include "widget/gui.h"
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
@ -66,6 +67,7 @@ void Nexus::start()
|
||||||
#else
|
#else
|
||||||
widget = Widget::getInstance();
|
widget = Widget::getInstance();
|
||||||
#endif
|
#endif
|
||||||
|
GUI::getInstance();
|
||||||
|
|
||||||
// Connections
|
// Connections
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
|
@ -119,3 +121,13 @@ Core* Nexus::getCore()
|
||||||
{
|
{
|
||||||
return getInstance().core;
|
return getInstance().core;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AndroidGUI* Nexus::getAndroidGUI()
|
||||||
|
{
|
||||||
|
return getInstance().androidgui;
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget* Nexus::getDesktopGUI()
|
||||||
|
{
|
||||||
|
return getInstance().widget;
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@ public:
|
||||||
|
|
||||||
static Nexus& getInstance();
|
static Nexus& getInstance();
|
||||||
static Core* getCore(); ///< Will return 0 if not started
|
static Core* getCore(); ///< Will return 0 if not started
|
||||||
|
static AndroidGUI* getAndroidGUI(); ///< Will return 0 if not started
|
||||||
|
static Widget* getDesktopGUI(); ///< Will return 0 if not started
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Nexus(QObject *parent = 0);
|
explicit Nexus(QObject *parent = 0);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "callconfirmwidget.h"
|
#include "callconfirmwidget.h"
|
||||||
#include "widget.h"
|
#include "gui.h"
|
||||||
|
#include <assert.h>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
@ -11,7 +12,7 @@
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
|
||||||
CallConfirmWidget::CallConfirmWidget(const QWidget *Anchor) :
|
CallConfirmWidget::CallConfirmWidget(const QWidget *Anchor) :
|
||||||
QWidget(Widget::getInstance()), anchor(Anchor),
|
QWidget(GUI::getMainWidget()), anchor(Anchor),
|
||||||
rectW{120}, rectH{85},
|
rectW{120}, rectH{85},
|
||||||
spikeW{30}, spikeH{15},
|
spikeW{30}, spikeH{15},
|
||||||
roundedFactor{20},
|
roundedFactor{20},
|
||||||
|
@ -43,7 +44,7 @@ CallConfirmWidget::CallConfirmWidget(const QWidget *Anchor) :
|
||||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &CallConfirmWidget::accepted);
|
connect(buttonBox, &QDialogButtonBox::accepted, this, &CallConfirmWidget::accepted);
|
||||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &CallConfirmWidget::rejected);
|
connect(buttonBox, &QDialogButtonBox::rejected, this, &CallConfirmWidget::rejected);
|
||||||
|
|
||||||
connect(Widget::getInstance(), &Widget::resized, this, &CallConfirmWidget::reposition);
|
connect(&GUI::getInstance(), &GUI::resized, this, &CallConfirmWidget::reposition);
|
||||||
|
|
||||||
layout->setMargin(12);
|
layout->setMargin(12);
|
||||||
layout->addSpacing(spikeH);
|
layout->addSpacing(spikeH);
|
||||||
|
@ -56,7 +57,7 @@ CallConfirmWidget::CallConfirmWidget(const QWidget *Anchor) :
|
||||||
|
|
||||||
void CallConfirmWidget::reposition()
|
void CallConfirmWidget::reposition()
|
||||||
{
|
{
|
||||||
Widget* w = Widget::getInstance();
|
QWidget* w = GUI::getMainWidget();
|
||||||
QPoint pos = anchor->mapToGlobal({(anchor->width()-rectW)/2,anchor->height()})-w->mapToGlobal({0,0});
|
QPoint pos = anchor->mapToGlobal({(anchor->width()-rectW)/2,anchor->height()})-w->mapToGlobal({0,0});
|
||||||
|
|
||||||
// We don't want the widget to overflow past the right of the screen
|
// We don't want the widget to overflow past the right of the screen
|
||||||
|
|
|
@ -359,4 +359,5 @@ void GeneralForm::onThemeColorChanged(int)
|
||||||
int index = bodyUI->themeColorCBox->currentIndex();
|
int index = bodyUI->themeColorCBox->currentIndex();
|
||||||
Settings::getInstance().setThemeColor(index);
|
Settings::getInstance().setThemeColor(index);
|
||||||
Style::setThemeColor(index);
|
Style::setThemeColor(index);
|
||||||
|
Style::applyTheme();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,30 @@
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
#include "src/nexus.h"
|
||||||
|
#include <assert.h>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
#include "androidgui.h"
|
||||||
|
#else
|
||||||
|
#include "widget.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
GUI::GUI(QObject *parent) :
|
GUI::GUI(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
|
assert(QThread::currentThread() == qApp->thread());
|
||||||
|
|
||||||
|
#ifndef Q_OS_ANDROID
|
||||||
|
assert(Nexus::getDesktopGUI());
|
||||||
|
connect(Nexus::getDesktopGUI(), &Widget::resized, this, &GUI::resized);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI& GUI::getInstance()
|
GUI& GUI::getInstance()
|
||||||
|
@ -14,6 +33,90 @@ GUI& GUI::getInstance()
|
||||||
return gui;
|
return gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementation of the public clean interface
|
||||||
|
|
||||||
|
void GUI::setEnabled(bool state)
|
||||||
|
{
|
||||||
|
if (QThread::currentThread() == qApp->thread())
|
||||||
|
{
|
||||||
|
getInstance()._setEnabled(state);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(&getInstance(), "_setEnabled", Qt::BlockingQueuedConnection,
|
||||||
|
Q_ARG(bool, state));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::setWindowTitle(const QString& title)
|
||||||
|
{
|
||||||
|
if (QThread::currentThread() == qApp->thread())
|
||||||
|
{
|
||||||
|
getInstance()._setWindowTitle(title);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(&getInstance(), "_setWindowTitle", Qt::BlockingQueuedConnection,
|
||||||
|
Q_ARG(const QString&, title));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::reloadTheme()
|
||||||
|
{
|
||||||
|
if (QThread::currentThread() == qApp->thread())
|
||||||
|
{
|
||||||
|
getInstance()._reloadTheme();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(&getInstance(), "_reloadTheme", Qt::BlockingQueuedConnection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::showWarning(const QString& title, const QString& msg)
|
||||||
|
{
|
||||||
|
if (QThread::currentThread() == qApp->thread())
|
||||||
|
{
|
||||||
|
getInstance()._showWarning(title, msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(&getInstance(), "_showWarning", Qt::BlockingQueuedConnection,
|
||||||
|
Q_ARG(const QString&, title), Q_ARG(const QString&, msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::showInfo(const QString& title, const QString& msg)
|
||||||
|
{
|
||||||
|
if (QThread::currentThread() == qApp->thread())
|
||||||
|
{
|
||||||
|
getInstance()._showInfo(title, msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(&getInstance(), "_showInfo", Qt::BlockingQueuedConnection,
|
||||||
|
Q_ARG(const QString&, title), Q_ARG(const QString&, msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GUI::askQuestion(const QString& title, const QString& msg,
|
||||||
|
bool defaultAns, bool warning)
|
||||||
|
{
|
||||||
|
if (QThread::currentThread() == qApp->thread())
|
||||||
|
{
|
||||||
|
return getInstance()._askQuestion(title, msg, defaultAns, warning);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool ret;
|
||||||
|
QMetaObject::invokeMethod(&getInstance(), "_askQuestion", Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(bool, ret),
|
||||||
|
Q_ARG(const QString&, title), Q_ARG(const QString&, msg),
|
||||||
|
Q_ARG(bool, defaultAns), Q_ARG(bool, warning));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString GUI::itemInputDialog(QWidget * parent, const QString & title,
|
QString GUI::itemInputDialog(QWidget * parent, const QString & title,
|
||||||
const QString & label, const QStringList & items,
|
const QString & label, const QStringList & items,
|
||||||
int current, bool editable, bool * ok,
|
int current, bool editable, bool * ok,
|
||||||
|
@ -37,6 +140,77 @@ QString GUI::itemInputDialog(QWidget * parent, const QString & title,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GUI::passwordDialog(const QString& cancel, const QString& body)
|
||||||
|
{
|
||||||
|
if (QThread::currentThread() == qApp->thread())
|
||||||
|
{
|
||||||
|
return getInstance()._passwordDialog(cancel, body);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString r;
|
||||||
|
QMetaObject::invokeMethod(&getInstance(), "_passwordDialog", Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(QString, r),
|
||||||
|
Q_ARG(const QString&, cancel), Q_ARG(const QString&, body));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private implementations
|
||||||
|
|
||||||
|
void GUI::_setEnabled(bool state)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
Nexus::getAndroidGUI()->setEnabled(state);
|
||||||
|
#else
|
||||||
|
Nexus::getDesktopGUI()->setEnabled(state);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::_setWindowTitle(const QString& title)
|
||||||
|
{
|
||||||
|
if (title.isEmpty())
|
||||||
|
getMainWidget()->setWindowTitle("qTox");
|
||||||
|
else
|
||||||
|
getMainWidget()->setWindowTitle("qTox - " +title);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::_reloadTheme()
|
||||||
|
{
|
||||||
|
#ifndef Q_OS_ANDROID
|
||||||
|
Nexus::getDesktopGUI()->reloadTheme();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::_showWarning(const QString& title, const QString& msg)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(getMainWidget(), title, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUI::_showInfo(const QString& title, const QString& msg)
|
||||||
|
{
|
||||||
|
QMessageBox::information(getMainWidget(), title, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GUI::_askQuestion(const QString& title, const QString& msg,
|
||||||
|
bool defaultAns, bool warning)
|
||||||
|
{
|
||||||
|
if (warning)
|
||||||
|
{
|
||||||
|
QMessageBox::StandardButton def = QMessageBox::Cancel;
|
||||||
|
if (defaultAns)
|
||||||
|
def = QMessageBox::Ok;
|
||||||
|
return QMessageBox::warning(getMainWidget(), title, msg, QMessageBox::Ok | QMessageBox::Cancel, def) == QMessageBox::Ok;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::StandardButton def = QMessageBox::No;
|
||||||
|
if (defaultAns)
|
||||||
|
def = QMessageBox::Yes;
|
||||||
|
return QMessageBox::question(getMainWidget(), title, msg, QMessageBox::Yes | QMessageBox::No, def) == QMessageBox::Yes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString GUI::_itemInputDialog(QWidget * parent, const QString & title,
|
QString GUI::_itemInputDialog(QWidget * parent, const QString & title,
|
||||||
const QString & label, const QStringList & items,
|
const QString & label, const QStringList & items,
|
||||||
int current, bool editable, bool * ok,
|
int current, bool editable, bool * ok,
|
||||||
|
@ -45,3 +219,72 @@ QString GUI::_itemInputDialog(QWidget * parent, const QString & title,
|
||||||
{
|
{
|
||||||
return QInputDialog::getItem(parent, title, label, items, current, editable, ok, flags, hints);
|
return QInputDialog::getItem(parent, title, label, items, current, editable, ok, flags, hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GUI::_passwordDialog(const QString& cancel, const QString& body)
|
||||||
|
{
|
||||||
|
// we use a hack. It is considered that closing the dialog without explicitly clicking
|
||||||
|
// disable history is confusing. But we can't distinguish between clicking the cancel
|
||||||
|
// button and closing the dialog. So instead, we reverse the Ok and Cancel roles,
|
||||||
|
// so that nothing but explicitly clicking disable history closes the dialog
|
||||||
|
QString ret;
|
||||||
|
QInputDialog dialog;
|
||||||
|
dialog.setWindowTitle(tr("Enter your password"));
|
||||||
|
dialog.setOkButtonText(cancel);
|
||||||
|
dialog.setCancelButtonText(tr("Decrypt"));
|
||||||
|
dialog.setInputMode(QInputDialog::TextInput);
|
||||||
|
dialog.setTextEchoMode(QLineEdit::Password);
|
||||||
|
dialog.setLabelText(body);
|
||||||
|
|
||||||
|
// problem with previous hack: the default button is disable history, not decrypt.
|
||||||
|
// use another hack to reverse the default buttons.
|
||||||
|
// http://www.qtcentre.org/threads/49924-Change-property-of-QInputDialog-button
|
||||||
|
QList<QDialogButtonBox*> l = dialog.findChildren<QDialogButtonBox*>();
|
||||||
|
if (!l.isEmpty())
|
||||||
|
{
|
||||||
|
QPushButton* ok = l.first()->button(QDialogButtonBox::Ok);
|
||||||
|
QPushButton* cancel = l.first()->button(QDialogButtonBox::Cancel);
|
||||||
|
if (ok && cancel)
|
||||||
|
{
|
||||||
|
ok->setAutoDefault(false);
|
||||||
|
ok->setDefault(false);
|
||||||
|
cancel->setAutoDefault(true);
|
||||||
|
cancel->setDefault(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qWarning() << "PasswordDialog: Missing button!";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qWarning() << "PasswordDialog: No QDialogButtonBox!";
|
||||||
|
|
||||||
|
// using similar code, set QLabels to wrap
|
||||||
|
for (auto* label : dialog.findChildren<QLabel*>())
|
||||||
|
label->setWordWrap(true);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
int val = dialog.exec();
|
||||||
|
if (val == QDialog::Accepted)
|
||||||
|
return QString();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = dialog.textValue();
|
||||||
|
if (!ret.isEmpty())
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
dialog.setTextValue("");
|
||||||
|
dialog.setLabelText(body + "\n\n" + tr("You must enter a non-empty password:"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Other
|
||||||
|
|
||||||
|
QWidget* GUI::getMainWidget()
|
||||||
|
{
|
||||||
|
QWidget* maingui{nullptr};
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
maingui = Nexus::getAndroidGUI();
|
||||||
|
#else
|
||||||
|
maingui = Nexus::getDesktopGUI();
|
||||||
|
#endif
|
||||||
|
return maingui;
|
||||||
|
}
|
||||||
|
|
|
@ -13,21 +13,60 @@ class GUI : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static GUI& getInstance();
|
static GUI& getInstance();
|
||||||
|
/// Returns the main QWidget* of the application
|
||||||
|
static QWidget* getMainWidget();
|
||||||
|
/// Will enable or disable the GUI.
|
||||||
|
/// A disabled GUI can't be interacted with by the user
|
||||||
|
static void setEnabled(bool state);
|
||||||
|
/// Change the title of the main window
|
||||||
|
/// This is usually always visible to the user
|
||||||
|
static void setWindowTitle(const QString& title);
|
||||||
|
/// Reloads the application theme and redraw the window
|
||||||
|
static void reloadTheme();
|
||||||
|
/// Show a warning to the user, for example in a message box
|
||||||
|
static void showWarning(const QString& title, const QString& msg);
|
||||||
|
/// Show some text to the user, for example in a message box
|
||||||
|
static void showInfo(const QString& title, const QString& msg);
|
||||||
|
/// Asks the user a question, for example in a message box.
|
||||||
|
/// If warning is true, we will use a special warning style.
|
||||||
|
/// Returns the answer.
|
||||||
|
static bool askQuestion(const QString& title, const QString& msg,
|
||||||
|
bool defaultAns = false, bool warning = true);
|
||||||
|
/// Asks the user to input text and returns the answer.
|
||||||
|
/// The interface is equivalent to QInputDialog::getItem()
|
||||||
static QString itemInputDialog(QWidget * parent, const QString & title,
|
static QString itemInputDialog(QWidget * parent, const QString & title,
|
||||||
const QString & label, const QStringList & items,
|
const QString & label, const QStringList & items,
|
||||||
int current = 0, bool editable = true, bool * ok = 0,
|
int current = 0, bool editable = true, bool * ok = 0,
|
||||||
Qt::WindowFlags flags = 0,
|
Qt::WindowFlags flags = 0,
|
||||||
Qt::InputMethodHints hints = Qt::ImhNone);
|
Qt::InputMethodHints hints = Qt::ImhNone);
|
||||||
|
/// Asks the user to answer a password
|
||||||
|
/// cancel is the text on the cancel button and body
|
||||||
|
/// is descriptive text that will be shown to the user
|
||||||
|
static QString passwordDialog(const QString& cancel, const QString& body);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/// Emitted when the GUI is resized on supported platforms
|
||||||
|
/// Guaranteed to work on desktop platforms
|
||||||
|
void resized();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit GUI(QObject *parent = 0);
|
explicit GUI(QObject *parent = 0);
|
||||||
|
|
||||||
|
// Private implementation, those must be called from the GUI thread
|
||||||
private slots:
|
private slots:
|
||||||
|
void _setEnabled(bool state);
|
||||||
|
void _setWindowTitle(const QString& title);
|
||||||
|
void _reloadTheme();
|
||||||
|
void _showWarning(const QString& title, const QString& msg);
|
||||||
|
void _showInfo(const QString& title, const QString& msg);
|
||||||
|
bool _askQuestion(const QString& title, const QString& msg,
|
||||||
|
bool defaultAns = false, bool warning = true);
|
||||||
QString _itemInputDialog(QWidget * parent, const QString & title,
|
QString _itemInputDialog(QWidget * parent, const QString & title,
|
||||||
const QString & label, const QStringList & items,
|
const QString & label, const QStringList & items,
|
||||||
int current = 0, bool editable = true, bool * ok = 0,
|
int current = 0, bool editable = true, bool * ok = 0,
|
||||||
Qt::WindowFlags flags = 0,
|
Qt::WindowFlags flags = 0,
|
||||||
Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
|
Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
|
||||||
|
QString _passwordDialog(const QString& cancel, const QString& body);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GUI_H
|
#endif // GUI_H
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "toxsave.h"
|
#include "toxsave.h"
|
||||||
#include "widget.h"
|
#include "gui.h"
|
||||||
#include "src/core.h"
|
#include "src/core.h"
|
||||||
#include "src/misc/settings.h"
|
#include "src/misc/settings.h"
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
@ -53,20 +53,19 @@ void handleToxSave(const QString& path)
|
||||||
|
|
||||||
if (info.suffix() != "tox")
|
if (info.suffix() != "tox")
|
||||||
{
|
{
|
||||||
QMessageBox::warning(Widget::getInstance(),
|
GUI::showWarning(QObject::tr("Ignoring non-Tox file", "popup title"),
|
||||||
QObject::tr("Ignoring non-Tox file", "popup title"),
|
QObject::tr("Warning: you've chosen a file that is not a Tox save file; ignoring.", "popup text"));
|
||||||
QObject::tr("Warning: you've chosen a file that is not a Tox save file; ignoring.", "popup text"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT);
|
QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT);
|
||||||
|
|
||||||
if (QFileInfo(profilePath).exists() && !Widget::getInstance()->askQuestion(QObject::tr("Profile already exists", "import confirm title"),
|
if (QFileInfo(profilePath).exists() && !GUI::askQuestion(QObject::tr("Profile already exists", "import confirm title"),
|
||||||
QObject::tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile)))
|
QObject::tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QFile::copy(path, profilePath);
|
QFile::copy(path, profilePath);
|
||||||
// no good way to update the ui from here... maybe we need a Widget:refreshUi() function...
|
// no good way to update the ui from here... maybe we need a Widget:refreshUi() function...
|
||||||
// such a thing would simplify other code as well I believe
|
// such a thing would simplify other code as well I believe
|
||||||
QMessageBox::information(Widget::getInstance(), QObject::tr("Profile imported"), QObject::tr("%1.tox was successfully imported").arg(profile));
|
GUI::showInfo(QObject::tr("Profile imported"), QObject::tr("%1.tox was successfully imported").arg(profile));
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,9 @@ void Widget::init()
|
||||||
this,
|
this,
|
||||||
SLOT(onIconClick(QSystemTrayIcon::ActivationReason)));
|
SLOT(onIconClick(QSystemTrayIcon::ActivationReason)));
|
||||||
|
|
||||||
|
icon->show();
|
||||||
|
icon->hide();
|
||||||
|
|
||||||
if (Settings::getInstance().getShowSystemTray())
|
if (Settings::getInstance().getShowSystemTray())
|
||||||
{
|
{
|
||||||
icon->show();
|
icon->show();
|
||||||
|
@ -125,7 +128,6 @@ void Widget::init()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
this->show();
|
this->show();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -194,7 +196,7 @@ void Widget::init()
|
||||||
ui->statusButton->setEnabled(false);
|
ui->statusButton->setEnabled(false);
|
||||||
|
|
||||||
Style::setThemeColor(Settings::getInstance().getThemeColor());
|
Style::setThemeColor(Settings::getInstance().getThemeColor());
|
||||||
Style::applyTheme();
|
reloadTheme();
|
||||||
|
|
||||||
filesForm = new FilesForm();
|
filesForm = new FilesForm();
|
||||||
addFriendForm = new AddFriendForm;
|
addFriendForm = new AddFriendForm;
|
||||||
|
@ -264,7 +266,7 @@ void Widget::updateTrayIcon()
|
||||||
|
|
||||||
Widget::~Widget()
|
Widget::~Widget()
|
||||||
{
|
{
|
||||||
qDebug() << "Deleting Widget";
|
qDebug() << "Widget: Deleting Widget";
|
||||||
AutoUpdater::abortUpdates();
|
AutoUpdater::abortUpdates();
|
||||||
icon->hide();
|
icon->hide();
|
||||||
hideMainForms();
|
hideMainForms();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user