korganizer

koeditorattachments.h
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (c) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of TQt, and distribute the resulting executable,
23  without including the source code for TQt in the source distribution.
24 */
25 #ifndef KOEDITORATTACHMENTS_H
26 #define KOEDITORATTACHMENTS_H
27 
28 #include <tqwidget.h>
29 #include <tqmap.h>
30 #include <kdialogbase.h>
31 #include <kmimetype.h>
32 #include <kurl.h>
33 #include <kiconview.h>
34 
35 #include <set>
36 
37 class AttachmentListItem;
38 class AttachmentIconView;
39 
40 namespace KCal {
41 class Incidence;
42 class Attachment;
43 }
44 
45 class TQCheckBox;
46 class TQIconViewItem;
47 class TQLabel;
48 class TQMimeSource;
49 class TQPushButton;
50 class TQPopupMenu;
51 
52 class TDEAction;
53 class KLineEdit;
54 class KURLRequester;
55 class KTempDir;
56 
57 class AttachmentEditDialog : public KDialogBase
58 {
59  TQ_OBJECT
60 
61  public:
62  AttachmentEditDialog( AttachmentListItem *item, TQWidget *parent=0 );
63 
64  void accept();
65 
66  protected slots:
67  void urlSelected( const TQString &url );
68  void urlChanged( const TQString & url );
69  virtual void slotApply();
70 
71  private:
72  friend class KOEditorAttachments;
73  KMimeType::Ptr mMimeType;
74  AttachmentListItem *mItem;
75  TQLabel *mTypeLabel, *mIcon;
76  TQCheckBox *mInline;
77  KLineEdit *mLabelEdit;
78  KURLRequester *mURLRequester;
79 };
80 
81 class KOEditorAttachments : public TQWidget
82 {
83  TQ_OBJECT
84 
85  public:
86  KOEditorAttachments( int spacing = 8, TQWidget *parent = 0,
87  const char *name = 0 );
88  ~KOEditorAttachments();
89 
90  void addUriAttachment( const TQString &uri,
91  const TQString &mimeType = TQString(),
92  const TQString &label = TQString(),
93  bool inLine = false );
94  void addAttachment( KCal::Attachment *attachment );
95  void addDataAttachment( const TQByteArray &data,
96  const TQString &mimeType = TQString(),
97  const TQString &label = TQString() );
98 
100  void setDefaults();
102  void readIncidence( KCal::Incidence * );
104  void writeIncidence( KCal::Incidence * );
105 
106  bool hasAttachments();
107 
108  protected slots:
109  void showAttachment( TQIconViewItem *item );
110  void saveAttachment( TQIconViewItem *item );
111  void slotAdd();
112  void slotAddData();
113  void slotEdit();
114  void slotRemove();
115  void slotShow();
116  void slotSaveAs();
117  void dragEnterEvent( TQDragEnterEvent *event );
118  void dragMoveEvent( TQDragMoveEvent *event );
119  void dropEvent( TQDropEvent *event );
120  void slotCopy();
121  void slotCut();
122  void slotPaste();
123  void selectionChanged();
124  void contextMenu( TQIconViewItem* item, const TQPoint &pos );
125 
126  signals:
127  void openURL( const KURL &url );
128 
129  protected:
130  enum {
131  DRAG_COPY = 0,
132  DRAG_LINK = 1,
133  DRAG_CANCEL = 2
134  };
135 
136  private:
137  friend class AttachmentIconView;
138  void handlePasteOrDrop( TQMimeSource* source );
139  TQString randomString( int length ) const;
140  AttachmentIconView *mAttachments;
141  TQPushButton *mRemoveBtn;
142  TQPopupMenu *mContextMenu, *mAddMenu;
143  TDEAction *mOpenAction;
144  TDEAction *mSaveAsAction;
145  TDEAction *mCopyAction;
146  TDEAction *mCutAction;
147  TDEAction *mDeleteAction;
148  TDEAction *mEditAction;
149 };
150 
151 
152 class AttachmentIconView : public TDEIconView
153 {
154  TQ_OBJECT
155 
156 
157  friend class KOEditorAttachments;
158  public:
159  AttachmentIconView( KOEditorAttachments* parent=0 );
160  KURL tempFileForAttachment( KCal::Attachment *attachment );
161  TQDragObject *mimeData();
162  ~AttachmentIconView();
163 
164  protected:
165  TQDragObject * dragObject();
166 
167  void dragMoveEvent( TQDragMoveEvent *event );
168  void contentsDragMoveEvent( TQDragMoveEvent *event );
169  void contentsDragEnterEvent( TQDragEnterEvent *event );
170  void dragEnterEvent( TQDragEnterEvent *event );
171 
172  protected slots:
173 
174  void handleDrop( TQDropEvent *event, const TQValueList<TQIconDragItem> & list );
175 
176  private:
177  std::set<KTempDir*> mTempDirs;
178  TQMap<KCal::Attachment *, KURL> mTempFiles;
179  KOEditorAttachments* mParent;
180 };
181 
182 #endif