3
// Copyright (C) 2008 GNOME Do
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.
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.
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/>.
20
using System.Collections.Generic;
23
using System.Runtime.Serialization;
24
using System.Runtime.Serialization.Formatters.Binary;
30
namespace Docky.Utilities
33
public class DockPreferences
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;
42
public const int IconBorderWidth = 2;
43
public const string HighlightFormat = "<span foreground=\"#5599ff\">{0}</span>";
45
static IPreferences prefs = Services.Preferences.Get<DockPreferences> ();
46
const int DefaultIconSize = 64;
48
static DockPreferences ()
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)
61
public static int TextWidth {
65
public static int ZoomSize {
66
get { return (int) (330 * (IconSize / (double) DefaultIconSize)); }
69
static bool indicate_multiple_windows = prefs.Get ("IndicateMultipleWindows", false);
70
public static bool IndicateMultipleWindows {
71
get { return indicate_multiple_windows; }
73
prefs.Set ("IndicateMultipleWindows", value);
74
indicate_multiple_windows = value;
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; }
84
prefs.Set ("ZoomPercent", value);
86
if (IconSizeChanged != null)
91
static bool enable_zoom = prefs.Get ("EnableZoom", true);
92
public static bool ZoomEnabled {
93
get { return enable_zoom; }
95
prefs.Set ("EnableZoom", value);
97
if (IconSizeChanged != null)
102
public static int FullIconSize {
104
return (int) (IconSize*IconQuality);
108
static int max_icon_size = 128;
109
public static int MaxIconSize {
110
get { return max_icon_size; }
113
max_icon_size = value;
114
if (tmp != IconSize && IconSizeChanged != null)
119
static int icon_size = prefs.Get ("IconSize", DefaultIconSize);
120
public static int IconSize {
121
get { return Math.Min (icon_size, MaxIconSize); }
128
if (value == icon_size)
131
prefs.Set ("IconSize", value);
133
if (IconSizeChanged != null)
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.
142
public static double IconQuality {
143
get { return ZoomPercent; }
146
public static bool AutoHide {
147
get { return AutohideType != AutohideType.None; }
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; }
154
prefs.Set ("SummonTime", value.TotalMilliseconds);
159
static int automatic_icons = prefs.Get ("AutomaticIcons", 5);
160
public static int AutomaticIcons {
161
get { return automatic_icons; }
165
prefs.Set ("AutomaticIcons", value);
166
automatic_icons = value;
168
if (AutomaticIconsChanged != null)
169
AutomaticIconsChanged ();
173
static int monitor = Math.Max (0, prefs.Get ("Monitor", 0));
174
public static int Monitor {
176
monitor = Math.Max (0, Math.Min (monitor, Gdk.Screen.Default.NMonitors - 1));
180
if (monitor == value)
183
if (value >= Gdk.Screen.Default.NMonitors || value < 0)
186
prefs.Set ("Monitor", value);
188
Interface.LayoutUtils.Recalculate ();
189
if (MonitorChanged != null)
194
static DockOrientation orientation = (DockOrientation) Enum.Parse (typeof (DockOrientation), prefs.Get ("Orientation", DockOrientation.Bottom.ToString ()));
195
public static DockOrientation Orientation {
197
if (orientation != DockOrientation.Top && orientation != DockOrientation.Bottom)
198
orientation = DockOrientation.Bottom;
203
if (orientation == value)
206
prefs.Set ("Orientation", value.ToString ());
207
if (OrientationChanged != null)
208
OrientationChanged ();
212
static AutohideType hide = (AutohideType) Enum.Parse (typeof (AutohideType), prefs.Get ("AutohideType", AutohideType.None.ToString ()));
213
public static AutohideType AutohideType {
219
prefs.Set ("AutohideType", value.ToString ());
220
if (AutohideChanged != null)
226
static List<string> item_blacklist = DeserializeBlacklist ();
227
public static IEnumerable<string> ItemBlacklist {
229
return item_blacklist;
233
public static void AddBlacklistItem (string item)
235
item_blacklist.Add (item);
236
SerializeBlacklist ();
239
public static void RemoveBlacklistItem (string item)
241
item_blacklist.Remove (item);
242
SerializeBlacklist ();
245
public static void ClearBlacklist ()
247
item_blacklist.Clear ();
248
SerializeBlacklist ();
251
static string BlacklistFile {
253
return Path.Combine (Services.Paths.UserDataDirectory, "dock_blacklist");
257
static List<string> DeserializeBlacklist ()
259
string file = BlacklistFile;
260
if (!File.Exists (file))
261
return new List<string> ();
264
Stream s = File.OpenRead (file);
265
BinaryFormatter bf = new BinaryFormatter ();
266
List<string> out_list = bf.Deserialize (s) as List<string>;
270
} catch { return new List<string> (); }
273
static void SerializeBlacklist ()
275
string file = BlacklistFile;
278
Stream s = File.Open (file, FileMode.OpenOrCreate);
279
BinaryFormatter bf = new BinaryFormatter ();
280
bf.Serialize (s, item_blacklist);