Esempio n. 1
0
    def hamster_facts_changed(self, *args, **kw):
        # get hamster tags
        facts = self.session_presence.GetTodaysFacts(
            dbus_interface=HAMSTAER_INTERFACE)
        if not facts:
            return
        if self.from_dbus_fact(facts[-1])['end_time']:
            accounts = gajim.connections.keys()
            for account in accounts:
                if gajim.account_is_connected(account):
                    connection = gajim.connections[account]
                    connection.retract_activity()
            return

        last_fact = self.from_dbus_fact(facts[-1])
        tags = set(last_fact['tags'])

        activity = "Other"
        activity_candidates = XMPP_ACTIVITIES.intersection(tags)
        if len(activity_candidates) >= 1:
            activity=list(activity_candidates)[0]
        subactivity = 'other'
        subactivity_candidates = SUBACTIVITIES.intersection(tags)
        if len(subactivity_candidates) >= 1:
            subactivity=list(subactivity_candidates)[0]

        # send activity
        for account in gajim.connections:
            if gajim.account_is_connected(account):
                connection = gajim.connections[account]
                connection.send_activity(activity, subactivity,
                    last_fact['fact'])
Esempio n. 2
0
    def hamster_facts_changed(self, *args, **kw):
        # get hamster tags
        facts = self.session_presence.GetTodaysFacts(
            dbus_interface=HAMSTAER_INTERFACE)
        if not facts:
            return
        if self.from_dbus_fact(facts[-1])['end_time']:
            accounts = gajim.connections.keys()
            for account in accounts:
                if gajim.account_is_connected(account):
                    connection = gajim.connections[account]
                    connection.retract_activity()
            return

        last_fact = self.from_dbus_fact(facts[-1])
        tags = set(last_fact['tags'])

        activity = "Other"
        activity_candidates = XMPP_ACTIVITIES.intersection(tags)
        if len(activity_candidates) >= 1:
            activity = list(activity_candidates)[0]
        subactivity = 'other'
        subactivity_candidates = SUBACTIVITIES.intersection(tags)
        if len(subactivity_candidates) >= 1:
            subactivity = list(subactivity_candidates)[0]

        # send activity
        for account in gajim.connections:
            if gajim.account_is_connected(account):
                connection = gajim.connections[account]
                connection.send_activity(activity, subactivity,
                                         last_fact['fact'])
Esempio n. 3
0
 def show_contacts(self):
     if not self.images:
         data = {}
         accounts = gajim.contacts._accounts
         for account in accounts:
             if not gajim.account_is_connected(account):
                 continue
             for contact in accounts[account].contacts._contacts:
                 pep = accounts[account].contacts._contacts[contact][0].pep
                 if 'location' not in pep:
                     continue
                 lat = pep['location']._pep_specific_data.get('lat', None)
                 lon = pep['location']._pep_specific_data.get('lon', None)
                 if not lat or not lon:
                     continue
                 data[contact] = (lat, lon)
         for jid in data:
             path = gtkgui_helpers.get_path_to_generic_or_avatar(
                 None, jid=jid, suffix='')
             icon = gtk.gdk.pixbuf_new_from_file_at_size(path, 24, 24)
             image = self.osm.image_add(float(data[jid][0]),
                                        float(data[jid][1]), icon)
             self.images.append(image)
     else:
         for image in self.images:
             self.osm.image_remove(image)
         self.images = []
Esempio n. 4
0
def on_suspend(active):
    """Signal handler for suspend event"""

    global fd

    if not active:
        # we just resumed, we should take another inhibitor
        get_inhibitor()
        return

    # we're going for suspend, let's disconnect
    log.debug("System suspend detected, disconnecting from network...")
    for name, conn in gajim.connections.items():
        if gajim.account_is_connected(name):
            conn.old_show = gajim.SHOW_LIST[conn.connected]
            st = conn.status
            conn.change_status("offline", _("Machine going to sleep"))
            conn.status = st
            conn.time_to_reconnect = 5

    # close the file descriptor and let the computer suspend
    if fd >= 0:
        os.close(fd)
        fd = -1
    else:
        # something is wrong, the system is suspending but we don't have
        # a lock file
        log.warning(
            "System suspend detected, but we don't seem to be holding " "a file descriptor for sleep inihibitor"
        )
Esempio n. 5
0
 def show_contacts(self):
     if not self.images:
         data = {}
         accounts = gajim.contacts._accounts
         for account in accounts:
             if not gajim.account_is_connected(account):
                 continue
             for contact in accounts[account].contacts._contacts:
                 pep = accounts[account].contacts._contacts[contact][0].pep
                 if 'location' not in pep:
                     continue
                 lat = pep['location']._pep_specific_data.get('lat', None)
                 lon = pep['location']._pep_specific_data.get('lon', None)
                 if not lat or not lon:
                     continue
                 data[contact] = (lat, lon)
         for jid in data:
             path = gtkgui_helpers.get_path_to_generic_or_avatar(None,
                                                                 jid=jid,
                                                                 suffix='')
             icon = gtk.gdk.pixbuf_new_from_file_at_size(path, 24, 24)
             image = self.osm.image_add(float(data[jid][0]),
                                        float(data[jid][1]), icon)
             self.images.append(image)
     else:
         for image in self.images:
             self.osm.image_remove(image)
         self.images = []
