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( Qt::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, TQT_SIGNAL(urlSelected(
const TQString &)),
227 TQT_SLOT(urlSelected(
const TQString &)) );
228 connect( mURLRequester, TQT_SIGNAL( textChanged(
const TQString& ) ),
229 TQT_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( mURLRequester->url() );
248 mItem->setLabel( url.isLocalFile() ? url.fileName() : url.url() );
249 }
else mItem->setLabel( i18n(
"New attachment" ) );
250 mItem->setMimeType( mMimeType->name() );
251 if ( mURLRequester ) {
252 KURL url( mURLRequester->url() );
254 TQString correctedUrl = mURLRequester->url();
255 if ( !url.isValid() ) {
261 correctedUrl = TQDir::home().filePath( mURLRequester->url() );
262 url = KURL( correctedUrl );
263 if ( url.isValid() ) {
264 urlSelected( correctedUrl );
265 mItem->setMimeType( mMimeType->name() );
269 if ( mInline->isChecked() ) {
271 if ( TDEIO::NetAccess::download( correctedUrl, tmpFile,
this ) ) {
273 if ( !f.open( IO_ReadOnly ) ) {
276 TQByteArray data = f.readAll();
278 mItem->setData( data );
280 TDEIO::NetAccess::removeTempFile( tmpFile );
282 mItem->setUri( url.url() );
287void AttachmentEditDialog::accept()
293void AttachmentEditDialog::urlChanged(
const TQString &url )
295 enableButton( Ok, !url.isEmpty() );
298void AttachmentEditDialog::urlSelected(
const TQString &url )
301 mMimeType = KMimeType::findByURL( kurl );
302 mTypeLabel->setText( mMimeType->comment() );
303 mIcon->setPixmap( AttachmentListItem::icon( mMimeType, kurl.path() ) );
306AttachmentIconView::AttachmentIconView( KOEditorAttachments* parent )
307 : TDEIconView( parent ),
310 setSelectionMode( TQIconView::Extended );
311 setMode( TDEIconView::Select );
312 setItemTextPos( TQIconView::Right );
313 setArrangement( TQIconView::LeftToRight );
314 setMaxItemWidth( TQMAX(maxItemWidth(), 250) );
315 setMinimumHeight( TQMAX(fontMetrics().height(), 16) + 12 );
317 connect(
this, TQT_SIGNAL( dropped ( TQDropEvent *,
const TQValueList<TQIconDragItem> & ) ),
318 this, TQT_SLOT( handleDrop( TQDropEvent *,
const TQValueList<TQIconDragItem> & ) ) );
321KURL AttachmentIconView::tempFileForAttachment(
KCal::Attachment *attachment )
323 if ( mTempFiles.contains( attachment ) ) {
324 return mTempFiles[attachment];
326 TQStringList patterns = KMimeType::mimeType( attachment->mimeType() )->patterns();
329 if ( !patterns.empty() ) {
330 file =
new KTempFile( TQString(),
331 TQString( patterns.first() ).remove(
'*' ),0600 );
333 file =
new KTempFile( TQString(), TQString(), 0600 );
335 file->setAutoDelete(
true );
336 file->file()->open( IO_WriteOnly );
337 TQTextStream stream( file->file() );
338 stream.writeRawBytes( attachment->decodedData().data(), attachment->size() );
339 KURL url( file->name() );
340 mTempFiles.insert( attachment, url );
342 return mTempFiles[attachment];
345TQDragObject *AttachmentIconView::mimeData()
350 for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() ) {
351 if ( it->isSelected() ) {
352 AttachmentListItem *item =
static_cast<AttachmentListItem *
>( it );
353 if ( item->isBinary() ) {
354 urls.append( tempFileForAttachment( item->attachment() ) );
356 urls.append( item->uri() );
358 labels.append( KURL::encode_string( item->label() ) );
361 if ( selectionMode() == TQIconView::NoSelection ) {
362 AttachmentListItem *item =
static_cast<AttachmentListItem *
>( currentItem() );
364 urls.append( item->uri() );
365 labels.append( KURL::encode_string( item->label() ) );
369 TQMap<TQString, TQString> metadata;
370 metadata[
"labels"] = labels.join(
":" );
372 KURLDrag *drag =
new KURLDrag( urls, metadata );
376AttachmentIconView::~AttachmentIconView()
378 for ( std::set<KTempDir*>::iterator it = mTempDirs.begin() ; it != mTempDirs.end() ; ++it ) {
383TQDragObject * AttachmentIconView::dragObject()
386 for ( TQIconViewItem *it = firstItem( ); it; it = it->nextItem( ) ) {
387 if ( !it->isSelected() )
continue;
388 AttachmentListItem * item =
dynamic_cast<AttachmentListItem*
>( it );
389 if ( !item )
return 0;
393 if ( att->isUri() ) {
394 url.setPath( att->uri() );
396 KTempDir *tempDir =
new KTempDir();
397 tempDir->setAutoDelete(
true );
398 mTempDirs.insert( tempDir );
400 encoded.duplicate( att->data(), strlen( att->data() ) );
402 KCodecs::base64Decode( encoded, decoded );
403 const TQString fileName = tempDir->name( ) +
'/' + att->label();
404 KPIM::kByteArrayToFile( decoded, fileName,
false,
false,
false );
405 url.setPath( fileName );
409 KURLDrag *drag =
new KURLDrag( urls,
this );
413void AttachmentIconView::handleDrop( TQDropEvent *event,
const TQValueList<TQIconDragItem> & list )
416 mParent->handlePasteOrDrop( event );
420void AttachmentIconView::dragMoveEvent( TQDragMoveEvent *event )
422 mParent->dragMoveEvent( event );
425void AttachmentIconView::contentsDragMoveEvent( TQDragMoveEvent *event )
427 mParent->dragMoveEvent( event );
430void AttachmentIconView::contentsDragEnterEvent( TQDragEnterEvent *event )
432 mParent->dragMoveEvent( event );
435void AttachmentIconView::dragEnterEvent( TQDragEnterEvent *event )
437 mParent->dragEnterEvent( event );
440KOEditorAttachments::KOEditorAttachments(
int spacing, TQWidget *parent,
442 : TQWidget( parent, name )
444 TQBoxLayout *topLayout =
new TQHBoxLayout(
this );
445 topLayout->setSpacing( spacing );
447 TQLabel *label =
new TQLabel( i18n(
"Attachments:"),
this );
448 topLayout->addWidget( label );
450 mAttachments =
new AttachmentIconView(
this );
451 TQWhatsThis::add( mAttachments,
452 i18n(
"Displays a list of current items (files, mail, etc.) "
453 "that have been associated with this event or to-do. ") );
454 topLayout->addWidget( mAttachments );
455 connect( mAttachments, TQT_SIGNAL( doubleClicked( TQIconViewItem * ) ),
456 TQT_SLOT( showAttachment( TQIconViewItem * ) ) );
457 connect( mAttachments, TQT_SIGNAL(selectionChanged()),
458 TQT_SLOT(selectionChanged()) );
459 connect( mAttachments, TQT_SIGNAL(contextMenuRequested(TQIconViewItem*,
const TQPoint&)),
460 TQT_SLOT(contextMenu(TQIconViewItem*,
const TQPoint&)) );
462 TQPushButton *addButton =
new TQPushButton(
this );
463 addButton->setIconSet( SmallIconSet(
"add" ) );
464 TQToolTip::add( addButton, i18n(
"Add an attachment" ) );
465 TQWhatsThis::add( addButton,
466 i18n(
"Shows a dialog used to select an attachment "
467 "to add to this event or to-do as link or as "
469 topLayout->addWidget( addButton );
470 connect( addButton, TQT_SIGNAL(clicked()), TQT_SLOT(slotAdd()) );
472 mRemoveBtn =
new TQPushButton(
this );
473 mRemoveBtn->setIconSet( SmallIconSet(
"remove" ) );
474 TQToolTip::add( mRemoveBtn, i18n(
"&Remove") );
475 TQWhatsThis::add( mRemoveBtn,
476 i18n(
"Removes the attachment selected in the list above "
477 "from this event or to-do.") );
478 topLayout->addWidget( mRemoveBtn );
479 connect( mRemoveBtn, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemove()) );
481 mContextMenu =
new TDEPopupMenu(
this );
483 TDEActionCollection* ac =
new TDEActionCollection( TQT_TQWIDGET(
this), TQT_TQOBJECT(
this) );
485 mOpenAction =
new TDEAction( i18n(
"Open"), 0, TQT_TQOBJECT(
this), TQT_SLOT(slotShow()), ac );
486 mOpenAction->plug( mContextMenu );
488 mSaveAsAction =
new TDEAction( i18n(
"Save As..." ), 0, TQT_TQOBJECT(
this), TQT_SLOT(slotSaveAs()), ac );
489 mSaveAsAction->plug( mContextMenu );
490 mContextMenu->insertSeparator();
492 mCopyAction = KStdAction::copy(TQT_TQOBJECT(
this), TQT_SLOT(slotCopy()), ac );
493 mCopyAction->plug( mContextMenu );
494 mCutAction = KStdAction::cut(TQT_TQOBJECT(
this), TQT_SLOT(slotCut()), ac );
495 mCutAction->plug( mContextMenu );
496 TDEAction *action = KStdAction::paste(TQT_TQOBJECT(
this), TQT_SLOT(slotPaste()), ac );
497 action->plug( mContextMenu );
498 mContextMenu->insertSeparator();
500 mDeleteAction =
new TDEAction( i18n(
"&Remove" ), 0, TQT_TQOBJECT(
this), TQT_SLOT(slotRemove()), ac );
501 mDeleteAction->plug( mContextMenu );
502 mDeleteAction->setShortcut( Key_Delete );
503 mContextMenu->insertSeparator();
505 mEditAction =
new TDEAction( i18n(
"&Properties..." ), 0, TQT_TQOBJECT(
this), TQT_SLOT(slotEdit()), ac );
506 mEditAction->plug( mContextMenu );
509 setAcceptDrops(
true );
512KOEditorAttachments::~KOEditorAttachments()
516bool KOEditorAttachments::hasAttachments()
518 return mAttachments->count() != 0;
521void KOEditorAttachments::dragMoveEvent( TQDragMoveEvent *event )
523 event->accept( KURLDrag::canDecode( event ) ||
524 TQTextDrag::canDecode( event ) ||
525 KPIM::MailListDrag::canDecode( event ) ||
526 KVCardDrag::canDecode( event ) );
529void KOEditorAttachments::dragEnterEvent( TQDragEnterEvent* event )
531 dragMoveEvent( event );
534void KOEditorAttachments::handlePasteOrDrop( TQMimeSource* source )
537 bool probablyWeHaveUris =
false;
538 bool weCanCopy =
true;
541 if ( KVCardDrag::canDecode( source ) ) {
542 TDEABC::Addressee::List addressees;
543 KVCardDrag::decode( source, addressees );
544 for ( TDEABC::Addressee::List::ConstIterator it = addressees.constBegin();
545 it != addressees.constEnd(); ++it ) {
546 urls.append( TDEPIMPROTOCOL_CONTACT + ( *it ).uid() );
548 labels.append( TQString::fromUtf8( ( *it ).realName().latin1() ) );
550 probablyWeHaveUris =
true;
551 }
else if ( KURLDrag::canDecode( source ) ) {
552 TQMap<TQString,TQString> metadata;
553 if ( KURLDrag::decode( source, urls, metadata ) ) {
554 probablyWeHaveUris =
true;
555 labels = TQStringList::split(
':', metadata[
"labels"], FALSE );
556 for ( TQStringList::Iterator it = labels.begin(); it != labels.end(); ++it ) {
557 *it = KURL::decode_string( (*it).latin1() );
561 }
else if ( TQTextDrag::canDecode( source ) ) {
563 TQTextDrag::decode( source, text );
564 TQStringList lst = TQStringList::split(
'\n', text, FALSE );
565 for ( TQStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it ) {
567 labels.append( TQString() );
569 probablyWeHaveUris =
true;
574 if ( probablyWeHaveUris ) {
575 menu.insertItem( i18n(
"&Link here" ), DRAG_LINK, items++ );
577 for ( KURL::List::ConstIterator it = urls.constBegin(); it != urls.constEnd(); ++it ) {
578 if ( !( weCanCopy = KProtocolInfo::supportsReading( *it ) ) ) {
583 menu.insertItem( SmallIcon(
"edit-copy" ), i18n(
"&Copy Here" ), DRAG_COPY, items++ );
586 menu.insertItem( SmallIcon(
"edit-copy" ), i18n(
"&Copy Here" ), DRAG_COPY, items++ );
589 menu.insertSeparator();
591 menu.insertItem( SmallIcon(
"cancel" ), i18n(
"C&ancel" ), DRAG_CANCEL, items );
592 int action = menu.exec( TQCursor::pos(), 0 );
594 if ( action == DRAG_LINK ) {
595 TQStringList::ConstIterator jt = labels.constBegin();
596 for ( KURL::List::ConstIterator it = urls.constBegin();
597 it != urls.constEnd(); ++it ) {
598 TQString label = (*jt++);
599 if ( mAttachments->findItem( label ) ) {
600 label +=
'~' + randomString( 3 );
602 addUriAttachment( (*it).url(), TQString(), label,
true );
604 }
else if ( action != DRAG_CANCEL ) {
605 if ( probablyWeHaveUris ) {
606 for ( KURL::List::ConstIterator it = urls.constBegin();
607 it != urls.constEnd(); ++it ) {
608 TQString label = (*it).fileName();
609 if ( label.isEmpty() ) {
610 label = (*it).prettyURL();
612 if ( mAttachments->findItem( label ) ) {
613 label +=
'~' + randomString( 3 );
615 addUriAttachment( (*it).url(), TQString(), label,
true );
618 addDataAttachment( source->encodedData( source->format() ),
620 KMimeType::mimeType( source->format() )->name() );
625void KOEditorAttachments::dropEvent( TQDropEvent* event )
627 handlePasteOrDrop( event );
630void KOEditorAttachments::showAttachment( TQIconViewItem *item )
632 AttachmentListItem *attitem =
static_cast<AttachmentListItem*
>(item);
633 if ( !attitem || !attitem->attachment() )
return;
639void KOEditorAttachments::saveAttachment( TQIconViewItem *item )
641 AttachmentListItem *attitem =
static_cast<AttachmentListItem*
>(item);
642 if ( !attitem || !attitem->attachment() )
return;
648void KOEditorAttachments::slotAdd()
650 AttachmentListItem *item =
new AttachmentListItem( 0, mAttachments );
652 AttachmentEditDialog *dlg =
new AttachmentEditDialog( item, mAttachments )
654 if ( dlg->exec() == KDialog::Rejected ) {
660void KOEditorAttachments::slotAddData()
662 KURL uri = KFileDialog::getOpenFileName( TQString(), TQString(),
this, i18n(
"Add Attachment") );
663 if ( !uri.isEmpty() ) {
664 TQString label = uri.fileName();
665 if ( label.isEmpty() ) {
666 label = uri.prettyURL();
668 addUriAttachment( uri.url(), TQString(), label,
true );
672void KOEditorAttachments::slotEdit()
674 for ( TQIconViewItem *item = mAttachments->firstItem(); item; item = item->nextItem() ) {
675 if ( item->isSelected() ) {
676 AttachmentListItem *attitem =
static_cast<AttachmentListItem*
>( item );
677 if ( !attitem || !attitem->attachment() ) {
681 AttachmentEditDialog *dialog =
new AttachmentEditDialog( attitem, mAttachments );
682 dialog->mInline->setEnabled(
false );
683 dialog->setModal(
false );
684 connect( dialog, TQT_SIGNAL(hidden()), dialog, TQT_SLOT(delayedDestruct()) );
690void KOEditorAttachments::slotRemove()
692 TQValueList<TQIconViewItem*> selected;
694 for ( TQIconViewItem *it = mAttachments->firstItem( ); it; it = it->nextItem( ) ) {
695 if ( !it->isSelected() )
continue;
698 AttachmentListItem *attitem =
static_cast<AttachmentListItem*
>(it);
700 labels << att->label();
703 if ( selected.isEmpty() ) {
707 TQString labelsStr = labels.join(
"<br>" );
709 if ( KMessageBox::questionYesNo(
711 i18n(
"<qt>Do you really want to remove these attachments?<p>%1</qt>" ).arg( labelsStr ),
712 i18n(
"Remove Attachment?" ),
713 KStdGuiItem::yes(), KStdGuiItem::no(),
714 "calendarRemoveAttachments" ) != KMessageBox::Yes ) {
718 for ( TQValueList<TQIconViewItem*>::iterator it( selected.begin() ), end( selected.end() );
720 if ( (*it)->nextItem() ) {
721 (*it)->nextItem()->setSelected(
true );
722 }
else if ( (*it)->prevItem() ) {
723 (*it)->prevItem()->setSelected(
true );
727 mAttachments->slotUpdate();
730void KOEditorAttachments::slotShow()
732 for ( TQIconViewItem *it = mAttachments->firstItem(); it; it = it->nextItem() ) {
733 if ( !it->isSelected() )
735 showAttachment( it );
739void KOEditorAttachments::slotSaveAs()
741 for ( TQIconViewItem *it = mAttachments->firstItem(); it; it = it->nextItem() ) {
742 if ( !it->isSelected() )
744 saveAttachment( it );
748void KOEditorAttachments::setDefaults()
750 mAttachments->clear();
753TQString KOEditorAttachments::randomString(
int length)
const
755 if (length <=0 )
return TQString();
757 TQString str; str.setLength( length );
771void KOEditorAttachments::addUriAttachment(
const TQString &uri,
772 const TQString &mimeType,
773 const TQString &label,
777 AttachmentListItem *item =
new AttachmentListItem( 0, mAttachments );
779 item->setLabel( label );
780 if ( mimeType.isEmpty() ) {
781 if ( uri.startsWith( TDEPIMPROTOCOL_CONTACT ) ) {
782 item->setMimeType(
"text/directory" );
783 }
else if ( uri.startsWith( TDEPIMPROTOCOL_EMAIL ) ) {
784 item->setMimeType(
"message/rfc822" );
785 }
else if ( uri.startsWith( TDEPIMPROTOCOL_INCIDENCE ) ) {
786 item->setMimeType(
"text/calendar" );
787 }
else if ( uri.startsWith( TDEPIMPROTOCOL_NEWSARTICLE ) ) {
788 item->setMimeType(
"message/news" );
790 item->setMimeType( KMimeType::findByURL( uri )->name() );
795 if ( TDEIO::NetAccess::download( uri, tmpFile,
this ) ) {
797 if ( !f.open( IO_ReadOnly ) ) {
800 const TQByteArray data = f.readAll();
802 addDataAttachment( data, mimeType, label );
804 TDEIO::NetAccess::removeTempFile( tmpFile );
808void KOEditorAttachments::addDataAttachment(
const TQByteArray &data,
809 const TQString &mimeType,
810 const TQString &label )
812 AttachmentListItem *item =
new AttachmentListItem( 0, mAttachments );
814 TQString nlabel = label;
815 if ( mimeType ==
"message/rfc822" ) {
818 msg.setContent( data.data() );
820 nlabel = msg.subject()->asUnicodeString();
823 item->setData( data );
824 item->setLabel( nlabel );
825 if ( mimeType.isEmpty() ) {
826 item->setMimeType( KMimeType::findByContent( data )->name() );
828 item->setMimeType( mimeType );
834 new AttachmentListItem( attachment, mAttachments );
839 mAttachments->clear();
841 KCal::Attachment::List attachments = i->
attachments();
842 KCal::Attachment::List::ConstIterator it;
843 for( it = attachments.begin(); it != attachments.end(); ++it ) {
844 addAttachment( (*it) );
846 if ( mAttachments->count() > 0 ) {
847 TQTimer::singleShot( 0, mAttachments, TQT_SLOT(arrangeItemsInGrid()) );
855 TQIconViewItem *item;
856 AttachmentListItem *attitem;
857 for( item = mAttachments->firstItem(); item; item = item->nextItem() ) {
858 attitem =
static_cast<AttachmentListItem*
>(item);
865void KOEditorAttachments::slotCopy()
867 TQApplication::clipboard()->setData( mAttachments->mimeData(), TQClipboard::Clipboard );
870void KOEditorAttachments::slotCut()
876void KOEditorAttachments::slotPaste()
878 handlePasteOrDrop( TQApplication::clipboard()->data() );
881void KOEditorAttachments::selectionChanged()
883 bool selected =
false;
884 for ( TQIconViewItem *item = mAttachments->firstItem(); item; item = item->nextItem() ) {
885 if ( item->isSelected() ) {
890 mRemoveBtn->setEnabled( selected );
893void KOEditorAttachments::contextMenu(TQIconViewItem * item,
const TQPoint & pos)
895 const bool enable = item != 0;
898 for ( TQIconViewItem *item = mAttachments->firstItem(); item; item = item->nextItem() ) {
899 if ( item->isSelected() ) {
904 mOpenAction->setEnabled( enable );
906 mSaveAsAction->setEnabled( enable && numSelected == 1 );
907 mCopyAction->setEnabled( enable && numSelected == 1 );
908 mCutAction->setEnabled( enable && numSelected == 1 );
909 mDeleteAction->setEnabled( enable );
910 mEditAction->setEnabled( enable );
911 mContextMenu->exec( pos );
914#include "koeditorattachments.moc"
void addAttachment(Attachment *attachment)
Attachment::List attachments() const
bool view(TQWidget *parent, Attachment *attachment)
bool saveAs(TQWidget *parent, Attachment *attachment)