summaryrefslogtreecommitdiffstats
path: root/amarok/src/mediadevice/ifp/ifpmediadevice.h
blob: 9dcffbe617cdbe90f4f9fda61661f20aadb8c68c (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
/***************************************************************************
 * copyright            : (C) 2005-2006 Seb Ruiz <me@sebruiz.net>          *
 *                                                                         *
 * With some code helpers from KIO_IFP                                     *
 *                        (c) 2004 Thomas Loeber <ifp@loeber1.de>          *
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 AMAROK_IFPMEDIADEVICE_H
#define AMAROK_IFPMEDIADEVICE_H

extern "C" {
    #include <ifp.h>
    #include <usb.h>
}

#include "mediabrowser.h"

#include <kurl.h>

#include <tqptrlist.h>

class IfpMediaItem;
class TransferDialog;

class IfpMediaDevice : public MediaDevice
{
    Q_OBJECT
  TQ_OBJECT

    public:
                          IfpMediaDevice();
        void              init( MediaBrowser* parent );
        virtual           ~IfpMediaDevice();

        bool              isConnected() { return m_connected; }
        void              rmbPressed( TQListViewItem* qitem, const TQPoint& point, int );
        bool              hasTransferDialog() { return true; }
        void              runTransferDialog();
        TransferDialog   *getTransferDialog() { return m_td; }

    protected:
        bool              openDevice( bool silent=false );
        bool              closeDevice();

        bool              lockDevice( bool ) { return true; }
        void              unlockDevice() {}
        void              synchronizeDevice() {}

        MediaItem        *copyTrackToDevice( const MetaBundle& bundle);
        int               deleteItemFromDevice( MediaItem *item, int flags=DeleteTrack );
        bool              getCapacity( KIO::filesize_t *total, KIO::filesize_t *available );
        MediaItem        *newDirectory( const TQString &name, MediaItem *parent );
        void              addToDirectory( MediaItem *directory, TQPtrList<MediaItem> items );

    protected slots:
        void              renameItem( TQListViewItem *item );
        void              expandItem( TQListViewItem *item );

    private:
        enum              Error { ERR_ACCESS_DENIED, ERR_CANNOT_RENAME, ERR_DISK_FULL, ERR_COULD_NOT_WRITE };

        // Too expensive to implement on a non-database device
        MediaItem        *trackExists( const MetaBundle& ) { return 0; }

        bool              checkResult( int result, TQString message );

        // file transfer
        MediaItem        *newDirectoryRecursive( const TQString &name, MediaItem *parent );
        int               uploadTrack( const TQCString& src, const TQCString& dest );
        void              downloadSelectedItems();
        int               downloadTrack( const TQCString& src, const TQCString& dest );

        // listDir
        void              listDir( const TQString &dir );
        static int        listDirCallback( void *pData, int type, const char *name, int size );
        int               addTrackToList( int type, TQString name, int size=0 );

        // miscellaneous methods
        static int        filetransferCallback( void *pData, struct ifp_transfer_status *progress );
        int               setProgressInfo( struct ifp_transfer_status *progress );
        // Will iterate over parents and add directory name to the item.
        // getFilename = false will return only parent structure, as opposed to returning the filename as well
        TQString           getFullPath( const TQListViewItem *item, const bool getFilename = true );
        TQString           cleanPath( const TQString &component );
        
        MediaItem        *findChildItem( const TQString &name, MediaItem *parent );

        // IFP device
        struct usb_device *m_dev;
        usb_dev_handle    *m_dh;
        struct ifp_device  m_ifpdev;

        bool               m_connected;

        IfpMediaItem      *m_last;
        //used to specify new IfpMediaItem parent. Make sure it is restored to 0 (m_listview)
        TQListViewItem     *m_tmpParent;
        TransferDialog    *m_td;
};

#endif /*AMAROK_IFPMEDIADEVICE_H*/