Esempio n. 6
0
def on_suspend(active):
    '''Signal handler for suspend event'''

    global fd

    if not active:
        # we just resumed, we should take another inhibitor
        get_inhibitor()
        return

    # we're going for suspend, let's disconnect
    log.debug('System suspend detected, disconnecting from network…')
    for name, conn in gajim.connections.items():
        if gajim.account_is_connected(name):
            conn.old_show = gajim.SHOW_LIST[conn.connected]
            st = conn.status
            conn.change_status('offline', _('Machine going to sleep'))
            conn.status = st
            conn.time_to_reconnect = 5

    # close the file descriptor and let the computer suspend
    if fd >= 0:
        os.close(fd)
        fd = -1
    else:
        # something is wrong, the system is suspending but we don't have
        # a lock file
        log.warning("System suspend detected, but we don't seem to be holding "
            "a file descriptor for sleep inihibitor")
Esempio n. 7
0
def on_suspend(*args, **kwargs):
    for name, conn in gajim.connections.items():
        if gajim.account_is_connected(name):
            conn.old_show = gajim.SHOW_LIST[conn.connected]
            st = conn.status
            conn.change_status('offline', _('Machine going to sleep'))
            conn.status = st
            conn.time_to_reconnect = 5
Esempio n. 8
0
 def request_archive_preferences(self):
     if not gajim.account_is_connected(self.name):
         return
     iq = nbxmpp.Iq(typ='get')
     id_ = self.connection.getAnID()
     iq.setID(id_)
     iq.addChild(name='prefs', namespace=nbxmpp.NS_MAM)
     self.connection.send(iq)
Esempio n. 9
0
def on_suspend(*args, **kwargs):
    for name, conn in gajim.connections.items():
        if gajim.account_is_connected(name):
            conn.old_show = gajim.SHOW_LIST[conn.connected]
            st = conn.status
            conn.change_status('offline', _('Machine going to sleep'))
            conn.status = st
            conn.time_to_reconnect = 5
Esempio n. 10
0
    def _disconnectedReconnCB(self):
        '''Called when we are disconnected. Comes from network manager for example
		we don't try to reconnect, network manager will tell us when we can'''
        if gajim.account_is_connected(self.name):
            # we cannot change our status to offline or connecting
            # after we auth to server
            self.old_show = STATUS_LIST[self.connected]
        self.connected = 0
        self.dispatch('STATUS', 'offline')
        # random number to show we wait network manager to send us a reconenct
        self.time_to_reconnect = 5
        self.on_purpose = False
Esempio n. 11
0
	def _disconnectedReconnCB(self):
		'''Called when we are disconnected. Comes from network manager for example
		we don't try to reconnect, network manager will tell us when we can'''
		if gajim.account_is_connected(self.name):
			# we cannot change our status to offline or connecting
			# after we auth to server
			self.old_show = STATUS_LIST[self.connected]
		self.connected = 0
		self.dispatch('STATUS', 'offline')
		# random number to show we wait network manager to send us a reconenct
		self.time_to_reconnect = 5
		self.on_purpose = False
Esempio n. 12
0
 def activate(self):
     if NS_NOTIFY not in gajim.gajim_common_features:
         gajim.gajim_common_features.append(NS_NOTIFY)
     self._compute_caps_hash()
     # Publish bundle information
     for account in gajim.connections:
         if account not in self.announced:
             if gajim.account_is_connected(account):
                 log.debug(account +
                           ' => Announce Support after Plugin Activation')
                 self.announced.append(account)
                 self.publish_bundle(account)
                 self.query_own_devicelist(account)
Esempio n. 13
0
 def activate(self):
     self.query_for_bundles = []
     if NS_NOTIFY not in gajim.gajim_common_features:
         gajim.gajim_common_features.append(NS_NOTIFY)
     self._compute_caps_hash()
     # Publish bundle information
     for account in gajim.connections:
         if account not in self.announced:
             if gajim.account_is_connected(account):
                 log.debug(account +
                           ' => Announce Support after Plugin Activation')
                 self.announced.append(account)
                 self.publish_bundle(account)
                 self.query_own_devicelist(account)
Esempio n. 14
0
 def _disconnectedReconnCB(self):
     """
     Called when we are disconnected. Comes from network manager for example
     we don't try to reconnect, network manager will tell us when we can
     """
     if gajim.account_is_connected(self.name):
         # we cannot change our status to offline or connecting
         # after we auth to server
         self.old_show = STATUS_LIST[self.connected]
     self.connected = 0
     gajim.nec.push_incoming_event(
         OurShowEvent(None, conn=self, show='offline'))
     # random number to show we wait network manager to send us a reconenct
     self.time_to_reconnect = 5
     self.on_purpose = False
Esempio n. 15
0
 def status_changed(self, widget, event):
     if event.keyval == gtk.keysyms.Return or \
         event.keyval == gtk.keysyms.KP_Enter:
         accounts = gajim.connections.keys()
         message = widget.get_text()
         for account in accounts:
             if not gajim.account_is_connected(account):
                 continue
             current_show = gajim.SHOW_LIST[
                 gajim.connections[account].connected]
             self.roster.send_status(account, current_show, message)
         self.font_desc.set_weight(pango.WEIGHT_BOLD)
         widget.modify_font(self.font_desc)
         self.font_desc.set_weight(pango.WEIGHT_NORMAL)
         gobject.timeout_add(1000, widget.modify_font, self.font_desc)
