added two files with ideas about bright future
authormishas <mikhail.sobolev@gmail.com>
Tue, 17 Apr 2007 14:39:23 +0000 (14:39 +0000)
committermishas <mikhail.sobolev@gmail.com>
Tue, 17 Apr 2007 14:39:23 +0000 (14:39 +0000)
git-svn-id: file:///svnroot/simple-launcher/trunk@197 3ba93dab-e023-0410-b42a-de7732cf370a

misc/BasicItem.cc [new file with mode: 0644]
misc/BasicItem.h [new file with mode: 0644]

diff --git a/misc/BasicItem.cc b/misc/BasicItem.cc
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/misc/BasicItem.h b/misc/BasicItem.h
new file mode 100644 (file)
index 0000000..13ba34f
--- /dev/null
@@ -0,0 +1,110 @@
+#ifndef __BASICITEM_H__
+#define __BASICITEM_H__
+
+#include <string>
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+class BasicItem {
+protected:
+  BasicItem(const std::string& type, const std::string& id) : myType(type), myID(id), myEnabled(false) {}
+public:
+  virtual ~BasicItem() {}
+
+       const std::string& getType() const { return myType; }
+       const std::string& getID() const { return myID; }
+
+  virtual std::string getName() const = 0;
+  virtual std::string getComment() const = 0;
+  virtual GdkPixbuf *getIcon(int iconSize) const = 0;
+
+  virtual void activate() = 0;
+
+  virtual bool isSane() const = 0;
+
+  bool isEnabled(void) const { return myEnabled; }
+
+  virtual void enable() { myEnabled = isSane(); }
+  virtual void disable() { myEnabled = false; }
+  void toggle() {
+    if (myEnabled) {
+      disable();
+    } else {
+      enable();
+    }
+  }
+private:
+  BasicItem();  // We do not want people to create these objects :)
+
+       const std::string& myType;
+       const std::string& myID;
+  bool myEnabled;
+};
+
+class BasicItemFactory {
+private:
+       BasicItemFactory();
+
+public:
+       virtual const string::std& factoryName() const = 0;
+
+       virtual BasicItem *createItem(const std::string&) const = 0;
+
+protected:
+       static void registerFactory(const std::string&, BasicItemFactory *);
+
+protected:
+       std::map<std::string, BasicItemFactory *> ourFactories;
+};
+
+typedef struct BasicItemCollection {
+  typedef std::vector<std::string> Names;
+  typedef std::map<std::string, BasicItem *> Items;
+
+  Names myNames;
+  Items myItems;
+
+  bool exists(const std::string& name) {
+    return std::find(myNames.begin(), myNames.end(), name) != myNames.end();
+  }
+
+  size_t size() { return myNames.size(); }
+
+  BasicItem *operator[](int index) {
+    return myItems[myNames[index]];
+  }
+
+  std::string& name(int index) {
+    return myNames[index];
+  }
+
+  void add(const std::string& name, BasicItem *item) {
+    myNames.push_back(name);
+    myItems[name] = item;
+  }
+
+  void swap(size_t i1, size_t i2) {
+    std::swap(myNames[i1], myNames[i2]);
+  }
+
+  void clear() {
+    for (Items::iterator it = myItems.begin(); it != myItems.end(); ++it) {
+      if (it->second != NULL) {
+        delete it->second;
+        it->second = NULL;
+      }
+    }
+
+    myNames.resize(0);
+    myItems.clear();
+  }
+
+  BasicItemCollection& operator=(const BasicItemCollection& that) {
+    myNames = that.myNames;
+    myItems = that.myItems;
+
+    return *this;
+  }
+};
+
+#endif