diff --git a/redshiftqt/RedShiftQt.pro b/redshiftqt/RedShiftQt.pro index 0d5c23b..ad87b22 100644 --- a/redshiftqt/RedShiftQt.pro +++ b/redshiftqt/RedShiftQt.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui +QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -15,16 +15,20 @@ TEMPLATE = app SOURCES += \ main.cpp \ redshiftqttray.cpp \ + redshiftqtprefs.cpp \ redshiftqtlog.cpp \ - redshiftqtprefs.cpp + redshiftqt.cpp \ + qdoublespinboxlist.cpp HEADERS += \ - redshiftqt.h \ redshiftqttray.h \ - redshiftqtlog.h + redshiftqtprefs.h \ + redshiftqtlog.h \ + redshiftqt.h \ + qdoublespinboxlist.h FORMS += \ - redshiftqt.ui \ + redshiftqtprefs.ui \ redshiftqtlog.ui RESOURCES += \ diff --git a/redshiftqt/main.cpp b/redshiftqt/main.cpp index a3b5cc7..2d52bd9 100644 --- a/redshiftqt/main.cpp +++ b/redshiftqt/main.cpp @@ -1,12 +1,12 @@ #include "redshiftqt.h" -#include "redshiftqtlog.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); + a.setQuitOnLastWindowClosed(false); + a.setOrganizationName(a.applicationName()); RedShiftQt w; - Redshift return a.exec(); } diff --git a/redshiftqt/qdoublespinboxlist.cpp b/redshiftqt/qdoublespinboxlist.cpp new file mode 100644 index 0000000..ff9c7ea --- /dev/null +++ b/redshiftqt/qdoublespinboxlist.cpp @@ -0,0 +1,23 @@ +#include "qdoublespinboxlist.h" + +QStringList QDoubleSpinBoxList::value(void) { + QStringList gamma; + QDoubleSpinBoxList::iterator i; + for(i = this->begin(); i != this->end(); i++) + gamma.append(QString("%1").arg((*i)->value())); + return gamma; +} + +void QDoubleSpinBoxList::setValue(QStringList v) +{ + for(int i = 0; i < this->count(); i++) { + this->at(i)->setValue(v.value(i, v.at(0)).toDouble()); + } +} + +void QDoubleSpinBoxList::setEnabled(bool b) +{ + QDoubleSpinBoxList::iterator i; + for(i = this->begin(); i != this->end(); i++) + (*i)->setEnabled(b); +} diff --git a/redshiftqt/qdoublespinboxlist.h b/redshiftqt/qdoublespinboxlist.h new file mode 100644 index 0000000..aa8e740 --- /dev/null +++ b/redshiftqt/qdoublespinboxlist.h @@ -0,0 +1,13 @@ +#ifndef QDOUBLESPINBOXLIST_H +#define QDOUBLESPINBOXLIST_H + +#include + +class QDoubleSpinBoxList : public QList +{ +public: + QStringList value(); + void setValue(QStringList); + void setEnabled(bool); +}; +#endif // QDOUBLESPINBOXLIST_H diff --git a/redshiftqt/redshiftqt.cpp b/redshiftqt/redshiftqt.cpp new file mode 100644 index 0000000..0e2d895 --- /dev/null +++ b/redshiftqt/redshiftqt.cpp @@ -0,0 +1,217 @@ +#include "redshiftqt.h" + +RedShiftQt::RedShiftQt(QWidget *parent) : + QMainWindow(parent) +{ + + setWindowIcon(QIcon(":/app/icon")); + setWindowTitle(qApp->applicationName()); + setGeometry(QStyle::alignedRect( + Qt::LeftToRight, + Qt::AlignCenter, + QSize(0,0), + qApp->desktop()->availableGeometry())); + + conf = new QSettings( + QSettings::IniFormat, + QSettings::UserScope, + qApp->organizationName(), + qApp->applicationName(), + this); + + tray = new RedShiftQtTray(this); + tray->show(); + + log = new RedShiftQtLog(this); + + info_timer = new QTimer(this); + info_timer->setTimerType(Qt::VeryCoarseTimer); + + susp_timer = new QTimer(this); + connect(susp_timer, SIGNAL(timeout()), this, SLOT(toggle())); + susp_timer->setTimerType(Qt::VeryCoarseTimer); + + redshift = new QProcess(this); + connect(redshift, SIGNAL(stateChanged(QProcess::ProcessState)), + this, SLOT(onRedshiftStateChanged(QProcess::ProcessState))); + //connect(redshift, SIGNAL(readyRead()), this, SLOT(onProcReadyRead())); + //connect(redshift, SINGAL(readyReadStandardError(), this, SLOT(onProcReadyRead))); + onRedshiftStateChanged(QProcess::NotRunning); + + redshift->setProgram(conf->value("redshift_path").toString()); + redshift->setArguments(getArguments()); + + if(conf->value("start_enabled").toBool()) + redshift->start(QProcess::ReadOnly); + + helper = new QProcess(this); + helper->setProgram(conf->value("redshift_path").toString()); + + prefs = new RedShiftQtPrefs(this); + connect(prefs, SIGNAL(confChanged()), this, SLOT(onConfChanged())); + + if(conf->value("show_prefs").toBool()) + prefs->show(); +} + +RedShiftQt::~RedShiftQt() +{ + redshift->kill(); + redshift->waitForFinished(); + helper->kill(); + helper->waitForFinished(); +} + +void RedShiftQt::onRedshiftStateChanged(QProcess::ProcessState state) +{ + switch(state) { + case QProcess::Running : + tray->setIcon(QIcon(":/tray/on")); + tray->setToolTip(windowTitle() +": Running"); + tray->status->setChecked(true); + tray->suspend->setEnabled(true); + log->setStatus(QString("Enabled")); + log->appendToLog(redshift->program().toUtf8() + " " + redshift->arguments().join(" ").toUtf8()); + break; + + case QProcess::NotRunning : + tray->setIcon(QIcon(":/tray/off")); + tray->setToolTip(windowTitle() +": Suspended"); + tray->status->setChecked(false); + tray->suspend->setEnabled(false); + log->setInfo(QStringList("Disabled")); + log->appendToLog("Redshift stopped"); + break; + + default: + break; + } + qDebug("Process state: %d", redshift->state()); +} + +void RedShiftQt::onReadyRead() +{ + +} + +void RedShiftQt::onConfChanged() +{ + int state = redshift->state(); + if(state) { + redshift->kill(); + redshift->waitForFinished(); + } + redshift->setProgram(conf->value("redshift_path").toString()); + redshift->setArguments(getArguments()); + helper->setProgram(conf->value("redshift_path").toString()); + if(state) { + redshift->start(QProcess::ReadOnly); + } +} + +void RedShiftQt::toggle(void) +{ + if(redshift->state() == QProcess::Running) { + redshift->kill(); + redshift->waitForFinished(); + helper->setArguments(QStringList("-x")); + helper->start(QProcess::ReadOnly); + helper->waitForFinished(); + } else { + susp_timer->stop(); + redshift->start(QProcess::ReadOnly); + redshift->waitForStarted(); + } +} + +void RedShiftQt::suspend(QAction* action) +{ + toggle(); + + susp_timer->setInterval(action->data().toInt() * 60 * 1000); + susp_timer->start(); + + tray->setToolTip(tray->toolTip() + QString(" for %1 minutes").arg(action->data().toInt())); + log->appendToLog(QString("Suspending reshift for %1 minutes").arg(susp_timer->interval()/60/1000)); +} + +void RedShiftQt::activated(QSystemTrayIcon::ActivationReason reason) +{ + if(reason == QSystemTrayIcon::Trigger) + toggle(); +} + +void RedShiftQt::showPrefs() +{ + prefs->setVisible(true); + prefs->raise(); +} + +void RedShiftQt::showLog() +{ + log->setVisible(true); + log->raise(); +} + +QStringList RedShiftQt::getArguments() +{ + QStringList args; + if(conf->value("use_own_conf").toBool()) { + + conf->beginGroup("color-temp"); + QString method(conf->value("method").toString()); + if(method != "default") { + args.append("-m"); + args.append(method); + } + args.append("-t"); + args.append(QString("%1:%2").arg( + conf->value("day").toString(), + conf->value("night").toString())); + if(!conf->value("transition").toBool()) args.append("-r"); + conf->endGroup(); + + conf->beginGroup("location"); + QString provider(conf->value("provider").toString()); + if(provider != "default") { + args.append("-l"); + if(provider == "manual") { + args.append(QString("%1:%2").arg( + conf->value("latitude").toString(), + conf->value("longitude").toString())); + } else { + args.append(provider); + } + } + conf->endGroup(); + + conf->beginGroup("brightness"); + if(conf->value("adj-type").toInt() > 0) { + args.append("-b"); + if(conf->value("adj-type").toInt() > 1) { + args.append(QString("%1:%2").arg( + conf->value("day").toString(), + conf->value("night").toString())); + } else { + args.append(conf->value("day").toString()); + } + } + conf->endGroup(); + + conf->beginGroup("gamma"); + if(conf->value("adj-type").toInt() > 0) { + args.append("-g"); + if(conf->value("adj-type").toInt() > 1) { + args.append(conf->value("day").toString()); + } else { + args.append(conf->value("day").toString()); + } + } + conf->endGroup(); + + } else { + args.append("-c"); + args.append(conf->value("config_path").toString()); + } + return args; +} diff --git a/redshiftqt/redshiftqt.h b/redshiftqt/redshiftqt.h index 573952a..f553fad 100644 --- a/redshiftqt/redshiftqt.h +++ b/redshiftqt/redshiftqt.h @@ -1,15 +1,17 @@ #ifndef REDSHIFTQT_H #define REDSHIFTQT_H +#include #include -#include -#include -#include +#include +#include #include #include -#include +#include #include "redshiftqttray.h" +#include "redshiftqtprefs.h" +#include "redshiftqtlog.h" namespace Ui { class RedShiftQt; @@ -18,21 +20,36 @@ class RedShiftQt; class RedShiftQt : public QMainWindow { Q_OBJECT - public: explicit RedShiftQt(QWidget *parent = 0); ~RedShiftQt(); -protected slots: - void onToolButtonPathClicked(void); - void onCheckBoxLocalSettingsChanged(void); +private slots: + void onRedshiftStateChanged(QProcess::ProcessState); + void onReadyRead(); + + void onConfChanged(); + + void toggle(); + void suspend(QAction*); + void activated(QSystemTrayIcon::ActivationReason); + void showPrefs(); + void showLog(); private: - QSettings* prefs; - QProcess* redshift; + RedShiftQtTray *tray; + RedShiftQtPrefs *prefs; + RedShiftQtLog *log; + + QProcess *redshift; + QProcess *helper; + + QTimer *susp_timer; + QTimer *info_timer; + + QSettings *conf; - RedShiftQtTray* tray; - Ui::RedShiftQt* ui; + QStringList getArguments(void); }; #endif // REDSHIFTQT_H diff --git a/redshiftqt/redshiftqt.qrc b/redshiftqt/redshiftqt.qrc index 711337c..f800bf6 100644 --- a/redshiftqt/redshiftqt.qrc +++ b/redshiftqt/redshiftqt.qrc @@ -2,5 +2,8 @@ images/redshift.ico - + + images/redshift-status-off.svg + images/redshift-status-on.svg + diff --git a/redshiftqt/redshiftqt.ui b/redshiftqt/redshiftqt.ui deleted file mode 100644 index 5dd6146..0000000 --- a/redshiftqt/redshiftqt.ui +++ /dev/null @@ -1,408 +0,0 @@ - - - RedShiftQt - - - - 0 - 0 - 327 - 388 - - - - - 0 - 0 - - - - - :/app/icon:/app/icon - - - - - - - Import - - - - - - - User Location - - - - - - Latitude: - - - - - - - - 0 - 0 - - - - - 80 - 16777215 - - - - 51.47 - - - - - - - Longitude: - - - - - - - - 0 - 0 - - - - - 80 - 16777215 - - - - 00.00 - - - - - - - Provider: - - - - - - - - Manual - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - - Screen Gamma - - - - - - - 0 - 0 - - - - - 80 - 16777215 - - - - 1.0 - - - - - - - Day: - - - - - - - Night: - - - - - - - - 0 - 0 - - - - - 80 - 16777215 - - - - 1.0 - - - - - - - - - - Show this configuration dialog on application startup. - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - QDialogButtonBox::Apply|QDialogButtonBox::Cancel - - - false - - - - - - - Redshift Path - - - - - - Path: - - - - - - - - - - ... - - - - - - - - - - Colour Temperature - - - - - - Night: - - - - - - - - 0 - 0 - - - - - 80 - 16777215 - - - - 5500 - - - - - - - Transition - - - - - - - Day: - - - - - - - - 0 - 0 - - - - - 80 - 16777215 - - - - 3500 - - - - - - - - Default - - - - - - - - Method: - - - - - - - - - - Start Redshift on application startup. - - - - - - - Screen Brightness - - - - - - - 0 - 0 - - - - - 80 - 16777215 - - - - 1.0 - - - - - - - - 0 - 0 - - - - - 80 - 16777215 - - - - 1.0 - - - - - - - Night: - - - - - - - Day: - - - - - - - - - - Use RedShiftQt settings instead of redshift.conf - - - - - - - - - - - diff --git a/redshiftqt/redshiftqtlog.cpp b/redshiftqt/redshiftqtlog.cpp index 1148cf7..cf29fc5 100644 --- a/redshiftqt/redshiftqtlog.cpp +++ b/redshiftqt/redshiftqtlog.cpp @@ -2,13 +2,66 @@ #include "ui_redshiftqtlog.h" RedShiftQtLog::RedShiftQtLog(QWidget *parent) : - QMainWindow(parent), + QDialog(parent), ui(new Ui::RedShiftQtLog) { ui->setupUi(this); + setWindowTitle(parent->windowTitle() + " Log"); + + connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(clearLog())); + connect(ui->pushButtonSave, SIGNAL(clicked()), this, SLOT(saveLog())); + + ui->plainTextEditLog->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); } RedShiftQtLog::~RedShiftQtLog() { delete ui; } + +void RedShiftQtLog::setStatus(QString status) +{ + ui->labelStatusInfo->setText(status); +} + +void RedShiftQtLog::setInfo(QStringList info) +{ + +} + +void RedShiftQtLog::appendToLog(QString input) +{ + ui->plainTextEditLog->appendPlainText(QTime::currentTime().toString() + ": " + input); +} + +void RedShiftQtLog::closeEvent(QCloseEvent* event) +{ + //hide(); + //event->ignore(); +} + +void RedShiftQtLog::clearLog() +{ + ui->plainTextEditLog->clear(); +} + +void RedShiftQtLog::saveLog() +{ + QString filename = QFileDialog::getSaveFileName( + this, "Save Log", + QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/redshiftqt_log.txt", + "Text files (*.txt);;All Files (*)"); + + if (filename.isEmpty()) { + return; + } else { + QFile file(filename); + if (!file.open(QIODevice::WriteOnly)) { + QMessageBox::information(this, tr("Unable to open file"), file.errorString()); + return; + } + QDataStream out(&file); + out.writeBytes(ui->plainTextEditLog->toPlainText().toUtf8(), + static_cast(ui->plainTextEditLog->toPlainText().length())); + } +} diff --git a/redshiftqt/redshiftqtlog.h b/redshiftqt/redshiftqtlog.h index 96819cd..15f4da5 100644 --- a/redshiftqt/redshiftqtlog.h +++ b/redshiftqt/redshiftqtlog.h @@ -1,13 +1,19 @@ #ifndef REDSHIFTQTLOG_H #define REDSHIFTQTLOG_H -#include +#include +#include +#include +#include +#include +#include +#include namespace Ui { class RedShiftQtLog; } -class RedShiftQtLog : public QMainWindow +class RedShiftQtLog : public QDialog { Q_OBJECT @@ -15,8 +21,21 @@ class RedShiftQtLog : public QMainWindow explicit RedShiftQtLog(QWidget *parent = 0); ~RedShiftQtLog(); + void setStatus(QString); + void setInfo(QStringList); + void appendToLog(QString); + +protected: + void closeEvent(QCloseEvent* event); + +private slots: + void clearLog(void); + void saveLog(void); + private: Ui::RedShiftQtLog *ui; + + QTimer *timer; }; #endif // REDSHIFTQTLOG_H diff --git a/redshiftqt/redshiftqtlog.ui b/redshiftqt/redshiftqtlog.ui index 577bbc4..6155bcf 100644 --- a/redshiftqt/redshiftqtlog.ui +++ b/redshiftqt/redshiftqtlog.ui @@ -1,60 +1,196 @@ RedShiftQtLog - + 0 0 - 549 - 369 + 800 + 360 - - MainWindow - - - - - - - true - - - - - - - - - Clear - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - QDialogButtonBox::Close - - - - - - - + + + + + + + Information + + + + + + + 75 + true + true + + + + Location: + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Disabled + + + + + + + 6500K + + + + + + + N, W + + + + + + + Day + + + + + + + + 75 + true + true + + + + Temperature: + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + true + true + + + + Status: + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + true + true + + + + Period: + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + true + + + + + + + + + + + Save Log + + + + + + + Clear + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QDialogButtonBox::Close + + + + + + diff --git a/redshiftqt/redshiftqtprefs.cpp b/redshiftqt/redshiftqtprefs.cpp index 744edc7..d7264fb 100644 --- a/redshiftqt/redshiftqtprefs.cpp +++ b/redshiftqt/redshiftqtprefs.cpp @@ -1,43 +1,346 @@ -#include "redshiftqt.h" -#include "ui_redshiftqt.h" +#include "redshiftqtprefs.h" +#include "ui_redshiftqtprefs.h" - -RedShiftQt::RedShiftQt(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::RedShiftQt) +RedShiftQtPrefs::RedShiftQtPrefs(QWidget *parent) : + QDialog(parent), + ui(new Ui::RedShiftQtPrefs) { ui->setupUi(this); - setWindowTitle(qApp->applicationName()); + setWindowTitle(parent->windowTitle() + " Preferences"); + + conf = new QSettings( + QSettings::IniFormat, + QSettings::UserScope, + qApp->organizationName(), + qApp->applicationName(), + this); connect(ui->toolButtonPath, SIGNAL(clicked()), this, SLOT(onToolButtonPathClicked())); + connect(ui->toolButtonConf, SIGNAL(clicked()), this, SLOT(onToolButtonConfClicked())); + connect(ui->checkBoxLocalSettings, SIGNAL(stateChanged(int)), + this, SLOT(onCheckBoxLocalSettingsChanged(int))); + + connect(ui->comboBoxLocProvider, SIGNAL(currentTextChanged(QString)), + this, SLOT(onComboBoxLocProviderTextChanged(QString))); + connect(ui->pushButtonLocDetect, SIGNAL(clicked()), this, SLOT(requestLocation())); + connect(ui->checkBoxBr, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxBrStateChanged(int))); + connect(ui->checkBoxGam, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxGamStateChanged(int))); + + connect(ui->pushButtonImport, SIGNAL(clicked()), this, SLOT(onImportClicked())); + connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), + this, SLOT(onCancelClicked())); + connect(ui->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), + this, SLOT(onApplyClicked())); - connect(ui->checkBoxLocalSettings, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxLocalSettingsChanged())); + doubleSpinBoxListGamDay.append(ui->doubleSpinBoxGamDayR); + doubleSpinBoxListGamDay.append(ui->doubleSpinBoxGamDayG); + doubleSpinBoxListGamDay.append(ui->doubleSpinBoxGamDayB); - tray = new RedShiftQtTray(this); - tray->show(); + doubleSpinBoxListGamNight.append(ui->doubleSpinBoxGamNightR); + doubleSpinBoxListGamNight.append(ui->doubleSpinBoxGamNightG); + doubleSpinBoxListGamNight.append(ui->doubleSpinBoxGamNightB); - this->show(); +#ifdef Q_OS_LINUX + ui->comboBoxTempMethod->addItem("drm"); + ui->comboBoxTempMethod->addItem("randr"); + ui->comboBoxTempMethod->addItem("vidmode"); + ui->comboBoxLocProvider->addItem("geoclue2"); +#endif +#ifdef Q_OS_DARWIN + ui->comboBoxTempMethod->addItem("quartz"); + ui->comboBoxLocProvider->addItem("corelocation"); +#endif +#ifdef Q_OS_WIN + ui->comboBoxTempMethod->addItem("wingdi"); +#endif + ui->comboBoxLocProvider->addItem("manual"); + + onCheckBoxLocalSettingsChanged(Qt::CheckState::Unchecked); + onComboBoxLocProviderTextChanged("default"); + onCheckBoxBrStateChanged(Qt::CheckState::Unchecked); + onCheckBoxGamStateChanged(Qt::CheckState::Unchecked); + + loadConf(); } -RedShiftQt::~RedShiftQt() +RedShiftQtPrefs::~RedShiftQtPrefs() { delete ui; } -void RedShiftQt::onToolButtonPathClicked() +void RedShiftQtPrefs::onToolButtonPathClicked() { - QString path = QFileDialog::getOpenFileName(this, tr("Find redshift executable"), "/", tr("redshift (redshift.exe)")); + QString path = QFileDialog::getOpenFileName( + this, + tr("Find redshift executable"), + "", + "redshift executable (redshift.exe)"); ui->lineEditPath->setText(path); } -void RedShiftQt::onCheckBoxLocalSettingsChanged() +void RedShiftQtPrefs::onToolButtonConfClicked() +{ + QString conf = QFileDialog::getOpenFileName( + this, + tr("Find redshift configuration file"), + QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation).first(), + "redshift configuration (redshift.conf)"); + + ui->lineEditConf->setText(conf); +} + + +void RedShiftQtPrefs::onCheckBoxLocalSettingsChanged(int state) +{ + ui->groupBoxBr->setEnabled(state); + ui->groupBoxGam->setEnabled(state); + ui->groupBoxLoc->setEnabled(state); + ui->groupBoxTemp->setEnabled(state); +} + +void RedShiftQtPrefs::onComboBoxLocProviderTextChanged(QString text) +{ + if(text == "manual") { + ui->lineEditLocLat->setEnabled(true); + ui->lineEditLocLon->setEnabled(true); + ui->pushButtonLocDetect->setEnabled(true); + } else { + ui->lineEditLocLat->setEnabled(false); + ui->lineEditLocLon->setEnabled(false); + ui->pushButtonLocDetect->setEnabled(false); + } +} + +void RedShiftQtPrefs::requestLocation() +{ + ui->pushButtonLocDetect->setDisabled(true); + + if(manager.isNull()){ + manager = new QNetworkAccessManager(this); + connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); + + manager->get(QNetworkRequest(QUrl("http://ip-api.com/json"))); + } +} + +void RedShiftQtPrefs::replyFinished(QNetworkReply* reply) +{ + QString document(reply->readAll()); + manager->deleteLater(); + reply->deleteLater(); + + QJsonDocument parser; + QJsonObject json = parser.fromJson(document.toUtf8()).object(); + + QMessageBox msg; + QString info = QString("

