44
44
// instance of this action for many playlists.
46
46
// This is used to handle some actions in the Playlist context menu.
47
class PlaylistAction : public KAction
50
PlaylistAction(const QString &userText,
53
const KShortcut &cut = KShortcut()) :
54
KAction(userText, actions()),
58
QAction::setIcon(pix);
61
typedef QMap<const Playlist *, QObject *> PlaylistRecipientMap;
64
* Defines a QObject to call (using the m_slot SLOT) when an action is
65
* emitted from a Playlist.
67
void addCallMapping(const Playlist *p, QObject *obj)
69
m_playlistRecipient[p] = obj;
75
// Determine current playlist, and call its slot.
76
Playlist *p = PlaylistCollection::instance()->visiblePlaylist();
80
// Make sure we're supposed to notify someone about this playlist.
81
QObject *recipient = m_playlistRecipient[p];
85
// Invoke the slot using some trickery.
86
// XXX: Use the QMetaObject to do this in Qt 4.
87
connect(this, SIGNAL(activated()), recipient, m_slot);
88
emit(QAction::triggered());
89
disconnect(this, SIGNAL(activated()), recipient, m_slot);
94
PlaylistRecipientMap m_playlistRecipient;
48
PlaylistAction::PlaylistAction(const QString &userText,
51
const KShortcut &cut) :
52
KAction(userText, actions()),
56
QAction::setIcon(pix);
57
connect(this, SIGNAL(triggered()), this, SLOT(slotActivated()));
61
* Defines a QObject to call (using the m_slot SLOT) when an action is
62
* emitted from a Playlist.
64
void PlaylistAction::addCallMapping(const Playlist *p, QObject *obj)
66
m_playlistRecipient[p] = obj;
69
void PlaylistAction::slotActivated()
71
// Determine current playlist, and call its slot.
72
Playlist *p = PlaylistCollection::instance()->visiblePlaylist();
75
// Make sure we're supposed to notify someone about this playlist.
76
QObject *recipient = m_playlistRecipient[p];
79
// Invoke the slot using some trickery.
80
recipient->metaObject()->invokeMethod(recipient, m_slot);
97
83
K3bExporter::K3bExporter(Playlist *parent) : PlaylistExporter(parent), m_parent(parent)
103
89
if(!m_action && !KStandardDirs::findExe("k3b").isNull()) {
104
90
m_action = new PlaylistAction(
105
91
i18n("Add Selected Items to Audio or Data CD"),
92
KIcon( QLatin1String( "k3b" )),
110
95
m_action->setShortcutConfigurable(false);
113
97
// Tell the action to let us know when it is activated when
114
98
// m_parent is the visible playlist. This allows us to reuse the
115
99
// action to avoid duplicate entries in KActionCollection.
117
101
m_action->addCallMapping(m_parent, this);
124
107
if(items.empty())
127
#warning "kde4: port it when k3b will port"
130
DCOPClient *client = DCOPClient::mainClient();
131
DCOPCString appId, appObj;
134
if(!client->findObject("k3b-*", "K3bInterface", "", data, appId, appObj))
135
exportViaCmdLine(items);
137
DCOPRef ref(appId, appObj);
138
exportViaDCOP(items, ref);
109
exportViaCmdLine(items);
143
112
void K3bExporter::slotExport()
177
146
KMessageBox::error(m_parent, i18n("Unable to start K3b."));
181
void K3bExporter::exportViaDCOP(const PlaylistItemList &items, DCOPRef &ref)
183
Q3ValueList<DCOPRef> projectList;
184
DCOPReply projectListReply = ref.call("projects()");
186
if(!projectListReply.get<Q3ValueList<DCOPRef> >(projectList, "QValueList<DCOPRef>")) {
191
if(projectList.count() == 0 && !startNewK3bProject(ref))
195
PlaylistItemList::ConstIterator it;
197
for(it = items.begin(); it != items.end(); ++it) {
200
item.setPath((*it)->file().absFilePath());
201
urlList.append(item);
204
if(!ref.send("addUrls(KUrl::List)", DCOPArg(urlList, "KUrl::List"))) {
210
void K3bExporter::DCOPErrorMessage()
212
KMessageBox::error(m_parent, i18n("There was a DCOP communication error with K3b."));
215
bool K3bExporter::startNewK3bProject(DCOPRef &ref)
218
K3bOpenMode mode = openMode();
222
request = "createAudioCDProject()";
226
request = "createDataCDProject()";
233
if(!ref.send(request)) {
241
149
K3bExporter::K3bOpenMode K3bExporter::openMode()
243
151
int reply = KMessageBox::questionYesNoCancel(
272
180
KAction *K3bPlaylistExporter::action()
274
182
if(!KStandardDirs::findExe("k3b").isNull()) {
275
KAction *action = new KAction(KIcon("k3b"),
183
KAction *action = new KAction(KIcon( QLatin1String( "k3b" )),
276
184
i18n("Add Playlist to Audio or Data CD"),