[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/multimedia/amarok/src/collection
From:       Alejandro Daniel Wainzinger <aikawarazuni () gmail ! com>
Date:       2009-07-16 18:07:26
Message-ID: 1247767646.792476.9076.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 997956 by awainzinger:

Add graphical feedback for when device has not enough space for a track transfer, and \
when tracks are not copied because they are all dupes.

 M  +40 -2     ipodcollection/handler/IpodHandler.cpp  
 M  +3 -0      ipodcollection/handler/IpodHandler.h  
 M  +12 -0     ipodcollection/handler/capabilities/IpodReadCapability.cpp  
 M  +3 -0      ipodcollection/handler/capabilities/IpodReadCapability.h  
 M  +31 -1     mediadevicecollection/handler/MediaDeviceHandler.cpp  
 M  +7 -1      mediadevicecollection/handler/MediaDeviceHandler.h  
 M  +7 -0      mediadevicecollection/handler/capabilities/ReadCapability.h  
 M  +4 -4      mediadevicecollection/playlist/MediaDeviceUserPlaylistProvider.cpp  
 M  +6 -6      mediadevicecollection/playlist/MediaDeviceUserPlaylistProvider.h  
 M  +33 -0     mtpcollection/handler/MtpHandler.cpp  
 M  +3 -0      mtpcollection/handler/MtpHandler.h  
 M  +12 -0     mtpcollection/handler/capabilities/MtpReadCapability.cpp  
 M  +3 -0      mtpcollection/handler/capabilities/MtpReadCapability.h  


--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/handler/IpodHandler.cpp \
#997955:997956 @@ -37,6 +37,7 @@
 #include "File.h" // for KIO file handling
 
 #include <KCodecs> // KMD5
+#include <kdiskfreespaceinfo.h>
 #include <KIO/Job>
 #include <KIO/CopyJob>
 #include <KIO/DeleteJob>
@@ -50,6 +51,7 @@
 #include <threadweaver/ThreadWeaver.h>
 
 #include <solid/device.h>
+#include <solid/storageaccess.h>
 
 #include <QDir>
 #include <QFile>
@@ -123,8 +125,8 @@
 
 
     GError *err = 0;
-    QString initError = "iPod was not initialized: ";
-    QString initErrorCaption = "iPod Initialization Failed";
+    QString initError = i18n( "iPod was not initialized: " );
+    QString initErrorCaption = i18n( "iPod Initialization Failed" );
     bool wasInitialized = false;
 
     // First attempt to parse the database
@@ -1338,6 +1340,42 @@
     return KUrl(m_mountPoint + (QString( m_itdbtrackhash[ track ]->ipod_path \
).split( ':' ).join( "/" )));  }
 
+float
+IpodHandler::usedCapacity() const
+{
+    Solid::Device device = Solid::Device( m_memColl->udi() );
+    if( device.isValid() )
+    {
+        Solid::StorageAccess *storage = device.as<Solid::StorageAccess>();
+        KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( \
storage->filePath() ); +        return info.used();
+
+    }
+
+    else
+    {
+        return 0.0;
+    }
+}
+
+float
+IpodHandler::totalCapacity() const
+{
+    Solid::Device device = Solid::Device( m_memColl->udi() );
+    if( device.isValid() )
+    {
+        Solid::StorageAccess *storage = device.as<Solid::StorageAccess>();
+        KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( \
storage->filePath() ); +        return info.size();
+    }
+
+    else
+    {
+        return 0.0;
+    }
+
+}
+
 /// Sets
 
 void
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/handler/IpodHandler.h \
#997955:997956 @@ -235,6 +235,9 @@
     virtual QString libGetType( const Meta::MediaDeviceTrackPtr &track );
     virtual KUrl libGetPlayableUrl( const Meta::MediaDeviceTrackPtr &track );
 
+    virtual float usedCapacity() const;
+    virtual float totalCapacity() const;
+
     /// Ipod Methods
 
     bool removeDBTrack( Itdb_Track *track );
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/handler/capabilities/IpodReadCapability.cpp \
#997955:997956 @@ -169,4 +169,16 @@
     return m_handler->libGetPlayableUrl( track );
 }
 
+float
+IpodReadCapability::usedCapacity() const
+{
+    return m_handler->usedCapacity();
+}
+
+float
+IpodReadCapability::totalCapacity() const
+{
+    return m_handler->totalCapacity();
+}
+
 #include "IpodReadCapability.moc"
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/handler/capabilities/IpodReadCapability.h \
#997955:997956 @@ -63,6 +63,9 @@
         virtual QString libGetType( const Meta::MediaDeviceTrackPtr &track );
         virtual KUrl libGetPlayableUrl( const Meta::MediaDeviceTrackPtr &track );
 
