annotate mainwindow.cpp @ 79:aaeabc920ca8

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