Skip to content

Commit a50d46d

Browse files
In preparation for 0.1.0 release
1 parent dc3d8c0 commit a50d46d

7 files changed

+103
-99
lines changed

redshiftqt/redshiftqt.cpp

+63-73
Original file line numberDiff line numberDiff line change
@@ -24,121 +24,110 @@ RedShiftQt::RedShiftQt(QWidget *parent) :
2424

2525
log = new RedShiftQtLog(this);
2626

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

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

3434
redshift = new QProcess(this);
35-
connect(redshift, SIGNAL(stateChanged(QProcess::ProcessState)),
36-
this, SLOT(onRedshiftStateChanged(QProcess::ProcessState)));
37-
//connect(redshift, SIGNAL(readyRead()), this, SLOT(onProcReadyRead()));
38-
//connect(redshift, SINGAL(readyReadStandardError(), this, SLOT(onProcReadyRead)));
39-
onRedshiftStateChanged(QProcess::NotRunning);
40-
35+
connect(redshift, SIGNAL(started()), this, SLOT(onRedshiftStarted()));
36+
connect(redshift, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onRedshiftFinished()));
4137
redshift->setProgram(conf->value("redshift_path").toString());
4238
redshift->setArguments(getArguments());
43-
39+
onRedshiftFinished();
4440
if(conf->value("start_enabled").toBool())
4541
redshift->start(QProcess::ReadOnly);
4642

47-
helper = new QProcess(this);
48-
helper->setProgram(conf->value("redshift_path").toString());
49-
5043
prefs = new RedShiftQtPrefs(this);
5144
connect(prefs, SIGNAL(confChanged()), this, SLOT(onConfChanged()));
5245

5346
if(conf->value("show_prefs").toBool())
54-
prefs->show();
47+
showPrefs();
5548
}
5649

5750
RedShiftQt::~RedShiftQt()
51+
{
52+
stopRedshift();
53+
}
54+
55+
QString RedShiftQt::getRedshiftInfo()
56+
{
57+
helper->setArguments(QStringList("-pv"));
58+
helper->start(QProcess::ReadOnly);
59+
helper->waitForFinished();
60+
return(helper->readAllStandardOutput());
61+
}
62+
63+
void RedShiftQt::startRedshift()
64+
{
65+
timer->stop();
66+
redshift->start(QProcess::ReadOnly);
67+
redshift->waitForStarted();
68+
}
69+
70+
void RedShiftQt::stopRedshift()
5871
{
5972
redshift->kill();
6073
redshift->waitForFinished();
61-
helper->kill();
74+
helper->setArguments(QStringList("-x"));
75+
helper->start(QProcess::ReadOnly);
6276
helper->waitForFinished();
6377
}
6478

65-
void RedShiftQt::onRedshiftStateChanged(QProcess::ProcessState state)
79+
void RedShiftQt::onRedshiftStarted()
6680
{
67-
switch(state) {
68-
case QProcess::Running :
69-
tray->setIcon(QIcon(":/tray/on"));
70-
tray->setToolTip(windowTitle() +": Running");
71-
tray->status->setChecked(true);
72-
tray->suspend->setEnabled(true);
73-
log->setStatus(QString("Enabled"));
74-
log->appendToLog(redshift->program().toUtf8() + " " + redshift->arguments().join(" ").toUtf8());
75-
break;
76-
77-
case QProcess::NotRunning :
78-
tray->setIcon(QIcon(":/tray/off"));
79-
tray->setToolTip(windowTitle() +": Suspended");
80-
tray->status->setChecked(false);
81-
tray->suspend->setEnabled(false);
82-
log->setInfo(QStringList("Disabled"));
83-
log->appendToLog("Redshift stopped");
84-
break;
85-
86-
default:
87-
break;
88-
}
89-
qDebug("Process state: %d", redshift->state());
81+
tray->setIcon(QIcon(":/tray/on"));
82+
tray->setToolTip(windowTitle() + ": Running");
83+
tray->status->setChecked(true);
84+
tray->suspend->setEnabled(true);
85+
log->setStatus(QString("Enabled"));
86+
log->setInfo(getRedshiftInfo());
87+
log->appendToLog("Redshift was started with: " + redshift->arguments().join(" ").toUtf8());
9088
}
9189

