comparison mainwindow.cpp @ 125:63c2f3f61c79

* Add Incoming dialog and better layouts for dialogs generally
author Chris Cannam
date Mon, 29 Nov 2010 17:03:17 +0000
parents c3e8342d2de9
children f41bbd0c7c27
comparison
equal deleted inserted replaced
124:1f27f71a7034 125:63c2f3f61c79
27 #include <QApplication> 27 #include <QApplication>
28 #include <QToolBar> 28 #include <QToolBar>
29 #include <QToolButton> 29 #include <QToolButton>
30 #include <QSettings> 30 #include <QSettings>
31 #include <QInputDialog> 31 #include <QInputDialog>
32 #include <QRegExp>
32 33
33 #include "mainwindow.h" 34 #include "mainwindow.h"
34 #include "multichoicedialog.h" 35 #include "multichoicedialog.h"
35 #include "startupdialog.h" 36 #include "startupdialog.h"
36 #include "colourset.h" 37 #include "colourset.h"
37 #include "debug.h" 38 #include "debug.h"
38 #include "logparser.h" 39 #include "logparser.h"
39 #include "confirmcommentdialog.h" 40 #include "confirmcommentdialog.h"
41 #include "incomingdialog.h"
40 42
41 43
42 MainWindow::MainWindow() 44 MainWindow::MainWindow()
43 { 45 {
44 QString wndTitle; 46 QString wndTitle;
183 void MainWindow::hgLog() 185 void MainWindow::hgLog()
184 { 186 {
185 QStringList params; 187 QStringList params;
186 params << "log"; 188 params << "log";
187 params << "--template"; 189 params << "--template";
188 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"; 190 params << Changeset::getLogTemplate();
189 191
190 runner->requestAction(HgAction(ACT_LOG, workFolderPath, params)); 192 runner->requestAction(HgAction(ACT_LOG, workFolderPath, params));
191 } 193 }
192 194
193 void MainWindow::hgLogIncremental() 195 void MainWindow::hgLogIncremental()
199 int n = head->number(); 201 int n = head->number();
200 params << "--prune" << QString("%1").arg(n); 202 params << "--prune" << QString("%1").arg(n);
201 } 203 }
202 204
203 params << "--template"; 205 params << "--template";
204 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"; 206 params << Changeset::getLogTemplate();
205 207
206 runner->requestAction(HgAction(ACT_LOG_INCREMENTAL, workFolderPath, params)); 208 runner->requestAction(HgAction(ACT_LOG_INCREMENTAL, workFolderPath, params));
207 } 209 }
208 210
209 void MainWindow::hgQueryParents() 211 void MainWindow::hgQueryParents()
578 void MainWindow::hgIncoming() 580 void MainWindow::hgIncoming()
579 { 581 {
580 QStringList params; 582 QStringList params;
581 583
582 params << "incoming" << "--newest-first" << remoteRepoPath; 584 params << "incoming" << "--newest-first" << remoteRepoPath;
585 params << "--template" << Changeset::getLogTemplate();
583 586
584 runner->requestAction(HgAction(ACT_INCOMING, workFolderPath, params)); 587 runner->requestAction(HgAction(ACT_INCOMING, workFolderPath, params));
585 } 588 }
586 589
587 590
1033 { 1036 {
1034 DEBUG << "MainWindow::fsFileChanged " << f << endl; 1037 DEBUG << "MainWindow::fsFileChanged " << f << endl;
1035 hgStat(); 1038 hgStat();
1036 } 1039 }
1037 1040
1041 QString MainWindow::format3(QString head, QString intro, QString code)
1042 {
1043 if (intro == "") {
1044 return QString("<qt><h3>%1</h3><code>%2</code>")
1045 .arg(head).arg(xmlEncode(code).replace("\n", "<br>"));
1046 } else {
1047 return QString("<qt><h3>%1</h3><p>%2</p><code>%3</code>")
1048 .arg(head).arg(intro).arg(xmlEncode(code).replace("\n", "<br>"));
1049 }
1050 }
1051
1038 void MainWindow::showIncoming(QString output) 1052 void MainWindow::showIncoming(QString output)
1039 { 1053 {
1040 runner->hide(); 1054 runner->hide();
1041 QMessageBox::information(this, "Incoming", output); 1055 IncomingDialog *d = new IncomingDialog(this, output);
1056 d->exec();
1057 delete d;
1058 }
1059
1060 int MainWindow::extractChangeCount(QString text)
1061 {
1062 QRegExp re("added (\\d+) ch\\w+ with (\\d+) ch\\w+ to (\\d+) f\\w+");
1063 if (re.indexIn(text) >= 0) {
1064 return re.cap(1).toInt();
1065 } else if (text.contains("no changes")) {
1066 return 0;
1067 } else {
1068 return -1; // unknown
1069 }
1042 } 1070 }
1043 1071
1044 void MainWindow::showPushResult(QString output) 1072 void MainWindow::showPushResult(QString output)
1045 { 1073 {
1074 QString report;
1075 int n = extractChangeCount(output);
1076 if (n > 0) {
1077 report = tr("Pushed %n changeset(s)", "", n);
1078 } else if (n == 0) {
1079 report = tr("No changes to push");
1080 } else {
1081 report = tr("Push complete");
1082 }
1083 report = format3(report, tr("The push command output was:"), output);
1046 runner->hide(); 1084 runner->hide();
1047 QMessageBox::information(this, "Push", output); 1085 QMessageBox::information(this, "Push complete", report);
1048 } 1086 }
1049 1087
1050 void MainWindow::showPullResult(QString output) 1088 void MainWindow::showPullResult(QString output)
1051 { 1089 {
1090 QString report;
1091 int n = extractChangeCount(output);
1092 if (n > 0) {
1093 report = tr("Pulled %n changeset(s)", "", n);
1094 } else if (n == 0) {
1095 report = tr("No changes to pull");
1096 } else {
1097 report = tr("Pull complete");
1098 }
1099 report = format3(report, tr("The pull command output was:"), output);
1052 runner->hide(); 1100 runner->hide();
1053 QMessageBox::information(this, "Pull", output); 1101
1102 //!!! and something about updating
1103
1104 QMessageBox::information(this, "Pull complete", report);
1054 } 1105 }
1055 1106
1056 void MainWindow::commandFailed(HgAction action, QString stderr) 1107 void MainWindow::commandFailed(HgAction action, QString stderr)
1057 { 1108 {
1058 DEBUG << "MainWindow::commandFailed" << endl; 1109 DEBUG << "MainWindow::commandFailed" << endl;
1064 // uh huh 1115 // uh huh
1065 return; 1116 return;
1066 case ACT_INCOMING: 1117 case ACT_INCOMING:
1067 // returns non-zero code if the check was successful but there 1118 // returns non-zero code if the check was successful but there
1068 // are no changes pending 1119 // are no changes pending
1120 if (stderr.trimmed() == "") showIncoming("");
1069 return; 1121 return;
1070 case ACT_FOLDERDIFF: 1122 case ACT_FOLDERDIFF:
1071 case ACT_FILEDIFF: 1123 case ACT_FILEDIFF:
1072 case ACT_CHGSETDIFF: 1124 case ACT_CHGSETDIFF:
1073 // external program, unlikely to be anything useful in stderr 1125 // external program, unlikely to be anything useful in stderr