comparison mainwindow.cpp @ 64:794db9353c7f

* Start rejigging the settings/repo-path dialog setup: startup dialog now asks for user name and email only
author Chris Cannam
date Wed, 17 Nov 2010 17:49:16 +0000
parents 2340b00561d2
children 7b1b333acf93
comparison
equal deleted inserted replaced
63:2340b00561d2 64:794db9353c7f
29 #include <QToolButton> 29 #include <QToolButton>
30 #include <QSettings> 30 #include <QSettings>
31 31
32 #include "mainwindow.h" 32 #include "mainwindow.h"
33 #include "settingsdialog.h" 33 #include "settingsdialog.h"
34 #include "startupdialog.h"
34 #include "colourset.h" 35 #include "colourset.h"
35 #include "debug.h" 36 #include "debug.h"
36 37
37 38
38 MainWindow::MainWindow() 39 MainWindow::MainWindow()
66 67
67 setUnifiedTitleAndToolBarOnMac(true); 68 setUnifiedTitleAndToolBarOnMac(true);
68 connectActions(); 69 connectActions();
69 enableDisableActions(); 70 enableDisableActions();
70 71
71 if (firstStart) 72 if (firstStart) {
72 { 73 startupDialog();
73 QMessageBox::information(this, tr("First start todo"), tr("Going to \"Settings\" first.")); 74 firstStart = false;
74 settings(); 75 }
75 } 76
76 77 ColourSet *cs = ColourSet::instance();
77 DEBUG << "User's real name is " << getUserRealName() << endl; 78 cs->clearDefaultNames();
79 cs->addDefaultName("");
80 cs->addDefaultName(getUserInfo());
78 81
79 hgStat(); 82 hgStat();
80 } 83 }
81 84
82 85
83 void MainWindow::closeEvent(QCloseEvent *) 86 void MainWindow::closeEvent(QCloseEvent *)
84 { 87 {
85 writeSettings(); 88 writeSettings();
86 } 89 }
87 90
91
92 QString MainWindow::getUserInfo() const
93 {
94 QSettings settings;
95 settings.beginGroup("User Information");
96 QString name = settings.value("name", getUserRealName()).toString();
97 QString email = settings.value("email", "").toString();
98
99 QString identifier;
100
101 if (email != "") {
102 identifier = QString("%1 <%2>").arg(name).arg(email);
103 } else {
104 identifier = name;
105 }
106
107 return identifier;
108 }
88 109
89 void MainWindow::about() 110 void MainWindow::about()
90 { 111 {
91 QMessageBox::about(this, tr("About HgExplorer"), 112 QMessageBox::about(this, tr("About HgExplorer"),
92 tr("<b>HgExplorer</b> tries to be Mercurial's <b>VSS Explorer:</b> ;-)<br><br>" 113 tr("<b>HgExplorer</b> tries to be Mercurial's <b>VSS Explorer:</b> ;-)<br><br>"
319 if (!comment.isEmpty()) 340 if (!comment.isEmpty())
320 { 341 {
321 if ((justMerged == false) && (areAllSelectedCommitable(hgExp -> workFolderFileList))) 342 if ((justMerged == false) && (areAllSelectedCommitable(hgExp -> workFolderFileList)))
322 { 343 {
323 //User wants to commit selected file(s) (and this is not merge commit, which would fail if we selected files) 344 //User wants to commit selected file(s) (and this is not merge commit, which would fail if we selected files)
324 params << "commit" << "--message" << comment << "--user" << userInfo << "--"; 345 params << "commit" << "--message" << comment << "--user" << getUserInfo() << "--";
325 346
326 QList <QListWidgetItem *> selList = hgExp -> workFolderFileList -> selectedItems(); 347 QList <QListWidgetItem *> selList = hgExp -> workFolderFileList -> selectedItems();
327 for (int i = 0; i < selList.size(); ++i) 348 for (int i = 0; i < selList.size(); ++i)
328 { 349 {
329 QString tmp = selList.at(i)->text(); 350 QString tmp = selList.at(i)->text();
331 } 352 }
332 } 353 }
333 else 354 else
334 { 355 {
335 //Commit all changes 356 //Commit all changes
336 params << "commit" << "--message" << comment << "--user" << userInfo; 357 params << "commit" << "--message" << comment << "--user" << getUserInfo();
337 } 358 }
338 359
339 runner -> startHgCommand(workFolderPath, params); 360 runner -> startHgCommand(workFolderPath, params);
340 runningAction = ACT_COMMIT; 361 runningAction = ACT_COMMIT;
341 } 362 }
369 390
370 if (QDialog::Accepted == getCommentOrTag(tag, tr("Tag:"), tr("Tag"))) 391 if (QDialog::Accepted == getCommentOrTag(tag, tr("Tag:"), tr("Tag")))
371 { 392 {
372 if (!tag.isEmpty()) 393 if (!tag.isEmpty())
373 { 394 {
374 params << "tag" << "--user" << userInfo << filterTag(tag); 395 params << "tag" << "--user" << getUserInfo() << filterTag(tag);
375 396
376 runner -> startHgCommand(workFolderPath, params); 397 runner -> startHgCommand(workFolderPath, params);
377 runningAction = ACT_TAG; 398 runningAction = ACT_TAG;
378 } 399 }
379 } 400 }
665 runner -> killCurrentCommand(); 686 runner -> killCurrentCommand();
666 } 687 }
667 } 688 }
668 689
669 690
691 void MainWindow::startupDialog()
692 {
693 StartupDialog *dlg = new StartupDialog(this);
694 dlg->exec();
695 }
696
670 697
671 void MainWindow::settings() 698 void MainWindow::settings()
672 { 699 {
673 SettingsDialog *settingsDlg = new SettingsDialog(this); 700 SettingsDialog *settingsDlg = new SettingsDialog(this);
674 settingsDlg->setModal(true); 701 settingsDlg->setModal(true);
1452 if (!workFolder.exists(workFolderPath)) 1479 if (!workFolder.exists(workFolderPath))
1453 { 1480 {
1454 workFolderPath = ""; 1481 workFolderPath = "";
1455 } 1482 }
1456 1483
1457 userInfo = settings.value("userinfo", "").toString();
1458
1459 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); 1484 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
1460 QSize size = settings.value("size", QSize(400, 400)).toSize(); 1485 QSize size = settings.value("size", QSize(400, 400)).toSize();
1461 firstStart = settings.value("firststart", QVariant(true)).toBool(); 1486 firstStart = settings.value("firststart", QVariant(true)).toBool();
1462 1487
1463 initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt(); 1488 initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt();
1464 resize(size); 1489 resize(size);
1465 move(pos); 1490 move(pos);
1466
1467 ColourSet *cs = ColourSet::instance();
1468 cs->clearDefaultNames();
1469 cs->addDefaultName("");
1470 cs->addDefaultName("default");
1471 cs->addDefaultName(userInfo);
1472 } 1491 }
1473 1492
1474 1493
1475 void MainWindow::writeSettings() 1494 void MainWindow::writeSettings()
1476 { 1495 {
1477 QSettings settings; 1496 QSettings settings;
1478 settings.setValue("pos", pos()); 1497 settings.setValue("pos", pos());
1479 settings.setValue("size", size()); 1498 settings.setValue("size", size());
1480 settings.setValue("remoterepopath", remoteRepoPath); 1499 settings.setValue("remoterepopath", remoteRepoPath);
1481 settings.setValue("workfolderpath", workFolderPath); 1500 settings.setValue("workfolderpath", workFolderPath);
1482 settings.setValue("userinfo", userInfo);
1483 settings.setValue("firststart", firstStart); 1501 settings.setValue("firststart", firstStart);
1484 settings.setValue("viewFileTypes", hgExp -> getFileTypesBits()); 1502 settings.setValue("viewFileTypes", hgExp -> getFileTypesBits());
1485 } 1503 }
1486 1504
1487 1505