]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiChanges.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiChanges.cpp
1 /**
2  * \file GuiChanges.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Michael Gerz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiChanges.h"
15
16 #include "qt_helpers.h"
17
18 #include "support/gettext.h"
19 #include "support/lstrings.h"
20 #include "support/lyxtime.h"
21
22 #include "Author.h"
23 #include "Buffer.h"
24 #include "BufferParams.h"
25 #include "BufferView.h"
26 #include "Changes.h"
27 #include "FuncRequest.h"
28 #include "LyXRC.h"
29
30 #include <QDateTime>
31 #include <QTextBrowser>
32
33
34 namespace lyx {
35 namespace frontend {
36
37
38 GuiChanges::GuiChanges(GuiView & lv)
39         : GuiDialog(lv, "changes", qt_("Merge Changes"))
40 {
41         setupUi(this);
42
43         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
44                 this, SLOT(slotButtonBox(QAbstractButton *)));
45         connect(nextPB, SIGNAL(clicked()), this, SLOT(nextChange()));
46         connect(previousPB, SIGNAL(clicked()), this, SLOT(previousChange()));
47         connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectChange()));
48         connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptChange()));
49
50         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
51         bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
52         bc().addReadOnly(acceptPB);
53         bc().addReadOnly(rejectPB);
54 }
55
56
57 void GuiChanges::updateContents()
58 {
59         bool const changesPresent = buffer().areChangesPresent();
60         nextPB->setEnabled(changesPresent);
61         previousPB->setEnabled(changesPresent);
62         changeTB->setEnabled(changesPresent);
63
64         Change const & c = bufferview()->getCurrentChange();
65         bool const changePresent = c.type != Change::UNCHANGED;
66         rejectPB->setEnabled(changePresent);
67         acceptPB->setEnabled(changePresent);
68
69         QString text;
70         if (changePresent) {
71                 QString const author =
72                         toqstr(buffer().params().authors().get(c.author).nameAndEmail());
73                 if (!author.isEmpty())
74                         text += qt_("Changed by %1\n\n").arg(author);
75
76                 QString const date = QDateTime::fromTime_t(c.changetime)
77                                          .toString(Qt::DefaultLocaleLongDate);
78                 if (!date.isEmpty())
79                         text += qt_("Change made on %1\n").arg(date);
80         }
81         changeTB->setPlainText(text);
82 }
83
84
85 void GuiChanges::nextChange()
86 {
87         dispatch(FuncRequest(LFUN_CHANGE_NEXT));
88 }
89
90
91 void GuiChanges::previousChange()
92 {
93         dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
94 }
95
96
97 void GuiChanges::acceptChange()
98 {
99         dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
100         nextChange();
101 }
102
103
104 void GuiChanges::rejectChange()
105 {
106         dispatch(FuncRequest(LFUN_CHANGE_REJECT));
107         nextChange();
108 }
109
110
111 Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
112
113
114 } // namespace frontend
115 } // namespace lyx
116
117 #include "moc_GuiChanges.cpp"