1 
2 #ifndef CDOPENER_H
3 #define CDOPENER_H
4 
5 #include <KDialog>
6 #include <QTimer>
7 
8 #include <KCddb/Kcddb>
9 #include <KCddb/Client>
10 #include <KCddb/Cdinfo>
11 
12 extern "C"
13 {
14 #include <cdda_interface.h>
15 #include <cdda_paranoia.h>
16 }
17 
18 #include <phonon/audiooutput.h>
19 #include <phonon/seekslider.h>
20 #include <phonon/mediaobject.h>
21 #include <phonon/volumeslider.h>
22 #include <phonon/backendcapabilities.h>
23 #include <phonon/MediaController>
24 
25 
26 class TagEngine;
27 class Config;
28 class Options;
29 class ConversionOptions;
30 class QTreeWidget;
31 class KPushButton;
32 class KLineEdit;
33 class KComboBox;
34 class KIntSpinBox;
35 class KTextEdit;
36 class QGroupBox;
37 class QTreeWidgetItem;
38 class QLabel;
39 class QCheckBox;
40 class TagData;
41 
42 
43 class PlayerWidget : public QWidget
44 {
45      Q_OBJECT
46 public:
47     PlayerWidget( Phonon::MediaObject *mediaObject, int _track, QTreeWidgetItem *_treeWidgetItem, QWidget *parent, Qt::WindowFlags f = 0 );
48     ~PlayerWidget();
49 
50     void trackChanged( int track );
isPlaying()51     bool isPlaying() { return playing; }
treeWidgetItem()52     QTreeWidgetItem *treeWidgetItem() { return m_treeWidgetItem; }
53 
54 private:
55     int track;
56     bool playing;
57     QTreeWidgetItem *m_treeWidgetItem;
58 
59     KPushButton *pStartPlayback;
60     KPushButton *pStopPlayback;
61     Phonon::SeekSlider *seekSlider;
62 
63 private slots:
64     void startPlaybackClicked();
65     void stopPlaybackClicked();
66 
67 signals:
68     void startPlayback( int track );
69     void stopPlayback();
70 };
71 
72 
73 /**
74  * @short Shows a dialog for selecting files from a CD
75  * @author Daniel Faust <hessijames@gmail.com>
76  * @version 1.0
77  */
78 class CDOpener : public KDialog
79 {
80      Q_OBJECT
81 public:
82     enum DialogPage {
83         CdOpenPage,
84         ConversionOptionsPage
85     };
86 
87     enum Columns {
88         Column_Rip      = 0,
89         Column_Track    = 1,
90         Column_Artist   = 2,
91         Column_Composer = 3,
92         Column_Title    = 4,
93         Column_Length   = 5,
94         Column_Player   = 6
95     };
96 
97     /** Constructor */
98     CDOpener( Config *_config, const QString& _device, QWidget *parent, Qt::WFlags f=0 );
99 
100     /** Destructor */
101     ~CDOpener();
102 
103     /** true if no CD was found (don't execute the dialog) */
104     bool noCdFound;
105 
106 public slots:
107     /** Set the current profile */
108     void setProfile( const QString& profile );
109 
110     /** Set the current format */
111     void setFormat( const QString& format );
112 
113     /** Set the current output directory */
114     void setOutputDirectory( const QString& directory );
115 
116     /** Set the command to execute after the conversion is complete */
117     void setCommand( const QString& _command );
118 
119 private:
120     /** returns a list of devices holding audio cds plus a short description (track count) */
121     QMap<QString,QString> cdDevices();
122     bool openCdDevice( const QString& _device );
123     int cdda_audio_tracks( cdrom_drive *cdDrive ) const;
124 
125     /** the widget for selecting and editing the cd tracks */
126     QWidget *cdOpenerWidget;
127     /** the widget for showing the progress of reading the cd / cddb data */
128     QWidget *cdOpenerOverlayWidget;
129     /** the conversion options editor widget */
130     Options *options;
131     /** the current page */
132     DialogPage page;
133 
134     QLabel *lSelector;
135     QLabel *lOptions;
136 
137     /** A list of all tracks on the CD */
138     QTreeWidget *trackList;
139 
140     /** A combobox for entering the artist or selecting VA of the whole CD */
141     KLineEdit *lArtist;
142     /** A lineedit for entering the album name */
143     KLineEdit *lAlbum;
144     /** A spinbox for entering or selecting the disc number */
145     KIntSpinBox *iDisc;
146     /** A spinbox for entering or selecting the total disc number */
147     KIntSpinBox *iDiscTotal;
148     /** A spinbox for entering or selecting the year of the album */
149     KIntSpinBox *iYear;
150     /** A combobox for entering or selecting the genre of the album */
151     KComboBox *cGenre;
152 
153     /** The groupbox shows the selected track numbers */
154     QGroupBox *tagGroupBox;
155 
156     /** Set the focus of the tag editor to the track over it */
157     KPushButton *pTrackUp;
158     /** Set the focus of the tag editor to the track under it */
159     KPushButton *pTrackDown;
160 
161     /** A lineedit for entering the title of track */
162     KLineEdit *lTrackTitle;
163     KPushButton *pTrackTitleEdit;
164     /** A lineedit for entering the artist of a track */
165     KLineEdit *lTrackArtist;
166     KPushButton *pTrackArtistEdit;
167     /** A lineedit for entering the composer of a track */
168     KLineEdit *lTrackComposer;
169     KPushButton *pTrackComposerEdit;
170     /** A textedit for entering a comment for a track */
171     KTextEdit *tTrackComment;
172     KPushButton *pTrackCommentEdit;
173 
174     Phonon::AudioOutput *audioOutput;
175     Phonon::MediaObject *mediaObject;
176     Phonon::MediaController *mediaController;
177     Phonon::MediaSource *mediaSource;
178 
179     QList<PlayerWidget*> playerWidgets;
180 
181     /** Save the tag information to a cue file */
182     KPushButton *pSaveCue;
183     /** Request CDDB information */
184     KPushButton *pCDDB;
185     /** Rip enitre CD as one track */
186     QCheckBox *cEntireCd;
187     /** Add selected tracks to the file list and quit the dialog */
188     KPushButton *pAdd;
189     /** proceed to select conversion options */
190     KPushButton *pProceed;
191     /** Quit the dialog */
192     KPushButton *pCancel;
193 
194     Config *config;
195 
196     QString device;
197 
198     cdrom_drive *cdDrive;
199     cdrom_paranoia *cdParanoia;
200 
201 //     void *wmHandle;
202 
203     KCDDB::Client *cddb;
204 
205     QList<TagData*> tags; // @0 disc tags
206     bool cdTextFound;
207     bool cddbFound;
208 
209     QString lastAlbumArtist;
210 
211     QTimer timeoutTimer;
212 
213     QList<int> selectedTracks;
214 
215     /** Show the progress of reading the cd / cddb data */
216     QLabel *lOverlayLabel;
217 
218     QTimer fadeTimer;
219     float fadeAlpha;
220     int fadeMode; // 1 = fade in, 2 = fade out
221 
222     QString command;
223 
brushSetAlpha(QBrush brush,const int alpha)224     inline QBrush brushSetAlpha( QBrush brush, const int alpha )
225     {
226         QColor color = brush.color();
227         color.setAlpha( alpha );
228         brush.setColor( color );
229         return brush;
230     }
231 
232     void fadeIn();
233     void fadeOut();
234 
235     void adjustArtistColumn();
236     void adjustComposerColumn();
237 
238 private slots:
239     void requestCddb( bool autoRequest = false );
240     void lookup_cddb_done( KCDDB::Result result );
241     void timeout();
242 
243     void trackChanged();
244     void trackUpPressed();
245     void trackDownPressed();
246     void artistChanged( const QString& text );
247     void trackTitleChanged( const QString& text );
248     void trackArtistChanged( const QString& text );
249     void trackComposerChanged( const QString& text );
250     void trackCommentChanged();
251     void editTrackTitleClicked();
252     void editTrackArtistClicked();
253     void editTrackComposerClicked();
254     void editTrackCommentClicked();
255 //     void itemHighlighted( QTreeWidgetItem *item, int column );
256 
257     void startPlayback( int track );
258     void stopPlayback();
259     void playbackTitleChanged( int title );
260     void playbackStateChanged( Phonon::State newstate, Phonon::State oldstate );
261 
262     void proceedClicked();
263     void addClicked();
264 //     void addAsOneTrackClicked();
265     void saveCuesheetClicked();
266 
267     void fadeAnim();
268 
269 signals:
270     void addTracks( const QString& device, QList<int> trackList, int tracks, QList<TagData*> tagList, ConversionOptions *conversionOptions, const QString& command );
271     void addDisc( const QString& device, ConversionOptions *conversionOptions );
272     //void openCuesheetEditor( const QString& content );
273 };
274 
275 #endif // CDOPENER_H
276