Skip to content

Commit

Permalink
Added support for tray albar965/littlenavmap#712
Browse files Browse the repository at this point in the history
Version 2.8.7
Close button on window frame now optionally minimizes window to system tray.
Navconnect system tray icons shows last five messages from log.
Tray icon has a context menu.
Fixed various issues with log field updates.
  • Loading branch information
albar965 committed Jun 29, 2023
1 parent 06e8cde commit 2bb2548
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 235 deletions.
3 changes: 1 addition & 2 deletions littlenavconnect.pro
Expand Up @@ -47,7 +47,7 @@
# =============================================================================

# Define program version here VERSION_NUMBER_TODO
VERSION_NUMBER=2.8.6
VERSION_NUMBER=2.8.7

QT += core gui xml network svg

Expand Down Expand Up @@ -191,7 +191,6 @@ message(-----------------------------------)
# Files

SOURCES +=\
src/constants.cpp \
src/main.cpp \
src/mainwindow.cpp \
src/optionsdialog.cpp
Expand Down
59 changes: 51 additions & 8 deletions mainwindow.ui
Expand Up @@ -13,6 +13,10 @@
<property name="windowTitle">
<string>Little Navconnect</string>
</property>
<property name="windowIcon">
<iconset resource="littlenavconnect.qrc">
<normaloff>:/littlenavconnect/resources/icons/navconnect.svg</normaloff>:/littlenavconnect/resources/icons/navconnect.svg</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
Expand Down Expand Up @@ -41,6 +45,9 @@
<property name="readOnly">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
Expand All @@ -51,7 +58,7 @@
<x>0</x>
<y>0</y>
<width>640</width>
<height>21</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand All @@ -64,8 +71,9 @@
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="actionContents"/>
<addaction name="actionContentsOffline"/>
<addaction name="actionHelp"/>
<addaction name="actionHelpOffline"/>
<addaction name="separator"/>
<addaction name="actionAbout"/>
<addaction name="separator"/>
<addaction name="actionAboutQt"/>
Expand All @@ -75,10 +83,20 @@
<string>&amp;Tools</string>
</property>
<addaction name="actionResetMessages"/>
<addaction name="separator"/>
<addaction name="actionOptions"/>
</widget>
<widget class="QMenu" name="menuWindow">
<property name="title">
<string>&amp;Window</string>
</property>
<addaction name="actionMinimizeTray"/>
<addaction name="actionStartMinimizeTray"/>
<addaction name="separator"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuTools"/>
<addaction name="menuWindow"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QToolBar" name="toolBar">
Expand All @@ -98,7 +116,7 @@
<bool>false</bool>
</attribute>
<addaction name="actionOptions"/>
<addaction name="actionContents"/>
<addaction name="actionHelp"/>
</widget>
<action name="actionQuit">
<property name="icon">
Expand Down Expand Up @@ -130,13 +148,13 @@
<string>About &amp;Qt</string>
</property>
</action>
<action name="actionContents">
<action name="actionHelp">
<property name="icon">
<iconset resource="littlenavconnect.qrc">
<normaloff>:/littlenavconnect/resources/icons/help.svg</normaloff>:/littlenavconnect/resources/icons/help.svg</iconset>
</property>
<property name="text">
<string>&amp;Contents (Online)</string>
<string>&amp;User Manual (Online)</string>
</property>
</action>
<action name="actionResetMessages">
Expand Down Expand Up @@ -177,13 +195,13 @@
<string>Stop Saving or Loading of Replay</string>
</property>
</action>
<action name="actionContentsOffline">
<action name="actionHelpOffline">
<property name="icon">
<iconset resource="littlenavconnect.qrc">
<normaloff>:/littlenavconnect/resources/icons/help.svg</normaloff>:/littlenavconnect/resources/icons/help.svg</iconset>
</property>
<property name="text">
<string>&amp;Contents (Offline, PDF)</string>
<string>&amp;User Manual (Offline, PDF)</string>
</property>
</action>
<action name="actionConnectFsx">
Expand Down Expand Up @@ -220,6 +238,31 @@
<string>Ctrl+Shift+X</string>
</property>
</action>
<action name="actionMinimizeTray">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Minimize to System Tray</string>
</property>
</action>
<action name="actionStartMinimizeTray">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Start minimized to System Tray</string>
</property>
<property name="toolTip">
<string>Startup minimized to the System Tray</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
Expand Down
18 changes: 0 additions & 18 deletions src/constants.cpp

