]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiCompareHistory.cpp
Implement proper Dialog factory instead of implicit link-time dependencies
[lyx.git] / src / frontends / qt / GuiCompareHistory.cpp
1 /**
2  * \file GuiCompareHistory.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Pavel Sanda
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiCompareHistory.h"
14
15 #include "Buffer.h"
16 #include "BufferView.h"
17 #include "FuncRequest.h"
18 #include "GuiView.h"
19 #include "LyXVC.h"
20
21 #include "support/convert.h"
22 #include "support/debug.h"
23 #include "support/lstrings.h"
24
25 #include <QDialogButtonBox>
26 #include <QPushButton>
27
28 #include <limits>
29
30 using namespace std;
31 using namespace lyx::support;
32
33 namespace lyx {
34 namespace frontend {
35
36
37 GuiCompareHistory::GuiCompareHistory(GuiView & lv)
38         : GuiDialog(lv, "comparehistory", qt_("Compare different revisions"))
39
40 {
41         setupUi(this);
42         setModal(Qt::WindowModal);
43
44         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
45                 this, SLOT(slotButtonBox(QAbstractButton *)));
46
47         connect(revbackRB, SIGNAL(clicked()), this, SLOT(selectRevback()));
48         connect(betweenrevRB, SIGNAL(clicked()), this, SLOT(selectBetweenrev()));
49 }
50
51 bool GuiCompareHistory::initialiseParams(std::string const &)
52 {
53         string revstring = lyxview().currentBufferView()->buffer().lyxvc().revisionInfo(LyXVC::File);
54         int rev = 0;
55
56         string tmp;
57         bool enableBetween = true;
58         // GIT case, hash is long
59         if (revstring.length() > 20) {
60                 enableBetween = false;
61                 rev = numeric_limits<int>::max();
62         } else {
63                 // RCS case
64                 if (!isStrInt(revstring))
65                         revstring = rsplit(revstring, tmp , '.' );
66                 // both SVN & RCS cases
67                 if (isStrInt(revstring))
68                         rev = convert<int>(revstring);
69         }
70
71         // later we can provide comparison between two hashes
72         betweenrevRB->setEnabled(enableBetween);
73
74         buttonBox->button(QDialogButtonBox::Ok)->setEnabled(rev);
75         rev1SB->setMaximum(rev);
76         rev2SB->setMaximum(rev);
77         revbackSB->setMaximum(rev-1);
78         rev2SB->setValue(rev);
79         rev1SB->setValue(rev-1);
80
81         //bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
82         //bc().setOK(okPB);
83         //bc().setCancel(cancelPB);
84         enableControls();
85         return true;
86 }
87
88
89 void GuiCompareHistory::updateContents()
90 {
91         enableControls();
92 }
93
94
95 void GuiCompareHistory::selectRevback()
96 {
97         betweenrevRB->setChecked(false);
98         enableControls();
99 }
100
101
102 void GuiCompareHistory::selectBetweenrev()
103 {
104         revbackRB->setChecked(false);
105         enableControls();
106 }
107
108
109 void GuiCompareHistory::enableControls()
110 {
111         bool rb = revbackRB->isChecked();
112         oldL->setEnabled(!rb);
113         newL->setEnabled(!rb);
114         rev1SB->setEnabled(!rb);
115         rev2SB->setEnabled(!rb);
116         rev2SB->setEnabled(!rb);
117         betweenrevRB->setChecked(!rb);
118         revbackSB->setEnabled(rb);
119 }
120
121
122 void GuiCompareHistory::slotOK()
123 {
124         string param;
125         if (revbackRB->isChecked())
126                 param = "-" + convert<string>(revbackSB->value());
127         else
128                 param = convert<string>(rev1SB->value()) +
129                         + " " + convert<string>(rev2SB->value());
130
131         GuiDialog::slotClose();
132         dispatch(FuncRequest(LFUN_VC_COMPARE, param));
133 }
134
135
136 void GuiCompareHistory::slotCancel()
137 {
138         GuiDialog::slotClose();
139 }
140
141
142 void GuiCompareHistory::slotButtonBox(QAbstractButton * button)
143 {
144         switch (buttonBox->standardButton(button)) {
145         case QDialogButtonBox::Ok:
146                 slotOK();
147                 break;
148         case QDialogButtonBox::Cancel:
149                 slotCancel();
150                 break;
151         default:
152                 break;
153         }
154 }
155
156
157 } // namespace frontend
158 } // namespace lyx
159
160
161 #include "moc_GuiCompareHistory.cpp"