Back to index

unity  6.0.0
LauncherModel.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 #ifndef LAUNCHERMODEL_H
00021 #define LAUNCHERMODEL_H
00022 
00023 #include <UnityCore/GLibSource.h>
00024 #include "AbstractLauncherIcon.h"
00025 #include "unity-shared/Introspectable.h"
00026 
00027 namespace unity
00028 {
00029 namespace launcher
00030 {
00031 
00032 class LauncherModel : public unity::debug::Introspectable, public sigc::trackable
00033 {
00034 public:
00035   typedef std::shared_ptr<LauncherModel> Ptr;
00036   typedef std::vector<AbstractLauncherIcon::Ptr> Base;
00037   typedef Base::iterator iterator;
00038   typedef Base::const_iterator const_iterator;
00039   typedef Base::reverse_iterator reverse_iterator;
00040   typedef Base::reverse_iterator const_reverse_iterator;
00041 
00042   LauncherModel();
00043 
00044   void AddIcon(AbstractLauncherIcon::Ptr icon);
00045   void RemoveIcon(AbstractLauncherIcon::Ptr icon);
00046   void Save();
00047   void Sort();
00048   int  Size() const;
00049 
00050   void OnIconRemove(AbstractLauncherIcon::Ptr icon);
00051 
00052   bool IconHasSister(AbstractLauncherIcon::Ptr icon) const;
00053 
00054   void ReorderAfter(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other);
00055   void ReorderBefore(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save);
00056 
00057   void ReorderSmart(AbstractLauncherIcon::Ptr icon, AbstractLauncherIcon::Ptr other, bool save);
00058 
00059   AbstractLauncherIcon::Ptr Selection() const;
00060   int SelectionIndex() const;
00061   void SetSelection(int selection);
00062   void SelectNext();
00063   void SelectPrevious();
00064 
00065   iterator begin();
00066   iterator end();
00067   iterator at(int index);
00068   reverse_iterator rbegin();
00069   reverse_iterator rend();
00070 
00071   iterator main_begin();
00072   iterator main_end();
00073   reverse_iterator main_rbegin();
00074   reverse_iterator main_rend();
00075 
00076   iterator shelf_begin();
00077   iterator shelf_end();
00078   reverse_iterator shelf_rbegin();
00079   reverse_iterator shelf_rend();
00080 
00081   sigc::signal<void, AbstractLauncherIcon::Ptr> icon_added;
00082   sigc::signal<void, AbstractLauncherIcon::Ptr> icon_removed;
00083   sigc::signal<void> order_changed;
00084   sigc::signal<void> saved;
00085   sigc::signal<void, AbstractLauncherIcon::Ptr> selection_changed;
00086 
00087   IntrospectableList GetIntrospectableChildren();
00088 protected:
00089   // Introspectable methods
00090   std::string GetName() const;
00091   void AddProperties(GVariantBuilder* builder);
00092 
00093 private:
00094   Base             _inner;
00095   Base             _inner_shelf;
00096   Base             _inner_main;
00097   int              selection_;
00098   std::list<unity::debug::Introspectable*> introspection_results_;
00099   glib::SourceManager timeouts_;
00100 
00101   bool Populate();
00102 
00103   bool IconShouldShelf(AbstractLauncherIcon::Ptr icon) const;
00104 
00105   static bool CompareIcons(AbstractLauncherIcon::Ptr first, AbstractLauncherIcon::Ptr second);
00106 
00107   /* Template Methods */
00108 public:
00109   template<class T>
00110   std::list<AbstractLauncherIcon::Ptr> GetSublist()
00111   {
00112     std::list<AbstractLauncherIcon::Ptr> result;
00113 
00114     iterator it;
00115     for (it = begin(); it != end(); it++)
00116     {
00117       T* var = dynamic_cast<T*>((*it).GetPointer());
00118 
00119       if (var)
00120         result.push_back(*it);
00121     }
00122 
00123     return result;
00124   }
00125 };
00126 
00127 }
00128 }
00129 
00130 #endif // LAUNCHERMODEL_H
00131