]> git.lyx.org Git - lyx.git/blob - src/Compare.cpp
eb98b383027d8898ed5843f73f5d1096bd4d2a40
[lyx.git] / src / Compare.cpp
1 /**
2  * \file Compare.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Vincent van Ravesteijn
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Compare.h"
14
15 #include "Buffer.h"
16 #include "BufferParams.h"
17
18
19 using namespace std;
20 using namespace lyx::support;
21
22
23 namespace lyx {
24
25 /**
26  * The implementation of the algorithm that does the comparison
27  * between two documents.
28  */
29 class Compare::Impl {
30 public:
31         ///
32         Impl(Compare const & compare) 
33                 : compare_(compare), abort_(false)
34         {}
35
36         ///
37         ~Impl() {}
38
39         /// Set to true to abort the algorithm
40         bool abort_;
41
42 private:
43         /// The thread object, used to emit signals to the GUI
44         Compare const & compare_;
45 };
46
47
48 Compare::Compare(Buffer const * new_buf, Buffer const * old_buf,
49         Buffer * const dest_buf, CompareOptions const & options)
50         : new_buffer(new_buf), old_buffer(old_buf), dest_buffer(dest_buf),
51           options_(options), pimpl_(new Impl(*this))
52 {
53 }
54
55
56 void Compare::run()
57 {
58         if (!dest_buffer || !new_buffer || !old_buffer)
59                 return;
60
61         // Copy the buffer params to the new buffer
62         dest_buffer->params() = options_.settings_from_new
63                 ? new_buffer->params() : old_buffer->params();
64         
65         // do the real work
66         if (!doCompare())
67                 return;
68         
69         finished(pimpl_->abort_);
70         return;
71 }
72
73
74 void Compare::abort()
75 {
76         pimpl_->abort_ = true;
77         condition_.wakeOne();
78         wait();
79         pimpl_->abort_ = false;
80 }
81
82
83 int Compare::doCompare()
84 {
85         return 1;
86 }
87
88
89 #include "moc_Compare.cpp"
90
91 } // namespace lyx