diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ec68b91b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*pro.user diff --git a/main.cpp b/main.cpp index b48f94ec..ef04b215 100644 --- a/main.cpp +++ b/main.cpp @@ -3,9 +3,14 @@ int main(int argc, char *argv[]) { + // MacOS directive to prevent the menu bar from being merged into the native bar + // i.e. it's in the window, and not the top left of the screen + QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar); + QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); + } diff --git a/mainwindow.cpp b/mainwindow.cpp index 57f85959..68dcbac9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,11 +1,40 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "popupmanager.h" +#include "identitymanager.h" +#include "nvpairingmanager.h" +#include "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() @@ -17,3 +46,33 @@ void MainWindow::on_actionExit_triggered() { exit(EXIT_SUCCESS); } + +void MainWindow::on_newHostBtn_clicked() +{ + QString hostname = popupmanager::getHostnameDialog(this); + if (!hostname.isEmpty()) { + + IdentityManager im = IdentityManager(QDir(QDir::current())); + NvPairingManager pm(hostname, im); + + QString pin = pm.generatePinString(); + NvHTTP http(hostname, im); + pm.pair(http.getServerInfo(), pin); + } +} + +void MainWindow::addHostToDisplay(QMap hostMdnsMap) { + + QMapIterator 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 +} diff --git a/mainwindow.h b/mainwindow.h index 450992cd..58affa92 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include namespace Ui { class MainWindow; @@ -15,11 +16,18 @@ 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); + void on_selectHostComboBox_activated(const QString &); private: Ui::MainWindow *ui; + }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 0c8dc36f..bb2092ec 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -7,20 +7,65 @@ 0 0 400 - 300 + 483 MainWindow - + + + + + 50 + 30 + 306 + 191 + + + + + QLayout::SetDefaultConstraint + + + 10 + + + 10 + + + 10 + + + 10 + + + + + PointingHandCursor + + + Add New Host + + + + :/res/icon128.png:/res/icon128.png + + + + + + + + + 0 0 400 - 24 + 22 @@ -50,6 +95,8 @@ - + + + diff --git a/moonlight-qt.pro b/moonlight-qt.pro index c730c792..d51a30f0 100644 --- a/moonlight-qt.pro +++ b/moonlight-qt.pro @@ -22,24 +22,32 @@ DEFINES += QT_DEPRECATED_WARNINGS # You can also select to disable deprecated APIs only up to a certain version of Qt. DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 +INCLUDEPATH += \ + /usr/local/opt/openssl/include SOURCES += \ main.cpp \ mainwindow.cpp \ nvhttp.cpp \ nvpairingmanager.cpp \ - identitymanager.cpp + identitymanager.cpp \ + popupmanager.cpp HEADERS += \ mainwindow.h \ nvhttp.h \ nvpairingmanager.h \ identitymanager.h \ - utils.h + utils.h \ + popupmanager.h FORMS += \ mainwindow.ui +RESOURCES += \ + resources.qrc + LIBS += \ + -L/usr/local/opt/openssl/lib \ -lssl \ -lcrypto diff --git a/popupmanager.cpp b/popupmanager.cpp new file mode 100644 index 00000000..83a17aec --- /dev/null +++ b/popupmanager.cpp @@ -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(""); + } +} + + diff --git a/popupmanager.h b/popupmanager.h new file mode 100644 index 00000000..934ba79d --- /dev/null +++ b/popupmanager.h @@ -0,0 +1,18 @@ +#ifndef POPUPMANAGER_H +#define POPUPMANAGER_H + +#include + +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 diff --git a/res/ic_add_to_queue_white_48px.svg b/res/ic_add_to_queue_white_48px.svg new file mode 100644 index 00000000..2323513c --- /dev/null +++ b/res/ic_add_to_queue_white_48px.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/res/ic_remove_circle_outline_white_48px.svg b/res/ic_remove_circle_outline_white_48px.svg new file mode 100644 index 00000000..22468895 --- /dev/null +++ b/res/ic_remove_circle_outline_white_48px.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/res/ic_remove_from_queue_white_48px.svg b/res/ic_remove_from_queue_white_48px.svg new file mode 100644 index 00000000..9ad352f4 --- /dev/null +++ b/res/ic_remove_from_queue_white_48px.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/res/ic_tv_white_48px.svg b/res/ic_tv_white_48px.svg new file mode 100644 index 00000000..b163cf7f --- /dev/null +++ b/res/ic_tv_white_48px.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/res/ic_videogame_asset_white_48px.svg b/res/ic_videogame_asset_white_48px.svg new file mode 100644 index 00000000..c771cf4e --- /dev/null +++ b/res/ic_videogame_asset_white_48px.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/res/icon128.png b/res/icon128.png new file mode 100644 index 00000000..05d4ae90 Binary files /dev/null and b/res/icon128.png differ diff --git a/res/no_app_image.png b/res/no_app_image.png new file mode 100644 index 00000000..4cbad3e0 Binary files /dev/null and b/res/no_app_image.png differ diff --git a/resources.qrc b/resources.qrc new file mode 100644 index 00000000..0fce81cc --- /dev/null +++ b/resources.qrc @@ -0,0 +1,11 @@ + + + res/icon128.png + res/ic_add_to_queue_white_48px.svg + res/ic_remove_circle_outline_white_48px.svg + res/ic_remove_from_queue_white_48px.svg + res/ic_tv_white_48px.svg + res/ic_videogame_asset_white_48px.svg + res/no_app_image.png + +