1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright (C) 2010 Canonical Ltd
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 3 as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Authored by: Jason Smith <jason.smith@canonical.com>
20
#ifndef UNITY_SIMPLELAUNCHERICON_H
21
#define UNITY_SIMPLELAUNCHERICON_H
23
#include <NuxCore/Logger.h>
25
#include <Nux/BaseWindow.h>
26
#include <UnityCore/Variant.h>
28
#include "SimpleLauncherIcon.h"
30
#include "unity-shared/UBusWrapper.h"
31
#include "unity-shared/UBusMessages.h"
37
DECLARE_LOGGER(logger, "unity.launcher.icon");
39
NUX_IMPLEMENT_OBJECT_TYPE(SimpleLauncherIcon);
41
SimpleLauncherIcon::SimpleLauncherIcon(IconType type)
43
, icon_name("", sigc::mem_fun(this, &SimpleLauncherIcon::SetIconName))
44
, theme_changed_id_(0)
46
LauncherIcon::mouse_down.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseDown));
47
LauncherIcon::mouse_up.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseUp));
48
LauncherIcon::mouse_click.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseClick));
49
LauncherIcon::mouse_enter.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseEnter));
50
LauncherIcon::mouse_leave.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseLeave));
52
theme_changed_id_ = g_signal_connect(gtk_icon_theme_get_default(), "changed",
53
G_CALLBACK(SimpleLauncherIcon::OnIconThemeChanged), this);
56
SimpleLauncherIcon::~SimpleLauncherIcon()
58
for (auto element : texture_map)
60
element.second->UnReference();
64
if (theme_changed_id_)
65
g_signal_handler_disconnect(gtk_icon_theme_get_default(), theme_changed_id_);
68
void SimpleLauncherIcon::OnMouseDown(int button, int monitor, unsigned long key_flags)
72
void SimpleLauncherIcon::OnMouseUp(int button, int monitor, unsigned long key_flags)
76
void SimpleLauncherIcon::OnMouseClick(int button, int monitor, unsigned long key_flags)
80
void SimpleLauncherIcon::OnMouseEnter(int monitor)
84
void SimpleLauncherIcon::OnMouseLeave(int monitor)
88
void SimpleLauncherIcon::ActivateLauncherIcon(ActionArg arg)
91
UBusManager::SendMessage(UBUS_OVERLAY_CLOSE_REQUEST,
92
g_variant_new_boolean(FALSE));
95
nux::BaseTexture* SimpleLauncherIcon::GetTextureForSize(int size)
97
if (texture_map[size] != 0)
98
return texture_map[size];
100
std::string icon_string(icon_name());
102
if (icon_string.empty())
105
if (icon_string[0] == '/')
106
texture_map[size] = TextureFromPath(icon_string, size);
108
texture_map[size] = TextureFromGtkTheme(icon_string, size);
109
return texture_map[size];
112
bool SimpleLauncherIcon::SetIconName(std::string& target, std::string const& value)
123
void SimpleLauncherIcon::ReloadIcon()
125
for (auto element : texture_map)
127
element.second->UnReference();
129
texture_map.clear ();
133
void SimpleLauncherIcon::OnIconThemeChanged(GtkIconTheme* icon_theme, gpointer data)
135
SimpleLauncherIcon* self = static_cast<SimpleLauncherIcon*>(data);
137
// invalidate the current cache
138
self->_current_theme_is_mono = -1;
142
std::string SimpleLauncherIcon::GetName() const
144
return "SimpleLauncherIcon";
147
void SimpleLauncherIcon::AddProperties(GVariantBuilder* builder)
149
LauncherIcon::AddProperties(builder);
150
variant::BuilderWrapper(builder).add("icon_name", icon_name);
153
} // namespace launcher