[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kcm-grub2/frameworks] /: Port QApt2Backend to QApt 3
From:       Alexander Volkov <null () kde ! org>
Date:       2018-05-11 16:44:08
Message-ID: E1fHB9M-00065t-Pz () code ! kde ! org
[Download RAW message or body]

Git commit 70d54cd5a00fbeca2cedd1b5fab4c280f97fcde1 by Alexander Volkov.
Committed on 11/05/2018 at 19:32.
Pushed by volkov into branch 'frameworks'.

Port QApt2Backend to QApt 3

Drop QAptBackend and rename QApt2Backend to QAptBackend.
Fix includes to build it with QApt 3.

M  +2    -2    CMakeLists.txt
D  +0    -76   cmake/modules/FindQApt.cmake
M  +0    -1    config.h.cmake
M  +2    -9    src/CMakeLists.txt
D  +0    -78   src/qapt2Backend.cpp
D  +0    -52   src/qapt2Backend.h
M  +11   -15   src/qaptBackend.cpp
M  +6    -4    src/qaptBackend.h
M  +0    -4    src/removeDlg.cpp
M  +0    -8    src/removeDlg.h

https://commits.kde.org/kcm-grub2/70d54cd5a00fbeca2cedd1b5fab4c280f97fcde1

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3060d1..e28ca6c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,12 +57,12 @@ else()
     set(HAVE_HD 0)
 endif()
 
-find_package(QApt)
+find_package(QApt 3.0.0)
 set_package_properties(QApt PROPERTIES
                        DESCRIPTION "Remove unneeded old entries (qapt backend)"
                        URL \
"https://projects.kde.org/projects/extragear/sysadmin/libqapt/"  TYPE OPTIONAL)
-if(QAPT_FOUND)
+if(QApt_FOUND)
     set(HAVE_QAPT 1)
 else()
     set(HAVE_QAPT 0)
diff --git a/cmake/modules/FindQApt.cmake b/cmake/modules/FindQApt.cmake
deleted file mode 100644
index 9d562aa..0000000
--- a/cmake/modules/FindQApt.cmake
+++ /dev/null
@@ -1,76 +0,0 @@
-# - Try to find QAPT
-# Once done this will define
-#
-#  QAPT_FOUND - system has QApt
-#  QAPT_INCLUDE_DIR - the QApt include directory
-#  QAPT_LIBRARIES - Link these to use all QApt libs
-#  QAPT_DEFINITIONS - Compiler switches required for using QApt
-
-# Copyright (c) 2009, Dario Freddi, <drf@kde.org>
-#
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
-
-if (QAPT_INCLUDE_DIR AND QAPT_LIB)
-    set(QAPT_FIND_QUIETLY TRUE)
-endif (QAPT_INCLUDE_DIR AND QAPT_LIB)
-
-if (NOT QAPT_MIN_VERSION)
-  set(QAPT_MIN_VERSION "0.1.0")
-endif (NOT QAPT_MIN_VERSION)
-
-if (NOT WIN32)
-   # use pkg-config to get the directories and then use these values
-   # in the FIND_PATH() and FIND_LIBRARY() calls
-   find_package(PkgConfig REQUIRED)
-   pkg_check_modules(PC_QAPT libqapt)
-   if(${PC_QAPT_FOUND})
-       set(QAPT_DEFINITIONS ${PC_QAPT_CFLAGS_OTHER})
-       string(REGEX MATCH "^[0-9]+" QAPT_VERSION_MAJOR ${PC_QAPT_VERSION})
-   endif(${PC_QAPT_FOUND})
-endif (NOT WIN32)
-
-find_path( QAPT_INCLUDE_DIR
-     NAMES libqapt/qaptversion.h
-)
-
-set(QAPT_VERSION_OK TRUE)
-if(QAPT_INCLUDE_DIR)
-  file(READ ${QAPT_INCLUDE_DIR}/libqapt/qaptversion.h QAPT_VERSION_CONTENT)
-  string (REGEX MATCH "QAPT_VERSION_STRING \".*\"\n" QAPT_VERSION_MATCH \
                "${QAPT_VERSION_CONTENT}")
