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 MediaDevice
;
169 friend class MediaView
;
170 friend class MediaQueue
;
171 friend class MediaItem
;
174 static bool isAvailable();
175 AMAROK_EXPORT
static MediaBrowser
*instance() { return s_instance
; }
176 AMAROK_EXPORT
static MediaQueue
*queue() { return s_instance
? s_instance
->m_queue
: 0; }
178 MediaBrowser( const char *name
);
179 virtual ~MediaBrowser();
180 bool blockQuit() const;
181 MediaDevice
*currentDevice() const { return m_currentDevice
; }
182 MediaDevice
*deviceFromId( const QString
&id
) const;
183 QStringList
deviceNames() const;
184 bool deviceSwitch( const QString
&name
);
186 QString
getInternalPluginName ( const QString string
) { return m_pluginName
[string
]; }
187 QString
getDisplayPluginName ( const QString string
) { return m_pluginAmarokName
[string
]; }
188 const KService::List
&getPlugins() { return m_plugins
; }
189 void transcodingFinished( const QString
&src
, const QString
&dst
);
190 bool isTranscoding() const { return m_waitForTranscode
; }
192 void updateButtons();
193 void updateDevices();
194 // return bundle for url if it is known to MediaBrowser
195 bool getBundle( const KUrl
&url
, MetaBundle
*bundle
) const;
196 bool isQuitting() const { return m_quitting
; }
198 KUrl
getProxyUrl( const KUrl
& daapUrl
) const;
199 KToolBar
* getToolBar() const { return m_toolbar
; }
200 KAction
*connectAction() const { return m_connectAction
; }
201 KAction
*disconnectAction() const { return m_disconnectAction
; }
202 KAction
*transferAction() const { return m_transferAction
; }
203 KAction
*configAction() const { return m_configAction
; }
204 KAction
*customAction() const { return m_customAction
; }
207 void transferClicked();
210 void slotSetFilterTimeout();
211 void slotSetFilter();
212 void slotSetFilter( const QString
&filter
);
213 void slotEditFilter();
214 void deviceAdded( const QString
&uid
);
215 void deviceRemoved( const QString
&uid
);
216 void activateDevice( const MediaDevice
*device
);
217 void activateDevice( int index
, bool skipDummy
= true );
218 //TODO Put these back!
219 void pluginSelected( const QString
&, const QString
& );
220 void showPluginManager();
221 //void configSelectPlugin( int index );
222 void cancelClicked();
223 void connectClicked();
224 void disconnectClicked();
225 void customClicked();
226 bool config(); // false if canceled by user
227 KUrl
transcode( const KUrl
&src
, const QString
&filetype
);
228 void tagsChanged( const MetaBundle
&bundle
);
229 void prepareToQuit();
232 MediaDevice
*loadDevicePlugin( const QString
&uid
);
233 void unloadDevicePlugin( MediaDevice
*device
);
236 AMAROK_EXPORT
static MediaBrowser
*s_instance
;
238 QList
<MediaDevice
*> m_devices
;
239 MediaDevice
* m_currentDevice
;
241 QMap
<QString
, QString
> m_pluginName
;
242 QMap
<QString
, QString
> m_pluginAmarokName
;
243 void addDevice( MediaDevice
*device
);
244 void removeDevice( MediaDevice
*device
);
247 bool m_waitForTranscode
;
248 KUrl m_transcodedUrl
;
249 QString m_transcodeSrc
;
252 KHBox
* m_progressBox
;
253 QProgressBar
* m_progress
;
255 KPushButton
* m_cancelButton
;
256 //KPushButton* m_playlistButton;
258 KComboBox
* m_configPluginCombo
;
259 KComboBox
* m_deviceCombo
;
260 Browser::ToolBar
*m_toolbar
;
261 typedef QMap
<QString
, MediaItem
*> ItemMap
;
262 mutable QMutex m_itemMapMutex
;
264 KService::List m_plugins
;
267 KAction
*m_connectAction
;
268 KAction
*m_disconnectAction
;
269 KAction
*m_customAction
;
270 KAction
*m_configAction
;
271 KAction
*m_transferAction
;
272 SearchWidget
*m_searchWidget
;
275 class MediaView
: public K3ListView
278 friend class MediaBrowser
;
279 friend class MediaDevice
;
289 MediaView( QWidget
*parent
, MediaDevice
*device
);
290 virtual ~MediaView();
291 AMAROK_EXPORT
KUrl::List
nodeBuildDragList( MediaItem
* item
, int flags
=OnlySelected
);
292 AMAROK_EXPORT
int getSelectedLeaves(MediaItem
*parent
, QList
<MediaItem
*> *list
, int flags
=OnlySelected
);
293 AMAROK_EXPORT MediaItem
*newDirectory( MediaItem
* parent
);
294 bool setFilter( const QString
&filter
, MediaItem
*parent
=NULL
);
297 void rmbPressed( Q3ListViewItem
*, const QPoint
&, int );
298 void renameItem( Q3ListViewItem
*item
);
299 void slotExpand( Q3ListViewItem
* );
300 void selectAll() { Q3ListView::selectAll(true); }
301 void invokeItem( Q3ListViewItem
*, const QPoint
&, int column
);
302 void invokeItem( Q3ListViewItem
* );
305 void keyPressEvent( QKeyEvent
*e
);
306 // Reimplemented from K3ListView
307 void contentsDropEvent( QDropEvent
*e
);
308 void viewportPaintEvent( QPaintEvent
* );
309 bool acceptDrag( QDropEvent
*e
) const;
310 Q3DragObject
*dragObject();
313 MediaDevice
*m_device
;
316 #endif /* AMAROK_MEDIABROWSER_H */