mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-01 15:26:09 +00:00
Refactored popups into a new class
This commit is contained in:
parent
0651062b81
commit
05fb400879
@ -1,5 +1,6 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
#include "popupmanager.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
@ -7,12 +8,13 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
// sample code for an iconized button performing an action
|
||||||
myButton = new QPushButton(this);
|
// will be useful to implement the game grid UI later
|
||||||
myButton->setIcon(QIcon(":/res/icon128.png"));
|
// myButton = new QPushButton(this);
|
||||||
myButton->setIconSize(QSize(128, 128));
|
// myButton->setIcon(QIcon(":/res/icon128.png"));
|
||||||
myButton->resize(QSize(128, 128));
|
// myButton->setIconSize(QSize(128, 128));
|
||||||
connect(myButton, &QAbstractButton::clicked, this, &MainWindow::on_actionExit_triggered);
|
// myButton->resize(QSize(128, 128));
|
||||||
|
// connect(myButton, &QAbstractButton::clicked, this, &MainWindow::on_actionExit_triggered);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event)
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
@ -35,8 +37,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
delete myButton;
|
|
||||||
delete pinMsgBox;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionExit_triggered()
|
void MainWindow::on_actionExit_triggered()
|
||||||
@ -46,39 +46,12 @@ void MainWindow::on_actionExit_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_newHostBtn_clicked()
|
void MainWindow::on_newHostBtn_clicked()
|
||||||
{
|
{
|
||||||
bool ok;
|
QString hostname = popupmanager::getHostnameDialog();
|
||||||
QString responseHost
|
if (!hostname.isEmpty()) {
|
||||||
= QInputDialog::getText(this, tr("Add Host Manually"),
|
//TODO: pairTo(hostname)
|
||||||
tr("IP Address or Hostname of GeForce PC"),
|
|
||||||
QLineEdit::Normal,
|
|
||||||
tr("default string"),
|
|
||||||
&ok);
|
|
||||||
if (ok && !responseHost.isEmpty()) {
|
|
||||||
// TODO: send pair request to "responseHost"
|
|
||||||
} else {
|
|
||||||
// silently close, user canceled
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this opens a non-blocking informative message telling the user to enter the given pin
|
|
||||||
// it is open-loop: if the user cancels, nothing happens
|
|
||||||
// it is expected that upon pairing completion, the ::closePinDialog function will be called.
|
|
||||||
void MainWindow::displayPinDialog(QString pin = tr("ERROR")) {
|
|
||||||
|
|
||||||
pinMsgBox = new QMessageBox( this );
|
|
||||||
pinMsgBox->setAttribute( Qt::WA_DeleteOnClose ); //makes sure the msgbox is deleted automatically when closed
|
|
||||||
pinMsgBox->setStandardButtons( QMessageBox::Ok );
|
|
||||||
pinMsgBox->setText("Please enter the number " + pin + " on the GFE dialog on the computer.");
|
|
||||||
pinMsgBox->setInformativeText("This dialog will be dismissed once complete.");
|
|
||||||
pinMsgBox->open();
|
|
||||||
}
|
|
||||||
|
|
||||||
// to be called when the pairing is complete
|
|
||||||
void MainWindow::closePinDialog() {
|
|
||||||
pinMsgBox->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::addHostToDisplay(QMap<QString, bool> hostMdnsMap) {
|
void MainWindow::addHostToDisplay(QMap<QString, bool> hostMdnsMap) {
|
||||||
|
|
||||||
QMapIterator<QString, bool> i(hostMdnsMap);
|
QMapIterator<QString, bool> i(hostMdnsMap);
|
||||||
|
@ -22,15 +22,11 @@ protected:
|
|||||||
private slots:
|
private slots:
|
||||||
void on_actionExit_triggered();
|
void on_actionExit_triggered();
|
||||||
void on_newHostBtn_clicked();
|
void on_newHostBtn_clicked();
|
||||||
void displayPinDialog(QString pin);
|
|
||||||
void closePinDialog();
|
|
||||||
void addHostToDisplay(QMap<QString, bool>);
|
void addHostToDisplay(QMap<QString, bool>);
|
||||||
void on_selectHostComboBox_activated(const QString &);
|
void on_selectHostComboBox_activated(const QString &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QAbstractButton *myButton = nullptr;
|
|
||||||
QMessageBox *pinMsgBox = nullptr;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,14 +28,16 @@ SOURCES += \
|
|||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
nvhttp.cpp \
|
nvhttp.cpp \
|
||||||
nvpairingmanager.cpp \
|
nvpairingmanager.cpp \
|
||||||
identitymanager.cpp
|
identitymanager.cpp \
|
||||||
|
popupmanager.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
nvhttp.h \
|
nvhttp.h \
|
||||||
nvpairingmanager.h \
|
nvpairingmanager.h \
|
||||||
identitymanager.h \
|
identitymanager.h \
|
||||||
utils.h
|
utils.h \
|
||||||
|
popupmanager.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
mainwindow.ui
|
mainwindow.ui
|
||||||
|
38
popupmanager.cpp
Normal file
38
popupmanager.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "popupmanager.h"
|
||||||
|
|
||||||
|
popupmanager::popupmanager();
|
||||||
|
|
||||||
|
// this opens a non-blocking informative message telling the user to enter the given pin
|
||||||
|
// it is open-loop: if the user cancels, nothing happens
|
||||||
|
// it is expected that upon pairing completion, the ::closePinDialog function will be called.
|
||||||
|
static void popupmanager::displayPinDialog(QString pin) {
|
||||||
|
|
||||||
|
pinMsgBox = new QMessageBox( this );
|
||||||
|
pinMsgBox->setAttribute( Qt::WA_DeleteOnClose ); //makes sure the msgbox is deleted automatically when closed
|
||||||
|
pinMsgBox->setStandardButtons( QMessageBox::Ok );
|
||||||
|
pinMsgBox->setText("Please enter the number " + pin + " on the GFE dialog on the computer.");
|
||||||
|
pinMsgBox->setInformativeText("This dialog will be dismissed once complete.");
|
||||||
|
pinMsgBox->open();
|
||||||
|
}
|
||||||
|
|
||||||
|
// to be called when the pairing is complete
|
||||||
|
static void popupmanager::closePinDialog() {
|
||||||
|
pinMsgBox->close();
|
||||||
|
delete pinMsgBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString popupmanager::getHostnameDialog() {
|
||||||
|
bool ok;
|
||||||
|
QString responseHost
|
||||||
|
= QInputDialog::getText(this, tr("Add Host Manually"),
|
||||||
|
tr("IP Address or Hostname of GeForce PC"),
|
||||||
|
QLineEdit::Normal,
|
||||||
|
tr("default string"),
|
||||||
|
&ok);
|
||||||
|
if (ok && !responseHost.isEmpty()) {
|
||||||
|
return responseHost;
|
||||||
|
} else {
|
||||||
|
return tr("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
18
popupmanager.h
Normal file
18
popupmanager.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef POPUPMANAGER_H
|
||||||
|
#define POPUPMANAGER_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class popupmanager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
popupmanager();
|
||||||
|
static void displayPinDialog(QString pin);
|
||||||
|
static void closePinDialog();
|
||||||
|
static QString getHostnameDialog();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
QMessageBox *pinMsgBox = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // POPUPMANAGER_H
|
Loading…
x
Reference in New Issue
Block a user