Back to index

unity  6.0.0
Filter.h
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: Neil Jagdish Patel <neil.patel@canonical.com>
00018  */
00019 
00020 #ifndef UNITY_FILTER_H
00021 #define UNITY_FILTER_H
00022 
00023 #include <dee.h>
00024 #include <map>
00025 #include <memory>
00026 #include <NuxCore/Property.h>
00027 #include <sigc++/trackable.h>
00028 
00029 #include "GLibSignal.h"
00030 #include "Variant.h"
00031 
00032 namespace unity
00033 {
00034 namespace dash
00035 {
00036 
00037 enum FilterColumn
00038 {
00039   ID = 0,
00040   NAME,
00041   ICON_HINT,
00042   RENDERER_NAME,
00043   RENDERER_STATE,
00044   VISIBLE,
00045   COLLAPSED,
00046   FILTERING
00047 };
00048 
00049 class FilterOption : public sigc::trackable
00050 {
00051 public:
00052   typedef std::shared_ptr<FilterOption> Ptr;
00053 
00054   FilterOption(std::string id_, std::string name_, std::string icon_hint_, bool active_)
00055     : id(id_)
00056     , name(name_)
00057     , icon_hint(icon_hint_)
00058     , active(active_)
00059   {}
00060   nux::Property<std::string> id;
00061   nux::Property<std::string> name;
00062   nux::Property<std::string> icon_hint;
00063   nux::Property<bool> active;
00064 };
00065 
00066 class Filter : public sigc::trackable
00067 {
00068 public:
00069   typedef std::shared_ptr<Filter> Ptr;
00070   typedef std::map<std::string, unity::glib::Variant> Hints;
00071 
00072   Filter(DeeModel* model, DeeModelIter* iter);
00073   virtual ~Filter();
00074 
00075   static Filter::Ptr FilterFromIter(DeeModel* model, DeeModelIter* iter);
00076 
00077   virtual void Clear() = 0;
00078   bool IsValid() const;
00079 
00080   nux::ROProperty<std::string> id;
00081   nux::ROProperty<std::string> name;
00082   nux::ROProperty<std::string> icon_hint;
00083   nux::ROProperty<std::string> renderer_name;
00084   nux::ROProperty<bool> visible;
00085   nux::ROProperty<bool> collapsed;
00086   nux::ROProperty<bool> filtering;
00087 
00088   sigc::signal<void> removed;
00089 
00090 protected:
00091   virtual void Update(Hints& hints) = 0;
00092   void Refresh();
00093   void IgnoreChanges(bool ignore);
00094 
00095 private:
00096   void SetupGetters();
00097   static void OnModelDestroyed(Filter* self, DeeModel* old_location);
00098   void OnRowChanged(DeeModel* model, DeeModelIter* iter);
00099   void OnRowRemoved(DeeModel* model, DeeModelIter* iter);
00100   void HintsToMap(Hints& hints);
00101 
00102   std::string get_id() const;
00103   std::string get_name() const;
00104   std::string get_icon_hint() const;
00105   std::string get_renderer_name() const;
00106   bool get_visible() const;
00107   bool get_collapsed() const;
00108   bool get_filtering() const;
00109 
00110 protected:
00111   DeeModel* model_;
00112   DeeModelIter* iter_;
00113   glib::SignalManager signal_manager_;
00114   bool ignore_changes_;
00115 };
00116 
00117 }
00118 }
00119 
00120 #endif