Skip to content

Commit

Permalink
Add command line option to disable tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick Thomssen committed Apr 10, 2016
1 parent 9b1de04 commit 1ca175f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Redmine Time Tracker
RedTimer is an easy-to-use platform-independent time tracker which allows the user to track time while working
on an issue.

Usage
-----

Usually, you can start the RedTimer executable from your file manager. After closing, RedTimer will create a
settings file called `RedTimer.ini` in your current working directory.

If you experience problems with the system tray icon, e.g. on Linux, you can deactivate the system tray icon
by calling `RedTimer --no-tray-icon`.

Installation instructions
-------------------------

Expand Down
7 changes: 4 additions & 3 deletions RedTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ using namespace qtredmine;
using namespace redtimer;
using namespace std;

RedTimer::RedTimer( QApplication* parent )
RedTimer::RedTimer( QApplication* parent, bool trayIcon )
: QObject( parent ),
app_( parent )
app_( parent ),
showTrayIcon_( trayIcon )
{
ENTER();
init();
Expand Down Expand Up @@ -152,7 +153,7 @@ RedTimer::initTrayIcon()
{
ENTER();

if( QSystemTrayIcon::isSystemTrayAvailable() )
if( showTrayIcon_ && QSystemTrayIcon::isSystemTrayAvailable() )
{
trayIcon_ = new QSystemTrayIcon( win_ );
trayIcon_->setIcon( QIcon(":/icons/clock_red.svg") );
Expand Down
8 changes: 6 additions & 2 deletions RedTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ class RedTimer : public QObject
/// Main item object
QQuickItem* item_;

/// Show the system tray icon
bool showTrayIcon_;

/// System tray icon
QSystemTrayIcon* trayIcon_;
QSystemTrayIcon* trayIcon_ = nullptr;

/// Timer for stopping the worked on time
QTimer* timer_;
Expand Down Expand Up @@ -112,8 +115,9 @@ class RedTimer : public QObject
* @brief RedTimer constructor
*
* @param parent Parent QObject
* @param trayIcon Show tray icon
*/
explicit RedTimer( QApplication* parent = nullptr );
explicit RedTimer( QApplication* parent = nullptr, bool trayIcon = true );

/**
* @brief Destructor
Expand Down
19 changes: 18 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "RedTimer.h"

#include <QApplication>
#include <QCommandLineParser>

#include <memory>

Expand All @@ -10,10 +11,26 @@ using namespace std;
int main(int argc, char* argv[])
{
QApplication app( argc, argv );
QApplication::setApplicationName( "RedTimer" );
QApplication::setApplicationVersion( "0.0.4" );

// Command line options
QCommandLineParser parser;
parser.setApplicationDescription( "Redmine Time Tracker" );
parser.addHelpOption();
parser.addVersionOption();

// Disable tray icon
QCommandLineOption noTrayOption( QStringList() << "no-tray-icon",
QApplication::translate("main", "Do not provide a tray icon.") );
parser.addOption( noTrayOption );

// Process command line options
parser.process( app );

app.setWindowIcon( QIcon(":/icons/clock_red.svg") );

new RedTimer( &app );
new RedTimer( &app, !parser.isSet(noTrayOption) );

return app.exec();
}

0 comments on commit 1ca175f

Please sign in to comment.