1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*
This class provides the basic network item for the core library of
Smb4K.
SPDX-FileCopyrightText: 2009-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
SPDX-License-Identifier: GPL-2.0-or-later
*/
// application specific includes
#include "smb4kbasicnetworkitem.h"
// Qt includes
#include <QDebug>
#include <QtGlobal>
using namespace Smb4KGlobal;
class Smb4KBasicNetworkItemPrivate
{
public:
NetworkItem type;
QIcon icon;
QUrl url;
bool dnsDiscovered;
QString comment;
};
Smb4KBasicNetworkItem::Smb4KBasicNetworkItem(NetworkItem type)
: d(new Smb4KBasicNetworkItemPrivate)
{
d->type = type;
d->dnsDiscovered = false;
pUrl = &d->url;
pIcon = &d->icon;
pComment = &d->comment;
pType = &d->type;
}
Smb4KBasicNetworkItem::Smb4KBasicNetworkItem(const Smb4KBasicNetworkItem &item)
: d(new Smb4KBasicNetworkItemPrivate)
{
*d = *item.d;
pUrl = &d->url;
pIcon = &d->icon;
pComment = &d->comment;
pType = &d->type;
}
Smb4KBasicNetworkItem::~Smb4KBasicNetworkItem()
{
}
void Smb4KBasicNetworkItem::setType(Smb4KGlobal::NetworkItem type) const
{
d->type = type;
}
Smb4KGlobal::NetworkItem Smb4KBasicNetworkItem::type() const
{
return d->type;
}
void Smb4KBasicNetworkItem::setIcon(const QIcon &icon) const
{
d->icon = icon;
}
QIcon Smb4KBasicNetworkItem::icon() const
{
return d->icon;
}
void Smb4KBasicNetworkItem::setUrl(const QUrl &url) const
{
//
// Check that the URL is valid
//
if (!url.isValid()) {
return;
}
//
// Do some checks depending on the type of the network item
//
switch (d->type) {
case Network: {
break;
}
case Workgroup:
case Host: {
//
// Check that the host name is present and there is no path
//
if (url.host().isEmpty() || !url.path().isEmpty()) {
return;
}
break;
}
case Share: {
//
// Check that the share name is present
//
if (url.path().isEmpty() || (url.path().size() == 1 && url.path().endsWith(QStringLiteral("/")))) {
return;
}
break;
}
default: {
break;
}
}
d->url = url;
d->url.setScheme(QStringLiteral("smb"));
}
QUrl Smb4KBasicNetworkItem::url() const
{
return d->url;
}
void Smb4KBasicNetworkItem::setDnsDiscovered(bool discovered) const
{
d->dnsDiscovered = discovered;
}
bool Smb4KBasicNetworkItem::dnsDiscovered() const
{
return d->dnsDiscovered;
}
void Smb4KBasicNetworkItem::setComment(const QString &comment) const
{
d->comment = comment;
}
QString Smb4KBasicNetworkItem::comment() const
{
return d->comment;
}
bool Smb4KBasicNetworkItem::hasUserInfo() const
{
return !d->url.userInfo().isEmpty();
}
Smb4KBasicNetworkItem &Smb4KBasicNetworkItem::operator=(const Smb4KBasicNetworkItem &other)
{
*d = *other.d;
return *this;
}
|