1 2 3 #ifndef CONVERT_H 4 #define CONVERT_H 5 6 #include "filelistitem.h" 7 8 #include <QProcess> 9 #include <QList> 10 #include <QMap> 11 #include <QObject> 12 #include <QTimer> 13 14 class BackendPlugin; 15 class CDManager; 16 class Config; 17 class ConvertItem; 18 class FileList; 19 class Logger; 20 21 class KJob; 22 23 24 /** 25 * @short The conversion engine 26 * @author Daniel Faust <hessijames@gmail.com> 27 */ 28 class Convert : public QObject 29 { 30 Q_OBJECT 31 public: 32 Convert( Config *_config, FileList *_fileList, Logger *_logger, QObject *parent ); 33 ~Convert(); 34 35 void cleanUp(); 36 37 private: 38 /** Copy the file with the file list item @p item to a temporary directory and download if necessary */ 39 void get( ConvertItem *item ); 40 41 /** Convert the file */ 42 void convert( ConvertItem *item ); 43 44 /** Apply a filter to the file after it has been decoded in convert() */ 45 void convertNextBackend( ConvertItem *item ); 46 47 /** Calculate replaygain tags of the file with the convert item @p item */ 48 void replaygain( ConvertItem *item ); 49 50 /** Write the tags of the file with the convert item @p item */ 51 void writeTags( ConvertItem *item ); 52 53 // /** Run the userscript for the convert item @p item */ 54 // void executeUserScript( ConvertItem *item ); 55 56 /** Decide, what to do next with out item @p item */ 57 void executeNextStep( ConvertItem *item ); 58 59 /** Make another try for @p item */ 60 void executeSameStep( ConvertItem *item ); 61 62 /** Remove item @p item and emit the state @p state */ 63 void remove( ConvertItem *item, FileListItem::ReturnCode returnCode = FileListItem::Succeeded ); 64 65 /** holds all active files */ 66 QList<ConvertItem*> items; 67 68 /** holds all items that are waiting for album gain QMap< album name,convert items list > */ 69 QMap< QString, QList<ConvertItem*> > albumGainItems; 70 71 Config *config; 72 CDManager* cdManager; 73 FileList *fileList; 74 Logger* logger; 75 QMap<int,QString> usedOutputNames; 76 77 QStringList activeVorbisGainDirectories; // vorbisgain creates temporary files with the fixed name "vorbisgain.tmp", so it must run only once per directory (https://github.com/dfaust/soundkonverter/issues/12) 78 79 struct LogQueue { 80 int id; 81 BackendPlugin *plugin; 82 QStringList messages; 83 }; 84 85 QList<LogQueue> pluginLogQueue; 86 87 QTimer updateTimer; 88 89 private slots: 90 /** The file is being moved */ 91 void kioJobProgress( KJob *job, unsigned long percent ); 92 93 /** The file has been moved */ 94 void kioJobFinished( KJob *job ); 95 96 /** Get the process' output */ 97 void processOutput(); 98 99 /** The process has exited */ 100 void processExit( int exitCode, QProcess::ExitStatus exitStatus ); 101 102 /** A plugin has finished converting a file */ 103 void pluginProcessFinished( int id, int exitCode ); 104 /** A plugin has something to log */ 105 void pluginLog( int id, const QString& message ); 106 107 /** sums up the progresses of all processes and sends it to the ProgressIndicator */ 108 void updateProgress(); 109 110 public slots: 111 // connected to FileList 112 /** Add a new @p item to the item list and start */ 113 void add( FileListItem *fileListItem ); 114 /** Stop the item with the file list item @p item in the item list and remove it */ 115 void kill( FileListItem *fileListItem ); 116 /** the file list item @p item will get removed */ 117 void itemRemoved( FileListItem *fileListItem ); 118 119 /** Change the process priorities */ 120 // void priorityChanged( int ); 121 122 signals: 123 // connected to FileList 124 /** The conversion of an item has finished and the state is reported */ 125 void finished( FileListItem *fileListItem, FileListItem::ReturnCode returnCode, bool waitingForAlbumGain = false ); 126 /** The next track from the device can be ripped while the track is being encoded */ 127 void rippingFinished( const QString& device ); 128 129 // connected to Logger 130 /** Tell the logger that the process has finished */ 131 void finishedProcess( int id, bool succeeded, bool waitingForAlbumGain = false ); 132 133 // connected to ProgressIndicator 134 void updateTime( float timeProgress ); 135 void timeFinished( float timeDelta ); 136 }; 137 138 #endif // CONVERT_H 139