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

« back to all changes in this revision

Viewing changes to src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationdiriterator.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: smblocationdiriterator.cpp
 
19
 * Date: 10/01/2015
 
20
 */
 
21
 
 
22
#include "smblocationdiriterator.h"
 
23
#include "smbiteminfo.h"
 
24
#include "smbutil.h"
 
25
 
 
26
#define INIT_ATTR(path,smb) SmbObject(path,smb), m_curItem(-1)
 
27
 
 
28
#define GOOD_INDEX() (m_curItem >= 0 && m_curItem < m_urlItems.count())
 
29
 
 
30
 
 
31
SmbLocationDirIterator::SmbLocationDirIterator(const QString &path,
 
32
                                               const QStringList &nameFilters,
 
33
                                               QDir::Filters filters,
 
34
                                               QDirIterator::IteratorFlags flags,
 
35
                                               Const_SmbUtil_Ptr smb,
 
36
                                               LocationItemDirIterator::LoadMode loadmode)
 
37
        : LocationItemDirIterator(path, nameFilters, filters, flags, loadmode)
 
38
        , INIT_ATTR(path, smb)
 
39
{
 
40
   if (loadmode == LocationItemDirIterator::LoadOnConstructor)
 
41
   {
 
42
       load();
 
43
   }
 
44
}
 
45
 
 
46
 
 
47
SmbLocationDirIterator::SmbLocationDirIterator(const QString &path,
 
48
                                               QDir::Filters filters,
 
49
                                               QDirIterator::IteratorFlags flags,
 
50
                                               Const_SmbUtil_Ptr smb,
 
51
                                               LocationItemDirIterator::LoadMode loadmode)
 
52
     : LocationItemDirIterator(path,filters,flags, loadmode)
 
53
     , INIT_ATTR(path, smb)
 
54
{
 
55
    if (loadmode == LocationItemDirIterator::LoadOnConstructor)
 
56
    {
 
57
        load();
 
58
    }
 
59
}
 
60
 
 
61
 
 
62
SmbLocationDirIterator::SmbLocationDirIterator(const QString &path,
 
63
                                               QDirIterator::IteratorFlags flags,
 
64
                                               Const_SmbUtil_Ptr smb,
 
65
                                               LocationItemDirIterator::LoadMode loadmode)
 
66
       : LocationItemDirIterator(path,flags, loadmode)
 
67
       , INIT_ATTR(path, smb)
 
68
{
 
69
    if (loadmode == LocationItemDirIterator::LoadOnConstructor)
 
70
    {
 
71
        load();
 
72
    }
 
73
}
 
74
 
 
75
 
 
76
SmbLocationDirIterator::~SmbLocationDirIterator()
 
77
{
 
78
 
 
79
}
 
80
 
 
81
 
 
82
QString SmbLocationDirIterator::next()
 
83
{
 
84
    QString ret;
 
85
    if (hasNext())
 
86
    {
 
87
        ret = m_urlItems.at(++m_curItem);
 
88
    }
 
89
    return ret;
 
90
}
 
91
 
 
92
 
 
93
bool SmbLocationDirIterator::hasNext() const
 
94
{
 
95
    return m_urlItems.count() > 0 && m_curItem < (m_urlItems.count() -1);
 
96
}
 
97
 
 
98
 
 
99
DirItemInfo SmbLocationDirIterator::fileInfo() const
 
100
{
 
101
    if (GOOD_INDEX())
 
102
    {
 
103
        SmbItemInfo  info(m_urlItems.at(m_curItem), m_smb);
 
104
        return info;
 
105
    }
 
106
    return SmbItemInfo();
 
107
}
 
108
 
 
109
 
 
110
QString SmbLocationDirIterator::fileName() const
 
111
{
 
112
    QString file;
 
113
    if (GOOD_INDEX())
 
114
    {
 
115
        QStringList paths = UrlItemInfo::separatePathFilename(m_urlItems.at(m_curItem));
 
116
        if (paths.count() == 2)
 
117
        {
 
118
            file = paths.at(1);
 
119
        }
 
120
    }
 
121
    return file;
 
122
}
 
123
 
 
124
 
 
125
QString SmbLocationDirIterator::filePath() const
 
126
{
 
127
    QString fullpathname;
 
128
    if (GOOD_INDEX())
 
129
    {
 
130
        fullpathname = m_urlItems.at(m_curItem);
 
131
    }
 
132
    return fullpathname;
 
133
}
 
134
 
 
135
 
 
136
void SmbLocationDirIterator::load()
 
137
{
 
138
    bool recursive = m_flags == QDirIterator::Subdirectories ? true : false;
 
139
    m_urlItems = smbObj()->listContent(path(), recursive, m_filters, m_nameFilters);
 
140
}