| 1 |
# Nagstamon - Nagios status monitor for your desktop |
| 2 |
# Copyright (C) 2008-2026 Henri Wahl <[email protected]> et al. |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 17 |
|
| 18 |
# it is important that this import is done before importing any other qui module, because |
| 19 |
# they may need a QApplication instance to be created |
| 20 |
from Nagstamon.qui.widgets.app import app |
| 21 |
|
| 22 |
from Nagstamon.qui.constants import (COLORS, |
| 23 |
COLOR_STATE_NAMES, |
| 24 |
COLOR_STATUS_LABEL, |
| 25 |
HEADERS, |
| 26 |
HEADERS_HEADERS, |
| 27 |
HEADERS_HEADERS_COLUMNS, |
| 28 |
HEADERS_HEADERS_KEYS, |
| 29 |
HEADERS_KEYS_COLUMNS, |
| 30 |
HEADERS_KEYS_HEADERS, |
| 31 |
SORT_ORDER, |
| 32 |
SORT_COLUMNS_INDEX, |
| 33 |
SPACE, |
| 34 |
WINDOW_FLAGS) |
| 35 |
from Nagstamon.qui.globals import (dbus_connection, |
| 36 |
font, |
| 37 |
font_default, |
| 38 |
font_icons, |
| 39 |
statuswindow_properties) |
| 40 |
from Nagstamon.qui.helpers import (check_servers, |
| 41 |
hide_macos_dock_icon) |
| 42 |
from Nagstamon.qui.widgets.buttons import (Button, |
| 43 |
CSS_CLOSE_BUTTON, |
| 44 |
PushButtonHamburger) |
| 45 |
from Nagstamon.qui.dialogs import dialogs |
| 46 |
from Nagstamon.qui.dialogs.check_version import CheckVersion |
| 47 |
from Nagstamon.qui.qt import (MediaPlayer, |
| 48 |
Slot) |
| 49 |
from Nagstamon.qui.widgets.combobox_servers import ComboBoxServers |
| 50 |
from Nagstamon.qui.widgets.buttons import PushButtonBrowserURL |
| 51 |
from Nagstamon.qui.widgets.draggables import (DraggableLabel, |
| 52 |
DraggableWidget) |
| 53 |
from Nagstamon.qui.widgets.icon import QIconWithFilename |
| 54 |
from Nagstamon.qui.widgets.labels import (ClosingLabel, |
| 55 |
LabelAllOK, |
| 56 |
ServerStatusLabel) |
| 57 |
from Nagstamon.qui.widgets.layout import HBoxLayout |
| 58 |
from Nagstamon.qui.widgets.mediaplayer import mediaplayer |
| 59 |
from Nagstamon.qui.widgets.menu import (MenuAtCursor, |
| 60 |
MenuContext, |
| 61 |
MenuContextSystrayicon) |
| 62 |
from Nagstamon.qui.widgets.model import Model |
| 63 |
from Nagstamon.qui.widgets.nagstamon_logo import NagstamonLogo |
| 64 |
from Nagstamon.qui.widgets.statuswindow import StatusWindow |
| 65 |
from Nagstamon.qui.widgets.system_tray_icon import SystemTrayIcon |
| 66 |
from Nagstamon.qui.widgets.toparea import TopArea |
| 67 |
from Nagstamon.qui.widgets.treeview import TreeView |
| 68 |
|
| 69 |
from Nagstamon.config import (conf, |
| 70 |
OS_NON_LINUX, |
| 71 |
OS, |
| 72 |
OS_MACOS) |
| 73 |
|
| 74 |
# make icon status in macOS dock accessible via NSApp, used by set_macos_dock_icon_visible() |
| 75 |
if OS == OS_MACOS: |
| 76 |
from AppKit import (NSApp, |
| 77 |
NSApplicationPresentationDefault, |
| 78 |
NSApplicationPresentationHideDock) |
| 79 |
|
| 80 |
|
| 81 |
# check for updates |
| 82 |
check_version = CheckVersion() |
| 83 |
|
| 84 |
# system tray icon |
| 85 |
systrayicon = SystemTrayIcon() |
| 86 |
|
| 87 |
# set to none here due to race condition |
| 88 |
#statusw indow = None |
| 89 |
#menu = None |
| 90 |
|
| 91 |
# combined statusbar/status window |
| 92 |
statuswindow = StatusWindow(dialogs=dialogs, |
| 93 |
systrayicon=systrayicon) |
| 94 |
|
| 95 |
# context menu for statuswindow etc. |
| 96 |
menu = MenuContext(parent=statuswindow) |
| 97 |
|
| 98 |
# necessary extra menu due to Qt5-Unity-integration |
| 99 |
if not OS in OS_NON_LINUX: |
| 100 |
menu_systray = MenuContextSystrayicon(parent=statuswindow) |
| 101 |
menu_systray.menu_ready.connect(systrayicon.set_menu) |
| 102 |
# menu has to be set here to solve Qt-5.10-Windows-systray-mess |
| 103 |
# and non-existence of macOS-systray-context-menu |
| 104 |
else: |
| 105 |
systrayicon.set_menu(menu) |
| 106 |
|
| 107 |
# to be connected someday elsewhere |
| 108 |
# server -> statuswindow remove_previous server |
| 109 |
dialogs.server.edited_remove_previous.connect(statuswindow.remove_previous_server_vbox) |
| 110 |
dialogs.server.create_server_vbox.connect(statuswindow.create_server_vbox) |
| 111 |
|
| 112 |
dialogs.authentication.show_up.connect(statuswindow.hide_window) |
| 113 |
dialogs.weblogin.show_up.connect(statuswindow.hide_window) |
| 114 |
|
| 115 |
dialogs.settings.settings_ok.connect(statuswindow.save_position_to_conf) |
| 116 |
# trigger the statuswindow.worker to check if debug loop is needed and if so, start it |
| 117 |
dialogs.settings.settings_ok.connect(statuswindow.worker.debug_loop) |
| 118 |
dialogs.settings.server_deleted.connect(statuswindow.worker.debug_loop) |
| 119 |
dialogs.settings.changed.connect(check_servers.check) |
| 120 |
dialogs.settings.changed.connect(statuswindow.label_all_ok.set_color) |
| 121 |
dialogs.settings.cancelled.connect(check_servers.check) |
| 122 |
|
| 123 |
# when there are new settings/colors recreate icons |
| 124 |
dialogs.settings.changed.connect(systrayicon.create_icons) |
| 125 |
|
| 126 |
# when there are new settings/colors refresh labels |
| 127 |
dialogs.settings.changed.connect(statuswindow.statusbar.reset) |
| 128 |
|
| 129 |
# when new settings are applied to adjust font size |
| 130 |
dialogs.settings.changed.connect(statuswindow.statusbar.adjust_size) |
| 131 |
|
| 132 |
# menu |
| 133 |
dialogs.settings.changed.connect(menu.initialize) |
| 134 |
|
| 135 |
# statuswindow |
| 136 |
statuswindow.toparea.button_filters.clicked.connect(dialogs.settings.show_filters) |
| 137 |
statuswindow.toparea.button_settings.clicked.connect(dialogs.settings.show) |
| 138 |
statuswindow.toparea.action_exit.triggered.connect(statuswindow.exit) |
| 139 |
# hide if settings dialog pops up |
| 140 |
dialogs.settings.show_dialog.connect(statuswindow.hide_window) |
| 141 |
# workaround for the timestamp trick to avoid flickering |
| 142 |
dialogs.settings.show_dialog.connect(statuswindow.decrease_shown_timestamp) |
| 143 |
# refresh all information after changed settings |
| 144 |
dialogs.settings.changed.connect(statuswindow.refresh) |
| 145 |
dialogs.settings.changed.connect(statuswindow.toparea.combobox_servers.fill) |
| 146 |
# hide status window if version check finished |
| 147 |
check_version.version_info_retrieved.connect(statuswindow.hide_window) |
| 148 |
# start debug loop by signal |
| 149 |
dialogs.settings.start_debug_loop.connect(statuswindow.worker.debug_loop) |
| 150 |
|
| 151 |
# clenaup vbox after server deletion |
| 152 |
dialogs.settings.server_deleted.connect(statuswindow.delete_server_vbox) |
| 153 |
|
| 154 |
# reinitialize statuswindow when display mode settings were changed |
| 155 |
dialogs.settings.changed_display_mode.connect(statuswindow.reinitialize) |
| 156 |
|
| 157 |
# connect application exit with server missing dialog |
| 158 |
dialogs.server_missing.window.button_exit.clicked.connect(statuswindow.exit) |
| 159 |
|
| 160 |
# connect weblogin browser |
| 161 |
#dialogs.weblogin.page_loaded.connect(statuswindow.refresh) |
| 162 |
|
| 163 |
# systray connections |
| 164 |
# show status popup when systray icon was clicked |
| 165 |
systrayicon.show_popwin.connect(statuswindow.show_window_systrayicon) |
| 166 |
systrayicon.hide_popwin.connect(statuswindow.hide_window) |
| 167 |
# flashing statusicon |
| 168 |
statuswindow.worker_notification.start_flash.connect(systrayicon.flash) |
| 169 |
statuswindow.worker_notification.stop_flash.connect(systrayicon.reset) |
| 170 |
|
| 171 |
# trigger showing and hiding of systray icon depending on display mode |
| 172 |
statuswindow.systrayicon_enabled.connect(systrayicon.show) |
| 173 |
statuswindow.systrayicon_disabled.connect(systrayicon.hide) |
| 174 |
|
| 175 |
# retrieve systray icon position for statuswindow position calculation |
| 176 |
statuswindow.request_systrayicon_position.connect(systrayicon.retrieve_icon_position) |
| 177 |
|
| 178 |
# connect statuswindow to authentication dialog |
| 179 |
statuswindow.authenticate.connect(dialogs.authentication.show_auth_dialog) |
| 180 |
|
| 181 |
# let statuswindow show message |
| 182 |
mediaplayer.send_message.connect(statuswindow.show_message) |
| 183 |
# connect with statuswindow notification worker |
| 184 |
statuswindow.worker_notification.load_sound.connect(mediaplayer.set_media) |
| 185 |
statuswindow.worker_notification.play_sound.connect(mediaplayer.play) |
| 186 |
|
| 187 |
# necessary extra menu due to Qt5-Unity-integration |
| 188 |
if not OS in OS_NON_LINUX: |
| 189 |
# change menu if there are changes in settings/servers |
| 190 |
dialogs.settings.changed.connect(menu_systray.initialize) |
| 191 |
menu_systray.action_settings.triggered.connect(statuswindow.hide_window) |
| 192 |
menu_systray.action_settings.triggered.connect(dialogs.settings.show) |
| 193 |
menu_systray.action_save_position.triggered.connect(statuswindow.save_position_to_conf) |
| 194 |
menu_systray.action_about.triggered.connect(statuswindow.hide_window) |
| 195 |
menu_systray.action_about.triggered.connect(dialogs.about.show) |
| 196 |
menu_systray.menu_ready.connect(systrayicon.set_menu) |
| 197 |
menu_systray.menu_ready.emit(menu_systray) |
| 198 |
|
| 199 |
# needs to be emitted adter signal/slots are connected, |
| 200 |
# might be necessary for others too |
| 201 |
if conf.icon_in_systray: |
| 202 |
statuswindow.systrayicon_enabled.emit() |
| 203 |
else: |
| 204 |
statuswindow.systrayicon_disabled.emit() |
| 205 |
# tell the widgets that the menu is ready |
| 206 |
menu.menu_ready.emit(menu) |