]> git.lyx.org Git - lyx.git/blob - src/Compare.h
* add PreBabelPreamble to Language definition (fixes #4786).
[lyx.git] / src / Compare.h
1 // -*- C++ -*-
2 /**
3  * \file Compare.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Vincent van Ravesteijn
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef COMPARE_H
13 #define COMPARE_H
14
15 #include "Buffer.h"
16
17 #include "support/FileName.h"
18
19 #include <QObject>
20 #include <QThread>
21 #include <QTimer>
22 #include <QWaitCondition>
23
24 #include <string>
25
26
27 namespace lyx {
28
29 /** 
30  * The options that are used by the Comparison algorithm
31  * and are set in the GuiCompare Dialog.
32  */
33 class CompareOptions {
34 public:
35         ///
36         CompareOptions()
37                 : settings_from_new(0)
38         {}
39         
40         /// Copy the settings from the new or old document
41         bool settings_from_new;
42 };
43
44 /**
45  * A threaded object that does the Comparison between two documents
46  * and creates a new document with the differences marked with track
47  * changes.
48  */
49 class Compare : public QThread
50 {
51         Q_OBJECT
52
53 public:
54         ///
55         Compare(Buffer const * const old_buf, Buffer const * const new_buf,
56                 Buffer * const dest_buf, CompareOptions const & options);
57
58         ///
59         ~Compare() {
60                 abort();
61         }
62
63 Q_SIGNALS:
64         /// The thread has finished due to an error.
65         void error() const;
66
67         /// The thread has finished. If the thread is cancelled
68         /// by the user \c aborted is true.
69         void finished(bool aborted) const;
70
71         /// Adds \c progress to the value of the progress bar in the dialog
72         void progress(int progress) const ;
73
74         /// Sets the maximum value of the progress bar in the dialog.
75         void progressMax(int max) const;
76
77         /// A message describing the process
78         void statusMessage(QString msg) const;
79
80 public Q_SLOTS:
81         /// Emits the status message signal
82         void doStatusMessage();
83
84 public:
85         /// \name QThread inherited methods
86         //@{
87         void run();
88         //@}
89
90         /// Aborts the thread
91         void abort();
92
93 private:
94         /// Starts the comparison algorithm
95         int doCompare();
96         
97         /// The new document's buffer
98         Buffer const * const new_buffer;
99         /// The old document's buffer
100         Buffer const * const old_buffer;
101         /// The buffer with the differences marked with track changes
102         Buffer * const dest_buffer;
103         
104         /// The options that are set in the GuiCompare dialog
105         CompareOptions options_;
106
107         ///
108         QWaitCondition condition_;
109
110         /// Emit a statusMessage signal from time to time
111         QTimer status_timer_;
112
113         /// Use the Pimpl idiom to hide the internals.
114         class Impl;
115         ///
116         Impl * pimpl_;
117 };
118
119
120 } // namespace lyx
121
122 #endif