Esempio n. 16
0
 def _disconnectedReconnCB(self):
     """
     Called when we are disconnected. Comes from network manager for example
     we don't try to reconnect, network manager will tell us when we can
     """
     if gajim.account_is_connected(self.name):
         # we cannot change our status to offline or connecting
         # after we auth to server
         self.old_show = STATUS_LIST[self.connected]
     self.connected = 0
     gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
         show='offline'))
     # random number to show we wait network manager to send us a reconenct
     self.time_to_reconnect = 5
     self.on_purpose = False
Esempio n. 17
0
 def status_changed(self, widget, event):
     if event.keyval == gtk.keysyms.Return or \
         event.keyval == gtk.keysyms.KP_Enter:
         accounts = gajim.connections.keys()
         message = widget.get_text()
         for account in accounts:
             if not gajim.account_is_connected(account):
                 continue
             current_show = gajim.SHOW_LIST[
                 gajim.connections[account].connected]
             self.roster.send_status(account, current_show, message)
         self.font_desc.set_weight(pango.WEIGHT_BOLD)
         widget.modify_font(self.font_desc)
         self.font_desc.set_weight(pango.WEIGHT_NORMAL)
         gobject.timeout_add(1000, widget.modify_font, self.font_desc)
Esempio n. 18
0
	def join_room(self, room_jid, nick, password, account):
		if not account:
			# get the first connected account
			accounts = gajim.connections.keys()
			for acct in accounts:
				if gajim.account_is_connected(acct):
					account = acct
					break
			if not account:
				return
		if not nick:
			nick = ''
			gajim.interface.instances[account]['join_gc'] = \
					JoinGroupchatWindow(account, room_jid, nick)
		else:
			gajim.interface.join_gc_room(account, room_jid, nick, password)
Esempio n. 19
0
 def set_indicator_icon(self, obj=''):
     is_connected = 0
     for account in gajim.connections:
         if not gajim.config.get_per('accounts', account,
         'sync_with_global_status'):
             continue
         if gajim.account_is_connected(account):
             is_connected = 1
             break
     if self.connected != is_connected:
         self.connected = is_connected
         if self.connected == 1:
             self.indicator.set_icon(self.online_icon)
             self.connect_menu_item.hide()
         else:
             self.indicator.set_icon(self.offline_icon)
             self.connect_menu_item.show()
Esempio n. 20
0
 def set_indicator_icon(self, obj=''):
     is_connected = 0
     for account in gajim.connections:
         if not gajim.config.get_per('accounts', account,
                                     'sync_with_global_status'):
             continue
         if gajim.account_is_connected(account):
             is_connected = 1
             break
     if self.connected != is_connected:
         self.connected = is_connected
         if self.connected == 1:
             self.indicator.set_icon(self.online_icon)
             self.connect_menu_item.hide()
         else:
             self.indicator.set_icon(self.offline_icon)
             self.connect_menu_item.show()
Esempio n. 21
0
 def _send_location(self):
     accounts = gajim.connections.keys()
     for acct in accounts:
         if not gajim.account_is_connected(acct):
             continue
         if not gajim.config.get_per('accounts', acct, 'publish_location'):
             continue
         if self.location_info == self._data:
             continue
         if 'timestamp' in self.location_info and 'timestamp' in self._data:
             last_data = self.location_info.copy()
             del last_data['timestamp']
             new_data = self._data.copy()
             del new_data['timestamp']
             if last_data == new_data:
                 continue
         gajim.connections[acct].send_location(self._data)
         self.location_info = self._data.copy()
Esempio n. 22
0
 def _send_location(self):
     accounts = gajim.connections.keys()
     for acct in accounts:
         if not gajim.account_is_connected(acct):
             continue
         if not gajim.config.get_per('accounts', acct, 'publish_location'):
             continue
         if self.location_info == self._data:
             continue
         if 'timestamp' in self.location_info and 'timestamp' in self._data:
             last_data = self.location_info.copy()
             del last_data['timestamp']
             new_data = self._data.copy()
             del new_data['timestamp']
             if last_data == new_data:
                 continue
         gajim.connections[acct].send_location(self._data)
         self.location_info = self._data.copy()
Esempio n. 23
0
 def activate(self):
     """ Method called when the Plugin is activated in the PluginManager
     """
     self.query_for_bundles = []
     # Publish bundle information and Entity Caps
     for account in gajim.connections:
         if account in self.disabled_accounts:
             log.debug(account + ' => Account is disabled')
             continue
         if NS_NOTIFY not in gajim.gajim_optional_features[account]:
             gajim.gajim_optional_features[account].append(NS_NOTIFY)
         self._compute_caps_hash(account)
         if account not in self.announced:
             if gajim.account_is_connected(account):
                 log.debug(account +
                           ' => Announce Support after Plugin Activation')
                 self.announced.append(account)
                 self.publish_bundle(account)
                 self.query_own_devicelist(account)
