2018-09-05 02:59:34 +02:00
|
|
|
# Copyright (C) 2006 Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
# Copyright (C) 2006-2007 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
# Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
# 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>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
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
|
2009-11-24 14:33:49 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import dialogs
|
2018-10-28 14:59:51 +01:00
|
|
|
|
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-10-04 23:55:35 +02:00
|
|
|
from gajim.common.i18n import _
|
2019-03-25 22:01:11 +01:00
|
|
|
from gajim.common.helpers import save_roster_position
|
2018-10-28 14:59:51 +01:00
|
|
|
|
2018-10-25 00:12:28 +02:00
|
|
|
from gajim.gtk.util import get_builder
|
2018-10-28 14:32:54 +01:00
|
|
|
from gajim.gtk.util import get_icon_name
|
2019-03-25 22:14:18 +01:00
|
|
|
from gajim.gtk.util import restore_roster_position
|
2018-09-26 19:06:47 +02:00
|
|
|
from gajim.gtk.single_message import SingleMessageWindow
|
2018-10-28 09:33:40 +01:00
|
|
|
from gajim.gtk.tooltips import NotificationAreaTooltip
|
2018-07-16 23:22:33 +02:00
|
|
|
|
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'
|
2018-10-25 00:12:28 +02:00
|
|
|
self._ui = get_builder('systray_context_menu.ui')
|
|
|
|
self.systray_context_menu = self._ui.systray_context_menu
|
|
|
|
self._ui.connect_signals(self)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.popup_menus = []
|
|
|
|
self.status_icon = None
|
2018-10-28 09:33:40 +01:00
|
|
|
self.tooltip = NotificationAreaTooltip()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
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)
|
2018-10-25 00:12:28 +02:00
|
|
|
self.status_icon.connect('activate', self._on_activate)
|
|
|
|
self.status_icon.connect('popup-menu', self._on_popup_menu)
|
|
|
|
self.status_icon.connect('query-tooltip', self._on_query_tooltip)
|
2017-10-27 12:20:15 +02:00
|
|
|
self.status_icon.connect('size-changed', self.set_img)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.set_img()
|
|
|
|
self.subscribe_events()
|
|
|
|
|
2018-10-25 00:12:28 +02:00
|
|
|
def _on_query_tooltip(self, _status_icon, _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()
|
|
|
|
|
2018-10-25 00:12:28 +02:00
|
|
|
def _on_popup_menu(self, _status_icon, button, activate_time):
|
|
|
|
if button == 1: # Left click
|
|
|
|
self.on_left_click()
|
|
|
|
elif button == 2: # middle click
|
|
|
|
self.on_middle_click()
|
|
|
|
elif button == 3: # right click
|
|
|
|
self.make_menu(button, activate_time)
|
|
|
|
|
|
|
|
def _on_activate(self, _status_icon):
|
2010-02-08 15:08:40 +01:00
|
|
|
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
|
|
|
|
2018-10-28 14:32:54 +01:00
|
|
|
icon_name = get_icon_name('event')
|
2017-10-27 12:20:15 +02:00
|
|
|
self.status_icon.set_from_icon_name(icon_name)
|
2012-12-23 16:23:43 +01:00
|
|
|
return
|
2018-09-18 10:14:04 +02:00
|
|
|
|
|
|
|
if app.config.get('trayicon') == 'on_event':
|
|
|
|
self.status_icon.set_visible(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-10-28 14:32:54 +01:00
|
|
|
icon_name = get_icon_name(self.status)
|
2017-10-27 12:20:15 +02:00
|
|
|
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()
|
|
|
|
|
2018-10-25 00:12:28 +02:00
|
|
|
chat_with_menuitem = self._ui.chat_with_menuitem
|
|
|
|
single_message_menuitem = self._ui.single_message_menuitem
|
|
|
|
status_menuitem = self._ui.status_menu
|
|
|
|
join_gc_menuitem = self._ui.join_gc_menuitem
|
|
|
|
sounds_mute_menuitem = self._ui.sounds_mute_menuitem
|
|
|
|
show_roster_menuitem = self._ui.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)
|
|
|
|
|
|
|
|
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-08-30 19:27:40 +02:00
|
|
|
account_label = app.get_account_label(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-08-30 19:27:40 +02:00
|
|
|
account_label = app.get_account_label(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
|
2018-09-16 01:10:04 +02:00
|
|
|
if not app.events.get_systray_events():
|
2010-02-08 15:08:40 +01:00
|
|
|
# No pending events, so toggle visible/hidden for roster window
|
2018-09-18 16:28:33 +02:00
|
|
|
if win.get_property('visible'):
|
|
|
|
if win.get_property('has-toplevel-focus') or os.name == 'nt':
|
2019-03-25 22:01:11 +01:00
|
|
|
save_roster_position(win)
|
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:
|
2019-03-25 22:01:11 +01:00
|
|
|
win.show_all()
|
2019-03-25 22:14:18 +01:00
|
|
|
restore_roster_position(win)
|
2017-08-13 13:18:56 +02:00
|
|
|
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
|
2019-03-25 22:14:18 +01:00
|
|
|
if not win.get_property('visible'):
|
|
|
|
# Needed if we are in one window mode
|
|
|
|
restore_roster_position(win)
|
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_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_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()
|