1 /* This file is part of the KDE project
2 Copyright (C) 2002, 2003 Laurent Montel <lmontel@mandrakesoft.com>
3 Copyright (C) 2006-2007 Jan Hambrecht <jaham@gmx.net>
4 
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9 
10 This library 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 GNU
13 Library General Public License for more details.
14 
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB.  If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20 
21 #include "KoConfigDocumentPage.h"
22 
23 #include <KoDocument.h>
24 #include <KoPart.h>
25 #include <KoComponentData.h>
26 
27 #include <klocalizedstring.h>
28 #include <kconfig.h>
29 #include <kconfiggroup.h>
30 
31 #include <QFormLayout>
32 #include <QCheckBox>
33 #include <QGroupBox>
34 #include <QSpinBox>
35 
36 class Q_DECL_HIDDEN KoConfigDocumentPage::Private
37 {
38 public:
Private(KoDocument * doc)39     Private(KoDocument* doc)
40     : doc(doc)
41     {}
42 
43     KoDocument* doc;
44     KSharedConfigPtr config;
45 
46     QSpinBox* autoSave;
47     int oldAutoSave;
48     QCheckBox *createBackupFile;
49     bool oldBackupFile;
50 };
51 
KoConfigDocumentPage(KoDocument * doc,char * name)52 KoConfigDocumentPage::KoConfigDocumentPage(KoDocument* doc, char* name)
53 : d(new Private(doc))
54 {
55     setObjectName(name);
56 
57     d->config = d->doc->documentPart()->componentData().config();
58 
59     QGroupBox* gbDocumentSettings = new QGroupBox(i18n("Document Settings"), this);
60     QFormLayout *layout = new QFormLayout(gbDocumentSettings);
61 
62     d->oldAutoSave = doc->defaultAutoSave() / 60;
63 
64     d->oldBackupFile = true;
65 
66     if(d->config->hasGroup("Interface")) {
67         KConfigGroup interfaceGroup = d->config->group("Interface");
68         d->oldAutoSave = interfaceGroup.readEntry("AutoSave", d->oldAutoSave);
69         d->oldBackupFile = interfaceGroup.readEntry("BackupFile", d->oldBackupFile);
70     }
71 
72     d->autoSave = new QSpinBox(gbDocumentSettings);
73     d->autoSave->setRange(0, 60);
74     d->autoSave->setSingleStep(1);
75     d->autoSave->setSpecialValueText(i18n("No autosave"));
76     d->autoSave->setSuffix(i18nc("unit symbol for minutes, leading space as separator", " min"));
77     d->autoSave->setValue(d->oldAutoSave);
78     layout->addRow(i18n("Autosave interval:"), d->autoSave);
79 
80     d->createBackupFile = new QCheckBox(gbDocumentSettings);
81     d->createBackupFile->setChecked(d->oldBackupFile);
82     layout->addRow(i18n("Create backup file:"), d->createBackupFile);
83 }
84 
~KoConfigDocumentPage()85 KoConfigDocumentPage::~KoConfigDocumentPage()
86 {
87     delete d;
88 }
89 
apply()90 void KoConfigDocumentPage::apply()
91 {
92     KConfigGroup interfaceGroup = d->config->group("Interface");
93 
94     int autoSave = d->autoSave->value();
95 
96     if (autoSave != d->oldAutoSave) {
97         interfaceGroup.writeEntry("AutoSave", autoSave);
98         d->doc->setAutoSave(autoSave * 60);
99         d->oldAutoSave = autoSave;
100     }
101 
102     bool state = d->createBackupFile->isChecked();
103 
104     if (state != d->oldBackupFile) {
105         interfaceGroup.writeEntry("BackupFile", state);
106         d->doc->setBackupFile(state);
107         d->oldBackupFile = state;
108     }
109 }
110 
slotDefault()111 void KoConfigDocumentPage::slotDefault()
112 {
113     d->autoSave->setValue(d->doc->defaultAutoSave() / 60);
114     d->createBackupFile->setChecked(true);
115 }
116