1 #ifndef __BASICITEM_H__
2 #define __BASICITEM_H__
6 #include <gdk-pixbuf/gdk-pixbuf.h>
10 BasicItem(const std::string& type, const std::string& id) : myType(type), myID(id), myEnabled(false) {}
12 virtual ~BasicItem() {}
14 const std::string& getType() const { return myType; }
15 const std::string& getID() const { return myID; }
17 virtual std::string getName() const = 0;
18 virtual std::string getComment() const = 0;
19 virtual GdkPixbuf *getIcon(int iconSize) const = 0;
21 virtual void activate() = 0;
23 virtual bool isSane() const = 0;
25 bool isEnabled(void) const { return myEnabled; }
27 virtual void enable() { myEnabled = isSane(); }
28 virtual void disable() { myEnabled = false; }
37 BasicItem(); // We do not want people to create these objects :)
39 const std::string& myType;
40 const std::string& myID;
44 class BasicItemFactory {
49 virtual const string::std& factoryName() const = 0;
51 virtual BasicItem *createItem(const std::string&) const = 0;
54 static void registerFactory(const std::string&, BasicItemFactory *);
57 std::map<std::string, BasicItemFactory *> ourFactories;
60 typedef struct BasicItemCollection {
61 typedef std::vector<std::string> Names;
62 typedef std::map<std::string, BasicItem *> Items;
67 bool exists(const std::string& name) {
68 return std::find(myNames.begin(), myNames.end(), name) != myNames.end();
71 size_t size() { return myNames.size(); }
73 BasicItem *operator[](int index) {
74 return myItems[myNames[index]];
77 std::string& name(int index) {
78 return myNames[index];
81 void add(const std::string& name, BasicItem *item) {
82 myNames.push_back(name);
86 void swap(size_t i1, size_t i2) {
87 std::swap(myNames[i1], myNames[i2]);
91 for (Items::iterator it = myItems.begin(); it != myItems.end(); ++it) {
92 if (it->second != NULL) {
102 BasicItemCollection& operator=(const BasicItemCollection& that) {
103 myNames = that.myNames;
104 myItems = that.myItems;