LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LaunchPoint.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef LAUNCHPOINT_H
23 #define LAUNCHPOINT_H
24 
25 #include "Common.h"
26 
27 #include <string>
28 #include <list>
29 #include <QPixmap>
30 #include <glib.h>
31 
33 class json_object;
34 
35 #define DEFAULT_ICON_W 64
36 #define DEFAULT_ICON_H 64
37 
39 {
40 public:
41 
43  const std::string& filePath);
44 
46  const std::string& id,
47  const std::string& launchPointId,
48  const std::string& title,
49  const std::string& menuName,
50  const std::string& iconPath,
51  const std::string& params,
52  bool removable);
53 
54  ~LaunchPoint();
55 
56  // NOTE: it is the callers responsibility to json_object_put the return value
57  json_object* toJSON() const;
58 
59  void setAppDesc(ApplicationDescription* appDesc) { m_appDesc = appDesc; }
60 
61  bool updateIconPath(std::string newIconPath);
62  void updateTitle(const std::string& titleStr);
63 
64  ApplicationDescription* appDesc() const { return m_appDesc; }
65  const std::string& id() const { return m_id; }
66  const std::string& launchPointId() const { return m_launchPointId; }
67  const std::string& title() const { return m_title.original; }
68  const std::string& menuName() const { return m_appmenuName; }
69  const std::string& iconPath() const { return m_iconPath; }
70  const std::string& params() const { return m_params; }
71  QPixmap icon() const;
72  bool isDefault() const {return m_bDefault;}
73  void setAsDefault(bool dv=true) { m_bDefault=dv;}
74  bool setRemovable(bool v=true) { bool pv=m_removable;m_removable=v;return pv;}
75  bool isRemovable() const {return m_removable;}
76  std::string category() const;
77  std::string entryPoint() const;
78 
79  bool matchesTitle(const gchar* str) const;
80  int compareByKeys(const LaunchPoint* lp) const;
81 
82  bool isVisible() const;
83 private:
84 
85  // prevent object copy
86  LaunchPoint(const LaunchPoint&);
87  LaunchPoint& operator=(const LaunchPoint&) const;
88 
89  struct Title {
90  Title() : original(""), lowercase(0), keyed(0) { }
91  ~Title() { cleanup(); }
92 
93  void cleanup()
94  {
95  if (lowercase)
96  g_free(lowercase);
97  lowercase = 0;
98  if (keyed)
99  g_free(keyed);
100  keyed = 0;
101  }
102 
103  void set(const std::string& title)
104  {
105  cleanup();
106  original = title;
107  lowercase = g_utf8_strdown(title.c_str(), -1);
108  keyed = g_utf8_collate_key(lowercase, -1);
109  }
110 
111  std::string original; // the title as given by the constructor
112  gchar* lowercase; // a lowercased version of the title
113  gchar* keyed; // a keyed version used for fast sorting
114  };
115 
116  static LaunchPoint* fromJSON(ApplicationDescription* appDesc,
117  const char* jsonStr,
118  const std::string& launchPointId);
119 
120  bool toFile() const;
121 
122  ApplicationDescription* m_appDesc;
123  std::string m_id;
124  std::string m_launchPointId;
125  Title m_title;
126  std::string m_appmenuName;
127  std::string m_iconPath;
128  std::string m_params;
129 // QPixmap m_icon;
130  bool m_removable;
131  bool m_bDefault; //is this the default launch point?
132 };
133 
134 typedef std::list<const LaunchPoint*> LaunchPointList;
135 
136 #endif /* LAUNCHPOINT_H */