exportwebdialog.cpp 10 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
  This file is part of KOrganizer.

  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
  Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

  As a special exception, permission is given to link this program
  with any edition of Qt, and distribute the resulting executable,
  without including the source code for Qt in the source distribution.
*/

#include "exportwebdialog.h"
#include "htmlexportsettings.h"

29
#include <KDateComboBox>
30
#include <KFileDialog>
Laurent Montel's avatar
Laurent Montel committed
31
#include <QHBoxLayout>
32
33
#include <KMessageBox>
#include <KUrlRequester>
Laurent Montel's avatar
Laurent Montel committed
34
#include <QVBoxLayout>
Laurent Montel's avatar
Laurent Montel committed
35
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
36
#include "korganizer_debug.h"
37
38

#include <QBoxLayout>
39
#include <QCheckBox>
40
#include <QGroupBox>
41
#include <QHBoxLayout>
42
#include <QLabel>
43
44
45
46
47
48
#include <QVBoxLayout>

// FIXME: The basic structure of this dialog has been copied from KPrefsDialog,
//        because we want custom buttons, a Tabbed dialog, and a different
//        headline... Maybe we should try to achieve the same without code
//        duplication.
Laurent Montel's avatar
Laurent Montel committed
49
50
ExportWebDialog::ExportWebDialog(KOrg::HTMLExportSettings *settings, QWidget *parent)
    : KPageDialog(parent), KPIM::KPrefsWidManager(settings), mSettings(settings)
51
{
Laurent Montel's avatar
Laurent Montel committed
52
53
54
    setAttribute(Qt::WA_DeleteOnClose);
    setFaceType(Tabbed);
    setWindowTitle(i18n("Export Calendar as Web Page"));
Laurent Montel's avatar
Laurent Montel committed
55
    setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults);
Laurent Montel's avatar
Laurent Montel committed
56
57
58
59
60
61
62
63
    setModal(false);
    mExportButton = new QPushButton(i18n("Export"));
    mExportButton->setDefault(true);
    addActionButton(mExportButton);

    setupGeneralPage();
    setupEventPage();
    setupTodoPage();
64
65
66
67
68
// Disabled bacause the functionality is not yet implemented.
//  setupJournalPage();
//  setupFreeBusyPage();
//  setupAdvancedPage();

Laurent Montel's avatar
Laurent Montel committed
69
70
71
72
73
    connect(mExportButton, &QPushButton::clicked, this, &ExportWebDialog::slotOk);
    connect(button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &ExportWebDialog::reject);
    connect(button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &ExportWebDialog::slotDefault);
    readConfig();
    updateState();
74
75
76
77
78
79
80
81
}

ExportWebDialog::~ExportWebDialog()
{
}

void ExportWebDialog::setDefaults()
{
Laurent Montel's avatar
Laurent Montel committed
82
    setWidDefaults();
83
84
85
86
}

void ExportWebDialog::readConfig()
{
Laurent Montel's avatar
Laurent Montel committed
87
88
    readWidConfig();
    usrReadConfig();
89
90
91
92
}

void ExportWebDialog::writeConfig()
{
Laurent Montel's avatar
Laurent Montel committed
93
94
95
    writeWidConfig();
    usrWriteConfig();
    readConfig();
96
97
98
99
}

void ExportWebDialog::slotApply()
{
Laurent Montel's avatar
Laurent Montel committed
100
101
    writeConfig();
    emit configChanged();
102
103
104
105
}

void ExportWebDialog::slotOk()
{
Laurent Montel's avatar
Laurent Montel committed
106
107
108
    slotApply();
    emit exportHTML(mSettings);
    accept();
109
110
111
112
}

void ExportWebDialog::slotDefault()
{
Laurent Montel's avatar
Laurent Montel committed
113
    qCDebug(KORGANIZER_LOG);
Laurent Montel's avatar
Laurent Montel committed
114
115
116
117
118
119
120
121
122

    if (KMessageBox::warningContinueCancel(
                this,
                i18n("You are about to set all preferences to default values. "
                     "All custom modifications will be lost."),
                i18n("Setting Default Preferences"),
                KGuiItem(i18n("Reset to Defaults"))) == KMessageBox::Continue) {
        setDefaults();
    }
123
124
125
126
}

