koeditorattachments.h
00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 Copyright (c) 2005 Reinhold Kainhofer <reinhold@kainhofer.com> 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 00021 As a special exception, permission is given to link this program 00022 with any edition of TQt, and distribute the resulting executable, 00023 without including the source code for TQt in the source distribution. 00024 */ 00025 #ifndef KOEDITORATTACHMENTS_H 00026 #define KOEDITORATTACHMENTS_H 00027 00028 #include <tqwidget.h> 00029 #include <tqmap.h> 00030 #include <kdialogbase.h> 00031 #include <kmimetype.h> 00032 #include <kurl.h> 00033 #include <kiconview.h> 00034 00035 #include <set> 00036 00037 class AttachmentListItem; 00038 class AttachmentIconView; 00039 00040 namespace KCal { 00041 class Incidence; 00042 class Attachment; 00043 } 00044 00045 class TQCheckBox; 00046 class TQIconViewItem; 00047 class TQLabel; 00048 class TQMimeSource; 00049 class TQPushButton; 00050 class TQPopupMenu; 00051 00052 class KAction; 00053 class KLineEdit; 00054 class KURLRequester; 00055 class KTempDir; 00056 00057 class AttachmentEditDialog : public KDialogBase 00058 { 00059 Q_OBJECT 00060 TQ_OBJECT 00061 public: 00062 AttachmentEditDialog( AttachmentListItem *item, TQWidget *parent=0 ); 00063 00064 void accept(); 00065 00066 protected slots: 00067 void urlSelected( const TQString &url ); 00068 void urlChanged( const TQString & url ); 00069 virtual void slotApply(); 00070 00071 private: 00072 friend class KOEditorAttachments; 00073 KMimeType::Ptr mMimeType; 00074 AttachmentListItem *mItem; 00075 TQLabel *mTypeLabel, *mIcon; 00076 TQCheckBox *mInline; 00077 KLineEdit *mLabelEdit; 00078 KURLRequester *mURLRequester; 00079 }; 00080 00081 class KOEditorAttachments : public TQWidget 00082 { 00083 Q_OBJECT 00084 TQ_OBJECT 00085 public: 00086 KOEditorAttachments( int spacing = 8, TQWidget *parent = 0, 00087 const char *name = 0 ); 00088 ~KOEditorAttachments(); 00089 00090 void addUriAttachment( const TQString &uri, 00091 const TQString &mimeType = TQString(), 00092 const TQString &label = TQString(), 00093 bool inLine = false ); 00094 void addAttachment( KCal::Attachment *attachment ); 00095 void addDataAttachment( const TQByteArray &data, 00096 const TQString &mimeType = TQString(), 00097 const TQString &label = TQString() ); 00098 00100 void setDefaults(); 00102 void readIncidence( KCal::Incidence * ); 00104 void writeIncidence( KCal::Incidence * ); 00105 00106 bool hasAttachments(); 00107 00108 protected slots: 00109 void showAttachment( TQIconViewItem *item ); 00110 void saveAttachment( TQIconViewItem *item ); 00111 void slotAdd(); 00112 void slotAddData(); 00113 void slotEdit(); 00114 void slotRemove(); 00115 void slotShow(); 00116 void slotSaveAs(); 00117 void dragEnterEvent( TQDragEnterEvent *event ); 00118 void dragMoveEvent( TQDragMoveEvent *event ); 00119 void dropEvent( TQDropEvent *event ); 00120 void slotCopy(); 00121 void slotCut(); 00122 void slotPaste(); 00123 void selectionChanged(); 00124 void contextMenu( TQIconViewItem* item, const TQPoint &pos ); 00125 00126 signals: 00127 void openURL( const KURL &url ); 00128 00129 protected: 00130 enum { 00131 DRAG_COPY = 0, 00132 DRAG_LINK = 1, 00133 DRAG_CANCEL = 2 00134 }; 00135 00136 private: 00137 friend class AttachmentIconView; 00138 void handlePasteOrDrop( TQMimeSource* source ); 00139 TQString randomString( int length ) const; 00140 AttachmentIconView *mAttachments; 00141 TQPushButton *mRemoveBtn; 00142 TQPopupMenu *mContextMenu, *mAddMenu; 00143 KAction *mOpenAction; 00144 KAction *mSaveAsAction; 00145 KAction *mCopyAction; 00146 KAction *mCutAction; 00147 KAction *mDeleteAction; 00148 KAction *mEditAction; 00149 }; 00150 00151 00152 class AttachmentIconView : public KIconView 00153 { 00154 Q_OBJECT 00155 TQ_OBJECT 00156 00157 friend class KOEditorAttachments; 00158 public: 00159 AttachmentIconView( KOEditorAttachments* parent=0 ); 00160 KURL tempFileForAttachment( KCal::Attachment *attachment ); 00161 TQDragObject *mimeData(); 00162 ~AttachmentIconView(); 00163 00164 protected: 00165 TQDragObject * dragObject(); 00166 00167 void dragMoveEvent( TQDragMoveEvent *event ); 00168 void contentsDragMoveEvent( TQDragMoveEvent *event ); 00169 void contentsDragEnterEvent( TQDragEnterEvent *event ); 00170 void dragEnterEvent( TQDragEnterEvent *event ); 00171 00172 protected slots: 00173 00174 void handleDrop( TQDropEvent *event, const TQValueList<TQIconDragItem> & list ); 00175 00176 private: 00177 std::set<KTempDir*> mTempDirs; 00178 TQMap<KCal::Attachment *, KURL> mTempFiles; 00179 KOEditorAttachments* mParent; 00180 }; 00181 00182 #endif