Merge pull request #157 from wengxt/wengxt-patch-1
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 22 Nov 2015 22:26:52 +0000 (23:26 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 22 Nov 2015 22:26:52 +0000 (23:26 +0100)
Fix SSL detection

13 files changed:
src/core/core.cpp
src/core/core.h
src/core/corenetwork.cpp
src/core/coreuserinputhandler.cpp
src/core/postgresqlstorage.cpp
src/core/sqlitestorage.cpp
src/qtui/mainpage.cpp
src/qtui/mainpage.h
src/qtui/mainwin.cpp
src/qtui/nicklistwidget.cpp
src/qtui/nicklistwidget.h
src/qtui/sslinfodlg.cpp
src/qtui/ui/sslinfodlg.ui

index 2049b63..e57a764 100644 (file)
@@ -198,13 +198,13 @@ void Core::init()
     }
 
     if (Quassel::isOptionSet("add-user")) {
-        createUser();
-        exit(0);
+        exit(createUser() ? EXIT_SUCCESS : EXIT_FAILURE);
+
     }
 
     if (Quassel::isOptionSet("change-userpass")) {
-        changeUserPass(Quassel::optionValue("change-userpass"));
-        exit(0);
+        exit(changeUserPass(Quassel::optionValue("change-userpass")) ?
+                       EXIT_SUCCESS : EXIT_FAILURE);
     }
 
     connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
@@ -739,7 +739,7 @@ bool Core::selectBackend(const QString &backend)
 }
 
 
-void Core::createUser()
+bool Core::createUser()
 {
     QTextStream out(stdout);
     QTextStream in(stdin);
@@ -761,30 +761,32 @@ void Core::createUser()
 
     if (password != password2) {
         qWarning() << "Passwords don't match!";
-        return;
+        return false;
     }
     if (password.isEmpty()) {
         qWarning() << "Password is empty!";
-        return;
+        return false;
     }
 
     if (_configured && _storage->addUser(username, password).isValid()) {
         out << "Added user " << username << " successfully!" << endl;
+        return true;
     }
     else {
         qWarning() << "Unable to add user:" << qPrintable(username);
+        return false;
     }
 }
 
 
-void Core::changeUserPass(const QString &username)
+bool Core::changeUserPass(const QString &username)
 {
     QTextStream out(stdout);
     QTextStream in(stdin);
     UserId userId = _storage->getUserId(username);
     if (!userId.isValid()) {
         out << "User " << username << " does not exist." << endl;
-        return;
+        return false;
     }
 
     out << "Change password for user: " << username << endl;
@@ -802,18 +804,20 @@ void Core::changeUserPass(const QString &username)
 
     if (password != password2) {
         qWarning() << "Passwords don't match!";
-        return;
+        return false;
     }
     if (password.isEmpty()) {
         qWarning() << "Password is empty!";
-        return;
+        return false;
     }
 
     if (_configured && _storage->updateUser(userId, password)) {
         out << "Password changed successfully!" << endl;
+        return true;
     }
     else {
         qWarning() << "Failed to change password!";
+        return false;
     }
 }
 
index e356a0f..aab2b84 100644 (file)
@@ -533,7 +533,7 @@ private slots:
     void socketError(QAbstractSocket::SocketError err, const QString &errorString);
     void setupClientSession(RemotePeer *, UserId);
 
-    void changeUserPass(const QString &username);
+    bool changeUserPass(const QString &username);
 
 private:
     Core();
@@ -551,7 +551,7 @@ private:
     void unregisterStorageBackends();
     void unregisterStorageBackend(Storage *);
     bool selectBackend(const QString &backend);
-    void createUser();
+    bool createUser();
     void saveBackendSettings(const QString &backend, const QVariantMap &settings);
     QVariantMap promptForSettings(const Storage *storage);
 
index 942e32f..c42325f 100644 (file)
@@ -81,7 +81,7 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session)
     connect(this, SIGNAL(newEvent(Event *)), coreSession()->eventManager(), SLOT(postEvent(Event *)));
 
     if (Quassel::isOptionSet("oidentd")) {
-        connect(this, SIGNAL(socketOpen(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)), Core::instance()->oidentdConfigGenerator(), SLOT(addSocket(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)), Qt::BlockingQueuedConnection);
+        connect(this, SIGNAL(socketInitialized(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)), Core::instance()->oidentdConfigGenerator(), SLOT(addSocket(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)), Qt::BlockingQueuedConnection);
         connect(this, SIGNAL(socketDisconnected(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)), Core::instance()->oidentdConfigGenerator(), SLOT(removeSocket(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)));
     }
 }
