updated the copyright year
[simple-launcher] / launcher-item.h
1 // This file is a part of Simple Launcher
2 //
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
4 //
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 #ifndef __LAUNCHER_ITEM_H__
19 #define __LAUNCHER_ITEM_H__
20
21 #include <vector>
22 #include <map>
23 #include <string>
24
25 #include <gdk-pixbuf/gdk-pixbuf.h>
26 #include <gtk/gtkicontheme.h>
27
28 class LauncherItem {
29 public:
30   LauncherItem();
31   virtual ~LauncherItem();
32
33   bool load(const std::string&);
34
35   GdkPixbuf *getIcon(int icon_size) const;
36
37   const std::string& getFileName() const { return myFileName; }
38   const std::string& getName() const { return myName; }
39   const std::string& getComment() const { return myComment; }
40   const std::string& getService() const { return myService; }
41
42   bool isEnabled(void) const { return myEnabled; }
43
44   void enable() { myEnabled = checkSanity(); }
45   void disable() { myEnabled = false; }
46   void toggle() {
47     if (myEnabled) {
48       disable();
49     } else {
50       enable();
51     }
52   }
53
54 private:
55   bool checkSanity(void) { return !(myName.empty() || myIcon.empty() || myService.empty()); }
56
57 private:
58   std::string myFileName, myName, myComment, myIcon, myService;
59   bool myEnabled;
60
61   static GtkIconTheme *ourTheme;
62 };
63
64 typedef struct {
65   typedef std::vector<std::string> Names;
66   typedef std::map<std::string, LauncherItem *> Items;
67
68   Names myNames;
69   Items myItems;
70
71   bool exists(const std::string& name) {
72     return myNames.find(name) != myNames.end();
73   }
74
75   size_t size() { return myNames.size(); }
76
77   LauncherItem *operator[](int index) {
78     return myItems[myNames[index]];
79   }
80
81   std::string& name(int index) {
82     return myNames[index];
83   }
84
85   void add(const std::string& name, LauncherItem *item) {
86     myNames.push_back(name);
87     myItems[name] = item;
88   }
89
90   void swap(size_t i1, size_t i2) {
91     std::swap(myNames[i1], myNames[i2]);
92   }
93
94   void clear() {
95     for (Items::iterator it = myItems.begin(); it != myItems.end(); ++it) {
96       if (it->second != NULL) {
97         delete it->second;
98         it->second = NULL;
99       }
100     }
101
102     myNames.resize(0);
103     myItems.clear();
104   }
105 } LauncherItems;
106
107 #endif
108
109 // vim:ts=2:sw=2:et