1
1
# -*- coding: utf-8 -*-
2
2
# -----------------------------------------------------------------------------
3
3
# Gettings Things Gnome! - a personal organizer for the GNOME desktop
4
# Copyright (c) 2008-2009 - Lionel Dricot & Bertrand Rousseau
4
# Copyright (c) 2008-2012 - Lionel Dricot & Bertrand Rousseau
6
6
# This program is free software: you can redistribute it and/or modify it under
7
7
# the terms of the GNU General Public License as published by the Free Software
34
33
- get your own personal FilteredTree and apply on it the filters you
35
34
want without interfering with the main view. (This is how the closed
36
35
tasks pane is built currently)
41
#=== IMPORT ====================================================================
38
#=== IMPORT ===================================================================
39
from configobj import ConfigObj, ConfigObjError
40
from xdg.BaseDirectory import xdg_data_home, xdg_config_home, xdg_data_dirs
43
from xdg.BaseDirectory import xdg_data_home, xdg_config_home
44
from configobj import ConfigObj
43
from GTG.tools.borg import Borg
45
44
from GTG.tools.testingmode import TestingMode
48
from GTG.tools.logger import Log
49
from GTG.tools.borg import Borg
54
'bg_color_enable': False,
49
"bg_color_enable": True,
55
50
"contents_preview_enable": False,
57
52
"sidebar_width": 120,
111
112
toreturn = self.__defaults[name]
112
113
self.__conf[name] = toreturn
114
print "Warning : no default conf value for %s in %s" % (name, self.__name)
115
print "Warning : no default conf value for %s in %s" % (
120
122
# Save immediately
121
123
self.__conf.parent.write()
125
def set_lst(self, name, value_lst):
126
self.__conf[name] = [str(s) for s in value_lst]
128
self.__conf.parent.write()
124
131
class CoreConfig(Borg):
125
132
#The projects and tasks are of course DATA !
138
145
SEP_TAG = "gtg-tags-sep"
139
146
SEARCH_TAG = "search"
148
def check_config_file(self,file_path):
149
""" This function bypasses the errors of config file and allows GTG to open smoothly"""
150
total_path=self.conf_dir+file_path
152
config = ConfigObj(total_path)
153
except ConfigObjError:
154
open(total_path, "w").close()
155
config = ConfigObj(total_path)
141
158
def __init__(self):
142
159
if hasattr(self, 'data_dir'):
143
160
#Borg has already been initialized
154
171
if not os.path.exists(self.data_dir):
155
172
os.makedirs(self.data_dir)
156
173
if not os.path.exists(self.conf_dir + self.CONF_FILE):
157
f = open(self.conf_dir + self.CONF_FILE, "w")
174
open(self.conf_dir + self.CONF_FILE, "w").close()
159
175
if not os.path.exists(self.conf_dir + self.TASK_CONF_FILE):
160
f = open(self.conf_dir + self.TASK_CONF_FILE, "w")
162
for file in [self.conf_dir + self.CONF_FILE,
176
open(self.conf_dir + self.TASK_CONF_FILE, "w").close()
177
for conf_file in [self.conf_dir + self.CONF_FILE,
163
178
self.conf_dir + self.TASK_CONF_FILE]:
164
if not ((file, os.R_OK) and os.access(file, os.W_OK)):
179
if not os.access(conf_file, os.R_OK | os.W_OK):
165
180
raise Exception("File " + file + \
166
181
" is a configuration file for gtg, but it "
167
182
"cannot be read or written. Please check it")
168
self.conf_dict = ConfigObj(self.conf_dir + self.CONF_FILE)
169
self.task_conf_dict = ConfigObj(self.conf_dir + self.TASK_CONF_FILE)
183
self.conf_dict = self.check_config_file(self.CONF_FILE)
184
self.task_conf_dict = self.check_config_file(self.TASK_CONF_FILE)
172
187
''' Saves the configuration of CoreConfig '''
173
188
self.conf_dict.write()
179
194
return SubConfig(name, self.conf_dict[name])
181
196
def get_icons_directories(self):
183
Returns the directories containing the icons
185
return [GTG.DATA_DIR, os.path.join(GTG.DATA_DIR, "icons")]
197
""" Returns the directories containing the icons """
198
icons_dirs = [os.path.join(dir, 'gtg/icons') for dir in xdg_data_dirs]
199
icons_dirs.append(os.path.join(GTG.DATA_DIR, "icons"))
200
icons_dirs.append(GTG.DATA_DIR)
187
203
def get_data_dir(self):
188
204
return self.data_dir