comparison mainwindow.cpp @ 90:b43355c2473a

* Add filesystem watcher; initial work on enable/disable logic for actions in new scheme
author Chris Cannam
date Tue, 23 Nov 2010 16:35:49 +0000
parents 89f793fbedda
children 879af4608c5e
comparison
equal deleted inserted replaced
89:622da79c0f4f 90:b43355c2473a
26 #include <QMenuBar> 26 #include <QMenuBar>
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 32
32 #include "mainwindow.h" 33 #include "mainwindow.h"
33 #include "settingsdialog.h" 34 #include "settingsdialog.h"
34 #include "multichoicedialog.h" 35 #include "multichoicedialog.h"
35 #include "startupdialog.h" 36 #include "startupdialog.h"
40 41
41 MainWindow::MainWindow() 42 MainWindow::MainWindow()
42 { 43 {
43 QString wndTitle; 44 QString wndTitle;
44 45
46 fsWatcher = 0;
47
45 createActions(); 48 createActions();
46 createMenus(); 49 createMenus();
47 createToolBars(); 50 createToolBars();
48 createStatusBar(); 51 createStatusBar();
49 52
89 92
90 93
91 void MainWindow::closeEvent(QCloseEvent *) 94 void MainWindow::closeEvent(QCloseEvent *)
92 { 95 {
93 writeSettings(); 96 writeSettings();
97 delete fsWatcher;
94 } 98 }
95 99
96 100
97 QString MainWindow::getUserInfo() const 101 QString MainWindow::getUserInfo() const
98 { 102 {
173 } 177 }
174 } 178 }
175 179
176 void MainWindow::hgLog() 180 void MainWindow::hgLog()
177 { 181 {
182 //!!! This needs to be incremental, except when we pull or set new repo
178 if (runningAction == ACT_NONE) 183 if (runningAction == ACT_NONE)
179 { 184 {
180 QStringList params; 185 QStringList params;
181 params << "log"; 186 params << "log";
182 params << "--template"; 187 params << "--template";
304 runner -> startHgCommand(workFolderPath, params); 309 runner -> startHgCommand(workFolderPath, params);
305 runningAction = ACT_ADD; 310 runningAction = ACT_ADD;
306 } 311 }
307 } 312 }
308 313
309 int MainWindow::getCommentOrTag(QString& commentOrTag, QString question, QString dlgTitle) 314 bool MainWindow::getCommentOrTag(QString& commentOrTag,
310 { 315 QString question,
316 QString dlgTitle)
317 {
318 bool ok = false;
319 QString text = QInputDialog::getText(this, dlgTitle, question, QLineEdit::Normal, commentOrTag, &ok);
320 commentOrTag = text;
321 return ok;
322
323 /*!!!
311 int ret; 324 int ret;
312 325
313 QDialog dlg(this); 326 QDialog dlg(this);
314 327
315 QLabel *commentLabel = new QLabel(question); 328 QLabel *commentLabel = new QLabel(question);
337 connect(btnCancel, SIGNAL(clicked()), &dlg, SLOT(reject())); 350 connect(btnCancel, SIGNAL(clicked()), &dlg, SLOT(reject()));
338 351
339 ret = dlg.exec(); 352 ret = dlg.exec();
340 commentOrTag = commentOrTagEdit -> text(); 353 commentOrTag = commentOrTagEdit -> text();
341 return ret; 354 return ret;
355 */
342 } 356 }
343 357
344 void MainWindow::hgCommit() 358 void MainWindow::hgCommit()
345 { 359 {
346 if (runningAction == ACT_NONE) 360 if (runningAction == ACT_NONE)
347 { 361 {
348 QStringList params; 362 QStringList params;
349 QString comment; 363 QString comment;
350 364
351 if (QDialog::Accepted == getCommentOrTag(comment, tr("Comment:"), tr("Save (commit)"))) 365 if (getCommentOrTag(comment, tr("Comment:"), tr("Save (commit)")))
352 { 366 {
353 if (!comment.isEmpty()) 367 if (!comment.isEmpty())
354 { 368 {
355 if ((justMerged == false) && (areAllSelectedCommitable(hgExp -> workFolderFileList))) 369 if ((justMerged == false) && (areAllSelectedCommitable(hgExp -> workFolderFileList)))
356 { 370 {
399 if (runningAction == ACT_NONE) 413 if (runningAction == ACT_NONE)
400 { 414 {
401 QStringList params; 415 QStringList params;
402 QString tag; 416 QString tag;
403 417
404 if (QDialog::Accepted == getCommentOrTag(tag, tr("Tag:"), tr("Tag"))) 418 if (getCommentOrTag(tag, tr("Tag:"), tr("Tag")))
405 { 419 {
406 if (!tag.isEmpty()) 420 if (!tag.isEmpty())
407 { 421 {
408 params << "tag" << "--user" << getUserInfo() << filterTag(tag); 422 params << "tag" << "--user" << getUserInfo() << filterTag(tag);
409 423
1216 selectedRemoved = 0; 1230 selectedRemoved = 0;
1217 selectedNotTracked = 0; 1231 selectedNotTracked = 0;
1218 } 1232 }
1219 } 1233 }
1220 1234
1235
1236 void MainWindow::updateFileSystemWatcher()
1237 {
1238 //!!! this needs to be incremental when something changes
1239
1240 delete fsWatcher;
1241 fsWatcher = new QFileSystemWatcher();
1242 std::deque<QString> pending;
1243 pending.push_back(workFolderPath);
1244 while (!pending.empty()) {
1245 QString path = pending.front();
1246 pending.pop_front();
1247 fsWatcher->addPath(path);
1248 DEBUG << "Added to file system watcher: " << path << endl;
1249 QDir d(path);
1250 if (d.exists()) {
1251 d.setFilter(QDir::Files | QDir::Dirs |
1252 QDir::NoDotAndDotDot | QDir::Readable);
1253 foreach (QString entry, d.entryList()) {
1254 if (entry == ".hg") continue;
1255 QString entryPath = d.absoluteFilePath(entry);
1256 pending.push_back(entryPath);
1257 }
1258 }
1259 }
1260 connect(fsWatcher, SIGNAL(directoryChanged(QString)),
1261 this, SLOT(fsDirectoryChanged(QString)));
1262 connect(fsWatcher, SIGNAL(fileChanged(QString)),
1263 this, SLOT(fsFileChanged(QString)));
1264 }
1265
1266 void MainWindow::fsDirectoryChanged(QString)
1267 {
1268 //!!! should just queue one of these!
1269 hgStat();
1270 }
1271
1272 void MainWindow::fsFileChanged(QString)
1273 {
1274 //!!! should just queue one of these!
1275 hgStat();
1276 }
1221 1277
1222 void MainWindow::commandFailed() 1278 void MainWindow::commandFailed()
1223 { 1279 {
1224 DEBUG << "MainWindow::commandFailed" << endl; 1280 DEBUG << "MainWindow::commandFailed" << endl;
1225 runningAction = ACT_NONE; 1281 runningAction = ACT_NONE;
1265 break; 1321 break;
1266 } 1322 }
1267 1323
1268 case ACT_STAT: 1324 case ACT_STAT:
1269 hgExp -> updateWorkFolderFileList(runner -> getOutput()); 1325 hgExp -> updateWorkFolderFileList(runner -> getOutput());
1326 updateFileSystemWatcher();
1270 break; 1327 break;
1271 1328
1272 case ACT_INCOMING: 1329 case ACT_INCOMING:
1273 case ACT_ANNOTATE: 1330 case ACT_ANNOTATE:
1274 case ACT_RESOLVE_LIST: 1331 case ACT_RESOLVE_LIST:
1401 hgPaths(); 1458 hgPaths();
1402 } 1459 }
1403 } 1460 }
1404 } 1461 }
1405 } 1462 }
1406 else 1463
1407 { 1464 enableDisableActions();
1408 enableDisableActions();
1409 }
1410 } 1465 }
1411 1466
1412 void MainWindow::connectActions() 1467 void MainWindow::connectActions()
1413 { 1468 {
1414 connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); 1469 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
1454 1509
1455 } 1510 }
1456 1511
1457 void MainWindow::enableDisableActions() 1512 void MainWindow::enableDisableActions()
1458 { 1513 {
1514 DEBUG << "MainWindow::enableDisableActions" << endl;
1515
1459 QDir localRepoDir; 1516 QDir localRepoDir;
1460 QDir workFolderDir; 1517 QDir workFolderDir;
1461 bool workFolderExist; 1518 bool workFolderExist;
1462 bool localRepoExist; 1519 bool localRepoExist;
1463 1520
1464 remoteRepoActionsEnabled = true; 1521 remoteRepoActionsEnabled = true;
1465 if (remoteRepoPath.isEmpty()) 1522 if (remoteRepoPath.isEmpty()) {
1466 {
1467 remoteRepoActionsEnabled = false; 1523 remoteRepoActionsEnabled = false;
1468 } 1524 }
1469 1525
1470 localRepoActionsEnabled = true; 1526 localRepoActionsEnabled = true;
1471 if (workFolderPath.isEmpty()) 1527 if (workFolderPath.isEmpty()) {
1472 {
1473 localRepoActionsEnabled = false; 1528 localRepoActionsEnabled = false;
1474 workFolderExist = false; 1529 workFolderExist = false;
1475 } 1530 }
1476 1531
1477 if (!workFolderDir.exists(workFolderPath)) 1532 if (!workFolderDir.exists(workFolderPath)) {
1478 {
1479 localRepoActionsEnabled = false; 1533 localRepoActionsEnabled = false;
1480 workFolderExist = false; 1534 workFolderExist = false;
1481 } 1535 } else {
1482 else
1483 {
1484 workFolderExist = true; 1536 workFolderExist = true;
1485 } 1537 }
1486 1538
1487 if (!localRepoDir.exists(workFolderPath + getHgDirName())) 1539 if (!localRepoDir.exists(workFolderPath + "/" + getHgDirName())) {
1488 {
1489 localRepoActionsEnabled = false; 1540 localRepoActionsEnabled = false;
1490 localRepoExist = false; 1541 localRepoExist = false;
1491 } 1542 }
1492 1543
1493 hgCloneFromRemoteAct -> setEnabled(remoteRepoActionsEnabled); 1544 hgCloneFromRemoteAct -> setEnabled(remoteRepoActionsEnabled);
1518 hgTagAct -> setEnabled(localRepoActionsEnabled); 1569 hgTagAct -> setEnabled(localRepoActionsEnabled);
1519 hgIgnoreAct -> setEnabled(localRepoActionsEnabled); 1570 hgIgnoreAct -> setEnabled(localRepoActionsEnabled);
1520 1571
1521 hgExp -> enableDisableOtherTabs(tabPage); 1572 hgExp -> enableDisableOtherTabs(tabPage);
1522 1573
1574 DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl;
1575 DEBUG << "canCommit = " << hgExp->canCommit() << endl;
1576
1577 //!!! new stuff:
1578 hgCommitAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit());
1579 hgRevertAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit());
1580
1581 /*!!!
1523 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked; 1582 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked;
1524 1583
1525 countModifications(hgExp -> workFolderFileList, 1584 countModifications(hgExp -> workFolderFileList,
1526 added, modified, removed, notTracked, 1585 added, modified, removed, notTracked,
1527 selected, 1586 selected,
1621 else 1680 else
1622 { 1681 {
1623 hgUpdateToRevAct -> setEnabled(false); 1682 hgUpdateToRevAct -> setEnabled(false);
1624 } 1683 }
1625 } 1684 }
1685 */
1626 } 1686 }
1627 1687
1628 void MainWindow::createActions() 1688 void MainWindow::createActions()
1629 { 1689 {
1630 //File actions 1690 //File actions