2011-02-21 16:30:31 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
2012-02-06 11:00:18 +01:00
|
|
|
** This file is part of Installer Framework
|
2011-02-21 16:30:31 +01:00
|
|
|
**
|
2012-02-06 11:00:18 +01:00
|
|
|
** Copyright (c) 2011-2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-02-21 16:30:31 +01:00
|
|
|
**
|
2012-02-06 11:30:37 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-02-21 16:30:31 +01:00
|
|
|
**
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2012-02-06 11:00:18 +01:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** Other Usage
|
2011-02-21 16:30:31 +01:00
|
|
|
**
|
2012-02-06 11:00:18 +01:00
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
2012-02-06 11:30:37 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-02-21 16:30:31 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
2012-02-06 11:00:18 +01:00
|
|
|
|
2011-02-21 16:30:31 +01:00
|
|
|
#include "componentselectiondialog.h"
|
|
|
|
#include "ui_componentselectiondialog.h"
|
|
|
|
|
2011-06-09 13:45:22 +02:00
|
|
|
#include <component.h>
|
2011-05-24 23:15:05 +02:00
|
|
|
#include <componentmodel.h>
|
2011-06-15 12:39:03 +02:00
|
|
|
#include <packagemanagercore.h>
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-06-01 14:55:19 +02:00
|
|
|
#include <QtGui/QHeaderView>
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
2011-02-21 16:30:31 +01:00
|
|
|
using namespace QInstaller;
|
|
|
|
|
|
|
|
class ComponentSelectionDialog::Private : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2011-06-01 14:55:19 +02:00
|
|
|
|
2011-02-21 16:30:31 +01:00
|
|
|
public:
|
2011-06-14 16:24:50 +02:00
|
|
|
Private(ComponentSelectionDialog *qq, PackageManagerCore *core)
|
2011-05-31 17:11:42 +02:00
|
|
|
: q(qq),
|
2011-06-14 16:24:50 +02:00
|
|
|
m_core(core)
|
2011-02-21 16:30:31 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-06-01 14:55:19 +02:00
|
|
|
void currentChanged(const QModelIndex &index)
|
2011-02-21 16:30:31 +01:00
|
|
|
{
|
2011-06-01 14:55:19 +02:00
|
|
|
installBtn->setEnabled(componentModel->hasCheckedComponents());
|
|
|
|
const int selectionCount = componentModel->checkedComponents().count();
|
2011-05-31 17:11:42 +02:00
|
|
|
installBtn->setText(selectionCount > 1 ? tr("Install %1 Items").arg(selectionCount) :
|
|
|
|
selectionCount == 1 ? tr("Install 1 Item") : tr("Install"));
|
2011-06-01 14:55:19 +02:00
|
|
|
ui.buttonBox->button(QDialogButtonBox::Cancel)->setText(selectionCount > 0 ? tr("Cancel")
|
|
|
|
: tr("Close"));
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-06-01 14:55:19 +02:00
|
|
|
if (index.isValid()) {
|
|
|
|
ui.textBrowser->setHtml(componentModel->data(componentModel->index(index.row(), 0,
|
|
|
|
index.parent()), Qt::ToolTipRole).toString());
|
2011-02-21 16:30:31 +01:00
|
|
|
} else {
|
|
|
|
ui.textBrowser->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void modelReset()
|
|
|
|
{
|
2011-05-31 17:11:42 +02:00
|
|
|
ui.treeView->header()->resizeSection(0, ui.labelTitle->sizeHint().width() / 1.5);
|
|
|
|
ui.treeView->header()->setStretchLastSection(true);
|
|
|
|
for (int i = 0; i < ui.treeView->model()->columnCount(); ++i)
|
|
|
|
ui.treeView->resizeColumnToContents(i);
|
2011-02-21 16:30:31 +01:00
|
|
|
|
|
|
|
bool hasChildren = false;
|
|
|
|
const int rowCount = ui.treeView->model()->rowCount();
|
2011-05-31 17:11:42 +02:00
|
|
|
for (int row = 0; row < rowCount && !hasChildren; ++row)
|
|
|
|
hasChildren = ui.treeView->model()->hasChildren(ui.treeView->model()->index(row, 0));
|
|
|
|
ui.treeView->setRootIsDecorated(hasChildren);
|
|
|
|
ui.treeView->expandToDepth(0);
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-05-31 17:11:42 +02:00
|
|
|
ComponentSelectionDialog *const q;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
Ui::ComponentSelectionDialog ui;
|
2011-06-14 16:24:50 +02:00
|
|
|
PackageManagerCore *const m_core;
|
2011-05-31 17:11:42 +02:00
|
|
|
ComponentModel *componentModel;
|
|
|
|
QPushButton *installBtn;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void selectAll();
|
|
|
|
void deselectAll();
|
|
|
|
};
|
|
|
|
|
|
|
|
void ComponentSelectionDialog::Private::selectAll()
|
|
|
|
{
|
2011-06-01 14:55:19 +02:00
|
|
|
componentModel->selectAll();
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentSelectionDialog::Private::deselectAll()
|
|
|
|
{
|
2011-06-01 14:55:19 +02:00
|
|
|
componentModel->deselectAll();
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-31 17:11:42 +02:00
|
|
|
// -- ComponentSelectionDialog
|
|
|
|
|
2011-06-14 16:24:50 +02:00
|
|
|
ComponentSelectionDialog::ComponentSelectionDialog(PackageManagerCore *core, QWidget *parent)
|
2011-05-31 17:11:42 +02:00
|
|
|
: QDialog(parent),
|
2011-06-14 16:24:50 +02:00
|
|
|
d(new Private(this, core))
|
2011-02-21 16:30:31 +01:00
|
|
|
{
|
2011-05-31 17:11:42 +02:00
|
|
|
d->ui.setupUi(this);
|
2011-06-01 14:55:19 +02:00
|
|
|
d->ui.icon->setPixmap(windowIcon().pixmap(48, 48));
|
|
|
|
|
|
|
|
d->ui.splitter->setStretchFactor(0, 2);
|
|
|
|
d->ui.splitter->setStretchFactor(1, 1);
|
|
|
|
d->ui.splitter->setCollapsible(0, false);
|
|
|
|
|
2011-06-20 14:01:49 +02:00
|
|
|
d->componentModel = new ComponentModel(4, core);
|
2011-06-01 14:55:19 +02:00
|
|
|
d->componentModel->setHeaderData(0, Qt::Horizontal, tr("Name"));
|
|
|
|
d->componentModel->setHeaderData(1, Qt::Horizontal, tr("Installed Version"));
|
|
|
|
d->componentModel->setHeaderData(2, Qt::Horizontal, tr("New Version"));
|
|
|
|
d->componentModel->setHeaderData(3, Qt::Horizontal, tr("Size"));
|
|
|
|
|
2011-05-31 17:11:42 +02:00
|
|
|
d->ui.treeView->setModel(d->componentModel);
|
|
|
|
d->ui.treeView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
2011-06-01 14:55:19 +02:00
|
|
|
connect(d->ui.treeView->model(), SIGNAL(modelReset()), this, SLOT(modelReset()));
|
|
|
|
connect(d->ui.treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
|
|
|
this, SLOT(currentChanged(QModelIndex)));
|
|
|
|
|
|
|
|
d->ui.labelSubTitle->setAttribute(Qt::WA_MacSmallSize);
|
|
|
|
d->ui.labelLicenseBlurb->setAttribute(Qt::WA_MacSmallSize);
|
2011-05-31 17:11:42 +02:00
|
|
|
d->ui.textBrowser->setAttribute(Qt::WA_MacShowFocusRect, false);
|
2011-06-01 14:55:19 +02:00
|
|
|
|
2011-05-31 17:11:42 +02:00
|
|
|
d->installBtn = d->ui.buttonBox->addButton(tr("Install"), QDialogButtonBox::AcceptRole) ;
|
|
|
|
if (!d->ui.buttonBox->button(QDialogButtonBox::Cancel)->icon().isNull())
|
|
|
|
d->installBtn->setIcon(style()->standardIcon(QStyle::SP_DialogOkButton));
|
|
|
|
|
|
|
|
connect(d->installBtn, SIGNAL(clicked()), this, SIGNAL(requestUpdate()));
|
|
|
|
connect(d->ui.selectAll, SIGNAL(clicked()), d, SLOT(selectAll()), Qt::QueuedConnection);
|
|
|
|
connect(d->ui.deselectAll, SIGNAL(clicked()), d, SLOT(deselectAll()), Qt::QueuedConnection);
|
|
|
|
|
|
|
|
d->ui.treeView->header()->setStretchLastSection(true);
|
2011-06-01 14:55:19 +02:00
|
|
|
d->ui.treeView->setCurrentIndex(d->ui.treeView->model()->index(0, 0));
|
2011-05-31 17:11:42 +02:00
|
|
|
for (int i = 0; i < d->ui.treeView->model()->columnCount(); ++i)
|
|
|
|
d->ui.treeView->resizeColumnToContents(i);
|
2011-02-21 16:30:31 +01:00
|
|
|
d->modelReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
ComponentSelectionDialog::~ComponentSelectionDialog()
|
|
|
|
{
|
2011-05-24 23:15:05 +02:00
|
|
|
delete d;
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
|
2011-05-31 17:11:42 +02:00
|
|
|
void ComponentSelectionDialog::selectAll()
|
|
|
|
{
|
2011-02-21 16:30:31 +01:00
|
|
|
d->selectAll();
|
|
|
|
}
|
|
|
|
|
2011-05-31 17:11:42 +02:00
|
|
|
void ComponentSelectionDialog::deselectAll()
|
|
|
|
{
|
2011-02-21 16:30:31 +01:00
|
|
|
d->deselectAll();
|
|
|
|
}
|
|
|
|
|
2011-05-31 17:11:42 +02:00
|
|
|
void ComponentSelectionDialog::install()
|
|
|
|
{
|
2011-02-21 16:30:31 +01:00
|
|
|
emit requestUpdate();
|
|
|
|
}
|
|
|
|
|
2011-06-01 14:55:19 +02:00
|
|
|
void ComponentSelectionDialog::selectComponent(const QString &id)
|
2011-05-31 17:11:42 +02:00
|
|
|
{
|
|
|
|
const QModelIndex &idx = d->componentModel->indexFromComponentName(id);
|
|
|
|
if (!idx.isValid())
|
2011-02-21 16:30:31 +01:00
|
|
|
return;
|
2011-06-01 14:55:19 +02:00
|
|
|
d->componentModel->setData(idx, Qt::Checked, Qt::CheckStateRole);
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
|
2011-06-01 14:55:19 +02:00
|
|
|
void ComponentSelectionDialog::deselectComponent(const QString &id)
|
2011-05-31 17:11:42 +02:00
|
|
|
{
|
|
|
|
const QModelIndex &idx = d->componentModel->indexFromComponentName(id);
|
|
|
|
if (!idx.isValid())
|
2011-02-21 16:30:31 +01:00
|
|
|
return;
|
2011-06-01 14:55:19 +02:00
|
|
|
d->componentModel->setData(idx, Qt::Unchecked, Qt::CheckStateRole);
|
2011-05-24 23:15:05 +02:00
|
|
|
}
|
|
|
|
|
2011-02-21 16:30:31 +01:00
|
|
|
#include "moc_componentselectiondialog.cpp"
|
|
|
|
#include "componentselectiondialog.moc"
|