show status icons for resources
This commit is contained in:
parent
8362334891
commit
2b460a39fe
111
src/dialogs.py
111
src/dialogs.py
|
@ -495,24 +495,17 @@ class RosterTooltip(gtk.Window):
|
||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
self.set_resizable(False)
|
self.set_resizable(False)
|
||||||
self.set_name('gtk-tooltips')
|
self.set_name('gtk-tooltips')
|
||||||
hbox = gtk.HBox()
|
self.hbox = gtk.HBox()
|
||||||
hbox.set_spacing(6)
|
self.hbox.set_border_width(6)
|
||||||
hbox.set_border_width(6)
|
self.add(self.hbox)
|
||||||
self.add(hbox)
|
|
||||||
self.image = gtk.Image()
|
self.image = gtk.Image()
|
||||||
self.image.set_alignment(0.5, 0.025)
|
self.image.set_alignment(0.5, 0.025)
|
||||||
|
|
||||||
hbox.pack_start(self.image, False, False)
|
self.hbox.pack_start(self.image, False, False)
|
||||||
contents = gtk.VBox()
|
self.account = None
|
||||||
contents.set_spacing(10)
|
self.table = None
|
||||||
hbox.pack_start(contents)
|
|
||||||
|
|
||||||
self.account = gtk.Label()
|
|
||||||
self.account.set_line_wrap(True)
|
|
||||||
self.account.set_alignment(0, 0)
|
|
||||||
self.account.set_selectable(False)
|
|
||||||
contents.pack_start(self.account)
|
|
||||||
|
|
||||||
|
self.current_row = 1
|
||||||
self.timeout = 0
|
self.timeout = 0
|
||||||
self.prefered_position = [0, 0]
|
self.prefered_position = [0, 0]
|
||||||
self.path = None
|
self.path = None
|
||||||
|
@ -522,6 +515,8 @@ class RosterTooltip(gtk.Window):
|
||||||
self.connect('size-request', self.size_request)
|
self.connect('size-request', self.size_request)
|
||||||
self.connect('motion-notify-event', self.motion_notify_event)
|
self.connect('motion-notify-event', self.motion_notify_event)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def motion_notify_event(self, widget, event):
|
def motion_notify_event(self, widget, event):
|
||||||
self.hide_tooltip()
|
self.hide_tooltip()
|
||||||
|
|
||||||
|
@ -569,9 +564,49 @@ class RosterTooltip(gtk.Window):
|
||||||
self.hide()
|
self.hide()
|
||||||
self.path = None
|
self.path = None
|
||||||
|
|
||||||
|
|
||||||
|
def add_status(self, file_path, resource, priority, show, status):
|
||||||
|
''' appends a new row with status icon to the table '''
|
||||||
|
self.current_row += 1
|
||||||
|
state_file = show.replace(' ', '_')
|
||||||
|
files = []
|
||||||
|
files.append(os.path.join(file_path, state_file + '.png'))
|
||||||
|
files.append(os.path.join(file_path, state_file + '.gif'))
|
||||||
|
image = gtk.Image()
|
||||||
|
image.set_from_pixbuf(None)
|
||||||
|
spacer = gtk.Label(' ')
|
||||||
|
for file in files:
|
||||||
|
if os.path.exists(file):
|
||||||
|
image.set_from_file(file)
|
||||||
|
break
|
||||||
|
self.table.attach(spacer, 1, 2, self.current_row,
|
||||||
|
self.current_row + 1, 0, 0, 0, 0)
|
||||||
|
self.table.attach(image,2,3,self.current_row,
|
||||||
|
self.current_row + 1, 0, 0, 3, 0)
|
||||||
|
str_status = resource + ' ('+str(priority)+')'
|
||||||
|
if status or status.strip() != '':
|
||||||
|
str_status += ' - ' + status
|
||||||
|
status_label = gtk.Label(str_status)
|
||||||
|
status_label.set_alignment(00, 0)
|
||||||
|
self.table.attach(status_label, 3, 4, self.current_row, self.current_row + 1,
|
||||||
|
gtk.EXPAND | gtk.FILL, 0, 0, 0)
|
||||||
|
|
||||||
def populate(self, contacts):
|
def populate(self, contacts):
|
||||||
if not contacts or len(contacts) == 0:
|
if not contacts or len(contacts) == 0:
|
||||||
return
|
return
|
||||||
|
# remove prevous table
|
||||||
|
if self.account:
|
||||||
|
self.table.remove(self.account)
|
||||||
|
if self.table:
|
||||||
|
self.hbox.remove(self.table)
|
||||||
|
self.table = gtk.Table(3, 1)
|
||||||
|
self.table.set_property('column-spacing', 6)
|
||||||
|
self.account = gtk.Label()
|
||||||
|
self.account.set_line_wrap(True)
|
||||||
|
self.account.set_alignment(0, 0)
|
||||||
|
self.account.set_selectable(False)
|
||||||
|
self.table.attach(self.account, 1, 4, 1, 2)
|
||||||
|
self.hbox.pack_start(self.table)
|
||||||
# default resource of the contact
|
# default resource of the contact
|
||||||
prim_contact = None # primary contact
|
prim_contact = None # primary contact
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
|
@ -591,8 +626,9 @@ class RosterTooltip(gtk.Window):
|
||||||
file_path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
|
file_path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
files.append(os.path.join(file_path, state_file + '.png'))
|
file_full_path = os.path.join(file_path, state_file)
|
||||||
files.append(os.path.join(file_path, state_file + '.gif'))
|
files.append(file_full_path + '.png')
|
||||||
|
files.append(file_full_path + '.gif')
|
||||||
self.image.set_from_pixbuf(None)
|
self.image.set_from_pixbuf(None)
|
||||||
for file in files:
|
for file in files:
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
|
@ -616,33 +652,28 @@ class RosterTooltip(gtk.Window):
|
||||||
'</span>' + keyID
|
'</span>' + keyID
|
||||||
|
|
||||||
single_line, resource_str, multiple_resource= '', '', False
|
single_line, resource_str, multiple_resource= '', '', False
|
||||||
|
num_resources = 0
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
if contact.resource:
|
if contact.resource:
|
||||||
if resource_str != '':
|
num_resources += 1
|
||||||
multiple_resource = True
|
if num_resources > 1:
|
||||||
else:
|
self.current_row = 1
|
||||||
# keep a single line entry in case there are no resources/statuses
|
self.table.resize(2,1)
|
||||||
single_line = contact.resource + ' (' + \
|
|
||||||
str(contact.priority) + ')'
|
|
||||||
resource_str += '\n\t' + contact.resource + \
|
|
||||||
' (' + str(contact.priority) + ')'
|
|
||||||
if contact.show:
|
|
||||||
if multiple_resource is False:
|
|
||||||
# keep a single line entry in case there are no resources/statuses
|
|
||||||
single_line += ": " + helpers.get_uf_show(contact.show)
|
|
||||||
resource_str += '\n\t\t' + helpers.get_uf_show(contact.show)
|
|
||||||
if contact.status:
|
|
||||||
resource_str += ' - ' + contact.status
|
|
||||||
if multiple_resource is False:
|
|
||||||
single_line += ' - ' + contact.status
|
|
||||||
|
|
||||||
if resource_str != '':
|
|
||||||
info += '\n<span weight="bold">' + _('Status: ') + '</span>'
|
info += '\n<span weight="bold">' + _('Status: ') + '</span>'
|
||||||
if multiple_resource:
|
for contact in contacts:
|
||||||
info += resource_str
|
if contact.resource:
|
||||||
else:
|
self.add_status(file_path, contact.resource, contact.priority,
|
||||||
# show the resource & status on the same line
|
contact.show, contact.status)
|
||||||
info += single_line
|
|
||||||
|
else: # only one resource
|
||||||
|
if contact.resource:
|
||||||
|
info += '\n<span weight="bold">' + _('Resource: ') + \
|
||||||
|
'</span>' + contact.resource + ' (' + str(contact.priority) + ')'
|
||||||
|
if contact.show:
|
||||||
|
info += '\n<span weight="bold">' + _('Status: ') + \
|
||||||
|
'</span>' + helpers.get_uf_show(contact.show)
|
||||||
|
if contact.status and contact.status.strip() != '':
|
||||||
|
info += ' - ' + contact.status
|
||||||
|
|
||||||
self.account.set_markup(info)
|
self.account.set_markup(info)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue