1
# Copyright 2013 Facundo Batista
3
# This program is free software: you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License version 3, as published
5
# by the Free Software Foundation.
7
# This program is distributed in the hope that it will be useful, but
8
# WITHOUT ANY WARRANTY; without even the implied warranties of
9
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
10
# PURPOSE. See the GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License along
13
# with this program. If not, see <http://www.gnu.org/licenses/>.
15
# For further info, check https://launchpad.net/encuentro
17
"""Show an icon in the systray."""
24
from encuentro import platform
26
from PyQt4.QtGui import QSystemTrayIcon, QIcon, QMenu
28
logger = logging.getLogger("encuentro.systray")
32
"""Tell if we should fix the Unity panel systray settings.
34
Return None if don't need, else return the current conf.
36
cmd = "gsettings get com.canonical.Unity.Panel systray-whitelist".split()
38
out = subprocess.check_output(cmd)
40
# don't have gsettings, nothing to fix
41
logger.debug("No gsettings, no systray conf to fix")
45
conf = map(str, json.loads(out.strip().replace("'", '"')))
47
# don't understand the output, can't really fix it :/
48
logger.warning("Don't understand gsettings output: %r", out)
51
logger.info("gsettings conf: %r", conf)
52
if "all" in conf or "encuentro" in conf:
60
def _fix_unity_systray():
66
conf.append("encuentro")
67
cmd = ["gsettings", "set", "com.canonical.Unity.Panel",
68
"systray-whitelist", str(conf)]
70
out = subprocess.check_output(cmd)
72
logger.warning("Error trying to set the new conf: %s", err)
74
logger.warning("New config set (result: %r)", out)
77
def show(main_window):
78
"""Show a system tray icon with a small icon."""
80
icon = QIcon(os.path.join(platform.BASEDIR, "encuentro",
81
"logos", "icon-192.png"))
82
sti = QSystemTrayIcon(icon, main_window)
83
if not sti.isSystemTrayAvailable():
84
logger.warning("System tray not available.")
88
"""Show or hide the main window."""
89
if main_window.isVisible():
94
_menu = QMenu(main_window)
95
_act = _menu.addAction("Mostrar/Ocultar")
96
_act.triggered.connect(showhide)
97
_act = _menu.addAction("Acerca de")
98
_act.triggered.connect(main_window.open_about_dialog)
99
_act = _menu.addAction("Salir")
100
_act.triggered.connect(main_window.on_close)
101
sti.setContextMenu(_menu)