media library: fix mouse event handler
[ncmpcpp.git] / src / server_info.cpp
blob67f00964341c09a7398e66bcdb73a82ac85c2513
1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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 2 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, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include <boost/date_time/posix_time/posix_time.hpp>
22 #include <iomanip>
24 #include "global.h"
25 #include "helpers.h"
26 #include "server_info.h"
27 #include "statusbar.h"
28 #include "screen_switcher.h"
30 using Global::MainHeight;
31 using Global::MainStartY;
33 ServerInfo *myServerInfo;
35 ServerInfo::ServerInfo()
36 : m_timer(boost::posix_time::from_time_t(0))
38 SetDimensions();
39 w = NC::Scrollpad((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "MPD server info", Config.main_color, Config.window_border);
42 void ServerInfo::switchTo()
44 using Global::myScreen;
45 if (myScreen != this)
47 SwitchTo::execute(this);
49 itsURLHandlers.clear();
50 itsTagTypes.clear();
52 Mpd.GetURLHandlers(vectorMoveInserter(itsURLHandlers));
53 Mpd.GetTagTypes(vectorMoveInserter(itsTagTypes));
55 else
56 switchToPreviousScreen();
59 void ServerInfo::resize()
61 SetDimensions();
62 w.resize(itsWidth, itsHeight);
63 w.moveTo((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY);
64 if (previousScreen() && previousScreen()->hasToBeResized) // resize background window
66 previousScreen()->resize();
67 previousScreen()->refresh();
69 hasToBeResized = 0;
72 std::wstring ServerInfo::title()
74 return previousScreen()->title();
77 void ServerInfo::update()
79 if (Global::Timer - m_timer < boost::posix_time::seconds(1))
80 return;
81 m_timer = Global::Timer;
83 MPD::Statistics stats = Mpd.getStatistics();
84 if (stats.empty())
85 return;
87 w.clear();
89 w << NC::Format::Bold << "Version: " << NC::Format::NoBold << "0." << Mpd.Version() << ".*\n";
90 w << NC::Format::Bold << "Uptime: " << NC::Format::NoBold;
91 ShowTime(w, stats.uptime(), 1);
92 w << '\n';
93 w << NC::Format::Bold << "Time playing: " << NC::Format::NoBold << MPD::Song::ShowTime(stats.playTime()) << '\n';
94 w << '\n';
95 w << NC::Format::Bold << "Total playtime: " << NC::Format::NoBold;
96 ShowTime(w, stats.dbPlayTime(), 1);
97 w << '\n';
98 w << NC::Format::Bold << "Artist names: " << NC::Format::NoBold << stats.artists() << '\n';
99 w << NC::Format::Bold << "Album names: " << NC::Format::NoBold << stats.albums() << '\n';
100 w << NC::Format::Bold << "Songs in database: " << NC::Format::NoBold << stats.songs() << '\n';
101 w << '\n';
102 w << NC::Format::Bold << "Last DB update: " << NC::Format::NoBold << Timestamp(stats.dbUpdateTime()) << '\n';
103 w << '\n';
104 w << NC::Format::Bold << "URL Handlers:" << NC::Format::NoBold;
105 for (auto it = itsURLHandlers.begin(); it != itsURLHandlers.end(); ++it)
106 w << (it != itsURLHandlers.begin() ? ", " : " ") << *it;
107 w << "\n\n";
108 w << NC::Format::Bold << "Tag Types:" << NC::Format::NoBold;
109 for (auto it = itsTagTypes.begin(); it != itsTagTypes.end(); ++it)
110 w << (it != itsTagTypes.begin() ? ", " : " ") << *it;
112 w.flush();
113 w.refresh();
116 void ServerInfo::SetDimensions()
118 itsWidth = COLS*0.6;
119 itsHeight = std::min(size_t(LINES*0.7), MainHeight);