summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
author Andrea Azzarone <azzaronea@gmail.com>2016-02-19 13:11:52 +0100
committer Andrea Azzarone <azzaronea@gmail.com>2016-02-19 13:11:52 +0100
commitc9b85961e24297eba74f3bcd6eaba57084e31a9d (patch)
tree5ac5d6729edb298e76f428b7e6d00880025288ae /unity-shared
parentc64b092d2cc6a6b72e64bd3377f56ff462021a31 (diff)
Integration with gnome-software.
(bzr r4067.2.2)
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/AppStreamApplication.cpp120
-rw-r--r--unity-shared/AppStreamApplication.h65
-rw-r--r--unity-shared/ApplicationManager.h3
-rw-r--r--unity-shared/CMakeLists.txt1
-rw-r--r--unity-shared/DesktopApplicationManager.h2
5 files changed, 190 insertions, 1 deletions
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 <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(std::bind(&Application::GetDesktopFile, this));
+ title.SetGetterFunction(std::bind(&Application::GetTitle, this));
+ icon_pixbuf.SetGetterFunction(std::bind(&Application::GetIconPixbuf, this));
+
+ 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);
+
+ 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<GdkPixbuf>(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<GdkPixbuf> Application::GetIconPixbuf() const
+{
+ return icon_pixbuf_;
+}
+
+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 "";
+}
+
+}
+}
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 <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
+ */
+
+#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<std::string> 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<GdkPixbuf> GetIconPixbuf() const;
+
+ std::string appstream_id_;
+ std::string title_;
+ glib::Object<GdkPixbuf> 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 <memory>
#include <vector>
+#include <gdk/gdk.h>
#include <sigc++/signal.h>
#include <NuxCore/Property.h>
+#include <UnityCore/GLibWrapper.h>
#include <unity-shared/WindowManager.h>
@@ -151,6 +153,7 @@ public:
nux::ROProperty<std::string> desktop_file;
nux::ROProperty<std::string> title;
nux::ROProperty<std::string> icon;
+ nux::ROProperty<glib::Object<GdkPixbuf>> icon_pixbuf;
// Considering using a property for the "unity-seen" quark
nux::RWProperty<bool> 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 <UnityCore/GLibWrapper.h>
#include <UnityCore/GLibSignal.h>
-#include "unity-shared/ApplicationManager.h"
+#include "ApplicationManager.h"
namespace unity
{