koincidenceeditor.cpp
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 #include "templatemanagementdialog.h"
00051
00052 KOIncidenceEditor::KOIncidenceEditor( const QString &caption,
00053 Calendar *calendar, QWidget *parent )
00054 : KDialogBase( Tabbed, caption, Ok | Cancel | Default, Ok,
00055 parent, 0, false, false ),
00056 mDetails( 0 ), mAttachments( 0 )
00057 {
00058
00059
00060 setWFlags( getWFlags() | WGroupLeader );
00061
00062 mCalendar = calendar;
00063
00064 if ( KOPrefs::instance()->mCompactDialogs ) {
00065 showButton( Apply, false );
00066 showButton( Default, false );
00067 } else {
00068 setButtonText( Default, "&Templates..." );
00069 }
00070
00071 mCategoryDialog = new KPIM::CategorySelectDialog( KOPrefs::instance(), this );
00072 KOGlobals::fitDialogToScreen( mCategoryDialog );
00073
00074 connect( mCategoryDialog, SIGNAL( editCategories() ),
00075 SIGNAL( editCategories() ) );
00076
00077 connect( this, SIGNAL( defaultClicked() ), SLOT( slotManageTemplates() ) );
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
00132
00133 if ( KOPrefs::instance()->thatIsMe( incidence->organizer().email() ) ) {
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::slotManageTemplates()
00146 {
00147 kdDebug(5850) << "KOIncidenceEditor::manageTemplates()" << endl;
00148
00149 QString tp = type();
00150
00151 TemplateManagementDialog * const d = new TemplateManagementDialog( this, templates() );
00152 connect( d, SIGNAL( loadTemplate( const QString& ) ),
00153 this, SLOT( slotLoadTemplate( const QString& ) ) );
00154 connect( d, SIGNAL( templatesChanged( const QStringList& ) ),
00155 this, SLOT( slotTemplatesChanged( const QStringList& ) ) );
00156 connect( d, SIGNAL( saveTemplate( const QString& ) ),
00157 this, SLOT( slotSaveTemplate( const QString& ) ) );
00158 d->exec();
00159 return;
00160 }
00161
00162 void KOIncidenceEditor::saveAsTemplate( Incidence *incidence,
00163 const QString &templateName )
00164 {
00165 if ( !incidence || templateName.isEmpty() ) return;
00166
00167 QString fileName = "templates/" + incidence->type();
00168 fileName.append( "/" + templateName );
00169 fileName = locateLocal( "data", "korganizer/" + fileName );
00170
00171 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId );
00172 cal.addIncidence( incidence );
00173 ICalFormat format;
00174 format.save( &cal, fileName );
00175 }
00176
00177 void KOIncidenceEditor::slotLoadTemplate( const QString& templateName )
00178 {
00179 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId );
00180 QString fileName = locateLocal( "data", "korganizer/templates/" + type() + "/" +
00181 templateName );
00182
00183 if ( fileName.isEmpty() ) {
00184 KMessageBox::error( this, i18n("Unable to find template '%1'.")
00185 .arg( fileName ) );
00186 } else {
00187 ICalFormat format;
00188 if ( !format.load( &cal, fileName ) ) {
00189 KMessageBox::error( this, i18n("Error loading template file '%1'.")
00190 .arg( fileName ) );
00191 return;
00192 }
00193 }
00194 loadTemplate( cal );
00195 }
00196
00197 void KOIncidenceEditor::slotTemplatesChanged( const QStringList& newTemplates )
00198 {
00199 templates() = newTemplates;
00200 }
00201
00202 #include "koincidenceeditor.moc"
This file is part of the documentation for korganizer Library Version 3.3.2.