~ubuntu-filemanager-dev/ubuntu-filemanager-app/trunk

« back to all changes in this revision

Viewing changes to src/plugin/folderlistmodel/smb/smblocation.cpp

  • Committer: Bileto Bot
  • Date: 2017-04-04 17:06:41 UTC
  • mfrom: (588.1.19 fix-desktop-file)
  • Revision ID: ci-train-bot@canonical.com-20170404170641-1p15lmx8wodlx2ut
* Rename binary file to ubuntu-filemanager-app
* Join plugin packages into the main package 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 *
 
3
 * Copyright 2015 Canonical Ltd.
 
4
 * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 *
 
18
 * File: smblocation.cpp
 
19
 * Date: 17/01/2015
 
20
 */
 
21
 
 
22
#include "smblocation.h"
 
23
#include "smbutil.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"
 
32
 
 
33
 
 
34
 
 
35
#if defined(Q_OS_UNIX)
 
36
#include <sys/statvfs.h>
 
37
#endif
 
38
 
 
39
SmbLocation::SmbLocation(int type, QObject *parent)
 
40
     : NetworkLocation(type, parent)
 
41
     , SmbLocationAuthentication()
 
42
{
 
43
     m_smb = new SmbUtil(suitableAuthenticationFunction());
 
44
     setAuthentication(NetAuthenticationData::currentUser(),
 
45
                       NetAuthenticationData::noPassword());
 
46
}
 
47
 
 
48
 
 
49
SmbLocation::~SmbLocation()
 
50
{
 
51
 
 
52
}
 
53
 
 
54
 
 
55
//======================================================================================================
 
56
/*!
 
57
 * \brief SmbLocation::setAuthentication() saves user/password ot be used in current SmbLocationAuthentication function
 
58
 *
 
59
 *  These information will be used in further Samba authentication for this instance
 
60
 *
 
61
 * \param user
 
62
 * \param password
 
63
 */
 
64
void SmbLocation::setAuthentication(const QString &user,
 
65
                                    const QString &password)
 
66
{
 
67
    //setInfo is not static
 
68
    SmbLocationAuthentication::setInfo(user,password);
 
69
}
 
70
 
 
71
 
 
72
QString SmbLocation::currentAuthenticationUser()
 
73
{
 
74
    //currenAuthUser is not static
 
75
    return SmbLocationAuthentication::currentAuthUser();
 
76
}
 
77
 
 
78
 
 
79
QString SmbLocation::currentAuthenticationPassword()
 
80
{
 
81
    return SmbLocationAuthentication::currentAuthPassword();
 
82
}
 
83
 
 
84
 
 
85
DirItemInfo * SmbLocation::newItemInfo(const QString &urlPath)
 
86
{
 
87
    return new SmbItemInfo(urlPath, m_smb);
 
88
}
 
89
 
 
90
 
 
91
QString SmbLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlash)
 
92
{
 
93
    QString ret;
 
94
    if ( urlPath.startsWith(LocationUrl::SmbURL.midRef(0,4)) ||
 
95
         urlPath.startsWith(LocationUrl::CifsURL.midRef(0,5))
 
96
       )
 
97
    {
 
98
        ret  = LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(urlPath, indexOfColonAndSlash+1);
 
99
    }
 
100
    return ret;
 
101
}
 
102
 
 
103
 
 
104
LocationItemDirIterator *
 
105
SmbLocation::newDirIterator(const QString &path,
 
106
                            QDir::Filters filters,
 
107
                            QDirIterator::IteratorFlags flags,
 
108
                            LocationItemDirIterator::LoadMode loadmode)
 
109
{
 
110
    return new SmbLocationDirIterator(path, filters, flags, m_smb, loadmode);
 
111
}
 
112
 
 
113
 
 
114
LocationItemFile *
 
115
SmbLocation::newFile(const QString &path)
 
116
{
 
117
    return new SmbLocationItemFile(path, this, m_smb);
 
118
}
 
119
 
 
120
 
 
121
LocationItemDir *
 
122
SmbLocation::newDir(const QString &dir)
 
123
{
 
124
    return new SmbLocationItemDir(dir, m_smb);
 
125
}
 
126
 
 
127
 
 
128
 
 
129
bool SmbLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
 
130
{
 
131
    bool ret = false;
 
132
#if defined(Q_OS_UNIX)
 
133
    struct statvfs st;
 
134
    if (m_smb->getStatvfsInfo(pathname, &st) == SmbUtil::StatDone)
 
135
    {
 
136
        qint64 free =  st.f_bsize * st.f_bfree;
 
137
        ret = free > requiredSize;
 
138
    }
 
139
#else
 
140
   ret =  true;
 
141
#endif
 
142
   return ret;
 
143
}