~3v1n0/unity/light-shortcuts

« back to all changes in this revision

Viewing changes to launcher/SimpleLauncherIcon.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2013-04-26 12:41:09 UTC
  • Revision ID: mail@3v1n0.net-20130426124109-t3b2shjah2omiqa2
Unity: Remove all the views, but the Shortcuts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
 
/*
3
 
 * Copyright (C) 2010 Canonical Ltd
4
 
 *
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.
8
 
 *
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.
13
 
 *
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/>.
16
 
 *
17
 
 * Authored by: Jason Smith <jason.smith@canonical.com>
18
 
 */
19
 
 
20
 
#ifndef UNITY_SIMPLELAUNCHERICON_H
21
 
#define UNITY_SIMPLELAUNCHERICON_H
22
 
 
23
 
#include <NuxCore/Logger.h>
24
 
#include <Nux/Nux.h>
25
 
#include <Nux/BaseWindow.h>
26
 
#include <UnityCore/Variant.h>
27
 
 
28
 
#include "SimpleLauncherIcon.h"
29
 
 
30
 
#include "unity-shared/UBusWrapper.h"
31
 
#include "unity-shared/UBusMessages.h"
32
 
 
33
 
namespace unity
34
 
{
35
 
namespace launcher
36
 
{
37
 
DECLARE_LOGGER(logger, "unity.launcher.icon");
38
 
 
39
 
NUX_IMPLEMENT_OBJECT_TYPE(SimpleLauncherIcon);
40
 
 
41
 
SimpleLauncherIcon::SimpleLauncherIcon(IconType type)
42
 
  : LauncherIcon(type)
43
 
  , icon_name("", sigc::mem_fun(this, &SimpleLauncherIcon::SetIconName))
44
 
  , theme_changed_id_(0)
45
 
{
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));
51
 
 
52
 
  theme_changed_id_ = g_signal_connect(gtk_icon_theme_get_default(), "changed",
53
 
                                       G_CALLBACK(SimpleLauncherIcon::OnIconThemeChanged), this);
54
 
}
55
 
 
56
 
SimpleLauncherIcon::~SimpleLauncherIcon()
57
 
{
58
 
  for (auto element : texture_map)
59
 
    if (element.second)
60
 
      element.second->UnReference();
61
 
 
62
 
  texture_map.clear ();
63
 
 
64
 
  if (theme_changed_id_)
65
 
    g_signal_handler_disconnect(gtk_icon_theme_get_default(), theme_changed_id_);
66
 
}
67
 
 
68
 
void SimpleLauncherIcon::OnMouseDown(int button, int monitor, unsigned long key_flags)
69
 
{
70
 
}
71
 
 
72
 
void SimpleLauncherIcon::OnMouseUp(int button, int monitor, unsigned long key_flags)
73
 
{
74
 
}
75
 
 
76
 
void SimpleLauncherIcon::OnMouseClick(int button, int monitor, unsigned long key_flags)
77
 
{
78
 
}
79
 
 
80
 
void SimpleLauncherIcon::OnMouseEnter(int monitor)
81
 
{
82
 
}
83
 
 
84
 
void SimpleLauncherIcon::OnMouseLeave(int monitor)
85
 
{
86
 
}
87
 
 
88
 
void SimpleLauncherIcon::ActivateLauncherIcon(ActionArg arg)
89
 
{
90
 
  activate.emit();
91
 
  UBusManager::SendMessage(UBUS_OVERLAY_CLOSE_REQUEST,
92
 
                           g_variant_new_boolean(FALSE));
93
 
}
94
 
 
95
 
nux::BaseTexture* SimpleLauncherIcon::GetTextureForSize(int size)
96
 
{
97
 
  if (texture_map[size] != 0)
98
 
    return texture_map[size];
99
 
 
100
 
  std::string icon_string(icon_name());
101
 
 
102
 
  if (icon_string.empty())
103
 
    return 0;
104
 
 
105
 
  if (icon_string[0] == '/')
106
 
    texture_map[size] = TextureFromPath(icon_string, size);
107
 
  else
108
 
    texture_map[size] = TextureFromGtkTheme(icon_string, size);
109
 
  return texture_map[size];
110
 
}
111
 
 
112
 
bool SimpleLauncherIcon::SetIconName(std::string& target, std::string const& value)
113
 
{
114
 
  if (target == value)
115
 
    return false;
116
 
 
117
 
  target = value;
118
 
  ReloadIcon();
119
 
 
120
 
  return true;
121
 
}
122
 
 
123
 
void SimpleLauncherIcon::ReloadIcon()
124
 
{
125
 
  for (auto element : texture_map)
126
 
    if (element.second)
127
 
      element.second->UnReference();
128
 
 
129
 
  texture_map.clear ();
130
 
  EmitNeedsRedraw();
131
 
}
132
 
 
133
 
void SimpleLauncherIcon::OnIconThemeChanged(GtkIconTheme* icon_theme, gpointer data)
134
 
{
135
 
  SimpleLauncherIcon* self = static_cast<SimpleLauncherIcon*>(data);
136
 
 
137
 
  // invalidate the current cache
138
 
  self->_current_theme_is_mono = -1;
139
 
  self->ReloadIcon();
140
 
}
141
 
 
142
 
std::string SimpleLauncherIcon::GetName() const
143
 
{
144
 
  return "SimpleLauncherIcon";
145
 
}
146
 
 
147
 
void SimpleLauncherIcon::AddProperties(GVariantBuilder* builder)
148
 
{
149
 
  LauncherIcon::AddProperties(builder);
150
 
  variant::BuilderWrapper(builder).add("icon_name", icon_name);
151
 
}
152
 
 
153
 
} // namespace launcher
154
 
} // namespace unity
155
 
 
156
 
#endif