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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 00031 #include <kdebug.h> 00032 #include <klocale.h> 00033 #include <kstandarddirs.h> 00034 #include <kmessagebox.h> 00035 #include <kinputdialog.h> 00036 00037 #include <libkdepim/categoryselectdialog.h> 00038 00039 #include <libkcal/calendarlocal.h> 00040 #include <libkcal/icalformat.h> 00041 00042 #include "koprefs.h" 00043 #include "koglobals.h" 00044 #include "koeditordetails.h" 00045 #include "koeditorattachments.h" 00046 00047 #include "koincidenceeditor.h" 00048 00049 KOIncidenceEditor::KOIncidenceEditor( const QString &caption, 00050 Calendar *calendar, QWidget *parent ) 00051 : KDialogBase( Tabbed, caption, Ok | Apply | Cancel | Default | User1, Ok, 00052 parent, 0, false, false ), 00053 mDetails( 0 ), mAttachments( 0 ) 00054 { 00055 mCalendar = calendar; 00056 00057 setButtonText( Default, i18n("Load &Template...") ); 00058 00059 QString saveTemplateText; 00060 if ( KOPrefs::instance()->mCompactDialogs ) { 00061 showButton( User1, false ); 00062 showButton( Apply, false ); 00063 } else { 00064 saveTemplateText = i18n("&Save as Template..."); 00065 } 00066 setButtonText( User1, saveTemplateText ); 00067 00068 mCategoryDialog = new KPIM::CategorySelectDialog( KOPrefs::instance(), this ); 00069 KOGlobals::fitDialogToScreen( mCategoryDialog ); 00070 00071 connect( mCategoryDialog, SIGNAL( editCategories() ), 00072 SIGNAL( editCategories() ) ); 00073 00074 connect( this, SIGNAL( defaultClicked() ), SLOT( slotLoadTemplate() ) ); 00075 connect( this, SIGNAL( user1Clicked() ), SLOT( slotSaveTemplate() ) ); 00076 } 00077 00078 KOIncidenceEditor::~KOIncidenceEditor() 00079 { 00080 delete mCategoryDialog; 00081 } 00082 00083 void KOIncidenceEditor::setupAttendeesTab() 00084 { 00085 QFrame *topFrame = addPage( i18n("Atte&ndees") ); 00086 00087 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 00088 00089 mDetails = new KOEditorDetails( spacingHint(), topFrame ); 00090 topLayout->addWidget( mDetails ); 00091 } 00092 00093 void KOIncidenceEditor::setupAttachmentsTab() 00094 { 00095 QFrame *topFrame = addPage( i18n("Attachments") ); 00096 00097 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 00098 00099 mAttachments = new KOEditorAttachments( spacingHint(), topFrame ); 00100 topLayout->addWidget( mAttachments ); 00101 } 00102 00103 void KOIncidenceEditor::slotApply() 00104 { 00105 processInput(); 00106 } 00107 00108 void KOIncidenceEditor::slotOk() 00109 { 00110 if ( processInput() ) accept(); 00111 } 00112 00113 void KOIncidenceEditor::updateCategoryConfig() 00114 { 00115 mCategoryDialog->updateCategoryConfig(); 00116 } 00117 00118 void KOIncidenceEditor::slotCancel() 00119 { 00120 processCancel(); 00121 reject(); 00122 } 00123 00124 void KOIncidenceEditor::slotLoadTemplate() 00125 { 00126 kdDebug(5850) << "KOIncidenceEditor::loadTemplate()" << endl; 00127 } 00128 00129 void KOIncidenceEditor::slotSaveTemplate() 00130 { 00131 kdDebug(5850) << "KOIncidenceEditor::saveTemplate()" << endl; 00132 QString tp = type(); 00133 QStringList templates; 00134 if ( tp == "Event" ) { 00135 templates = KOPrefs::instance()->mEventTemplates; 00136 } else if( tp == "ToDo" ) { 00137 templates = KOPrefs::instance()->mTodoTemplates; 00138 } 00139 bool ok = false; 00140 QString templateName = KInputDialog::getItem( i18n("Save Template"), 00141 i18n("Please enter a name for the template:"), templates, 00142 -1, true, &ok, this ); 00143 if ( ok && templateName.isEmpty() ) { 00144 KMessageBox::error( this, i18n("You did not give a valid template name, " 00145 "no template will be saved") ); 00146 ok = false; 00147 } 00148 00149 if ( ok && templates.contains( templateName ) ) { 00150 int res = KMessageBox::warningYesNo( this, 00151 i18n("The selected template " 00152 "already exists. Overwrite it?"), 00153 i18n("Template already exists") ); 00154 if ( res == KMessageBox::No ) { 00155 ok = false; 00156 } 00157 } 00158 00159 if ( ok ) { 00160 saveTemplate( templateName ); 00161 00162 // Add template to list of existing templates 00163 if ( !templates.contains( templateName ) ) { 00164 templates.append( templateName ); 00165 if ( tp == "Event" ) { 00166 KOPrefs::instance()->mEventTemplates = templates; 00167 } else if( tp == "ToDo" ) { 00168 KOPrefs::instance()->mTodoTemplates = templates; 00169 } 00170 } 00171 00172 } 00173 } 00174 00175 void KOIncidenceEditor::saveAsTemplate( Incidence *incidence, 00176 const QString &templateName ) 00177 { 00178 if ( !incidence || templateName.isEmpty() ) return; 00179 00180 QString fileName = "templates/" + incidence->type(); 00181 fileName.append( "/" + templateName ); 00182 fileName = locateLocal( "data", "korganizer/" + fileName ); 00183 00184 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId ); 00185 cal.addIncidence( incidence ); 00186 ICalFormat format; 00187 format.save( &cal, fileName ); 00188 } 00189 00190 QString KOIncidenceEditor::loadTemplate( Calendar *cal, const QString &type, 00191 const QStringList &templates ) 00192 { 00193 bool ok = false; 00194 QString templateName = KInputDialog::getItem( i18n("Load Template"), 00195 i18n("Select a template to load:"), templates, 0, false, &ok, this ); 00196 00197 if ( !ok || templateName.isEmpty() ) return QString::null; 00198 00199 QString fileName = locateLocal( "data", "korganizer/templates/" + type + "/" + 00200 templateName ); 00201 00202 if ( fileName.isEmpty() ) { 00203 KMessageBox::error( this, i18n("Unable to find template '%1'.") 00204 .arg( fileName ) ); 00205 return QString::null; 00206 } else { 00207 ICalFormat format; 00208 if ( !format.load( cal, fileName ) ) { 00209 KMessageBox::error( this, i18n("Error loading template file '%1'.") 00210 .arg( fileName ) ); 00211 return QString::null; 00212 } 00213 } 00214 00215 return templateName; 00216 } 00217 00218 #include "koincidenceeditor.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:13 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003