summaryrefslogtreecommitdiffstats
path: root/krename/threadedlister.h
blob: e99af30ff6697d7e378294321e5a593477048aed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/***************************************************************************
                          
                          threadedlister.h  -  description
                             -------------------
    begin                : Tue Feb 01 2005
    copyright            : (C) 2005 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
 
#ifndef THREADEDLISTER_H
#define THREADEDLISTER_H

#include <tqobject.h>
#include <tqthread.h>

#include <tdefileitem.h>

class KDirLister;
class KRecursiveLister;
class KMyListBox;
class TQMutex;

class FileList : public TQPtrList<KFileItem> {
    public:
        FileList() : TQPtrList<KFileItem>() {}
        FileList( KFileItemList list ) 
            : TQPtrList<KFileItem>() {
                KFileItem* it;
                for( it = list.first(); it; it = list.next() )  
                    this->append( it );
            }

    protected:
        int compareItems( TQPtrCollection::Item item1, TQPtrCollection::Item item2 ) {
            return static_cast<KFileItem*>(item1)->url().url().compare( static_cast<KFileItem*>(item2)->url().url() );
        }
        
};


class ThreadedLister : public TQObject, public TQThread
{
    Q_OBJECT
  
    public:
        ThreadedLister( TQMutex* mutex, unsigned int* counter, KMyListBox* list );
        ~ThreadedLister();

        static int TYPE() { return 51984; }
        
        inline FileList* items();
        
        inline const KURL & dirname();
        inline bool dirnames();
        inline const TQString & filter();
        inline bool hidden();
        
        inline void setDirname( const KURL & dirname );
        inline void setDirnames( bool names );        
        inline void setFilter( const TQString & filter );
        inline void setHidden( bool h );
        inline void setRecursive( bool r );
        inline void setRecursiveDirOnlyMode( bool m );
        
    signals:
        void listerDone( ThreadedLister* );
        
    protected:
        void run();
        
    private slots:
        void reclisterFinished();
        void listerFinished();
        
    private:        
        TQMutex* m_mutex;
        TQMutex* m_internal;
        unsigned int* m_counter;

        FileList m_files;
        
        KURL m_dirname;
        TQString m_filter;
        bool m_hidden;
        bool m_recursive;
        bool m_dirnames;
        bool m_dironly;
                
        KDirLister* m_lister;
        KRecursiveLister* m_reclister;
        
        KMyListBox* m_list;
};

void ThreadedLister::setDirname( const KURL & dirname )
{
    m_dirname = dirname;
}

void ThreadedLister::setDirnames( bool names )
{
    m_dirnames = names;
}

void ThreadedLister::setFilter( const TQString & filter )
{
    m_filter = filter;
}

void ThreadedLister::setHidden( bool h )
{
    m_hidden = h;
}

void ThreadedLister::setRecursive( bool r )
{
    m_recursive = r;
}

void ThreadedLister::setRecursiveDirOnlyMode( bool m )
{
    m_dironly = m;
}

FileList* ThreadedLister::items()
{
    return &m_files;
}

const KURL & ThreadedLister::dirname()
{
    return m_dirname;
}

bool ThreadedLister::dirnames()
{
    return m_dirnames;
}

const TQString & ThreadedLister::filter()
{
    return m_filter;
}

bool ThreadedLister::hidden()
{
    return m_hidden;
}

#endif