annotate mainwindow.cpp @ 97:05203e53b92a

* Update About box
author Chris Cannam
date Wed, 24 Nov 2010 16:53:40 +0000
parents 87ef2fa9ee8b
children 3e6c3281fb97
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@57 6 Based on HgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@57 8 Copyright (c) 2010 Chris Cannam
Chris@57 9 Copyright (c) 2010 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
Chris@50 17
jtkorhonen@0 18 #include <QStringList>
jtkorhonen@0 19 #include <QDir>
jtkorhonen@24 20 #include <QNetworkInterface>
jtkorhonen@17 21 #include <QHostAddress>
jtkorhonen@17 22 #include <QHostInfo>
jtkorhonen@34 23 #include <QDesktopServices>
Chris@50 24 #include <QStatusBar>
Chris@50 25 #include <QMessageBox>
Chris@50 26 #include <QMenuBar>
Chris@50 27 #include <QApplication>
Chris@50 28 #include <QToolBar>
Chris@61 29 #include <QToolButton>
Chris@50 30 #include <QSettings>
Chris@90 31 #include <QInputDialog>
jtkorhonen@0 32
Chris@53 33 #include "mainwindow.h"
Chris@53 34 #include "settingsdialog.h"
Chris@69 35 #include "multichoicedialog.h"
Chris@64 36 #include "startupdialog.h"
Chris@53 37 #include "colourset.h"
Chris@62 38 #include "debug.h"
Chris@74 39 #include "logparser.h"
Chris@53 40
jtkorhonen@0 41
jtkorhonen@0 42 MainWindow::MainWindow()
jtkorhonen@0 43 {
jtkorhonen@0 44 QString wndTitle;
jtkorhonen@0 45
Chris@90 46 fsWatcher = 0;
Chris@90 47
jtkorhonen@0 48 createActions();
jtkorhonen@0 49 createMenus();
jtkorhonen@0 50 createToolBars();
jtkorhonen@0 51 createStatusBar();
jtkorhonen@0 52
jtkorhonen@0 53 runner = new HgRunner(this);
Chris@62 54 connect(runner, SIGNAL(commandCompleted()),
Chris@62 55 this, SLOT(commandCompleted()));
Chris@62 56 connect(runner, SIGNAL(commandFailed()),
Chris@62 57 this, SLOT(commandFailed()));
jtkorhonen@0 58 runningAction = ACT_NONE;
jtkorhonen@0 59 statusBar()->addPermanentWidget(runner);
jtkorhonen@0 60
Chris@61 61 setWindowTitle(tr("EasyMercurial"));
jtkorhonen@0 62
jtkorhonen@0 63 remoteRepoPath = "";
jtkorhonen@0 64 workFolderPath = "";
jtkorhonen@0 65
jtkorhonen@0 66 readSettings();
jtkorhonen@0 67
jtkorhonen@0 68 tabPage = 0;
jtkorhonen@33 69 justMerged = false;
Chris@96 70 hgExp = new HgTabWidget((QWidget *) this, remoteRepoPath, workFolderPath);
jtkorhonen@0 71 setCentralWidget(hgExp);
jtkorhonen@0 72
Chris@95 73 connect(hgExp, SIGNAL(selectionChanged()),
Chris@95 74 this, SLOT(enableDisableActions()));
Chris@95 75
jtkorhonen@0 76 setUnifiedTitleAndToolBarOnMac(true);
jtkorhonen@0 77 connectActions();
jtkorhonen@0 78 enableDisableActions();
jtkorhonen@0 79
Chris@64 80 if (firstStart) {
Chris@64 81 startupDialog();
jtkorhonen@0 82 }
jtkorhonen@0 83
Chris@64 84 ColourSet *cs = ColourSet::instance();
Chris@64 85 cs->clearDefaultNames();
Chris@64 86 cs->addDefaultName("");
Chris@64 87 cs->addDefaultName(getUserInfo());
Chris@62 88
Chris@72 89 if (workFolderPath == "") {
Chris@72 90 open();
Chris@72 91 }
Chris@72 92
Chris@74 93 hgPaths();
jtkorhonen@0 94 }
jtkorhonen@0 95
jtkorhonen@0 96
jtkorhonen@0 97 void MainWindow::closeEvent(QCloseEvent *)
jtkorhonen@0 98 {
jtkorhonen@0 99 writeSettings();
Chris@90 100 delete fsWatcher;
jtkorhonen@0 101 }
jtkorhonen@0 102
jtkorhonen@0 103
Chris@64 104 QString MainWindow::getUserInfo() const
Chris@64 105 {
Chris@64 106 QSettings settings;
Chris@64 107 settings.beginGroup("User Information");
Chris@64 108 QString name = settings.value("name", getUserRealName()).toString();
Chris@64 109 QString email = settings.value("email", "").toString();
Chris@64 110
Chris@64 111 QString identifier;
Chris@64 112
Chris@64 113 if (email != "") {
Chris@64 114 identifier = QString("%1 <%2>").arg(name).arg(email);
Chris@64 115 } else {
Chris@64 116 identifier = name;
Chris@64 117 }
Chris@64 118
Chris@64 119 return identifier;
Chris@64 120 }
Chris@64 121
jtkorhonen@0 122 void MainWindow::about()
jtkorhonen@0 123 {
Chris@97 124 QMessageBox::about(this, tr("About EasyMercurial"),
Chris@97 125 tr("<qt><h2>About EasyMercurial</h2>"
Chris@97 126 "<p>EasyMercurial is a simple user interface for the "
Chris@97 127 "Mercurial version control system.</p>"
Chris@97 128 "<p>EasyMercurial is based on HgExplorer by "
Chris@97 129 "Jari Korhonen, with thanks.<br>EasyMercurial development carried out by "
Chris@97 130 "Chris Cannam for soundsoftware.ac.uk at the Centre for Digital Music, Queen Mary, University of London."
Chris@97 131 "<ul><li>Copyright &copy; 2010 Jari Korhonen</li>"
Chris@97 132 "<li>Copyright &copy; 2010 Chris Cannam</li>"
Chris@97 133 "<li>Copyright &copy; 2010 Queen Mary, University of London</li>"
Chris@97 134 "</ul>"
Chris@97 135 "<p> This program is free software; you can redistribute it and/or "
Chris@97 136 "modify it under the terms of the GNU General Public License as "
Chris@97 137 "published by the Free Software Foundation; either version 2 of the "
Chris@97 138 "License, or (at your option) any later version. See the file "
Chris@97 139 "COPYING included with this distribution for more information."));
jtkorhonen@0 140 }
jtkorhonen@0 141
Chris@94 142 void MainWindow::clearSelections()
Chris@94 143 {
Chris@94 144 hgExp->clearSelections();
Chris@94 145 }
jtkorhonen@0 146
jtkorhonen@0 147 void MainWindow::hgStat()
jtkorhonen@0 148 {
Chris@73 149 if (runningAction == ACT_NONE)
jtkorhonen@0 150 {
Chris@73 151 QStringList params;
Chris@73 152
Chris@91 153 params << "stat" << "-ardum";
Chris@73 154
Chris@73 155 runner -> startHgCommand(workFolderPath, params);
Chris@73 156 runningAction = ACT_STAT;
jtkorhonen@0 157 }
jtkorhonen@0 158 }
jtkorhonen@0 159
Chris@74 160 void MainWindow::hgPaths()
Chris@74 161 {
Chris@74 162 if (runningAction == ACT_NONE)
Chris@74 163 {
Chris@74 164 QStringList params;
Chris@74 165 params << "paths";
Chris@74 166 runner -> startHgCommand(workFolderPath, params);
Chris@74 167 runningAction = ACT_PATHS;
Chris@74 168 }
Chris@74 169 }
Chris@74 170
jtkorhonen@0 171 void MainWindow::hgHeads()
jtkorhonen@0 172 {
jtkorhonen@0 173 if (runningAction == ACT_NONE)
jtkorhonen@0 174 {
jtkorhonen@0 175 QStringList params;
jtkorhonen@0 176 params << "heads";
jtkorhonen@0 177
jtkorhonen@0 178 //on empty repos, "hg heads" will fail, don't care of that.
Chris@62 179 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 180 runningAction = ACT_HEADS;
jtkorhonen@0 181 }
jtkorhonen@0 182 }
jtkorhonen@0 183
jtkorhonen@0 184 void MainWindow::hgLog()
jtkorhonen@0 185 {
Chris@90 186 //!!! This needs to be incremental, except when we pull or set new repo
jtkorhonen@0 187 if (runningAction == ACT_NONE)
jtkorhonen@0 188 {
jtkorhonen@0 189 QStringList params;
Chris@43 190 params << "log";
Chris@43 191 params << "--template";
Chris@52 192 params << "id: {rev}:{node|short}\\nauthor: {author}\\nbranch: {branches}\\ntag: {tag}\\ndatetime: {date|isodate}\\ntimestamp: {date|hgdate}\\nage: {date|age}\\nparents: {parents}\\ncomment: {desc|json}\\n\\n";
jtkorhonen@0 193
Chris@62 194 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 195 runningAction = ACT_LOG;
jtkorhonen@0 196 }
jtkorhonen@0 197 }
jtkorhonen@0 198
jtkorhonen@0 199
jtkorhonen@0 200 void MainWindow::hgParents()
jtkorhonen@0 201 {
jtkorhonen@0 202 if (runningAction == ACT_NONE)
jtkorhonen@0 203 {
jtkorhonen@0 204 QStringList params;
jtkorhonen@0 205 params << "parents";
jtkorhonen@0 206
Chris@62 207 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 208 runningAction = ACT_PARENTS;
jtkorhonen@0 209 }
jtkorhonen@0 210 }
jtkorhonen@0 211
jtkorhonen@0 212
jtkorhonen@0 213
jtkorhonen@0 214 void MainWindow::hgRemove()
jtkorhonen@0 215 {
jtkorhonen@0 216 if (runningAction == ACT_NONE)
jtkorhonen@0 217 {
jtkorhonen@0 218 QStringList params;
Chris@91 219 QString currentFile;//!!! = hgExp -> getCurrentFileListLine();
jtkorhonen@0 220
jtkorhonen@0 221 if (!currentFile.isEmpty())
jtkorhonen@0 222 {
jtkorhonen@6 223 if (QMessageBox::Ok == QMessageBox::warning(this, "Remove file", "Really remove file " + currentFile.mid(2) + "?",
jtkorhonen@6 224 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel))
jtkorhonen@6 225 {
mg@41 226 params << "remove" << "--after" << "--force" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@0 227
Chris@62 228 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@6 229 runningAction = ACT_REMOVE;
jtkorhonen@6 230 }
jtkorhonen@0 231 }
jtkorhonen@0 232 }
jtkorhonen@0 233 }
jtkorhonen@0 234
jtkorhonen@0 235 void MainWindow::hgAnnotate()
jtkorhonen@0 236 {
jtkorhonen@0 237 if (runningAction == ACT_NONE)
jtkorhonen@0 238 {
jtkorhonen@0 239 QStringList params;
Chris@91 240 QString currentFile;//!!! = hgExp -> getCurrentFileListLine();
jtkorhonen@0 241
jtkorhonen@0 242 if (!currentFile.isEmpty())
jtkorhonen@0 243 {
mg@41 244 params << "annotate" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@0 245
Chris@62 246 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 247 runningAction = ACT_ANNOTATE;
jtkorhonen@0 248 }
jtkorhonen@0 249 }
jtkorhonen@0 250 }
jtkorhonen@0 251
jtkorhonen@0 252
jtkorhonen@0 253 void MainWindow::hgResolveMark()
jtkorhonen@0 254 {
jtkorhonen@0 255 if (runningAction == ACT_NONE)
jtkorhonen@0 256 {
jtkorhonen@0 257 QStringList params;
Chris@91 258 QString currentFile;//!!! = hgExp -> getCurrentFileListLine();
jtkorhonen@0 259
jtkorhonen@0 260 if (!currentFile.isEmpty())
jtkorhonen@0 261 {
mg@41 262 params << "resolve" << "--mark" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@0 263
Chris@62 264 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 265 runningAction = ACT_RESOLVE_MARK;
jtkorhonen@0 266 }
jtkorhonen@0 267 }
jtkorhonen@0 268 }
jtkorhonen@0 269
jtkorhonen@0 270
jtkorhonen@0 271
jtkorhonen@0 272 void MainWindow::hgResolveList()
jtkorhonen@0 273 {
jtkorhonen@0 274 if (runningAction == ACT_NONE)
jtkorhonen@0 275 {
jtkorhonen@0 276 QStringList params;
jtkorhonen@0 277
jtkorhonen@0 278 params << "resolve" << "--list";
Chris@62 279 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 280 runningAction = ACT_RESOLVE_LIST;
jtkorhonen@0 281 }
jtkorhonen@0 282 }
jtkorhonen@0 283
jtkorhonen@0 284
jtkorhonen@0 285
jtkorhonen@0 286 void MainWindow::hgAdd()
jtkorhonen@0 287 {
jtkorhonen@0 288 if (runningAction == ACT_NONE)
jtkorhonen@0 289 {
jtkorhonen@0 290 QStringList params;
jtkorhonen@0 291
Chris@91 292 QString currentFile;//!!! = hgExp -> getCurrentFileListLine();
Chris@91 293 /*!!!
jtkorhonen@17 294 if (areAllSelectedUntracked(hgExp -> workFolderFileList))
jtkorhonen@5 295 {
jtkorhonen@17 296 //User wants to add selected file(s)
jtkorhonen@42 297 params << "add" << "--";
jtkorhonen@17 298
jtkorhonen@17 299 QList <QListWidgetItem *> selList = hgExp -> workFolderFileList -> selectedItems();
jtkorhonen@17 300
jtkorhonen@17 301 for (int i = 0; i < selList.size(); ++i)
jtkorhonen@17 302 {
jtkorhonen@17 303 QString tmp = selList.at(i)->text();
jtkorhonen@17 304 params.append(tmp.mid(2));
jtkorhonen@17 305 }
jtkorhonen@5 306 }
jtkorhonen@5 307 else
jtkorhonen@5 308 {
jtkorhonen@5 309 //Add all untracked files
jtkorhonen@5 310 params << "add";
jtkorhonen@5 311 }
jtkorhonen@0 312
Chris@62 313 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 314 runningAction = ACT_ADD;
Chris@91 315 */
jtkorhonen@0 316 }
jtkorhonen@0 317 }
jtkorhonen@0 318
Chris@90 319 bool MainWindow::getCommentOrTag(QString& commentOrTag,
Chris@90 320 QString question,
Chris@90 321 QString dlgTitle)
jtkorhonen@0 322 {
Chris@90 323 bool ok = false;
Chris@90 324 QString text = QInputDialog::getText(this, dlgTitle, question, QLineEdit::Normal, commentOrTag, &ok);
Chris@90 325 commentOrTag = text;
Chris@90 326 return ok;
Chris@90 327
Chris@90 328 /*!!!
jtkorhonen@0 329 int ret;
jtkorhonen@0 330
jtkorhonen@0 331 QDialog dlg(this);
jtkorhonen@0 332
jtkorhonen@34 333 QLabel *commentLabel = new QLabel(question);
jtkorhonen@34 334 QLineEdit *commentOrTagEdit = new QLineEdit;
jtkorhonen@34 335 commentOrTagEdit -> setFixedWidth(400);
jtkorhonen@0 336 QHBoxLayout *commentLayout = new QHBoxLayout;
jtkorhonen@0 337 commentLayout -> addWidget(commentLabel);
jtkorhonen@34 338 commentLayout -> addWidget(commentOrTagEdit);
jtkorhonen@0 339
jtkorhonen@0 340 QPushButton *btnOk = new QPushButton(tr("Ok"));
jtkorhonen@0 341 QPushButton *btnCancel = new QPushButton(tr("Cancel"));
jtkorhonen@0 342 QHBoxLayout *btnLayout = new QHBoxLayout;
jtkorhonen@0 343 btnLayout -> addWidget(btnOk);
jtkorhonen@0 344 btnLayout -> addWidget(btnCancel);
jtkorhonen@0 345
jtkorhonen@0 346 QVBoxLayout *mainLayout = new QVBoxLayout;
jtkorhonen@0 347 mainLayout -> addLayout(commentLayout);
jtkorhonen@0 348 mainLayout -> addLayout(btnLayout);
jtkorhonen@0 349
jtkorhonen@0 350 dlg.setLayout(mainLayout);
jtkorhonen@0 351
jtkorhonen@34 352 dlg.setWindowTitle(dlgTitle);
jtkorhonen@0 353
jtkorhonen@0 354 connect(btnOk, SIGNAL(clicked()), &dlg, SLOT(accept()));
jtkorhonen@0 355 connect(btnCancel, SIGNAL(clicked()), &dlg, SLOT(reject()));
jtkorhonen@0 356
jtkorhonen@0 357 ret = dlg.exec();
jtkorhonen@34 358 commentOrTag = commentOrTagEdit -> text();
jtkorhonen@0 359 return ret;
Chris@90 360 */
jtkorhonen@0 361 }
jtkorhonen@0 362
jtkorhonen@0 363 void MainWindow::hgCommit()
jtkorhonen@0 364 {
Chris@94 365 //!!! Now that hg actions can be fired asynchronously (e.g. from
Chris@94 366 // the filesystem modified callback) we _really_ need to be able to
Chris@94 367 // queue important actions rather than just ignore them if busy!
Chris@94 368
jtkorhonen@0 369 if (runningAction == ACT_NONE)
jtkorhonen@0 370 {
jtkorhonen@0 371 QStringList params;
jtkorhonen@0 372 QString comment;
jtkorhonen@0 373
Chris@90 374 if (getCommentOrTag(comment, tr("Comment:"), tr("Save (commit)")))
jtkorhonen@0 375 {
jtkorhonen@0 376 if (!comment.isEmpty())
jtkorhonen@0 377 {
Chris@91 378 /*!!!
jtkorhonen@33 379 if ((justMerged == false) && (areAllSelectedCommitable(hgExp -> workFolderFileList)))
jtkorhonen@11 380 {
jtkorhonen@33 381 //User wants to commit selected file(s) (and this is not merge commit, which would fail if we selected files)
Chris@64 382 params << "commit" << "--message" << comment << "--user" << getUserInfo() << "--";
jtkorhonen@17 383
jtkorhonen@17 384 QList <QListWidgetItem *> selList = hgExp -> workFolderFileList -> selectedItems();
jtkorhonen@17 385 for (int i = 0; i < selList.size(); ++i)
jtkorhonen@17 386 {
jtkorhonen@17 387 QString tmp = selList.at(i)->text();
jtkorhonen@17 388 params.append(tmp.mid(2));
jtkorhonen@17 389 }
jtkorhonen@11 390 }
jtkorhonen@11 391 else
jtkorhonen@11 392 {
jtkorhonen@11 393 //Commit all changes
Chris@64 394 params << "commit" << "--message" << comment << "--user" << getUserInfo();
jtkorhonen@11 395 }
jtkorhonen@0 396
Chris@62 397 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 398 runningAction = ACT_COMMIT;
Chris@91 399 */
jtkorhonen@0 400 }
jtkorhonen@0 401 }
jtkorhonen@0 402 }
jtkorhonen@0 403 }
jtkorhonen@0 404
jtkorhonen@34 405 QString MainWindow::filterTag(QString tag)
jtkorhonen@34 406 {
jtkorhonen@34 407 for(int i = 0; i < tag.size(); i++)
jtkorhonen@34 408 {
jtkorhonen@34 409 if (tag[i].isLower() || tag[i].isUpper() || tag[i].isDigit() || (tag[i] == QChar('.')))
jtkorhonen@34 410 {
jtkorhonen@34 411 //ok
jtkorhonen@34 412 }
jtkorhonen@34 413 else
jtkorhonen@34 414 {
jtkorhonen@34 415 tag[i] = QChar('_');
jtkorhonen@34 416 }
jtkorhonen@34 417 }
jtkorhonen@34 418 return tag;
jtkorhonen@34 419 }
jtkorhonen@34 420
jtkorhonen@34 421
jtkorhonen@34 422 void MainWindow::hgTag()
jtkorhonen@34 423 {
jtkorhonen@34 424 if (runningAction == ACT_NONE)
jtkorhonen@34 425 {
jtkorhonen@34 426 QStringList params;
jtkorhonen@34 427 QString tag;
jtkorhonen@34 428
Chris@90 429 if (getCommentOrTag(tag, tr("Tag:"), tr("Tag")))
jtkorhonen@34 430 {
jtkorhonen@34 431 if (!tag.isEmpty())
jtkorhonen@34 432 {
Chris@64 433 params << "tag" << "--user" << getUserInfo() << filterTag(tag);
jtkorhonen@34 434
Chris@62 435 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@34 436 runningAction = ACT_TAG;
jtkorhonen@34 437 }
jtkorhonen@34 438 }
jtkorhonen@34 439 }
jtkorhonen@34 440 }
jtkorhonen@34 441
jtkorhonen@34 442
jtkorhonen@34 443 void MainWindow::hgIgnore()
jtkorhonen@34 444 {
jtkorhonen@34 445 if (runningAction == ACT_NONE)
jtkorhonen@34 446 {
jtkorhonen@34 447 QString hgIgnorePath;
jtkorhonen@36 448 QStringList params;
jtkorhonen@36 449 QString editorName;
jtkorhonen@34 450
jtkorhonen@36 451 hgIgnorePath = workFolderPath;
jtkorhonen@34 452 hgIgnorePath += ".hgignore";
jtkorhonen@34 453
jtkorhonen@36 454 params << hgIgnorePath;
jtkorhonen@36 455
jtkorhonen@36 456 if ((getSystem() == "Linux"))
jtkorhonen@36 457 {
jtkorhonen@36 458 editorName = "gedit";
jtkorhonen@36 459 }
jtkorhonen@36 460 else
jtkorhonen@36 461 {
jtkorhonen@36 462 editorName = """C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe""";
jtkorhonen@36 463 }
jtkorhonen@36 464
Chris@62 465 runner -> startCommand(editorName, workFolderPath, params);
jtkorhonen@36 466 runningAction = ACT_HG_IGNORE;
jtkorhonen@34 467 }
jtkorhonen@34 468 }
jtkorhonen@34 469
jtkorhonen@34 470
jtkorhonen@34 471
jtkorhonen@0 472 void MainWindow::hgFileDiff()
jtkorhonen@0 473 {
jtkorhonen@0 474 if (runningAction == ACT_NONE)
jtkorhonen@0 475 {
jtkorhonen@0 476 QStringList params;
Chris@91 477 /*!!!
jtkorhonen@0 478 QString currentFile = hgExp -> getCurrentFileListLine();
jtkorhonen@0 479
jtkorhonen@0 480 if (!currentFile.isEmpty())
jtkorhonen@0 481 {
jtkorhonen@0 482 //Diff parent file against working folder file
mg@41 483 params << "kdiff3" << "--" << currentFile.mid(2);
Chris@62 484 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 485 runningAction = ACT_FILEDIFF;
jtkorhonen@0 486 }
Chris@91 487 */
jtkorhonen@0 488 }
jtkorhonen@0 489 }
jtkorhonen@0 490
jtkorhonen@0 491
jtkorhonen@0 492 void MainWindow::hgFolderDiff()
jtkorhonen@0 493 {
jtkorhonen@0 494 if (runningAction == ACT_NONE)
jtkorhonen@0 495 {
jtkorhonen@0 496 QStringList params;
jtkorhonen@0 497
jtkorhonen@0 498 //Diff parent against working folder (folder diff)
jtkorhonen@0 499 params << "kdiff3";
Chris@62 500 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 501 runningAction = ACT_FOLDERDIFF;
jtkorhonen@0 502 }
jtkorhonen@0 503 }
jtkorhonen@0 504
jtkorhonen@0 505
jtkorhonen@0 506 void MainWindow::hgChgSetDiff()
jtkorhonen@0 507 {
jtkorhonen@0 508 if (runningAction == ACT_NONE)
jtkorhonen@0 509 {
jtkorhonen@0 510 QStringList params;
jtkorhonen@0 511
jtkorhonen@0 512 //Diff 2 history log versions against each other
jtkorhonen@0 513 QString revA;
jtkorhonen@0 514 QString revB;
Chris@91 515 /*!!!
jtkorhonen@0 516 hgExp -> getHistoryDiffRevisions(revA, revB);
jtkorhonen@0 517
jtkorhonen@0 518 if ((!revA.isEmpty()) && (!revB.isEmpty()))
jtkorhonen@0 519 {
jtkorhonen@0 520 params << "kdiff3" << "--rev" << revA << "--rev" << revB;
Chris@62 521 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 522 runningAction = ACT_CHGSETDIFF;
jtkorhonen@0 523 }
jtkorhonen@0 524 else
jtkorhonen@0 525 {
jtkorhonen@0 526 QMessageBox::information(this, tr("Changeset diff"), tr("Please select two changesets from history list or heads list first."));
jtkorhonen@0 527 }
Chris@91 528 */
jtkorhonen@0 529 }
jtkorhonen@0 530 }
jtkorhonen@0 531
jtkorhonen@0 532
jtkorhonen@0 533
jtkorhonen@0 534 void MainWindow::hgUpdate()
jtkorhonen@0 535 {
jtkorhonen@0 536 if (runningAction == ACT_NONE)
jtkorhonen@0 537 {
jtkorhonen@0 538 QStringList params;
jtkorhonen@0 539
jtkorhonen@0 540
jtkorhonen@0 541 params << "update";
jtkorhonen@0 542
jtkorhonen@0 543
Chris@62 544 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 545 runningAction = ACT_UPDATE;
jtkorhonen@0 546 }
jtkorhonen@0 547 }
jtkorhonen@0 548
jtkorhonen@0 549
jtkorhonen@0 550 void MainWindow::hgUpdateToRev()
jtkorhonen@0 551 {
jtkorhonen@0 552 if (runningAction == ACT_NONE)
jtkorhonen@0 553 {
jtkorhonen@0 554 QStringList params;
jtkorhonen@0 555 QString rev;
Chris@91 556 /*!!!
jtkorhonen@0 557 hgExp -> getUpdateToRevRevision(rev);
jtkorhonen@0 558
jtkorhonen@0 559 hgExp -> setCurrentIndex(WORKTAB);
jtkorhonen@0 560 enableDisableActions();
jtkorhonen@0 561
jtkorhonen@0 562 params << "update" << "--rev" << rev << "--clean";
jtkorhonen@0 563
Chris@62 564 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 565
jtkorhonen@0 566 runningAction = ACT_UPDATE;
Chris@91 567 */
jtkorhonen@0 568 }
jtkorhonen@0 569 }
jtkorhonen@0 570
jtkorhonen@0 571
jtkorhonen@0 572 void MainWindow::hgRevert()
jtkorhonen@0 573 {
jtkorhonen@0 574 if (runningAction == ACT_NONE)
jtkorhonen@0 575 {
Chris@91 576 /*!!!
jtkorhonen@0 577 QStringList params;
jtkorhonen@0 578 QString currentFile = hgExp -> getCurrentFileListLine();
jtkorhonen@0 579
mg@41 580 params << "revert" << "--no-backup" << "--" << currentFile.mid(2);
jtkorhonen@0 581
Chris@62 582 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 583 runningAction = ACT_REVERT;
Chris@91 584 */
jtkorhonen@0 585 }
jtkorhonen@0 586 }
jtkorhonen@0 587
jtkorhonen@33 588 void MainWindow::hgRetryMerge()
jtkorhonen@33 589 {
jtkorhonen@33 590 if (runningAction == ACT_NONE)
jtkorhonen@33 591 {
jtkorhonen@33 592 QStringList params;
jtkorhonen@33 593
jtkorhonen@33 594 params << "resolve" << "--all";
Chris@62 595 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@33 596 runningAction = ACT_RETRY_MERGE;
jtkorhonen@33 597 }
jtkorhonen@33 598 }
jtkorhonen@33 599
jtkorhonen@33 600
jtkorhonen@0 601 void MainWindow::hgMerge()
jtkorhonen@0 602 {
jtkorhonen@0 603 if (runningAction == ACT_NONE)
jtkorhonen@0 604 {
jtkorhonen@0 605 QStringList params;
jtkorhonen@0 606
jtkorhonen@0 607 params << "merge";
jtkorhonen@0 608
Chris@62 609 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 610 runningAction = ACT_MERGE;
jtkorhonen@0 611 }
jtkorhonen@0 612 }
jtkorhonen@0 613
jtkorhonen@0 614
jtkorhonen@0 615 void MainWindow::hgCloneFromRemote()
jtkorhonen@0 616 {
jtkorhonen@0 617 if (runningAction == ACT_NONE)
jtkorhonen@0 618 {
jtkorhonen@0 619 QStringList params;
jtkorhonen@0 620
jtkorhonen@0 621 params << "clone" << remoteRepoPath << workFolderPath;
jtkorhonen@0 622
Chris@62 623 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 624 runningAction = ACT_CLONEFROMREMOTE;
jtkorhonen@0 625 }
jtkorhonen@0 626 }
jtkorhonen@0 627
jtkorhonen@0 628
jtkorhonen@0 629 void MainWindow::hgInit()
jtkorhonen@0 630 {
jtkorhonen@0 631 if (runningAction == ACT_NONE)
jtkorhonen@0 632 {
jtkorhonen@0 633 QStringList params;
jtkorhonen@0 634
jtkorhonen@0 635 params << "init";
Chris@84 636 params << workFolderPath;
jtkorhonen@0 637
Chris@62 638 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 639 runningAction = ACT_INIT;
jtkorhonen@0 640 }
jtkorhonen@0 641 }
jtkorhonen@0 642
jtkorhonen@0 643
jtkorhonen@0 644 void MainWindow::hgIncoming()
jtkorhonen@0 645 {
jtkorhonen@0 646 if (runningAction == ACT_NONE)
jtkorhonen@0 647 {
jtkorhonen@0 648 QStringList params;
jtkorhonen@0 649
jtkorhonen@0 650 params << "incoming" << "--newest-first" << remoteRepoPath;
jtkorhonen@0 651
Chris@62 652 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 653 runningAction = ACT_INCOMING;
jtkorhonen@0 654 }
jtkorhonen@0 655 }
jtkorhonen@0 656
jtkorhonen@0 657
jtkorhonen@0 658 void MainWindow::hgPull()
jtkorhonen@0 659 {
jtkorhonen@0 660 if (runningAction == ACT_NONE)
jtkorhonen@0 661 {
jtkorhonen@0 662 QStringList params;
jtkorhonen@0 663
jtkorhonen@0 664 params << "pull" << remoteRepoPath;
jtkorhonen@0 665
Chris@62 666 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 667 runningAction = ACT_PULL;
jtkorhonen@0 668 }
jtkorhonen@0 669 }
jtkorhonen@0 670
jtkorhonen@0 671
jtkorhonen@0 672 void MainWindow::hgPush()
jtkorhonen@0 673 {
jtkorhonen@0 674 if (runningAction == ACT_NONE)
jtkorhonen@0 675 {
jtkorhonen@0 676 QStringList params;
jtkorhonen@0 677
jtkorhonen@0 678 params << "push" << remoteRepoPath;
jtkorhonen@0 679
Chris@62 680 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 681 runningAction = ACT_PUSH;
jtkorhonen@0 682 }
jtkorhonen@0 683 }
jtkorhonen@0 684
jtkorhonen@0 685
jtkorhonen@28 686 QString MainWindow::listAllUpIpV4Addresses()
jtkorhonen@26 687 {
jtkorhonen@28 688 QString ret;
jtkorhonen@26 689 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
jtkorhonen@26 690
jtkorhonen@26 691 for (int i = 0; i < ifaces.count(); i++)
jtkorhonen@26 692 {
jtkorhonen@26 693 QNetworkInterface iface = ifaces.at(i);
jtkorhonen@26 694
jtkorhonen@26 695 if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack))
jtkorhonen@26 696 {
jtkorhonen@26 697 for (int j=0; j<iface.addressEntries().count(); j++)
jtkorhonen@26 698 {
jtkorhonen@28 699 QHostAddress tmp = iface.addressEntries().at(j).ip();
jtkorhonen@28 700 if (QAbstractSocket::IPv4Protocol == tmp.protocol())
jtkorhonen@24 701 {
jtkorhonen@28 702 if (!ret.isEmpty())
jtkorhonen@28 703 {
jtkorhonen@28 704 ret += " ";
jtkorhonen@28 705 }
jtkorhonen@28 706 ret += tmp.toString();
jtkorhonen@24 707 }
jtkorhonen@24 708 }
jtkorhonen@22 709 }
jtkorhonen@17 710 }
jtkorhonen@28 711 return ret;
jtkorhonen@28 712 }
jtkorhonen@17 713
jtkorhonen@17 714
jtkorhonen@11 715 void MainWindow::hgServe()
jtkorhonen@11 716 {
jtkorhonen@11 717 if (runningAction == ACT_NONE)
jtkorhonen@11 718 {
jtkorhonen@11 719 QStringList params;
jtkorhonen@22 720 QString msg;
jtkorhonen@11 721
jtkorhonen@28 722 QString addrs = listAllUpIpV4Addresses();
jtkorhonen@28 723 QTextStream(&msg) << "Server running on address(es) (" << addrs << "), port 8000";
jtkorhonen@28 724 params << "serve";
jtkorhonen@11 725
Chris@62 726 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@11 727 runningAction = ACT_SERVE;
jtkorhonen@11 728
jtkorhonen@17 729 QMessageBox::information(this, "Serve", msg, QMessageBox::Close);
Chris@62 730 runner -> killCurrentCommand();
jtkorhonen@11 731 }
jtkorhonen@11 732 }
jtkorhonen@11 733
jtkorhonen@11 734
Chris@64 735 void MainWindow::startupDialog()
Chris@64 736 {
Chris@64 737 StartupDialog *dlg = new StartupDialog(this);
Chris@65 738 if (dlg->exec()) firstStart = false;
Chris@64 739 }
Chris@64 740
jtkorhonen@11 741
Chris@69 742 void MainWindow::open()
Chris@69 743 {
Chris@86 744 bool done = false;
Chris@69 745
Chris@86 746 while (!done) {
Chris@69 747
Chris@86 748 MultiChoiceDialog *d = new MultiChoiceDialog
Chris@86 749 (tr("Open Repository"),
Chris@86 750 tr("<qt><big>What would you like to open?</big></qt>"),
Chris@86 751 this);
Chris@69 752
Chris@86 753 d->addChoice("remote",
Chris@86 754 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
Chris@86 755 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
Chris@86 756 MultiChoiceDialog::UrlToDirectoryArg);
Chris@69 757
Chris@86 758 d->addChoice("local",
Chris@86 759 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
Chris@86 760 tr("Open an existing local Mercurial repository."),
Chris@86 761 MultiChoiceDialog::DirectoryArg);
Chris@69 762
Chris@86 763 d->addChoice("init",
Chris@86 764 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
Chris@86 765 tr("Open a local folder, by creating a Mercurial repository in it."),
Chris@86 766 MultiChoiceDialog::DirectoryArg);
Chris@79 767
Chris@86 768 d->setCurrentChoice("local");
Chris@86 769
Chris@86 770 if (d->exec() == QDialog::Accepted) {
Chris@86 771
Chris@86 772 QString choice = d->getCurrentChoice();
Chris@86 773 QString arg = d->getArgument().trimmed();
Chris@86 774
Chris@86 775 bool result = false;
Chris@86 776
Chris@86 777 if (choice == "local") {
Chris@86 778 result = openLocal(arg);
Chris@86 779 } else if (choice == "remote") {
Chris@86 780 result = openRemote(arg, d->getAdditionalArgument().trimmed());
Chris@86 781 } else if (choice == "init") {
Chris@86 782 result = openInit(arg);
Chris@86 783 }
Chris@86 784
Chris@86 785 if (result) {
Chris@86 786 enableDisableActions();
Chris@86 787 hgPaths();
Chris@91 788 done = true;
Chris@91 789 }
Chris@86 790
Chris@86 791 } else {
Chris@86 792
Chris@86 793 // cancelled
Chris@86 794 done = true;
Chris@69 795 }
Chris@79 796
Chris@86 797 delete d;
Chris@69 798 }
Chris@69 799 }
Chris@69 800
Chris@79 801 bool MainWindow::complainAboutFilePath(QString arg)
Chris@79 802 {
Chris@79 803 QMessageBox::critical
Chris@79 804 (this, tr("File chosen"),
Chris@84 805 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 806 return false;
Chris@79 807 }
Chris@79 808
Chris@79 809 bool MainWindow::complainAboutUnknownFolder(QString arg)
Chris@79 810 {
Chris@79 811 QMessageBox::critical
Chris@79 812 (this, tr("Folder does not exist"),
Chris@84 813 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 814 return false;
Chris@84 815 }
Chris@84 816
Chris@84 817 bool MainWindow::complainAboutInitInRepo(QString arg)
Chris@84 818 {
Chris@84 819 QMessageBox::critical
Chris@84 820 (this, tr("Path is in existing repository"),
Chris@84 821 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 822 return false;
Chris@84 823 }
Chris@84 824
Chris@84 825 bool MainWindow::complainAboutInitFile(QString arg)
Chris@84 826 {
Chris@84 827 QMessageBox::critical
Chris@84 828 (this, tr("Path is a file"),
Chris@84 829 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 830 return false;
Chris@84 831 }
Chris@84 832
Chris@84 833 bool MainWindow::complainAboutCloneToExisting(QString arg)
Chris@84 834 {
Chris@84 835 QMessageBox::critical
Chris@84 836 (this, tr("Path is in existing repository"),
Chris@84 837 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 new folder name for the local repository.</qt>").arg(xmlEncode(arg)));
Chris@84 838 return false;
Chris@84 839 }
Chris@84 840
Chris@84 841 bool MainWindow::complainAboutCloneToFile(QString arg)
Chris@84 842 {
Chris@84 843 QMessageBox::critical
Chris@84 844 (this, tr("Path is a file"),
Chris@84 845 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 846 return false;
Chris@84 847 }
Chris@84 848
Chris@84 849 bool MainWindow::complainAboutCloneToExistingFolder(QString arg)
Chris@84 850 {
Chris@84 851 QMessageBox::critical
Chris@84 852 (this, tr("Folder exists"),
Chris@84 853 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This is the path of an existing folder.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg)));
Chris@79 854 return false;
Chris@79 855 }
Chris@79 856
Chris@79 857 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
Chris@79 858 {
Chris@79 859 return (QMessageBox::question
Chris@84 860 (this, tr("Path is inside a repository"),
Chris@86 861 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 862 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
Chris@79 863 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 864 QMessageBox::Ok)
Chris@79 865 == QMessageBox::Ok);
Chris@79 866 }
Chris@79 867
Chris@79 868 bool MainWindow::askToInitExisting(QString arg)
Chris@79 869 {
Chris@79 870 return (QMessageBox::question
Chris@84 871 (this, tr("Folder has no repository"),
Chris@84 872 tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder does not contain a Mercurial repository.<br><br>Would you like to initialise a repository here?</qt>")
Chris@79 873 .arg(xmlEncode(arg)),
Chris@79 874 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 875 QMessageBox::Ok)
Chris@79 876 == QMessageBox::Ok);
Chris@79 877 }
Chris@79 878
Chris@79 879 bool MainWindow::askToInitNew(QString arg)
Chris@79 880 {
Chris@79 881 return (QMessageBox::question
Chris@84 882 (this, tr("Folder does not exist"),
Chris@84 883 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 884 .arg(xmlEncode(arg)),
Chris@84 885 QMessageBox::Ok | QMessageBox::Cancel,
Chris@84 886 QMessageBox::Ok)
Chris@84 887 == QMessageBox::Ok);
Chris@84 888 }
Chris@84 889
Chris@84 890 bool MainWindow::askToOpenInsteadOfInit(QString arg)
Chris@84 891 {
Chris@84 892 return (QMessageBox::question
Chris@84 893 (this, tr("Repository exists"),
Chris@84 894 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 895 .arg(xmlEncode(arg)),
Chris@79 896 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 897 QMessageBox::Ok)
Chris@79 898 == QMessageBox::Ok);
Chris@79 899 }
Chris@79 900
Chris@79 901 bool MainWindow::openLocal(QString local)
Chris@79 902 {
Chris@79 903 DEBUG << "open " << local << endl;
Chris@79 904
Chris@79 905 FolderStatus status = getFolderStatus(local);
Chris@79 906 QString containing = getContainingRepoFolder(local);
Chris@79 907
Chris@79 908 switch (status) {
Chris@79 909
Chris@79 910 case FolderHasRepo:
Chris@79 911 // fine
Chris@79 912 break;
Chris@79 913
Chris@79 914 case FolderExists:
Chris@79 915 if (containing != "") {
Chris@79 916 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 917 local = containing;
Chris@79 918 } else {
Chris@86 919 //!!! No -- this is likely to happen far more by accident
Chris@86 920 // than because the user actually wanted to init something.
Chris@86 921 // Don't ask, just politely reject.
Chris@79 922 if (!askToInitExisting(local)) return false;
Chris@79 923 return openInit(local);
Chris@79 924 }
Chris@79 925 break;
Chris@79 926
Chris@79 927 case FolderParentExists:
Chris@79 928 if (containing != "") {
Chris@79 929 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 930 local = containing;
Chris@79 931 } else {
Chris@79 932 if (!askToInitNew(local)) return false;
Chris@79 933 return openInit(local);
Chris@79 934 }
Chris@79 935 break;
Chris@79 936
Chris@79 937 case FolderUnknown:
Chris@84 938 if (containing != "") {
Chris@84 939 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 940 local = containing;
Chris@84 941 } else {
Chris@84 942 return complainAboutUnknownFolder(local);
Chris@84 943 }
Chris@84 944 break;
Chris@79 945
Chris@79 946 case FolderIsFile:
Chris@79 947 return complainAboutFilePath(local);
Chris@79 948 }
Chris@79 949
Chris@79 950 workFolderPath = local;
Chris@79 951 remoteRepoPath = "";
Chris@79 952 return true;
Chris@79 953 }
Chris@79 954
Chris@79 955 bool MainWindow::openRemote(QString remote, QString local)
Chris@79 956 {
Chris@79 957 DEBUG << "clone " << remote << " to " << local << endl;
Chris@84 958
Chris@84 959 FolderStatus status = getFolderStatus(local);
Chris@84 960 QString containing = getContainingRepoFolder(local);
Chris@84 961
Chris@84 962 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 963
Chris@84 964 if (status == FolderHasRepo || containing != "") {
Chris@84 965 return complainAboutCloneToExisting(local);
Chris@84 966 }
Chris@84 967
Chris@84 968 if (status == FolderIsFile) {
Chris@84 969 return complainAboutCloneToFile(local);
Chris@84 970 }
Chris@84 971
Chris@84 972 if (status == FolderUnknown) {
Chris@84 973 return complainAboutUnknownFolder(local);
Chris@84 974 }
Chris@84 975
Chris@84 976 if (status == FolderExists) {
Chris@84 977 //!!! we can do better than this surely?
Chris@84 978 return complainAboutCloneToExistingFolder(local);
Chris@84 979 }
Chris@84 980
Chris@84 981 workFolderPath = local;
Chris@84 982 remoteRepoPath = remote;
Chris@84 983 hgCloneFromRemote();
Chris@84 984
Chris@79 985 return true;
Chris@79 986 }
Chris@79 987
Chris@84 988 bool MainWindow::openInit(QString local)
Chris@79 989 {
Chris@84 990 DEBUG << "openInit " << local << endl;
Chris@84 991
Chris@84 992 FolderStatus status = getFolderStatus(local);
Chris@84 993 QString containing = getContainingRepoFolder(local);
Chris@84 994
Chris@84 995 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 996
Chris@84 997 if (status == FolderHasRepo) {
Chris@84 998 if (!askToOpenInsteadOfInit(local)) return false;
Chris@84 999 }
Chris@84 1000
Chris@84 1001 if (containing != "") {
Chris@84 1002 return complainAboutInitInRepo(local);
Chris@84 1003 }
Chris@84 1004
Chris@84 1005 if (status == FolderIsFile) {
Chris@84 1006 return complainAboutInitFile(local);
Chris@84 1007 }
Chris@84 1008
Chris@84 1009 if (status == FolderUnknown) {
Chris@84 1010 return complainAboutUnknownFolder(local);
Chris@84 1011 }
Chris@84 1012
Chris@84 1013 workFolderPath = local;
Chris@84 1014 remoteRepoPath = "";
Chris@84 1015 hgInit();
Chris@79 1016 return true;
Chris@79 1017 }
Chris@79 1018
jtkorhonen@0 1019 void MainWindow::settings()
jtkorhonen@0 1020 {
Chris@69 1021 /*!!!
jtkorhonen@0 1022 SettingsDialog *settingsDlg = new SettingsDialog(this);
jtkorhonen@0 1023 settingsDlg->setModal(true);
jtkorhonen@0 1024 settingsDlg->exec();
jtkorhonen@0 1025 hgExp -> clearLists();
jtkorhonen@0 1026 enableDisableActions();
jtkorhonen@0 1027 hgStat();
Chris@69 1028 */
jtkorhonen@0 1029 }
jtkorhonen@0 1030
jtkorhonen@2 1031 #define STDOUT_NEEDS_BIG_WINDOW 512
jtkorhonen@2 1032 #define SMALL_WND_W 500
jtkorhonen@2 1033 #define SMALL_WND_H 300
jtkorhonen@2 1034
jtkorhonen@2 1035 #define BIG_WND_W 1024
jtkorhonen@2 1036 #define BIG_WND_H 768
jtkorhonen@2 1037
jtkorhonen@2 1038
jtkorhonen@2 1039 void MainWindow::presentLongStdoutToUser(QString stdo)
jtkorhonen@0 1040 {
jtkorhonen@2 1041 if (!stdo.isEmpty())
jtkorhonen@2 1042 {
jtkorhonen@2 1043 QDialog dlg;
jtkorhonen@0 1044
jtkorhonen@2 1045 if (stdo.length() > STDOUT_NEEDS_BIG_WINDOW)
jtkorhonen@2 1046 {
jtkorhonen@2 1047 dlg.setMinimumWidth(BIG_WND_W);
jtkorhonen@2 1048 dlg.setMinimumHeight(BIG_WND_H);
jtkorhonen@2 1049 }
jtkorhonen@2 1050 else
jtkorhonen@2 1051 {
jtkorhonen@2 1052 dlg.setMinimumWidth(SMALL_WND_W);
jtkorhonen@2 1053 dlg.setMinimumHeight(SMALL_WND_H);
jtkorhonen@2 1054 }
jtkorhonen@0 1055
jtkorhonen@2 1056 QVBoxLayout *box = new QVBoxLayout;
jtkorhonen@2 1057 QListWidget *list = new QListWidget;
jtkorhonen@2 1058 list-> addItems(stdo.split("\n"));
jtkorhonen@2 1059 QPushButton *btn = new QPushButton(tr("Ok"));
jtkorhonen@2 1060 connect(btn, SIGNAL(clicked()), &dlg, SLOT(accept()));
jtkorhonen@0 1061
jtkorhonen@2 1062 box -> addWidget(list);
jtkorhonen@2 1063 box -> addWidget(btn);
jtkorhonen@2 1064 dlg.setLayout(box);
jtkorhonen@2 1065
jtkorhonen@2 1066 dlg.exec();
jtkorhonen@2 1067 }
jtkorhonen@2 1068 else
jtkorhonen@2 1069 {
jtkorhonen@2 1070 QMessageBox::information(this, tr("HgExplorer"), tr("Mercurial command did not return any output."));
jtkorhonen@2 1071 }
jtkorhonen@0 1072 }
jtkorhonen@0 1073
Chris@90 1074 void MainWindow::updateFileSystemWatcher()
Chris@90 1075 {
Chris@90 1076 //!!! this needs to be incremental when something changes
Chris@90 1077
Chris@90 1078 delete fsWatcher;
Chris@90 1079 fsWatcher = new QFileSystemWatcher();
Chris@90 1080 std::deque<QString> pending;
Chris@90 1081 pending.push_back(workFolderPath);
Chris@90 1082 while (!pending.empty()) {
Chris@90 1083 QString path = pending.front();
Chris@90 1084 pending.pop_front();
Chris@90 1085 fsWatcher->addPath(path);
Chris@90 1086 DEBUG << "Added to file system watcher: " << path << endl;
Chris@90 1087 QDir d(path);
Chris@90 1088 if (d.exists()) {
Chris@90 1089 d.setFilter(QDir::Files | QDir::Dirs |
Chris@90 1090 QDir::NoDotAndDotDot | QDir::Readable);
Chris@90 1091 foreach (QString entry, d.entryList()) {
Chris@90 1092 if (entry == ".hg") continue;
Chris@90 1093 QString entryPath = d.absoluteFilePath(entry);
Chris@90 1094 pending.push_back(entryPath);
Chris@90 1095 }
Chris@90 1096 }
Chris@90 1097 }
Chris@90 1098 connect(fsWatcher, SIGNAL(directoryChanged(QString)),
Chris@90 1099 this, SLOT(fsDirectoryChanged(QString)));
Chris@90 1100 connect(fsWatcher, SIGNAL(fileChanged(QString)),
Chris@90 1101 this, SLOT(fsFileChanged(QString)));
Chris@90 1102 }
Chris@90 1103
Chris@90 1104 void MainWindow::fsDirectoryChanged(QString)
Chris@90 1105 {
Chris@90 1106 //!!! should just queue one of these!
Chris@90 1107 hgStat();
Chris@90 1108 }
Chris@90 1109
Chris@90 1110 void MainWindow::fsFileChanged(QString)
Chris@90 1111 {
Chris@90 1112 //!!! should just queue one of these!
Chris@90 1113 hgStat();
Chris@90 1114 }
Chris@90 1115
Chris@62 1116 void MainWindow::commandFailed()
Chris@62 1117 {
Chris@62 1118 DEBUG << "MainWindow::commandFailed" << endl;
Chris@74 1119 runningAction = ACT_NONE;
Chris@74 1120 runner -> hideProgBar();
Chris@74 1121
Chris@79 1122 //!!! N.B hg incoming returns 1 even if successful, if there were no changes
Chris@62 1123 }
Chris@62 1124
Chris@62 1125 void MainWindow::commandCompleted()
jtkorhonen@0 1126 {
jtkorhonen@0 1127 bool shouldHgStat = false;
jtkorhonen@0 1128
jtkorhonen@0 1129 if (runningAction != ACT_NONE)
jtkorhonen@0 1130 {
jtkorhonen@0 1131 //We are running some hg command...
Chris@62 1132 if (runner -> isCommandRunning() == false)
jtkorhonen@0 1133 {
jtkorhonen@0 1134 //Running has just ended.
jtkorhonen@0 1135 int exitCode = runner -> getExitCode();
jtkorhonen@0 1136
jtkorhonen@0 1137 runner -> hideProgBar();
jtkorhonen@0 1138
jtkorhonen@0 1139 //Clumsy...
jtkorhonen@0 1140 if ((EXITOK(exitCode)) || ((exitCode == 1) && (runningAction == ACT_INCOMING)))
jtkorhonen@0 1141 {
jtkorhonen@0 1142 //Successful running.
jtkorhonen@0 1143 switch(runningAction)
jtkorhonen@0 1144 {
Chris@74 1145 case ACT_PATHS:
Chris@74 1146 {
Chris@84 1147 QString sout = runner->getOutput();
Chris@76 1148 DEBUG << "stdout is " << sout << endl;
Chris@76 1149 LogParser lp(sout, "=");
Chris@74 1150 LogList ll = lp.parse();
Chris@74 1151 DEBUG << ll.size() << " results" << endl;
Chris@74 1152 if (!ll.empty()) {
Chris@74 1153 remoteRepoPath = lp.parse()[0]["default"].trimmed();
Chris@74 1154 DEBUG << "Set remote path to " << remoteRepoPath << endl;
Chris@74 1155 }
Chris@74 1156 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@74 1157 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
Chris@74 1158 enableDisableActions();
Chris@74 1159 break;
Chris@74 1160 }
Chris@74 1161
jtkorhonen@0 1162 case ACT_STAT:
Chris@84 1163 hgExp -> updateWorkFolderFileList(runner -> getOutput());
Chris@90 1164 updateFileSystemWatcher();
jtkorhonen@0 1165 break;
jtkorhonen@0 1166
jtkorhonen@0 1167 case ACT_INCOMING:
jtkorhonen@0 1168 case ACT_ANNOTATE:
jtkorhonen@0 1169 case ACT_RESOLVE_LIST:
jtkorhonen@0 1170 case ACT_RESOLVE_MARK:
Chris@84 1171 presentLongStdoutToUser(runner -> getOutput());
jtkorhonen@0 1172 shouldHgStat = true;
jtkorhonen@0 1173 break;
jtkorhonen@0 1174
jtkorhonen@0 1175 case ACT_PULL:
Chris@84 1176 QMessageBox::information(this, "Pull", runner -> getOutput());
jtkorhonen@0 1177 shouldHgStat = true;
jtkorhonen@0 1178 break;
jtkorhonen@0 1179
jtkorhonen@0 1180 case ACT_PUSH:
Chris@84 1181 QMessageBox::information(this, "Push", runner -> getOutput());
jtkorhonen@0 1182 shouldHgStat = true;
jtkorhonen@0 1183 break;
jtkorhonen@0 1184
jtkorhonen@0 1185 case ACT_INIT:
Chris@69 1186 MultiChoiceDialog::addRecentArgument("init", workFolderPath);
Chris@69 1187 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
jtkorhonen@0 1188 enableDisableActions();
jtkorhonen@0 1189 shouldHgStat = true;
jtkorhonen@0 1190 break;
jtkorhonen@0 1191
jtkorhonen@0 1192 case ACT_CLONEFROMREMOTE:
Chris@69 1193 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@69 1194 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
Chris@72 1195 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true);
Chris@84 1196 QMessageBox::information(this, "Clone", runner -> getOutput());
jtkorhonen@0 1197 enableDisableActions();
jtkorhonen@0 1198 shouldHgStat = true;
jtkorhonen@0 1199 break;
jtkorhonen@0 1200
jtkorhonen@0 1201 case ACT_LOG:
Chris@91 1202 hgExp -> updateLocalRepoHgLogList(runner -> getOutput());
jtkorhonen@0 1203 break;
jtkorhonen@0 1204
jtkorhonen@0 1205 case ACT_PARENTS:
jtkorhonen@0 1206 {
Chris@91 1207 //!!! hgExp -> updateLocalRepoParentsList(runner -> getOutput());
jtkorhonen@0 1208 }
jtkorhonen@0 1209 break;
jtkorhonen@0 1210
jtkorhonen@0 1211 case ACT_HEADS:
jtkorhonen@0 1212 {
Chris@84 1213 QString stdOut = runner -> getOutput();
Chris@91 1214 //!!! hgExp -> updateLocalRepoHeadsList(stdOut);
jtkorhonen@0 1215 }
jtkorhonen@0 1216 break;
jtkorhonen@0 1217
jtkorhonen@0 1218 case ACT_REMOVE:
jtkorhonen@0 1219 case ACT_ADD:
jtkorhonen@0 1220 case ACT_COMMIT:
jtkorhonen@0 1221 case ACT_FILEDIFF:
jtkorhonen@0 1222 case ACT_FOLDERDIFF:
jtkorhonen@0 1223 case ACT_CHGSETDIFF:
jtkorhonen@0 1224 case ACT_REVERT:
jtkorhonen@11 1225 case ACT_SERVE:
jtkorhonen@34 1226 case ACT_TAG:
jtkorhonen@36 1227 case ACT_HG_IGNORE:
jtkorhonen@0 1228 shouldHgStat = true;
jtkorhonen@0 1229 break;
jtkorhonen@0 1230
jtkorhonen@0 1231 case ACT_UPDATE:
Chris@84 1232 QMessageBox::information(this, tr("Update"), runner -> getOutput());
jtkorhonen@0 1233 shouldHgStat = true;
jtkorhonen@0 1234 break;
jtkorhonen@0 1235
jtkorhonen@0 1236 case ACT_MERGE:
Chris@84 1237 QMessageBox::information(this, tr("Merge"), runner -> getOutput());
jtkorhonen@0 1238 shouldHgStat = true;
jtkorhonen@33 1239 justMerged = true;
jtkorhonen@33 1240 break;
jtkorhonen@33 1241
jtkorhonen@33 1242 case ACT_RETRY_MERGE:
jtkorhonen@38 1243 QMessageBox::information(this, tr("Merge retry"), tr("Merge retry successful."));
jtkorhonen@33 1244 shouldHgStat = true;
jtkorhonen@33 1245 justMerged = true;
jtkorhonen@0 1246 break;
jtkorhonen@0 1247
jtkorhonen@0 1248 default:
jtkorhonen@0 1249 break;
jtkorhonen@0 1250 }
jtkorhonen@0 1251 }
jtkorhonen@0 1252
jtkorhonen@37 1253
Chris@74 1254 //Typical sequence goes paths -> stat -> heads -> parents -> log
Chris@74 1255 if (runningAction == ACT_PATHS)
Chris@74 1256 {
Chris@74 1257 runningAction = ACT_NONE;
Chris@74 1258 hgStat();
Chris@74 1259 }
Chris@74 1260 else if (runningAction == ACT_STAT)
jtkorhonen@0 1261 {
jtkorhonen@0 1262 runningAction = ACT_NONE;
jtkorhonen@0 1263 hgHeads();
jtkorhonen@0 1264 }
jtkorhonen@0 1265 else if (runningAction == ACT_HEADS)
jtkorhonen@0 1266 {
jtkorhonen@0 1267 runningAction = ACT_NONE;
jtkorhonen@0 1268 hgParents();
jtkorhonen@0 1269 }
jtkorhonen@0 1270 else if (runningAction == ACT_PARENTS)
jtkorhonen@0 1271 {
jtkorhonen@0 1272 runningAction = ACT_NONE;
jtkorhonen@0 1273 hgLog();
jtkorhonen@0 1274 }
jtkorhonen@37 1275 else if ((runningAction == ACT_MERGE) && (exitCode != 0))
jtkorhonen@37 1276 {
jtkorhonen@37 1277 //If we had a failed merge, offer to retry
jtkorhonen@37 1278 if (QMessageBox::Ok == QMessageBox::information(this, tr("Retry merge ?"), tr("Merge attempt failed. retry ?"), QMessageBox::Ok | QMessageBox::Cancel))
jtkorhonen@37 1279 {
jtkorhonen@37 1280 runningAction = ACT_NONE;
jtkorhonen@37 1281 hgRetryMerge();
jtkorhonen@37 1282 }
jtkorhonen@37 1283 else
jtkorhonen@37 1284 {
jtkorhonen@37 1285 runningAction = ACT_NONE;
jtkorhonen@37 1286 hgStat();
jtkorhonen@37 1287 }
jtkorhonen@37 1288 }
jtkorhonen@0 1289 else
jtkorhonen@0 1290 {
jtkorhonen@0 1291 runningAction = ACT_NONE;
jtkorhonen@0 1292 if (shouldHgStat)
jtkorhonen@0 1293 {
Chris@74 1294 hgPaths();
jtkorhonen@0 1295 }
jtkorhonen@0 1296 }
jtkorhonen@0 1297 }
jtkorhonen@0 1298 }
Chris@90 1299
Chris@90 1300 enableDisableActions();
jtkorhonen@0 1301 }
jtkorhonen@0 1302
jtkorhonen@0 1303 void MainWindow::connectActions()
jtkorhonen@0 1304 {
jtkorhonen@0 1305 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
jtkorhonen@0 1306 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
jtkorhonen@0 1307 connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
jtkorhonen@0 1308
Chris@74 1309 connect(hgStatAct, SIGNAL(triggered()), this, SLOT(hgPaths()));
Chris@74 1310 connect(hgExp, SIGNAL(workFolderViewTypesChanged()), this, SLOT(hgPaths()));
jtkorhonen@0 1311 connect(hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
jtkorhonen@0 1312 connect(hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
jtkorhonen@0 1313 connect(hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
jtkorhonen@0 1314 connect(hgFileDiffAct, SIGNAL(triggered()), this, SLOT(hgFileDiff()));
jtkorhonen@0 1315 connect(hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
jtkorhonen@0 1316 connect(hgChgSetDiffAct, SIGNAL(triggered()), this, SLOT(hgChgSetDiff()));
jtkorhonen@0 1317 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
jtkorhonen@0 1318 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
jtkorhonen@0 1319 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
jtkorhonen@33 1320 connect(hgRetryMergeAct, SIGNAL(triggered()), this, SLOT(hgRetryMerge()));
jtkorhonen@34 1321 connect(hgTagAct, SIGNAL(triggered()), this, SLOT(hgTag()));
jtkorhonen@34 1322 connect(hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
jtkorhonen@0 1323
jtkorhonen@0 1324 connect(settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
Chris@69 1325 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
jtkorhonen@0 1326
jtkorhonen@0 1327 connect(hgInitAct, SIGNAL(triggered()), this, SLOT(hgInit()));
jtkorhonen@0 1328 connect(hgCloneFromRemoteAct, SIGNAL(triggered()), this, SLOT(hgCloneFromRemote()));
jtkorhonen@0 1329 connect(hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
jtkorhonen@0 1330 connect(hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
jtkorhonen@0 1331 connect(hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
jtkorhonen@0 1332
jtkorhonen@0 1333 connect(hgExp, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
jtkorhonen@0 1334
jtkorhonen@0 1335 connect(hgUpdateToRevAct, SIGNAL(triggered()), this, SLOT(hgUpdateToRev()));
jtkorhonen@0 1336 connect(hgAnnotateAct, SIGNAL(triggered()), this, SLOT(hgAnnotate()));
jtkorhonen@0 1337 connect(hgResolveListAct, SIGNAL(triggered()), this, SLOT(hgResolveList()));
jtkorhonen@0 1338 connect(hgResolveMarkAct, SIGNAL(triggered()), this, SLOT(hgResolveMark()));
jtkorhonen@11 1339 connect(hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
Chris@94 1340 connect(clearSelectionsAct, SIGNAL(triggered()), this, SLOT(clearSelections()));
jtkorhonen@0 1341 }
jtkorhonen@0 1342
jtkorhonen@0 1343 void MainWindow::tabChanged(int currTab)
jtkorhonen@0 1344 {
jtkorhonen@0 1345 tabPage = currTab;
jtkorhonen@32 1346
jtkorhonen@0 1347 }
jtkorhonen@0 1348
jtkorhonen@0 1349 void MainWindow::enableDisableActions()
jtkorhonen@0 1350 {
Chris@90 1351 DEBUG << "MainWindow::enableDisableActions" << endl;
Chris@90 1352
jtkorhonen@0 1353 QDir localRepoDir;
jtkorhonen@0 1354 QDir workFolderDir;
jtkorhonen@0 1355 bool workFolderExist;
jtkorhonen@0 1356 bool localRepoExist;
jtkorhonen@0 1357
jtkorhonen@0 1358 remoteRepoActionsEnabled = true;
Chris@90 1359 if (remoteRepoPath.isEmpty()) {
jtkorhonen@0 1360 remoteRepoActionsEnabled = false;
jtkorhonen@0 1361 }
jtkorhonen@0 1362
jtkorhonen@0 1363 localRepoActionsEnabled = true;
Chris@90 1364 if (workFolderPath.isEmpty()) {
jtkorhonen@0 1365 localRepoActionsEnabled = false;
jtkorhonen@0 1366 workFolderExist = false;
jtkorhonen@0 1367 }
jtkorhonen@0 1368
Chris@90 1369 if (!workFolderDir.exists(workFolderPath)) {
jtkorhonen@0 1370 localRepoActionsEnabled = false;
jtkorhonen@0 1371 workFolderExist = false;
Chris@90 1372 } else {
jtkorhonen@0 1373 workFolderExist = true;
jtkorhonen@0 1374 }
jtkorhonen@0 1375
Chris@90 1376 if (!localRepoDir.exists(workFolderPath + "/" + getHgDirName())) {
jtkorhonen@0 1377 localRepoActionsEnabled = false;
jtkorhonen@0 1378 localRepoExist = false;
jtkorhonen@0 1379 }
jtkorhonen@0 1380
jtkorhonen@0 1381 hgCloneFromRemoteAct -> setEnabled(remoteRepoActionsEnabled);
jtkorhonen@0 1382 hgIncomingAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
jtkorhonen@0 1383 hgPullAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
jtkorhonen@0 1384 hgPushAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
Chris@73 1385 /*
jtkorhonen@0 1386 if (tabPage != WORKTAB)
jtkorhonen@0 1387 {
jtkorhonen@0 1388 localRepoActionsEnabled = false;
jtkorhonen@0 1389 }
Chris@73 1390 */
jtkorhonen@0 1391 hgInitAct -> setEnabled((localRepoExist == false) && (workFolderExist==true));
jtkorhonen@0 1392 hgStatAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1393 hgFileDiffAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1394 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1395 hgRevertAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1396 hgAddAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1397 hgRemoveAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1398 hgUpdateAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1399 hgCommitAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1400 hgMergeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@33 1401 hgRetryMergeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 1402 hgResolveListAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 1403 hgResolveMarkAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 1404 hgAnnotateAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@11 1405 hgServeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@34 1406 hgTagAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@34 1407 hgIgnoreAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1408
Chris@91 1409 //!!!hgExp -> enableDisableOtherTabs(tabPage);
jtkorhonen@0 1410
Chris@90 1411 DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl;
Chris@90 1412 DEBUG << "canCommit = " << hgExp->canCommit() << endl;
Chris@90 1413
Chris@90 1414 //!!! new stuff:
Chris@95 1415 hgAddAct->setEnabled(localRepoActionsEnabled && hgExp->canAdd());
Chris@95 1416 hgRemoveAct->setEnabled(localRepoActionsEnabled && hgExp->canRemove());
Chris@90 1417 hgCommitAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit());
Chris@90 1418 hgRevertAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit());
Chris@95 1419 hgFolderDiffAct->setEnabled(localRepoActionsEnabled && hgExp->canDoDiff());
Chris@90 1420
Chris@90 1421 /*!!!
jtkorhonen@17 1422 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked;
jtkorhonen@17 1423
jtkorhonen@17 1424 countModifications(hgExp -> workFolderFileList,
jtkorhonen@17 1425 added, modified, removed, notTracked,
jtkorhonen@17 1426 selected,
jtkorhonen@17 1427 selectedAdded, selectedModified, selectedRemoved, selectedNotTracked);
jtkorhonen@0 1428
jtkorhonen@0 1429 if (tabPage == WORKTAB)
jtkorhonen@0 1430 {
jtkorhonen@0 1431 //Enable / disable actions according to workFolderFileList selections / currentSelection / count
jtkorhonen@0 1432 hgChgSetDiffAct -> setEnabled(false);
jtkorhonen@0 1433 hgUpdateToRevAct -> setEnabled(false);
jtkorhonen@0 1434
jtkorhonen@0 1435 if (localRepoActionsEnabled)
jtkorhonen@0 1436 {
jtkorhonen@17 1437 if ((added == 0) && (modified == 0) && (removed == 0))
jtkorhonen@0 1438 {
jtkorhonen@0 1439 hgCommitAct -> setEnabled(false);
jtkorhonen@0 1440 hgRevertAct -> setEnabled(false);
jtkorhonen@0 1441 }
jtkorhonen@17 1442 else if (selected != 0)
jtkorhonen@17 1443 {
jtkorhonen@17 1444 if (selectedNotTracked != 0)
jtkorhonen@17 1445 {
jtkorhonen@17 1446 hgCommitAct -> setEnabled(false);
jtkorhonen@17 1447 }
jtkorhonen@17 1448 else if ((selectedAdded == 0) && (selectedModified == 0) && (selectedRemoved == 0))
jtkorhonen@17 1449 {
jtkorhonen@17 1450 hgCommitAct -> setEnabled(false);
jtkorhonen@17 1451 }
jtkorhonen@17 1452 }
jtkorhonen@0 1453
jtkorhonen@17 1454 if (modified == 0)
jtkorhonen@0 1455 {
jtkorhonen@0 1456 hgFolderDiffAct -> setEnabled(false);
jtkorhonen@0 1457 }
jtkorhonen@0 1458
jtkorhonen@0 1459 if (!isSelectedModified(hgExp -> workFolderFileList))
jtkorhonen@0 1460 {
jtkorhonen@0 1461 hgFileDiffAct -> setEnabled(false);
jtkorhonen@0 1462 hgRevertAct -> setEnabled(false);
jtkorhonen@0 1463 }
jtkorhonen@0 1464
jtkorhonen@5 1465 //JK 14.5.2010: Fixed confusing add button. Now this is simple: If we have something to add (any non-tracked files), add is enabled.
jtkorhonen@17 1466 if (notTracked == 0)
jtkorhonen@0 1467 {
jtkorhonen@0 1468 hgAddAct -> setEnabled(false);
jtkorhonen@0 1469 }
jtkorhonen@0 1470
jtkorhonen@6 1471 if (!isSelectedDeletable(hgExp -> workFolderFileList))
jtkorhonen@0 1472 {
jtkorhonen@0 1473 hgRemoveAct -> setEnabled(false);
jtkorhonen@0 1474 }
jtkorhonen@0 1475
jtkorhonen@2 1476 hgResolveListAct -> setEnabled(true);
jtkorhonen@2 1477
jtkorhonen@5 1478 if (hgExp -> localRepoHeadsList->count() < 2)
jtkorhonen@0 1479 {
jtkorhonen@0 1480 hgMergeAct -> setEnabled(false);
jtkorhonen@33 1481 hgRetryMergeAct -> setEnabled(false);
jtkorhonen@0 1482 }
jtkorhonen@0 1483
jtkorhonen@34 1484 if (hgExp -> localRepoHeadsList->count() < 1)
jtkorhonen@34 1485 {
jtkorhonen@34 1486 hgTagAct -> setEnabled(false);
jtkorhonen@34 1487 }
jtkorhonen@34 1488
jtkorhonen@2 1489 QString currentFile = hgExp -> getCurrentFileListLine();
jtkorhonen@2 1490 if (!currentFile.isEmpty())
jtkorhonen@2 1491 {
jtkorhonen@2 1492 hgAnnotateAct -> setEnabled(true);
jtkorhonen@2 1493 hgResolveMarkAct -> setEnabled(true);
jtkorhonen@2 1494 }
jtkorhonen@2 1495 else
jtkorhonen@2 1496 {
jtkorhonen@2 1497 hgAnnotateAct -> setEnabled(false);
jtkorhonen@2 1498 hgResolveMarkAct -> setEnabled(false);
jtkorhonen@2 1499 }
jtkorhonen@0 1500 }
jtkorhonen@0 1501 }
jtkorhonen@0 1502 else
jtkorhonen@0 1503 {
jtkorhonen@0 1504 QList <QListWidgetItem *> headSelList = hgExp -> localRepoHeadsList->selectedItems();
jtkorhonen@0 1505 QList <QListWidgetItem *> historySelList = hgExp -> localRepoHgLogList->selectedItems();
jtkorhonen@0 1506
jtkorhonen@0 1507 if ((historySelList.count() == 2) || (headSelList.count() == 2))
jtkorhonen@0 1508 {
jtkorhonen@0 1509 hgChgSetDiffAct -> setEnabled(true);
jtkorhonen@0 1510 }
jtkorhonen@0 1511 else
jtkorhonen@0 1512 {
jtkorhonen@0 1513 hgChgSetDiffAct -> setEnabled(false);
jtkorhonen@0 1514 }
jtkorhonen@0 1515
jtkorhonen@30 1516 if (historySelList.count() == 1)
jtkorhonen@0 1517 {
jtkorhonen@30 1518 hgUpdateToRevAct -> setEnabled(true);
jtkorhonen@0 1519 }
jtkorhonen@0 1520 else
jtkorhonen@0 1521 {
jtkorhonen@0 1522 hgUpdateToRevAct -> setEnabled(false);
jtkorhonen@0 1523 }
jtkorhonen@0 1524 }
Chris@90 1525 */
jtkorhonen@0 1526 }
jtkorhonen@0 1527
jtkorhonen@0 1528 void MainWindow::createActions()
jtkorhonen@0 1529 {
jtkorhonen@0 1530 //File actions
jtkorhonen@0 1531 hgInitAct = new QAction(tr("Init local repository"), this);
jtkorhonen@0 1532 hgInitAct->setStatusTip(tr("Create an empty local repository in selected folder"));
jtkorhonen@0 1533
jtkorhonen@0 1534 hgCloneFromRemoteAct = new QAction(tr("Clone from remote"), this);
jtkorhonen@0 1535 hgCloneFromRemoteAct->setStatusTip(tr("Clone from remote repository into local repository in selected folder"));
jtkorhonen@0 1536
Chris@69 1537 openAct = new QAction(QIcon(":/images/fileopen.png"), tr("Open..."), this);
Chris@69 1538 openAct -> setStatusTip(tr("Open repository"));
Chris@69 1539 openAct -> setIconVisibleInMenu(true);
Chris@69 1540
jtkorhonen@0 1541 settingsAct = new QAction(QIcon(":/images/settings.png"), tr("Settings..."), this);
jtkorhonen@0 1542 settingsAct -> setStatusTip(tr("View and change application settings"));
jtkorhonen@0 1543 settingsAct -> setIconVisibleInMenu(true);
jtkorhonen@0 1544
jtkorhonen@0 1545 exitAct = new QAction(QIcon(":/images/exit.png"), tr("Exit"), this);
jtkorhonen@0 1546 exitAct->setShortcuts(QKeySequence::Quit);
jtkorhonen@0 1547 exitAct->setStatusTip(tr("Exit application"));
jtkorhonen@0 1548 exitAct -> setIconVisibleInMenu(true);
jtkorhonen@0 1549
jtkorhonen@0 1550 //Repository actions
Chris@61 1551 hgStatAct = new QAction(QIcon(":/images/status.png"), tr("Refresh"), this);
Chris@61 1552 hgStatAct->setStatusTip(tr("Refresh (info of) status of workfolder files"));
Chris@61 1553
Chris@61 1554 hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Preview"), this);
jtkorhonen@0 1555 hgIncomingAct -> setStatusTip(tr("View info of changesets incoming to us from remote repository (on pull operation)"));
jtkorhonen@0 1556
Chris@61 1557 hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pull"), this);
jtkorhonen@0 1558 hgPullAct -> setStatusTip(tr("Pull changesets from remote repository to local repository"));
jtkorhonen@0 1559
Chris@61 1560 hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Push"), this);
jtkorhonen@0 1561 hgPushAct->setStatusTip(tr("Push local changesets to remote repository"));
jtkorhonen@0 1562
jtkorhonen@0 1563 //Workfolder actions
Chris@61 1564 hgFileDiffAct = new QAction(QIcon(":/images/diff.png"), tr("Diff"), this);
jtkorhonen@0 1565 hgFileDiffAct->setStatusTip(tr("Filediff: View differences between selected working folder file and local repository file"));
jtkorhonen@0 1566
jtkorhonen@0 1567 hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("View folderdiff"), this);
jtkorhonen@0 1568 hgFolderDiffAct->setStatusTip(tr("Folderdiff: View all differences between working folder files and local repository files"));
jtkorhonen@0 1569
jtkorhonen@0 1570 hgChgSetDiffAct = new QAction(QIcon(":/images/chgsetdiff.png"), tr("View changesetdiff"), this);
jtkorhonen@0 1571 hgChgSetDiffAct->setStatusTip(tr("Change set diff: View differences between all files of 2 repository changesets"));
jtkorhonen@0 1572
Chris@61 1573 hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Revert"), this);
jtkorhonen@0 1574 hgRevertAct->setStatusTip(tr("Undo selected working folder file changes (return to local repository version)"));
jtkorhonen@0 1575
Chris@61 1576 hgAddAct = new QAction(QIcon(":/images/add.png"), tr("Add"), this);
jtkorhonen@17 1577 hgAddAct -> setStatusTip(tr("Add working folder file(s) (selected or all yet untracked) to local repository (on next commit)"));
jtkorhonen@0 1578
Chris@61 1579 hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("Remove"), this);
jtkorhonen@0 1580 hgRemoveAct -> setStatusTip(tr("Remove selected working folder file from local repository (on next commit)"));
jtkorhonen@0 1581
Chris@61 1582 hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("Update"), this);
jtkorhonen@0 1583 hgUpdateAct->setStatusTip(tr("Update working folder from local repository"));
jtkorhonen@0 1584
Chris@61 1585 hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("Commit"), this);
jtkorhonen@20 1586 hgCommitAct->setStatusTip(tr("Save selected file(s) or all changed files in working folder (and all subfolders) to local repository"));
jtkorhonen@0 1587
jtkorhonen@0 1588 hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("Merge"), this);
jtkorhonen@0 1589 hgMergeAct->setStatusTip(tr("Merge two local repository changesets to working folder"));
jtkorhonen@0 1590
jtkorhonen@0 1591 //Advanced actions
jtkorhonen@0 1592 hgUpdateToRevAct = new QAction(tr("Update to revision"), this);
jtkorhonen@0 1593 hgUpdateToRevAct -> setStatusTip(tr("Update working folder to version selected from history list"));
jtkorhonen@0 1594
jtkorhonen@0 1595 hgAnnotateAct = new QAction(tr("Annotate"), this);
jtkorhonen@0 1596 hgAnnotateAct -> setStatusTip(tr("Show line-by-line version information for selected file"));
jtkorhonen@0 1597
jtkorhonen@0 1598 hgResolveListAct = new QAction(tr("Resolve (list)"), this);
jtkorhonen@0 1599 hgResolveListAct -> setStatusTip(tr("Resolve (list): Show list of files needing merge"));
jtkorhonen@0 1600
jtkorhonen@0 1601 hgResolveMarkAct = new QAction(tr("Resolve (mark)"), this);
jtkorhonen@0 1602 hgResolveMarkAct -> setStatusTip(tr("Resolve (mark): Mark selected file status as resolved"));
jtkorhonen@0 1603
jtkorhonen@33 1604 hgRetryMergeAct = new QAction(tr("Retry merge"), this);
jtkorhonen@33 1605 hgRetryMergeAct -> setStatusTip(tr("Retry merge after failed merge attempt."));
jtkorhonen@33 1606
jtkorhonen@34 1607 hgTagAct = new QAction(tr("Tag revision"), this);
jtkorhonen@34 1608 hgTagAct -> setStatusTip(tr("Give decsriptive name (tag) to current workfolder parent revision."));
jtkorhonen@34 1609
jtkorhonen@34 1610 hgIgnoreAct = new QAction(tr("Edit .hgignore"), this);
jtkorhonen@34 1611 hgIgnoreAct -> setStatusTip(tr("Edit .hgignore file (file contains names of files that should be ignored by mercurial)"));
jtkorhonen@34 1612
jtkorhonen@11 1613 hgServeAct = new QAction(tr("Serve (via http)"), this);
jtkorhonen@11 1614 hgServeAct -> setStatusTip(tr("Serve local repository via http for workgroup access"));
jtkorhonen@11 1615
jtkorhonen@0 1616 //Help actions
jtkorhonen@0 1617 aboutAct = new QAction(tr("About"), this);
jtkorhonen@0 1618 aboutAct->setStatusTip(tr("Show the application's About box"));
jtkorhonen@0 1619
jtkorhonen@0 1620 aboutQtAct = new QAction(tr("About Qt"), this);
jtkorhonen@0 1621 aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
Chris@94 1622
Chris@94 1623 // Miscellaneous
Chris@94 1624 clearSelectionsAct = new QAction(tr("Clear selections"), this);
Chris@94 1625 clearSelectionsAct->setShortcut(Qt::Key_Escape);
jtkorhonen@0 1626 }
jtkorhonen@0 1627
jtkorhonen@0 1628 void MainWindow::createMenus()
jtkorhonen@0 1629 {
jtkorhonen@0 1630 fileMenu = menuBar()->addMenu(tr("File"));
jtkorhonen@0 1631 fileMenu -> addAction(hgInitAct);
jtkorhonen@0 1632 fileMenu -> addAction(hgCloneFromRemoteAct);
Chris@94 1633 fileMenu->addAction(clearSelectionsAct); //!!! can't live here!
jtkorhonen@0 1634 fileMenu -> addSeparator();
Chris@69 1635 fileMenu -> addAction(openAct);
jtkorhonen@0 1636 fileMenu -> addAction(settingsAct);
jtkorhonen@0 1637 fileMenu -> addSeparator();
jtkorhonen@0 1638 fileMenu -> addAction(exitAct);
jtkorhonen@0 1639
jtkorhonen@0 1640 advancedMenu = menuBar()->addMenu(tr("Advanced"));
jtkorhonen@0 1641 advancedMenu -> addAction(hgUpdateToRevAct);
jtkorhonen@0 1642 advancedMenu -> addSeparator();
jtkorhonen@0 1643 advancedMenu -> addAction(hgAnnotateAct);
jtkorhonen@0 1644 advancedMenu -> addSeparator();
jtkorhonen@33 1645 advancedMenu -> addAction(hgRetryMergeAct);
jtkorhonen@0 1646 advancedMenu -> addAction(hgResolveListAct);
jtkorhonen@0 1647 advancedMenu -> addAction(hgResolveMarkAct);
jtkorhonen@11 1648 advancedMenu -> addSeparator();
jtkorhonen@34 1649 advancedMenu -> addAction(hgTagAct);
jtkorhonen@34 1650 advancedMenu -> addSeparator();
jtkorhonen@34 1651 advancedMenu -> addAction(hgIgnoreAct);
jtkorhonen@34 1652 advancedMenu -> addSeparator();
jtkorhonen@11 1653 advancedMenu -> addAction(hgServeAct);
jtkorhonen@0 1654
jtkorhonen@0 1655 helpMenu = menuBar()->addMenu(tr("Help"));
jtkorhonen@0 1656 helpMenu->addAction(aboutAct);
jtkorhonen@0 1657 helpMenu->addAction(aboutQtAct);
jtkorhonen@0 1658 }
jtkorhonen@0 1659
jtkorhonen@0 1660 void MainWindow::createToolBars()
jtkorhonen@0 1661 {
jtkorhonen@0 1662 fileToolBar = addToolBar(tr("File"));
jtkorhonen@0 1663 fileToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
Chris@69 1664 fileToolBar -> addAction(openAct);
Chris@43 1665 fileToolBar -> addAction(hgStatAct);
jtkorhonen@0 1666 fileToolBar -> addSeparator();
Chris@61 1667 // fileToolBar -> addAction(hgChgSetDiffAct);
jtkorhonen@0 1668 fileToolBar -> setMovable(false);
jtkorhonen@0 1669
jtkorhonen@0 1670 repoToolBar = addToolBar(tr(REPOMENU_TITLE));
jtkorhonen@0 1671 repoToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
jtkorhonen@0 1672 repoToolBar->addAction(hgIncomingAct);
jtkorhonen@0 1673 repoToolBar->addAction(hgPullAct);
jtkorhonen@0 1674 repoToolBar->addAction(hgPushAct);
jtkorhonen@0 1675 repoToolBar -> setMovable(false);
jtkorhonen@0 1676
jtkorhonen@0 1677 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE));
jtkorhonen@0 1678 addToolBar(Qt::LeftToolBarArea, workFolderToolBar);
jtkorhonen@0 1679 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
Chris@61 1680 // workFolderToolBar->addSeparator();
Chris@95 1681 // workFolderToolBar->addAction(hgFileDiffAct);
Chris@95 1682 workFolderToolBar->addAction(hgFolderDiffAct);
jtkorhonen@0 1683 workFolderToolBar->addSeparator();
jtkorhonen@0 1684 workFolderToolBar->addAction(hgRevertAct);
jtkorhonen@0 1685 workFolderToolBar->addAction(hgUpdateAct);
jtkorhonen@0 1686 workFolderToolBar->addAction(hgCommitAct);
jtkorhonen@0 1687 workFolderToolBar->addAction(hgMergeAct);
jtkorhonen@0 1688 workFolderToolBar->addSeparator();
jtkorhonen@0 1689 workFolderToolBar->addAction(hgAddAct);
jtkorhonen@0 1690 workFolderToolBar->addAction(hgRemoveAct);
jtkorhonen@0 1691 workFolderToolBar -> setMovable(false);
Chris@61 1692
Chris@61 1693 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
Chris@61 1694 tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
Chris@61 1695 }
jtkorhonen@0 1696 }
jtkorhonen@0 1697
jtkorhonen@0 1698
jtkorhonen@0 1699 void MainWindow::createStatusBar()
jtkorhonen@0 1700 {
jtkorhonen@0 1701 statusBar()->showMessage(tr("Ready"));
jtkorhonen@0 1702 }
jtkorhonen@0 1703
Chris@69 1704
Chris@69 1705 //!!! review these:
Chris@69 1706
jtkorhonen@0 1707 void MainWindow::readSettings()
jtkorhonen@0 1708 {
jtkorhonen@0 1709 QDir workFolder;
jtkorhonen@0 1710
Chris@61 1711 QSettings settings;
jtkorhonen@0 1712
jtkorhonen@30 1713 remoteRepoPath = settings.value("remoterepopath", "").toString();
jtkorhonen@0 1714 workFolderPath = settings.value("workfolderpath", "").toString();
jtkorhonen@0 1715 if (!workFolder.exists(workFolderPath))
jtkorhonen@0 1716 {
jtkorhonen@0 1717 workFolderPath = "";
jtkorhonen@0 1718 }
jtkorhonen@0 1719
jtkorhonen@0 1720 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
jtkorhonen@0 1721 QSize size = settings.value("size", QSize(400, 400)).toSize();
jtkorhonen@0 1722 firstStart = settings.value("firststart", QVariant(true)).toBool();
jtkorhonen@0 1723
jtkorhonen@0 1724 initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt();
jtkorhonen@0 1725 resize(size);
jtkorhonen@0 1726 move(pos);
jtkorhonen@0 1727 }
jtkorhonen@0 1728
jtkorhonen@17 1729
jtkorhonen@0 1730 void MainWindow::writeSettings()
jtkorhonen@0 1731 {
Chris@61 1732 QSettings settings;
jtkorhonen@0 1733 settings.setValue("pos", pos());
jtkorhonen@0 1734 settings.setValue("size", size());
jtkorhonen@0 1735 settings.setValue("remoterepopath", remoteRepoPath);
jtkorhonen@0 1736 settings.setValue("workfolderpath", workFolderPath);
jtkorhonen@0 1737 settings.setValue("firststart", firstStart);
Chris@91 1738 //!!!settings.setValue("viewFileTypes", hgExp -> getFileTypesBits());
jtkorhonen@0 1739 }
jtkorhonen@0 1740
jtkorhonen@0 1741
jtkorhonen@0 1742
jtkorhonen@0 1743