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/>.
20
using System.Text.RegularExpressions;
21
using System.Collections.Generic;
23
using System.Reflection;
28
namespace Do.Launchpad
31
/// Singleton class for saving and storing Launchpad icons.
32
/// When an icon is requested, it is extracted from the resources file
33
/// and saved to a temp directory, and the path to that icon is returned.
34
/// Upon destruction, the class will clear out all its icons.
38
public static LaunchpadIcons instance = null;
39
private Dictionary<string, string> iconcache;
42
private LaunchpadIcons()
44
iconcache = new Dictionary<string, string>();
45
asm = Assembly.GetExecutingAssembly();
48
public static LaunchpadIcons Instance
54
instance = new LaunchpadIcons();
62
foreach (string s in iconcache.Keys)
66
if (File.Exists(iconcache[s]))
68
File.Delete(iconcache[s]); //TODO: be smarter about this.
77
public string GetIconPath(string iconName)
79
if (false == iconcache.ContainsKey(iconName))
81
//Extract the icon from the resource file.
82
Stream icon = asm.GetManifestResourceStream(iconName);
83
//TODO: Use a facility within gnome-do's core for creating
85
if (false == Directory.Exists("/tmp/gnome-do"))
86
Directory.CreateDirectory("/tmp/gnome-do");
87
if (false == Directory.Exists("/tmp/gnome-do/icons"))
88
Directory.CreateDirectory("/tmp/gnome-do/icons");
89
string tmp_filename = Path.Combine("/tmp/gnome-do/icons", iconName);
90
BinaryReader input = new BinaryReader(icon);
91
BinaryWriter output = new BinaryWriter(File.OpenWrite(tmp_filename));
96
try_read = input.ReadInt32();
97
output.Write(try_read);
106
iconcache[iconName] = tmp_filename;
108
return iconcache[iconName];