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/
|
||||
local/
|
||||
spacetray
|
||||
*~
|
||||
|
||||
# CLion
|
||||
.idea/
|
||||
.junie/
|
||||
spacetray.iml
|
||||
|
||||
# CMake
|
||||
|
|
@ -54,12 +54,3 @@ cmake-build-debug/
|
|||
*.su
|
||||
*.idb
|
||||
*.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
|
||||
|
||||
To compile the sources, run:
|
||||
To configure and compile the sources, run:
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
cmake -S . -B build
|
||||
cmake --build build
|
||||
|
||||
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:
|
||||
|
||||
sudo cp ./bin/spacetray /usr/bin/
|
||||
sudo cp ./build/spacetray /usr/bin/
|
||||
|
||||
Configuration:
|
||||
--------------
|
||||
|
|
@ -56,12 +54,20 @@ Usage:
|
|||
|
||||
Run spacetray with:
|
||||
|
||||
./bin/spacetray <statusurl> &
|
||||
./build/spacetray <statusurl> &
|
||||
|
||||
Or if in your $PATH:
|
||||
|
||||
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:
|
||||
-------
|
||||
|
||||
|
|
@ -105,4 +111,3 @@ to:
|
|||
in:
|
||||
|
||||
./spacetray.cpp
|
||||
|
||||
|
|
|
|||
33
main.cpp
33
main.cpp
|
|
@ -1,17 +1,44 @@
|
|||
#include <QApplication>
|
||||
#include <QString>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include "spacetray.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " <statusurl>" << std::endl;
|
||||
if (argc != 2 && argc != 4) {
|
||||
std::cerr << "Usage: " << argv[0]
|
||||
<< " <statusurl> [-i|--interval <seconds>]\n " << argv[0]
|
||||
<< " [-i|--interval <seconds>] <statusurl>" << std::endl;
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <QPixmap>
|
||||
#include <QDebug>
|
||||
|
||||
SpaceTray::SpaceTray(const QString &url, QObject *parent)
|
||||
SpaceTray::SpaceTray(const QString &url, int intervalSeconds, QObject *parent)
|
||||
: QObject(parent),
|
||||
m_statusUrl(url),
|
||||
m_doorOpen(false),
|
||||
|
|
@ -45,10 +45,10 @@ SpaceTray::SpaceTray(const QString &url, QObject *parent)
|
|||
// Setup network manager
|
||||
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);
|
||||
connect(m_timer, &QTimer::timeout, this, &SpaceTray::fetchData);
|
||||
m_timer->start(300000); // 300 seconds in ms
|
||||
m_timer->start(intervalSeconds * 1000);
|
||||
|
||||
// Initial fetch
|
||||
fetchData();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class SpaceTray : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SpaceTray(const QString &url, QObject *parent = nullptr);
|
||||
explicit SpaceTray(const QString &url, int intervalSeconds = 300, QObject *parent = nullptr);
|
||||
~SpaceTray();
|
||||
|
||||
private slots:
|
||||
|
|
|
|||
3329
themes/lock.h
3329
themes/lock.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue