mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-05 13:03:55 -07:00
Merge pull request #289 from acron0/auto-connect
Added 'auto connect' checkbox to connect dialog.
This commit is contained in:
commit
b5de708756
21 changed files with 471 additions and 333 deletions
|
|
@ -4,6 +4,8 @@
|
|||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDebug>
|
||||
#include <iostream>
|
||||
#include "dlg_connect.h"
|
||||
|
||||
DlgConnect::DlgConnect(QWidget *parent)
|
||||
|
|
@ -32,6 +34,19 @@ DlgConnect::DlgConnect(QWidget *parent)
|
|||
savePasswordCheckBox = new QCheckBox(tr("&Save password"));
|
||||
savePasswordCheckBox->setChecked(settings.value("save_password", 1).toInt());
|
||||
|
||||
autoConnectCheckBox = new QCheckBox(tr("A&uto connect at start"));
|
||||
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;
|
||||
grid->addWidget(hostLabel, 0, 0);
|
||||
grid->addWidget(hostEdit, 0, 1);
|
||||
|
|
@ -42,10 +57,11 @@ DlgConnect::DlgConnect(QWidget *parent)
|
|||
grid->addWidget(passwordLabel, 3, 0);
|
||||
grid->addWidget(passwordEdit, 3, 1);
|
||||
grid->addWidget(savePasswordCheckBox, 4, 0, 1, 2);
|
||||
grid->addWidget(autoConnectCheckBox, 5, 0, 1, 2);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
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;
|
||||
mainLayout->addLayout(grid);
|
||||
|
|
@ -57,6 +73,16 @@ DlgConnect::DlgConnect(QWidget *parent)
|
|||
setMinimumWidth(300);
|
||||
}
|
||||
|
||||
void DlgConnect::passwordSaved(int state)
|
||||
{
|
||||
if(savePasswordCheckBox->isChecked()) {
|
||||
autoConnectCheckBox->setEnabled(true);
|
||||
} else {
|
||||
autoConnectCheckBox->setChecked(0);
|
||||
autoConnectCheckBox->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void DlgConnect::actOk()
|
||||
{
|
||||
QSettings settings;
|
||||
|
|
@ -66,7 +92,19 @@ void DlgConnect::actOk()
|
|||
settings.setValue("playername", playernameEdit->text());
|
||||
settings.setValue("password", savePasswordCheckBox->isChecked() ? passwordEdit->text() : QString());
|
||||
settings.setValue("save_password", savePasswordCheckBox->isChecked() ? 1 : 0);
|
||||
settings.setValue("auto_connect", autoConnectCheckBox->isChecked() ? 1 : 0);
|
||||
settings.endGroup();
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
void DlgConnect::actCancel()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup("server");
|
||||
settings.setValue("save_password", savePasswordCheckBox->isChecked() ? 1 : 0);
|
||||
settings.setValue("auto_connect", autoConnectCheckBox->isChecked() ? 1 : 0);
|
||||
settings.endGroup();
|
||||
|
||||
reject();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@ public:
|
|||
QString getPassword() const { return passwordEdit->text(); }
|
||||
private slots:
|
||||
void actOk();
|
||||
void actCancel();
|
||||
void passwordSaved(int state);
|
||||
private:
|
||||
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel;
|
||||
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit;
|
||||
QCheckBox *savePasswordCheckBox;
|
||||
QCheckBox *savePasswordCheckBox, *autoConnectCheckBox;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ SettingsCache::SettingsCache()
|
|||
priceTagSource = settings->value("deckeditor/pricetagsource", 0).toInt();
|
||||
|
||||
ignoreUnregisteredUsers = settings->value("chat/ignore_unregistered", false).toBool();
|
||||
|
||||
attemptAutoConnect = settings->value("server/auto_connect", 0).toBool();
|
||||
}
|
||||
|
||||
void SettingsCache::setLang(const QString &_lang)
|
||||
|
|
@ -267,6 +269,12 @@ void SettingsCache::setMainWindowGeometry(const QByteArray &_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)
|
||||
{
|
||||
// test source && return if inexistent
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ private:
|
|||
bool ignoreUnregisteredUsers;
|
||||
QString picUrl;
|
||||
QString picUrlHq;
|
||||
bool attemptAutoConnect;
|
||||
public:
|
||||
SettingsCache();
|
||||
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
|
||||
|
|
@ -93,6 +94,7 @@ public:
|
|||
QString getPicUrl() const { return picUrl; }
|
||||
QString getPicUrlHq() const { return picUrlHq; }
|
||||
void copyPath(const QString &src, const QString &dst);
|
||||
bool getAutoConnect() const { return attemptAutoConnect; }
|
||||
public slots:
|
||||
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
|
||||
void setLang(const QString &_lang);
|
||||
|
|
@ -127,6 +129,7 @@ public slots:
|
|||
void setIgnoreUnregisteredUsers(bool _ignoreUnregisteredUsers);
|
||||
void setPicUrl(const QString &_picUrl);
|
||||
void setPicUrlHq(const QString &_picUrlHq);
|
||||
void setAutoConnect(const bool &_autoConnect);
|
||||
};
|
||||
|
||||
extern SettingsCache *settingsCache;
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ void MainWindow::createMenus()
|
|||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), localServer(0)
|
||||
: QMainWindow(parent), localServer(0), bHasActivated(false)
|
||||
{
|
||||
QPixmapCache::setCacheLimit(200000);
|
||||
|
||||
|
|
@ -417,5 +417,16 @@ void MainWindow::changeEvent(QEvent *event)
|
|||
{
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ private:
|
|||
QThread *clientThread;
|
||||
|
||||
LocalServer *localServer;
|
||||
bool bHasActivated;
|
||||
public:
|
||||
MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue