summaryrefslogtreecommitdiffstats
path: root/amarok/src/mediadevice/njb/njbmediadevice.h
blob: ba2a32e8a8042a5bca21d56aa04c8bf0e4b870c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/***************************************************************************
    copyright            : (C) 2006 by Andres Oton
    email                : andres.oton@gmail.com

    copyright            : (C) 2006 by T.R.Shashwath
    email                : trshash84@gmail.com
 ***************************************************************************/

/***************************************************************************
 *   This library is free software; you can redistribute it and/or modify  *
 *   it  under the terms of the GNU General Public License version 2 as    *
 *   published by the Free Software Foundation.                            *
 *                                                                         *
 *   This library is distributed in the hope that it will be useful, but   *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this library; if not, write to the Free Software           *
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,            *
 *   MA  02110-1301  USA                                                   *
 ***************************************************************************/

#ifndef NJBMEDIADEVICE_H
#define NJBMEDIADEVICE_H

#include <mediabrowser.h>
#include <transferdialog.h>
#include <libnjb.h>

#include <tqptrlist.h>
#include <tqlistview.h>

#include "playlist.h"
#include "track.h"

#include <tqcstring.h>
#include <tqstring.h>
#include <tqvaluelist.h>

// kde
#include <kurl.h>
#include <kio/global.h>
#include <kio/slavebase.h>

/**
  This class is used to manipulate Nomad Creative Jukebox and others media player that works with the njb libraries.

  You can find the njb libs at : http://libnjb.sourceforge.net

  Based on kionjb

  @author Andres Oton <andres.oton@gmail.com>
  @author T.R.Shashwath <trshash84@gmail.com>
 */

const int NJB_SUCCESS = 0;
const int NJB_FAILURE = -1;

// Global track list
extern trackValueList* theTracks;

class NjbMediaItem : public MediaItem
{
    public:
        NjbMediaItem( TQListView *parent, TQListViewItem *after = 0 ) : MediaItem( parent, after )
        {}

        NjbMediaItem( TQListViewItem *parent, TQListViewItem *after = 0 ) : MediaItem( parent, after )
        {}

        ~NjbMediaItem()
        {
            //m_track->removeItem(this);
        }
        
        void setTrack( NjbTrack *track ) { m_track = track; m_track->addItem(this); }
        NjbTrack *track() { return m_track; }
        TQString filename() { return m_track->bundle()->url().path(); }
    private:
        NjbTrack *m_track;
};

class NjbMediaDevice : public MediaDevice
{
    Q_OBJECT

    public:
        NjbMediaDevice();

        ~NjbMediaDevice();

        virtual bool isConnected();
        virtual bool isPlayable(const MetaBundle& bundle);
        virtual bool isPreferredFormat(const MetaBundle& bundle);

        //    virtual bool needsManualConfig();

        virtual MediaItem* newPlaylist(const TQString& name, MediaItem* parent, TQPtrList< MediaItem > items);

        //    virtual MediaItem* tagsChanged(MediaItem* item, const MetaBundle& changed);

        virtual TQStringList supportedFiletypes();

        virtual bool hasTransferDialog() { return true; }
        virtual TransferDialog* getTransferDialog();
        virtual void addConfigElements(TQWidget* arg1);
        virtual void addToDirectory(MediaItem* directory, TQPtrList< MediaItem > items) { Q_UNUSED(directory) Q_UNUSED(items) }
        virtual void addToPlaylist(MediaItem* playlist, MediaItem* after, TQPtrList< MediaItem > items);
        virtual void applyConfig();
        virtual void init(MediaBrowser* parent);
        virtual void loadConfig();
        virtual void removeConfigElements(TQWidget* arg1);
        virtual void rmbPressed(TQListViewItem* qitem, const TQPoint& point, int arg1);
        virtual void runTransferDialog();
        virtual void customClicked();

        void setDeviceType(const TQString& type);
        void setSpacesToUnderscores(bool yesno);
        static njb_t *theNjb();
    public slots:
        void expandItem( TQListViewItem *item );
        
    protected:

        virtual bool closeDevice();
        virtual bool getCapacity(KIO::filesize_t* total, KIO::filesize_t* available);

        // virtual bool isSpecialItem(MediaItem* item);

        virtual bool lockDevice(bool tryOnly);
        virtual bool openDevice(bool silent);

        int deleteFromDevice(unsigned id);
        int deleteItemFromDevice(MediaItem* item, int flags=DeleteTrack );
        int deleteTrack(NjbMediaItem *trackItem);

        int downloadSelectedItems();
        int downloadToCollection();

        virtual MediaItem* copyTrackToDevice(const MetaBundle& bundle);
        virtual void copyTrackFromDevice(MediaItem *item);

        virtual void cancelTransfer();
        virtual void synchronizeDevice() {};

        virtual void unlockDevice();

        virtual void updateRootItems() {};
        
    private:
        // TODO:
        MediaItem        *trackExists( const MetaBundle& );
        // miscellaneous methods
        static int progressCallback( u_int64_t sent, u_int64_t total, const char* /*buf*/, unsigned /*len*/, void* data);

        int readJukeboxMusic( void);
        void clearItems();
        
        NjbMediaItem *addTrackToView(NjbTrack *track, NjbMediaItem *item=0);
        NjbMediaItem* addAlbums( const TQString &artist, NjbMediaItem *item );
        NjbMediaItem* addTracks( const TQString &artist, const TQString &track, NjbMediaItem *item );
        NjbMediaItem* addTrack( NjbTrack *track );
        NjbMediaItem* addArtist( NjbTrack *track );
        TransferDialog      *m_td;
        
        TQListView *listAmarokPlayLists;
        TQString devNode;
        TQString m_errMsg;
        bool m_connected; // Replaces m_captured from the original code.

        njb_t njbs[NJB_MAX_DEVICES];
        static njb_t* m_njb;
        trackValueList trackList;
        
        int m_libcount;
        bool m_busy;
        unsigned m_progressStart;
        TQString m_progressMessage;
        NjbMediaItem *m_artistItem;
        NjbMediaItem *m_albumItem;
        NjbMediaItem *m_allTracksItem;
};

#endif