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

List:       kde-commits
Subject:    [Amarok]  unmount iphone if it was mounted by Amarok
From:       Martin Aumueller <aumuell () reserv ! at>
Date:       2009-08-04 21:12:06
Message-ID: 200908050109.n75194Mn025938 () Wurst ! kollide ! net
[Download RAW message or body]

commit 4880fada5f07e8ae9c08d1ee8d726b962881376b
Author:     Martin Aumueller <aumuell@reserv.at>
AuthorDate: Sun Aug 2 21:56:16 2009 +0200
Commit:     Martin Aumueller <aumuell@reserv.at>
CommitDate: Tue Aug 4 23:05:02 2009 +0200

    unmount iphone if it was mounted by Amarok

diff --git a/src/collection/ipodcollection/handler/IpodHandler.cpp \
b/src/collection/ipodcollection/handler/IpodHandler.cpp index 8c0bbe8..8c1d96e 100644
--- a/src/collection/ipodcollection/handler/IpodHandler.cpp
+++ b/src/collection/ipodcollection/handler/IpodHandler.cpp
@@ -77,6 +77,7 @@ IpodHandler::IpodHandler( IpodCollection *mc, const QString& \
mountPoint )  , m_jobcounter( 0 )
     , m_autoConnect( false )
     , m_mountPoint( mountPoint )
+    , m_wasMounted( !mountPoint.isEmpty() )
     , m_name()
     , m_isShuffle( false )
     , m_isMobile( false )
@@ -110,14 +111,32 @@ IpodHandler::~IpodHandler()
     debug() << "Cleaning up Ipod Database";
     if ( m_itdb )
         itdb_free( m_itdb );
+
+    if ( !m_wasMounted && !m_mountPoint.isEmpty() )
+    {
+        int error = QProcess::execute("fusermount -u " + m_mountPoint);
+        debug() << "unmounting" << (error ? "failed" : "worked");
+    }
 }
 
 void
 IpodHandler::init()
 {
+    m_wasMounted = true;
+
     if( m_mountPoint.isEmpty() )
     {
         debug() << "Error: empty mountpoint, probably an unmounted iPod/iPhone, \
trying to mount"; +        m_wasMounted = false;
+
+        Solid::Device device = Solid::Device(m_memColl->udi());
+        /* going until we reach a vendor, e.g. Apple */
+        while ( device.isValid() && device.vendor().isEmpty() )
+        {
+            device = Solid::Device( device.parentUdi() );
+        }
+        m_isIPhone = device.product().startsWith("iPhone");
+
         m_mountPoint = KStandardDirs::locateLocal( "tmp", "amarok/" );
         QString udi = m_memColl->udi().replace(QChar('/'), QChar('-'));
         while( udi.startsWith('-') )
@@ -134,18 +153,17 @@ IpodHandler::init()
         QString command = QString("mount.fuse.ifuse %1 %2").arg(udi, m_mountPoint);
         debug() << "mountpoint: " << m_mountPoint;
         debug() << "command: " << command;
-        int result = QProcess::execute(command);
+        int error = QProcess::execute(command);
 
-        debug() << "mounting" << (result ? "failed" : "worked");
+        debug() << "mounting" << (error ? "failed" : "worked");
 
-        if( result )
+        if( error )
         {
             m_memColl->slotAttemptConnectionDone( false );
             return;
         }
     }
 
-
     GError *err = 0;
     QString initError = i18n( "iPod was not initialized:" );
     QString initErrorCaption = i18n( "iPod Initialization Failed" );
@@ -362,7 +380,7 @@ bool
 IpodHandler::isWritable() const
 {
     // TODO: check if read-only
-    return true;
+    return !m_isIPhone;
 }
 
 QString
diff --git a/src/collection/ipodcollection/handler/IpodHandler.h \
b/src/collection/ipodcollection/handler/IpodHandler.h index d4a8e55..c492384 100644
--- a/src/collection/ipodcollection/handler/IpodHandler.h
+++ b/src/collection/ipodcollection/handler/IpodHandler.h
@@ -329,6 +329,7 @@ class MEDIADEVICECOLLECTION_EXPORT IpodHandler : public \
Meta::MediaDeviceHandler  /* Ipod Connection */
         bool    m_autoConnect;
         QString m_mountPoint;
+        bool    m_wasMounted;
         QString m_name;
 
         /* Ipod Model */


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

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