# Path: sunflower/common.py
# def get_cache_directory():
# 	"""Get full path to cache files for curring user."""
# 	if 'XDG_CACHE_HOME' in os.environ:
# 		result = os.path.abspath(os.environ['XDG_CACHE_HOME'])
# 	else:
# 		result = os.path.expanduser('~/.cache')
# 
# 	return result
# 
# def encode_file_name(file_name):
# 	"""Encode filename to bytes so it can be passed to GI APIs that expect a file name
# 	(and specify `filename` as their argument type in the GIR bindings)."""
# 	return str(file_name).encode('utf-8', 'surrogateescape')


import os
import sqlite3 as sql
from gi.repository import Gtk
from sunflower.common import get_cache_directory, encode_file_name
		result = False

		cursor.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name=?', (table_name, ))
		result = cursor.fetchone()[0] > 0

		return result

	def _check_database(self):
		"""Check storage database integrity."""
		result = False

		cursor = self._get_cursor()
		result = self._table_exists(cursor, 'items')
		result = result and self._table_exists(cursor, 'emblems')

		return result

	def _create_database(self):
		"""Create database tables."""
		cursor = self._get_cursor()

		cursor.executescript('''
				CREATE TABLE items (
					id INTEGER PRIMARY KEY AUTOINCREMENT,
					path TEXT NOT NULL,
					name TEXT NOT NULL
				);
				CREATE INDEX items_by_path ON items(path);
				CREATE INDEX items_by_path_and_name ON items(path, name);


# Path: sunflower/common.py
# def get_cache_directory():
# 	"""Get full path to cache files for curring user."""
# 	if 'XDG_CACHE_HOME' in os.environ:
# 		result = os.path.abspath(os.environ['XDG_CACHE_HOME'])
# 	else:
# 		result = os.path.expanduser('~/.cache')
# 
# 	return result
# 
# def encode_file_name(file_name):
# 	"""Encode filename to bytes so it can be passed to GI APIs that expect a file name
# 	(and specify `filename` as their argument type in the GIR bindings)."""
# 	return str(file_name).encode('utf-8', 'surrogateescape')


# Path: sunflower/emblems.py
import os
import sqlite3 as sql
from gi.repository import Gtk
from sunflower.common import get_cache_directory, encode_file_name

		result = False

		cursor.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name=?', (table_name, ))
		result = cursor.fetchone()[0] > 0

		return result

	def _check_database(self):
		"""Check storage database integrity."""
		result = False

		cursor = self._get_cursor()
		result = self._table_exists(cursor, 'items')
		result = result and self._table_exists(cursor, 'emblems')

		return result

	def _create_database(self):
		"""Create database tables."""
		cursor = self._get_cursor()

		cursor.executescript('''
				CREATE TABLE items (
					id INTEGER PRIMARY KEY AUTOINCREMENT,
					path TEXT NOT NULL,
					name TEXT NOT NULL
				);
				CREATE INDEX items_by_path ON items(path);
				CREATE INDEX items_by_path_and_name ON items(path, name);


				CREATE TABLE emblems (