stupid re-ordering of function calls :(
[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 #include <algorithm>
25
26 #include <gdk-pixbuf/gdk-pixbuf.h>
27 #include <gtk/gtkicontheme.h>
28
29 class LauncherItem {
30 public:
31   LauncherItem();
32   virtual ~LauncherItem();
33
34   bool load(const std::string&);
35
36   GdkPixbuf *getIcon(int icon_size) const;
37
38   const std::string& getFileName() const { return myFileName; }
39   const std::string& getName() const { return myName; }
40   const std::string& getComment() const { return myComment; }
41   const std::string& getService() const { return myService; }
42
43   bool isEnabled(void) const { return myEnabled; }
44
45   void enable() { myEnabled = checkSanity(); }
46   void disable() { myEnabled = false; }
47   void toggle() {
48     if (myEnabled) {
49       disable();
50     } else {
51       enable();
52     }
53   }
54
55 private:
56   bool checkSanity(void) { return !(myName.empty() || myIcon.empty() || myService.empty()); }
57
58 private:
59   std::string myFileName, myName, myComment, myIcon, myService;
60   bool myEnabled;
61
62   static GtkIconTheme *ourTheme;
63 };
64
65 typedef struct LauncherItems {
66   typedef std::vector<std::string> Names;
67   typedef std::map<std::string, LauncherItem *> Items;
68
69   Names myNames;
70   Items myItems;
71
72   bool exists(const std::string& name) {
73     return std::find(myNames.begin(), myNames.end(), name) != myNames.end();
74   }
75
76   size_t size() { return myNames.size(); }
77
78   LauncherItem *operator[](int index) {
79     return myItems[myNames[index]];
80   }
81
82   std::string& name(int index) {
83     return myNames[index];
84   }
85
86   void add(const std::string& name, LauncherItem *item) {
87     myNames.push_back(name);
88     myItems[name] = item;
89   }
90
91   void swap(size_t i1, size_t i2) {
92     std::swap(myNames[i1], myNames[i2]);
93   }
94
95   void clear() {
96     for (Items::iterator it = myItems.begin(); it != myItems.end(); ++it) {
97       if (it->second != NULL) {
98         delete it->second;
99         it->second = NULL;
100       }
101     }
102
103     myNames.resize(0);
104     myItems.clear();
105   }
106
107   LauncherItems& operator=(const LauncherItems& that) {
108     myNames = that.myNames;
109     myItems = that.myItems;
110
111     return *this;
112   }
113 };
114
115 #endif
116
117 // vim:ts=2:sw=2:et