1 /***************************************************************************
2 * Copyright (C) 2008-2009 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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 2 of the License, or *
8 * (at your option) any later version. *
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. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
25 std::string
Display::Columns()
27 if (Config
.columns
.empty())
30 std::string result
, tag
;
34 std::vector
<Column
>::const_iterator next2last
;
35 bool last_fixed
= Config
.columns
.back().fixed
;
36 if (Config
.columns
.size() > 1)
37 next2last
= Config
.columns
.end()-2;
39 for (std::vector
<Column
>::const_iterator it
= Config
.columns
.begin(); it
!= Config
.columns
.end(); ++it
)
41 width
= (last_fixed
&& it
== next2last
42 ? COLS
-where
-(++next2last
)->width
43 : (it
== Config
.columns
.end()-1
45 : (it
->width
*(it
->fixed
? 1 : COLS
/100.0))
95 if (it
->right_alignment
)
96 for (long i
= 0; i
< long(width
-tag
.length()-(it
!= Config
.columns
.begin())); ++i
, result
+= ' ') { }
101 if (result
.length() > where
)
102 result
= result
.substr(0, where
);
104 for (size_t i
= result
.length(); i
<= where
&& i
< size_t(COLS
); ++i
, result
+= ' ') { }
109 void Display::SongsInColumns(const MPD::Song
&s
, void *, Menu
<MPD::Song
> *menu
)
112 const_cast<MPD::Song
*>(&s
)->Localize();
114 bool is_now_playing
= menu
== myPlaylist
->Items
&& (menu
->isFiltered() ? s
.GetPosition() : menu
->CurrentlyDrawedPosition()) == size_t(myPlaylist
->NowPlaying
);
116 *menu
<< Config
.now_playing_prefix
;
118 if (Config
.columns
.empty())
121 std::vector
<Column
>::const_iterator next2last
, it
;
125 bool last_fixed
= Config
.columns
.back().fixed
;
126 if (Config
.columns
.size() > 1)
127 next2last
= Config
.columns
.end()-2;
129 for (it
= Config
.columns
.begin(); it
!= Config
.columns
.end(); ++it
)
133 menu
->GotoXY(where
, menu
->Y());
135 if ((it
-1)->color
!= clDefault
)
139 width
= (last_fixed
&& it
== next2last
140 ? COLS
-where
-(++next2last
)->width
141 : (it
== Config
.columns
.end()-1
142 ? menu
->GetWidth()-where
143 : (it
->width
*(it
->fixed
? 1 : COLS
/100.0))
147 MPD::Song::GetFunction get
= 0;
152 get
= &MPD::Song::GetLength
;
155 get
= &MPD::Song::GetDirectory
;
158 get
= &MPD::Song::GetName
;
161 get
= &MPD::Song::GetArtist
;
164 get
= &MPD::Song::GetAlbum
;
167 get
= &MPD::Song::GetDate
;
170 get
= &MPD::Song::GetTrackNumber
;
173 get
= &MPD::Song::GetTrack
;
176 get
= &MPD::Song::GetGenre
;
179 get
= &MPD::Song::GetComposer
;
182 get
= &MPD::Song::GetPerformer
;
185 get
= &MPD::Song::GetDisc
;
188 get
= &MPD::Song::GetComment
;
191 if (!s
.GetTitle().empty())
192 get
= &MPD::Song::GetTitle
;
194 get
= &MPD::Song::GetName
;
199 if (it
->color
!= clDefault
)
201 whline(menu
->Raw(), 32, menu
->GetWidth()-where
);
202 std::string tag
= get
? s
.GetTags(get
) : "";
203 if (it
->right_alignment
)
205 if (!tag
.empty() || it
->display_empty_tag
)
209 std::basic_string
<my_char_t
> wtag
= TO_WSTRING(tag
.empty() ? Config
.empty_tag
: tag
).substr(0, width
-!!x
);
210 *menu
<< XY(x
+width
-Window::Length(wtag
)-!!x
, y
) << wtag
;
217 else if (it
->display_empty_tag
)
218 *menu
<< Config
.empty_tag
;
222 if ((--it
)->color
!= clDefault
)
225 *menu
<< Config
.now_playing_suffix
;
228 void Display::Songs(const MPD::Song
&s
, void *data
, Menu
<MPD::Song
> *menu
)
231 const_cast<MPD::Song
*>(&s
)->Localize();
233 bool is_now_playing
= menu
== myPlaylist
->Items
&& (menu
->isFiltered() ? s
.GetPosition() : menu
->CurrentlyDrawedPosition()) == size_t(myPlaylist
->NowPlaying
);
235 *menu
<< Config
.now_playing_prefix
;
237 std::string line
= s
.toString(*static_cast<std::string
*>(data
), "$");
238 for (std::string::const_iterator it
= line
.begin(); it
!= line
.end(); ++it
)
242 if (++it
== line
.end()) // end of format
247 else if (isdigit(*it
)) // color
249 *menu
<< Color(*it
-'0');
251 else if (*it
== 'R') // right align
253 basic_buffer
<my_char_t
> buf
;
255 String2Buffer(TO_WSTRING(line
.substr(it
-line
.begin()+1)), buf
);
257 buf
<< Config
.now_playing_suffix
;
258 *menu
<< XY(menu
->GetWidth()-buf
.Str().length(), menu
->Y()) << buf
;
261 else // not a color nor right align, just a random character
264 else if (*it
== MPD::Song::FormatEscapeCharacter
)
266 // treat '$' as a normal character if song format escape char is prepended to it
267 if (++it
== line
.end() || *it
!= '$')
275 *menu
<< Config
.now_playing_suffix
;
278 void Display::Tags(const MPD::Song
&s
, void *data
, Menu
<MPD::Song
> *menu
)
280 switch (static_cast<Menu
<std::string
> *>(data
)->Choice())
283 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetTitle
));
286 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetArtist
));
289 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetAlbum
));
292 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetDate
));
295 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetTrack
));
298 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetGenre
));
301 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetComposer
));
304 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetPerformer
));
307 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetDisc
));
310 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetComment
));
313 if (s
.GetNewName().empty())
314 *menu
<< s
.GetName();
316 *menu
<< s
.GetName() << Config
.color2
<< " -> " << clEnd
<< s
.GetNewName();
323 void Display::Items(const MPD::Item
&item
, void *, Menu
<MPD::Item
> *menu
)
327 case MPD::itDirectory
:
334 *menu
<< "[" << ExtractTopDirectory(item
.name
) << "]";
338 if (!Config
.columns_in_browser
)
339 Display::Songs(*item
.song
, &Config
.song_list_format
, reinterpret_cast<Menu
<MPD::Song
> *>(menu
));
341 Display::SongsInColumns(*item
.song
, 0, reinterpret_cast<Menu
<MPD::Song
> *>(menu
));
343 case MPD::itPlaylist
:
344 *menu
<< Config
.browser_playlist_prefix
<< item
.name
;
351 void Display::SearchEngine(const std::pair
<Buffer
*, MPD::Song
*> &pair
, void *, Menu
< std::pair
<Buffer
*, MPD::Song
*> > *menu
)
355 if (!Config
.columns_in_search_engine
)
356 Display::Songs(*pair
.second
, &Config
.song_list_format
, reinterpret_cast<Menu
<MPD::Song
> *>(menu
));
358 Display::SongsInColumns(*pair
.second
, 0, reinterpret_cast<Menu
<MPD::Song
> *>(menu
));
362 *menu
<< *pair
.first
;