Back to index

unity  6.0.0
HudLauncherIcon.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2012 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: Gordon Allott <gord.allott@canonical.com>
00018  */
00019 
00020 #include "HudLauncherIcon.h"
00021 #include "Launcher.h"
00022 #include "UnityCore/GLibWrapper.h"
00023 #include <NuxCore/Logger.h>
00024 
00025 #include "unity-shared/UBusMessages.h"
00026 
00027 #include <glib/gi18n-lib.h>
00028 
00029 namespace unity
00030 {
00031 namespace launcher
00032 {
00033 
00034 namespace
00035 {
00036 nux::logging::Logger logger("unity.launcher.hudlaunchericon");
00037 }
00038 
00039 UBusManager HudLauncherIcon::ubus_manager_;
00040 
00041 HudLauncherIcon::HudLauncherIcon(LauncherHideMode hide_mode)
00042  : SingleMonitorLauncherIcon(0)
00043  , launcher_hide_mode_(hide_mode)
00044 {
00045   tooltip_text = _("HUD");
00046   icon_name = PKGDATADIR"/launcher_bfb.png";
00047   SetQuirk(QUIRK_VISIBLE, false);
00048   SetQuirk(QUIRK_RUNNING, false);
00049   SetQuirk(QUIRK_ACTIVE, true);
00050   SetIconType(TYPE_HUD);
00051 
00052   background_color_ = nux::color::White;
00053 
00054   ubus_manager_.RegisterInterest(UBUS_HUD_ICON_CHANGED, [&](GVariant *data)
00055   {
00056     std::string hud_icon_name;
00057     const gchar* data_string = g_variant_get_string(data, NULL);
00058     if (data_string)
00059       hud_icon_name = data_string;
00060     LOG_DEBUG(logger) << "Hud icon change: " << hud_icon_name;
00061     if (hud_icon_name != icon_name)
00062     {
00063       if (hud_icon_name.empty())
00064         icon_name = PKGDATADIR"/launcher_bfb.png";
00065       else
00066         icon_name = hud_icon_name;
00067 
00068       EmitNeedsRedraw();
00069     }
00070   });
00071 
00072   ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, sigc::bind(sigc::mem_fun(this, &HudLauncherIcon::OnOverlayShown), true));
00073   ubus_manager_.RegisterInterest(UBUS_OVERLAY_HIDDEN, sigc::bind(sigc::mem_fun(this, &HudLauncherIcon::OnOverlayShown), false));
00074 
00075   mouse_enter.connect([&](int m) { ubus_manager_.SendMessage(UBUS_DASH_ABOUT_TO_SHOW); });
00076 }
00077 
00078 void HudLauncherIcon::SetHideMode(LauncherHideMode hide_mode)
00079 {
00080   if (launcher_hide_mode_ != hide_mode)
00081   {
00082     launcher_hide_mode_ = hide_mode;
00083 
00084     if (launcher_hide_mode_ == LAUNCHER_HIDE_AUTOHIDE)
00085       SetQuirk(QUIRK_VISIBLE, false);
00086   }
00087 }
00088 
00089 void HudLauncherIcon::OnOverlayShown(GVariant* data, bool visible)
00090 {
00091   unity::glib::String overlay_identity;
00092   gboolean can_maximise = FALSE;
00093   gint32 overlay_monitor = 0;
00094   g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING,
00095                 &overlay_identity, &can_maximise, &overlay_monitor);
00096 
00097   // If the hud is open, we show the HUD button if we have a locked launcher
00098   if (overlay_identity.Str() == "hud" &&
00099       launcher_hide_mode_ == LAUNCHER_HIDE_NEVER)
00100   {
00101     SetMonitor(overlay_monitor);
00102     SetQuirk(QUIRK_VISIBLE, visible);
00103     SetQuirk(QUIRK_ACTIVE, visible);
00104     tooltip_enabled = !visible;
00105     EmitNeedsRedraw();
00106   }
00107 }
00108 
00109 nux::Color HudLauncherIcon::BackgroundColor() const
00110 {
00111   return background_color_;
00112 }
00113 
00114 nux::Color HudLauncherIcon::GlowColor()
00115 {
00116   return background_color_;
00117 }
00118 
00119 void HudLauncherIcon::ActivateLauncherIcon(ActionArg arg)
00120 {
00121   if (GetQuirk(QUIRK_VISIBLE))
00122   {
00123     ubus_manager_.SendMessage(UBUS_HUD_CLOSE_REQUEST);
00124   }
00125 }
00126 
00127 std::list<DbusmenuMenuitem*> HudLauncherIcon::GetMenus()
00128 {
00129   std::list<DbusmenuMenuitem*> result;
00130   return result;
00131 }
00132 
00133 std::string HudLauncherIcon::GetName() const
00134 {
00135   return "HudLauncherIcon";
00136 }
00137 
00138 } // namespace launcher
00139 } // namespace unity
00140