Back to index

unity  6.0.0
FilterGenreWidget.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2011 Canonical Ltd.
00004  *
00005  * This program is free software: you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser 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, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License version 3 along with this program.  If not, see
00017  * <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Gordon Allott <gord.allott@canonical.com>
00020  *
00021  */
00022 
00023 #include <glib.h>
00024 #include <glib/gi18n-lib.h>
00025 #include <UnityCore/GLibWrapper.h>
00026 
00027 #include "unity-shared/DashStyle.h"
00028 #include "FilterGenreWidget.h"
00029 #include "FilterGenreButton.h"
00030 #include "FilterBasicButton.h"
00031 
00032 namespace unity
00033 {
00034 namespace dash
00035 {
00036 
00037 NUX_IMPLEMENT_OBJECT_TYPE(FilterGenre);
00038 
00039 FilterGenre::FilterGenre(int columns, NUX_FILE_LINE_DECL)
00040  : FilterExpanderLabel(_("Categories"), NUX_FILE_LINE_PARAM)
00041 {
00042   dash::Style& style = dash::Style::Instance();
00043 
00044   InitTheme();
00045 
00046   all_button_ = new FilterAllButton(NUX_TRACKER_LOCATION);
00047 
00048   genre_layout_ = new nux::GridHLayout(NUX_TRACKER_LOCATION);
00049   genre_layout_->ForceChildrenSize(true);
00050   genre_layout_->MatchContentSize(true);
00051   genre_layout_->SetTopAndBottomPadding(style.GetSpaceBetweenFilterWidgets() - style.GetFilterHighlightPadding(), style.GetFilterHighlightPadding());
00052   genre_layout_->EnablePartialVisibility(false);
00053 
00054   if (columns == 3)
00055   {
00056     genre_layout_->SetChildrenSize((style.GetFilterBarWidth() - 12 * 2) / 3, style.GetFilterButtonHeight());
00057     genre_layout_->SetSpaceBetweenChildren (12, 12);
00058   }
00059   else
00060   {
00061     genre_layout_->SetChildrenSize((style.GetFilterBarWidth() - 10 ) / 2, style.GetFilterButtonHeight());
00062     genre_layout_->SetSpaceBetweenChildren (10, 12);
00063   }
00064 
00065   SetRightHandView(all_button_);
00066   SetContents(genre_layout_);
00067 }
00068 
00069 FilterGenre::~FilterGenre()
00070 {
00071 }
00072 
00073 void FilterGenre::SetFilter(Filter::Ptr const& filter)
00074 {
00075   filter_ = std::static_pointer_cast<CheckOptionFilter>(filter);
00076 
00077   all_button_->SetFilter(filter_);
00078   expanded = !filter_->collapsed();
00079 
00080   filter_->option_added.connect(sigc::mem_fun(this, &FilterGenre::OnOptionAdded));
00081   filter_->option_removed.connect(sigc::mem_fun(this, &FilterGenre::OnOptionRemoved));
00082 
00083   // finally - make sure we are up-todate with our filter list
00084   for (auto it : filter_->options())
00085     OnOptionAdded(it);
00086 
00087   SetLabel(filter_->name);
00088 }
00089 
00090 void FilterGenre::OnOptionAdded(FilterOption::Ptr const& new_filter)
00091 {
00092   std::string tmp_label(new_filter->name);
00093 
00094   glib::String escape(g_markup_escape_text(tmp_label.c_str(), -1));
00095   std::string label(escape.Value());
00096 
00097   FilterGenreButton* button = new FilterGenreButton(label, NUX_TRACKER_LOCATION);
00098   button->SetFilter(new_filter);
00099   genre_layout_->AddView(button, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00100   buttons_.push_back(button);
00101 }
00102 
00103 void FilterGenre::OnOptionRemoved(FilterOption::Ptr const& removed_filter)
00104 {
00105   for (auto it=buttons_.begin() ; it != buttons_.end(); ++it)
00106   {
00107     if ((*it)->GetFilter() == removed_filter)
00108     {
00109       genre_layout_->RemoveChildObject(*it);
00110       buttons_.erase(it);
00111       break;
00112     }
00113   }
00114 }
00115 
00116 std::string FilterGenre::GetFilterType()
00117 {
00118   return "FilterBasicButton";
00119 }
00120 
00121 void FilterGenre::InitTheme()
00122 {
00123   //FIXME - build theme here - store images, cache them, fun fun fun
00124 }
00125 
00126 } // namespace dash
00127 } // namespace unity