1 /***************************************************************************
2 begin : Mon May 31 2004
3 copyright : (C) 2004 by Michael Pyne
4 (c) 2004 by Pierpaolo Di Panfilo
5 email : michael.pyne@kdemail.net
6 ***************************************************************************/
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 ***************************************************************************/
17 #include "playlistitem.h"
18 #include "querybuilder.h"
19 #include "k3bexporter.h"
22 #include <k3process.h>
23 #include <kmessagebox.h>
25 #include <kstandarddirs.h>
28 #include <QStringList>
30 #include <Q3ValueList>
33 K3bExporter
*K3bExporter::s_instance
= 0;
35 // FIXME: implement me!
37 bool K3bExporter::isAvailable() //static
39 return !KStandardDirs::findExe( "k3b" ).isNull();
42 void K3bExporter::exportTracks( const KUrl::List
&urls
, int openmode
)
47 DCOPClient
*client
= DCOPClient::mainClient();
48 QByteArray appId
, appObj
;
52 //ask to open a data or an audio cd project
53 openmode
= openMode();
55 if( !client
->findObject( "k3b-*", "K3bInterface", "", data
, appId
, appObj
) )
56 exportViaCmdLine( urls
, openmode
);
58 DCOPRef
ref( appId
, appObj
);
59 exportViaDCOP( urls
, ref
, openmode
);
63 void K3bExporter::exportCurrentPlaylist( int openmode
)
65 Playlist::instance()->burnPlaylist( openmode
);
68 void K3bExporter::exportSelectedTracks( int openmode
)
70 Playlist::instance()->burnSelectedTracks( openmode
);
73 void K3bExporter::exportAlbum( const QString
&album
, int openmode
)
75 exportAlbum( QString(), album
, openmode
);
78 void K3bExporter::exportAlbum( const QString
&artist
, const QString
&album
, int openmode
)
80 QString albumId
= QString::number( CollectionDB::instance()->albumID( album
, false, false, true ) );
82 if( !artist
.isNull() )
83 artistId
= QString::number( CollectionDB::instance()->artistID( artist
, false, false, true ) );
86 qb
.addReturnValue( QueryBuilder::tabSong
, QueryBuilder::valURL
);
87 qb
.addMatch( QueryBuilder::tabSong
, QueryBuilder::valAlbumID
, albumId
);
88 if( !artist
.isNull() )
89 qb
.addMatch( QueryBuilder::tabSong
, QueryBuilder::valArtistID
, artistId
);
90 qb
.sortBy( QueryBuilder::tabSong
, QueryBuilder::valDiscNumber
);
91 qb
.sortBy( QueryBuilder::tabSong
, QueryBuilder::valTrack
);
93 QStringList
values( qb
.run() );
95 if( !values
.isEmpty() )
102 exportTracks( urls
, openmode
);
106 void K3bExporter::exportArtist( const QString
&artist
, int openmode
)
108 const QString artistId
= QString::number( CollectionDB::instance()->artistID( artist
, false, false, true ) );
111 qb
.addReturnValue( QueryBuilder::tabSong
, QueryBuilder::valURL
);
112 qb
.addMatch( QueryBuilder::tabSong
, QueryBuilder::valArtistID
, artistId
);
113 qb
.sortBy( QueryBuilder::tabAlbum
, QueryBuilder::valName
);
114 qb
.sortBy( QueryBuilder::tabSong
, QueryBuilder::valDiscNumber
);
115 qb
.sortBy( QueryBuilder::tabSong
, QueryBuilder::valTrack
);
117 QStringList
values( qb
.run() );
119 if( !values
.isEmpty() )
126 exportTracks( urls
, openmode
);
130 void K3bExporter::exportComposer( const QString
&composer
, int openmode
)
132 const QString composerId
= QString::number( CollectionDB::instance()->composerID( composer
, false, false, true ) );
135 qb
.addReturnValue( QueryBuilder::tabSong
, QueryBuilder::valURL
);
136 qb
.addMatch( QueryBuilder::tabSong
, QueryBuilder::valComposerID
, composerId
);
137 qb
.sortBy( QueryBuilder::tabAlbum
, QueryBuilder::valName
);
138 qb
.sortBy( QueryBuilder::tabSong
, QueryBuilder::valDiscNumber
);
139 qb
.sortBy( QueryBuilder::tabSong
, QueryBuilder::valTrack
);
141 QStringList
values( qb
.run() );
143 if( !values
.isEmpty() )
150 exportTracks( urls
, openmode
);
154 void K3bExporter::exportViaCmdLine( const KUrl::List
&urls
, int openmode
)
156 QByteArray cmdOption
;
160 cmdOption
= "--audiocd";
164 cmdOption
= "--datacd";
171 K3Process
*process
= new K3Process
;
174 *process
<< cmdOption
;
176 KUrl::List::ConstIterator it
;
177 KUrl::List::ConstIterator
end( urls
.end() );
178 for( it
= urls
.begin(); it
!= end
; ++it
)
179 *process
<< ( *it
).path();
181 if( !process
->start( K3Process::DontCare
) )
182 KMessageBox::error( 0, i18n("Unable to start K3b.") );
185 void K3bExporter::exportViaDCOP( const KUrl::List
&urls
, DCOPRef
&ref
, int openmode
)
187 Q3ValueList
<DCOPRef
> projectList
;
188 DCOPReply projectListReply
= ref
.call("projects()");
190 if( !projectListReply
.get
<Q3ValueList
<DCOPRef
> >(projectList
, "QValueList<DCOPRef>") ) {
195 if( projectList
.count() == 0 && !startNewK3bProject(ref
, openmode
) )
198 if( !ref
.send( "addUrls(KUrl::List)", DCOPArg(urls
, "KUrl::List") ) ) {
204 void K3bExporter::DCOPErrorMessage()
206 KMessageBox::error( 0, i18n("There was a DCOP communication error with K3b."));
209 bool K3bExporter::startNewK3bProject( DCOPRef
&ref
, int openmode
)
212 //K3bOpenMode mode = openMode();
216 request
= "createAudioCDProject()";
220 request
= "createDataCDProject()";
227 KMessageBox::sorry(0,request
);
228 if( !ref
.send( request
) ) {
236 K3bExporter::K3bOpenMode
K3bExporter::openMode()
238 int reply
= KMessageBox::questionYesNoCancel(
240 i18n("Create an audio mode CD suitable for CD players, or a data "
241 "mode CD suitable for computers and other digital music "
243 i18n("Create K3b Project"),
249 case KMessageBox::Cancel
:
252 case KMessageBox::No
:
255 case KMessageBox::Yes
: