korganizer Library API Documentation

koincidenceeditor.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., 675 Mass Ave, Cambridge, MA 02139, 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 <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 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:09 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001