Revert previous commit, was incorrect
[amarok.git] / src / mediabrowser.h
blob267271b3397d714a4fb0fe3567d729f2789b2635
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"
11 #include "amarok.h"
12 #include "browserToolBar.h"
13 #include "medium.h"
14 #include "Meta.h"
15 #include "pluginmanager.h"
16 #include "plugin/plugin.h" //baseclass
17 #include "scrobbler.h" //SubmitItem
19 #include <k3listview.h> //baseclass
20 #include <KHBox>
21 #include <kio/global.h> //filesize_t
22 #include <KUrl> //stack allocated
23 #include <KVBox> //baseclass
25 #include <QDateTime>
26 #include <QLabel>
27 #include <QMutex>
28 #include <QPainter>
29 #include <QPaintEvent>
30 #include <QPixmap>
31 #include <QWidget>
34 class MediaBrowser;
35 class MediaDevice;
36 class MediaItem;
37 class MediaView;
38 class SpaceLabel;
39 class TransferDialog;
40 class SearchWidget;
42 class KAction;
43 class KComboBox;
44 class KPushButton;
45 class K3ShellProcess;
47 class QDropEvent;
48 class QKeyEvent;
49 class QPaintEvent;
50 class Q3DragObject;
51 class QLabel;
52 class QProgressBar;
54 class SpaceLabel : public QLabel {
55 public:
56 SpaceLabel(QWidget *parent)
57 : QLabel(parent)
59 m_total = m_used = m_scheduled = 0;
62 void paintEvent(QPaintEvent *e)
64 QPainter p(this);
65 p.fillRect(e->rect(), palette().brush(QColorGroup::Background));
67 if(m_total > 0)
69 int used = int(float(m_used)/float(m_total)*width());
70 int scheduled = int(float(m_used + m_scheduled)/float(m_total)*width());
72 if(m_used > 0)
74 QColor blueish(70,120,255);
75 if(e->rect().left() < used)
77 int right = 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));
85 if(m_scheduled > 0)
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();
93 if(used > left)
94 left = used;
95 int right = e->rect().right();
96 if(scheduled < right)
97 right = scheduled;
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();
105 if(scheduled > left)
106 left = scheduled;
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
121 Q_OBJECT
123 public:
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();
133 void clearItems();
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();
150 public slots:
151 void itemCountChanged();
153 private slots:
154 void selectAll() {Q3ListView::selectAll(true); }
155 void slotShowContextMenu( Q3ListViewItem* item, const QPoint& point, int );
156 void slotDropped (QDropEvent* e, Q3ListViewItem* parent, Q3ListViewItem* after);
158 private:
159 void keyPressEvent( QKeyEvent *e );
160 MediaBrowser *m_parent;
161 mutable KIO::filesize_t m_totalSize;
165 class MediaBrowser : public KVBox
167 Q_OBJECT
168 friend class MediaDevice;
169 friend class MediaView;
170 friend class MediaQueue;
171 friend class MediaItem;
172 friend class MediaDevicePluginManager;
174 public:
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; }
192 void updateStats();
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; }
207 protected slots:
208 void transferClicked();
210 private slots:
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();
230 private:
231 MediaDevice *loadDevicePlugin( const QString &udi );
232 void unloadDevicePlugin( MediaDevice *device );
234 QTimer *m_timer;
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 );
245 MediaQueue* m_queue;
246 bool m_waitForTranscode;
247 KUrl m_transcodedUrl;
248 QString m_transcodeSrc;
250 SpaceLabel* m_stats;
251 KHBox* m_progressBox;
252 QProgressBar* m_progress;
253 KVBox* m_views;
254 KPushButton* m_cancelButton;
255 //KPushButton* m_playlistButton;
256 KVBox* m_configBox;
257 KComboBox* m_configPluginCombo;
258 KComboBox* m_deviceCombo;
259 Browser::ToolBar*m_toolbar;
260 typedef QMap<QString, MediaItem*> ItemMap;
261 mutable QMutex m_itemMapMutex;
262 ItemMap m_itemMap;
263 KService::List m_plugins;
264 bool m_haveDevices;
265 bool m_quitting;
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
276 Q_OBJECT
277 friend class MediaBrowser;
278 friend class MediaDevice;
280 public:
281 enum Flags
283 None = 0,
284 OnlySelected = 1,
285 OnlyPlayed = 2
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 );
295 private slots:
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* );
303 private:
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();
311 QWidget *m_parent;
312 MediaDevice *m_device;
315 #endif /* AMAROK_MEDIABROWSER_H */