moonlight-qt/mainwindow.cpp

97 lines
2.9 KiB
C++

#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
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;
delete myButton;
delete pinMsgBox;
}
void MainWindow::on_actionExit_triggered()
{
exit(EXIT_SUCCESS);
}
void MainWindow::on_newHostBtn_clicked()
{
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()) {
// 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) {
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
}