Debian Codegraph @

liblomiri-app-launch/application-impl-legacy.h

raw
1 /*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Ted Gould <[email protected]>
18 */
19
20 #include <gio/gdesktopappinfo.h>
21 #include <regex>
22
23 #include "application-impl-base.h"
24 #include "application-info-desktop.h"
25
26 #pragma once
27
28 namespace lomiri
29 {
30 namespace app_launch
31 {
32 namespace app_impls
33 {
34
35 /** Application Implementation for Legacy applications. These are applications
36 that are typically installed as Debian packages on the base system. The
37 standard place for them to put their desktop files is in /usr/share/applications
38 though other directories may be used by setting the appropriate XDG environment
39 variables. This implementation makes use of the GIO Desktop Appinfo functions
40 which do caching of those files to make access faster.
41
42 AppIDs for legacy applications only include the Appname variable. Both the package
43 and the version entries are empty strings. The appname variable is the filename
44 of the desktop file describing the application with the ".desktop" suffix.
45
46 More info: https://specifications.freedesktop.org/desktop-entry-spec/latest/
47 */
48 class Legacy : public Base
49 {
50 public:
51 Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry::Impl>& registry);
52
53 AppID appId() const override
54 {
55 return {AppID::Package::from_raw({}), _appname, AppID::Version::from_raw({})};
56 }
57
58 std::shared_ptr<Info> info() override;
59
60 std::vector<std::shared_ptr<Instance>> instances() override;
61
62 std::shared_ptr<Instance> launch(const std::vector<Application::URL>& urls = {}) override;
63 std::shared_ptr<Instance> launchTest(const std::vector<Application::URL>& urls = {}) override;
64
65 virtual std::shared_ptr<Application::Instance> findInstance(const std::string& instanceid) override;
66
67 private:
68 AppID::AppName _appname;
69 std::string _basedir;
70 std::shared_ptr<GKeyFile> _keyfile;
71 std::shared_ptr<app_info::Desktop> appinfo_;
72 std::string desktopPath_;
73 std::regex instanceRegex_;
74
75 std::list<std::pair<std::string, std::string>> launchEnv(const std::string& instance);
76 };
77
78 } // namespace app_impls
79 } // namespace app_launch
80 } // namespace lomiri