1 // This file is a part of Simple Launcher
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
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.
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
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
18 #ifndef __BASICITEM_H__
19 #define __BASICITEM_H__
23 #include <gdk-pixbuf/gdk-pixbuf.h>
27 BasicItem(const std::string& type, const std::string& id) : myType(type), myID(id), myEnabled(false) {}
29 virtual ~BasicItem() {}
31 const std::string& getType() const { return myType; }
32 const std::string& getID() const { return myID; }
34 virtual std::string getName() const = 0;
35 virtual std::string getComment() const = 0;
36 virtual GdkPixbuf *getIcon(int iconSize) const = 0;
38 virtual void activate() = 0;
40 virtual bool isSane() const = 0;
42 bool isEnabled(void) const { return myEnabled; }
44 virtual void enable() { myEnabled = isSane(); }
45 virtual void disable() { myEnabled = false; }
54 BasicItem(); // We do not want people to create these objects :)
56 const std::string& myType;
57 const std::string& myID;
61 class BasicItemFactory {
65 virtual ~BasicItemFactory();
68 static BasicItem *create(const std::string& factoryName, const std::string& itemID);
71 virtual const string::std& factoryName() const = 0;
74 virtual BasicItem *createItem(const std::string&) const = 0;
76 static void registerFactory(const std::string&, BasicItemFactory *);
77 static void deRegisterFactory(const std::string&, BasicItemFactory *);
80 static std::map<std::string, BasicItemFactory *> ourFactories;
83 struct BasicItemCollection {
84 typedef std::vector<std::string> Names;
85 typedef std::map<std::string, BasicItem *> Items;
90 bool exists(const std::string& name) {
91 return std::find(myNames.begin(), myNames.end(), name) != myNames.end();
94 size_t size() { return myNames.size(); }
96 BasicItem *operator[](int index) {
97 return myItems[myNames[index]];
100 std::string& name(int index) {
101 return myNames[index];
104 void add(const std::string& name, BasicItem *item) {
105 myNames.push_back(name);
106 myItems[name] = item;
109 void swap(size_t i1, size_t i2) {
110 std::swap(myNames[i1], myNames[i2]);
114 for (Items::iterator it = myItems.begin(); it != myItems.end(); ++it) {
115 if (it->second != NULL) {
125 BasicItemCollection& operator=(const BasicItemCollection& that) {
126 myNames = that.myNames;
127 myItems = that.myItems;