From dfbf3f6aaf623f52ada8260942cd844eec4b1d7b Mon Sep 17 00:00:00 2001 From: Nick Vrvilo Date: Fri, 7 Aug 2009 17:57:22 +0000 Subject: [PATCH] Added comments and cleaned up some code. Altered the Date Estimator to only append the place names if defaultPlace is non-empty, non-null. git-svn-id: http://svn.phoenixteam.org/repos/GedTools@45 9dab71d7-c464-4d9a-89bf-b85db2a2fdf8 --- inc/MainWindow.h | 19 ++++++++++++++--- inc/UpdateChecker.h | 46 ++++++++++++++++++++++++++++++++++++++++++ src/GDateEstimator.cpp | 4 ++-- src/GFamilyTree.cpp | 5 +---- src/GIndiModel.cpp | 1 - src/MainMenuBar.cpp | 3 +-- src/MainWindow.cpp | 39 +++++++++++++++++++---------------- src/UpdateChecker.cpp | 28 ++++++++++++++++++++++++- 8 files changed, 115 insertions(+), 30 deletions(-) diff --git a/inc/MainWindow.h b/inc/MainWindow.h index 015c0b8..a292716 100644 --- a/inc/MainWindow.h +++ b/inc/MainWindow.h @@ -65,8 +65,10 @@ Q_OBJECT // Qt Library Macro //=== GUI Components ===// + // The main menu bar for the main window MainMenuBar * _menuBar; + // Table-style view to display the GEDCOM file data QTableView * _tableView; //=== Private Helper Methods ===// @@ -93,32 +95,43 @@ public slots: //=== Menu Action Methods ===// + /* Open a GEDCOM file */ void openFile(); + /* Save current GEDCOM file */ void saveFile(); + /* Append Hanyu Pinyin data */ void appendPinyin(); /* Toggles display between the full set - * of names, and the filtered set containg - * only entries with incomplete pinyin. - */ + * of names, and the filtered set containg + * only entries with incomplete pinyin. + */ void filterIncomplete(bool checked); + /* Open a new tree view to view all families */ void viewTree(); + /* Estimate missing dates in the family tree */ void estimateDates(); + /* Switch between GUI translations */ void switchLanguage(QAction * source); + /* Launch browser to view the GedTools website */ void launchWebsite(); + /* Enable/Disable automatic update checks */ void setAutoUpdate(bool enabled); + /* Display "About" dialog */ void displayAbout(); //=== Other Actions ===// + /* Called when the update check has been completed + */ void updateCheckFinished(const UpdateChecker * checker); }; diff --git a/inc/UpdateChecker.h b/inc/UpdateChecker.h index aaa5aed..19de6e3 100644 --- a/inc/UpdateChecker.h +++ b/inc/UpdateChecker.h @@ -4,6 +4,14 @@ #include #include +/* UpdateChecker: Utility for making HTTP queries to + * check the current program's version against the + * current version on a specified web server + * The web server response should be plain-text, + * containing only the version number. + * Version numbers must be in the format + * [0-9]+.[0-9]+.[0-9]+ + */ class UpdateChecker : public QObject { Q_OBJECT // Qt Library Macro @@ -12,50 +20,88 @@ Q_OBJECT // Qt Library Macro //=== Constructor/Destructor ===// + /* Constructor + * @arg url - URL to query for an updated program version number + * @arg currentVersion - current version number of this program + */ UpdateChecker(const char * url, const QString & currentVersion); + /* Destructor */ ~UpdateChecker(); //=== Accessors ===// + /* Finished + * True if the check has been completed + */ bool finished() const; + /* Has major update + * True if a non-minor version change has been made + * (Numbers before the first two dots have changed) + */ bool hasUpdate() const; + /* Has minor update + * True if any version change has been made + */ bool hasMinorUpdate() const; + /* Errors returned by the network request + */ QNetworkReply::NetworkError error() const; + /* HTTP Response text from the version check + * Should contain the updated version number of the program + * (Could also be helpful in determining causes of errors) + */ const QByteArray & httpResponse() const; //=== Mutators ===// + /* Query the already-specified URL to determine if any + * version updates have been made to the program. + * Fires requestFinished() on completion. + */ void check(); private: + // URL to query for new version info QUrl _url; + // The 3 sub-parts of the current version number: + // _v1._v2._v3 int _v1, _v2, _v3; + // Errors returned from the HTTP request QNetworkReply::NetworkError _error; + // Regular expression for parsing the version string QRegExp versionExp; + // Flags for query results bool _finished, _hasUpdate, _hasMinorUpdate; + // Query response string + // (Should contain the new version number) QByteArray _httpResponse; + // Network Manager used to perform the query QNetworkAccessManager * _netManager; signals: + /* Signal fired upon completion of the version check + */ void checkFinished(const UpdateChecker * updateChecker); private slots: //=== Network Action Slots ===// + /* Called when the Network Manager has finished its request + */ void requestFinished(QNetworkReply * reply); }; diff --git a/src/GDateEstimator.cpp b/src/GDateEstimator.cpp index 9747867..033c87d 100644 --- a/src/GDateEstimator.cpp +++ b/src/GDateEstimator.cpp @@ -178,8 +178,8 @@ int GDateEstimator::updateIndividual(GIndiEntry * indi, GFamily * fam, GIndiEntr ++updated; } } - // Fill in any empty PLAC nodes - if (birthYear.isValid()) { + // Fill in any empty PLAC nodes if default place is set + if (!_defaultPlace.isEmpty() && birthYear.isValid()) { if (indi->birthPlace().isEmpty() && !indi->birthDate().isEmpty()) { indi->setBirthPlace(_defaultPlace); } diff --git a/src/GFamilyTree.cpp b/src/GFamilyTree.cpp index 7e7e7c4..f1f2a68 100644 --- a/src/GFamilyTree.cpp +++ b/src/GFamilyTree.cpp @@ -100,10 +100,7 @@ GFTNode * GFamilyTree::buildBranch(GFamily * fam, QString GFamilyTree::getFamilyName(GIndiEntry * head, GIndiEntry * spouse) { QString familyName; familyName = head->name(); - if (spouse) { - // TODO: Should the " & " be translated? - familyName.append(" & ").append(spouse->name()); - } + if (spouse) familyName.append(" & ").append(spouse->name()); return familyName; } diff --git a/src/GIndiModel.cpp b/src/GIndiModel.cpp index 733ff0b..fb24380 100644 --- a/src/GIndiModel.cpp +++ b/src/GIndiModel.cpp @@ -159,7 +159,6 @@ void GIndiModel::resetViews() { QString GIndiModel::getColData(const GIndiEntry * indi, int col) { QString data; QDate year; - // Todo: Change the cases to constants instead of literals switch (col) { case NAME_COL: data = indi->name(); diff --git a/src/MainMenuBar.cpp b/src/MainMenuBar.cpp index a1083c0..4a29a7b 100644 --- a/src/MainMenuBar.cpp +++ b/src/MainMenuBar.cpp @@ -86,8 +86,7 @@ MainMenuBar::MainMenuBar(MainWindow * mainWin) : QMenuBar(mainWin) { action->setData(locale); _languageMenu->addAction(action); _languageActionGroup->addAction(action); - if (language == currentLanguage) - action->setChecked(true); + if (language == currentLanguage) action->setChecked(true); } // Help Menu _helpMenu = addMenu(tr("&Help")); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index b218cfa..76289d1 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -127,6 +127,7 @@ void MainWindow::checkForUpdates() { //=== Menu Action Methods ===// +/* Open a GEDCOM file */ void MainWindow::openFile() { QString fileName = QFileDialog::getOpenFileName( this, tr("Open GEDCOM File"), @@ -152,11 +153,12 @@ void MainWindow::openFile() { statusBar()->showMessage(tr("File opened.")); } catch (...) { - QMessageBox::critical(this, tr("Error"), fileName.prepend(tr("Unable to open file:\n"))); + QMessageBox::critical(this, tr("Error"), tr("Unable to open file:\n").append(fileName)); } } } +/* Save current GEDCOM file */ void MainWindow::saveFile() { // TODO: check for file write fails QString fileName = QFileDialog::getSaveFileName( @@ -174,6 +176,7 @@ void MainWindow::saveFile() { } } +/* Append Hanyu Pinyin data */ void MainWindow::appendPinyin() { // Todo: Separate this from the GUI int incompleteCount = 0; @@ -182,11 +185,9 @@ void MainWindow::appendPinyin() { GIndiMap & indiMap = _gedFile->indiMap(); GIndiMap::Iterator i, end = indiMap.end(); QString name, romanName, pinyin; - bool needSpace; - // If there are no hanzi then we don't need a romanized name - bool hasHanzi; - // If this romanization has a "?" then it's incomplete - bool incomplete; + bool needSpace; // Don't append spaces between hanzi + bool hasHanzi; // If there are no hanzi then we don't need a romanized name + bool incomplete; // If this romanization has a "?" then it's incomplete // Loop through every GIndiEntry in the GIndiMap for (i=indiMap.begin();i!=end;++i) { // Reset variables for this name entry @@ -200,9 +201,7 @@ void MainWindow::appendPinyin() { // If it's a Hanzi then append pinyin for it if (name[j] >= CJK_CODEPOINT) { // Append space if needed - if (needSpace) { - romanName.append(' '); - } + if (needSpace) romanName.append(' '); hasHanzi = true; // Find the pinyin entry for this hanzi pinyin = pinyinMap.lookup(name[j]); @@ -225,14 +224,9 @@ void MainWindow::appendPinyin() { } } // Update the romanized name entry if needed - if (hasHanzi) { - i.value()->setRomanizedName(romanName); - } + if (hasHanzi) i.value()->setRomanizedName(romanName); // If this entry was incomplete then increment the count - if (incomplete) { - ++incompleteCount; - } - + if (incomplete) ++incompleteCount; } // Update the Model/View now that data has been changed _indiModel->resetViews(); @@ -252,6 +246,10 @@ void MainWindow::appendPinyin() { } } +/* Toggles display between the full set + * of names, and the filtered set containg + * only entries with incomplete pinyin. + */ void MainWindow::filterIncomplete(bool checked) { // Make sure the filtered model exists if (!_filteredModel) { @@ -278,6 +276,7 @@ void MainWindow::filterIncomplete(bool checked) { } } +/* Open a new tree view to view all families */ void MainWindow::viewTree() { // Build the family trees first if necessary if (!_trees) createFamilyTrees(); @@ -289,6 +288,7 @@ void MainWindow::viewTree() { delete treeModel; } +/* Estimate missing dates in the family tree */ void MainWindow::estimateDates() { // Build the family trees first if necessary if (!_trees) createFamilyTrees(); @@ -298,7 +298,6 @@ void MainWindow::estimateDates() { defaultLocation[0] = QChar(0x4e2d); // Zhong1 defaultLocation[1] = QChar(0x570b); // Guo2 bool okPressed; - // Todo: fix this so that the OK/Cancel buttons get translated into Chinese defaultLocation = QInputDialog::getText(this, tr("Enter Default Location"), tr("Automatically use this location to\nfill in blank birth, marriage and death places:"), QLineEdit::Normal, defaultLocation, &okPressed); @@ -319,6 +318,7 @@ void MainWindow::estimateDates() { } } +/* Switch between GUI translations */ void MainWindow::switchLanguage(QAction * source) { // Set translators _appTranslator->load("lang/GedTools_" + source->data().toString()); @@ -332,12 +332,14 @@ void MainWindow::switchLanguage(QAction * source) { resetDisplayModel(_indiModel); } +/* Launch browser to view the GedTools website */ void MainWindow::launchWebsite() { if (!QDesktopServices::openUrl(QUrl(tr("http://ouuuuch.phoenixteam.org/released/gedTools/")))) { QMessageBox::critical(this, tr("Error"), tr("Failed to open web browser")); } } +/* Enable/Disable automatic update checks */ void MainWindow::setAutoUpdate(bool enabled) { // Delete the file "noUpdates" if enabled if (enabled) { @@ -351,6 +353,7 @@ void MainWindow::setAutoUpdate(bool enabled) { } } +/* Display "About" dialog */ void MainWindow::displayAbout() { QMessageBox::about(this, tr("About GedTools"), QString(tr( "GedTools v%1\n" @@ -364,6 +367,8 @@ void MainWindow::displayAbout() { //=== Other Actions ===// +/* Called when the update check has been completed + */ void MainWindow::updateCheckFinished(const UpdateChecker * checker) { if (checker->hasUpdate()) { int response = QMessageBox::information( diff --git a/src/UpdateChecker.cpp b/src/UpdateChecker.cpp index 23c014d..70d1112 100644 --- a/src/UpdateChecker.cpp +++ b/src/UpdateChecker.cpp @@ -3,6 +3,10 @@ //=== Constructor/Destructor ===// +/* Constructor + * @arg url - URL to query for an updated program version number + * @arg currentVersion - current version number of this program + */ UpdateChecker::UpdateChecker(const char * url, const QString & currentVersion) : _url(url), versionExp("(\\d+)\\.(\\d+)\\.(\\d+)") { // Get the current version information @@ -14,35 +18,55 @@ UpdateChecker::UpdateChecker(const char * url, const QString & currentVersion) _netManager = 0; } +/* Destructor */ UpdateChecker::~UpdateChecker() { delete _netManager; } //=== Accessors ===// +/* Finished + * True if the check has been completed + */ bool UpdateChecker::finished() const { return _finished; } - +/* Has major update + * True if a non-minor version change has been made + * (Numbers before the first two dots have changed) + */ bool UpdateChecker::hasUpdate() const { return _hasUpdate; } +/* Has minor update + * True if any version change has been made + */ bool UpdateChecker::hasMinorUpdate() const { return _hasMinorUpdate; } +/* Errors returned by the network request + */ QNetworkReply::NetworkError UpdateChecker::error() const { return _error; } +/* HTTP Response text from the version check + * Should contain the updated version number of the program + * (Could also be helpful in determining causes of errors) + */ const QByteArray & UpdateChecker::httpResponse() const { return _httpResponse; } //=== Mutators ===// +/* Query the already-specified URL to determine if any + * version updates have been made to the program. + * Fires requestFinished() on completion. + */ void UpdateChecker::check() { // Only make the check if there hasn't been one already if (!_netManager) { @@ -57,6 +81,8 @@ void UpdateChecker::check() { //=== Network Action Slots ===// +/* Called when the Network Manager has finished its request + */ void UpdateChecker::requestFinished(QNetworkReply * reply) { _httpResponse = reply->readAll(); _error = reply->error();