From e906a096c969ad636454bc438c6cbf778586c65e Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Sun, 5 Aug 2007 22:57:04 +0000
Subject: [PATCH] [blarz] ability to load iconsets from ~/.gajim/iconsets.
 fixes #3339

---
 src/common/configpaths.py |  6 ++++--
 src/common/gajim.py       |  1 +
 src/common/helpers.py     |  6 ++++++
 src/config.py             |  9 ++++++---
 src/roster_window.py      | 22 +++++++++++-----------
 src/systray.py            |  2 +-
 src/tooltips.py           |  6 +++---
 7 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/src/common/configpaths.py b/src/common/configpaths.py
index 57b39ec09..da41fb8d7 100644
--- a/src/common/configpaths.py
+++ b/src/common/configpaths.py
@@ -78,8 +78,10 @@ class ConfigPaths:
 			self.root = root
 
 		# LOG is deprecated
-		k = ( 'LOG',   'LOG_DB',   'VCARD',   'AVATAR',   'MY_EMOTS' )
-		v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons')
+		k = ( 'LOG',   'LOG_DB',   'VCARD',   'AVATAR',   'MY_EMOTS',
+			'MY_ICONSETS' )
+		v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons',
+			u'iconsets')
 
 		if os.name == 'nt':
 			v = map(lambda x: x.capitalize(), v)
diff --git a/src/common/gajim.py b/src/common/gajim.py
index fc109e8d0..8610f3f7a 100644
--- a/src/common/gajim.py
+++ b/src/common/gajim.py
@@ -71,6 +71,7 @@ LOGPATH = gajimpaths['LOG'] # deprecated
 VCARD_PATH = gajimpaths['VCARD']
 AVATAR_PATH = gajimpaths['AVATAR']
 MY_EMOTS_PATH = gajimpaths['MY_EMOTS']
+MY_ICONSETS_PATH = gajimpaths['MY_ICONSETS']
 TMP = gajimpaths['TMP']
 DATA_DIR = gajimpaths['DATA']
 HOME_DIR = gajimpaths['HOME']
diff --git a/src/common/helpers.py b/src/common/helpers.py
index cc855c597..c768d10f8 100644
--- a/src/common/helpers.py
+++ b/src/common/helpers.py
@@ -1044,3 +1044,9 @@ def datetime_tuple(timestamp):
 	timestamp = timestamp.replace('-', '')
 	from time import strptime
 	return strptime(timestamp, '%Y%m%dT%H:%M:%S')
+
+def get_iconset_path(iconset):
+	if os.path.isdir(os.path.join(gajim.DATA_DIR, 'iconsets', iconset)):
+		return os.path.join(gajim.DATA_DIR, 'iconsets', iconset)
+	elif os.path.isdir(os.path.join(gajim.MY_ICONSETS_PATH, iconset)):
+		return os.path.join(gajim.MY_ICONSETS_PATH, iconset)
diff --git a/src/config.py b/src/config.py
index 3ec20724b..99718ea07 100644
--- a/src/config.py
+++ b/src/config.py
@@ -146,6 +146,8 @@ class PreferencesWindow:
 
 		# iconset
 		iconsets_list = os.listdir(os.path.join(gajim.DATA_DIR, 'iconsets'))
+		if os.path.isdir(gajim.MY_ICONSETS_PATH):
+			iconsets_list += os.listdir(gajim.MY_ICONSETS_PATH) 
 		# new model, image in 0, string in 1
 		model = gtk.ListStore(gtk.Image, str)
 		renderer_image = cell_renderer_image.CellRendererImage(0, 0)
@@ -158,7 +160,8 @@ class PreferencesWindow:
 		self.iconset_combobox.set_model(model)
 		l = []
 		for dir in iconsets_list:
-			if not os.path.isdir(os.path.join(gajim.DATA_DIR, 'iconsets', dir)):
+			if not os.path.isdir(os.path.join(gajim.DATA_DIR, 'iconsets', dir)) \
+			and not os.path.isdir(os.path.join(gajim.MY_ICONSETS_PATH, dir)):
 				continue
 			if dir != '.svn' and dir != 'transports':
 				l.append(dir)
@@ -167,9 +170,9 @@ class PreferencesWindow:
 		for i in xrange(len(l)):
 			preview = gtk.Image()
 			files = []
