* @param device The LIBMTP_mtpdevice_t pointer to cache
* @param udi The UDI of the new device to cache
*/
-CachedDevice::CachedDevice ( LIBMTP_mtpdevice_t* device, LIBMTP_raw_device_t* rawdevice, const QString udi, qint32 timeout )
+CachedDevice::CachedDevice(LIBMTP_mtpdevice_t* device, LIBMTP_raw_device_t* rawdevice, const QString udi, qint32 timeout)
{
this->timeout = timeout;
this->mtpdevice = device;
this->rawdevice = *rawdevice;
this->udi = udi;
- char *deviceName = LIBMTP_Get_Friendlyname ( device );
- char *deviceModel = LIBMTP_Get_Modelname ( device );
+ char *deviceName = LIBMTP_Get_Friendlyname(device);
+ char *deviceModel = LIBMTP_Get_Modelname(device);
// prefer friendly devicename over model
- if ( !deviceName )
- name = QString::fromUtf8 ( deviceModel );
- else
- name = QString::fromUtf8 ( deviceName );
+ if (!deviceName) {
+ name = QString::fromUtf8(deviceModel);
+ } else {
+ name = QString::fromUtf8(deviceName);
+ }
- kDebug ( KIO_MTP ) << "Created device " << name << " with udi=" << udi << " and timeout " << timeout;
+ kDebug(KIO_MTP) << "Created device" << name << "with udi" << udi << " and timeout" << timeout;
}
CachedDevice::~CachedDevice()
{
- LIBMTP_Release_Device ( mtpdevice );
+ LIBMTP_Release_Device(mtpdevice);
}
LIBMTP_mtpdevice_t* CachedDevice::getDevice()
{
LIBMTP_mtpdevice_t* device = mtpdevice;
- if (!device->storage)
- {
- kDebug ( KIO_MTP ) << "reopen mtpdevice if we have no storage found";
- LIBMTP_Release_Device ( mtpdevice );
- mtpdevice = LIBMTP_Open_Raw_Device_Uncached ( &rawdevice );
+ if (!device->storage) {
+ kDebug(KIO_MTP) << "reopen mtpdevice if we have no storage found";
+ LIBMTP_Release_Device(mtpdevice);
+ mtpdevice = LIBMTP_Open_Raw_Device_Uncached(&rawdevice);
}
-
return mtpdevice;
}
-const QString CachedDevice::getName()
+const QString CachedDevice::getName() const
{
return name;
}
-const QString CachedDevice::getUdi()
+
+const QString CachedDevice::getUdi() const
{
return udi;
}
-
-DeviceCache::DeviceCache ( qint32 timeout, QObject* parent ) : QEventLoop ( parent )
+DeviceCache::DeviceCache(qint32 timeout, QObject*parent)
+ : QEventLoop(parent)
{
this->timeout = timeout;
notifier = Solid::DeviceNotifier::instance();
- connect( notifier, SIGNAL( deviceAdded( QString ) ), this, SLOT( deviceAdded( QString ) ) );
- connect( notifier, SIGNAL( deviceRemoved(QString) ), this, SLOT( deviceRemoved(QString) ) );
+ connect(notifier, SIGNAL(deviceAdded(QString)), this, SLOT(deviceAdded(QString)));
+ connect(notifier, SIGNAL(deviceRemoved(QString)), this, SLOT(deviceRemoved(QString)));
- foreach ( Solid::Device solidDevice, Solid::Device::listFromType ( Solid::DeviceInterface::PortableMediaPlayer, QString() ) )
- {
- checkDevice( solidDevice );
+ foreach (Solid::Device solidDevice, Solid::Device::listFromType(Solid::DeviceInterface::PortableMediaPlayer)) {
+ checkDevice(solidDevice);
}
}
void DeviceCache::checkDevice ( Solid::Device solidDevice )
{
Solid::PortableMediaPlayer *iface = solidDevice.as<Solid::PortableMediaPlayer>();
- if ( !iface )
- {
- kWarning ( KIO_MTP ) << "not portable media player device" << solidDevice.udi();
+ if (!iface) {
+ kWarning(KIO_MTP) << "Not portable media player device" << solidDevice.udi();
return;
}
// request handle for MTP protocol
- static const QString solidDriver( QLatin1String("mtp") );
+ static const QString solidDriver(QLatin1String("mtp"));
const QByteArray solidSerial = iface->driverHandle(solidDriver).toByteArray();
- if ( solidSerial.isEmpty() )
- {
- kWarning ( KIO_MTP ) << "no serial for device" << solidDevice.udi();
+ if (solidSerial.isEmpty()) {
+ kWarning (KIO_MTP) << "No serial for device" << solidDevice.udi();
return;
}
- if (!udiCache.contains( solidDevice.udi() ) )
- {
- kDebug ( KIO_MTP ) << "new device, getting raw devices";
+ if (!udiCache.contains(solidDevice.udi())) {
+ kDebug(KIO_MTP) << "New device, getting raw devices";
LIBMTP_raw_device_t *rawdevices = 0;
int numrawdevices;
- LIBMTP_error_number_t err;
-
- QMap<QString, LIBMTP_raw_device_t*> devices;
- err = LIBMTP_Detect_Raw_Devices ( &rawdevices, &numrawdevices );
- switch ( err )
- {
- case LIBMTP_ERROR_CONNECTING:
- kError( KIO_MTP ) << "There has been an error connecting to the devices";
+ LIBMTP_error_number_t err = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices);
+ switch (err) {
+ case LIBMTP_ERROR_CONNECTING: {
+ kError(KIO_MTP) << "There has been an error connecting to the devices";
break;
- case LIBMTP_ERROR_MEMORY_ALLOCATION:
- kError( KIO_MTP ) << "Encountered a Memory Allocation Error";
+ }
+ case LIBMTP_ERROR_MEMORY_ALLOCATION: {
+ kError(KIO_MTP) << "Encountered a Memory Allocation Error";
break;
- case LIBMTP_ERROR_NONE:
- {
- kDebug( KIO_MTP ) << "No Error, continuing";
+ }
+ case LIBMTP_ERROR_NONE: {
+ kDebug(KIO_MTP) << "No Error, continuing";
- for ( int i = 0; i < numrawdevices; i++ )
- {
+ for (int i = 0; i < numrawdevices; i++) {
LIBMTP_raw_device_t* rawDevice = &rawdevices[i];
- LIBMTP_mtpdevice_t *mtpDevice = LIBMTP_Open_Raw_Device_Uncached ( rawDevice );
- const char* rawDeviceSerial = LIBMTP_Get_Serialnumber( mtpDevice );
+ LIBMTP_mtpdevice_t *mtpDevice = LIBMTP_Open_Raw_Device_Uncached(rawDevice);
+ const char* rawDeviceSerial = LIBMTP_Get_Serialnumber(mtpDevice);
- kDebug( KIO_MTP ) << "Checking for device match" << solidSerial << rawDeviceSerial;
- if ( solidSerial == rawDeviceSerial )
- {
+ kDebug(KIO_MTP) << "Checking for device match" << solidSerial << rawDeviceSerial;
+ if (solidSerial == rawDeviceSerial) {
kDebug( KIO_MTP ) << "Found device matching the Solid description";
- }
- else
- {
+ } else {
LIBMTP_Release_Device( mtpDevice);
continue;
}
- if ( udiCache.find( solidDevice.udi() ) == udiCache.end() )
- {
- CachedDevice *cDev = new CachedDevice( mtpDevice, rawDevice, solidDevice.udi(), timeout );
- udiCache.insert( solidDevice.udi(), cDev );
- nameCache.insert( cDev->getName(), cDev );
+ if (!udiCache.contains(solidDevice.udi())) {
+ CachedDevice *cDev = new CachedDevice(mtpDevice, rawDevice, solidDevice.udi(), timeout);
+ udiCache.insert(solidDevice.udi(), cDev);
+ nameCache.insert(cDev->getName(), cDev);
}
}
break;
}
case LIBMTP_ERROR_GENERAL:
- default:
- kError( KIO_MTP ) << "Unknown connection error";
+ default: {
+ kError(KIO_MTP) << "Unknown connection error";
break;
+ }
}
- free(rawdevices);
+ ::free(rawdevices);
}
}
-void DeviceCache::deviceAdded ( const QString& udi )
+void DeviceCache::deviceAdded(const QString& udi)
{
- kDebug( KIO_MTP ) << "New device attached with udi=" << udi << ". Checking if PortableMediaPlayer...";
+ kDebug(KIO_MTP) << "New device attached with udi" << udi << ". Checking if PortableMediaPlayer...";
- Solid::Device device( udi );
- if ( device.isDeviceInterface( Solid::DeviceInterface::PortableMediaPlayer ) )
- {
- kDebug ( KIO_MTP ) << "SOLID: New Device with udi=" << udi;
+ Solid::Device device(udi);
+ if (device.isDeviceInterface(Solid::DeviceInterface::PortableMediaPlayer)) {
+ kDebug(KIO_MTP) << "SOLID: New Device with udi" << udi;
- checkDevice( device );
+ checkDevice(device);
}
}
-void DeviceCache::deviceRemoved ( const QString& udi )
+void DeviceCache::deviceRemoved(const QString& udi)
{
- if ( udiCache.contains( udi ) )
- {
- kDebug ( KIO_MTP ) << "SOLID: Device with udi=" << udi << " removed.";
+ if (udiCache.contains(udi)) {
+ kDebug ( KIO_MTP ) << "SOLID: Device with udi" << udi << "removed.";
- CachedDevice *cDev = udiCache.value( udi );
+ CachedDevice *cDev = udiCache.value(udi);
- udiCache.remove( cDev->getUdi() );
- nameCache.remove( cDev->getName() );
+ udiCache.remove(cDev->getUdi());
+ nameCache.remove(cDev->getName());
delete cDev;
}
}
processEvents();
// Release devices
- foreach ( QString udi, udiCache.keys() )
- {
- deviceRemoved( udi );
+ foreach (QString udi, udiCache.keys()) {
+ deviceRemoved(udi);
}
}
QHash<QString, CachedDevice*> DeviceCache::getAll()
{
- kDebug ( KIO_MTP ) << "getAll()";
+ kDebug(KIO_MTP ) << "getAll()";
processEvents();
return nameCache;
}
-bool DeviceCache::contains ( QString string, bool isUdi )
+bool DeviceCache::contains(QString string, bool isUdi)
{
processEvents();
- if ( isUdi )
- return udiCache.find ( string ) != udiCache.end();
- else
- return nameCache.find ( string ) != nameCache.end();
+ if (isUdi) {
+ return udiCache.contains(string);
+ }
+ return nameCache.contains(string);
}
-CachedDevice* DeviceCache::get ( const QString& string, bool isUdi )
+CachedDevice* DeviceCache::get(const QString& string, bool isUdi)
{
processEvents();
- if ( isUdi )
- return udiCache.value ( string );
- else
- return nameCache.value ( string );
+ if (isUdi) {
+ return udiCache.value(string);
+ }
+ return nameCache.value(string);
}
int DeviceCache::size()
//////////////////////////////////////////////////////////////////////////////
extern "C"
-int KDE_EXPORT kdemain ( int argc, char **argv )
+int KDE_EXPORT kdemain(int argc, char **argv)
{
- KComponentData instance ( "kio_mtp" );
+ KComponentData instance("kio_mtp");
KGlobal::locale();
- QCoreApplication app( argc, argv );
+ QCoreApplication app(argc, argv);
- if ( argc != 4 )
- {
- fprintf ( stderr, "Usage: kio_mtp protocol domain-socket1 domain-socket2\n" );
- exit ( -1 );
+ if (argc != 4) {
+ fprintf(stderr, "Usage: kio_mtp protocol domain-socket1 domain-socket2\n");
+ exit(-1);
}
- MTPSlave slave ( argv[2], argv[3] );
+ MTPSlave slave(argv[2], argv[3]);
slave.dispatchLoop();
- kDebug ( KIO_MTP ) << "Slave EventLoop ended";
+ kDebug(KIO_MTP) << "Slave EventLoop ended";
return 0;
}
-MTPSlave::MTPSlave ( const QByteArray& pool, const QByteArray& app )
- : SlaveBase ( "mtp", pool, app )
+MTPSlave::MTPSlave(const QByteArray& pool, const QByteArray& app)
+ : SlaveBase("mtp", pool, app)
{
LIBMTP_Init();
- kDebug ( KIO_MTP ) << "Slave started";
+ kDebug(KIO_MTP) << "Slave started";
- deviceCache = new DeviceCache( 60000, this );
- fileCache = new FileCache ( this );
+ deviceCache = new DeviceCache(60000, this);
+ fileCache = new FileCache(this);
- kDebug ( KIO_MTP ) << "Caches created";
+ kDebug(KIO_MTP) << "Caches created";
}
MTPSlave::~MTPSlave()
{
- kDebug ( KIO_MTP ) << "Slave destroyed";
+ kDebug(KIO_MTP) << "Slave destroyed";
}
/**
* @param pathItems A QStringList containing the items of the filepath
* @return QPair with the object and its device. pair.first is a nullpointer if the object doesn't exist or for root or, depending on the pathItems size device (1), storage (2) or file (>=3)
*/
-QPair<void*, LIBMTP_mtpdevice_t*> MTPSlave::getPath ( const QString& path )
+QPair<void*, LIBMTP_mtpdevice_t*> MTPSlave::getPath(const QString& path)
{
- QStringList pathItems = path.split ( QLatin1Char ( '/' ), QString::SkipEmptyParts );
+ QStringList pathItems = path.split(QLatin1Char('/'), QString::SkipEmptyParts);
- kDebug ( KIO_MTP ) << path << pathItems.size();
+ kDebug(KIO_MTP) << path << pathItems.size();
QPair<void*, LIBMTP_mtpdevice_t*> ret;
// Don' handle the root directory
- if ( pathItems.size() <= 0 )
- {
+ if (pathItems.size() <= 0) {
return ret;
}
- if ( deviceCache->contains( pathItems.at ( 0 ) ) )
+ if (deviceCache->contains(pathItems.at(0)))
{
- LIBMTP_mtpdevice_t *device = deviceCache->get ( pathItems.at ( 0 ) )->getDevice();
+ LIBMTP_mtpdevice_t *device = deviceCache->get(pathItems.at(0))->getDevice();
// return specific device
- if ( pathItems.size() == 1 )
- {
+ if (pathItems.size() == 1) {
ret.first = device;
ret.second = device;
kDebug(KIO_MTP) << "returning LIBMTP_mtpdevice_t";
}
- if ( pathItems.size() > 2 )
- {
+ if (pathItems.size() > 2) {
// Query Cache after we have the device
- uint32_t c_fileID = fileCache->queryPath ( path );
- if ( c_fileID != 0 )
- {
- kDebug() << "Match found in cache, checking device";
-
- LIBMTP_file_t* file = LIBMTP_Get_Filemetadata ( device, c_fileID );
- if ( file )
- {
- kDebug ( KIO_MTP ) << "Found file in cache";
+ uint32_t c_fileID = fileCache->queryPath(path);
+ if (c_fileID != 0) {
+ kDebug(KIO_MTP) << "Match found in cache, checking device";
+
+ LIBMTP_file_t* file = LIBMTP_Get_Filemetadata(device, c_fileID);
+ if (file) {
+ kDebug(KIO_MTP) << "Found file in cache";
+
ret.first = file;
ret.second = device;
return ret;
}
- }
// Query cache for parent
- else if ( pathItems.size() > 3 )
- {
- QString parentPath = convertToPath ( pathItems, pathItems.size() - 1 );
- uint32_t c_parentID = fileCache->queryPath ( parentPath );
+ } else if (pathItems.size() > 3) {
+ QString parentPath = convertToPath(pathItems, pathItems.size() - 1);
+ uint32_t c_parentID = fileCache->queryPath(parentPath);
- kDebug() << "Match for parent found in cache, checking device. Parent id = " << c_parentID;
+ kDebug(KIO_MTP) << "Match for parent found in cache, checking device. Parent id" << c_parentID;
- LIBMTP_file_t* parent = LIBMTP_Get_Filemetadata ( device, c_parentID );
- if ( parent )
- {
- kDebug ( KIO_MTP ) << "Found parent in cache";
-// fileCache->addPath( parentPath, c_parentID );
+ LIBMTP_file_t* parent = LIBMTP_Get_Filemetadata(device, c_parentID);
+ if (parent) {
+ kDebug(KIO_MTP) << "Found parent in cache";
+ // fileCache->addPath(parentPath, c_parentID);
- QMap<QString, LIBMTP_file_t*> files = getFiles ( device, parent->storage_id, c_parentID );
+ QMap<QString, LIBMTP_file_t*> files = getFiles(device, parent->storage_id, c_parentID);
- for ( QMap<QString, LIBMTP_file_t*>::iterator it = files.begin(); it != files.end(); ++it )
- {
+ for ( QMap<QString, LIBMTP_file_t*>::iterator it = files.begin(); it != files.end(); ++it) {
QString filePath = parentPath;
- filePath.append( QString::fromUtf8("/") ).append( it.key() );
- fileCache->addPath( filePath, it.value()->item_id );
+ filePath.append(QString::fromUtf8("/") ).append(it.key());
+ fileCache->addPath(filePath, it.value()->item_id);
}
- if ( files.contains ( pathItems.last() ) )
- {
- LIBMTP_file_t* file = files.value( pathItems.last() );
+ if (files.contains(pathItems.last())) {
+ LIBMTP_file_t* file = files.value(pathItems.last());
ret.first = file;
ret.second = device;
- kDebug(KIO_MTP) << "returning LIBMTP_file_t from cached parent" ;
+ kDebug(KIO_MTP) << "returning LIBMTP_file_t from cached parent";
- fileCache->addPath( path, file->item_id );
+ fileCache->addPath(path, file->item_id);
}
return ret;
}
}
- QMap<QString, LIBMTP_devicestorage_t*> storages = getDevicestorages ( device );
+ QMap<QString, LIBMTP_devicestorage_t*> storages = getDevicestorages(device);
- if ( pathItems.size() > 1 && storages.contains ( pathItems.at ( 1 ) ) )
- {
- LIBMTP_devicestorage_t *storage = storages.value ( pathItems.at ( 1 ) );
+ if (pathItems.size() > 1 && storages.contains(pathItems.at(1))) {
+ LIBMTP_devicestorage_t *storage = storages.value(pathItems.at(1));
- if ( pathItems.size() == 2 )
- {
+ if (pathItems.size() == 2) {
ret.first = storage;
ret.second = device;
QMap<QString, LIBMTP_file_t*> files;
// traverse further while depth not reached
- while ( currentLevel < pathItems.size() )
- {
- files = getFiles ( device, storage->id, currentParent );
-
- if ( files.contains ( pathItems.at ( currentLevel ) ) )
- {
- currentParent = files.value ( pathItems.at ( currentLevel ) )->item_id;
- }
- else
- {
+ while (currentLevel < pathItems.size()) {
+ files = getFiles(device, storage->id, currentParent);
+ if (files.contains(pathItems.at(currentLevel))) {
+ currentParent = files.value(pathItems.at(currentLevel))->item_id;
+ } else {
kDebug(KIO_MTP) << "returning LIBMTP_file_t using tree walk";
return ret;
currentLevel++;
}
- ret.first = LIBMTP_Get_Filemetadata ( device, currentParent );
+ ret.first = LIBMTP_Get_Filemetadata(device, currentParent);
ret.second = device;
- fileCache->addPath ( path, currentParent );
+ fileCache->addPath(path, currentParent);
}
}
return ret;
}
-int MTPSlave::checkUrl ( const KUrl& url, bool redirect )
+int MTPSlave::checkUrl(const KUrl& url, bool redirect)
{
- kDebug ( KIO_MTP ) << url;
+ kDebug(KIO_MTP ) << url;
- if ( url.path().startsWith ( QLatin1String ( "udi=" ) ) && redirect )
- {
- QString udi = url.path( KUrl::RemoveTrailingSlash ).remove ( 0, 4 );
+ if (url.path().startsWith(QLatin1String("udi=")) && redirect) {
+ QString udi = url.path(KUrl::RemoveTrailingSlash).remove(0, 4);
- kDebug ( KIO_MTP ) << "udi = " << udi;
+ kDebug(KIO_MTP) << "udi" << udi;
- if ( deviceCache->contains( udi, true ) )
- {
+ if (deviceCache->contains(udi, true)) {
KUrl newUrl;
- newUrl.setProtocol ( QLatin1String ( "mtp" ) );
- newUrl.setPath ( QLatin1Char ( '/' ) + deviceCache->get( udi, true )->getName() );
- redirection ( newUrl );
+ newUrl.setProtocol(QLatin1String("mtp"));
+ newUrl.setPath(QLatin1Char('/') + deviceCache->get(udi, true)->getName());
+ redirection(newUrl);
return 1;
- }
- else
- {
+ } else {
return 2;
}
- }
- else if ( url.path().startsWith(QLatin1Char ( '/' ) ) )
- {
+ } else if (url.path().startsWith(QLatin1Char('/'))) {
return 0;
}
return -1;
}
-void MTPSlave::listDir ( const KUrl& url )
+void MTPSlave::listDir(const KUrl& url)
{
- kDebug ( KIO_MTP ) << url.path();
+ kDebug(KIO_MTP) << url.path();
- int check = checkUrl( url );
- switch ( check )
- {
- case 0:
+ int check = checkUrl(url);
+ switch (check) {
+ case 0: {
break;
- case 1:
+ }
+ case 1: {
finished();
return;
- case 2:
- error( ERR_DOES_NOT_EXIST, url.path() );
+ }
+ case 2: {
+ error(ERR_DOES_NOT_EXIST, url.path());
return;
- default:
- error( ERR_MALFORMED_URL, url.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, url.path());
return;
+ }
}
- QStringList pathItems = url.path().split ( QLatin1Char ( '/' ), QString::SkipEmptyParts );
+ QStringList pathItems = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
UDSEntry entry;
// list devices
- if ( pathItems.size() == 0 )
- {
- kDebug ( KIO_MTP ) << "Root directory, listing devices";
- totalSize ( deviceCache->size() );
+ if (pathItems.size() == 0) {
+ kDebug (KIO_MTP) << "Root directory, listing devices";
- foreach ( CachedDevice* cachedDevice, deviceCache->getAll().values() )
+ totalSize(deviceCache->size());
+
+ foreach (CachedDevice* cachedDevice, deviceCache->getAll().values())
{
LIBMTP_mtpdevice_t *device = cachedDevice->getDevice();
- getEntry ( entry, device );
+ getEntry(entry, device);
- listEntry ( entry, false );
+ listEntry(entry, false);
entry.clear();
}
- listEntry ( entry, true );
+ listEntry(entry, true);
- kDebug ( KIO_MTP ) << "[SUCCESS] :: Devices";
+ kDebug(KIO_MTP ) << "[SUCCESS] :: Devices";
finished();
- }
// traverse into device
- else if ( deviceCache->contains ( pathItems.at ( 0 ) ) )
- {
- QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( url.path() );
+ } else if (deviceCache->contains(pathItems.at(0))) {
+ QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath(url.path());
UDSEntry entry;
-
- if ( pair.first )
- {
+
+ if (pair.first) {
LIBMTP_mtpdevice_t *device = pair.second;
// Device, list storages
- if ( pathItems.size() == 1 )
- {
- QMap<QString, LIBMTP_devicestorage_t*> storages = getDevicestorages ( device );
-
- kDebug ( KIO_MTP ) << "Listing storages for device " << pathItems.at ( 0 );
- totalSize ( storages.size() );
+ if (pathItems.size() == 1) {
+ QMap<QString, LIBMTP_devicestorage_t*> storages = getDevicestorages(device);
- if ( storages.size() > 0 )
- {
- foreach ( const QString &storageName, storages.keys() )
- {
- getEntry ( entry, storages.value ( storageName ) );
+ kDebug (KIO_MTP) << "Listing storages for device " << pathItems.at(0);
+ totalSize (storages.size());
- listEntry ( entry, false );
+ if (storages.size() > 0) {
+ foreach (const QString &storageName, storages.keys()) {
+ getEntry(entry, storages.value(storageName));
+
+ listEntry(entry, false);
entry.clear();
}
- listEntry ( entry, true );
+ listEntry(entry, true);
finished();
- kDebug ( KIO_MTP ) << "[SUCCESS] :: Storages";
- }
- else
- {
- warning( i18n("No Storages found. Maybe you need to unlock your device?") );
+ kDebug(KIO_MTP) << "[SUCCESS] :: Storages";
+ } else {
+ warning(i18n("No Storages found. Maybe you need to unlock your device?"));
}
- }
// Storage, list files and folders of storage root
- else
- {
+ } else {
QMap<QString, LIBMTP_file_t*> files;
-
- if ( pathItems.size() == 2 )
- {
+
+ if (pathItems.size() == 2) {
kDebug(KIO_MTP) << "Getting storage root listing";
-
+
LIBMTP_devicestorage_t *storage = (LIBMTP_devicestorage_t*)pair.first;
-
+
kDebug(KIO_MTP) << "We have a storage:" << (storage == NULL);
-
- files = getFiles( device, storage->id );
- }
- else
- {
+
+ files = getFiles(device, storage->id);
+ } else {
LIBMTP_file_t *parent = (LIBMTP_file_t*)pair.first;
-
- files = getFiles( device, parent->storage_id, parent->item_id );
+
+ files = getFiles(device, parent->storage_id, parent->item_id);
}
- for ( QMap<QString, LIBMTP_file_t*>::iterator it = files.begin(); it != files.end(); ++it )
- {
+ for (QMap<QString, LIBMTP_file_t*>::iterator it = files.begin(); it != files.end(); ++it) {
LIBMTP_file_t *file = it.value();
+
+ QString filePath = url.path(KUrl::AddTrailingSlash).append(it.key());
+ fileCache->addPath(filePath, file->item_id);
- QString filePath = url.path( KUrl::AddTrailingSlash ).append( it.key() );
- fileCache->addPath( filePath, file->item_id );
-
- getEntry ( entry, file );
+ getEntry(entry, file);
- listEntry ( entry, false );
+ listEntry(entry, false);
entry.clear();
}
-
- listEntry ( entry, true );
+
+ listEntry(entry, true);
finished();
-
- kDebug ( KIO_MTP ) << "[SUCCESS] Files";
+
+ kDebug(KIO_MTP) << "[SUCCESS] Files";
}
+ } else {
+ error(ERR_CANNOT_ENTER_DIRECTORY, url.path());
+ kDebug(KIO_MTP) << "[ERROR]";
}
- else
- {
- error ( ERR_CANNOT_ENTER_DIRECTORY, url.path() );
- kDebug ( KIO_MTP ) << "[ERROR]";
- }
- }
- else
- {
- error ( ERR_CANNOT_ENTER_DIRECTORY, url.path() );
- kDebug ( KIO_MTP ) << "[ERROR]";
+ } else {
+ error(ERR_CANNOT_ENTER_DIRECTORY, url.path());
+ kDebug(KIO_MTP) << "[ERROR]";
}
}
-void MTPSlave::stat ( const KUrl& url )
+void MTPSlave::stat(const KUrl& url)
{
- kDebug ( KIO_MTP ) << url.path();
+ kDebug(KIO_MTP) << url.path();
- int check = checkUrl( url );
- switch ( check )
- {
- case 0:
+ int check = checkUrl(url);
+ switch (check) {
+ case 0: {
break;
- case 1:
+ }
+ case 1: {
finished();
return;
- case 2:
- error( ERR_DOES_NOT_EXIST, url.path() );
+ }
+ case 2: {
+ error(ERR_DOES_NOT_EXIST, url.path());
return;
- default:
- error( ERR_MALFORMED_URL, url.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, url.path());
return;
+ }
}
- QStringList pathItems = url.path().split ( QLatin1Char ( '/' ), QString::SkipEmptyParts );
+ QStringList pathItems = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
- QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( url.path() );
+ QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath(url.path());
UDSEntry entry;
- if ( pair.first )
- {
+ if (pair.first) {
// Root
- if ( pathItems.size() < 1 )
- {
- entry.insert ( UDSEntry::UDS_NAME, QLatin1String ( "mtp:///" ) );
- entry.insert ( UDSEntry::UDS_FILE_TYPE, S_IFDIR );
- entry.insert ( UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH );
- entry.insert ( UDSEntry::UDS_MIME_TYPE, QLatin1String ( "inode/directory" ) );
- }
+ if (pathItems.size() < 1) {
+ entry.insert(UDSEntry::UDS_NAME, QLatin1String("mtp:///"));
+ entry.insert(UDSEntry::UDS_FILE_TYPE, S_IFDIR );
+ entry.insert(UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH);
+ entry.insert(UDSEntry::UDS_MIME_TYPE, QLatin1String("inode/directory"));
// Device
- else if ( pathItems.size() < 2 )
- {
- getEntry ( entry, pair.second );
- }
+ } else if (pathItems.size() < 2) {
+ getEntry(entry, pair.second);
// Storage
- else if ( pathItems.size() < 3 )
- {
- getEntry ( entry, ( LIBMTP_devicestorage_t* ) pair.first );
- }
+ } else if (pathItems.size() < 3) {
+ getEntry ( entry, (LIBMTP_devicestorage_t* )pair.first);
// Folder/File
- else
- {
- getEntry ( entry, ( LIBMTP_file_t* ) pair.first );
+ } else {
+ getEntry(entry, (LIBMTP_file_t*) pair.first);
}
}
- statEntry ( entry );
+ statEntry(entry);
finished();
}
-void MTPSlave::mimetype ( const KUrl& url )
+void MTPSlave::mimetype(const KUrl& url)
{
- int check = checkUrl( url );
- switch ( check )
+ int check = checkUrl(url);
+ switch (check)
{
- case 0:
+ case 0: {
break;
- case 1:
+ }
+ case 1: {
finished();
return;
- case 2:
- error( ERR_DOES_NOT_EXIST, url.path() );
+ }
+ case 2: {
+ error(ERR_DOES_NOT_EXIST, url.path());
return;
- default:
- error( ERR_MALFORMED_URL, url.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, url.path());
return;
+ }
}
- kDebug ( KIO_MTP ) << url.path();
+ kDebug(KIO_MTP) << url.path();
- QStringList pathItems = url.path().split ( QLatin1Char ( '/' ), QString::SkipEmptyParts );
+ QStringList pathItems = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
- QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( url.path() );
+ QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath(url.path());
- if ( pair.first )
- {
- if ( pathItems.size() > 2 )
- mimetype ( getMimetype ( ( ( LIBMTP_file_t* ) pair.first )->filetype ) );
- else
- mimetype ( QString::fromLatin1 ( "inode/directory" ) );
- }
- else
- {
- error ( ERR_DOES_NOT_EXIST, url.path() );
+ if (pair.first) {
+ if (pathItems.size() > 2) {
+ mimetype(getMimetype(((LIBMTP_file_t*)pair.first)->filetype));
+ } else {
+ mimetype(QString::fromLatin1("inode/directory"));
+ }
+ } else {
+ error(ERR_DOES_NOT_EXIST, url.path());
return;
}
}
-void MTPSlave::put ( const KUrl& url, int, JobFlags flags )
+void MTPSlave::put(const KUrl& url, int, JobFlags flags)
{
- int check = checkUrl( url );
- switch ( check )
- {
- case 0:
+ int check = checkUrl(url);
+ switch (check) {
+ case 0: {
break;
- default:
- error( ERR_MALFORMED_URL, url.path() );
+ }
+ default: {
+ error( ERR_MALFORMED_URL, url.path());
return;
+ }
}
- kDebug ( KIO_MTP ) << url.path();
+ kDebug(KIO_MTP) << url.path();
- QStringList destItems = url.path().split ( QLatin1Char ( '/' ), QString::SkipEmptyParts );
+ QStringList destItems = url.path().split(QLatin1Char( '/' ), QString::SkipEmptyParts);
// Can't copy to root or device, needs storage
- if ( destItems.size() < 2 )
- {
- error ( ERR_UNSUPPORTED_ACTION, url.path() );
+ if (destItems.size() < 2) {
+ error(ERR_UNSUPPORTED_ACTION, url.path());
return;
}
- if ( !(flags & KIO::Overwrite) && getPath( url.path() ).first )
- {
- error( ERR_FILE_ALREADY_EXIST, url.path() );
+ if (!(flags & KIO::Overwrite) && getPath(url.path()).first) {
+ error(ERR_FILE_ALREADY_EXIST, url.path());
return;
}
destItems.takeLast();
- QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( url.directory() );
+ QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath(url.directory());
- if ( !pair.first )
- {
- error ( ERR_DOES_NOT_EXIST, url.path() );
+ if (!pair.first) {
+ error(ERR_DOES_NOT_EXIST, url.path());
return;
}
LIBMTP_mtpdevice_t *device = pair.second;
- LIBMTP_file_t *parent = ( LIBMTP_file_t* ) pair.first;
- if ( parent->filetype != LIBMTP_FILETYPE_FOLDER )
- {
- error ( ERR_IS_FILE, url.directory() );
+ LIBMTP_file_t *parent = (LIBMTP_file_t*)pair.first;
+ if (parent->filetype != LIBMTP_FILETYPE_FOLDER) {
+ error(ERR_IS_FILE, url.directory());
return;
}
// We did get a total size from the application
- if ( hasMetaData ( QLatin1String ( "sourceSize" ) ) )
- {
- kDebug ( KIO_MTP ) << "direct put";
+ if (hasMetaData(QLatin1String("sourceSize"))) {
+ kDebug(KIO_MTP) << "direct put";
LIBMTP_file_t *file = LIBMTP_new_file_t();
file->parent_id = parent->item_id;
- file->filename = strdup ( url.fileName().toUtf8().data() );
- file->filetype = getFiletype ( url.fileName() );
- file->filesize = metaData ( QLatin1String ( "sourceSize" ) ).toULongLong();
+ file->filename = strdup(url.fileName().toUtf8().data());
+ file->filetype = getFiletype(url.fileName());
+ file->filesize = metaData(QLatin1String("sourceSize")).toULongLong();
file->modificationdate = QDateTime::currentDateTime().toTime_t();
file->storage_id = parent->storage_id;
- kDebug ( KIO_MTP ) << "Sending file" << file->filename;
+ kDebug(KIO_MTP) << "Sending file" << file->filename;
- int ret = LIBMTP_Send_File_From_Handler ( device, &dataGet, this, file, &dataProgress, this );
- if ( ret != 0 )
- {
- error ( KIO::ERR_COULD_NOT_WRITE, url.fileName() );
- LIBMTP_Dump_Errorstack ( device );
- LIBMTP_Clear_Errorstack ( device );
+ int ret = LIBMTP_Send_File_From_Handler(device, &dataGet, this, file, &dataProgress, this);
+ if (ret != 0) {
+ error (KIO::ERR_COULD_NOT_WRITE, url.fileName());
+ LIBMTP_Dump_Errorstack(device);
+ LIBMTP_Clear_Errorstack(device);
return;
}
- }
// We need to get the entire file first, then we can upload
- else
- {
- kDebug ( KIO_MTP ) << "use temp file";
+ } else {
+ kDebug(KIO_MTP) << "use temp file";
KTemporaryFile temp;
QByteArray buffer;
int len = 0;
- do
- {
+ do {
dataReq();
- len = readData ( buffer );
- temp.write ( buffer );
- }
- while ( len > 0 );
+ len = readData(buffer);
+ temp.write (buffer);
+ } while (len > 0);
- QFileInfo info ( temp );
+ QFileInfo info(temp);
LIBMTP_file_t *file = LIBMTP_new_file_t();
file->parent_id = parent->item_id;
- file->filename = strdup ( url.fileName().toUtf8().data() );
- file->filetype = getFiletype ( url.fileName() );
+ file->filename = strdup(url.fileName().toUtf8().data());
+ file->filetype = getFiletype(url.fileName());
file->filesize = info.size();
file->modificationdate = QDateTime::currentDateTime().toTime_t();
file->storage_id = parent->storage_id;
- int ret = LIBMTP_Send_File_From_File_Descriptor ( device, temp.handle(), file, NULL, NULL );
- if ( ret != 0 )
- {
- error ( KIO::ERR_COULD_NOT_WRITE, url.fileName() );
+ int ret = LIBMTP_Send_File_From_File_Descriptor(device, temp.handle(), file, NULL, NULL);
+ if (ret != 0) {
+ error(KIO::ERR_COULD_NOT_WRITE, url.fileName());
return;
}
finished();
}
}
-void MTPSlave::get ( const KUrl& url )
+void MTPSlave::get(const KUrl& url)
{
int check = checkUrl( url );
- switch ( check )
- {
- case 0:
+ switch (check) {
+ case 0: {
break;
- default:
- error( ERR_MALFORMED_URL, url.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, url.path());
return;
+ }
}
- kDebug ( KIO_MTP ) << url.path();
+ kDebug(KIO_MTP) << url.path();
- QStringList pathItems = url.path().split ( QLatin1Char ( '/' ), QString::SkipEmptyParts );
+ QStringList pathItems = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
// File
- if ( pathItems.size() > 2 )
- {
- QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( url.path() );
+ if (pathItems.size() > 2) {
+ QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath(url.path());
- if ( pair.first )
- {
- LIBMTP_file_t *file = ( LIBMTP_file_t* ) pair.first;
+ if (pair.first) {
+ LIBMTP_file_t *file = (LIBMTP_file_t*)pair.first;
- mimeType ( getMimetype ( file->filetype ) );
- totalSize ( file->filesize );
+ mimeType(getMimetype(file->filetype));
+ totalSize(file->filesize);
LIBMTP_mtpdevice_t *device = pair.second;
- int ret = LIBMTP_Get_File_To_Handler ( device, file->item_id, &dataPut, this, &dataProgress, this );
- if ( ret != 0 )
- {
- error ( ERR_COULD_NOT_READ, url.path() );
+ int ret = LIBMTP_Get_File_To_Handler(device, file->item_id, &dataPut, this, &dataProgress, this);
+ if (ret != 0) {
+ error(ERR_COULD_NOT_READ, url.path());
return;
}
- data ( QByteArray() );
+ data(QByteArray());
finished();
+ } else {
+ error(ERR_DOES_NOT_EXIST, url.path());
}
- else
- error ( ERR_DOES_NOT_EXIST, url.path() );
+ } else {
+ error(ERR_UNSUPPORTED_ACTION, url.path());
}
- else
- error ( ERR_UNSUPPORTED_ACTION, url.path() );
}
-void MTPSlave::copy ( const KUrl& src, const KUrl& dest, int, JobFlags flags )
+void MTPSlave::copy(const KUrl& src, const KUrl& dest, int, JobFlags flags)
{
- kDebug ( KIO_MTP ) << src.path() << dest.path();
+ kDebug(KIO_MTP) << src.path() << dest.path();
// mtp:/// to mtp:///
- if ( src.protocol() == QLatin1String ( "mtp" ) && dest.protocol() == QLatin1String ( "mtp" ) )
- {
- kDebug ( KIO_MTP ) << "Copy on device: Not supported";
+ if (src.protocol() == QLatin1String("mtp") && dest.protocol() == QLatin1String("mtp")) {
+ kDebug(KIO_MTP) << "Copy on device: Not supported";
// MTP doesn't support moving files directly on the device, so we have to download and then upload...
- error ( ERR_UNSUPPORTED_ACTION, i18n( "Cannot copy/move files on the device itself" ) );
+ error(ERR_UNSUPPORTED_ACTION, i18n("Cannot copy/move files on the device itself"));
}
- // file:/// tp mtp:///
- if ( src.protocol() == QLatin1String ( "file" ) && dest.protocol() == QLatin1String ( "mtp" ) )
- {
+ // file:/// to mtp:///
+ if (src.protocol() == QLatin1String("file" ) && dest.protocol() == QLatin1String ("mtp")) {
int check = checkUrl( dest );
- switch ( check )
- {
- case 0:
+ switch (check) {
+ case 0: {
break;
- default:
- error( ERR_MALFORMED_URL, dest.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, dest.path());
return;
+ }
}
- QStringList destItems = dest.path().split ( QLatin1Char ( '/') , QString::SkipEmptyParts );
+ QStringList destItems = dest.path().split(QLatin1Char('/') , QString::SkipEmptyParts);
// Can't copy to root or device, needs storage
- if ( destItems.size() < 2 )
- {
- error ( ERR_UNSUPPORTED_ACTION, dest.path() );
+ if (destItems.size() < 2) {
+ error(ERR_UNSUPPORTED_ACTION, dest.path());
return;
}
- kDebug ( KIO_MTP ) << "Copy file " << src.fileName() << "from filesystem to device" << src.directory ( KUrl::AppendTrailingSlash ) << dest.directory ( KUrl::AppendTrailingSlash );
+ kDebug(KIO_MTP) << "Copy file" << src.fileName() << "from filesystem to device"
+ << src.directory(KUrl::AppendTrailingSlash) << dest.directory(KUrl::AppendTrailingSlash);
- if ( !(flags & KIO::Overwrite) && getPath( dest.path() ).first )
- {
- error( ERR_FILE_ALREADY_EXIST, dest.path() );
+ if (!(flags & KIO::Overwrite) && getPath(dest.path()).first) {
+ error(ERR_FILE_ALREADY_EXIST, dest.path());
return;
}
destItems.takeLast();
- QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( dest.directory() );
+ QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath(dest.directory());
- if ( !pair.first )
- {
- error ( ERR_DOES_NOT_EXIST, dest.directory ( KUrl::AppendTrailingSlash ) );
+ if (!pair.first) {
+ error(ERR_DOES_NOT_EXIST, dest.directory(KUrl::AppendTrailingSlash));
return;
}
uint32_t parent_id = 0xFFFFFFFF, storage_id = 0;
- if ( destItems.size() == 2 )
- {
- LIBMTP_devicestorage_t *storage = ( LIBMTP_devicestorage_t*) pair.first;
+ if (destItems.size() == 2) {
+ LIBMTP_devicestorage_t *storage = (LIBMTP_devicestorage_t*)pair.first;
storage_id = storage->id;
- }
- else
- {
- LIBMTP_file_t *parent = ( LIBMTP_file_t* ) pair.first;
+ } else {
+ LIBMTP_file_t *parent = (LIBMTP_file_t*)pair.first;
storage_id = parent->storage_id;
parent_id = parent->item_id;
- if ( parent->filetype != LIBMTP_FILETYPE_FOLDER )
- {
- error ( ERR_IS_FILE, dest.directory() );
+ if (parent->filetype != LIBMTP_FILETYPE_FOLDER) {
+ error(ERR_IS_FILE, dest.directory());
return;
}
}
- QFileInfo source ( src.path() );
+ QFileInfo source(src.path());
LIBMTP_file_t *file = LIBMTP_new_file_t();
file->parent_id = parent_id;
- file->filename = strdup ( dest.fileName().toUtf8().data() );
- file->filetype = getFiletype ( dest.fileName() );
+ file->filename = strdup(dest.fileName().toUtf8().data());
+ file->filetype = getFiletype(dest.fileName());
file->filesize = source.size();
file->modificationdate = source.lastModified().toTime_t();
file->storage_id = storage_id;
totalSize ( source.size() );
- int ret = LIBMTP_Send_File_From_File ( device, src.path().toUtf8().data(), file, ( LIBMTP_progressfunc_t ) &dataProgress, this );
- if ( ret != 0 )
- {
- error ( KIO::ERR_COULD_NOT_WRITE, dest.fileName() );
- LIBMTP_Dump_Errorstack ( device );
- LIBMTP_Clear_Errorstack ( device );
+ int ret = LIBMTP_Send_File_From_File(device, src.path().toUtf8().data(), file, (LIBMTP_progressfunc_t )&dataProgress, this);
+ if (ret != 0) {
+ error(KIO::ERR_COULD_NOT_WRITE, dest.fileName());
+ LIBMTP_Dump_Errorstack(device);
+ LIBMTP_Clear_Errorstack(device);
return;
}
- kDebug ( KIO_MTP ) << "Sent file";
+ kDebug(KIO_MTP) << "Sent file";
}
// mtp:/// to file:///
- if ( src.protocol() == QLatin1String ( "mtp" ) && dest.protocol() == QLatin1String ( "file" ) )
- {
- int check = checkUrl( src );
- switch ( check )
- {
- case 0:
+ if (src.protocol() == QLatin1String("mtp") && dest.protocol() == QLatin1String("file")) {
+ int check = checkUrl(src);
+ switch (check) {
+ case 0: {
break;
- default:
- error( ERR_MALFORMED_URL, src.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, src.path());
return;
+ }
}
- kDebug ( KIO_MTP ) << "Copy file " << src.fileName() << "from device to filesystem" << dest.directory ( KUrl::AppendTrailingSlash ) << dest.directory ( KUrl::AppendTrailingSlash );
+ kDebug(KIO_MTP) << "Copy file" << src.fileName() << "from device to filesystem"
+ << dest.directory(KUrl::AppendTrailingSlash) << dest.directory(KUrl::AppendTrailingSlash);
- QFileInfo destination ( dest.path() );
+ QFileInfo destination(dest.path());
- if ( !(flags & KIO::Overwrite) && destination.exists() )
- {
- error( ERR_FILE_ALREADY_EXIST, dest.path() );
+ if (!(flags & KIO::Overwrite) && destination.exists()) {
+ error(ERR_FILE_ALREADY_EXIST, dest.path());
return;
}
- QStringList srcItems = src.path().split ( QLatin1Char ( '/' ), QString::SkipEmptyParts );
+ QStringList srcItems = src.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
// Can't copy to root or device, needs storage
- if ( srcItems.size() < 2 )
- {
- error ( ERR_UNSUPPORTED_ACTION, src.path() );
+ if (srcItems.size() < 2) {
+ error(ERR_UNSUPPORTED_ACTION, src.path());
return;
}
- QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( src.path() );
+ QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath(src.path());
LIBMTP_mtpdevice_t *device = pair.second;
- LIBMTP_file_t *source = ( LIBMTP_file_t* ) pair.first;
- if ( source->filetype == LIBMTP_FILETYPE_FOLDER )
- {
- error ( ERR_IS_DIRECTORY, src.directory() );
+ LIBMTP_file_t *source = (LIBMTP_file_t* )pair.first;
+ if (source->filetype == LIBMTP_FILETYPE_FOLDER) {
+ error(ERR_IS_DIRECTORY, src.directory());
return;
}
- kDebug ( KIO_MTP ) << "Getting file" << source->filename << dest.fileName() << source->filesize;
+ kDebug(KIO_MTP) << "Getting file" << source->filename << dest.fileName() << source->filesize;
- totalSize ( source->filesize );
+ totalSize(source->filesize);
- int ret = LIBMTP_Get_File_To_File ( device, source->item_id, dest.path().toUtf8().data(), ( LIBMTP_progressfunc_t ) &dataProgress, this );
- if ( ret != 0 )
- {
- error ( KIO::ERR_COULD_NOT_WRITE, dest.fileName() );
- LIBMTP_Dump_Errorstack ( device );
- LIBMTP_Clear_Errorstack ( device );
+ int ret = LIBMTP_Get_File_To_File(device, source->item_id, dest.path().toUtf8().data(), (LIBMTP_progressfunc_t)&dataProgress, this);
+ if (ret != 0) {
+ error(KIO::ERR_COULD_NOT_WRITE, dest.fileName());
+ LIBMTP_Dump_Errorstack(device);
+ LIBMTP_Clear_Errorstack(device);
return;
}
- struct utimbuf *times = (utimbuf*) malloc( sizeof( utimbuf ) );
+ struct utimbuf *times = (utimbuf*)::malloc(sizeof(utimbuf));
times->actime = QDateTime::currentDateTime().toTime_t();
times->modtime = source->modificationdate;
- int result = utime( dest.path().toUtf8().data(), times );
+ int result = utime(dest.path().toUtf8().data(), times);
- free( times );
+ ::free(times);
- kDebug ( KIO_MTP ) << "Sent file";
+ kDebug(KIO_MTP) << "Sent file";
}
finished();
}
-void MTPSlave::mkdir ( const KUrl& url, int )
+void MTPSlave::mkdir(const KUrl& url, int)
{
- int check = checkUrl( url );
- switch ( check )
- {
- case 0:
+ int check = checkUrl(url);
+ switch (check) {
+ case 0: {
break;
- default:
- error( ERR_MALFORMED_URL, url.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, url.path());
return;
+ }
}
- kDebug ( KIO_MTP ) << url.path();
+ kDebug(KIO_MTP) << url.path();
- QStringList pathItems = url.path().split ( QLatin1Char ( '/' ) , QString::SkipEmptyParts );
+ QStringList pathItems = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
int pathDepth= pathItems.size();
- if ( pathItems.size() > 2 && !getPath ( url.path() ).first )
- {
- char *dirName = strdup ( pathItems.takeLast().toUtf8().data() );
+ if (pathItems.size() > 2 && !getPath(url.path()).first) {
+ char *dirName = strdup(pathItems.takeLast().toUtf8().data());
LIBMTP_mtpdevice_t *device;
LIBMTP_file_t *file;
QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( url.directory() );
- if (pathDepth == 3)
- { //the folder need to be created straight to a storage device
- storage= ( LIBMTP_devicestorage_t* ) pair.first;
+ if (pathDepth == 3) {
+ //the folder need to be created straight to a storage device
+ storage= (LIBMTP_devicestorage_t*)pair.first;
device = pair.second;
- ret = LIBMTP_Create_Folder ( device, dirName, 0xFFFFFFFF, storage->id );
- }
- else if ( pair.first )
- {
- file = ( LIBMTP_file_t* ) pair.first;
+ ret = LIBMTP_Create_Folder(device, dirName, 0xFFFFFFFF, storage->id);
+ } else if (pair.first) {
+ file = (LIBMTP_file_t*) pair.first;
device = pair.second;
- if ( file && file->filetype == LIBMTP_FILETYPE_FOLDER )
- {
- kDebug ( KIO_MTP ) << "Found parent" << file->item_id << file->filename;
- kDebug ( KIO_MTP ) << "Attempting to create folder" << dirName;
+ if (file && file->filetype == LIBMTP_FILETYPE_FOLDER) {
+ kDebug(KIO_MTP) << "Found parent" << file->item_id << file->filename;
+ kDebug(KIO_MTP) << "Attempting to create folder" << dirName;
- ret = LIBMTP_Create_Folder ( device, dirName, file->item_id, file->storage_id );
+ ret = LIBMTP_Create_Folder(device, dirName, file->item_id, file->storage_id);
}
}
- if ( ret != 0 )
- {
- fileCache->addPath( url.path(), ret );
+ if (ret != 0) {
+ fileCache->addPath(url.path(), ret);
finished();
return;
+ } else {
+ LIBMTP_Dump_Errorstack(device);
+ LIBMTP_Clear_Errorstack(device);
}
- else
- {
- LIBMTP_Dump_Errorstack ( device );
- LIBMTP_Clear_Errorstack ( device );
- }
- }
- else
- {
- error ( ERR_DIR_ALREADY_EXIST, url.path() );
+ } else {
+ error(ERR_DIR_ALREADY_EXIST, url.path());
return;
}
- error ( ERR_COULD_NOT_MKDIR, url.path() );
+ error(ERR_COULD_NOT_MKDIR, url.path());
}
-void MTPSlave::del ( const KUrl& url, bool )
+void MTPSlave::del(const KUrl& url, bool)
{
- int check = checkUrl( url );
- switch ( check )
- {
- case 0:
+ int check = checkUrl(url);
+ switch (check) {
+ case 0: {
break;
- default:
- error( ERR_MALFORMED_URL, url.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, url.path());
return;
+ }
}
- kDebug ( KIO_MTP ) << url.path();
+ kDebug(KIO_MTP) << url.path();
- QStringList pathItems = url.path().split ( QLatin1Char ( '/' ), QString::SkipEmptyParts );
+ QStringList pathItems = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
- if ( pathItems.size() < 2 )
- {
- error ( ERR_CANNOT_DELETE, url.path() );
+ if (pathItems.size() < 2) {
+ error(ERR_CANNOT_DELETE, url.path());
return;
}
- QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( url.path() );
+ QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath(url.path());
- LIBMTP_file_t *file = ( LIBMTP_file_t* ) pair.first;
+ LIBMTP_file_t *file = (LIBMTP_file_t*)pair.first;
- int ret = LIBMTP_Delete_Object ( pair.second, file->item_id );
+ int ret = LIBMTP_Delete_Object(pair.second, file->item_id);
- LIBMTP_destroy_file_t ( file );
+ LIBMTP_destroy_file_t(file);
- if ( ret != 0 )
- {
- error ( ERR_CANNOT_DELETE, url.path() );
+ if (ret != 0) {
+ error(ERR_CANNOT_DELETE, url.path());
return;
}
- fileCache->removePath( url.path() );
+ fileCache->removePath(url.path());
finished();
}
-void MTPSlave::rename ( const KUrl& src, const KUrl& dest, JobFlags flags )
+void MTPSlave::rename(const KUrl& src, const KUrl& dest, JobFlags flags)
{
- int check = checkUrl( src );
- switch ( check )
- {
- case 0:
+ int check = checkUrl(src);
+ switch (check) {
+ case 0: {
break;
- default:
- error( ERR_MALFORMED_URL, src.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, src.path());
return;
+ }
}
- check = checkUrl( dest );
- switch ( check )
- {
- case 0:
+ check = checkUrl(dest);
+ switch (check) {
+ case 0: {
break;
- default:
- error( ERR_MALFORMED_URL, dest.path() );
+ }
+ default: {
+ error(ERR_MALFORMED_URL, dest.path());
return;
+ }
}
- kDebug ( KIO_MTP ) << src.path();
+ kDebug(KIO_MTP) << src.path();
- QStringList srcItems = src.path().split ( QLatin1Char ( '/' ), QString::SkipEmptyParts );
- QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath ( src.path() );
+ QStringList srcItems = src.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
+ QPair<void*, LIBMTP_mtpdevice_t*> pair = getPath(src.path());
- if ( pair.first )
- {
+ if (pair.first) {
// Rename Device
- if ( srcItems.size() == 1 )
- {
- LIBMTP_Set_Friendlyname ( pair.second, dest.fileName().toUtf8().data() );
- }
+ if (srcItems.size() == 1) {
+ LIBMTP_Set_Friendlyname(pair.second, dest.fileName().toUtf8().data());
// Rename Storage
- else if ( srcItems.size() == 2 )
- {
- error ( ERR_CANNOT_RENAME, src.path() );
+ } else if (srcItems.size() == 2) {
+ error(ERR_CANNOT_RENAME, src.path());
return;
- }
- else
- {
- LIBMTP_file_t *destination = ( LIBMTP_file_t* ) getPath ( dest.path() ).first;
- LIBMTP_file_t *source = ( LIBMTP_file_t* ) pair.first;
-
- if ( !(flags & KIO::Overwrite) && destination )
- {
- if ( destination->filetype == LIBMTP_FILETYPE_FOLDER )
- {
- error( ERR_DIR_ALREADY_EXIST, dest.path() );
- }
- else
- {
- error( ERR_FILE_ALREADY_EXIST, dest.path() );
+ } else {
+ LIBMTP_file_t *destination = (LIBMTP_file_t*)getPath(dest.path()).first;
+ LIBMTP_file_t *source = (LIBMTP_file_t*)pair.first;
+
+ if (!(flags & KIO::Overwrite) && destination) {
+ if (destination->filetype == LIBMTP_FILETYPE_FOLDER) {
+ error(ERR_DIR_ALREADY_EXIST, dest.path());
+ } else {
+ error(ERR_FILE_ALREADY_EXIST, dest.path());
}
return;
}
- int ret = LIBMTP_Set_File_Name ( pair.second, source, dest.fileName().toUtf8().data() );
+ int ret = LIBMTP_Set_File_Name(pair.second, source, dest.fileName().toUtf8().data());
- if ( ret != 0 )
- {
- error ( ERR_CANNOT_RENAME, src.path() );
+ if (ret != 0) {
+ error(ERR_CANNOT_RENAME, src.path());
return;
- }
- else
- {
- fileCache->addPath( dest.path(), source->item_id );
- fileCache->removePath( src.path() );
+ } else {
+ fileCache->addPath(dest.path(), source->item_id);
+ fileCache->removePath(src.path());
}
- LIBMTP_destroy_file_t ( source );
+ LIBMTP_destroy_file_t(source);
}
finished();
- }
- else
- {
- error ( ERR_DOES_NOT_EXIST, src.path() );
+ } else {
+ error(ERR_DOES_NOT_EXIST, src.path());
}
}
-
#include "moc_kio_mtp.cpp"
-
#include "kio_mtp_helpers.h"
-int dataProgress ( uint64_t const sent, uint64_t const, void const *const priv )
+int dataProgress(uint64_t const sent, uint64_t const, void const *const priv)
{
- ( ( MTPSlave* ) priv )->processedSize ( sent );
+ ((MTPSlave*)priv)->processedSize(sent);
return 0;
}
/**
* MTPDataPutFunc callback function, "puts" data from the device somewhere else
*/
-uint16_t dataPut ( void*, void *priv, uint32_t sendlen, unsigned char *data, uint32_t *putlen )
+uint16_t dataPut(void*, void *priv, uint32_t sendlen, unsigned char *data, uint32_t *putlen)
{
kDebug(KIO_MTP) << "transferring" << sendlen << "bytes to data()";
- ( ( MTPSlave* ) priv )->data ( QByteArray ( ( char* ) data, ( int ) sendlen ) );
+ ((MTPSlave* )priv)->data(QByteArray((char*)data, (int)sendlen));
*putlen = sendlen;
return LIBMTP_HANDLER_RETURN_OK;
/**
* MTPDataGetFunc callback function, "gets" data and puts it on the device
*/
-uint16_t dataGet ( void*, void *priv, uint32_t, unsigned char *data, uint32_t *gotlen )
+uint16_t dataGet(void*, void *priv, uint32_t, unsigned char *data, uint32_t *gotlen)
{
- ( ( MTPSlave* ) priv )->dataReq();
+ ((MTPSlave*)priv)->dataReq();
QByteArray buffer;
- *gotlen = ( ( MTPSlave* ) priv )->readData ( buffer );
+ *gotlen = ((MTPSlave*)priv)->readData(buffer);
kDebug(KIO_MTP) << "transferring" << *gotlen << "bytes to data()";
- data = ( unsigned char* ) buffer.data();
+ data = (unsigned char*) buffer.data();
return LIBMTP_HANDLER_RETURN_OK;
}
-QString convertToPath( const QStringList& pathItems, const int elements )
+QString convertToPath(const QStringList& pathItems, const int elements)
{
QString path;
- for ( int i = 0; i < elements && elements <= pathItems.size(); i++ )
- {
- path.append( QLatin1Char ('/') );
- path.append( pathItems.at(i) );
+ for (int i = 0; i < elements && elements <= pathItems.size(); i++) {
+ path.append(QLatin1Char('/'));
+ path.append(pathItems.at(i));
}
return path;
}
-QString getMimetype ( LIBMTP_filetype_t filetype )
+QString getMimetype(LIBMTP_filetype_t filetype)
{
- switch ( filetype )
- {
- case LIBMTP_FILETYPE_FOLDER:
- return QLatin1String ( "inode/directory" );
-
- case LIBMTP_FILETYPE_WAV:
- return QLatin1String ( "audio/wav" );
- case LIBMTP_FILETYPE_MP3:
- return QLatin1String ( "audio/x-mp3" );
- case LIBMTP_FILETYPE_WMA:
- return QLatin1String ( "audio/x-ms-wma" );
- case LIBMTP_FILETYPE_OGG:
- return QLatin1String ( "audio/x-vorbis+ogg" );
- case LIBMTP_FILETYPE_AUDIBLE:
- return QLatin1String ( "" );
- case LIBMTP_FILETYPE_MP4:
- return QLatin1String ( "audio/mp4" );
- case LIBMTP_FILETYPE_UNDEF_AUDIO:
- return QLatin1String ( "" );
- case LIBMTP_FILETYPE_WMV:
- return QLatin1String ( "video/x-ms-wmv" );
- case LIBMTP_FILETYPE_AVI:
- return QLatin1String ( "video/x-msvideo" );
- case LIBMTP_FILETYPE_MPEG:
- return QLatin1String ( "video/mpeg" );
- case LIBMTP_FILETYPE_ASF:
- return QLatin1String ( "video/x-ms-asf" );
- case LIBMTP_FILETYPE_QT:
- return QLatin1String ( "video/quicktime" );
- case LIBMTP_FILETYPE_UNDEF_VIDEO:
- return QLatin1String ( "" );
- case LIBMTP_FILETYPE_JPEG:
- return QLatin1String ( "image/jpeg" );
- case LIBMTP_FILETYPE_JFIF:
- return QLatin1String ( "" );
- case LIBMTP_FILETYPE_TIFF:
- return QLatin1String ( "image/tiff" );
- case LIBMTP_FILETYPE_BMP:
- return QLatin1String ( "image/bmp" );
- case LIBMTP_FILETYPE_GIF:
- return QLatin1String ( "image/gif" );
- case LIBMTP_FILETYPE_PICT:
- return QLatin1String ( "image/x-pict" );
- case LIBMTP_FILETYPE_PNG:
- return QLatin1String ( "image/png" );
- case LIBMTP_FILETYPE_VCALENDAR1:
- return QLatin1String ( "text/x-vcalendar" );
- case LIBMTP_FILETYPE_VCALENDAR2:
- return QLatin1String ( "text/x-vcalendar" );
- case LIBMTP_FILETYPE_VCARD2:
- return QLatin1String ( "text/x-vcard" );
- case LIBMTP_FILETYPE_VCARD3:
- return QLatin1String ( "text/x-vcard" );
- case LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT:
- return QLatin1String ( "image/x-wmf" );
- case LIBMTP_FILETYPE_WINEXEC:
- return QLatin1String ( "application/x-ms-dos-executable" );
- case LIBMTP_FILETYPE_TEXT:
- return QLatin1String ( "text/plain" );
- case LIBMTP_FILETYPE_HTML:
- return QLatin1String ( "text/html" );
- case LIBMTP_FILETYPE_FIRMWARE:
- return QLatin1String ( "" );
- case LIBMTP_FILETYPE_AAC:
- return QLatin1String ( "audio/aac" );
- case LIBMTP_FILETYPE_MEDIACARD:
- return QLatin1String ( "" );
- case LIBMTP_FILETYPE_FLAC:
- return QLatin1String ( "audio/flac" );
- case LIBMTP_FILETYPE_MP2:
- return QLatin1String ( "video/mpeg" );
- case LIBMTP_FILETYPE_M4A:
- return QLatin1String ( "audio/mp4" );
- case LIBMTP_FILETYPE_DOC:
- return QLatin1String ( "application/msword" );
- case LIBMTP_FILETYPE_XML:
- return QLatin1String ( "text/xml" );
- case LIBMTP_FILETYPE_XLS:
- return QLatin1String ( "application/vnd.ms-excel" );
- case LIBMTP_FILETYPE_PPT:
- return QLatin1String ( "application/vnd.ms-powerpoint" );
- case LIBMTP_FILETYPE_MHT:
- return QLatin1String ( "" );
- case LIBMTP_FILETYPE_JP2:
- return QLatin1String ( "image/jpeg2000" );
- case LIBMTP_FILETYPE_JPX:
- return QLatin1String ( "application/x-jbuilder-project" );
- case LIBMTP_FILETYPE_UNKNOWN:
- return QLatin1String ( "" );
-
- default:
- return QLatin1String ( "" );
- }
+ switch (filetype) {
+ case LIBMTP_FILETYPE_FOLDER:
+ return QLatin1String("inode/directory");
+ case LIBMTP_FILETYPE_WAV:
+ return QLatin1String("audio/wav");
+ case LIBMTP_FILETYPE_MP3:
+ return QLatin1String("audio/x-mp3");
+ case LIBMTP_FILETYPE_WMA:
+ return QLatin1String("audio/x-ms-wma");
+ case LIBMTP_FILETYPE_OGG:
+ return QLatin1String("audio/x-vorbis+ogg");
+ case LIBMTP_FILETYPE_AUDIBLE:
+ return QLatin1String("");
+ case LIBMTP_FILETYPE_MP4:
+ return QLatin1String("audio/mp4");
+ case LIBMTP_FILETYPE_UNDEF_AUDIO:
+ return QLatin1String("");
+ case LIBMTP_FILETYPE_WMV:
+ return QLatin1String("video/x-ms-wmv");
+ case LIBMTP_FILETYPE_AVI:
+ return QLatin1String("video/x-msvideo");
+ case LIBMTP_FILETYPE_MPEG:
+ return QLatin1String("video/mpeg");
+ case LIBMTP_FILETYPE_ASF:
+ return QLatin1String("video/x-ms-asf");
+ case LIBMTP_FILETYPE_QT:
+ return QLatin1String("video/quicktime");
+ case LIBMTP_FILETYPE_UNDEF_VIDEO:
+ return QLatin1String("");
+ case LIBMTP_FILETYPE_JPEG:
+ return QLatin1String("image/jpeg");
+ case LIBMTP_FILETYPE_JFIF:
+ return QLatin1String("");
+ case LIBMTP_FILETYPE_TIFF:
+ return QLatin1String("image/tiff");
+ case LIBMTP_FILETYPE_BMP:
+ return QLatin1String("image/bmp");
+ case LIBMTP_FILETYPE_GIF:
+ return QLatin1String("image/gif");
+ case LIBMTP_FILETYPE_PICT:
+ return QLatin1String("image/x-pict");
+ case LIBMTP_FILETYPE_PNG:
+ return QLatin1String("image/png");
+ case LIBMTP_FILETYPE_VCALENDAR1:
+ return QLatin1String("text/x-vcalendar");
+ case LIBMTP_FILETYPE_VCALENDAR2:
+ return QLatin1String("text/x-vcalendar");
+ case LIBMTP_FILETYPE_VCARD2:
+ return QLatin1String("text/x-vcard");
+ case LIBMTP_FILETYPE_VCARD3:
+ return QLatin1String("text/x-vcard");
+ case LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT:
+ return QLatin1String("image/x-wmf");
+ case LIBMTP_FILETYPE_WINEXEC:
+ return QLatin1String("application/x-ms-dos-executable");
+ case LIBMTP_FILETYPE_TEXT:
+ return QLatin1String("text/plain");
+ case LIBMTP_FILETYPE_HTML:
+ return QLatin1String("text/html");
+ case LIBMTP_FILETYPE_FIRMWARE:
+ return QLatin1String("");
+ case LIBMTP_FILETYPE_AAC:
+ return QLatin1String("audio/aac");
+ case LIBMTP_FILETYPE_MEDIACARD:
+ return QLatin1String("");
+ case LIBMTP_FILETYPE_FLAC:
+ return QLatin1String("audio/flac");
+ case LIBMTP_FILETYPE_MP2:
+ return QLatin1String("video/mpeg");
+ case LIBMTP_FILETYPE_M4A:
+ return QLatin1String("audio/mp4");
+ case LIBMTP_FILETYPE_DOC:
+ return QLatin1String("application/msword");
+ case LIBMTP_FILETYPE_XML:
+ return QLatin1String("text/xml");
+ case LIBMTP_FILETYPE_XLS:
+ return QLatin1String("application/vnd.ms-excel");
+ case LIBMTP_FILETYPE_PPT:
+ return QLatin1String("application/vnd.ms-powerpoint");
+ case LIBMTP_FILETYPE_MHT:
+ return QLatin1String(""); // TODO: application/x-mimearchive?
+ case LIBMTP_FILETYPE_JP2:
+ return QLatin1String("image/jpeg2000");
+ case LIBMTP_FILETYPE_JPX:
+ return QLatin1String("application/x-jbuilder-project");
+ case LIBMTP_FILETYPE_UNKNOWN:
+ return QString();
+ }
+ return QString();
}
-LIBMTP_filetype_t getFiletype ( const QString &filename )
+LIBMTP_filetype_t getFiletype( const QString &filename)
{
LIBMTP_filetype_t filetype;
- QString ptype = filename.split ( QLatin1Char ( '.' ) ).last();
+ QString ptype = filename.split(QLatin1Char('.')).last();
/* This need to be kept constantly updated as new file types arrive. */
- if ( ptype == QLatin1String ( "wav" ) )
- {
+ if (ptype == QLatin1String("wav")) {
filetype = LIBMTP_FILETYPE_WAV;
- }
- else if ( ptype == QLatin1String ( "mp3" ) )
- {
+ } else if (ptype == QLatin1String("mp3")) {
filetype = LIBMTP_FILETYPE_MP3;
- }
- else if ( ptype == QLatin1String ( "wma" ) )
- {
+ } else if (ptype == QLatin1String("wma")) {
filetype = LIBMTP_FILETYPE_WMA;
- }
- else if ( ptype == QLatin1String ( "ogg" ) )
- {
+ } else if (ptype == QLatin1String("ogg")) {
filetype = LIBMTP_FILETYPE_OGG;
- }
- else if ( ptype == QLatin1String ( "mp4" ) )
- {
+ } else if (ptype == QLatin1String("mp4")) {
filetype = LIBMTP_FILETYPE_MP4;
- }
- else if ( ptype == QLatin1String ( "wmv" ) )
- {
+ } else if (ptype == QLatin1String("wmv")) {
filetype = LIBMTP_FILETYPE_WMV;
- }
- else if ( ptype == QLatin1String ( "avi" ) )
- {
+ } else if (ptype == QLatin1String("avi")) {
filetype = LIBMTP_FILETYPE_AVI;
- }
- else if ( ptype == QLatin1String ( "mpeg" ) ||
- ptype == QLatin1String ( "mpg" ) )
- {
+ } else if (ptype == QLatin1String("mpeg") || ptype == QLatin1String("mpg")) {
filetype = LIBMTP_FILETYPE_MPEG;
- }
- else if ( ptype == QLatin1String ( "asf" ) )
- {
+ } else if (ptype == QLatin1String("asf")) {
filetype = LIBMTP_FILETYPE_ASF;
- }
- else if ( ptype == QLatin1String ( "qt" ) ||
- ptype == QLatin1String ( "mov" ) )
- {
+ } else if (ptype == QLatin1String("qt") || ptype == QLatin1String("mov")) {
filetype = LIBMTP_FILETYPE_QT;
- }
- else if ( ptype == QLatin1String ( "wma" ) )
- {
+ } else if (ptype == QLatin1String("wma")) {
filetype = LIBMTP_FILETYPE_WMA;
- }
- else if ( ptype == QLatin1String ( "jpg" ) ||
- ptype == QLatin1String ( "jpeg" ) )
- {
+ } else if (ptype == QLatin1String("jpg") || ptype == QLatin1String("jpeg")) {
filetype = LIBMTP_FILETYPE_JPEG;
- }
- else if ( ptype == QLatin1String ( "jfif" ) )
- {
+ } else if (ptype == QLatin1String("jfif")) {
filetype = LIBMTP_FILETYPE_JFIF;
- }
- else if ( ptype == QLatin1String ( "tif" ) ||
- ptype == QLatin1String ( "tiff" ) )
- {
+ } else if (ptype == QLatin1String("tif") || ptype == QLatin1String("tiff")) {
filetype = LIBMTP_FILETYPE_TIFF;
- }
- else if ( ptype == QLatin1String ( "bmp" ) )
- {
+ } else if (ptype == QLatin1String("bmp")) {
filetype = LIBMTP_FILETYPE_BMP;
- }
- else if ( ptype == QLatin1String ( "gif" ) )
- {
+ } else if (ptype == QLatin1String ("gif")) {
filetype = LIBMTP_FILETYPE_GIF;
- }
- else if ( ptype == QLatin1String ( "pic" ) ||
- ptype == QLatin1String ( "pict" ) )
- {
+ } else if (ptype == QLatin1String("pic") || ptype == QLatin1String ("pict")) {
filetype = LIBMTP_FILETYPE_PICT;
- }
- else if ( ptype == QLatin1String ( "png" ) )
- {
+ } else if (ptype == QLatin1String("png")) {
filetype = LIBMTP_FILETYPE_PNG;
- }
- else if ( ptype == QLatin1String ( "wmf" ) )
- {
+ } else if (ptype == QLatin1String("wmf")) {
filetype = LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT;
- }
- else if ( ptype == QLatin1String ( "ics" ) )
- {
+ } else if (ptype == QLatin1String("ics")) {
filetype = LIBMTP_FILETYPE_VCALENDAR2;
- }
- else if ( ptype == QLatin1String ( "exe" ) ||
- ptype == QLatin1String ( "com" ) ||
- ptype == QLatin1String ( "bat" ) ||
- ptype == QLatin1String ( "dll" ) ||
- ptype == QLatin1String ( "sys" ) )
- {
+ } else if (ptype == QLatin1String ("exe") || ptype == QLatin1String("com") ||
+ ptype == QLatin1String("bat") || ptype == QLatin1String("dll") ||
+ ptype == QLatin1String("sys")) {
filetype = LIBMTP_FILETYPE_WINEXEC;
- }
- else if ( ptype == QLatin1String ( "aac" ) )
- {
+ } else if (ptype == QLatin1String("aac")) {
filetype = LIBMTP_FILETYPE_AAC;
- }
- else if ( ptype == QLatin1String ( "mp2" ) )
- {
+ } else if (ptype == QLatin1String("mp2")) {
filetype = LIBMTP_FILETYPE_MP2;
- }
- else if ( ptype == QLatin1String ( "flac" ) )
- {
+ } else if (ptype == QLatin1String("flac")) {
filetype = LIBMTP_FILETYPE_FLAC;
- }
- else if ( ptype == QLatin1String ( "m4a" ) )
- {
+ } else if (ptype == QLatin1String("m4a")) {
filetype = LIBMTP_FILETYPE_M4A;
- }
- else if ( ptype == QLatin1String ( "doc" ) )
- {
+ } else if (ptype == QLatin1String("doc")) {
filetype = LIBMTP_FILETYPE_DOC;
- }
- else if ( ptype == QLatin1String ( "xml" ) )
- {
+ } else if (ptype == QLatin1String("xml")) {
filetype = LIBMTP_FILETYPE_XML;
- }
- else if ( ptype == QLatin1String ( "xls" ) )
- {
+ } else if (ptype == QLatin1String("xls")) {
filetype = LIBMTP_FILETYPE_XLS;
- }
- else if ( ptype == QLatin1String ( "ppt" ) )
- {
+ } else if (ptype == QLatin1String("ppt")) {
filetype = LIBMTP_FILETYPE_PPT;
- }
- else if ( ptype == QLatin1String ( "mht" ) )
- {
+ } else if (ptype == QLatin1String("mht")) {
filetype = LIBMTP_FILETYPE_MHT;
- }
- else if ( ptype == QLatin1String ( "jp2" ) )
- {
+ } else if (ptype == QLatin1String("jp2")) {
filetype = LIBMTP_FILETYPE_JP2;
- }
- else if ( ptype == QLatin1String ( "jpx" ) )
- {
+ } else if (ptype == QLatin1String ("jpx")) {
filetype = LIBMTP_FILETYPE_JPX;
- }
- else if ( ptype == QLatin1String ( "bin" ) )
- {
+ } else if (ptype == QLatin1String("bin")) {
filetype = LIBMTP_FILETYPE_FIRMWARE;
- }
- else if ( ptype == QLatin1String ( "vcf" ) )
- {
+ } else if (ptype == QLatin1String("vcf")) {
filetype = LIBMTP_FILETYPE_VCARD3;
- }
- else
- {
+ } else {
/* Tagging as unknown file type */
filetype = LIBMTP_FILETYPE_UNKNOWN;
}
return filetype;
}
-QMap<QString, LIBMTP_devicestorage_t*> getDevicestorages ( LIBMTP_mtpdevice_t *&device )
+QMap<QString, LIBMTP_devicestorage_t*> getDevicestorages(LIBMTP_mtpdevice_t *&device)
{
- kDebug ( KIO_MTP ) << "[ENTER]" << ( device == 0 );
+ kDebug (KIO_MTP) << "[ENTER]" << (device == 0);
QMap<QString, LIBMTP_devicestorage_t*> storages;
- if ( device )
- {
- for ( LIBMTP_devicestorage_t* storage = device->storage; storage != NULL; storage = storage->next )
- {
- // char *storageIdentifier = storage->VolumeIdentifier;
+ if (device) {
+ for (LIBMTP_devicestorage_t* storage = device->storage; storage != NULL; storage = storage->next) {
+ // char *storageIdentifier = storage->VolumeIdentifier;
char *storageDescription = storage->StorageDescription;
QString storagename;
- // if ( !storageIdentifier )
- storagename = QString::fromUtf8 ( storageDescription );
- // else
- // storagename = QString::fromUtf8 ( storageIdentifier );
+ // if (!storageIdentifier)
+ storagename = QString::fromUtf8(storageDescription);
+ // } else {
+ // storagename = QString::fromUtf8(storageIdentifier);
+ // }
kDebug(KIO_MTP) << "found storage" << storagename;
- storages.insert ( storagename, storage );
+ storages.insert(storagename, storage);
}
}
- kDebug ( KIO_MTP ) << "[EXIT]" << storages.size();
+ kDebug(KIO_MTP) << "[EXIT]" << storages.size();
return storages;
}
-QMap<QString, LIBMTP_file_t*> getFiles ( LIBMTP_mtpdevice_t *&device, uint32_t storage_id, uint32_t parent_id )
+QMap<QString, LIBMTP_file_t*> getFiles(LIBMTP_mtpdevice_t *&device, uint32_t storage_id, uint32_t parent_id)
{
- kDebug ( KIO_MTP ) << "getFiles() for parent" << parent_id;
+ kDebug(KIO_MTP) << "getFiles() for parent" << parent_id;
QMap<QString, LIBMTP_file_t*> fileMap;
- LIBMTP_file_t *files = LIBMTP_Get_Files_And_Folders ( device, storage_id, parent_id ), *file;
- for ( file = files; file != NULL; file = file->next )
- {
- fileMap.insert ( QString::fromUtf8 ( file->filename ), file );
+ LIBMTP_file_t *files = LIBMTP_Get_Files_And_Folders(device, storage_id, parent_id), *file;
+ for (file = files; file != NULL; file = file->next) {
+ fileMap.insert(QString::fromUtf8(file->filename), file);
// kDebug(KIO_MTP) << "found file" << file->filename;
}
- kDebug ( KIO_MTP ) << "[EXIT]";
+ kDebug(KIO_MTP) << "[EXIT]";
return fileMap;
}
-void getEntry ( UDSEntry &entry, LIBMTP_mtpdevice_t* device )
+void getEntry(UDSEntry &entry, LIBMTP_mtpdevice_t* device)
{
- char *charName = LIBMTP_Get_Friendlyname ( device );
- char *charModel = LIBMTP_Get_Modelname ( device );
+ char *charName = LIBMTP_Get_Friendlyname(device);
+ char *charModel = LIBMTP_Get_Modelname(device);
// prefer friendly devicename over model
QString deviceName;
- if ( !charName )
- deviceName = QString::fromUtf8 ( charModel );
- else
- deviceName = QString::fromUtf8 ( charName );
+ if (!charName) {
+ deviceName = QString::fromUtf8(charModel);
+ } else {
+ deviceName = QString::fromUtf8(charName);
+ }
- entry.insert ( UDSEntry::UDS_NAME, deviceName );
- entry.insert ( UDSEntry::UDS_ICON_NAME, QLatin1String ( "multimedia-player" ) );
- entry.insert ( UDSEntry::UDS_FILE_TYPE, S_IFDIR );
- entry.insert ( UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH );
- entry.insert ( UDSEntry::UDS_MIME_TYPE, QLatin1String ( "inode/directory" ) );
+ entry.insert(UDSEntry::UDS_NAME, deviceName);
+ entry.insert(UDSEntry::UDS_ICON_NAME, QLatin1String("multimedia-player"));
+ entry.insert(UDSEntry::UDS_FILE_TYPE, S_IFDIR);
+ entry.insert(UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH);
+ entry.insert(UDSEntry::UDS_MIME_TYPE, QLatin1String("inode/directory"));
}
-void getEntry ( UDSEntry &entry, const LIBMTP_devicestorage_t* storage )
+void getEntry(UDSEntry &entry, const LIBMTP_devicestorage_t* storage)
{
// char *charIdentifier = storage->VolumeIdentifier;
char *charDescription = storage->StorageDescription;
QString storageName;
-// if ( !charIdentifier )
- storageName = QString::fromUtf8 ( charDescription );
-// else
-// storageName = QString::fromUtf8 ( charIdentifier );
+ // if ( !charIdentifier )
+ storageName = QString::fromUtf8(charDescription);
+ // else {
+ // storageName = QString::fromUtf8(charIdentifier);
+ // }
- entry.insert ( UDSEntry::UDS_NAME, storageName );
- entry.insert ( UDSEntry::UDS_ICON_NAME, QLatin1String ( "drive-removable-media" ) );
- entry.insert ( UDSEntry::UDS_FILE_TYPE, S_IFDIR );
- entry.insert ( UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH );
- entry.insert ( UDSEntry::UDS_MIME_TYPE, QLatin1String ( "inode/directory" ) );
+ entry.insert(UDSEntry::UDS_NAME, storageName);
+ entry.insert(UDSEntry::UDS_ICON_NAME, QLatin1String("drive-removable-media"));
+ entry.insert(UDSEntry::UDS_FILE_TYPE, S_IFDIR );
+ entry.insert(UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH);
+ entry.insert(UDSEntry::UDS_MIME_TYPE, QLatin1String("inode/directory"));
}
-void getEntry ( UDSEntry &entry, const LIBMTP_file_t* file )
+void getEntry(UDSEntry &entry, const LIBMTP_file_t* file)
{
- entry.insert ( UDSEntry::UDS_NAME, QString::fromUtf8 ( file->filename ) );
- if ( file->filetype == LIBMTP_FILETYPE_FOLDER )
- {
- entry.insert ( UDSEntry::UDS_FILE_TYPE, S_IFDIR );
- entry.insert ( UDSEntry::UDS_ACCESS, S_IRWXU | S_IRWXG | S_IRWXO );
- entry.insert ( UDSEntry::UDS_MIME_TYPE, QLatin1String ( "inode/directory" ) );
- }
- else
- {
- entry.insert ( UDSEntry::UDS_FILE_TYPE, S_IFREG );
- entry.insert ( UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH );
- entry.insert ( UDSEntry::UDS_SIZE, file->filesize );
- entry.insert ( UDSEntry::UDS_MIME_TYPE, getMimetype( file->filetype ) );
- }
- entry.insert ( UDSEntry::UDS_INODE, file->item_id );
- entry.insert ( UDSEntry::UDS_ACCESS_TIME, file->modificationdate );
- entry.insert ( UDSEntry::UDS_MODIFICATION_TIME, file->modificationdate );
- entry.insert ( UDSEntry::UDS_CREATION_TIME, file->modificationdate );
+ entry.insert(UDSEntry::UDS_NAME, QString::fromUtf8(file->filename));
+ if (file->filetype == LIBMTP_FILETYPE_FOLDER) {
+ entry.insert(UDSEntry::UDS_FILE_TYPE, S_IFDIR);
+ entry.insert(UDSEntry::UDS_ACCESS, S_IRWXU | S_IRWXG | S_IRWXO);
+ entry.insert(UDSEntry::UDS_MIME_TYPE, QLatin1String("inode/directory"));
+ } else {
+ entry.insert(UDSEntry::UDS_FILE_TYPE, S_IFREG );
+ entry.insert(UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH);
+ entry.insert(UDSEntry::UDS_SIZE, file->filesize );
+ entry.insert(UDSEntry::UDS_MIME_TYPE, getMimetype(file->filetype));
+ }
+ entry.insert(UDSEntry::UDS_INODE, file->item_id);
+ entry.insert(UDSEntry::UDS_ACCESS_TIME, file->modificationdate);
+ entry.insert(UDSEntry::UDS_MODIFICATION_TIME, file->modificationdate);
+ entry.insert(UDSEntry::UDS_CREATION_TIME, file->modificationdate);
}