]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiChanges.cpp
* fix spelling in comments to please John.
[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(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
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 void GuiChanges::previousChange()
78 {
79         dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
80 }
81
82
83 docstring GuiChanges::changeDate() const
84 {
85         Change const & c = bufferview()->getCurrentChange();
86         if (c.type == Change::UNCHANGED)
87                 return docstring();
88
89         // FIXME UNICODE
90         return from_utf8(formatted_time(c.changetime, lyxrc.date_insert_format));
91 }
92
93
94 docstring GuiChanges::changeAuthor() const
95 {
96         Change const & c = bufferview()->getCurrentChange();
97         if (c.type == Change::UNCHANGED)
98                 return docstring();
99
100         Author const & a = buffer().params().authors().get(c.author);
101
102         docstring author = a.name();
103
104         if (!a.email().empty())
105                 author += " (" + a.email() + ")";
106
107         return author;
108 }
109
110
111 void GuiChanges::acceptChange()
112 {
113         dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
114         nextChange();
115 }
116
117
118 void GuiChanges::rejectChange()
119 {
120         dispatch(FuncRequest(LFUN_CHANGE_REJECT));
121         nextChange();
122 }
123
124
125 Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
126
127
128 } // namespace frontend
129 } // namespace lyx
130
131 #include "moc_GuiChanges.cpp"