annotate mainwindow.cpp @ 238:e2f2c6e3c01b

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