def _fill_search_results_listview(self, text): """ Ask db and fill listview with results that match text """ self.search_results_liststore.clear() like_sql = '%' + text + '%' self.cur.execute(''' SELECT log_line_id, jid_id, time, message, subject, contact_name FROM logs WHERE message LIKE ? OR subject LIKE ? ORDER BY time ''', (like_sql, like_sql)) results = self.cur.fetchall() format_ = helpers.from_one_line(app.settings.get('time_stamp')) for row in results: # exposed in UI (TreeViewColumns) are only # JID, time, message, subject, nickname # but store in liststore # log_line_id, jid (from jid_id), time, message, subject, nickname log_line_id, jid_id, time_, message, subject, nickname = row try: time_ = time.strftime(format_, time.localtime(float(time_))) except ValueError: pass else: jid = self._get_jid_from_jid_id(jid_id) self.search_results_liststore.append((log_line_id, jid, time_, message, subject, nickname))
def _get_presets(self): self._presets = {} for preset_name in app.settings.get_status_presets(): preset = app.settings.get_status_preset_settings(preset_name) opts = list(preset.values()) opts[0] = from_one_line(opts[0]) self._presets[preset_name] = opts self._build_preset_popover()
def __init__(self, callback=None, account=None, status=None, show_pep=True): Gtk.ApplicationWindow.__init__(self) countdown_time = app.settings.get('change_status_window_timeout') TimeoutWindow.__init__(self, countdown_time) self.set_name('StatusChange') self.set_application(app.app) self.set_position(Gtk.WindowPosition.CENTER) self.set_default_size(400, 350) self.set_show_menubar(False) self.set_transient_for(app.interface.roster.window) self.title_text = _('Status Message') # TimeoutWindow self.account = account self._callback = callback self._status = status self._show_pep = show_pep self._ui = get_builder('status_change_window.ui') self.add(self._ui.status_stack) self._status_message = '' self._pep_dict = { 'activity': '', 'subactivity': '', 'mood': '', } self._get_current_status_data() self._presets = {} self._get_presets() if self._status: self._ui.activity_switch.set_active(self._pep_dict['activity']) self._ui.activity_page_button.set_sensitive( self._pep_dict['activity']) self._ui.mood_switch.set_active(self._pep_dict['mood']) self._ui.mood_page_button.set_sensitive(self._pep_dict['mood']) self._message_buffer = self._ui.message_textview.get_buffer() self._apply_speller() self._message_buffer.set_text(from_one_line(self._status_message)) self._activity_btns = {} self._mood_btns = {} if show_pep: self._init_activities() self._draw_activity() self._init_moods() self._draw_mood() else: self._ui.pep_grid.set_no_show_all(True) self._ui.pep_grid.hide() self._message_buffer.connect('changed', self.stop_timeout) self.connect('key-press-event', self._on_key_press) self._ui.connect_signals(self) self.show_all() self.start_timeout()
def fill_default_msg_treeview(self): model = self._ui.default_msg_treeview.get_model() model.clear() status = [] for status_ in app.config.get_per('defaultstatusmsg'): status.append(status_) status.sort() for status_ in status: msg = app.config.get_per('defaultstatusmsg', status_, 'message') msg = helpers.from_one_line(msg) enabled = app.config.get_per('defaultstatusmsg', status_, 'enabled') iter_ = model.append() uf_show = helpers.get_uf_show(status_) model.set(iter_, 0, status_, 1, uf_show, 2, msg, 3, enabled)
def fill_msg_treeview(self): self._ui.delete_msg_button.set_sensitive(False) model = self._ui.msg_treeview.get_model() model.clear() preset_status = [] for msg_name in app.config.get_per('statusmsg'): if msg_name.startswith('_last_'): continue preset_status.append(msg_name) preset_status.sort() for msg_name in preset_status: msg_text = app.config.get_per('statusmsg', msg_name, 'message') msg_text = helpers.from_one_line(msg_text) activity = app.config.get_per('statusmsg', msg_name, 'activity') subactivity = app.config.get_per('statusmsg', msg_name, 'subactivity') activity_text = app.config.get_per('statusmsg', msg_name, 'activity_text') mood = app.config.get_per('statusmsg', msg_name, 'mood') mood_text = app.config.get_per('statusmsg', msg_name, 'mood_text') iter_ = model.append() model.set(iter_, 0, msg_name, 1, msg_text, 2, activity, 3, subactivity, 4, activity_text, 5, mood, 6, mood_text)
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)
def _add_message(self, msg): if not msg.message and msg.kind not in (KindConstant.STATUS, KindConstant.GCSTATUS): return tim = msg.time kind = msg.kind show = msg.show message = msg.message subject = msg.subject log_line_id = msg.log_line_id contact_name = msg.contact_name additional_data = msg.additional_data buf = self.history_buffer end_iter = buf.get_end_iter() # Make the beginning of every message searchable by its log_line_id buf.create_mark(str(log_line_id), end_iter, left_gravity=True) if app.config.get('print_time') == 'always': timestamp_str = app.config.get('time_stamp') timestamp_str = helpers.from_one_line(timestamp_str) tim = time.strftime(timestamp_str, time.localtime(float(tim))) buf.insert(end_iter, tim) elif app.config.get('print_time') == 'sometimes': every_foo_seconds = 60 * app.config.get( 'print_ichat_every_foo_minutes') seconds_passed = tim - self.last_time_printout if seconds_passed > every_foo_seconds: self.last_time_printout = tim tim = time.strftime('%X ', time.localtime(float(tim))) buf.insert_with_tags_by_name( end_iter, tim + '\n', 'time_sometimes') # print the encryption icon if kind in (KindConstant.CHAT_MSG_SENT, KindConstant.CHAT_MSG_RECV): self.history_textview.print_encryption_status( end_iter, additional_data) tag_name = '' tag_msg = '' show = self._get_string_show_from_constant_int(show) if kind == KindConstant.GC_MSG: tag_name = 'incoming' elif kind in (KindConstant.SINGLE_MSG_RECV, KindConstant.CHAT_MSG_RECV): contact_name = self.completion_dict[self.jid][InfoColumn.NAME] tag_name = 'incoming' tag_msg = 'incomingtxt' elif kind in (KindConstant.SINGLE_MSG_SENT, KindConstant.CHAT_MSG_SENT): if self.account: contact_name = app.nicks[self.account] else: # we don't have roster, we don't know our own nick, use first # account one (urk!) account = list(app.contacts.get_accounts())[0] contact_name = app.nicks[account] tag_name = 'outgoing' tag_msg = 'outgoingtxt' elif kind == KindConstant.GCSTATUS: # message here (if not None) is status message if message: message = _('%(nick)s is now %(status)s: %(status_msg)s') % { 'nick': contact_name, 'status': helpers.get_uf_show(show), 'status_msg': message} else: message = _('%(nick)s is now %(status)s') % { 'nick': contact_name, 'status': helpers.get_uf_show(show)} tag_msg = 'status' else: # 'status' # message here (if not None) is status message if show is None: # it means error if message: message = _('Error: %s') % message else: message = _('Error') elif message: message = _('Status is now: %(status)s: %(status_msg)s') % { 'status': helpers.get_uf_show(show), 'status_msg': message} else: message = _('Status is now: %(status)s') % { 'status': helpers.get_uf_show(show)} tag_msg = 'status' if message.startswith('/me ') or message.startswith('/me\n'): tag_msg = tag_name else: # do not do this if gcstats, avoid dupping contact_name # eg. nkour: nkour is now Offline if contact_name and kind != KindConstant.GCSTATUS: # add stuff before and after contact name before_str = app.config.get('before_nickname') before_str = helpers.from_one_line(before_str) after_str = app.config.get('after_nickname') after_str = helpers.from_one_line(after_str) format_ = before_str + contact_name + after_str + ' ' if tag_name: buf.insert_with_tags_by_name(end_iter, format_, tag_name) else: buf.insert(end_iter, format_) if subject: message = _('Subject: %s\n') % subject + message xhtml = None if message.startswith('<body '): xhtml = message if tag_msg: self.history_textview.print_real_text( message, [tag_msg], name=contact_name, xhtml=xhtml, additional_data=additional_data) else: self.history_textview.print_real_text( message, name=contact_name, xhtml=xhtml, additional_data=additional_data) self.history_textview.print_real_text('\n', text_tags=['eol'])
def _fill_logs_listview(self, jid): """ Fill the listview with all messages that user sent to or received from JID """ # no need to lower jid in this context as jid is already lowered # as we use those jids from db jid_id = self._get_jid_id(jid) self.cur.execute(''' SELECT log_line_id, jid_id, time, kind, message, subject, contact_name, show FROM logs WHERE jid_id = ? ORDER BY time ''', (jid_id,)) results = self.cur.fetchall() if self._jid_is_room_type(jid): # is it room? self.nickname_col_for_logs.set_visible(True) self.subject_col_for_logs.set_visible(False) else: self.nickname_col_for_logs.set_visible(False) self.subject_col_for_logs.set_visible(True) format_ = helpers.from_one_line(app.settings.get('time_stamp')) for row in results: # exposed in UI (TreeViewColumns) are only # time, message, subject, nickname # but store in liststore # log_line_id, jid_id, time, message, subject, nickname log_line_id, jid_id, time_, kind, message, subject, nickname, \ show = row try: time_ = time.strftime(format_, time.localtime(float(time_))) except ValueError: pass else: color = None if kind in (KindConstant.SINGLE_MSG_RECV, KindConstant.CHAT_MSG_RECV, KindConstant.GC_MSG): color = app.css_config.get_value( '.gajim-incoming-nickname', StyleAttr.COLOR) elif kind in (KindConstant.SINGLE_MSG_SENT, KindConstant.CHAT_MSG_SENT): color = app.css_config.get_value( '.gajim-outgoing-nickname', StyleAttr.COLOR) elif kind in (KindConstant.STATUS, KindConstant.GCSTATUS): color = app.css_config.get_value( '.gajim-status-message', StyleAttr.COLOR) # include status into (status) message if message is None: message = '' else: message = ' : ' + message message = helpers.get_uf_show(ShowConstant(show)) + message message_ = '<span' if color: message_ += ' foreground="%s"' % convert_rgb_to_hex(color) message_ += '>%s</span>' % GLib.markup_escape_text(message) self.logs_liststore.append( (str(log_line_id), str(jid_id), time_, message_, subject, nickname))
def __init__(self, on_response, show=None, show_pep=True): countdown_time = app.config.get('change_status_window_timeout') TimeoutDialog.__init__(self, countdown_time) self.show = show self.pep_dict = {} self.show_pep = show_pep self.on_response = on_response self.xml = get_builder('change_status_message_dialog.ui') self.dialog = self.xml.get_object('change_status_message_dialog') self.dialog.set_transient_for(app.interface.roster.window) msg = None if show: uf_show = helpers.get_uf_show(show) self.title_text = _('%s Status Message') % uf_show msg = app.config.get_per('statusmsg', '_last_' + self.show, 'message') self.pep_dict['activity'] = app.config.get_per( 'statusmsg', '_last_' + self.show, 'activity') self.pep_dict['subactivity'] = app.config.get_per( 'statusmsg', '_last_' + self.show, 'subactivity') self.pep_dict['activity_text'] = app.config.get_per( 'statusmsg', '_last_' + self.show, 'activity_text') self.pep_dict['mood'] = app.config.get_per('statusmsg', '_last_' + self.show, 'mood') self.pep_dict['mood_text'] = app.config.get_per( 'statusmsg', '_last_' + self.show, 'mood_text') else: self.title_text = _('Status Message') self.dialog.set_title(self.title_text) message_textview = self.xml.get_object('message_textview') self.message_buffer = message_textview.get_buffer() if app.config.get('use_speller') and app.is_installed('GSPELL'): lang = app.config.get('speller_language') gspell_lang = Gspell.language_lookup(lang) if gspell_lang is None: AspellDictError(lang) else: spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer( self.message_buffer) spell_buffer.set_spell_checker(Gspell.Checker.new(gspell_lang)) spell_view = Gspell.TextView.get_from_gtk_text_view( message_textview) spell_view.set_inline_spell_checking(True) spell_view.set_enable_language_menu(True) self.message_buffer.connect('changed', self.on_message_buffer_changed) if not msg: msg = '' msg = helpers.from_one_line(msg) self.message_buffer.set_text(msg) # have an empty string selectable, so user can clear msg self.preset_messages_dict = {'': ['', '', '', '', '', '']} for msg_name in app.config.get_per('statusmsg'): if msg_name.startswith('_last_'): continue opts = [] for opt in [ 'message', 'activity', 'subactivity', 'activity_text', 'mood', 'mood_text' ]: opts.append(app.config.get_per('statusmsg', msg_name, opt)) opts[0] = helpers.from_one_line(opts[0]) self.preset_messages_dict[msg_name] = opts sorted_keys_list = helpers.get_sorted_keys(self.preset_messages_dict) self.message_liststore = Gtk.ListStore(str) # msg_name self.message_combobox = self.xml.get_object('message_combobox') self.message_combobox.set_model(self.message_liststore) cellrenderertext = Gtk.CellRendererText() self.message_combobox.pack_start(cellrenderertext, True) self.message_combobox.add_attribute(cellrenderertext, 'text', 0) for msg_name in sorted_keys_list: self.message_liststore.append((msg_name, )) if show_pep: self.draw_activity() self.draw_mood() else: # remove acvtivity / mood lines self.xml.get_object('activity_label').set_no_show_all(True) self.xml.get_object('activity_button').set_no_show_all(True) self.xml.get_object('mood_label').set_no_show_all(True) self.xml.get_object('mood_button').set_no_show_all(True) self.xml.get_object('activity_label').hide() self.xml.get_object('activity_button').hide() self.xml.get_object('mood_label').hide() self.xml.get_object('mood_button').hide() self.xml.connect_signals(self) self.run_timeout() self.dialog.connect('response', self.on_dialog_response) self.dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) self.dialog.show_all()