KTextEditor

kateswapfile.h
1/*
2 SPDX-FileCopyrightText: 2010-2018 Dominik Haumann <dhaumann@kde.org>
3 SPDX-FileCopyrightText: 2010 Diana-Victoria Tiriplica <diana.tiriplica@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KATE_SWAPFILE_H
9#define KATE_SWAPFILE_H
10
11#include <QDataStream>
12#include <QFile>
13#include <QObject>
14#include <QPointer>
15
16class QTimer;
17namespace KTextEditor
18{
19class ViewPrivate;
20class DocumentPrivate;
21class Message;
22class Range;
23class Cursor;
24class Document;
25}
26
27namespace Kate
28{
29/**
30 * Class for tracking editing actions.
31 * In case Kate crashes, this can be used to replay all edit actions to
32 * recover the lost data.
33 */
34class SwapFile : public QObject
35{
36public:
37 explicit SwapFile(KTextEditor::DocumentPrivate *document);
38 ~SwapFile() override;
39 bool shouldRecover() const;
40
41 void fileClosed();
42 QString fileName();
43
45
46private:
47 void setTrackingEnabled(bool trackingEnabled);
48 void removeSwapFile();
49 bool updateFileName();
50 bool isValidSwapFile(QDataStream &stream, bool checkDigest) const;
51
52private:
54 bool m_trackingEnabled;
55
56protected:
57 void fileSaved(const QString &filename);
58 void fileLoaded(const QString &filename);
59 void modifiedChanged();
60
61 void startEditing();
62 void finishEditing();
63
64 void wrapLine(KTextEditor::Document *, const KTextEditor::Cursor position);
65 void unwrapLine(KTextEditor::Document *, int line);
66 void insertText(KTextEditor::Document *, const KTextEditor::Cursor position, const QString &text);
67 void removeText(KTextEditor::Document *, KTextEditor::Range range, const QString &);
68
69public:
70 void discard();
71 void recover();
72 bool recover(QDataStream &, bool checkDigest = true);
73 void configChanged();
74
75private:
76 QDataStream m_stream;
77 QFile m_swapfile;
78 bool m_recovered;
79 bool m_needSync;
80 static QTimer *s_timer;
81
82protected:
83 void writeFileToDisk();
84
85private:
86 static QTimer *syncTimer();
87
88public:
89 void showSwapFileMessage();
90 void showDiff();
91
92private:
94};
95}
96
97#endif // KATE_SWAPFILE_H
The Cursor represents a position in a Document.
Definition cursor.h:75
Backend of KTextEditor::Document related public KTextEditor interfaces.
A KParts derived class representing a text document.
Definition document.h:284
An object representing a section of text, from one Cursor to another.
Class for tracking editing actions.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:53:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.