]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiChanges.cpp
Transfer some more dialog related code from core to frontend:
[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/lstrings.h"
19 #include "support/lyxtime.h"
20
21 #include "Author.h"
22 #include "Buffer.h"
23 #include "BufferParams.h"
24 #include "BufferView.h"
25 #include "Changes.h"
26 #include "FuncRequest.h"
27 #include "lyxfind.h"
28 #include "LyXRC.h"
29
30 #include <QCloseEvent>
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")
41 {
42         setupUi(this);
43         setViewTitle(_("Merge Changes"));
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::closeEvent(QCloseEvent *e)
58 {
59         slotClose();
60         e->accept();
61 }
62
63
64 void GuiChanges::updateContents()
65 {
66         docstring text;
67         docstring author = changeAuthor();
68         docstring date = changeDate();
69
70         if (!author.empty())
71                 text += bformat(_("Change by %1$s\n\n"), author);
72         if (!date.empty())
73                 text += bformat(_("Change made at %1$s\n"), date);
74
75         changeTB->setPlainText(toqstr(text));
76 }
77
78
79 void GuiChanges::nextChange()
80 {
81         dispatch(FuncRequest(LFUN_CHANGE_NEXT));
82 }
83
84
85 docstring GuiChanges::changeDate() const
86 {
87         Change const & c = bufferview()->getCurrentChange();
88         if (c.type == Change::UNCHANGED)
89                 return docstring();
90
91         // FIXME UNICODE
92         return from_utf8(formatted_time(c.changetime, lyxrc.date_insert_format));
93 }
94
95
96 docstring GuiChanges::changeAuthor() const
97 {
98         Change const & c = bufferview()->getCurrentChange();
99         if (c.type == Change::UNCHANGED)
100                 return docstring();
101
102         Author const & a = buffer().params().authors().get(c.author);
103
104         docstring author = a.name();
105
106         if (!a.email().empty())
107                 author += " (" + a.email() + ")";
108
109         return author;
110 }
111
112
113 void GuiChanges::acceptChange()
114 {
115         dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
116         nextChange();
117 }
118
119
120 void GuiChanges::rejectChange()
121 {
122         dispatch(FuncRequest(LFUN_CHANGE_REJECT));
123         nextChange();
124 }
125
126
127 Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
128
129
130 } // namespace frontend
131 } // namespace lyx
132
133 #include "GuiChanges_moc.cpp"