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 mOutputFileEdit->setMode( KFile::File ); 00126 mOutputFileEdit->setFilter( "text/html" ); 00127 connect( mOutputFileEdit->lineEdit(), SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotTextChanged( const QString & ) ) ); 00128 slotTextChanged( mOutputFileEdit->lineEdit()->text()); 00129 topLayout->addStretch(1); 00130 } 00131 00132 void ExportWebDialog::slotTextChanged( const QString & _text) 00133 { 00134 enableButton( User1, !_text.isEmpty() ); 00135 } 00136 00137 void ExportWebDialog::setupTodoPage() 00138 { 00139 mTodoPage = addPage(i18n("To-Do")); 00140 00141 QVBoxLayout *topLayout = new QVBoxLayout(mTodoPage, 10); 00142 00143 mCbDueDates = new QCheckBox (i18n("Due dates"),mTodoPage); 00144 topLayout->addWidget(mCbDueDates); 00145 00146 mCbCategoriesTodo = new QCheckBox (i18n("Categories"),mTodoPage); 00147 topLayout->addWidget(mCbCategoriesTodo); 00148 00149 mCbAttendeesTodo = new QCheckBox (i18n("Attendees"),mTodoPage); 00150 topLayout->addWidget(mCbAttendeesTodo); 00151 00152 mCbExcludePrivateTodo = new QCheckBox (i18n("Exclude private"),mTodoPage); 00153 topLayout->addWidget(mCbExcludePrivateTodo); 00154 00155 mCbExcludeConfidentialTodo = new QCheckBox (i18n("Exclude confidential"),mTodoPage); 00156 topLayout->addWidget(mCbExcludeConfidentialTodo); 00157 00158 topLayout->addStretch(1); 00159 } 00160 00161 void ExportWebDialog::setupEventPage() 00162 { 00163 mEventPage = addPage(i18n("Event")); 00164 00165 QVBoxLayout *topLayout = new QVBoxLayout(mEventPage, 10); 00166 00167 mCbCategoriesEvent = new QCheckBox (i18n("Categories"),mEventPage); 00168 topLayout->addWidget(mCbCategoriesEvent); 00169 00170 mCbAttendeesEvent = new QCheckBox (i18n("Attendees"),mEventPage); 00171 topLayout->addWidget(mCbAttendeesEvent); 00172 00173 mCbExcludePrivateEvent = new QCheckBox (i18n("Exclude private"),mEventPage); 00174 topLayout->addWidget(mCbExcludePrivateEvent); 00175 00176 mCbExcludeConfidentialEvent = new QCheckBox (i18n("Exclude confidential"),mEventPage); 00177 topLayout->addWidget(mCbExcludeConfidentialEvent); 00178 00179 topLayout->addStretch(1); 00180 } 00181 00182 void ExportWebDialog::setupAdvancedPage() 00183 { 00184 mAdvancedPage = addPage(i18n("Advanced")); 00185 00186 QVBoxLayout *topLayout = new QVBoxLayout(mAdvancedPage, 10); 00187 00188 mCbHtmlFragment = new QCheckBox (i18n("Only generate HTML fragment"), 00189 mAdvancedPage); 00190 topLayout->addWidget(mCbHtmlFragment); 00191 00192 QPushButton *colorsButton = new QPushButton(i18n("Colors"),mAdvancedPage); 00193 topLayout->addWidget(colorsButton); 00194 00195 // Implement the functionality to enable this buttons. 00196 mCbHtmlFragment->setEnabled(false); 00197 colorsButton->setEnabled(false); 00198 00199 topLayout->addStretch(1); 00200 } 00201 00202 void ExportWebDialog::loadSettings() 00203 { 00204 KConfig *cfg = KOGlobals::self()->config(); 00205 cfg->setGroup( "HtmlExport" ); 00206 00207 mCbMonth->setChecked( cfg->readBoolEntry( "Month", false ) ); 00208 mCbEvent->setChecked( cfg->readBoolEntry( "Event", true ) ); 00209 mCbTodo->setChecked( cfg->readBoolEntry( "Todo", true ) ); 00210 mCbCategoriesEvent->setChecked( cfg->readBoolEntry( "CategoriesEvent", false ) ); 00211 mCbAttendeesEvent->setChecked( cfg->readBoolEntry( "AttendeesEvent", false ) ); 00212 mCbExcludePrivateEvent->setChecked( cfg->readBoolEntry( "ExcludePrivateEvent", true ) ); 00213 mCbExcludeConfidentialEvent->setChecked( cfg->readBoolEntry( "ExcludeConfidentialEvent", true ) ); 00214 mCbCategoriesTodo->setChecked( cfg->readBoolEntry( "CategoriesTodo", false ) ); 00215 mCbAttendeesTodo->setChecked( cfg->readBoolEntry( "AttendeesTodo", false ) ); 00216 mCbExcludePrivateTodo->setChecked( cfg->readBoolEntry( "ExcludePrivateTodo", true ) ); 00217 mCbExcludeConfidentialTodo->setChecked( cfg->readBoolEntry( "ExcludeConfidentialTodo", true ) ); 00218 mCbDueDates->setChecked( cfg->readBoolEntry( "DueDates", true ) ); 00219 } 00220 00221 void ExportWebDialog::saveSettings() 00222 { 00223 KConfig *cfg = KOGlobals::self()->config(); 00224 cfg->setGroup( "HtmlExport" ); 00225 00226 cfg->writeEntry( "Month", mCbMonth->isChecked() ); 00227 cfg->writeEntry( "Event", mCbEvent->isChecked() ); 00228 cfg->writeEntry( "Todo", mCbTodo->isChecked() ); 00229 cfg->writeEntry( "CategoriesEvent", mCbCategoriesEvent->isChecked() ); 00230 cfg->writeEntry( "AttendeesEvent", mCbAttendeesEvent->isChecked()); 00231 cfg->writeEntry( "ExcludePrivateEvent", mCbExcludePrivateEvent->isChecked()); 00232 cfg->writeEntry( "ExcludeConfidentialEvent", mCbExcludeConfidentialEvent->isChecked()); 00233 cfg->writeEntry( "CategoriesTodo", mCbCategoriesTodo->isChecked()); 00234 cfg->writeEntry( "AttendeesTodo", mCbAttendeesTodo->isChecked()); 00235 cfg->writeEntry( "ExcludePrivateTodo", mCbExcludePrivateTodo->isChecked()); 00236 cfg->writeEntry( "ExcludeConfidentialTodo", mCbExcludeConfidentialTodo->isChecked()); 00237 cfg->writeEntry( "DueDates", mCbDueDates->isChecked()); 00238 00239 cfg->sync(); 00240 } 00241 00242 void ExportWebDialog::exportWebPage(bool synchronous) 00243 { 00244 saveSettings(); 00245 00246 mExport->setTitle( "KOrganizer Calendar" ); 00247 mExport->setTitleTodo( "KOrganizer To-Do List" ); 00248 mExport->setCredit( "KOrganizer", "http://korganizer.kde.org" ); 00249 mExport->setEmail( KOPrefs::instance()->email() ); 00250 mExport->setFullName( KOPrefs::instance()->fullName() ); 00251 mExport->setMonthViewEnabled(mCbMonth->isChecked()); 00252 mExport->setEventsEnabled(mCbEvent->isChecked()); 00253 mExport->setTodosEnabled(mCbTodo->isChecked()); 00254 mExport->setCategoriesEventEnabled(mCbCategoriesEvent->isChecked()); 00255 mExport->setAttendeesEventEnabled(mCbAttendeesEvent->isChecked()); 00256 mExport->setExcludePrivateEventEnabled(mCbExcludePrivateEvent->isChecked()); 00257 mExport->setExcludeConfidentialEventEnabled(mCbExcludeConfidentialEvent->isChecked()); 00258 mExport->setCategoriesTodoEnabled(mCbCategoriesTodo->isChecked()); 00259 mExport->setAttendeesTodoEnabled(mCbAttendeesTodo->isChecked()); 00260 mExport->setExcludePrivateTodoEnabled(mCbExcludePrivateTodo->isChecked()); 00261 mExport->setExcludeConfidentialTodoEnabled(mCbExcludeConfidentialTodo->isChecked()); 00262 mExport->setDueDateEnabled(mCbDueDates->isChecked()); 00263 mExport->setDateRange(mFromDate->date(),mToDate->date()); 00264 00265 QDate cdate=mFromDate->date(); 00266 while (cdate<=mToDate->date()) 00267 { 00268 if ( !KOCore::self()->holiday(cdate).isEmpty() ) 00269 mExport->addHoliday( cdate, KOCore::self()->holiday(cdate) ); 00270 cdate = cdate.addDays(1); 00271 } 00272 00273 KURL dest(mOutputFileEdit->lineEdit()->text()); 00274 // Remember destination. 00275 KOPrefs::instance()->mHtmlExportFile = mOutputFileEdit->lineEdit()->text(); 00276 00277 if (synchronous) { 00278 if (!dest.isLocalFile()) { 00279 KTempFile tf; 00280 QString tfile = tf.name(); 00281 tf.close(); 00282 mExport->save(tfile); 00283 if (!KIO::NetAccess::upload (tfile, dest, this)) { 00284 KNotifyClient::event (winId(),"Could not upload file."); 00285 } 00286 tf.unlink(); 00287 } else { 00288 mExport->save(dest.path()); 00289 } 00290 } else { 00291 mDataAvailable = true; 00292 KIO::TransferJob *job = KIO::put(dest,-1,true,false); 00293 connect(job,SIGNAL(dataReq(KIO::Job *,QByteArray &)), 00294 SLOT(slotDataReq(KIO::Job *,QByteArray &))); 00295 connect(job,SIGNAL(result(KIO::Job *)),SLOT(slotResult(KIO::Job *))); 00296 } 00297 } 00298 00299 void ExportWebDialog::slotResult(KIO::Job *job) 00300 { 00301 kdDebug(5850) << "slotResult" << endl; 00302 int err = job->error(); 00303 if (err) 00304 { 00305 kdDebug(5850) << " Error " << err << ": " << job->errorString() << endl; 00306 job->showErrorDialog(); 00307 } else { 00308 kdDebug(5850) << " No Error" << endl; 00309 accept(); 00310 } 00311 kdDebug(5850) << "slotResult done" << endl; 00312 } 00313 00314 void ExportWebDialog::slotDataReq(KIO::Job *,QByteArray &data) 00315 { 00316 kdDebug(5850) << "ExportWebDialog::slotDataReq()" << endl; 00317 00318 if (mDataAvailable) { 00319 kdDebug(5850) << " Data availavble" << endl; 00320 QTextStream ts(data,IO_WriteOnly); 00321 ts.setEncoding( QTextStream::Latin1 ); 00322 00323 mExport->save(&ts); 00324 mDataAvailable = false; 00325 } else 00326 kdDebug(5850) << " No Data" << endl; 00327 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:30 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003