• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

filelight

  • sources
  • kde-4.12
  • kdeutils
  • filelight
  • src
  • part
remoteLister.cpp
Go to the documentation of this file.
1 /***********************************************************************
2 * Copyright 2003-2004 Max Howell <max.howell@methylblue.com>
3 * Copyright 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License or (at your option) version 3 or any later version
9 * accepted by the membership of KDE e.V. (or its successor approved
10 * by the membership of KDE e.V.), which shall act as a proxy
11 * defined in Section 14 of version 3 of the license.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 
22 #include "remoteLister.h"
23 #include "fileTree.h"
24 #include "scan.h"
25 
26 #include <KDebug>
27 #include <KDirLister>
28 
29 #include <QtCore/QLinkedList>
30 #include <QtCore/QTimer>
31 #include <QtGui/QWidget>
32 
33 namespace Filelight
34 {
35 
36 //TODO: delete all this stuff!
37 
38 // You need to use a single DirLister.
39 // One per folder breaks KIO (seemingly) and also uses un-godly amounts of memory!
40 
41 struct Store {
42 
43  typedef QLinkedList<Store*> List;
44 
46  const KUrl url;
48  Folder *folder;
50  Store *parent;
52  List stores;
53 
54  Store() : folder(0), parent(0) {}
55  Store(const KUrl &u, const QString &name, Store *s)
56  : url(u), folder(new Folder(name.toUtf8() + '/')), parent(s) {}
57 
58 
59  Store* propagate()
60  {
62 
63  kDebug() << "propagate: " << url << endl;
64 
65  if (parent) {
66  parent->folder->append(folder);
67  if (parent->stores.isEmpty()) {
68  return parent->propagate();
69  }
70  else
71  return parent;
72  }
73 
74  //we reached the root, let's get our next folder scanned
75  return this;
76  }
77 
78 private:
79  Store(Store&);
80  Store &operator=(const Store&);
81 };
82 
83 
84 RemoteLister::RemoteLister(const KUrl &url, QWidget *parent, ScanManager* manager)
85  : KDirLister(parent)
86  , m_root(new Store(url, url.url(), 0))
87  , m_store(m_root)
88  , m_manager(manager)
89 {
90  setShowingDotFiles(true); // Stupid KDirLister API function names
91  setMainWindow(parent);
92 
93  // Use SIGNAL(result(KIO::Job*)) instead and then use Job::error()
94  connect(this, SIGNAL(completed()), SLOT(completed()));
95  connect(this, SIGNAL(canceled()), SLOT(canceled()));
96 }
97 
98 RemoteLister::~RemoteLister()
99 {
100  Folder *tree = isFinished() ? m_store->folder : 0;
101 
102  emit branchCompleted(tree, false);
103  delete m_root;
104 }
105 
106 void
107 RemoteLister::completed()
108 {
109  kDebug() << "completed: " << url().prettyUrl() << endl;
110 
111  // Delay the call to _completed since it can do a "delete this"
112  QTimer::singleShot(0, this, SLOT(_completed()));
113 }
114 
115 void
116 RemoteLister::canceled()
117 {
118  kDebug() << "canceled: " << url().prettyUrl() << endl;
119 
120  QTimer::singleShot(0, this, SLOT(_completed()));
121 }
122 
123 void
124 RemoteLister::_completed()
125 {
126  //m_folder is set to the folder we should operate on
127 
128  const KFileItemList items = KDirLister::items();
129  for (KFileItemList::ConstIterator it = items.begin(), end = items.end(); it != end; ++it)
130  {
131  if (it->isDir())
132  m_store->stores += new Store(it->url(), it->name(), m_store);
133  else
134  m_store->folder->append(it->name().toUtf8(), it->size());
135 
136  m_manager->m_files++;
137  }
138 
139 
140  if (m_store->stores.isEmpty())
141  //no directories to scan, so we need to append ourselves to the parent folder
142  //propagate() will return the next ancestor that has stores left to be scanned, or root if we are done
143  m_store = m_store->propagate();
144 
145  if (!m_store->stores.isEmpty())
146  {
147  Store::List::Iterator first = m_store->stores.begin();
148  const KUrl url((*first)->url);
149  Store *currentStore = m_store;
150 
151  //we should operate with this store next time this function is called
152  m_store = *first;
153 
154  //we don't want to handle this store again
155  currentStore->stores.erase(first);
156 
157  //this returns _immediately_
158  kDebug() << "scanning: " << url << endl;
159  openUrl(url);
160  }
161  else {
162  kDebug() << "I think we're done\n";
163 
164  Q_ASSERT(m_root == m_store);
165 
166  delete this;
167  }
168 }
169 }
170 
171 #include "remoteLister.moc"
QWidget
Folder
Definition: fileTree.h:271
fileTree.h
Filelight::RemoteLister::branchCompleted
void branchCompleted(Folder *tree, bool finished)
Filelight::parent
http QObject * parent
Definition: part.cpp:74
Filelight::RemoteLister::RemoteLister
RemoteLister(const KUrl &url, QWidget *parent, ScanManager *manager)
Definition: remoteLister.cpp:84
scan.h
Filelight::RemoteLister::~RemoteLister
~RemoteLister()
Definition: remoteLister.cpp:98
KDirLister
Filelight::ScanManager
Definition: scan.h:35
remoteLister.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:08:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

filelight

Skip menu "filelight"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal