korganizer

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 Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 #ifndef KOEDITORATTACHMENTS_H
00026 #define KOEDITORATTACHMENTS_H
00027 
00028 #include <qwidget.h>
00029 #include <qmap.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 QCheckBox;
00046 class QIconViewItem;
00047 class QLabel;
00048 class QMimeSource;
00049 class QPushButton;
00050 class QPopupMenu;
00051 
00052 class KAction;
00053 class KLineEdit;
00054 class KURLRequester;
00055 class KTempDir;
00056 
00057 class AttachmentEditDialog : public KDialogBase
00058 {
00059   Q_OBJECT
00060   public:
00061     AttachmentEditDialog( AttachmentListItem *item, QWidget *parent=0 );
00062 
00063     void accept();
00064 
00065   protected slots:
00066     void urlSelected( const QString &url );
00067     void urlChanged( const QString & url );
00068     virtual void slotApply();
00069 
00070   private:
00071     friend class KOEditorAttachments;
00072     KMimeType::Ptr mMimeType;
00073     AttachmentListItem *mItem;
00074     QLabel *mTypeLabel, *mIcon;
00075     QCheckBox *mInline;
00076     KLineEdit *mLabelEdit;
00077     KURLRequester *mURLRequester;
00078 };
00079 
00080 class KOEditorAttachments : public QWidget
00081 {
00082     Q_OBJECT
00083   public:
00084     KOEditorAttachments( int spacing = 8, QWidget *parent = 0,
00085                          const char *name = 0 );
00086     ~KOEditorAttachments();
00087 
00088     void addAttachment( const QString &uri,
00089                         const QString &mimeType = QString(),
00090                         const QString &label = QString(),
00091                         bool binary = false );
00092     void addAttachment( KCal::Attachment *attachment );
00093     void addAttachment( const QByteArray &data,
00094                         const QString &mimeType = QString(),
00095                         const QString &label = QString() );
00096 
00098     void setDefaults();
00100     void readIncidence( KCal::Incidence * );
00102     void writeIncidence( KCal::Incidence * );
00103 
00104     bool hasAttachments();
00105 
00106   protected slots:
00107     void showAttachment( QIconViewItem *item );
00108     void slotAdd();
00109     void slotAddData();
00110     void slotEdit();
00111     void slotRemove();
00112     void slotShow();
00113     void dragEnterEvent( QDragEnterEvent *event );
00114     void dragMoveEvent( QDragMoveEvent *event );
00115     void dropEvent( QDropEvent *event );
00116     void slotCopy();
00117     void slotCut();
00118     void slotPaste();
00119     void selectionChanged();
00120     void contextMenu( QIconViewItem* item, const QPoint &pos );
00121   signals:
00122     void openURL( const KURL &url );
00123 
00124   protected:
00125     enum {
00126       DRAG_COPY = 0,
00127       DRAG_LINK = 1,
00128       DRAG_CANCEL = 2
00129     };
00130 
00131   private:
00132     friend class AttachmentIconView;
00133     void handlePasteOrDrop( QMimeSource* source );
00134     QString randomString( int length ) const;
00135     AttachmentIconView *mAttachments;
00136     QPushButton *mRemoveBtn;
00137     QPopupMenu *mContextMenu, *mAddMenu;
00138     KAction *mOpenAction, *mCopyAction, *mCutAction;
00139     KAction *mDeleteAction, *mEditAction;
00140 };
00141 
00142 
00143 class AttachmentIconView : public KIconView
00144 {
00145   Q_OBJECT
00146 
00147   friend class KOEditorAttachments;
00148   public:
00149     AttachmentIconView( KOEditorAttachments* parent=0 );
00150     KURL tempFileForAttachment( KCal::Attachment *attachment );
00151     QDragObject *mimeData();
00152     ~AttachmentIconView();
00153 
00154   protected:
00155     QDragObject * dragObject();
00156 
00157     void dragMoveEvent( QDragMoveEvent *event );
00158     void contentsDragMoveEvent( QDragMoveEvent *event );
00159     void contentsDragEnterEvent( QDragEnterEvent *event );
00160     void dragEnterEvent( QDragEnterEvent *event );
00161 
00162   protected slots:
00163 
00164     void handleDrop( QDropEvent *event, const QValueList<QIconDragItem> & list );
00165 
00166   private:
00167     std::set<KTempDir*> mTempDirs;
00168     QMap<KCal::Attachment *, KURL> mTempFiles;
00169     KOEditorAttachments* mParent;
00170 };
00171 
00172 #endif