| 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 |
from Nagstamon.config import conf |
| 19 |
from Nagstamon.helpers import webbrowser_open |
| 20 |
from Nagstamon.qui.qt import (QComboBox, |
| 21 |
Signal, |
| 22 |
Slot) |
| 23 |
from Nagstamon.servers import servers |
| 24 |
|
| 25 |
|
| 26 |
class ComboBoxServers(QComboBox): |
| 27 |
""" |
| 28 |
combobox which does lock status window so it does not close when opening combobox |
| 29 |
""" |
| 30 |
monitor_opened = Signal() |
| 31 |
|
| 32 |
# flag to avoid silly focusOutEvent |
| 33 |
freshly_opened = False |
| 34 |
|
| 35 |
def __init__(self, parent=None): |
| 36 |
QComboBox.__init__(self, parent=parent) |
| 37 |
# react to clicked monitor |
| 38 |
self.activated.connect(self.response) |
| 39 |
|
| 40 |
def mousePressEvent(self, event): |
| 41 |
# first click opens combobox popup |
| 42 |
self.freshly_opened = True |
| 43 |
# tell status window that there is no combobox anymore |
| 44 |
self.showPopup() |
| 45 |
|
| 46 |
def fill(self): |
| 47 |
""" |
| 48 |
fill default order fields combobox with server names |
| 49 |
""" |
| 50 |
self.clear() |
| 51 |
self.addItem('Go to monitor...') |
| 52 |
self.addItems(sorted([x.name for x in conf.servers.values() if x.enabled], key=str.lower)) |
| 53 |
|
| 54 |
@Slot() |
| 55 |
def response(self): |
| 56 |
""" |
| 57 |
response to activated item in servers combobox |
| 58 |
""" |
| 59 |
if self.currentText() in servers: |
| 60 |
# open webbrowser with server URL |
| 61 |
webbrowser_open(servers[self.currentText()].monitor_url) |
| 62 |
|
| 63 |
# hide window to make room for webbrowser |
| 64 |
self.monitor_opened.emit() |
| 65 |
|
| 66 |
self.setCurrentIndex(0) |
| 67 |
|
| 68 |
|