File: syncpreferences.py

package info (click to toggle)
taskcoach 1.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,496 kB
  • ctags: 17,810
  • sloc: python: 72,170; makefile: 254; ansic: 120; xml: 29; sh: 16
file content (154 lines) | stat: -rw-r--r-- 7,101 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -*- coding: utf-8 -*-

'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2014 Task Coach developers <developers@taskcoach.org>

Task Coach is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Task Coach is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

import wx
from taskcoachlib.gui.dialog.preferences import SettingsPageBase
from taskcoachlib import widgets, operating_system
from taskcoachlib.i18n import _


class SyncMLBasePage(SettingsPageBase):
    def __init__(self, iocontroller=None, *args, **kwargs):
        super(SyncMLBasePage, self).__init__(*args, **kwargs)

        self.iocontroller = iocontroller
        self.config = iocontroller.syncMLConfig()

    def get(self, section, name):
        if section == 'access':
            if name in [ 'syncUrl' ]:
                return str(self.config.children()[0]['spds']['syncml']['Conn'].get(name))
            elif name in [ 'username' ]:
                return str(self.config.children()[0]['spds']['syncml']['Auth'].get(name))

        elif section == 'task':
            for child in self.config.children()[0]['spds']['sources'].children():
                if child.name.endswith('Tasks'):
                    return child.get(name)            

        elif section == 'note':
            for child in self.config.children()[0]['spds']['sources'].children():
                if child.name.endswith('Notes'):
                    return child.get(name)
        return ''

    def set(self, section, name, value):
        if section == 'access':
            if name in [ 'syncUrl' ]:
                self.config.children()[0]['spds']['syncml']['Conn'].set(name, value)
            elif name in [ 'username' ]:
                self.config.children()[0]['spds']['syncml']['Auth'].set(name, value)

        elif section == 'task':
            for child in self.config.children()[0]['spds']['sources'].children():
                if child.name.endswith('Tasks'):
                    child.set(name, value)
                    break

        elif section == 'note':
            for child in self.config.children()[0]['spds']['sources'].children():
                if child.name.endswith('Notes'):
                    child.set(name, value)
                    break

    def ok(self):
        super(SyncMLBasePage, self).ok()

        self.iocontroller.setSyncMLConfig(self.config)


class SyncMLAccessPage(SyncMLBasePage):
    def __init__(self, *args, **kwargs):
        super(SyncMLAccessPage, self).__init__(*args, **kwargs)

        choice = self.addChoiceSetting(None, 'preset', _('SyncML server'), '',
                                       [('0', _('Custom')),
                                        ('1', _('MemoToo (http://www.memotoo.com/)')),
                                        ('2', _('Horde-based'))])[0]
        wx.EVT_CHOICE(choice, wx.ID_ANY, self.OnPresetChanged)

        self.addTextSetting('access', 'syncUrl', _('SyncML server URL'))
        self.addTextSetting('access', 'username', _('User name/ID'))

        checkBox = self.addBooleanSetting('task', 'dosync', _('Enable tasks synchronization'))
        wx.EVT_CHECKBOX(checkBox, wx.ID_ANY, self.OnSyncTaskChanged)
        self.addTextSetting('task', 'uri', _('Tasks database name'))
        self.addChoiceSetting('task', 'preferredsyncmode', _('Preferred synchronization mode'), '',
                              [('TWO_WAY', _('Two way')),
                               ('SLOW', _('Slow')),
                               ('ONE_WAY_FROM_CLIENT', _('One way from client')),
                               ('REFRESH_FROM_CLIENT', _('Refresh from client')),
                               ('ONE_WAY_FROM_SERVER', _('One way from server')),
                               ('REFRESH_FROM_SERVER', _('Refresh from server'))])
        self.enableTextSetting('task', 'uri', self.getboolean('task', 'dosync'))
        self.enableChoiceSetting('task', 'preferredsyncmode', self.getboolean('task', 'dosync'))

        checkBox = self.addBooleanSetting('note', 'dosync', _('Enable notes synchronization'))
        wx.EVT_CHECKBOX(checkBox, wx.ID_ANY, self.OnSyncNoteChanged)
        self.addTextSetting('note', 'uri', _('Notes database name'))
        self.addChoiceSetting('note', 'preferredsyncmode', _('Preferred synchronization mode'), '',
                              [('TWO_WAY', _('Two way')),
                               ('SLOW', _('Slow')),
                               ('ONE_WAY_FROM_CLIENT', _('One way from client')),
                               ('REFRESH_FROM_CLIENT', _('Refresh from client')),
                               ('ONE_WAY_FROM_SERVER', _('One way from server')),
                               ('REFRESH_FROM_SERVER', _('Refresh from server'))])
        self.enableTextSetting('note', 'uri', self.getboolean('note', 'dosync'))
        self.enableChoiceSetting('note', 'preferredsyncmode', self.getboolean('note', 'dosync'))

        self.fit()

    def OnPresetChanged(self, event):
        if event.GetInt() == 1:
            self.setTextSetting('access', 'syncUrl', 'http://sync.memotoo.com/syncml')
            self.setTextSetting('task', 'uri', 'task')
            self.setTextSetting('note', 'uri', 'note')
        elif event.GetInt() == 2:
            self.setTextSetting('access', 'syncUrl', 'http://<hostname_and_path>/rpc.php')
            self.setTextSetting('task', 'uri', 'tasks')
            self.setTextSetting('note', 'uri', 'notes')

    def OnSyncTaskChanged(self, event):
        self.enableTextSetting('task', 'uri', event.IsChecked())
        self.enableChoiceSetting('task', 'preferredsyncmode', event.IsChecked())

    def OnSyncNoteChanged(self, event):
        self.enableTextSetting('note', 'uri', event.IsChecked())
        self.enableChoiceSetting('note', 'preferredsyncmode', event.IsChecked())


class SyncMLPreferences(widgets.NotebookDialog):
    def __init__(self, iocontroller=None, *args, **kwargs):
        self.iocontroller = iocontroller
        super(SyncMLPreferences, self).__init__(bitmap='wrench_icon', *args,
                                                **kwargs)
        self.SetSize((700, -1))
        if operating_system.isMac():
            self.CentreOnParent()

    def addPages(self):
        self._interior.SetMinSize((550, 400))
        kwargs = dict(parent=self._interior, columns=3,
                      iocontroller=self.iocontroller)
        # pylint: disable=W0142
        pages = [(SyncMLAccessPage(growableColumn=1, **kwargs), _('Access'), 'earth_blue_icon')]

        for page, title, bitmap in pages:
            self._interior.AddPage(page, title, bitmap=bitmap)