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"
14 #include "metabundle.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
, MetaBundle
*bundle
=NULL
, 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 DeviceConfigureDialog
;
169 friend class MediaDevice
;
170 friend class MediaView
;
171 friend class MediaQueue
;
172 friend class MediumPluginChooser
;
173 friend class MediaItem
;
176 static bool isAvailable();
177 AMAROK_EXPORT
static MediaBrowser
*instance() { return s_instance
; }
178 AMAROK_EXPORT
static MediaQueue
*queue() { return s_instance
? s_instance
->m_queue
: 0; }
180 MediaBrowser( const char *name
);
181 virtual ~MediaBrowser();
182 bool blockQuit() const;
183 MediaDevice
*currentDevice() const { return m_currentDevice
; }
184 MediaDevice
*deviceFromId( const QString
&id
) const;
185 QStringList
deviceNames() const;
186 bool deviceSwitch( const QString
&name
);
188 QString
getInternalPluginName ( const QString string
) { return m_pluginName
[string
]; }
189 QString
getDisplayPluginName ( const QString string
) { return m_pluginAmarokName
[string
]; }
190 const KService::List
&getPlugins() { return m_plugins
; }
191 void transcodingFinished( const QString
&src
, const QString
&dst
);
192 bool isTranscoding() const { return m_waitForTranscode
; }
194 void updateButtons();
195 void updateDevices();
196 // return bundle for url if it is known to MediaBrowser
197 bool getBundle( const KUrl
&url
, MetaBundle
*bundle
) const;
198 bool isQuitting() const { return m_quitting
; }
200 KUrl
getProxyUrl( const KUrl
& daapUrl
) const;
201 KToolBar
* getToolBar() const { return m_toolbar
; }
202 KAction
*connectAction() const { return m_connectAction
; }
203 KAction
*disconnectAction() const { return m_disconnectAction
; }
204 KAction
*transferAction() const { return m_transferAction
; }
205 KAction
*configAction() const { return m_configAction
; }
206 KAction
*customAction() const { return m_customAction
; }
209 void transferClicked();
212 void slotSetFilterTimeout();
213 void slotSetFilter();
214 void slotSetFilter( const QString
&filter
);
215 void slotEditFilter();
216 void deviceAdded( const QString
&udi
);
217 void deviceRemoved( const QString
&udi
);
218 void activateDevice( const MediaDevice
*device
);
219 void activateDevice( int index
, bool skipDummy
= true );
220 //TODO Put these back!
221 //void pluginSelected( const Medium *, const QString );
222 //void showPluginManager();
223 //void configSelectPlugin( int index );
224 void cancelClicked();
225 void connectClicked();
226 void disconnectClicked();
227 void customClicked();
228 bool config(); // false if canceled by user
229 KUrl
transcode( const KUrl
&src
, const QString
&filetype
);
230 void tagsChanged( const MetaBundle
&bundle
);
231 void prepareToQuit();
234 MediaDevice
*loadDevicePlugin( const QString
&udi
);
235 void unloadDevicePlugin( MediaDevice
*device
);
238 AMAROK_EXPORT
static MediaBrowser
*s_instance
;
240 QList
<MediaDevice
*> m_devices
;
241 MediaDevice
* m_currentDevice
;
243 QMap
<QString
, QString
> m_pluginName
;
244 QMap
<QString
, QString
> m_pluginAmarokName
;
245 void addDevice( MediaDevice
*device
);
246 void removeDevice( MediaDevice
*device
);
249 bool m_waitForTranscode
;
250 KUrl m_transcodedUrl
;
251 QString m_transcodeSrc
;
254 KHBox
* m_progressBox
;
255 QProgressBar
* m_progress
;
257 KPushButton
* m_cancelButton
;
258 //KPushButton* m_playlistButton;
260 KComboBox
* m_configPluginCombo
;
261 KComboBox
* m_deviceCombo
;
262 Browser::ToolBar
*m_toolbar
;
263 typedef QMap
<QString
, MediaItem
*> ItemMap
;
264 mutable QMutex m_itemMapMutex
;
266 KService::List m_plugins
;
269 KAction
*m_connectAction
;
270 KAction
*m_disconnectAction
;
271 KAction
*m_customAction
;
272 KAction
*m_configAction
;
273 KAction
*m_transferAction
;
274 SearchWidget
*m_searchWidget
;
277 class MediaView
: public K3ListView
280 friend class MediaBrowser
;
281 friend class MediaDevice
;
291 MediaView( QWidget
*parent
, MediaDevice
*device
);
292 virtual ~MediaView();
293 AMAROK_EXPORT
KUrl::List
nodeBuildDragList( MediaItem
* item
, int flags
=OnlySelected
);
294 AMAROK_EXPORT
int getSelectedLeaves(MediaItem
*parent
, QList
<MediaItem
*> *list
, int flags
=OnlySelected
);
295 AMAROK_EXPORT MediaItem
*newDirectory( MediaItem
* parent
);
296 bool setFilter( const QString
&filter
, MediaItem
*parent
=NULL
);
299 void rmbPressed( Q3ListViewItem
*, const QPoint
&, int );
300 void renameItem( Q3ListViewItem
*item
);
301 void slotExpand( Q3ListViewItem
* );
302 void selectAll() { Q3ListView::selectAll(true); }
303 void invokeItem( Q3ListViewItem
*, const QPoint
&, int column
);
304 void invokeItem( Q3ListViewItem
* );
307 void keyPressEvent( QKeyEvent
*e
);
308 // Reimplemented from K3ListView
309 void contentsDropEvent( QDropEvent
*e
);
310 void viewportPaintEvent( QPaintEvent
* );
311 bool acceptDrag( QDropEvent
*e
) const;
312 Q3DragObject
*dragObject();
315 MediaDevice
*m_device
;
318 #endif /* AMAROK_MEDIABROWSER_H */