korganizer

exportwebdialog.cpp
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4  Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include <tqlayout.h>
26 #include <tqhgroupbox.h>
27 #include <tqvgroupbox.h>
28 #include <tqvbuttongroup.h>
29 #include <tqradiobutton.h>
30 #include <tqcheckbox.h>
31 #include <tqlineedit.h>
32 #include <tqhbox.h>
33 #include <tqvbox.h>
34 #include <tqpushbutton.h>
35 #include <tqfiledialog.h>
36 #include <tqtextstream.h>
37 #include <tqlabel.h>
38 
39 #include <tdelocale.h>
40 #include <kdebug.h>
41 #include <tdefiledialog.h>
42 #include <klineedit.h>
43 #include <kurl.h>
44 #include <tdeio/job.h>
45 #include <kstandarddirs.h>
46 #include <tdeconfig.h>
47 #include "koglobals.h"
48 #include <kurlrequester.h>
49 #include <tdeio/netaccess.h>
50 #include <knotifyclient.h>
51 #include <tdetempfile.h>
52 #include <tdemessagebox.h>
53 
54 #include <libkcal/calendar.h>
55 #include <libkcal/htmlexportsettings.h>
56 
57 #include <libtdepim/kdateedit.h>
58 #include <libtdepim/kdateedit.h>
59 
60 #include "koprefs.h"
61 #include "kocore.h"
62 
63 #include "exportwebdialog.h"
64 #include "exportwebdialog.moc"
65 
66 
67 // FIXME: The basic structure of this dialog has been copied from KPrefsDialog,
68 // because we want custom buttons, a Tabbed dialog, and a different
69 // headline... Maybe we should try to achieve the same without code
70 // duplication.
71 ExportWebDialog::ExportWebDialog( HTMLExportSettings *settings, TQWidget *parent,
72  const char *name)
73  : KDialogBase( Tabbed,i18n("Export Calendar as Web Page"),Help|Default|User1|Cancel, User1, parent, name, false, false, i18n("Export") ),
74  KPrefsWidManager( settings ), mSettings( settings )
75 {
76  setupGeneralPage();
77  setupEventPage();
78  setupTodoPage();
79 // Disabled bacause the functionality is not yet implemented.
80 // setupJournalPage();
81 // setupFreeBusyPage();
82 // setupAdvancedPage();
83 
84  connect( this, TQ_SIGNAL( user1Clicked() ), TQ_SLOT( slotOk() ) );
85  connect( this, TQ_SIGNAL( cancelClicked() ), TQ_SLOT( reject() ) );
86 
87  readConfig();
88  updateState();
89 }
90 
91 ExportWebDialog::~ExportWebDialog()
92 {
93 }
94 
95 void ExportWebDialog::setDefaults()
96 {
97  setWidDefaults();
98 }
99 
100 void ExportWebDialog::readConfig()
101 {
102  readWidConfig();
103  usrReadConfig();
104 }
105 
106 void ExportWebDialog::writeConfig()
107 {
108  writeWidConfig();
109  usrWriteConfig();
110  readConfig();
111 }
112 
113 void ExportWebDialog::slotApply()
114 {
115  writeConfig();
116  emit configChanged();
117 }
118 
119 void ExportWebDialog::slotOk()
120 {
121  slotApply();
122  emit exportHTML( mSettings );
123  accept();
124 }
125 
126 void ExportWebDialog::slotDefault()
127 {
128  kdDebug(5850) << "KPrefsDialog::slotDefault()" << endl;
129 
130  if (KMessageBox::warningContinueCancel(this,
131  i18n("You are about to set all preferences to default values. All "
132  "custom modifications will be lost."),i18n("Setting Default Preferences"),
133  i18n("Reset to Defaults"))
134  == KMessageBox::Continue) setDefaults();
135 }
136 
137 
138 void ExportWebDialog::setupGeneralPage()
139 {
140  mGeneralPage = addPage( i18n("General") );
141  TQVBoxLayout *topLayout = new TQVBoxLayout(mGeneralPage, 10);
142 
143  mDateRangeBox = new TQHGroupBox( i18n("Date Range"), mGeneralPage );
144  topLayout->addWidget( mDateRangeBox );
145  addWidDate( mSettings->dateStartItem(), mDateRangeBox );
146  addWidDate( mSettings->dateEndItem(), mDateRangeBox );
147 
148  TQButtonGroup *typeGroup = new TQVButtonGroup( i18n("View Type"), mGeneralPage );
149  topLayout->addWidget( typeGroup );
150 // addWidBool( mSettings->weekViewItem(), typeGroup );
151  mMonthViewCheckBox = addWidBool( mSettings->monthViewItem(), typeGroup )->checkBox();
152  connect( mMonthViewCheckBox, TQ_SIGNAL(toggled(bool)), TQ_SLOT(updateState()) );
153  mEventListCheckBox = addWidBool( mSettings->eventViewItem(), typeGroup )->checkBox();
154  connect( mEventListCheckBox, TQ_SIGNAL(toggled(bool)), TQ_SLOT(updateState()) );
155  addWidBool( mSettings->todoViewItem(), typeGroup );
156 // addWidBool( mSettings->journalViewItem(), typeGroup );
157 // addWidBool( mSettings->freeBusyViewItem(), typeGroup );
158  addWidBool( mSettings->excludePrivateItem(), typeGroup );
159  addWidBool( mSettings->excludeConfidentialItem(), typeGroup );
160 
161  TQGroupBox *destGroup = new TQVGroupBox(i18n("Destination"), mGeneralPage );
162  topLayout->addWidget(destGroup);
163  KPrefsWidPath *pathWid = addWidPath( mSettings->outputFileItem(),
164  destGroup, "text/html", KFile::File );
165  connect( pathWid->urlRequester(), TQ_SIGNAL( textChanged( const TQString & ) ),
166  TQ_SLOT( slotTextChanged( const TQString & ) ) );
167 
168  topLayout->addStretch( 1 );
169 }
170 
171 void ExportWebDialog::slotTextChanged( const TQString & _text)
172 {
173  enableButton( User1, !_text.isEmpty() );
174 }
175 
176 void ExportWebDialog::setupTodoPage()
177 {
178  mTodoPage = addPage(i18n("To-dos"));
179  TQVBoxLayout *topLayout = new TQVBoxLayout( mTodoPage, 10 );
180 
181  TQHBox *hbox = new TQHBox( mTodoPage );
182  topLayout->addWidget( hbox );
183  addWidString( mSettings->todoListTitleItem(), hbox );
184 
185  TQVBox *vbox = new TQVBox( mTodoPage );
186  topLayout->addWidget( vbox );
187  addWidBool( mSettings->taskDueDateItem(), vbox );
188  addWidBool( mSettings->taskLocationItem(), vbox );
189  addWidBool( mSettings->taskCategoriesItem(), vbox );
190  addWidBool( mSettings->taskAttendeesItem(), vbox );
191 // addWidBool( mSettings->taskExcludePrivateItem(), vbox );
192 // addWidBool( mSettings->taskExcludeConfidentialItem(), vbox );
193 
194  topLayout->addStretch(1);
195 }
196 
197 void ExportWebDialog::setupEventPage()
198 {
199  mEventPage = addPage(i18n("Events"));
200  TQVBoxLayout *topLayout = new TQVBoxLayout( mEventPage, 10 );
201 
202  TQHBox *hbox = new TQHBox( mEventPage );
203  topLayout->addWidget( hbox );
204  addWidString( mSettings->eventTitleItem(), hbox );
205 
206  TQVBox *vbox = new TQVBox( mEventPage );
207  topLayout->addWidget( vbox );
208  addWidBool( mSettings->eventLocationItem(), vbox );
209  addWidBool( mSettings->eventCategoriesItem(), vbox );
210  addWidBool( mSettings->eventAttendeesItem(), vbox );
211 // addWidBool( mSettings->eventExcludePrivateItem(), vbox );
212 // addWidBool( mSettings->eventExcludeConfidentialItem(), vbox );
213 
214  topLayout->addStretch(1);
215 }
216 /*
217 void ExportWebDialog::setupJournalPage()
218 {
219  mJournalPage = addPage(i18n("Journal"));
220  TQVBoxLayout *topLayout = new TQVBoxLayout( mJournalPage, 10 );
221 
222  TQHBox *hbox = new TQHBox( mJournalPage );
223  topLayout->addWidget( hbox );
224  addWidString( mSettings->journalTitleItem(), hbox );
225 
226  TQVBox *vbox = new TQVBox( mJournalPage );
227  topLayout->addWidget( vbox );
228 // addWidBool( mSettings->eventExcludeConfidentialItem(), vbox );
229 
230  topLayout->addStretch(1);
231 }
232 
233 void ExportWebDialog::setupFreeBusyPage()
234 {
235  mFreeBusyPage = addPage(i18n("Free/Busy"));
236  TQVBoxLayout *topLayout = new TQVBoxLayout( mFreeBusyPage, 10 );
237 
238  TQHBox *hbox = new TQHBox( mFreeBusyPage );
239  topLayout->addWidget( hbox );
240  addWidString( mSettings->journalTitleItem(), hbox );
241 
242  TQVBox *vbox = new TQVBox( mFreeBusyPage );
243  topLayout->addWidget( vbox );
244 // addWidBool( mSettings->eventExcludeConfidentialItem(), vbox );
245 
246  topLayout->addStretch(1);
247 }
248 
249 void ExportWebDialog::setupAdvancedPage()
250 {
251  mAdvancedPage = addPage(i18n("Advanced"));
252  TQVBoxLayout *topLayout = new TQVBoxLayout( mAdvancedPage, 10 );
253 
254  TQVBox *vbox = new TQVBox( mAdvancedPage );
255  topLayout->addWidget( vbox );
256 // addWidBool( mSettings->eventExcludeConfidentialItem(), vbox );
257 
258  topLayout->addStretch(1);
259 }
260 */
261 
262 void ExportWebDialog::updateState()
263 {
264  const bool exportEvents = mMonthViewCheckBox->isChecked() || mEventListCheckBox->isChecked();
265  mDateRangeBox->setEnabled( exportEvents );
266  mEventPage->setEnabled( exportEvents );
267 }
268