123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #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
- #error "OS specific"
- #endif
- p->start(exe);
- }
-
- void ConnectWidget::processFinished(int)
- {
- loadUsers();
- }
|