strbuffer: change basic_buffer to BasicBuffer
[ncmpcpp.git] / src / outputs.cpp
blob98a7bd0efa380cf8a2b125d8ab90087cb31f7e62
1 /***************************************************************************
2 * Copyright (C) 2008-2012 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 "outputs.h"
23 #ifdef ENABLE_OUTPUTS
25 #include "display.h"
26 #include "global.h"
27 #include "settings.h"
28 #include "status.h"
29 #include "statusbar.h"
30 #include "title.h"
32 using Global::MainHeight;
33 using Global::MainStartY;
34 using Global::myScreen;
36 Outputs *myOutputs = new Outputs;
38 void Outputs::Init()
40 w = new NC::Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone);
41 w->cyclicScrolling(Config.use_cyclic_scrolling);
42 w->centeredCursor(Config.centered_cursor);
43 w->setHighlightColor(Config.main_highlight_color);
44 w->setItemDisplayer(Display::Outputs);
46 isInitialized = 1;
47 FetchList();
50 void Outputs::SwitchTo()
52 using Global::myLockedScreen;
54 if (myScreen == this)
55 return;
57 if (!isInitialized)
58 Init();
60 if (myLockedScreen)
61 UpdateInactiveScreen(this);
63 if (hasToBeResized || myLockedScreen)
64 Resize();
66 if (myScreen != this && myScreen->isTabbable())
67 Global::myPrevScreen = myScreen;
68 myScreen = this;
69 w->Window::clear();
70 drawHeader();
73 void Outputs::Resize()
75 size_t x_offset, width;
76 GetWindowResizeParams(x_offset, width);
77 w->resize(width, MainHeight);
78 w->moveTo(x_offset, MainStartY);
79 hasToBeResized = 0;
82 std::wstring Outputs::Title()
84 return L"Outputs";
87 void Outputs::EnterPressed()
89 if (w->current().value().isEnabled())
91 if (Mpd.DisableOutput(w->choice()))
92 Statusbar::msg("Output \"%s\" disabled", w->current().value().name().c_str());
94 else
96 if (Mpd.EnableOutput(w->choice()))
97 Statusbar::msg("Output \"%s\" enabled", w->current().value().name().c_str());
99 if (!Mpd.SupportsIdle())
100 FetchList();
103 void Outputs::MouseButtonPressed(MEVENT me)
105 if (w->empty() || !w->hasCoords(me.x, me.y) || size_t(me.y) >= w->size())
106 return;
107 if (me.bstate & BUTTON1_PRESSED || me.bstate & BUTTON3_PRESSED)
109 w->Goto(me.y);
110 if (me.bstate & BUTTON3_PRESSED)
111 EnterPressed();
113 else
114 Screen< NC::Menu<MPD::Output> >::MouseButtonPressed(me);
117 void Outputs::FetchList()
119 if (!isInitialized)
120 return;
121 w->clear();
122 auto outputs = Mpd.GetOutputs();
123 for (auto o = outputs.begin(); o != outputs.end(); ++o)
124 w->addItem(*o, o->isEnabled());
125 if (myScreen == this)
126 w->refresh();
129 #endif // ENABLE_OUTPUTS