00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00058
00059 setWFlags( getWFlags() | WGroupLeader );
00060
00061 mCalendar = calendar;
00062
00063 setButtonText( Default, i18n("Load &Template...") );
00064
00065 QString saveTemplateText;
00066 if ( KOPrefs::instance()->mCompactDialogs ) {
00067 showButton( User1, false );
00068 showButton( Apply, false );
00069 } else {
00070 saveTemplateText = i18n("&Save as Template...");
00071 }
00072 setButtonText( User1, saveTemplateText );
00073
00074 mCategoryDialog = new KPIM::CategorySelectDialog( KOPrefs::instance(), this );
00075 KOGlobals::fitDialogToScreen( mCategoryDialog );
00076
00077 connect( mCategoryDialog, SIGNAL( editCategories() ),
00078 SIGNAL( editCategories() ) );
00079
00080 connect( this, SIGNAL( defaultClicked() ), SLOT( slotLoadTemplate() ) );
00081 connect( this, SIGNAL( user1Clicked() ), SLOT( slotSaveTemplate() ) );
00082 connect( this, SIGNAL( finished() ), SLOT( delayedDestruct() ) );
00083 }
00084
00085 KOIncidenceEditor::~KOIncidenceEditor()
00086 {
00087 delete mCategoryDialog;
00088 }
00089
00090 void KOIncidenceEditor::setupAttendeesTab()
00091 {
00092 QFrame *topFrame = addPage( i18n("Atte&ndees") );
00093
00094 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00095
00096 mDetails = new KOEditorDetails( spacingHint(), topFrame );
00097 topLayout->addWidget( mDetails );
00098 }
00099
00100 void KOIncidenceEditor::setupAttachmentsTab()
00101 {
00102 QFrame *topFrame = addPage( i18n("Attachments") );
00103
00104 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00105
00106 mAttachments = new KOEditorAttachments( spacingHint(), topFrame );
00107 topLayout->addWidget( mAttachments );
00108 }
00109
00110 void KOIncidenceEditor::slotApply()
00111 {
00112 processInput();
00113 }
00114
00115 void KOIncidenceEditor::slotOk()
00116 {
00117 if ( processInput() ) accept();
00118 }
00119
00120 void KOIncidenceEditor::updateCategoryConfig()
00121 {
00122 mCategoryDialog->updateCategoryConfig();
00123 }
00124
00125 void KOIncidenceEditor::slotCancel()
00126 {
00127 processCancel();
00128 reject();
00129 }
00130
00131 void KOIncidenceEditor::cancelRemovedAttendees( Incidence *incidence )
00132 {
00133 if ( !incidence ) return;
00134
00135
00136
00137 if ( KOPrefs::instance()->thatIsMe( incidence->organizer().email() ) ) {
00138 Incidence *ev = incidence->clone();
00139 ev->registerObserver( 0 );
00140 mDetails->cancelAttendeeEvent( ev );
00141 if ( ev->attendeeCount() > 0 ) {
00142 emit deleteAttendee( ev );
00143 }
00144 delete( ev );
00145 }
00146
00147 }
00148
00149 void KOIncidenceEditor::slotLoadTemplate()
00150 {
00151 kdDebug(5850) << "KOIncidenceEditor::loadTemplate()" << endl;
00152 }
00153
00154 void KOIncidenceEditor::slotSaveTemplate()
00155 {
00156 kdDebug(5850) << "KOIncidenceEditor::saveTemplate()" << endl;
00157 QString tp = type();
00158 QStringList templates;
00159 if ( tp == "Event" ) {
00160 templates = KOPrefs::instance()->mEventTemplates;
00161 } else if( tp == "ToDo" ) {
00162 templates = KOPrefs::instance()->mTodoTemplates;
00163 } else if ( tp == "Journal" ) {
00164 templates = KOPrefs::instance()->mJournalTemplates;
00165 }
00166 bool ok = false;
00167 QString templateName = KInputDialog::getItem( i18n("Save Template"),
00168 i18n("Please enter a name for the template:"), templates,
00169 -1, true, &ok, this );
00170 if ( ok && templateName.isEmpty() ) {
00171 KMessageBox::error( this, i18n("You did not give a valid template name, "
00172 "no template will be saved") );
00173 ok = false;
00174 }
00175
00176 if ( ok && templates.contains( templateName ) ) {
00177 int res = KMessageBox::warningYesNo( this,
00178 i18n("The selected template "
00179 "already exists. Overwrite it?"),
00180 i18n("Template Already Exists") );
00181 if ( res == KMessageBox::No ) {
00182 ok = false;
00183 }
00184 }
00185
00186 if ( ok ) {
00187 saveTemplate( templateName );
00188
00189
00190 if ( !templates.contains( templateName ) ) {
00191 templates.append( templateName );
00192 if ( tp == "Event" ) {
00193 KOPrefs::instance()->mEventTemplates = templates;
00194 } else if ( tp == "ToDo" ) {
00195 KOPrefs::instance()->mTodoTemplates = templates;
00196 } else if ( tp == "Journal" ) {
00197 KOPrefs::instance()->mJournalTemplates = templates;
00198 }
00199 }
00200
00201 }
00202 }
00203
00204 void KOIncidenceEditor::saveAsTemplate( Incidence *incidence,
00205 const QString &templateName )
00206 {
00207 if ( !incidence || templateName.isEmpty() ) return;
00208
00209 QString fileName = "templates/" + incidence->type();
00210 fileName.append( "/" + templateName );
00211 fileName = locateLocal( "data", "korganizer/" + fileName );
00212
00213 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId );
00214 cal.addIncidence( incidence );
00215 ICalFormat format;
00216 format.save( &cal, fileName );
00217 }
00218
00219 QString KOIncidenceEditor::loadTemplate( Calendar *cal, const QString &type,
00220 const QStringList &templates )
00221 {
00222 bool ok = false;
00223 QString templateName = KInputDialog::getItem( i18n("Load Template"),
00224 i18n("Select a template to load:"), templates, 0, false, &ok, this );
00225
00226 if ( !ok || templateName.isEmpty() ) return QString::null;
00227
00228 QString fileName = locateLocal( "data", "korganizer/templates/" + type + "/" +
00229 templateName );
00230
00231 if ( fileName.isEmpty() ) {
00232 KMessageBox::error( this, i18n("Unable to find template '%1'.")
00233 .arg( fileName ) );
00234 return QString::null;
00235 } else {
00236 ICalFormat format;
00237 if ( !format.load( cal, fileName ) ) {
00238 KMessageBox::error( this, i18n("Error loading template file '%1'.")
00239 .arg( fileName ) );
00240 return QString::null;
00241 }
00242 }
00243
00244 return templateName;
00245 }
00246
00247
00248 #include "koincidenceeditor.moc"