comparison src/mainwindow.cpp @ 370:b9c153e00e84

Move source files to src/
author Chris Cannam
date Thu, 24 Mar 2011 10:27:51 +0000
parents mainwindow.cpp@1482f5b9f9dc
children 4d13cacb3e65
comparison
equal deleted inserted replaced
369:19cce6d2c470 370:b9c153e00e84
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 EasyMercurial
5
6 Based on hgExplorer by Jari Korhonen
7 Copyright (c) 2010 Jari Korhonen
8 Copyright (c) 2011 Chris Cannam
9 Copyright (c) 2011 Queen Mary, University of London
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18 #include <QStringList>
19 #include <QDir>
20 #include <QNetworkInterface>
21 #include <QHostAddress>
22 #include <QHostInfo>
23 #include <QDesktopServices>
24 #include <QStatusBar>
25 #include <QMessageBox>
26 #include <QMenuBar>
27 #include <QApplication>
28 #include <QToolBar>
29 #include <QToolButton>
30 #include <QSettings>
31 #include <QInputDialog>
32 #include <QWidgetAction>
33 #include <QRegExp>
34 #include <QShortcut>
35 #include <QUrl>
36 #include <QTimer>
37
38 #include "mainwindow.h"
39 #include "multichoicedialog.h"
40 #include "startupdialog.h"
41 #include "colourset.h"
42 #include "debug.h"
43 #include "logparser.h"
44 #include "confirmcommentdialog.h"
45 #include "incomingdialog.h"
46 #include "settingsdialog.h"
47 #include "moreinformationdialog.h"
48 #include "annotatedialog.h"
49 #include "version.h"
50 #include "workstatuswidget.h"
51
52
53 MainWindow::MainWindow(QString myDirPath) :
54 m_myDirPath(myDirPath),
55 m_fsWatcherGeneralTimer(0),
56 m_fsWatcherRestoreTimer(0),
57 m_fsWatcherSuspended(false)
58 {
59 setWindowIcon(QIcon(":images/easyhg-icon.png"));
60
61 QString wndTitle;
62
63 m_showAllFiles = false;
64
65 m_fsWatcher = 0;
66 m_commitsSincePush = 0;
67 m_shouldHgStat = true;
68
69 createActions();
70 createMenus();
71 createToolBars();
72 createStatusBar();
73
74 m_runner = new HgRunner(m_myDirPath, this);
75 connect(m_runner, SIGNAL(commandStarting(HgAction)),
76 this, SLOT(commandStarting(HgAction)));
77 connect(m_runner, SIGNAL(commandCompleted(HgAction, QString)),
78 this, SLOT(commandCompleted(HgAction, QString)));
79 connect(m_runner, SIGNAL(commandFailed(HgAction, QString)),
80 this, SLOT(commandFailed(HgAction, QString)));
81 statusBar()->addPermanentWidget(m_runner);
82
83 setWindowTitle(tr("EasyMercurial"));
84
85 m_remoteRepoPath = "";
86 m_workFolderPath = "";
87
88 readSettings();
89
90 m_justMerged = false;
91
92 QWidget *central = new QWidget(this);
93 setCentralWidget(central);
94
95 QGridLayout *cl = new QGridLayout(central);
96 int row = 0;
97
98 #ifndef Q_OS_MAC
99 cl->setMargin(0);
100 #endif
101
102 m_workStatus = new WorkStatusWidget(this);
103 cl->addWidget(m_workStatus, row++, 0);
104
105 m_hgTabs = new HgTabWidget(central, m_workFolderPath);
106 connectTabsSignals();
107
108 cl->addWidget(m_hgTabs, row++, 0);
109
110 connect(m_hgTabs, SIGNAL(selectionChanged()),
111 this, SLOT(enableDisableActions()));
112 connect(m_hgTabs, SIGNAL(showAllChanged(bool)),
113 this, SLOT(showAllChanged(bool)));
114
115 setUnifiedTitleAndToolBarOnMac(true);
116 connectActions();
117 clearState();
118 enableDisableActions();
119
120 if (m_firstStart) {
121 startupDialog();
122 }
123
124 SettingsDialog::findDefaultLocations(m_myDirPath);
125
126 ColourSet *cs = ColourSet::instance();
127 cs->clearDefaultNames();
128 cs->addDefaultName("");
129 cs->addDefaultName("default");
130 cs->addDefaultName(getUserInfo());
131
132 hgTest();
133 updateRecentMenu();
134 }
135
136
137 void MainWindow::closeEvent(QCloseEvent *)
138 {
139 writeSettings();
140 delete m_fsWatcher;
141 }
142
143
144 QString MainWindow::getUserInfo() const
145 {
146 QSettings settings;
147 settings.beginGroup("User Information");
148 QString name = settings.value("name", getUserRealName()).toString();
149 QString email = settings.value("email", "").toString();
150
151 QString identifier;
152
153 if (email != "") {
154 identifier = QString("%1 <%2>").arg(name).arg(email);
155 } else {
156 identifier = name;
157 }
158
159 return identifier;
160 }
161
162 void MainWindow::about()
163 {
164 QMessageBox::about(this, tr("About EasyMercurial"),
165 tr("<qt><h2>EasyMercurial v%1</h2>"
166 #ifdef Q_OS_MAC
167 "<font size=-1>"
168 #endif
169 "<p>EasyMercurial is a simple user interface for the "
170 "Mercurial</a> version control system.</p>"
171 "<h4>Credits and Copyright</h4>"
172 "<p>Development carried out by Chris Cannam for "
173 "SoundSoftware.ac.uk at the Centre for Digital Music, "
174 "Queen Mary, University of London.</p>"
175 "<p>EasyMercurial is based on HgExplorer by "
176 "Jari Korhonen, with thanks.</p>"
177 "<p style=\"margin-left: 2em;\">"
178 "Copyright &copy; 2011 Queen Mary, University of London.<br>"
179 "Copyright &copy; 2010 Jari Korhonen.<br>"
180 "Copyright &copy; 2011 Chris Cannam."
181 "</p>"
182 "<p style=\"margin-left: 2em;\">"
183 "This program requires Mercurial, by Matt Mackall and others.<br>"
184 "This program uses Qt by Nokia.<br>"
185 "This program uses Nuvola icons by David Vignoni.<br>"
186 "This program may use KDiff3 by Joachim Eibl.<br>"
187 "This program may use PyQt by River Bank Computing.<br>"
188 "Packaging for Mercurial and other dependencies on Windows is derived from TortoiseHg by Steve Borho and others."
189 "</p>"
190 "<h4>License</h4>"
191 "<p>This program is free software; you can redistribute it and/or "
192 "modify it under the terms of the GNU General Public License as "
193 "published by the Free Software Foundation; either version 2 of the "
194 "License, or (at your option) any later version. See the file "
195 "COPYING included with this distribution for more information.</p>"
196 #ifdef Q_OS_MAC
197 "</font>"
198 #endif
199 ).arg(EASYHG_VERSION));
200 }
201
202 void MainWindow::clearSelections()
203 {
204 m_hgTabs->clearSelections();
205 }
206
207 void MainWindow::showAllChanged(bool s)
208 {
209 m_showAllFiles = s;
210 hgQueryPaths();
211 }
212
213 void MainWindow::hgRefresh()
214 {
215 clearState();
216 hgQueryPaths();
217 }
218
219 void MainWindow::hgTest()
220 {
221 QStringList params;
222 //!!! should we test version output? Really we want at least 1.7.x
223 //!!! for options such as merge --tool
224 params << "--version";
225 m_runner->requestAction(HgAction(ACT_TEST_HG, m_myDirPath, params));
226 }
227
228 void MainWindow::hgTestExtension()
229 {
230 QStringList params;
231 params << "--version";
232 m_runner->requestAction(HgAction(ACT_TEST_HG_EXT, m_myDirPath, params));
233 }
234
235 void MainWindow::hgStat()
236 {
237 QStringList params;
238
239 if (m_showAllFiles) {
240 params << "stat" << "-A";
241 } else {
242 params << "stat" << "-ardum";
243 }
244
245 m_lastStatOutput = "";
246
247 m_runner->requestAction(HgAction(ACT_STAT, m_workFolderPath, params));
248 }
249
250 void MainWindow::hgQueryPaths()
251 {
252 // Quickest is to just read the file
253
254 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc");
255
256 QString path;
257
258 if (hgrc.exists()) {
259 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
260 s.beginGroup("paths");
261 path = s.value("default").toString();
262 }
263
264 m_remoteRepoPath = path;
265
266 // We have to do this here, because commandCompleted won't be called
267 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
268 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
269 updateWorkFolderAndRepoNames();
270
271 hgQueryBranch();
272 return;
273
274 /* The classic method!
275
276 QStringList params;
277 params << "paths";
278 m_runner->requestAction(HgAction(ACT_QUERY_PATHS, m_workFolderPath, params));
279 */
280 }
281
282 void MainWindow::hgQueryBranch()
283 {
284 // Quickest is to just read the file
285
286 QFile hgbr(m_workFolderPath + "/.hg/branch");
287
288 QString br = "default";
289
290 if (hgbr.exists() && hgbr.open(QFile::ReadOnly)) {
291 QByteArray ba = hgbr.readLine();
292 br = QString::fromUtf8(ba).trimmed();
293 }
294
295 m_currentBranch = br;
296
297 // We have to do this here, because commandCompleted won't be called
298 hgStat();
299 return;
300
301 /* The classic method!
302
303 QStringList params;
304 params << "branch";
305 m_runner->requestAction(HgAction(ACT_QUERY_BRANCH, m_workFolderPath, params));
306 */
307 }
308
309 void MainWindow::hgQueryHeads()
310 {
311 QStringList params;
312 // On empty repos, "hg heads" will fail -- we don't care about
313 // that. Use --closed option so as to include closed branches;
314 // otherwise we'll be stuck if the user updates into one, and our
315 // incremental log will end up with spurious stuff in it because
316 // we won't be pruning at the ends of closed branches
317 params << "heads" << "--closed";
318 m_runner->requestAction(HgAction(ACT_QUERY_HEADS, m_workFolderPath, params));
319 }
320
321 void MainWindow::hgLog()
322 {
323 QStringList params;
324 params << "log";
325 params << "--template";
326 params << Changeset::getLogTemplate();
327
328 m_runner->requestAction(HgAction(ACT_LOG, m_workFolderPath, params));
329 }
330
331 void MainWindow::hgLogIncremental(QStringList prune)
332 {
333 // Sometimes we can be called with prune empty -- it represents
334 // the current heads, but if we have none already and for some
335 // reason are being prompted for an incremental update, we may run
336 // into trouble. In that case, make this a full log instead
337
338 if (prune.empty()) {
339 hgLog();
340 return;
341 }
342
343 QStringList params;
344 params << "log";
345
346 foreach (QString p, prune) {
347 params << "--prune" << Changeset::hashOf(p);
348 }
349
350 params << "--template";
351 params << Changeset::getLogTemplate();
352
353 m_runner->requestAction(HgAction(ACT_LOG_INCREMENTAL, m_workFolderPath, params));
354 }
355
356 void MainWindow::hgQueryParents()
357 {
358 QStringList params;
359 params << "parents";
360 m_runner->requestAction(HgAction(ACT_QUERY_PARENTS, m_workFolderPath, params));
361 }
362
363 void MainWindow::hgAnnotateFiles(QStringList files)
364 {
365 QStringList params;
366
367 if (!files.isEmpty()) {
368 params << "annotate" << "-udqc" << "--" << files;
369 m_runner->requestAction(HgAction(ACT_ANNOTATE, m_workFolderPath, params));
370 }
371 }
372
373 void MainWindow::hgResolveList()
374 {
375 QStringList params;
376
377 params << "resolve" << "--list";
378 m_runner->requestAction(HgAction(ACT_RESOLVE_LIST, m_workFolderPath, params));
379 }
380
381 void MainWindow::hgAdd()
382 {
383 // hgExplorer permitted adding "all" files -- I'm not sure
384 // that one is a good idea, let's require the user to select
385
386 hgAddFiles(m_hgTabs->getSelectedAddableFiles());
387 }
388
389 void MainWindow::hgAddFiles(QStringList files)
390 {
391 QStringList params;
392
393 if (!files.empty()) {
394 params << "add" << "--" << files;
395 m_runner->requestAction(HgAction(ACT_ADD, m_workFolderPath, params));
396 }
397 }
398
399 void MainWindow::hgRemove()
400 {
401 hgRemoveFiles(m_hgTabs->getSelectedRemovableFiles());
402 }
403
404 void MainWindow::hgRemoveFiles(QStringList files)
405 {
406 QStringList params;
407
408 if (!files.empty()) {
409 params << "remove" << "--after" << "--force" << "--" << files;
410 m_runner->requestAction(HgAction(ACT_REMOVE, m_workFolderPath, params));
411 }
412 }
413
414 void MainWindow::hgCommit()
415 {
416 hgCommitFiles(QStringList());
417 }
418
419 void MainWindow::hgCommitFiles(QStringList files)
420 {
421 QStringList params;
422 QString comment;
423
424 if (m_justMerged) {
425 comment = m_mergeCommitComment;
426 }
427
428 QStringList allFiles = m_hgTabs->getAllCommittableFiles();
429 QStringList reportFiles = files;
430 if (reportFiles.empty()) {
431 reportFiles = allFiles;
432 }
433
434 QString subsetNote;
435 if (reportFiles != allFiles) {
436 subsetNote = tr("<p><b>Note:</b> you are committing only the files you have selected, not all of the files that have been changed!");
437 }
438
439 QString cf(tr("Commit files"));
440
441 QString branchText;
442 if (m_currentBranch == "" || m_currentBranch == "default") {
443 branchText = tr("the default branch");
444 } else {
445 branchText = tr("branch \"%1\"").arg(m_currentBranch);
446 }
447
448 if (ConfirmCommentDialog::confirmAndGetLongComment
449 (this,
450 cf,
451 tr("<h3>%1</h3><p>%2%3").arg(cf)
452 .arg(tr("You are about to commit the following files to %1:").arg(branchText))
453 .arg(subsetNote),
454 tr("<h3>%1</h3><p>%2%3").arg(cf)
455 .arg(tr("You are about to commit %n file(s) to %1.", "", reportFiles.size()).arg(branchText))
456 .arg(subsetNote),
457 reportFiles,
458 comment,
459 tr("Co&mmit"))) {
460
461 if (!m_justMerged && !files.empty()) {
462 // User wants to commit selected file(s) (and this is not
463 // merge commit, which would fail if we selected files)
464 params << "commit" << "--message" << comment
465 << "--user" << getUserInfo() << "--" << files;
466 } else {
467 // Commit all changes
468 params << "commit" << "--message" << comment
469 << "--user" << getUserInfo();
470 }
471
472 m_runner->requestAction(HgAction(ACT_COMMIT, m_workFolderPath, params));
473 m_mergeCommitComment = "";
474 }
475 }
476
477 QString MainWindow::filterTag(QString tag)
478 {
479 for(int i = 0; i < tag.size(); i++) {
480 if (tag[i].isLower() || tag[i].isUpper() ||
481 tag[i].isDigit() || (tag[i] == QChar('.'))) {
482 //ok
483 } else {
484 tag[i] = QChar('_');
485 }
486 }
487 return tag;
488 }
489
490
491 void MainWindow::hgNewBranch()
492 {
493 QStringList params;
494 QString branch;
495
496 if (ConfirmCommentDialog::confirmAndGetShortComment
497 (this,
498 tr("New Branch"),
499 tr("Enter new branch name:"),
500 branch,
501 tr("Start &Branch"))) {
502 if (!branch.isEmpty()) {//!!! do something better if it is empty
503
504 params << "branch" << filterTag(branch);
505 m_runner->requestAction(HgAction(ACT_NEW_BRANCH, m_workFolderPath, params));
506 }
507 }
508 }
509
510 void MainWindow::hgNoBranch()
511 {
512 if (m_currentParents.empty()) return;
513
514 QString parentBranch = m_currentParents[0]->branch();
515 if (parentBranch == "") parentBranch = "default";
516
517 QStringList params;
518 params << "branch" << parentBranch;
519 m_runner->requestAction(HgAction(ACT_NEW_BRANCH, m_workFolderPath, params));
520 }
521
522 void MainWindow::hgTag(QString id)
523 {
524 QStringList params;
525 QString tag;
526
527 if (ConfirmCommentDialog::confirmAndGetShortComment
528 (this,
529 tr("Tag"),
530 tr("Enter tag:"),
531 tag,
532 tr("Add &Tag"))) {
533 if (!tag.isEmpty()) {//!!! do something better if it is empty
534
535 params << "tag" << "--user" << getUserInfo();
536 params << "--rev" << Changeset::hashOf(id) << filterTag(tag);
537
538 m_runner->requestAction(HgAction(ACT_TAG, m_workFolderPath, params));
539 }
540 }
541 }
542
543 void MainWindow::hgIgnore()
544 {
545 QString hgIgnorePath;
546 QStringList params;
547
548 hgIgnorePath = m_workFolderPath;
549 hgIgnorePath += "/.hgignore";
550
551 if (!QDir(m_workFolderPath).exists()) return;
552 QFile f(hgIgnorePath);
553 if (!f.exists()) {
554 f.open(QFile::WriteOnly);
555 QTextStream *ts = new QTextStream(&f);
556 *ts << "syntax: glob\n";
557 delete ts;
558 f.close();
559 }
560
561 params << hgIgnorePath;
562
563 QString editor = getEditorBinaryName();
564
565 if (editor == "") {
566 DEBUG << "Failed to find a text editor" << endl;
567 //!!! visible error!
568 return;
569 }
570
571 HgAction action(ACT_HG_IGNORE, m_workFolderPath, params);
572 action.executable = editor;
573
574 m_runner->requestAction(action);
575 }
576
577 void MainWindow::hgIgnoreFiles(QStringList files)
578 {
579 //!!! not implemented yet
580 DEBUG << "MainWindow::hgIgnoreFiles: Not implemented" << endl;
581 }
582
583 void MainWindow::hgUnIgnoreFiles(QStringList files)
584 {
585 //!!! not implemented yet
586 DEBUG << "MainWindow::hgUnIgnoreFiles: Not implemented" << endl;
587 }
588
589 QString MainWindow::getDiffBinaryName()
590 {
591 QSettings settings;
592 settings.beginGroup("Locations");
593 return settings.value("extdiffbinary", "").toString();
594 }
595
596 QString MainWindow::getMergeBinaryName()
597 {
598 QSettings settings;
599 settings.beginGroup("Locations");
600 return settings.value("mergebinary", "").toString();
601 }
602
603 QString MainWindow::getEditorBinaryName()
604 {
605 QSettings settings;
606 settings.beginGroup("Locations");
607 return settings.value("editorbinary", "").toString();
608 }
609
610 void MainWindow::hgShowSummary()
611 {
612 QStringList params;
613
614 params << "diff" << "--stat";
615
616 m_runner->requestAction(HgAction(ACT_UNCOMMITTED_SUMMARY, m_workFolderPath, params));
617 }
618
619 void MainWindow::hgFolderDiff()
620 {
621 hgDiffFiles(QStringList());
622 }
623
624 void MainWindow::hgDiffFiles(QStringList files)
625 {
626 QString diff = getDiffBinaryName();
627 if (diff == "") return;
628
629 QStringList params;
630
631 // Diff parent against working folder (folder diff)
632
633 params << "--config" << "extensions.extdiff=" << "extdiff";
634 params << "--program" << diff;
635
636 params << "--" << files; // may be none: whole dir
637
638 m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, params));
639 }
640
641 void MainWindow::hgDiffToCurrent(QString id)
642 {
643 QString diff = getDiffBinaryName();
644 if (diff == "") return;
645
646 QStringList params;
647
648 // Diff given revision against working folder
649
650 params << "--config" << "extensions.extdiff=" << "extdiff";
651 params << "--program" << diff;
652 params << "--rev" << Changeset::hashOf(id);
653
654 m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, params));
655 }
656
657 void MainWindow::hgDiffToParent(QString child, QString parent)
658 {
659 QString diff = getDiffBinaryName();
660 if (diff == "") return;
661
662 QStringList params;
663
664 // Diff given revision against parent revision
665
666 params << "--config" << "extensions.extdiff=" << "extdiff";
667 params << "--program" << diff;
668 params << "--rev" << Changeset::hashOf(parent)
669 << "--rev" << Changeset::hashOf(child);
670
671 m_runner->requestAction(HgAction(ACT_CHGSETDIFF, m_workFolderPath, params));
672 }
673
674
675 void MainWindow::hgShowSummaryFor(Changeset *cs)
676 {
677 QStringList params;
678
679 // This will pick a default parent if there is more than one
680 // (whereas with diff we need to supply one). But it does need a
681 // bit more parsing
682 params << "log" << "--stat" << "--rev" << Changeset::hashOf(cs->id());
683
684 m_runner->requestAction(HgAction(ACT_DIFF_SUMMARY, m_workFolderPath,
685 params, cs));
686 }
687
688
689 void MainWindow::hgUpdate()
690 {
691 QStringList params;
692
693 params << "update";
694
695 m_runner->requestAction(HgAction(ACT_UPDATE, m_workFolderPath, params));
696 }
697
698
699 void MainWindow::hgUpdateToRev(QString id)
700 {
701 QStringList params;
702
703 params << "update" << "--rev" << Changeset::hashOf(id) << "--check";
704
705 m_runner->requestAction(HgAction(ACT_UPDATE, m_workFolderPath, params));
706 }
707
708
709 void MainWindow::hgRevert()
710 {
711 hgRevertFiles(QStringList());
712 }
713
714 void MainWindow::hgRevertFiles(QStringList files)
715 {
716 QStringList params;
717 QString comment;
718 bool all = false;
719
720 QStringList allFiles = m_hgTabs->getAllRevertableFiles();
721 if (files.empty() || files == allFiles) {
722 files = allFiles;
723 all = true;
724 }
725
726 QString subsetNote;
727 if (!all) {
728 subsetNote = tr("<p><b>Note:</b> you are reverting only the files you have selected, not all of the files that have been changed!");
729 }
730
731 QString rf(tr("Revert files"));
732
733 // Set up params before asking for confirmation, because there is
734 // a failure case here that we would need to report on early
735
736 DEBUG << "hgRevert: m_justMerged = " << m_justMerged << ", m_mergeTargetRevision = " << m_mergeTargetRevision << endl;
737
738 if (m_justMerged) {
739
740 // This is a little fiddly. The proper way to "revert" the
741 // whole of an uncommitted merge is with "hg update --clean ."
742 // But if the user has selected only some files, we're sort of
743 // promising to revert only those, which means we need to
744 // specify which parent to revert to. We can only do that if
745 // we have a record of it, which we do if you just did the
746 // merge from within easyhg but don't if you've exited and
747 // restarted, or changed repository, since then. Hmmm.
748
749 if (all) {
750 params << "update" << "--clean" << ".";
751 } else {
752 if (m_mergeTargetRevision != "") {
753 params << "revert" << "--rev"
754 << Changeset::hashOf(m_mergeTargetRevision)
755 << "--" << files;
756 } else {
757 QMessageBox::information
758 (this, tr("Unable to revert"),
759 tr("<qt><b>Sorry, unable to revert these files</b><br><br>EasyMercurial can only revert a subset of files during a merge if it still has a record of which parent was the original merge target; that information is no longer available.<br><br>This is a limitation of EasyMercurial. Consider reverting all files, or using hg revert with a specific revision at the command-line instead.</qt>"));
760 return;
761 }
762 }
763 } else {
764 params << "revert" << "--" << files;
765 }
766
767 if (ConfirmCommentDialog::confirmDangerousFilesAction
768 (this,
769 rf,
770 tr("<h3>%1</h3><p>%2%3").arg(rf)
771 .arg(tr("You are about to <b>revert</b> the following files to their previous committed state.<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed."))
772 .arg(subsetNote),
773 tr("<h3>%1</h3><p>%2%3").arg(rf)
774 .arg(tr("You are about to <b>revert</b> %n file(s).<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed.", "", files.size()))
775 .arg(subsetNote),
776 files,
777 tr("Re&vert"))) {
778
779 m_lastRevertedFiles = files;
780
781 m_runner->requestAction(HgAction(ACT_REVERT, m_workFolderPath, params));
782 }
783 }
784
785
786 void MainWindow::hgRenameFiles(QStringList files)
787 {
788 QString renameTo;
789
790 QString file;
791 if (files.empty()) return;
792 file = files[0];
793
794 if (ConfirmCommentDialog::confirmAndGetShortComment
795 (this,
796 tr("Rename"),
797 tr("Rename <code>%1</code> to:").arg(xmlEncode(file)),
798 renameTo,
799 tr("Re&name"))) {
800
801 if (renameTo != "" && renameTo != file) {
802
803 QStringList params;
804
805 params << "rename" << "--" << file << renameTo;
806
807 m_runner->requestAction(HgAction(ACT_RENAME_FILE, m_workFolderPath, params));
808 }
809 }
810 }
811
812
813 void MainWindow::hgCopyFiles(QStringList files)
814 {
815 QString copyTo;
816
817 QString file;
818 if (files.empty()) return;
819 file = files[0];
820
821 if (ConfirmCommentDialog::confirmAndGetShortComment
822 (this,
823 tr("Copy"),
824 tr("Copy <code>%1</code> to:").arg(xmlEncode(file)),
825 copyTo,
826 tr("Co&py"))) {
827
828 if (copyTo != "" && copyTo != file) {
829
830 QStringList params;
831
832 params << "copy" << "--" << file << copyTo;
833
834 m_runner->requestAction(HgAction(ACT_COPY_FILE, m_workFolderPath, params));
835 }
836 }
837 }
838
839
840 void MainWindow::hgMarkFilesResolved(QStringList files)
841 {
842 QStringList params;
843
844 params << "resolve" << "--mark";
845
846 if (files.empty()) {
847 params << "--all";
848 } else {
849 params << "--" << files;
850 }
851
852 m_runner->requestAction(HgAction(ACT_RESOLVE_MARK, m_workFolderPath, params));
853 }
854
855
856 void MainWindow::hgRedoMerge()
857 {
858 hgRedoFileMerges(QStringList());
859 }
860
861
862 void MainWindow::hgRedoFileMerges(QStringList files)
863 {
864 QStringList params;
865
866 params << "resolve";
867
868 QString merge = getMergeBinaryName();
869 if (merge != "") {
870 params << "--tool" << merge;
871 }
872
873 if (files.empty()) {
874 params << "--all";
875 } else {
876 params << "--" << files;
877 }
878
879 if (m_currentParents.size() == 1) {
880 m_mergeTargetRevision = m_currentParents[0]->id();
881 }
882
883 m_runner->requestAction(HgAction(ACT_RETRY_MERGE, m_workFolderPath, params));
884
885 m_mergeCommitComment = tr("Merge");
886 }
887
888
889 void MainWindow::hgMerge()
890 {
891 if (m_hgTabs->canResolve()) {
892 hgRedoMerge();
893 return;
894 }
895
896 QStringList params;
897
898 params << "merge";
899
900 QString merge = getMergeBinaryName();
901 if (merge != "") {
902 params << "--tool" << merge;
903 }
904
905 if (m_currentParents.size() == 1) {
906 m_mergeTargetRevision = m_currentParents[0]->id();
907 }
908
909 m_runner->requestAction(HgAction(ACT_MERGE, m_workFolderPath, params));
910
911 m_mergeCommitComment = tr("Merge");
912 }
913
914
915 void MainWindow::hgMergeFrom(QString id)
916 {
917 QStringList params;
918
919 params << "merge";
920 params << "--rev" << Changeset::hashOf(id);
921
922 QString merge = getMergeBinaryName();
923 if (merge != "") {
924 params << "--tool" << merge;
925 }
926
927 if (m_currentParents.size() == 1) {
928 m_mergeTargetRevision = m_currentParents[0]->id();
929 }
930
931 m_runner->requestAction(HgAction(ACT_MERGE, m_workFolderPath, params));
932
933 m_mergeCommitComment = "";
934
935 foreach (Changeset *cs, m_currentHeads) {
936 if (cs->id() == id && !cs->isOnBranch(m_currentBranch)) {
937 if (cs->branch() == "" || cs->branch() == "default") {
938 m_mergeCommitComment = tr("Merge from the default branch");
939 } else {
940 m_mergeCommitComment = tr("Merge from branch \"%1\"").arg(cs->branch());
941 }
942 }
943 }
944
945 if (m_mergeCommitComment == "") {
946 m_mergeCommitComment = tr("Merge from %1").arg(id);
947 }
948 }
949
950
951 void MainWindow::hgCloneFromRemote()
952 {
953 QStringList params;
954
955 if (!QDir(m_workFolderPath).exists()) {
956 if (!QDir().mkpath(m_workFolderPath)) {
957 DEBUG << "hgCloneFromRemote: Failed to create target path "
958 << m_workFolderPath << endl;
959 //!!! report error
960 return;
961 }
962 }
963
964 params << "clone" << m_remoteRepoPath << m_workFolderPath;
965
966 updateWorkFolderAndRepoNames();
967 m_hgTabs->updateWorkFolderFileList("");
968
969 m_runner->requestAction(HgAction(ACT_CLONEFROMREMOTE, m_workFolderPath, params));
970 }
971
972 void MainWindow::hgInit()
973 {
974 QStringList params;
975
976 params << "init";
977 params << m_workFolderPath;
978
979 m_runner->requestAction(HgAction(ACT_INIT, m_workFolderPath, params));
980 }
981
982 void MainWindow::hgIncoming()
983 {
984 QStringList params;
985
986 params << "incoming" << "--newest-first" << m_remoteRepoPath;
987 params << "--template" << Changeset::getLogTemplate();
988
989 m_runner->requestAction(HgAction(ACT_INCOMING, m_workFolderPath, params));
990 }
991
992 void MainWindow::hgPull()
993 {
994 if (ConfirmCommentDialog::confirm
995 (this, tr("Confirm pull"),
996 tr("<qt><h3>Pull from remote repository?</h3></qt>"),
997 tr("<qt><p>You are about to pull changes from the remote repository at <code>%1</code>.</p></qt>").arg(xmlEncode(m_remoteRepoPath)),
998 tr("&Pull"))) {
999
1000 QStringList params;
1001 params << "pull" << m_remoteRepoPath;
1002 m_runner->requestAction(HgAction(ACT_PULL, m_workFolderPath, params));
1003 }
1004 }
1005
1006 void MainWindow::hgPush()
1007 {
1008 if (m_remoteRepoPath.isEmpty()) {
1009 changeRemoteRepo(true);
1010 if (m_remoteRepoPath.isEmpty()) return;
1011 }
1012
1013 QString uncommittedNote;
1014 if (m_hgTabs->canCommit()) {
1015 uncommittedNote = tr("<p><b>Note:</b> You have uncommitted changes. If you want to push these changes to the remote repository, you need to commit them first.");
1016 }
1017
1018 if (ConfirmCommentDialog::confirm
1019 (this, tr("Confirm push"),
1020 tr("<qt><h3>Push to remote repository?</h3></qt>"),
1021 tr("<qt><p>You are about to push your commits to the remote repository at <code>%1</code>.</p>%2</qt>").arg(xmlEncode(m_remoteRepoPath)).arg(uncommittedNote),
1022 tr("&Push"))) {
1023
1024 QStringList params;
1025 params << "push" << "--new-branch" << m_remoteRepoPath;
1026 m_runner->requestAction(HgAction(ACT_PUSH, m_workFolderPath, params));
1027 }
1028 }
1029
1030 QStringList MainWindow::listAllUpIpV4Addresses()
1031 {
1032 QStringList ret;
1033 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
1034
1035 for (int i = 0; i < ifaces.count(); i++) {
1036 QNetworkInterface iface = ifaces.at(i);
1037 if (iface.flags().testFlag(QNetworkInterface::IsUp)
1038 && !iface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
1039 for (int j=0; j<iface.addressEntries().count(); j++) {
1040 QHostAddress tmp = iface.addressEntries().at(j).ip();
1041 if (QAbstractSocket::IPv4Protocol == tmp.protocol()) {
1042 ret.push_back(tmp.toString());
1043 }
1044 }
1045 }
1046 }
1047 return ret;
1048 }
1049
1050 void MainWindow::clearState()
1051 {
1052 DEBUG << "MainWindow::clearState" << endl;
1053 foreach (Changeset *cs, m_currentParents) delete cs;
1054 m_currentParents.clear();
1055 foreach (Changeset *cs, m_currentHeads) delete cs;
1056 m_currentHeads.clear();
1057 m_currentBranch = "";
1058 m_lastStatOutput = "";
1059 m_lastRevertedFiles.clear();
1060 m_mergeTargetRevision = "";
1061 m_mergeCommitComment = "";
1062 m_stateUnknown = true;
1063 m_needNewLog = true;
1064 if (m_fsWatcher) {
1065 delete m_fsWatcherGeneralTimer;
1066 m_fsWatcherGeneralTimer = 0;
1067 delete m_fsWatcherRestoreTimer;
1068 m_fsWatcherRestoreTimer = 0;
1069 delete m_fsWatcher;
1070 m_fsWatcher = 0;
1071 }
1072 }
1073
1074 void MainWindow::hgServe()
1075 {
1076 QStringList params;
1077 QString msg;
1078
1079 QStringList addrs = listAllUpIpV4Addresses();
1080
1081 if (addrs.empty()) {
1082 QMessageBox::critical
1083 (this, tr("Serve"), tr("Failed to identify an active IPv4 address"));
1084 return;
1085 }
1086
1087 //!!! should find available port as well
1088
1089 QTextStream ts(&msg);
1090 ts << QString("<qt><p>%1</p>")
1091 .arg(tr("Running temporary server at %n address(es):", "", addrs.size()));
1092 foreach (QString addr, addrs) {
1093 ts << QString("<pre>&nbsp;&nbsp;http://%1:8000</pre>").arg(xmlEncode(addr));
1094 }
1095 ts << tr("<p>Press Close to stop the server and return.</p>");
1096 ts.flush();
1097
1098 params << "serve";
1099
1100 m_runner->requestAction(HgAction(ACT_SERVE, m_workFolderPath, params));
1101
1102 QMessageBox::information(this, tr("Serve"), msg, QMessageBox::Close);
1103
1104 m_runner->killCurrentActions();
1105 }
1106
1107 void MainWindow::startupDialog()
1108 {
1109 StartupDialog *dlg = new StartupDialog(this);
1110 if (dlg->exec()) m_firstStart = false;
1111 else exit(0);
1112 }
1113
1114 void MainWindow::open()
1115 {
1116 bool done = false;
1117
1118 while (!done) {
1119
1120 MultiChoiceDialog *d = new MultiChoiceDialog
1121 (tr("Open Repository"),
1122 tr("<qt><big>What would you like to open?</big></qt>"),
1123 this);
1124
1125 d->addChoice("remote",
1126 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
1127 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
1128 MultiChoiceDialog::UrlToDirectoryArg);
1129
1130 d->addChoice("local",
1131 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
1132 tr("Open an existing local Mercurial repository."),
1133 MultiChoiceDialog::DirectoryArg);
1134
1135 d->addChoice("init",
1136 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
1137 tr("Open a local folder, by creating a Mercurial repository in it."),
1138 MultiChoiceDialog::DirectoryArg);
1139
1140 QSettings settings;
1141 settings.beginGroup("General");
1142 QString lastChoice = settings.value("lastopentype", "remote").toString();
1143 if (lastChoice != "local" &&
1144 lastChoice != "remote" &&
1145 lastChoice != "init") {
1146 lastChoice = "remote";
1147 }
1148
1149 d->setCurrentChoice(lastChoice);
1150
1151 if (d->exec() == QDialog::Accepted) {
1152
1153 QString choice = d->getCurrentChoice();
1154 settings.setValue("lastopentype", choice);
1155
1156 QString arg = d->getArgument().trimmed();
1157
1158 bool result = false;
1159
1160 if (choice == "local") {
1161 result = openLocal(arg);
1162 } else if (choice == "remote") {
1163 result = openRemote(arg, d->getAdditionalArgument().trimmed());
1164 } else if (choice == "init") {
1165 result = openInit(arg);
1166 }
1167
1168 if (result) {
1169 enableDisableActions();
1170 clearState();
1171 hgQueryPaths();
1172 done = true;
1173 }
1174
1175 } else {
1176
1177 // cancelled
1178 done = true;
1179 }
1180
1181 delete d;
1182 }
1183 }
1184
1185 void MainWindow::recentMenuActivated()
1186 {
1187 QAction *a = qobject_cast<QAction *>(sender());
1188 if (!a) return;
1189 QString local = a->text();
1190 open(local);
1191 }
1192
1193 void MainWindow::changeRemoteRepo()
1194 {
1195 changeRemoteRepo(false);
1196 }
1197
1198 void MainWindow::changeRemoteRepo(bool initial)
1199 {
1200 // This will involve rewriting the local .hgrc
1201
1202 QDir hgDir(m_workFolderPath + "/.hg");
1203 if (!hgDir.exists()) {
1204 //!!! visible error!
1205 return;
1206 }
1207
1208 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc");
1209 if (hgrc.exists() && !hgrc.isWritable()) {
1210 //!!! visible error!
1211 return;
1212 }
1213
1214 MultiChoiceDialog *d = new MultiChoiceDialog
1215 (tr("Set Remote Location"),
1216 tr("<qt><big>Set the remote location</big></qt>"),
1217 this);
1218
1219 QString explanation;
1220 if (initial) {
1221 explanation = tr("Provide a URL to use for push and pull actions from the current local repository.<br>This will be the default for subsequent pushes and pulls.<br>You can change it using &ldquo;Set Remote Location&rdquo; on the File menu.");
1222 } else {
1223 explanation = tr("Provide a new URL to use for push and pull actions from the current local repository.");
1224 }
1225
1226 d->addChoice("remote",
1227 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
1228 explanation,
1229 MultiChoiceDialog::UrlArg);
1230
1231 if (d->exec() == QDialog::Accepted) {
1232
1233 // New block to ensure QSettings is deleted before
1234 // hgQueryPaths called. NB use of absoluteFilePath instead of
1235 // canonicalFilePath, which would fail if the file did not yet
1236 // exist
1237
1238 {
1239 QSettings s(hgrc.absoluteFilePath(), QSettings::IniFormat);
1240 s.beginGroup("paths");
1241 s.setValue("default", d->getArgument());
1242 }
1243
1244 m_stateUnknown = true;
1245 hgQueryPaths();
1246 }
1247
1248 delete d;
1249 }
1250
1251 void MainWindow::open(QString local)
1252 {
1253 if (openLocal(local)) {
1254 enableDisableActions();
1255 clearState();
1256 hgQueryPaths();
1257 }
1258 }
1259
1260 bool MainWindow::complainAboutFilePath(QString arg)
1261 {
1262 QMessageBox::critical
1263 (this, tr("File chosen"),
1264 tr("<qt><b>Folder required</b><br><br>You asked to open \"%1\".<br>This is a file; to open a repository, you need to choose a folder.</qt>").arg(xmlEncode(arg)));
1265 return false;
1266 }
1267
1268 bool MainWindow::askAboutUnknownFolder(QString arg)
1269 {
1270 bool result = (QMessageBox::question
1271 (this, tr("Path does not exist"),
1272 tr("<qt><b>Path does not exist: create it?</b><br><br>You asked to open a remote repository by cloning it to \"%1\". This folder does not exist, and neither does its parent.<br><br>Would you like to create the parent folder as well?</qt>").arg(xmlEncode(arg)),
1273 QMessageBox::Ok | QMessageBox::Cancel,
1274 QMessageBox::Cancel)
1275 == QMessageBox::Ok);
1276 if (result) {
1277 QDir dir(arg);
1278 dir.cdUp();
1279 if (!dir.mkpath(dir.absolutePath())) {
1280 QMessageBox::critical
1281 (this, tr("Failed to create folder"),
1282 tr("<qt><b>Failed to create folder</b><br><br>Sorry, the path for the parent folder \"%1\" could not be created.</qt>").arg(dir.absolutePath()));
1283 return false;
1284 }
1285 return true;
1286 }
1287 return false;
1288 }
1289
1290 bool MainWindow::complainAboutUnknownFolder(QString arg)
1291 {
1292 QMessageBox::critical
1293 (this, tr("Folder does not exist"),
1294 tr("<qt><b>Folder does not exist</b><br><br>You asked to open \"%1\".<br>This folder does not exist, and it cannot be created because its parent does not exist either.</qt>").arg(xmlEncode(arg)));
1295 return false;
1296 }
1297
1298 bool MainWindow::complainAboutInitInRepo(QString arg)
1299 {
1300 QMessageBox::critical
1301 (this, tr("Path is in existing repository"),
1302 tr("<qt><b>Path is in an existing repository</b><br><br>You asked to initialise a repository at \"%1\".<br>This path is already inside an existing repository.</qt>").arg(xmlEncode(arg)));
1303 return false;
1304 }
1305
1306 bool MainWindow::complainAboutInitFile(QString arg)
1307 {
1308 QMessageBox::critical
1309 (this, tr("Path is a file"),
1310 tr("<qt><b>Path is a file</b><br><br>You asked to initialise a repository at \"%1\".<br>This is an existing file; it is only possible to initialise in folders.</qt>").arg(xmlEncode(arg)));
1311 return false;
1312 }
1313
1314 bool MainWindow::complainAboutCloneToExisting(QString arg)
1315 {
1316 QMessageBox::critical
1317 (this, tr("Path is in existing repository"),
1318 tr("<qt><b>Local path is in an existing repository</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This path is already inside an existing repository.<br>Please provide a different folder name for the local repository.</qt>").arg(xmlEncode(arg)));
1319 return false;
1320 }
1321
1322 bool MainWindow::complainAboutCloneToFile(QString arg)
1323 {
1324 QMessageBox::critical
1325 (this, tr("Path is a file"),
1326 tr("<qt><b>Local path is a file</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This path is an existing file.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg)));
1327 return false;
1328 }
1329
1330 QString MainWindow::complainAboutCloneToExistingFolder(QString arg, QString remote)
1331 {
1332 // If the directory "arg" exists but is empty, then we accept it.
1333
1334 // If the directory "arg" exists and is non-empty, but "arg" plus
1335 // the last path component of "remote" does not exist, then offer
1336 // the latter as an alternative path.
1337
1338 QString offer;
1339
1340 QDir d(arg);
1341
1342 if (d.exists()) {
1343
1344 if (d.entryList(QDir::Dirs | QDir::Files |
1345 QDir::NoDotAndDotDot |
1346 QDir::Hidden | QDir::System).empty()) {
1347 // directory is empty; accept it
1348 return arg;
1349 }
1350
1351 if (QRegExp("^\\w+://").indexIn(remote) >= 0) {
1352 QString rpath = QUrl(remote).path();
1353 if (rpath != "") {
1354 rpath = QDir(rpath).dirName();
1355 if (rpath != "" && !d.exists(rpath)) {
1356 offer = d.filePath(rpath);
1357 }
1358 }
1359 }
1360 }
1361
1362 if (offer != "") {
1363 bool result = (QMessageBox::question
1364 (this, tr("Folder exists"),
1365 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to \"%1\", but this folder already exists and so cannot be cloned to.<br><br>Would you like to create the new folder \"%2\" instead?</qt>")
1366 .arg(xmlEncode(arg)).arg(xmlEncode(offer)),
1367 QMessageBox::Ok | QMessageBox::Cancel,
1368 QMessageBox::Cancel)
1369 == QMessageBox::Ok);
1370 if (result) return offer;
1371 else return "";
1372 }
1373
1374 QMessageBox::critical
1375 (this, tr("Folder exists"),
1376 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to \"%1\", but this file or folder already exists and so cannot be cloned to.<br>Please provide a different folder name for the local repository.</qt>").arg(xmlEncode(arg)));
1377 return "";
1378 }
1379
1380 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
1381 {
1382 return (QMessageBox::question
1383 (this, tr("Path is inside a repository"),
1384 tr("<qt><b>Open the repository that contains this path?</b><br><br>You asked to open \"%1\".<br>This is not the root folder of a repository.<br>But it is inside a repository, whose root is at \"%2\". <br><br>Would you like to open that repository instead?</qt>")
1385 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
1386 QMessageBox::Ok | QMessageBox::Cancel,
1387 QMessageBox::Ok)
1388 == QMessageBox::Ok);
1389 }
1390
1391 bool MainWindow::askToInitExisting(QString arg)
1392 {
1393 return (QMessageBox::question
1394 (this, tr("Folder has no repository"),
1395 tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder is not a Mercurial working copy.<br><br>Would you like to initialise a repository here?</qt>")
1396 .arg(xmlEncode(arg)),
1397 QMessageBox::Ok | QMessageBox::Cancel,
1398 QMessageBox::Ok)
1399 == QMessageBox::Ok);
1400 }
1401
1402 bool MainWindow::askToInitNew(QString arg)
1403 {
1404 return (QMessageBox::question
1405 (this, tr("Folder does not exist"),
1406 tr("<qt><b>Initialise a new repository?</b><br><br>You asked to open \"%1\".<br>This folder does not yet exist.<br><br>Would you like to create the folder and initialise a new empty repository in it?</qt>")
1407 .arg(xmlEncode(arg)),
1408 QMessageBox::Ok | QMessageBox::Cancel,
1409 QMessageBox::Ok)
1410 == QMessageBox::Ok);
1411 }
1412
1413 bool MainWindow::askToOpenInsteadOfInit(QString arg)
1414 {
1415 return (QMessageBox::question
1416 (this, tr("Repository exists"),
1417 tr("<qt><b>Open existing repository?</b><br><br>You asked to initialise a new repository at \"%1\".<br>This folder already contains a repository. Would you like to open it?</qt>")
1418 .arg(xmlEncode(arg)),
1419 QMessageBox::Ok | QMessageBox::Cancel,
1420 QMessageBox::Ok)
1421 == QMessageBox::Ok);
1422 }
1423
1424 bool MainWindow::openLocal(QString local)
1425 {
1426 DEBUG << "open " << local << endl;
1427
1428 FolderStatus status = getFolderStatus(local);
1429 QString containing = getContainingRepoFolder(local);
1430
1431 switch (status) {
1432
1433 case FolderHasRepo:
1434 // fine
1435 break;
1436
1437 case FolderExists:
1438 if (containing != "") {
1439 if (!askToOpenParentRepo(local, containing)) return false;
1440 local = containing;
1441 } else {
1442 //!!! No -- this is likely to happen far more by accident
1443 // than because the user actually wanted to init something.
1444 // Don't ask, just politely reject.
1445 if (!askToInitExisting(local)) return false;
1446 return openInit(local);
1447 }
1448 break;
1449
1450 case FolderParentExists:
1451 if (containing != "") {
1452 if (!askToOpenParentRepo(local, containing)) return false;
1453 local = containing;
1454 } else {
1455 if (!askToInitNew(local)) return false;
1456 return openInit(local);
1457 }
1458 break;
1459
1460 case FolderUnknown:
1461 if (containing != "") {
1462 if (!askToOpenParentRepo(local, containing)) return false;
1463 local = containing;
1464 } else {
1465 return complainAboutUnknownFolder(local);
1466 }
1467 break;
1468
1469 case FolderIsFile:
1470 return complainAboutFilePath(local);
1471 }
1472
1473 m_workFolderPath = local;
1474 m_remoteRepoPath = "";
1475 return true;
1476 }
1477
1478 bool MainWindow::openRemote(QString remote, QString local)
1479 {
1480 DEBUG << "clone " << remote << " to " << local << endl;
1481
1482 FolderStatus status = getFolderStatus(local);
1483 QString containing = getContainingRepoFolder(local);
1484
1485 DEBUG << "status = " << status << ", containing = " << containing << endl;
1486
1487 if (status == FolderHasRepo || containing != "") {
1488 return complainAboutCloneToExisting(local);
1489 }
1490
1491 if (status == FolderIsFile) {
1492 return complainAboutCloneToFile(local);
1493 }
1494
1495 if (status == FolderUnknown) {
1496 if (!askAboutUnknownFolder(local)) {
1497 return false;
1498 }
1499 }
1500
1501 if (status == FolderExists) {
1502 local = complainAboutCloneToExistingFolder(local, remote);
1503 if (local == "") return false;
1504 }
1505
1506 m_workFolderPath = local;
1507 m_remoteRepoPath = remote;
1508 hgCloneFromRemote();
1509
1510 return true;
1511 }
1512
1513 bool MainWindow::openInit(QString local)
1514 {
1515 DEBUG << "openInit " << local << endl;
1516
1517 FolderStatus status = getFolderStatus(local);
1518 QString containing = getContainingRepoFolder(local);
1519
1520 DEBUG << "status = " << status << ", containing = " << containing << endl;
1521
1522 if (status == FolderHasRepo) {
1523 if (!askToOpenInsteadOfInit(local)) return false;
1524 }
1525
1526 if (containing != "") {
1527 return complainAboutInitInRepo(local);
1528 }
1529
1530 if (status == FolderIsFile) {
1531 return complainAboutInitFile(local);
1532 }
1533
1534 if (status == FolderUnknown) {
1535 return complainAboutUnknownFolder(local);
1536 }
1537
1538 m_workFolderPath = local;
1539 m_remoteRepoPath = "";
1540 hgInit();
1541 return true;
1542 }
1543
1544 void MainWindow::settings()
1545 {
1546 SettingsDialog *settingsDlg = new SettingsDialog(this);
1547 settingsDlg->exec();
1548
1549 if (settingsDlg->presentationChanged()) {
1550 m_hgTabs->updateFileStates();
1551 updateToolBarStyle();
1552 hgRefresh();
1553 }
1554 }
1555
1556 void MainWindow::updateFileSystemWatcher()
1557 {
1558 bool justCreated = false;
1559 if (!m_fsWatcher) {
1560 m_fsWatcher = new QFileSystemWatcher();
1561 justCreated = true;
1562 }
1563
1564 // QFileSystemWatcher will refuse to add a file or directory to
1565 // its watch list that it is already watching -- fine, that's what
1566 // we want -- but it prints a warning when this happens, which is
1567 // annoying because it would be the normal case for us. So we'll
1568 // check for duplicates ourselves.
1569 QSet<QString> alreadyWatched;
1570 QStringList dl(m_fsWatcher->directories());
1571 foreach (QString d, dl) alreadyWatched.insert(d);
1572
1573 std::deque<QString> pending;
1574 pending.push_back(m_workFolderPath);
1575
1576 while (!pending.empty()) {
1577
1578 QString path = pending.front();
1579 pending.pop_front();
1580 if (!alreadyWatched.contains(path)) {
1581 m_fsWatcher->addPath(path);
1582 DEBUG << "Added to file system watcher: " << path << endl;
1583 }
1584
1585 QDir d(path);
1586 if (d.exists()) {
1587 d.setFilter(QDir::Dirs | QDir::NoDotAndDotDot |
1588 QDir::Readable | QDir::NoSymLinks);
1589 foreach (QString entry, d.entryList()) {
1590 if (entry.startsWith('.')) continue;
1591 QString entryPath = d.absoluteFilePath(entry);
1592 pending.push_back(entryPath);
1593 }
1594 }
1595 }
1596
1597 // The general timer isn't really related to the fs watcher
1598 // object, it just does something similar -- every now and then we
1599 // do a refresh just to update the history dates etc
1600
1601 m_fsWatcherGeneralTimer = new QTimer(this);
1602 connect(m_fsWatcherGeneralTimer, SIGNAL(timeout()),
1603 this, SLOT(checkFilesystem()));
1604 m_fsWatcherGeneralTimer->setInterval(30 * 60 * 1000); // half an hour
1605 m_fsWatcherGeneralTimer->start();
1606
1607 if (justCreated) {
1608 connect(m_fsWatcher, SIGNAL(directoryChanged(QString)),
1609 this, SLOT(fsDirectoryChanged(QString)));
1610 connect(m_fsWatcher, SIGNAL(fileChanged(QString)),
1611 this, SLOT(fsFileChanged(QString)));
1612 }
1613 }
1614
1615 void MainWindow::suspendFileSystemWatcher()
1616 {
1617 DEBUG << "MainWindow::suspendFileSystemWatcher" << endl;
1618 if (m_fsWatcher) {
1619 m_fsWatcherSuspended = true;
1620 if (m_fsWatcherRestoreTimer) {
1621 delete m_fsWatcherRestoreTimer;
1622 m_fsWatcherRestoreTimer = 0;
1623 }
1624 m_fsWatcherGeneralTimer->stop();
1625 }
1626 }
1627
1628 void MainWindow::restoreFileSystemWatcher()
1629 {
1630 DEBUG << "MainWindow::restoreFileSystemWatcher" << endl;
1631 if (m_fsWatcherRestoreTimer) delete m_fsWatcherRestoreTimer;
1632
1633 // The restore timer is used to leave a polite interval between
1634 // being asked to restore the watcher and actually doing so. It's
1635 // a single shot timer each time it's used, but we don't use
1636 // QTimer::singleShot because we want to stop the previous one if
1637 // it's running (via deleting it)
1638
1639 m_fsWatcherRestoreTimer = new QTimer(this);
1640 connect(m_fsWatcherRestoreTimer, SIGNAL(timeout()),
1641 this, SLOT(actuallyRestoreFileSystemWatcher()));
1642 m_fsWatcherRestoreTimer->setInterval(1000);
1643 m_fsWatcherRestoreTimer->setSingleShot(true);
1644 m_fsWatcherRestoreTimer->start();
1645 }
1646
1647 void MainWindow::actuallyRestoreFileSystemWatcher()
1648 {
1649 DEBUG << "MainWindow::actuallyRestoreFileSystemWatcher" << endl;
1650 if (m_fsWatcher) {
1651 m_fsWatcherSuspended = false;
1652 m_fsWatcherGeneralTimer->start();
1653 }
1654 }
1655
1656 void MainWindow::checkFilesystem()
1657 {
1658 DEBUG << "MainWindow::checkFilesystem" << endl;
1659 hgRefresh();
1660 }
1661
1662 void MainWindow::fsDirectoryChanged(QString d)
1663 {
1664 DEBUG << "MainWindow::fsDirectoryChanged " << d << endl;
1665 if (!m_fsWatcherSuspended) {
1666 hgStat();
1667 }
1668 }
1669
1670 void MainWindow::fsFileChanged(QString f)
1671 {
1672 DEBUG << "MainWindow::fsFileChanged " << f << endl;
1673 if (!m_fsWatcherSuspended) {
1674 hgStat();
1675 }
1676 }
1677
1678 QString MainWindow::format1(QString head)
1679 {
1680 return QString("<qt><h3>%1</h3></qt>").arg(head);
1681 }
1682
1683 QString MainWindow::format3(QString head, QString intro, QString code)
1684 {
1685 code = xmlEncode(code).replace("\n", "<br>")
1686 #ifndef Q_OS_WIN32
1687 // The hard hyphen comes out funny on Windows
1688 .replace("-", "&#8209;")
1689 #endif
1690 .replace(" ", "&nbsp;");
1691 if (intro == "") {
1692 return QString("<qt><h3>%1</h3><p><code>%2</code></p>")
1693 .arg(head).arg(code);
1694 } else if (code == "") {
1695 return QString("<qt><h3>%1</h3><p>%2</p>")
1696 .arg(head).arg(intro);
1697 } else {
1698 return QString("<qt><h3>%1</h3><p>%2</p><p><code>%3</code></p>")
1699 .arg(head).arg(intro).arg(code);
1700 }
1701 }
1702
1703 void MainWindow::showIncoming(QString output)
1704 {
1705 m_runner->hide();
1706 IncomingDialog *d = new IncomingDialog(this, output);
1707 d->exec();
1708 delete d;
1709 }
1710
1711 int MainWindow::extractChangeCount(QString text)
1712 {
1713 QRegExp re("added (\\d+) ch\\w+ with (\\d+) ch\\w+ to (\\d+) f\\w+");
1714 if (re.indexIn(text) >= 0) {
1715 return re.cap(1).toInt();
1716 } else if (text.contains("no changes")) {
1717 return 0;
1718 } else {
1719 return -1; // unknown
1720 }
1721 }
1722
1723 void MainWindow::showPushResult(QString output)
1724 {
1725 QString head;
1726 QString report;
1727 int n = extractChangeCount(output);
1728 if (n > 0) {
1729 head = tr("Pushed %n changeset(s)", "", n);
1730 report = tr("<qt>Successfully pushed to the remote repository at <code>%1</code>.</qt>").arg(xmlEncode(m_remoteRepoPath));
1731 } else if (n == 0) {
1732 head = tr("No changes to push");
1733 report = tr("The remote repository already contains all changes that have been committed locally.");
1734 if (m_hgTabs->canCommit()) {
1735 report = tr("%1<p>You do have some uncommitted changes. If you wish to push those to the remote repository, commit them locally first.").arg(report);
1736 }
1737 } else {
1738 head = tr("Push complete");
1739 }
1740 m_runner->hide();
1741
1742 MoreInformationDialog::information(this, tr("Push complete"),
1743 head, report, output);
1744 }
1745
1746 void MainWindow::showPullResult(QString output)
1747 {
1748 QString head;
1749 QString report;
1750 int n = extractChangeCount(output);
1751 if (n > 0) {
1752 head = tr("Pulled %n changeset(s)", "", n);
1753 report = tr("New changes will be highlighted in yellow in the history.");
1754 } else if (n == 0) {
1755 head = tr("No changes to pull");
1756 report = tr("Your local repository already contains all changes found in the remote repository.");
1757 } else {
1758 head = tr("Pull complete");
1759 }
1760 m_runner->hide();
1761
1762 MoreInformationDialog::information(this, tr("Pull complete"),
1763 head, report, output);
1764 }
1765
1766 void MainWindow::reportNewRemoteHeads(QString output)
1767 {
1768 bool headsAreLocal = false;
1769
1770 if (m_currentParents.size() == 1) {
1771 int m_currentBranchHeads = 0;
1772 bool parentIsHead = false;
1773 Changeset *parent = m_currentParents[0];
1774 foreach (Changeset *head, m_currentHeads) {
1775 if (head->isOnBranch(m_currentBranch)) {
1776 ++m_currentBranchHeads;
1777 }
1778 if (parent->id() == head->id()) {
1779 parentIsHead = true;
1780 }
1781 }
1782 if (m_currentBranchHeads == 2 && parentIsHead) {
1783 headsAreLocal = true;
1784 }
1785 }
1786
1787 if (headsAreLocal) {
1788 MoreInformationDialog::warning
1789 (this,
1790 tr("Push failed"),
1791 tr("Push failed"),
1792 tr("Your local repository could not be pushed to the remote repository.<br><br>You may need to merge the changes locally first."),
1793 output);
1794 } else if (m_hgTabs->canCommit() && m_currentParents.size() > 1) {
1795 MoreInformationDialog::warning
1796 (this,
1797 tr("Push failed"),
1798 tr("Push failed"),
1799 tr("Your local repository could not be pushed to the remote repository.<br><br>You have an uncommitted merge in your local folder. You probably need to commit it before you push."),
1800 output);
1801 } else {
1802 MoreInformationDialog::warning
1803 (this,
1804 tr("Push failed"),
1805 tr("Push failed"),
1806 tr("Your local repository could not be pushed to the remote repository.<br><br>The remote repository may have been changed by someone else since you last pushed. Try pulling and merging their changes into your local repository first."),
1807 output);
1808 }
1809 }
1810
1811 void MainWindow::reportAuthFailed(QString output)
1812 {
1813 MoreInformationDialog::warning
1814 (this,
1815 tr("Authorization failed"),
1816 tr("Authorization failed"),
1817 tr("You may have entered an incorrect user name or password, or the remote URL may be wrong.<br><br>Or you may lack the necessary permissions on the remote repository.<br><br>Check with the administrator of your remote repository if necessary."),
1818 output);
1819 }
1820
1821 void MainWindow::commandStarting(HgAction action)
1822 {
1823 // Annoyingly, hg stat actually modifies the working directory --
1824 // it creates files called hg-checklink and hg-checkexec to test
1825 // properties of the filesystem. For safety's sake, suspend the
1826 // fs watcher while running commands, and restore it shortly after
1827 // a command has finished.
1828
1829 if (action.action == ACT_STAT) {
1830 suspendFileSystemWatcher();
1831 }
1832 }
1833
1834 void MainWindow::commandFailed(HgAction action, QString output)
1835 {
1836 DEBUG << "MainWindow::commandFailed" << endl;
1837 restoreFileSystemWatcher();
1838
1839 QString setstr;
1840 #ifdef Q_OS_MAC
1841 setstr = tr("Preferences");
1842 #else
1843 setstr = tr("Settings");
1844 #endif
1845
1846 // Some commands we just have to ignore bad return values from,
1847 // and some output gets special treatment.
1848
1849 // Note our fallback case should always be to report a
1850 // non-specific error and show the text -- in case output scraping
1851 // fails (as it surely will). Note also that we must force the
1852 // locale in order to ensure the output is scrapable; this happens
1853 // in HgRunner and may break some system encodings.
1854
1855 switch(action.action) {
1856 case ACT_NONE:
1857 // uh huh
1858 return;
1859 case ACT_TEST_HG:
1860 MoreInformationDialog::warning
1861 (this,
1862 tr("Failed to run Mercurial"),
1863 tr("Failed to run Mercurial"),
1864 tr("The Mercurial program either could not be found or failed to run.<br>Check that the Mercurial program path is correct in %1.").arg(setstr),
1865 output);
1866 settings();
1867 return;
1868 case ACT_TEST_HG_EXT:
1869 MoreInformationDialog::warning
1870 (this,
1871 tr("Failed to run Mercurial"),
1872 tr("Failed to run Mercurial with extension enabled"),
1873 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem.<br><br>You may be able to continue working if you switch off &ldquo;Use EasyHg Mercurial Extension&rdquo; in %1. Note that remote repositories that require authentication might not work if you do this.").arg(setstr),
1874 output);
1875 settings();
1876 return;
1877 case ACT_CLONEFROMREMOTE:
1878 // if clone fails, we have no repo
1879 m_workFolderPath = "";
1880 enableDisableActions();
1881 break; // go on to default report
1882 case ACT_INCOMING:
1883 if (output.contains("authorization failed")) {
1884 reportAuthFailed(output);
1885 return;
1886 } else if (output.contains("entry cancelled")) {
1887 // ignore this, user cancelled username or password dialog
1888 return;
1889 } else {
1890 // Incoming returns non-zero code and no output if the
1891 // check was successful but there are no changes
1892 // pending. This is the only case where we need to remove
1893 // warning messages, because it's the only case where a
1894 // non-zero code can be returned even though the command
1895 // has for our purposes succeeded
1896 QString replaced = output;
1897 while (1) {
1898 QString r1 = replaced;
1899 r1.replace(QRegExp("warning: [^\\n]*"), "");
1900 if (r1 == replaced) break;
1901 replaced = r1.trimmed();
1902 }
1903 if (replaced == "") {
1904 showIncoming("");
1905 return;
1906 }
1907 }
1908 break; // go on to default report
1909 case ACT_PULL:
1910 if (output.contains("authorization failed")) {
1911 reportAuthFailed(output);
1912 return;
1913 } else if (output.contains("entry cancelled")) {
1914 // ignore this, user cancelled username or password dialog
1915 return;
1916 }
1917 break; // go on to default report
1918 case ACT_PUSH:
1919 if (output.contains("creates new remote heads")) {
1920 reportNewRemoteHeads(output);
1921 return;
1922 } else if (output.contains("authorization failed")) {
1923 reportAuthFailed(output);
1924 return;
1925 } else if (output.contains("entry cancelled")) {
1926 // ignore this, user cancelled username or password dialog
1927 return;
1928 }
1929 break; // go on to default report
1930 case ACT_QUERY_HEADS:
1931 // fails if repo is empty; we don't care (if there's a genuine
1932 // problem, something else will fail too). Pretend it
1933 // succeeded, so that any further actions that are contingent
1934 // on the success of the heads query get carried out properly.
1935 commandCompleted(action, "");
1936 return;
1937 case ACT_FOLDERDIFF:
1938 case ACT_CHGSETDIFF:
1939 // external program, unlikely to be anything useful in stderr
1940 // and some return with failure codes when something as basic
1941 // as the user closing the window via the wm happens
1942 return;
1943 case ACT_MERGE:
1944 case ACT_RETRY_MERGE:
1945 MoreInformationDialog::information
1946 (this, tr("Merge"), tr("Merge failed"),
1947 tr("Some files were not merged successfully.<p>You can Merge again to repeat the interactive merge; use Revert to abandon the merge entirely; or edit the files that are in conflict in an editor and, when you are happy with them, choose Mark Resolved in each file's right-button menu."),
1948 output);
1949 return;
1950 case ACT_STAT:
1951 break; // go on to default report
1952 default:
1953 break;
1954 }
1955
1956 QString command = action.executable;
1957 if (command == "") command = "hg";
1958 foreach (QString arg, action.params) {
1959 command += " " + arg;
1960 }
1961
1962 MoreInformationDialog::warning
1963 (this,
1964 tr("Command failed"),
1965 tr("Command failed"),
1966 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.<br><br>See &ldquo;More Details&rdquo; for the command output."),
1967 output);
1968 }
1969
1970 void MainWindow::commandCompleted(HgAction completedAction, QString output)
1971 {
1972 restoreFileSystemWatcher();
1973 HGACTIONS action = completedAction.action;
1974
1975 if (action == ACT_NONE) return;
1976
1977 bool headsChanged = false;
1978 QStringList oldHeadIds;
1979
1980 switch (action) {
1981
1982 case ACT_TEST_HG:
1983 break;
1984
1985 case ACT_TEST_HG_EXT:
1986 break;
1987
1988 case ACT_QUERY_PATHS:
1989 {
1990 DEBUG << "stdout is " << output << endl;
1991 LogParser lp(output, "=");
1992 LogList ll = lp.parse();
1993 DEBUG << ll.size() << " results" << endl;
1994 if (!ll.empty()) {
1995 m_remoteRepoPath = lp.parse()[0]["default"].trimmed();
1996 DEBUG << "Set remote path to " << m_remoteRepoPath << endl;
1997 } else {
1998 m_remoteRepoPath = "";
1999 }
2000 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
2001 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
2002 updateWorkFolderAndRepoNames();
2003 break;
2004 }
2005
2006 case ACT_QUERY_BRANCH:
2007 m_currentBranch = output.trimmed();
2008 break;
2009
2010 case ACT_STAT:
2011 m_lastStatOutput = output;
2012 updateFileSystemWatcher();
2013 break;
2014
2015 case ACT_RESOLVE_LIST:
2016 if (output != "") {
2017 // Remove lines beginning with R (they are resolved,
2018 // and the file stat parser treats R as removed)
2019 QStringList outList = output.split('\n');
2020 QStringList winnowed;
2021 foreach (QString line, outList) {
2022 if (!line.startsWith("R ")) winnowed.push_back(line);
2023 }
2024 output = winnowed.join("\n");
2025 }
2026 DEBUG << "m_lastStatOutput = " << m_lastStatOutput << endl;
2027 DEBUG << "resolve output = " << output << endl;
2028 m_hgTabs->updateWorkFolderFileList(m_lastStatOutput + output);
2029 break;
2030
2031 case ACT_RESOLVE_MARK:
2032 m_shouldHgStat = true;
2033 break;
2034
2035 case ACT_INCOMING:
2036 showIncoming(output);
2037 break;
2038
2039 case ACT_ANNOTATE:
2040 {
2041 AnnotateDialog dialog(this, output);
2042 dialog.exec();
2043 m_shouldHgStat = true;
2044 break;
2045 }
2046
2047 case ACT_PULL:
2048 showPullResult(output);
2049 m_shouldHgStat = true;
2050 break;
2051
2052 case ACT_PUSH:
2053 showPushResult(output);
2054 break;
2055
2056 case ACT_INIT:
2057 MultiChoiceDialog::addRecentArgument("init", m_workFolderPath);
2058 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
2059 enableDisableActions();
2060 m_shouldHgStat = true;
2061 break;
2062
2063 case ACT_CLONEFROMREMOTE:
2064 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
2065 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
2066 MultiChoiceDialog::addRecentArgument("remote", m_workFolderPath, true);
2067 MoreInformationDialog::information
2068 (this,
2069 tr("Clone"),
2070 tr("Clone successful"),
2071 tr("The remote repository was successfully cloned to the local folder <code>%1</code>.").arg(xmlEncode(m_workFolderPath)),
2072 output);
2073 enableDisableActions();
2074 m_shouldHgStat = true;
2075 break;
2076
2077 case ACT_LOG:
2078 m_hgTabs->setNewLog(output);
2079 m_needNewLog = false;
2080 break;
2081
2082 case ACT_LOG_INCREMENTAL:
2083 m_hgTabs->addIncrementalLog(output);
2084 break;
2085
2086 case ACT_QUERY_PARENTS:
2087 {
2088 foreach (Changeset *cs, m_currentParents) delete cs;
2089 m_currentParents = Changeset::parseChangesets(output);
2090 QStringList parentIds = Changeset::getIds(m_currentParents);
2091 m_hgTabs->setCurrent(parentIds, m_currentBranch);
2092 }
2093 break;
2094
2095 case ACT_QUERY_HEADS:
2096 {
2097 oldHeadIds = Changeset::getIds(m_currentHeads);
2098 Changesets newHeads = Changeset::parseChangesets(output);
2099 QStringList newHeadIds = Changeset::getIds(newHeads);
2100 if (oldHeadIds != newHeadIds) {
2101 DEBUG << "Heads changed, will prompt an incremental log if appropriate" << endl;
2102 DEBUG << "Old heads: " << oldHeadIds.join(",") << endl;
2103 DEBUG << "New heads: " << newHeadIds.join(",") << endl;
2104 headsChanged = true;
2105 foreach (Changeset *cs, m_currentHeads) delete cs;
2106 m_currentHeads = newHeads;
2107 }
2108 }
2109 break;
2110
2111 case ACT_COMMIT:
2112 if (m_currentParents.empty()) {
2113 // first commit to empty repo
2114 m_needNewLog = true;
2115 }
2116 m_hgTabs->clearSelections();
2117 m_justMerged = false;
2118 m_shouldHgStat = true;
2119 break;
2120
2121 case ACT_REVERT:
2122 hgMarkFilesResolved(m_lastRevertedFiles);
2123 m_justMerged = false;
2124 break;
2125
2126 case ACT_REMOVE:
2127 case ACT_ADD:
2128 m_hgTabs->clearSelections();
2129 m_shouldHgStat = true;
2130 break;
2131
2132 case ACT_TAG:
2133 m_needNewLog = true;
2134 m_shouldHgStat = true;
2135 break;
2136
2137 case ACT_NEW_BRANCH:
2138 m_shouldHgStat = true;
2139 break;
2140
2141 case ACT_UNCOMMITTED_SUMMARY:
2142 QMessageBox::information(this, tr("Change summary"),
2143 format3(tr("Summary of uncommitted changes"),
2144 "",
2145 output));
2146 break;
2147
2148 case ACT_DIFF_SUMMARY:
2149 {
2150 // Output has log info first, diff following after a blank line
2151 output.replace("\r\n", "\n");
2152 QStringList olist = output.split("\n\n", QString::SkipEmptyParts);
2153 if (olist.size() > 1) output = olist[1];
2154
2155 Changeset *cs = (Changeset *)completedAction.extraData;
2156 if (cs) {
2157 QMessageBox::information
2158 (this, tr("Change summary"),
2159 format3(tr("Summary of changes"),
2160 cs->formatHtml(),
2161 output));
2162 } else if (output == "") {
2163 // Can happen, for a merge commit (depending on parent)
2164 QMessageBox::information(this, tr("Change summary"),
2165 format3(tr("Summary of changes"),
2166 tr("No changes"),
2167 output));
2168 } else {
2169 QMessageBox::information(this, tr("Change summary"),
2170 format3(tr("Summary of changes"),
2171 "",
2172 output));
2173 }
2174 break;
2175 }
2176
2177 case ACT_FOLDERDIFF:
2178 case ACT_CHGSETDIFF:
2179 case ACT_SERVE:
2180 case ACT_HG_IGNORE:
2181 m_shouldHgStat = true;
2182 break;
2183
2184 case ACT_UPDATE:
2185 QMessageBox::information(this, tr("Update"), tr("<qt><h3>Update successful</h3><p>%1</p>").arg(xmlEncode(output)));
2186 m_shouldHgStat = true;
2187 break;
2188
2189 case ACT_MERGE:
2190 MoreInformationDialog::information
2191 (this, tr("Merge"), tr("Merge successful"),
2192 tr("Remember to test and commit the result before making any further changes."),
2193 output);
2194 m_shouldHgStat = true;
2195 m_justMerged = true;
2196 break;
2197
2198 case ACT_RETRY_MERGE:
2199 QMessageBox::information(this, tr("Resolved"),
2200 tr("<qt><h3>Merge resolved</h3><p>Merge resolved successfully.<br>Remember to test and commit the result before making any further changes.</p>"));
2201 m_shouldHgStat = true;
2202 m_justMerged = true;
2203 break;
2204
2205 default:
2206 break;
2207 }
2208
2209 // Sequence when no full log required:
2210 // paths -> branch -> stat -> resolve-list -> heads ->
2211 // incremental-log (only if heads changed) -> parents
2212 //
2213 // Sequence when full log required:
2214 // paths -> branch -> stat -> resolve-list -> heads -> parents -> log
2215 //
2216 // Note we want to call enableDisableActions only once, at the end
2217 // of whichever sequence is in use.
2218
2219 bool noMore = false;
2220
2221 switch (action) {
2222
2223 case ACT_TEST_HG:
2224 {
2225 QSettings settings;
2226 settings.beginGroup("General");
2227 if (settings.value("useextension", true).toBool()) {
2228 hgTestExtension();
2229 } else if (m_workFolderPath == "") {
2230 open();
2231 } else {
2232 hgQueryPaths();
2233 }
2234 break;
2235 }
2236
2237 case ACT_TEST_HG_EXT:
2238 if (m_workFolderPath == "") {
2239 open();
2240 } else{
2241 hgQueryPaths();
2242 }
2243 break;
2244
2245 case ACT_QUERY_PATHS:
2246 hgQueryBranch();
2247 break;
2248
2249 case ACT_QUERY_BRANCH:
2250 hgStat();
2251 break;
2252
2253 case ACT_STAT:
2254 hgResolveList();
2255 break;
2256
2257 case ACT_RESOLVE_LIST:
2258 hgQueryHeads();
2259 break;
2260
2261 case ACT_QUERY_HEADS:
2262 if (headsChanged && !m_needNewLog) {
2263 hgLogIncremental(oldHeadIds);
2264 } else {
2265 hgQueryParents();
2266 }
2267 break;
2268
2269 case ACT_LOG_INCREMENTAL:
2270 hgQueryParents();
2271 break;
2272
2273 case ACT_QUERY_PARENTS:
2274 if (m_needNewLog) {
2275 hgLog();
2276 } else {
2277 // we're done
2278 noMore = true;
2279 }
2280 break;
2281
2282 case ACT_LOG:
2283 // we're done
2284 noMore = true;
2285 break;
2286
2287 default:
2288 if (m_shouldHgStat) {
2289 m_shouldHgStat = false;
2290 hgQueryPaths();
2291 } else {
2292 noMore = true;
2293 }
2294 break;
2295 }
2296
2297 if (noMore) {
2298 m_stateUnknown = false;
2299 enableDisableActions();
2300 m_hgTabs->updateHistory();
2301 updateRecentMenu();
2302 }
2303 }
2304
2305 void MainWindow::connectActions()
2306 {
2307 connect(m_exitAct, SIGNAL(triggered()), this, SLOT(close()));
2308 connect(m_aboutAct, SIGNAL(triggered()), this, SLOT(about()));
2309
2310 connect(m_hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh()));
2311 connect(m_hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
2312 connect(m_hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
2313 connect(m_hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
2314 connect(m_hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
2315 connect(m_hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
2316 connect(m_hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
2317 connect(m_hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
2318 connect(m_hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
2319
2320 connect(m_settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
2321 connect(m_openAct, SIGNAL(triggered()), this, SLOT(open()));
2322 connect(m_changeRemoteRepoAct, SIGNAL(triggered()), this, SLOT(changeRemoteRepo()));
2323
2324 connect(m_hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
2325 connect(m_hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
2326 connect(m_hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
2327
2328 connect(m_hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
2329 }
2330
2331 void MainWindow::connectTabsSignals()
2332 {
2333 connect(m_hgTabs, SIGNAL(currentChanged(int)),
2334 this, SLOT(enableDisableActions()));
2335
2336 connect(m_hgTabs, SIGNAL(commit()),
2337 this, SLOT(hgCommit()));
2338
2339 connect(m_hgTabs, SIGNAL(revert()),
2340 this, SLOT(hgRevert()));
2341
2342 connect(m_hgTabs, SIGNAL(diffWorkingFolder()),
2343 this, SLOT(hgFolderDiff()));
2344
2345 connect(m_hgTabs, SIGNAL(showSummary()),
2346 this, SLOT(hgShowSummary()));
2347
2348 connect(m_hgTabs, SIGNAL(newBranch()),
2349 this, SLOT(hgNewBranch()));
2350
2351 connect(m_hgTabs, SIGNAL(noBranch()),
2352 this, SLOT(hgNoBranch()));
2353
2354 connect(m_hgTabs, SIGNAL(updateTo(QString)),
2355 this, SLOT(hgUpdateToRev(QString)));
2356
2357 connect(m_hgTabs, SIGNAL(diffToCurrent(QString)),
2358 this, SLOT(hgDiffToCurrent(QString)));
2359
2360 connect(m_hgTabs, SIGNAL(diffToParent(QString, QString)),
2361 this, SLOT(hgDiffToParent(QString, QString)));
2362
2363 connect(m_hgTabs, SIGNAL(showSummary(Changeset *)),
2364 this, SLOT(hgShowSummaryFor(Changeset *)));
2365
2366 connect(m_hgTabs, SIGNAL(mergeFrom(QString)),
2367 this, SLOT(hgMergeFrom(QString)));
2368
2369 connect(m_hgTabs, SIGNAL(newBranch(QString)),
2370 this, SLOT(hgNewBranch()));
2371
2372 connect(m_hgTabs, SIGNAL(tag(QString)),
2373 this, SLOT(hgTag(QString)));
2374
2375 connect(m_hgTabs, SIGNAL(annotateFiles(QStringList)),
2376 this, SLOT(hgAnnotateFiles(QStringList)));
2377
2378 connect(m_hgTabs, SIGNAL(diffFiles(QStringList)),
2379 this, SLOT(hgDiffFiles(QStringList)));
2380
2381 connect(m_hgTabs, SIGNAL(commitFiles(QStringList)),
2382 this, SLOT(hgCommitFiles(QStringList)));
2383
2384 connect(m_hgTabs, SIGNAL(revertFiles(QStringList)),
2385 this, SLOT(hgRevertFiles(QStringList)));
2386
2387 connect(m_hgTabs, SIGNAL(renameFiles(QStringList)),
2388 this, SLOT(hgRenameFiles(QStringList)));
2389
2390 connect(m_hgTabs, SIGNAL(copyFiles(QStringList)),
2391 this, SLOT(hgCopyFiles(QStringList)));
2392
2393 connect(m_hgTabs, SIGNAL(addFiles(QStringList)),
2394 this, SLOT(hgAddFiles(QStringList)));
2395
2396 connect(m_hgTabs, SIGNAL(removeFiles(QStringList)),
2397 this, SLOT(hgRemoveFiles(QStringList)));
2398
2399 connect(m_hgTabs, SIGNAL(redoFileMerges(QStringList)),
2400 this, SLOT(hgRedoFileMerges(QStringList)));
2401
2402 connect(m_hgTabs, SIGNAL(markFilesResolved(QStringList)),
2403 this, SLOT(hgMarkFilesResolved(QStringList)));
2404
2405 connect(m_hgTabs, SIGNAL(ignoreFiles(QStringList)),
2406 this, SLOT(hgIgnoreFiles(QStringList)));
2407
2408 connect(m_hgTabs, SIGNAL(unIgnoreFiles(QStringList)),
2409 this, SLOT(hgUnIgnoreFiles(QStringList)));
2410 }
2411
2412 void MainWindow::enableDisableActions()
2413 {
2414 DEBUG << "MainWindow::enableDisableActions" << endl;
2415
2416 QString dirname = QDir(m_workFolderPath).dirName();
2417
2418 if (m_workFolderPath != "") { // dirname of "" is ".", so test path instead
2419 setWindowTitle(tr("EasyMercurial: %1").arg(dirname));
2420 } else {
2421 setWindowTitle(tr("EasyMercurial"));
2422 }
2423
2424 //!!! should also do things like set the status texts for the
2425 //!!! actions appropriately by context
2426
2427 QDir localRepoDir;
2428 QDir workFolderDir;
2429 bool workFolderExist = true;
2430 bool localRepoExist = true;
2431
2432 m_remoteRepoActionsEnabled = true;
2433 if (m_remoteRepoPath.isEmpty()) {
2434 m_remoteRepoActionsEnabled = false;
2435 }
2436
2437 m_localRepoActionsEnabled = true;
2438 if (m_workFolderPath.isEmpty()) {
2439 m_localRepoActionsEnabled = false;
2440 workFolderExist = false;
2441 }
2442
2443 if (m_workFolderPath == "" || !workFolderDir.exists(m_workFolderPath)) {
2444 m_localRepoActionsEnabled = false;
2445 workFolderExist = false;
2446 } else {
2447 workFolderExist = true;
2448 }
2449
2450 if (!localRepoDir.exists(m_workFolderPath + "/.hg")) {
2451 m_localRepoActionsEnabled = false;
2452 localRepoExist = false;
2453 }
2454
2455 bool haveDiff = false;
2456 QSettings settings;
2457 settings.beginGroup("Locations");
2458 if (settings.value("extdiffbinary", "").toString() != "") {
2459 haveDiff = true;
2460 }
2461 settings.endGroup();
2462
2463 m_hgRefreshAct->setEnabled(m_localRepoActionsEnabled);
2464 m_hgFolderDiffAct->setEnabled(m_localRepoActionsEnabled && haveDiff);
2465 m_hgRevertAct->setEnabled(m_localRepoActionsEnabled);
2466 m_hgAddAct->setEnabled(m_localRepoActionsEnabled);
2467 m_hgRemoveAct->setEnabled(m_localRepoActionsEnabled);
2468 m_hgUpdateAct->setEnabled(m_localRepoActionsEnabled);
2469 m_hgCommitAct->setEnabled(m_localRepoActionsEnabled);
2470 m_hgMergeAct->setEnabled(m_localRepoActionsEnabled);
2471 m_hgServeAct->setEnabled(m_localRepoActionsEnabled);
2472 m_hgIgnoreAct->setEnabled(m_localRepoActionsEnabled);
2473
2474 DEBUG << "m_localRepoActionsEnabled = " << m_localRepoActionsEnabled << endl;
2475 DEBUG << "canCommit = " << m_hgTabs->canCommit() << endl;
2476
2477 m_hgAddAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canAdd());
2478 m_hgRemoveAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canRemove());
2479 m_hgCommitAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canCommit());
2480 m_hgRevertAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canRevert());
2481 m_hgFolderDiffAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canDiff());
2482
2483 // A default merge makes sense if:
2484 // * there is only one parent (if there are two, we have an uncommitted merge) and
2485 // * there are exactly two heads that have the same branch as the current branch and
2486 // * our parent is one of those heads
2487 //
2488 // A default update makes sense if:
2489 // * there is only one parent and
2490 // * the parent is not one of the current heads
2491
2492 bool canMerge = false;
2493 bool canUpdate = false;
2494 bool haveMerge = false;
2495 bool emptyRepo = false;
2496 bool noWorkingCopy = false;
2497 bool newBranch = false;
2498 int m_currentBranchHeads = 0;
2499
2500 if (m_currentParents.size() == 1) {
2501 bool parentIsHead = false;
2502 Changeset *parent = m_currentParents[0];
2503 foreach (Changeset *head, m_currentHeads) {
2504 DEBUG << "head branch " << head->branch() << ", current branch " << m_currentBranch << endl;
2505 if (head->isOnBranch(m_currentBranch)) {
2506 ++m_currentBranchHeads;
2507 }
2508 if (parent->id() == head->id()) {
2509 parentIsHead = true;
2510 }
2511 }
2512 if (m_currentBranchHeads == 2 && parentIsHead) {
2513 canMerge = true;
2514 }
2515 if (m_currentBranchHeads == 0 && parentIsHead) {
2516 // Just created a new branch
2517 newBranch = true;
2518 }
2519 if (!parentIsHead) {
2520 canUpdate = true;
2521 DEBUG << "parent id = " << parent->id() << endl;
2522 DEBUG << " head ids "<<endl;
2523 foreach (Changeset *h, m_currentHeads) {
2524 DEBUG << "head id = " << h->id() << endl;
2525 }
2526 }
2527 m_justMerged = false;
2528 } else if (m_currentParents.size() == 0) {
2529 if (m_currentHeads.size() == 0) {
2530 // No heads -> empty repo
2531 emptyRepo = true;
2532 } else {
2533 // Heads, but no parents -> no working copy, e.g. we have
2534 // just converted this repo but haven't updated in it yet.
2535 // Uncommon but confusing; probably merits a special case
2536 noWorkingCopy = true;
2537 canUpdate = true;
2538 }
2539 m_justMerged = false;
2540 } else {
2541 haveMerge = true;
2542 m_justMerged = true;
2543 }
2544
2545 m_hgIncomingAct->setEnabled(m_remoteRepoActionsEnabled);
2546 m_hgPullAct->setEnabled(m_remoteRepoActionsEnabled);
2547 // permit push even if no remote yet; we'll ask for one
2548 m_hgPushAct->setEnabled(m_localRepoActionsEnabled && !emptyRepo);
2549
2550 m_hgMergeAct->setEnabled(m_localRepoActionsEnabled &&
2551 (canMerge || m_hgTabs->canResolve()));
2552 m_hgUpdateAct->setEnabled(m_localRepoActionsEnabled &&
2553 (canUpdate && !m_hgTabs->haveChangesToCommit()));
2554
2555 // Set the state field on the file status widget
2556
2557 QString branchText;
2558 if (m_currentBranch == "" || m_currentBranch == "default") {
2559 branchText = tr("the default branch");
2560 } else {
2561 branchText = tr("branch \"%1\"").arg(m_currentBranch);
2562 }
2563
2564 if (m_stateUnknown) {
2565 if (m_workFolderPath == "") {
2566 m_workStatus->setState(tr("No repository open"));
2567 } else {
2568 m_workStatus->setState(tr("(Examining repository)"));
2569 }
2570 } else if (emptyRepo) {
2571 m_workStatus->setState(tr("Nothing committed to this repository yet"));
2572 } else if (noWorkingCopy) {
2573 m_workStatus->setState(tr("No working copy yet: consider updating"));
2574 } else if (canMerge) {
2575 m_workStatus->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
2576 } else if (!m_hgTabs->getAllUnresolvedFiles().empty()) {
2577 m_workStatus->setState(tr("Have unresolved files following merge on %1").arg(branchText));
2578 } else if (haveMerge) {
2579 m_workStatus->setState(tr("Have merged but not yet committed on %1").arg(branchText));
2580 } else if (newBranch) {
2581 m_workStatus->setState(tr("On %1. New branch: has not yet been committed").arg(branchText));
2582 } else if (canUpdate) {
2583 if (m_hgTabs->haveChangesToCommit()) {
2584 // have uncommitted changes
2585 m_workStatus->setState(tr("On %1. Not at the head of the branch").arg(branchText));
2586 } else {
2587 // no uncommitted changes
2588 m_workStatus->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText));
2589 }
2590 } else if (m_currentBranchHeads > 1) {
2591 m_workStatus->setState(tr("At one of %n heads of %1", "", m_currentBranchHeads).arg(branchText));
2592 } else {
2593 m_workStatus->setState(tr("At the head of %1").arg(branchText));
2594 }
2595 }
2596
2597
2598 void MainWindow::updateRecentMenu()
2599 {
2600 m_recentMenu->clear();
2601 RecentFiles rf("Recent-local");
2602 QStringList recent = rf.getRecent();
2603 if (recent.empty()) {
2604 QLabel *label = new QLabel(tr("No recent local repositories"));
2605 QWidgetAction *wa = new QWidgetAction(m_recentMenu);
2606 wa->setDefaultWidget(label);
2607 return;
2608 }
2609 foreach (QString r, recent) {
2610 QAction *a = m_recentMenu->addAction(r);
2611 connect(a, SIGNAL(activated()), this, SLOT(recentMenuActivated()));
2612 }
2613 }
2614
2615 void MainWindow::createActions()
2616 {
2617 //File actions
2618 m_openAct = new QAction(QIcon(":/images/fileopen.png"), tr("&Open..."), this);
2619 m_openAct->setStatusTip(tr("Open an existing repository or working folder"));
2620 m_openAct->setShortcut(tr("Ctrl+O"));
2621
2622 m_changeRemoteRepoAct = new QAction(tr("Set Remote &Location..."), this);
2623 m_changeRemoteRepoAct->setStatusTip(tr("Set or change the default remote repository for pull and push actions"));
2624
2625 m_settingsAct = new QAction(QIcon(":/images/settings.png"), tr("&Settings..."), this);
2626 m_settingsAct->setStatusTip(tr("View and change application settings"));
2627
2628 #ifdef Q_OS_WIN32
2629 m_exitAct = new QAction(QIcon(":/images/exit.png"), tr("E&xit"), this);
2630 #else
2631 m_exitAct = new QAction(QIcon(":/images/exit.png"), tr("&Quit"), this);
2632 #endif
2633 m_exitAct->setShortcuts(QKeySequence::Quit);
2634 m_exitAct->setStatusTip(tr("Exit EasyMercurial"));
2635
2636 //Repository actions
2637 m_hgRefreshAct = new QAction(QIcon(":/images/status.png"), tr("&Refresh"), this);
2638 m_hgRefreshAct->setShortcut(tr("Ctrl+R"));
2639 m_hgRefreshAct->setStatusTip(tr("Refresh the window to show the current state of the working folder"));
2640
2641 m_hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Pre&view Incoming Changes"), this);
2642 m_hgIncomingAct->setIconText(tr("Preview"));
2643 m_hgIncomingAct->setStatusTip(tr("See what changes are available in the remote repository waiting to be pulled"));
2644
2645 m_hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pu&ll from Remote Repository"), this);
2646 m_hgPullAct->setIconText(tr("Pull"));
2647 m_hgPullAct->setShortcut(tr("Ctrl+L"));
2648 m_hgPullAct->setStatusTip(tr("Pull changes from the remote repository to the local repository"));
2649
2650 m_hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Pus&h to Remote Repository"), this);
2651 m_hgPushAct->setIconText(tr("Push"));
2652 m_hgPushAct->setShortcut(tr("Ctrl+H"));
2653 m_hgPushAct->setStatusTip(tr("Push changes from the local repository to the remote repository"));
2654
2655 //Workfolder actions
2656 m_hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("&Diff"), this);
2657 m_hgFolderDiffAct->setIconText(tr("Diff"));
2658 m_hgFolderDiffAct->setShortcut(tr("Ctrl+D"));
2659 m_hgFolderDiffAct->setStatusTip(tr("See what has changed in the working folder compared with the last committed state"));
2660
2661 m_hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Re&vert"), this);
2662 m_hgRevertAct->setStatusTip(tr("Throw away your changes and return to the last committed state"));
2663
2664 m_hgAddAct = new QAction(QIcon(":/images/add.png"), tr("&Add Files"), this);
2665 m_hgAddAct->setIconText(tr("Add"));
2666 m_hgAddAct->setShortcut(tr("+"));
2667 m_hgAddAct->setStatusTip(tr("Mark the selected files to be added on the next commit"));
2668
2669 m_hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("&Remove Files"), this);
2670 m_hgRemoveAct->setIconText(tr("Remove"));
2671 m_hgRemoveAct->setShortcut(tr("Del"));
2672 m_hgRemoveAct->setStatusTip(tr("Mark the selected files to be removed from version control on the next commit"));
2673
2674 m_hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("&Update to Branch Head"), this);
2675 m_hgUpdateAct->setIconText(tr("Update"));
2676 m_hgUpdateAct->setShortcut(tr("Ctrl+U"));
2677 m_hgUpdateAct->setStatusTip(tr("Update the working folder to the head of the current repository branch"));
2678
2679 m_hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("&Commit..."), this);
2680 m_hgCommitAct->setShortcut(tr("Ctrl+Return"));
2681 m_hgCommitAct->setStatusTip(tr("Commit your changes to the local repository"));
2682
2683 m_hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("&Merge"), this);
2684 m_hgMergeAct->setShortcut(tr("Ctrl+M"));
2685 m_hgMergeAct->setStatusTip(tr("Merge the two independent sets of changes in the local repository into the working folder"));
2686
2687 //Advanced actions
2688
2689 m_hgIgnoreAct = new QAction(tr("Edit .hgignore File"), this);
2690 m_hgIgnoreAct->setStatusTip(tr("Edit the .hgignore file, containing the names of files that should be ignored by Mercurial"));
2691
2692 m_hgServeAct = new QAction(tr("Serve via HTTP"), this);
2693 m_hgServeAct->setStatusTip(tr("Serve local repository via http for workgroup access"));
2694
2695 //Help actions
2696 m_aboutAct = new QAction(tr("About EasyMercurial"), this);
2697
2698 // Miscellaneous
2699 QShortcut *clearSelectionsShortcut = new QShortcut(Qt::Key_Escape, this);
2700 connect(clearSelectionsShortcut, SIGNAL(activated()),
2701 this, SLOT(clearSelections()));
2702 }
2703
2704 void MainWindow::createMenus()
2705 {
2706 m_fileMenu = menuBar()->addMenu(tr("&File"));
2707
2708 m_fileMenu->addAction(m_openAct);
2709 m_recentMenu = m_fileMenu->addMenu(tr("Open Re&cent"));
2710 m_fileMenu->addAction(m_hgRefreshAct);
2711 m_fileMenu->addSeparator();
2712 m_fileMenu->addAction(m_settingsAct);
2713 m_fileMenu->addSeparator();
2714 m_fileMenu->addAction(m_exitAct);
2715
2716 QMenu *workMenu;
2717 workMenu = menuBar()->addMenu(tr("&Work"));
2718 workMenu->addAction(m_hgFolderDiffAct);
2719 workMenu->addSeparator();
2720 workMenu->addAction(m_hgUpdateAct);
2721 workMenu->addAction(m_hgCommitAct);
2722 workMenu->addAction(m_hgMergeAct);
2723 workMenu->addSeparator();
2724 workMenu->addAction(m_hgAddAct);
2725 workMenu->addAction(m_hgRemoveAct);
2726 workMenu->addSeparator();
2727 workMenu->addAction(m_hgRevertAct);
2728
2729 QMenu *remoteMenu;
2730 remoteMenu = menuBar()->addMenu(tr("&Remote"));
2731 remoteMenu->addAction(m_hgIncomingAct);
2732 remoteMenu->addSeparator();
2733 remoteMenu->addAction(m_hgPullAct);
2734 remoteMenu->addAction(m_hgPushAct);
2735 remoteMenu->addSeparator();
2736 remoteMenu->addAction(m_changeRemoteRepoAct);
2737
2738 m_advancedMenu = menuBar()->addMenu(tr("&Advanced"));
2739 m_advancedMenu->addAction(m_hgIgnoreAct);
2740 m_advancedMenu->addSeparator();
2741 m_advancedMenu->addAction(m_hgServeAct);
2742
2743 m_helpMenu = menuBar()->addMenu(tr("Help"));
2744 m_helpMenu->addAction(m_aboutAct);
2745 }
2746
2747 void MainWindow::createToolBars()
2748 {
2749 m_fileToolBar = addToolBar(tr("File"));
2750 m_fileToolBar->setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
2751 m_fileToolBar->addAction(m_openAct);
2752 m_fileToolBar->addAction(m_hgRefreshAct);
2753 m_fileToolBar->setMovable(false);
2754
2755 m_repoToolBar = addToolBar(tr(REPOMENU_TITLE));
2756 m_repoToolBar->setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
2757 m_repoToolBar->addAction(m_hgIncomingAct);
2758 m_repoToolBar->addAction(m_hgPullAct);
2759 m_repoToolBar->addAction(m_hgPushAct);
2760 m_repoToolBar->setMovable(false);
2761
2762 m_workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE));
2763 addToolBar(Qt::LeftToolBarArea, m_workFolderToolBar);
2764 m_workFolderToolBar->setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
2765 m_workFolderToolBar->addAction(m_hgFolderDiffAct);
2766 m_workFolderToolBar->addSeparator();
2767 m_workFolderToolBar->addAction(m_hgRevertAct);
2768 m_workFolderToolBar->addAction(m_hgUpdateAct);
2769 m_workFolderToolBar->addAction(m_hgCommitAct);
2770 m_workFolderToolBar->addAction(m_hgMergeAct);
2771 m_workFolderToolBar->addSeparator();
2772 m_workFolderToolBar->addAction(m_hgAddAct);
2773 m_workFolderToolBar->addAction(m_hgRemoveAct);
2774 m_workFolderToolBar->setMovable(false);
2775
2776 updateToolBarStyle();
2777 }
2778
2779 void MainWindow::updateToolBarStyle()
2780 {
2781 QSettings settings;
2782 settings.beginGroup("Presentation");
2783 bool showText = settings.value("showiconlabels", true).toBool();
2784 settings.endGroup();
2785
2786 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
2787 tb->setToolButtonStyle(showText ?
2788 Qt::ToolButtonTextUnderIcon :
2789 Qt::ToolButtonIconOnly);
2790 }
2791 }
2792
2793 void MainWindow::updateWorkFolderAndRepoNames()
2794 {
2795 m_hgTabs->setLocalPath(m_workFolderPath);
2796
2797 m_workStatus->setLocalPath(m_workFolderPath);
2798 m_workStatus->setRemoteURL(m_remoteRepoPath);
2799 }
2800
2801 void MainWindow::createStatusBar()
2802 {
2803 statusBar()->showMessage(tr("Ready"));
2804 }
2805
2806 void MainWindow::readSettings()
2807 {
2808 QDir workFolder;
2809
2810 QSettings settings;
2811
2812 m_remoteRepoPath = settings.value("remoterepopath", "").toString();
2813 m_workFolderPath = settings.value("workfolderpath", "").toString();
2814 if (!workFolder.exists(m_workFolderPath))
2815 {
2816 m_workFolderPath = "";
2817 }
2818
2819 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
2820 QSize size = settings.value("size", QSize(550, 550)).toSize();
2821 m_firstStart = settings.value("firststart", QVariant(true)).toBool();
2822
2823 resize(size);
2824 move(pos);
2825 }
2826
2827 void MainWindow::writeSettings()
2828 {
2829 QSettings settings;
2830 settings.setValue("pos", pos());
2831 settings.setValue("size", size());
2832 settings.setValue("remoterepopath", m_remoteRepoPath);
2833 settings.setValue("workfolderpath", m_workFolderPath);
2834 settings.setValue("firststart", m_firstStart);
2835 }
2836
2837
2838
2839