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