~ubuntu-branches/ubuntu/precise/gnome-do/precise-proposed

« back to all changes in this revision

Viewing changes to Do/src/Do.UI/GeneralPreferencesWidget.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2008-09-14 10:09:40 UTC
  • mto: (0.1.8 sid)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20080914100940-kyghudg7py14bu2z
Tags: upstream-0.6.0.0
ImportĀ upstreamĀ versionĀ 0.6.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// GeneralPreferencesWidget.cs
 
2
//
 
3
// GNOME Do is the legal property of its developers. Please refer to the
 
4
// COPYRIGHT file distributed with this source distribution.
 
5
//
 
6
// This program is free software: you can redistribute it and/or modify
 
7
// it under the terms of the GNU General Public License as published by
 
8
// the Free Software Foundation, either version 3 of the License, or
 
9
// (at your option) any later version.
 
10
//
 
11
// This program is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
// GNU General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public License
 
17
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
using System;
 
20
using System.IO;
 
21
using System.Reflection;
 
22
 
 
23
using Do;
 
24
using Gtk;
 
25
 
 
26
namespace Do.UI
 
27
{
 
28
    [System.ComponentModel.Category("Do")]
 
29
    [System.ComponentModel.ToolboxItem(true)]
 
30
    public partial class GeneralPreferencesWidget : Bin, Addins.IConfigurable
 
31
    {
 
32
        const string AutostartAttribute = "X-GNOME-Autostart-enabled";
 
33
        
 
34
        string AutostartDir {
 
35
                        get {
 
36
                                return Paths.Combine (Paths.UserHome, ".config/autostart");
 
37
                        }
 
38
                }
 
39
 
 
40
        string AutostartFile {
 
41
                        get {
 
42
                                return Paths.Combine (AutostartDir, "gnome-do.desktop");
 
43
                        }
 
44
                }
 
45
                
 
46
                new public string Name {
 
47
                        get { return "General"; }
 
48
                }
 
49
                
 
50
        public string Description {
 
51
                get { return ""; }
 
52
        }
 
53
        
 
54
        public string Icon {
 
55
                get { return ""; }
 
56
        }
 
57
        
 
58
        public string[] Themes {
 
59
                get {
 
60
                        return new string[] {
 
61
                                "Classic",
 
62
                                "Glass Frame",
 
63
                                "Mini",
 
64
                        };
 
65
                }
 
66
        }
 
67
                
 
68
        public GeneralPreferencesWidget ()
 
69
        {
 
70
                int themeI;
 
71
                
 
72
            Build ();
 
73
            
 
74
                        // Setup theme combo
 
75
            themeI = Array.IndexOf (Themes, Do.Preferences.Theme);
 
76
            themeI = themeI >= 0 ? themeI : 0;
 
77
            theme_combo.Active = themeI;
 
78
 
 
79
                        // Setup checkboxes
 
80
                hide_check.Active = Do.Preferences.QuietStart;
 
81
                login_check.Active = AutostartEnabled;
 
82
                notification_check.Active = Do.Preferences.StatusIconVisible;
 
83
                        pin_check.Active = Do.Preferences.AlwaysShowResults;
 
84
        }
 
85
        
 
86
        public Bin GetConfiguration ()
 
87
        {
 
88
                return this;
 
89
        }
 
90
        
 
91
        /// <value>
 
92
        /// This property sacrifies much efficiency to eschew the gnomedesktop
 
93
        /// dependency and to work more reliably.
 
94
        /// </value>
 
95
        protected bool AutostartEnabled {
 
96
                get {
 
97
                        try {
 
98
                                return File.Exists (AutostartFile) &&
 
99
                                        !File.ReadAllText (AutostartFile).Contains (
 
100
                                                        AutostartAttribute + "=false");
 
101
                                } catch (Exception e) {
 
102
                                        Log.Error ("Failed to get autostart: {0}", e.Message);
 
103
                                }
 
104
                                return false;
 
105
                        }
 
106
                        set {
 
107
                                try {
 
108
                                        if (File.Exists (AutostartFile))
 
109
                                                File.Delete (AutostartFile);
 
110
                                        if (value) {
 
111
                                                Directory.CreateDirectory (AutostartDir);
 
112
                                                Stream s = Assembly.GetExecutingAssembly ()
 
113
                                                        .GetManifestResourceStream ("gnome-do.desktop");
 
114
                                                using (StreamReader sr = new StreamReader (s))
 
115
                                                        File.AppendAllText (AutostartFile, sr.ReadToEnd ());
 
116
                                                
 
117
                                        }
 
118
                                } catch (Exception e) {
 
119
                                        Log.Error ("Failed to set autostart: {0}", e.Message);
 
120
                                }
 
121
                        }
 
122
        }
 
123
 
 
124
        protected virtual void OnLoginCheckClicked (object sender, EventArgs e)
 
125
        {
 
126
                AutostartEnabled = login_check.Active;
 
127
        }
 
128
 
 
129
        protected virtual void OnHideCheckClicked (object sender, EventArgs e)
 
130
        {
 
131
                Do.Preferences.QuietStart = hide_check.Active;
 
132
        }
 
133
 
 
134
        protected virtual void OnThemeComboChanged (object sender, EventArgs e)
 
135
        {
 
136
                Do.Preferences.Theme = theme_combo.ActiveText;
 
137
        }
 
138
 
 
139
        protected virtual void OnNotificationCheckClicked (object sender, System.EventArgs e)
 
140
        {       
 
141
                NotificationIcon trayIcon = Do.NotificationIcon;
 
142
                Do.Preferences.StatusIconVisible = notification_check.Active;
 
143
                if (notification_check.Active)
 
144
                        trayIcon.Show ();
 
145
                else
 
146
                        trayIcon.Hide ();
 
147
        }
 
148
 
 
149
        protected virtual void OnPinChecklicked (object sender, System.EventArgs e)
 
150
        {
 
151
                        Do.Preferences.AlwaysShowResults = pin_check.Active;
 
152
        }
 
153
    }
 
154
}