-			files.append(os.path.join(gajim.DATA_DIR, 'iconsets', l[i], '16x16',
+			files.append(os.path.join(helpers.get_iconset_path(l[i]), '16x16',
 				'online.png'))
-			files.append(os.path.join(gajim.DATA_DIR, 'iconsets', l[i], '16x16',
+			files.append(os.path.join(helpers.get_iconset_path(l[i]), '16x16',
 				'online.gif'))
 			for file in files:
 				if os.path.exists(file):
diff --git a/src/roster_window.py b/src/roster_window.py
index c58aeebe7..941658918 100644
--- a/src/roster_window.py
+++ b/src/roster_window.py
@@ -1983,7 +1983,7 @@ class RosterWindow:
 				start_chat_menuitem.set_submenu(sub_menu)
 
 				iconset = gajim.config.get('iconset')
-				path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+				path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 				for c in contacts:
 					# icon MUST be different instance for every item
 					state_images = self.load_iconset(path)
@@ -2170,7 +2170,7 @@ class RosterWindow:
 		status_menuitems = gtk.Menu()
 		send_custom_status_menuitem.set_submenu(status_menuitems)
 		iconset = gajim.config.get('iconset')
-		path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+		path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 		for s in ['online', 'chat', 'away', 'xa', 'dnd', 'offline']:
 			# icon MUST be different instance for every item
 			state_images = self.load_iconset(path)
@@ -2189,7 +2189,7 @@ class RosterWindow:
 				iconset = gajim.config.get('iconset')
 				if not iconset:
 					iconset = gajim.config.DEFAULT_ICONSET
-				path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+				path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 				for c in contacts:
 					# icon MUST be different instance for every item
 					state_images = self.load_iconset(path)
@@ -2668,7 +2668,7 @@ class RosterWindow:
 			status_menuitems = gtk.Menu()
 			send_custom_status_menuitem.set_submenu(status_menuitems)
 			iconset = gajim.config.get('iconset')
-			path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+			path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 			for s in ['online', 'chat', 'away', 'xa', 'dnd', 'offline']:
 				# icon MUST be different instance for every item
 				state_images = self.load_iconset(path)
@@ -2860,7 +2860,7 @@ class RosterWindow:
 		# we have to create our own set of icons for the menu
 		# using self.jabber_status_images is poopoo
 		iconset = gajim.config.get('iconset')
-		path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+		path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 		state_images = self.load_iconset(path)
 
 		if not gajim.config.get_per('accounts', account, 'is_zeroconf'):
@@ -3006,7 +3006,7 @@ class RosterWindow:
 		else:
 			menu = gtk.Menu()
 			iconset = gajim.config.get('iconset')
-			path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+			path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 			accounts = [] # Put accounts in a list to sort them
 			for account in gajim.connections:
 				accounts.append(account)
@@ -3603,7 +3603,7 @@ class RosterWindow:
 		except:
 			pass
 		iconset = gajim.config.get('iconset')
-		prefix = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '32x32')
+		prefix = os.path.join(helpers.get_iconset_path(iconset), '32x32')
 		if status in ('chat', 'away', 'xa', 'dnd', 'invisible', 'offline'):
 			status = status + '.png'
 		elif status == 'online':
@@ -4300,7 +4300,7 @@ class RosterWindow:
 	def load_icon(self, icon_name):
 		'''load an icon from the iconset in 16x16'''
 		iconset = gajim.config.get('iconset')
-		path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16'+ '/')
+		path = os.path.join(helpers.get_iconset_path(iconset), '16x16'+ '/')
 		icon_list = self._load_icon_list([icon_name], path)
 		return icon_list[icon_name]
 
@@ -4335,16 +4335,16 @@ class RosterWindow:
 		'''initialise jabber_state_images dict'''
 		iconset = gajim.config.get('iconset')
 		if iconset:
-			path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+			path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 			if not os.path.exists(path):
 				iconset = gajim.config.DEFAULT_ICONSET
 		else:
 			iconset = gajim.config.DEFAULT_ICONSET
 
-		path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '32x32')
+		path = os.path.join(helpers.get_iconset_path(iconset), '32x32')
 		self.jabber_state_images['32'] = self.load_iconset(path)
 
-		path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+		path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 		self.jabber_state_images['16'] = self.load_iconset(path)
 		# try to find opened_meta.png file, else opened.png else nopixbuf merge
 		path_opened = os.path.join(path, 'opened_meta.png')
diff --git a/src/systray.py b/src/systray.py
index f7bd72493..84ae49877 100644
--- a/src/systray.py
+++ b/src/systray.py
@@ -145,7 +145,7 @@ class Systray:
 
 		# We need our own set of status icons, let's make 'em!
 		iconset = gajim.config.get('iconset')
-		path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+		path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 		state_images = gajim.interface.roster.load_iconset(path)
 
 		if state_images.has_key('muc_active'):
diff --git a/src/tooltips.py b/src/tooltips.py
index cd19e9131..8edae2f6d 100644
--- a/src/tooltips.py
+++ b/src/tooltips.py
@@ -228,7 +228,7 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
 		iconset = gajim.config.get('iconset')
 		if not iconset:
 			iconset = 'dcraven'
-		file_path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
+		file_path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
 		for acct in accounts:
 			message = acct['message']
 			# before reducing the chars we should assure we send unicode, else 
@@ -441,8 +441,8 @@ class RosterTooltip(NotificationAreaTooltip):
 				iconset = gajim.config.get('iconset')
 				if not iconset:
 					iconset = 'dcraven'
-				file_path = os.path.join(gajim.DATA_DIR,
-					'iconsets', iconset, '16x16')
+				file_path = os.path.join(helpers.get_iconset_path(iconsets),
+					'16x16')
 
 			contact_keys = contacts_dict.keys()
 			contact_keys.sort()