~azzar1/unity/fix-crash-acc-controller

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2016 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
 */

#include "AppStreamApplication.h"

#include <appstream-glib.h>

#include <iostream>

namespace unity
{
namespace appstream
{

Application::Application(std::string const& appstream_id)
  : appstream_id_(appstream_id)
{
  desktop_file.SetGetterFunction([this](){ return appstream_id_; });
  title.SetGetterFunction([this](){ return title_; });
  icon_pixbuf.SetGetterFunction([this](){ return icon_pixbuf_; });

  glib::Object<AsStore> as_store(as_store_new());
  g_return_if_fail(as_store);

  as_store_load(as_store, AS_STORE_LOAD_FLAG_APP_INFO_SYSTEM, nullptr, nullptr);

  AsApp *as_app = as_store_get_app_by_id(as_store, appstream_id_.c_str());
  g_return_if_fail(as_app);

  title_ = glib::gchar_to_string(as_app_get_name(as_app, nullptr));

  AsIcon *as_icon = as_app_get_icon_default(as_app);
  g_return_if_fail(as_icon);

  as_icon_load(as_icon, AS_ICON_LOAD_FLAG_SEARCH_SIZE, nullptr);
  icon_pixbuf_ = glib::Object<GdkPixbuf>(as_icon_get_pixbuf(as_icon), glib::AddRef());
}

AppType Application::type() const
{
  return AppType::NORMAL;
}

std::string Application::repr() const
{
  std::ostringstream sout;
  sout << "<AppStream::Application " << appstream_id_ << " >";
  return sout.str();
}

WindowList const& Application::GetWindows() const
{
  return window_list_;
}

bool Application::OwnsWindow(Window window_id) const
{
  return false;
}

std::vector<std::string> Application::GetSupportedMimeTypes() const
{
  return std::vector<std::string>();
}

ApplicationWindowPtr Application::GetFocusableWindow() const
{
  return nullptr;
}

void Application::Focus(bool show_on_visible, int monitor) const
{}

void Application::Quit() const
{}

bool Application::CreateLocalDesktopFile() const
{
  return false;
}

std::string Application::desktop_id() const
{
  return "";
}

}
}