1
/*********************************************************
2
* Copyright (C) 2010 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation version 2.1 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11
* License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*********************************************************/
22
* Manages "pseudo-applications" for special menu items, such as
23
* directories for which we wish to display custom menu item icons or
24
* executables which do not have regular menu items.
26
* Pseudo apps are assigned well-known IDs (AppId, compile-time), and
27
* are associated with URIs at runtime. (Example: A user's Desktop
28
* folder has a compile-time AppId of PSEUDO_APP_DESKTOP with a likely
29
* runtime URI of $HOME/Desktop.)
31
* URIs may be influenced by environment variables or simply the existence
32
* of a program in the user's search path.
37
#include <glib/gi18n.h>
40
#include "vmware/tools/ghi/pseudoAppMgr.hh"
52
* PseudoApps indexed by URI (ex: file:///home/user/Desktop).
54
std::tr1::unordered_map<Glib::ustring,PseudoApp,
55
std::tr1::hash<std::string> > PseudoAppMgr::sApps;
58
* PseudoApp URIs indexed by app ID.
60
std::vector<Glib::ustring> PseudoAppMgr::sUris;
64
*-----------------------------------------------------------------------------
66
* PseudoAppMgr::PseudoAppMgr --
76
*-----------------------------------------------------------------------------
79
PseudoAppMgr::PseudoAppMgr()
81
static bool initialized = false;
92
*-----------------------------------------------------------------------------
94
* PseudoAppMgr::GetAppByAppId --
96
* Search for pseudo app by AppId.
104
*-----------------------------------------------------------------------------
108
PseudoAppMgr::GetAppByAppId(AppId id, // IN
109
PseudoApp& app) // OUT
112
if (id < PSEUDO_APP_HOME || id >= PSEUDO_APP_NAPPS) {
113
throw std::logic_error("Invalid PseudoApp identifier");
116
app = sApps[sUris[id]];
121
*-----------------------------------------------------------------------------
123
* PseudoAppMgr::LookupPath --
125
* Search for pseudo app by URI.
128
* Returns true and populates app on success.
129
* Returns false on failure.
134
*-----------------------------------------------------------------------------
138
PseudoAppMgr::GetAppByUri(const Glib::ustring& uri, // IN
139
PseudoApp& app) // OUT
142
if (sApps.find(uri) != sApps.end()) {
152
******************************************************************************
153
* BEGIN private methods.
158
*-----------------------------------------------------------------------------
160
* PseudoAppMgr::InitAppMap --
162
* Populate application map based on static data.
170
*-----------------------------------------------------------------------------
174
PseudoAppMgr::InitAppMap()
176
static const struct {
177
const char* symbolicName;
178
const char* iconName;
180
{ "Home Folder", "user-home" }, // PSEUDO_APP_HOME
181
{ "Bookmarks", "user-bookmarks" }, // ..._BOOKMARKS
182
{ "Desktop", "user-desktop" }, // ..._DESKTOP
183
{ "Documents", "folder" }, // ..._DOCUMENTS
184
{ "Download", "folder" }, // ..._DOWNLOAD
185
{ "Music", "folder" }, // ..._MUSIC
186
{ "Pictures", "folder" }, // ..._PICTURES
187
{ "Connect to Server...", "applications-internet" }, // ..._GNOME_CONNECT
191
ASSERT_ON_COMPILE(ARRAYSIZE(initTable) == PSEUDO_APP_NAPPS);
193
for (idx = 0; idx < ARRAYSIZE(initTable); idx++) {
194
Glib::ustring uri = sUris[idx];
196
sApps[uri].uri = uri;
198
* gettext lookup against xdg-user-dirs is purely opportunistic. Standalone
199
* apps (likely) won't exist there, but to keep the loop logic simple, they
200
* aren't excluded from said lookup.
202
sApps[uri].symbolicName = g_dgettext("xdg-user-dirs",
203
initTable[idx].symbolicName);
204
sApps[uri].iconName = initTable[idx].iconName;
211
*-----------------------------------------------------------------------------
213
* PseudoAppMgr::InitUriVector --
215
* Populate sUris based on runtime environment. See xdg-user-dirs for
224
*-----------------------------------------------------------------------------
228
PseudoAppMgr::InitUriVector()
230
sUris.resize(PSEUDO_APP_NAPPS);
233
sUris[PSEUDO_APP_HOME] = Glib::filename_to_uri(Glib::get_home_dir());
235
std::vector<Glib::ustring> components;
236
components.push_back(Glib::get_home_dir());
237
components.push_back(".gtk-bookmarks");
238
sUris[PSEUDO_APP_BOOKMARKS] =
239
Glib::filename_to_uri(Glib::build_filename(components));
241
#define MAP_GUSER_PSEUDO(gUserDir, pAppId) { \
242
Glib::ustring dir = Glib::get_user_special_dir((gUserDir)); \
243
if (!dir.empty()) { \
244
sUris[(pAppId)] = Glib::filename_to_uri(dir); \
248
MAP_GUSER_PSEUDO(G_USER_DIRECTORY_DESKTOP, PSEUDO_APP_DESKTOP);
249
MAP_GUSER_PSEUDO(G_USER_DIRECTORY_DOCUMENTS, PSEUDO_APP_DOCUMENTS);
250
MAP_GUSER_PSEUDO(G_USER_DIRECTORY_DOWNLOAD, PSEUDO_APP_DOWNLOAD);
251
MAP_GUSER_PSEUDO(G_USER_DIRECTORY_MUSIC, PSEUDO_APP_MUSIC);
252
MAP_GUSER_PSEUDO(G_USER_DIRECTORY_PICTURES, PSEUDO_APP_PICTURES);
254
Glib::ustring connectPath = Glib::find_program_in_path("nautilus-connect-server");
255
if (!connectPath.empty()) {
256
sUris[PSEUDO_APP_GNOME_CONNECT] = Glib::filename_to_uri(connectPath);
258
} catch (std::exception& e) {
259
g_warning("%s: Caught exception while learning XDG directories: %s\n",
266
* END private methods.
267
******************************************************************************
270
} /* namespace ghi */ } /* namespace tools */ } /* namespace vmware */