示例#1
0
文件: bookmarks.py 项目: bj-h/gajim
    def __init__(self):
        self._ui = get_builder('manage_bookmarks_window.ui')
        self._ui.manage_bookmarks_window.set_transient_for(
            app.interface.roster.window)

        self.ignore_events = False

        # Account-JID, RoomName, Room-JID, Autojoin, Password, Nick, Name
        self.treestore = Gtk.TreeStore(str, str, str, bool, str, str, str)
        self.treestore.set_sort_column_id(1, Gtk.SortType.ASCENDING)

        # Store bookmarks in treeview.
        for account, account_label in app.get_enabled_accounts_with_labels(
                connected_only=True, private_storage_only=True):
            iter_ = self.treestore.append(None, [
                None, account, None, None,
                None, None, account_label])

            con = app.connections[account]
            bookmarks = con.get_module('Bookmarks').get_sorted_bookmarks()

            for bookmark in bookmarks:
                self.treestore.append(iter_, [account,
                                              bookmark.name,
                                              str(bookmark.jid),
                                              bookmark.autojoin,
                                              bookmark.password,
                                              bookmark.nick,
                                              bookmark.name])

        self._ui.bookmarks_treeview.set_model(self.treestore)
        self._ui.bookmarks_treeview.expand_all()

        renderer = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('Bookmarks', renderer, text=Row.LABEL)
        self._ui.bookmarks_treeview.append_column(column)

        self.selection = self._ui.bookmarks_treeview.get_selection()
        self.selection.connect('changed', self.bookmark_selected)

        # Prepare input fields
        self._ui.title_entry.connect('changed', self.on_title_entry_changed)
        self._ui.nick_entry.connect('changed', self.on_nick_entry_changed)
        self._ui.server_entry.connect(
            'focus-out-event', self.on_server_entry_focus_out)
        self.room_entry_changed_id = self._ui.room_entry.connect(
            'changed', self.on_room_entry_changed)
        self._ui.pass_entry.connect('changed', self.on_pass_entry_changed)

        self._ui.connect_signals(self)
        self._ui.manage_bookmarks_window.show_all()
        # select root iter
        first_iter = self.treestore.get_iter_first()
        if first_iter:
            self.selection.select_iter(first_iter)
示例#2
0
    def __init__(self):
        Gtk.ApplicationWindow.__init__(self)
        self.set_name('StartChatDialog')
        self.set_application(app.app)
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_show_menubar(False)
        self.set_title(_('Start New Conversation'))
        self.set_default_size(-1, 400)
        self.ready_to_destroy = False
        self._parameter_form = None
        self._keywords = []
        self._destroyed = False
        self._search_stopped = False
        self._redirected = False

        self._ui = get_builder('start_chat_dialog.ui')
        self.add(self._ui.stack)

        self.new_contact_row_visible = False
        self.new_contact_rows = {}
        self.new_groupchat_rows = {}
        self._accounts = app.get_enabled_accounts_with_labels()
        self._add_accounts()
        self._add_contacts()
        self._add_groupchats()

        self._ui.search_entry.connect('search-changed',
                                      self._on_search_changed)
        self._ui.search_entry.connect('next-match', self._select_new_match,
                                      'next')
        self._ui.search_entry.connect('previous-match', self._select_new_match,
                                      'prev')
        self._ui.search_entry.connect(
            'stop-search', lambda *args: self._ui.search_entry.set_text(''))

        self._ui.listbox.set_filter_func(self._filter_func, None)
        self._ui.listbox.set_sort_func(self._sort_func, None)
        self._ui.listbox.connect('row-activated', self._on_row_activated)

        self._global_search_listbox = GlobalSearch()
        self._global_search_listbox.connect('row-activated',
                                            self._on_row_activated)
        self._current_listbox = self._ui.listbox

        self._muc_info_box = GroupChatInfoScrolled()
        self._ui.info_box.add(self._muc_info_box)

        self.connect('key-press-event', self._on_key_press)
        self.connect('destroy', self._destroy)

        self.select_first_row()
        self._ui.connect_signals(self)
        self.show_all()
示例#3
0
    def _fill_account_combo(self, account):
        accounts = app.get_enabled_accounts_with_labels(connected_only=True)
        account_liststore = self._ui.account_combo.get_model()
        for acc in accounts:
            account_liststore.append(acc)

        # Hide account combobox if there is only one account
        if len(accounts) == 1:
            self._ui.account_combo.hide()
            self._ui.account_label.hide()

        if account is None:
            account = accounts[0][0]

        self._ui.account_combo.set_active_id(account)
        return account
