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

KIO

  • kio
  • kio
fileundomanager_p.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
3  Copyright (C) 2006, 2008 David Faure <faure@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef FILEUNDOMANAGER_P_H
22 #define FILEUNDOMANAGER_P_H
23 
24 #include "fileundomanager.h"
25 #include <QtCore/QStack>
26 #include <QUndoCommand>
27 #include <kurl.h>
28 #include <ctime>
29 
30 class KJob;
31 
32 namespace KIO {
33 
34 class FileUndoManagerAdaptor;
35 
36 struct BasicOperation
37 {
38  typedef QList<BasicOperation> Stack;
39 
40  BasicOperation()
41  { m_valid = false; }
42 
43  bool m_valid;
44  bool m_renamed;
45 
46  enum Type { File, Link, Directory };
47  Type m_type:2;
48 
49  KUrl m_src;
50  KUrl m_dst;
51  QString m_target;
52  time_t m_mtime;
53 };
54 
55 class UndoCommand
56 {
57 public:
58  typedef QList<UndoCommand> Stack;
59 
60  UndoCommand()
61  {
62  m_valid = false;
63  }
64 
65  // TODO: is ::TRASH missing?
66  bool isMoveCommand() const { return m_type == FileUndoManager::Move || m_type == FileUndoManager::Rename; }
67 
68  bool m_valid;
69 
70  FileUndoManager::CommandType m_type;
71  BasicOperation::Stack m_opStack;
72  KUrl::List m_src;
73  KUrl m_dst;
74  quint64 m_serialNumber;
75 };
76 
77 
78 // This class listens to a job, collects info while it's running (for copyjobs)
79 // and when the job terminates, on success, it calls addCommand in the undomanager.
80 class CommandRecorder : public QObject
81 {
82  Q_OBJECT
83 public:
84  CommandRecorder( FileUndoManager::CommandType op, const KUrl::List &src, const KUrl &dst, KIO::Job *job );
85  virtual ~CommandRecorder();
86 
87 private Q_SLOTS:
88  void slotResult( KJob *job );
89 
90  void slotCopyingDone( KIO::Job *, const KUrl &from, const KUrl &to, time_t, bool directory, bool renamed );
91  void slotCopyingLinkDone( KIO::Job *, const KUrl &from, const QString &target, const KUrl &to );
92 
93 private:
94  UndoCommand m_cmd;
95 };
96 
97 enum UndoState { MAKINGDIRS = 0, MOVINGFILES, STATINGFILE, REMOVINGDIRS, REMOVINGLINKS };
98 
99 // The private class is, exceptionally, a real QObject
100 // so that it can be the class with the DBUS adaptor forwarding its signals.
101 class FileUndoManagerPrivate : public QObject
102 {
103  Q_OBJECT
104 public:
105  FileUndoManagerPrivate(FileUndoManager* qq);
106 
107  ~FileUndoManagerPrivate()
108  {
109  delete m_uiInterface;
110  }
111 
112  void pushCommand( const UndoCommand& cmd );
113 
114  void broadcastPush( const UndoCommand &cmd );
115  void broadcastPop();
116  void broadcastLock();
117  void broadcastUnlock();
118 
119  void addDirToUpdate( const KUrl& url );
120  bool initializeFromKDesky();
121 
122  void undoStep();
123 
124  void stepMakingDirectories();
125  void stepMovingFiles();
126  void stepRemovingLinks();
127  void stepRemovingDirectories();
128 
130  QByteArray get() const;
131 
132  friend class UndoJob;
134  void stopUndo( bool step );
135 
136  friend class UndoCommandRecorder;
138  void addCommand( const UndoCommand &cmd );
139 
140  bool m_syncronized;
141  bool m_lock;
142 
143  UndoCommand::Stack m_commands;
144 
145  UndoCommand m_current;
146  KIO::Job *m_currentJob;
147  UndoState m_undoState;
148  QStack<KUrl> m_dirStack;
149  QStack<KUrl> m_dirCleanupStack;
150  QStack<KUrl> m_fileCleanupStack; // files and links
151  QList<KUrl> m_dirsToUpdate;
152  FileUndoManager::UiInterface* m_uiInterface;
153 
154  UndoJob *m_undoJob;
155  quint64 m_nextCommandIndex;
156 
157  FileUndoManager* q;
158 
159  // DBUS interface
160 Q_SIGNALS:
162  void push(const QByteArray &command);
164  void pop();
166  void lock();
168  void unlock();
169 
170 public Q_SLOTS:
171  // Those four slots are connected to DBUS signals
172  void slotPush(QByteArray);
173  void slotPop();
174  void slotLock();
175  void slotUnlock();
176 
177  void slotResult(KJob*);
178 };
179 
180 } // namespace
181 
182 #endif /* FILEUNDOMANAGER_P_H */
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat May 18 2013 11:40:46 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

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

kdelibs-4.10.3 API Reference

Skip menu "kdelibs-4.10.3 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal