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