示例#4
0
文件: add_contact.py 项目: bj-h/gajim
    def __init__(self, account=None, jid=None, user_nick=None, group=None):
        Gtk.ApplicationWindow.__init__(self)
        self.set_application(app.app)
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_show_menubar(False)
        self.set_resizable(False)
        self.set_title(_('Add Contact'))

        self.connect('destroy', self._on_destroy)
        self.connect('key-press-event', self._on_key_press)

        self.account = account
        self.adding_jid = False

        # fill accounts with active accounts
        accounts = app.get_enabled_accounts_with_labels()

        if not accounts:
            return

        if not account:
            self.account = accounts[0][0]

        self.xml = get_builder('add_new_contact_window.ui')
        self.add(self.xml.get_object('add_contact_box'))
        self.xml.connect_signals(self)

        for w in ('account_combobox', 'account_label', 'prompt_label',
                  'uid_label', 'uid_entry', 'show_contact_info_button',
                  'protocol_combobox', 'protocol_jid_combobox',
                  'protocol_label', 'nickname_entry', 'message_scrolledwindow',
                  'save_message_checkbutton', 'register_hbox', 'add_button',
                  'message_textview', 'connected_label', 'group_comboboxentry',
                  'auto_authorize_checkbutton', 'save_message_revealer',
                  'nickname_label', 'group_label'):
            self.__dict__[w] = self.xml.get_object(w)

        self.subscription_table = [
            self.uid_label, self.uid_entry, self.show_contact_info_button,
            self.nickname_label, self.nickname_entry, self.group_label,
            self.group_comboboxentry
        ]

        self.add_button.grab_default()

        self.agents = {'jabber': []}
        self.gateway_prompt = {}
        # types to which we are not subscribed but account has an agent for it
        self.available_types = []
        for acct in accounts:
            for j in app.contacts.get_jid_list(acct[0]):
                if app.jid_is_transport(j):
                    type_ = app.get_transport_name_from_jid(j, False)
                    if not type_:
                        continue
                    if type_ in self.agents:
                        self.agents[type_].append(j)
                    else:
                        self.agents[type_] = [j]
                    self.gateway_prompt[j] = {'desc': None, 'prompt': None}
        # Now add the one to which we can register
        for acct in accounts:
            for type_ in app.connections[acct[0]].available_transports:
                if type_ in self.agents:
                    continue
                self.agents[type_] = []
                for jid_ in app.connections[
                        acct[0]].available_transports[type_]:
                    if jid_ not in self.agents[type_]:
                        self.agents[type_].append(jid_)
                        self.gateway_prompt[jid_] = {
                            'desc': None,
                            'prompt': None
                        }
                self.available_types.append(type_)

        uf_type = {'jabber': 'XMPP', 'gadu-gadu': 'Gadu Gadu', 'icq': 'ICQ'}
        # Jabber as first
        liststore = self.protocol_combobox.get_model()
        liststore.append(['XMPP', 'xmpp', 'jabber'])
        for type_ in self.agents:
            if type_ == 'jabber':
                continue
            if type_ in uf_type:
                liststore.append([uf_type[type_], type_ + '-online', type_])
            else:
                liststore.append([type_, type_ + '-online', type_])

            if account:
                for service in self.agents[type_]:
                    con = app.connections[account]
                    con.get_module('Gateway').request_gateway_prompt(service)
        self.protocol_combobox.set_active(0)
        self.auto_authorize_checkbutton.show()

        if jid:
            self.jid_escaped = True
            type_ = app.get_transport_name_from_jid(jid)
            if not type_:
                type_ = 'jabber'
            if type_ == 'jabber':
                self.uid_entry.set_text(jid)
                transport = None
            else:
                uid, transport = app.get_name_and_server_from_jid(jid)
                self.uid_entry.set_text(uid.replace('%', '@', 1))
            # set protocol_combobox
            model = self.protocol_combobox.get_model()
            iter_ = model.get_iter_first()
            i = 0
            while iter_:
                if model[iter_][2] == type_:
                    self.protocol_combobox.set_active(i)
                    break
                iter_ = model.iter_next(iter_)
                i += 1

            # set protocol_jid_combobox
            self.protocol_jid_combobox.set_active(0)
            model = self.protocol_jid_combobox.get_model()
            iter_ = model.get_iter_first()
            i = 0
            while iter_:
                if model[iter_][0] == transport:
                    self.protocol_jid_combobox.set_active(i)
                    break
                iter_ = model.iter_next(iter_)
                i += 1
            if user_nick:
                self.nickname_entry.set_text(user_nick)
            self.nickname_entry.grab_focus()
        else:
            self.jid_escaped = False
            self.uid_entry.grab_focus()
        group_names = []
        for acct in accounts:
            for g in app.groups[acct[0]].keys():
                if g not in helpers.special_groups and g not in group_names:
                    group_names.append(g)
        group_names.sort()
        i = 0
        for g in group_names:
            self.group_comboboxentry.append_text(g)
            if group == g:
                self.group_comboboxentry.set_active(i)
            i += 1

        if len(accounts) > 1:
            liststore = self.account_combobox.get_model()
            for acc in accounts:
                liststore.append(acc)

            self.account_combobox.set_active_id(self.account)
            self.account_label.show()
            self.account_combobox.show()

        if len(self.agents) > 1:
            self.protocol_label.show()
            self.protocol_combobox.show()

        if self.account:
            message_buffer = self.message_textview.get_buffer()
            msg = helpers.from_one_line(
                helpers.get_subscription_request_msg(self.account))
            message_buffer.set_text(msg)

        self.uid_entry.connect('changed', self.on_uid_entry_changed)
        self.show_all()

        app.ged.register_event_handler('gateway-prompt-received', ged.GUI1,
                                       self._nec_gateway_prompt_received)
        app.ged.register_event_handler('presence-received', ged.GUI1,
                                       self._nec_presence_received)