-
-  if(QAPT_VERSION_MATCH)
-    string(REGEX REPLACE "QAPT_VERSION_STRING \"(.*)\"\n" "\\1" QAPT_VERSION \
                ${QAPT_VERSION_MATCH})
-    if(QAPT_VERSION STRLESS "${QAPT_MIN_VERSION}")
-      set(QAPT_VERSION_OK FALSE)
-      if(QAPT_FIND_REQUIRED)
-        message(FATAL_ERROR "QApt version ${QAPT_VERSION} was found, but it is too \
                old. Please install ${QAPT_MIN_VERSION} or
-newer.")
-      else(QAPT_FIND_REQUIRED)
-        message(STATUS "QApt version ${QAPT_VERSION} is too old. Please install \
                ${QAPT_MIN_VERSION} or newer.")
-      endif(QAPT_FIND_REQUIRED)
-    endif(QAPT_VERSION STRLESS "${QAPT_MIN_VERSION}")
-  endif(QAPT_VERSION_MATCH)
-elseif(QAPT_INCLUDE_DIR)
-  # The version is so old that it does not even have the file
-  set(QAPT_VERSION_OK FALSE)
-  if(QAPT_FIND_REQUIRED)
-    message(FATAL_ERROR "It looks like QApt is too old. Please install QApt version \
                ${QAPT_MIN_VERSION} or newer.")
-  else(QAPT_FIND_REQUIRED)
-    message(STATUS "It looks like QApt is too old. Please install QApt version \
                ${QAPT_MIN_VERSION} or newer.")
-  endif(QAPT_FIND_REQUIRED)
-endif(QAPT_INCLUDE_DIR)
-
-    find_library(QAPT_LIBRARY
-        NAMES qapt
-        HINTS ${PC_QAPT_LIBDIR} ${PC_QAPT_LIBRARY_DIRS}
-        )
-
-include(FindPackageHandleStandardArgs)
-
-# handle the QUIETLY and REQUIRED arguments and set QAPT_FOUND to TRUE if
-# all listed variables are TRUE
-find_package_handle_standard_args(QAPT DEFAULT_MSG QAPT_LIBRARY QAPT_INCLUDE_DIR \
                QAPT_VERSION_OK)
-
-mark_as_advanced(QAPT_INCLUDE_DIR QAPT_LIBRARY QAPT_VERSION_OK)
-
diff --git a/config.h.cmake b/config.h.cmake
index 25475af..84bb6ba 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -7,7 +7,6 @@
 #define HAVE_HD @HAVE_HD@
 #define HAVE_QAPT @HAVE_QAPT@
 #define HAVE_QPACKAGEKIT @HAVE_QPACKAGEKIT@
-#define QAPT_VERSION_MAJOR @QAPT_VERSION_MAJOR@
 
 //Qt
 #include <QFile>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index bc19f57..57f5a91 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -4,9 +4,6 @@ add_subdirectory(helper)
 if(HAVE_IMAGEMAGICK)
     set(kcm_grub2_INCLUDE_DIRS ${kcm_grub2_INCLUDE_DIRS} \
${ImageMagick_INCLUDE_DIRS})  endif(HAVE_IMAGEMAGICK)
-if(HAVE_QAPT)
-    set(kcm_grub2_INCLUDE_DIRS ${kcm_grub2_INCLUDE_DIRS} ${QAPT_INCLUDE_DIR})
-endif(HAVE_QAPT)
 
 # Set Sources
 set(kcm_grub2_SRCS common.cpp entry.cpp installDlg.cpp kcm_grub2.cpp \
textinputdialog.cpp) @@ -20,11 +17,7 @@ if(HAVE_QAPT OR HAVE_QPACKAGEKIT)
     qt5_wrap_ui(kcm_grub2_SRCS ../ui/removeDlg.ui)
 endif(HAVE_QAPT OR HAVE_QPACKAGEKIT)
 if(HAVE_QAPT)
-    if(QAPT_VERSION_MAJOR EQUAL 1)
-        set(kcm_grub2_SRCS ${kcm_grub2_SRCS} qaptBackend.cpp)
-    elseif(QAPT_VERSION_MAJOR EQUAL 2)
-        set(kcm_grub2_SRCS ${kcm_grub2_SRCS} qapt2Backend.cpp)
-    endif(QAPT_VERSION_MAJOR EQUAL 1)
+    set(kcm_grub2_SRCS ${kcm_grub2_SRCS} qaptBackend.cpp)
 elseif(HAVE_QPACKAGEKIT)
     set(kcm_grub2_SRCS ${kcm_grub2_SRCS} qPkBackend.cpp)
 endif(HAVE_QAPT)
@@ -34,7 +27,7 @@ if(HAVE_IMAGEMAGICK)
     set(kcm_grub2_LINK_LIBS ${kcm_grub2_LINK_LIBS} ${ImageMagick_LIBRARIES})
 endif(HAVE_IMAGEMAGICK)
 if(HAVE_QAPT)
-    set(kcm_grub2_LINK_LIBS ${kcm_grub2_LINK_LIBS} ${QAPT_LIBRARY})
+    set(kcm_grub2_LINK_LIBS ${kcm_grub2_LINK_LIBS} QApt::Main)
 elseif(HAVE_QPACKAGEKIT)
     set(kcm_grub2_LINK_LIBS ${kcm_grub2_LINK_LIBS} ${PackageKitQt5_LIBRARIES})
 endif(HAVE_QAPT)
diff --git a/src/qapt2Backend.cpp b/src/qapt2Backend.cpp
deleted file mode 100644
index 47cea04..0000000
--- a/src/qapt2Backend.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2008-2013 Konstantinos Smanis <konstantinos.smanis@gmail.com> *
- *                                                                             *
- * This program is free software: you can redistribute it and/or modify it     *
- * under the terms of the GNU General Public License as published by the Free  *
- * Software Foundation, either version 3 of the License, or (at your option)   *
- * any later version.                                                          *
- *                                                                             *
- * This program is distributed in the hope that it will be useful, but WITHOUT *
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
- * more details.                                                               *
- *                                                                             *
- * You should have received a copy of the GNU General Public License along     *
- * with this program. If not, see <http://www.gnu.org/licenses/>.              *
- *******************************************************************************/
-
-//Own
-#include "qapt2Backend.h"
-
-QApt2Backend::QApt2Backend(QObject *parent) : QObject(parent)
-{
-    m_backend = new QApt::Backend;
-    m_backend->init();
-    m_exitStatus = QApt::ExitSuccess;
-}
-QApt2Backend::~QApt2Backend()
-{
-    delete m_backend;
-}
-
-QStringList QApt2Backend::ownerPackage(const QString &fileName)
-{
-    QApt::Package *package;
-    return (package = m_backend->packageForFile(fileName)) ? QStringList() << \
                package->name() << package->version() : QStringList();
-}
-void QApt2Backend::markForRemoval(const QString &packageName)
-{
-    Q_FOREACH(const QApt::Package *package, m_backend->markedPackages()) {
-        if (packageName.compare(package->name()) == 0) {
-            return;
-        }
-    }
-    QApt::Package *package;
-    if ((package = m_backend->package(packageName))) {
-        package->setRemove();
-    }
-}
-QStringList QApt2Backend::markedForRemoval() const
-{
-    QStringList marked;
-    Q_FOREACH(const QApt::Package *package, m_backend->markedPackages()) {
-        marked.append(package->name());
-    }
-    return marked;
-}
-void QApt2Backend::removePackages()
-{
-    m_trans = m_backend->commitChanges();
-
-    connect(m_trans, SIGNAL(progressChanged(int)), this, \
                SLOT(slotUpdateProgress()));
-    connect(m_trans, SIGNAL(finished(QApt::ExitStatus)), this, \
                SLOT(slotTransactionFinished(QApt::ExitStatus)));
-    m_trans->run();
-}
-void QApt2Backend::undoChanges()
-{
-    m_backend->init();
-}
-
-void QApt2Backend::slotUpdateProgress()
-{
-    Q_EMIT progress(m_trans->statusDetails(), m_trans->progress());
-}
-void QApt2Backend::slotTransactionFinished(QApt::ExitStatus status)
-{
-    m_exitStatus = status;
-    Q_EMIT finished(status == QApt::ExitSuccess);
-}
diff --git a/src/qapt2Backend.h b/src/qapt2Backend.h
deleted file mode 100644
index bf39cff..0000000
--- a/src/qapt2Backend.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2008-2013 Konstantinos Smanis <konstantinos.smanis@gmail.com> *
- *                                                                             *
- * This program is free software: you can redistribute it and/or modify it     *
- * under the terms of the GNU General Public License as published by the Free  *
- * Software Foundation, either version 3 of the License, or (at your option)   *
- * any later version.                                                          *
- *                                                                             *
- * This program is distributed in the hope that it will be useful, but WITHOUT *
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
- * more details.                                                               *
- *                                                                             *
- * You should have received a copy of the GNU General Public License along     *
- * with this program. If not, see <http://www.gnu.org/licenses/>.              *
- *******************************************************************************/
-
-#ifndef QAPT2BACKEND_H
-#define QAPT2BACKEND_H
-
-//Qt
-#include <QStringList>
-
-//QApt
-#include <LibQApt/Backend>
-#include <LibQApt/Transaction>
-
-class QApt2Backend : public QObject
-{
-    Q_OBJECT
-public:
-    explicit QApt2Backend(QObject *parent = 0);
-    virtual ~QApt2Backend();
-
-    QStringList ownerPackage(const QString &fileName);
-    void markForRemoval(const QString &packageName);
-    QStringList markedForRemoval() const;
-    void removePackages();
-    void undoChanges();
-Q_SIGNALS:
-    void finished(bool success);
-    void progress(const QString &status, int percentage);
-private Q_SLOTS:
-    void slotUpdateProgress();
-    void slotTransactionFinished(QApt::ExitStatus status);
-private:
-    QApt::Backend *m_backend;
-    QApt::ExitStatus m_exitStatus;
-    QApt::Transaction *m_trans;
-};
-
-#endif
diff --git a/src/qaptBackend.cpp b/src/qaptBackend.cpp
index 6d9b6fe..d5d0f55 100644
--- a/src/qaptBackend.cpp
+++ b/src/qaptBackend.cpp
@@ -18,14 +18,11 @@
 //Own
 #include "qaptBackend.h"
 
-//Qt
-#include <QEventLoop>
-
 QAptBackend::QAptBackend(QObject *parent) : QObject(parent)
 {
     m_backend = new QApt::Backend;
     m_backend->init();
-    m_error = QApt::UnknownError;
+    m_exitStatus = QApt::ExitSuccess;
 }
 QAptBackend::~QAptBackend()
 {
@@ -59,24 +56,23 @@ QStringList QAptBackend::markedForRemoval() const
 }
 void QAptBackend::removePackages()
 {
-    connect(m_backend, SIGNAL(commitProgress(QString,int)), this, \
                SIGNAL(progress(QString,int)));
-    connect(m_backend, SIGNAL(workerEvent(QApt::WorkerEvent)), this, \
                SLOT(slotWorkerEvent(QApt::WorkerEvent)));
-    connect(m_backend, SIGNAL(errorOccurred(QApt::ErrorCode,QVariantMap)), this, \
                SLOT(slotErrorOccurred(QApt::ErrorCode,QVariantMap)));
-    m_backend->commitChanges();
+    m_trans = m_backend->commitChanges();
+
+    connect(m_trans, SIGNAL(progressChanged(int)), this, \
SLOT(slotUpdateProgress())); +    connect(m_trans, \
SIGNAL(finished(QApt::ExitStatus)), this, \
SLOT(slotTransactionFinished(QApt::ExitStatus))); +    m_trans->run();
 }
 void QAptBackend::undoChanges()
 {
     m_backend->init();
 }
 
-void QAptBackend::slotWorkerEvent(QApt::WorkerEvent event)
+void QAptBackend::slotUpdateProgress()
 {
-    if (event == QApt::CommitChangesFinished) {
-        Q_EMIT finished(m_error == QApt::UnknownError);
-    }
+    Q_EMIT progress(m_trans->statusDetails(), m_trans->progress());
 }
-void QAptBackend::slotErrorOccurred(QApt::ErrorCode error, const QVariantMap \
&details) +void QAptBackend::slotTransactionFinished(QApt::ExitStatus status)
 {
-    Q_UNUSED(details)
-    m_error = error;
+    m_exitStatus = status;
+    Q_EMIT finished(status == QApt::ExitSuccess);
 }
diff --git a/src/qaptBackend.h b/src/qaptBackend.h
index 3aff49e..90e92f6 100644
--- a/src/qaptBackend.h
+++ b/src/qaptBackend.h
@@ -22,7 +22,8 @@
 #include <QStringList>
 
 //QApt
-#include <libqapt/backend.h>
+#include <QApt/Backend>
+#include <QApt/Transaction>
 
 class QAptBackend : public QObject
 {
@@ -40,11 +41,12 @@ Q_SIGNALS:
     void finished(bool success);
     void progress(const QString &status, int percentage);
 private Q_SLOTS:
-    void slotWorkerEvent(QApt::WorkerEvent event);
-    void slotErrorOccurred(QApt::ErrorCode error, const QVariantMap &details);
+    void slotUpdateProgress();
+    void slotTransactionFinished(QApt::ExitStatus status);
 private:
     QApt::Backend *m_backend;
-    QApt::ErrorCode m_error;
+    QApt::ExitStatus m_exitStatus;
+    QApt::Transaction *m_trans;
 };
 
 #endif
diff --git a/src/removeDlg.cpp b/src/removeDlg.cpp
index 23f1247..7be8301 100644
--- a/src/removeDlg.cpp
+++ b/src/removeDlg.cpp
@@ -63,11 +63,7 @@ RemoveDialog::RemoveDialog(const QList<Entry> &entries, QWidget \
*parent) : QDial  m_progressDlg = 0;
 
 #if HAVE_QAPT
-#if QAPT_VERSION_MAJOR == 1
     m_backend = new QAptBackend;
-#elif QAPT_VERSION_MAJOR == 2
-    m_backend = new QApt2Backend;
-#endif
 #elif HAVE_QPACKAGEKIT
     m_backend = new QPkBackend;
 #endif
diff --git a/src/removeDlg.h b/src/removeDlg.h
index bdb3b51..5af9c3c 100644
--- a/src/removeDlg.h
+++ b/src/removeDlg.h
@@ -29,11 +29,7 @@ class QProgressDialog;
 #include <config.h>
 class Entry;
 #if HAVE_QAPT
-#if QAPT_VERSION_MAJOR == 1
 #include "qaptBackend.h"
-#elif QAPT_VERSION_MAJOR == 2
-#include "qapt2Backend.h"
-#endif
 #elif HAVE_QPACKAGEKIT
 #include "qPkBackend.h"
 #endif
@@ -59,11 +55,7 @@ private:
     void detectCurrentKernelImage();
 
 #if HAVE_QAPT
-#if QAPT_VERSION_MAJOR == 1
     QAptBackend *m_backend;
-#elif QAPT_VERSION_MAJOR == 2
-    QApt2Backend *m_backend;
-#endif
 #elif HAVE_QPACKAGEKIT
     QPkBackend *m_backend;
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic