File indexing completed on 2024-05-05 17:33:22

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 #include "libdiscover_debug.h"
0009 
0010 AddonList::AddonList()
0011 {
0012 }
0013 
0014 bool AddonList::isEmpty() const
0015 {
0016     return m_toInstall.isEmpty() && m_toRemove.isEmpty();
0017 }
0018 
0019 QStringList AddonList::addonsToInstall() const
0020 {
0021     return m_toInstall;
0022 }
0023 
0024 QStringList AddonList::addonsToRemove() const
0025 {
0026     return m_toRemove;
0027 }
0028 
0029 void AddonList::addAddon(const QString &addon, bool toInstall)
0030 {
0031     if (toInstall) {
0032         m_toInstall.append(addon);
0033         m_toRemove.removeAll(addon);
0034     } else {
0035         m_toInstall.removeAll(addon);
0036         m_toRemove.append(addon);
0037     }
0038 }
0039 
0040 void AddonList::resetAddon(const QString &addon)
0041 {
0042     m_toInstall.removeAll(addon);
0043     m_toRemove.removeAll(addon);
0044 }
0045 
0046 void AddonList::clear()
0047 {
0048     m_toInstall.clear();
0049     m_toRemove.clear();
0050 }
0051 
0052 AddonList::State AddonList::addonState(const QString &addonName) const
0053 {
0054     if (m_toInstall.contains(addonName))
0055         return ToInstall;
0056     else if (m_toRemove.contains(addonName))
0057         return ToRemove;
0058     else
0059         return None;
0060 }
0061 
0062 QDebug operator<<(QDebug debug, const AddonList &addons)
0063 {
0064     QDebugStateSaver saver(debug);
0065     debug.nospace() << "AddonsList(";
0066     debug.nospace() << "install:" << addons.addonsToInstall() << ',';
0067     debug.nospace() << "remove:" << addons.addonsToRemove() << ',';
0068     debug.nospace() << ')';
0069     return debug;
0070 }