示例#5
0
    def __init__(self):
        Gtk.ApplicationWindow.__init__(self)
        self.set_name('StartChatDialog')
        self.set_application(app.app)
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_show_menubar(False)
        self.set_title(_('Start / Join Chat'))
        self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
        self.set_default_size(-1, 600)
        self.ready_to_destroy = False
        self._parameter_form = None
        self._keywords = []
        self._destroyed = False
        self._search_stopped = False
        self._redirected = False
        self._source_id = None

        self._ui = get_builder('start_chat_dialog.ui')
        self.add(self._ui.stack)

        self._nick_chooser = NickChooser()
        self._ui.join_box.pack_start(self._nick_chooser, True, False, 0)

        self.new_contact_row_visible = False
        self.new_contact_rows = {}
        self.new_groupchat_rows = {}
        self._accounts = app.get_enabled_accounts_with_labels()

        rows = []
        self._add_accounts()
        self._add_contacts(rows)
        self._add_groupchats(rows)

        self._ui.search_entry.connect('search-changed',
                                      self._on_search_changed)
        self._ui.search_entry.connect('next-match', self._select_new_match,
                                      'next')
        self._ui.search_entry.connect('previous-match', self._select_new_match,
                                      'prev')
        self._ui.search_entry.connect(
            'stop-search', lambda *args: self._ui.search_entry.set_text(''))

        self._ui.listbox.set_placeholder(self._ui.placeholder)
        self._ui.listbox.set_filter_func(self._filter_func, None)
        self._ui.listbox.connect('row-activated', self._on_row_activated)

        self._global_search_listbox = GlobalSearch()
        self._global_search_listbox.connect('row-activated',
                                            self._on_row_activated)
        self._current_listbox = self._ui.listbox

        self._muc_info_box = GroupChatInfoScrolled()
        self._ui.info_box.add(self._muc_info_box)

        self._ui.infobar.set_revealed(app.settings.get('show_help_start_chat'))

        self.connect('key-press-event', self._on_key_press)
        self.connect('destroy', self._destroy)

        self.select_first_row()
        self._ui.connect_signals(self)
        self.show_all()

        if rows:
            self._load_contacts(rows)
