[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r3365: Populate the UpdateDialog UI with information from a list of (vidalia/branches/auto-updates/src/vidalia)
Author: edmanm
Date: 2008-12-06 19:20:07 -0500 (Sat, 06 Dec 2008)
New Revision: 3365
Modified:
vidalia/branches/auto-updates/src/vidalia/updatedialog.cpp
vidalia/branches/auto-updates/src/vidalia/updatedialog.h
Log:
Populate the UpdateDialog UI with information from a list of
available PackageInfo objects.
Modified: vidalia/branches/auto-updates/src/vidalia/updatedialog.cpp
===================================================================
--- vidalia/branches/auto-updates/src/vidalia/updatedialog.cpp 2008-12-07 00:18:59 UTC (rev 3364)
+++ vidalia/branches/auto-updates/src/vidalia/updatedialog.cpp 2008-12-07 00:20:07 UTC (rev 3365)
@@ -16,11 +16,84 @@
** skip the updates entirely.
*/
+#include <vidalia.h>
+#include <QHeaderView>
+
#include "updatedialog.h"
-UpdateDialog::UpdateDialog(QWidget *parent)
+
+UpdateDialog::UpdateDialog(const PackageList &packageList, QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
+
+ connect(ui.btnInstall, SIGNAL(clicked()),
+ this, SLOT(installUpdatesNow()));
+ connect(ui.btnInstallLater, SIGNAL(clicked()),
+ this, SLOT(installUpdatesLater()));
+
+ connect(ui.treeUpdates,
+ SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
+ this, SLOT(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
+
+ loadPackagesTable(packageList);
}
+void
+UpdateDialog::showEvent(QShowEvent *e)
+{
+ ui.treeUpdates->header()->resizeSection(0, 240);
+ ui.treeUpdates->header()->setResizeMode(1, QHeaderView::ResizeToContents);
+ QDialog::showEvent(e);
+}
+
+void
+UpdateDialog::loadPackagesTable(const PackageList &packageList)
+{
+ int row = 0;
+ QString language;
+ QTreeWidgetItem *item;
+
+ language = Vidalia::language();
+
+ foreach (PackageInfo package, packageList) {
+ item = new QTreeWidgetItem(ui.treeUpdates);
+
+ if (package.hasShortDescription(language))
+ item->setText(0, package.shortDescription(language));
+ else
+ item->setText(0, package.shortDescription("en"));
+
+ if (package.hasLongDescription(language))
+ item->setData(0, Qt::UserRole, package.longDescription(language));
+ else
+ item->setData(0, Qt::UserRole, package.longDescription("en"));
+
+ item->setText(1, package.version());
+ ui.treeUpdates->insertTopLevelItem(row++, item);
+ }
+}
+
+void
+UpdateDialog::currentItemChanged(QTreeWidgetItem *current,
+ QTreeWidgetItem *previous)
+{
+ Q_UNUSED(previous);
+
+ ui.textDetails->clear();
+ if (current)
+ ui.textDetails->setText(current->data(0, Qt::UserRole).toString());
+}
+
+void
+UpdateDialog::installUpdatesNow()
+{
+ done(InstallUpdatesNow);
+}
+
+void
+UpdateDialog::installUpdatesLater()
+{
+ done(InstallUpdatesLater);
+}
+
Modified: vidalia/branches/auto-updates/src/vidalia/updatedialog.h
===================================================================
--- vidalia/branches/auto-updates/src/vidalia/updatedialog.h 2008-12-07 00:18:59 UTC (rev 3364)
+++ vidalia/branches/auto-updates/src/vidalia/updatedialog.h 2008-12-07 00:20:07 UTC (rev 3365)
@@ -9,7 +9,7 @@
*/
/*
-** \file updatedialog.cpp
+** \file updatedialog.h
** \version $Id$
** \brief Displays a list of available updates and details, such as release
** notes. The user can choose to either install the updates now or later, or
@@ -20,7 +20,10 @@
#define _UPDATEDIALOG_H
#include <QDialog>
+#include <QShowEvent>
+#include <QTreeWidgetItem>
+#include "packageinfo.h"
#include "ui_updatedialog.h"
@@ -29,10 +32,43 @@
Q_OBJECT
public:
- /** Default constructor. */
- UpdateDialog(QWidget *parent = 0);
+ enum UpdateDialogExitCode {
+ InstallUpdatesNow,
+ InstallUpdatesLater,
+ };
+ /** Constructor. */
+ UpdateDialog(const PackageList &packageList, QWidget *parent = 0);
+
+protected:
+ /** Called when the dialog receives a QShowEvent. This simply adjusts
+ * the column widths to something close to sane and forwards the event
+ * to the parent.
+ */
+ virtual void showEvent(QShowEvent *e);
+
+private slots:
+ /** Called when the user selects a different package in the list. The widget
+ * displaying details on the selected package will be updated.
+ */
+ void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
+
+ /** Called when the user opts to install the displayed software updates
+ * immediately.
+ */
+ void installUpdatesNow();
+
+ /** Called when the user opts to install the display software updates at
+ * a later time.
+ */
+ void installUpdatesLater();
+
private:
+ /** Populates the table of available updates with package information
+ * from <b>packageList</b>.
+ */
+ void loadPackagesTable(const PackageList &packageList);
+
Ui::UpdateDialog ui; /**< Qt Designer generated object. */
};