Vidalia 0.2.15
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.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file BridgeDownloaderProgressDialog.cpp
00013 ** \brief Displays the progress of a request for bridge addresses
00014 */
00015 
00016 #include "BridgeDownloaderProgressDialog.h"
00017 
00018 #include <QTimer>
00019 
00020 
00021 BridgeDownloaderProgressDialog::BridgeDownloaderProgressDialog(QWidget *parent)
00022   : QDialog(parent)
00023 {
00024   ui.setupUi(this);
00025  
00026   connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)),
00027           this, SLOT(buttonClicked(QAbstractButton *)));
00028 
00029   setModal(true);
00030 }
00031 
00032 void
00033 BridgeDownloaderProgressDialog::setVisible(bool visible)
00034 {
00035   if (visible) {
00036     ui.progressBar->setRange(0, 0);
00037     ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
00038   }
00039   QDialog::setVisible(visible);
00040 }
00041 
00042 void
00043 BridgeDownloaderProgressDialog::setStatus(const QString &status)
00044 {
00045   ui.lblStatus->setText(status);
00046 }
00047 
00048 void
00049 BridgeDownloaderProgressDialog::setDownloadProgress(qint64 done, qint64 total)
00050 {
00051   ui.progressBar->setRange(0, total);
00052   ui.progressBar->setValue(done);
00053 }
00054 
00055 void
00056 BridgeDownloaderProgressDialog::bridgeRequestFinished(const QStringList &bridges)
00057 {
00058   Q_UNUSED(bridges);
00059   
00060   accept();
00061 }
00062 
00063 void
00064 BridgeDownloaderProgressDialog::bridgeRequestFailed(const QString &error)
00065 {
00066   ui.lblStatus->setText(tr("Unable to download bridges: %1").arg(error));
00067 
00068   ui.progressBar->setRange(0, 1);
00069   ui.progressBar->setValue(1);
00070 
00071   ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel
00072                                      | QDialogButtonBox::Retry
00073                                      | QDialogButtonBox::Help);
00074 }
00075 
00076 void
00077 BridgeDownloaderProgressDialog::buttonClicked(QAbstractButton *button)
00078 {
00079   int standardButton = ui.buttonBox->standardButton(button);
00080   if (standardButton == QDialogButtonBox::Retry) {
00081     setStatus(tr("Retrying bridge request..."));
00082     setDownloadProgress(0, 0);
00083     ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
00084   
00085     QTimer::singleShot(1000, this, SIGNAL(retry()));
00086   } else {
00087     done(standardButton);
00088   }
00089 }
00090