index 7887a92..73aac48 100644 (file)
@@ -228,7 +228,7 @@ void CoreUserInputHandler::doMode(const BufferInfo &bufferInfo, const QChar& add
     if (!isNumber || maxModes == 0) maxModes = 1;
 
     QStringList nickList;
-    if (nicks == "*") { // All users in channel
+    if (nicks == "*" && bufferInfo.type() == BufferInfo::ChannelBuffer) { // All users in channel
         const QList<IrcUser*> users = network()->ircChannel(bufferInfo.bufferName())->ircUsers();
         foreach(IrcUser *user, users) {
             if ((addOrRemove == '+' && !network()->ircChannel(bufferInfo.bufferName())->userModes(user).contains(mode))
index b16f4b0..65460df 100644 (file)
@@ -944,7 +944,7 @@ void PostgreSqlStorage::setChannelPersistent(UserId user, const NetworkId &netwo
     QSqlQuery query(logDb());
     query.prepare(queryString("update_buffer_persistent_channel"));
     query.bindValue(":userid", user.toInt());
-    query.bindValue(":networkId", networkId.toInt());
+    query.bindValue(":networkid", networkId.toInt());
     query.bindValue(":buffercname", channel.toLower());
     query.bindValue(":joined", isJoined);
     safeExec(query);
@@ -957,7 +957,7 @@ void PostgreSqlStorage::setPersistentChannelKey(UserId user, const NetworkId &ne
     QSqlQuery query(logDb());
     query.prepare(queryString("update_buffer_set_channel_key"));
     query.bindValue(":userid", user.toInt());
-    query.bindValue(":networkId", networkId.toInt());
+    query.bindValue(":networkid", networkId.toInt());
     query.bindValue(":buffercname", channel.toLower());
     query.bindValue(":key", key);
     safeExec(query);
index 46e2c70..354b340 100644 (file)
@@ -968,7 +968,7 @@ void SqliteStorage::setChannelPersistent(UserId user, const NetworkId &networkId
         QSqlQuery query(db);
         query.prepare(queryString("update_buffer_persistent_channel"));
         query.bindValue(":userid", user.toInt());
-        query.bindValue(":networkId", networkId.toInt());
+        query.bindValue(":networkid", networkId.toInt());
         query.bindValue(":buffercname", channel.toLower());
         query.bindValue(":joined", isJoined ? 1 : 0);
 
@@ -990,7 +990,7 @@ void SqliteStorage::setPersistentChannelKey(UserId user, const NetworkId &networ
         QSqlQuery query(db);
         query.prepare(queryString("update_buffer_set_channel_key"));
         query.bindValue(":userid", user.toInt());
-        query.bindValue(":networkId", networkId.toInt());
+        query.bindValue(":networkid", networkId.toInt());
         query.bindValue(":buffercname", channel.toLower());
         query.bindValue(":key", key);
 
index 82387ab..4838e25 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
+#include <QPushButton>
 #include <QImage>
+#include <QLabel>
+#include <QLayout>
 #include <QPainter>
 
 #include "mainpage.h"
+#include "coreconnectdlg.h"
+#include "client.h"
 
 MainPage::MainPage(QWidget *parent) : QWidget(parent)
 {
-}
-
-
-void MainPage::paintEvent(QPaintEvent *event)
-{
-    Q_UNUSED(event);
+    QVBoxLayout *layout = new QVBoxLayout(this);
+    layout->setAlignment(Qt::AlignCenter);
+    QLabel *label = new QLabel(this);
+    label->setPixmap(QPixmap(":/pics/quassel-logo.png"));
+    layout->addWidget(label);
 
-    QPainter painter(this);
-    QImage img(":/pics/quassel-logo.png"); // FIXME load externally
+    if (Quassel::runMode() != Quassel::Monolithic) {
+        _connectButton = new QPushButton(QIcon::fromTheme("network-connect"), tr("Connect to Core..."));
+        _connectButton->setEnabled(Client::coreConnection()->state() == CoreConnection::Disconnected);
 
-    if (img.height() > height() || img.width() > width())
-        img = img.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
+        connect(Client::coreConnection(), SIGNAL(stateChanged(CoreConnection::ConnectionState)), this, SLOT(coreConnectionStateChanged()));
+        connect(_connectButton, SIGNAL(clicked(bool)), this, SLOT(showCoreConnectionDlg()));
+        layout->addWidget(_connectButton);
+    }
+}
 
-    int xmargin = (width() - img.width()) / 2;
-    int ymargin = (height() - img.height()) / 2;
+void MainPage::showCoreConnectionDlg()
+{
+    CoreConnectDlg dlg(this);
+    if (dlg.exec() == QDialog::Accepted) {
+        AccountId accId = dlg.selectedAccount();
+        if (accId.isValid())
+            Client::coreConnection()->connectToCore(accId);
+    }
+}
 
-    painter.drawImage(xmargin, ymargin, img);
+void MainPage::coreConnectionStateChanged()
+{
+    if (Client::coreConnection()->state() == CoreConnection::Disconnected) {
+        _connectButton->setEnabled(true);
+    } else {
+        _connectButton->setDisabled(true);
+    }
 }
index 0557f8e..6ac8039 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <QWidget>
 
+class QPushButton;
+
 class MainPage : public QWidget
 {
     Q_OBJECT
@@ -30,8 +32,12 @@ class MainPage : public QWidget
 public:
     MainPage(QWidget *parent = 0);
 
-protected:
-    void paintEvent(QPaintEvent *event);
+private slots:
+    void showCoreConnectionDlg();
+    void coreConnectionStateChanged();
+
+private:
+    QPushButton *_connectButton;
 };
 
 
index bd8727a..95d2e6f 100644 (file)
@@ -879,6 +879,8 @@ void MainWin::setupNickWidget()
     // attach the NickListWidget to the BufferModel and the default selection
     _nickListWidget->setModel(Client::bufferModel());
     _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
+
+    _nickListWidget->setVisible(false);
 }
 
 
@@ -1131,7 +1133,7 @@ void MainWin::loadLayout()
         _layoutLoaded = true;
         return;
     }
-
+    _nickListWidget->setVisible(true);
     restoreState(state, accountId);
     int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
     if (bufferViewId >= 0)
@@ -1201,6 +1203,7 @@ void MainWin::setDisconnectedState()
         _msgProcessorStatusWidget->setProgress(0, 0);
     updateIcon();
     systemTray()->setState(SystemTray::Passive);
+    _nickListWidget->setVisible(false);
 }
 
 
index d5af971..a47cc6e 100644 (file)
@@ -84,6 +84,19 @@ void NickListWidget::showWidget(bool visible)
     }
 }
 
+void NickListWidget::setVisible(bool visible)
+{
+    QWidget::setVisible(visible);
+    QDockWidget *dock_ = dock();
+    if (!dock_)
+        return;
+
+    if (visible)
+        dock_->show();
+    else
+        dock_->close();
+}
+
 
 void NickListWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous)
 {
index 1b7253f..84fc432 100644 (file)
@@ -43,6 +43,7 @@ public:
 
 public slots:
     void showWidget(bool visible);
+    void setVisible(bool visible) override;
 
 signals:
     void nickSelectionChanged(const QModelIndexList &);
index 6fbf110..d3069df 100644 (file)
@@ -80,6 +80,13 @@ void SslInfoDlg::setCurrentCert(int index)
     ui.validity->setText(tr("%1 to %2").arg(cert.effectiveDate().date().toString(Qt::ISODate), cert.expiryDate().date().toString(Qt::ISODate)));
     ui.md5Digest->setText(prettyDigest(cert.digest(QCryptographicHash::Md5)));
     ui.sha1Digest->setText(prettyDigest(cert.digest(QCryptographicHash::Sha1)));
+#if QT_VERSION < 0x050000
+    // Qt 4 doesn't include SHA-2 hashes, so hide the row
+    ui.sha256Label->hide();
+    ui.sha256Digest->hide();
+#else
+    ui.sha256Digest->setText(prettyDigest(cert.digest(QCryptographicHash::Sha256)));
+#endif
 }
 
 // in Qt5, subjectInfo returns a QStringList(); turn this into a comma-separated string instead
index a52580b..f623f6d 100644 (file)
        </property>
       </widget>
      </item>
+     <item row="10" column="0">
+      <widget class="QLabel" name="sha256Label">
+       <property name="text">
+        <string>&lt;b&gt;SHA256 digest:&lt;/b&gt;</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+       </property>
+      </widget>
+     </item>
+     <item row="10" column="1">
+      <widget class="QLabel" name="sha256Digest">
+       <property name="text">
+        <string notr="true">n/a</string>
+       </property>
+      </widget>
+     </item>
      <item row="4" column="2" colspan="2">
       <spacer name="horizontalSpacer_2">
        <property name="orientation">
        </property>
       </spacer>
      </item>
-     <item row="10" column="0">
+     <item row="11" column="0">
       <widget class="QLabel" name="label_19">
        <property name="text">
         <string>&lt;b&gt;Trusted:&lt;/b&gt;</string>
        </property>
       </widget>
      </item>
-     <item row="10" column="1">
+     <item row="11" column="1">
       <widget class="QLabel" name="trusted">
        <property name="sizePolicy">
         <sizepolicy hsizetype="Preferred" vsizetype="Maximum">