Detected Location

" + "City: %1, %2, %3
" + "Timezone: %4
" + "IP: %5
").arg( + json["city"].toString(), + json["regionName"].toString(), + json["countryCode"].toString(), + json["timezone"].toString(), + json["query"].toString()); + msg.setText(info); + msg.exec(); + + ui->pushButtonLocDetect->setEnabled(true); + + ui->lineEditLocLat->setText(QString("%1").arg(json["lat"].toDouble())); + ui->lineEditLocLon->setText(QString("%1").arg(json["lon"].toDouble())); +} + +void RedShiftQtPrefs::onCheckBoxBrStateChanged(int state) { + ui->doubleSpinBoxBrDay->setEnabled(state > 0); + ui->doubleSpinBoxBrNight->setEnabled(state > 1); +} + +void RedShiftQtPrefs::onCheckBoxGamStateChanged(int state) { + doubleSpinBoxListGamDay.setEnabled(state > 0); + doubleSpinBoxListGamNight.setEnabled(state > 1); +} + +void RedShiftQtPrefs::onImportClicked() +{ + if(ui->lineEditConf->text().isEmpty()){ + ui->lineEditConf->setStyleSheet("background-color: rgba(255, 0, 0, 50);"); + ui->lineEditConf->setFocus(); + QMessageBox msg; + msg.setText("

