12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include "connectwidget.h"
- #include "ui_connectwidget.h"
-
- ConnectWidget::ConnectWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ConnectWidget)
- {
- ui->setupUi(this);
- connect(ui->btnConnect, SIGNAL(clicked()), this, SLOT(login()));
- connect(ui->btnManage, SIGNAL(clicked()), this, SLOT(launchUsrManager()));
- connect(ui->btnReload, SIGNAL(clicked()), this, SLOT(loadUsers()));
- loadUsers();
- if(ui->lineLogin->count() == 0)
- {
- QMessageBox* msg = new QMessageBox(this);
- msg->setIcon(QMessageBox::Question);
- msg->setWindowTitle("No logins available");
- msg->setText("No logins with socks are available.\nDo you want to open User Manager to create one?");
- connect(msg->addButton(QMessageBox::Yes), SIGNAL(clicked()), this, SLOT(launchUsrManager()));
- connect(msg->addButton(QMessageBox::No), SIGNAL(clicked()), this, SLOT(loadUsers()));
- msg->show();
- }
- }
-
- ConnectWidget::~ConnectWidget()
- {
- delete ui;
- }
-
- bool ConnectWidget::hasLogin(QString login)
- {
- for(int i = 0; i < ui->lineLogin->count(); ++i)
- if(ui->lineLogin->itemText(i) == login)
- return true;
- return false;
- }
-
- void ConnectWidget::nsStateChanged(NetSoul::State s)
- {
- ui->btnConnect->setEnabled(s == NetSoul::Disconnected || s == NetSoul::ProtocolError || s == NetSoul::NetworkError || s == NetSoul::BadLogin);
- ui->lineLogin->setEnabled(ui->btnConnect->isEnabled());
- }
-
- void ConnectWidget::login()
- {
- if(ui->lineLogin->count() > 0)
- emit loginRequested(qvariant_cast<EpiUser>(ui->lineLogin->itemData(ui->lineLogin->currentIndex())));
- }
-
- void ConnectWidget::loadUsers()
- {
- ui->lineLogin->clear();
- EpiUsers users = Epimafia::loadUsers();
- foreach(EpiUser user, users)
- if(!user.isUnknown() && user.hasLogin() && user.hasPwd_socks())
- ui->lineLogin->addItem(user.getLogin(), user.toVariant());
-
- QString login = Options::instance()->getDefaultLogin();
- for(int i = 0; i < ui->lineLogin->count(); ++i)
- if(ui->lineLogin->itemText(i) == login)
- {
- ui->lineLogin->setCurrentIndex(i);
- return;
- }
- }
-
- void ConnectWidget::launchUsrManager()
- {
- QProcess* p = new QProcess(this);
- connect(p, SIGNAL(finished(int)), this, SLOT(processFinished(int)));
- QString exe;
- #ifdef Q_OS_WIN
- exe = "usermgr.exe";
- #else
- #ifdef Q_OS_LINUX
- exe = "usermgr";
- #else
- #error "OS specific"
- #endif
- #endif
- p->start(exe);
- }
-
- void ConnectWidget::processFinished(int)
- {
- loadUsers();
- }
|