Display the PSK entry box near the mouse.
authorRoy Marples <roy@marples.name>
Thu, 4 Dec 2014 21:02:00 +0000 (21:02 +0000)
committerRoy Marples <roy@marples.name>
Thu, 4 Dec 2014 21:02:00 +0000 (21:02 +0000)
src/dhcpcd-gtk/wpa.c
src/dhcpcd-qt/dhcpcd-qt.pro
src/dhcpcd-qt/dhcpcd-ssid.cpp [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-ssid.h [new file with mode: 0644]
src/dhcpcd-qt/dhcpcd-ssidmenu.cpp
src/dhcpcd-qt/dhcpcd-ssidmenu.h
src/dhcpcd-qt/dhcpcd-wi.cpp
src/dhcpcd-qt/dhcpcd-wi.h

index e2f70972e3b8a163bf564bd327604cd9f8b15332..140642fb7ecf4161b4b86a06ef8f13ac7ac7ebe3 100644 (file)
@@ -129,6 +129,7 @@ wpa_configure(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *scan)
            GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
            GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
            NULL);
+       gtk_window_set_position(GTK_WINDOW(wpa_dialog), GTK_WIN_POS_MOUSE);
        gtk_window_set_resizable(GTK_WINDOW(wpa_dialog), false);
        gtk_window_set_icon_name(GTK_WINDOW(wpa_dialog),
            "network-wireless-encrypted");
index 9d6b83880be3d7db66512e1ba53c80e941d79417..0030047ca94bbd203a6fdcf54f7771fcea9af690 100644 (file)
@@ -3,11 +3,13 @@ QMAKE_CXXFLAGS+=      -std=c++11 -O2
 
 HEADERS=               dhcpcd-qt.h dhcpcd-about.h dhcpcd-preferences.h \
                        dhcpcd-wi.h dhcpcd-ifmenu.h \
+                       dhcpcd-ssid.h \
                        dhcpcd-ssidmenu.h dhcpcd-ssidmenuwidget.h \
                        dhcpcd-ipv4validator.h
 SOURCES=               main.cpp dhcpcd-qt.cpp dhcpcd-about.cpp \
                        dhcpcd-preferences.cpp dhcpcd-wi.cpp \
                        dhcpcd-ifmenu.cpp \
+                       dhcpcd-ssid.cpp \
                        dhcpcd-ssidmenu.cpp dhcpcd-ssidmenuwidget.cpp \
                        dhcpcd-ipv4validator.cpp
 
diff --git a/src/dhcpcd-qt/dhcpcd-ssid.cpp b/src/dhcpcd-qt/dhcpcd-ssid.cpp
new file mode 100644 (file)
index 0000000..fec48a7
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * dhcpcd-qt
+ * Copyright 2014 Roy Marples <roy@marples.name>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QSpacerItem>
+#include <QVBoxLayout>
+
+#include "dhcpcd.h"
+#include "dhcpcd-qt.h"
+#include "dhcpcd-ssid.h"
+#include "dhcpcd-wi.h"
+
+DhcpcdSsid::DhcpcdSsid(DhcpcdWi *parent, DHCPCD_WI_SCAN *scan)
+    : QDialog()
+{
+       this->parent = parent;
+       QVBoxLayout *layout;
+       setWindowIcon(DhcpcdQt::getIcon("status",
+           "network-wireless-encrypted"));
+       setWindowTitle(scan->ssid);
+       setMinimumWidth(300);
+       resize(10, 10);
+       QPoint p = QCursor::pos();
+       move(p.x(), p.y());
+
+       layout = new QVBoxLayout(this);
+
+       QHBoxLayout *hbox = new QHBoxLayout();
+       layout->addLayout(hbox);
+       QLabel *label = new QLabel(tr("Pre Shared Key:"));
+       hbox->addWidget(label);
+       psk = new QLineEdit();
+       psk->setSizePolicy(QSizePolicy::Expanding,
+           QSizePolicy::Fixed);
+       hbox->addWidget(psk);
+
+       hbox = new QHBoxLayout();
+       layout->addLayout(hbox);
+       hbox->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding,
+           QSizePolicy::Expanding));
+       QDialogButtonBox *okcancel = new QDialogButtonBox(
+           QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+       hbox->addWidget(okcancel);
+       connect(okcancel, SIGNAL(accepted()), this, SLOT(accept()));
+       connect(okcancel, SIGNAL(rejected()), this, SLOT(reject()));
+}
+
+QString DhcpcdSsid::getPsk(bool *ok)
+{
+       int r;
+
+       exec();
+       if (result() == QDialog::Rejected) {
+               if (ok)
+                       *ok = false;
+               return QString::Null();
+       }
+
+       if (ok)
+               *ok = true;
+       return psk->text();
+}
diff --git a/src/dhcpcd-qt/dhcpcd-ssid.h b/src/dhcpcd-qt/dhcpcd-ssid.h
new file mode 100644 (file)
index 0000000..fdb34a8
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * dhcpcd-qt
+ * Copyright 2014 Roy Marples <roy@marples.name>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef DHCPCD_SSID_H
+#define DHCPCD_SSID_H
+
+#include <QDialog>
+
+#include "dhcpcd.h"
+
+class DhcpcdWi;
+class QLineEdit;
+
+class DhcpcdSsid : public QDialog
+{
+       Q_OBJECT
+
+public:
+       DhcpcdSsid(DhcpcdWi *parent, DHCPCD_WI_SCAN *scan);
+       QString getPsk(bool *ok);
+
+private:
+       DhcpcdWi *parent;
+       QLineEdit *psk;
+};
+
+#endif
index 459301a8559584cb39f5370d3c637f2290bff64b..5b422510b53fde450869cab592008671d2104307 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "dhcpcd.h"
 #include "dhcpcd-qt.h"
