~ubuntu-branches/debian/sid/gtg/sid

« back to all changes in this revision

Viewing changes to GTG/core/__init__.py

  • Committer: Package Import Robot
  • Author(s): Luca Falavigna
  • Date: 2013-05-05 14:23:30 UTC
  • mfrom: (17.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130505142330-a1lmq91yf5ld4zoq
Tags: 0.3-2
* Upload to unstable.
* debian/control:
  - Use canonical URIs for VCS fields
* debian/install:
  - Install bash-completion script.
* debian/links:
  - gtcli link must point to gtcli, not gtg.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
5
5
#
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
17
17
# this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
# -----------------------------------------------------------------------------
19
19
 
20
 
 
21
20
"""
22
21
GTG's core functionality.
23
22
 
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)
37
 
 
38
36
"""
39
37
 
40
 
 
41
 
#=== IMPORT ====================================================================
 
38
#=== IMPORT ===================================================================
 
39
from configobj         import ConfigObj, ConfigObjError
 
40
from xdg.BaseDirectory import xdg_data_home, xdg_config_home, xdg_data_dirs
42
41
import os
43
 
from xdg.BaseDirectory import xdg_data_home, xdg_config_home
44
 
from configobj         import ConfigObj
 
42
 
 
43
from GTG.tools.borg   import Borg
45
44
from GTG.tools.testingmode import TestingMode
46
 
 
47
45
import GTG
48
 
from GTG.tools.logger import Log
49
 
from GTG.tools.borg   import Borg
50
 
 
51
46
 
52
47
DEFAULTS = {
53
48
'browser': {
54
 
            'bg_color_enable': False,
 
49
            "bg_color_enable": True,
55
50
            "contents_preview_enable": False,
56
51
            'tag_pane': False,
57
52
            "sidebar_width": 120,
59
54
            'bottom_pane_position': 300,
60
55
            'toolbar': True,
61
56
            'quick_add': True,
62
 
            "bg_color_enable": True,
63
57
            'collapsed_tasks': [],
64
 
            'collapsed_tags': [],
 
58
            'expanded_tags': [],
65
59
            'view': 'default',
66
60
            "opened_tasks": [],
67
61
            'width': 400,
68
62
            'height': 400,
 
63
            'max': False,
69
64
            'x_pos': 10,
70
65
            'y_pos': 10,
71
66
            'tasklist_sort_column': 5,
72
67
            'tasklist_sort_order': 1,
 
68
            "font_name": ""
 
69
            },
 
70
'tag_editor': {
 
71
            "custom_colors": [],
73
72
            }
74
73
}
75
74
 
86
85
#
87
86
#Currently done : browser
88
87
#Todo : editor, plugins
 
88
 
89
89
class SubConfig():
 
90
 
90
91
    def __init__(self, name, conf_dic):
91
92
        self.__name = name
92
93
        self.__conf = conf_dic
111
112
            toreturn = self.__defaults[name]
112
113
            self.__conf[name] = toreturn
113
114
        else:
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" % (
 
116
                name, self.__name)
115
117
            toreturn = None
116
118
        return toreturn
117
119
 
120
122
        # Save immediately
121
123
        self.__conf.parent.write()
122
124
 
 
125
    def set_lst(self, name, value_lst):
 
126
        self.__conf[name] = [str(s) for s in value_lst]
 
127
        # Save immediately
 
128
        self.__conf.parent.write()
 
129
 
123
130
 
124
131
class CoreConfig(Borg):
125
132
    #The projects and tasks are of course DATA !
129
136
    CONF_FILE = "gtg.conf"
130
137
    TASK_CONF_FILE = "tasks.conf"
131
138
    conf_dict = None
132
 
    #DBUS
 
139
    #DBus
133
140
    BUSNAME = "org.gnome.GTG"
134
141
    BUSINTERFACE = "/org/gnome/GTG"
135
142
    #TAGS
138
145
    SEP_TAG = "gtg-tags-sep"
139
146
    SEARCH_TAG = "search"
140
147
 
 
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    
 
151
        try:
 
152
            config = ConfigObj(total_path)
 
153
        except ConfigObjError:
 
154
            open(total_path, "w").close()
 
155
            config = ConfigObj(total_path)            
 
156
        return config
 
157
 
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")
158
 
            f.close()
 
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")
161
 
            f.close()
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)
170
 
 
 
183
        self.conf_dict = self.check_config_file(self.CONF_FILE)
 
184
        self.task_conf_dict = self.check_config_file(self.TASK_CONF_FILE)    
 
185
        
171
186
    def save(self):
172
187
        ''' Saves the configuration of CoreConfig '''
173
188
        self.conf_dict.write()
179
194
        return SubConfig(name, self.conf_dict[name])
180
195
 
181
196
    def get_icons_directories(self):
182
 
        '''
183
 
        Returns the directories containing the icons
184
 
        '''
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)
 
201
        return icons_dirs
186
202
 
187
203
    def get_data_dir(self):
188
204
        return self.data_dir