void ExportWebDialog::setupGeneralPage()
{
Laurent Montel's avatar
Laurent Montel committed
127
128
129
130
    mGeneralPage = new QFrame(this);
    addPage(mGeneralPage, i18nc("general settings for html export", "General"));
    QVBoxLayout *topLayout = new QVBoxLayout(mGeneralPage);
    topLayout->setSpacing(10);
131

Laurent Montel's avatar
Laurent Montel committed
132
133
    mDateRangeGroup = new QGroupBox(i18n("Date Range"), mGeneralPage);
    topLayout->addWidget(mDateRangeGroup);
134

Laurent Montel's avatar
Laurent Montel committed
135
    QHBoxLayout *rangeLayout = new QHBoxLayout(mDateRangeGroup);
136

Laurent Montel's avatar
Laurent Montel committed
137
138
139
140
141
142
    KPIM::KPrefsWidDate *dateStart = addWidDate(mSettings->dateStartItem());
    rangeLayout->addWidget(dateStart->label());
    rangeLayout->addWidget(dateStart->dateEdit());
    KPIM::KPrefsWidDate *dateEnd = addWidDate(mSettings->dateEndItem());
    rangeLayout->addWidget(dateEnd->label());
    rangeLayout->addWidget(dateEnd->dateEdit());
143

Laurent Montel's avatar
Laurent Montel committed
144
145
    QGroupBox *typeGroup = new QGroupBox(i18n("View Type"), mGeneralPage);
    topLayout->addWidget(typeGroup);
146

Laurent Montel's avatar
Laurent Montel committed
147
    QBoxLayout *typeLayout = new QVBoxLayout(typeGroup);
148

Laurent Montel's avatar
Laurent Montel committed
149
150
151
    mMonthViewCheckBox = addWidBool(mSettings->monthViewItem())->checkBox();
    connect(mMonthViewCheckBox, &QCheckBox::stateChanged, this, &ExportWebDialog::updateState);
    typeLayout->addWidget(mMonthViewCheckBox);
152

Laurent Montel's avatar
Laurent Montel committed
153
154
155
    mEventListCheckBox = addWidBool(mSettings->eventViewItem())->checkBox();
    connect(mEventListCheckBox, &QCheckBox::stateChanged, this, &ExportWebDialog::updateState);
    typeLayout->addWidget(mEventListCheckBox);
156

Laurent Montel's avatar
Laurent Montel committed
157
158
159
160
161
    typeLayout->addWidget(addWidBool(mSettings->todoViewItem())->checkBox());
    typeLayout->addWidget(
        addWidBool(mSettings->excludePrivateItem())->checkBox());
    typeLayout->addWidget(
        addWidBool(mSettings->excludeConfidentialItem())->checkBox());
162

Laurent Montel's avatar
Laurent Montel committed
163
164
    QGroupBox *destGroup = new QGroupBox(i18n("Destination"), mGeneralPage);
    topLayout->addWidget(destGroup);
165

Laurent Montel's avatar
Laurent Montel committed
166
    QBoxLayout *destLayout = new QHBoxLayout(destGroup);
167

Laurent Montel's avatar
Laurent Montel committed
168
169
170
171
172
173
    KPIM::KPrefsWidPath *pathWid = addWidPath(mSettings->outputFileItem(),
                                   destGroup, QLatin1String("text/html"), KFile::File);
    connect(pathWid->urlRequester(), SIGNAL(textChanged(QString)),
            SLOT(slotTextChanged(QString)));
    destLayout->addWidget(pathWid->label());
    destLayout->addWidget(pathWid->urlRequester());
174

Laurent Montel's avatar
Laurent Montel committed
175
    topLayout->addStretch(1);
176
177
}

Laurent Montel's avatar
Laurent Montel committed
178
void ExportWebDialog::slotTextChanged(const QString &_text)
179
{
Laurent Montel's avatar
Laurent Montel committed
180
    mExportButton->setEnabled(!_text.trimmed().isEmpty());
181
182
183
184
}

void ExportWebDialog::setupTodoPage()
{
Laurent Montel's avatar
Laurent Montel committed
185
186
187
188
189
190
191
192
193
    mTodoPage = new QFrame(this);
    addPage(mTodoPage, i18n("To-dos"));
    QVBoxLayout *topLayout = new QVBoxLayout(mTodoPage);
    topLayout->setSpacing(10);

    QWidget *hbox = new QWidget(mTodoPage);
    QHBoxLayout *hboxHBoxLayout = new QHBoxLayout(hbox);
    hboxHBoxLayout->setMargin(0);
    topLayout->addWidget(hbox);
Laurent Montel's avatar
Laurent Montel committed
194
195
196
    KPIM::KPrefsWidString *s = addWidString(mSettings->todoListTitleItem(), hbox);
    hboxHBoxLayout->addWidget(s->label());
    hboxHBoxLayout->addWidget(s->lineEdit());
Laurent Montel's avatar
Laurent Montel committed
197
198
199
200
201

    QWidget *vbox = new QWidget(mTodoPage);
    QVBoxLayout *vboxVBoxLayout = new QVBoxLayout(vbox);
    vboxVBoxLayout->setMargin(0);
    topLayout->addWidget(vbox);
Laurent Montel's avatar
Laurent Montel committed
202
203
204
205
206
207
208
209
    KPIM::KPrefsWidBool *boolWid = addWidBool(mSettings->taskDueDateItem(), vbox);
    vboxVBoxLayout->addWidget(boolWid->checkBox());
    boolWid = addWidBool(mSettings->taskLocationItem(), vbox);
    vboxVBoxLayout->addWidget(boolWid->checkBox());
    boolWid = addWidBool(mSettings->taskCategoriesItem(), vbox);
    vboxVBoxLayout->addWidget(boolWid->checkBox());
    boolWid = addWidBool(mSettings->taskAttendeesItem(), vbox);
    vboxVBoxLayout->addWidget(boolWid->checkBox());
210
211
212
//  addWidBool( mSettings->taskExcludePrivateItem(), vbox );
//  addWidBool( mSettings->taskExcludeConfidentialItem(), vbox );

Laurent Montel's avatar
Laurent Montel committed
213
    topLayout->addStretch(1);
214
215
216
217
}

void ExportWebDialog::setupEventPage()
{
Laurent Montel's avatar
Laurent Montel committed
218
219
220
221
222
223
224
225
226
    mEventPage = new QFrame(this);
    addPage(mEventPage, i18n("Events"));
    QVBoxLayout *topLayout = new QVBoxLayout(mEventPage);
    topLayout->setSpacing(10);

    QWidget *hbox = new QWidget(mEventPage);
    QHBoxLayout *hboxHBoxLayout = new QHBoxLayout(hbox);
    hboxHBoxLayout->setMargin(0);
    topLayout->addWidget(hbox);
Laurent Montel's avatar
Laurent Montel committed
227
228
229
    KPIM::KPrefsWidString *s = addWidString(mSettings->eventTitleItem(), hbox);
    hboxHBoxLayout->addWidget(s->label());
    hboxHBoxLayout->addWidget(s->lineEdit());
Laurent Montel's avatar
Laurent Montel committed
230
231
232
233
234

    QWidget *vbox = new QWidget(mEventPage);
    QVBoxLayout *vboxVBoxLayout = new QVBoxLayout(vbox);
    vboxVBoxLayout->setMargin(0);
    topLayout->addWidget(vbox);
Laurent Montel's avatar
Laurent Montel committed
235
236
237
238
239
240
    KPIM::KPrefsWidBool *boolWid = addWidBool(mSettings->eventLocationItem(), vbox);
    vboxVBoxLayout->addWidget(boolWid->checkBox());
    boolWid = addWidBool(mSettings->eventCategoriesItem(), vbox);
    vboxVBoxLayout->addWidget(boolWid->checkBox());
    boolWid = addWidBool(mSettings->eventAttendeesItem(), vbox);
    vboxVBoxLayout->addWidget(boolWid->checkBox());
241
242
243
//  addWidBool( mSettings->eventExcludePrivateItem(), vbox );
//  addWidBool( mSettings->eventExcludeConfidentialItem(), vbox );

Laurent Montel's avatar
Laurent Montel committed
244
    topLayout->addStretch(1);
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
}
/*
void ExportWebDialog::setupJournalPage()
{
  mJournalPage = addPage(i18n("Journal"));
  QVBoxLayout *topLayout = new QVBoxLayout( mJournalPage );
  topLayout->setSpacing( 10 );

  QHBox *hbox = new QHBox( mJournalPage );
  topLayout->addWidget( hbox );
  addWidString( mSettings->journalTitleItem(), hbox );

  QVBox *vbox = new QVBox( mJournalPage );
  topLayout->addWidget( vbox );
//  addWidBool( mSettings->eventExcludeConfidentialItem(), vbox );

  topLayout->addStretch(1);
}

void ExportWebDialog::setupFreeBusyPage()
{
  mFreeBusyPage = addPage(i18n("Free/Busy"));
  QVBoxLayout *topLayout = new QVBoxLayout( mFreeBusyPage );
  topLayout->setSpacing( 10 );

  QHBox *hbox = new QHBox( mFreeBusyPage );
  topLayout->addWidget( hbox );
  addWidString( mSettings->journalTitleItem(), hbox );

  QVBox *vbox = new QVBox( mFreeBusyPage );
  topLayout->addWidget( vbox );
//  addWidBool( mSettings->eventExcludeConfidentialItem(), vbox );

  topLayout->addStretch(1);
}

void ExportWebDialog::setupAdvancedPage()
{
  mAdvancedPage = addPage(i18n("Advanced"));
  QVBoxLayout *topLayout = new QVBoxLayout( mAdvancedPage );
  topLayout->setSpacing( 10 );

  QVBox *vbox = new QVBox( mAdvancedPage );
  topLayout->addWidget( vbox );
//  addWidBool( mSettings->eventExcludeConfidentialItem(), vbox );

  topLayout->addStretch(1);
}
*/

void ExportWebDialog::updateState()
{
Laurent Montel's avatar
Laurent Montel committed
297
298
299
300
    const bool exportEvents = mMonthViewCheckBox->isChecked() ||
                              mEventListCheckBox->isChecked();
    mDateRangeGroup->setEnabled(exportEvents);
    mEventPage->setEnabled(exportEvents);
301
302
}