示例#6
0
    def __init__(self,
                 account,
                 room_jid,
                 password=None,
                 automatic=None,
                 transient_for=None):
        Gtk.ApplicationWindow.__init__(self)
        self.set_name('JoinGroupchat')
        self.set_application(app.app)
        self.set_show_menubar(False)
        self.set_resizable(False)
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_title(_('Join Group Chat'))
        if transient_for:
            self.set_transient_for(transient_for)

        self.automatic = automatic
        self.password = password
        self.requested_jid = None
        self.room_jid = room_jid
        self.account = account

        if self.room_jid is None:
            self.minimal_mode = False
        else:
            self.minimal_mode = True

        glade_objects = [
            'main_box', 'account_label', 'account_combo', 'server_label',
            'server_combo', 'room_entry', 'recently_button',
            'recently_popover', 'recently_treeview', 'search_button',
            'password_label', 'password_entry', 'nick_entry',
            'bookmark_switch', 'autojoin_switch'
        ]

        self.builder = get_builder('join_groupchat_window.ui')
        for obj in glade_objects:
            setattr(self, obj, self.builder.get_object(obj))

        self.add(self.main_box)

        # Show widgets depending on the mode the window is in
        if not self.minimal_mode:
            self.recently_button.show()
            self.search_button.show()

        accounts = app.get_enabled_accounts_with_labels()
        account_liststore = self.account_combo.get_model()
        for acc in accounts:
            account_liststore.append(acc)

        if not accounts:
            return

        if not self.account:
            self.account = accounts[0][0]

        self.builder.connect_signals(self)
        self.connect('key-press-event', self._on_key_press_event)

        # Hide account combobox if there is only one account
        if len(accounts) == 1:
            self.account_combo.hide()
            self.account_label.hide()

        self.account_combo.set_active_id(self.account)

        if self.minimal_mode:
            if '@' in self.room_jid:
                (room, server) = self.room_jid.split('@')
                self.room_entry.set_text(room)
                if not muc_caps_cache.supports(self.room_jid,
                                               'muc_passwordprotected'):
                    self.password_entry.hide()
                    self.password_label.hide()
                    self.nick_entry.grab_focus()
                else:
                    self.password_entry.grab_focus()
            else:
                server = self.room_jid
                self.room_entry.grab_focus()

            self.server_combo.insert_text(0, server)
            self.server_combo.set_active(0)

        if self.password is not None:
            self.password_entry.set_text(self.password)

        # Set bookmark switch sensitive if server supports bookmarks
        acc = self.account_combo.get_active_id()

        self.show_all()
示例#7
0
    def __init__(self):
        self.xml = get_builder('manage_bookmarks_window.ui')
        self.window = self.xml.get_object('manage_bookmarks_window')
        self.window.set_transient_for(app.interface.roster.window)

        self.ignore_events = False

        # Account-JID, RoomName, Room-JID, Autojoin, Minimize, Password, Nick,
        # Show_Status
        self.treestore = Gtk.TreeStore(str, str, str, bool, bool, str, str,
                                       str, str)
        self.treestore.set_sort_column_id(1, Gtk.SortType.ASCENDING)

        # Store bookmarks in treeview.
        for account, account_label in app.get_enabled_accounts_with_labels(
                connected_only=True, private_storage_only=True):
            iter_ = self.treestore.append(None, [
                None, account, None, None, None, None, None, None,
                account_label
            ])

            con = app.connections[account]
            bookmarks = con.get_module('Bookmarks').bookmarks
            for jid, bookmark in bookmarks.items():
                if not bookmark['name']:
                    # No name was given for this bookmark.
                    # Use the first part of JID instead...
                    name = jid.split("@")[0]
                    bookmark['name'] = name

                # make '1', '0', 'true', 'false' (or other) to True/False
                autojoin = helpers.from_xs_boolean_to_python_boolean(
                    bookmark['autojoin'])

                minimize = helpers.from_xs_boolean_to_python_boolean(
                    bookmark['minimize'])

                print_status = bookmark.get('print_status', '')
                if print_status not in ('', 'all', 'in_and_out', 'none'):
                    print_status = ''
                self.treestore.append(iter_, [
                    account, bookmark['name'], jid, autojoin, minimize,
                    bookmark['password'], bookmark['nick'], print_status,
                    bookmark['name']
                ])

        self.print_status_combobox = self.xml.get_object(
            'print_status_combobox')
        model = Gtk.ListStore(str, str)

        self.option_list = {
            '': _('Default'),
            'all': Q_('?print_status:All'),
            'in_and_out': _('Enter and leave only'),
            'none': Q_('?print_status:None')
        }
        for opt, label in sorted(self.option_list.items()):
            model.append([label, opt])

        self.print_status_combobox.set_model(model)
        self.print_status_combobox.set_active(1)

        self.view = self.xml.get_object('bookmarks_treeview')
        self.view.set_model(self.treestore)
        self.view.expand_all()

        renderer = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('Bookmarks', renderer, text=8)
        self.view.append_column(column)

        self.selection = self.view.get_selection()
        self.selection.connect('changed', self.bookmark_selected)

        # Prepare input fields
        self.title_entry = self.xml.get_object('title_entry')
        self.title_entry.connect('changed', self.on_title_entry_changed)
        self.nick_entry = self.xml.get_object('nick_entry')
        self.nick_entry.connect('changed', self.on_nick_entry_changed)
        self.server_entry = self.xml.get_object('server_entry')
        self.server_entry.connect('focus-out-event',
                                  self.on_server_entry_focus_out)
        self.room_entry = self.xml.get_object('room_entry')
        self.room_entry_changed_id = self.room_entry.connect(
            'changed', self.on_room_entry_changed)
        self.pass_entry = self.xml.get_object('pass_entry')
        self.pass_entry.connect('changed', self.on_pass_entry_changed)
        self.autojoin_checkbutton = self.xml.get_object('autojoin_checkbutton')
        self.minimize_checkbutton = self.xml.get_object('minimize_checkbutton')
        self.settings_box = self.xml.get_object('settings_box')
        self.remove_bookmark_button = self.xml.get_object(
            'remove_bookmark_button')

        self.xml.connect_signals(self)
        self.window.show_all()
        # select root iter
        first_iter = self.treestore.get_iter_first()
        if first_iter:
            self.selection.select_iter(first_iter)
