korganizer Library API Documentation

exportwebdialog.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of Qt, and distribute the resulting executable, 00021 without including the source code for Qt in the source distribution. 00022 */ 00023 00024 #include <qlayout.h> 00025 #include <qhgroupbox.h> 00026 #include <qvgroupbox.h> 00027 #include <qvbuttongroup.h> 00028 #include <qradiobutton.h> 00029 #include <qcheckbox.h> 00030 #include <qlineedit.h> 00031 #include <qhbox.h> 00032 #include <qpushbutton.h> 00033 #include <qfiledialog.h> 00034 #include <qtextstream.h> 00035 #include <qlabel.h> 00036 00037 #include <klocale.h> 00038 #include <kdebug.h> 00039 #include <kfiledialog.h> 00040 #include <klineedit.h> 00041 #include <kurl.h> 00042 #include <kio/job.h> 00043 #include <kstandarddirs.h> 00044 #include <kconfig.h> 00045 #include "koglobals.h" 00046 #include <kurlrequester.h> 00047 #include <kio/netaccess.h> 00048 #include <knotifyclient.h> 00049 #include <ktempfile.h> 00050 00051 #include <libkcal/calendar.h> 00052 00053 #include <libkdepim/kdateedit.h> 00054 #include <libkdepim/kdateedit.h> 00055 00056 #include "koprefs.h" 00057 #include "kocore.h" 00058 00059 #include "exportwebdialog.h" 00060 #include "exportwebdialog.moc" 00061 00062 ExportWebDialog::ExportWebDialog (Calendar *cal, QWidget *parent, 00063 const char *name) : 00064 KDialogBase(Tabbed,i18n("Export Calendar as Web Page"), 00065 Help|Default|User1|Cancel,User1,parent,name,false,false, 00066 i18n("Export")), 00067 mCalendar(cal), 00068 mDataAvailable(false) 00069 { 00070 mExport = new HtmlExport(cal); 00071 00072 mConfig = KOGlobals::self()->config(); 00073 00074 setupGeneralPage(); 00075 setupEventPage(); 00076 setupTodoPage(); 00077 // Disabled bacause the functionality is not yet implemented. 00078 // setupAdvancedPage(); 00079 00080 loadSettings(); 00081 00082 QObject::connect( this, SIGNAL( user1Clicked() ), SLOT( exportWebPage() ) ); 00083 } 00084 00085 ExportWebDialog::~ExportWebDialog() 00086 { 00087 delete(mExport); 00088 } 00089 00090 void ExportWebDialog::setupGeneralPage() 00091 { 00092 mGeneralPage = addPage(i18n("General")); 00093 00094 QVBoxLayout *topLayout = new QVBoxLayout(mGeneralPage, 10); 00095 00096 QGroupBox *rangeGroup = new QHGroupBox(i18n("Date Range"),mGeneralPage); 00097 topLayout->addWidget(rangeGroup); 00098 00099 mFromDate = new KDateEdit(rangeGroup); 00100 mFromDate->setDate(QDate::currentDate()); 00101 00102 mToDate = new KDateEdit(rangeGroup); 00103 mToDate->setDate(QDate::currentDate().addMonths(1)); 00104 00105 QButtonGroup *typeGroup = new QVButtonGroup(i18n("View Type"),mGeneralPage); 00106 topLayout->addWidget(typeGroup); 00107 00108 00109 // For now we just support the todo view. Other view types will follow 00110 // shortly. 00111 // new QRadioButton(i18n("Day"), typeGroup); 00112 // new QRadioButton(i18n("Week"), typeGroup); 00113 mCbMonth = new QCheckBox(i18n("Month"), typeGroup); 00114 mCbEvent = new QCheckBox(i18n("Event list"), typeGroup); 00115 mCbTodo = new QCheckBox(i18n("To-do list"), typeGroup); 00116 00117 QGroupBox *destGroup = new QVGroupBox(i18n("Destination"),mGeneralPage); 00118 topLayout->addWidget(destGroup); 00119 00120 new QLabel(i18n("Output file:"),destGroup); 00121 00122 QHBox *outputFileLayout = new QHBox(destGroup); 00123 mOutputFileEdit = new KURLRequester(KOPrefs::instance()->mHtmlExportFile, 00124 outputFileLayout); 00125 connect( mOutputFileEdit->lineEdit(), SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotTextChanged( const QString & ) ) ); 00126 slotTextChanged( mOutputFileEdit->lineEdit()->text()); 00127 topLayout->addStretch(1); 00128 } 00129 00130 void ExportWebDialog::slotTextChanged( const QString & _text) 00131 { 00132 enableButton( User1, !_text.isEmpty() ); 00133 } 00134 00135 void ExportWebDialog::setupTodoPage() 00136 { 00137 mTodoPage = addPage(i18n("To-Do")); 00138 00139 QVBoxLayout *topLayout = new QVBoxLayout(mTodoPage, 10); 00140 00141 mCbDueDates = new QCheckBox (i18n("Due dates"),mTodoPage); 00142 topLayout->addWidget(mCbDueDates); 00143 00144 mCbCategoriesTodo = new QCheckBox (i18n("Categories"),mTodoPage); 00145 topLayout->addWidget(mCbCategoriesTodo); 00146 00147 mCbAttendeesTodo = new QCheckBox (i18n("Attendees"),mTodoPage); 00148 topLayout->addWidget(mCbAttendeesTodo); 00149 00150 mCbExcludePrivateTodo = new QCheckBox (i18n("Exclude private"),mTodoPage); 00151 topLayout->addWidget(mCbExcludePrivateTodo); 00152 00153 mCbExcludeConfidentialTodo = new QCheckBox (i18n("Exclude confidential"),mTodoPage); 00154 topLayout->addWidget(mCbExcludeConfidentialTodo); 00155 00156 topLayout->addStretch(1); 00157 } 00158 00159 void ExportWebDialog::setupEventPage() 00160 { 00161 mEventPage = addPage(i18n("Event")); 00162 00163 QVBoxLayout *topLayout = new QVBoxLayout(mEventPage, 10); 00164 00165 mCbCategoriesEvent = new QCheckBox (i18n("Categories"),mEventPage); 00166 topLayout->addWidget(mCbCategoriesEvent); 00167 00168 mCbAttendeesEvent = new QCheckBox (i18n("Attendees"),mEventPage); 00169 topLayout->addWidget(mCbAttendeesEvent); 00170 00171 mCbExcludePrivateEvent = new QCheckBox (i18n("Exclude private"),mEventPage); 00172 topLayout->addWidget(mCbExcludePrivateEvent); 00173 00174 mCbExcludeConfidentialEvent = new QCheckBox (i18n("Exclude confidential"),mEventPage); 00175 topLayout->addWidget(mCbExcludeConfidentialEvent); 00176 00177 topLayout->addStretch(1); 00178 } 00179 00180 void ExportWebDialog::setupAdvancedPage() 00181 { 00182 mAdvancedPage = addPage(i18n("Advanced")); 00183 00184 QVBoxLayout *topLayout = new QVBoxLayout(mAdvancedPage, 10); 00185 00186 mCbHtmlFragment = new QCheckBox (i18n("Only generate HTML fragment"), 00187 mAdvancedPage); 00188 topLayout->addWidget(mCbHtmlFragment); 00189 00190 QPushButton *colorsButton = new QPushButton(i18n("Colors"),mAdvancedPage); 00191 topLayout->addWidget(colorsButton); 00192 00193 // Implement the functionality to enable this buttons. 00194 mCbHtmlFragment->setEnabled(false); 00195 colorsButton->setEnabled(false); 00196 00197 topLayout->addStretch(1); 00198 } 00199 00200 void ExportWebDialog::loadSettings() 00201 { 00202 KConfig *cfg = KOGlobals::self()->config(); 00203 cfg->setGroup( "HtmlExport" ); 00204 00205 mCbMonth->setChecked( cfg->readBoolEntry( "Month", false ) ); 00206 mCbEvent->setChecked( cfg->readBoolEntry( "Event", true ) ); 00207 mCbTodo->setChecked( cfg->readBoolEntry( "Todo", true ) ); 00208 mCbCategoriesEvent->setChecked( cfg->readBoolEntry( "CategoriesEvent", false ) ); 00209 mCbAttendeesEvent->setChecked( cfg->readBoolEntry( "AttendeesEvent", false ) ); 00210 mCbExcludePrivateEvent->setChecked( cfg->readBoolEntry( "ExcludePrivateEvent", true ) ); 00211 mCbExcludeConfidentialEvent->setChecked( cfg->readBoolEntry( "ExcludeConfidentialEvent", true ) ); 00212 mCbCategoriesTodo->setChecked( cfg->readBoolEntry( "CategoriesTodo", false ) ); 00213 mCbAttendeesTodo->setChecked( cfg->readBoolEntry( "AttendeesTodo", false ) ); 00214 mCbExcludePrivateTodo->setChecked( cfg->readBoolEntry( "ExcludePrivateTodo", true ) ); 00215 mCbExcludeConfidentialTodo->setChecked( cfg->readBoolEntry( "ExcludeConfidentialTodo", true ) ); 00216 mCbDueDates->setChecked( cfg->readBoolEntry( "DueDates", true ) ); 00217 } 00218 00219 void ExportWebDialog::saveSettings() 00220 { 00221 KConfig *cfg = KOGlobals::self()->config(); 00222 cfg->setGroup( "HtmlExport" ); 00223 00224 cfg->writeEntry( "Month", mCbMonth->isChecked() ); 00225 cfg->writeEntry( "Event", mCbEvent->isChecked() ); 00226 cfg->writeEntry( "Todo", mCbTodo->isChecked() ); 00227 cfg->writeEntry( "CategoriesEvent", mCbCategoriesEvent->isChecked() ); 00228 cfg->writeEntry( "AttendeesEvent", mCbAttendeesEvent->isChecked()); 00229 cfg->writeEntry( "ExcludePrivateEvent", mCbExcludePrivateEvent->isChecked()); 00230 cfg->writeEntry( "ExcludeConfidentialEvent", mCbExcludeConfidentialEvent->isChecked()); 00231 cfg->writeEntry( "CategoriesTodo", mCbCategoriesTodo->isChecked()); 00232 cfg->writeEntry( "AttendeesTodo", mCbAttendeesTodo->isChecked()); 00233 cfg->writeEntry( "ExcludePrivateTodo", mCbExcludePrivateTodo->isChecked()); 00234 cfg->writeEntry( "ExcludeConfidentialTodo", mCbExcludeConfidentialTodo->isChecked()); 00235 cfg->writeEntry( "DueDates", mCbDueDates->isChecked()); 00236 00237 cfg->sync(); 00238 } 00239 00240 void ExportWebDialog::exportWebPage(bool synchronous) 00241 { 00242 saveSettings(); 00243 00244 mExport->setEmail( KOPrefs::instance()->email() ); 00245 mExport->setFullName( KOPrefs::instance()->fullName() ); 00246 mExport->setMonthViewEnabled(mCbMonth->isChecked()); 00247 mExport->setEventsEnabled(mCbEvent->isChecked()); 00248 mExport->setTodosEnabled(mCbTodo->isChecked()); 00249 mExport->setCategoriesEventEnabled(mCbCategoriesEvent->isChecked()); 00250 mExport->setAttendeesEventEnabled(mCbAttendeesEvent->isChecked()); 00251 mExport->setExcludePrivateEventEnabled(mCbExcludePrivateEvent->isChecked()); 00252 mExport->setExcludeConfidentialEventEnabled(mCbExcludeConfidentialEvent->isChecked()); 00253 mExport->setCategoriesTodoEnabled(mCbCategoriesTodo->isChecked()); 00254 mExport->setAttendeesTodoEnabled(mCbAttendeesTodo->isChecked()); 00255 mExport->setExcludePrivateTodoEnabled(mCbExcludePrivateTodo->isChecked()); 00256 mExport->setExcludeConfidentialTodoEnabled(mCbExcludeConfidentialTodo->isChecked()); 00257 mExport->setDueDateEnabled(mCbDueDates->isChecked()); 00258 mExport->setDateRange(mFromDate->date(),mToDate->date()); 00259 00260 QDate cdate=mFromDate->date(); 00261 while (cdate<=mToDate->date()) 00262 { 00263 if ( !KOCore::self()->holiday(cdate).isEmpty() ) 00264 mExport->addHoliday( cdate, KOCore::self()->holiday(cdate) ); 00265 cdate = cdate.addDays(1); 00266 } 00267 00268 KURL dest(mOutputFileEdit->lineEdit()->text()); 00269 // Remember destination. 00270 KOPrefs::instance()->mHtmlExportFile = mOutputFileEdit->lineEdit()->text(); 00271 00272 if (synchronous) { 00273 if (!dest.isLocalFile()) { 00274 KTempFile tf; 00275 QString tfile = tf.name(); 00276 tf.close(); 00277 mExport->save(tfile); 00278 if (!KIO::NetAccess::upload (tfile, dest, this)) { 00279 KNotifyClient::event (winId(), i18n( "Could not upload file." )); 00280 } 00281 tf.unlink(); 00282 } else { 00283 mExport->save(dest.path()); 00284 } 00285 } else { 00286 mDataAvailable = true; 00287 KIO::TransferJob *job = KIO::put(dest,-1,true,false); 00288 connect(job,SIGNAL(dataReq(KIO::Job *,QByteArray &)), 00289 SLOT(slotDataReq(KIO::Job *,QByteArray &))); 00290 connect(job,SIGNAL(result(KIO::Job *)),SLOT(slotResult(KIO::Job *))); 00291 } 00292 } 00293 00294 void ExportWebDialog::slotResult(KIO::Job *job) 00295 { 00296 kdDebug(5850) << "slotResult" << endl; 00297 int err = job->error(); 00298 if (err) 00299 { 00300 kdDebug(5850) << " Error " << err << ": " << job->errorString() << endl; 00301 job->showErrorDialog(); 00302 } else { 00303 kdDebug(5850) << " No Error" << endl; 00304 accept(); 00305 } 00306 kdDebug(5850) << "slotResult done" << endl; 00307 } 00308 00309 void ExportWebDialog::slotDataReq(KIO::Job *,QByteArray &data) 00310 { 00311 kdDebug(5850) << "ExportWebDialog::slotDataReq()" << endl; 00312 00313 if (mDataAvailable) { 00314 kdDebug(5850) << " Data availavble" << endl; 00315 QTextStream ts(data,IO_WriteOnly); 00316 ts.setEncoding( QTextStream::Latin1 ); 00317 00318 mExport->save(&ts); 00319 mDataAvailable = false; 00320 } else 00321 kdDebug(5850) << " No Data" << endl; 00322 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003