Mercurial > hg > easyhg
comparison hgexpwidget.cpp @ 0:a9098eba2ee5
Initial commit.
author | Jari Korhonen <jtkorhonen@gmail.com> |
---|---|
date | Thu, 22 Apr 2010 03:15:35 +0300 |
parents | |
children | 39bbb7b00934 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a9098eba2ee5 |
---|---|
1 //** Copyright (C) Jari Korhonen, 2010 (under lgpl) | |
2 | |
3 #include <QtGui> | |
4 | |
5 #include "hgexpwidget.h" | |
6 #include "common.h" | |
7 | |
8 #define REMOTE_REPO_STR "Remote repository: " | |
9 #define LOCAL_REPO_STR "Local repository: " | |
10 #define WORKFOLDER_STR "Working folder: " | |
11 | |
12 | |
13 const char hgStatViewOptions[NUM_STAT_FILE_TYPES] = {'m','a','r','d','u','c','i'}; | |
14 | |
15 const char *statFilesStr[NUM_STAT_FILE_TYPES] = { "M: Modified", | |
16 "A: To be added on next commit", | |
17 "R: To be removed on next commit", | |
18 "!: Tracked, locally deleted", | |
19 "?: Unknown, not yet tracked", | |
20 "C: Clean (not changed)", | |
21 "I: Ignored (via .hgignore file)"}; | |
22 | |
23 | |
24 HgExpWidget::HgExpWidget(QWidget *parent, QString remoteRepo, QString workFolderPath, unsigned char viewFileTypesBits): QTabWidget(parent) | |
25 { | |
26 //Work page | |
27 //Work page | |
28 //Work page | |
29 | |
30 //Remote repo | |
31 grpRemoteRepo = new QGroupBox(tr(REMOTE_REPO_STR) + remoteRepo); | |
32 grpRemoteRepo -> setMinimumHeight(24); | |
33 | |
34 //Local Repo | |
35 grpLocalRepo = new QGroupBox(tr(LOCAL_REPO_STR) + workFolderPath + getHgDirName()); | |
36 parentsLabel = new QLabel(tr("Working folder parent(s):")); | |
37 localRepoHgParentsList = new QListWidget; | |
38 localRepoHgParentsList -> setSelectionMode(QAbstractItemView::NoSelection); | |
39 parentsLayout = new QVBoxLayout; | |
40 parentsLayout -> addWidget(parentsLabel); | |
41 parentsLayout -> addWidget(localRepoHgParentsList); | |
42 grpLocalRepo -> setLayout(parentsLayout); | |
43 | |
44 //Workfolder | |
45 grpWorkFolder = new QGroupBox(tr(WORKFOLDER_STR) + workFolderPath); | |
46 workFolderLayout = new QHBoxLayout; | |
47 workFolderFileList = new QListWidget; | |
48 workFolderFileList -> setSelectionMode(QAbstractItemView::SingleSelection); | |
49 grpViewFileTypes = new QGroupBox; | |
50 fileTypesLayout = new QVBoxLayout; | |
51 | |
52 for(int i = 0; i < NUM_STAT_FILE_TYPES; i++) | |
53 { | |
54 chkViewFileTypes[i] = new QCheckBox(statFilesStr[i]); | |
55 if ((1U << i) & viewFileTypesBits) | |
56 { | |
57 chkViewFileTypes[i]->setChecked(true); | |
58 } | |
59 else | |
60 { | |
61 chkViewFileTypes[i]->setChecked(false); | |
62 } | |
63 connect(chkViewFileTypes[i], SIGNAL(stateChanged(int)), this, SIGNAL(workFolderViewTypesChanged())); | |
64 fileTypesLayout -> addWidget(chkViewFileTypes[i]); | |
65 } | |
66 | |
67 grpViewFileTypes -> setLayout(fileTypesLayout); | |
68 workFolderLayout->addWidget(workFolderFileList, 3); | |
69 workFolderLayout->addWidget(grpViewFileTypes, 1); | |
70 grpWorkFolder -> setLayout(workFolderLayout); | |
71 | |
72 workPageWidget = new QWidget; | |
73 mainLayout = new QVBoxLayout(workPageWidget); | |
74 mainLayout -> addWidget(grpRemoteRepo, 1); | |
75 mainLayout -> addWidget(grpLocalRepo, 8); | |
76 mainLayout -> addWidget(grpWorkFolder, 12); | |
77 addTab(workPageWidget, tr("Work")); | |
78 | |
79 //History page | |
80 //History page | |
81 //History page | |
82 historyPageWidget = new QWidget; | |
83 localRepoHgLogList = new QListWidget; | |
84 localRepoHgLogList->setFont(QFont("Courier New")); | |
85 localRepoHgLogList -> setSelectionMode(QAbstractItemView::ExtendedSelection); | |
86 | |
87 historyLayout = new QVBoxLayout(historyPageWidget); | |
88 historyLayout->addWidget(localRepoHgLogList); | |
89 addTab(historyPageWidget, tr("History (log)")); | |
90 | |
91 //Heads page | |
92 //Heads page | |
93 //Heads page | |
94 headsPageWidget = new QWidget; | |
95 localRepoHeadsList = new QListWidget; | |
96 localRepoHeadsList -> setSelectionMode(QAbstractItemView::ExtendedSelection); | |
97 | |
98 headsLayout = new QVBoxLayout(headsPageWidget); | |
99 headsLayout->addWidget(localRepoHeadsList); | |
100 addTab(headsPageWidget, tr("Heads")); | |
101 | |
102 //Initially, only work page is active | |
103 setTabEnabled(HEADSTAB, false); | |
104 setTabEnabled(HISTORYTAB, false); | |
105 } | |
106 | |
107 | |
108 QString HgExpWidget::getStatFlags() | |
109 { | |
110 QString ret; | |
111 | |
112 for(int i = 0; i < NUM_STAT_FILE_TYPES; i++) | |
113 { | |
114 if (Qt::Checked == chkViewFileTypes[i]->checkState()) | |
115 { | |
116 ret += hgStatViewOptions[i]; | |
117 } | |
118 } | |
119 | |
120 return ret; | |
121 } | |
122 | |
123 | |
124 unsigned char HgExpWidget::getFileTypesBits() | |
125 { | |
126 unsigned char ret; | |
127 | |
128 ret = 0; | |
129 | |
130 for(int i = 0; i < NUM_STAT_FILE_TYPES; i++) | |
131 { | |
132 if (Qt::Checked == chkViewFileTypes[i]->checkState()) | |
133 { | |
134 ret |= (1U << i); | |
135 } | |
136 } | |
137 | |
138 return ret; | |
139 } | |
140 | |
141 | |
142 void HgExpWidget::updateWorkFolderFileList(QString fileList) | |
143 { | |
144 workFolderFileList-> clear(); | |
145 workFolderFileList -> addItems(fileList.split("\n")); | |
146 } | |
147 | |
148 void HgExpWidget::updateLocalRepoHeadsList(QString headList) | |
149 { | |
150 localRepoHeadsList-> clear(); | |
151 localRepoHeadsList -> addItems(splitChangeSets(headList)); | |
152 | |
153 //heads list is interesting only when we have 2 or more | |
154 if (localRepoHeadsList-> count() < 2) | |
155 { | |
156 setTabEnabled(HEADSTAB, false); | |
157 } | |
158 else | |
159 { | |
160 setTabEnabled(HEADSTAB, true); | |
161 } | |
162 } | |
163 | |
164 | |
165 void HgExpWidget::clearLists() | |
166 { | |
167 localRepoHeadsList-> clear(); | |
168 localRepoHgParentsList-> clear(); | |
169 workFolderFileList-> clear(); | |
170 localRepoHgLogList -> clear(); | |
171 } | |
172 | |
173 void HgExpWidget::updateLocalRepoParentsList(QString parentsList) | |
174 { | |
175 localRepoHgParentsList-> clear(); | |
176 localRepoHgParentsList -> addItems(splitChangeSets(parentsList)); | |
177 } | |
178 | |
179 void HgExpWidget::updateLocalRepoHgLogList(QString hgLogList) | |
180 { | |
181 localRepoHgLogList -> clear(); | |
182 localRepoHgLogList -> addItems(splitChangeSets(hgLogList)); | |
183 | |
184 } | |
185 | |
186 | |
187 int HgExpWidget::findLineStart(int nowIndex, QString str) | |
188 { | |
189 if (nowIndex < 0) | |
190 { | |
191 return -1; | |
192 } | |
193 | |
194 while(str.at(nowIndex) != '\n') | |
195 { | |
196 if (nowIndex == 0) | |
197 { | |
198 return nowIndex; | |
199 } | |
200 nowIndex--; | |
201 } | |
202 return nowIndex + 1; | |
203 } | |
204 | |
205 | |
206 QStringList HgExpWidget::splitChangeSets(QString chgSetsStr) | |
207 { | |
208 int currChgSet; | |
209 int currChgSetLineStart; | |
210 | |
211 int prevChgSet; | |
212 QStringList tmp; | |
213 | |
214 currChgSet = chgSetsStr.indexOf(CHGSET); | |
215 currChgSetLineStart = findLineStart(currChgSet, chgSetsStr); | |
216 prevChgSet = -1; | |
217 while (currChgSet != -1) | |
218 { | |
219 if (prevChgSet != -1) | |
220 { | |
221 tmp.append(chgSetsStr.mid(prevChgSet, (currChgSetLineStart - prevChgSet - 1))); | |
222 } | |
223 | |
224 prevChgSet = currChgSetLineStart; | |
225 | |
226 currChgSet = chgSetsStr.indexOf(CHGSET, currChgSet + 1); | |
227 currChgSetLineStart = findLineStart(currChgSet, chgSetsStr); | |
228 } | |
229 | |
230 if (prevChgSet != -1) | |
231 { | |
232 //Last changeset | |
233 tmp.append(chgSetsStr.mid(prevChgSet)); | |
234 } | |
235 else | |
236 { | |
237 //Only changeset (if any) | |
238 if (!chgSetsStr.isEmpty()) | |
239 { | |
240 tmp.append(chgSetsStr.mid(0)); | |
241 } | |
242 } | |
243 | |
244 return tmp; | |
245 } | |
246 | |
247 QString HgExpWidget::getCurrentFileListLine() | |
248 { | |
249 if (workFolderFileList -> currentItem() != NULL) | |
250 { | |
251 return workFolderFileList -> currentItem()->text(); | |
252 } | |
253 return ""; | |
254 } | |
255 | |
256 void HgExpWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath) | |
257 { | |
258 grpRemoteRepo -> setTitle(tr(REMOTE_REPO_STR) + remoteRepoPath); | |
259 grpLocalRepo -> setTitle(tr(LOCAL_REPO_STR) + workFolderPath + getHgDirName()); | |
260 grpWorkFolder -> setTitle(tr(WORKFOLDER_STR) + workFolderPath); | |
261 } | |
262 | |
263 #define MERC_SHA1_MARKER_LEN 12 | |
264 QString HgExpWidget::findRev(QString itemText, QString & smallRev) | |
265 { | |
266 QString tmp(itemText); | |
267 int i; | |
268 int j; | |
269 | |
270 smallRev ="0"; | |
271 | |
272 i = tmp.indexOf(CHGSET); | |
273 if (i != -1) | |
274 { | |
275 j = i + 10; | |
276 i = tmp.indexOf(":", j); //xx:yyyyyy after changeset: | |
277 | |
278 if (i != -1) | |
279 { | |
280 smallRev = tmp.mid(j, (i-j)); | |
281 return tmp.mid(i+1, MERC_SHA1_MARKER_LEN); | |
282 } | |
283 } | |
284 | |
285 return ""; | |
286 } | |
287 | |
288 void HgExpWidget::getHistoryDiffRevisions(QString& revA, QString& revB) | |
289 { | |
290 QList <QListWidgetItem *> histList = localRepoHgLogList->selectedItems(); | |
291 QList <QListWidgetItem *> headList = localRepoHeadsList->selectedItems(); | |
292 | |
293 QString revATmp; | |
294 QString revBTmp; | |
295 QString smallRevA; | |
296 QString smallRevB; | |
297 QString txtA; | |
298 QString txtB; | |
299 | |
300 if (histList.count() == REQUIRED_CHGSET_DIFF_COUNT) | |
301 { | |
302 txtA = histList.last()->text(); | |
303 txtB = histList.first()->text(); | |
304 | |
305 } | |
306 else if (headList.count() == REQUIRED_CHGSET_DIFF_COUNT) | |
307 { | |
308 txtA = headList.last()->text(); | |
309 txtB = headList.first()->text(); | |
310 } | |
311 else | |
312 { | |
313 revA = ""; | |
314 revB = ""; | |
315 return; | |
316 } | |
317 | |
318 revATmp = findRev(txtA, smallRevA); | |
319 revBTmp = findRev(txtB, smallRevB); | |
320 | |
321 //Switch order according to repo small revision number (user can select items from list in "wrong" order) | |
322 if (smallRevB.toULongLong() > smallRevA.toULongLong()) | |
323 { | |
324 revA = revATmp; | |
325 revB = revBTmp; | |
326 } | |
327 else | |
328 { | |
329 revA = revBTmp; | |
330 revB = revATmp; | |
331 } | |
332 } | |
333 | |
334 | |
335 void HgExpWidget::getUpdateToRevRevision(QString& rev) | |
336 { | |
337 QList <QListWidgetItem *> histList = localRepoHgLogList->selectedItems(); | |
338 QString txt; | |
339 QString smallRev; | |
340 | |
341 | |
342 if (histList.count() == 1) | |
343 { | |
344 txt = histList.first()->text(); | |
345 rev = findRev(txt, smallRev); | |
346 } | |
347 else | |
348 { | |
349 rev = ""; | |
350 } | |
351 } | |
352 | |
353 | |
354 | |
355 void HgExpWidget::enableDisableOtherTabs() | |
356 { | |
357 //history list is only interesting when we have something in it ;-) | |
358 if (localRepoHgLogList -> count() < 2) | |
359 { | |
360 setTabEnabled(HISTORYTAB, false); | |
361 } | |
362 else | |
363 { | |
364 setTabEnabled(HISTORYTAB, true); | |
365 } | |
366 | |
367 //history list is only interesting when we have something in it ;-) | |
368 if (localRepoHgLogList -> count() < 2) | |
369 { | |
370 setTabEnabled(HISTORYTAB, false); | |
371 } | |
372 else | |
373 { | |
374 setTabEnabled(HISTORYTAB, true); | |
375 } | |
376 } | |
377 | |
378 | |
379 | |
380 |