Esempio n. 24
0
 def set_archive_preferences(self, items, default):
     if not gajim.account_is_connected(self.name):
         return
     iq = nbxmpp.Iq(typ='set')
     id_ = self.connection.getAnID()
     self.iq_answer.append(id_)
     iq.setID(id_)
     prefs = iq.addChild(name='prefs',
                         namespace=nbxmpp.NS_MAM,
                         attrs={'default': default})
     always = prefs.addChild(name='always')
     never = prefs.addChild(name='never')
     for item in items:
         jid, preference = item
         if preference == 'always':
             always.addChild(name='jid').setData(jid)
         else:
             never.addChild(name='jid').setData(jid)
     self.connection.send(iq)
Esempio n. 25
0
 def activate(self):
     """ Method called when the Plugin is activated in the PluginManager
     """
     self.query_for_bundles = []
     # Publish bundle information and Entity Caps
     for account in gajim.connections:
         if account in self.disabled_accounts:
             log.debug(account +
                       ' => Account is disabled')
             continue
         if NS_NOTIFY not in gajim.gajim_optional_features[account]:
             gajim.gajim_optional_features[account].append(NS_NOTIFY)
         self._compute_caps_hash(account)
         if account not in self.announced:
             if gajim.account_is_connected(account):
                 log.debug(account +
                           ' => Announce Support after Plugin Activation')
                 self.announced.append(account)
                 self.publish_bundle(account)
                 self.query_own_devicelist(account)
Esempio n. 26
0
 def set_priority(self, prio, account):
     """
     set_priority(prio, account). Account is optional - if not specified
     priority is changed for all accounts. That are synced with global status
     """
     if account:
         gajim.config.set_per('accounts', account, 'priority', prio)
         show = gajim.SHOW_LIST[gajim.connections[account].connected]
         status = gajim.connections[account].status
         GLib.idle_add(gajim.connections[account].change_status, show,
                       status)
     else:
         # account not specified, so change prio of all accounts
         for acc in gajim.contacts.get_accounts():
             if not gajim.account_is_connected(acc):
                 continue
             if not gajim.config.get_per('accounts', acc,
                                         'sync_with_global_status'):
                 continue
             gajim.config.set_per('accounts', acc, 'priority', prio)
             show = gajim.SHOW_LIST[gajim.connections[acc].connected]
             status = gajim.connections[acc].status
             GLib.idle_add(gajim.connections[acc].change_status, show,
                           status)
Esempio n. 27
0
 def set_priority(self, prio, account):
     """
     set_priority(prio, account). Account is optional - if not specified
     priority is changed for all accounts. That are synced with global status
     """
     if account:
         gajim.config.set_per('accounts', account, 'priority', prio)
         show = gajim.SHOW_LIST[gajim.connections[account].connected]
         status = gajim.connections[account].status
         GLib.idle_add(gajim.connections[account].change_status, show,
             status)
     else:
         # account not specified, so change prio of all accounts
         for acc in gajim.contacts.get_accounts():
             if not gajim.account_is_connected(acc):
                 continue
             if not gajim.config.get_per('accounts', acc,
             'sync_with_global_status'):
                 continue
             gajim.config.set_per('accounts', acc, 'priority', prio)
             show = gajim.SHOW_LIST[gajim.connections[acc].connected]
             status = gajim.connections[acc].status
             GLib.idle_add(gajim.connections[acc].change_status, show,
                 status)
Esempio n. 28
0
 def send_pep(self):
     accounts = gajim.connections.keys()
     for account in accounts:
         if gajim.account_is_connected(account):
             self.roster.send_pep(account, self.pep_dict)
Esempio n. 29
0
 def send_pep(self):
     accounts = gajim.connections.keys()
     for account in accounts:
         if gajim.account_is_connected(account):
             self.roster.send_pep(account, self.pep_dict)
Esempio n. 30
0
    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')
        show_roster_menuitem = self.xml.get_object('show_roster_menuitem')

        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

        sub_menu = Gtk.Menu()
        self.popup_menus.append(sub_menu)
        status_menuitem.set_submenu(sub_menu)

        gc_sub_menu = Gtk.Menu() # gc is always a submenu
        join_gc_menuitem.set_submenu(gc_sub_menu)

        # We need our own set of status icons, let's make 'em!
        iconset = gajim.config.get('iconset')
        path = os.path.join(helpers.get_iconset_path(iconset), '16x16')

        for show in ('online', 'chat', 'away', 'xa', 'dnd', 'invisible'):
            uf_show = helpers.get_uf_show(show, use_mnemonic=True)
            item = Gtk.MenuItem.new_with_mnemonic(uf_show)
            sub_menu.append(item)
            item.connect('activate', self.on_show_menuitem_activate, show)

        item = Gtk.SeparatorMenuItem.new()
        sub_menu.append(item)

        item = Gtk.MenuItem.new_with_mnemonic(_('_Change Status Message…'))
        sub_menu.append(item)
        item.connect('activate', self.on_change_status_message_activate)

        connected_accounts = gajim.get_number_of_connected_accounts()
        if connected_accounts < 1:
            item.set_sensitive(False)

        connected_accounts_with_private_storage = 0

        item = Gtk.SeparatorMenuItem.new()
        sub_menu.append(item)

        uf_show = helpers.get_uf_show('offline', use_mnemonic=True)
        item = Gtk.MenuItem.new_with_mnemonic(uf_show)
        sub_menu.append(item)
        item.connect('activate', self.on_show_menuitem_activate, 'offline')

        iskey = connected_accounts > 0 and not (connected_accounts == 1 and
            gajim.zeroconf_is_connected())
        chat_with_menuitem.set_sensitive(iskey)
        single_message_menuitem.set_sensitive(iskey)
        join_gc_menuitem.set_sensitive(iskey)

        accounts_list = sorted(gajim.contacts.get_accounts())
        # items that get shown whether an account is zeroconf or not
        if connected_accounts > 1: # 2 or more connections? make submenus
            account_menu_for_chat_with = Gtk.Menu()
            chat_with_menuitem.set_submenu(account_menu_for_chat_with)
            self.popup_menus.append(account_menu_for_chat_with)

            for account in accounts_list:
                if gajim.account_is_connected(account):
                    # for chat_with
                    item = Gtk.MenuItem.new_with_label(
                        _('using account %s') % account)
                    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'
            for account in gajim.connections:
                if gajim.connections[account].connected > 1:
                    # 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 \
        gajim.zeroconf_is_connected()):
            # only one 'real' (non-zeroconf) account is connected, don't need
            # submenus
            for account in gajim.connections:
                if gajim.account_is_connected(account) and \
                not gajim.config.get_per('accounts', account, 'is_zeroconf'):
                    if gajim.connections[account].private_storage_supported:
                        connected_accounts_with_private_storage += 1

                    # for single message
                    single_message_menuitem.set_submenu(None)
                    self.single_message_handler_id = single_message_menuitem.\
                            connect('activate',
                            self.on_single_message_menuitem_activate, account)
                    # join gc
                    gajim.interface.roster.add_bookmarks_list(gc_sub_menu,
                            account)
                    break # No other account connected
        else:
            # 2 or more 'real' accounts are connected, make submenus
            account_menu_for_single_message = Gtk.Menu()
            single_message_menuitem.set_submenu(
                    account_menu_for_single_message)
            self.popup_menus.append(account_menu_for_single_message)

            for account in accounts_list:
                if gajim.connections[account].is_zeroconf or \
                not gajim.account_is_connected(account):
                    continue
                if gajim.connections[account].private_storage_supported:
                    connected_accounts_with_private_storage += 1
                # for single message
                item = Gtk.MenuItem.new_with_label(
                    _('using account %s') % account)
                item.connect('activate',
                        self.on_single_message_menuitem_activate, account)
                account_menu_for_single_message.append(item)

                # join gc
                gc_item = Gtk.MenuItem.new_with_label(
                    _('using account %s') % account)
                gc_sub_menu.append(gc_item)
                gc_menuitem_menu = Gtk.Menu()
                gajim.interface.roster.add_bookmarks_list(gc_menuitem_menu,
                        account)
                gc_item.set_submenu(gc_menuitem_menu)
                gc_sub_menu.show_all()

        newitem = Gtk.SeparatorMenuItem.new() # separator
        gc_sub_menu.append(newitem)
        newitem = Gtk.MenuItem.new_with_mnemonic(_('_Manage Bookmarks…'))
        newitem.connect('activate',
            gajim.interface.roster.on_manage_bookmarks_menuitem_activate)
        gc_sub_menu.append(newitem)
        if connected_accounts_with_private_storage == 0:
            newitem.set_sensitive(False)

        sounds_mute_menuitem.set_active(not gajim.config.get('sounds_on'))

        win = gajim.interface.roster.window
        if self.show_roster_handler_id:
            show_roster_menuitem.handler_disconnect(self.show_roster_handler_id)
        if win.get_property('has-toplevel-focus'):
            show_roster_menuitem.get_children()[0].set_label(_('Hide _Roster'))
            self.show_roster_handler_id = show_roster_menuitem.connect(
                'activate', self.on_hide_roster_menuitem_activate)
        else:
            show_roster_menuitem.get_children()[0].set_label(_('Show _Roster'))
            self.show_roster_handler_id = show_roster_menuitem.connect(
                'activate', self.on_show_roster_menuitem_activate)

        if os.name == 'nt':
            if self.added_hide_menuitem is False:
                self.systray_context_menu.prepend(Gtk.SeparatorMenuItem.new())
                item = Gtk.MenuItem.new_with_label(
                    _('Hide this menu'))
                self.systray_context_menu.prepend(item)
                self.added_hide_menuitem = True

        self.systray_context_menu.show_all()
        self.systray_context_menu.popup(None, None, None, None, 0, event_time)
