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))
98 if (it
->right_alignment
)
99 for (long i
= 0; i
< long(width
-tag
.length()-(it
!= Config
.columns
.begin())); ++i
, result
+= ' ') { }
104 if (result
.length() > where
)
105 result
= result
.substr(0, where
);
107 for (size_t i
= result
.length(); i
<= where
&& i
< size_t(COLS
); ++i
, result
+= ' ') { }
112 void Display::SongsInColumns(const MPD::Song
&s
, void *, Menu
<MPD::Song
> *menu
)
115 const_cast<MPD::Song
*>(&s
)->Localize();
117 bool is_now_playing
= menu
== myPlaylist
->Items
&& (menu
->isFiltered() ? s
.GetPosition() : menu
->CurrentlyDrawedPosition()) == size_t(myPlaylist
->NowPlaying
);
119 *menu
<< Config
.now_playing_prefix
;
121 if (Config
.columns
.empty())
124 std::vector
<Column
>::const_iterator next2last
, it
;
128 bool last_fixed
= Config
.columns
.back().fixed
;
129 if (Config
.columns
.size() > 1)
130 next2last
= Config
.columns
.end()-2;
132 for (it
= Config
.columns
.begin(); it
!= Config
.columns
.end(); ++it
)
136 menu
->GotoXY(where
, menu
->Y());
138 if ((it
-1)->color
!= clDefault
)
142 width
= (last_fixed
&& it
== next2last
143 ? COLS
-where
-(++next2last
)->width
144 : (it
== Config
.columns
.end()-1
145 ? menu
->GetWidth()-where
146 : (it
->width
*(it
->fixed
? 1 : COLS
/100.0))
150 MPD::Song::GetFunction get
= 0;
155 get
= &MPD::Song::GetLength
;
158 get
= &MPD::Song::GetDirectory
;
161 get
= &MPD::Song::GetName
;
164 get
= &MPD::Song::GetArtist
;
167 get
= &MPD::Song::GetAlbumArtist
;
170 get
= &MPD::Song::GetAlbum
;
173 get
= &MPD::Song::GetDate
;
176 get
= &MPD::Song::GetTrackNumber
;
179 get
= &MPD::Song::GetTrack
;
182 get
= &MPD::Song::GetGenre
;
185 get
= &MPD::Song::GetComposer
;
188 get
= &MPD::Song::GetPerformer
;
191 get
= &MPD::Song::GetDisc
;
194 get
= &MPD::Song::GetComment
;
197 if (!s
.GetTitle().empty())
198 get
= &MPD::Song::GetTitle
;
200 get
= &MPD::Song::GetName
;
205 if (it
->color
!= clDefault
)
207 whline(menu
->Raw(), 32, menu
->GetWidth()-where
);
208 std::string tag
= get
? s
.GetTags(get
) : "";
209 if (it
->right_alignment
)
211 if (!tag
.empty() || it
->display_empty_tag
)
215 std::basic_string
<my_char_t
> wtag
= TO_WSTRING(tag
.empty() ? Config
.empty_tag
: tag
).substr(0, width
-!!x
);
216 *menu
<< XY(x
+width
-Window::Length(wtag
)-!!x
, y
) << wtag
;
223 else if (it
->display_empty_tag
)
224 *menu
<< Config
.empty_tag
;
228 if ((--it
)->color
!= clDefault
)
231 *menu
<< Config
.now_playing_suffix
;
234 void Display::Songs(const MPD::Song
&s
, void *data
, Menu
<MPD::Song
> *menu
)
237 const_cast<MPD::Song
*>(&s
)->Localize();
239 bool is_now_playing
= menu
== myPlaylist
->Items
&& (menu
->isFiltered() ? s
.GetPosition() : menu
->CurrentlyDrawedPosition()) == size_t(myPlaylist
->NowPlaying
);
241 *menu
<< Config
.now_playing_prefix
;
243 std::string line
= s
.toString(*static_cast<std::string
*>(data
), "$");
244 for (std::string::const_iterator it
= line
.begin(); it
!= line
.end(); ++it
)
248 if (++it
== line
.end()) // end of format
253 else if (isdigit(*it
)) // color
255 *menu
<< Color(*it
-'0');
257 else if (*it
== 'R') // right align
259 basic_buffer
<my_char_t
> buf
;
261 String2Buffer(TO_WSTRING(line
.substr(it
-line
.begin()+1)), buf
);
263 buf
<< Config
.now_playing_suffix
;
264 *menu
<< XY(menu
->GetWidth()-buf
.Str().length()-(menu
->isSelected(menu
->CurrentlyDrawedPosition()) ? Config
.selected_item_suffix_length
: 0), menu
->Y()) << buf
;
267 else // not a color nor right align, just a random character
270 else if (*it
== MPD::Song::FormatEscapeCharacter
)
272 // treat '$' as a normal character if song format escape char is prepended to it
273 if (++it
== line
.end() || *it
!= '$')
281 *menu
<< Config
.now_playing_suffix
;
284 void Display::Tags(const MPD::Song
&s
, void *data
, Menu
<MPD::Song
> *menu
)
286 switch (static_cast<Menu
<std::string
> *>(data
)->Choice())
289 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetTitle
));
292 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetArtist
));
295 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetAlbumArtist
));
298 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetAlbum
));
301 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetDate
));
304 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetTrack
));
307 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetGenre
));
310 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetComposer
));
313 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetPerformer
));
316 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetDisc
));
319 ShowTag(*menu
, s
.GetTags(&MPD::Song::GetComment
));
322 if (s
.GetNewName().empty())
323 *menu
<< s
.GetName();
325 *menu
<< s
.GetName() << Config
.color2
<< " -> " << clEnd
<< s
.GetNewName();
332 void Display::Items(const MPD::Item
&item
, void *, Menu
<MPD::Item
> *menu
)
336 case MPD::itDirectory
:
343 *menu
<< "[" << ExtractTopDirectory(item
.name
) << "]";
347 if (!Config
.columns_in_browser
)
348 Display::Songs(*item
.song
, &Config
.song_list_format
, reinterpret_cast<Menu
<MPD::Song
> *>(menu
));
350 Display::SongsInColumns(*item
.song
, 0, reinterpret_cast<Menu
<MPD::Song
> *>(menu
));
352 case MPD::itPlaylist
:
353 *menu
<< Config
.browser_playlist_prefix
<< item
.name
;
360 void Display::SearchEngine(const std::pair
<Buffer
*, MPD::Song
*> &pair
, void *, Menu
< std::pair
<Buffer
*, MPD::Song
*> > *menu
)
364 if (!Config
.columns_in_search_engine
)
365 Display::Songs(*pair
.second
, &Config
.song_list_format
, reinterpret_cast<Menu
<MPD::Song
> *>(menu
));
367 Display::SongsInColumns(*pair
.second
, 0, reinterpret_cast<Menu
<MPD::Song
> *>(menu
));
371 *menu
<< *pair
.first
;