]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiChanges.cpp
remove unneeded header.
[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 <QTextBrowser>
31
32
33 namespace lyx {
34 namespace frontend {
35
36 using support::bformat;
37
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(rejectPB, SIGNAL(clicked()), this, SLOT(rejectChange()));
46         connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptChange()));
47
48         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
49         bc().setCancel(closePB);
50         bc().addReadOnly(acceptPB);
51         bc().addReadOnly(rejectPB);
52 }
53
54
55 void GuiChanges::updateContents()
56 {
57         docstring text;
58         docstring author = changeAuthor();
59         docstring date = changeDate();
60
61         if (!author.empty())
62                 text += bformat(_("Change by %1$s\n\n"), author);
63         if (!date.empty())
64                 text += bformat(_("Change made at %1$s\n"), date);
65
66         changeTB->setPlainText(toqstr(text));
67 }
68
69
70 void GuiChanges::nextChange()
71 {
72         dispatch(FuncRequest(LFUN_CHANGE_NEXT));
73 }
74
75
76 docstring GuiChanges::changeDate() const
77 {
78         Change const & c = bufferview()->getCurrentChange();
79         if (c.type == Change::UNCHANGED)
80                 return docstring();
81
82         // FIXME UNICODE
83         return from_utf8(formatted_time(c.changetime, lyxrc.date_insert_format));
84 }
85
86
87 docstring GuiChanges::changeAuthor() const
88 {
89         Change const & c = bufferview()->getCurrentChange();
90         if (c.type == Change::UNCHANGED)
91                 return docstring();
92
93         Author const & a = buffer().params().authors().get(c.author);
94
95         docstring author = a.name();
96
97         if (!a.email().empty())
98                 author += " (" + a.email() + ")";
99
100         return author;
101 }
102
103
104 void GuiChanges::acceptChange()
105 {
106         dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
107         nextChange();
108 }
109
110
111 void GuiChanges::rejectChange()
112 {
113         dispatch(FuncRequest(LFUN_CHANGE_REJECT));
114         nextChange();
115 }
116
117
118 Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
119
120
121 } // namespace frontend
122 } // namespace lyx
123
124 #include "moc_GuiChanges.cpp"