File indexing completed on 2022-09-27 16:24:39

0001 /***************************************************************************
0002  *   Copyright (C) 2008-2011 by Daniel Nicoletti                           *
0003  *   dantti12@gmail.com                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; see the file COPYING. If not, write to       *
0017  *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
0018  *   Boston, MA 02110-1301, USA.                                           *
0019  ***************************************************************************/
0020 
0021 #include "ReviewChanges.h"
0022 #include "ui_ReviewChanges.h"
0023 
0024 #include <PackageModel.h>
0025 #include <ChangesDelegate.h>
0026 #include <KLocalizedString>
0027 
0028 #include <KCategorizedSortFilterProxyModel>
0029 
0030 #include <QLoggingCategory>
0031 
0032 ReviewChanges::ReviewChanges(PackageModel *model, QWidget *parent) :
0033     QWidget(parent),
0034     ui(new Ui::ReviewChanges),
0035     m_model(model)
0036 {
0037     ui->setupUi(this);
0038 
0039 
0040     //initialize the model, delegate, client and  connect it's signals
0041     ui->packageView->viewport()->setAttribute(Qt::WA_Hover);
0042     auto changedProxy = new KCategorizedSortFilterProxyModel(this);
0043     changedProxy->setSourceModel(m_model);
0044     changedProxy->setCategorizedModel(true);
0045     changedProxy->sort(0);
0046     changedProxy->setDynamicSortFilter(true);
0047     changedProxy->setSortCaseSensitivity(Qt::CaseInsensitive);
0048     changedProxy->setSortRole(PackageModel::SortRole);
0049     ui->packageView->setModel(changedProxy);
0050 
0051     setWindowTitle(i18np("The following package was found",
0052                          "The following packages were found",
0053                          m_model->rowCount()));
0054 
0055     auto delegate = new ChangesDelegate(ui->packageView);
0056     delegate->setExtendPixmapWidth(0);
0057     ui->packageView->setItemDelegate(delegate);
0058 
0059     connect(m_model, &PackageModel::dataChanged, this, &ReviewChanges::selectionChanged);
0060 }
0061 
0062 ReviewChanges::~ReviewChanges()
0063 {
0064     delete ui;
0065 }
0066 
0067 PackageModel *ReviewChanges::model() const
0068 {
0069     return m_model;
0070 }
0071 
0072 void ReviewChanges::selectionChanged()
0073 {
0074     emit hasSelectedPackages(!m_model->selectedPackagesToInstall().isEmpty() ||
0075                              !m_model->selectedPackagesToRemove().isEmpty());
0076 }
0077 
0078 #include "moc_ReviewChanges.cpp"