Back to index

unity  6.0.0
SimpleLauncherIcon.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Jason Smith <jason.smith@canonical.com>
00018  */
00019 
00020 #ifndef UNITY_SIMPLELAUNCHERICON_H
00021 #define UNITY_SIMPLELAUNCHERICON_H
00022 
00023 #include <NuxCore/Logger.h>
00024 #include <Nux/Nux.h>
00025 #include <Nux/BaseWindow.h>
00026 #include <UnityCore/Variant.h>
00027 
00028 #include "SimpleLauncherIcon.h"
00029 #include "unity-shared/PluginAdapter.h"
00030 
00031 #include "unity-shared/ubus-server.h"
00032 #include "unity-shared/UBusMessages.h"
00033 
00034 namespace unity
00035 {
00036 namespace launcher
00037 {
00038 
00039 namespace
00040 {
00041   nux::logging::Logger logger("unity.dash.CategoryViewGrid");
00042 }
00043 
00044 NUX_IMPLEMENT_OBJECT_TYPE(SimpleLauncherIcon);
00045 
00046 SimpleLauncherIcon::SimpleLauncherIcon()
00047   : icon_name("", sigc::mem_fun(this, &SimpleLauncherIcon::SetIconName))
00048   , theme_changed_id_(0)
00049 {
00050   LauncherIcon::mouse_down.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseDown));
00051   LauncherIcon::mouse_up.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseUp));
00052   LauncherIcon::mouse_click.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseClick));
00053   LauncherIcon::mouse_enter.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseEnter));
00054   LauncherIcon::mouse_leave.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseLeave));
00055 
00056   theme_changed_id_ = g_signal_connect(gtk_icon_theme_get_default(), "changed",
00057                                        G_CALLBACK(SimpleLauncherIcon::OnIconThemeChanged), this);
00058 }
00059 
00060 SimpleLauncherIcon::~SimpleLauncherIcon()
00061 {
00062   for (auto element : texture_map)
00063     if (element.second)
00064       element.second->UnReference();
00065 
00066   texture_map.clear ();
00067 
00068   if (theme_changed_id_)
00069     g_signal_handler_disconnect(gtk_icon_theme_get_default(), theme_changed_id_);
00070 }
00071 
00072 void SimpleLauncherIcon::OnMouseDown(int button, int monitor, unsigned long key_flags)
00073 {
00074 }
00075 
00076 void SimpleLauncherIcon::OnMouseUp(int button, int monitor, unsigned long key_flags)
00077 {
00078 }
00079 
00080 void SimpleLauncherIcon::OnMouseClick(int button, int monitor, unsigned long key_flags)
00081 {
00082 }
00083 
00084 void SimpleLauncherIcon::OnMouseEnter(int monitor)
00085 {
00086 }
00087 
00088 void SimpleLauncherIcon::OnMouseLeave(int monitor)
00089 {
00090 }
00091 
00092 void SimpleLauncherIcon::ActivateLauncherIcon(ActionArg arg)
00093 {
00094   activate.emit();
00095   ubus_server_send_message(ubus_server_get_default(),
00096                            UBUS_PLACE_VIEW_CLOSE_REQUEST,
00097                            g_variant_new_boolean(FALSE));
00098 }
00099 
00100 nux::BaseTexture* SimpleLauncherIcon::GetTextureForSize(int size)
00101 {
00102   if (texture_map[size] != 0)
00103     return texture_map[size];
00104 
00105   std::string icon_string(icon_name());
00106 
00107   if (icon_string.empty())
00108     return 0;
00109 
00110   if (icon_string[0] == '/')
00111     texture_map[size] = TextureFromPath(icon_string.c_str(), size);
00112   else
00113     texture_map[size] = TextureFromGtkTheme(icon_string.c_str(), size);
00114   return texture_map[size];
00115 }
00116 
00117 bool SimpleLauncherIcon::SetIconName(std::string& target, std::string const& value)
00118 {
00119   if (target == value)
00120     return false;
00121 
00122   target = value;
00123   ReloadIcon();
00124 
00125   return true;
00126 }
00127 
00128 void SimpleLauncherIcon::ReloadIcon()
00129 {
00130   for (auto element : texture_map)
00131     if (element.second)
00132       element.second->UnReference();
00133 
00134   texture_map.clear ();
00135   EmitNeedsRedraw();
00136 }
00137 
00138 void SimpleLauncherIcon::OnIconThemeChanged(GtkIconTheme* icon_theme, gpointer data)
00139 {
00140   SimpleLauncherIcon* self = static_cast<SimpleLauncherIcon*>(data);
00141 
00142   // invalidate the current cache
00143   self->_current_theme_is_mono = -1;
00144   self->ReloadIcon();
00145 }
00146 
00147 std::string SimpleLauncherIcon::GetName() const
00148 {
00149   return "SimpleLauncherIcon";
00150 }
00151 
00152 void SimpleLauncherIcon::AddProperties(GVariantBuilder* builder)
00153 {
00154   LauncherIcon::AddProperties(builder);
00155   variant::BuilderWrapper(builder).add("icon_name", icon_name);
00156 }
00157 
00158 } // namespace launcher
00159 } // namespace unity
00160 
00161 #endif