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
GuiChanges(GuiView & lv)38 GuiChanges::GuiChanges(GuiView & lv)
39 : GuiDialog(lv, "changes", qt_("Merge Changes"))
40 {
41 setupUi(this);
42
43 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44 connect(nextPB, SIGNAL(clicked()), this, SLOT(nextChange()));
45 connect(previousPB, SIGNAL(clicked()), this, SLOT(previousChange()));
46 connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectChange()));
47 connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptChange()));
48
49 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
50 bc().setCancel(closePB);
51 bc().addReadOnly(acceptPB);
52 bc().addReadOnly(rejectPB);
53 }
54
55
updateContents()56 void GuiChanges::updateContents()
57 {
58 bool const changesPresent = buffer().areChangesPresent();
59 nextPB->setEnabled(changesPresent);
60 previousPB->setEnabled(changesPresent);
61 changeTB->setEnabled(changesPresent);
62
63 Change const & c = bufferview()->getCurrentChange();
64 bool const changePresent = c.type != Change::UNCHANGED;
65 rejectPB->setEnabled(changePresent);
66 acceptPB->setEnabled(changePresent);
67
68 QString text;
69 if (changePresent) {
70 QString const author =
71 toqstr(buffer().params().authors().get(c.author).nameAndEmail());
72 if (!author.isEmpty())
73 text += qt_("Changed by %1\n\n").arg(author);
74
75 QString const date = QDateTime::fromTime_t(c.changetime)
76 .toString(Qt::DefaultLocaleLongDate);
77 if (!date.isEmpty())
78 text += qt_("Change made on %1\n").arg(date);
79 }
80 changeTB->setPlainText(text);
81 }
82
83
nextChange()84 void GuiChanges::nextChange()
85 {
86 dispatch(FuncRequest(LFUN_CHANGE_NEXT));
87 }
88
89
previousChange()90 void GuiChanges::previousChange()
91 {
92 dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
93 }
94
95
acceptChange()96 void GuiChanges::acceptChange()
97 {
98 dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
99 nextChange();
100 }
101
102
rejectChange()103 void GuiChanges::rejectChange()
104 {
105 dispatch(FuncRequest(LFUN_CHANGE_REJECT));
106 nextChange();
107 }
108
109
createGuiChanges(GuiView & lv)110 Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
111
112
113 } // namespace frontend
114 } // namespace lyx
115
116 #include "moc_GuiChanges.cpp"
117