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 "kocore.h" 00028 #include "urihandler.h" 00029 00030 #include <klocale.h> 00031 #include <kdebug.h> 00032 #include <kinputdialog.h> 00033 #include <kmessagebox.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 QString uri = KInputDialog::getText( i18n("Add Attachment"), 00088 i18n("Please put in URI of attachment:"), 00089 QString::null, 0, this ); 00090 if ( !uri.isEmpty() ) { 00091 new QListViewItem( mAttachments, uri ); 00092 } 00093 } 00094 00095 void KOEditorAttachments::slotEdit() 00096 { 00097 QListViewItem *item = mAttachments->currentItem(); 00098 if ( !item ) return; 00099 00100 QString uri = KInputDialog::getText( i18n("Edit Attachment"), 00101 i18n("Please put in URI of attachment:"), 00102 item->text( 0 ), 0, this ); 00103 00104 if ( !uri.isEmpty() ) item->setText( 0, uri ); 00105 } 00106 00107 void KOEditorAttachments::slotRemove() 00108 { 00109 QListViewItem *item = mAttachments->currentItem(); 00110 if ( !item ) return; 00111 00112 if ( KMessageBox::warningContinueCancel(this, 00113 i18n("This item will be permanently deleted."), 00114 i18n("KOrganizer Confirmation"),KGuiItem(i18n("Delete"),"editdelete")) == KMessageBox::Continue ) 00115 delete item; 00116 } 00117 00118 void KOEditorAttachments::slotShow() 00119 { 00120 showAttachment( mAttachments->currentItem() ); 00121 } 00122 00123 void KOEditorAttachments::setDefaults() 00124 { 00125 mAttachments->clear(); 00126 } 00127 00128 void KOEditorAttachments::addAttachment( const QString &uri, 00129 const QString &mimeType ) 00130 { 00131 new QListViewItem( mAttachments, uri, mimeType ); 00132 } 00133 00134 void KOEditorAttachments::readIncidence( Incidence *i ) 00135 { 00136 mAttachments->clear(); 00137 00138 Attachment::List attachments = i->attachments(); 00139 Attachment::List::ConstIterator it; 00140 for( it = attachments.begin(); it != attachments.end(); ++it ) { 00141 QString uri; 00142 if ( (*it)->isUri() ) uri = (*it)->uri(); 00143 else uri = i18n("[Binary data]"); 00144 addAttachment( uri, (*it)->mimeType() ); 00145 } 00146 } 00147 00148 void KOEditorAttachments::writeIncidence( Incidence *i ) 00149 { 00150 i->clearAttachments(); 00151 00152 QListViewItem *item; 00153 for( item = mAttachments->firstChild(); item; item = item->nextSibling() ) { 00154 i->addAttachment( new Attachment( item->text( 0 ), item->text( 1 ) ) ); 00155 } 00156 } 00157 00158 #include "koeditorattachments.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