File indexing completed on 2024-05-05 17:01:32

0001 /***************************************************************************
0002     This class derives from QObject and encapsulates a bookmark item. It
0003     is for use with QtQuick.
0004                              -------------------
0005     begin                : Fr Mai 11 2013
0006     copyright            : (C) 2013-2019 by Alexander Reinholdt
0007     email                : alexander.reinholdt@kdemail.net
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  *   This program is distributed in the hope that it will be useful, but   *
0017  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
0018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
0019  *   General Public License for more details.                              *
0020  *                                                                         *
0021  *   You should have received a copy of the GNU General Public License     *
0022  *   along with this program; if not, write to the                         *
0023  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
0024  *   MA 02110-1335, USA                                                    *
0025  ***************************************************************************/
0026 
0027 #ifdef HAVE_CONFIG_H
0028 #include <config.h>
0029 #endif
0030 
0031 // application specific includes
0032 #include "smb4kbookmarkobject.h"
0033 
0034 // Qt includes
0035 #include <QHostAddress>
0036 
0037 // KDE includes
0038 #include <KIconThemes/KIconLoader>
0039 
0040 
0041 class Smb4KBookmarkObjectPrivate
0042 {
0043   public:
0044     QString workgroup;
0045     QUrl url;
0046     QString label;
0047     QString group;
0048     QString login;
0049     bool isGroup;
0050     bool isMounted;
0051     QHostAddress hostIP;
0052 };
0053 
0054 
0055 Smb4KBookmarkObject::Smb4KBookmarkObject(Smb4KBookmark* bookmark, QObject* parent)
0056 : QObject(parent), d(new Smb4KBookmarkObjectPrivate)
0057 {
0058   d->workgroup  = bookmark->workgroupName();
0059   d->url        = bookmark->url();
0060   d->label      = bookmark->label();
0061   d->group      = bookmark->groupName();
0062   d->login      = bookmark->login();
0063   d->isGroup    = false;
0064   d->isMounted  = false;
0065   d->hostIP.setAddress(bookmark->hostIpAddress());
0066 }
0067 
0068 
0069 Smb4KBookmarkObject::Smb4KBookmarkObject(const QString& groupName, QObject* parent)
0070 : QObject(parent), d(new Smb4KBookmarkObjectPrivate)
0071 {
0072   d->group      = groupName;
0073   d->isGroup    = true;
0074   d->isMounted  = false;
0075 }
0076 
0077 
0078 
0079 Smb4KBookmarkObject::Smb4KBookmarkObject(QObject* parent)
0080 : QObject(parent), d(new Smb4KBookmarkObjectPrivate)
0081 {
0082   d->isGroup    = false;
0083   d->isMounted  = false;
0084 }
0085 
0086 
0087 Smb4KBookmarkObject::~Smb4KBookmarkObject()
0088 {
0089 }
0090 
0091 
0092 QString Smb4KBookmarkObject::workgroupName() const
0093 {
0094   return d->workgroup;
0095 }
0096 
0097 
0098 void Smb4KBookmarkObject::setWorkgroupName(const QString& name)
0099 {
0100   d->workgroup = name;
0101   emit changed();
0102 }
0103 
0104 
0105 QString Smb4KBookmarkObject::hostName() const
0106 {
0107   return d->url.host().toUpper();
0108 }
0109 
0110 
0111 QString Smb4KBookmarkObject::shareName() const
0112 {
0113   return d->url.path().remove('/');
0114 }
0115 
0116 
0117 QString Smb4KBookmarkObject::label() const
0118 {
0119   return d->label;
0120 }
0121 
0122 
0123 void Smb4KBookmarkObject::setLabel(const QString& label)
0124 {
0125   d->label = label;
0126   emit changed();
0127 }
0128 
0129 
0130 QUrl Smb4KBookmarkObject::url() const
0131 {
0132   return d->url;
0133 }
0134 
0135 
0136 void Smb4KBookmarkObject::setURL(const QUrl& url)
0137 {
0138   d->url = url;
0139   emit changed();
0140 }
0141 
0142 
0143 QString Smb4KBookmarkObject::groupName() const
0144 {
0145   return d->group;
0146 }
0147 
0148 
0149 void Smb4KBookmarkObject::setGroupName(const QString& name)
0150 {
0151   d->group = name;
0152   emit changed();
0153 }
0154 
0155 
0156 bool Smb4KBookmarkObject::isGroup() const
0157 {
0158   return d->isGroup;
0159 }
0160 
0161 
0162 void Smb4KBookmarkObject::setGroup(bool group)
0163 {
0164   d->isGroup = group;
0165   emit changed();
0166 }
0167 
0168 
0169 bool Smb4KBookmarkObject::isMounted() const
0170 {
0171   return d->isMounted;
0172 }
0173 
0174 
0175 void Smb4KBookmarkObject::setMounted(bool mounted)
0176 {
0177   d->isMounted = mounted;
0178   emit changed();
0179 }
0180 
0181 
0182 QString Smb4KBookmarkObject::login() const
0183 {
0184   return d->login;
0185 }
0186 
0187 
0188 void Smb4KBookmarkObject::setLogin(const QString& name)
0189 {
0190   d->login = name;
0191   emit changed();
0192 }
0193 
0194 
0195 QString Smb4KBookmarkObject::hostIP() const
0196 {
0197   return d->hostIP.toString();
0198 }
0199 
0200 
0201 void Smb4KBookmarkObject::setHostIP(const QString& ip)
0202 {
0203   if (d->hostIP.setAddress(ip))
0204   {
0205     emit changed();
0206   }
0207 }
0208 
0209 
0210