change version to 0.7.3
[ncmpcpp.git] / src / outputs.cpp
blob48adcef685dbcaee7f6e1be461603ce02a87aff3
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 "outputs.h"
23 #ifdef ENABLE_OUTPUTS
25 #include "charset.h"
26 #include "display.h"
27 #include "global.h"
28 #include "menu_impl.h"
29 #include "settings.h"
30 #include "status.h"
31 #include "statusbar.h"
32 #include "title.h"
33 #include "screen_switcher.h"
35 using Global::MainHeight;
36 using Global::MainStartY;
37 using Global::myScreen;
39 Outputs *myOutputs;
41 Outputs::Outputs()
42 : Screen(NC::Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
44 w.cyclicScrolling(Config.use_cyclic_scrolling);
45 w.centeredCursor(Config.centered_cursor);
46 w.setHighlightColor(Config.main_highlight_color);
47 w.setItemDisplayer([](NC::Menu<MPD::Output> &menu) {
48 menu << Charset::utf8ToLocale(menu.drawn()->value().name());
49 });
52 void Outputs::switchTo()
54 SwitchTo::execute(this);
55 drawHeader();
58 void Outputs::resize()
60 size_t x_offset, width;
61 getWindowResizeParams(x_offset, width);
62 w.resize(width, MainHeight);
63 w.moveTo(x_offset, MainStartY);
64 hasToBeResized = 0;
67 std::wstring Outputs::title()
69 return L"Outputs";
72 void Outputs::mouseButtonPressed(MEVENT me)
74 if (w.empty() || !w.hasCoords(me.x, me.y) || size_t(me.y) >= w.size())
75 return;
76 if (me.bstate & BUTTON1_PRESSED || me.bstate & BUTTON3_PRESSED)
78 w.Goto(me.y);
79 if (me.bstate & BUTTON3_PRESSED)
80 toggleOutput();
82 else
83 Screen<WindowType>::mouseButtonPressed(me);
86 void Outputs::fetchList()
88 w.clear();
89 for (MPD::OutputIterator out = Mpd.GetOutputs(), end; out != end; ++out)
91 auto properties = NC::List::Properties::Selectable;
92 if (out->enabled())
93 properties |= NC::List::Properties::Bold;
94 w.addItem(std::move(*out), properties);
96 if (myScreen == this)
97 w.refresh();
100 void Outputs::toggleOutput()
102 if (w.current()->value().enabled())
104 Mpd.DisableOutput(w.choice());
105 Statusbar::printf("Output \"%s\" disabled", w.current()->value().name());
107 else
109 Mpd.EnableOutput(w.choice());
110 Statusbar::printf("Output \"%s\" enabled", w.current()->value().name());
114 #endif // ENABLE_OUTPUTS