+        virtual float usedCapacity() const;
+        virtual float totalCapacity() const;
+
         private:
             Meta::IpodHandler *m_handler;
 };
--- trunk/extragear/multimedia/amarok/src/collection/mediadevicecollection/handler/MediaDeviceHandler.cpp \
#997955:997956 @@ -27,6 +27,7 @@
 
 #include "playlist/MediaDevicePlaylist.h"
 
+#include <KMessageBox>
 #include <threadweaver/ThreadWeaver.h>
 #include <threadweaver/JobCollection.h>
 
@@ -287,6 +288,8 @@
     bool isDupe;
     bool hasDupe;
     QString format;
+    QString copyError = i18n( "Tracks not copied: " );
+    QString copyErrorCaption = i18n( "Copying Tracks Failed" );
     TrackMap trackMap = m_memColl->trackMap();
 
     Meta::TrackList tempTrackList;
@@ -382,10 +385,31 @@
 
     if( m_tracksToCopy.size() == 0 )
     {
-        The::statusBar()->shortMessage( i18n( "The tracks to copy are already on the \
device!" ) ); +        KMessageBox::error( 0, i18n( "%1the device already has these \
tracks", copyError ), copyErrorCaption );  emit copyTracksDone( false );
         return;
     }
+
+    // Check for available space, in bytes, after the copy
+
+    int transfersize = 0;
+
+    foreach( Meta::TrackPtr track, m_tracksToCopy )
+    {
+        transfersize += track->filesize();
+    }
+
+    debug() << "Total transfer size: " << transfersize;
+
+    // NOTE: if the device will not have more than 5 MB to spare, abort the copy
+    if( !( (freeSpace() - transfersize) > 1024*1024*5 ) )
+    {
+        debug() << "Free space: " << freeSpace();
+        debug() << "Space would've been after copy: " << (freeSpace() - \
transfersize); +        KMessageBox::error( 0, i18n( "%1the device has insufficient \
space", copyError ), copyErrorCaption ); +        emit copyTracksDone( false );
+        return;
+    }
     debug() << "Copying " << m_tracksToCopy.size() << " tracks";
 
     // Set up progress bar
@@ -1011,6 +1035,12 @@
     emit copyTracksDone( true );
 }
 
+float
+MediaDeviceHandler::freeSpace() const
+{
+    return ( m_rc->totalCapacity() - m_rc->usedCapacity() );
+}
+
 /** Observer Methods **/
 void
 MediaDeviceHandler::metadataChanged( TrackPtr track )
--- trunk/extragear/multimedia/amarok/src/collection/mediadevicecollection/handler/MediaDeviceHandler.h \
#997955:997956 @@ -192,7 +192,7 @@
 
     virtual QList<PopupDropperAction *> collectionActions() { return \
QList<PopupDropperAction*> (); }  
-    
+
 signals:
     void gotCopyableUrls( const QMap<Meta::TrackPtr, KUrl> &urls );
     void databaseWritten( bool succeeded );
@@ -295,6 +295,12 @@
     void setupComposerMap( Meta::MediaDeviceTrackPtr track, ComposerMap &composerMap \
                );
     void setupYearMap( Meta::MediaDeviceTrackPtr track, YearMap &yearMap );
 
+    /**
+     *  @return free space on the device
+     */
+
+    float freeSpace() const;
+
     /// Observer Methods
 
     /** These methods are called when the metadata of a track has changed. They \
                invoke an MediaDevice DB update */
--- trunk/extragear/multimedia/amarok/src/collection/mediadevicecollection/handler/capabilities/ReadCapability.h \
#997955:997956 @@ -95,6 +95,13 @@
         virtual QString libGetType( const Meta::MediaDeviceTrackPtr &track ) = 0;
         virtual KUrl libGetPlayableUrl( const Meta::MediaDeviceTrackPtr &track ) = \
0;  
+        /**
+          Methods related to device space usage, in bytes
+          */
+
+        virtual float usedCapacity() const { return 0.0; }
+        virtual float totalCapacity() const { return 0.0; }
+
         static Type capabilityInterfaceType() { return \
Handler::Capability::Readable; }  
     };
--- trunk/extragear/multimedia/amarok/src/collection/mediadevicecollection/playlist/MediaDeviceUserPlaylistProvider.cpp \
#997955:997956 @@ -100,24 +100,24 @@
 
     return Meta::PlaylistPtr::dynamicCast( mediadevicePlaylist ); //assumes \
