From: mishas Date: Tue, 17 Apr 2007 14:39:23 +0000 (+0000) Subject: added two files with ideas about bright future X-Git-Url: https://vcs.maemo.org/git/?p=simple-launcher;a=commitdiff_plain;h=be883d0d17dddf451d18671c2f264f209948e15b added two files with ideas about bright future git-svn-id: file:///svnroot/simple-launcher/trunk@197 3ba93dab-e023-0410-b42a-de7732cf370a --- diff --git a/misc/BasicItem.cc b/misc/BasicItem.cc new file mode 100644 index 0000000..e69de29 diff --git a/misc/BasicItem.h b/misc/BasicItem.h new file mode 100644 index 0000000..13ba34f --- /dev/null +++ b/misc/BasicItem.h @@ -0,0 +1,110 @@ +#ifndef __BASICITEM_H__ +#define __BASICITEM_H__ + +#include + +#include + +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 ourFactories; +}; + +typedef struct BasicItemCollection { + typedef std::vector Names; + typedef std::map 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