Back to index

unity  6.0.0
MockLauncherIcon.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 MOCKLAUNCHERICON_H
00022 #define MOCKLAUNCHERICON_H
00023 
00024 #include <Nux/Nux.h>
00025 #include <NuxCore/Math/MathInc.h>
00026 
00027 #include <Nux/BaseWindow.h>
00028 #include <Nux/View.h>
00029 
00030 #include <gtk/gtk.h>
00031 
00032 #include <sigc++/sigc++.h>
00033 
00034 #include <libdbusmenu-glib/menuitem.h>
00035 
00036 #include "AbstractLauncherIcon.h"
00037 
00038 namespace unity
00039 {
00040 namespace launcher
00041 {
00042 
00043 class MockLauncherIcon : public AbstractLauncherIcon
00044 {
00045   NUX_DECLARE_OBJECT_TYPE(MockLauncherIcon, AbstractLauncherIcon);
00046 public:
00047   MockLauncherIcon()
00048     : icon_(0)
00049   {
00050     tooltip_text = "Mock Icon";
00051     sort_priority_ = 0;
00052     type_ = TYPE_APPLICATION;
00053   }
00054 
00055   std::string GetName() const { return "MockLauncherIcon"; }
00056   
00057   void AddProperties(GVariantBuilder* builder) {}
00058 
00059   void HideTooltip() {}
00060 
00061   void    SetShortcut(guint64 shortcut) {}
00062 
00063   guint64 GetShortcut()
00064   {
00065     return 0;
00066   }
00067 
00068   std::vector<Window> Windows ()
00069   {
00070     std::vector<Window> result;
00071 
00072     result.push_back ((100 << 16) + 200);
00073     result.push_back ((500 << 16) + 200);
00074     result.push_back ((300 << 16) + 200);
00075     result.push_back ((200 << 16) + 200);
00076     result.push_back ((300 << 16) + 200);
00077     result.push_back ((100 << 16) + 200);
00078     result.push_back ((300 << 16) + 200);
00079     result.push_back ((600 << 16) + 200);
00080 
00081     return result;
00082   }
00083 
00084   std::vector<Window> WindowsOnViewport ()
00085   {
00086     std::vector<Window> result;
00087 
00088     result.push_back ((100 << 16) + 200);
00089     result.push_back ((500 << 16) + 200);
00090     result.push_back ((300 << 16) + 200);
00091     result.push_back ((200 << 16) + 200);
00092     result.push_back ((300 << 16) + 200);
00093     result.push_back ((100 << 16) + 200);
00094     result.push_back ((300 << 16) + 200);
00095     result.push_back ((600 << 16) + 200);
00096 
00097     return result;
00098   }
00099 
00100   std::vector<Window> WindowsForMonitor (int monitor)
00101   {
00102     std::vector<Window> result;
00103 
00104     result.push_back ((100 << 16) + 200);
00105     result.push_back ((500 << 16) + 200);
00106     result.push_back ((300 << 16) + 200);
00107     result.push_back ((200 << 16) + 200);
00108     result.push_back ((300 << 16) + 200);
00109     result.push_back ((100 << 16) + 200);
00110     result.push_back ((300 << 16) + 200);
00111     result.push_back ((600 << 16) + 200);
00112 
00113     return result;
00114   }
00115 
00116   std::string NameForWindow (Window window)
00117   {
00118     return std::string();
00119   }
00120 
00121   void SetSortPriority(int priority) { sort_priority_ = priority; }
00122 
00123   bool OpenQuicklist(bool select_first_item = false, int monitor = -1)
00124   {
00125     return false;
00126   }
00127 
00128   void        SetCenter(nux::Point3 center, int monitor, nux::Geometry geo) {}
00129 
00130   nux::Point3 GetCenter(int monitor)
00131   {
00132     return nux::Point3();
00133   }
00134 
00135   nux::Point3 GetSavedCenter(int monitor)
00136   {
00137     return nux::Point3();
00138   }
00139 
00140   void SaveCenter() {}
00141 
00142   void Activate(ActionArg arg) {}
00143 
00144   void OpenInstance(ActionArg arg) {}
00145 
00146   int SortPriority()
00147   {
00148     return sort_priority_;
00149   }
00150 
00151   int RelatedWindows()
00152   {
00153     return 7;
00154   }
00155 
00156   const bool WindowVisibleOnViewport()
00157   {
00158     return false;
00159   }
00160 
00161   const bool WindowVisibleOnMonitor(int monitor)
00162   {
00163     return false;
00164   }
00165 
00166   void SetVisibleOnMonitor(int monitor, bool visible) {}
00167 
00168   bool IsVisibleOnMonitor(int monitor) const
00169   {
00170     return true;
00171   }
00172 
00173   bool IsSpacer()
00174   {
00175     return false;
00176   }
00177 
00178   float PresentUrgency()
00179   {
00180     return 0.0f;
00181   }
00182 
00183   float GetProgress()
00184   {
00185     return 0.0f;
00186   }
00187 
00188   bool ShowInSwitcher(bool current)
00189   {
00190     return true;
00191   }
00192 
00193   void InsertEntryRemote(LauncherEntryRemote::Ptr const& remote) {}
00194 
00195   void RemoveEntryRemote(LauncherEntryRemote::Ptr const& remote) {}
00196 
00197   unsigned long long SwitcherPriority()
00198   {
00199     return 0;
00200   }
00201 
00202   bool GetQuirk(Quirk quirk) const
00203   {
00204     return false;
00205   }
00206 
00207   void SetQuirk(Quirk quirk, bool value) {}
00208 
00209   void ResetQuirkTime(Quirk quirk) {};
00210 
00211   struct timespec GetQuirkTime(Quirk quirk)
00212   {
00213     timespec tv;
00214     return tv;
00215   }
00216 
00217   IconType GetIconType()
00218   {
00219     return type_;
00220   }
00221 
00222   nux::Color BackgroundColor() const
00223   {
00224     return nux::Color(0xFFAAAAAA);
00225   }
00226 
00227   nux::Color GlowColor()
00228   {
00229     return nux::Color(0xFFAAAAAA);
00230   }
00231 
00232   std::string RemoteUri()
00233   {
00234     return "fake";
00235   }
00236 
00237   nux::BaseTexture* TextureForSize(int size)
00238   {
00239     if (icon_ && size == icon_->GetHeight())
00240       return icon_;
00241 
00242     if (icon_)
00243       icon_->UnReference();
00244     icon_ = 0;
00245 
00246     icon_ = TextureFromGtkTheme("firefox", size);
00247     return icon_;
00248   }
00249 
00250   nux::BaseTexture* Emblem()
00251   {
00252     return 0;
00253   }
00254 
00255   std::list<DbusmenuMenuitem*> Menus()
00256   {
00257     return std::list<DbusmenuMenuitem*> ();
00258   }
00259 
00260   nux::DndAction QueryAcceptDrop(DndData const& dnd_data)
00261   {
00262     return nux::DNDACTION_NONE;
00263   }
00264 
00265   bool ShouldHighlightOnDrag(DndData const& dnd_data)
00266   {
00267     return false;
00268   }
00269 
00270   void AcceptDrop(DndData const& dnd_data) {}
00271 
00272   void SendDndEnter() {}
00273 
00274   void SendDndLeave() {}
00275 
00276   std::string DesktopFile() { return std::string(""); }
00277 
00278   bool IsSticky() const { return false; }
00279 
00280   bool IsVisible() const { return false; }
00281 
00282   void AboutToRemove() {}
00283   
00284   void Stick(bool save = true) {}
00285   
00286   void UnStick() {}
00287 
00288 private:
00289   nux::BaseTexture* TextureFromGtkTheme(const char* icon_name, int size)
00290   {
00291     GdkPixbuf* pbuf;
00292     GtkIconInfo* info;
00293     nux::BaseTexture* result = NULL;
00294     GError* error = NULL;
00295     GIcon* icon;
00296 
00297     GtkIconTheme* theme = gtk_icon_theme_get_default();
00298 
00299     icon = g_icon_new_for_string(icon_name, NULL);
00300 
00301     if (G_IS_ICON(icon))
00302     {
00303       info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
00304       g_object_unref(icon);
00305     }
00306     else
00307     {
00308       info = gtk_icon_theme_lookup_icon(theme,
00309                                         icon_name,
00310                                         size,
00311                                         (GtkIconLookupFlags) 0);
00312     }
00313 
00314     if (!info)
00315       return NULL;
00316 
00317     pbuf = gtk_icon_info_load_icon(info, &error);
00318     gtk_icon_info_free(info);
00319 
00320     if (GDK_IS_PIXBUF(pbuf))
00321     {
00322       result = nux::CreateTexture2DFromPixbuf(pbuf, true);
00323       g_object_unref(pbuf);
00324     }
00325     else
00326     {
00327       g_warning("Unable to load '%s' from icon theme: %s",
00328                 icon_name,
00329                 error ? error->message : "unknown");
00330       g_error_free(error);
00331     }
00332 
00333     return result;
00334   }
00335 
00336   nux::BaseTexture* icon_;
00337   int sort_priority_;
00338   IconType type_;
00339 };
00340 
00341 NUX_IMPLEMENT_OBJECT_TYPE(MockLauncherIcon);
00342 
00343 }
00344 }
00345 
00346 #endif // MOCKLAUNCHERICON_H
00347