Make plasma libs build.
[amarok.git] / src / mediadevice / njb / njbmediadevice.h
blobd3678fb05583bbdd0db5fc68deb38d318ce444e4
1 /***************************************************************************
2 copyright : (C) 2006 by Andres Oton
3 email : andres.oton@gmail.com
5 copyright : (C) 2006 by T.R.Shashwath
6 email : trshash84@gmail.com
7 ***************************************************************************/
9 /***************************************************************************
10 * This library is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License version 2 as *
12 * published by the Free Software Foundation. *
13 * *
14 * This library is distributed in the hope that it will be useful, but *
15 * WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
17 * Lesser General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License *
20 * along with this library; if not, write to the Free Software *
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
22 * MA 02110-1301 USA *
23 ***************************************************************************/
25 #ifndef NJBMEDIADEVICE_H
26 #define NJBMEDIADEVICE_H
28 #include <mediabrowser.h>
29 #include <transferdialog.h>
30 #include <libnjb.h>
32 #include <q3ptrlist.h>
33 #include <q3listview.h>
36 #include "track.h"
38 #include <QByteArray>
39 #include <QString>
40 #include <q3valuelist.h>
42 // kde
43 #include <kurl.h>
44 #include <kio/global.h>
45 #include <kio/slavebase.h>
47 /**
48 This class is used to manipulate Nomad Creative Jukebox and others media player that works with the njb libraries.
50 You can find the njb libs at : http://libnjb.sourceforge.net
52 Based on kionjb
54 @author Andres Oton <andres.oton@gmail.com>
55 @author T.R.Shashwath <trshash84@gmail.com>
58 const int NJB_SUCCESS = 0;
59 const int NJB_FAILURE = -1;
61 // Global track list
62 extern trackValueList* theTracks;
64 class NjbMediaItem : public MediaItem
66 public:
67 explicit NjbMediaItem( Q3ListView *parent, Q3ListViewItem *after = 0 ) : MediaItem( parent, after )
70 explicit NjbMediaItem( Q3ListViewItem *parent, Q3ListViewItem *after = 0 ) : MediaItem( parent, after )
73 ~NjbMediaItem()
75 //m_track->removeItem(this);
78 void setTrack( NjbTrack *track ) { m_track = track; m_track->addItem(this); }
79 NjbTrack *track() { return m_track; }
80 QString filename() { return m_track->bundle()->url().path(); }
81 private:
82 NjbTrack *m_track;
85 class NjbMediaDevice : public MediaDevice
87 Q_OBJECT
89 public:
90 NjbMediaDevice();
92 ~NjbMediaDevice();
94 virtual bool isConnected();
95 virtual bool isPlayable(const MetaBundle& bundle);
96 virtual bool isPreferredFormat(const MetaBundle& bundle);
98 // virtual bool needsManualConfig();
100 virtual MediaItem* newPlaylist(const QString& name, MediaItem* parent, Q3PtrList< MediaItem > items);
102 // virtual MediaItem* tagsChanged(MediaItem* item, const MetaBundle& changed);
104 virtual QStringList supportedFiletypes();
106 virtual bool hasTransferDialog() { return true; }
107 virtual TransferDialog* getTransferDialog();
108 virtual void addConfigElements(QWidget* arg1);
109 virtual void addToDirectory(MediaItem* directory, Q3PtrList< MediaItem > items) { Q_UNUSED(directory) Q_UNUSED(items) }
110 virtual void addToPlaylist(MediaItem* playlist, MediaItem* after, Q3PtrList< MediaItem > items);
111 virtual void applyConfig();
112 virtual void init(MediaBrowser* parent);
113 virtual void loadConfig();
114 virtual void removeConfigElements(QWidget* arg1);
115 virtual void rmbPressed(Q3ListViewItem* qitem, const QPoint& point, int arg1);
116 virtual void runTransferDialog();
117 virtual void customClicked();
119 void setDeviceType(const QString& type);
120 void setSpacesToUnderscores(bool yesno);
121 static njb_t *theNjb();
122 public slots:
123 void expandItem( Q3ListViewItem *item );
125 protected:
127 virtual bool closeDevice();
128 virtual bool getCapacity(KIO::filesize_t* total, KIO::filesize_t* available);
130 // virtual bool isSpecialItem(MediaItem* item);
132 virtual bool lockDevice(bool tryOnly);
133 virtual bool openDevice(bool silent);
135 int deleteFromDevice(unsigned id);
136 int deleteItemFromDevice(MediaItem* item, int flags=DeleteTrack );
137 int deleteTrack(NjbMediaItem *trackItem);
139 int downloadSelectedItems();
140 int downloadToCollection();
142 virtual MediaItem* copyTrackToDevice(const MetaBundle& bundle);
143 virtual void copyTrackFromDevice(MediaItem *item);
145 virtual void cancelTransfer();
146 virtual void synchronizeDevice() {};
148 virtual void unlockDevice();
150 virtual void updateRootItems() {};
152 private:
153 // TODO:
154 MediaItem *trackExists( const MetaBundle& );
155 // miscellaneous methods
156 static int progressCallback( u_int64_t sent, u_int64_t total, const char* /*buf*/, unsigned /*len*/, void* data);
158 int readJukeboxMusic( void);
159 void clearItems();
161 NjbMediaItem *addTrackToView(NjbTrack *track, NjbMediaItem *item=0);
162 NjbMediaItem* addAlbums( const QString &artist, NjbMediaItem *item );
163 NjbMediaItem* addTracks( const QString &artist, const QString &track, NjbMediaItem *item );
164 NjbMediaItem* addTrack( NjbTrack *track );
165 NjbMediaItem* addArtist( NjbTrack *track );
166 TransferDialog *m_td;
168 Q3ListView *listAmarokPlayLists;
169 QString devNode;
170 QString m_errMsg;
171 bool m_connected; // Replaces m_captured from the original code.
173 njb_t njbs[NJB_MAX_DEVICES];
174 static njb_t* m_njb;
175 trackValueList trackList;
177 int m_libcount;
178 bool m_busy;
179 unsigned m_progressStart;
180 QString m_progressMessage;
181 NjbMediaItem *m_artistItem;
182 NjbMediaItem *m_albumItem;
183 NjbMediaItem *m_allTracksItem;
186 #endif