Commit f7cc5737 authored by Michael Pyne's avatar Michael Pyne

Add "export to K3b" support to JuK.

* You can select songs from your playlist and export them to K3b.
* You can export an entire playlist to K3b as well.
* The feature is accessible from the appropriate context menus.
* The feature won't be visible on the menu unless K3b is in your PATH.
* K3b will be started if it's not already running.
* If no project is open in K3b, JuK will prompt you to select either an audio CD project or a data CD project. Otherwise the songs are added to the current project.

Watchers of bug 56465 will be interested in this commit.  CD Ripping hasn't
been started yet, so the bug will remain open.  Also, K3b isn't "integrated"
into JuK, JuK simply tells K3b where to find the files, and you still use K3b
as normal to burn the CD.  Still, this is very useful IMHO.

CCMAIL:56465@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=316931
parent bfb4c579
...@@ -19,6 +19,7 @@ juk_SOURCES = \ ...@@ -19,6 +19,7 @@ juk_SOURCES = \
historyplaylist.cpp \ historyplaylist.cpp \
juk.cpp \ juk.cpp \
jukIface.skel \ jukIface.skel \
k3bexporter.cpp \
keydialog.cpp \ keydialog.cpp \
main.cpp \ main.cpp \
mediafiles.cpp \ mediafiles.cpp \
......
/***************************************************************************
k3bexporter.cpp - description
-------------------
begin : Mon May 31 2004
copyright : (C) 2004 by Michael Pyne
email : pynm0001@comcast.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <kprocess.h>
#include <kmessagebox.h>
#include <kurl.h>
#include <klocale.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <kstandarddirs.h>
#include <kiconloader.h>
#include <kapplication.h>
#include <qcstring.h>
#include <dcopref.h>
#include <dcopclient.h>
#include "k3bexporter.h"
#include "playlistitem.h"
#include "playlist.h"
#include "playlistbox.h"
#include "actioncollection.h"
using ActionCollection::actions;
K3bExporter::K3bExporter(Playlist *parent) : PlaylistExporter(parent), m_parent(parent)
{
}
KAction *K3bExporter::action()
{
if(!KStandardDirs::findExe("k3b").isNull()) {
return new KAction(
i18n("Add Selected Items to K3B project"),
SmallIconSet("k3b"),
0,
this,
SLOT(slotExport()),
actions(),
"export_to_k3b"
);
}
return 0;
}
void K3bExporter::exportPlaylistItems(const PlaylistItemList &items)
{
if(items.empty())
return;
DCOPClient *client = DCOPClient::mainClient();
QCString appId, appObj;
QByteArray data;
if(!client->findObject("k3b-*", "K3bInterface", "", data, appId, appObj))
exportViaCmdLine(items);
else {
DCOPRef ref(appId, appObj);
exportViaDCOP(items, ref);
}
}
void K3bExporter::slotExport()
{
if(m_parent)
exportPlaylistItems(m_parent->selectedItems());
}
void K3bExporter::exportViaCmdLine(const PlaylistItemList &items)
{
K3bOpenMode mode = openMode();
QCString cmdOption;
switch(mode) {
case AudioCD:
cmdOption = "--audiocd";
break;
case DataCD:
cmdOption = "--datacd";
break;
case Abort:
return;
}
KProcess *process = new KProcess;
*process << "k3b";
*process << cmdOption;
PlaylistItemList::ConstIterator it;
for(it = items.begin(); it != items.end(); ++it)
*process << (*it)->file().absFilePath();
if(!process->start(KProcess::DontCare))
KMessageBox::error(m_parent, i18n("Unable to start K3B!"));
}
void K3bExporter::exportViaDCOP(const PlaylistItemList &items, DCOPRef &ref)
{
QValueList<DCOPRef> projectList;
DCOPReply projectListReply = ref.call("projects()");
if(!projectListReply.get<QValueList<DCOPRef> >(projectList, "QValueList<DCOPRef>")) {
DCOPErrorMessage();
return;
}
if(projectList.count() == 0 && !startNewK3bProject(ref))
return;
KURL::List urlList;
PlaylistItemList::ConstIterator it;
for(it = items.begin(); it != items.end(); ++it) {
KURL item;
item.setPath((*it)->file().absFilePath());
urlList.append(item);
}
if(!ref.send("addUrls(KURL::List)", DCOPArg(urlList, "KURL::List"))) {
DCOPErrorMessage();
return;
}
}
void K3bExporter::DCOPErrorMessage()
{
KMessageBox::error(m_parent, i18n("There was a DCOP Communication error with K3b!"));
}
bool K3bExporter::startNewK3bProject(DCOPRef &ref)
{
QCString request;
K3bOpenMode mode = openMode();
switch(mode) {
case AudioCD:
request = "createAudioCDProject()";
break;
case DataCD:
request = "createDataCDProject()";
break;
case Abort:
return false;
}
if(!ref.send(request)) {
DCOPErrorMessage();
return false;
}
return true;
}
K3bExporter::K3bOpenMode K3bExporter::openMode()
{
int reply = KMessageBox::questionYesNoCancel(
m_parent,
i18n("Create an audio mode CD suitable for CD players, or a data "
"mode CD suitable for computers and other digital music "
"players?"),
i18n("Create K3B project"),
i18n("Audio Mode"),
i18n("Data Mode")
);
switch(reply) {
case KMessageBox::Cancel:
return Abort;
case KMessageBox::No:
return DataCD;
case KMessageBox::Yes:
return AudioCD;
}
return Abort;
}
K3bPlaylistExporter::K3bPlaylistExporter(PlaylistBox *parent) : K3bExporter(0),
m_playlistBox(parent)
{
}
KAction *K3bPlaylistExporter::action()
{
if(!KStandardDirs::findExe("k3b").isNull()) {
return new KAction(
i18n("Add Playlist to K3B project"),
SmallIconSet("k3b"),
0,
this,
SLOT(slotExport()),
actions(),
"export_playlist_to_k3b"
);
}
return 0;
}
void K3bPlaylistExporter::slotExport()
{
if(m_playlistBox) {
setPlaylist(m_playlistBox->currentPlaylist());
exportPlaylistItems(m_playlistBox->currentPlaylist()->items());
}
}
#include "k3bexporter.moc"
// vim: set et sw=4 ts=4:
/***************************************************************************
k3bexporter.h - description
-------------------
begin : Mon May 31 2004
copyright : (C) 2004 by Michael Pyne
email : pynm0001@comcast.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef K3BEXPORTER_H
#define K3BEXPORTER_H
#include "playlistexporter.h"
#include "playlistitem.h"
class QWidget;
class DCOPRef;
class PlaylistBox;
/**
* Class that will export the selected items of a playlist to K3b.
*/
class K3bExporter : public PlaylistExporter
{
Q_OBJECT
public:
K3bExporter(Playlist *parent = 0);
/**
* Returns a KAction that can be used to invoke the export.
*
* @return action used to start the export.
*/
virtual KAction *action();
Playlist *playlist() const { return m_parent; }
void setPlaylist(Playlist *playlist) { m_parent = playlist; }
protected:
void exportPlaylistItems(const PlaylistItemList &items);
private slots:
void slotExport();
private:
enum K3bOpenMode { AudioCD, DataCD, Abort };
// Private method declarations
void exportViaCmdLine(const PlaylistItemList &items);
void exportViaDCOP(const PlaylistItemList &items, DCOPRef &ref);
void DCOPErrorMessage();
bool startNewK3bProject(DCOPRef &ref);
K3bOpenMode openMode();
// Private member variable declarations
Playlist *m_parent;
};
/**
* Class to export EVERY item in a playlist to K3b. Used with the PlaylistBox
* class to implement context-menus there.
*
* @see PlaylistBox
*/
class K3bPlaylistExporter : public K3bExporter
{
Q_OBJECT
public:
K3bPlaylistExporter(PlaylistBox *parent = 0);
virtual KAction *action();
private slots:
void slotExport();
private:
PlaylistBox *m_playlistBox;
};
#endif /* K3BEXPORTER_H */
// vim: set et ts=4 sw=4:
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "actioncollection.h" #include "actioncollection.h"
#include "juk.h" #include "juk.h"
#include "tag.h" #include "tag.h"
#include "k3bexporter.h"
#include "painteater.h" #include "painteater.h"
using namespace ActionCollection; using namespace ActionCollection;
...@@ -1529,6 +1530,11 @@ void Playlist::slotShowRMBMenu(QListViewItem *item, const QPoint &point, int col ...@@ -1529,6 +1530,11 @@ void Playlist::slotShowRMBMenu(QListViewItem *item, const QPoint &point, int col
m_rmbMenu->insertItem( m_rmbMenu->insertItem(
SmallIcon("folder_new"), i18n("Create Playlist From Selected Items"), this, SLOT(slotCreateGroup())); SmallIcon("folder_new"), i18n("Create Playlist From Selected Items"), this, SLOT(slotCreateGroup()));
K3bExporter *exporter = new K3bExporter(this);
KAction *k3bAction = exporter->action();
if(k3bAction)
k3bAction->plug(m_rmbMenu);
} }
if(!readOnly()) if(!readOnly())
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "searchplaylist.h" #include "searchplaylist.h"
#include "actioncollection.h" #include "actioncollection.h"
#include "cache.h" #include "cache.h"
#include "k3bexporter.h"
using namespace ActionCollection; using namespace ActionCollection;
...@@ -66,6 +67,9 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack, ...@@ -66,6 +67,9 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
m_contextMenu = new KPopupMenu(this); m_contextMenu = new KPopupMenu(this);
K3bPlaylistExporter *exporter = new K3bPlaylistExporter(this);
m_k3bAction = exporter->action();
action("file_new")->plug(m_contextMenu); action("file_new")->plug(m_contextMenu);
action("renamePlaylist")->plug(m_contextMenu); action("renamePlaylist")->plug(m_contextMenu);
action("editSearch")->plug(m_contextMenu); action("editSearch")->plug(m_contextMenu);
...@@ -74,6 +78,8 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack, ...@@ -74,6 +78,8 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
action("deleteItemPlaylist")->plug(m_contextMenu); action("deleteItemPlaylist")->plug(m_contextMenu);
action("file_save")->plug(m_contextMenu); action("file_save")->plug(m_contextMenu);
action("file_save_as")->plug(m_contextMenu); action("file_save_as")->plug(m_contextMenu);
if(m_k3bAction)
m_k3bAction->plug(m_contextMenu);
m_contextMenu->insertSeparator(); m_contextMenu->insertSeparator();
...@@ -520,6 +526,7 @@ void PlaylistBox::slotPlaylistChanged() ...@@ -520,6 +526,7 @@ void PlaylistBox::slotPlaylistChanged()
} }
action("reloadPlaylist")->setEnabled(allowReload); action("reloadPlaylist")->setEnabled(allowReload);
action("duplicatePlaylist")->setEnabled(!playlists.isEmpty()); action("duplicatePlaylist")->setEnabled(!playlists.isEmpty());
m_k3bAction->setEnabled(!playlists.isEmpty());
bool searchList = bool searchList =
playlists.count() == 1 && dynamic_cast<SearchPlaylist *>(playlists.front()); playlists.count() == 1 && dynamic_cast<SearchPlaylist *>(playlists.front());
......
...@@ -144,6 +144,7 @@ private: ...@@ -144,6 +144,7 @@ private:
int m_viewModeIndex; int m_viewModeIndex;
QValueList<ViewMode *> m_viewModes; QValueList<ViewMode *> m_viewModes;
KSelectAction *m_viewModeAction; KSelectAction *m_viewModeAction;
KAction *m_k3bAction;
bool m_hasSelection; bool m_hasSelection;
bool m_doingMultiSelect; bool m_doingMultiSelect;
Item *m_dropItem; Item *m_dropItem;
......
/***************************************************************************
playlistexporter.h - description
-------------------
begin : Tue Jun 1 2004
copyright : (C) 2004 by Michael Pyne
email : pynm0001@comcast.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef PLAYLISTEXPORTER_H
#define PLAYLISTEXPORTER_H
#include <qobject.h>
#include "playlistitem.h"
class KAction;
class KActionCollection;
/**
* Abstract base class to define an interface for classes that export
* PlaylistItem data.
*
* @author Michael Pyne <pynm0001@comcast.net>
* @see K3bExporter
*/
class PlaylistExporter : public QObject
{
public:
PlaylistExporter(QWidget *parent = 0) : QObject(parent) { }
virtual ~PlaylistExporter() { }
/**
* Returns a KAction that can be used to invoke the export.
* Returns 0 if it is not possible.
*
* @return pointer to a KAction that can invoke the export, or 0 on
* failure.
*/
virtual KAction *action() = 0;
};
#endif /* PLAYLISTEXPORTER_H */
// vim: set et ts=4 sw=4:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment