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 "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"),i18n("Delete")) == 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"
This file is part of the documentation for korganizer Library Version 3.2.2.