UpdatesAvailableDialog.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 UpdatesAvailableDialog.cpp
00013 ** \version $Id: UpdatesAvailableDialog.cpp 3735 2009-04-28 20:28:01Z edmanm $
00014 ** \brief Displays a list of available updates and details, such as release
00015 ** notes. The user can choose to either install the updates now or later, or
00016 ** skip the updates entirely.
00017 */
00018 
00019 #include "UpdatesAvailableDialog.h"
00020 #include "Vidalia.h"
00021 
00022 #include <QHeaderView>
00023 
00024 
00025 UpdatesAvailableDialog::UpdatesAvailableDialog(const PackageList &packageList,
00026                                                QWidget *parent)
00027   : QDialog(parent)
00028 {
00029   ui.setupUi(this);
00030 
00031   connect(ui.btnInstall, SIGNAL(clicked()),
00032           this, SLOT(installUpdatesNow()));
00033   connect(ui.btnInstallLater, SIGNAL(clicked()),
00034           this, SLOT(installUpdatesLater()));
00035 
00036   connect(ui.treeUpdates,
00037           SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
00038           this, SLOT(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
00039 
00040   loadPackagesTable(packageList);
00041 }
00042 
00043 void
00044 UpdatesAvailableDialog::showEvent(QShowEvent *e)
00045 {
00046   ui.treeUpdates->header()->resizeSection(0, 240);
00047   ui.treeUpdates->header()->setResizeMode(1, QHeaderView::ResizeToContents);
00048   QDialog::showEvent(e);
00049 }
00050 
00051 void
00052 UpdatesAvailableDialog::loadPackagesTable(const PackageList &packageList)
00053 {
00054   int row = 0;
00055   QString language;
00056   QTreeWidgetItem *item;
00057  
00058   language = Vidalia::language();
00059 
00060   foreach (PackageInfo package, packageList) {
00061     item = new QTreeWidgetItem(ui.treeUpdates);
00062 
00063     if (package.hasShortDescription(language))
00064       item->setText(0, package.shortDescription(language));
00065     else
00066       item->setText(0, package.shortDescription("en"));
00067 
00068     if (package.hasLongDescription(language))
00069       item->setData(0, Qt::UserRole, package.longDescription(language));
00070     else
00071       item->setData(0, Qt::UserRole, package.longDescription("en"));
00072 
00073     item->setText(1, package.version());
00074     ui.treeUpdates->insertTopLevelItem(row++, item);
00075   }
00076 }
00077 
00078 void
00079 UpdatesAvailableDialog::currentItemChanged(QTreeWidgetItem *current,
00080                                          QTreeWidgetItem *previous)
00081 { 
00082   Q_UNUSED(previous);
00083 
00084   ui.textDetails->clear();
00085   if (current)
00086     ui.textDetails->setText(current->data(0, Qt::UserRole).toString());
00087 }
00088 
00089 void
00090 UpdatesAvailableDialog::installUpdatesNow()
00091 {
00092   done(InstallUpdatesNow);
00093 }
00094 
00095 void
00096 UpdatesAvailableDialog::installUpdatesLater()
00097 {
00098   done(InstallUpdatesLater);
00099 }
00100 

Generated on Mon Aug 30 19:14:03 2010 for Vidalia by  doxygen 1.5.9