Added interval argument (-i/--interval)
This commit is contained in:
parent
68eb540e41
commit
50be6a3db4
7 changed files with 1715 additions and 1693 deletions
13
.gitignore
vendored
13
.gitignore
vendored
|
|
@ -1,11 +1,11 @@
|
||||||
bin/
|
# General
|
||||||
build/
|
build/
|
||||||
local/
|
local/
|
||||||
spacetray
|
|
||||||
*~
|
*~
|
||||||
|
|
||||||
# CLion
|
# CLion
|
||||||
.idea/
|
.idea/
|
||||||
|
.junie/
|
||||||
spacetray.iml
|
spacetray.iml
|
||||||
|
|
||||||
# CMake
|
# CMake
|
||||||
|
|
@ -54,12 +54,3 @@ cmake-build-debug/
|
||||||
*.su
|
*.su
|
||||||
*.idb
|
*.idb
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
# Kernel Module Compile Results
|
|
||||||
*.mod*
|
|
||||||
*.cmd
|
|
||||||
.tmp_versions/
|
|
||||||
modules.order
|
|
||||||
Module.symvers
|
|
||||||
Mkfile.old
|
|
||||||
dkms.conf
|
|
||||||
|
|
|
||||||
25
README.md
25
README.md
|
|
@ -29,22 +29,20 @@ Change into the new directory:
|
||||||
|
|
||||||
cd spacetray
|
cd spacetray
|
||||||
|
|
||||||
To compile the sources, run:
|
To configure and compile the sources, run:
|
||||||
|
|
||||||
mkdir build
|
cmake -S . -B build
|
||||||
cd build
|
cmake --build build
|
||||||
cmake ..
|
|
||||||
make
|
|
||||||
|
|
||||||
This will compile spacetray with status icon and notification support.
|
This will compile spacetray with status icon and notification support.
|
||||||
|
|
||||||
Just copy "bin/spacetray" to a folder in your $PATH. I do:
|
Just copy "build/spacetray" to a folder in your $PATH. I do:
|
||||||
|
|
||||||
cp ./bin/spacetray ~/bin/
|
cp ./build/spacetray ~/bin/
|
||||||
|
|
||||||
You can copy the file to /usr/bin to make it available to all users but I don't. If you want that just run:
|
You can copy the file to /usr/bin to make it available to all users but I don't. If you want that just run:
|
||||||
|
|
||||||
sudo cp ./bin/spacetray /usr/bin/
|
sudo cp ./build/spacetray /usr/bin/
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
--------------
|
--------------
|
||||||
|
|
@ -56,12 +54,20 @@ Usage:
|
||||||
|
|
||||||
Run spacetray with:
|
Run spacetray with:
|
||||||
|
|
||||||
./bin/spacetray <statusurl> &
|
./build/spacetray <statusurl> &
|
||||||
|
|
||||||
Or if in your $PATH:
|
Or if in your $PATH:
|
||||||
|
|
||||||
spacetray <statusurl>
|
spacetray <statusurl>
|
||||||
|
|
||||||
|
The polling interval defaults to 300 seconds (5 minutes). It can be changed with the `-i` or `--interval` option, given either before or after the status URL:
|
||||||
|
|
||||||
|
./build/spacetray <statusurl> -i 60 &
|
||||||
|
|
||||||
|
./build/spacetray -i 60 <statusurl>
|
||||||
|
|
||||||
|
The interval is specified in seconds and must be a positive number.
|
||||||
|
|
||||||
Themes:
|
Themes:
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
@ -105,4 +111,3 @@ to:
|
||||||
in:
|
in:
|
||||||
|
|
||||||
./spacetray.cpp
|
./spacetray.cpp
|
||||||
|
|
||||||
|
|
|
||||||
33
main.cpp
33
main.cpp
|
|
@ -1,17 +1,44 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QString>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
#include "spacetray.h"
|
#include "spacetray.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2 && argc != 4) {
|
||||||
std::cerr << "Usage: " << argv[0] << " <statusurl>" << std::endl;
|
std::cerr << "Usage: " << argv[0]
|
||||||
|
<< " <statusurl> [-i|--interval <seconds>]\n " << argv[0]
|
||||||
|
<< " [-i|--interval <seconds>] <statusurl>" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpaceTray tray(argv[1]);
|
QString statusUrl;
|
||||||
|
int intervalSeconds = 300;
|
||||||
|
if (argc == 4) {
|
||||||
|
const QString firstArgument = QString::fromLocal8Bit(argv[1]);
|
||||||
|
const bool intervalFirst = firstArgument == "-i" || firstArgument == "--interval";
|
||||||
|
const QString option = intervalFirst ? firstArgument : QString::fromLocal8Bit(argv[2]);
|
||||||
|
const QString intervalArgument = QString::fromLocal8Bit(argv[intervalFirst ? 2 : 3]);
|
||||||
|
bool validInterval = false;
|
||||||
|
const qlonglong parsedInterval = intervalArgument.toLongLong(&validInterval);
|
||||||
|
const qlonglong maximumSeconds = std::numeric_limits<int>::max() / 1000;
|
||||||
|
|
||||||
|
if ((option != "-i" && option != "--interval") ||
|
||||||
|
!validInterval || parsedInterval <= 0 || parsedInterval > maximumSeconds) {
|
||||||
|
std::cerr << "Invalid interval. Use -i or --interval followed by a positive number of seconds."
|
||||||
|
<< std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
intervalSeconds = static_cast<int>(parsedInterval);
|
||||||
|
statusUrl = QString::fromLocal8Bit(argv[intervalFirst ? 3 : 1]);
|
||||||
|
} else {
|
||||||
|
statusUrl = QString::fromLocal8Bit(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpaceTray tray(statusUrl, intervalSeconds);
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
SpaceTray::SpaceTray(const QString &url, QObject *parent)
|
SpaceTray::SpaceTray(const QString &url, int intervalSeconds, QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_statusUrl(url),
|
m_statusUrl(url),
|
||||||
m_doorOpen(false),
|
m_doorOpen(false),
|
||||||
|
|
@ -45,10 +45,10 @@ SpaceTray::SpaceTray(const QString &url, QObject *parent)
|
||||||
// Setup network manager
|
// Setup network manager
|
||||||
m_networkManager = new QNetworkAccessManager(this);
|
m_networkManager = new QNetworkAccessManager(this);
|
||||||
|
|
||||||
// Setup timer (300 seconds as per previous delay=300 in C code)
|
// QTimer expects milliseconds; the command-line interval is specified in seconds.
|
||||||
m_timer = new QTimer(this);
|
m_timer = new QTimer(this);
|
||||||
connect(m_timer, &QTimer::timeout, this, &SpaceTray::fetchData);
|
connect(m_timer, &QTimer::timeout, this, &SpaceTray::fetchData);
|
||||||
m_timer->start(300000); // 300 seconds in ms
|
m_timer->start(intervalSeconds * 1000);
|
||||||
|
|
||||||
// Initial fetch
|
// Initial fetch
|
||||||
fetchData();
|
fetchData();
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class SpaceTray : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SpaceTray(const QString &url, QObject *parent = nullptr);
|
explicit SpaceTray(const QString &url, int intervalSeconds = 300, QObject *parent = nullptr);
|
||||||
~SpaceTray();
|
~SpaceTray();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
||||||
|
|
@ -1674,4 +1674,3 @@ static const quint8 icon_closed_data[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* width: 52, height: 48, rowstride: 208, n_channels: 4 */
|
/* width: 52, height: 48, rowstride: 208, n_channels: 4 */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue