1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/////////////////////////////////////////////////////////////////////////////
//
// Project: SMB kioslave for KDE2
//
// File: kio_smb_internal.cpp
//
// Abstract: Utility class implementation used by SMBSlave
//
// Author(s): Matthew Peterson <mpeterson@caldera.com>
//
//---------------------------------------------------------------------------
//
// Copyright (c) 2000 Caldera Systems, Inc.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; see the file COPYING. If not, please obtain
// a copy from http://www.gnu.org/copyleft/gpl.html
//
/////////////////////////////////////////////////////////////////////////////
#include "kio_smb_internal.h"
#include "kio_smb.h"
#include <kconfig.h>
#include <QDir> // for QDir::cleanPath
//===========================================================================
// SMBUrl Function Implementation
//===========================================================================
//-----------------------------------------------------------------------
SMBUrl::SMBUrl()
{
m_type = SMBURLTYPE_UNKNOWN;
}
//-----------------------------------------------------------------------
SMBUrl::SMBUrl(const QUrl& kurl)
: QUrl(kurl)
//-----------------------------------------------------------------------
{
updateCache();
}
SMBUrl::SMBUrl(const SMBUrl& other)
: QUrl(other),
m_surl(other.m_surl),
m_type(other.m_type)
{
}
//-----------------------------------------------------------------------
void SMBUrl::addPath(const QString &filedir)
{
if(path().length() > 0 && path().at(path().length() - 1) != QLatin1Char('/')) {
QUrl::setPath(path() + QLatin1Char('/') + filedir);
} else {
QUrl::setPath(path() + filedir);
}
updateCache();
}
//-----------------------------------------------------------------------
bool SMBUrl::cd(const QString &filedir)
{
if (filedir == "..") {
setUrl(KIO::upUrl(*this).url());
} else {
setUrl(filedir);
}
updateCache();
return true;
}
//-----------------------------------------------------------------------
void SMBUrl::updateCache()
//-----------------------------------------------------------------------
{
QUrl::setPath(QDir::cleanPath(path()));
// SMB URLs are UTF-8 encoded
qCDebug(KIO_SMB) << "updateCache " << QUrl::path();
if ( QUrl::url() == "smb:/" )
m_surl = "smb://";
else
m_surl = toString(QUrl::PrettyDecoded).toUtf8();
m_type = SMBURLTYPE_UNKNOWN;
// update m_type
(void)getType();
}
//-----------------------------------------------------------------------
SMBUrlType SMBUrl::getType() const
// Returns the type of this SMBUrl:
// SMBURLTYPE_UNKNOWN - Type could not be determined. Bad SMB Url.
// SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network
// SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver"
// SMBURLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir"
//-----------------------------------------------------------------------
{
if(m_type != SMBURLTYPE_UNKNOWN)
return m_type;
if (scheme() != "smb")
{
m_type = SMBURLTYPE_UNKNOWN;
return m_type;
}
if (path().isEmpty() || path(QUrl::FullyDecoded) == "/")
{
if (host().isEmpty())
m_type = SMBURLTYPE_ENTIRE_NETWORK;
else
m_type = SMBURLTYPE_WORKGROUP_OR_SERVER;
return m_type;
}
// Check for the path if we get this far
m_type = SMBURLTYPE_SHARE_OR_PATH;
return m_type;
}
SMBUrl SMBUrl::partUrl() const
{
if (m_type == SMBURLTYPE_SHARE_OR_PATH && !fileName().isEmpty()) {
SMBUrl url (*this);
url.setFileName(fileName() + QLatin1String(".part"));
return url;
}
return SMBUrl();
}
|