Skip to content

Commit

Permalink
Added comments and cleaned up some code.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DaoWen committed Aug 7, 2009
1 parent 21837db commit dfbf3f6
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 30 deletions.
19 changes: 16 additions & 3 deletions inc/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===//
Expand All @@ -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);

};
Expand Down
46 changes: 46 additions & 0 deletions inc/UpdateChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
#include <QtCore>
#include <QtNetwork>

/* 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
Expand All @@ -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);

};
Expand Down
4 changes: 2 additions & 2 deletions src/GDateEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 1 addition & 4 deletions src/GFamilyTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion src/GIndiModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/MainMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
39 changes: 22 additions & 17 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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(
Expand All @@ -174,6 +176,7 @@ void MainWindow::saveFile() {
}
}

/* Append Hanyu Pinyin data */
void MainWindow::appendPinyin() {
// Todo: Separate this from the GUI
int incompleteCount = 0;
Expand All @@ -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
Expand All @@ -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]);
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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) {
Expand All @@ -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"
Expand All @@ -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(
Expand Down
Loading

0 comments on commit dfbf3f6

Please sign in to comment.