26#include "koeditorattachments.h"
29#include <libkcal/incidence.h>
30#include <libtdepim/kpimurlrequesterdlg.h>
31#include <libtdepim/tdefileio.h>
32#include <libtdepim/tdepimprotocols.h>
33#include <libtdepim/maillistdrag.h>
34#include <libtdepim/kvcarddrag.h>
35#include <libtdepim/tdepimprotocols.h>
40#include <tdemessagebox.h>
43#include <tdetempfile.h>
45#include <tdeio/netaccess.h>
47#include <kiconloader.h>
48#include <tdefiledialog.h>
49#include <kstdaction.h>
50#include <tdeactioncollection.h>
51#include <tdepopupmenu.h>
52#include <kprotocolinfo.h>
54#include <kseparator.h>
55#include <kurlrequester.h>
56#include <libkmime/kmime_message.h>
58#include <tqcheckbox.h>
62#include <tqlistview.h>
63#include <tqpushbutton.h>
64#include <tqdragobject.h>
66#include <tqwhatsthis.h>
67#include <tqapplication.h>
68#include <tqclipboard.h>
73class AttachmentListItem :
public TDEIconViewItem
77 TDEIconViewItem( parent )
85 setDragEnabled(
true );
87 ~AttachmentListItem() {
delete mAttachment; }
90 const TQString uri()
const
92 return mAttachment->uri();
94 void setUri(
const TQString &uri )
96 mAttachment->setUri( uri );
99 void setData(
const TQByteArray data )
101 mAttachment->setDecodedData( data );
104 const TQString mimeType()
const
106 return mAttachment->mimeType();
108 void setMimeType(
const TQString &mime )
110 mAttachment->setMimeType( mime );
113 const TQString label()
const
115 return mAttachment->label();
117 void setLabel(
const TQString &label )
119 mAttachment->setLabel( label );
122 bool isBinary()
const
124 return mAttachment->isBinary();
126 TQPixmap icon()
const
128 return icon( KMimeType::mimeType( mAttachment->mimeType() ),
129 mAttachment->uri() );
131 static TQPixmap icon( KMimeType::Ptr mimeType,
const TQString &uri )
133 TQString iconStr = mimeType->icon( uri,
false );
134 return TDEGlobal::iconLoader()->loadIcon( iconStr, TDEIcon::Small );
136 void readAttachment()
138 if ( mAttachment->label().isEmpty() ) {
139 if ( mAttachment->isUri() ) {
140 setText( mAttachment->uri() );
142 setText( i18n(
"[Binary data]" ) );
145 setText( mAttachment->label() );
147 if ( mAttachment->mimeType().isEmpty() ||
148 !( KMimeType::mimeType( mAttachment->mimeType() ) ) ) {
149 KMimeType::Ptr mimeType;
150 if ( mAttachment->isUri() ) {
151 mimeType = KMimeType::findByURL( mAttachment->uri() );
153 mimeType = KMimeType::findByContent( mAttachment->decodedData() );
155 mAttachment->setMimeType( mimeType->name() );
165AttachmentEditDialog::AttachmentEditDialog( AttachmentListItem *item,
167 : KDialogBase ( Plain, i18n(
"Add Attachment" ), Ok|Cancel, Ok, parent, 0, false, false ),
168 mItem( item ), mURLRequester( 0 )
170 TQFrame *topFrame = plainPage();
171 TQVBoxLayout *vbl =
new TQVBoxLayout( topFrame, 0, spacingHint() );
173 TQGridLayout *grid =
new TQGridLayout();
174 grid->setColStretch( 0, 0 );
175 grid->setColStretch( 1, 0 );
176 grid->setColStretch( 2, 1 );
177 vbl->addLayout( grid );
179 mIcon =
new TQLabel( topFrame );
180 mIcon->setPixmap( item->icon() );
181 grid->addWidget( mIcon, 0, 0 );
183 mLabelEdit =
new KLineEdit( topFrame );
184 mLabelEdit->setText( item->label().isEmpty() ? item->uri() : item->label() );
185 mLabelEdit->setClickMessage( i18n(
"Attachment name" ) );
186 TQToolTip::add( mLabelEdit, i18n(
"Give the attachment a name" ) );
187 TQWhatsThis::add( mLabelEdit,
188 i18n(
"Type any string you desire here for the name of the attachment" ) );
189 grid->addMultiCellWidget( mLabelEdit, 0, 0, 1, 2 );
191 KSeparator *sep =
new KSeparator( TQt::Horizontal, topFrame );
192 grid->addMultiCellWidget( sep, 1, 1, 0, 2 );
194 TQLabel *label =
new TQLabel( i18n(
"Type:" ), topFrame );
195 grid->addWidget( label, 2, 0 );
196 TQString typecomment = item->mimeType().isEmpty() ?
198 KMimeType::mimeType( item->mimeType() )->comment();
199 mTypeLabel =
new TQLabel( typecomment, topFrame );
200 grid->addWidget( mTypeLabel, 2, 1 );
201 mMimeType = KMimeType::mimeType( item->mimeType() );
203 mInline =
new TQCheckBox( i18n(
"Store attachment inline" ), topFrame );
204 grid->addMultiCellWidget( mInline, 3, 3, 0, 2 );
205 mInline->setChecked( item->isBinary() || item->label().isEmpty() );
206 TQToolTip::add( mInline, i18n(
"Store the attachment file inside the calendar" ) );
209 i18n(
"Checking this option will cause the attachment to be stored inside "
210 "your calendar, which can take a lot of space depending on the size "
211 "of the attachment. If this option is not checked, then only a link "
212 "pointing to the attachment will be stored. Do not use a link for "
213 "attachments that change often or may be moved (or removed) from "
214 "their current location." ) );
216 if ( item->attachment()->isUri() || item->label().isEmpty() || !item->attachment()->data() ) {
217 label =
new TQLabel( i18n(
"Location:" ), topFrame );
218 grid->addWidget( label, 4, 0 );
219 mURLRequester =
new KURLRequester( item->uri(), topFrame );
220 TQToolTip::add( mURLRequester, i18n(
"Provide a location for the attachment file" ) );
223 i18n(
"Enter the path to the attachment file or use the "
224 "file browser by pressing the adjacent button" ) );
225 grid->addMultiCellWidget( mURLRequester, 4, 4, 1, 2 );
226 connect( mURLRequester, TQ_SIGNAL(urlSelected(
const TQString &)),
227 TQ_SLOT(urlSelected(
const TQString &)) );
228 connect( mURLRequester, TQ_SIGNAL( textChanged(
const TQString& ) ),
229 TQ_SLOT( urlChanged(
const TQString& ) ) );
230 urlChanged( item->uri() );
232 uint size = item->attachment()->size();
233 grid->addWidget(
new TQLabel( i18n(
"Size:" ), topFrame ), 4, 0 );
234 grid->addWidget(
new TQLabel( TQString::fromLatin1(
"%1 (%2)" ).
235 arg( TDEIO::convertSize( size ) ).
236 arg( TDEGlobal::locale()->formatNumber(
237 size, 0 ) ), topFrame ), 4, 2 );
239 vbl->addStretch( 10 );
242void AttachmentEditDialog::slotApply()
244 if ( !mLabelEdit->text().isEmpty() ) {
245 mItem->setLabel( mLabelEdit->text() );
246 }
else if ( mURLRequester && !mURLRequester->url().isEmpty() ) {
247 KURL url = KURL::fromPathOrURL( mURLRequester->url() );
248 mItem->setLabel( url.isLocalFile() ? url.fileName() : url.url() );
250 mItem->setLabel( i18n(
"New attachment" ) );
252 mItem->setMimeType( mMimeType->name() );
253 if ( mURLRequester ) {
254 KURL url = KURL::fromPathOrURL( mURLRequester->url() );
256 TQString correctedUrl = mURLRequester->url();
257 if ( !url.isValid() ) {
263 correctedUrl = TQDir::home().filePath( mURLRequester->url() );
264 url = KURL::fromPathOrURL( correctedUrl );
265 if ( url.isValid() ) {
266 urlSelected( correctedUrl );
267 mItem->setMimeType( mMimeType->name() );
271 if ( mInline->isChecked() ) {
273 if ( TDEIO::NetAccess::download( url, tmpFile,
this ) ) {
275 if ( !f.open( IO_ReadOnly ) ) {
278 TQByteArray data = f.readAll();
280 mItem->setData( data );
282 TDEIO::NetAccess::removeTempFile( tmpFile );
284 mItem->setUri( url.url() );
289void AttachmentEditDialog::accept()
295void AttachmentEditDialog::urlChanged(
const TQString &url )
297 enableButton( Ok, !url.isEmpty() );
300void AttachmentEditDialog::urlSelected(
const TQString &url )
302 KURL kurl = KURL::fromPathOrURL( url );
303 mMimeType = KMimeType::findByURL( kurl );
304 mTypeLabel->setText( mMimeType->comment() );
305 mIcon->setPixmap( AttachmentListItem::icon( mMimeType, kurl.path() ) );
308AttachmentIconView::AttachmentIconView( KOEditorAttachments* parent )
309 : TDEIconView( parent ),
312 setSelectionMode( TQIconView::Extended );
313 setMode( TDEIconView::Select );
314 setItemTextPos( TQIconView::Right );
315 setArrangement( TQIconView::LeftToRight );
316 setMaxItemWidth( TQMAX(maxItemWidth(), 250) );
317 setMinimumHeight( TQMAX(fontMetrics().height(), 16) + 12 );
319 connect(
this, TQ_SIGNAL( dropped ( TQDropEvent *,
const TQValueList<TQIconDragItem> & ) ),
320 this, TQ_SLOT( handleDrop( TQDropEvent *,
const TQValueList<TQIconDragItem> & ) ) );
323KURL AttachmentIconView::tempFileForAttachment(
KCal::Attachment *attachment )
325 if ( mTempFiles.contains( attachment ) ) {
326 return mTempFiles[attachment];
328 TQStringList patterns = KMimeType::mimeType( attachment->mimeType() )->patterns();
331 if ( !patterns.empty() ) {
332 file =
new KTempFile( TQString(),
333 TQString( patterns.first() ).remove(
'*' ),0600 );
335 file =
new KTempFile( TQString(), TQString(), 0600 );
337 file->setAutoDelete(
true );
338 file->file()->open( IO_WriteOnly );
339 TQTextStream stream( file->file() );
340 stream.writeRawBytes( attachment->decodedData().data(), attachment->size() );
341 KURL url( file->name() );
342 mTempFiles.insert( attachment, url );
344 return mTempFiles[attachment];
347TQDragObject *AttachmentIconView::mimeData()
352 for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() ) {
353 if ( it->isSelected() ) {
354 AttachmentListItem *item =
static_cast<AttachmentListItem *
>( it );
355 if ( item->isBinary() ) {
356 urls.append( tempFileForAttachment( item->attachment() ) );
358 urls.append( item->uri() );
360 labels.append( KURL::encode_string( item->label() ) );
363 if ( selectionMode() == TQIconView::NoSelection ) {
364 AttachmentListItem *item =
static_cast<AttachmentListItem *
>( currentItem() );
366 urls.append( item->uri() );
367 labels.append( KURL::encode_string( item->label() ) );
371 TQMap<TQString, TQString> metadata;
372 metadata[
"labels"] = labels.join(
":" );
374 KURLDrag *drag =
new KURLDrag( urls, metadata );
378AttachmentIconView::~AttachmentIconView()
380 for ( std::set<KTempDir*>::iterator it = mTempDirs.begin() ; it != mTempDirs.end() ; ++it ) {
385TQDragObject * AttachmentIconView::dragObject()
388 for ( TQIconViewItem *it = firstItem( ); it; it = it->nextItem( ) ) {
389 if ( !it->isSelected() )
continue;
390 AttachmentListItem * item =
dynamic_cast<AttachmentListItem*
>( it );
391 if ( !item )
return 0;
395 if ( att->isUri() ) {
396 url.setPath( att->uri() );
398 KTempDir *tempDir =
new KTempDir();
399 tempDir->setAutoDelete(
true );
400 mTempDirs.insert( tempDir );
402 encoded.duplicate( att->data(), strlen( att->data() ) );
404 KCodecs::base64Decode( encoded, decoded );
405 const TQString fileName = tempDir->name( ) +
'/' + att->label();
406 KPIM::kByteArrayToFile( decoded, fileName,
false,
false,
false );
407 url.setPath( fileName );
411 KURLDrag *drag =
new KURLDrag( urls,
this );
415void AttachmentIconView::handleDrop( TQDropEvent *event,
const TQValueList<TQIconDragItem> & list )
418 mParent->handlePasteOrDrop( event );
422void AttachmentIconView::dragMoveEvent( TQDragMoveEvent *event )
424 mParent->dragMoveEvent( event );
427void AttachmentIconView::contentsDragMoveEvent( TQDragMoveEvent *event )
429 mParent->dragMoveEvent( event );
432void AttachmentIconView::contentsDragEnterEvent( TQDragEnterEvent *event )
434 mParent->dragMoveEvent( event );
437void AttachmentIconView::dragEnterEvent( TQDragEnterEvent *event )
439 mParent->dragEnterEvent( event );
442KOEditorAttachments::KOEditorAttachments(
int spacing, TQWidget *parent,
444 : TQWidget( parent, name )
446 TQBoxLayout *topLayout =
new TQHBoxLayout(
this );
447 topLayout->setSpacing( spacing );
449 TQLabel *label =
new TQLabel( i18n(
"Attachments:"),
this );
450 topLayout->addWidget( label );
452 mAttachments =
new AttachmentIconView(
this );
453 TQWhatsThis::add( mAttachments,
454 i18n(
"Displays a list of current items (files, mail, etc.) "
455 "that have been associated with this event or to-do. ") );
456 topLayout->addWidget( mAttachments );
457 connect( mAttachments, TQ_SIGNAL( doubleClicked( TQIconViewItem * ) ),
458 TQ_SLOT( showAttachment( TQIconViewItem * ) ) );
459 connect( mAttachments, TQ_SIGNAL(selectionChanged()),
460 TQ_SLOT(selectionChanged()) );
461 connect( mAttachments, TQ_SIGNAL(contextMenuRequested(TQIconViewItem*,
const TQPoint&)),
462 TQ_SLOT(contextMenu(TQIconViewItem*,
const TQPoint&)) );
464 TQPushButton *addButton =
new TQPushButton(
this );
465 addButton->setIconSet( SmallIconSet(
"add" ) );
466 TQToolTip::add( addButton, i18n(
"Add an attachment" ) );
467 TQWhatsThis::add( addButton,
468 i18n(
"Shows a dialog used to select an attachment "
469 "to add to this event or to-do as link or as "
471 topLayout->addWidget( addButton );
472 connect( addButton, TQ_SIGNAL(clicked()), TQ_SLOT(slotAdd()) );
474 mRemoveBtn =
new TQPushButton(
this );
475 mRemoveBtn->setIconSet( SmallIconSet(
"remove" ) );
476 TQToolTip::add( mRemoveBtn, i18n(
"&Remove") );
477 TQWhatsThis::add( mRemoveBtn,
478 i18n(
"Removes the attachment selected in the list above "
479 "from this event or to-do.") );
480 topLayout->addWidget( mRemoveBtn );
481 connect( mRemoveBtn, TQ_SIGNAL(clicked()), TQ_SLOT(slotRemove()) );
483 mContextMenu =
new TDEPopupMenu(
this );
485 TDEActionCollection* ac =
new TDEActionCollection(
this,
this );
487 mOpenAction =
new TDEAction( i18n(
"Open"), 0,
this, TQ_SLOT(slotShow()), ac );
488 mOpenAction->plug( mContextMenu );
490 mSaveAsAction =
new TDEAction( i18n(
"Save As..." ), 0,
this, TQ_SLOT(slotSaveAs()), ac );
491 mSaveAsAction->plug( mContextMenu );
492 mContextMenu->insertSeparator();
494 mCopyAction = KStdAction::copy(
this, TQ_SLOT(slotCopy()), ac );
495 mCopyAction->plug( mContextMenu );
496 mCutAction = KStdAction::cut(
this, TQ_SLOT(slotCut()), ac );
497 mCutAction->plug( mContextMenu );
498 TDEAction *action = KStdAction::paste(
this, TQ_SLOT(slotPaste()), ac );
499 action->plug( mContextMenu );
500 mContextMenu->insertSeparator();
502 mDeleteAction =
new TDEAction( i18n(
"&Remove" ), 0,
this, TQ_SLOT(slotRemove()), ac );
503 mDeleteAction->plug( mContextMenu );
504 mDeleteAction->setShortcut( Key_Delete );
505 mContextMenu->insertSeparator();
507 mEditAction =
new TDEAction( i18n(
"&Properties..." ), 0,
this, TQ_SLOT(slotEdit()), ac );
508 mEditAction->plug( mContextMenu );
511 setAcceptDrops(
true );
514KOEditorAttachments::~KOEditorAttachments()
518bool KOEditorAttachments::hasAttachments()
520 return mAttachments->count() != 0;
523void KOEditorAttachments::dragMoveEvent( TQDragMoveEvent *event )
525 event->accept( KURLDrag::canDecode( event ) ||
526 TQTextDrag::canDecode( event ) ||
527 KPIM::MailListDrag::canDecode( event ) ||
528 KVCardDrag::canDecode( event ) );
531void KOEditorAttachments::dragEnterEvent( TQDragEnterEvent* event )
533 dragMoveEvent( event );
536void KOEditorAttachments::handlePasteOrDrop( TQMimeSource* source )
539 bool probablyWeHaveUris =
false;
540 bool weCanCopy =
true;
543 if ( KVCardDrag::canDecode( source ) ) {
544 TDEABC::Addressee::List addressees;
545 KVCardDrag::decode( source, addressees );
546 for ( TDEABC::Addressee::List::ConstIterator it = addressees.constBegin();
547 it != addressees.constEnd(); ++it ) {
548 urls.append( TDEPIMPROTOCOL_CONTACT + ( *it ).uid() );
550 labels.append( TQString::fromUtf8( ( *it ).realName().latin1() ) );
552 probablyWeHaveUris =
true;
553 }
else if ( KURLDrag::canDecode( source ) ) {
554 TQMap<TQString,TQString> metadata;
555 if ( KURLDrag::decode( source, urls, metadata ) ) {
556 probablyWeHaveUris =
true;
557 labels = TQStringList::split(
':', metadata[
"labels"],
false );
558 for ( TQStringList::Iterator it = labels.begin(); it != labels.end(); ++it ) {
559 *it = KURL::decode_string( (*it).latin1() );
563 }
else if ( TQTextDrag::canDecode( source ) ) {
565 TQTextDrag::decode( source, text );
566 TQStringList lst = TQStringList::split(
'\n', text,
false );
567 for ( TQStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it ) {
569 labels.append( TQString() );
571 probablyWeHaveUris =
true;
576 if ( probablyWeHaveUris ) {
577 menu.insertItem( i18n(
"&Link here" ), DRAG_LINK, items++ );
579 for ( KURL::List::ConstIterator it = urls.constBegin(); it != urls.constEnd(); ++it ) {
580 if ( !( weCanCopy = KProtocolInfo::supportsReading( *it ) ) ) {
585 menu.insertItem( SmallIcon(
"edit-copy" ), i18n(
"&Copy Here" ), DRAG_COPY, items++ );
588 menu.insertItem( SmallIcon(
"edit-copy" ), i18n(
"&Copy Here" ), DRAG_COPY, items++ );
591 menu.insertSeparator();
593 menu.insertItem( SmallIcon(
"cancel" ), i18n(
"C&ancel" ), DRAG_CANCEL, items );
594 int action = menu.exec( TQCursor::pos(), 0 );
596 if ( action == DRAG_LINK ) {
597 TQStringList::ConstIterator jt = labels.constBegin();
598 for ( KURL::List::ConstIterator it = urls.constBegin();
599 it != urls.constEnd(); ++it ) {
600 TQString label = (*jt++);
601 if ( mAttachments->findItem( label ) ) {
602 label +=
'~' + randomString( 3 );
604 addUriAttachment( (*it).url(), TQString(), label,
true );
606 }
else if ( action != DRAG_CANCEL ) {
607 if ( probablyWeHaveUris ) {
608 for ( KURL::List::ConstIterator it = urls.constBegin();
609 it != urls.constEnd(); ++it ) {
610 TQString label = (*it).fileName();
611 if ( label.isEmpty() ) {
612 label = (*it).prettyURL();
614 if ( mAttachments->findItem( label ) ) {
615 label +=
'~' + randomString( 3 );
617 addUriAttachment( (*it).url(), TQString(), label,
true );
620 addDataAttachment( source->encodedData( source->format() ),
622 KMimeType::mimeType( source->format() )->name() );
627void KOEditorAttachments::dropEvent( TQDropEvent* event )
629 handlePasteOrDrop( event );
632void KOEditorAttachments::showAttachment( TQIconViewItem *item )
634 AttachmentListItem *attitem =
static_cast<AttachmentListItem*
>(item);
635 if ( !attitem || !attitem->attachment() )
return;
641void KOEditorAttachments::saveAttachment( TQIconViewItem *item )
643 AttachmentListItem *attitem =
static_cast<AttachmentListItem*
>(item);
644 if ( !attitem || !attitem->attachment() )
return;
650void KOEditorAttachments::slotAdd()
652 AttachmentListItem *item =
new AttachmentListItem( 0, mAttachments );
654 AttachmentEditDialog *dlg =
new AttachmentEditDialog( item, mAttachments )
656 if ( dlg->exec() == KDialog::Rejected ) {
662void KOEditorAttachments::slotAddData()
664 KURL uri = KFileDialog::getOpenFileName( TQString(), TQString(),
this, i18n(
"Add Attachment") );
665 if ( !uri.isEmpty() ) {
666 TQString label = uri.fileName();
667 if ( label.isEmpty() ) {
668 label = uri.prettyURL();
670 addUriAttachment( uri.url(), TQString(), label,
true );
674void KOEditorAttachments::slotEdit()
676 for ( TQIconViewItem *item = mAttachments->firstItem(); item; item = item->nextItem() ) {
677 if ( item->isSelected() ) {
678 AttachmentListItem *attitem =
static_cast<AttachmentListItem*
>( item );
679 if ( !attitem || !attitem->attachment() ) {
683 AttachmentEditDialog *dialog =
new AttachmentEditDialog( attitem, mAttachments );
684 dialog->mInline->setEnabled(
false );
685 dialog->setModal(
false );
686 connect( dialog, TQ_SIGNAL(hidden()), dialog, TQ_SLOT(delayedDestruct()) );
692void KOEditorAttachments::slotRemove()
694 TQValueList<TQIconViewItem*> selected;
696 for ( TQIconViewItem *it = mAttachments->firstItem( ); it; it = it->nextItem( ) ) {
697 if ( !it->isSelected() )
continue;
700 AttachmentListItem *attitem =
static_cast<AttachmentListItem*
>(it);
702 labels << att->label();
705 if ( selected.isEmpty() ) {
709 TQString labelsStr = labels.join(
"<br>" );
711 if ( KMessageBox::questionYesNo(
713 i18n(
"<qt>Do you really want to remove these attachments?<p>%1</qt>" ).arg( labelsStr ),
714 i18n(
"Remove Attachment?" ),
715 KStdGuiItem::yes(), KStdGuiItem::no(),
716 "calendarRemoveAttachments" ) != KMessageBox::Yes ) {
720 for ( TQValueList<TQIconViewItem*>::iterator it( selected.begin() ), end( selected.end() );
722 if ( (*it)->nextItem() ) {
723 (*it)->nextItem()->setSelected(
true );
724 }
else if ( (*it)->prevItem() ) {
725 (*it)->prevItem()->setSelected(
true );
729 mAttachments->slotUpdate();
732void KOEditorAttachments::slotShow()
734 for ( TQIconViewItem *it = mAttachments->firstItem(); it; it = it->nextItem() ) {
735 if ( !it->isSelected() )
737 showAttachment( it );
741void KOEditorAttachments::slotSaveAs()
743 for ( TQIconViewItem *it = mAttachments->firstItem(); it; it = it->nextItem() ) {
744 if ( !it->isSelected() )
746 saveAttachment( it );
750void KOEditorAttachments::setDefaults()
752 mAttachments->clear();
755TQString KOEditorAttachments::randomString(
int length)
const
757 if (length <=0 )
return TQString();
759 TQString str; str.setLength( length );
773void KOEditorAttachments::addUriAttachment(
const TQString &uri,
774 const TQString &mimeType,
775 const TQString &label,
779 AttachmentListItem *item =
new AttachmentListItem( 0, mAttachments );
781 item->setLabel( label );
782 if ( mimeType.isEmpty() ) {
783 if ( uri.startsWith( TDEPIMPROTOCOL_CONTACT ) ) {
784 item->setMimeType(
"text/directory" );
785 }
else if ( uri.startsWith( TDEPIMPROTOCOL_EMAIL ) ) {
786 item->setMimeType(
"message/rfc822" );
787 }
else if ( uri.startsWith( TDEPIMPROTOCOL_INCIDENCE ) ) {
788 item->setMimeType(
"text/calendar" );
789 }
else if ( uri.startsWith( TDEPIMPROTOCOL_NEWSARTICLE ) ) {
790 item->setMimeType(
"message/news" );
792 item->setMimeType( KMimeType::findByURL( uri )->name() );
797 if ( TDEIO::NetAccess::download( uri, tmpFile,
this ) ) {
799 if ( !f.open( IO_ReadOnly ) ) {
802 const TQByteArray data = f.readAll();
804 addDataAttachment( data, mimeType, label );
806 TDEIO::NetAccess::removeTempFile( tmpFile );
810void KOEditorAttachments::addDataAttachment(
const TQByteArray &data,
811 const TQString &mimeType,
812 const TQString &label )
814 AttachmentListItem *item =
new AttachmentListItem( 0, mAttachments );
816 TQString nlabel = label;
817 if ( mimeType ==
"message/rfc822" ) {
820 msg.setContent( data.data() );
822 nlabel = msg.subject()->asUnicodeString();
825 item->setData( data );
826 item->setLabel( nlabel );
827 if ( mimeType.isEmpty() ) {
828 item->setMimeType( KMimeType::findByContent( data )->name() );
830 item->setMimeType( mimeType );
836 new AttachmentListItem( attachment, mAttachments );
841 mAttachments->clear();
843 KCal::Attachment::List attachments = i->
attachments();
844 KCal::Attachment::List::ConstIterator it;
845 for( it = attachments.begin(); it != attachments.end(); ++it ) {
846 addAttachment( (*it) );
848 if ( mAttachments->count() > 0 ) {
849 TQTimer::singleShot( 0, mAttachments, TQ_SLOT(arrangeItemsInGrid()) );
857 TQIconViewItem *item;
858 AttachmentListItem *attitem;
859 for( item = mAttachments->firstItem(); item; item = item->nextItem() ) {
860 attitem =
static_cast<AttachmentListItem*
>(item);
867void KOEditorAttachments::slotCopy()
869 TQApplication::clipboard()->setData( mAttachments->mimeData(), TQClipboard::Clipboard );
872void KOEditorAttachments::slotCut()
878void KOEditorAttachments::slotPaste()
880 handlePasteOrDrop( TQApplication::clipboard()->data() );
883void KOEditorAttachments::selectionChanged()
885 bool selected =
false;
886 for ( TQIconViewItem *item = mAttachments->firstItem(); item; item = item->nextItem() ) {
887 if ( item->isSelected() ) {
892 mRemoveBtn->setEnabled( selected );
895void KOEditorAttachments::contextMenu(TQIconViewItem * item,
const TQPoint & pos)
897 const bool enable = item != 0;
900 for ( TQIconViewItem *item = mAttachments->firstItem(); item; item = item->nextItem() ) {
901 if ( item->isSelected() ) {
906 mOpenAction->setEnabled( enable );
908 mSaveAsAction->setEnabled( enable && numSelected == 1 );
909 mCopyAction->setEnabled( enable && numSelected == 1 );
910 mCutAction->setEnabled( enable && numSelected == 1 );
911 mDeleteAction->setEnabled( enable );
912 mEditAction->setEnabled( enable );
913 mContextMenu->exec( pos );
916#include "koeditorattachments.moc"
void addAttachment(Attachment *attachment)
Attachment::List attachments() const
bool view(TQWidget *parent, Attachment *attachment)
bool saveAs(TQWidget *parent, Attachment *attachment)