insertion in db was successful!  }
-
+#if 0
 QList<PopupDropperAction *>
 MediaDeviceUserPlaylistProvider::playlistActions( Meta::PlaylistList list )
 {
     Q_UNUSED( list )
     QList<PopupDropperAction *> actions;
-#if 0
+
     if ( m_renameAction == 0 )
     {
         m_renameAction =  new PopupDropperAction( The::svgHandler()->getRenderer( \
"amarok/images/pud_items.svg" ), "edit", KIcon( "media-track-edit-amarok" ), i18n( \
                "&Rename" ), this );
         connect( m_renameAction, SIGNAL( triggered() ), this, SLOT( slotRename() ) \
);  }
     actions << m_renameAction;
-#endif
 
+
     return actions;
 }
-
+#endif
 void
 MediaDeviceUserPlaylistProvider::addPlaylist( Meta::MediaDevicePlaylistPtr &playlist \
)  {
--- trunk/extragear/multimedia/amarok/src/collection/mediadevicecollection/playlist/MediaDeviceUserPlaylistProvider.h \
#997955:997956 @@ -41,16 +41,16 @@
         virtual Meta::PlaylistPtr save( const Meta::TrackList &tracks );
         virtual Meta::PlaylistPtr save( const Meta::TrackList &tracks, const \
QString& name );  
-	//      virtual bool supportsEmptyGroups() { return true; }
+        //      virtual bool supportsEmptyGroups() { return true; }
 
-        QList<PopupDropperAction *> playlistActions( Meta::PlaylistList list );
+        //virtual QList<PopupDropperAction *> playlistActions( Meta::PlaylistList \
list );  
-	/// MediaDevice-specific Functions
+        /// MediaDevice-specific Functions
 
-	void addPlaylist( Meta::MediaDevicePlaylistPtr &playlist );
+        void addPlaylist( Meta::MediaDevicePlaylistPtr &playlist );
 
-	public slots:
-	    void sendUpdated() { emit updated(); }
+        public slots:
+            void sendUpdated() { emit updated(); }
 
  private:
 
--- trunk/extragear/multimedia/amarok/src/collection/mtpcollection/handler/MtpHandler.cpp \
#997955:997956 @@ -1024,6 +1024,39 @@
         return KUrl( QString::number(  m_mtptrackhash[ track ]->item_id,  10 ) );
 }
 
+float
+MtpHandler::usedCapacity() const
+{
+    DEBUG_BLOCK
+    if( LIBMTP_Get_Storage( m_device, LIBMTP_STORAGE_SORTBY_NOTSORTED ) != 0 )
+    {
+        debug() << "Failed to get storage properties, cannot get capacity";
+        return 0.0;
+    }
+
+    else
+    {
+        return m_device->storage->FreeSpaceInBytes;
+    }
+}
+
+float
+MtpHandler::totalCapacity() const
+{
+    DEBUG_BLOCK
+    if( LIBMTP_Get_Storage( m_device, LIBMTP_STORAGE_SORTBY_NOTSORTED ) != 0 )
+    {
+        debug() << "Failed to get storage properties, cannot get capacity";
+        return 0.0;
+    }
+
+    else
+    {
+        return m_device->storage->MaxCapacity;
+    }
+
+}
+
 /// Sets
 
 void
--- trunk/extragear/multimedia/amarok/src/collection/mtpcollection/handler/MtpHandler.h \
#997955:997956 @@ -148,6 +148,9 @@
     virtual QString libGetType( const Meta::MediaDeviceTrackPtr &track );
     virtual KUrl    libGetPlayableUrl( const Meta::MediaDeviceTrackPtr &track );
 
+    virtual float usedCapacity() const;
+    virtual float totalCapacity() const;
+
     virtual void    libSetTitle( Meta::MediaDeviceTrackPtr &track, const QString& \
                title );
     virtual void    libSetAlbum( Meta::MediaDeviceTrackPtr &track, const QString& \
                album );
     virtual void    libSetArtist( Meta::MediaDeviceTrackPtr &track, const QString& \
                artist );
--- trunk/extragear/multimedia/amarok/src/collection/mtpcollection/handler/capabilities/MtpReadCapability.cpp \
#997955:997956 @@ -169,4 +169,16 @@
     return m_handler->libGetPlayableUrl( track );
 }
 
+float
+MtpReadCapability::usedCapacity() const
+{
+    return m_handler->usedCapacity();
+}
+
+float
+MtpReadCapability::totalCapacity() const
+{
+    return m_handler->totalCapacity();
+}
+
 #include "MtpReadCapability.moc"
--- trunk/extragear/multimedia/amarok/src/collection/mtpcollection/handler/capabilities/MtpReadCapability.h \
#997955:997956 @@ -63,6 +63,9 @@
         virtual QString libGetType( const Meta::MediaDeviceTrackPtr &track );
         virtual KUrl libGetPlayableUrl( const Meta::MediaDeviceTrackPtr &track );
 
+        virtual float usedCapacity() const;
+        virtual float totalCapacity() const;
+
         private:
             Meta::MtpHandler *m_handler;
 };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic