From c9b85961e24297eba74f3bcd6eaba57084e31a9d Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Fri, 19 Feb 2016 13:11:52 +0100 Subject: Integration with gnome-software. (bzr r4067.2.2) --- unity-shared/AppStreamApplication.cpp | 120 +++++++++++++++++++++++++++++++ unity-shared/AppStreamApplication.h | 65 +++++++++++++++++ unity-shared/ApplicationManager.h | 3 + unity-shared/CMakeLists.txt | 1 + unity-shared/DesktopApplicationManager.h | 2 +- 5 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 unity-shared/AppStreamApplication.cpp create mode 100644 unity-shared/AppStreamApplication.h (limited to 'unity-shared') diff --git a/unity-shared/AppStreamApplication.cpp b/unity-shared/AppStreamApplication.cpp new file mode 100644 index 000000000..6f6b5c84c --- /dev/null +++ b/unity-shared/AppStreamApplication.cpp @@ -0,0 +1,120 @@ +// -*- 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 . + * + * Authored by: Andrea Azzarone + */ + +#include "AppStreamApplication.h" + +#include + +#include + +namespace unity +{ +namespace appstream +{ + +Application::Application(std::string const& appstream_id) + : appstream_id_(appstream_id) +{ + desktop_file.SetGetterFunction(std::bind(&Application::GetDesktopFile, this)); + title.SetGetterFunction(std::bind(&Application::GetTitle, this)); + icon_pixbuf.SetGetterFunction(std::bind(&Application::GetIconPixbuf, this)); + + glib::Object 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); + + const gchar* name = as_app_get_name(as_app, nullptr); + title_ = name ? name : ""; + + 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(as_icon_get_pixbuf(as_icon), glib::AddRef()); +} + +std::string Application::GetDesktopFile() const +{ + return appstream_id_; +} + +std::string Application::GetTitle() const +{ + return title_; +} + +glib::Object Application::GetIconPixbuf() const +{ + return icon_pixbuf_; +} + +AppType Application::type() const +{ + return AppType::NORMAL; +} + +std::string Application::repr() const +{ + std::ostringstream sout; + sout << ""; + return sout.str(); +} + +WindowList const& Application::GetWindows() const +{ + return window_list_; +} + +bool Application::OwnsWindow(Window window_id) const +{ + return false; +} + +std::vector Application::GetSupportedMimeTypes() const +{ + return std::vector(); +} + +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 ""; +} + +} +} diff --git a/unity-shared/AppStreamApplication.h b/unity-shared/AppStreamApplication.h new file mode 100644 index 000000000..34099fdd0 --- /dev/null +++ b/unity-shared/AppStreamApplication.h @@ -0,0 +1,65 @@ +// -*- 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 . + * + * Authored by: Andrea Azzarone + */ + +#ifndef UNITYSHARED_APPSTREAM_APPLICATION_H +#define UNITYSHARED_APPSTREAM_APPLICATION_H + +#include "DesktopApplicationManager.h" + +namespace unity +{ +namespace appstream +{ + +class Application : public desktop::Application +{ +public: + Application(std::string const& appstream_id); + + AppType type() const override; + std::string repr() const override; + + WindowList const& GetWindows() const override; + bool OwnsWindow(Window window_id) const override; + + std::vector GetSupportedMimeTypes() const override; + + ApplicationWindowPtr GetFocusableWindow() const override; + void Focus(bool show_on_visible, int monitor) const override; + void Quit() const override; + + bool CreateLocalDesktopFile() const override; + + std::string desktop_id() const override; + +private: + std::string GetDesktopFile() const; + std::string GetTitle() const; + glib::Object GetIconPixbuf() const; + + std::string appstream_id_; + std::string title_; + glib::Object icon_pixbuf_; + WindowList window_list_; +}; + +} +} + +#endif diff --git a/unity-shared/ApplicationManager.h b/unity-shared/ApplicationManager.h index c0f681a5e..29b855aab 100644 --- a/unity-shared/ApplicationManager.h +++ b/unity-shared/ApplicationManager.h @@ -23,8 +23,10 @@ #include #include +#include #include #include +#include #include @@ -151,6 +153,7 @@ public: nux::ROProperty desktop_file; nux::ROProperty title; nux::ROProperty icon; + nux::ROProperty> icon_pixbuf; // Considering using a property for the "unity-seen" quark nux::RWProperty seen; diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index a65703171..2a8f3db39 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -18,6 +18,7 @@ include_directories (.. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_DIR # set (UNITY_SHARED_SOURCES ApplicationManager.cpp + AppStreamApplication.cpp BGHash.cpp CoverArt.cpp BackgroundEffectHelper.cpp diff --git a/unity-shared/DesktopApplicationManager.h b/unity-shared/DesktopApplicationManager.h index 8bd7f1105..6ab2ede47 100644 --- a/unity-shared/DesktopApplicationManager.h +++ b/unity-shared/DesktopApplicationManager.h @@ -24,7 +24,7 @@ #include #include -#include "unity-shared/ApplicationManager.h" +#include "ApplicationManager.h" namespace unity { -- cgit v1.2.3