Back to index

unity  6.0.0
LauncherIcon.h
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 
00021 #ifndef LAUNCHERICON_H
00022 #define LAUNCHERICON_H
00023 
00024 #include <set>
00025 #include <boost/unordered_map.hpp>
00026 
00027 #include <Nux/Nux.h>
00028 #include <Nux/BaseWindow.h>
00029 #include <NuxCore/Math/MathInc.h>
00030 
00031 #include <gtk/gtk.h>
00032 #include <libdbusmenu-glib/client.h>
00033 #include <libdbusmenu-glib/menuitem.h>
00034 
00035 #include <UnityCore/GLibSource.h>
00036 #include "AbstractLauncherIcon.h"
00037 #include "Tooltip.h"
00038 #include "QuicklistView.h"
00039 #include "unity-shared/Introspectable.h"
00040 #include "LauncherEntryRemote.h"
00041 
00042 
00043 namespace unity
00044 {
00045 namespace launcher
00046 {
00047 
00048 class Launcher;
00049 
00050 class LauncherIcon : public AbstractLauncherIcon
00051 {
00052   NUX_DECLARE_OBJECT_TYPE(LauncherIcon, AbstractLauncherIcon);
00053 
00054 public:
00055   typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr;
00056 
00057   LauncherIcon();
00058 
00059   virtual ~LauncherIcon();
00060 
00061   bool SetTooltipText(std::string& target, std::string const& value);
00062 
00063   void    SetShortcut(guint64 shortcut);
00064 
00065   guint64 GetShortcut();
00066 
00067   void SetSortPriority(int priority);
00068 
00069   void RecvMouseEnter(int monitor);
00070 
00071   void RecvMouseLeave(int monitor);
00072 
00073   void RecvMouseDown(int button, int monitor, unsigned long key_flags = 0);
00074 
00075   void RecvMouseUp(int button, int monitor, unsigned long key_flags = 0);
00076 
00077   void RecvMouseClick(int button, int monitor, unsigned long key_flags = 0);
00078 
00079   void HideTooltip();
00080 
00081   void ShowTooltip();
00082 
00083   bool OpenQuicklist(bool select_first_item = false, int monitor = -1);
00084 
00085   void        SetCenter(nux::Point3 center, int parent_monitor, nux::Geometry parent_geo);
00086 
00087   nux::Point3 GetCenter(int monitor);
00088 
00089   virtual void Activate(ActionArg arg);
00090 
00091   void OpenInstance(ActionArg arg);
00092 
00093   void SaveCenter();
00094 
00095   nux::Point3 GetSavedCenter(int monitor);
00096 
00097   int SortPriority();
00098 
00099   virtual std::vector<Window> Windows() { return std::vector<Window> (); }
00100 
00101   virtual std::vector<Window> WindowsOnViewport() { return std::vector<Window> (); }
00102 
00103   virtual std::vector<Window> WindowsForMonitor(int monitor) { return std::vector<Window> (); }
00104 
00105   virtual std::string NameForWindow(Window window) { return std::string(); }
00106 
00107   const bool WindowVisibleOnMonitor(int monitor);
00108 
00109   const bool WindowVisibleOnViewport();
00110 
00111   virtual bool IsSpacer()
00112   {
00113     return false;
00114   };
00115 
00116   float PresentUrgency();
00117 
00118   float GetProgress();
00119 
00120   void SetEmblemIconName(std::string const& name);
00121 
00122   void SetEmblemText(std::string const& text);
00123 
00124   void DeleteEmblem();
00125 
00126   virtual bool ShowInSwitcher(bool current)
00127   {
00128     return false;
00129   };
00130 
00131   virtual unsigned long long SwitcherPriority()
00132   {
00133     return 0;
00134   }
00135 
00136   bool GetQuirk(Quirk quirk) const;
00137 
00138   void SetQuirk(Quirk quirk, bool value);
00139 
00140   struct timespec GetQuirkTime(Quirk quirk);
00141 
00142   IconType GetIconType();
00143 
00144   virtual nux::Color BackgroundColor() const;
00145 
00146   virtual nux::Color GlowColor();
00147 
00148   std::string RemoteUri()
00149   {
00150     return GetRemoteUri();
00151   }
00152 
00153   nux::BaseTexture* TextureForSize(int size);
00154 
00155   nux::BaseTexture* Emblem();
00156 
00157   std::list<DbusmenuMenuitem*> Menus();
00158 
00159   void InsertEntryRemote(LauncherEntryRemote::Ptr const& remote);
00160 
00161   void RemoveEntryRemote(LauncherEntryRemote::Ptr const& remote);
00162 
00163   nux::DndAction QueryAcceptDrop(DndData const& dnd_data)
00164   {
00165     return OnQueryAcceptDrop(dnd_data);
00166   }
00167 
00168 
00169   bool ShouldHighlightOnDrag(DndData const& dnd_data)
00170   {
00171     return OnShouldHighlightOnDrag(dnd_data);
00172   }
00173 
00174   void AcceptDrop(DndData const& dnd_data)
00175   {
00176     return OnAcceptDrop(dnd_data);
00177   }
00178 
00179   void SendDndEnter()
00180   {
00181     OnDndEnter();
00182   }
00183 
00184   void SendDndLeave()
00185   {
00186     OnDndLeave();
00187   }
00188 
00189   void SetIconType(IconType type);
00190 
00191   virtual std::string DesktopFile() { return std::string(""); }
00192 
00193   virtual bool IsSticky() const { return false; }
00194 
00195   virtual bool IsVisible() const { return false; }
00196 
00197   virtual bool IsVisibleOnMonitor(int monitor) const;
00198 
00199   virtual void SetVisibleOnMonitor(int monitor, bool visible);
00200 
00201   virtual void AboutToRemove() {}
00202 
00203   virtual void Stick(bool save = true) {}
00204 
00205   virtual void UnStick() {}
00206 
00207 protected:
00208   std::vector<nux::Point3> GetCenters();
00209 
00210   std::string GetName() const;
00211 
00212   void AddProperties(GVariantBuilder* builder);
00213 
00214   void UpdateQuirkTimeDelayed(guint ms, Quirk quirk);
00215 
00216   void UpdateQuirkTime(Quirk quirk);
00217 
00218   void ResetQuirkTime(Quirk quirk);
00219 
00220   void Remove();
00221 
00222   void SetProgress(float progress);
00223 
00224   void SetWindowVisibleOnMonitor(bool val, int monitor);
00225 
00226   void Present(float urgency, int length);
00227 
00228   void Unpresent();
00229 
00230   void SetEmblem(BaseTexturePtr const& emblem);
00231 
00232   virtual std::list<DbusmenuMenuitem*> GetMenus();
00233 
00234   virtual nux::BaseTexture* GetTextureForSize(int size) = 0;
00235 
00236   virtual void OnCenterStabilized(std::vector<nux::Point3> center) {}
00237 
00238   virtual std::string GetRemoteUri()
00239   {
00240     return "";
00241   }
00242 
00243   virtual nux::DndAction OnQueryAcceptDrop(DndData const& dnd_data)
00244   {
00245     return nux::DNDACTION_NONE;
00246   }
00247 
00248   virtual bool OnShouldHighlightOnDrag(DndData const& dnd_data)
00249   {
00250     return false;
00251   }
00252 
00253   virtual void OnAcceptDrop(DndData const& dnd_data) {}
00254 
00255   virtual void OnDndEnter() {}
00256 
00257   virtual void OnDndLeave() {}
00258 
00259   virtual void ActivateLauncherIcon(ActionArg arg) {}
00260 
00261   virtual void OpenInstanceLauncherIcon(ActionArg arg) {}
00262 
00263   virtual bool HandlesSpread () { return false; }
00264 
00265   nux::BaseTexture* TextureFromGtkTheme(std::string name, int size, bool update_glow_colors = true);
00266 
00267   nux::BaseTexture* TextureFromSpecificGtkTheme(GtkIconTheme* theme, std::string const& name, int size, bool update_glow_colors = true, bool is_default_theme = false);
00268 
00269   nux::BaseTexture* TextureFromPath(std::string const& name, int size, bool update_glow_colors = true);
00270 
00271   static bool        IsMonoDefaultTheme();
00272 
00273   GtkIconTheme*      GetUnityTheme();
00274 
00275   void OnRemoteEmblemChanged(LauncherEntryRemote* remote);
00276 
00277   void OnRemoteCountChanged(LauncherEntryRemote* remote);
00278 
00279   void OnRemoteProgressChanged(LauncherEntryRemote* remote);
00280 
00281   void OnRemoteQuicklistChanged(LauncherEntryRemote* remote);
00282 
00283   void OnRemoteUrgentChanged(LauncherEntryRemote* remote);
00284 
00285   void OnRemoteEmblemVisibleChanged(LauncherEntryRemote* remote);
00286 
00287   void OnRemoteCountVisibleChanged(LauncherEntryRemote* remote);
00288 
00289   void OnRemoteProgressVisibleChanged(LauncherEntryRemote* remote);
00290 
00291   void EmitNeedsRedraw();
00292 
00293   void EmitRemove();
00294 
00295   // This looks like a case for boost::logical::tribool
00296   static int _current_theme_is_mono;
00297 
00298   glib::Object<DbusmenuClient> _menuclient_dynamic_quicklist;
00299 
00300 private:
00301   nux::ObjectPtr<Tooltip> _tooltip;
00302   nux::ObjectPtr<QuicklistView> _quicklist;
00303 
00304   static void ChildRealized(DbusmenuMenuitem* newitem, QuicklistView* quicklist);
00305   static void RootChanged(DbusmenuClient* client, DbusmenuMenuitem* newroot, QuicklistView* quicklist);
00306   bool OnPresentTimeout();
00307   bool OnCenterStabilizeTimeout();
00308 
00309   void ColorForIcon(GdkPixbuf* pixbuf, nux::Color& background, nux::Color& glow);
00310 
00311   void LoadTooltip();
00312   void LoadQuicklist();
00313 
00314   void OnTooltipEnabledChanged(bool value);
00315 
00316   bool              _remote_urgent;
00317   float             _present_urgency;
00318   float             _progress;
00319   int               _sort_priority;
00320   int               _last_monitor;
00321   nux::Color        _background_color;
00322   nux::Color        _glow_color;
00323 
00324   gint64            _shortcut;
00325 
00326   IconType                 _icon_type;
00327 
00328   std::vector<nux::Point3> _center;
00329   std::vector<bool> _has_visible_window;
00330   std::vector<bool> _is_visible_on_monitor;
00331   std::vector<nux::Point3> _last_stable;
00332   std::vector<nux::Geometry> _parent_geo;
00333   std::vector<nux::Point3> _saved_center;
00334 
00335   static glib::Object<GtkIconTheme> _unity_theme;
00336 
00337   BaseTexturePtr _emblem;
00338 
00339   bool             _quirks[QUIRK_LAST];
00340   struct timespec  _quirk_times[QUIRK_LAST];
00341 
00342   std::list<LauncherEntryRemote::Ptr> _entry_list;
00343 
00344 protected:
00345   glib::SourceManager _source_manager;
00346 };
00347 
00348 }
00349 }
00350 
00351 #endif // LAUNCHERICON_H
00352