add more spacing
[personal-kdebase.git] / runtime / kioslave / smb / kio_smb_internal.cpp
blob0ca1d0b0c94678efd48131278b88c90aa05599e2
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // Project: SMB kioslave for KDE2
4 //
5 // File: kio_smb_internal.cpp
6 //
7 // Abstract: Utility class implementation used by SMBSlave
8 //
9 // Author(s): Matthew Peterson <mpeterson@caldera.com>
11 //---------------------------------------------------------------------------
13 // Copyright (c) 2000 Caldera Systems, Inc.
15 // This program is free software; you can redistribute it and/or modify it
16 // under the terms of the GNU General Public License as published by the
17 // Free Software Foundation; either version 2.1 of the License, or
18 // (at your option) any later version.
20 // This program is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU Lesser General Public License for more details.
25 // You should have received a copy of the GNU General Public License
26 // along with this program; see the file COPYING. If not, please obtain
27 // a copy from http://www.gnu.org/copyleft/gpl.html
29 /////////////////////////////////////////////////////////////////////////////
31 #include "kio_smb_internal.h"
32 #include "kio_smb.h"
34 #include <QTextCodec>
36 #include <kconfig.h>
37 #include <kglobal.h>
40 //===========================================================================
41 // SMBUrl Function Implementation
42 //===========================================================================
44 //-----------------------------------------------------------------------
45 SMBUrl::SMBUrl()
47 m_type = SMBURLTYPE_UNKNOWN;
50 //-----------------------------------------------------------------------
51 SMBUrl::SMBUrl(const KUrl& kurl)
52 : KUrl(kurl)
53 //-----------------------------------------------------------------------
55 updateCache();
59 //-----------------------------------------------------------------------
60 void SMBUrl::addPath(const QString &filedir)
62 KUrl::addPath(filedir);
63 updateCache();
66 //-----------------------------------------------------------------------
67 bool SMBUrl::cd(const QString &filedir)
69 if (!KUrl::cd(filedir))
70 return false;
71 updateCache();
72 return true;
75 //-----------------------------------------------------------------------
76 void SMBUrl::updateCache()
77 //-----------------------------------------------------------------------
79 cleanPath();
81 // SMB URLs are UTF-8 encoded
82 kDebug(KIO_SMB) << "updateCache " << KUrl::path();
84 if ( KUrl::url() == "smb:/" )
85 m_surl = "smb://";
86 else
87 m_surl = KUrl::url( RemoveTrailingSlash ).toUtf8();
89 m_type = SMBURLTYPE_UNKNOWN;
90 // update m_type
91 (void)getType();
94 //-----------------------------------------------------------------------
95 SMBUrlType SMBUrl::getType() const
96 // Returns the type of this SMBUrl:
97 // SMBURLTYPE_UNKNOWN - Type could not be determined. Bad SMB Url.
98 // SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network
99 // SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver"
100 // SMBURLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir"
101 //-----------------------------------------------------------------------
103 if(m_type != SMBURLTYPE_UNKNOWN)
104 return m_type;
106 if (protocol() != "smb")
108 m_type = SMBURLTYPE_UNKNOWN;
109 return m_type;
112 if (path(KUrl::AddTrailingSlash) == "/")
114 if (host().isEmpty())
115 m_type = SMBURLTYPE_ENTIRE_NETWORK;
116 else
117 m_type = SMBURLTYPE_WORKGROUP_OR_SERVER;
118 return m_type;
121 // Check for the path if we get this far
122 m_type = SMBURLTYPE_SHARE_OR_PATH;
124 return m_type;