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