Vidalia  0.2.15
UpdateProgressDialog.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 #include "UpdateProgressDialog.h"
00012 
00013 
00014 UpdateProgressDialog::UpdateProgressDialog(QWidget *parent)
00015   : QDialog(parent)
00016 {
00017   ui.setupUi(this);
00018 
00019   connect(ui.btnHide, SIGNAL(clicked()), this, SLOT(onHide()));
00020   connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(onCancel()));
00021 
00022   setModal(true);
00023 }
00024 
00025 void
00026 UpdateProgressDialog::setStatus(UpdateProgressDialog::Status status)
00027 {
00028   switch (status) {
00029     case CheckingForUpdates:
00030       ui.lblCurrentAction->setText(tr("Checking for available updates..."));
00031 
00032       ui.progressBar->setMinimum(0);
00033       ui.progressBar->setMaximum(0);
00034 
00035       ui.btnHide->setText(tr("Hide"));
00036       ui.btnCancel->setVisible(true);
00037       ui.btnCancel->setEnabled(true);
00038       break;
00039 
00040     case DownloadingUpdates:
00041       ui.lblCurrentAction->setText(tr("Downloading updates..."));
00042       break;
00043 
00044     case InstallingUpdates:
00045       ui.lblCurrentAction->setText(tr("Installing updated software..."));
00046 
00047       ui.progressBar->setMinimum(0);
00048       ui.progressBar->setMaximum(0);
00049 
00050       ui.btnCancel->setEnabled(false);
00051       break;
00052 
00053     case UpdatesInstalled:
00054       ui.lblCurrentAction->setText(tr("Done! Your software is now up to date."));
00055 
00056       ui.progressBar->setMinimum(0);
00057       ui.progressBar->setMaximum(1);
00058       ui.progressBar->setValue(1);
00059 
00060       ui.btnHide->setText(tr("OK"));
00061       ui.btnCancel->setVisible(false);
00062       break;
00063 
00064     default:
00065       break;
00066   }
00067 }
00068 
00069 void
00070 UpdateProgressDialog::setDownloadProgress(const QString &url,
00071                                           int bytesReceived, int bytesTotal)
00072 {
00073   Q_UNUSED(url);
00074 
00075   setStatus(DownloadingUpdates);
00076   ui.progressBar->setMaximum(bytesTotal);
00077   ui.progressBar->setValue(bytesReceived);
00078 }
00079 
00080 void
00081 UpdateProgressDialog::onHide()
00082 {
00083   setVisible(false);
00084 }
00085 
00086 void
00087 UpdateProgressDialog::onCancel()
00088 {
00089   emit cancelUpdate();
00090   hide();
00091 }
00092