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 "server_info.h"
26 #include "statusbar.h"
27 #include "screen_switcher.h"
29 using Global::MainHeight
;
30 using Global::MainStartY
;
32 ServerInfo
*myServerInfo
;
34 ServerInfo::ServerInfo()
37 w
= NC::Scrollpad((COLS
-itsWidth
)/2, (MainHeight
-itsHeight
)/2+MainStartY
, itsWidth
, itsHeight
, "MPD server info", Config
.main_color
, Config
.window_border
);
40 void ServerInfo::switchTo()
42 using Global::myScreen
;
45 SwitchTo::execute(this);
47 itsURLHandlers
.clear();
50 Mpd
.GetURLHandlers(vectorMoveInserter(itsURLHandlers
));
51 Mpd
.GetTagTypes(vectorMoveInserter(itsTagTypes
));
54 switchToPreviousScreen();
57 void ServerInfo::resize()
60 w
.resize(itsWidth
, itsHeight
);
61 w
.moveTo((COLS
-itsWidth
)/2, (MainHeight
-itsHeight
)/2+MainStartY
);
62 if (previousScreen() && previousScreen()->hasToBeResized
) // resize background window
64 previousScreen()->resize();
65 previousScreen()->refresh();
70 std::wstring
ServerInfo::title()
72 return previousScreen()->title();
75 void ServerInfo::update()
77 if (Global::Timer
- m_timer
< boost::posix_time::seconds(1))
79 m_timer
= Global::Timer
;
81 MPD::Statistics stats
= Mpd
.getStatistics();
87 w
<< NC::Format::Bold
<< "Version: " << NC::Format::NoBold
<< "0." << Mpd
.Version() << ".*\n";
88 w
<< NC::Format::Bold
<< "Uptime: " << NC::Format::NoBold
;
89 ShowTime(w
, stats
.uptime(), 1);
91 w
<< NC::Format::Bold
<< "Time playing: " << NC::Format::NoBold
<< MPD::Song::ShowTime(stats
.playTime()) << '\n';
93 w
<< NC::Format::Bold
<< "Total playtime: " << NC::Format::NoBold
;
94 ShowTime(w
, stats
.dbPlayTime(), 1);
96 w
<< NC::Format::Bold
<< "Artist names: " << NC::Format::NoBold
<< stats
.artists() << '\n';
97 w
<< NC::Format::Bold
<< "Album names: " << NC::Format::NoBold
<< stats
.albums() << '\n';
98 w
<< NC::Format::Bold
<< "Songs in database: " << NC::Format::NoBold
<< stats
.songs() << '\n';
100 w
<< NC::Format::Bold
<< "Last DB update: " << NC::Format::NoBold
<< Timestamp(stats
.dbUpdateTime()) << '\n';
102 w
<< NC::Format::Bold
<< "URL Handlers:" << NC::Format::NoBold
;
103 for (auto it
= itsURLHandlers
.begin(); it
!= itsURLHandlers
.end(); ++it
)
104 w
<< (it
!= itsURLHandlers
.begin() ? ", " : " ") << *it
;
106 w
<< NC::Format::Bold
<< "Tag Types:" << NC::Format::NoBold
;
107 for (auto it
= itsTagTypes
.begin(); it
!= itsTagTypes
.end(); ++it
)
108 w
<< (it
!= itsTagTypes
.begin() ? ", " : " ") << *it
;
114 void ServerInfo::SetDimensions()
117 itsHeight
= std::min(size_t(LINES
*0.7), MainHeight
);