Skip to content

Commit

Permalink
In preparation for 0.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
loathingKernel committed Oct 1, 2017
1 parent dc3d8c0 commit a50d46d
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 99 deletions.
136 changes: 63 additions & 73 deletions redshiftqt/redshiftqt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,121 +24,110 @@ RedShiftQt::RedShiftQt(QWidget *parent) :

log = new RedShiftQtLog(this);

info_timer = new QTimer(this);
info_timer->setTimerType(Qt::VeryCoarseTimer);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(startRedshift()));
timer->setTimerType(Qt::VeryCoarseTimer);

susp_timer = new QTimer(this);
connect(susp_timer, SIGNAL(timeout()), this, SLOT(toggle()));
susp_timer->setTimerType(Qt::VeryCoarseTimer);
helper = new QProcess(this);
helper->setProgram(conf->value("redshift_path").toString());

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);

connect(redshift, SIGNAL(started()), this, SLOT(onRedshiftStarted()));
connect(redshift, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onRedshiftFinished()));
redshift->setProgram(conf->value("redshift_path").toString());
redshift->setArguments(getArguments());

onRedshiftFinished();
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();
showPrefs();
}

RedShiftQt::~RedShiftQt()
{
stopRedshift();
}

QString RedShiftQt::getRedshiftInfo()
{
helper->setArguments(QStringList("-pv"));
helper->start(QProcess::ReadOnly);
helper->waitForFinished();
return(helper->readAllStandardOutput());
}

void RedShiftQt::startRedshift()
{
timer->stop();
redshift->start(QProcess::ReadOnly);
redshift->waitForStarted();
}

void RedShiftQt::stopRedshift()
{
redshift->kill();
redshift->waitForFinished();
helper->kill();
helper->setArguments(QStringList("-x"));
helper->start(QProcess::ReadOnly);
helper->waitForFinished();
}

void RedShiftQt::onRedshiftStateChanged(QProcess::ProcessState state)
void RedShiftQt::onRedshiftStarted()
{
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());
tray->setIcon(QIcon(":/tray/on"));
tray->setToolTip(windowTitle() + ": Running");
tray->status->setChecked(true);
tray->suspend->setEnabled(true);
log->setStatus(QString("Enabled"));
log->setInfo(getRedshiftInfo());
log->appendToLog("Redshift was started with: " + redshift->arguments().join(" ").toUtf8());
}

void RedShiftQt::onReadyRead()
void RedShiftQt::onRedshiftFinished()
{

tray->setIcon(QIcon(":/tray/off"));
tray->setToolTip(windowTitle() + ": Suspended");
tray->status->setChecked(false);
tray->suspend->setEnabled(false);
log->setStatus(QString("Disabled"));
log->setInfo(getRedshiftInfo());
log->appendToLog("Redshift was suspended");
}

void RedShiftQt::onConfChanged()
{
int state = redshift->state();
if(state) {
redshift->kill();
redshift->waitForFinished();
}
if(state) stopRedshift();
redshift->setProgram(conf->value("redshift_path").toString());
redshift->setArguments(getArguments());
helper->setProgram(conf->value("redshift_path").toString());
if(state) {
redshift->start(QProcess::ReadOnly);
}
if(state) startRedshift();
}

void RedShiftQt::toggle(void)
void RedShiftQt::toggleRedshift()
{
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();
}
if(redshift->state()) stopRedshift();
else startRedshift();
}

void RedShiftQt::suspend(QAction* action)
void RedShiftQt::toggleRedshift(QSystemTrayIcon::ActivationReason reason)
{
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));
if(reason == QSystemTrayIcon::Trigger) toggleRedshift();
}

void RedShiftQt::activated(QSystemTrayIcon::ActivationReason reason)
void RedShiftQt::suspendRedshift(QAction* action)
{
if(reason == QSystemTrayIcon::Trigger)
toggle();
stopRedshift();

timer->setInterval(action->data().toInt() * 60 * 1000);
timer->start();

tray->setToolTip(tray->toolTip() + QString(" for %1 minutes").arg(action->data().toInt()));
log->appendToLog(QString("Suspending reshift for %1 minutes").arg(timer->interval()/60/1000));
}

void RedShiftQt::showPrefs()
Expand All @@ -149,6 +138,7 @@ void RedShiftQt::showPrefs()

void RedShiftQt::showLog()
{
log->setInfo(getRedshiftInfo());
log->setVisible(true);
log->raise();
}
Expand Down
16 changes: 9 additions & 7 deletions redshiftqt/redshiftqt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ class RedShiftQt : public QMainWindow
~RedShiftQt();

