1 /*
2    Vimpc
3    Copyright (C) 2010 - 2011 Nathan Sweetman
4 
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18    list.hpp - handling of multiple mpd playlists
19    */
20 
21 #ifndef __MPC__LISTS
22 #define __MPC__LISTS
23 
24 // Includes
25 #include "algorithm.hpp"
26 #include "buffer.hpp"
27 #include "settings.hpp"
28 
29 // Lists
30 namespace Mpc
31 {
32    class List
33    {
34       public:
List(std::string const & name)35          List(std::string const & name) : path_(name), name_(name), file_(false) { }
List(std::string const & path,std::string const & name)36          List(std::string const & path, std::string const & name) : path_(path), name_(name), file_(true) { }
37 
operator !=(Mpc::List const & rhs) const38          bool operator!=(Mpc::List const & rhs) const
39          {
40             return ((this->path_ != rhs.path_) ||
41                     (this->name_ != rhs.name_));
42          }
43 
44          std::string path_;
45          std::string name_;
46          bool        file_;
47    };
48 
49    class ListComparator
50    {
51       public:
operator ()(List i,List j)52       bool operator() (List i, List j)
53       {
54          return Algorithm::icompare(i.name_, j.name_,
55                   Main::Settings::Instance().Get(Setting::IgnoreTheSort),
56                   Main::Settings::Instance().Get(Setting::IgnoreCaseSort));
57       }
58    };
59 
60 
61    class Lists : public Main::Buffer<List>
62    {
63    public:
Lists()64       Lists()
65       {
66       }
~Lists()67       ~Lists()
68       {
69       }
70 
71    public:
72       using Main::Buffer<List>::Sort;
73 
Sort()74       void Sort()
75       {
76          ListComparator sorter;
77          Main::Buffer<List>::Sort(sorter);
78       }
79 
String(uint32_t position) const80       std::string String(uint32_t position) const      { return Get(position).name_; }
PrintString(uint32_t position) const81       std::string PrintString(uint32_t position) const { return " " + Get(position).name_; }
82    };
83 }
84 #endif
85 /* vim: set sw=3 ts=3: */
86