extragear/multimedia/amarok/src
Alejandro Daniel Wainzinger
aikawarazuni at gmail.com
Fri Jan 16 18:46:55 CET 2009
SVN commit 912095 by awainzinger:
First step in a series to generalize Media Device code, to make adding new Media Device support easier. This work is far from done (barely started).
- Device detection will be handled by Factory via a MediaDeviceInfo object, passed to MediaDeviceMonitor, which forwards it to whoever needs it (e.g. MediaDevicesApplet).
-- This also allows embedding of device-specific information for applet display (e.g. battery %, free space %)
- New devices to be supported inherit classes in mediadevicecollection which abstract core functionality of a media device. The MediaDeviceCollection stuff itself is turned into a lib.
Note: possibly merging MediaDeviceCache and MediaDeviceMonitor in a future step, since detection is moved to Factory.
CCMAIL:amarok-devel at kde.org
M +2 -0 CMakeLists.txt
M +6 -0 MediaDeviceMonitor.h
M +1 -0 collection/CMakeLists.txt
M +2 -0 collection/ipodcollection/CMakeLists.txt
M +63 -2 collection/ipodcollection/IpodCollection.cpp
M +9 -0 collection/ipodcollection/IpodCollection.h
M +8 -7 collection/mediadevicecollection/CMakeLists.txt
M +10 -2 collection/mediadevicecollection/MediaDeviceCollection.cpp
M +13 -15 collection/mediadevicecollection/MediaDeviceCollection.h
A collection/mediadevicecollection/support (directory)
A collection/mediadevicecollection/support/IpodDeviceInfo.cpp [License: GPL (v2+)]
A collection/mediadevicecollection/support/IpodDeviceInfo.h [License: GPL (v2+)]
A collection/mediadevicecollection/support/MediaDeviceInfo.cpp [License: GPL (v2+)]
A collection/mediadevicecollection/support/MediaDeviceInfo.h [License: GPL (v2+)]
M +1 -0 collection/mtpcollection/CMakeLists.txt
--- trunk/extragear/multimedia/amarok/src/CMakeLists.txt #912094:912095
@@ -42,6 +42,7 @@
charset-detector/src
charset-detector/src/tables
collection
+ collection/mediadevicecollection/support # for MediaDeviceInfo
configdialog
configdialog/dialogs
context
@@ -563,6 +564,7 @@
amarok_taglib
amarokplasma
amarokpud
+ mediadevicelib
)
if(WIN32)
--- trunk/extragear/multimedia/amarok/src/MediaDeviceMonitor.h #912094:912095
@@ -33,6 +33,8 @@
#ifndef AMAROK_MEDIADEVICEMONITOR_H
#define AMAROK_MEDIADEVICEMONITOR_H
+#include "MediaDeviceInfo.h"
+
#include "amarok_export.h"
#include <QObject>
@@ -58,6 +60,8 @@
void checkDevicesForMtp();
void checkDevicesForIpod();
+ // void fetchDevices(); // emits device info for each device present
+
signals:
void deviceRemoved( const QString &udi );
void ipodDetected( const QString &mountPoint, const QString &udi );
@@ -68,6 +72,8 @@
void mtpReadyToConnect( const QString &serial, const QString &udi );
void mtpReadyToDisconnect( const QString &udi );
+ void deviceDetected( const MediaDeviceInfo &deviceinfo );
+
public slots:
void connectIpod( const QString &mountpoint, const QString &udi );
--- trunk/extragear/multimedia/amarok/src/collection/CMakeLists.txt #912094:912095
@@ -4,6 +4,7 @@
add_subdirectory( daap )
+add_subdirectory( mediadevicecollection )
add_subdirectory( ipodcollection )
add_subdirectory( mtpcollection )
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/CMakeLists.txt #912094:912095
@@ -14,6 +14,7 @@
../../meta/file
../../collection
../../metadata/audible
+ ../mediadevicecollection/support
handler
${GLIB2_INCLUDE_DIR}
${GDK_INCLUDE_DIR}
@@ -39,6 +40,7 @@
kde4_add_plugin(amarok_collection-ipodcollection WITH_PREFIX ${amarok_collection-ipodcollection_PART_SRCS})
target_link_libraries(amarok_collection-ipodcollection
+ mediadevicelib
amaroklib
amarokpud
${KDE4_KDECORE_LIBS}
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/IpodCollection.cpp #912094:912095
@@ -19,6 +19,7 @@
#define DEBUG_PREFIX "IpodCollection"
#include "IpodCollection.h"
+#include "IpodDeviceInfo.h"
#include "meta/capabilities/CollectionCapability.h"
#include "IpodCollectionLocation.h"
@@ -29,13 +30,16 @@
#include "amarokconfig.h"
#include "Debug.h"
+#include "MediaDeviceCache.h"
#include "MediaDeviceMonitor.h"
#include "MemoryQueryMaker.h"
#include <KMessageBox>
#include <KUrl>
+#include <solid/device.h>
+
AMAROK_EXPORT_PLUGIN( IpodCollectionFactory )
IpodCollectionFactory::IpodCollectionFactory()
@@ -56,16 +60,23 @@
// connect to the monitor
- // TODO: the connection to this slot needs to be redone elsewhere
+ // connect( this, SIGNAL( ipodDetected( const MediaDeviceInfo & ) ),
+// MediaDeviceMonitor::instance(), SIGNAL( deviceDetected( const MediaDeviceInfo & ) ) );
+
connect( MediaDeviceMonitor::instance(), SIGNAL( ipodReadyToConnect( const QString &, const QString & ) ),
SLOT( ipodDetected( const QString &, const QString & ) ) );
+
+ // HACK: emitting old signal to avoid refactoring applet yet
+ connect( this, SIGNAL( tellIpodDetected( const QString &, const QString & ) ),
+ MediaDeviceMonitor::instance(), SIGNAL( ipodDetected( const QString &, const QString & ) ) );
+
connect( MediaDeviceMonitor::instance(), SIGNAL( ipodReadyToDisconnect( const QString & ) ),
SLOT( deviceRemoved( const QString & ) ) );
connect( MediaDeviceMonitor::instance(), SIGNAL( deviceRemoved( const QString & ) ), SLOT( deviceRemoved( const QString & ) ) );
// HACK: Usability: Force auto-connection of device upon detection
- MediaDeviceMonitor::instance()->checkDevicesForIpod();
+ checkDevicesForIpod();
}
void
@@ -126,6 +137,56 @@
}
}
+void
+IpodCollectionFactory::checkDevicesForIpod()
+{
+ QStringList udiList = MediaDeviceMonitor::instance()->getDevices();
+
+ /* poll udi list for supported devices */
+ foreach( const QString &udi, udiList )
+ {
+ /* if ipod device found, emit signal */
+ if( isIpod( udi ) )
+ {
+ // HACK: Usability: Force auto-connection of device upon detection
+ QString mountpoint = MediaDeviceCache::instance()->volumeMountPoint(udi);
+ ipodDetected( mountpoint, udi );
+
+ MediaDeviceInfo *deviceinfo = new IpodDeviceInfo( mountpoint, udi );
+ //emit ipodDetected( deviceinfo );
+ // HACK: emit old signal to avoid refactor of applet yet
+ emit tellIpodDetected( mountpoint, udi );
+ }
+ }
+}
+
+bool
+IpodCollectionFactory::isIpod( const QString &udi )
+{
+ DEBUG_BLOCK
+
+ Solid::Device device;
+
+ device = Solid::Device(udi);
+ /* going until we reach a vendor, e.g. Apple */
+ while ( device.isValid() && device.vendor().isEmpty() )
+ {
+ device = Solid::Device( device.parentUdi() );
+ }
+
+ debug() << "Device udi: " << udi;
+ debug() << "Device name: " << MediaDeviceCache::instance()->deviceName(udi);
+ debug() << "Mount point: " << MediaDeviceCache::instance()->volumeMountPoint(udi);
+ if ( device.isValid() )
+ {
+ debug() << "vendor: " << device.vendor() << ", product: " << device.product();
+ }
+
+ /* if iPod found, return true */
+ return device.product() == "iPod";
+}
+
+
//IpodCollection
IpodCollection::IpodCollection( const QString &mountPoint, const QString &udi )
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/IpodCollection.h #912094:912095
@@ -23,6 +23,8 @@
#include <gpod/itdb.h>
}
+#include "MediaDeviceInfo.h"
+
#include "Debug.h"
#include "Collection.h"
@@ -43,6 +45,10 @@
virtual void init();
+ signals:
+ void ipodDetected( const MediaDeviceInfo &deviceinfo );
+ void tellIpodDetected( const QString &mountPoint, const QString &udi );
+
public slots:
// convenience slot
void removeIpod( const QString &udi ) { deviceRemoved( udi ); }
@@ -54,6 +60,9 @@
void slotCollectionDisconnected( const QString & udi );
private:
+ void checkDevicesForIpod();
+ bool isIpod( const QString &udi );
+
QMap<QString, IpodCollection*> m_collectionMap;
};
--- trunk/extragear/multimedia/amarok/src/collection/mediadevicecollection/CMakeLists.txt #912094:912095
@@ -10,19 +10,20 @@
########### next target ###############
- set(amarok_collection-mediadevicecollection_PART_SRCS
- MediaDeviceMeta.cpp
- MediaDeviceCollection.cpp)
+ set(mediadevicelib_LIB_SRCS
+ support/MediaDeviceInfo.cpp
+ support/IpodDeviceInfo.cpp)
- kde4_add_plugin(amarok_collection-mediadevicecollection WITH_PREFIX ${amarok_collection-mediadevicecollection_PART_SRCS})
+ kde4_add_library(mediadevicelib SHARED ${mediadevicelib_LIB_SRCS})
- target_link_libraries(amarok_collection-mediadevicecollection amaroklib ${KDE4_THREADWEAVER_LIBRARIES} )
+ target_link_libraries(mediadevicelib ${KDE4_KUTILS_LIBS})
- install(TARGETS amarok_collection-mediadevicecollection DESTINATION ${PLUGIN_INSTALL_DIR} )
+ set_target_properties(mediadevicelib PROPERTIES VERSION 1.0.0 SOVERSION 1 )
+ install(TARGETS mediadevicelib ${INSTALL_TARGETS_DEFAULT_ARGS} )
########### install files ###############
- install( FILES amarok_collection-mediadevicecollection.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+# install( FILES amarok_collection-mediadevicecollection.desktop DESTINATION ${SERVICES_INSTALL_DIR})
--- trunk/extragear/multimedia/amarok/src/collection/mediadevicecollection/MediaDeviceCollection.cpp #912094:912095
@@ -60,10 +60,9 @@
//MediaDeviceCollection
-MediaDeviceCollection::MediaDeviceCollection( const QString &mountPoint )
+MediaDeviceCollection::MediaDeviceCollection()
: Collection()
, MemoryCollection()
- , m_mountPoint(mountPoint)
{
DEBUG_BLOCK
}
@@ -74,6 +73,15 @@
}
void
+MediaDeviceCollection::copyTrackListToDevice( const Meta::TrackList tracklist )
+{
+ DEBUG_BLOCK
+ connect( m_handler, SIGNAL( copyTracksDone() ),
+ SLOT( slotCopyTracksCompleted() ), Qt::QueuedConnection );
+ m_handler->copyTrackListToDevice( tracklist );
+}
+
+void
MediaDeviceCollection::startFullScan()
{
//ignore
--- trunk/extragear/multimedia/amarok/src/collection/mediadevicecollection/MediaDeviceCollection.h #912094:912095
@@ -1,8 +1,5 @@
-/*
- Mostly taken from Daap code:
- Copyright (C) 2006 Ian Monroe <ian at monroe.nu>
- Copyright (C) 2006 Seb Ruiz <ruiz at kde.org>
- Copyright (C) 2007 Maximilian Kossick <maximilian.kossick at googlemail.com>
+/*
+ Copyright (C) 2008 Alejandro Wainzinger <aikawarazuni at gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -27,8 +24,6 @@
#include <QtGlobal>
-class MediaDeviceCollection;
-
class MediaDeviceCollectionFactory : public Amarok::CollectionFactory
{
Q_OBJECT
@@ -36,13 +31,15 @@
MediaDeviceCollectionFactory();
virtual ~MediaDeviceCollectionFactory();
- virtual void init();
+ virtual void init() = 0;
private:
private slots:
-
- private:
+ virtual void deviceDetected() = 0;
+ virtual void deviceRemoved( const QString &udi ) = 0;
+ virtual void slotCollectionReady() = 0;
+ virtual void slotCollectionDisconnected( const QString & udi ) = 0;
};
@@ -51,25 +48,26 @@
Q_OBJECT
public:
- MediaDeviceCollection( const QString &mountPoint);
- virtual ~MediaDeviceCollection();
+ void copyTrackListToDevice( const Meta::TrackList tracklist );
virtual void startFullScan();
virtual QueryMaker* queryMaker();
virtual QString collectionId() const;
- virtual QString prettyName() const;
+ virtual QString prettyName() const;
signals:
void collectionReady();
public slots:
+ virtual void deleteTracksSlot( Meta::TrackList tracklist );
+ protected:
+ MediaDevice::MediaDeviceHandler *m_handler;
+
private slots:
- private:
-
};
#endif
--- trunk/extragear/multimedia/amarok/src/collection/mtpcollection/CMakeLists.txt #912094:912095
@@ -10,6 +10,7 @@
../../meta
../../meta/file
../../collection
+ ../mediadevicecollection/support
handler
${GLIB2_INCLUDE_DIR}
${MTP_INCLUDE_DIR}
More information about the Amarok-devel
mailing list