private slots:
void onRedshiftStateChanged(QProcess::ProcessState);
void onReadyRead();
void startRedshift();
void stopRedshift();
void onRedshiftStarted();
void onRedshiftFinished();
QString getRedshiftInfo();

void onConfChanged();

void toggle();
void suspend(QAction*);
void activated(QSystemTrayIcon::ActivationReason);
void toggleRedshift();
void toggleRedshift(QSystemTrayIcon::ActivationReason);
void suspendRedshift(QAction*);
void showPrefs();
void showLog();

Expand All @@ -44,8 +47,7 @@ private slots:
QProcess *redshift;
QProcess *helper;

QTimer *susp_timer;
QTimer *info_timer;
QTimer *timer;

QSettings *conf;

Expand Down
20 changes: 17 additions & 3 deletions redshiftqt/redshiftqtlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@ RedShiftQtLog::~RedShiftQtLog()

void RedShiftQtLog::setStatus(QString status)
{
ui->labelStatusInfo->setText(status);
ui->labelStatusValue->setText(status);
}

void RedShiftQtLog::setInfo(QStringList info)
void RedShiftQtLog::setInfo(QString info)
{

QStringList info_list = info.split('\n');
QStringList::iterator i;
for(i = info_list.begin(); i != info_list.end(); ++i) {
if(i->startsWith("Location")) {
ui->labelLocValue->setText(i->split(": ").at(1));
++i;
}
if(i->startsWith("Period")) {
ui->labelPeriodValue->setText(i->split(": ").at(1));
++i;
}
if(i->startsWith("Color temp")) {
ui->labelTempValue->setText(i->split(": ").at(1));
}
}
}

void RedShiftQtLog::appendToLog(QString input)
Expand Down
2 changes: 1 addition & 1 deletion redshiftqt/redshiftqtlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RedShiftQtLog : public QDialog
~RedShiftQtLog();

void setStatus(QString);
void setInfo(QStringList);
void setInfo(QString);
void appendToLog(QString);

protected:
Expand Down
8 changes: 4 additions & 4 deletions redshiftqt/redshiftqtlog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="labelStatusInfo">
<widget class="QLabel" name="labelStatusValue">
<property name="text">
<string>Disabled</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="labelTempInfo">
<widget class="QLabel" name="labelTempValue">
<property name="text">
<string>6500K</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="labelLocInfo">
<widget class="QLabel" name="labelLocValue">
<property name="text">
<string>N, W</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="labelPeriodInfo">
<widget class="QLabel" name="labelPeriodValue">
<property name="text">
<string>Day</string>
</property>
Expand Down
14 changes: 6 additions & 8 deletions redshiftqt/redshiftqtprefs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
<ui version="4.0">
<class>RedShiftQtPrefs</class>
<widget class="QDialog" name="RedShiftQtPrefs">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>382</width>
<height>447</height>
</rect>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
Expand Down Expand Up @@ -131,7 +129,7 @@
<number>100</number>
</property>
<property name="value">
<number>6500</number>
<number>5500</number>
</property>
</widget>
</item>
Expand Down
6 changes: 3 additions & 3 deletions redshiftqt/redshiftqttray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ RedShiftQtTray::RedShiftQtTray(QMainWindow* parent) : QSystemTrayIcon(parent)
menu = new QMenu();

status = new QAction(tr("&Enabled"), this);
connect(status, SIGNAL(triggered()), parent, SLOT(toggle()));
connect(status, SIGNAL(triggered()), parent, SLOT(toggleRedshift()));
status->setCheckable(true);
menu->addAction(status);

suspend = new QMenu(tr("&Suspend for"));
connect(suspend, SIGNAL(triggered(QAction*)), parent, SLOT(suspend(QAction*)));
connect(suspend, SIGNAL(triggered(QAction*)), parent, SLOT(suspendRedshift(QAction*)));

suspend30m = new QAction(tr("&30 minutes"));
suspend30m->setData(30);
Expand Down Expand Up @@ -47,7 +47,7 @@ RedShiftQtTray::RedShiftQtTray(QMainWindow* parent) : QSystemTrayIcon(parent)
setToolTip(parent->windowTitle());

connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
parent, SLOT(activated(QSystemTrayIcon::ActivationReason)));
parent, SLOT(toggleRedshift(QSystemTrayIcon::ActivationReason)));
}

RedShiftQtTray::~RedShiftQtTray()
Expand Down

0 comments on commit a50d46d

Please sign in to comment.