1 
2 
3 #ifndef CONVERTITEM_H
4 #define CONVERTITEM_H
5 
6 #include "pluginloader.h"
7 
8 #include <kio/job.h>
9 
10 #include <QList>
11 #include <QTime>
12 #include <QWeakPointer>
13 
14 class FileListItem;
15 class KProcess;
16 
17 
18 /**
19  * @short The items for the conversion (for every active file)
20  * @author Daniel Faust <hessijames@gmail.com>
21  */
22 class ConvertItem
23 {
24 public:
25     /**
26      * A list of flags for knowing what to do
27      */
28     enum Mode {
29         initial            = 0x0000, // Initial state
30         get                = 0x0001, // Copy the file to tmp
31         convert            = 0x0002, // Convert the file
32         rip                = 0x0004, // Ripping the file (only for the current state)
33         decode             = 0x0008, // Decoding the file (only for the current state)
34         filter             = 0x0010, // Applying filters (only for the current state)
35         encode             = 0x0020, // Encoding the file (only for the current state)
36         wait_replaygain    = 0x0040, // Wait for replaygain
37         replaygain         = 0x0080  // Apply replaygain
38 //         write_tags         = 0x0100, // Write the tags to the file
39 //         execute_userscript = 0x0200  // Run the user script
40     };
41 
42     /** Constructor, @p item a pointer to the file list item */
43     explicit ConvertItem( FileListItem *item );
44 
45     /** Destructor */
46     ~ConvertItem();
47 
48     /** a reference to the file list item, in case it's a convert item */
49     FileListItem *fileListItem;
50 
51     /** a list of conversion pipes that are suitable for this item */
52     QList<ConversionPipe> conversionPipes;
53     /** a list of replaygain pipes that are suitable for this item */
54     QList<ReplayGainPipe> replaygainPipes;
55     /** number of the current attempt to convert the file/add replaygain (for the pipes lists) */
56     int take;
57     /** number of the last try in case the conversion wasn't successful in the end */
58     int lastTake; // TODO use cleaner solution
59 
60     /** for the conversion and moving the file to a temporary place */
61     QWeakPointer<KProcess> process;
62     /** for moving the file to the temporary directory */
63     QWeakPointer<KIO::FileCopyJob> kioCopyJob;
64     /** the active plugin */
65     BackendPlugin *backendPlugin;
66     /** the id from the active plugin (-1 if false) */
67     int backendID;
68     /** the current conversion step */
69     int conversionPipesStep;
70     /** has the process been killed on purpose? */
71     bool killed;
72     /** has the internal replaygain been used in this conversion take? */
73     bool internalReplayGainUsed;
74 
75     /** the url from fileListItem or the download temp file */
76     KUrl inputUrl;
77     /** the path and the name of the output file */
78     KUrl outputUrl;
79     /** the downloaded input file */
80     KUrl tempInputUrl;
81     /** the temp files for the conversion */
82     QList<KUrl> tempConvertUrls;
83 
84     KUrl generateTempUrl( const QString& prefix, const QString& extension, bool useSharedMemory = false );
85 
86     /** what shall we do with the file? */
87     Mode mode;
88     /** and what are we doing with the file? */
89     Mode state;
90 
91     /** the id with that the item is registered at the logger */
92     int logID;
93 
94     /** the time from the file list item splitted up */
95     float getTime;
96     QList<float> convertTimes;
97     float replaygainTime;
98 
99     float finishedTime; // the time of the finished conversion steps
100 
101     void updateTimes();
102 
103     /** the current conversion progress */
104     float progress;
105 
106     QTime progressedTime;
107 };
108 
109 #endif // CONVERTITEM_H
110