Fwd: extragear/multimedia/amarok/src/collection/sqlcollection

Maximilian Kossick maximilian.kossick at googlemail.com
Sat Mar 29 17:08:23 CET 2008


I forgot to send this commit to the devel list, so in case anybody
developing on windows did not see this commit or did not read it
completely:
I changed the way amarok handles the collectionscanner output. it
works for me, but there's some weird codec handling on win32, so
please test that scanning works on windows too.


---------- Forwarded message ----------
From: Maximilian Kossick <maximilian.kossick at googlemail.com>
Date: Sat, Mar 29, 2008 at 12:08 PM
Subject: extragear/multimedia/amarok/src/collection/sqlcollection
To: kde-commits at kde.org


SVN commit 791382 by mkossick:

 do not convert the byte data delivered by a qprocess to a qstring
directly, which can break on multi-byte characters.
 This might fix bug #159320
 CCBUG: 159320


  M  +28 -12    ScanManager.cpp
  M  +5 -2      ScanManager.h


 --- trunk/extragear/multimedia/amarok/src/collection/sqlcollection/ScanManager.cpp
#791381:791382
 @@ -20,6 +20,7 @@
  #include "ScanManager.h"

  #include "amarokconfig.h"
 +#include "AmarokProcess.h"
  #include "statusbar/ContextStatusBar.h"
  #include "statusbar/progressBar.h"
  #include "debug.h"
 @@ -47,6 +48,7 @@
     , m_parser( 0 )
     , m_restartCount( 0 )
     , m_isIncremental( false )
 +    , m_textStream( 0 )
  {
     //nothing to do
  }
 @@ -62,6 +64,8 @@
     }
     cleanTables();
     m_scanner = new AmarokProcess( this );
 +    m_scanner->setTextModeEnabled( true );
 +    m_textStream = new QTextStream( m_scanner );
     *m_scanner << "amarokcollectionscanner" << "--nocrashhandler";
     if( AmarokConfig::scanRecursively() ) *m_scanner << "-r";
     *m_scanner << MountPointManager::instance()->collectionFolders();
 @@ -98,6 +102,8 @@
         return;
     }
     m_scanner = new AmarokProcess( this );
 +    m_scanner->setTextModeEnabled( true );
 +    m_textStream = new QTextStream( m_scanner );
     *m_scanner << "amarokcollectionscanner" << "--nocrashhandler" << "--i";
     if( AmarokConfig::scanRecursively() ) *m_scanner << "-r";
     *m_scanner << dirs;
 @@ -163,22 +169,26 @@
  void
  ScanManager::slotReadReady()
  {
 -    QByteArray line;
     QString newData;
 -    line = m_scanner->readLine();
 +    QString data = m_textStream->readLine();

 -    while( !line.isEmpty() ) {
 -        //important! see
 +    //converting the byte data as delivered by QProcess to a QString
does not work correctly
 +    //because it might truncate multi-byte characters. I'm leaving
it the code below as a reference
 +    //so that somebody can test if the new code works with the
QTextStreamd defaults on win32, and
 +    //fix it if it does not
 +
 +    while( !data.isEmpty() ) {
 +        /*//important! see
         //http://www.qtcentre.org/forum/f-general-programming-9/t-passing-to-a-console-application-managed-via-qprocess-utf-8-encoded-parameters-5375.html
         //for an explanation of the QString::fromLocal8Bit call
  #ifdef Q_OS_WIN32
         QString data = QTextCodec::codecForName( "UTF-8"
)->toUnicode( line ); // on windows we're UTF-8 regardless of what the
codepage says
  #else
         QString data = QString::fromLocal8Bit( line );
 -#endif
 +#endif*/
         if( !data.startsWith( "exepath=" ) ) // skip binary location
info from scanner
             newData += data;
 -        line = m_scanner->readLine();
 +        data = m_textStream->readLine();
     }
     if( m_parser )
         m_parser->addNewXmlData( newData );
 @@ -193,6 +203,8 @@
     slotReadReady();
     m_scanner->deleteLater();
     m_scanner = 0;
 +    delete m_textStream;
 +    m_textStream = 0;
     m_restartCount = 0;
  }

 @@ -203,6 +215,13 @@
     {
         handleRestart();
     }
 +    else
 +    {
 +        m_scanner->deleteLater();
 +        delete m_textStream;
 +        m_scanner = 0;
 +        m_textStream = 0;
 +    }
  }

  QStringList
 @@ -237,7 +256,6 @@
             {
                 result << folder;
                 changedFolderIds << id;
 -//                 debug() << "Collection dir changed: " << folder;
             }
         }
         else
 @@ -245,7 +263,6 @@
             // this folder has been removed
             result << folder;
             changedFolderIds << id;
 -//             debug() << "Collection dir removed: " << folder;
         }
     }
     {
 @@ -268,10 +285,6 @@
         QString sql = QString( "DELETE FROM tracks WHERE url IN ( %1
);" ).arg( ids );
         m_collection->query( sql );
     }
 -// //     if( result.isEmpty() )
 -// //         debug() << "incremental scan not necessary";
 -// // //     else
 -// // //         debug() << "scanning dirs: " << result;
     return result;
  }

 @@ -302,7 +315,10 @@
             m_parser = 0;
         }
         delete m_scanner;
 +        delete m_textStream;
         m_scanner = new AmarokProcess( this );
 +        m_scanner->setTextModeEnabled( true );
 +        m_textStream = new QTextStream( m_scanner );
         *m_scanner << "amarokcollectionscanner" << "--nocrashhandler";
         if( m_isIncremental )
         {
 --- trunk/extragear/multimedia/amarok/src/collection/sqlcollection/ScanManager.h
#791381:791382
 @@ -20,10 +20,10 @@
  #ifndef AMAROK_SQL_SCANMANAGER_H
  #define AMAROK_SQL_SCANMANAGER_H

 -#include "AmarokProcess.h"
 -
  #include <QMutex>
  #include <QObject>
 +#include <QProcess>
 +#include <QTextStream>
  #include <QWaitCondition>
  #include <QXmlStreamReader>

 @@ -31,6 +31,7 @@

  class SqlCollection;
  class XmlParseJob;
 +class AmarokProcess;

  class ScanManager : public QObject
  {
 @@ -64,6 +65,8 @@

         int m_restartCount;
         bool m_isIncremental;
 +
 +        QTextStream *m_textStream;
  };

  class XmlParseJob : public ThreadWeaver::Job


More information about the Amarok-devel mailing list