~ubuntu-branches/ubuntu/raring/mumble/raring

« back to all changes in this revision

Viewing changes to src/mumble/ConnectDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thorvald Natvig, Patrick Matthäi, Thorvald Natvig
  • Date: 2011-02-19 22:58:58 UTC
  • mfrom: (9.1.15 sid)
  • Revision ID: james.westby@ubuntu.com-20110219225858-0xlftrf4z1z4jt9e
Tags: 1.2.3-1
[ Patrick Matthäi ]
* Do not build with non existant libpulse-dev on hurd-i386.

[ Thorvald Natvig ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "ServerHandler.h"
34
34
#include "Channel.h"
35
35
#include "Database.h"
 
36
#include "NetworkConfig.h"
36
37
 
37
38
QMap<QString, QIcon> ServerItem::qmIcons;
38
39
QList<PublicInfo> ConnectDialog::qlPublicServers;
99
100
 
100
101
ServerView::~ServerView() {
101
102
        delete siFavorite;
102
 
        if (siLAN)
103
 
                delete siLAN;
 
103
        delete siLAN;
104
104
        delete siPublic;
105
105
}
106
106
 
274
274
        init();
275
275
}
276
276
 
277
 
ServerItem::ServerItem(const QString &name, const QString &host, unsigned short port, const QString &username) : QTreeWidgetItem(QTreeWidgetItem::UserType) {
 
277
ServerItem::ServerItem(const QString &name, const QString &host, unsigned short port, const QString &username, const QString &password) : QTreeWidgetItem(QTreeWidgetItem::UserType) {
278
278
        siParent = NULL;
279
279
        bParent = false;
280
280
        itType = FavoriteType;
281
281
        qsName = name;
282
282
        usPort = port;
283
283
        qsUsername = username;
 
284
        qsPassword = password;
 
285
 
284
286
        bCA = false;
285
287
 
286
288
        if (host.startsWith(QLatin1Char('@'))) {
407
409
        if (! url.hasQueryItem(QLatin1String("title")))
408
410
                url.addQueryItem(QLatin1String("title"), url.host());
409
411
 
410
 
        ServerItem *si = new ServerItem(url.queryItemValue(QLatin1String("title")), url.host(), static_cast<unsigned short>(url.port()), url.userName());
411
 
        if (! url.password().isEmpty())
412
 
                si->qsPassword = url.password();
 
412
        ServerItem *si = new ServerItem(url.queryItemValue(QLatin1String("title")), url.host(), static_cast<unsigned short>(url.port()), url.userName(), url.password());
413
413
 
414
414
        if (url.hasQueryItem(QLatin1String("url")))
415
415
                si->qsUrl = url.queryItemValue(QLatin1String("url"));
678
678
        return qmIcons.value(name);
679
679
}
680
680
 
681
 
ConnectDialogEdit::ConnectDialogEdit(QWidget *p, const QString &name, const QString &host, const QString &user, unsigned short port) : QDialog(p) {
 
681
ConnectDialogEdit::ConnectDialogEdit(QWidget *p, const QString &name, const QString &host, const QString &user, unsigned short port, const QString &password, bool add) : QDialog(p) {
682
682
        setupUi(this);
 
683
        if (add)
 
684
                setWindowTitle(tr("Add Server"));
 
685
 
683
686
        qlePort->setValidator(new QIntValidator(1, 65535, qlePort));
684
687
 
685
688
        qleName->setText(name);
686
689
        qleServer->setText(host);
687
690
        qleUsername->setText(user.isEmpty() ? g.s.qsUsername : user);
688
691
        qlePort->setText(QString::number(port));
 
692
        qlePassword->setEchoMode(QLineEdit::Password);
 
693
        qlePassword->setText(password);
689
694
 
690
695
        usPort = 0;
691
696
        bOk = true;
694
699
        connect(qleServer, SIGNAL(textChanged(const QString &)), this, SLOT(validate()));
695
700
        connect(qlePort, SIGNAL(textChanged(const QString &)), this, SLOT(validate()));
696
701
        connect(qleUsername, SIGNAL(textChanged(const QString &)), this, SLOT(validate()));
 
702
        connect(qlePassword, SIGNAL(textChanged(const QString &)), this, SLOT(validate()));
697
703
 
698
704
        validate();
699
705
}
703
709
        qsHostname = qleServer->text().simplified();
704
710
        usPort = qlePort->text().toUShort();
705
711
        qsUsername = qleUsername->text().simplified();
 
712
        qsPassword = qlePassword->text();
 
713
 
 
714
        // For bonjour hosts disable the port field as it's auto-detected
 
715
        qlePort->setDisabled(!qsHostname.isEmpty() && qsHostname.startsWith(QLatin1Char('@')));
 
716
 
 
717
        // For SuperUser show password edit
 
718
        if (qsUsername == QLatin1String("SuperUser")) {
 
719
                qliPassword->setVisible(true);
 
720
                qlePassword->setVisible(true);
 
721
                qcbShowPassword->setVisible(true);
 
722
                adjustSize();
 
723
        } else if (qsPassword.isEmpty()) {
 
724
                qliPassword->setVisible(false);
 
725
                qlePassword->setVisible(false);
 
726
                qcbShowPassword->setVisible(false);
 
727
                adjustSize();
 
728
        }
706
729
 
707
730
        bOk = ! qsName.isEmpty() && ! qsHostname.isEmpty() && ! qsUsername.isEmpty() && usPort;
708
731
        qdbbButtonBox->button(QDialogButtonBox::Ok)->setEnabled(bOk);
714
737
                QDialog::accept();
715
738
}
716
739
 
717
 
void ConnectDialogEdit::on_qleServer_textChanged(const QString &text) {
718
 
        qlePort->setDisabled(!text.isEmpty() && text.startsWith(QLatin1Char('@')));
 
740
void ConnectDialogEdit::on_qcbShowPassword_toggled(bool checked) {
 
741
        qlePassword->setEchoMode(checked ? QLineEdit::Normal : QLineEdit::Password);
719
742
}
720
743
 
721
 
ConnectDialog::ConnectDialog(QWidget *p) : QDialog(p) {
 
744
ConnectDialog::ConnectDialog(QWidget *p, bool autoconnect) : QDialog(p), bAutoConnect(autoconnect) {
722
745
        setupUi(this);
723
746
#ifdef Q_OS_MAC
724
747
        setWindowModality(Qt::WindowModal);
725
748
#endif
726
749
        bPublicInit = false;
727
750
 
 
751
        siAutoConnect = NULL;
 
752
 
728
753
        if (tPublicServers.elapsed() >= 60 * 24 * 1000000ULL) {
729
754
                qlPublicServers.clear();
730
755
        }
851
876
 
852
877
void ConnectDialog::accept() {
853
878
        ServerItem *si = static_cast<ServerItem *>(qtwServers->currentItem());
854
 
        if (! si || si->qlAddresses.isEmpty() || si->qsHostname.isEmpty())
 
879
        if (! si || si->qlAddresses.isEmpty() || si->qsHostname.isEmpty()) {
 
880
                qWarning() << "Sad panda";
855
881
                return;
 
882
        }
856
883
 
857
884
        qsPassword = si->qsPassword;
858
885
        qsServer = si->qsHostname;
900
927
        QString name;
901
928
        unsigned short port = 64738;
902
929
 
903
 
        if (g.sh && g.sh->isRunning()) {
904
 
                g.sh->getConnectionInfo(host, port, user, pw);
905
 
                Channel *c = Channel::get(0);
906
 
                if (c) {
907
 
                        if (c->qsName != QLatin1String("Root"))
908
 
                                name = c->qsName;
 
930
        // Try to fill out fields if possible
 
931
        {
 
932
                ServerItem *si = ServerItem::fromMimeData(QApplication::clipboard()->mimeData());
 
933
                if (si) {
 
934
                        // If there is server information in the clipboard assume user wants to add it
 
935
                        name = si->qsName;
 
936
 
 
937
                        if (! si->qsBonjourHost.isEmpty())
 
938
                                host = QLatin1Char('@') + si->qsBonjourHost;
 
939
                        else
 
940
                                host = si->qsHostname;
 
941
 
 
942
                        port = si->usPort;
 
943
                        pw = si->qsPassword;
 
944
                } else {
 
945
                        // If connected to a server assume the user wants to add it
 
946
                        if (g.sh && g.sh->isRunning()) {
 
947
                                g.sh->getConnectionInfo(host, port, user, pw);
 
948
                                Channel *c = Channel::get(0);
 
949
                                if (c) {
 
950
                                        if (c->qsName != QLatin1String("Root"))
 
951
                                                name = c->qsName;
 
952
                                }
 
953
                        } else
 
954
                                user = g.s.qsUsername;
909
955
                }
910
 
        } else
911
 
                user = g.s.qsUsername;
 
956
        }
912
957
 
913
 
        ConnectDialogEdit *cde = new ConnectDialogEdit(this, name, host, user, port);
 
958
        ConnectDialogEdit *cde = new ConnectDialogEdit(this, name, host, user, port, pw, true);
914
959
 
915
960
        if (cde->exec() == QDialog::Accepted) {
916
 
                ServerItem *si = new ServerItem(cde->qsName, cde->qsHostname, cde->usPort, cde->qsUsername);
 
961
                ServerItem *si = new ServerItem(cde->qsName, cde->qsHostname, cde->usPort, cde->qsUsername, cde->qsPassword);
917
962
                qlItems << si;
918
963
                qtwServers->siFavorite->addServerItem(si);
919
964
                qtwServers->setCurrentItem(si);
933
978
        else
934
979
                host = si->qsHostname;
935
980
 
936
 
        ConnectDialogEdit *cde = new ConnectDialogEdit(this, si->qsName, host, si->qsUsername, si->usPort);
 
981
        ConnectDialogEdit *cde = new ConnectDialogEdit(this, si->qsName, host, si->qsUsername, si->usPort, si->qsPassword);
937
982
 
938
983
        if (cde->exec() == QDialog::Accepted) {
939
984
 
940
985
                si->qsName = cde->qsName;
941
986
                si->qsUsername = cde->qsUsername;
 
987
                si->qsPassword = cde->qsPassword;
942
988
                if ((cde->qsHostname != host) || (cde->usPort != si->usPort)) {
943
989
                        stopDns(si);
944
990
 
1073
1119
        url.setPath(QLatin1String("/list2.cgi"));
1074
1120
        url.addQueryItem(QLatin1String("version"), QLatin1String(MUMTEXT(MUMBLE_VERSION_STRING)));
1075
1121
 
1076
 
        QNetworkRequest req(url);
1077
 
        QNetworkReply *rep = g.nam->get(req);
 
1122
        QNetworkReply *rep = Network::get(url);
1078
1123
        connect(rep, SIGNAL(finished()), this, SLOT(finished()));
1079
1124
}
1080
1125
 
1178
1223
                if (!items.isEmpty()) {
1179
1224
                        bLastFound = true;
1180
1225
                        qtwServers->setCurrentItem(items.at(0));
 
1226
                        if (g.s.bAutoConnect && bAutoConnect) {
 
1227
                                siAutoConnect = static_cast<ServerItem *>(items.at(0));
 
1228
                                if (! siAutoConnect->qlAddresses.isEmpty()) {
 
1229
                                        accept();
 
1230
                                        return;
 
1231
                                }
 
1232
                        }
1181
1233
                }
1182
1234
        }
1183
1235
 
1334
1386
                        qhPings[addr].insert(si);
1335
1387
                }
1336
1388
 
1337
 
                if (si == qtwServers->currentItem())
 
1389
                if (si == qtwServers->currentItem()) {
1338
1390
                        on_qtwServers_currentItemChanged(si, si);
 
1391
                        if (si == siAutoConnect)
 
1392
                                accept();
 
1393
                }
1339
1394
        }
1340
1395
 
1341
1396
        qhDNSWait.remove(host);
1384
1439
 
1385
1440
                qint64 len = sock->readDatagram(blob+4, 24, &host, &port);
1386
1441
                if (len == 24) {
 
1442
                        if (host.scopeId() == QLatin1String("0"))
 
1443
                                host.setScopeId(QLatin1String(""));
 
1444
 
1387
1445
                        qpAddress address(host, port);
1388
1446
                        if (qhPings.contains(address)) {
1389
1447
                                quint32 *ping = reinterpret_cast<quint32 *>(blob+4);
1420
1478
                QUrl url = rep->request().url();
1421
1479
                if (url.host() == g.qsRegionalHost) {
1422
1480
                        url.setHost(QLatin1String("mumble.info"));
1423
 
                        QNetworkRequest req(url);
1424
 
                        QNetworkReply *nrep = g.nam->get(req);
 
1481
                        QNetworkReply *nrep = Network::get(url);
1425
1482
                        connect(nrep, SIGNAL(finished()), this, SLOT(finished()));
1426
1483
 
1427
1484
                        rep->deleteLater();