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