annotate mainwindow.cpp @ 72:121cb1032717

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