File indexing completed on 2024-05-12 05:29:05

0001 /*
0002  *   SPDX-FileCopyrightText: 2012 Jonathan Thomas <echidnaman@kubuntu.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include "AddonList.h"
0008 
0009 #include <QDebug>
0010 
0011 AddonList::AddonList()
0012 {
0013 }
0014 
0015 bool AddonList::isEmpty() const
0016 {
0017     return m_toInstall.isEmpty() && m_toRemove.isEmpty();
0018 }
0019 
0020 QStringList AddonList::addonsToInstall() const
0021 {
0022     return m_toInstall;
0023 }
0024 
0025 QStringList AddonList::addonsToRemove() const
0026 {
0027     return m_toRemove;
0028 }
0029 
0030 void AddonList::addAddon(const QString &addon, bool toInstall)
0031 {
0032     if (toInstall) {
0033         m_toInstall.append(addon);
0034         m_toRemove.removeAll(addon);
0035     } else {
0036         m_toInstall.removeAll(addon);
0037         m_toRemove.append(addon);
0038     }
0039 }
0040 
0041 void AddonList::resetAddon(const QString &addon)
0042 {
0043     m_toInstall.removeAll(addon);
0044     m_toRemove.removeAll(addon);
0045 }
0046 
0047 void AddonList::clear()
0048 {
0049     m_toInstall.clear();
0050     m_toRemove.clear();
0051 }
0052 
0053 AddonList::State AddonList::addonState(const QString &addonName) const
0054 {
0055     if (m_toInstall.contains(addonName)) {
0056         return ToInstall;
0057     } else if (m_toRemove.contains(addonName)) {
0058         return ToRemove;
0059     } else {
0060         return None;
0061     }
0062 }
0063 
0064 QDebug operator<<(QDebug debug, const AddonList &addons)
0065 {
0066     QDebugStateSaver saver(debug);
0067     debug.nospace() << "AddonsList(";
0068     debug.nospace() << "install:" << addons.addonsToInstall() << ',';
0069     debug.nospace() << "remove:" << addons.addonsToRemove() << ')';
0070     return debug;
0071 }