Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / lib / konq / konq_operations.h
blob51852f3745c8d08ba7f8aee0723e49d49b531dec
1 /* This file is part of the KDE project
2 Copyright 2000-2007 David Faure <faure@kde.org>
3 Copyright 2003 Waldo Bastian <bastian@kde.org>
4 Copyright 2001-2002 Alexander Neundorf <neundorf@kde.org>
5 Copyright 2002 Michael Brade <brade@kde.org>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) version 3.
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.
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.
22 #ifndef __konq_operations_h__
23 #define __konq_operations_h__
25 #include <kurl.h>
26 #include <libkonq_export.h>
28 #include <QtCore/QObject>
29 #include <QtGui/QDropEvent>
31 class KJob;
32 namespace KIO { class Job; class SimpleJob; struct CopyInfo; }
33 class QWidget;
34 class KFileItem;
36 /**
37 * Implements file operations (move,del,trash,paste,copy,move,link...)
38 * for konqueror and kdesktop whatever the view mode is (icon, tree, ...)
40 class LIBKONQ_EXPORT KonqOperations : public QObject
42 Q_OBJECT
43 protected:
44 KonqOperations( QWidget * parent );
45 virtual ~KonqOperations();
47 public:
48 /**
49 * Pop up properties dialog for mimetype @p mimeType.
50 * @param parent parent widget (for dialogs)
52 static void editMimeType( const QString & mimeType, QWidget* parent );
54 enum Operation { TRASH, DEL, COPY, MOVE, LINK, EMPTYTRASH, STAT, MKDIR, RESTORE, UNKNOWN };
55 /**
56 * Delete the @p selectedUrls if possible.
58 * @param parent parent widget (for error dialog box if any)
59 * @param method should be TRASH or DEL
60 * @param selectedUrls the URLs to be deleted
62 static void del( QWidget * parent, Operation method, const KUrl::List & selectedUrls );
64 /**
65 * Copy the @p selectedUrls to the destination @p destUrl.
67 * @param parent parent widget (for error dialog box if any)
68 * @param method should be COPY, MOVE or LINK
69 * @param selectedUrls the URLs to copy
70 * @param destUrl destination of the copy
72 * @todo document restrictions on the kind of destination
74 static void copy( QWidget * parent, Operation method, const KUrl::List & selectedUrls, const KUrl& destUrl );
75 /**
76 * Drop
77 * @param destItem destination KFileItem for the drop (background or item)
78 * @param destUrl destination URL for the drop.
79 * @param ev the drop event
80 * @param parent parent widget (for error dialog box if any)
82 * If destItem is 0L, doDrop will stat the URL to determine it.
84 static void doDrop( const KFileItem & destItem, const KUrl & destUrl, QDropEvent * ev, QWidget * parent );
86 /**
87 * Paste the clipboard contents
89 static void doPaste( QWidget * parent, const KUrl & destUrl, const QPoint &pos = QPoint() );
91 /**
92 * Empty the trash
94 static void emptyTrash( QWidget* parent );
95 /**
96 * Restore trashed items
98 static void restoreTrashedItems( const KUrl::List& urls, QWidget* parent );
101 * Create a directory. Same as KIO::mkdir but records job into KonqFileUndoManager for undo/redo purposes.
103 static KIO::SimpleJob* mkdir( QWidget *parent, const KUrl & url );
106 * Ask for the name of a new directory and create it.
107 * Calls KonqOperations::mkdir.
109 * @param parent the parent widget
110 * @param baseUrl the directory to create the new directory in
111 * @return the job used to create the directory or 0 if the creation was cancelled by the user
113 static KIO::SimpleJob* newDir( QWidget * parent, const KUrl & baseUrl );
116 * Get info about a given URL, and when that's done (it's asynchronous!),
117 * call a given slot with the KFileItem& as argument.
118 * The KFileItem will be deleted by statUrl after calling the slot. Make a copy
119 * if you need one !
121 static void statUrl( const KUrl & url, const QObject *receiver, const char *member, QWidget* parent );
124 * Do a renaming.
125 * @param parent the parent widget, passed to KonqOperations ctor
126 * @param oldurl the current url of the file to be renamed
127 * @param name the new name for the file. Shouldn't include '/'.
129 static void rename( QWidget * parent, const KUrl & oldurl, const QString & name );
132 * Do a renaming.
133 * @param parent the parent widget, passed to KonqOperations ctor
134 * @param oldurl the current url of the file to be renamed
135 * @param newurl the new url for the file
136 * Use this version if the other one wouldn't work :) (e.g. because name could
137 * be a relative path, including a '/').
139 static void rename( QWidget * parent, const KUrl & oldurl, const KUrl & newurl );
141 enum ConfirmationType { DEFAULT_CONFIRMATION, SKIP_CONFIRMATION, FORCE_CONFIRMATION };
143 * Ask for confirmation before deleting/trashing @p selectedUrls.
144 * @param selectedUrls the urls about to be deleted
145 * @param method the type of deletion (DEL for real deletion, anything else for trash)
146 * @param confirmation default (based on config file), skip (no confirmation) or force (always confirm)
147 * @param widget parent widget for message boxes
148 * @return true if confirmed
150 static bool askDeleteConfirmation( const KUrl::List & selectedUrls, int method, ConfirmationType confirmation, QWidget* widget );
152 Q_SIGNALS:
153 void statFinished( const KFileItem & item );
154 void aboutToCreate(const QPoint &pos, const QList<KIO::CopyInfo> &files);
156 private:
157 QWidget* parentWidget() const;
158 void _del( Operation method, const KUrl::List & selectedUrls, ConfirmationType confirmation );
159 void _restoreTrashedItems( const KUrl::List& urls );
160 void _statUrl( const KUrl & url, const QObject *receiver, const char *member );
162 // internal, for COPY/MOVE/LINK/MKDIR
163 void setOperation( KIO::Job * job, Operation method, const KUrl & dest );
165 struct DropInfo
167 DropInfo( Qt::KeyboardModifiers k, const KUrl::List & u, const QMap<QString,QString> &m,
168 const QPoint& pos, Qt::DropAction a ) :
169 keyboardModifiers(k), urls(u), metaData(m), mousePos(pos), action(a)
171 Qt::KeyboardModifiers keyboardModifiers;
172 KUrl::List urls;
173 QMap<QString,QString> metaData;
174 QPoint mousePos;
175 Qt::DropAction action;
177 // internal, for doDrop
178 void setDropInfo( DropInfo * info ) { m_info = info; }
180 struct KIOPasteInfo // KDE4: remove and use DropInfo instead or a QPoint member
182 // Used to position the files at the position where RMB/Paste was used [mostly on the desktop]
183 QPoint mousePos;
185 void setPasteInfo( KIOPasteInfo * info ) { m_pasteInfo = info; }
187 protected Q_SLOTS:
189 void slotAboutToCreate(KIO::Job *job, const QList<KIO::CopyInfo> &files);
190 void slotResult( KJob * job );
191 void slotStatResult( KJob * job );
192 void asyncDrop( const KFileItem & item );
193 void doDropFileCopy();
195 private:
196 Operation m_method;
197 //KUrl::List m_srcUrls;
198 KUrl m_destUrl;
199 // for doDrop
200 DropInfo * m_info;
201 KIOPasteInfo * m_pasteInfo;
204 #include <kio/job.h>
206 /// Restore multiple trashed files
207 class KonqMultiRestoreJob : public KIO::Job
209 Q_OBJECT
211 public:
212 KonqMultiRestoreJob( const KUrl::List& urls );
214 protected Q_SLOTS:
215 virtual void slotStart();
216 virtual void slotResult( KJob *job );
218 private:
219 const KUrl::List m_urls;
220 KUrl::List::const_iterator m_urlsIterator;
221 int m_progress;
224 #endif