~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to juk/k3bexporter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
// instance of this action for many playlists.
45
45
//
46
46
// This is used to handle some actions in the Playlist context menu.
47
 
class PlaylistAction : public KAction
48
 
{
49
 
    public:
50
 
    PlaylistAction(const QString &userText,
51
 
                   const QIcon &pix,
52
 
                   const char *slot,
53
 
                   const KShortcut &cut = KShortcut()) :
54
 
        KAction(userText, actions()),
55
 
        m_slot(slot)
56
 
    {
57
 
        setShortcut(cut);
58
 
        QAction::setIcon(pix);
59
 
    }
60
 
 
61
 
    typedef QMap<const Playlist *, QObject *> PlaylistRecipientMap;
62
 
 
63
 
    /**
64
 
     * Defines a QObject to call (using the m_slot SLOT) when an action is
65
 
     * emitted from a Playlist.
66
 
     */
67
 
    void addCallMapping(const Playlist *p, QObject *obj)
68
 
    {
69
 
        m_playlistRecipient[p] = obj;
70
 
    }
71
 
 
72
 
    protected slots:
73
 
    void slotActivated()
74
 
    {
75
 
        // Determine current playlist, and call its slot.
76
 
        Playlist *p = PlaylistCollection::instance()->visiblePlaylist();
77
 
        if(!p)
78
 
            return;
79
 
 
80
 
        // Make sure we're supposed to notify someone about this playlist.
81
 
        QObject *recipient = m_playlistRecipient[p];
82
 
        if(!recipient)
83
 
            return;
84
 
 
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);
90
 
    }
91
 
 
92
 
    private:
93
 
    QByteArray m_slot;
94
 
    PlaylistRecipientMap m_playlistRecipient;
95
 
};
 
47
 
 
48
PlaylistAction::PlaylistAction(const QString &userText,
 
49
                const QIcon &pix,
 
50
                const char *slot,
 
51
                const KShortcut &cut) :
 
52
    KAction(userText, actions()),
 
53
    m_slot(slot)
 
54
{
 
55
    setShortcut(cut);
 
56
    QAction::setIcon(pix);
 
57
    connect(this, SIGNAL(triggered()), this, SLOT(slotActivated()));
 
58
}
 
59
 
 
60
/**
 
61
 * Defines a QObject to call (using the m_slot SLOT) when an action is
 
62
 * emitted from a Playlist.
 
63
 */
 
64
void PlaylistAction::addCallMapping(const Playlist *p, QObject *obj)
 
65
{
 
66
    m_playlistRecipient[p] = obj;
 
67
}
 
68
 
 
69
void PlaylistAction::slotActivated()
 
70
{
 
71
    // Determine current playlist, and call its slot.
 
72
    Playlist *p = PlaylistCollection::instance()->visiblePlaylist();
 
73
    if(!p)
 
74
        return;
 
75
    // Make sure we're supposed to notify someone about this playlist.
 
76
    QObject *recipient = m_playlistRecipient[p];
 
77
    if(!recipient)
 
78
        return;
 
79
    // Invoke the slot using some trickery.
 
80
    recipient->metaObject()->invokeMethod(recipient, m_slot);
 
81
}
96
82
 
97
83
K3bExporter::K3bExporter(Playlist *parent) : PlaylistExporter(parent), m_parent(parent)
98
84
{
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"),
106
 
            KIcon("k3b"),
107
 
            SLOT(slotExport())
 
92
            KIcon( QLatin1String( "k3b" )),
 
93
            "slotExport"
108
94
        );
109
 
 
110
95
        m_action->setShortcutConfigurable(false);
111
96
    }
112
 
 
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.
116
100
    if(m_action)
117
101
        m_action->addCallMapping(m_parent, this);
118
 
 
119
102
    return m_action;
120
103
}
121
104
 
123
106
{
124
107
    if(items.empty())
125
108
        return;
126
 
#ifdef __GNUC__
127
 
#warning "kde4: port it when k3b will port"
128
 
#endif
129
 
#if 0
130
 
    DCOPClient *client = DCOPClient::mainClient();
131
 
    DCOPCString appId, appObj;
132
 
    QByteArray data;
133
 
 
134
 
    if(!client->findObject("k3b-*", "K3bInterface", "", data, appId, appObj))
135
 
        exportViaCmdLine(items);
136
 
    else {
137
 
        DCOPRef ref(appId, appObj);
138
 
        exportViaDCOP(items, ref);
139
 
    }
140
 
#endif
 
109
    exportViaCmdLine(items);
141
110
}
142
111
 
143
112
void K3bExporter::slotExport()
157
126
        break;
158
127
 
159
128
    case DataCD:
160
 
        cmdOption = "--datacd";
 
129
        cmdOption = "--data";
161
130
        break;
162
131
 
163
132
    case Abort:
177
146
        KMessageBox::error(m_parent, i18n("Unable to start K3b."));
178
147
}
179
148
 
180
 
#if 0
181
 
void K3bExporter::exportViaDCOP(const PlaylistItemList &items, DCOPRef &ref)
182
 
{
183
 
    Q3ValueList<DCOPRef> projectList;
184
 
    DCOPReply projectListReply = ref.call("projects()");
185
 
 
186
 
    if(!projectListReply.get<Q3ValueList<DCOPRef> >(projectList, "QValueList<DCOPRef>")) {
187
 
        DCOPErrorMessage();
188
 
        return;
189
 
    }
190
 
 
191
 
    if(projectList.count() == 0 && !startNewK3bProject(ref))
192
 
        return;
193
 
 
194
 
    KUrl::List urlList;
195
 
    PlaylistItemList::ConstIterator it;
196
 
 
197
 
    for(it = items.begin(); it != items.end(); ++it) {
198
 
        KUrl item;
199
 
 
200
 
        item.setPath((*it)->file().absFilePath());
201
 
        urlList.append(item);
202
 
    }
203
 
 
204
 
    if(!ref.send("addUrls(KUrl::List)", DCOPArg(urlList, "KUrl::List"))) {
205
 
        DCOPErrorMessage();
206
 
        return;
207
 
    }
208
 
}
209
 
 
210
 
void K3bExporter::DCOPErrorMessage()
211
 
{
212
 
    KMessageBox::error(m_parent, i18n("There was a DCOP communication error with K3b."));
213
 
}
214
 
 
215
 
bool K3bExporter::startNewK3bProject(DCOPRef &ref)
216
 
{
217
 
    Q3CString request;
218
 
    K3bOpenMode mode = openMode();
219
 
 
220
 
    switch(mode) {
221
 
    case AudioCD:
222
 
        request = "createAudioCDProject()";
223
 
        break;
224
 
 
225
 
    case DataCD:
226
 
        request = "createDataCDProject()";
227
 
        break;
228
 
 
229
 
    case Abort:
230
 
        return false;
231
 
    }
232
 
 
233
 
    if(!ref.send(request)) {
234
 
        DCOPErrorMessage();
235
 
        return false;
236
 
    }
237
 
 
238
 
    return true;
239
 
}
240
 
#endif
241
149
K3bExporter::K3bOpenMode K3bExporter::openMode()
242
150
{
243
151
    int reply = KMessageBox::questionYesNoCancel(
272
180
KAction *K3bPlaylistExporter::action()
273
181
{
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"),
277
185
            actions()
278
186
        );