92-
void RedShiftQt::onReadyRead()
90+
void RedShiftQt::onRedshiftFinished()
9391
{
94-
92+
tray->setIcon(QIcon(":/tray/off"));
93+
tray->setToolTip(windowTitle() + ": Suspended");
94+
tray->status->setChecked(false);
95+
tray->suspend->setEnabled(false);
96+
log->setStatus(QString("Disabled"));
97+
log->setInfo(getRedshiftInfo());
98+
log->appendToLog("Redshift was suspended");
9599
}
96100

97101
void RedShiftQt::onConfChanged()
98102
{
99103
int state = redshift->state();
100-
if(state) {
101-
redshift->kill();
102-
redshift->waitForFinished();
103-
}
104+
if(state) stopRedshift();
104105
redshift->setProgram(conf->value("redshift_path").toString());
105106
redshift->setArguments(getArguments());
106107
helper->setProgram(conf->value("redshift_path").toString());
107-
if(state) {
108-
redshift->start(QProcess::ReadOnly);
109-
}
108+
if(state) startRedshift();
110109
}
111110

112-
void RedShiftQt::toggle(void)
111+
void RedShiftQt::toggleRedshift()
113112
{
114-
if(redshift->state() == QProcess::Running) {
115-
redshift->kill();
116-
redshift->waitForFinished();
117-
helper->setArguments(QStringList("-x"));
118-
helper->start(QProcess::ReadOnly);
119-
helper->waitForFinished();
120-
} else {
121-
susp_timer->stop();
122-
redshift->start(QProcess::ReadOnly);
123-
redshift->waitForStarted();
124-
}
113+
if(redshift->state()) stopRedshift();
114+
else startRedshift();
125115
}
126116

127-
void RedShiftQt::suspend(QAction* action)
117+
void RedShiftQt::toggleRedshift(QSystemTrayIcon::ActivationReason reason)
128118
{
129-
toggle();
130-
131-
susp_timer->setInterval(action->data().toInt() * 60 * 1000);
132-
susp_timer->start();
133-
134-
tray->setToolTip(tray->toolTip() + QString(" for %1 minutes").arg(action->data().toInt()));
135-
log->appendToLog(QString("Suspending reshift for %1 minutes").arg(susp_timer->interval()/60/1000));
119+
if(reason == QSystemTrayIcon::Trigger) toggleRedshift();
136120
}
137121

138-
void RedShiftQt::activated(QSystemTrayIcon::ActivationReason reason)
122+
void RedShiftQt::suspendRedshift(QAction* action)
139123
{
140-
if(reason == QSystemTrayIcon::Trigger)
141-
toggle();
124+
stopRedshift();
125+
126+
timer->setInterval(action->data().toInt() * 60 * 1000);
127+
timer->start();
128+
129+
tray->setToolTip(tray->toolTip() + QString(" for %1 minutes").arg(action->data().toInt()));
130+
log->appendToLog(QString("Suspending reshift for %1 minutes").arg(timer->interval()/60/1000));
142131
}
143132

144133
void RedShiftQt::showPrefs()
@@ -149,6 +138,7 @@ void RedShiftQt::showPrefs()
149138

150139
void RedShiftQt::showLog()
151140
{
141+
log->setInfo(getRedshiftInfo());
152142
log->setVisible(true);
153143
log->raise();
154144
}

redshiftqt/redshiftqt.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ class RedShiftQt : public QMainWindow
2525
~RedShiftQt();
2626

2727
private slots:
28-
void onRedshiftStateChanged(QProcess::ProcessState);
29-
void onReadyRead();
28+
void startRedshift();
29+
void stopRedshift();
30+
void onRedshiftStarted();
31+
void onRedshiftFinished();
32+
QString getRedshiftInfo();
3033

3134
void onConfChanged();
3235

33-
void toggle();
34-
void suspend(QAction*);
35-
void activated(QSystemTrayIcon::ActivationReason);
36+
void toggleRedshift();
37+
void toggleRedshift(QSystemTrayIcon::ActivationReason);
38+
void suspendRedshift(QAction*);
3639
void showPrefs();
3740
void showLog();
3841

