• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KIO

fileundomanager_p.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
00003    Copyright (C) 2006, 2008 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef FILEUNDOMANAGER_P_H
00022 #define FILEUNDOMANAGER_P_H
00023 
00024 #include "fileundomanager.h"
00025 #include <QtCore/QStack>
00026 #include <QUndoCommand>
00027 #include <kurl.h>
00028 #include <ctime>
00029 
00030 class KJob;
00031 
00032 namespace KIO {
00033 
00034 class FileUndoManagerAdaptor;
00035 
00036 struct BasicOperation
00037 {
00038     typedef QStack<BasicOperation> Stack;
00039 
00040     BasicOperation()
00041     { m_valid = false; }
00042 
00043     bool m_valid;
00044     bool m_renamed;
00045 
00046     enum Type { File, Link, Directory };
00047     Type m_type:2;
00048 
00049     KUrl m_src;
00050     KUrl m_dst;
00051     QString m_target;
00052     time_t m_mtime;
00053 };
00054 
00055 class UndoCommand
00056 {
00057 public:
00058     typedef QStack<UndoCommand> Stack;
00059 
00060     UndoCommand()
00061     {
00062       m_valid = false;
00063     }
00064 
00065     // TODO: is ::TRASH missing?
00066     bool isMoveCommand() const { return m_type == FileUndoManager::Move || m_type == FileUndoManager::Rename; }
00067 
00068     bool m_valid;
00069 
00070     FileUndoManager::CommandType m_type;
00071     BasicOperation::Stack m_opStack;
00072     KUrl::List m_src;
00073     KUrl m_dst;
00074     quint64 m_serialNumber;
00075 };
00076 
00077 
00078 // This class listens to a job, collects info while it's running (for copyjobs)
00079 // and when the job terminates, on success, it calls addCommand in the undomanager.
00080 class CommandRecorder : public QObject
00081 {
00082   Q_OBJECT
00083 public:
00084   CommandRecorder( FileUndoManager::CommandType op, const KUrl::List &src, const KUrl &dst, KIO::Job *job );
00085   virtual ~CommandRecorder();
00086 
00087 private Q_SLOTS:
00088   void slotResult( KJob *job );
00089 
00090   void slotCopyingDone( KIO::Job *, const KUrl &from, const KUrl &to, time_t, bool directory, bool renamed );
00091   void slotCopyingLinkDone( KIO::Job *, const KUrl &from, const QString &target, const KUrl &to );
00092 
00093 private:
00094   UndoCommand m_cmd;
00095 };
00096 
00097 enum UndoState { MAKINGDIRS = 0, MOVINGFILES, STATINGFILE, REMOVINGDIRS, REMOVINGLINKS };
00098 
00099 // The private class is, exceptionally, a real QObject
00100 // so that it can be the class with the DBUS adaptor forwarding its signals.
00101 class FileUndoManagerPrivate : public QObject
00102 {
00103     Q_OBJECT
00104 public:
00105     FileUndoManagerPrivate(FileUndoManager* qq);
00106 
00107     ~FileUndoManagerPrivate()
00108     {
00109         delete m_uiInterface;
00110     }
00111 
00112     void pushCommand( const UndoCommand& cmd );
00113 
00114     void broadcastPush( const UndoCommand &cmd );
00115     void broadcastPop();
00116     void broadcastLock();
00117     void broadcastUnlock();
00118 
00119     void addDirToUpdate( const KUrl& url );
00120     bool initializeFromKDesky();
00121 
00122     void undoStep();
00123 
00124     void stepMakingDirectories();
00125     void stepMovingFiles();
00126     void stepRemovingLinks();
00127     void stepRemovingDirectories();
00128 
00130     QByteArray get() const;
00131 
00132     friend class UndoJob;
00134     void stopUndo( bool step );
00135 
00136     friend class UndoCommandRecorder;
00138     void addCommand( const UndoCommand &cmd );
00139 
00140     bool m_syncronized;
00141     bool m_lock;
00142 
00143     UndoCommand::Stack m_commands;
00144 
00145     UndoCommand m_current;
00146     KIO::Job *m_currentJob;
00147     UndoState m_undoState;
00148     QStack<KUrl> m_dirStack;
00149     QStack<KUrl> m_dirCleanupStack;
00150     QStack<KUrl> m_linkCleanupStack;
00151     QList<KUrl> m_dirsToUpdate;
00152     FileUndoManager::UiInterface* m_uiInterface;
00153 
00154     UndoJob *m_undoJob;
00155     quint64 m_nextCommandIndex;
00156 
00157     FileUndoManager* q;
00158 
00159     // DBUS interface
00160 Q_SIGNALS:
00162     void push(const QByteArray &command);
00164     void pop();
00166     void lock();
00168     void unlock();
00169 
00170 public Q_SLOTS:
00171     // Those four slots are connected to DBUS signals
00172     void slotPush(QByteArray);
00173     void slotPop();
00174     void slotLock();
00175     void slotUnlock();
00176 
00177     void slotResult(KJob*);
00178 };
00179 
00180 } // namespace
00181 
00182 #endif /* FILEUNDOMANAGER_P_H */

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal