Back to index

unity  6.0.0
FilesystemLenses.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011-2012 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_FILESYSTEM_LENSES_H
00021 #define UNITY_FILESYSTEM_LENSES_H
00022 
00023 #include <memory>
00024 #include <sigc++/signal.h>
00025 #include <sigc++/trackable.h>
00026 
00027 #include "Lenses.h"
00028 
00029 namespace unity
00030 {
00031 namespace dash
00032 {
00033 
00034 class LensDirectoryReader : public sigc::trackable
00035 {
00036 public:
00037   struct LensFileData
00038   {
00039     LensFileData(GKeyFile* file, const gchar *lens_id);
00040     static bool IsValid(GKeyFile* file, glib::Error& error);
00041 
00042     glib::String id;
00043     glib::String domain;
00044     glib::String dbus_name;
00045     glib::String dbus_path;
00046     glib::String name;
00047     glib::String icon;
00048     glib::String description;
00049     glib::String search_hint;
00050     bool         visible;
00051     glib::String shortcut;
00052   };
00053 
00054   typedef std::shared_ptr<LensDirectoryReader> Ptr;
00055   typedef std::shared_ptr<LensFileData> LensFileDataPtr;
00056   typedef std::vector<LensFileDataPtr> DataList;
00057 
00058   LensDirectoryReader(std::string const& directory);
00059   ~LensDirectoryReader();
00060 
00061   static LensDirectoryReader::Ptr GetDefault();
00062 
00063   bool IsDataLoaded() const;
00064   DataList GetLensData() const;
00065 
00066   sigc::signal<void> load_finished;
00067 
00068 private:
00069   class Impl;
00070   Impl* pimpl;
00071 };
00072 
00073 // Reads Lens information from the filesystem, as per-specification, and creates
00074 // Lens instances using this data
00075 class FilesystemLenses : public Lenses
00076 {
00077 public:
00078   typedef std::shared_ptr<FilesystemLenses> Ptr;
00079 
00080   FilesystemLenses();
00081   FilesystemLenses(LensDirectoryReader::Ptr const& reader);
00082 
00083   ~FilesystemLenses();
00084 
00085   LensList GetLenses() const;
00086   Lens::Ptr GetLens(std::string const& lens_id) const;
00087   Lens::Ptr GetLensAtIndex(std::size_t index) const;
00088   Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const;
00089 
00090   sigc::signal<void> lenses_loaded;
00091 
00092 private:
00093   void Init();
00094 
00095   class Impl;
00096   Impl* pimpl;
00097 };
00098 
00099 }
00100 }
00101 
00102 #endif