File indexing completed on 2024-04-21 05:01:36
0001 /* 0002 This is the bookmark container for Smb4K (next generation). 0003 0004 SPDX-FileCopyrightText: 2008-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 // application specific includes 0009 #include "smb4kbookmark.h" 0010 #include "smb4kshare.h" 0011 0012 // Qt includes 0013 #include <QDebug> 0014 #include <QHostAddress> 0015 0016 // KDE includes 0017 #include <KIconLoader> 0018 #include <KLocalizedString> 0019 0020 using namespace Smb4KGlobal; 0021 0022 class Smb4KBookmarkPrivate 0023 { 0024 public: 0025 QUrl url; 0026 QString workgroup; 0027 QHostAddress ip; 0028 QString label; 0029 QString category; 0030 QString profile; 0031 QIcon icon; 0032 Smb4KGlobal::ShareType type; 0033 }; 0034 0035 Smb4KBookmark::Smb4KBookmark(Smb4KShare *share, const QString &label) 0036 : d(new Smb4KBookmarkPrivate) 0037 { 0038 setShare(share); 0039 d->label = label; 0040 } 0041 0042 Smb4KBookmark::Smb4KBookmark(const Smb4KBookmark &b) 0043 : d(new Smb4KBookmarkPrivate) 0044 { 0045 *d = *b.d; 0046 } 0047 0048 Smb4KBookmark::Smb4KBookmark() 0049 : d(new Smb4KBookmarkPrivate) 0050 { 0051 d->type = FileShare; 0052 d->icon = KDE::icon(QStringLiteral("folder-network")); 0053 } 0054 0055 Smb4KBookmark::~Smb4KBookmark() 0056 { 0057 } 0058 0059 void Smb4KBookmark::setShare(Smb4KShare *share) const 0060 { 0061 if (!share->isHomesShare()) { 0062 d->url = share->url(); 0063 } else { 0064 d->url = share->homeUrl(); 0065 } 0066 0067 d->workgroup = share->workgroupName(); 0068 d->type = share->shareType(); 0069 d->icon = KDE::icon(QStringLiteral("folder-network")); 0070 d->ip.setAddress(share->hostIpAddress()); 0071 } 0072 0073 void Smb4KBookmark::setWorkgroupName(const QString &workgroup) const 0074 { 0075 d->workgroup = workgroup; 0076 } 0077 0078 QString Smb4KBookmark::workgroupName() const 0079 { 0080 return d->workgroup; 0081 } 0082 0083 QString Smb4KBookmark::hostName() const 0084 { 0085 return d->url.host().toUpper(); 0086 } 0087 0088 QString Smb4KBookmark::shareName() const 0089 { 0090 if (d->url.path().startsWith(QStringLiteral("/"))) { 0091 return d->url.path().remove(0, 1); 0092 } 0093 0094 return d->url.path(); 0095 } 0096 0097 void Smb4KBookmark::setHostIpAddress(const QString &ip) const 0098 { 0099 d->ip.setAddress(ip); 0100 } 0101 0102 QString Smb4KBookmark::hostIpAddress() const 0103 { 0104 return d->ip.toString(); 0105 } 0106 0107 void Smb4KBookmark::setShareType(Smb4KGlobal::ShareType type) const 0108 { 0109 d->type = type; 0110 } 0111 0112 Smb4KGlobal::ShareType Smb4KBookmark::shareType() const 0113 { 0114 return d->type; 0115 } 0116 0117 void Smb4KBookmark::setLabel(const QString &label) const 0118 { 0119 d->label = label; 0120 } 0121 0122 QString Smb4KBookmark::label() const 0123 { 0124 return d->label; 0125 } 0126 0127 void Smb4KBookmark::setUserName(const QString &name) const 0128 { 0129 d->url.setUserName(name); 0130 } 0131 0132 QString Smb4KBookmark::userName() const 0133 { 0134 return d->url.userName(); 0135 } 0136 0137 void Smb4KBookmark::setUrl(const QUrl &url) const 0138 { 0139 d->url = url; 0140 d->url.setScheme(QStringLiteral("smb")); 0141 } 0142 0143 QUrl Smb4KBookmark::url() const 0144 { 0145 return d->url; 0146 } 0147 0148 void Smb4KBookmark::setCategoryName(const QString &name) const 0149 { 0150 d->category = name; 0151 } 0152 0153 QString Smb4KBookmark::categoryName() const 0154 { 0155 return d->category; 0156 } 0157 0158 void Smb4KBookmark::setProfile(const QString &profile) const 0159 { 0160 d->profile = profile; 0161 } 0162 0163 QString Smb4KBookmark::profile() const 0164 { 0165 return d->profile; 0166 } 0167 0168 void Smb4KBookmark::setIcon(const QIcon &icon) const 0169 { 0170 d->icon = icon; 0171 } 0172 0173 QIcon Smb4KBookmark::icon() const 0174 { 0175 return d->icon; 0176 } 0177 0178 QString Smb4KBookmark::displayString() const 0179 { 0180 return i18n("%1 on %2", shareName(), hostName()); 0181 } 0182 0183 Smb4KBookmark &Smb4KBookmark::operator=(const Smb4KBookmark &other) 0184 { 0185 *d = *other.d; 0186 return *this; 0187 }