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 ***************************************************************************/
24 #include "server_info.h"
26 using Global::MainHeight
;
27 using Global::MainStartY
;
28 using Global::myScreen
;
29 using Global::myOldScreen
;
31 ServerInfo
*myServerInfo
= new ServerInfo
;
33 void ServerInfo::Init()
36 w
= new Scrollpad((COLS
-itsWidth
)/2, (MainHeight
-itsHeight
)/2+MainStartY
, itsWidth
, itsHeight
, "MPD server info", Config
.main_color
, Config
.window_border
);
38 Mpd
.GetURLHandlers(itsURLHandlers
);
39 Mpd
.GetTagTypes(itsTagTypes
);
44 void ServerInfo::SwitchTo()
48 myOldScreen
->SwitchTo();
53 ShowMessage("Screen is too small to display this window!");
60 // Resize() can fall back to old screen, so we need it updated
61 myOldScreen
= myScreen
;
70 void ServerInfo::Resize()
73 if (itsHeight
< 5) // screen too low to display this window
74 return myOldScreen
->SwitchTo();
75 w
->Resize(itsWidth
, itsHeight
);
76 w
->MoveTo((COLS
-itsWidth
)/2, (MainHeight
-itsHeight
)/2+MainStartY
);
77 if (myOldScreen
&& myOldScreen
->hasToBeResized
) // resize background window
79 myOldScreen
->Resize();
80 myOldScreen
->Refresh();
85 std::basic_string
<my_char_t
> ServerInfo::Title()
87 return myOldScreen
->Title();
90 void ServerInfo::Update()
92 static time_t now
= 0, past
;
101 *w
<< fmtBold
<< U("Version: ") << fmtBoldEnd
<< U("0.") << std::fixed
<< std::setprecision(1) << Mpd
.Version() << '\n';
102 *w
<< fmtBold
<< U("Uptime: ") << fmtBoldEnd
;
103 ShowTime(*w
, Mpd
.Uptime(), 1);
105 *w
<< fmtBold
<< U("Time playing: ") << fmtBoldEnd
<< MPD::Song::ShowTime(Mpd
.PlayTime()) << '\n';
107 *w
<< fmtBold
<< U("Total playtime: ") << fmtBoldEnd
;
108 ShowTime(*w
, Mpd
.DBPlayTime(), 1);
110 *w
<< fmtBold
<< U("Artist names: ") << fmtBoldEnd
<< Mpd
.NumberOfArtists() << '\n';
111 *w
<< fmtBold
<< U("Album names: ") << fmtBoldEnd
<< Mpd
.NumberOfAlbums() << '\n';
112 *w
<< fmtBold
<< U("Songs in database: ") << fmtBoldEnd
<< Mpd
.NumberOfSongs() << '\n';
114 *w
<< fmtBold
<< U("Last DB update: ") << fmtBoldEnd
<< Timestamp(Mpd
.DBUpdateTime()) << '\n';
116 *w
<< fmtBold
<< U("URL Handlers:") << fmtBoldEnd
;
117 for (MPD::TagList::const_iterator it
= itsURLHandlers
.begin(); it
!= itsURLHandlers
.end(); ++it
)
118 *w
<< (it
!= itsURLHandlers
.begin() ? U(", ") : U(" ")) << *it
;
120 *w
<< fmtBold
<< U("Tag Types:") << fmtBoldEnd
;
121 for (MPD::TagList::const_iterator it
= itsTagTypes
.begin(); it
!= itsTagTypes
.end(); ++it
)
122 *w
<< (it
!= itsTagTypes
.begin() ? U(", ") : U(" ")) << *it
;
128 void ServerInfo::SetDimensions()
131 itsHeight
= std::min(size_t(LINES
*0.7), MainHeight
);