mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Cleanup 331baa7447
This commit is contained in:
parent
148f7e6b1b
commit
830f0ddc13
|
@ -21,6 +21,7 @@
|
||||||
#include "src/misc/settings.h"
|
#include "src/misc/settings.h"
|
||||||
#include "src/widget/croppinglabel.h"
|
#include "src/widget/croppinglabel.h"
|
||||||
#include "src/widget/widget.h"
|
#include "src/widget/widget.h"
|
||||||
|
#include "src/widget/gui.h"
|
||||||
#include "src/historykeeper.h"
|
#include "src/historykeeper.h"
|
||||||
#include "src/misc/style.h"
|
#include "src/misc/style.h"
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
@ -151,7 +152,7 @@ void IdentityForm::onRenameClicked()
|
||||||
name = Core::sanitize(name);
|
name = Core::sanitize(name);
|
||||||
QDir dir(Settings::getSettingsDirPath());
|
QDir dir(Settings::getSettingsDirPath());
|
||||||
QString file = dir.filePath(name+Core::TOX_EXT);
|
QString file = dir.filePath(name+Core::TOX_EXT);
|
||||||
if (!QFile::exists(file) || Widget::getInstance()->askQuestion(tr("Profile already exists", "rename confirm title"),
|
if (!QFile::exists(file) || GUI::askQuestion(tr("Profile already exists", "rename confirm title"),
|
||||||
tr("A profile named \"%1\" already exists. Do you want to erase it?", "rename confirm text").arg(cur)))
|
tr("A profile named \"%1\" already exists. Do you want to erase it?", "rename confirm text").arg(cur)))
|
||||||
{
|
{
|
||||||
QFile::rename(dir.filePath(cur+Core::TOX_EXT), file);
|
QFile::rename(dir.filePath(cur+Core::TOX_EXT), file);
|
||||||
|
@ -197,7 +198,7 @@ void IdentityForm::onDeleteClicked()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Widget::getInstance()->askQuestion(tr("Deletion imminent!","deletion confirmation title"),
|
if (GUI::askQuestion(tr("Deletion imminent!","deletion confirmation title"),
|
||||||
tr("Are you sure you want to delete this profile?","deletion confirmation text")))
|
tr("Are you sure you want to delete this profile?","deletion confirmation text")))
|
||||||
{
|
{
|
||||||
QString profile = bodyUI->profiles->currentText();
|
QString profile = bodyUI->profiles->currentText();
|
||||||
|
@ -236,7 +237,7 @@ void IdentityForm::onImportClicked()
|
||||||
|
|
||||||
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(tr("Profile already exists", "import confirm title"),
|
if (QFileInfo(profilePath).exists() && !GUI::askQuestion(tr("Profile already exists", "import confirm title"),
|
||||||
tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile)))
|
tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "src/historykeeper.h"
|
#include "src/historykeeper.h"
|
||||||
#include "src/core.h"
|
#include "src/core.h"
|
||||||
#include "src/widget/widget.h"
|
#include "src/widget/widget.h"
|
||||||
|
#include "src/widget/gui.h"
|
||||||
#include "src/widget/form/setpassworddialog.h"
|
#include "src/widget/form/setpassworddialog.h"
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -106,14 +107,14 @@ bool PrivacyForm::setChatLogsPassword()
|
||||||
if (haveEncHist)
|
if (haveEncHist)
|
||||||
{
|
{
|
||||||
Widget::getInstance()->reloadHistory();
|
Widget::getInstance()->reloadHistory();
|
||||||
Widget::getInstance()->showWarningMsgBox(tr("Successfully decrypted old chat history","popup title"), tr("You have succesfully decrypted the old chat history, and it has been added to your current history and re-encrypted.", "popup text"));
|
GUI::showWarning(tr("Successfully decrypted old chat history","popup title"), tr("You have succesfully decrypted the old chat history, and it has been added to your current history and re-encrypted.", "popup text"));
|
||||||
}
|
}
|
||||||
delete dialog;
|
delete dialog;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!Widget::getInstance()->askQuestion(tr("Old encrypted chat history", "popup title"), tr("There is currently an unused encrypted chat history, but the password you just entered doesn't match.\nWould you like to try again?\nCanceling will delete the old history and set the password to what you just entered.", "This happens when enabling encryption after previously \"Disabling History\""), true, true))
|
if (!GUI::askQuestion(tr("Old encrypted chat history", "popup title"), tr("There is currently an unused encrypted chat history, but the password you just entered doesn't match.\nWould you like to try again?\nCanceling will delete the old history and set the password to what you just entered.", "This happens when enabling encryption after previously \"Disabling History\""), true, true))
|
||||||
haveEncHist = false; // logically this is really just a `break`, but conceptually this is more accurate
|
haveEncHist = false; // logically this is really just a `break`, but conceptually this is more accurate
|
||||||
}
|
}
|
||||||
} while (haveEncHist);
|
} while (haveEncHist);
|
||||||
|
@ -237,7 +238,7 @@ void PrivacyForm::onEncryptToxUpdated()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!Widget::getInstance()->askQuestion(tr("Decrypt your data file", "title"), tr("Would you like to decrypt your data file?")))
|
if (!GUI::askQuestion(tr("Decrypt your data file", "title"), tr("Would you like to decrypt your data file?")))
|
||||||
{
|
{
|
||||||
bodyUI->cbEncryptTox->setChecked(true);
|
bodyUI->cbEncryptTox->setChecked(true);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1122,134 +1122,6 @@ void Widget::onSplitterMoved(int pos, int index)
|
||||||
saveSplitterGeometry();
|
saveSplitterGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::showWarningMsgBox(const QString& title, const QString& msg)
|
|
||||||
{
|
|
||||||
// We can only display widgets from the GUI thread
|
|
||||||
if (QThread::currentThread() != qApp->thread())
|
|
||||||
{
|
|
||||||
QMetaObject::invokeMethod(this, "showWarningMsgBox", Qt::BlockingQueuedConnection,
|
|
||||||
Q_ARG(const QString&, title), Q_ARG(const QString&, msg));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::warning(this, title, msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Widget::setEnabledThreadsafe(bool enabled)
|
|
||||||
{
|
|
||||||
// We can only do this from the GUI thread
|
|
||||||
if (QThread::currentThread() != qApp->thread())
|
|
||||||
{
|
|
||||||
QMetaObject::invokeMethod(this, "setEnabledThreadsafe", Qt::BlockingQueuedConnection,
|
|
||||||
Q_ARG(bool, enabled));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return setEnabled(enabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Widget::askQuestion(const QString& title, const QString& msg, bool defaultAns, bool warning)
|
|
||||||
{
|
|
||||||
// We can only display widgets from the GUI thread
|
|
||||||
if (QThread::currentThread() != qApp->thread())
|
|
||||||
{
|
|
||||||
bool ret;
|
|
||||||
QMetaObject::invokeMethod(this, "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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (warning)
|
|
||||||
{
|
|
||||||
QMessageBox::StandardButton def = QMessageBox::Cancel;
|
|
||||||
if (defaultAns)
|
|
||||||
def = QMessageBox::Ok;
|
|
||||||
return QMessageBox::warning(this, title, msg, QMessageBox::Ok | QMessageBox::Cancel, def) == QMessageBox::Ok;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::StandardButton def = QMessageBox::No;
|
|
||||||
if (defaultAns)
|
|
||||||
def = QMessageBox::Yes;
|
|
||||||
return QMessageBox::question(this, title, msg, QMessageBox::Yes | QMessageBox::No, def) == QMessageBox::Yes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Widget::passwordDialog(const QString& cancel, const QString& body)
|
|
||||||
{
|
|
||||||
// We can only display widgets from the GUI thread
|
|
||||||
if (QThread::currentThread() != qApp->thread())
|
|
||||||
{
|
|
||||||
QString ret;
|
|
||||||
QMetaObject::invokeMethod(this, "passwordDialog", Qt::BlockingQueuedConnection,
|
|
||||||
Q_RETURN_ARG(QString, ret),
|
|
||||||
Q_ARG(const QString&, cancel), Q_ARG(const QString&, body));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 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:"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Widget::clearAllReceipts()
|
void Widget::clearAllReceipts()
|
||||||
{
|
{
|
||||||
QList<Friend*> frnds = FriendList::getAllFriends();
|
QList<Friend*> frnds = FriendList::getAllFriends();
|
||||||
|
|
|
@ -62,11 +62,6 @@ public:
|
||||||
void clearContactsList();
|
void clearContactsList();
|
||||||
void setTranslation();
|
void setTranslation();
|
||||||
void updateTrayIcon();
|
void updateTrayIcon();
|
||||||
Q_INVOKABLE void showWarningMsgBox(const QString& title, const QString& msg);
|
|
||||||
Q_INVOKABLE void setEnabledThreadsafe(bool enabled);
|
|
||||||
Q_INVOKABLE bool askQuestion(const QString& title, const QString& msg, bool defaultAns = false, bool warning = true);
|
|
||||||
Q_INVOKABLE QString passwordDialog(const QString& cancel, const QString& body);
|
|
||||||
// hooray for threading hacks
|
|
||||||
~Widget();
|
~Widget();
|
||||||
|
|
||||||
virtual void closeEvent(QCloseEvent *event);
|
virtual void closeEvent(QCloseEvent *event);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user