comparison mainwindow.cpp @ 34:43e3b271d293 Version_0.5.2.

Version 0.5.2. Added hg tag, .hgignore editing.
author Jari Korhonen <jtkorhonen@gmail.com>
date Sat, 19 Jun 2010 02:01:36 +0300
parents ff8d64625aa3
children 5986d0758069
comparison
equal deleted inserted replaced
33:ff8d64625aa3 34:43e3b271d293
6 #include <QStringList> 6 #include <QStringList>
7 #include <QDir> 7 #include <QDir>
8 #include <QNetworkInterface> 8 #include <QNetworkInterface>
9 #include <QHostAddress> 9 #include <QHostAddress>
10 #include <QHostInfo> 10 #include <QHostInfo>
11 #include <QDesktopServices>
11 12
12 #include "mainwindow.h" 13 #include "mainwindow.h"
13 #include "settingsdialog.h" 14 #include "settingsdialog.h"
14 15
15 16
242 runner -> startProc(getHgBinaryName(), workFolderPath, params); 243 runner -> startProc(getHgBinaryName(), workFolderPath, params);
243 runningAction = ACT_ADD; 244 runningAction = ACT_ADD;
244 } 245 }
245 } 246 }
246 247
247 int MainWindow::getCommitComment(QString& comment) 248 int MainWindow::getCommentOrTag(QString& commentOrTag, QString question, QString dlgTitle)
248 { 249 {
249 int ret; 250 int ret;
250 251
251 QDialog dlg(this); 252 QDialog dlg(this);
252 253
253 QLabel *commentLabel = new QLabel(tr("Comment:")); 254 QLabel *commentLabel = new QLabel(question);
254 QLineEdit *commentEdit = new QLineEdit; 255 QLineEdit *commentOrTagEdit = new QLineEdit;
255 commentEdit -> setFixedWidth(400); 256 commentOrTagEdit -> setFixedWidth(400);
256 QHBoxLayout *commentLayout = new QHBoxLayout; 257 QHBoxLayout *commentLayout = new QHBoxLayout;
257 commentLayout -> addWidget(commentLabel); 258 commentLayout -> addWidget(commentLabel);
258 commentLayout -> addWidget(commentEdit); 259 commentLayout -> addWidget(commentOrTagEdit);
259 260
260 QPushButton *btnOk = new QPushButton(tr("Ok")); 261 QPushButton *btnOk = new QPushButton(tr("Ok"));
261 QPushButton *btnCancel = new QPushButton(tr("Cancel")); 262 QPushButton *btnCancel = new QPushButton(tr("Cancel"));
262 QHBoxLayout *btnLayout = new QHBoxLayout; 263 QHBoxLayout *btnLayout = new QHBoxLayout;
263 btnLayout -> addWidget(btnOk); 264 btnLayout -> addWidget(btnOk);
267 mainLayout -> addLayout(commentLayout); 268 mainLayout -> addLayout(commentLayout);
268 mainLayout -> addLayout(btnLayout); 269 mainLayout -> addLayout(btnLayout);
269 270
270 dlg.setLayout(mainLayout); 271 dlg.setLayout(mainLayout);
271 272
272 dlg.setWindowTitle(tr("Save (commit)")); 273 dlg.setWindowTitle(dlgTitle);
273 274
274 connect(btnOk, SIGNAL(clicked()), &dlg, SLOT(accept())); 275 connect(btnOk, SIGNAL(clicked()), &dlg, SLOT(accept()));
275 connect(btnCancel, SIGNAL(clicked()), &dlg, SLOT(reject())); 276 connect(btnCancel, SIGNAL(clicked()), &dlg, SLOT(reject()));
276 277
277 ret = dlg.exec(); 278 ret = dlg.exec();
278 comment = commentEdit -> text(); 279 commentOrTag = commentOrTagEdit -> text();
279 return ret; 280 return ret;
280 } 281 }
281 282
282 void MainWindow::hgCommit() 283 void MainWindow::hgCommit()
283 { 284 {
284 if (runningAction == ACT_NONE) 285 if (runningAction == ACT_NONE)
285 { 286 {
286 QStringList params; 287 QStringList params;
287 QString comment; 288 QString comment;
288 289
289 if (QDialog::Accepted == getCommitComment(comment)) 290 if (QDialog::Accepted == getCommentOrTag(comment, tr("Comment:"), tr("Save (commit)")))
290 { 291 {
291 if (!comment.isEmpty()) 292 if (!comment.isEmpty())
292 { 293 {
293 QString currentFile = hgExp -> getCurrentFileListLine();
294
295 if ((justMerged == false) && (areAllSelectedCommitable(hgExp -> workFolderFileList))) 294 if ((justMerged == false) && (areAllSelectedCommitable(hgExp -> workFolderFileList)))
296 { 295 {
297 //User wants to commit selected file(s) (and this is not merge commit, which would fail if we selected files) 296 //User wants to commit selected file(s) (and this is not merge commit, which would fail if we selected files)
298 params << "commit" << "--message" << comment << "--user" << userInfo; 297 params << "commit" << "--message" << comment << "--user" << userInfo;
299 298
315 } 314 }
316 } 315 }
317 } 316 }
318 } 317 }
319 318
319 QString MainWindow::filterTag(QString tag)
320 {
321 for(int i = 0; i < tag.size(); i++)
322 {
323 if (tag[i].isLower() || tag[i].isUpper() || tag[i].isDigit() || (tag[i] == QChar('.')))
324 {
325 //ok
326 }
327 else
328 {
329 tag[i] = QChar('_');
330 }
331 }
332 return tag;
333 }
334
335
336 void MainWindow::hgTag()
337 {
338 if (runningAction == ACT_NONE)
339 {
340 QStringList params;
341 QString tag;
342
343 if (QDialog::Accepted == getCommentOrTag(tag, tr("Tag:"), tr("Tag")))
344 {
345 if (!tag.isEmpty())
346 {
347 params << "tag" << "--user" << userInfo << filterTag(tag);
348
349 runner -> startProc(getHgBinaryName(), workFolderPath, params);
350 runningAction = ACT_TAG;
351 }
352 }
353 }
354 }
355
356
357 void MainWindow::hgIgnore()
358 {
359 if (runningAction == ACT_NONE)
360 {
361 QString hgIgnorePath;
362
363 hgIgnorePath = "file:///";
364 hgIgnorePath += workFolderPath;
365 hgIgnorePath += ".hgignore";
366
367 QDesktopServices::openUrl(QUrl(hgIgnorePath, QUrl::TolerantMode));
368 }
369 }
370
371
372
320 void MainWindow::hgFileDiff() 373 void MainWindow::hgFileDiff()
321 { 374 {
322 if (runningAction == ACT_NONE) 375 if (runningAction == ACT_NONE)
323 { 376 {
324 QStringList params; 377 QStringList params;
521 574
522 runner -> startProc(getHgBinaryName(), workFolderPath, params); 575 runner -> startProc(getHgBinaryName(), workFolderPath, params);
523 runningAction = ACT_PUSH; 576 runningAction = ACT_PUSH;
524 } 577 }
525 } 578 }
526
527 579
528 580
529 QString MainWindow::listAllUpIpV4Addresses() 581 QString MainWindow::listAllUpIpV4Addresses()
530 { 582 {
531 QString ret; 583 QString ret;
887 case ACT_FILEDIFF: 939 case ACT_FILEDIFF:
888 case ACT_FOLDERDIFF: 940 case ACT_FOLDERDIFF:
889 case ACT_CHGSETDIFF: 941 case ACT_CHGSETDIFF:
890 case ACT_REVERT: 942 case ACT_REVERT:
891 case ACT_SERVE: 943 case ACT_SERVE:
944 case ACT_TAG:
892 shouldHgStat = true; 945 shouldHgStat = true;
893 break; 946 break;
894 947
895 case ACT_UPDATE: 948 case ACT_UPDATE:
896 QMessageBox::information(this, "update", runner -> getStdOut()); 949 QMessageBox::information(this, "update", runner -> getStdOut());
962 connect(hgChgSetDiffAct, SIGNAL(triggered()), this, SLOT(hgChgSetDiff())); 1015 connect(hgChgSetDiffAct, SIGNAL(triggered()), this, SLOT(hgChgSetDiff()));
963 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate())); 1016 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
964 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert())); 1017 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
965 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge())); 1018 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
966 connect(hgRetryMergeAct, SIGNAL(triggered()), this, SLOT(hgRetryMerge())); 1019 connect(hgRetryMergeAct, SIGNAL(triggered()), this, SLOT(hgRetryMerge()));
1020 connect(hgTagAct, SIGNAL(triggered()), this, SLOT(hgTag()));
1021 connect(hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
967 1022
968 connect(settingsAct, SIGNAL(triggered()), this, SLOT(settings())); 1023 connect(settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
969 1024
970 connect(hgInitAct, SIGNAL(triggered()), this, SLOT(hgInit())); 1025 connect(hgInitAct, SIGNAL(triggered()), this, SLOT(hgInit()));
971 connect(hgCloneFromRemoteAct, SIGNAL(triggered()), this, SLOT(hgCloneFromRemote())); 1026 connect(hgCloneFromRemoteAct, SIGNAL(triggered()), this, SLOT(hgCloneFromRemote()));
1047 hgRetryMergeAct -> setEnabled(localRepoActionsEnabled); 1102 hgRetryMergeAct -> setEnabled(localRepoActionsEnabled);
1048 hgResolveListAct -> setEnabled(localRepoActionsEnabled); 1103 hgResolveListAct -> setEnabled(localRepoActionsEnabled);
1049 hgResolveMarkAct -> setEnabled(localRepoActionsEnabled); 1104 hgResolveMarkAct -> setEnabled(localRepoActionsEnabled);
1050 hgAnnotateAct -> setEnabled(localRepoActionsEnabled); 1105 hgAnnotateAct -> setEnabled(localRepoActionsEnabled);
1051 hgServeAct -> setEnabled(localRepoActionsEnabled); 1106 hgServeAct -> setEnabled(localRepoActionsEnabled);
1107 hgTagAct -> setEnabled(localRepoActionsEnabled);
1108 hgIgnoreAct -> setEnabled(localRepoActionsEnabled);
1052 1109
1053 hgExp -> enableDisableOtherTabs(tabPage); 1110 hgExp -> enableDisableOtherTabs(tabPage);
1054 1111
1055 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked; 1112 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked;
1056 1113
1112 { 1169 {
1113 hgMergeAct -> setEnabled(false); 1170 hgMergeAct -> setEnabled(false);
1114 hgRetryMergeAct -> setEnabled(false); 1171 hgRetryMergeAct -> setEnabled(false);
1115 } 1172 }
1116 1173
1174 if (hgExp -> localRepoHeadsList->count() < 1)
1175 {
1176 hgTagAct -> setEnabled(false);
1177 }
1178
1117 QString currentFile = hgExp -> getCurrentFileListLine(); 1179 QString currentFile = hgExp -> getCurrentFileListLine();
1118 if (!currentFile.isEmpty()) 1180 if (!currentFile.isEmpty())
1119 { 1181 {
1120 hgAnnotateAct -> setEnabled(true); 1182 hgAnnotateAct -> setEnabled(true);
1121 hgResolveMarkAct -> setEnabled(true); 1183 hgResolveMarkAct -> setEnabled(true);
1224 hgResolveMarkAct = new QAction(tr("Resolve (mark)"), this); 1286 hgResolveMarkAct = new QAction(tr("Resolve (mark)"), this);
1225 hgResolveMarkAct -> setStatusTip(tr("Resolve (mark): Mark selected file status as resolved")); 1287 hgResolveMarkAct -> setStatusTip(tr("Resolve (mark): Mark selected file status as resolved"));
1226 1288
1227 hgRetryMergeAct = new QAction(tr("Retry merge"), this); 1289 hgRetryMergeAct = new QAction(tr("Retry merge"), this);
1228 hgRetryMergeAct -> setStatusTip(tr("Retry merge after failed merge attempt.")); 1290 hgRetryMergeAct -> setStatusTip(tr("Retry merge after failed merge attempt."));
1291
1292 hgTagAct = new QAction(tr("Tag revision"), this);
1293 hgTagAct -> setStatusTip(tr("Give decsriptive name (tag) to current workfolder parent revision."));
1294
1295 hgIgnoreAct = new QAction(tr("Edit .hgignore"), this);
1296 hgIgnoreAct -> setStatusTip(tr("Edit .hgignore file (file contains names of files that should be ignored by mercurial)"));
1229 1297
1230 hgServeAct = new QAction(tr("Serve (via http)"), this); 1298 hgServeAct = new QAction(tr("Serve (via http)"), this);
1231 hgServeAct -> setStatusTip(tr("Serve local repository via http for workgroup access")); 1299 hgServeAct -> setStatusTip(tr("Serve local repository via http for workgroup access"));
1232 1300
1233 //Help actions 1301 //Help actions
1254 advancedMenu -> addAction(hgAnnotateAct); 1322 advancedMenu -> addAction(hgAnnotateAct);
1255 advancedMenu -> addSeparator(); 1323 advancedMenu -> addSeparator();
1256 advancedMenu -> addAction(hgRetryMergeAct); 1324 advancedMenu -> addAction(hgRetryMergeAct);
1257 advancedMenu -> addAction(hgResolveListAct); 1325 advancedMenu -> addAction(hgResolveListAct);
1258 advancedMenu -> addAction(hgResolveMarkAct); 1326 advancedMenu -> addAction(hgResolveMarkAct);
1327 advancedMenu -> addSeparator();
1328 advancedMenu -> addAction(hgTagAct);
1329 advancedMenu -> addSeparator();
1330 advancedMenu -> addAction(hgIgnoreAct);
1259 advancedMenu -> addSeparator(); 1331 advancedMenu -> addSeparator();
1260 advancedMenu -> addAction(hgServeAct); 1332 advancedMenu -> addAction(hgServeAct);
1261 1333
1262 helpMenu = menuBar()->addMenu(tr("Help")); 1334 helpMenu = menuBar()->addMenu(tr("Help"));
1263 helpMenu->addAction(aboutAct); 1335 helpMenu->addAction(aboutAct);
1295 workFolderToolBar->addAction(hgMergeAct); 1367 workFolderToolBar->addAction(hgMergeAct);
1296 workFolderToolBar->addSeparator(); 1368 workFolderToolBar->addSeparator();
1297 workFolderToolBar->addAction(hgAddAct); 1369 workFolderToolBar->addAction(hgAddAct);
1298 workFolderToolBar->addAction(hgRemoveAct); 1370 workFolderToolBar->addAction(hgRemoveAct);
1299 workFolderToolBar -> setMovable(false); 1371 workFolderToolBar -> setMovable(false);
1300
1301 } 1372 }
1302 1373
1303 1374
1304 void MainWindow::createStatusBar() 1375 void MainWindow::createStatusBar()
1305 { 1376 {