Filter for directory listing
[owncloud:sebas-mirall.git] / src / plasma / lib / directorylister.cpp
1 /***************************************************************************
2  *                                                                         *
3  *   Copyright 2012 Sebastian K├╝gler <sebas@kde.org>                       *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
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 General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
19  ***************************************************************************/
20
21
22 #include "directorylister.h"
23
24 #include "../applet/owncloud_interface.h"
25
26 #include <kdebug.h>
27
28 class DirectoryListerPrivate {
29 public:
30     DirectoryLister *q;
31     QDir dir;
32     QString path;
33     QStringList directories;
34     QString filter;
35 };
36
37 DirectoryLister::DirectoryLister(QObject* parent) :
38     QObject(parent)
39 {
40     d = new DirectoryListerPrivate;
41     d->q = this;
42
43     //d->directories = QStringList() << "/home/sebas/tmp/test1/" << "/home/sebas/tmp/test2/" << "/home/sebas/tmp/test3/" << "/home/sebas/tmp/test4/" << "/home/sebas/tmp/test5/";
44
45     init();
46 }
47
48 DirectoryLister::~DirectoryLister()
49 {
50     delete d;
51 }
52
53
54 void DirectoryLister::init()
55 {
56 }
57
58 void DirectoryLister::up()
59 {
60
61     emit directoriesChanged();
62 }
63
64 QStringList DirectoryLister::directories()
65 {
66     return d->directories.filter(d->filter);
67 }
68
69 QString DirectoryLister::currentPath()
70 {
71     return d->dir.absolutePath();
72 }
73
74 void DirectoryLister::enterDirectory(const QString &directory)
75 {
76     kDebug() << "entering dir: " << directory;
77     QString dir = directory;
78     if (!dir.startsWith("/")) {
79         dir = d->dir.absolutePath() + "/" + directory;
80     }
81     d->dir.setPath(dir);
82     d->directories = d->dir.entryList(QDir::AllDirs);
83     kDebug() << "Dirs: " << d->directories;
84     //d->directories.removeAll(QString('.'));
85     currentPathChanged();
86     emit directoriesChanged();
87 }
88
89 QString DirectoryLister::filter()
90 {
91     return d->filter;
92 }
93
94 void DirectoryLister::setFilter(const QString &f)
95 {
96     kDebug() << "Setting filter to : " << f;
97     if (f != d->filter) {
98         d->filter = f;
99         emit directoriesChanged();
100         emit filterChanged();
101     }
102 }
103
104
105 #include "directorylister.moc"