KTextEditor

kateswapfile.h
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2010-2018 Dominik Haumann <[email protected]>
4  Copyright (C) 2010 Diana-Victoria Tiriplica <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef KATE_SWAPFILE_H
23 #define KATE_SWAPFILE_H
24 
25 #include <QDataStream>
26 #include <QFile>
27 #include <QObject>
28 #include <QTimer>
29 
30 #include "katebuffer.h"
31 #include "katedocument.h"
32 #include "katetextbuffer.h"
33 #include <ktexteditor_export.h>
34 
35 #include <KTextEditor/Message>
36 
37 namespace KTextEditor
38 {
39 class ViewPrivate;
40 }
41 
42 namespace Kate
43 {
49 class KTEXTEDITOR_EXPORT SwapFile : public QObject
50 {
51  Q_OBJECT
52 
53 public:
54  explicit SwapFile(KTextEditor::DocumentPrivate *document);
55  ~SwapFile();
56  bool shouldRecover() const;
57 
58  void fileClosed();
59  QString fileName();
60 
61  KTextEditor::DocumentPrivate *document();
62 
63 private:
64  void setTrackingEnabled(bool trackingEnabled);
65  void removeSwapFile();
66  bool updateFileName();
67  bool isValidSwapFile(QDataStream &stream, bool checkDigest) const;
68 
69 private:
70  KTextEditor::DocumentPrivate *m_document;
71  bool m_trackingEnabled;
72 
73 protected Q_SLOTS:
74  void fileSaved(const QString &filename);
75  void fileLoaded(const QString &filename);
76  void modifiedChanged();
77 
78  void startEditing();
79  void finishEditing();
80 
81  void wrapLine(const KTextEditor::Cursor &position);
82  void unwrapLine(int line);
83  void insertText(const KTextEditor::Cursor &position, const QString &text);
84  void removeText(const KTextEditor::Range &range);
85 
86 public Q_SLOTS:
87  void discard();
88  void recover();
89  bool recover(QDataStream &, bool checkDigest = true);
90  void configChanged();
91 
92 private:
93  QDataStream m_stream;
94  QFile m_swapfile;
95  bool m_recovered;
96  bool m_needSync;
97  static QTimer *s_timer;
98 
99 protected Q_SLOTS:
100  void writeFileToDisk();
101 
102 private:
103  QTimer *syncTimer();
104 
105 public Q_SLOTS:
106  void showSwapFileMessage();
107  void showDiff();
108 
109 private:
110  QPointer<KTextEditor::Message> m_swapMessage;
111 };
112 
113 }
114 
115 #endif // KATE_SWAPFILE_H
The Cursor represents a position in a Document.
Definition: cursor.h:83
Class for tracking editing actions.
Definition: kateswapfile.h:49
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
An object representing a section of text, from one Cursor to another.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun May 24 2020 23:10:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.