Esempio n. 31
0
    def update_button_state(self, chat_control):
        global jid_to_servers
        global iq_ids_to_callbacks
        global last_info_query

        if gajim.connections[chat_control.account].connection == None and \
            gajim.get_jid_from_account(chat_control.account) in jid_to_servers:
            # maybe don't delete this and detect vanished upload components when actually trying to upload something
            log.info("Deleting %s from jid_to_servers (disconnected)" % gajim.get_jid_from_account(chat_control.account))
            del jid_to_servers[gajim.get_jid_from_account(chat_control.account)]
            #pass

        # query info at most every 60 seconds in case something goes wrong
        if (not chat_control.account in last_info_query or \
            last_info_query[chat_control.account] + 60 < time.time()) and \
            not gajim.get_jid_from_account(chat_control.account) in jid_to_servers and \
            gajim.account_is_connected(chat_control.account):
            log.info("Account %s: Using dicovery to find jid of httpupload component" % chat_control.account)
            id_ = gajim.get_an_id()
            iq = nbxmpp.Iq(
                typ='get',
                to=gajim.get_server_from_jid(gajim.get_jid_from_account(chat_control.account)),
                queryNS="http://jabber.org/protocol/disco#items"
            )
            iq.setID(id_)
            def query_info(stanza):
                global last_info_query
                for item in stanza.getTag("query").getTags("item"):
                    id_ = gajim.get_an_id()
                    iq = nbxmpp.Iq(
                        typ='get',
                        to=item.getAttr("jid"),
                        queryNS="http://jabber.org/protocol/disco#info"
                    )
                    iq.setID(id_)
                    last_info_query[chat_control.account] = time.time()
                    gajim.connections[chat_control.account].connection.send(iq)
            iq_ids_to_callbacks[str(id_)] = query_info
            gajim.connections[chat_control.account].connection.send(iq)
            #send disco query to main server jid
            id_ = gajim.get_an_id()
            iq = nbxmpp.Iq(
                typ='get',
                to=gajim.get_server_from_jid(gajim.get_jid_from_account(chat_control.account)),
                queryNS="http://jabber.org/protocol/disco#info"
            )
            iq.setID(id_)
            last_info_query[chat_control.account] = time.time()
            gajim.connections[chat_control.account].connection.send(iq)

        for base in self.controls:
            if base.chat_control == chat_control:
                is_supported = gajim.get_jid_from_account(chat_control.account) in jid_to_servers and \
                    gajim.connections[chat_control.account].connection != None
                log.info("Account %s: httpupload is_supported: %s" % (str(chat_control.account), str(is_supported)))
                if not is_supported:
                    text = _('Your server does not support http uploads')
                    image_text = text
                else:
                    text = _('Send file via http upload')
                    image_text = _('Send image via http upload')
                base.button.set_sensitive(is_supported)
                base.button.set_tooltip_text(text)
                base.image_button.set_sensitive(is_supported)
                base.image_button.set_tooltip_text(image_text)
Esempio n. 32
0
    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')
        show_roster_menuitem = self.xml.get_object('show_roster_menuitem')

        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

        sub_menu = gtk.Menu()
        self.popup_menus.append(sub_menu)
        status_menuitem.set_submenu(sub_menu)

        gc_sub_menu = gtk.Menu() # gc is always a submenu
        join_gc_menuitem.set_submenu(gc_sub_menu)

        # We need our own set of status icons, let's make 'em!
        iconset = gajim.config.get('iconset')
        path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
        state_images = gtkgui_helpers.load_iconset(path)

        if 'muc_active' in state_images:
            join_gc_menuitem.set_image(state_images['muc_active'])

        for show in ('online', 'chat', 'away', 'xa', 'dnd', 'invisible'):
            uf_show = helpers.get_uf_show(show, use_mnemonic = True)
            item = gtk.ImageMenuItem(uf_show)
            item.set_image(state_images[show])
            sub_menu.append(item)
            item.connect('activate', self.on_show_menuitem_activate, show)

        item = gtk.SeparatorMenuItem()
        sub_menu.append(item)

        item = gtk.ImageMenuItem(_('_Change Status Message...'))
        gtkgui_helpers.add_image_to_menuitem(item, 'gajim-kbd_input')
        sub_menu.append(item)
        item.connect('activate', self.on_change_status_message_activate)

        connected_accounts = gajim.get_number_of_connected_accounts()
        if connected_accounts < 1:
            item.set_sensitive(False)

        connected_accounts_with_private_storage = 0

        item = gtk.SeparatorMenuItem()
        sub_menu.append(item)

        uf_show = helpers.get_uf_show('offline', use_mnemonic = True)
        item = gtk.ImageMenuItem(uf_show)
        item.set_image(state_images['offline'])
        sub_menu.append(item)
        item.connect('activate', self.on_show_menuitem_activate, 'offline')

        iskey = connected_accounts > 0 and not (connected_accounts == 1 and
            gajim.zeroconf_is_connected())
        chat_with_menuitem.set_sensitive(iskey)
        single_message_menuitem.set_sensitive(iskey)
        join_gc_menuitem.set_sensitive(iskey)

        accounts_list = sorted(gajim.contacts.get_accounts())
        # items that get shown whether an account is zeroconf or not
        if connected_accounts > 1: # 2 or more connections? make submenus
            account_menu_for_chat_with = gtk.Menu()
            chat_with_menuitem.set_submenu(account_menu_for_chat_with)
            self.popup_menus.append(account_menu_for_chat_with)

            for account in accounts_list:
                if gajim.account_is_connected(account):
                    # for chat_with
                    item = gtk.MenuItem(_('using account %s') % account)
                    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'
            for account in gajim.connections:
                if gajim.connections[account].connected > 1:
                    # 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 \
        gajim.zeroconf_is_connected()):
            # only one 'real' (non-zeroconf) account is connected, don't need
            # submenus
            for account in gajim.connections:
                if gajim.account_is_connected(account) and \
                not gajim.config.get_per('accounts', account, 'is_zeroconf'):
                    if gajim.connections[account].private_storage_supported:
                        connected_accounts_with_private_storage += 1

                    # for single message
                    single_message_menuitem.remove_submenu()
                    self.single_message_handler_id = single_message_menuitem.\
                            connect('activate',
                            self.on_single_message_menuitem_activate, account)
                    # join gc
                    gajim.interface.roster.add_bookmarks_list(gc_sub_menu,
                            account)
                    break # No other account connected
        else:
            # 2 or more 'real' accounts are connected, make submenus
            account_menu_for_single_message = gtk.Menu()
            single_message_menuitem.set_submenu(
                    account_menu_for_single_message)
            self.popup_menus.append(account_menu_for_single_message)

            for account in accounts_list:
                if gajim.connections[account].is_zeroconf or \
                not gajim.account_is_connected(account):
                    continue
                if gajim.connections[account].private_storage_supported:
                    connected_accounts_with_private_storage += 1
                # for single message
                item = gtk.MenuItem(_('using account %s') % account)
                item.connect('activate',
                        self.on_single_message_menuitem_activate, account)
                account_menu_for_single_message.append(item)

                # join gc
                gc_item = gtk.MenuItem(_('using account %s') % account, False)
                gc_sub_menu.append(gc_item)
                gc_menuitem_menu = gtk.Menu()
                gajim.interface.roster.add_bookmarks_list(gc_menuitem_menu,
                        account)
                gc_item.set_submenu(gc_menuitem_menu)
                gc_sub_menu.show_all()

        newitem = gtk.SeparatorMenuItem() # separator
        gc_sub_menu.append(newitem)
        newitem = gtk.ImageMenuItem(_('_Manage Bookmarks...'))
        img = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU)
        newitem.set_image(img)
        newitem.connect('activate',
                gajim.interface.roster.on_manage_bookmarks_menuitem_activate)
        gc_sub_menu.append(newitem)
        if connected_accounts_with_private_storage == 0:
            newitem.set_sensitive(False)

        sounds_mute_menuitem.set_active(not gajim.config.get('sounds_on'))

        win = gajim.interface.roster.window
        if self.show_roster_handler_id:
            show_roster_menuitem.handler_disconnect(self.show_roster_handler_id)
        if win.get_property('has-toplevel-focus'):
            show_roster_menuitem.get_children()[0].set_label(_('Hide _Roster'))
            self.show_roster_handler_id = show_roster_menuitem.connect(
                'activate', self.on_hide_roster_menuitem_activate)
        else:
            show_roster_menuitem.get_children()[0].set_label(_('Show _Roster'))
            self.show_roster_handler_id = show_roster_menuitem.connect(
                'activate', self.on_show_roster_menuitem_activate)

        if os.name == 'nt':
            if self.added_hide_menuitem is False:
                self.systray_context_menu.prepend(gtk.SeparatorMenuItem())
                item = gtk.MenuItem(_('Hide this menu'))
                self.systray_context_menu.prepend(item)
                self.added_hide_menuitem = True

        self.systray_context_menu.show_all()
        self.systray_context_menu.popup(None, None, None, 0,
                event_time)
