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 #include <qtooltip.h>
00025 #include <qframe.h>
00026 #include <qpixmap.h>
00027 #include <qlayout.h>
00028 #include <qwidgetstack.h>
00029 #include <qdatetime.h>
00030 #include <qinputdialog.h>
00031
00032 #include <kdebug.h>
00033 #include <klocale.h>
00034 #include <kstandarddirs.h>
00035 #include <kmessagebox.h>
00036
00037 #include <libkdepim/categoryselectdialog.h>
00038 #include <libkcal/calendarlocal.h>
00039 #include <libkcal/icalformat.h>
00040
00041 #include "koprefs.h"
00042
00043 #include "koincidenceeditor.h"
00044 #include "koincidenceeditor.moc"
00045
00046 KOIncidenceEditor::KOIncidenceEditor( const QString &caption,
00047 Calendar *calendar, QWidget *parent ) :
00048 KDialogBase( Tabbed, caption, Ok | Apply | Cancel | Default | User1, Ok,
00049 parent, 0, false, false, i18n("Save as Template...") ),
00050 mSaveTemplateDialog( 0 )
00051 {
00052 mCalendar = calendar;
00053
00054 setButtonText( Default, i18n("Template...") );
00055
00056 mCategoryDialog = new KPIM::CategorySelectDialog( KOPrefs::instance(), this );
00057
00058 connect(mCategoryDialog,SIGNAL(editCategories()),SIGNAL(editCategories()));
00059
00060 connect( this, SIGNAL( defaultClicked() ), SLOT( slotLoadTemplate() ) );
00061 connect( this, SIGNAL( user1Clicked() ), SLOT( slotSaveTemplate() ) );
00062 }
00063
00064 KOIncidenceEditor::~KOIncidenceEditor()
00065 {
00066 delete mCategoryDialog;
00067 }
00068
00069 void KOIncidenceEditor::setupAttendeesTab()
00070 {
00071 QFrame *topFrame = addPage(i18n("Attendees"));
00072
00073 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00074
00075 mDetails = new KOEditorDetails(spacingHint(),topFrame);
00076 topLayout->addWidget(mDetails);
00077 }
00078
00079 void KOIncidenceEditor::slotApply()
00080 {
00081 processInput();
00082 }
00083
00084 void KOIncidenceEditor::slotOk()
00085 {
00086 if ( processInput() ) accept();
00087 }
00088
00089 void KOIncidenceEditor::updateCategoryConfig()
00090 {
00091 mCategoryDialog->updateCategoryConfig();
00092 }
00093
00094 void KOIncidenceEditor::slotCancel()
00095 {
00096 reject();
00097 }
00098
00099 void KOIncidenceEditor::slotLoadTemplate()
00100 {
00101 kdDebug() << "KOIncidenceEditor::loadTemplate()" << endl;
00102 }
00103
00104 void KOIncidenceEditor::slotSaveTemplate()
00105 {
00106 kdDebug() << "KOIncidenceEditor::saveTemplate()" << endl;
00107 }
00108
00109 void KOIncidenceEditor::createSaveTemplateDialog( SaveTemplateDialog::IncidenceType type )
00110 {
00111 if ( !mSaveTemplateDialog ) {
00112 mSaveTemplateDialog = new SaveTemplateDialog( type, this );
00113 connect( mSaveTemplateDialog, SIGNAL( templateSelected( const QString & ) ),
00114 SLOT( saveTemplate( const QString & ) ) );
00115 }
00116 mSaveTemplateDialog->show();
00117 mSaveTemplateDialog->raise();
00118 }
00119
00120 void KOIncidenceEditor::saveAsTemplate( Incidence *incidence,
00121 const QString &templateName )
00122 {
00123 if ( !incidence || templateName.isEmpty() ) return;
00124
00125 QString fileName = "templates/" + incidence->type();
00126 fileName.append( "/" + templateName );
00127 fileName = locateLocal( "appdata", fileName );
00128
00129 CalendarLocal cal;
00130 cal.addIncidence( incidence );
00131 ICalFormat format;
00132 format.save( &cal, fileName );
00133 }
00134
00135 QString KOIncidenceEditor::loadTemplate( Calendar *cal, const QString &type,
00136 const QStringList &templates )
00137 {
00138 bool ok = false;
00139 QString templateName = QInputDialog::getItem( i18n("Load Template"),
00140 i18n("Select a template to load:"), templates, 0, false, &ok );
00141 if ( !ok || templateName.isEmpty() ) return QString::null;
00142
00143 QString fileName = locateLocal( "appdata", "templates/" + type + "/" +
00144 templateName );
00145
00146 if ( fileName.isEmpty() ) {
00147 KMessageBox::error( this, i18n("Unable to find template '%1'.")
00148 .arg( fileName ) );
00149 return QString::null;
00150 } else {
00151 ICalFormat format;
00152 if ( !format.load( cal, fileName ) ) {
00153 KMessageBox::error( this, i18n("Error loading template file '%1'.")
00154 .arg( fileName ) );
00155 return QString::null;
00156 }
00157 }
00158
00159 return templateName;
00160 }
This file is part of the documentation for kdelibs Version 3.1.4.