1 /* GUI_Shutdown.cpp */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "GUI_Shutdown.h"
22 #include "Gui/Shutdown/ui_GUI_Shutdown.h"
23 
24 #include "Utils/Macros.h"
25 #include "Gui/Utils/Icons.h"
26 
27 #include "Components/Shutdown/Shutdown.h"
28 
29 #ifdef SAYONARA_WITH_SHUTDOWN
30 
GUI_Shutdown(QWidget * parent)31 GUI_Shutdown::GUI_Shutdown(QWidget* parent):
32 	Gui::Dialog(parent)
33 {
34 	ui = new Ui::GUI_Shutdown();
35 	ui->setupUi(this);
36 
37 	connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &GUI_Shutdown::accepted);
38 	connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &GUI_Shutdown::rejected);
39 	connect(ui->rb_after_finished, &QRadioButton::clicked, this, &GUI_Shutdown::afterPlaylistFinishedClicked);
40 	connect(ui->rb_after_minutes, &QRadioButton::clicked, this, &GUI_Shutdown::afterTimespanClicked);
41 }
42 
~GUI_Shutdown()43 GUI_Shutdown::~GUI_Shutdown()
44 {
45 	delete ui; ui=nullptr;
46 }
47 
skinChanged()48 void GUI_Shutdown::skinChanged()
49 {
50 	ui->lab_icon->setPixmap(Gui::Icons::pixmap(Gui::Icons::Shutdown, ui->lab_icon->size()));
51 }
52 
53 
accepted()54 void GUI_Shutdown::accepted()
55 {
56 	if(ui->sb_minutes->isEnabled())
57 	{
58 		MilliSeconds msec = ui->sb_minutes->value() * 60 * 1000;
59 		Shutdown::instance()->shutdown(msec);
60 	}
61 
62 	else {
63 		Shutdown::instance()->shutdownAfterSessionEnd();
64 	}
65 
66 	close();
67 }
68 
rejected()69 void GUI_Shutdown::rejected()
70 {
71 	close();
72 	emit sigClosed();
73 }
74 
afterPlaylistFinishedClicked(bool b)75 void GUI_Shutdown::afterPlaylistFinishedClicked(bool b)
76 {
77 	Q_UNUSED(b)
78 	ui->rb_after_minutes->setChecked(false);
79 	ui->sb_minutes->setEnabled(false);
80 }
81 
afterTimespanClicked(bool b)82 void GUI_Shutdown::afterTimespanClicked(bool b)
83 {
84 	Q_UNUSED(b)
85 	ui->rb_after_minutes->setChecked(false);
86 	ui->sb_minutes->setEnabled(true);
87 }
88 
89 #endif // SAYONARA_WITH_SHUTDOWN
90