This file was deleted.

1 change: 1 addition & 0 deletions src/constants.h
Expand Up @@ -30,6 +30,7 @@ const QLatin1String SETTINGS_OPTIONS_FETCH_AI_SHIP("Options/FetchAiShip");
const QLatin1String SETTINGS_OPTIONS_FETCH_AI_RADIUS("Options/FetchAiRadius");
const QLatin1String SETTINGS_ACTIONS_SHOW_PORT_CHANGE("Actions/ShowPortChange");
const QLatin1String SETTINGS_ACTIONS_SHOW_QUIT("Actions/ShowQuit");
const QLatin1String SETTINGS_ACTIONS_SHOW_TRAY_HINT("Actions/ShowTrayHint");
const QLatin1String SETTINGS_OPTIONS_VERBOSE("Options/Verbose");
const QLatin1String SETTINGS_MAINWINDOW_WIDGET("MainWindow/Widget");
const QLatin1String SETTINGS_OPTIONS_RECONNECT_RATE("Options/ReconnectRate2");
Expand Down
127 changes: 71 additions & 56 deletions src/main.cpp
@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright 2015-2020 Alexander Barthel alex@littlenavmap.org
* Copyright 2015-2023 Alexander Barthel alex@littlenavmap.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -27,16 +27,13 @@
#include "atools.h"
#include "geo/calculations.h"
#include "fs/fspaths.h"
#include "exception.h"

#include <QSslSocket>
#include <QStyleFactory>

#if defined(Q_OS_WIN32)
#include <QSharedMemory>
#include <QMessageBox>

#endif

using atools::gui::Application;
using atools::logging::LoggingHandler;
using atools::logging::LoggingUtil;
Expand All @@ -53,70 +50,88 @@ int main(int argc, char *argv[])
atools::geo::registerMetaTypes();
atools::fs::FsPaths::intitialize();

using atools::gui::Application;
Application app(argc, argv);
Application::setWindowIcon(QIcon(":/littlenavconnect/resources/icons/navconnect.svg"));
Application::setApplicationName("Little Navconnect");
Application::setOrganizationName("ABarthel");
Application::setOrganizationDomain("littlenavmap.org");

Application::setApplicationVersion(VERSION_NUMBER_LITTLENAVCONNECT);
Application::setEmailAddresses({"alex@littlenavmap.org"});

// Initialize logging and force logfiles into the system or user temp directory
LoggingHandler::initializeForTemp(atools::settings::Settings::getOverloadedPath(":/littlenavconnect/resources/config/logging.cfg"));
int retval = 0;

Application::addReportPath(QObject::tr("Log files:"), LoggingHandler::getLogFiles());

Application::addReportPath(QObject::tr("Configuration:"), {Settings::getFilename()});

// Disable tooltip effects since these do not work well with tooltip updates while displaying
QApplication::setEffectEnabled(Qt::UI_FadeTooltip, false);
QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, false);
try
{
using atools::gui::Application;
Application app(argc, argv);
Application::setWindowIcon(QIcon(":/littlenavconnect/resources/icons/navconnect.svg"));
Application::setApplicationName("Little Navconnect");
Application::setOrganizationName("ABarthel");
Application::setOrganizationDomain("littlenavmap.org");

#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0)
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
#endif
Application::setApplicationVersion(VERSION_NUMBER_LITTLENAVCONNECT);
Application::setEmailAddresses({"alex@littlenavmap.org"});

// Print some information which can be useful for debugging
LoggingUtil::logSystemInformation();
qInfo().noquote().nospace() << "atools revision " << atools::gitRevision() << " "
<< Application::applicationName() << " revision " << GIT_REVISION_LITTLENAVCONNECT;
// Initialize logging and force logfiles into the system or user temp directory
LoggingHandler::initializeForTemp(atools::settings::Settings::getOverloadedPath(":/littlenavconnect/resources/config/logging.cfg"));

LoggingUtil::logStandardPaths();
qInfo() << "SSL supported" << QSslSocket::supportsSsl()
<< "build library" << QSslSocket::sslLibraryBuildVersionString()
<< "library" << QSslSocket::sslLibraryVersionString();
Application::addReportPath(QObject::tr("Log files:"), LoggingHandler::getLogFiles());

qInfo() << "Available styles" << QStyleFactory::keys();
Application::addReportPath(QObject::tr("Configuration:"), {Settings::getFilename()});

Settings::logSettingsInformation();
// Disable tooltip effects since these do not work well with tooltip updates while displaying
QApplication::setEffectEnabled(Qt::UI_FadeTooltip, false);
QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, false);

