File indexing completed on 2023-11-26 08:54:34

0001 /*
0002     SPDX-FileCopyrightText: 2013-2018 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "networkitemslist.h"
0008 #include "networkmodelitem.h"
0009 
0010 NetworkItemsList::NetworkItemsList(QObject *parent)
0011     : QObject(parent)
0012 {
0013 }
0014 
0015 NetworkItemsList::~NetworkItemsList()
0016 {
0017     qDeleteAll(m_items);
0018 }
0019 
0020 bool NetworkItemsList::contains(const NetworkItemsList::FilterType type, const QString &parameter) const
0021 {
0022     for (NetworkModelItem *item : m_items) {
0023         switch (type) {
0024         case NetworkItemsList::ActiveConnection:
0025             if (item->activeConnectionPath() == parameter) {
0026                 return true;
0027             }
0028             break;
0029         case NetworkItemsList::Connection:
0030             if (item->connectionPath() == parameter) {
0031                 return true;
0032             }
0033             break;
0034         case NetworkItemsList::Device:
0035             if (item->devicePath() == parameter) {
0036                 return true;
0037             }
0038             break;
0039         case NetworkItemsList::Name:
0040             if (item->name() == parameter) {
0041                 return true;
0042             }
0043             break;
0044         case NetworkItemsList::Ssid:
0045             if (item->ssid() == parameter) {
0046                 return true;
0047             }
0048             break;
0049         case NetworkItemsList::Uuid:
0050             if (item->uuid() == parameter) {
0051                 return true;
0052             }
0053             break;
0054         case NetworkItemsList::Type:
0055             break;
0056         default:
0057             break;
0058         }
0059     }
0060 
0061     return false;
0062 }
0063 
0064 int NetworkItemsList::count() const
0065 {
0066     return m_items.count();
0067 }
0068 
0069 int NetworkItemsList::indexOf(NetworkModelItem *item) const
0070 {
0071     return m_items.indexOf(item);
0072 }
0073 
0074 void NetworkItemsList::insertItem(NetworkModelItem *item)
0075 {
0076     m_items << item;
0077 }
0078 
0079 NetworkModelItem *NetworkItemsList::itemAt(int index) const
0080 {
0081     return m_items.at(index);
0082 }
0083 
0084 QList<NetworkModelItem *> NetworkItemsList::items() const
0085 {
0086     return m_items;
0087 }
0088 
0089 void NetworkItemsList::removeItem(NetworkModelItem *item)
0090 {
0091     m_items.removeAll(item);
0092 }
0093 
0094 QList<NetworkModelItem *>
0095 NetworkItemsList::returnItems(const NetworkItemsList::FilterType type, const QString &parameter, const QString &additionalParameter) const
0096 {
0097     QList<NetworkModelItem *> result;
0098 
0099     for (NetworkModelItem *item : m_items) {
0100         switch (type) {
0101         case NetworkItemsList::ActiveConnection:
0102             if (item->activeConnectionPath() == parameter) {
0103                 result << item;
0104             }
0105             break;
0106         case NetworkItemsList::Connection:
0107             if (item->connectionPath() == parameter) {
0108                 if (additionalParameter.isEmpty()) {
0109                     result << item;
0110                 } else {
0111                     if (item->devicePath() == additionalParameter) {
0112                         result << item;
0113                     }
0114                 }
0115             }
0116             break;
0117         case NetworkItemsList::Device:
0118             if (item->devicePath() == parameter) {
0119                 result << item;
0120             }
0121             break;
0122         case NetworkItemsList::Name:
0123             if (item->name() == parameter) {
0124                 result << item;
0125             }
0126             break;
0127         case NetworkItemsList::Ssid:
0128             if (item->ssid() == parameter) {
0129                 if (additionalParameter.isEmpty()) {
0130                     result << item;
0131                 } else {
0132                     if (item->devicePath() == additionalParameter) {
0133                         result << item;
0134                     }
0135                 }
0136             }
0137             break;
0138         case NetworkItemsList::Uuid:
0139             if (item->uuid() == parameter) {
0140                 result << item;
0141             }
0142             break;
0143         case NetworkItemsList::Type:
0144             break;
0145         }
0146     }
0147 
0148     return result;
0149 }
0150 
0151 QList<NetworkModelItem *> NetworkItemsList::returnItems(const NetworkItemsList::FilterType type,
0152                                                         NetworkManager::ConnectionSettings::ConnectionType typeParameter) const
0153 {
0154     QList<NetworkModelItem *> result;
0155 
0156     for (NetworkModelItem *item : m_items) {
0157         if (type == NetworkItemsList::Type) {
0158             if (item->type() == typeParameter) {
0159                 result << item;
0160             }
0161         }
0162     }
0163     return result;
0164 }