1 /***************************************************************************
2 * Copyright (C) 2008-2014 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 #include "statusbar.h"
27 bool addSongToPlaylist(const MPD::Song
&s
, bool play
, int position
)
30 if (Config
.space_add_mode
== SpaceAddMode::AddRemove
&& myPlaylist
->checkForSong(s
))
32 auto &w
= myPlaylist
->main();
35 auto song
= std::find(w
.beginV(), w
.endV(), s
);
36 assert(song
!= w
.endV());
37 Mpd
.PlayID(song
->getID());
42 Mpd
.StartCommandsList();
43 for (auto it
= w
.rbeginV(); it
!= w
.rendV(); ++it
)
45 Mpd
.Delete(it
->getPosition());
46 Mpd
.CommitCommandsList();
47 // we return false in this case
52 int id
= Mpd
.AddSong(s
, position
);
55 Statusbar::printf("Added to playlist: %s",
56 s
.toString(Config
.song_status_format_no_colors
, Config
.tags_separator
)
66 std::string
Timestamp(time_t t
)
70 result
[strftime(result
, 31, "%x %X", localtime(&t
))] = 0;
73 result
[strftime(result
, 31, "%x %X", localtime_r(&t
, &info
))] = 0;
78 void markSongsInPlaylist(ProxySongList pl
)
80 size_t list_size
= pl
.size();
81 for (size_t i
= 0; i
< list_size
; ++i
)
82 if (auto s
= pl
.getSong(i
))
83 pl
.setBold(i
, myPlaylist
->checkForSong(*s
));
86 std::wstring
Scroller(const std::wstring
&str
, size_t &pos
, size_t width
)
89 if (!Config
.header_text_scrolling
)
92 size_t len
= wideLength(s
);
98 auto b
= s
.begin(), e
= s
.end();
99 for (auto it
= b
+pos
; it
< e
&& len
< width
; ++it
)
101 if ((len
+= wcwidth(*it
)) > width
)
105 if (++pos
>= s
.length())
107 for (; len
< width
; ++b
)
109 if ((len
+= wcwidth(*b
)) > width
)
119 void writeCyclicBuffer(const NC::WBuffer
&buf
, NC::Window
&w
, size_t &start_pos
,
120 size_t width
, const std::wstring
&separator
)
122 const auto &s
= buf
.str();
123 size_t len
= wideLength(s
);
127 const auto &ps
= buf
.properties();
130 // load attributes from before starting pos
131 for (; p
!= ps
.end() && p
->position() < start_pos
; ++p
)
134 auto write_buffer
= [&](size_t start
) {
135 for (size_t i
= start
; i
< s
.length() && len
< width
; ++i
)
137 for (; p
!= ps
.end() && p
->position() == i
; ++p
)
139 len
+= wcwidth(s
[i
]);
144 for (; p
!= ps
.end(); ++p
)
149 write_buffer(start_pos
);
151 if (start_pos
> s
.length())
152 i
= start_pos
- s
.length();
153 for (; i
< separator
.length() && len
< width
; ++i
)
155 len
+= wcwidth(separator
[i
]);
163 if (start_pos
>= s
.length() + separator
.length())