+#include "dhcpcd-ssid.h"
 #include "dhcpcd-ssidmenu.h"
 #include "dhcpcd-ssidmenuwidget.h"
 
index a359c50459f9b6098007f16a12f12c4099c17ed2..0cebcd60ee28e4fefd849721b933d9c9ca35fcf1 100644 (file)
@@ -54,7 +54,7 @@ public slots:
 
 signals:
        void hovered();
-       void triggered(DHCPCD_WI_SCAN *scan);
+       void triggered(DHCPCD_WI_SCAN *);
 
 private:
        DhcpcdWi *wi;
index 979bebea92617792ba14671f20f84cc6fe80adf4..260938bcbe0fe3264ae148c694401857b515e0a5 100644 (file)
@@ -40,6 +40,7 @@
 #include "dhcpcd-wi.h"
 #include "dhcpcd-qt.h"
 #include "dhcpcd-ifmenu.h"
+#include "dhcpcd-ssid.h"
 #include "dhcpcd-ssidmenu.h"
 
 DhcpcdWi::DhcpcdWi(DhcpcdQt *parent, DHCPCD_WPA *wpa)
@@ -49,6 +50,7 @@ DhcpcdWi::DhcpcdWi(DhcpcdQt *parent, DHCPCD_WPA *wpa)
        this->wpa = wpa;
        menu = NULL;
        scans = NULL;
+       ssid = NULL;
 
        notifier = NULL;
        pingTimer = NULL;
@@ -79,6 +81,12 @@ DhcpcdWi::~DhcpcdWi()
                pingTimer = NULL;
        }
 
+       if (ssid) {
+               ssid->reject();
+               ssid->deleteLater();
+               ssid = NULL;
+       }
+
 #ifdef BG_SCAN
        if (scanTimer) {
                scanTimer->stop();
@@ -270,32 +278,6 @@ void DhcpcdWi::ping()
                dhcpcd_wpa_close(wpa);
 }
 
-#ifdef BG_SCAN
-void DhcpcdWi::scan()
-{
-
-       dhcpcd_wpa_scan(wpa);
-}
-
-void DhcpcdWi::menuHidden()
-{
-
-       if (scanTimer) {
-               scanTimer->stop();
-               scanTimer->start(DHCPCD_WPA_SCAN_LONG);
-       }
-}
-
-void DhcpcdWi::menuShown()
-{
-
-       if (scanTimer) {
-               scanTimer->stop();
-               scanTimer->start(DHCPCD_WPA_SCAN_SHORT);
-       }
-}
-#endif
-
 void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
 {
        DHCPCD_WI_SCAN s;
@@ -307,8 +289,12 @@ void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
 
        if (s.flags & WSF_PSK) {
                bool ok;
-               QString pwd = QInputDialog::getText(dhcpcdQt, s.ssid,
-                   tr("Pre Shared key"), QLineEdit::Normal, NULL, &ok);
+               QString pwd;
+
+               ssid = new DhcpcdSsid(this, &s);
+               pwd = ssid->getPsk(&ok);
+               ssid->deleteLater();
+               ssid = NULL;
                if (!ok)
                        return;
                if (pwd.isNull() || pwd.isEmpty())
@@ -319,7 +305,6 @@ void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
                err = dhcpcd_wpa_configure(wpa, &s, NULL);
 
        QString errt;
-
        switch (err) {
        case DHCPCD_WPA_SUCCESS:
                return;
@@ -355,3 +340,29 @@ void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
        QMessageBox::critical(dhcpcdQt, tr("Error setting wireless properties"),
            errt);
 }
+
+#ifdef BG_SCAN
+void DhcpcdWi::scan()
+{
+
+       dhcpcd_wpa_scan(wpa);
+}
+
+void DhcpcdWi::menuHidden()
+{
+
+       if (scanTimer) {
+               scanTimer->stop();
+               scanTimer->start(DHCPCD_WPA_SCAN_LONG);
+       }
+}
+
+void DhcpcdWi::menuShown()
+{
+
+       if (scanTimer) {
+               scanTimer->stop();
+               scanTimer->start(DHCPCD_WPA_SCAN_SHORT);
+       }
+}
+#endif
index 1159725cb71a4e7522e20e63599fa7ca95930967..55d158bf5236665395b8500eb638b498d000d547 100644 (file)
@@ -38,6 +38,7 @@ class QTimer;
 class QWidgetAction;
 
 class DhcpcdQt;
+class DhcpcdSsid;
 class DhcpcdSsidMenu;
 
 class DhcpcdWi : public QObject
@@ -59,17 +60,18 @@ public:
 private slots:
        void dispatch();
        void ping();
+       void connectSsid(DHCPCD_WI_SCAN *scan);
 #ifdef BG_SCAN
        void scan();
        void menuHidden();
        void menuShown();
 #endif
-       void connectSsid(DHCPCD_WI_SCAN *scan);
 
 private:
        DhcpcdQt *dhcpcdQt;
        DHCPCD_WPA *wpa;
        DHCPCD_WI_SCAN *scans;
+       DhcpcdSsid *ssid;
 
        QSocketNotifier *notifier;
        QTimer *pingTimer;