added persistent address
This commit is contained in:
3
main.cpp
3
main.cpp
@@ -6,6 +6,9 @@ using namespace yremote;
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
QCoreApplication::setOrganizationName("RogoSoftware");
|
||||||
|
QCoreApplication::setOrganizationDomain("git.rogocloud.eu");
|
||||||
|
QCoreApplication::setApplicationName("yremote");
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
|
|||||||
@@ -10,24 +10,26 @@ namespace yremote {
|
|||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
QString DEFAULT_ADDRESS = "10.0.0.227";
|
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setFixedSize(size());
|
setFixedSize(size());
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
|
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
|
||||||
#endif
|
#endif
|
||||||
ui->txt_address->setText(DEFAULT_ADDRESS);
|
|
||||||
|
ui->txt_address->setText(mSettings.value("av_address", "").toString());
|
||||||
mAddress = ui->txt_address->text();
|
mAddress = ui->txt_address->text();
|
||||||
|
|
||||||
// setup volume value collection
|
// setup volume value collection
|
||||||
connect(&mTimerValCollect, &QTimer::timeout, this, &MainWindow::sendVolume);
|
connect(&mTimerValCollect, &QTimer::timeout, this, &MainWindow::sendVolume);
|
||||||
mTimerValCollect.setSingleShot(true);
|
mTimerValCollect.setSingleShot(true);
|
||||||
|
|
||||||
|
connect(&mTimerUpdateAddress, &QTimer::timeout, this, &MainWindow::updateAVState);
|
||||||
|
mTimerUpdateAddress.setSingleShot(true);
|
||||||
|
|
||||||
// load initial data and set update rate
|
// load initial data and set update rate
|
||||||
updateAVState();
|
updateAVState();
|
||||||
connect(&mTimerUpdate, &QTimer::timeout, this, &MainWindow::updateAVState);
|
connect(&mTimerUpdateState, &QTimer::timeout, this, &MainWindow::updateAVState);
|
||||||
mTimerUpdate.start(UPDATETIME);
|
mTimerUpdateState.start(TIME_UPDATE_STATE);
|
||||||
|
|
||||||
QFile css(":style.css");
|
QFile css(":style.css");
|
||||||
if (css.open(QFile::ReadOnly | QFile::Text))
|
if (css.open(QFile::ReadOnly | QFile::Text))
|
||||||
@@ -61,7 +63,8 @@ void MainWindow::replyFinished(QNetworkReply* reply)
|
|||||||
} else {
|
} else {
|
||||||
qDebug() << reply->url();
|
qDebug() << reply->url();
|
||||||
qDebug() << reply->errorString();
|
qDebug() << reply->errorString();
|
||||||
return;
|
|
||||||
|
mPowered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check power state
|
// check power state
|
||||||
@@ -136,6 +139,8 @@ void MainWindow::setPowerState()
|
|||||||
void MainWindow::on_txt_address_textEdited(const QString &arg1)
|
void MainWindow::on_txt_address_textEdited(const QString &arg1)
|
||||||
{
|
{
|
||||||
mAddress = arg1;
|
mAddress = arg1;
|
||||||
|
mSettings.setValue("av_address", mAddress);
|
||||||
|
mTimerUpdateAddress.start(TIME_UPDATE_ADDRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_btn_onoff_clicked()
|
void MainWindow::on_btn_onoff_clicked()
|
||||||
@@ -163,7 +168,7 @@ void MainWindow::on_dial_valueChanged(int value)
|
|||||||
|
|
||||||
ui->lbl_volume->setText(QString::number(value));
|
ui->lbl_volume->setText(QString::number(value));
|
||||||
mVolume = value;
|
mVolume = value;
|
||||||
mTimerValCollect.start(COLLECTTIME);
|
mTimerValCollect.start(TIME_VOL_COLLECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::sendVolume()
|
void MainWindow::sendVolume()
|
||||||
|
|||||||
14
mainwindow.h
14
mainwindow.h
@@ -2,6 +2,7 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QSettings>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "QtNetwork/QNetworkAccessManager"
|
#include "QtNetwork/QNetworkAccessManager"
|
||||||
|
|
||||||
@@ -40,20 +41,23 @@ private:
|
|||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
QString mAddress;
|
QString mAddress;
|
||||||
|
QSettings mSettings;
|
||||||
QTimer mTimerValCollect;
|
QTimer mTimerValCollect;
|
||||||
QTimer mTimerUpdate;
|
QTimer mTimerUpdateState;
|
||||||
|
QTimer mTimerUpdateAddress;
|
||||||
|
|
||||||
bool mPowered = false;
|
bool mPowered = false;
|
||||||
int mVolume = 0;
|
int mVolume = 0;
|
||||||
QString mInput;
|
QString mInput;
|
||||||
const int COLLECTTIME = 400;
|
const int TIME_VOL_COLLECT = 400;
|
||||||
const int UPDATETIME = 20000;
|
const int TIME_UPDATE_STATE = 5000;
|
||||||
|
const int TIME_UPDATE_ADDRESS = 1000;
|
||||||
|
|
||||||
|
|
||||||
void sendCommand(QString cmd);
|
void sendCommand(QString cmd);
|
||||||
void updateUi();
|
void updateUi();
|
||||||
void sendVolume();
|
|
||||||
|
|
||||||
void setActiveButton(QString prop);
|
void setActiveButton(QString prop);
|
||||||
|
void sendVolume();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user