File indexing completed on 2024-03-24 16:27:20
0001 /*************************************************************************** 0002 Smb4K's container class for information about a directory or file. 0003 ------------------- 0004 begin : Sa Nov 10 2018 0005 copyright : (C) 2018-2019 by Alexander Reinholdt 0006 email : alexander.reinholdt@kdemail.net 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * This program is free software; you can redistribute it and/or modify * 0011 * it under the terms of the GNU General Public License as published by * 0012 * the Free Software Foundation; either version 2 of the License, or * 0013 * (at your option) any later version. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, but * 0016 * WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0018 * General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program; if not, write to the * 0022 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* 0023 * MA 02110-1335, USA * 0024 ***************************************************************************/ 0025 0026 #ifdef HAVE_CONFIG_H 0027 #include <config.h> 0028 #endif 0029 0030 // application specific includes 0031 #include "smb4kfile.h" 0032 #include "smb4kglobal.h" 0033 0034 // Qt includes 0035 #include <QDebug> 0036 #include <QDir> 0037 0038 // KDE includes 0039 #include <KIconThemes/KIconLoader> 0040 #include <KIO/Global> 0041 0042 using namespace Smb4KGlobal; 0043 0044 0045 class Smb4KFilePrivate 0046 { 0047 public: 0048 QString workgroupName; 0049 QHostAddress ip; 0050 }; 0051 0052 0053 Smb4KFile::Smb4KFile(const QUrl& url, Smb4KGlobal::NetworkItem type) 0054 : Smb4KBasicNetworkItem(type), d(new Smb4KFilePrivate) 0055 { 0056 *pUrl = url; 0057 0058 if (type == Directory) 0059 { 0060 *pIcon = KDE::icon("folder"); 0061 } 0062 else 0063 { 0064 *pIcon = KDE::icon(KIO::iconNameForUrl(url)); 0065 } 0066 } 0067 0068 0069 Smb4KFile::Smb4KFile(const Smb4KFile &file) 0070 : Smb4KBasicNetworkItem(file.type()), d(new Smb4KFilePrivate) 0071 { 0072 *d = *file.d; 0073 } 0074 0075 0076 Smb4KFile::~Smb4KFile() 0077 { 0078 } 0079 0080 0081 void Smb4KFile::setWorkgroupName(const QString &name) 0082 { 0083 d->workgroupName = name; 0084 } 0085 0086 0087 QString Smb4KFile::workgroupName() const 0088 { 0089 return d->workgroupName; 0090 } 0091 0092 0093 QString Smb4KFile::hostName() const 0094 { 0095 return pUrl->host().toUpper(); 0096 } 0097 0098 0099 void Smb4KFile::setHostIpAddress(const QHostAddress &address) 0100 { 0101 if (!address.isNull() && address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol) 0102 { 0103 d->ip = address; 0104 } 0105 } 0106 0107 0108 QString Smb4KFile::hostIpAddress() const 0109 { 0110 return d->ip.toString(); 0111 } 0112 0113 0114 bool Smb4KFile::hasHostIpAddress() const 0115 { 0116 return !d->ip.isNull(); 0117 } 0118 0119 0120 QString Smb4KFile::shareName() const 0121 { 0122 return pUrl->path().section('/', 1, 1); 0123 } 0124 0125 0126 void Smb4KFile::setLogin(const QString &name) 0127 { 0128 pUrl->setUserName(name); 0129 } 0130 0131 0132 QString Smb4KFile::login() const 0133 { 0134 return pUrl->userName(); 0135 } 0136 0137 0138 void Smb4KFile::setPassword(const QString &pass) 0139 { 0140 pUrl->setPassword(pass); 0141 } 0142 0143 0144 QString Smb4KFile::password() const 0145 { 0146 return pUrl->password(); 0147 } 0148 0149 0150 bool Smb4KFile::isDirectory() const 0151 { 0152 return (type() == Directory); 0153 } 0154 0155 0156 QString Smb4KFile::name() const 0157 { 0158 QString name; 0159 0160 switch (type()) 0161 { 0162 case Directory: 0163 { 0164 name = pUrl->path().section(QDir::separator(), -1, -1); 0165 break; 0166 } 0167 case File: 0168 { 0169 name = pUrl->fileName(); 0170 break; 0171 } 0172 default: 0173 { 0174 break; 0175 } 0176 } 0177 0178 return name; 0179 } 0180 0181 0182 bool Smb4KFile::isHidden() const 0183 { 0184 return name().startsWith('.'); 0185 } 0186