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