~ubuntu-branches/ubuntu/wily/gnome-do/wily

« back to all changes in this revision

Viewing changes to Do.Interface.Linux.Docky/src/Docky.Utilities/DockPreferences.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2011-02-15 21:50:02 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110215215002-1j8ylb69o15asb06
Tags: 0.8.4-0ubuntu1
* The Race Against FF upload.  Merge from unreleased Debian git.
  Remaining Ubuntu changes:
  + debian/patches/05_disable_resize_grips.patch.diff:
    Disable resize handles for the Do windows.
  + debian/control:
    Bump gtk# build dep for HasResizeGrip API.
* New Debian changes:
* The long fortold release
  + Fixes a threadsafety issue resulting in 100% CPU usage (Closes: 565591,
    LP: #450852).
  + Proxies all keyring calls to the GTK main thread, as required by the new
    gnome-keyring (Closes: 603876, LP: #553643)
* debian/patches/00_bundledlibs.dpatch:
* debian/rules:
  + Upstream has dropped bundled gmcs binary; now 100% DFSG-free, so we don't
    have to repack the tarball or patch the buildsystem.
* debian/patches/03_disable_docky.dpatch:
  + Drop.  Docky is now gone in the upstream tarball.
* debian/rules:
* debian/control:
* debian/patches/*:
  + Switch to quilt to harmonise with other pkg-cli-* packages.
* debian/control:
  + Drop recommends on gnome-do-docklets.  Docky is now a separate package,
    so the docklets are useless for Do.
  + Bump Breaks on gnome-do-plugins to 0.8.3.  Do no longer provides the Wink
    library, which has been imported into the 0.8.3 do-plugins sources.
  + Bump standards-version; no changes needed.
  + Migrate to git and update VCS fields appropriately

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Preferences.cs
2
 
// 
3
 
// Copyright (C) 2008 GNOME Do
4
 
//
5
 
// This program is free software: you can redistribute it and/or modify
6
 
// it under the terms of the GNU General Public License as published by
7
 
// the Free Software Foundation, either version 3 of the License, or
8
 
// (at your option) any later version.
9
 
//
10
 
// This program is distributed in the hope that it will be useful,
11
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
// GNU General Public License for more details.
14
 
//
15
 
// You should have received a copy of the GNU General Public License
16
 
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
//
18
 
 
19
 
using System;
20
 
using System.Collections.Generic;
21
 
using System.IO;
22
 
using System.Linq;
23
 
using System.Runtime.Serialization;
24
 
using System.Runtime.Serialization.Formatters.Binary;
25
 
 
26
 
using Do.Interface;
27
 
using Do.Universe;
28
 
using Do.Platform;
29
 
 
30
 
namespace Docky.Utilities
31
 
{
32
 
        
33
 
        public class DockPreferences
34
 
        {
35
 
                public static event Action AutohideChanged;
36
 
                public static event Action IconSizeChanged;
37
 
                public static event Action AutomaticIconsChanged;
38
 
                public static event Action MonitorChanged;
39
 
                public static event Action AllowOverlapChanged;
40
 
                public static event Action OrientationChanged;
41
 
        
42
 
                public const int IconBorderWidth = 2;
43
 
                public const string HighlightFormat = "<span foreground=\"#5599ff\">{0}</span>";
44
 
                
45
 
                static IPreferences prefs = Services.Preferences.Get<DockPreferences> ();
46
 
                const int DefaultIconSize = 64;
47
 
                
48
 
                static DockPreferences ()
49
 
                {
50
 
                        if (System.IO.Directory.Exists ("/sys/module/nvidia")) {
51
 
                                // new nvidia drivers have the nasty habbit of migrating out pixmaps out of video memory after 10
52
 
                                // minutes or so, so if we recreate them more frequently than that, it doesn't do that to us.
53
 
                                GLib.Timeout.Add (5 * 60 * 1000, delegate {
54
 
                                        if (IconSizeChanged != null)
55
 
                                                IconSizeChanged ();
56
 
                                        return true;
57
 
                                });
58
 
                        }
59
 
                }
60
 
                
61
 
                public static int TextWidth {
62
 
                        get { return 350; }
63
 
                }
64
 
                
65
 
                public static int ZoomSize {
66
 
                        get { return (int) (330 * (IconSize / (double) DefaultIconSize)); }
67
 
                }
68
 
 
69
 
                static bool indicate_multiple_windows = prefs.Get ("IndicateMultipleWindows", false);
70
 
                public static bool IndicateMultipleWindows {
71
 
                        get { return indicate_multiple_windows; }
72
 
                        set { 
73
 
                                prefs.Set ("IndicateMultipleWindows", value); 
74
 
                                indicate_multiple_windows = value;
75
 
                        }
76
 
                }
77
 
                
78
 
                static double zoom_percent = Math.Round (prefs.Get ("ZoomPercent", 2.0), 1);
79
 
                public static double ZoomPercent {
80
 
                        get { return ZoomEnabled ? zoom_percent : 1; }
81
 
                        set {
82
 
                                if (value < 1)
83
 
                                        value = 1;
84
 
                                prefs.Set ("ZoomPercent", value);
85
 
                                zoom_percent = value;
86
 
                                if (IconSizeChanged != null)
87
 
                                        IconSizeChanged ();
88
 
                        }
89
 
                }
90
 
                
91
 
                static bool enable_zoom = prefs.Get ("EnableZoom", true);
92
 
                public static bool ZoomEnabled {
93
 
                        get { return enable_zoom; }
94
 
                        set {
95
 
                                prefs.Set ("EnableZoom", value);
96
 
                                enable_zoom = value;
97
 
                                if (IconSizeChanged != null)
98
 
                                        IconSizeChanged ();
99
 
                        }
100
 
                }
101
 
                
102
 
                public static int FullIconSize {
103
 
                        get {
104
 
                                return (int) (IconSize*IconQuality);
105
 
                        }
106
 
                }
107
 
                
108
 
                static int max_icon_size = 128;
109
 
                public static int MaxIconSize {
110
 
                        get { return max_icon_size; }
111
 
                        set {
112
 
                                int tmp = IconSize;
113
 
                                max_icon_size = value;
114
 
                                if (tmp != IconSize && IconSizeChanged != null)
115
 
                                        IconSizeChanged ();
116
 
                        }
117
 
                }
118
 
                
119
 
                static int icon_size = prefs.Get ("IconSize", DefaultIconSize);
120
 
                public static int IconSize {
121
 
                        get { return Math.Min (icon_size, MaxIconSize); }
122
 
                        set {
123
 
                                if (value < 24)
124
 
                                        value = 24;
125
 
                                if (value > 128)
126
 
                                        value = 128;
127
 
                                
128
 
                                if (value == icon_size)
129
 
                                        return;
130
 
                                
131
 
                                prefs.Set ("IconSize", value); 
132
 
                                icon_size = value;
133
 
                                if (IconSizeChanged != null)
134
 
                                        IconSizeChanged ();
135
 
                        }
136
 
                }
137
 
                
138
 
                /// <summary>
139
 
                /// Currently returns ZoomPercent.  This is useful in the future case where we wish to optimize for best
140
 
                /// looking icons by picking "good" sizes.  This is not implemented yet however.
141
 
                /// </summary>
142
 
                public static double IconQuality {
143
 
                        get { return ZoomPercent; }
144
 
                }
145
 
                
146
 
                public static bool AutoHide {
147
 
                        get { return AutohideType != AutohideType.None; }
148
 
                }
149
 
                
150
 
                static TimeSpan summon_time = new TimeSpan (0, 0, 0, 0, prefs.Get ("SummonTime", 100));
151
 
                public static TimeSpan SummonTime {
152
 
                        get { return summon_time; }
153
 
                        set {
154
 
                                prefs.Set ("SummonTime", value.TotalMilliseconds);
155
 
                                summon_time = value;
156
 
                        }
157
 
                }
158
 
                
159
 
                static int automatic_icons = prefs.Get ("AutomaticIcons", 5);
160
 
                public static int AutomaticIcons {
161
 
                        get { return automatic_icons; }
162
 
                        set {
163
 
                                if (value < 0)
164
 
                                        value = 0;
165
 
                                prefs.Set ("AutomaticIcons", value);
166
 
                                automatic_icons = value;
167
 
                                
168
 
                                if (AutomaticIconsChanged != null)
169
 
                                        AutomaticIconsChanged ();
170
 
                        }
171
 
                }
172
 
 
173
 
                static int monitor = Math.Max (0, prefs.Get ("Monitor", 0));
174
 
                public static int Monitor {
175
 
                        get {
176
 
                                monitor = Math.Max (0, Math.Min (monitor, Gdk.Screen.Default.NMonitors - 1));
177
 
                                return monitor;
178
 
                        }
179
 
                        set {
180
 
                                if (monitor == value)
181
 
                                        return;
182
 
                                
183
 
                                if (value >= Gdk.Screen.Default.NMonitors || value < 0)
184
 
                                        value = 0;
185
 
                                monitor = value;
186
 
                                prefs.Set ("Monitor", value);
187
 
 
188
 
                                Interface.LayoutUtils.Recalculate ();
189
 
                                if (MonitorChanged != null)
190
 
                                        MonitorChanged ();
191
 
                        }
192
 
                }
193
 
 
194
 
                static DockOrientation orientation = (DockOrientation) Enum.Parse (typeof (DockOrientation), prefs.Get ("Orientation", DockOrientation.Bottom.ToString ()));
195
 
                public static DockOrientation Orientation {
196
 
                        get {
197
 
                                if (orientation != DockOrientation.Top && orientation != DockOrientation.Bottom)
198
 
                                        orientation = DockOrientation.Bottom;
199
 
                                
200
 
                                return orientation;
201
 
                        }
202
 
                        set {
203
 
                                if (orientation == value)
204
 
                                        return;
205
 
                                orientation = value;
206
 
                                prefs.Set ("Orientation", value.ToString ());
207
 
                                if (OrientationChanged != null)
208
 
                                        OrientationChanged ();
209
 
                        }
210
 
                }
211
 
                
212
 
                static AutohideType hide = (AutohideType) Enum.Parse (typeof (AutohideType), prefs.Get ("AutohideType", AutohideType.None.ToString ()));
213
 
                public static AutohideType AutohideType {
214
 
                        get { return hide; }
215
 
                        set {
216
 
                                if (hide == value)
217
 
                                        return;
218
 
                                hide = value;
219
 
                                prefs.Set ("AutohideType", value.ToString ());
220
 
                                if (AutohideChanged != null)
221
 
                                        AutohideChanged ();
222
 
                        }
223
 
                }
224
 
 
225
 
                #region blacklists
226
 
                static List<string> item_blacklist = DeserializeBlacklist ();
227
 
                public static IEnumerable<string> ItemBlacklist {
228
 
                        get {
229
 
                                return item_blacklist;
230
 
                        }
231
 
                }
232
 
                
233
 
                public static void AddBlacklistItem (string item) 
234
 
                {
235
 
                        item_blacklist.Add (item);
236
 
                        SerializeBlacklist ();
237
 
                }
238
 
                
239
 
                public static void RemoveBlacklistItem (string item)
240
 
                {
241
 
                        item_blacklist.Remove (item);
242
 
                        SerializeBlacklist ();
243
 
                }
244
 
                
245
 
                public static void ClearBlacklist ()
246
 
                {
247
 
                        item_blacklist.Clear ();
248
 
                        SerializeBlacklist ();
249
 
                }
250
 
 
251
 
                static string BlacklistFile {
252
 
                        get {
253
 
                                return Path.Combine (Services.Paths.UserDataDirectory, "dock_blacklist");
254
 
                        }
255
 
                }
256
 
                
257
 
                static List<string> DeserializeBlacklist ()
258
 
                {
259
 
                        string file = BlacklistFile;
260
 
                        if (!File.Exists (file))
261
 
                                return new List<string> ();
262
 
                        
263
 
                        try {
264
 
                                Stream s = File.OpenRead (file);
265
 
                                BinaryFormatter bf = new BinaryFormatter ();
266
 
                                List<string> out_list = bf.Deserialize (s) as List<string>;
267
 
                                s.Close ();
268
 
                                s.Dispose ();
269
 
                                return out_list;
270
 
                        } catch { return new List<string> (); }
271
 
                }
272
 
                
273
 
                static void SerializeBlacklist ()
274
 
                {
275
 
                        string file = BlacklistFile;
276
 
                        
277
 
                        try {
278
 
                                Stream s = File.Open (file, FileMode.OpenOrCreate);
279
 
                                BinaryFormatter bf = new BinaryFormatter ();
280
 
                                bf.Serialize (s, item_blacklist);
281
 
                                s.Close ();
282
 
                                s.Dispose ();
283
 
                        } catch { }
284
 
                }
285
 
                #endregion
286
 
        }
287
 
}