Reorganize and prepare for SDL integration

This commit is contained in:
Cameron Gutman
2018-06-23 18:46:59 -07:00
parent ea459a0319
commit ce64966843
18 changed files with 637 additions and 586 deletions

78
app/gui/mainwindow.cpp Normal file
View File

@@ -0,0 +1,78 @@
#include "gui/mainwindow.h"
#include "ui_mainwindow.h"
#include "gui/popupmanager.h"
#include "http/identitymanager.h"
#include "http/nvpairingmanager.h"
#include "http/nvhttp.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// sample code for an iconized button performing an action
// will be useful to implement the game grid UI later
// myButton = new QPushButton(this);
// myButton->setIcon(QIcon(":/res/icon128.png"));
// myButton->setIconSize(QSize(128, 128));
// myButton->resize(QSize(128, 128));
// connect(myButton, &QAbstractButton::clicked, this, &MainWindow::on_actionExit_triggered);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
const QMessageBox::StandardButton ret
= QMessageBox::warning(this, tr("Application"),
tr("something-something-close?"),
QMessageBox::Yes | QMessageBox::No);
switch (ret) {
case QMessageBox::Yes:
event->accept();
break;
case QMessageBox::No:
default:
event->ignore();
break;
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionExit_triggered()
{
exit(EXIT_SUCCESS);
}
void MainWindow::on_newHostBtn_clicked()
{
QString hostname = popupmanager::getHostnameDialog(this);
if (!hostname.isEmpty()) {
IdentityManager im = IdentityManager();
NvPairingManager pm(hostname, im);
QString pin = pm.generatePinString();
NvHTTP http(hostname, im);
pm.pair(http.getServerInfo(), pin);
}
}
void MainWindow::addHostToDisplay(QMap<QString, bool> hostMdnsMap) {
QMapIterator<QString, bool> i(hostMdnsMap);
while (i.hasNext()) {
i.next();
ui->hostSelectCombo->addItem(i.key());
// we can ignore the mdns for now, it's only useful for displaying unpairing options
}
}
void MainWindow::on_selectHostComboBox_activated(const QString &selectedHostname)
{
// TODO: get all the applications that "selectedHostname" has listed
// probably populate another combobox of applications for the time being
}

33
app/gui/mainwindow.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtWidgets>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void closeEvent(QCloseEvent *event) override;
private slots:
void on_actionExit_triggered();
void on_newHostBtn_clicked();
void addHostToDisplay(QMap<QString, bool>);
void on_selectHostComboBox_activated(const QString &);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

102
app/gui/mainwindow.ui Normal file
View File

@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>483</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>50</x>
<y>30</y>
<width>306</width>
<height>191</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="newHostBtn">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Add New Host</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/res/icon128.png</normaloff>:/res/icon128.png</iconset>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="hostSelectCombo"/>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionSettings"/>
<addaction name="actionGamepad_Mapping"/>
<addaction name="actionExit"/>
</widget>
<addaction name="menuFile"/>
</widget>
<action name="actionSettings">
<property name="text">
<string>Settings</string>
</property>
</action>
<action name="actionGamepad_Mapping">
<property name="text">
<string>Gamepad Mapping</string>
</property>
</action>
<action name="actionExit">
<property name="text">
<string>Exit</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

41
app/gui/popupmanager.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "popupmanager.h"
QMessageBox *popupmanager::pinMsgBox = nullptr;
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.
void popupmanager::displayPinDialog(QString pin, QWidget* parent) {
popupmanager::pinMsgBox = new QMessageBox( parent );
popupmanager::pinMsgBox->setAttribute( Qt::WA_DeleteOnClose ); //makes sure the msgbox is deleted automatically when closed
popupmanager::pinMsgBox->setStandardButtons( QMessageBox::Ok );
popupmanager::pinMsgBox->setText("Please enter the number " + pin + " on the GFE dialog on the computer.");
popupmanager::pinMsgBox->setInformativeText("This dialog will be dismissed once complete.");
popupmanager::pinMsgBox->open();
}
// to be called when the pairing is complete
void popupmanager::closePinDialog() {
pinMsgBox->close();
delete pinMsgBox;
}
QString popupmanager::getHostnameDialog(QWidget* parent) {
bool ok;
QString responseHost
= QInputDialog::getText(parent, QObject::tr("Add Host Manually"),
QObject::tr("IP Address or Hostname of GeForce PC"),
QLineEdit::Normal,
QObject::tr("default string"),
&ok);
if (ok && !responseHost.isEmpty()) {
return responseHost;
} else {
return QObject::tr("");
}
}

18
app/gui/popupmanager.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef POPUPMANAGER_H
#define POPUPMANAGER_H
#include <QtWidgets>
class popupmanager
{
public:
popupmanager();
static void displayPinDialog(QString pin, QWidget* parent);
static void closePinDialog();
static QString getHostnameDialog(QWidget* parent);
private:
static QMessageBox *pinMsgBox;
};
#endif // POPUPMANAGER_H