File indexing completed on 2024-04-14 15:05:23

0001 /***************************************************************************
0002     This class provides the basic network item for the core library of 
0003     Smb4K.
0004                              -------------------
0005     begin                : Do Apr 2 2009
0006     copyright            : (C) 2009-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 "smb4kbasicnetworkitem.h"
0033 
0034 // Qt includes
0035 #include <QtGlobal>
0036 #include <QDebug>
0037 
0038 using namespace Smb4KGlobal;
0039 
0040 class Smb4KBasicNetworkItemPrivate
0041 {
0042   public:
0043     NetworkItem type;
0044     QIcon icon;
0045     QUrl url;
0046 };
0047 
0048 
0049 Smb4KBasicNetworkItem::Smb4KBasicNetworkItem(NetworkItem type)
0050 : d(new Smb4KBasicNetworkItemPrivate)
0051 {
0052   //
0053   // Set the type
0054   // 
0055   d->type = type;
0056   
0057   //
0058   // Initialize the protected variables
0059   // 
0060   pUrl = &d->url;
0061   pIcon = &d->icon;
0062 }
0063 
0064 Smb4KBasicNetworkItem::Smb4KBasicNetworkItem(const Smb4KBasicNetworkItem &item)
0065 : d(new Smb4KBasicNetworkItemPrivate)
0066 {
0067   //
0068   // Copy the private variables
0069   // 
0070   *d = *item.d;
0071   
0072   //
0073   // Initialize the protected variables
0074   // 
0075   pUrl = &d->url;
0076   pIcon = &d->icon;
0077 }
0078 
0079 
0080 Smb4KBasicNetworkItem::~Smb4KBasicNetworkItem()
0081 {
0082 }
0083 
0084 
0085 Smb4KGlobal::NetworkItem Smb4KBasicNetworkItem::type() const
0086 {
0087   return d->type;
0088 }
0089 
0090 
0091 void Smb4KBasicNetworkItem::setIcon(const QIcon &icon)
0092 {
0093   d->icon = icon;
0094 }
0095 
0096 
0097 QIcon Smb4KBasicNetworkItem::icon() const
0098 {
0099   return d->icon;
0100 }
0101 
0102 
0103 void Smb4KBasicNetworkItem::setUrl(const QUrl& url)
0104 {
0105   //
0106   // Check that the URL is valid
0107   // 
0108   if (!url.isValid())
0109   {
0110     return;
0111   }
0112   
0113   //
0114   // Do some checks depending on the type of the network item
0115   // 
0116   switch (d->type)
0117   {
0118     case Network:
0119     {
0120       break;
0121     }
0122     case Workgroup:
0123     case Host:
0124     {
0125       // 
0126       // Check that the host name is present and there is no path
0127       // 
0128       if (url.host().isEmpty() || !url.path().isEmpty())
0129       {
0130         return;
0131       }
0132       
0133       break;
0134     }
0135     case Share:
0136     {
0137       //
0138       // Check that the share name is present
0139       // 
0140       if (url.path().isEmpty() || (url.path().size() == 1 && url.path().endsWith('/')))
0141       {
0142         return;
0143       }
0144       
0145       break;
0146     }
0147     default:
0148     {
0149       break;
0150     }
0151   }
0152   
0153   //
0154   // Set the URL
0155   //
0156   d->url = url;
0157   
0158   //
0159   // Force the scheme
0160   // 
0161   if (d->url.scheme() != "smb")
0162   {
0163     d->url.setScheme("smb");
0164   }
0165 }
0166 
0167 
0168 QUrl Smb4KBasicNetworkItem::url() const
0169 {
0170   return d->url;
0171 }
0172 
0173