~ci-train-bot/ubuntu-app-launch/ubuntu-app-launch-ubuntu-yakkety-landing-053

« back to all changes in this revision

Viewing changes to tools/ubuntu-app-info.cpp

  • Committer: CI Train Bot
  • Author(s): Ted Gould
  • Date: 2016-05-04 20:12:11 UTC
  • mfrom: (219.1.3 app-info-tool)
  • Revision ID: ci-train-bot@canonical.com-20160504201211-yet2wb11w8lqhz79
Add a small commandline tool for application information
Approved by: Charles Kerr, Larry Price

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <ted.gould@canonical.com>
 
18
 */
 
19
 
 
20
#include <iostream>
 
21
#include "libubuntu-app-launch/application.h"
 
22
#include "libubuntu-app-launch/registry.h"
 
23
 
 
24
int main(int argc, char* argv[])
 
25
{
 
26
    if (argc != 2) {
 
27
        std::cerr << "Usage: " << argv[0] << " (appid)" << std::endl;
 
28
        exit(1);
 
29
    }
 
30
 
 
31
    auto appid = ubuntu::app_launch::AppID::find(argv[1]);
 
32
    if (appid.empty()) {
 
33
        std::cerr << "Unable to find app for appid: " << argv[1] << std::endl;
 
34
        return 1;
 
35
    }
 
36
 
 
37
    std::shared_ptr<ubuntu::app_launch::Application> app;
 
38
    try {
 
39
        app = ubuntu::app_launch::Application::create(appid, ubuntu::app_launch::Registry::getDefault());
 
40
        if (!app)
 
41
            throw std::runtime_error("Application object is nullptr");
 
42
    } catch (std::runtime_error &e) {
 
43
        std::cerr << "Unable to find application for AppID: " << argv[1] << std::endl;
 
44
        exit(1);
 
45
    }
 
46
 
 
47
    try {
 
48
        auto info = app->info();
 
49
 
 
50
        std::cout << "Name:             " << info->name().value() << std::endl;
 
51
        std::cout << "Description:      " << info->description().value() << std::endl;
 
52
        std::cout << "Icon Path:        " << info->iconPath().value() << std::endl;
 
53
        std::cout << "Splash:           " << std::endl;
 
54
        std::cout << "  Title:          " << info->splash().title.value() << std::endl;
 
55
        std::cout << "  Image:          " << info->splash().image.value() << std::endl;
 
56
        std::cout << "  BG Color:       " << info->splash().backgroundColor.value() << std::endl;
 
57
        std::cout << "  Header Color:   " << info->splash().headerColor.value() << std::endl;
 
58
        std::cout << "  Footer Color:   " << info->splash().footerColor.value() << std::endl;
 
59
        std::cout << "  Show Header:    " << info->splash().showHeader.value() << std::endl;
 
60
        std::cout << "Orientations:     " << std::endl;
 
61
        std::cout << "  Portrait:       " << info->supportedOrientations().portrait << std::endl;
 
62
        std::cout << "  Landscape:      " << info->supportedOrientations().landscape << std::endl;
 
63
        std::cout << "  Inv Portrait:   " << info->supportedOrientations().invertedPortrait << std::endl;
 
64
        std::cout << "  Inv Landscape:  " << info->supportedOrientations().invertedLandscape << std::endl;
 
65
        std::cout << "Rotates:          " << info->rotatesWindowContents().value() << std::endl;
 
66
        std::cout << "Ubuntu Lifecycle: " << info->supportsUbuntuLifecycle().value() << std::endl;
 
67
    } catch (std::runtime_error &e) {
 
68
        std::cerr << "Unable to parse Application info for application '" << std::string(appid) << "': " << e.what() << std::endl;
 
69
        exit(1);
 
70
    }
 
71
 
 
72
    return 0;
 
73
}