Back to index

unity  6.0.0
BFBLauncherIcon.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011 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  *              Andrea Azzarone <azzaronea@gmail.com>
00019  */
00020 
00021 #include "BFBLauncherIcon.h"
00022 #include "Launcher.h"
00023 
00024 #include "unity-shared/UBusMessages.h"
00025 
00026 #include <glib/gi18n-lib.h>
00027 
00028 namespace unity
00029 {
00030 namespace launcher
00031 {
00032 
00033 UBusManager BFBLauncherIcon::ubus_manager_;
00034 
00035 BFBLauncherIcon::BFBLauncherIcon(LauncherHideMode hide_mode)
00036  : SimpleLauncherIcon()
00037  , reader_(dash::LensDirectoryReader::GetDefault())
00038  , launcher_hide_mode_(hide_mode)
00039 {
00040   tooltip_text = _("Dash Home");
00041   icon_name = PKGDATADIR"/launcher_bfb.png";
00042   SetQuirk(QUIRK_VISIBLE, true);
00043   SetQuirk(QUIRK_RUNNING, false);
00044   SetIconType(TYPE_HOME);
00045 
00046   background_color_ = nux::color::White;
00047 
00048   mouse_enter.connect([&](int m) { ubus_manager_.SendMessage(UBUS_DASH_ABOUT_TO_SHOW, NULL); });
00049   ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, sigc::bind(sigc::mem_fun(this, &BFBLauncherIcon::OnOverlayShown), true));
00050   ubus_manager_.RegisterInterest(UBUS_OVERLAY_HIDDEN, sigc::bind(sigc::mem_fun(this, &BFBLauncherIcon::OnOverlayShown), false));
00051 }
00052 
00053 void BFBLauncherIcon::SetHideMode(LauncherHideMode hide_mode)
00054 {
00055   launcher_hide_mode_ = hide_mode;
00056 }
00057 
00058 void BFBLauncherIcon::OnOverlayShown(GVariant *data, bool visible)
00059 {
00060   unity::glib::String overlay_identity;
00061   gboolean can_maximise = FALSE;
00062   gint32 overlay_monitor = 0;
00063   g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING,
00064                 &overlay_identity, &can_maximise, &overlay_monitor);
00065 
00066   if (overlay_identity.Str() == "dash" && IsVisibleOnMonitor(overlay_monitor))
00067   {
00068     tooltip_enabled = !visible;
00069     SetQuirk(QUIRK_ACTIVE, visible);
00070     EmitNeedsRedraw();
00071   }
00072   // If the hud is open, we hide the BFB if we have a locked launcher
00073   else if (overlay_identity.Str() == "hud")
00074   {
00075     if (launcher_hide_mode_ == LAUNCHER_HIDE_NEVER)
00076     {
00077       SetVisibleOnMonitor(overlay_monitor, !visible);
00078       EmitNeedsRedraw();
00079     }
00080   }
00081 }
00082 
00083 nux::Color BFBLauncherIcon::BackgroundColor() const
00084 {
00085   return background_color_;
00086 }
00087 
00088 nux::Color BFBLauncherIcon::GlowColor()
00089 {
00090   return background_color_;
00091 }
00092 
00093 void BFBLauncherIcon::ActivateLauncherIcon(ActionArg arg)
00094 {
00095   ubus_manager_.SendMessage(UBUS_PLACE_ENTRY_ACTIVATE_REQUEST, g_variant_new("(sus)", "home.lens", dash::NOT_HANDLED, ""));
00096 
00097   // dont chain down to avoid random dash close events
00098 }
00099 
00100 void BFBLauncherIcon::OnMenuitemActivated(DbusmenuMenuitem* item,
00101                                           int time,
00102                                           gchar* lens)
00103 {
00104   if (lens != NULL)
00105   {
00106     ubus_manager_.SendMessage(UBUS_PLACE_ENTRY_ACTIVATE_REQUEST, g_variant_new("(sus)", lens, dash::GOTO_DASH_URI, ""));
00107     g_free(lens);
00108   }
00109 }
00110 
00111 std::list<DbusmenuMenuitem*> BFBLauncherIcon::GetMenus()
00112 {
00113   std::list<DbusmenuMenuitem*> result;
00114   DbusmenuMenuitem* menu_item;
00115 
00116   // Home dash
00117   menu_item = dbusmenu_menuitem_new();
00118 
00119   dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Dash Home"));
00120   dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
00121   dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
00122 
00123   g_signal_connect(menu_item,
00124                    DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
00125                    (GCallback)&BFBLauncherIcon::OnMenuitemActivated,
00126                    g_strdup("home.lens"));
00127 
00128   result.push_back(menu_item);
00129 
00130   // Other lenses..
00131   for (auto lens : reader_->GetLensData())
00132   {
00133     if (!lens->visible)
00134       continue;
00135 
00136     menu_item = dbusmenu_menuitem_new();
00137 
00138     dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, lens->name);
00139     dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
00140     dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
00141 
00142     g_signal_connect(menu_item,
00143                      DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
00144                      (GCallback)&BFBLauncherIcon::OnMenuitemActivated,
00145                      g_strdup(lens->id));
00146 
00147     result.push_back(menu_item);
00148   }
00149 
00150   return result;
00151 }
00152 
00153 std::string BFBLauncherIcon::GetName() const
00154 {
00155   return "BFBLauncherIcon";
00156 }
00157 
00158 } // namespace launcher
00159 } // namespace unity
00160