1
/**************************************************************************
3
* Copyright 2015 Canonical Ltd.
4
* Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; version 3.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
* File: smblocation.cpp
22
#include "smblocation.h"
24
#include "smbiteminfo.h"
25
#include "smblocationdiriterator.h"
26
#include "iorequest.h"
27
#include "ioworkerthread.h"
28
#include "locationurl.h"
29
#include "smblocationitemfile.h"
30
#include "smblocationitemdir.h"
31
#include "netauthenticationdata.h"
35
#if defined(Q_OS_UNIX)
36
#include <sys/statvfs.h>
39
SmbLocation::SmbLocation(int type, QObject *parent)
40
: NetworkLocation(type, parent)
41
, SmbLocationAuthentication()
43
m_smb = new SmbUtil(suitableAuthenticationFunction());
44
setAuthentication(NetAuthenticationData::currentUser(),
45
NetAuthenticationData::noPassword());
49
SmbLocation::~SmbLocation()
55
//======================================================================================================
57
* \brief SmbLocation::setAuthentication() saves user/password ot be used in current SmbLocationAuthentication function
59
* These information will be used in further Samba authentication for this instance
64
void SmbLocation::setAuthentication(const QString &user,
65
const QString &password)
67
//setInfo is not static
68
SmbLocationAuthentication::setInfo(user,password);
72
QString SmbLocation::currentAuthenticationUser()
74
//currenAuthUser is not static
75
return SmbLocationAuthentication::currentAuthUser();
79
QString SmbLocation::currentAuthenticationPassword()
81
return SmbLocationAuthentication::currentAuthPassword();
85
DirItemInfo * SmbLocation::newItemInfo(const QString &urlPath)
87
return new SmbItemInfo(urlPath, m_smb);
91
QString SmbLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlash)
94
if ( urlPath.startsWith(LocationUrl::SmbURL.midRef(0,4)) ||
95
urlPath.startsWith(LocationUrl::CifsURL.midRef(0,5))
98
ret = LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(urlPath, indexOfColonAndSlash+1);
104
LocationItemDirIterator *
105
SmbLocation::newDirIterator(const QString &path,
106
QDir::Filters filters,
107
QDirIterator::IteratorFlags flags,
108
LocationItemDirIterator::LoadMode loadmode)
110
return new SmbLocationDirIterator(path, filters, flags, m_smb, loadmode);
115
SmbLocation::newFile(const QString &path)
117
return new SmbLocationItemFile(path, this, m_smb);
122
SmbLocation::newDir(const QString &dir)
124
return new SmbLocationItemDir(dir, m_smb);
129
bool SmbLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
132
#if defined(Q_OS_UNIX)
134
if (m_smb->getStatvfsInfo(pathname, &st) == SmbUtil::StatDone)
136
qint64 free = st.f_bsize * st.f_bfree;
137
ret = free > requiredSize;