~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do/src/CorePreferences.cs

  • Committer: Hardeep S
  • Date: 2009-06-23 05:57:47 UTC
  • Revision ID: ootz0rz@gmail.com-20090623055747-3srobsuq3q8wbn81
initial adding of Do core stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* CorePreferences.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this
 
5
 * source distribution.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
using System;
 
22
using System.Linq;
 
23
using System.Collections;
 
24
using System.Collections.Generic;
 
25
using Env = System.Environment;
 
26
 
 
27
using Do.Platform;
 
28
 
 
29
namespace Do
 
30
{
 
31
        class CorePreferences  {
 
32
 
 
33
                #region Key constants and default values
 
34
                const string ThemeKey = "Theme";
 
35
                const string QuietStartKey = "QuietStart";
 
36
                const string StartAtLoginKey = "StartAtLogin";
 
37
                const string AlwaysShowResultsKey = "AlwaysShowResults";
 
38
 
 
39
                const string ThemeDefaultValue = "Classic Interface";
 
40
                const bool QuietStartDefaultValue = false;
 
41
                const bool StartAtLoginDefaultValue = false;
 
42
                const bool AlwaysShowResultsDefaultValue = false;
 
43
                const string TextModeKeybindingDefaultValue = "period";
 
44
                const string SummonKeybindingDefaultValue = "<Super>space";
 
45
 
 
46
                const string DebugOption = "--debug";
 
47
                const string LogToFileOption = "--log-to-file";
 
48
                
 
49
 
 
50
                #endregion
 
51
 
 
52
                public event EventHandler<PreferencesChangedEventArgs> ThemeChanged;
 
53
                
 
54
                IPreferences Preferences { get; set; }
 
55
                
 
56
                public CorePreferences ()
 
57
                {
 
58
                        Preferences = Services.Preferences.Get<CorePreferences> ();
 
59
                        Preferences.PreferencesChanged += PreferencesChanged;
 
60
                }
 
61
                
 
62
                public bool WriteLogToFile {
 
63
                        get { return HasOption (LogToFileOption); }
 
64
                }
 
65
                
 
66
                public static bool PeekDebug {
 
67
                        get { return HasOption (DebugOption); }
 
68
                }
 
69
 
 
70
                public bool Debug {
 
71
                        get { return CorePreferences.PeekDebug; }
 
72
                }
 
73
 
 
74
                public string Theme {
 
75
                        get { return Preferences.Get (ThemeKey, ThemeDefaultValue); }
 
76
                        set { Preferences.Set (ThemeKey, value); }
 
77
                }
 
78
 
 
79
                public bool QuietStart {
 
80
                        get { return Preferences.Get (QuietStartKey, QuietStartDefaultValue); }
 
81
                        set { Preferences.Set (QuietStartKey, value); }
 
82
                }
 
83
 
 
84
                public bool StartAtLogin {
 
85
                        get { return Preferences.Get(StartAtLoginKey, StartAtLoginDefaultValue); }
 
86
                        set { Preferences.Set (StartAtLoginKey, value); }
 
87
                }
 
88
                
 
89
                public bool AlwaysShowResults {
 
90
                        get { return Preferences.Get (AlwaysShowResultsKey, AlwaysShowResultsDefaultValue); }
 
91
                        set { Preferences.Set (AlwaysShowResultsKey, value); }
 
92
                }
 
93
                
 
94
                static bool HasOption (string option)
 
95
                {
 
96
                        return Env.GetCommandLineArgs ().Contains (option);
 
97
                }
 
98
 
 
99
 
 
100
                void PreferencesChanged (object sender, PreferencesChangedEventArgs e)
 
101
                {
 
102
                        switch (e.Key) {
 
103
                        case ThemeKey:
 
104
                                if (ThemeChanged != null)
 
105
                                        ThemeChanged (this, e);
 
106
                                break;
 
107
                        }
 
108
                }
 
109
        }
 
110
}