// Load simulator paths =================================
atools::fs::FsPaths::loadAllPaths();
atools::fs::FsPaths::logAllPaths();
// Avoid closing if options dialog is closed with main window hidden to tray
QApplication::setQuitOnLastWindowClosed(false);

// Load local and Qt system translations from various places
Translator::load(Settings::instance().valueStr(lnc::SETTINGS_OPTIONS_LANGUAGE, QString()));
#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0)
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
#endif

#if defined(Q_OS_WIN32)
// Detect other running application instance - this is unsafe on Unix since shm can remain after crashes
QSharedMemory shared("ed1b2f62-a6b3-8c64-09b4-e4daa232ecf4"); // generated GUID
if(!shared.create(512, QSharedMemory::ReadWrite))
// Print some information which can be useful for debugging
LoggingUtil::logSystemInformation();
qInfo().noquote().nospace() << "atools revision " << atools::gitRevision() << " "
<< Application::applicationName() << " revision " << GIT_REVISION_LITTLENAVCONNECT;

LoggingUtil::logStandardPaths();
qInfo() << "SSL supported" << QSslSocket::supportsSsl()
<< "build library" << QSslSocket::sslLibraryBuildVersionString()
<< "library" << QSslSocket::sslLibraryVersionString();

qInfo() << "Available styles" << QStyleFactory::keys();

Settings::logSettingsInformation();

// Load simulator paths =================================
atools::fs::FsPaths::loadAllPaths();
atools::fs::FsPaths::logAllPaths();

// Load local and Qt system translations from various places
Translator::load(Settings::instance().valueStr(lnc::SETTINGS_OPTIONS_LANGUAGE, QString()));

// Detect other running application instance - this is unsafe on Unix since shared memory can remain after crashes
QSharedMemory shared("ed1b2f62-a6b3-8c64-09b4-e4daa232ecf4"); // generated GUID
if(!shared.create(64, QSharedMemory::ReadOnly))
{
shared.detach();
QMessageBox::critical(nullptr, QObject::tr("%1 - Error").arg(QCoreApplication::applicationName()),
QObject::tr("%1 is already running.").arg(QCoreApplication::applicationName()));
return 1;
}

// Put in separate block to destroy main window before shutting down logging
MainWindow mainWindow;
mainWindow.showInitial();
retval = QCoreApplication::exec();
}
catch(atools::Exception& e)
{
QMessageBox::critical(nullptr, QObject::tr("%1 - Error").arg(QCoreApplication::applicationName()),
QObject::tr("%1 is already running.").arg(QCoreApplication::applicationName()));
return 1;
ATOOLS_HANDLE_EXCEPTION(e);
// Does not return in case of fatal error
}
catch(...)
{
ATOOLS_HANDLE_UNKNOWN_EXCEPTION;
// Does not return in case of fatal error
}
#endif

MainWindow mainWindow;

mainWindow.show();

int retval = app.exec();

qDebug() << "app.exec() done, retval is" << retval << (retval == 0 ? "(ok)" : "(error)");
qInfo() << "About to shut down logging";
atools::logging::LoggingHandler::shutdown();

return retval;
}

0 comments on commit 2bb2548

Please sign in to comment.