koeditorattachments.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
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"
This file is part of the documentation for korganizer Library Version 3.3.2.