File indexing completed on 2022-11-29 20:25:18

0001 /***************************************************************************
0002 
0003                           threadedlister.h  -  description
0004                              -------------------
0005     begin                : Tue Feb 01 2005
0006     copyright            : (C) 2005 by Dominik Seichter
0007     email                : domseichter@web.de
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *   This program is free software; you can redistribute it and/or modify  *
0013  *   it under the terms of the GNU General Public License as published by  *
0014  *   the Free Software Foundation; either version 2 of the License, or     *
0015  *   (at your option) any later version.                                   *
0016  *                                                                         *
0017  ***************************************************************************/
0018 
0019 #ifndef THREADEDLISTER_H
0020 #define THREADEDLISTER_H
0021 
0022 #include <QThread>
0023 #include <QMutex>
0024 
0025 #include <kfileitem.h>
0026 
0027 #include "krenamefile.h"
0028 
0029 class KRenameModel;
0030 class QMutex;
0031 class QWidget;
0032 
0033 namespace KIO
0034 {
0035 class Job;
0036 };
0037 
0038 class ThreadedLister : public QObject
0039 {
0040     Q_OBJECT
0041 public:
0042     ThreadedLister(const QUrl &dirname, QWidget *cache, KRenameModel *model);
0043     ~ThreadedLister();
0044 
0045     inline void start()
0046     {
0047         this->run();
0048     }
0049 
0050     /** Sets if dirnames should listed along with the filenames.
0051      *  This is disabled by default.
0052      *
0053      *  \param names if true dirnames are listed along with the filenames.
0054      */
0055     inline void setListDirnames(bool names);
0056 
0057     /** Sets if only dirnames should listed.
0058      *  This is disabled by default.
0059      *
0060      *  \param names if true only dirnames are listed.
0061      */
0062     inline void setListDirnamesOnly(bool names);
0063 
0064     inline void setFilter(const QString &filter);
0065     inline void setListHidden(bool h);
0066     inline void setListRecursively(bool r);
0067 
0068 Q_SIGNALS:
0069     void listerDone(ThreadedLister *);
0070 
0071 protected:
0072     void run();
0073 
0074 private Q_SLOTS:
0075     void completed();
0076 
0077     void foundItem(KIO::Job *, const KIO::UDSEntryList &list);
0078 
0079 private:
0080     static QMutex     s_mutex; ///< Mutex assuring that only one thread at a time will work on m_model
0081 
0082     QUrl              m_dirname;
0083     QString           m_filter;
0084     bool              m_listHiddenFiles;
0085     bool              m_listRecursive;
0086     bool              m_listDirnamesOnly;
0087     bool              m_listDirnames;
0088 
0089     QWidget          *m_cache;
0090     KRenameModel     *m_model;
0091     KRenameFile::List m_files;
0092 
0093     ESplitMode        m_eSplitMode;
0094     unsigned int      m_dot;
0095 };
0096 
0097 void ThreadedLister::setListDirnames(bool names)
0098 {
0099     m_listDirnames = names;
0100 }
0101 
0102 void ThreadedLister::setListDirnamesOnly(bool names)
0103 {
0104     m_listDirnamesOnly = names;
0105 }
0106 
0107 void ThreadedLister::setFilter(const QString &filter)
0108 {
0109     m_filter = filter;
0110 }
0111 
0112 void ThreadedLister::setListHidden(bool h)
0113 {
0114     m_listHiddenFiles = h;
0115 }
0116 
0117 void ThreadedLister::setListRecursively(bool r)
0118 {
0119     m_listRecursive = r;
0120 }
0121 
0122 #endif