summaryrefslogtreecommitdiffstats
path: root/krename/kmylistbox.h
blob: ccb584f40803843aaf67631dfbf9657670ac44cf (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/***************************************************************************
                          kmylistbox.h  -  description
                             -------------------
    begin                : Tue Oct 16 2001
    copyright            : (C) 2001 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 KMYLISTBOX_H
#define KMYLISTBOX_H

// KDE includes
#include <tdelistbox.h>
#include <kurl.h>
#include <tdefileitem.h>

// TQt includes
#include <tqmutex.h>
#include <tqstringlist.h>

class ThreadedLister;

class KFileItem;
class KURLLabel;
class TQDragObject;
class TQPixmap;
class TQPainter;
class TQPoint;
class KMyListBox : public TDEListBox  {
    Q_OBJECT
  
    public:
        enum { ASCENDING = 1, DESCENDING = 2, RANDOM = 3, NUMMERIC = 4, UNSORTED = 0 };

        KMyListBox(TQWidget* parent=0, const char* name=0, WFlags fl=0);
        ~KMyListBox();

        void removeItem( int index );
        void addDir( const KURL & dirname, const TQString & m_filter, bool m_hidden, bool recursively, bool dirnames = false );
        void addDirName( const KURL & dirname, const TQString & m_filter, bool m_hidden, bool recursive = false );
        void setPreview( bool prv );

        inline int sorting() const { return m_sorting; }
        
        void setName( bool name );

        void move( int i );
        void setPreviewSize( int size );
        inline int getPreviewSize() const { return previewSize; }

        KURL url( int index ) const;
        bool dir( int index ) const;

        bool isFile( const KURL & f, bool autoadd = true );
        void positionLabel();
        
        void clear();

        /**
         * returns the number of currently running ThreadedListers for adding files
         * or 0 if there is no file adding in progress right now.
         */
        unsigned int runningAddListeners();

    public slots:
        void moveMode();
        void moveDown();
        void moveDown( int i );
        void moveUp();
        void moveUp( int i );
        void setSorting( int s );

        void addFile( const KURL & filename, bool isfile = false );
        void addDirName( const KURL & dirname );

    signals:
        // emited when new item is drag'n'dropped into listobox
        // or when files are removed or something similar
        void updateCount();
        void updatePreview();
        void deletePressed();
        void addFiles();
        
        void currentlyAddingFiles();

    private:
        void preview( KURL::List list );

        void dropEvent( TQDropEvent* e );
        void dragEnterEvent( TQDragEnterEvent* e );
        void viewportMousePressEvent( TQMouseEvent* e );
        void viewportMouseReleaseEvent( TQMouseEvent* e );
        void viewportMouseMoveEvent( TQMouseEvent* e );
        void keyPressEvent( TQKeyEvent* e );
        void keyReleaseEvent( TQKeyEvent* e );

        bool isInList( KURL text );

        void sortAscending();
        void sortDescending();
        void sortUnsorted();
        void sortRandom();
        void sortNummeric();
        void sortList();
        void setButtonText();
    
        int compareNummeric( const TQString & s1, const TQString & s2 );
        const TQString findNumInString( unsigned int pos, const TQString & s );
        
    private slots:
        void openFile( TQListBoxItem* item );
        void select( TQListBoxItem* item );

        void previewDone( const KFileItem* item, const TQPixmap &pixmap );
        void previewFailed( const KFileItem* item );
        void previewFinished();

        void listerDone( ThreadedLister* lister );
        
    protected:
        void resizeEvent( TQResizeEvent* e );
        void customEvent( TQCustomEvent* e );
        void paintEvent( TQPaintEvent* e );                

        bool drag;
        bool mousePressed;
        bool ctrlPressed;
        bool shiftPressed;
        bool moving;
        int previewSize;
        int m_sorting;

        unsigned int m_running_lister_counter;
        TQMutex m_add_mutex;
        
        KURLLabel* label;

        TQDragObject* drobj;
        TQPoint presspos;
};

class KMyListBoxItem : public TQListBoxItem {
    public:
        KMyListBoxItem( const KMyListBoxItem* item );
        KMyListBoxItem( const KURL&, bool );

        bool hasPreview() const { return m_has_preview; }
        
        static void setName( bool b );
        static void setPreview( bool b );
        void setPixmap( const TQPixmap & pix );

        static bool preview() { return m_preview; }
        static bool name() { return m_name; }

        inline bool dir() const { return m_dir; }
        inline KURL url() const { return m_url; }
        inline const TQPixmap* pixmap() const { return &pm; }

    private:
        TQString text() const;

    protected:
        virtual void paint( TQPainter *painter );
        virtual int width( const TQListBox* ) const;
        virtual int height( const TQListBox* lb ) const;

    private:
        KURL m_url;
        bool m_dir;
        bool m_has_preview;
        TQPixmap pm;

        static bool m_preview;
        static bool m_name;
};

#endif