File indexing completed on 2024-04-14 15:05:32
0001 /*************************************************************************** 0002 Smb4K's container class for information about a workgroup. 0003 ------------------- 0004 begin : Sa Jan 26 2008 0005 copyright : (C) 2008-2017 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 "smb4kworkgroup.h" 0032 #include "smb4kglobal.h" 0033 0034 // Qt includes 0035 #include <QAbstractSocket> 0036 #include <QUrl> 0037 0038 // KDE includes 0039 #include <KIconThemes/KIconLoader> 0040 0041 using namespace Smb4KGlobal; 0042 0043 class Smb4KWorkgroupPrivate 0044 { 0045 public: 0046 QUrl masterURL; 0047 QHostAddress masterIP; 0048 }; 0049 0050 0051 Smb4KWorkgroup::Smb4KWorkgroup(const QString &name) 0052 : Smb4KBasicNetworkItem(Workgroup), d(new Smb4KWorkgroupPrivate) 0053 { 0054 // 0055 // Set the URL of the workgroup 0056 // 0057 pUrl->setScheme("smb"); 0058 pUrl->setHost(name); 0059 0060 // 0061 // Set the icon 0062 // 0063 *pIcon = KDE::icon("network-workgroup"); 0064 } 0065 0066 0067 Smb4KWorkgroup::Smb4KWorkgroup(const Smb4KWorkgroup &w) 0068 : Smb4KBasicNetworkItem(Workgroup), d(new Smb4KWorkgroupPrivate) 0069 { 0070 // Copy the private variables 0071 // 0072 *d = *w.d; 0073 0074 // 0075 // Set the icon if necessary 0076 // 0077 if (pIcon->isNull()) 0078 { 0079 *pIcon = KDE::icon("network-workgroup"); 0080 } 0081 } 0082 0083 0084 Smb4KWorkgroup::Smb4KWorkgroup() 0085 : Smb4KBasicNetworkItem(Workgroup), d(new Smb4KWorkgroupPrivate) 0086 { 0087 // 0088 // Set the URL 0089 // 0090 pUrl->setScheme("smb"); 0091 0092 // 0093 // Set the icon 0094 // 0095 *pIcon = KDE::icon("network-workgroup"); 0096 } 0097 0098 0099 Smb4KWorkgroup::~Smb4KWorkgroup() 0100 { 0101 } 0102 0103 0104 void Smb4KWorkgroup::setWorkgroupName(const QString &name) 0105 { 0106 pUrl->setHost(name); 0107 pUrl->setScheme("smb"); 0108 } 0109 0110 0111 QString Smb4KWorkgroup::workgroupName() const 0112 { 0113 return pUrl->host().toUpper(); 0114 } 0115 0116 0117 void Smb4KWorkgroup::setMasterBrowserName(const QString &name) 0118 { 0119 d->masterURL.setHost(name); 0120 d->masterURL.setScheme("smb"); 0121 } 0122 0123 0124 QString Smb4KWorkgroup::masterBrowserName() const 0125 { 0126 return d->masterURL.host().toUpper(); 0127 } 0128 0129 0130 void Smb4KWorkgroup::setMasterBrowserIpAddress(const QString &ip) 0131 { 0132 d->masterIP.setAddress(ip); 0133 } 0134 0135 0136 void Smb4KWorkgroup::setMasterBrowserIpAddress(const QHostAddress& address) 0137 { 0138 if (!address.isNull() && address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol) 0139 { 0140 d->masterIP = address; 0141 } 0142 } 0143 0144 0145 QString Smb4KWorkgroup::masterBrowserIpAddress() const 0146 { 0147 return d->masterIP.toString(); 0148 } 0149 0150 0151 bool Smb4KWorkgroup::hasMasterBrowserIpAddress() const 0152 { 0153 return !d->masterIP.isNull(); 0154 } 0155 0156 0157 void Smb4KWorkgroup::update(Smb4KWorkgroup* workgroup) 0158 { 0159 if (QString::compare(workgroupName(), workgroup->workgroupName()) == 0) 0160 { 0161 setMasterBrowserName(workgroup->masterBrowserName()); 0162 setMasterBrowserIpAddress(workgroup->masterBrowserIpAddress()); 0163 } 0164 0165 0166 0167 0168 } 0169 0170