~mial/ubuntu/oneiric/unity/bug-791810

« back to all changes in this revision

Viewing changes to src/SimpleLauncherIcon.cpp

Import the work done so far with Compiz

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
 
#include <NuxCore/Logger.h>
21
 
#include <Nux/Nux.h>
22
 
#include <Nux/BaseWindow.h>
 
1
#include "Nux/Nux.h"
 
2
#include "Nux/BaseWindow.h"
23
3
 
24
4
#include "SimpleLauncherIcon.h"
25
5
#include "Launcher.h"
26
 
#include "PluginAdapter.h"
27
 
 
28
 
#include "ubus-server.h"
29
 
#include "UBusMessages.h"
30
 
 
31
 
namespace
32
 
{
33
 
  nux::logging::Logger logger("unity.dash.CategoryViewGrid");
34
 
}
35
 
 
36
 
SimpleLauncherIcon::SimpleLauncherIcon(Launcher* IconManager)
37
 
  : LauncherIcon(IconManager)
38
 
  , theme_changed_id_(0)
39
 
{
40
 
  LauncherIcon::mouse_down.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseDown));
41
 
  LauncherIcon::mouse_up.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseUp));
42
 
  LauncherIcon::mouse_click.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseClick));
43
 
  LauncherIcon::mouse_enter.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseEnter));
44
 
  LauncherIcon::mouse_leave.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseLeave));
45
 
 
46
 
  theme_changed_id_ = g_signal_connect(gtk_icon_theme_get_default(), "changed",
47
 
                                       G_CALLBACK(SimpleLauncherIcon::OnIconThemeChanged), this);
 
6
 
 
7
SimpleLauncherIcon::SimpleLauncherIcon (Launcher* IconManager, NUX_FILE_LINE_DECL)
 
8
:   LauncherIcon(IconManager)
 
9
{
 
10
    m_Icon = 0;
 
11
    m_IconName = 0;
 
12
    
 
13
    LauncherIcon::MouseDown.connect (sigc::mem_fun (this, &SimpleLauncherIcon::OnMouseDown));
 
14
    LauncherIcon::MouseUp.connect (sigc::mem_fun (this, &SimpleLauncherIcon::OnMouseUp));
 
15
    LauncherIcon::MouseClick.connect (sigc::mem_fun (this, &SimpleLauncherIcon::OnMouseClick));
 
16
    LauncherIcon::MouseEnter.connect (sigc::mem_fun (this, &SimpleLauncherIcon::OnMouseEnter));
 
17
    LauncherIcon::MouseLeave.connect (sigc::mem_fun (this, &SimpleLauncherIcon::OnMouseLeave));
48
18
}
49
19
 
50
20
SimpleLauncherIcon::~SimpleLauncherIcon()
51
21
{
52
 
  for (auto element : texture_map)
53
 
    if (element.second)
54
 
      element.second->UnReference();
55
 
 
56
 
  texture_map.clear ();
57
 
 
58
 
  if (theme_changed_id_)
59
 
    g_signal_handler_disconnect(gtk_icon_theme_get_default(), theme_changed_id_);
60
 
}
61
 
 
62
 
void SimpleLauncherIcon::OnMouseDown(int button)
63
 
{
64
 
}
65
 
 
66
 
void SimpleLauncherIcon::OnMouseUp(int button)
67
 
{
68
 
}
69
 
 
70
 
void SimpleLauncherIcon::OnMouseClick(int button)
71
 
{
72
 
}
73
 
 
74
 
void SimpleLauncherIcon::OnMouseEnter()
75
 
{
76
 
}
77
 
 
78
 
void SimpleLauncherIcon::OnMouseLeave()
79
 
{
80
 
}
81
 
 
82
 
void SimpleLauncherIcon::ActivateLauncherIcon(ActionArg arg)
83
 
{
84
 
  activate.emit();
85
 
  ubus_server_send_message(ubus_server_get_default(),
86
 
                           UBUS_PLACE_VIEW_CLOSE_REQUEST,
87
 
                           g_variant_new_boolean(FALSE));
88
 
}
89
 
 
90
 
nux::BaseTexture* SimpleLauncherIcon::GetTextureForSize(int size)
91
 
{
92
 
  if (texture_map[size] != 0)
93
 
    return texture_map[size];
94
 
 
95
 
  if (icon_name_.empty())
96
 
    return 0;
97
 
 
98
 
  if (icon_name_[0] == '/')
99
 
    texture_map[size] = TextureFromPath(icon_name_.c_str(), size);
100
 
  else
101
 
    texture_map[size] = TextureFromGtkTheme(icon_name_.c_str(), size);
102
 
  return texture_map[size];
103
 
}
104
 
 
105
 
void SimpleLauncherIcon::SetIconName(const char* name)
106
 
{
107
 
  if (name == NULL)
108
 
  {
109
 
    LOG_WARNING(logger) << "attempted to set NULL as IconName";
110
 
    icon_name_.clear();
111
 
  }
112
 
  else
113
 
  {
114
 
    icon_name_ = name;
115
 
  }
116
 
 
117
 
  ReloadIcon();
118
 
}
119
 
 
120
 
void SimpleLauncherIcon::ReloadIcon()
121
 
{
122
 
  for (auto element : texture_map)
123
 
    if (element.second)
124
 
      element.second->UnReference();
125
 
 
126
 
  texture_map.clear ();
127
 
  needs_redraw.emit(this);
128
 
}
129
 
 
130
 
void SimpleLauncherIcon::OnIconThemeChanged(GtkIconTheme* icon_theme, gpointer data)
131
 
{
132
 
  SimpleLauncherIcon* self = static_cast<SimpleLauncherIcon*>(data);
133
 
 
134
 
  // invalidate the current cache
135
 
  self->_current_theme_is_mono = -1;
136
 
  self->ReloadIcon();
 
22
    if (m_Icon)
 
23
      delete m_Icon;
 
24
}
 
25
 
 
26
void
 
27
SimpleLauncherIcon::OnMouseDown ()
 
28
{
 
29
}
 
30
 
 
31
void
 
32
SimpleLauncherIcon::OnMouseUp ()
 
33
{
 
34
}
 
35
 
 
36
void
 
37
SimpleLauncherIcon::OnMouseClick ()
 
38
{
 
39
}
 
40
 
 
41
void
 
42
SimpleLauncherIcon::OnMouseEnter ()
 
43
{
 
44
}
 
45
 
 
46
void
 
47
SimpleLauncherIcon::OnMouseLeave ()
 
48
{
 
49
}
 
50
 
 
51
void SimpleLauncherIcon::Remove ()
 
52
{
 
53
    remove.emit (this);
 
54
}
 
55
 
 
56
nux::BaseTexture *
 
57
SimpleLauncherIcon::GetTextureForSize (int size)
 
58
{
 
59
    if (m_Icon && size == m_Icon->GetHeight ())
 
60
      return m_Icon;
 
61
      
 
62
    if (m_Icon)
 
63
      delete m_Icon;
 
64
    
 
65
    if (!m_IconName)
 
66
      return 0;
 
67
    
 
68
    m_Icon = TextureFromGtkTheme (m_IconName, size);
 
69
    return m_Icon;
 
70
}
 
71
 
 
72
void 
 
73
SimpleLauncherIcon::SetIconName (const char *name)
 
74
{
 
75
    m_IconName = g_strdup (name);
137
76
}