mark one item as possibly done :)
[simple-launcher] / misc / ApplicationItem.cc
1 // This file is a part of Simple Launcher
2 //
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
4 //
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 #include "ApplicationItem.h"
19
20 static ApplicationItemFactory factory;
21
22 const std::string& ApplicationItemFactory::factoryName() const {
23   const std::string& NAME = "ApplicationItem";
24
25   return NAME;
26 }
27
28 BasicItem *ApplicationItemFactory::createItem(const std::string& itemID) const {
29   return new ApplicationItem(itemID);
30 }
31
32 ApplicationItem::ApplicationItem(const std::string& itemID): BasicItem(factory.factoryName(), itemID) {
33 }
34
35 ApplicationItem::~ApplicationItem() {
36 }
37
38 bool ApplicationItem::load() {
39   GKeyFileWrapper key_file;
40
41   for (;;) {
42     if (!key_file.load(myID)) {
43       break;
44     }
45
46     if (key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_TYPE_FIELD) != "Application") {
47       break;
48     }
49
50     myName = key_file.getLocaleString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_NAME_FIELD);
51     myComment = key_file.getLocaleString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_COMMENT_FIELD);
52     myIcon = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_ICON_FIELD);
53     myService = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_SERVICE_FIELD);
54     myExec = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_EXEC_FIELD);
55     myTextDomain = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_TEXT_DOMAIN);
56
57     break;
58   }
59
60   return (myEnabled = checkSanity());
61 }
62
63 void ApplicationItem::activate(osso_context_t *context) {
64   bool result = false;
65
66   if (myService.empty() || !(result = osso_rpc_run_with_defaults(context, myService.c_str(), "top_application", NULL, DBUS_TYPE_INVALID) == OSSO_OK)) {
67     runApplication(getExec());
68     return true;
69   } else {
70     return result;
71   }
72 }