BridgeDownloaderProgressDialog.cpp

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file BridgeDownloaderProgressDialog.cpp
00013 ** \version $Id: BridgeDownloaderProgressDialog.cpp 3735 2009-04-28 20:28:01Z edmanm $
00014 ** \brief Displays the progress of a request for bridge addresses
00015 */
00016 
00017 #include "BridgeDownloaderProgressDialog.h"
00018 
00019 #include <QTimer>
00020 
00021 
00022 BridgeDownloaderProgressDialog::BridgeDownloaderProgressDialog(QWidget *parent)
00023   : QDialog(parent)
00024 {
00025   ui.setupUi(this);
00026  
00027   connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)),
00028           this, SLOT(buttonClicked(QAbstractButton *)));
00029 
00030   setModal(true);
00031 }
00032 
00033 void
00034 BridgeDownloaderProgressDialog::setVisible(bool visible)
00035 {
00036   if (visible) {
00037     ui.progressBar->setRange(0, 0);
00038     ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
00039   }
00040   QDialog::setVisible(visible);
00041 }
00042 
00043 void
00044 BridgeDownloaderProgressDialog::setStatus(const QString &status)
00045 {
00046   ui.lblStatus->setText(status);
00047 }
00048 
00049 void
00050 BridgeDownloaderProgressDialog::setDownloadProgress(int done, int total)
00051 {
00052   ui.progressBar->setRange(0, total);
00053   ui.progressBar->setValue(done);
00054 }
00055 
00056 void
00057 BridgeDownloaderProgressDialog::bridgeRequestFinished(const QStringList &bridges)
00058 {
00059   Q_UNUSED(bridges);
00060   
00061   accept();
00062 }
00063 
00064 void
00065 BridgeDownloaderProgressDialog::bridgeRequestFailed(const QString &error)
00066 {
00067   ui.lblStatus->setText(tr("Unable to download bridges: %1").arg(error));
00068 
00069   ui.progressBar->setRange(0, 1);
00070   ui.progressBar->setValue(1);
00071 
00072   ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel
00073                                      | QDialogButtonBox::Retry
00074                                      | QDialogButtonBox::Help);
00075 }
00076 
00077 void
00078 BridgeDownloaderProgressDialog::buttonClicked(QAbstractButton *button)
00079 {
00080   int standardButton = ui.buttonBox->standardButton(button);
00081   if (standardButton == QDialogButtonBox::Retry) {
00082     setStatus(tr("Retrying bridge request..."));
00083     setDownloadProgress(0, 0);
00084     ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
00085   
00086     QTimer::singleShot(1000, this, SIGNAL(retry()));
00087   } else {
00088     done(standardButton);
00089   }
00090 }
00091 

Generated on Mon Aug 30 19:09:59 2010 for Vidalia by  doxygen 1.5.9