Mercurial > hg > forks > UniversalIndentGUI
changeset 246:41709ff54de7
Improved the dialog handling. Works almost as wished.
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@455 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Mon, 20 Aug 2007 15:32:03 +0000 |
parents | 03887c196019 |
children | d8002e788c72 |
files | src/UpdateCheckDialog.ui src/updatecheckdialog.cpp src/updatecheckdialog.h |
diffstat | 3 files changed, 65 insertions(+), 95 deletions(-) [+] |
line wrap: on
line diff
--- a/src/UpdateCheckDialog.ui Mon Aug 20 13:20:30 2007 +0000 +++ b/src/UpdateCheckDialog.ui Mon Aug 20 15:32:03 2007 +0000 @@ -8,8 +8,8 @@ <rect> <x>0</x> <y>0</y> - <width>299</width> - <height>247</height> + <width>317</width> + <height>91</height> </rect> </property> <property name="windowTitle" > @@ -17,82 +17,30 @@ </property> <layout class="QVBoxLayout" > <item> - <widget class="QWidget" native="1" name="checkingWidget" > - <layout class="QVBoxLayout" > - <item> - <widget class="QLabel" name="label" > - <property name="text" > - <string>Checking for available update</string> - </property> - </widget> - </item> - <item> - <widget class="QProgressBar" name="progressBar" > - <property name="value" > - <number>24</number> - </property> - <property name="textVisible" > - <bool>false</bool> - </property> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox" > - <property name="standardButtons" > - <set>QDialogButtonBox::Cancel</set> - </property> - <property name="centerButtons" > - <bool>true</bool> - </property> - </widget> - </item> - </layout> + <widget class="QLabel" name="label" > + <property name="text" > + <string>Checking whether a newer version is available</string> + </property> </widget> </item> <item> - <widget class="QWidget" native="1" name="newVersionAvailableWidget" > - <layout class="QVBoxLayout" > - <item> - <widget class="QLabel" name="label_2" > - <property name="text" > - <string>A newer version is available. Go to download web site?</string> - </property> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox_2" > - <property name="standardButtons" > - <set>QDialogButtonBox::No|QDialogButtonBox::NoButton|QDialogButtonBox::Yes</set> - </property> - <property name="centerButtons" > - <bool>true</bool> - </property> - </widget> - </item> - </layout> + <widget class="QProgressBar" name="progressBar" > + <property name="value" > + <number>24</number> + </property> + <property name="textVisible" > + <bool>false</bool> + </property> </widget> </item> <item> - <widget class="QWidget" native="1" name="noNewVersionAvailableWidget" > - <layout class="QVBoxLayout" > - <item> - <widget class="QLabel" name="label_3" > - <property name="text" > - <string>No new version available.</string> - </property> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox_3" > - <property name="standardButtons" > - <set>QDialogButtonBox::Ok</set> - </property> - <property name="centerButtons" > - <bool>true</bool> - </property> - </widget> - </item> - </layout> + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="standardButtons" > + <set>QDialogButtonBox::Cancel</set> + </property> + <property name="centerButtons" > + <bool>true</bool> + </property> </widget> </item> </layout>
--- a/src/updatecheckdialog.cpp Mon Aug 20 13:20:30 2007 +0000 +++ b/src/updatecheckdialog.cpp Mon Aug 20 15:32:03 2007 +0000 @@ -23,27 +23,24 @@ setupUi(this); manualUpdateRequested = false; + roleOfClickedButton = QDialogButtonBox::InvalidRole; http = new QHttp(this); connect( http, SIGNAL(done(bool)), this, SLOT(checkForUpdatedReturned(bool)) ); + connect( buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(handleDialogButtonClicked(QAbstractButton*)) ); + this->currentVersion = currentVersion; this->settings = settings; setModal(true); - checkingWidget->show(); - newVersionAvailableWidget->hide(); - noNewVersionAvailableWidget->hide(); } void UpdateCheckDialog::updateCheckManuallyInvoked() { manualUpdateRequested = true; - checkingWidget->show(); - newVersionAvailableWidget->hide(); - noNewVersionAvailableWidget->hide(); + showCheckingForUpdateDialog(); show(); - adjustSize(); checkForUpdate(); } @@ -82,29 +79,17 @@ // Only show update dialog, if the current version string is not equal to the received one. if ( returnedString != currentVersion ) { - checkingWidget->hide(); - newVersionAvailableWidget->show(); - noNewVersionAvailableWidget->hide(); - adjustSize(); + // Show message box whether to download the new version. + showNewVersionAvailableDialog(returnedString); - // Show message box whether to download the new version. - int ret = QMessageBox::question(this, tr("Update available"), - tr("A newer version of UniversalIndentGUI is available.\nYour version is %1. New version is %2.\nDo you want to go to the download website?").arg(currentVersion).arg(returnedString), - QMessageBox::Yes | QMessageBox::Default, - QMessageBox::No); // If yes clicked, open the download url in the default browser. - if (ret == QMessageBox::Yes) { + if ( roleOfClickedButton == QDialogButtonBox::YesRole ) { QDesktopServices::openUrl( QUrl("http://sourceforge.net/project/showfiles.php?group_id=167482") ); } } else if ( manualUpdateRequested ) { - checkingWidget->hide(); - newVersionAvailableWidget->hide(); - noNewVersionAvailableWidget->show(); - adjustSize(); + showNoNewVersionAvailableDialog(); - QMessageBox::information(this, tr("No new update available"), - tr("You already have the latest version of UniversalIndentGUI."), QMessageBox::Ok | QMessageBox::Default); } // Set last update check date. settings->setValueByName("LastUpdateCheck", QDate::currentDate()); @@ -120,3 +105,35 @@ } manualUpdateRequested = false; } + + +void UpdateCheckDialog::showCheckingForUpdateDialog() { + progressBar->show(); + setWindowTitle( tr("Checking for update...") ); + label->setText( tr("Checking whether a newer version is available") ); + buttonBox->setStandardButtons(QDialogButtonBox::Cancel); +} + + +void UpdateCheckDialog::showNewVersionAvailableDialog(QString newVersion) { + progressBar->hide(); + setWindowTitle( tr("Update available") ); + label->setText( tr("A newer version of UniversalIndentGUI is available.\nYour version is %1. \ + New version is %2.\nDo you want to go to the download website?").arg(currentVersion).arg(newVersion) ); + buttonBox->setStandardButtons(QDialogButtonBox::No|QDialogButtonBox::NoButton|QDialogButtonBox::Yes); +} + + +void UpdateCheckDialog::showNoNewVersionAvailableDialog() { + progressBar->hide(); + setWindowTitle( tr("No new update available") ); + label->setText( tr("You already have the latest version of UniversalIndentGUI.") ); + buttonBox->setStandardButtons(QDialogButtonBox::Ok); + exec(); +} + + +void UpdateCheckDialog::handleDialogButtonClicked(QAbstractButton *clickedButton) { + roleOfClickedButton = buttonBox->buttonRole(clickedButton); + accept(); +}
--- a/src/updatecheckdialog.h Mon Aug 20 13:20:30 2007 +0000 +++ b/src/updatecheckdialog.h Mon Aug 20 15:32:03 2007 +0000 @@ -45,14 +45,19 @@ private: void checkForUpdate(); + void showCheckingForUpdateDialog(); + void showNewVersionAvailableDialog(QString newVersion); + void showNoNewVersionAvailableDialog(); UiGuiSettings *settings; bool manualUpdateRequested; QHttp *http; QString currentVersion; + QDialogButtonBox::ButtonRole roleOfClickedButton; private slots: void checkForUpdatedReturned(bool errorOccurred); + void handleDialogButtonClicked(QAbstractButton *clickedButton); }; #endif // UPDATECHECKDIALOG_H