# Path: sunflower/common.py
# class UserDirectory:
# 	DESKTOP = 'XDG_DESKTOP_DIR'
# 	DOWNLOADS = 'XDG_DOWNLOAD_DIR'
# 	TEMPLATES = 'XDG_TEMPLATES_DIR'
# 	PUBLIC = 'XDG_PUBLICSHARE_DIR'
# 	DOCUMENTS = 'XDG_DOCUMENTS_DIR'
# 	MUSIC = 'XDG_MUSIC_DIR'
# 	PICTURES = 'XDG_PICTURES_DIR'
# 	VIDEOS = 'XDG_VIDEOS_DIR'
# 
# def get_user_directory(directory):
# 	"""Get full path to current users predefined directory"""
# 	result = None
# 	config_file = os.path.join(get_config_directory(), 'user-dirs.dirs')
# 
# 	if os.path.isfile(config_file):
# 		# read configuration file
# 		with open(config_file, 'r') as raw_file:
# 			lines = raw_file.read().splitlines(False)
# 
# 		# get desired path
# 		for line in lines:
# 			data = line.split('=')
# 
# 			if data[0] == directory:
# 				result = data[1].replace('$HOME', os.path.expanduser('~'))
# 				result = result.strip('"')
# 				break
# 
# 	return result
# 
# def get_static_assets_directory():
# 	"""Return path to directory that holds static files"""
# 	script_dir = os.path.join(os.path.dirname(__file__), '..')
# 	prefix_dir = os.path.join(sys.prefix, 'share', 'sunflower')
# 	result = prefix_dir
# 
# 	if os.path.exists(os.path.join(script_dir, 'images', 'sunflower.svg')):
# 		result = script_dir
# 
# 	return result


from builtins import filter
from gi.repository import Gtk, Gio, GdkPixbuf, GLib
from sunflower.common import UserDirectory, get_user_directory, get_static_assets_directory
import os
import sys
import zipfile
		"""Return existing icon name from the specified list"""
		result = 'drive-harddisk'

		# create a list of icons and filter non-existing
		icon_list = icons.split(' ')
		icon_list = list(filter(self.has_icon, icon_list))

		# if list has items, grab first
		if len(icon_list) > 0:
			result = icon_list[0]

		return result

	def set_window_icon(self, window):
		"""Set window icon"""
		# check system for icon
		if self.has_icon('sunflower'):
			window.set_icon(self._icon_theme.load_icon('sunflower', 256, 0))

		# try loading from zip file
		elif os.path.isfile(sys.path[0]) and sys.path[0] != '':
			archive = zipfile.ZipFile(sys.path[0])
			with archive.open('images/sunflower.svg') as raw_file:
				buff = Gio.MemoryInputStream.new_from_bytes(GLib.Bytes.new(raw_file.read()))
				icon = GdkPixbuf.Pixbuf.new_from_stream(buff, None)
				window.set_icon(icon)
			archive.close()

		# load from local path
		else:

# Path: sunflower/common.py
# class UserDirectory:
# 	DESKTOP = 'XDG_DESKTOP_DIR'
# 	DOWNLOADS = 'XDG_DOWNLOAD_DIR'
# 	TEMPLATES = 'XDG_TEMPLATES_DIR'
# 	PUBLIC = 'XDG_PUBLICSHARE_DIR'
# 	DOCUMENTS = 'XDG_DOCUMENTS_DIR'
# 	MUSIC = 'XDG_MUSIC_DIR'
# 	PICTURES = 'XDG_PICTURES_DIR'
# 	VIDEOS = 'XDG_VIDEOS_DIR'
# 
# def get_user_directory(directory):
# 	"""Get full path to current users predefined directory"""
# 	result = None
# 	config_file = os.path.join(get_config_directory(), 'user-dirs.dirs')
# 
# 	if os.path.isfile(config_file):
# 		# read configuration file
# 		with open(config_file, 'r') as raw_file:
# 			lines = raw_file.read().splitlines(False)
# 
# 		# get desired path
# 		for line in lines:
# 			data = line.split('=')
# 
# 			if data[0] == directory:
# 				result = data[1].replace('$HOME', os.path.expanduser('~'))
# 				result = result.strip('"')
# 				break
# 
# 	return result
# 
# def get_static_assets_directory():
# 	"""Return path to directory that holds static files"""
# 	script_dir = os.path.join(os.path.dirname(__file__), '..')
# 	prefix_dir = os.path.join(sys.prefix, 'share', 'sunflower')
# 	result = prefix_dir
# 
# 	if os.path.exists(os.path.join(script_dir, 'images', 'sunflower.svg')):
# 		result = script_dir
# 
# 	return result


# Path: sunflower/icons.py
from builtins import filter
from gi.repository import Gtk, Gio, GdkPixbuf, GLib
from sunflower.common import UserDirectory, get_user_directory, get_static_assets_directory
import os
import sys
import zipfile

		"""Return existing icon name from the specified list"""
		result = 'drive-harddisk'

		# create a list of icons and filter non-existing
		icon_list = icons.split(' ')
		icon_list = list(filter(self.has_icon, icon_list))

		# if list has items, grab first
		if len(icon_list) > 0:
			result = icon_list[0]

		return result

	def set_window_icon(self, window):
		"""Set window icon"""
		# check system for icon
		if self.has_icon('sunflower'):
			window.set_icon(self._icon_theme.load_icon('sunflower', 256, 0))

		# try loading from zip file
		elif os.path.isfile(sys.path[0]) and sys.path[0] != '':
			archive = zipfile.ZipFile(sys.path[0])
			with archive.open('images/sunflower.svg') as raw_file:
				buff = Gio.MemoryInputStream.new_from_bytes(GLib.Bytes.new(raw_file.read()))
				icon = GdkPixbuf.Pixbuf.new_from_stream(buff, None)
				window.set_icon(icon)
			archive.close()

		# load from local path
		else:

			base_path = get_static_assets_directory()