korganizer Library API Documentation

koincidenceeditor.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 00023 */ 00024 00025 #include <qtooltip.h> 00026 #include <qframe.h> 00027 #include <qpixmap.h> 00028 #include <qlayout.h> 00029 #include <qwidgetstack.h> 00030 #include <qdatetime.h> 00031 00032 #include <kdebug.h> 00033 #include <klocale.h> 00034 #include <kstandarddirs.h> 00035 #include <kmessagebox.h> 00036 #include <kinputdialog.h> 00037 00038 #include <libkdepim/categoryselectdialog.h> 00039 00040 #include <libkcal/calendarlocal.h> 00041 #include <libkcal/incidence.h> 00042 #include <libkcal/icalformat.h> 00043 00044 #include "koprefs.h" 00045 #include "koglobals.h" 00046 #include "koeditordetails.h" 00047 #include "koeditorattachments.h" 00048 00049 #include "koincidenceeditor.h" 00050 00051 KOIncidenceEditor::KOIncidenceEditor( const QString &caption, 00052 Calendar *calendar, QWidget *parent ) 00053 : KDialogBase( Tabbed, caption, Ok | Apply | Cancel | Default | User1, Ok, 00054 parent, 0, false, false ), 00055 mDetails( 0 ), mAttachments( 0 ) 00056 { 00057 mCalendar = calendar; 00058 00059 setButtonText( Default, i18n("Load &Template...") ); 00060 00061 QString saveTemplateText; 00062 if ( KOPrefs::instance()->mCompactDialogs ) { 00063 showButton( User1, false ); 00064 showButton( Apply, false ); 00065 } else { 00066 saveTemplateText = i18n("&Save as Template..."); 00067 } 00068 setButtonText( User1, saveTemplateText ); 00069 00070 mCategoryDialog = new KPIM::CategorySelectDialog( KOPrefs::instance(), this ); 00071 KOGlobals::fitDialogToScreen( mCategoryDialog ); 00072 00073 connect( mCategoryDialog, SIGNAL( editCategories() ), 00074 SIGNAL( editCategories() ) ); 00075 00076 connect( this, SIGNAL( defaultClicked() ), SLOT( slotLoadTemplate() ) ); 00077 connect( this, SIGNAL( user1Clicked() ), SLOT( slotSaveTemplate() ) ); 00078 connect( this, SIGNAL( finished() ), SLOT( delayedDestruct() ) ); 00079 } 00080 00081 KOIncidenceEditor::~KOIncidenceEditor() 00082 { 00083 delete mCategoryDialog; 00084 } 00085 00086 void KOIncidenceEditor::setupAttendeesTab() 00087 { 00088 QFrame *topFrame = addPage( i18n("Atte&ndees") ); 00089 00090 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 00091 00092 mDetails = new KOEditorDetails( spacingHint(), topFrame ); 00093 topLayout->addWidget( mDetails ); 00094 } 00095 00096 void KOIncidenceEditor::setupAttachmentsTab() 00097 { 00098 QFrame *topFrame = addPage( i18n("Attachments") ); 00099 00100 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 00101 00102 mAttachments = new KOEditorAttachments( spacingHint(), topFrame ); 00103 topLayout->addWidget( mAttachments ); 00104 } 00105 00106 void KOIncidenceEditor::slotApply() 00107 { 00108 processInput(); 00109 } 00110 00111 void KOIncidenceEditor::slotOk() 00112 { 00113 if ( processInput() ) accept(); 00114 } 00115 00116 void KOIncidenceEditor::updateCategoryConfig() 00117 { 00118 mCategoryDialog->updateCategoryConfig(); 00119 } 00120 00121 void KOIncidenceEditor::slotCancel() 00122 { 00123 processCancel(); 00124 reject(); 00125 } 00126 00127 void KOIncidenceEditor::cancelRemovedAttendees( Incidence *incidence ) 00128 { 00129 if ( !incidence ) return; 00130 00131 // cancelAttendeeEvent removes all attendees from the incidence, 00132 // and then only adds those that need to be cancelled (i.e. a mail needs to be sent to them). 00133 if ( KOPrefs::instance()->thatIsMe( incidence->organizer() ) ) { 00134 Incidence *ev = incidence->clone(); 00135 ev->registerObserver( 0 ); 00136 mDetails->cancelAttendeeEvent( ev ); 00137 if ( ev->attendeeCount() > 0 ) { 00138 emit deleteAttendee( ev ); 00139 } 00140 delete( ev ); 00141 } 00142 00143 } 00144 00145 void KOIncidenceEditor::slotLoadTemplate() 00146 { 00147 kdDebug(5850) << "KOIncidenceEditor::loadTemplate()" << endl; 00148 } 00149 00150 void KOIncidenceEditor::slotSaveTemplate() 00151 { 00152 kdDebug(5850) << "KOIncidenceEditor::saveTemplate()" << endl; 00153 QString tp = type(); 00154 QStringList templates; 00155 if ( tp == "Event" ) { 00156 templates = KOPrefs::instance()->mEventTemplates; 00157 } else if( tp == "ToDo" ) { 00158 templates = KOPrefs::instance()->mTodoTemplates; 00159 } else if ( tp == "Journal" ) { 00160 templates = KOPrefs::instance()->mJournalTemplates; 00161 } 00162 bool ok = false; 00163 QString templateName = KInputDialog::getItem( i18n("Save Template"), 00164 i18n("Please enter a name for the template:"), templates, 00165 -1, true, &ok, this ); 00166 if ( ok && templateName.isEmpty() ) { 00167 KMessageBox::error( this, i18n("You did not give a valid template name, " 00168 "no template will be saved") ); 00169 ok = false; 00170 } 00171 00172 if ( ok && templates.contains( templateName ) ) { 00173 int res = KMessageBox::warningYesNo( this, 00174 i18n("The selected template " 00175 "already exists. Overwrite it?"), 00176 i18n("Template Already Exists") ); 00177 if ( res == KMessageBox::No ) { 00178 ok = false; 00179 } 00180 } 00181 00182 if ( ok ) { 00183 saveTemplate( templateName ); 00184 00185 // Add template to list of existing templates 00186 if ( !templates.contains( templateName ) ) { 00187 templates.append( templateName ); 00188 if ( tp == "Event" ) { 00189 KOPrefs::instance()->mEventTemplates = templates; 00190 } else if ( tp == "ToDo" ) { 00191 KOPrefs::instance()->mTodoTemplates = templates; 00192 } else if ( tp == "Journal" ) { 00193 KOPrefs::instance()->mJournalTemplates = templates; 00194 } 00195 } 00196 00197 } 00198 } 00199 00200 void KOIncidenceEditor::saveAsTemplate( Incidence *incidence, 00201 const QString &templateName ) 00202 { 00203 if ( !incidence || templateName.isEmpty() ) return; 00204 00205 QString fileName = "templates/" + incidence->type(); 00206 fileName.append( "/" + templateName ); 00207 fileName = locateLocal( "data", "korganizer/" + fileName ); 00208 00209 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId ); 00210 cal.addIncidence( incidence ); 00211 ICalFormat format; 00212 format.save( &cal, fileName ); 00213 } 00214 00215 QString KOIncidenceEditor::loadTemplate( Calendar *cal, const QString &type, 00216 const QStringList &templates ) 00217 { 00218 bool ok = false; 00219 QString templateName = KInputDialog::getItem( i18n("Load Template"), 00220 i18n("Select a template to load:"), templates, 0, false, &ok, this ); 00221 00222 if ( !ok || templateName.isEmpty() ) return QString::null; 00223 00224 QString fileName = locateLocal( "data", "korganizer/templates/" + type + "/" + 00225 templateName ); 00226 00227 if ( fileName.isEmpty() ) { 00228 KMessageBox::error( this, i18n("Unable to find template '%1'.") 00229 .arg( fileName ) ); 00230 return QString::null; 00231 } else { 00232 ICalFormat format; 00233 if ( !format.load( cal, fileName ) ) { 00234 KMessageBox::error( this, i18n("Error loading template file '%1'.") 00235 .arg( fileName ) ); 00236 return QString::null; 00237 } 00238 } 00239 00240 return templateName; 00241 } 00242 00243 00244 #include "koincidenceeditor.moc"
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 Thu Oct 21 19:46:57 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003