Commit f041f8dd authored by jimpp's avatar jimpp

JID->Jabber ID in gc tooltip

if print_time==sometimes : Show the day if needed also. Use locale for time format (do
not force
24h)
Delete a lot of unused locale variables (thanks pychecker)
del gajim.py useless global vars after use
configpaths.py : use self. not this.
parent 6ece819a
......@@ -1120,7 +1120,6 @@ class ChatControl(ChatControlBase):
self.reset_kbd_mouse_timeout_vars()
contact = self.contact
jid = self.contact.jid
keyID = ''
encrypted = False
......@@ -1189,7 +1188,6 @@ class ChatControl(ChatControlBase):
if yes we go active
if no we go inactive '''
contact = self.contact
jid = contact.jid
current_state = contact.our_chatstate
if current_state is False: # jid doesn't support chatstates
......@@ -1439,7 +1437,6 @@ class ChatControl(ChatControlBase):
# contact was from pm in MUC, and left the room so contact is None
# so we cannot send chatstate anymore
return
jid = contact.jid
# Don't send chatstates to offline contacts
if contact.show == 'offline':
......
......@@ -58,8 +58,6 @@ class OldEntry(xmpp.Node, object):
def get_feed_title(self):
''' Returns title of feed, where the entry was created. The result is the feed name
concatenated with source-feed title. '''
title = u''
if self.parent is not None:
main_feed = self.parent.getTagData('title')
else:
......
......@@ -26,11 +26,11 @@ def fse(s):
return unicode(s, sys.getfilesystemencoding())
class ConfigPaths:
def __init__(this, root=None):
this.root = root
this.paths = {}
def __init__(self, root=None):
self.root = root
self.paths = {}
if this.root is None:
if self.root is None:
if os.name == 'nt':
try:
# Documents and Settings\[User Name]\Application Data\Gajim
......@@ -38,35 +38,35 @@ class ConfigPaths:
# How are we supposed to know what encoding the environment
# variable 'appdata' is in? Assuming it to be in filesystem
# encoding.
this.root = os.path.join(fse(os.environ[u'appdata']), u'Gajim')
self.root = os.path.join(fse(os.environ[u'appdata']), u'Gajim')
except KeyError:
# win9x, in cwd
this.root = u''
self.root = u''
else: # Unices
# Pass in an Unicode string, and hopefully get one back.
this.root = os.path.expanduser(u'~/.gajim')
self.root = os.path.expanduser(u'~/.gajim')
def add_from_root(this, name, path):
this.paths[name] = (True, path)
def add_from_root(self, name, path):
self.paths[name] = (True, path)
def add(this, name, path):
this.paths[name] = (False, path)
def add(self, name, path):
self.paths[name] = (False, path)
def __getitem__(this, key):
relative, path = this.paths[key]
def __getitem__(self, key):
relative, path = self.paths[key]
if not relative:
return path
return os.path.join(this.root, path)
return os.path.join(self.root, path)
def get(this, key, default=None):
def get(self, key, default=None):
try:
return this[key]
return self[key]
except KeyError:
return default
def iteritems(this):
for key in this.paths.iterkeys():
yield (key, this[key])
def iteritems(self):
for key in self.paths.iterkeys():
yield (key, self[key])
def windowsify(s):
if os.name == 'nt':
......
......@@ -107,8 +107,11 @@ class ProxyResolver:
query = iq.setTag('query')
query.setNamespace(common.xmpp.NS_BYTESTREAM)
query.setAttr('sid', self.sid)
activate = query.setTag('activate')
query.setTag('activate')
# activate = query.setTag('activate')
# activate.setData(self.jid + "/" + self.sid)
if self.active_connection:
self.active_connection.send(iq)
self.state = S_ACTIVATED
......
......@@ -268,7 +268,6 @@ class ConversationTextview:
if over_line and not self.line_tooltip.win:
# check if the current pointer is still over the line
position = self.tv.window.get_origin()
win = self.tv.get_toplevel()
self.line_tooltip.show_tooltip(_('Text below this line is what has '
'been said since the last time you paid attention to this group chat'), 8, position[1] + pointer[1])
......@@ -408,7 +407,6 @@ class ConversationTextview:
if event.button != 3: # if not right click
return False
win = self.tv.get_window(gtk.TEXT_WINDOW_TEXT)
x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT,
int(event.x), int(event.y))
iter = self.tv.get_iter_at_location(x, y)
......@@ -691,27 +689,7 @@ class ConversationTextview:
before_str = helpers.from_one_line(before_str)
after_str = gajim.config.get('after_time')
after_str = helpers.from_one_line(after_str)
# get difference in days since epoch (86400 = 24*3600)
# number of days since epoch for current time (in GMT) -
# number of days since epoch for message (in GMT)
diff_day = int(timegm(time.localtime())) / 86400 - int(timegm(tim)) / 86400
if diff_day == 0:
day_str = ''
elif diff_day == 1:
day_str = _('Yesterday')
else:
#the number is >= 2
# %i is day in year (1-365), %d (1-31) we want %i
day_str = _('%i days ago') % diff_day
format = before_str
if day_str:
format += day_str + ' '
format += '%X' + after_str
tim_format = time.strftime(format, tim)
if locale.getpreferredencoding() == 'UTF-8':
# if tim_format comes as unicode because of day_str.
# we convert it to the encoding that we want (and that is utf-8)
tim_format = helpers.ensure_utf8_string(tim_format)
tim_format = before_str + self.get_time_to_show(tim) + after_str
buffer.insert_with_tags_by_name(end_iter, tim_format + ' ',
*other_tags_for_time)
elif current_print_time == 'sometimes' and kind != 'info':
......@@ -727,9 +705,7 @@ class ConversationTextview:
ft = fc.getFuzzyTime(gajim.config.get('print_time_fuzzy'))
tim_format = ft.decode(locale.getpreferredencoding())
else:
tim_format = time.strftime('%H:%M', tim).decode(
locale.getpreferredencoding())
tim_format = self.get_time_to_show(tim)
buffer.insert_with_tags_by_name(end_iter, tim_format + '\n',
'time_sometimes')
# kind = info, we print things as if it was a status: same color, ...
......@@ -761,6 +737,33 @@ class ConversationTextview:
buffer.end_user_action()
def get_time_to_show(self, tim):
'''Get the time, with the day before if needed and return it.
It DOESN'T format a fuzzy time'''
format = ''
# get difference in days since epoch (86400 = 24*3600)
# number of days since epoch for current time (in GMT) -
# number of days since epoch for message (in GMT)
diff_day = int(timegm(time.localtime())) / 86400 -\
int(timegm(tim)) / 86400
if diff_day == 0:
day_str = ''
elif diff_day == 1:
day_str = _('Yesterday')
else:
#the number is >= 2
# %i is day in year (1-365), %d (1-31) we want %i
day_str = _('%i days ago') % diff_day
if day_str:
format += day_str + ' '
format += '%X'
tim_format = time.strftime(format, tim)
if locale.getpreferredencoding() == 'UTF-8':
# if tim_format comes as unicode because of day_str.
# we convert it to the encoding that we want (and that is utf-8)
tim_format = helpers.ensure_utf8_string(tim_format)
return tim_format
def detect_other_text_tag(self, text, kind):
if kind == 'status':
return kind
......
......@@ -131,6 +131,8 @@ for o, a in opts:
gajim.verbose = True
elif o in ('-p', '--profile'): # gajim --profile name
profile = a
del opts
del args
import locale
profile = unicode(profile, locale.getpreferredencoding())
......@@ -152,8 +154,13 @@ if os.path.exists(pid_filename):
dialog = dialogs.YesNoDialog(pritext, sectext)
if dialog.get_response() != gtk.RESPONSE_YES:
sys.exit(3)
# run anyway, delete pid and useless global vars
if os.path.exists(pid_filename):
os.remove(pid_filename)
del path_to_file
del pix
del pritext
del sectext
dialog.destroy()
# Create .gajim dir
......@@ -163,6 +170,7 @@ if not os.path.exists(pid_dir):
# Create pid file
f = open(pid_filename, 'a')
f.close()
del pid_dir
def on_exit():
# delete pid file on normal exit
......@@ -1145,7 +1153,7 @@ class Interface:
path_to_bw_file = path_to_file + '_notif_size_bw.png'
bwbuf.save(path_to_bw_file, 'png')
def add_event(self, account, jid, type_, args):
def add_event(self, account, jid, type_, event_args):
'''add an event to the gajim.events var'''
# We add it to the gajim.events queue
# Do we have a queue?
......@@ -1161,7 +1169,7 @@ class Interface:
event_type = event_types[type_]
show_in_roster = notify.get_show_in_roster(event_type, account, jid)
show_in_systray = notify.get_show_in_systray(event_type, account, jid)
event = gajim.events.create_event(type_, args,
event = gajim.events.create_event(type_, event_args,
show_in_roster = show_in_roster,
show_in_systray = show_in_systray)
gajim.events.add_event(account, jid, event)
......
......@@ -878,7 +878,6 @@ class GroupchatControl(ChatControlBase):
if (time.time() - self.room_creation) > 30 and \
nick != self.nick and statusCode != '303':
st = ''
found = False
print_status = None
for bookmark in gajim.connections[self.account].bookmarks:
if bookmark['jid'] == self.room_jid:
......@@ -1414,8 +1413,6 @@ class GroupchatControl(ChatControlBase):
message_buffer = widget.get_buffer()
start_iter, end_iter = message_buffer.get_bounds()
message = message_buffer.get_text(start_iter, end_iter, False).decode(
'utf-8')
if event.keyval == gtk.keysyms.Tab: # TAB
cursor_position = message_buffer.get_insert()
......@@ -1765,7 +1762,6 @@ class GroupchatControl(ChatControlBase):
self.room_jid, nick))
def on_list_treeview_leave_notify_event(self, widget, event):
model = widget.get_model()
props = widget.get_path_at_pos(int(event.x), int(event.y))
if self.tooltip.timeout > 0:
if not props or self.tooltip.id == props[0]:
......
......@@ -792,7 +792,6 @@ class HtmlTextView(gtk.TextView):
if text:
pointer = self.get_pointer()
position = self.window.get_origin()
win = self.get_toplevel()
self.tooltip.show_tooltip(text, 8, position[1] + pointer[1])
def __motion_notify_event(self, widget, event):
......
......@@ -491,8 +491,6 @@ class MessageWindow:
def _on_notebook_key_press(self, widget, event):
st = '1234567890' # alt+1 means the first tab (tab 0)
ctrl = self.get_active_control()
contact = ctrl.contact
jid = ctrl.contact.jid
# CTRL mask
if event.state & gtk.gdk.CONTROL_MASK:
......@@ -557,7 +555,6 @@ class MessageWindow:
source_page_num = int(selection.data)
dest_page_num, to_right = self.get_tab_at_xy(x, y)
source_child = self.notebook.get_nth_page(source_page_num)
source_tab_label = self.notebook.get_tab_label(source_child)
if dest_page_num != source_page_num:
self.notebook.reorder_child(source_child, dest_page_num)
......
......@@ -329,11 +329,9 @@ def popup(event_type, jid, account, msg_type = '', path_to_image = None,
instance)
def on_pynotify_notification_clicked(notification, action):
event_type = notification.get_data('event_type')
jid = notification.get_data('jid')
account = notification.get_data('account')
msg_type = notification.get_data('msg_type')
path_to_image = notification.get_data('path_to_image')
notification.close()
gajim.interface.handle_event(account, jid, msg_type)
......
......@@ -109,7 +109,6 @@ class ProfileWindow:
self.avatar_mime_type = None
def on_set_avatar_button_clicked(self, widget):
f = None
def on_ok(widget, path_to_file):
filesize = os.path.getsize(path_to_file) # in bytes
#FIXME: use messages for invalid file for 0.11
......
......@@ -120,7 +120,6 @@ class SignalObject(dbus.service.Object):
returns status (show to be exact) which is the global one
unless account is given'''
account = self._get_real_arguments(args, 1)[0]
accounts = gajim.contacts.get_accounts()
if not account:
# If user did not ask for account, returns the global status
return helpers.get_global_show()
......@@ -134,7 +133,6 @@ class SignalObject(dbus.service.Object):
returns status which is the global one
unless account is given'''
account = self._get_real_arguments(args, 1)[0]
accounts = gajim.contacts.get_accounts()
if not account:
# If user did not ask for account, returns the global status
return str(helpers.get_global_status())
......
......@@ -805,8 +805,6 @@ class RosterWindow:
add_new_contact_menuitem = self.xml.get_widget('add_new_contact_menuitem')
service_disco_menuitem = self.xml.get_widget('service_disco_menuitem')
advanced_menuitem = self.xml.get_widget('advanced_menuitem')
show_offline_contacts_menuitem = self.xml.get_widget(
'show_offline_contacts_menuitem')
profile_avatar_menuitem = self.xml.get_widget('profile_avatar_menuitem')
# destroy old advanced menus
......@@ -1161,7 +1159,6 @@ class RosterWindow:
def chg_contact_status(self, contact, show, status, account):
'''When a contact changes his or her status'''
showOffline = gajim.config.get('showoffline')
contact_instances = gajim.contacts.get_contact(account, contact.jid)
contact.show = show
contact.status = status
......@@ -1176,11 +1173,10 @@ class RosterWindow:
jid_list = [contact.jid]
if contact.get_full_jid() != contact.jid:
jid_list.append(contact.get_full_jid())
for j in jid_list:
if gajim.interface.msg_win_mgr.has_window(j, account):
jid = contact.jid
win = gajim.interface.msg_win_mgr.get_window(j, account)
ctrl = win.get_control(j, account)
for jid in jid_list:
if gajim.interface.msg_win_mgr.has_window(jid, account):
win = gajim.interface.msg_win_mgr.get_window(jid, account)
ctrl = win.get_control(jid, account)
ctrl.contact = contact
ctrl.update_ui()
win.redraw_tab(ctrl)
......@@ -1248,7 +1244,6 @@ class RosterWindow:
self.tooltip.hide_tooltip()
def on_roster_treeview_leave_notify_event(self, widget, event):
model = widget.get_model()
props = widget.get_path_at_pos(int(event.x), int(event.y))
if self.tooltip.timeout > 0:
if not props or self.tooltip.id == props[0]:
......@@ -3976,7 +3971,6 @@ class RosterWindow:
contact.groups)
def remove_contact_from_group(self, account, contact, group):
model = self.tree.get_model()
# Make sure contact was in the group
if group in contact.groups:
contact.groups.remove(group)
......@@ -4049,7 +4043,6 @@ class RosterWindow:
it = iter_source
while model[it][C_TYPE] == 'contact':
it = model.iter_parent(it)
iter_group_source = it
grp_source = model[it][C_JID].decode('utf-8')
if grp_source in helpers.special_groups:
return
......
......@@ -341,7 +341,6 @@ class Systray:
self.tooltip.show_tooltip('', size[1], position[1])
def on_tray_motion_notify_event(self, widget, event):
wireq=widget.size_request()
position = widget.window.get_origin()
if self.tooltip.timeout > 0:
if self.tooltip.id != position:
......
......@@ -306,7 +306,7 @@ class GCTooltip(BaseTooltip):
properties.append((show, None))
if contact.jid.strip() != '':
properties.append((_('JID: '), contact.jid))
properties.append((_('Jabber ID: '), contact.jid))
if hasattr(contact, 'resource') and contact.resource.strip() != '':
properties.append((_('Resource: '),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment