// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2012 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: Tim Penhey
*/
#ifndef UNITYSHARED_APPLICATION_MANAGER_H
#define UNITYSHARED_APPLICATION_MANAGER_H
#include
#include
#include
#include
#include
namespace unity
{
class Application;
class ApplicationManager;
class ApplicationWindow;
class ApplicationSubject;
typedef std::shared_ptr ApplicationPtr;
typedef std::shared_ptr ApplicationWindowPtr;
typedef std::shared_ptr ApplicationSubjectPtr;
typedef std::vector ApplicationList;
typedef std::vector WindowList;
enum class ApplicationEventType
{
CREATE,
DELETE,
ACCESS,
LEAVE
};
class ApplicationWindow
{
public:
virtual ~ApplicationWindow() = default;
virtual std::string type() const = 0; // 'window' or 'tab'
virtual Window window_id() const = 0;
virtual int monitor() const = 0;
// It is possible for this to be null, especially in situations where
// the application is starting up or shutting down.
virtual ApplicationPtr application() const = 0;
// Returns true if we made a best effort at focusing the window, or
// false if this was not possible for some reason (like a missing window_id).
virtual bool Focus() const = 0;
// Closes the window, or the browser tab if a webapp.
virtual void Quit() const = 0;
nux::ROProperty title;
nux::ROProperty icon;
nux::ROProperty visible;
nux::ROProperty active;
nux::ROProperty urgent;
};
class Application
{
public:
virtual ~Application() = default;
virtual std::string type() const = 0;
// A string representation of the object.
virtual std::string repr() const = 0;
virtual WindowList GetWindows() const = 0;
virtual bool OwnsWindow(Window window_id) const = 0;
virtual std::vector GetSupportedMimeTypes() const = 0;
virtual ApplicationWindowPtr GetFocusableWindow() const = 0;
virtual void Focus(bool show_on_visible, int monitor) const = 0;
// Calls quit on all the Windows for this application.
virtual void Quit() const = 0;
virtual bool CreateLocalDesktopFile() const = 0;
virtual void LogEvent(ApplicationEventType, ApplicationSubjectPtr const&) const = 0;
virtual std::string desktop_id() const = 0;
nux::ROProperty desktop_file;
nux::ROProperty title;
nux::ROProperty icon;
// Considering using a property for the "unity-seen" quark
nux::RWProperty seen;
nux::RWProperty sticky;
nux::ROProperty visible;
nux::ROProperty active;
nux::ROProperty running;
nux::ROProperty urgent;
sigc::signal closed;
sigc::signal window_opened;
sigc::signal window_moved;
sigc::signal window_closed;
};
class ApplicationSubject
{
public:
virtual ~ApplicationSubject() = default;
nux::RWProperty uri;
nux::RWProperty origin;
nux::RWProperty text;
nux::RWProperty storage;
nux::RWProperty current_uri;
nux::RWProperty current_origin;
nux::RWProperty mimetype;
nux::RWProperty interpretation;
nux::RWProperty manifestation;
bool operator==(ApplicationSubject const& other) const
{
return uri() == other.uri() &&
origin() == other.origin() &&
text() == other.text() &&
storage() == other.storage() &&
current_uri() == other.current_uri() &&
current_origin() == other.current_origin() &&
mimetype() == other.mimetype() &&
interpretation() == other.interpretation() &&
manifestation() == other.manifestation();
}
bool operator!=(ApplicationSubject const& other) const
{
return !(operator==(other));
}
};
class ApplicationManager
{
public:
virtual ~ApplicationManager() = default;
static ApplicationManager& Default();
virtual ApplicationPtr GetUnityApplication() const = 0;
virtual ApplicationWindowPtr GetActiveWindow() const = 0;
virtual ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file) const = 0;
virtual ApplicationList GetRunningApplications() const = 0;
virtual ApplicationPtr GetApplicationForWindow(Window xid) const = 0;
sigc::signal application_started;
sigc::signal active_application_changed;
sigc::signal active_window_changed;
};
}
#endif // UNITYSHARED_APPLICATION_MANAGER_H