示例#8
0
    def __init__(self, account, event):
        Gtk.ApplicationWindow.__init__(self)
        self.set_name('GroupChatInvitation')
        self.set_application(app.app)
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_show_menubar(False)
        self.set_title(_('Group Chat Invitation'))
        self.set_type_hint(Gdk.WindowTypeHint.DIALOG)

        self.account = account
        self._room_jid = str(event.muc)
        self._from = str(event.from_)
        self._password = event.password

        main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        main_box.set_valign(Gtk.Align.FILL)
        main_box.get_style_context().add_class('padding-18')

        muc_info_box = GroupChatInfoScrolled(account, {'minimal': True})
        muc_info_box.set_from_disco_info(event.info)

        main_box.add(muc_info_box)

        separator = Gtk.Separator()
        contact_label = Gtk.Label(label=event.get_inviter_name())
        contact_label.get_style_context().add_class('bold16')
        contact_label.set_line_wrap(True)
        contact_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
                              spacing=6)
        contact_box.set_halign(Gtk.Align.CENTER)
        contact_box.add(contact_label)

        enabled_accounts = app.get_enabled_accounts_with_labels()
        if len(enabled_accounts) > 1:
            account_badge = generate_account_badge(account)
            account_badge.set_tooltip_text(
                _('Account: %s') % app.get_account_label(account))
            contact_box.add(account_badge)

        invitation_label = Gtk.Label(
            label=_('has invited you to a group chat.\nDo you want to join?'))
        invitation_label.set_halign(Gtk.Align.CENTER)
        invitation_label.set_justify(Gtk.Justification.CENTER)
        invitation_label.set_max_width_chars(50)
        invitation_label.set_line_wrap(True)

        main_box.add(separator)
        main_box.add(contact_box)
        main_box.add(invitation_label)

        decline_button = Gtk.Button.new_with_mnemonic(_('_Decline'))
        decline_button.set_halign(Gtk.Align.START)
        decline_button.connect('clicked', self._on_decline)

        self._nick_chooser = NickChooser()
        self._nick_chooser.set_text(
            get_group_chat_nick(self.account, event.info.jid))

        join_button = Gtk.Button.new_with_mnemonic(_('_Join'))
        join_button.set_halign(Gtk.Align.END)
        join_button.get_style_context().add_class('suggested-action')
        join_button.connect('clicked', self._on_join)

        join_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        join_box.get_style_context().add_class('linked')
        join_box.set_halign(Gtk.Align.END)
        join_box.add(self._nick_chooser)
        join_box.add(join_button)

        button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        button_box.set_margin_top(6)
        button_box.pack_start(decline_button, False, False, 0)
        button_box.pack_end(join_box, False, False, 0)

        main_box.add(button_box)

        self.connect('key-press-event', self._on_key_press_event)

        self.add(main_box)

        join_button.set_can_default(True)
        join_button.grab_focus()

        self.show_all()