1
// GeneralPreferencesWidget.cs
3
// GNOME Do is the legal property of its developers. Please refer to the
4
// COPYRIGHT file distributed with this source distribution.
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.
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.
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/>.
21
using System.Reflection;
28
[System.ComponentModel.Category("Do")]
29
[System.ComponentModel.ToolboxItem(true)]
30
public partial class GeneralPreferencesWidget : Bin, Addins.IConfigurable
32
const string AutostartAttribute = "X-GNOME-Autostart-enabled";
36
return Paths.Combine (Paths.UserHome, ".config/autostart");
40
string AutostartFile {
42
return Paths.Combine (AutostartDir, "gnome-do.desktop");
46
new public string Name {
47
get { return "General"; }
50
public string Description {
58
public string[] Themes {
68
public GeneralPreferencesWidget ()
75
themeI = Array.IndexOf (Themes, Do.Preferences.Theme);
76
themeI = themeI >= 0 ? themeI : 0;
77
theme_combo.Active = themeI;
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;
86
public Bin GetConfiguration ()
92
/// This property sacrifies much efficiency to eschew the gnomedesktop
93
/// dependency and to work more reliably.
95
protected bool AutostartEnabled {
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);
108
if (File.Exists (AutostartFile))
109
File.Delete (AutostartFile);
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 ());
118
} catch (Exception e) {
119
Log.Error ("Failed to set autostart: {0}", e.Message);
124
protected virtual void OnLoginCheckClicked (object sender, EventArgs e)
126
AutostartEnabled = login_check.Active;
129
protected virtual void OnHideCheckClicked (object sender, EventArgs e)
131
Do.Preferences.QuietStart = hide_check.Active;
134
protected virtual void OnThemeComboChanged (object sender, EventArgs e)
136
Do.Preferences.Theme = theme_combo.ActiveText;
139
protected virtual void OnNotificationCheckClicked (object sender, System.EventArgs e)
141
NotificationIcon trayIcon = Do.NotificationIcon;
142
Do.Preferences.StatusIconVisible = notification_check.Active;
143
if (notification_check.Active)
149
protected virtual void OnPinChecklicked (object sender, System.EventArgs e)
151
Do.Preferences.AlwaysShowResults = pin_check.Active;