summaryrefslogtreecommitdiffstats
path: root/src/filelist.h
blob: 272dd0c200636ccfbd7fe185d8a9f3d3d87f3983 (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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236


#ifndef FILELIST_H
#define FILELIST_H

#include <klistview.h>

#include "conversionoptions.h"

class CDManager;
class TagEngine;
class TagData;
class Options;
class OptionsEditor;
class Config;
class Logger;
class FormatItem; // NOTE DEBUG

class TQPainter;
class TQColorGroup;
class TQSimpleRichText;
class KProgress;
class KPopupMenu;
class KAction;
class KActionCollection;

/**
 * @short The items for the file list
 * @author Daniel Faust <hessijames@gmail.com>
 * @version 0.3
 */
class FileListItem : public KListViewItem
{
public:
    /**
     * Constructor
     * @param parent The parent list view
     */
    FileListItem( KListView* parent );

    /**
     * Constructor
     * @param parent The parent list view
     * @param after The item, the new item should be placed after
     */
    FileListItem( KListView* parent, FileListItem* after );

    /**
     * Destructor
     */
    virtual ~FileListItem();

    virtual void paintCell( TQPainter* p, const TQColorGroup& cg, int column, int width, int alignment );

    //void updateOutputCell();
    //void updateOptionsCell();

    FileListItem* nextSibling() const { return static_cast<FileListItem*>( KListViewItem::nextSibling() ); }
    FileListItem* itemAbove() { return static_cast<FileListItem*>( KListViewItem::itemAbove() ); }
    FileListItem* itemBelow() { return static_cast<FileListItem*>( KListViewItem::itemBelow() ); }
    //FileList* listView() const { return static_cast<FileList*>( KListViewItem::listView() ); }

    ConversionOptions options;  // the information we get from the options class for creating the item
    TagData* tags;              // we need to instruct the tagengine to read the tags from the file!
                                // and the user can change them!
    TQString fileName;           // just the _name_ of the file
    TQString mimeType;           // the mime type of the file
    TQString fileFormat;         // just the _format_ of the file (for easier use)
    TQString url;                // the original input file name string
    bool converting;            // is this item being converted at the moment?
    bool local;                 // is this file a local one?
    int track;                  // the number of the track, if it is on an audio cd
                                // if it is lower than 0, it isn't an audio cd track at all
    TQString device;             // the device of the audio cd
    bool ripping;               // is this track currently being ripped?

    float time;                 // the duration of the track, used for the calculation of the progress bar
    TQString notify;             // execute this command, when the file is converted
};

/**
 * @short The file list
 * @author Daniel Faust <hessijames@gmail.com>
 * @version 0.3
 */
class FileList : public KListView
{
    Q_OBJECT
  TQ_OBJECT
public:
    /**
     * Constructor
     * @param parent The parent widget
     * @param name The name of the file list
     */
    FileList( CDManager*, TagEngine*, Config*, Options*, Logger*, TQWidget *parent = 0, const char* name = 0 );

    /**
     * Destructor
     */
    virtual ~FileList();

    FileListItem* firstChild() const { return static_cast<FileListItem*>( KListView::firstChild() ); }
    FileListItem* lastItem() const { return static_cast<FileListItem*>( KListView::lastItem() ); }

    int columnByName( const TQString& name );
    void updateItem( FileListItem* item );

    bool queueEnabled() { return queue; }

    void setNotify( const TQString& cmd ) { notify = cmd; }

protected:
    virtual bool acceptDrag( TQDropEvent *e ) const;

private:
    /** Lists all file in a directory and adds them to the file list, if @p fast is false. The number of listed files is returned */
    int listDir( const TQString& directory, TQStringList filter, bool recursive = true, bool fast = false, int count = 0 );

    /** A progressbar, that is shown, when a directory is added recursive */
    KProgress* pScanStatus;

    void convertNextItem();

    void viewportPaintEvent( TQPaintEvent* );
    void viewportResizeEvent( TQResizeEvent* );

    void debug(); // NOTE DEBUG
    TQString debug_params( ConversionOptions conversionOptions, FormatItem* formatItem ); // NOTE DEBUG

    TQSimpleRichText* bubble;

    /** The context menu for editing or starting the files */
    KPopupMenu* contextMenu;

    KActionCollection* actionCollection;
    KAction* edit;
    KAction* start;
    KAction* stop;
    KAction* remove;
    KAction* paste;

    CDManager* cdManager;
    TagEngine* tagEngine;
    OptionsEditor* optionsEditor;

    Options* options;
    Config* config;
    Logger* logger;

    TQValueList<FileListItem*> selectedFiles;

    bool queue;

    /**
     * A command that should be executed after the conversion of a file is complete
     * %i will be replaced by the input file path
     * %o "    "  "        "  "   output "   "
     */
    TQString notify;

private slots:
    /*
     * The user clicked somewhere into the list view (e.g. the link in the bubble)
     */
//     void clickedSomewhere( TQListViewItem*, const TQPoint&, int );

    /**
     * We'll recive a signal, when we should show the context menu
     * @p item The item, that's context menu should be shown
     * @p point The position of the click (start position of the context menu)
     */
    void showContextMenu( TQListViewItem* item, const TQPoint& point, int );

    /**
     * Remove selected items from the file list
     */
    void removeSelectedItems();

    /**
     * Add selected items to the conversion list
     */
    void convertSelectedItems();

    /**
     * Stop the conversion of all selected items
     */
    void stopSelectedItems();

    void columnResizeEvent( int, int, int );
    void slotDropped( TQDropEvent*, TQListViewItem*, TQListViewItem* ); // NOTE rename?

public slots:
    void addFiles( TQStringList, FileListItem* after = 0, bool enabled = false ); // NOTE const TQStringList& ?
    void addDir( const TQString&, const TQStringList& filter = "", bool recursive = true );
    void addTracks( const TQString& device, TQValueList<int> );
    void addDisc( const TQString& device );
    /**
     * The conversion of an item has finished and the state is reported ( 0 = ok, -1 = error, 1 = aborted )
     */
    void itemFinished( FileListItem*, int );
    void rippingFinished( const TQString& device );
    void showOptionsEditorDialog();
    void selectPreviousItem();
    void selectNextItem();
    void itemsSelected();
    //void moveOptionsEditor( int x, int y );
    void startConversion();
    void stopConversion();
    void continueConversion();
    void killConversion();

    void load( bool autosave = false );
    void save( bool autosave = false );

signals:
    void convertItem( FileListItem* );
    void stopItem( FileListItem* );
    void editItems( TQValueList<FileListItem*> );
    void setPreviousItemEnabled( bool );
    void setNextItemEnabled( bool );
    //void moveEditor( int x, int y );
    void fileCountChanged( int );
    void startedConversion();
    void stopClicked();
    void continueClicked();
    void stoppedConversion();

    void increaseTime( float );
    void decreaseTime( float );
    //void countTime( float );
    //void setTime( float );
    void finished( float );
};

#endif // FILELIST_H