comparison hgexpwidget.cpp @ 91:879af4608c5e

* Remove some old code in preparation for rebuilding it with the newer structure
author Chris Cannam
date Tue, 23 Nov 2010 21:04:02 +0000
parents b43355c2473a
children 06f4fffd5287
comparison
equal deleted inserted replaced
90:b43355c2473a 91:879af4608c5e
29 #include <QContextMenuEvent> 29 #include <QContextMenuEvent>
30 #include <QApplication> 30 #include <QApplication>
31 31
32 #include <iostream> 32 #include <iostream>
33 33
34 #define REMOTE_REPO_STR "Remote repository: "
35 #define LOCAL_REPO_STR "Local repository: "
36 #define WORKFOLDER_STR "Working folder: "
37
38
39 const char hgStatViewOptions[NUM_STAT_FILE_TYPES] = {'m','a','r','d','u','c','i'};
40
41 const char *statFilesStr[NUM_STAT_FILE_TYPES] = { "M: Modified",
42 "A: To be added on next commit",
43 "R: To be removed on next commit",
44 "!: Tracked, locally deleted",
45 "?: Unknown, not yet tracked",
46 "C: Clean (not changed)",
47 "I: Ignored (via .hgignore file)"};
48
49
50 HgExpWidget::HgExpWidget(QWidget *parent, QString remoteRepo, 34 HgExpWidget::HgExpWidget(QWidget *parent, QString remoteRepo,
51 QString workFolderPath, 35 QString workFolderPath,
52 unsigned char viewFileTypesBits) : 36 unsigned char viewFileTypesBits) :
53 QTabWidget(parent) 37 QTabWidget(parent)
54 { 38 {
55 //Work page 39 // Work page
56 //Work page
57 //Work page
58
59 //Remote repo
60 grpRemoteRepo = new QGroupBox(tr(REMOTE_REPO_STR) + remoteRepo);
61 grpRemoteRepo -> setMinimumHeight(24);
62
63 //Local Repo
64 grpLocalRepo = new QGroupBox(tr(LOCAL_REPO_STR) + workFolderPath + getHgDirName());
65 parentsLabel = new QLabel(tr("Working folder parent(s):"));
66 localRepoHgParentsList = new QListWidget;
67 localRepoHgParentsList -> setSelectionMode(QAbstractItemView::NoSelection);
68 parentsLayout = new QVBoxLayout;
69 parentsLayout -> addWidget(parentsLabel);
70 parentsLayout -> addWidget(localRepoHgParentsList);
71 grpLocalRepo -> setLayout(parentsLayout);
72 copyCommentAct = new QAction("Copy comment", localRepoHgParentsList);
73 userListMenu = new QMenu(localRepoHgParentsList);
74 userListMenu -> addAction(copyCommentAct);
75 connect(copyCommentAct, SIGNAL(triggered()), this, SLOT(copyComment()));
76
77 //Workfolder
78 grpWorkFolder = new QGroupBox(tr(WORKFOLDER_STR) + workFolderPath);
79 workFolderLayout = new QHBoxLayout;
80 workFolderFileList = new QListWidget;
81 workFolderFileList -> setSelectionMode(QAbstractItemView::ExtendedSelection);
82 grpViewFileTypes = new QGroupBox;
83 fileTypesLayout = new QVBoxLayout;
84
85 for(int i = 0; i < NUM_STAT_FILE_TYPES; i++)
86 {
87 chkViewFileTypes[i] = new QCheckBox(statFilesStr[i]);
88 if ((1U << i) & viewFileTypesBits)
89 {
90 chkViewFileTypes[i]->setChecked(true);
91 }
92 else
93 {
94 chkViewFileTypes[i]->setChecked(false);
95 }
96 connect(chkViewFileTypes[i], SIGNAL(stateChanged(int)), this, SIGNAL(workFolderViewTypesChanged()));
97 fileTypesLayout -> addWidget(chkViewFileTypes[i]);
98 }
99
100 grpViewFileTypes -> setLayout(fileTypesLayout);
101 workFolderLayout->addWidget(workFolderFileList, 3);
102 workFolderLayout->addWidget(grpViewFileTypes, 1);
103 grpWorkFolder -> setLayout(workFolderLayout);
104
105 workPageWidget = new QWidget;
106 mainLayout = new QVBoxLayout(workPageWidget);
107 mainLayout -> addWidget(grpRemoteRepo, 1);
108 mainLayout -> addWidget(grpLocalRepo, 8);
109 mainLayout -> addWidget(grpWorkFolder, 12);
110 //!!! addTab(workPageWidget, tr("My work"));
111
112 // New work page
113 fileStatusWidget = new FileStatusWidget; 40 fileStatusWidget = new FileStatusWidget;
114 fileStatusWidget->setLocalPath(workFolderPath); 41 fileStatusWidget->setLocalPath(workFolderPath);
115 fileStatusWidget->setRemoteURL(remoteRepo); 42 fileStatusWidget->setRemoteURL(remoteRepo);
116 addTab(fileStatusWidget, tr("My work")); 43 addTab(fileStatusWidget, tr("My work"));
117 44
126 layout->addWidget(historyGraphPanner, 0, 1); 53 layout->addWidget(historyGraphPanner, 0, 1);
127 panner->setMaximumWidth(80); 54 panner->setMaximumWidth(80);
128 panner->connectToPanned(panned); 55 panner->connectToPanned(panned);
129 historyGraphPageWidget->setLayout(layout); 56 historyGraphPageWidget->setLayout(layout);
130 addTab(historyGraphPageWidget, tr("History")); 57 addTab(historyGraphPageWidget, tr("History"));
131
132
133 //History page
134 //History page
135 //History page
136 historyPageWidget = new QWidget;
137 localRepoHgLogList = new QListWidget;
138 localRepoHgLogList->setFont(QFont("Courier New"));
139 localRepoHgLogList -> setSelectionMode(QAbstractItemView::ExtendedSelection);
140
141 historyLayout = new QVBoxLayout(historyPageWidget);
142 historyLayout->addWidget(localRepoHgLogList);
143 //!!! addTab(historyPageWidget, tr("History (log)"));
144
145 //Heads page
146 //Heads page
147 //Heads page
148 headsPageWidget = new QWidget;
149 localRepoHeadsList = new QListWidget;
150 localRepoHeadsList -> setSelectionMode(QAbstractItemView::ExtendedSelection);
151
152 headsLayout = new QVBoxLayout(headsPageWidget);
153 headsLayout->addWidget(localRepoHeadsList);
154 //!!! addTab(headsPageWidget, tr("Heads"));
155
156 //Initially, only work page is active
157 //!!! setTabEnabled(HEADSTAB, false);
158 //!!! setTabEnabled(HISTORYTAB, false);
159 }
160
161 void HgExpWidget::contextMenuEvent(QContextMenuEvent * event)
162 {
163 if (copyCommentAct -> isEnabled())
164 {
165 QPoint topL;
166 QPoint bottomR;
167
168 topL = localRepoHgParentsList->
169 mapToGlobal(QPoint(0, 0));
170 bottomR = localRepoHgParentsList->
171 mapToGlobal(QPoint(localRepoHgParentsList -> width(), localRepoHgParentsList -> height()));
172
173 if ((event -> globalPos().x() > topL.x()) && (event -> globalPos().x() < bottomR.x()))
174 {
175 if ((event -> globalPos().y() > topL.y()) && (event -> globalPos().y() < bottomR.y()))
176 {
177 userListMenu->exec(event -> globalPos());
178 }
179 }
180 }
181 }
182
183 void HgExpWidget::copyComment()
184 {
185 if (localRepoHgParentsList -> count() >= 1)
186 {
187 QListWidgetItem *it = localRepoHgParentsList -> item(0);
188 QString tmp = it -> text();
189 int ind = tmp.indexOf("summary:");
190 if (ind != -1)
191 {
192 QString comment;
193 ind += 11; //jump over word "summary:"
194
195 comment = tmp.mid(ind);
196
197 QClipboard *clipboard = QApplication::clipboard();
198 clipboard->setText(comment);
199 }
200 }
201 } 58 }
202 59
203 bool HgExpWidget::canCommit() const 60 bool HgExpWidget::canCommit() const
204 { 61 {
205 return fileStatusWidget->haveChangesToCommit(); 62 return fileStatusWidget->haveChangesToCommit();
206 } 63 }
207 64
208 QString HgExpWidget::getStatFlags()
209 {
210 QString ret;
211
212 for(int i = 0; i < NUM_STAT_FILE_TYPES; i++)
213 {
214 if (Qt::Checked == chkViewFileTypes[i]->checkState())
215 {
216 ret += hgStatViewOptions[i];
217 }
218 }
219
220 return ret;
221 }
222
223
224 unsigned char HgExpWidget::getFileTypesBits()
225 {
226 unsigned char ret;
227
228 ret = 0;
229
230 for(int i = 0; i < NUM_STAT_FILE_TYPES; i++)
231 {
232 if (Qt::Checked == chkViewFileTypes[i]->checkState())
233 {
234 ret |= (1U << i);
235 }
236 }
237
238 return ret;
239 }
240
241
242 void HgExpWidget::updateWorkFolderFileList(QString fileList) 65 void HgExpWidget::updateWorkFolderFileList(QString fileList)
243 { 66 {
244 statParser = StatParser(fileList); 67 statParser = StatParser(fileList);
245
246 fileStatusWidget->setStatParser(statParser); 68 fileStatusWidget->setStatParser(statParser);
247
248 workFolderFileList-> clear();
249 workFolderFileList -> addItems(fileList.split("\n"));
250 }
251
252 void HgExpWidget::updateLocalRepoHeadsList(QString headList)
253 {
254 localRepoHeadsList-> clear();
255 localRepoHeadsList -> addItems(splitChangeSets(headList));
256
257 //heads list is interesting only when we have 2 or more
258 if (localRepoHeadsList-> count() < 2)
259 {
260 setTabEnabled(HEADSTAB, false);
261 }
262 else
263 {
264 setTabEnabled(HEADSTAB, true);
265 }
266 }
267
268
269 void HgExpWidget::clearLists()
270 {
271 localRepoHeadsList-> clear();
272 localRepoHgParentsList-> clear();
273 workFolderFileList-> clear();
274 localRepoHgLogList -> clear();
275 }
276
277 void HgExpWidget::updateLocalRepoParentsList(QString parentsList)
278 {
279 localRepoHgParentsList-> clear();
280 localRepoHgParentsList -> addItems(splitChangeSets(parentsList));
281 } 69 }
282 70
283 void HgExpWidget::updateLocalRepoHgLogList(QString hgLogList) 71 void HgExpWidget::updateLocalRepoHgLogList(QString hgLogList)
284 { 72 {
285 localRepoHgLogList -> clear();
286 localRepoHgLogList -> addItems(splitChangeSets(hgLogList));
287
288 //!!! 73 //!!!
289 Panned *panned = static_cast<Panned *>(historyGraphWidget); 74 Panned *panned = static_cast<Panned *>(historyGraphWidget);
290 Panner *panner = static_cast<Panner *>(historyGraphPanner); 75 Panner *panner = static_cast<Panner *>(historyGraphPanner);
291 QGraphicsScene *scene = new QGraphicsScene(); 76 QGraphicsScene *scene = new QGraphicsScene();
292 Changesets csets = parseChangeSets(hgLogList); 77 Changesets csets = parseChangeSets(hgLogList);
301 panned->setScene(scene); 86 panned->setScene(scene);
302 panner->setScene(scene); 87 panner->setScene(scene);
303 if (oldScene) delete oldScene; 88 if (oldScene) delete oldScene;
304 ChangesetItem *tipItem = g.getItemFor(csets[0]); 89 ChangesetItem *tipItem = g.getItemFor(csets[0]);
305 if (tipItem) tipItem->ensureVisible(); 90 if (tipItem) tipItem->ensureVisible();
306 }
307
308
309
310 int HgExpWidget::findLineStart(int nowIndex, QString str)
311 {
312 if (nowIndex < 0)
313 {
314 return -1;
315 }
316
317 while(str.at(nowIndex) != '\n')
318 {
319 if (nowIndex == 0)
320 {
321 return nowIndex;
322 }
323 nowIndex--;
324 }
325 return nowIndex + 1;
326 }
327
328
329 QStringList HgExpWidget::splitChangeSets(QString chgSetsStr)
330 {
331 return LogParser(chgSetsStr).split();
332 /*
333 int currChgSet;
334 int currChgSetLineStart;
335
336 int prevChgSet;
337 QStringList tmp;
338
339 currChgSet = chgSetsStr.indexOf(CHGSET);
340 currChgSetLineStart = findLineStart(currChgSet, chgSetsStr);
341 prevChgSet = -1;
342 while (currChgSet != -1)
343 {
344 if (prevChgSet != -1)
345 {
346 tmp.append(chgSetsStr.mid(prevChgSet, (currChgSetLineStart - prevChgSet - 1)));
347 }
348
349 prevChgSet = currChgSetLineStart;
350
351 currChgSet = chgSetsStr.indexOf(CHGSET, currChgSet + 1);
352 currChgSetLineStart = findLineStart(currChgSet, chgSetsStr);
353 }
354
355 if (prevChgSet != -1)
356 {
357 //Last changeset
358 tmp.append(chgSetsStr.mid(prevChgSet));
359 }
360 else
361 {
362 //Only changeset (if any)
363 if (!chgSetsStr.isEmpty())
364 {
365 tmp.append(chgSetsStr.mid(0));
366 }
367 }
368
369 return tmp;
370 */
371 } 91 }
372 92
373 Changesets HgExpWidget::parseChangeSets(QString changeSetsStr) 93 Changesets HgExpWidget::parseChangeSets(QString changeSetsStr)
374 { 94 {
375 Changesets csets; 95 Changesets csets;
398 } 118 }
399 } 119 }
400 return csets; 120 return csets;
401 } 121 }
402 122
403 QString HgExpWidget::getCurrentFileListLine()
404 {
405 if (workFolderFileList -> currentItem() != NULL)
406 {
407 return workFolderFileList -> currentItem()->text();
408 }
409 return "";
410 }
411
412 void HgExpWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath) 123 void HgExpWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath)
413 { 124 {
414 grpRemoteRepo -> setTitle(tr(REMOTE_REPO_STR) + remoteRepoPath);
415 grpLocalRepo -> setTitle(tr(LOCAL_REPO_STR) + workFolderPath + getHgDirName());
416 grpWorkFolder -> setTitle(tr(WORKFOLDER_STR) + workFolderPath);
417
418 fileStatusWidget->setLocalPath(workFolderPath); 125 fileStatusWidget->setLocalPath(workFolderPath);
419 fileStatusWidget->setRemoteURL(remoteRepoPath); 126 fileStatusWidget->setRemoteURL(remoteRepoPath);
420 } 127 }
421
422 #define MERC_SHA1_MARKER_LEN 12
423 QString HgExpWidget::findRev(QString itemText, QString & smallRev)
424 {
425 QString tmp(itemText);
426 int i;
427 int j;
428
429 smallRev ="0";
430
431 i = tmp.indexOf(CHGSET);
432 if (i != -1)
433 {
434 j = i + 10;
435 i = tmp.indexOf(":", j); //xx:yyyyyy after changeset:
436
437 if (i != -1)
438 {
439 smallRev = tmp.mid(j, (i-j));
440 return tmp.mid(i+1, MERC_SHA1_MARKER_LEN);
441 }
442 }
443
444 return "";
445 }
446
447 void HgExpWidget::getHistoryDiffRevisions(QString& revA, QString& revB)
448 {
449 QList <QListWidgetItem *> histList = localRepoHgLogList->selectedItems();
450 QList <QListWidgetItem *> headList = localRepoHeadsList->selectedItems();
451
452 QString revATmp;
453 QString revBTmp;
454 QString smallRevA;
455 QString smallRevB;
456 QString txtA;
457 QString txtB;
458
459 if (histList.count() == REQUIRED_CHGSET_DIFF_COUNT)
460 {
461 txtA = histList.last()->text();
462 txtB = histList.first()->text();
463
464 }
465 else if (headList.count() == REQUIRED_CHGSET_DIFF_COUNT)
466 {
467 txtA = headList.last()->text();
468 txtB = headList.first()->text();
469 }
470 else
471 {
472 revA = "";
473 revB = "";
474 return;
475 }
476
477 revATmp = findRev(txtA, smallRevA);
478 revBTmp = findRev(txtB, smallRevB);
479
480 //Switch order according to repo small revision number (user can select items from list in "wrong" order)
481 if (smallRevB.toULongLong() > smallRevA.toULongLong())
482 {
483 revA = revATmp;
484 revB = revBTmp;
485 }
486 else
487 {
488 revA = revBTmp;
489 revB = revATmp;
490 }
491 }
492
493
494 void HgExpWidget::getUpdateToRevRevision(QString& rev)
495 {
496 QList <QListWidgetItem *> histList = localRepoHgLogList->selectedItems();
497 QString txt;
498 QString smallRev;
499
500
501 if (histList.count() == 1)
502 {
503 txt = histList.first()->text();
504 rev = findRev(txt, smallRev);
505 }
506 else
507 {
508 rev = "";
509 }
510 }
511
512
513 void HgExpWidget::enableDisableOtherTabs(int tabPage)
514 {
515 static int oldTabPage = -1;
516
517 if (tabPage != oldTabPage)
518 {
519 oldTabPage = tabPage;
520 if (tabPage == WORKTAB)
521 {
522 copyCommentAct -> setEnabled(true);
523 }
524 else
525 {
526 copyCommentAct -> setEnabled(false);
527 }
528 }
529
530 //history list is only interesting when we have something in it ;-)
531 if (localRepoHgLogList -> count() < 2)
532 {
533 setTabEnabled(HISTORYTAB, false);
534 }
535 else
536 {
537 setTabEnabled(HISTORYTAB, true);
538 }
539
540 //history list is only interesting when we have something in it ;-)
541 if (localRepoHgLogList -> count() < 2)
542 {
543 setTabEnabled(HISTORYTAB, false);
544 }
545 else
546 {
547 setTabEnabled(HISTORYTAB, true);
548 }
549 }
550
551
552
553