@@ -44,8 +47,7 @@ private slots:
4447
QProcess *redshift;
4548
QProcess *helper;
4649

47-
QTimer *susp_timer;
48-
QTimer *info_timer;
50+
QTimer *timer;
4951

5052
QSettings *conf;
5153

redshiftqt/redshiftqtlog.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,26 @@ RedShiftQtLog::~RedShiftQtLog()
2121

2222
void RedShiftQtLog::setStatus(QString status)
2323
{
24-
ui->labelStatusInfo->setText(status);
24+
ui->labelStatusValue->setText(status);
2525
}
2626

27-
void RedShiftQtLog::setInfo(QStringList info)
27+
void RedShiftQtLog::setInfo(QString info)
2828
{
29-
29+
QStringList info_list = info.split('\n');
30+
QStringList::iterator i;
31+
for(i = info_list.begin(); i != info_list.end(); ++i) {
32+
if(i->startsWith("Location")) {
33+
ui->labelLocValue->setText(i->split(": ").at(1));
34+
++i;
35+
}
36+
if(i->startsWith("Period")) {
37+
ui->labelPeriodValue->setText(i->split(": ").at(1));
38+
++i;
39+
}
40+
if(i->startsWith("Color temp")) {
41+
ui->labelTempValue->setText(i->split(": ").at(1));
42+
}
43+
}
3044
}
3145

3246
void RedShiftQtLog::appendToLog(QString input)

redshiftqt/redshiftqtlog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RedShiftQtLog : public QDialog
2222
~RedShiftQtLog();
2323

2424
void setStatus(QString);
25-
void setInfo(QStringList);
25+
void setInfo(QString);
2626
void appendToLog(QString);
2727

2828
protected:

redshiftqt/redshiftqtlog.ui

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,28 @@
4040
</widget>
4141
</item>
4242
<item row="0" column="2">
43-
<widget class="QLabel" name="labelStatusInfo">
43+
<widget class="QLabel" name="labelStatusValue">
4444
<property name="text">
4545
<string>Disabled</string>
4646
</property>
4747
</widget>
4848
</item>
4949
<item row="2" column="2">
50-
<widget class="QLabel" name="labelTempInfo">
50+
<widget class="QLabel" name="labelTempValue">
5151
<property name="text">
5252
<string>6500K</string>
5353
</property>
5454
</widget>
5555
</item>
5656
<item row="1" column="2">
57-
<widget class="QLabel" name="labelLocInfo">
57+
<widget class="QLabel" name="labelLocValue">
5858
<property name="text">
5959
<string>N, W</string>
6060
</property>
6161
</widget>
6262
</item>
6363
<item row="3" column="2">
64-
<widget class="QLabel" name="labelPeriodInfo">
64+
<widget class="QLabel" name="labelPeriodValue">
6565
<property name="text">
6666
<string>Day</string>
6767
</property>

redshiftqt/redshiftqtprefs.ui

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
<ui version="4.0">
33
<class>RedShiftQtPrefs</class>
44
<widget class="QDialog" name="RedShiftQtPrefs">
5-
<property name="geometry">
6-
<rect>
7-
<x>0</x>
8-
<y>0</y>
9-
<width>382</width>
10-
<height>447</height>
11-
</rect>
5+
<property name="sizePolicy">
6+
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
7+
<horstretch>0</horstretch>
8+
<verstretch>0</verstretch>
9+
</sizepolicy>
1210
</property>
1311
<layout class="QVBoxLayout" name="verticalLayout">
1412
<item>
@@ -131,7 +129,7 @@
131129
<number>100</number>
132130
</property>
133131
<property name="value">
134-
<number>6500</number>
132+
<number>5500</number>
135133
</property>
136134
</widget>
137135
</item>

redshiftqt/redshiftqttray.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ RedShiftQtTray::RedShiftQtTray(QMainWindow* parent) : QSystemTrayIcon(parent)
55
menu = new QMenu();
66

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

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

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

4949
connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
50-
parent, SLOT(activated(QSystemTrayIcon::ActivationReason)));
50+
parent, SLOT(toggleRedshift(QSystemTrayIcon::ActivationReason)));
5151
}
5252

5353
RedShiftQtTray::~RedShiftQtTray()

0 commit comments

Comments
 (0)