71
71
completion list consists of (Pixbuf, Text) rows'''
72
72
completion = gtk.EntryCompletion()
73
73
liststore = gtk.ListStore(gtk.gdk.Pixbuf, str)
75
75
render_pixbuf = gtk.CellRendererPixbuf()
76
76
completion.pack_start(render_pixbuf, expand = False)
77
77
completion.add_attribute(render_pixbuf, 'pixbuf', 0)
79
79
render_text = gtk.CellRendererText()
80
80
completion.pack_start(render_text, expand = True)
81
81
completion.add_attribute(render_text, 'text', 1)
83
83
completion.set_model(liststore)
84
84
entry.set_completion(completion)
88
88
def popup_emoticons_under_button(menu, button, parent_win):
89
89
''' pops emoticons menu under button, which is in parent_win'''
90
90
window_x1, window_y1 = parent_win.get_origin()
91
91
def position_menu_under_button(menu):
92
92
# inline function, which will not keep refs, when used as CB
93
93
button_x, button_y = button.allocation.x, button.allocation.y
95
95
# now convert them to X11-relative
96
96
window_x, window_y = window_x1, window_y1
97
97
x = window_x + button_x
98
98
y = window_y + button_y
100
menu_width, menu_height = menu.size_request()
100
menu_height = menu.size_request()[1]
102
102
## should we pop down or up?
103
103
if (y + button.allocation.height + menu_height
150
150
# and http://freedesktop.org/Standards/basedir-spec
151
151
xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '')
152
152
if xdg_config_home == '':
153
xdg_config_home = os.path.expanduser('~/.config') # default
153
xdg_config_home = os.path.expanduser('~/.config') # default
154
154
xfce_config_file = os.path.join(xdg_config_home, 'xfce4/mcs_settings/gtk.xml')
156
156
kde_config_file = os.path.expanduser('~/.kde/share/config/kdeglobals')
158
158
if os.path.exists(xfce_config_file):
160
160
for line in open(xfce_config_file):
229
224
files = filter(str.isdigit, files)
231
226
# files that aren't directories...
232
files = filter(lambda f:os.path.isdir('/proc/' + f), files)
227
files = [f for f in files if os.path.isdir('/proc/' + f)]
234
229
# processes owned by somebody not running gajim...
235
230
# (we check if we have access to that file)
236
files = filter(lambda f:os.access('/proc/' + f +'/exe', os.F_OK), files)
231
files = [f for f in files if os.access('/proc/' + f +'/exe', os.F_OK)]
238
233
# be sure that /proc/[number]/exe is really a symlink
239
234
# to avoid TBs in incorrectly configured systems
240
files = filter(lambda f:os.path.islink('/proc/' + f + '/exe'), files)
235
files = [f for f in files if os.path.islink('/proc/' + f + '/exe')]
242
237
# list of processes
243
238
processes = [os.path.basename(os.readlink('/proc/' + f +'/exe')) for f in files]
371
366
'''checks if we are svn or normal user and returns abspath to asked script
372
367
if want_type is True we return 'svn' or 'install' '''
373
368
if os.path.isdir('.svn'): # we are svn user
375
370
cwd = os.getcwd() # it's always ending with src
377
372
if scriptname == 'gajim-remote':
378
373
path_to_script = cwd + '/gajim-remote.py'
380
375
elif scriptname == 'gajim':
381
376
script = '#!/bin/sh\n' # the script we may create
382
377
script += 'cd %s' % cwd
383
378
path_to_script = cwd + '/../scripts/gajim_sm_script'
386
381
if os.path.exists(path_to_script):
387
382
os.remove(path_to_script)
629
624
for extension in ('.png', '.jpeg'):
630
625
path_to_local_file_full = path_to_local_file + extension
631
626
if os.path.exists(path_to_local_file_full):
632
return path_to_local_file_full
627
return path_to_local_file_full
633
628
for extension in ('.png', '.jpeg'):
634
629
path_to_file_full = path_to_file + extension
635
630
if os.path.exists(path_to_file_full):
656
651
except Exception:
658
653
file_paths_list.append(file_path)
660
655
return file_paths_list
662
657
def possibly_set_gajim_as_xmpp_handler():
663
658
'''registers (by default only the first time) xmmp: to Gajim.'''
664
659
path_to_dot_kde = os.path.expanduser('~/.kde')
665
660
if os.path.exists(path_to_dot_kde):
666
path_to_kde_file = os.path.join(path_to_dot_kde,
661
path_to_kde_file = os.path.join(path_to_dot_kde,
667
662
'share/services/xmpp.protocol')
669
664
path_to_kde_file = None
810
805
def on_ok(widget):
811
def on_ok2(file_path, pixbuf):
812
pixbuf.save(file_path, 'jpeg')
815
806
file_path = dialog.get_filename()
816
807
file_path = decode_filechooser_file_paths((file_path,))[0]
817
808
if os.path.exists(file_path):
818
809
# check if we have write permissions
819
810
if not os.access(file_path, os.W_OK):
820
811
file_name = os.path.basename(file_path)
821
dialogs.ErrorDialog(_('Cannot overwrite existing file "%s"' %
812
dialogs.ErrorDialog(_('Cannot overwrite existing file "%s"' %
823
814
_('A file with this name already exists and you do not have '
824
815
'permission to overwrite it.'))
841
832
def on_cancel(widget):
844
dialog = dialogs.FileChooserDialog(title_text=_('Save Image as...'),
835
dialog = dialogs.FileChooserDialog(title_text=_('Save Image as...'),
845
836
action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_CANCEL,
846
837
gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK),
847
838
default_response=gtk.RESPONSE_OK,
872
863
combobox.show_all()
875
def load_iconset(path, pixbuf2 = None, transport = False):
866
def create_list_multi(value_list, selected_values=None):
867
'''Value_list is [(label1, value1), ]'''
868
liststore = gtk.ListStore(str, str)
869
treeview = gtk.TreeView(liststore)
870
treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
871
treeview.set_headers_visible(False)
872
col = gtk.TreeViewColumn()
873
treeview.append_column(col)
874
cell = gtk.CellRendererText()
875
col.pack_start(cell, True)
876
col.set_attributes(cell, text=0)
877
for value in value_list:
878
iter = liststore.append(value)
879
if value[1] in selected_values:
880
treeview.get_selection().select_iter(iter)
884
def load_iconset(path, pixbuf2=None, transport=False):
876
885
'''load full iconset from the given path, and add
877
886
pixbuf2 on top left of each static images'''
880
list = ('online', 'chat', 'away', 'xa', 'dnd', 'offline',
889
list_ = ('online', 'chat', 'away', 'xa', 'dnd', 'offline',
883
list = ('connecting', 'online', 'chat', 'away', 'xa', 'dnd',
892
list_ = ('connecting', 'online', 'chat', 'away', 'xa', 'dnd',
884
893
'invisible', 'offline', 'error', 'requested', 'event', 'opened',
885
894
'closed', 'not in roster', 'muc_active', 'muc_inactive')
887
list = ('connecting', 'online', 'chat', 'away', 'xa', 'dnd',
896
list_ = ('connecting', 'online', 'chat', 'away', 'xa', 'dnd',
888
897
'offline', 'error', 'requested', 'event', 'not in roster')
889
return _load_icon_list(list, path, pixbuf2)
898
return _load_icon_list(list_, path, pixbuf2)
891
900
def load_icon(icon_name):
892
901
'''load an icon from the iconset in 16x16'''
966
975
'''initialise jabber_state_images dict'''
967
976
iconset = gajim.config.get('iconset')
969
path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
970
if not os.path.exists(path):
978
if helpers.get_iconset_path(iconset):
979
path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
980
if not os.path.exists(path):
981
iconset = gajim.config.DEFAULT_ICONSET
982
gajim.config.set('iconset', iconset)
971
984
iconset = gajim.config.DEFAULT_ICONSET
985
gajim.config.set('iconset', iconset)
973
987
iconset = gajim.config.DEFAULT_ICONSET
988
gajim.config.set('iconset', iconset)
975
990
path = os.path.join(helpers.get_iconset_path(iconset), '32x32')
976
991
gajim.interface.jabber_state_images['32'] = load_iconset(path)
986
1001
make_jabber_state_images()
987
1002
gajim.interface.roster.update_jabber_state_images()
1004
def label_set_autowrap(widget):
1005
'''Make labels automatically re-wrap if their containers are resized.
1006
Accepts label or container widgets.'''
1007
if isinstance (widget, gtk.Container):
1008
children = widget.get_children()
1009
for i in xrange (len (children)):
1010
label_set_autowrap(children[i])
1011
elif isinstance(widget, gtk.Label):
1012
widget.set_line_wrap(True)
1013
widget.connect_after('size-allocate', __label_size_allocate)
1015
def __label_size_allocate(widget, allocation):
1016
'''Callback which re-allocates the size of a label.'''
1017
layout = widget.get_layout()
1019
lw_old, lh_old = layout.get_size()
1020
# fixed width labels
1021
if lw_old/pango.SCALE == allocation.width:
1024
# set wrap width to the pango.Layout of the labels ###
1025
layout.set_width (allocation.width * pango.SCALE)
1026
lw, lh = layout.get_size ()
1029
widget.set_size_request (-1, lh / pango.SCALE)