[svn-buildpackage] Tagging simple-launcher (0.9)
[simple-launcher] / launcher-item.h
index 5a60611..ec53bb9 100644 (file)
@@ -1,6 +1,6 @@
 // This file is a part of Simple Launcher
 //
-// Copyright (C) 2006, Mikhail Sobolev
+// Copyright (C) 2006, 2007, Mikhail Sobolev
 //
 // Simple Launcher is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License version 2 as published by
@@ -21,6 +21,7 @@
 #include <vector>
 #include <map>
 #include <string>
+#include <algorithm>
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gtk/gtkicontheme.h>
@@ -35,8 +36,8 @@ public:
   GdkPixbuf *getIcon(int icon_size) const;
 
   const std::string& getFileName() const { return myFileName; }
-  const std::string& getName() const { return myName; }
-  const std::string& getComment() const { return myComment; }
+  std::string getName(bool translate = true) const { return translate ? translateString(myName) : myName; }
+  std::string getComment(bool translate = true) const { return translate ? translateString(myComment) : myComment; }
   const std::string& getService() const { return myService; }
 
   bool isEnabled(void) const { return myEnabled; }
@@ -52,22 +53,28 @@ public:
   }
 
 private:
+  std::string translateString(const std::string& what) const;
+
   bool checkSanity(void) { return !(myName.empty() || myIcon.empty() || myService.empty()); }
 
 private:
-  std::string myFileName, myName, myComment, myIcon, myService;
+  std::string myFileName, myName, myComment, myIcon, myService, myTextDomain;
   bool myEnabled;
 
   static GtkIconTheme *ourTheme;
 };
 
-typedef struct {
+typedef struct LauncherItems {
   typedef std::vector<std::string> Names;
   typedef std::map<std::string, LauncherItem *> 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(); }
 
   LauncherItem *operator[](int index) {
@@ -78,7 +85,7 @@ typedef struct {
     return myNames[index];
   }
 
-  void add(std::string& name, LauncherItem *item) {
+  void add(const std::string& name, LauncherItem *item) {
     myNames.push_back(name);
     myItems[name] = item;
   }
@@ -98,7 +105,14 @@ typedef struct {
     myNames.resize(0);
     myItems.clear();
   }
-} LauncherItems;
+
+  LauncherItems& operator=(const LauncherItems& that) {
+    myNames = that.myNames;
+    myItems = that.myItems;
+
+    return *this;
+  }
+};
 
 #endif