Mercurial > hg > easyhg
comparison mainwindow.cpp @ 62:68aebc316898
* Some adjustments to process running (avoid timer): caller must now report errors
* Function to find user's real name
* Locate hg executable in path explicitly, use a setting to remember it
author | Chris Cannam |
---|---|
date | Wed, 17 Nov 2010 13:32:56 +0000 |
parents | bf57a16315bd |
children | 2340b00561d2 |
comparison
equal
deleted
inserted
replaced
61:bf57a16315bd | 62:68aebc316898 |
---|---|
30 #include <QSettings> | 30 #include <QSettings> |
31 | 31 |
32 #include "mainwindow.h" | 32 #include "mainwindow.h" |
33 #include "settingsdialog.h" | 33 #include "settingsdialog.h" |
34 #include "colourset.h" | 34 #include "colourset.h" |
35 #include "debug.h" | |
35 | 36 |
36 | 37 |
37 MainWindow::MainWindow() | 38 MainWindow::MainWindow() |
38 { | 39 { |
39 QString wndTitle; | 40 QString wndTitle; |
41 createActions(); | 42 createActions(); |
42 createMenus(); | 43 createMenus(); |
43 createToolBars(); | 44 createToolBars(); |
44 createStatusBar(); | 45 createStatusBar(); |
45 | 46 |
46 timerId = startTimer(200); | |
47 runner = new HgRunner(this); | 47 runner = new HgRunner(this); |
48 connect(runner, SIGNAL(commandCompleted()), | |
49 this, SLOT(commandCompleted())); | |
50 connect(runner, SIGNAL(commandFailed()), | |
51 this, SLOT(commandFailed())); | |
48 runningAction = ACT_NONE; | 52 runningAction = ACT_NONE; |
49 statusBar()->addPermanentWidget(runner); | 53 statusBar()->addPermanentWidget(runner); |
50 | 54 |
51 setWindowTitle(tr("EasyMercurial")); | 55 setWindowTitle(tr("EasyMercurial")); |
52 | 56 |
67 if (firstStart) | 71 if (firstStart) |
68 { | 72 { |
69 QMessageBox::information(this, tr("First start todo"), tr("Going to \"Settings\" first.")); | 73 QMessageBox::information(this, tr("First start todo"), tr("Going to \"Settings\" first.")); |
70 settings(); | 74 settings(); |
71 } | 75 } |
76 | |
77 DEBUG << "User's real name is " << getUserRealName() << endl; | |
72 | 78 |
73 hgStat(); | 79 hgStat(); |
74 } | 80 } |
75 | 81 |
76 | 82 |
112 { | 118 { |
113 params << "stat" << "-" + statFlags; | 119 params << "stat" << "-" + statFlags; |
114 } | 120 } |
115 | 121 |
116 | 122 |
117 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 123 runner -> startHgCommand(workFolderPath, params); |
118 runningAction = ACT_STAT; | 124 runningAction = ACT_STAT; |
119 } | 125 } |
120 } | 126 } |
121 } | 127 } |
122 | 128 |
126 { | 132 { |
127 QStringList params; | 133 QStringList params; |
128 params << "heads"; | 134 params << "heads"; |
129 | 135 |
130 //on empty repos, "hg heads" will fail, don't care of that. | 136 //on empty repos, "hg heads" will fail, don't care of that. |
131 runner -> startProc(getHgBinaryName(), workFolderPath, params, false); | 137 runner -> startHgCommand(workFolderPath, params); |
132 runningAction = ACT_HEADS; | 138 runningAction = ACT_HEADS; |
133 } | 139 } |
134 } | 140 } |
135 | 141 |
136 void MainWindow::hgLog() | 142 void MainWindow::hgLog() |
140 QStringList params; | 146 QStringList params; |
141 params << "log"; | 147 params << "log"; |
142 params << "--template"; | 148 params << "--template"; |
143 params << "id: {rev}:{node|short}\\nauthor: {author}\\nbranch: {branches}\\ntag: {tag}\\ndatetime: {date|isodate}\\ntimestamp: {date|hgdate}\\nage: {date|age}\\nparents: {parents}\\ncomment: {desc|json}\\n\\n"; | 149 params << "id: {rev}:{node|short}\\nauthor: {author}\\nbranch: {branches}\\ntag: {tag}\\ndatetime: {date|isodate}\\ntimestamp: {date|hgdate}\\nage: {date|age}\\nparents: {parents}\\ncomment: {desc|json}\\n\\n"; |
144 | 150 |
145 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 151 runner -> startHgCommand(workFolderPath, params); |
146 runningAction = ACT_LOG; | 152 runningAction = ACT_LOG; |
147 } | 153 } |
148 } | 154 } |
149 | 155 |
150 | 156 |
153 if (runningAction == ACT_NONE) | 159 if (runningAction == ACT_NONE) |
154 { | 160 { |
155 QStringList params; | 161 QStringList params; |
156 params << "parents"; | 162 params << "parents"; |
157 | 163 |
158 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 164 runner -> startHgCommand(workFolderPath, params); |
159 runningAction = ACT_PARENTS; | 165 runningAction = ACT_PARENTS; |
160 } | 166 } |
161 } | 167 } |
162 | 168 |
163 | 169 |
174 if (QMessageBox::Ok == QMessageBox::warning(this, "Remove file", "Really remove file " + currentFile.mid(2) + "?", | 180 if (QMessageBox::Ok == QMessageBox::warning(this, "Remove file", "Really remove file " + currentFile.mid(2) + "?", |
175 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel)) | 181 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel)) |
176 { | 182 { |
177 params << "remove" << "--after" << "--force" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ") | 183 params << "remove" << "--after" << "--force" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ") |
178 | 184 |
179 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 185 runner -> startHgCommand(workFolderPath, params); |
180 runningAction = ACT_REMOVE; | 186 runningAction = ACT_REMOVE; |
181 } | 187 } |
182 } | 188 } |
183 } | 189 } |
184 } | 190 } |
192 | 198 |
193 if (!currentFile.isEmpty()) | 199 if (!currentFile.isEmpty()) |
194 { | 200 { |
195 params << "annotate" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ") | 201 params << "annotate" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ") |
196 | 202 |
197 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 203 runner -> startHgCommand(workFolderPath, params); |
198 runningAction = ACT_ANNOTATE; | 204 runningAction = ACT_ANNOTATE; |
199 } | 205 } |
200 } | 206 } |
201 } | 207 } |
202 | 208 |
210 | 216 |
211 if (!currentFile.isEmpty()) | 217 if (!currentFile.isEmpty()) |
212 { | 218 { |
213 params << "resolve" << "--mark" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ") | 219 params << "resolve" << "--mark" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ") |
214 | 220 |
215 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 221 runner -> startHgCommand(workFolderPath, params); |
216 runningAction = ACT_RESOLVE_MARK; | 222 runningAction = ACT_RESOLVE_MARK; |
217 } | 223 } |
218 } | 224 } |
219 } | 225 } |
220 | 226 |
225 if (runningAction == ACT_NONE) | 231 if (runningAction == ACT_NONE) |
226 { | 232 { |
227 QStringList params; | 233 QStringList params; |
228 | 234 |
229 params << "resolve" << "--list"; | 235 params << "resolve" << "--list"; |
230 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 236 runner -> startHgCommand(workFolderPath, params); |
231 runningAction = ACT_RESOLVE_LIST; | 237 runningAction = ACT_RESOLVE_LIST; |
232 } | 238 } |
233 } | 239 } |
234 | 240 |
235 | 241 |
259 { | 265 { |
260 //Add all untracked files | 266 //Add all untracked files |
261 params << "add"; | 267 params << "add"; |
262 } | 268 } |
263 | 269 |
264 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 270 runner -> startHgCommand(workFolderPath, params); |
265 runningAction = ACT_ADD; | 271 runningAction = ACT_ADD; |
266 } | 272 } |
267 } | 273 } |
268 | 274 |
269 int MainWindow::getCommentOrTag(QString& commentOrTag, QString question, QString dlgTitle) | 275 int MainWindow::getCommentOrTag(QString& commentOrTag, QString question, QString dlgTitle) |
328 { | 334 { |
329 //Commit all changes | 335 //Commit all changes |
330 params << "commit" << "--message" << comment << "--user" << userInfo; | 336 params << "commit" << "--message" << comment << "--user" << userInfo; |
331 } | 337 } |
332 | 338 |
333 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 339 runner -> startHgCommand(workFolderPath, params); |
334 runningAction = ACT_COMMIT; | 340 runningAction = ACT_COMMIT; |
335 } | 341 } |
336 } | 342 } |
337 } | 343 } |
338 } | 344 } |
365 { | 371 { |
366 if (!tag.isEmpty()) | 372 if (!tag.isEmpty()) |
367 { | 373 { |
368 params << "tag" << "--user" << userInfo << filterTag(tag); | 374 params << "tag" << "--user" << userInfo << filterTag(tag); |
369 | 375 |
370 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 376 runner -> startHgCommand(workFolderPath, params); |
371 runningAction = ACT_TAG; | 377 runningAction = ACT_TAG; |
372 } | 378 } |
373 } | 379 } |
374 } | 380 } |
375 } | 381 } |
395 else | 401 else |
396 { | 402 { |
397 editorName = """C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"""; | 403 editorName = """C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"""; |
398 } | 404 } |
399 | 405 |
400 runner -> startProc(editorName, workFolderPath, params); | 406 runner -> startCommand(editorName, workFolderPath, params); |
401 runningAction = ACT_HG_IGNORE; | 407 runningAction = ACT_HG_IGNORE; |
402 } | 408 } |
403 } | 409 } |
404 | 410 |
405 | 411 |
414 | 420 |
415 if (!currentFile.isEmpty()) | 421 if (!currentFile.isEmpty()) |
416 { | 422 { |
417 //Diff parent file against working folder file | 423 //Diff parent file against working folder file |
418 params << "kdiff3" << "--" << currentFile.mid(2); | 424 params << "kdiff3" << "--" << currentFile.mid(2); |
419 runner -> startProc(getHgBinaryName(), workFolderPath, params, false); | 425 runner -> startHgCommand(workFolderPath, params); |
420 runningAction = ACT_FILEDIFF; | 426 runningAction = ACT_FILEDIFF; |
421 } | 427 } |
422 } | 428 } |
423 } | 429 } |
424 | 430 |
429 { | 435 { |
430 QStringList params; | 436 QStringList params; |
431 | 437 |
432 //Diff parent against working folder (folder diff) | 438 //Diff parent against working folder (folder diff) |
433 params << "kdiff3"; | 439 params << "kdiff3"; |
434 runner -> startProc(getHgBinaryName(), workFolderPath, params, false); | 440 runner -> startHgCommand(workFolderPath, params); |
435 runningAction = ACT_FOLDERDIFF; | 441 runningAction = ACT_FOLDERDIFF; |
436 } | 442 } |
437 } | 443 } |
438 | 444 |
439 | 445 |
450 hgExp -> getHistoryDiffRevisions(revA, revB); | 456 hgExp -> getHistoryDiffRevisions(revA, revB); |
451 | 457 |
452 if ((!revA.isEmpty()) && (!revB.isEmpty())) | 458 if ((!revA.isEmpty()) && (!revB.isEmpty())) |
453 { | 459 { |
454 params << "kdiff3" << "--rev" << revA << "--rev" << revB; | 460 params << "kdiff3" << "--rev" << revA << "--rev" << revB; |
455 runner -> startProc(getHgBinaryName(), workFolderPath, params, false); | 461 runner -> startHgCommand(workFolderPath, params); |
456 runningAction = ACT_CHGSETDIFF; | 462 runningAction = ACT_CHGSETDIFF; |
457 } | 463 } |
458 else | 464 else |
459 { | 465 { |
460 QMessageBox::information(this, tr("Changeset diff"), tr("Please select two changesets from history list or heads list first.")); | 466 QMessageBox::information(this, tr("Changeset diff"), tr("Please select two changesets from history list or heads list first.")); |
472 | 478 |
473 | 479 |
474 params << "update"; | 480 params << "update"; |
475 | 481 |
476 | 482 |
477 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 483 runner -> startHgCommand(workFolderPath, params); |
478 runningAction = ACT_UPDATE; | 484 runningAction = ACT_UPDATE; |
479 } | 485 } |
480 } | 486 } |
481 | 487 |
482 | 488 |
492 hgExp -> setCurrentIndex(WORKTAB); | 498 hgExp -> setCurrentIndex(WORKTAB); |
493 enableDisableActions(); | 499 enableDisableActions(); |
494 | 500 |
495 params << "update" << "--rev" << rev << "--clean"; | 501 params << "update" << "--rev" << rev << "--clean"; |
496 | 502 |
497 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 503 runner -> startHgCommand(workFolderPath, params); |
498 | 504 |
499 runningAction = ACT_UPDATE; | 505 runningAction = ACT_UPDATE; |
500 } | 506 } |
501 } | 507 } |
502 | 508 |
508 QStringList params; | 514 QStringList params; |
509 QString currentFile = hgExp -> getCurrentFileListLine(); | 515 QString currentFile = hgExp -> getCurrentFileListLine(); |
510 | 516 |
511 params << "revert" << "--no-backup" << "--" << currentFile.mid(2); | 517 params << "revert" << "--no-backup" << "--" << currentFile.mid(2); |
512 | 518 |
513 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 519 runner -> startHgCommand(workFolderPath, params); |
514 runningAction = ACT_REVERT; | 520 runningAction = ACT_REVERT; |
515 } | 521 } |
516 } | 522 } |
517 | 523 |
518 void MainWindow::hgRetryMerge() | 524 void MainWindow::hgRetryMerge() |
520 if (runningAction == ACT_NONE) | 526 if (runningAction == ACT_NONE) |
521 { | 527 { |
522 QStringList params; | 528 QStringList params; |
523 | 529 |
524 params << "resolve" << "--all"; | 530 params << "resolve" << "--all"; |
525 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 531 runner -> startHgCommand(workFolderPath, params); |
526 runningAction = ACT_RETRY_MERGE; | 532 runningAction = ACT_RETRY_MERGE; |
527 } | 533 } |
528 } | 534 } |
529 | 535 |
530 | 536 |
534 { | 540 { |
535 QStringList params; | 541 QStringList params; |
536 | 542 |
537 params << "merge"; | 543 params << "merge"; |
538 | 544 |
539 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 545 runner -> startHgCommand(workFolderPath, params); |
540 runningAction = ACT_MERGE; | 546 runningAction = ACT_MERGE; |
541 } | 547 } |
542 } | 548 } |
543 | 549 |
544 | 550 |
548 { | 554 { |
549 QStringList params; | 555 QStringList params; |
550 | 556 |
551 params << "clone" << remoteRepoPath << workFolderPath; | 557 params << "clone" << remoteRepoPath << workFolderPath; |
552 | 558 |
553 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 559 runner -> startHgCommand(workFolderPath, params); |
554 runningAction = ACT_CLONEFROMREMOTE; | 560 runningAction = ACT_CLONEFROMREMOTE; |
555 } | 561 } |
556 } | 562 } |
557 | 563 |
558 | 564 |
562 { | 568 { |
563 QStringList params; | 569 QStringList params; |
564 | 570 |
565 params << "init"; | 571 params << "init"; |
566 | 572 |
567 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 573 runner -> startHgCommand(workFolderPath, params); |
568 runningAction = ACT_INIT; | 574 runningAction = ACT_INIT; |
569 } | 575 } |
570 } | 576 } |
571 | 577 |
572 | 578 |
576 { | 582 { |
577 QStringList params; | 583 QStringList params; |
578 | 584 |
579 params << "incoming" << "--newest-first" << remoteRepoPath; | 585 params << "incoming" << "--newest-first" << remoteRepoPath; |
580 | 586 |
581 runner -> startProc(getHgBinaryName(), workFolderPath, params, false); | 587 runner -> startHgCommand(workFolderPath, params); |
582 runningAction = ACT_INCOMING; | 588 runningAction = ACT_INCOMING; |
583 } | 589 } |
584 } | 590 } |
585 | 591 |
586 | 592 |
590 { | 596 { |
591 QStringList params; | 597 QStringList params; |
592 | 598 |
593 params << "pull" << remoteRepoPath; | 599 params << "pull" << remoteRepoPath; |
594 | 600 |
595 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 601 runner -> startHgCommand(workFolderPath, params); |
596 runningAction = ACT_PULL; | 602 runningAction = ACT_PULL; |
597 } | 603 } |
598 } | 604 } |
599 | 605 |
600 | 606 |
604 { | 610 { |
605 QStringList params; | 611 QStringList params; |
606 | 612 |
607 params << "push" << remoteRepoPath; | 613 params << "push" << remoteRepoPath; |
608 | 614 |
609 runner -> startProc(getHgBinaryName(), workFolderPath, params); | 615 runner -> startHgCommand(workFolderPath, params); |
610 runningAction = ACT_PUSH; | 616 runningAction = ACT_PUSH; |
611 } | 617 } |
612 } | 618 } |
613 | 619 |
614 | 620 |
650 | 656 |
651 QString addrs = listAllUpIpV4Addresses(); | 657 QString addrs = listAllUpIpV4Addresses(); |
652 QTextStream(&msg) << "Server running on address(es) (" << addrs << "), port 8000"; | 658 QTextStream(&msg) << "Server running on address(es) (" << addrs << "), port 8000"; |
653 params << "serve"; | 659 params << "serve"; |
654 | 660 |
655 runner -> startProc(getHgBinaryName(), workFolderPath, params, false); | 661 runner -> startHgCommand(workFolderPath, params); |
656 runningAction = ACT_SERVE; | 662 runningAction = ACT_SERVE; |
657 | 663 |
658 QMessageBox::information(this, "Serve", msg, QMessageBox::Close); | 664 QMessageBox::information(this, "Serve", msg, QMessageBox::Close); |
659 runner -> killProc(); | 665 runner -> killCurrentCommand(); |
660 } | 666 } |
661 } | 667 } |
662 | 668 |
663 | 669 |
664 | 670 |
891 selectedNotTracked = 0; | 897 selectedNotTracked = 0; |
892 } | 898 } |
893 } | 899 } |
894 | 900 |
895 | 901 |
896 void MainWindow::timerEvent(QTimerEvent *) | 902 void MainWindow::commandFailed() |
903 { | |
904 DEBUG << "MainWindow::commandFailed" << endl; | |
905 } | |
906 | |
907 void MainWindow::commandCompleted() | |
897 { | 908 { |
898 bool shouldHgStat = false; | 909 bool shouldHgStat = false; |
899 | 910 |
900 if (runningAction != ACT_NONE) | 911 if (runningAction != ACT_NONE) |
901 { | 912 { |
902 //We are running some hg command... | 913 //We are running some hg command... |
903 if (runner -> isProcRunning() == false) | 914 if (runner -> isCommandRunning() == false) |
904 { | 915 { |
905 //Running has just ended. | 916 //Running has just ended. |
906 int exitCode = runner -> getExitCode(); | 917 int exitCode = runner -> getExitCode(); |
907 | 918 |
908 runner -> hideProgBar(); | 919 runner -> hideProgBar(); |