Esempio n. 33
0
    def populate(self, contacts, account, typ):
        """
        Populate the Tooltip Grid with data of from the contact
        """
        self.current_row = 0
        self.account = account
        if self.last_widget:
            self.last_widget.set_vexpand(False)

        self.clear_tooltip()

        if account == 'all':
            # Tooltip for merged accounts row
            accounts = helpers.get_notification_icon_tooltip_dict()
            self.spacer_label = ''
            self.fill_table_with_accounts(accounts)
            self.tooltip_grid.attach(self.table, 0, 3, 2, 1)
            self.table.show_all()
            return

        if typ == 'account':
            jid = gajim.get_jid_from_account(account)
            contacts = []
            connection = gajim.connections[account]
            # get our current contact info

            nbr_on, nbr_total = gajim.\
                contacts.get_nb_online_total_contacts(
                accounts=[account])
            account_name = account
            if gajim.account_is_connected(account):
                account_name += ' (%s/%s)' % (repr(nbr_on),
                    repr(nbr_total))
            contact = gajim.contacts.create_self_contact(jid=jid,
                account=account, name=account_name,
                show=connection.get_status(), status=connection.status,
                resource=connection.server_resource,
                priority=connection.priority)
            if gajim.connections[account].gpg:
                contact.keyID = gajim.config.get_per('accounts',
                    connection.name, 'keyid')
            contacts.append(contact)
            # if we're online ...
            if connection.connection:
                roster = connection.connection.getRoster()
                # in threadless connection when no roster stanza is sent
                # 'roster' is None
                if roster and roster.getItem(jid):
                    resources = roster.getResources(jid)
                    # ...get the contact info for our other online
                    # resources
                    for resource in resources:
                        # Check if we already have this resource
                        found = False
                        for contact_ in contacts:
                            if contact_.resource == resource:
                                found = True
                                break
                        if found:
                            continue
                        show = roster.getShow(jid + '/' + resource)
                        if not show:
                            show = 'online'
                        contact = gajim.contacts.create_self_contact(
                            jid=jid, account=account, show=show,
                            status=roster.getStatus(
                            jid + '/' + resource),
                            priority=roster.getPriority(
                            jid + '/' + resource), resource=resource)
                        contacts.append(contact)

        # Username/Account/Groupchat
        self.prim_contact = gajim.contacts.get_highest_prio_contact_from_contacts(
            contacts)
        self.contact_jid = self.prim_contact.jid
        name = GLib.markup_escape_text(self.prim_contact.get_shown_name())
        name_markup = '<b>{}</b>'.format(name)
        if gajim.config.get('mergeaccounts'):
            color = gajim.config.get('tooltip_account_name_color')
            account_name = GLib.markup_escape_text(self.prim_contact.account.name)
            name_markup += " <span foreground='{}'>({})</span>".format(
                color, account_name)

        if account and helpers.jid_is_blocked(account, self.prim_contact.jid):
            name_markup += _(' [blocked]')

        try:
            if self.prim_contact.jid in gajim.interface.minimized_controls[account]:
                name_markup += _(' [minimized]')
        except KeyError:
            pass

        self.name.set_markup(name_markup)
        self.name.show()

        self.num_resources = 0
        # put contacts in dict, where key is priority
        contacts_dict = {}
        for contact in contacts:
            if contact.resource:
                self.num_resources += 1
                priority = int(contact.priority)
                if priority in contacts_dict:
                    contacts_dict[priority].append(contact)
                else:
                    contacts_dict[priority] = [contact]
        if self.num_resources > 1:
            self.status_label.show()
            transport = gajim.get_transport_name_from_jid(self.prim_contact.jid)
            if transport:
                file_path = os.path.join(helpers.get_transport_path(transport),
                    '16x16')
            else:
                iconset = gajim.config.get('iconset')
                if not iconset:
                    iconset = 'dcraven'
                file_path = os.path.join(helpers.get_iconset_path(iconset),
                    '16x16')

            contact_keys = sorted(contacts_dict.keys())
            contact_keys.reverse()
            for priority in contact_keys:
                for acontact in contacts_dict[priority]:
                    icon_name = self._get_icon_name_for_tooltip(acontact)
                    if acontact.status and len(acontact.status) > 25:
                        status = ''
                        add_text = True
                    else:
                        status = acontact.status
                        add_text = False

                    status_line = self.get_status_info(acontact.resource,
                    acontact.priority, acontact.show, status)
                    self.add_status_row(file_path, icon_name, status_line,
                        acontact.last_status_time)
                    if add_text:
                        self.add_text_row(acontact.status, 2)

            self.tooltip_grid.attach(self.table, 0, 3, 2, 1)
            self.table.show_all()

        else:  # only one resource
            if contact.show:
                request_time = False
                try:
                    last_time = self.check_last_time[contact]
                    if isinstance(last_time, float) and last_time < time.time() - 60:
                        request_time = True
                except KeyError:
                    request_time = True

                if request_time:
                    if contact.show == 'offline':
                        gajim.connections[account].\
                            request_last_status_time(contact.jid, '')
                    elif contact.resource:
                        gajim.connections[account].\
                            request_last_status_time(
                            contact.jid, contact.resource)
                    self.check_last_time[contact] = time.time()

                if contact.status:
                    status = contact.status.strip()
                    if status:
                        self.status.set_text(status)
                        self.status.show()
                        self.status_label.show()

        # PEP Info
        self._append_pep_info(contact)

        # JID
        self.jid.set_text(self.prim_contact.jid)
        self.jid.show()
        self.jid_label.show()

        # contact has only one ressource
        if self.num_resources == 1 and contact.resource:
            res = GLib.markup_escape_text(contact.resource)
            prio = str(contact.priority)
            self.resource.set_text("{} ({})".format(res, prio))
            self.resource.show()
            self.resource_label.show()

        if self.prim_contact.jid not in gajim.gc_connected[account]:
            if (account and
                self.prim_contact.sub and
                    self.prim_contact.sub != 'both'):
                # ('both' is the normal sub so we don't show it)
                self.sub.set_text(helpers.get_uf_sub(self.prim_contact.sub))
                self.sub.show()
                self.sub_label.show()

        if self.prim_contact.keyID:
            keyID = None
            if len(self.prim_contact.keyID) == 8:
                keyID = self.prim_contact.keyID
            elif len(self.prim_contact.keyID) == 16:
                keyID = self.prim_contact.keyID[8:]
            if keyID:
                self.pgp.set_text(keyID)
                self.pgp.show()
                self.pgp_label.show()

        self._set_idle_time(contact)

        # Avatar
        puny_jid = helpers.sanitize_filename(self.prim_contact.jid)
        file_ = helpers.get_avatar_path(os.path.join(gajim.AVATAR_PATH,
            puny_jid))
        if file_:
            with open(file_, 'rb') as file_data:
                pix = gtkgui_helpers.get_pixbuf_from_data(file_data.read())
            pix = gtkgui_helpers.get_scaled_pixbuf(pix, 'tooltip')
            self.avatar.set_from_pixbuf(pix)
            self.avatar.show()

            # Sets the Widget that is at the bottom to expand.
            # This is needed in case the Picture takes more Space then the Labels
            i = 1
            while i < 15:
                if self.tooltip_grid.get_child_at(0, i):
                    if self.tooltip_grid.get_child_at(0, i).get_visible():
                        self.last_widget = self.tooltip_grid.get_child_at(0, i)
                i += 1
            self.last_widget.set_vexpand(True)