1 /* ============================================================
2  * Copyright 2005-2007,2010 by Tom Albers <toma@kde.org>
3  *
4  * This program is free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General
6  * Public License as published by the Free Software Foundation;
7  * either version 2, or (at your option)
8  * 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 Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  * ============================================================ */
19 
20 #include "setup.h"
21 
22 // Qt includes.
23 #include <QIcon>
24 
25 // KDE includes.
26 #include <KConfigGroup>
27 #include <KWindowConfig>
28 #include <KSharedConfig>
29 #include <klocalizedstring.h>
30 
31 // Local includes.
32 #include "setupgeneral.h"
33 #include "setuptiming.h"
34 #include "setupmaximized.h"
35 #include "setupnotifications.h"
36 
37 
38 class SetupPriv
39 {
40 public:
41     SetupGeneral  *generalPage;
42     SetupTiming  *timingPage;
43     SetupMaximized  *maximizedPage;
44     SetupNotifications *notificationsPage;
45 };
46 
Setup(QWidget * parent)47 Setup::Setup( QWidget* parent )
48         : KPageDialog( parent )
49 {
50     setFaceType( List );
51     d = new SetupPriv;
52 
53     d->generalPage = new SetupGeneral( this );
54     KPageWidgetItem* page1 = addPage( d->generalPage, i18n( "General Settings" ) );
55     page1->setIcon( QIcon::fromTheme( "configure" ) );
56 
57     d->timingPage = new SetupTiming( this );
58     KPageWidgetItem* page2 = addPage( d->timingPage, i18n( "Timings" ) );
59     page2->setIcon( QIcon::fromTheme( "timings" ) );
60 
61     d->maximizedPage = new SetupMaximized( this );
62     KPageWidgetItem* page3 = addPage( d->maximizedPage, i18n( "During Breaks" ) );
63     page3->setIcon( QIcon::fromTheme( "duringbreaks" ) ); // krazy:exclude=iconnames
64 
65     d->notificationsPage = new SetupNotifications( this );
66     KPageWidgetItem* page4 = addPage( d->notificationsPage, i18n( "Actions" ) );
67     page4->setIcon( QIcon::fromTheme( "configure" ) ); // krazy:exclude=iconnames
68 
69     connect(this, &Setup::accepted, this, &Setup::slotOkClicked);
70 
71     connect(d->generalPage, &SetupGeneral::useIdleTimerChanged, d->maximizedPage, &SetupMaximized::slotSetUseIdleTimer);
72     d->maximizedPage->slotSetUseIdleTimer(d->generalPage->useIdleTimer());
73     connect(d->generalPage, &SetupGeneral::useIdleTimerChanged, d->timingPage, &SetupTiming::slotSetUseIdleTimer);
74     d->timingPage->slotSetUseIdleTimer(d->generalPage->useIdleTimer());
75 
76     KConfigGroup config = KSharedConfig::openConfig()->group( "SetupDimensions" );
77     KWindowConfig::restoreWindowSize( windowHandle(), config );
78     show();
79 }
80 
~Setup()81 Setup::~Setup()
82 {
83     KConfigGroup config = KSharedConfig::openConfig()->group( "SetupDimensions" );
84     KWindowConfig::saveWindowSize( windowHandle(), config );
85     delete d;
86 }
87 
slotOkClicked()88 void Setup::slotOkClicked()
89 {
90     d->generalPage->applySettings();
91     d->timingPage->applySettings();
92     d->maximizedPage->applySettings();
93     d->notificationsPage->save();
94     close();
95 }
96