Error:

Missing redshift cofiguration file location (redshift.conf)"); + msg.exec(); + return; + } else { + ui->lineEditConf->setStyleSheet(styleSheet()); + } + + importConf(); +} + +void RedShiftQtPrefs::onCancelClicked() +{ + loadConf(); +} + +void RedShiftQtPrefs::onApplyClicked() +{ + QStringList errors; + QMessageBox msg; + msg.setText("

Error(s):

"); + if(ui->lineEditPath->text().isEmpty()) { + errors.append("Missing redshift executable location."); + } else { + if(ui->checkBoxLocalSettings->checkState()) { + if(ui->comboBoxLocProvider->currentText() == "manual") { + if(ui->lineEditLocLat->text().isEmpty()) + errors.append("Missing location latitude."); + if(ui->lineEditLocLon->text().isEmpty()) + errors.append("Missing location longitude."); + } + } else { + if(ui->lineEditConf->text().isEmpty()) { + errors.append("Missing redshift cofiguration file location."); + } + } + } + + if(errors.isEmpty()) { + saveConf(); + emit confChanged(); + } + else { + msg.setText(msg.text() + errors.join("
")); + msg.exec(); + } +} + +void RedShiftQtPrefs::importConf() { - bool state = !ui->checkBoxLocalSettings->isChecked(); + QSettings import(ui->lineEditConf->text(), QSettings::IniFormat, this); + import.beginGroup("redshift"); + ui->spinBoxTempDay->setValue(import.value("temp-day").toInt()); + ui->spinBoxTempNight->setValue(import.value("temp-night").toInt()); + ui->checkBoxTempTrans->setChecked(import.value("transition").toBool()); + + double brightness_day = import.value("brightness-day").toDouble(); + double brightness_night = import.value("brightness-night").toDouble(); + if(brightness_day != 0.0 && brightness_night != 0.0) { + ui->checkBoxBr->setCheckState(Qt::CheckState::Checked); + ui->doubleSpinBoxBrDay->setValue(brightness_day); + ui->doubleSpinBoxBrNight->setValue(brightness_night); + } else { + double brightness = import.value("brightness").toDouble(); + if(brightness != 0.0) { + ui->checkBoxBr->setCheckState(Qt::CheckState::PartiallyChecked); + ui->doubleSpinBoxBrDay->setValue(brightness); + } else { + ui->checkBoxBr->setCheckState(Qt::CheckState::Unchecked); + } + } + + QStringList gamma_day = import.value("gamma-day").toString().split(':', QString::SkipEmptyParts); + QStringList gamma_night = import.value("gamma-night").toString().split(':', QString::SkipEmptyParts); + if(!gamma_day.isEmpty() && !gamma_night.isEmpty()) { + ui->checkBoxGam->setCheckState(Qt::CheckState::Checked); + doubleSpinBoxListGamDay.setValue(gamma_day); + doubleSpinBoxListGamNight.setValue(gamma_night); + } else { + QStringList gamma = import.value("gamma").toString().split(':', QString::SkipEmptyParts); + if(!gamma.isEmpty()) { + ui->checkBoxGam->setCheckState(Qt::CheckState::PartiallyChecked); + doubleSpinBoxListGamDay.setValue(gamma); + } else { + ui->checkBoxGam->setCheckState(Qt::CheckState::Unchecked); + } + } + + QString method = import.value("adjustment-method").toString(); + QString provider = import.value("location-provider").toString(); + import.endGroup(); - ui->groupBoxBrightness->setDisabled(state); - ui->groupBoxGamma->setDisabled(state); - ui->groupBoxLocation->setDisabled(state); - ui->groupBoxTemp->setDisabled(state); + if(!method.isEmpty()) { + ui->comboBoxTempMethod->setCurrentText(method); + import.beginGroup(method); + import.endGroup(); + } + if(!provider.isEmpty()) { + ui->comboBoxLocProvider->setCurrentText(provider); + import.beginGroup(provider); + ui->lineEditLocLat->setText(import.value("lat").toString()); + ui->lineEditLocLon->setText(import.value("lon").toString()); + import.endGroup(); + } } + +void RedShiftQtPrefs::loadConf() +{ + ui->lineEditPath->setText(conf->value("redshift_path", "").toString()); + ui->lineEditConf->setText(conf->value("config_path", "").toString()); + ui->checkBoxLocalSettings->setChecked(conf->value("use_own_conf").toBool()); + ui->checkBoxRun->setChecked(conf->value("start_enabled").toBool()); + ui->checkBoxShow->setChecked(conf->value("show_prefs").toBool()); + + conf->beginGroup("color-temp"); + QString method = conf->value("method").toString(); + ui->comboBoxTempMethod->setCurrentText(method); + ui->spinBoxTempDay->setValue(conf->value("day").toInt()); + ui->spinBoxTempNight->setValue(conf->value("night").toInt()); + ui->checkBoxTempTrans->setChecked(conf->value("transition").toBool()); + conf->endGroup(); + + conf->beginGroup("location"); + QString provider = conf->value("provider").toString(); + ui->comboBoxLocProvider->setCurrentText(provider); + ui->lineEditLocLat->setText(conf->value("latitude").toString()); + ui->lineEditLocLon->setText(conf->value("longitude").toString()); + conf->endGroup(); + + conf->beginGroup("brightness"); + ui->checkBoxBr->setCheckState(static_cast(conf->value("adj-type").toInt())); + ui->doubleSpinBoxBrDay->setValue(conf->value("day").toDouble()); + ui->doubleSpinBoxBrNight->setValue(conf->value("night").toDouble()); + conf->endGroup(); + + conf->beginGroup("gamma"); + ui->checkBoxGam->setCheckState(static_cast(conf->value("adj-type").toInt())); + doubleSpinBoxListGamDay.setValue(conf->value("day").toString().split(':', QString::SkipEmptyParts)); + doubleSpinBoxListGamNight.setValue(conf->value("night").toString().split(':', QString::SkipEmptyParts)); + conf->endGroup(); +} + +void RedShiftQtPrefs::saveConf() +{ + conf->setValue("redshift_path", ui->lineEditPath->text()); + conf->setValue("config_path", ui->lineEditConf->text()); + conf->setValue("use_own_conf", ui->checkBoxLocalSettings->checkState()); + conf->setValue("start_enabled", ui->checkBoxRun->checkState()); + conf->setValue("show_prefs", ui->checkBoxShow->checkState()); + + conf->beginGroup("color-temp"); + conf->setValue("method", ui->comboBoxTempMethod->currentText()); + conf->setValue("day", ui->spinBoxTempDay->value()); + conf->setValue("night", ui->spinBoxTempNight->value()); + conf->setValue("transition", ui->checkBoxTempTrans->checkState()); + conf->endGroup(); + + conf->beginGroup("location"); + conf->setValue("provider", ui->comboBoxLocProvider->currentText()); + conf->setValue("latitude", ui->lineEditLocLat->text().toDouble()); + conf->setValue("longitude", ui->lineEditLocLon->text().toDouble()); + conf->endGroup(); + + conf->beginGroup("brightness"); + conf->setValue("adj-type", ui->checkBoxBr->checkState()); + conf->setValue("day", ui->doubleSpinBoxBrDay->value()); + conf->setValue("night", ui->doubleSpinBoxBrNight->value()); + conf->endGroup(); + + conf->beginGroup("gamma"); + conf->setValue("adj-type", ui->checkBoxGam->checkState()); + conf->setValue("day", doubleSpinBoxListGamDay.value().join(":")); + conf->setValue("night", doubleSpinBoxListGamNight.value().join(":")); + conf->endGroup(); +} + diff --git a/redshiftqt/redshiftqtprefs.h b/redshiftqt/redshiftqtprefs.h new file mode 100644 index 0000000..c53c229 --- /dev/null +++ b/redshiftqt/redshiftqtprefs.h @@ -0,0 +1,63 @@ +#ifndef REDSHIFTQTPREFS_H +#define REDSHIFTQTPREFS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qdoublespinboxlist.h" + +namespace Ui { +class RedShiftQtPrefs; +} + +class RedShiftQtPrefs : public QDialog +{ + Q_OBJECT + +public: + explicit RedShiftQtPrefs(QWidget *parent = 0); + ~RedShiftQtPrefs(); + +signals: + void confChanged(); + +private slots: + void onToolButtonPathClicked(void); + void onToolButtonConfClicked(void); + void onCheckBoxLocalSettingsChanged(int); + + void onComboBoxLocProviderTextChanged(QString); + void requestLocation(void); + void replyFinished(QNetworkReply*); + + void onCheckBoxBrStateChanged(int); + void onCheckBoxGamStateChanged(int); + + void onImportClicked(void); + void onCancelClicked(void); + void onApplyClicked(void); + +private: + void importConf(void); + void loadConf(void); + void saveConf(void); + + Ui::RedShiftQtPrefs *ui; + + QSettings* conf; + QPointer manager; + + QDoubleSpinBoxList doubleSpinBoxListGamDay; + QDoubleSpinBoxList doubleSpinBoxListGamNight; +}; + +#endif // REDSHIFTQTPREFS_H diff --git a/redshiftqt/redshiftqtprefs.ui b/redshiftqt/redshiftqtprefs.ui new file mode 100644 index 0000000..ce676c0 --- /dev/null +++ b/redshiftqt/redshiftqtprefs.ui @@ -0,0 +1,513 @@ + + + RedShiftQtPrefs + + + + 0 + 0 + 382 + 447 + + + + + + + Redshift Path + + + + + + + + + Conf: + + + + + + + ... + + + + + + + Path: + + + + + + + + + + ... + + + + + + + Use RedShiftQt settings instead of redshift.conf + + + + + lineEditConf + labelConf + toolButtonConf + labelPath + toolButtonPath + checkBoxLocalSettings + lineEditPath + + + + + + + + Colour Temperature + + + + + + Smooth Transition + + + + + + + Day: + + + + + + + Night: + + + + + + + + default + + + + + + + + Method: + + + + + + + + 80 + 0 + + + + 3500 + + + 6500 + + + 100 + + + 6500 + + + + + + + + 80 + 0 + + + + 3500 + + + 6500 + + + 100 + + + + + + + + + + Screen Gamma + + + + + + Night: + + + + + + + Day: + + + + + + + true + + + 2 + + + 0.100000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + 2 + + + 0.100000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + 2 + + + 0.100000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + Adjust Gamma + + + false + + + true + + + + + + + 2 + + + 0.100000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + 2 + + + 0.100000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + 2 + + + 0.100000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + + + + Screen Brightness + + + + + + Day: + + + + + + + Night: + + + + + + + + 80 + 0 + + + + 2 + + + 0.100000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + + 80 + 0 + + + + 2 + + + 0.100000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + Adjust Brightness + + + false + + + true + + + + + + + + + + User Location + + + + + + 00.00 + + + + + + + Provider: + + + + + + + + default + + + + + + + + Longitude: + + + + + + + Latitude: + + + + + + + 00.00 + + + + + + + Detect Location + + + + + + + + + + + + Start with RedShift enabled. + + + + + + + Show this configuration dialog on application startup. + + + true + + + + + + + + + Import + + + + + + + Qt::Horizontal + + + + 62 + 20 + + + + + + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel + + + + + + + + + + diff --git a/redshiftqt/redshiftqttray.cpp b/redshiftqt/redshiftqttray.cpp index 1220025..f988010 100644 --- a/redshiftqt/redshiftqttray.cpp +++ b/redshiftqt/redshiftqttray.cpp @@ -2,45 +2,56 @@ RedShiftQtTray::RedShiftQtTray(QMainWindow* parent) : QSystemTrayIcon(parent) { - actionPrefs = new QAction(tr("&Preferences"), this); - connect(actionPrefs, SIGNAL(triggered()), this, SLOT(showPrefs())); + menu = new QMenu(); - actionLog = new QAction(tr("&View Log"), this); - connect(actionLog, SIGNAL(triggered()), this, SLOT(showLog())); + status = new QAction(tr("&Enabled"), this); + connect(status, SIGNAL(triggered()), parent, SLOT(toggle())); + status->setCheckable(true); + menu->addAction(status); - actionQuit = new QAction(tr("&Quit"), this); - connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); + suspend = new QMenu(tr("&Suspend for")); + connect(suspend, SIGNAL(triggered(QAction*)), parent, SLOT(suspend(QAction*))); - trayMenu = new QMenu(); - trayMenu->addAction(actionPrefs); - trayMenu->addAction(actionLog); - trayMenu->addSeparator(); - trayMenu->addAction(actionQuit); + suspend30m = new QAction(tr("&30 minutes")); + suspend30m->setData(30); + suspend->addAction(suspend30m); - setContextMenu(trayMenu); - setIcon(parent->windowIcon()); - setToolTip(parent->windowTitle()); + suspend1h = new QAction(tr("&1 hour")); + suspend1h->setData(60); + suspend->addAction(suspend1h); - connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - this, SLOT(activated(QSystemTrayIcon::ActivationReason))); -} + suspend2h = new QAction(tr("&2 hours")); + suspend2h->setData(120); + suspend->addAction(suspend2h); -RedShiftQtTray::~RedShiftQtTray() -{ + menu->addMenu(suspend); -} + log = new QAction(tr("&View Info"), this); + connect(log, SIGNAL(triggered()), parent, SLOT(showLog())); + menu->addAction(log); -void RedShiftQtTray::showPrefs() -{ + menu->addSeparator(); -} + prefs = new QAction(tr("&Preferences"), this); + connect(prefs, SIGNAL(triggered()), parent, SLOT(showPrefs())); + menu->addAction(prefs); -void RedShiftQtTray::showLog() -{ + menu->addSeparator(); + + quit = new QAction(tr("&Quit"), this); + connect(quit, SIGNAL(triggered()), qApp, SLOT(quit())); + menu->addAction(quit); + + setContextMenu(menu); + setIcon(parent->windowIcon()); + setToolTip(parent->windowTitle()); + connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + parent, SLOT(activated(QSystemTrayIcon::ActivationReason))); } -void RedShiftQtTray::activated(QSystemTrayIcon::ActivationReason reason) +RedShiftQtTray::~RedShiftQtTray() { } + diff --git a/redshiftqt/redshiftqttray.h b/redshiftqt/redshiftqttray.h index d0d20d1..330c47c 100644 --- a/redshiftqt/redshiftqttray.h +++ b/redshiftqt/redshiftqttray.h @@ -2,30 +2,33 @@ #define REDSHIFTQTTRAY_H #include -#include #include +#include #include #include class RedShiftQtTray : public QSystemTrayIcon { Q_OBJECT - public: explicit RedShiftQtTray(QMainWindow *parent = 0); ~RedShiftQtTray(); -private slots: - void showPrefs(); - void showLog(); - - void activated(QSystemTrayIcon::ActivationReason); + QAction* status; + QMenu* suspend; private: - QAction* actionPrefs; - QAction* actionLog; - QAction* actionQuit; - QMenu* trayMenu; + + QAction* suspend30m; + QAction* suspend1h; + QAction* suspend2h; + + QAction autostart; + + QAction* prefs; + QAction* log; + QAction* quit; + QMenu* menu; }; #endif // REDSHIFTQTTRAY_H