File indexing completed on 2024-04-14 04:56:24
0001 /* 0002 Smb4K's container class for information about a directory or file. 0003 0004 SPDX-FileCopyrightText: 2018-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 // application specific includes 0009 #include "smb4kfile.h" 0010 #include "smb4kglobal.h" 0011 0012 // Qt includes 0013 #include <QDebug> 0014 #include <QDir> 0015 0016 // KDE includes 0017 #include <KIO/Global> 0018 #include <KIconLoader> 0019 0020 using namespace Smb4KGlobal; 0021 0022 class Smb4KFilePrivate 0023 { 0024 public: 0025 QString workgroupName; 0026 QHostAddress ip; 0027 bool isDirectory; 0028 }; 0029 0030 Smb4KFile::Smb4KFile(const QUrl &url) 0031 : Smb4KBasicNetworkItem(Smb4KGlobal::FileOrDirectory) 0032 , d(new Smb4KFilePrivate) 0033 { 0034 *pUrl = url; 0035 *pIcon = KDE::icon(KIO::iconNameForUrl(url)); 0036 d->isDirectory = false; 0037 } 0038 0039 Smb4KFile::Smb4KFile(const Smb4KFile &file) 0040 : Smb4KBasicNetworkItem(file) 0041 , d(new Smb4KFilePrivate) 0042 { 0043 *d = *file.d; 0044 } 0045 0046 Smb4KFile::Smb4KFile() 0047 : Smb4KBasicNetworkItem(Smb4KGlobal::FileOrDirectory) 0048 , d(new Smb4KFilePrivate) 0049 { 0050 d->isDirectory = false; 0051 } 0052 0053 Smb4KFile::~Smb4KFile() 0054 { 0055 } 0056 0057 void Smb4KFile::setWorkgroupName(const QString &name) const 0058 { 0059 d->workgroupName = name; 0060 } 0061 0062 QString Smb4KFile::workgroupName() const 0063 { 0064 return d->workgroupName; 0065 } 0066 0067 QString Smb4KFile::hostName() const 0068 { 0069 return pUrl->host().toUpper(); 0070 } 0071 0072 void Smb4KFile::setHostIpAddress(const QHostAddress &address) const 0073 { 0074 if (!address.isNull() && address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol) { 0075 d->ip = address; 0076 } 0077 } 0078 0079 QString Smb4KFile::hostIpAddress() const 0080 { 0081 return d->ip.toString(); 0082 } 0083 0084 bool Smb4KFile::hasHostIpAddress() const 0085 { 0086 return !d->ip.isNull(); 0087 } 0088 0089 QString Smb4KFile::shareName() const 0090 { 0091 return pUrl->path().section(QStringLiteral("/"), 1, 1); 0092 } 0093 0094 void Smb4KFile::setUserName(const QString &name) const 0095 { 0096 pUrl->setUserName(name); 0097 } 0098 0099 QString Smb4KFile::userName() const 0100 { 0101 return pUrl->userName(); 0102 } 0103 0104 void Smb4KFile::setPassword(const QString &pass) const 0105 { 0106 pUrl->setPassword(pass); 0107 } 0108 0109 QString Smb4KFile::password() const 0110 { 0111 return pUrl->password(); 0112 } 0113 0114 void Smb4KFile::setDirectory(bool directory) const 0115 { 0116 d->isDirectory = directory; 0117 *pIcon = KDE::icon(QStringLiteral("folder")); 0118 } 0119 0120 bool Smb4KFile::isDirectory() const 0121 { 0122 return d->isDirectory; 0123 } 0124 0125 QString Smb4KFile::name() const 0126 { 0127 QString name; 0128 0129 if (d->isDirectory) { 0130 name = pUrl->path().section(QDir::separator(), -1, -1); 0131 } else { 0132 name = pUrl->fileName(); 0133 } 0134 0135 return name; 0136 } 0137 0138 bool Smb4KFile::isHidden() const 0139 { 0140 return name().startsWith(QStringLiteral(".")); 0141 } 0142 0143 Smb4KFile &Smb4KFile::operator=(const Smb4KFile &other) 0144 { 0145 *d = *other.d; 0146 return *this; 0147 }