annotate mainwindow.cpp @ 251:0689dada1419

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