File indexing completed on 2024-04-21 15:42:43
0001 /*************************************************************************** 0002 This is the bookmark container for Smb4K (next generation). 0003 ------------------- 0004 begin : So Jun 8 2008 0005 copyright : (C) 2008-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 "smb4kbookmark.h" 0032 #include "smb4kshare.h" 0033 0034 // Qt includes 0035 #include <QDebug> 0036 #include <QHostAddress> 0037 0038 // KDE includes 0039 #define TRANSLATION_DOMAIN "smb4k-core" 0040 #include <KI18n/KLocalizedString> 0041 #include <KIconThemes/KIconLoader> 0042 0043 using namespace Smb4KGlobal; 0044 0045 0046 class Smb4KBookmarkPrivate 0047 { 0048 public: 0049 QUrl url; 0050 QString workgroup; 0051 QHostAddress ip; 0052 QString label; 0053 QString group; 0054 QString profile; 0055 QIcon icon; 0056 Smb4KGlobal::ShareType type; 0057 }; 0058 0059 0060 Smb4KBookmark::Smb4KBookmark(Smb4KShare *share, const QString &label) 0061 : d(new Smb4KBookmarkPrivate) 0062 { 0063 if (!share->isHomesShare()) 0064 { 0065 d->url = share->url(); 0066 } 0067 else 0068 { 0069 d->url = share->homeUrl(); 0070 } 0071 0072 d->workgroup = share->workgroupName(); 0073 d->type = share->shareType(); 0074 d->label = label; 0075 d->icon = KDE::icon("folder-network"); 0076 d->ip.setAddress(share->hostIpAddress()); 0077 } 0078 0079 0080 Smb4KBookmark::Smb4KBookmark(const Smb4KBookmark &b) 0081 : d(new Smb4KBookmarkPrivate) 0082 { 0083 *d = *b.d; 0084 } 0085 0086 0087 Smb4KBookmark::Smb4KBookmark() 0088 : d(new Smb4KBookmarkPrivate) 0089 { 0090 d->type = FileShare; 0091 d->icon = KDE::icon("folder-network"); 0092 } 0093 0094 0095 Smb4KBookmark::~Smb4KBookmark() 0096 { 0097 } 0098 0099 0100 void Smb4KBookmark::setWorkgroupName( const QString &workgroup ) 0101 { 0102 d->workgroup = workgroup; 0103 } 0104 0105 0106 QString Smb4KBookmark::workgroupName() const 0107 { 0108 return d->workgroup; 0109 } 0110 0111 0112 void Smb4KBookmark::setHostName(const QString &host) 0113 { 0114 d->url.setHost(host); 0115 d->url.setScheme("smb"); 0116 } 0117 0118 0119 QString Smb4KBookmark::hostName() const 0120 { 0121 return d->url.host().toUpper(); 0122 } 0123 0124 0125 void Smb4KBookmark::setShareName(const QString &share) 0126 { 0127 d->url.setPath(share); 0128 } 0129 0130 0131 QString Smb4KBookmark::shareName() const 0132 { 0133 if (d->url.path().startsWith('/')) 0134 { 0135 return d->url.path().remove(0, 1); 0136 } 0137 0138 return d->url.path(); 0139 } 0140 0141 0142 void Smb4KBookmark::setHostIpAddress(const QString &ip) 0143 { 0144 d->ip.setAddress(ip); 0145 } 0146 0147 0148 QString Smb4KBookmark::hostIpAddress() const 0149 { 0150 return d->ip.toString(); 0151 } 0152 0153 0154 void Smb4KBookmark::setShareType(Smb4KGlobal::ShareType type) 0155 { 0156 d->type = type; 0157 } 0158 0159 0160 Smb4KGlobal::ShareType Smb4KBookmark::shareType() const 0161 { 0162 return d->type; 0163 } 0164 0165 0166 void Smb4KBookmark::setLabel(const QString &label) 0167 { 0168 d->label = label; 0169 } 0170 0171 0172 QString Smb4KBookmark::label() const 0173 { 0174 return d->label; 0175 } 0176 0177 0178 void Smb4KBookmark::setLogin(const QString &login) 0179 { 0180 d->url.setUserName(login); 0181 } 0182 0183 0184 QString Smb4KBookmark::login() const 0185 { 0186 return d->url.userName(); 0187 } 0188 0189 0190 void Smb4KBookmark::setUrl(const QUrl &url) 0191 { 0192 d->url = url; 0193 d->url.setScheme("smb"); 0194 } 0195 0196 0197 void Smb4KBookmark::setUrl(const QString &url) 0198 { 0199 d->url.setUrl(url, QUrl::TolerantMode); 0200 d->url.setScheme("smb"); 0201 } 0202 0203 0204 QUrl Smb4KBookmark::url() const 0205 { 0206 return d->url; 0207 } 0208 0209 0210 void Smb4KBookmark::setGroupName(const QString &name) 0211 { 0212 d->group = name; 0213 } 0214 0215 0216 QString Smb4KBookmark::groupName() const 0217 { 0218 return d->group; 0219 } 0220 0221 0222 void Smb4KBookmark::setProfile(const QString &profile) 0223 { 0224 d->profile = profile; 0225 } 0226 0227 0228 QString Smb4KBookmark::profile() const 0229 { 0230 return d->profile; 0231 } 0232 0233 0234 void Smb4KBookmark::setIcon(const QIcon &icon) 0235 { 0236 d->icon = icon; 0237 } 0238 0239 0240 QIcon Smb4KBookmark::icon() const 0241 { 0242 return d->icon; 0243 } 0244 0245 QString Smb4KBookmark::displayString() const 0246 { 0247 return i18n("%1 on %2", shareName(), hostName()); 0248 } 0249