1 // (c) 2004 Christian Muehlhaeuser <chris@chris.de>
2 // (c) 2005 Martin Aumueller <aumuell@reserv.at>
3 // (c) 2005 Seb Ruiz <ruiz@kde.org>
4 // (c) 2006 T.R.Shashwath <trshash84@gmail.com>
5 // See COPYING file for licensing information
7 #ifndef AMAROK_MEDIABROWSER_H
8 #define AMAROK_MEDIABROWSER_H
10 #include "amarok_export.h"
12 #include "browserToolBar.h"
15 #include "pluginmanager.h"
16 #include "plugin/plugin.h" //baseclass
17 #include "scrobbler.h" //SubmitItem
19 #include <k3listview.h> //baseclass
21 #include <kio/global.h> //filesize_t
22 #include <KUrl> //stack allocated
23 #include <KVBox> //baseclass
29 #include <QPaintEvent>
54 class SpaceLabel
: public QLabel
{
56 SpaceLabel(QWidget
*parent
)
59 m_total
= m_used
= m_scheduled
= 0;
62 void paintEvent(QPaintEvent
*e
)
65 p
.fillRect(e
->rect(), palette().brush(QColorGroup::Background
));
69 int used
= int(float(m_used
)/float(m_total
)*width());
70 int scheduled
= int(float(m_used
+ m_scheduled
)/float(m_total
)*width());
74 QColor
blueish(70,120,255);
75 if(e
->rect().left() < used
)
78 if(e
->rect().right() < right
)
79 right
= e
->rect().right();
80 p
.fillRect(e
->rect().left(), e
->rect().top(),
81 used
, e
->rect().bottom()+1, QBrush(blueish
, Qt::SolidPattern
));
87 QColor
sched(70, 230, 120);
88 if(m_used
+ m_scheduled
> m_total
- m_total
/200)
90 sched
.setRgb( 255, 120, 120 );
92 int left
= e
->rect().left();
95 int right
= e
->rect().right();
98 p
.fillRect(left
, e
->rect().top(), right
, e
->rect().bottom()+1, QBrush(sched
, Qt::SolidPattern
));
101 if(m_used
+ m_scheduled
< m_total
)
103 QColor
grey(180, 180, 180);
104 int left
= e
->rect().left();
107 int right
= e
->rect().right();
108 p
.fillRect(left
, e
->rect().top(), right
, e
->rect().bottom()+1, palette().brush(QColorGroup::Background
));
111 QLabel::paintEvent(e
);
114 KIO::filesize_t m_total
;
115 KIO::filesize_t m_used
;
116 KIO::filesize_t m_scheduled
;
119 class MediaQueue
: public K3ListView
124 MediaQueue(MediaBrowser
*parent
);
125 MediaItem
*findPath( QString path
);
127 KIO::filesize_t
totalSize() const; // total size of items to transfer in KB
128 void computeSize() const; // compute total size of items to transfer in KB
129 void addItemToSize( const MediaItem
*item
) const;
130 void subtractItemFromSize( const MediaItem
*item
, bool unconditonally
=false ) const;
132 void removeSelected();
135 void load( const QString
&path
);
136 void save( const QString
&path
);
137 void syncPlaylist( const QString
&playlistName
, const QString
&sql
, bool loading
=false );
138 void syncPlaylist( const QString
&playlistName
, const KUrl
&url
, bool loading
=false );
139 void addUrl( const KUrl
& url
, Meta::TrackPtr
=Meta::TrackPtr(), const QString
&playlistName
=QString() );
140 void addUrl( const KUrl
& url
, MediaItem
*item
);
141 void addUrls( const KUrl::List urls
, const QString
&playlistName
=QString() );
143 void URLsAdded(); // call after finishing adding single urls
145 void dropProxyEvent( QDropEvent
*e
);
146 // Reimplemented from K3ListView
147 bool acceptDrag( QDropEvent
*e
) const;
148 Q3DragObject
*dragObject();
151 void itemCountChanged();
154 void selectAll() {Q3ListView::selectAll(true); }
155 void slotShowContextMenu( Q3ListViewItem
* item
, const QPoint
& point
, int );
156 void slotDropped (QDropEvent
* e
, Q3ListViewItem
* parent
, Q3ListViewItem
* after
);
159 void keyPressEvent( QKeyEvent
*e
);
160 MediaBrowser
*m_parent
;
161 mutable KIO::filesize_t m_totalSize
;
165 class MediaBrowser
: public KVBox
168 friend class MediaDevice
;
169 friend class MediaView
;
170 friend class MediaQueue
;
171 friend class MediaItem
;
172 friend class MediaDevicePluginManager
;
175 static bool isAvailable();
176 /*AMAROK_EXPORT*/ static MediaBrowser
*instance() { return s_instance
; }
177 /*AMAROK_EXPORT*/ static MediaQueue
*queue() { return s_instance
? s_instance
->m_queue
: 0; }
179 MediaBrowser( const char *name
);
180 virtual ~MediaBrowser();
181 bool blockQuit() const;
182 MediaDevice
*currentDevice() const { return m_currentDevice
; }
183 MediaDevice
*deviceFromId( const QString
&udi
) const;
184 QStringList
deviceNames() const;
185 bool deviceSwitch( const QString
&name
);
187 QString
getInternalPluginName ( const QString string
) { return m_pluginName
[string
]; }
188 QString
getDisplayPluginName ( const QString string
) { return m_pluginAmarokName
[string
]; }
189 const KService::List
&getPlugins() { return m_plugins
; }
190 void transcodingFinished( const QString
&src
, const QString
&dst
);
191 bool isTranscoding() const { return m_waitForTranscode
; }
193 void updateButtons();
194 void updateDevices();
195 // return meta for url if it is known to MediaBrowser
196 Meta::TrackPtr
getMeta( const KUrl
&url
) const;
197 bool isQuitting() const { return m_quitting
; }
199 KUrl
getProxyUrl( const KUrl
& daapUrl
) const;
200 KToolBar
* getToolBar() const { return m_toolbar
; }
201 KAction
*connectAction() const { return m_connectAction
; }
202 KAction
*disconnectAction() const { return m_disconnectAction
; }
203 KAction
*transferAction() const { return m_transferAction
; }
204 KAction
*configAction() const { return m_configAction
; }
205 KAction
*customAction() const { return m_customAction
; }
208 void transferClicked();
211 void slotSetFilterTimeout();
212 void slotSetFilter();
213 void slotSetFilter( const QString
&filter
);
214 void slotEditFilter();
215 void deviceAdded( const QString
&udi
);
216 void deviceRemoved( const QString
&udi
);
217 void activateDevice( const MediaDevice
*device
);
218 void activateDevice( int index
, bool skipDummy
= true );
219 void pluginSelected( const QString
&, const QString
& );
220 void showPluginManager();
221 void cancelClicked();
222 void connectClicked();
223 void disconnectClicked();
224 void customClicked();
225 bool config(); // false if canceled by user
226 KUrl
transcode( const KUrl
&src
, const QString
&filetype
);
227 void tagsChanged( const Meta::TrackPtr newTrack
);
228 void prepareToQuit();
231 MediaDevice
*loadDevicePlugin( const QString
&udi
);
232 void unloadDevicePlugin( MediaDevice
*device
);
235 AMAROK_EXPORT
static MediaBrowser
*s_instance
;
237 QList
<MediaDevice
*> m_devices
;
238 MediaDevice
* m_currentDevice
;
240 QMap
<QString
, QString
> m_pluginName
;
241 QMap
<QString
, QString
> m_pluginAmarokName
;
242 void addDevice( MediaDevice
*device
);
243 void removeDevice( MediaDevice
*device
);
246 bool m_waitForTranscode
;
247 KUrl m_transcodedUrl
;
248 QString m_transcodeSrc
;
251 KHBox
* m_progressBox
;
252 QProgressBar
* m_progress
;
254 KPushButton
* m_cancelButton
;
255 //KPushButton* m_playlistButton;
257 KComboBox
* m_configPluginCombo
;
258 KComboBox
* m_deviceCombo
;
259 Browser::ToolBar
*m_toolbar
;
260 typedef QMap
<QString
, MediaItem
*> ItemMap
;
261 mutable QMutex m_itemMapMutex
;
263 KService::List m_plugins
;
266 KAction
*m_connectAction
;
267 KAction
*m_disconnectAction
;
268 KAction
*m_customAction
;
269 KAction
*m_configAction
;
270 KAction
*m_transferAction
;
271 SearchWidget
*m_searchWidget
;
274 class MediaView
: public K3ListView
277 friend class MediaBrowser
;
278 friend class MediaDevice
;
288 MediaView( QWidget
*parent
, MediaDevice
*device
);
289 virtual ~MediaView();
290 AMAROK_EXPORT
KUrl::List
nodeBuildDragList( MediaItem
* item
, int flags
=OnlySelected
);
291 AMAROK_EXPORT
int getSelectedLeaves(MediaItem
*parent
, QList
<MediaItem
*> *list
, int flags
=OnlySelected
);
292 AMAROK_EXPORT MediaItem
*newDirectory( MediaItem
* parent
);
293 bool setFilter( const QString
&filter
, MediaItem
*parent
=NULL
);
296 void rmbPressed( Q3ListViewItem
*, const QPoint
&, int );
297 void renameItem( Q3ListViewItem
*item
);
298 void slotExpand( Q3ListViewItem
* );
299 void selectAll() { Q3ListView::selectAll(true); }
300 void invokeItem( Q3ListViewItem
*, const QPoint
&, int column
);
301 void invokeItem( Q3ListViewItem
* );
304 void keyPressEvent( QKeyEvent
*e
);
305 // Reimplemented from K3ListView
306 void contentsDropEvent( QDropEvent
*e
);
307 void viewportPaintEvent( QPaintEvent
* );
308 bool acceptDrag( QDropEvent
*e
) const;
309 Q3DragObject
*dragObject();
312 MediaDevice
*m_device
;
315 #endif /* AMAROK_MEDIABROWSER_H */