]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiChanges.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[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 "lyxfind.h"
29 #include "LyXRC.h"
30
31 #include <QTextBrowser>
32
33
34 namespace lyx {
35 namespace frontend {
36
37 using support::bformat;
38
39 GuiChanges::GuiChanges(GuiView & lv)
40         : GuiDialog(lv, "changes", qt_("Merge Changes"))
41 {
42         setupUi(this);
43
44         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
45         connect(nextPB, SIGNAL(clicked()), this, SLOT(nextChange()));
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
56 void GuiChanges::updateContents()
57 {
58         docstring text;
59         docstring author = changeAuthor();
60         docstring date = changeDate();
61
62         if (!author.empty())
63                 text += bformat(_("Change by %1$s\n\n"), author);
64         if (!date.empty())
65                 text += bformat(_("Change made at %1$s\n"), date);
66
67         changeTB->setPlainText(toqstr(text));
68 }
69
70
71 void GuiChanges::nextChange()
72 {
73         dispatch(FuncRequest(LFUN_CHANGE_NEXT));
74 }
75
76
77 docstring GuiChanges::changeDate() const
78 {
79         Change const & c = bufferview()->getCurrentChange();
80         if (c.type == Change::UNCHANGED)
81                 return docstring();
82
83         // FIXME UNICODE
84         return from_utf8(formatted_time(c.changetime, lyxrc.date_insert_format));
85 }
86
87
88 docstring GuiChanges::changeAuthor() const
89 {
90         Change const & c = bufferview()->getCurrentChange();
91         if (c.type == Change::UNCHANGED)
92                 return docstring();
93
94         Author const & a = buffer().params().authors().get(c.author);
95
96         docstring author = a.name();
97
98         if (!a.email().empty())
99                 author += " (" + a.email() + ")";
100
101         return author;
102 }
103
104
105 void GuiChanges::acceptChange()
106 {
107         dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
108         nextChange();
109 }
110
111
112 void GuiChanges::rejectChange()
113 {
114         dispatch(FuncRequest(LFUN_CHANGE_REJECT));
115         nextChange();
116 }
117
118
119 Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
120
121
122 } // namespace frontend
123 } // namespace lyx
124
125 #include "GuiChanges_moc.cpp"