annotate src/mainwindow.cpp @ 401:c3276f8998ee

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