2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/statusicon.py
|
2006-10-05 02:05:47 +02:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2006 Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
## Copyright (C) 2006-2007 Jean-Marie Traissard <jim AT lapin.org>
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net>
|
|
|
|
## Julien Pivotto <roidelapluie AT gmail.com>
|
|
|
|
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
|
2006-10-05 02:05:47 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 3 only.
|
2006-10-05 02:05:47 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2006-10-05 02:05:47 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2006-10-05 02:05:47 +02:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2006-10-05 02:05:47 +02:00
|
|
|
|
2018-03-26 01:06:56 +02:00
|
|
|
import os
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Gtk
|
2015-01-19 13:39:11 +01:00
|
|
|
from gi.repository import Gdk
|
2009-11-24 14:33:49 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import dialogs
|
|
|
|
from gajim import config
|
|
|
|
from gajim import tooltips
|
|
|
|
from gajim import gtkgui_helpers
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import helpers
|
2018-07-16 23:22:33 +02:00
|
|
|
from gajim.gtk import SingleMessageWindow
|
|
|
|
|
2006-10-05 02:05:47 +02:00
|
|
|
|
2009-11-24 14:33:49 +01:00
|
|
|
class StatusIcon:
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Class for the notification area icon
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.single_message_handler_id = None
|
2011-03-08 19:55:16 +01:00
|
|
|
self.show_roster_handler_id = None
|
2010-02-08 15:08:40 +01:00
|
|
|
self.new_chat_handler_id = None
|
|
|
|
# click somewhere else does not popdown menu. workaround this.
|
|
|
|
self.added_hide_menuitem = False
|
|
|
|
self.status = 'offline'
|
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('systray_context_menu.ui')
|
|
|
|
self.systray_context_menu = self.xml.get_object('systray_context_menu')
|
|
|
|
self.xml.connect_signals(self)
|
|
|
|
self.popup_menus = []
|
|
|
|
self.status_icon = None
|
|
|
|
self.tooltip = tooltips.NotificationAreaTooltip()
|
|
|
|
|
|
|
|
def subscribe_events(self):
|
|
|
|
"""
|
|
|
|
Register listeners to the events class
|
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
app.events.event_added_subscribe(self.on_event_added)
|
|
|
|
app.events.event_removed_subscribe(self.on_event_removed)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def unsubscribe_events(self):
|
|
|
|
"""
|
|
|
|
Unregister listeners to the events class
|
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
app.events.event_added_unsubscribe(self.on_event_added)
|
|
|
|
app.events.event_removed_unsubscribe(self.on_event_removed)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_event_added(self, event):
|
|
|
|
"""
|
|
|
|
Called when an event is added to the event list
|
|
|
|
"""
|
|
|
|
if event.show_in_systray:
|
|
|
|
self.set_img()
|
|
|
|
|
|
|
|
def on_event_removed(self, event_list):
|
|
|
|
"""
|
|
|
|
Called when one or more events are removed from the event list
|
|
|
|
"""
|
|
|
|
self.set_img()
|
|
|
|
|
|
|
|
def show_icon(self):
|
|
|
|
if not self.status_icon:
|
2012-12-23 16:23:43 +01:00
|
|
|
self.status_icon = Gtk.StatusIcon()
|
2010-02-08 15:08:40 +01:00
|
|
|
self.status_icon.set_property('has-tooltip', True)
|
2017-10-27 12:20:15 +02:00
|
|
|
self.status_icon.connect('activate',
|
|
|
|
self.on_status_icon_left_clicked)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.status_icon.connect('popup-menu',
|
2017-10-27 12:20:15 +02:00
|
|
|
self.on_status_icon_right_clicked)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.status_icon.connect('query-tooltip',
|
2017-10-27 12:20:15 +02:00
|
|
|
self.on_status_icon_query_tooltip)
|
|
|
|
self.status_icon.connect('size-changed', self.set_img)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.set_img()
|
|
|
|
self.subscribe_events()
|
|
|
|
|
|
|
|
def on_status_icon_right_clicked(self, widget, event_button, event_time):
|
|
|
|
self.make_menu(event_button, event_time)
|
|
|
|
|
|
|
|
def on_status_icon_query_tooltip(self, widget, x, y, keyboard_mode, tooltip):
|
2017-12-23 21:08:00 +01:00
|
|
|
tooltip.set_custom(self.tooltip.get_tooltip())
|
2010-02-08 15:08:40 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
def hide_icon(self):
|
|
|
|
self.status_icon.set_visible(False)
|
|
|
|
self.unsubscribe_events()
|
|
|
|
|
|
|
|
def on_status_icon_left_clicked(self, widget):
|
|
|
|
self.on_left_click()
|
|
|
|
|
2010-09-16 20:27:54 +02:00
|
|
|
def on_status_icon_size_changed(self, statusicon, size):
|
|
|
|
if size > 31:
|
|
|
|
self.statusicon_size = '32'
|
2012-10-18 14:05:31 +02:00
|
|
|
elif size > 23:
|
2012-08-31 11:46:45 +02:00
|
|
|
self.statusicon_size = '24'
|
2010-09-16 20:27:54 +02:00
|
|
|
else:
|
|
|
|
self.statusicon_size = '16'
|
|
|
|
if os.environ.get('KDE_FULL_SESSION') == 'true':
|
|
|
|
# detect KDE session. see #5476
|
|
|
|
self.statusicon_size = '32'
|
|
|
|
self.set_img()
|
|
|
|
|
2017-10-27 12:20:15 +02:00
|
|
|
def set_img(self, *args):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Apart from image, we also update tooltip text here
|
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
if not app.interface.systray_enabled:
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get('trayicon') == 'always':
|
2010-09-18 23:06:36 +02:00
|
|
|
self.status_icon.set_visible(True)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.events.get_nb_systray_events():
|
2010-09-18 23:06:36 +02:00
|
|
|
self.status_icon.set_visible(True)
|
2017-10-27 12:20:15 +02:00
|
|
|
|
|
|
|
icon_name = gtkgui_helpers.get_iconset_name_for('event')
|
|
|
|
self.status_icon.set_from_icon_name(icon_name)
|
2012-12-23 16:23:43 +01:00
|
|
|
return
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get('trayicon') == 'on_event':
|
2010-09-18 23:06:36 +02:00
|
|
|
self.status_icon.set_visible(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-10-27 12:20:15 +02:00
|
|
|
icon_name = gtkgui_helpers.get_iconset_name_for(self.status)
|
|
|
|
self.status_icon.set_from_icon_name(icon_name)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def change_status(self, global_status):
|
|
|
|
"""
|
|
|
|
Set tray image to 'global_status'
|
|
|
|
"""
|
|
|
|
# change image and status, only if it is different
|
|
|
|
if global_status is not None and self.status != global_status:
|
|
|
|
self.status = global_status
|
|
|
|
self.set_img()
|
|
|
|
|
|
|
|
def start_chat(self, widget, account, jid):
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.get_first_contact_from_jid(account, jid)
|
|
|
|
if app.interface.msg_win_mgr.has_window(jid, account):
|
|
|
|
app.interface.msg_win_mgr.get_window(jid, account).set_active_tab(
|
2010-02-08 15:08:40 +01:00
|
|
|
jid, account)
|
|
|
|
elif contact:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.new_chat(contact, account)
|
|
|
|
app.interface.msg_win_mgr.get_window(jid, account).set_active_tab(
|
2010-02-08 15:08:40 +01:00
|
|
|
jid, account)
|
|
|
|
|
|
|
|
def on_single_message_menuitem_activate(self, widget, account):
|
2018-07-16 23:22:33 +02:00
|
|
|
SingleMessageWindow(account, action='send')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_new_chat(self, widget, account):
|
2017-11-30 22:55:06 +01:00
|
|
|
app.app.activate_action('start-chat')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def make_menu(self, event_button, event_time):
|
|
|
|
"""
|
|
|
|
Create chat with and new message (sub) menus/menuitems
|
|
|
|
"""
|
|
|
|
for m in self.popup_menus:
|
|
|
|
m.destroy()
|
|
|
|
|
|
|
|
chat_with_menuitem = self.xml.get_object('chat_with_menuitem')
|
|
|
|
single_message_menuitem = self.xml.get_object(
|
|
|
|
'single_message_menuitem')
|
|
|
|
status_menuitem = self.xml.get_object('status_menu')
|
|
|
|
join_gc_menuitem = self.xml.get_object('join_gc_menuitem')
|
|
|
|
sounds_mute_menuitem = self.xml.get_object('sounds_mute_menuitem')
|
2010-02-09 19:36:32 +01:00
|
|
|
show_roster_menuitem = self.xml.get_object('show_roster_menuitem')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if self.single_message_handler_id:
|
|
|
|
single_message_menuitem.handler_disconnect(
|
|
|
|
self.single_message_handler_id)
|
|
|
|
self.single_message_handler_id = None
|
|
|
|
if self.new_chat_handler_id:
|
|
|
|
chat_with_menuitem.disconnect(self.new_chat_handler_id)
|
|
|
|
self.new_chat_handler_id = None
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
sub_menu = Gtk.Menu()
|
2010-02-08 15:08:40 +01:00
|
|
|
self.popup_menus.append(sub_menu)
|
|
|
|
status_menuitem.set_submenu(sub_menu)
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
gc_sub_menu = Gtk.Menu() # gc is always a submenu
|
2010-02-08 15:08:40 +01:00
|
|
|
join_gc_menuitem.set_submenu(gc_sub_menu)
|
|
|
|
|
|
|
|
# We need our own set of status icons, let's make 'em!
|
2017-08-13 13:18:56 +02:00
|
|
|
iconset = app.config.get('iconset')
|
2010-02-08 15:08:40 +01:00
|
|
|
path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
|
|
|
|
|
|
|
|
for show in ('online', 'chat', 'away', 'xa', 'dnd', 'invisible'):
|
2013-01-08 11:52:46 +01:00
|
|
|
uf_show = helpers.get_uf_show(show, use_mnemonic=True)
|
2014-11-11 23:11:15 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(uf_show)
|
2010-02-08 15:08:40 +01:00
|
|
|
sub_menu.append(item)
|
|
|
|
item.connect('activate', self.on_show_menuitem_activate, show)
|
|
|
|
|
2013-01-01 16:46:04 +01:00
|
|
|
item = Gtk.SeparatorMenuItem.new()
|
2010-02-08 15:08:40 +01:00
|
|
|
sub_menu.append(item)
|
|
|
|
|
2017-02-04 23:29:45 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('_Change Status Message…'))
|
2010-02-08 15:08:40 +01:00
|
|
|
sub_menu.append(item)
|
|
|
|
item.connect('activate', self.on_change_status_message_activate)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
connected_accounts = app.get_number_of_connected_accounts()
|
2010-02-08 15:08:40 +01:00
|
|
|
if connected_accounts < 1:
|
|
|
|
item.set_sensitive(False)
|
|
|
|
|
2013-01-01 16:46:04 +01:00
|
|
|
item = Gtk.SeparatorMenuItem.new()
|
2010-02-08 15:08:40 +01:00
|
|
|
sub_menu.append(item)
|
|
|
|
|
2013-01-08 11:52:46 +01:00
|
|
|
uf_show = helpers.get_uf_show('offline', use_mnemonic=True)
|
2014-11-11 23:11:15 +01:00
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(uf_show)
|
2010-02-08 15:08:40 +01:00
|
|
|
sub_menu.append(item)
|
|
|
|
item.connect('activate', self.on_show_menuitem_activate, 'offline')
|
|
|
|
|
|
|
|
iskey = connected_accounts > 0 and not (connected_accounts == 1 and
|
2017-08-13 13:18:56 +02:00
|
|
|
app.zeroconf_is_connected())
|
2010-02-08 15:08:40 +01:00
|
|
|
chat_with_menuitem.set_sensitive(iskey)
|
|
|
|
single_message_menuitem.set_sensitive(iskey)
|
|
|
|
join_gc_menuitem.set_sensitive(iskey)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts_list = sorted(app.contacts.get_accounts())
|
2010-02-08 15:08:40 +01:00
|
|
|
# items that get shown whether an account is zeroconf or not
|
|
|
|
if connected_accounts > 1: # 2 or more connections? make submenus
|
2012-12-23 16:23:43 +01:00
|
|
|
account_menu_for_chat_with = Gtk.Menu()
|
2010-02-08 15:08:40 +01:00
|
|
|
chat_with_menuitem.set_submenu(account_menu_for_chat_with)
|
|
|
|
self.popup_menus.append(account_menu_for_chat_with)
|
|
|
|
|
|
|
|
for account in accounts_list:
|
2018-02-16 20:55:28 +01:00
|
|
|
account_label = app.config.get_per(
|
2018-02-19 21:22:28 +01:00
|
|
|
'accounts', account, 'account_label') or account
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_connected(account):
|
2010-02-08 15:08:40 +01:00
|
|
|
# for chat_with
|
2014-10-20 17:20:38 +02:00
|
|
|
item = Gtk.MenuItem.new_with_label(
|
2018-02-16 20:55:28 +01:00
|
|
|
_('using account %s') % account_label)
|
2010-02-08 15:08:40 +01:00
|
|
|
account_menu_for_chat_with.append(item)
|
|
|
|
item.connect('activate', self.on_new_chat, account)
|
|
|
|
|
|
|
|
elif connected_accounts == 1: # one account
|
|
|
|
# one account connected, no need to show 'as jid'
|
2017-08-13 13:18:56 +02:00
|
|
|
for account in app.connections:
|
|
|
|
if app.connections[account].connected > 1:
|
2010-02-08 15:08:40 +01:00
|
|
|
# for start chat
|
|
|
|
self.new_chat_handler_id = chat_with_menuitem.connect(
|
|
|
|
'activate', self.on_new_chat, account)
|
|
|
|
break # No other connected account
|
|
|
|
|
|
|
|
# menu items that don't apply to zeroconf connections
|
|
|
|
if connected_accounts == 1 or (connected_accounts == 2 and \
|
2017-08-13 13:18:56 +02:00
|
|
|
app.zeroconf_is_connected()):
|
2010-02-08 15:08:40 +01:00
|
|
|
# only one 'real' (non-zeroconf) account is connected, don't need
|
|
|
|
# submenus
|
2017-08-13 13:18:56 +02:00
|
|
|
for account in app.connections:
|
|
|
|
if app.account_is_connected(account) and \
|
|
|
|
not app.config.get_per('accounts', account, 'is_zeroconf'):
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# for single message
|
2013-01-01 16:58:57 +01:00
|
|
|
single_message_menuitem.set_submenu(None)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.single_message_handler_id = single_message_menuitem.\
|
|
|
|
connect('activate',
|
|
|
|
self.on_single_message_menuitem_activate, account)
|
|
|
|
# join gc
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.add_bookmarks_list(gc_sub_menu,
|
2010-02-08 15:08:40 +01:00
|
|
|
account)
|
|
|
|
break # No other account connected
|
|
|
|
else:
|
|
|
|
# 2 or more 'real' accounts are connected, make submenus
|
2012-12-23 16:23:43 +01:00
|
|
|
account_menu_for_single_message = Gtk.Menu()
|
2010-02-08 15:08:40 +01:00
|
|
|
single_message_menuitem.set_submenu(
|
|
|
|
account_menu_for_single_message)
|
|
|
|
self.popup_menus.append(account_menu_for_single_message)
|
|
|
|
|
|
|
|
for account in accounts_list:
|
2018-02-16 20:55:28 +01:00
|
|
|
account_label = app.config.get_per(
|
2018-02-19 21:22:28 +01:00
|
|
|
'accounts', account, 'account_label') or account
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.connections[account].is_zeroconf or \
|
|
|
|
not app.account_is_connected(account):
|
2010-02-08 15:08:40 +01:00
|
|
|
continue
|
|
|
|
# for single message
|
2014-10-20 17:20:38 +02:00
|
|
|
item = Gtk.MenuItem.new_with_label(
|
2018-02-16 20:55:28 +01:00
|
|
|
_('using account %s') % account_label)
|
2010-02-08 15:08:40 +01:00
|
|
|
item.connect('activate',
|
|
|
|
self.on_single_message_menuitem_activate, account)
|
|
|
|
account_menu_for_single_message.append(item)
|
|
|
|
|
|
|
|
# join gc
|
2014-10-20 17:20:38 +02:00
|
|
|
gc_item = Gtk.MenuItem.new_with_label(
|
2018-02-16 20:55:28 +01:00
|
|
|
_('using account %s') % account_label)
|
2010-02-08 15:08:40 +01:00
|
|
|
gc_sub_menu.append(gc_item)
|
2012-12-23 16:23:43 +01:00
|
|
|
gc_menuitem_menu = Gtk.Menu()
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.add_bookmarks_list(gc_menuitem_menu,
|
2010-02-08 15:08:40 +01:00
|
|
|
account)
|
|
|
|
gc_item.set_submenu(gc_menuitem_menu)
|
|
|
|
gc_sub_menu.show_all()
|
|
|
|
|
2013-01-01 16:46:04 +01:00
|
|
|
newitem = Gtk.SeparatorMenuItem.new() # separator
|
2010-02-08 15:08:40 +01:00
|
|
|
gc_sub_menu.append(newitem)
|
2017-02-04 23:29:45 +01:00
|
|
|
newitem = Gtk.MenuItem.new_with_mnemonic(_('_Manage Bookmarks…'))
|
2010-02-08 15:08:40 +01:00
|
|
|
newitem.connect('activate',
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.on_manage_bookmarks_menuitem_activate)
|
2018-07-27 15:46:02 +02:00
|
|
|
newitem.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
gc_sub_menu.append(newitem)
|
2018-07-27 15:46:02 +02:00
|
|
|
for account in accounts_list:
|
|
|
|
if app.account_supports_private_storage(account):
|
|
|
|
newitem.set_sensitive(True)
|
|
|
|
break
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
sounds_mute_menuitem.set_active(not app.config.get('sounds_on'))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
win = app.interface.roster.window
|
2011-03-08 19:55:16 +01:00
|
|
|
if self.show_roster_handler_id:
|
|
|
|
show_roster_menuitem.handler_disconnect(self.show_roster_handler_id)
|
2010-02-09 19:36:32 +01:00
|
|
|
if win.get_property('has-toplevel-focus'):
|
|
|
|
show_roster_menuitem.get_children()[0].set_label(_('Hide _Roster'))
|
2011-03-08 19:55:16 +01:00
|
|
|
self.show_roster_handler_id = show_roster_menuitem.connect(
|
|
|
|
'activate', self.on_hide_roster_menuitem_activate)
|
2010-02-09 19:36:32 +01:00
|
|
|
else:
|
|
|
|
show_roster_menuitem.get_children()[0].set_label(_('Show _Roster'))
|
2011-03-08 19:55:16 +01:00
|
|
|
self.show_roster_handler_id = show_roster_menuitem.connect(
|
|
|
|
'activate', self.on_show_roster_menuitem_activate)
|
2010-02-09 19:36:32 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if os.name == 'nt':
|
|
|
|
if self.added_hide_menuitem is False:
|
2013-01-01 16:46:04 +01:00
|
|
|
self.systray_context_menu.prepend(Gtk.SeparatorMenuItem.new())
|
2014-10-20 17:20:38 +02:00
|
|
|
item = Gtk.MenuItem.new_with_label(
|
|
|
|
_('Hide this menu'))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.systray_context_menu.prepend(item)
|
|
|
|
self.added_hide_menuitem = True
|
|
|
|
|
|
|
|
self.systray_context_menu.show_all()
|
2012-12-27 21:58:52 +01:00
|
|
|
self.systray_context_menu.popup(None, None, None, None, 0, event_time)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_show_all_events_menuitem_activate(self, widget):
|
2017-08-13 13:18:56 +02:00
|
|
|
events = app.events.get_systray_events()
|
2010-02-08 15:08:40 +01:00
|
|
|
for account in events:
|
|
|
|
for jid in events[account]:
|
|
|
|
for event in events[account][jid]:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.handle_event(account, jid, event.type_)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_sounds_mute_menuitem_activate(self, widget):
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set('sounds_on', not widget.get_active())
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_show_roster_menuitem_activate(self, widget):
|
2017-08-13 13:18:56 +02:00
|
|
|
win = app.interface.roster.window
|
2010-02-08 15:08:40 +01:00
|
|
|
win.present()
|
|
|
|
|
2010-02-09 19:36:32 +01:00
|
|
|
def on_hide_roster_menuitem_activate(self, widget):
|
2017-08-13 13:18:56 +02:00
|
|
|
win = app.interface.roster.window
|
2010-02-09 19:36:32 +01:00
|
|
|
win.hide()
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_preferences_menuitem_activate(self, widget):
|
2018-08-06 19:44:51 +02:00
|
|
|
from gajim.gtk.preferences import Preferences
|
|
|
|
window = app.get_app_window(Preferences)
|
|
|
|
if window is None:
|
|
|
|
Preferences()
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2018-08-06 19:44:51 +02:00
|
|
|
window.present()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_quit_menuitem_activate(self, widget):
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.on_quit_request()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_left_click(self):
|
2017-08-13 13:18:56 +02:00
|
|
|
win = app.interface.roster.window
|
|
|
|
if len(app.events.get_systray_events()) == 0:
|
2010-02-08 15:08:40 +01:00
|
|
|
# No pending events, so toggle visible/hidden for roster window
|
|
|
|
if win.get_property('visible') and (win.get_property(
|
|
|
|
'has-toplevel-focus') or os.name == 'nt'):
|
|
|
|
# visible in ANY virtual desktop?
|
|
|
|
|
|
|
|
# we could be in another VD right now. eg vd2
|
|
|
|
# and we want to show it in vd2
|
2011-04-21 20:52:14 +02:00
|
|
|
if not gtkgui_helpers.possibly_move_window_in_current_desktop(
|
2017-08-13 13:18:56 +02:00
|
|
|
win) and app.config.get('save-roster-position'):
|
2010-02-19 09:48:22 +01:00
|
|
|
x, y = win.get_position()
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set('roster_x-position', x)
|
|
|
|
app.config.set('roster_y-position', y)
|
2011-03-21 09:49:42 +01:00
|
|
|
win.hide() # else we hide it from VD that was visible in
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2010-02-19 09:48:22 +01:00
|
|
|
if not win.get_property('visible'):
|
|
|
|
win.show_all()
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get('save-roster-position'):
|
2011-04-21 20:52:14 +02:00
|
|
|
gtkgui_helpers.move_window(win,
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.get('roster_x-position'),
|
|
|
|
app.config.get('roster_y-position'))
|
|
|
|
if not app.config.get('roster_window_skip_taskbar'):
|
2010-02-08 15:08:40 +01:00
|
|
|
win.set_property('skip-taskbar-hint', False)
|
2012-12-23 16:23:43 +01:00
|
|
|
win.present_with_time(Gtk.get_current_event_time())
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
self.handle_first_event()
|
|
|
|
|
|
|
|
def handle_first_event(self):
|
2017-08-13 13:18:56 +02:00
|
|
|
account, jid, event = app.events.get_first_systray_event()
|
2010-02-08 15:08:40 +01:00
|
|
|
if not event:
|
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
win = app.interface.roster.window
|
|
|
|
if not win.get_property('visible') and app.config.get(
|
2011-04-21 20:52:14 +02:00
|
|
|
'save-roster-position'):
|
2011-01-27 17:10:15 +01:00
|
|
|
gtkgui_helpers.move_window(win,
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.get('roster_x-position'),
|
|
|
|
app.config.get('roster_y-position'))
|
|
|
|
app.interface.handle_event(account, jid, event.type_)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_middle_click(self):
|
|
|
|
"""
|
|
|
|
Middle click raises window to have complete focus (fe. get kbd events)
|
|
|
|
but if already raised, it hides it
|
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
win = app.interface.roster.window
|
2010-02-08 15:08:40 +01:00
|
|
|
if win.is_active(): # is it fully raised? (eg does it receive kbd events?)
|
|
|
|
win.hide()
|
|
|
|
else:
|
|
|
|
win.present()
|
|
|
|
|
|
|
|
def on_clicked(self, widget, event):
|
|
|
|
self.on_tray_leave_notify_event(widget, None)
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.type_ != Gdk.EventType.BUTTON_PRESS:
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
|
|
|
if event.button == 1: # Left click
|
|
|
|
self.on_left_click()
|
|
|
|
elif event.button == 2: # middle click
|
|
|
|
self.on_middle_click()
|
|
|
|
elif event.button == 3: # right click
|
|
|
|
self.make_menu(event.button, event.time)
|
|
|
|
|
|
|
|
def on_show_menuitem_activate(self, widget, show):
|
|
|
|
# we all add some fake (we cannot select those nor have them as show)
|
|
|
|
# but this helps to align with roster's status_combobox index positions
|
|
|
|
l = ['online', 'chat', 'away', 'xa', 'dnd', 'invisible', 'SEPARATOR',
|
|
|
|
'CHANGE_STATUS_MSG_MENUITEM', 'SEPARATOR', 'offline']
|
|
|
|
index = l.index(show)
|
|
|
|
if not helpers.statuses_unified():
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.status_combobox.set_active(index + 2)
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
current = app.interface.roster.status_combobox.get_active()
|
2010-02-08 15:08:40 +01:00
|
|
|
if index != current:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.status_combobox.set_active(index)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_change_status_message_activate(self, widget):
|
2017-08-13 13:18:56 +02:00
|
|
|
model = app.interface.roster.status_combobox.get_model()
|
|
|
|
active = app.interface.roster.status_combobox.get_active()
|
2013-01-01 19:44:25 +01:00
|
|
|
status = model[active][2]
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_response(message, pep_dict):
|
|
|
|
if message is None: # None if user press Cancel
|
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts = app.connections.keys()
|
2010-02-08 15:08:40 +01:00
|
|
|
for acct in accounts:
|
2017-08-13 13:18:56 +02:00
|
|
|
if not app.config.get_per('accounts', acct,
|
2010-02-08 15:08:40 +01:00
|
|
|
'sync_with_global_status'):
|
|
|
|
continue
|
2017-08-13 13:18:56 +02:00
|
|
|
show = app.SHOW_LIST[app.connections[acct].connected]
|
|
|
|
app.interface.roster.send_status(acct, show, message)
|
|
|
|
app.interface.roster.send_pep(acct, pep_dict)
|
2010-02-08 15:08:40 +01:00
|
|
|
dlg = dialogs.ChangeStatusMessageDialog(on_response, status)
|
|
|
|
dlg.dialog.present()
|