Added 'auto connect' checkbox to connect dialog. When the main window becomes active for the first time and auto connect is set to true, it will call connectToServer at that point.
This commit is contained in:
parent
6f319c8b63
commit
b381298981
6 changed files with 66 additions and 3 deletions
|
@ -4,6 +4,8 @@
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <iostream>
|
||||||
#include "dlg_connect.h"
|
#include "dlg_connect.h"
|
||||||
|
|
||||||
DlgConnect::DlgConnect(QWidget *parent)
|
DlgConnect::DlgConnect(QWidget *parent)
|
||||||
|
@ -32,6 +34,20 @@ DlgConnect::DlgConnect(QWidget *parent)
|
||||||
savePasswordCheckBox = new QCheckBox(tr("&Save password"));
|
savePasswordCheckBox = new QCheckBox(tr("&Save password"));
|
||||||
savePasswordCheckBox->setChecked(settings.value("save_password", 1).toInt());
|
savePasswordCheckBox->setChecked(settings.value("save_password", 1).toInt());
|
||||||
|
|
||||||
|
//autoConnectCheckBox = new QCheckBox(tr("A&uto connect at start"));
|
||||||
|
autoConnectCheckBox = new QCheckBox("A&uto connect at start"); // TODO needs tr()
|
||||||
|
if(savePasswordCheckBox->isChecked())
|
||||||
|
{
|
||||||
|
autoConnectCheckBox->setChecked(settings.value("auto_connect", 0).toInt());
|
||||||
|
autoConnectCheckBox->setEnabled(true);
|
||||||
|
} else {
|
||||||
|
settings.setValue("auto_connect", 0);
|
||||||
|
autoConnectCheckBox->setChecked(0);
|
||||||
|
autoConnectCheckBox->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(savePasswordCheckBox, SIGNAL(stateChanged(int)), this, SLOT(passwordSaved(int)));
|
||||||
|
|
||||||
QGridLayout *grid = new QGridLayout;
|
QGridLayout *grid = new QGridLayout;
|
||||||
grid->addWidget(hostLabel, 0, 0);
|
grid->addWidget(hostLabel, 0, 0);
|
||||||
grid->addWidget(hostEdit, 0, 1);
|
grid->addWidget(hostEdit, 0, 1);
|
||||||
|
@ -42,10 +58,11 @@ DlgConnect::DlgConnect(QWidget *parent)
|
||||||
grid->addWidget(passwordLabel, 3, 0);
|
grid->addWidget(passwordLabel, 3, 0);
|
||||||
grid->addWidget(passwordEdit, 3, 1);
|
grid->addWidget(passwordEdit, 3, 1);
|
||||||
grid->addWidget(savePasswordCheckBox, 4, 0, 1, 2);
|
grid->addWidget(savePasswordCheckBox, 4, 0, 1, 2);
|
||||||
|
grid->addWidget(autoConnectCheckBox, 5, 0, 1, 2);
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(actCancel()));
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addLayout(grid);
|
mainLayout->addLayout(grid);
|
||||||
|
@ -57,6 +74,17 @@ DlgConnect::DlgConnect(QWidget *parent)
|
||||||
setMinimumWidth(300);
|
setMinimumWidth(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgConnect::passwordSaved(int state)
|
||||||
|
{
|
||||||
|
if(!savePasswordCheckBox->isChecked())
|
||||||
|
{
|
||||||
|
autoConnectCheckBox->setChecked(0);
|
||||||
|
autoConnectCheckBox->setEnabled(false);
|
||||||
|
} else {
|
||||||
|
autoConnectCheckBox->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DlgConnect::actOk()
|
void DlgConnect::actOk()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
@ -66,7 +94,17 @@ void DlgConnect::actOk()
|
||||||
settings.setValue("playername", playernameEdit->text());
|
settings.setValue("playername", playernameEdit->text());
|
||||||
settings.setValue("password", savePasswordCheckBox->isChecked() ? passwordEdit->text() : QString());
|
settings.setValue("password", savePasswordCheckBox->isChecked() ? passwordEdit->text() : QString());
|
||||||
settings.setValue("save_password", savePasswordCheckBox->isChecked() ? 1 : 0);
|
settings.setValue("save_password", savePasswordCheckBox->isChecked() ? 1 : 0);
|
||||||
|
settings.setValue("auto_connect", autoConnectCheckBox->isChecked() ? 1 : 0);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgConnect::actCancel()
|
||||||
|
{
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup("server");
|
||||||
|
settings.setValue("auto_connect", autoConnectCheckBox->isChecked() ? 1 : 0);
|
||||||
|
settings.endGroup();
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
|
|
@ -18,10 +18,12 @@ public:
|
||||||
QString getPassword() const { return passwordEdit->text(); }
|
QString getPassword() const { return passwordEdit->text(); }
|
||||||
private slots:
|
private slots:
|
||||||
void actOk();
|
void actOk();
|
||||||
|
void actCancel();
|
||||||
|
void passwordSaved(int state);
|
||||||
private:
|
private:
|
||||||
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel;
|
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel;
|
||||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit;
|
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit;
|
||||||
QCheckBox *savePasswordCheckBox;
|
QCheckBox *savePasswordCheckBox, *autoConnectCheckBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -48,6 +48,8 @@ SettingsCache::SettingsCache()
|
||||||
priceTagSource = settings->value("deckeditor/pricetagsource", 0).toInt();
|
priceTagSource = settings->value("deckeditor/pricetagsource", 0).toInt();
|
||||||
|
|
||||||
ignoreUnregisteredUsers = settings->value("chat/ignore_unregistered", false).toBool();
|
ignoreUnregisteredUsers = settings->value("chat/ignore_unregistered", false).toBool();
|
||||||
|
|
||||||
|
attemptAutoConnect = settings->value("server/auto_connect", 0).toInt() == 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsCache::setLang(const QString &_lang)
|
void SettingsCache::setLang(const QString &_lang)
|
||||||
|
@ -267,6 +269,12 @@ void SettingsCache::setMainWindowGeometry(const QByteArray &_mainWindowGeometry)
|
||||||
settings->setValue("interface/main_window_geometry", mainWindowGeometry);
|
settings->setValue("interface/main_window_geometry", mainWindowGeometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsCache::setAutoConnect(const bool &_autoConnect)
|
||||||
|
{
|
||||||
|
attemptAutoConnect = _autoConnect;
|
||||||
|
settings->value("server/auto_connect", attemptAutoConnect ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsCache::copyPath(const QString &src, const QString &dst)
|
void SettingsCache::copyPath(const QString &src, const QString &dst)
|
||||||
{
|
{
|
||||||
// test source && return if inexistent
|
// test source && return if inexistent
|
||||||
|
|
|
@ -57,6 +57,7 @@ private:
|
||||||
bool ignoreUnregisteredUsers;
|
bool ignoreUnregisteredUsers;
|
||||||
QString picUrl;
|
QString picUrl;
|
||||||
QString picUrlHq;
|
QString picUrlHq;
|
||||||
|
bool attemptAutoConnect;
|
||||||
public:
|
public:
|
||||||
SettingsCache();
|
SettingsCache();
|
||||||
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
|
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
|
||||||
|
@ -93,6 +94,7 @@ public:
|
||||||
QString getPicUrl() const { return picUrl; }
|
QString getPicUrl() const { return picUrl; }
|
||||||
QString getPicUrlHq() const { return picUrlHq; }
|
QString getPicUrlHq() const { return picUrlHq; }
|
||||||
void copyPath(const QString &src, const QString &dst);
|
void copyPath(const QString &src, const QString &dst);
|
||||||
|
bool getAutoConnect() const { return attemptAutoConnect; }
|
||||||
public slots:
|
public slots:
|
||||||
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
|
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
|
||||||
void setLang(const QString &_lang);
|
void setLang(const QString &_lang);
|
||||||
|
@ -127,6 +129,7 @@ public slots:
|
||||||
void setIgnoreUnregisteredUsers(bool _ignoreUnregisteredUsers);
|
void setIgnoreUnregisteredUsers(bool _ignoreUnregisteredUsers);
|
||||||
void setPicUrl(const QString &_picUrl);
|
void setPicUrl(const QString &_picUrl);
|
||||||
void setPicUrlHq(const QString &_picUrlHq);
|
void setPicUrlHq(const QString &_picUrlHq);
|
||||||
|
void setAutoConnect(const bool &_autoConnect);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SettingsCache *settingsCache;
|
extern SettingsCache *settingsCache;
|
||||||
|
|
|
@ -359,7 +359,7 @@ void MainWindow::createMenus()
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent), localServer(0)
|
: QMainWindow(parent), localServer(0), bHasActivated(false)
|
||||||
{
|
{
|
||||||
QPixmapCache::setCacheLimit(200000);
|
QPixmapCache::setCacheLimit(200000);
|
||||||
|
|
||||||
|
@ -417,5 +417,16 @@ void MainWindow::changeEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::LanguageChange)
|
if (event->type() == QEvent::LanguageChange)
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
else if(event->type() == QEvent::ActivationChange) {
|
||||||
|
if(isActiveWindow() && !bHasActivated){
|
||||||
|
bHasActivated = true;
|
||||||
|
if(settingsCache->getAutoConnect()) {
|
||||||
|
qDebug() << "Attempting auto-connect...";
|
||||||
|
DlgConnect dlg(this);
|
||||||
|
client->connectToServer(dlg.getHost(), dlg.getPort(), dlg.getPlayerName(), dlg.getPassword());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QMainWindow::changeEvent(event);
|
QMainWindow::changeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ private:
|
||||||
QThread *clientThread;
|
QThread *clientThread;
|
||||||
|
|
||||||
LocalServer *localServer;
|
LocalServer *localServer;
|
||||||
|
bool bHasActivated;
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = 0);
|
MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
Loading…
Reference in a new issue