korganizer Library API Documentation

koeditorattachments.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 00023 */ 00024 00025 #include "koeditorattachments.h" 00026 00027 #include "urihandler.h" 00028 00029 #include <klocale.h> 00030 #include <kdebug.h> 00031 #include <kurlrequesterdlg.h> 00032 #include <kmessagebox.h> 00033 #include <libkcal/incidence.h> 00034 00035 #include <qlayout.h> 00036 #include <qlistview.h> 00037 #include <qpushbutton.h> 00038 00039 KOEditorAttachments::KOEditorAttachments( int spacing, QWidget *parent, 00040 const char *name ) 00041 : QWidget( parent, name ) 00042 { 00043 QBoxLayout *topLayout = new QVBoxLayout( this ); 00044 topLayout->setSpacing( spacing ); 00045 00046 mAttachments = new QListView( this ); 00047 mAttachments->addColumn( i18n("URI") ); 00048 mAttachments->addColumn( i18n("MIME Type") ); 00049 topLayout->addWidget( mAttachments ); 00050 connect( mAttachments, SIGNAL( doubleClicked( QListViewItem * ) ), 00051 SLOT( showAttachment( QListViewItem * ) ) ); 00052 00053 QBoxLayout *buttonLayout = new QHBoxLayout( topLayout ); 00054 00055 QPushButton *button = new QPushButton( i18n("Add..."), this ); 00056 buttonLayout->addWidget( button ); 00057 connect( button, SIGNAL( clicked() ), SLOT( slotAdd() ) ); 00058 00059 button = new QPushButton( i18n("Edit..."), this ); 00060 buttonLayout->addWidget( button ); 00061 connect( button, SIGNAL( clicked() ), SLOT( slotEdit() ) ); 00062 00063 button = new QPushButton( i18n("Remove"), this ); 00064 buttonLayout->addWidget( button ); 00065 connect( button, SIGNAL( clicked() ), SLOT( slotRemove() ) ); 00066 00067 button = new QPushButton( i18n("Show"), this ); 00068 buttonLayout->addWidget( button ); 00069 connect( button, SIGNAL( clicked() ), SLOT( slotShow() ) ); 00070 } 00071 00072 KOEditorAttachments::~KOEditorAttachments() 00073 { 00074 } 00075 00076 void KOEditorAttachments::showAttachment( QListViewItem *item ) 00077 { 00078 if ( !item ) return; 00079 00080 QString uri = item->text( 0 ); 00081 00082 UriHandler::process( uri ); 00083 } 00084 00085 void KOEditorAttachments::slotAdd() 00086 { 00087 KURL uri = KURLRequesterDlg::getURL( QString::null, 0, 00088 i18n("Add Attachment") ); 00089 if ( !uri.isEmpty() ) { 00090 new QListViewItem( mAttachments, uri.url() ); 00091 } 00092 } 00093 00094 void KOEditorAttachments::slotEdit() 00095 { 00096 QListViewItem *item = mAttachments->currentItem(); 00097 if ( !item ) return; 00098 00099 KURL uri = KURLRequesterDlg::getURL( item->text( 0 ), 0, 00100 i18n("Edit Attachment") ); 00101 00102 if ( !uri.isEmpty() ) item->setText( 0, uri.url() ); 00103 } 00104 00105 void KOEditorAttachments::slotRemove() 00106 { 00107 QListViewItem *item = mAttachments->currentItem(); 00108 if ( !item ) return; 00109 00110 if ( KMessageBox::warningContinueCancel(this, 00111 i18n("This item will be permanently deleted."), 00112 i18n("KOrganizer Confirmation"),KGuiItem(i18n("Delete"),"editdelete")) == KMessageBox::Continue ) 00113 delete item; 00114 } 00115 00116 void KOEditorAttachments::slotShow() 00117 { 00118 showAttachment( mAttachments->currentItem() ); 00119 } 00120 00121 void KOEditorAttachments::setDefaults() 00122 { 00123 mAttachments->clear(); 00124 } 00125 00126 void KOEditorAttachments::addAttachment( const QString &uri, 00127 const QString &mimeType ) 00128 { 00129 new QListViewItem( mAttachments, uri, mimeType ); 00130 } 00131 00132 void KOEditorAttachments::readIncidence( Incidence *i ) 00133 { 00134 mAttachments->clear(); 00135 00136 Attachment::List attachments = i->attachments(); 00137 Attachment::List::ConstIterator it; 00138 for( it = attachments.begin(); it != attachments.end(); ++it ) { 00139 QString uri; 00140 if ( (*it)->isUri() ) uri = (*it)->uri(); 00141 else uri = i18n("[Binary data]"); 00142 addAttachment( uri, (*it)->mimeType() ); 00143 } 00144 } 00145 00146 void KOEditorAttachments::writeIncidence( Incidence *i ) 00147 { 00148 i->clearAttachments(); 00149 00150 QListViewItem *item; 00151 for( item = mAttachments->firstChild(); item; item = item->nextSibling() ) { 00152 i->addAttachment( new Attachment( item->text( 0 ), item->text( 1 ) ) ); 00153 } 00154 } 00155 00156 #include "koeditorattachments.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:22 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003