File indexing completed on 2024-04-21 05:45:48

0001 /*******************************************************************************
0002  * Copyright (C) 2008-2013 Konstantinos Smanis <konstantinos.smanis@gmail.com> *
0003  *                                                                             *
0004  * This program is free software: you can redistribute it and/or modify it     *
0005  * under the terms of the GNU General Public License as published by the Free  *
0006  * Software Foundation, either version 3 of the License, or (at your option)   *
0007  * any later version.                                                          *
0008  *                                                                             *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT *
0010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
0011  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
0012  * more details.                                                               *
0013  *                                                                             *
0014  * You should have received a copy of the GNU General Public License along     *
0015  * with this program. If not, see <http://www.gnu.org/licenses/>.              *
0016  *******************************************************************************/
0017 
0018 //Own
0019 #include "qaptBackend.h"
0020 
0021 QAptBackend::QAptBackend(QObject *parent) : QObject(parent)
0022 {
0023     m_backend = new QApt::Backend;
0024     m_backend->init();
0025     m_exitStatus = QApt::ExitSuccess;
0026 }
0027 QAptBackend::~QAptBackend()
0028 {
0029     delete m_backend;
0030 }
0031 
0032 QStringList QAptBackend::ownerPackage(const QString &fileName)
0033 {
0034     QApt::Package *package;
0035     return (package = m_backend->packageForFile(fileName)) ? QStringList() << package->name() << package->version() : QStringList();
0036 }
0037 void QAptBackend::markForRemoval(const QString &packageName)
0038 {
0039     const auto markedPackages = m_backend->markedPackages();
0040     for (const QApt::Package *package : markedPackages) {
0041         if (packageName.compare(package->name()) == 0) {
0042             return;
0043         }
0044     }
0045     QApt::Package *package;
0046     if ((package = m_backend->package(packageName))) {
0047         package->setRemove();
0048     }
0049 }
0050 QStringList QAptBackend::markedForRemoval() const
0051 {
0052     QStringList marked;
0053     const auto markedPackages = m_backend->markedPackages();
0054     for (const QApt::Package *package : markedPackages) {
0055         marked.append(package->name());
0056     }
0057     return marked;
0058 }
0059 void QAptBackend::removePackages()
0060 {
0061     m_trans = m_backend->commitChanges();
0062 
0063     connect(m_trans, SIGNAL(progressChanged(int)), this, SLOT(slotUpdateProgress()));
0064     connect(m_trans, SIGNAL(finished(QApt::ExitStatus)), this, SLOT(slotTransactionFinished(QApt::ExitStatus)));
0065     m_trans->run();
0066 }
0067 void QAptBackend::undoChanges()
0068 {
0069     m_backend->init();
0070 }
0071 
0072 void QAptBackend::slotUpdateProgress()
0073 {
0074     Q_EMIT progress(m_trans->statusDetails(), m_trans->progress());
0075 }
0076 void QAptBackend::slotTransactionFinished(QApt::ExitStatus status)
0077 {
0078     m_exitStatus = status;
0079     Q_EMIT finished(status == QApt::ExitSuccess);
0080 }