File indexing completed on 2024-11-10 04:22:06
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef SQLMOUNTPOINTMANAGERMOCK_H 0018 #define SQLMOUNTPOINTMANAGERMOCK_H 0019 0020 #include "core-impl/collections/db/MountPointManager.h" 0021 #include "core-impl/collections/db/sql/SqlCollection.h" 0022 0023 #include <QMap> 0024 #include <QString> 0025 0026 //Note: this class will probably break horribly on win32 0027 0028 class SqlMountPointManagerMock : public MountPointManager 0029 { 0030 public: 0031 0032 SqlMountPointManagerMock( QObject *parent, QSharedPointer<SqlStorage> storage ) 0033 : MountPointManager( parent, storage ) 0034 { 0035 } 0036 0037 int getIdForUrl( const QUrl &url ) override 0038 { 0039 QString path = url.path(); 0040 foreach( int id, m_mountPoints.keys() ) 0041 { 0042 if( path.startsWith( m_mountPoints.value( id ) ) ) 0043 { 0044 return id; 0045 } 0046 } 0047 0048 return -1; 0049 } 0050 0051 QString getAbsolutePath ( const int deviceId, const QString& relativePath ) const override 0052 { 0053 if( deviceId == -1 ) 0054 return relativePath.right( relativePath.length() -1 ); 0055 else 0056 { 0057 return m_mountPoints.value( deviceId ) + relativePath.right( relativePath.length() -1 ); 0058 } 0059 } 0060 0061 QString getRelativePath( const int deviceId, const QString& absolutePath ) const override 0062 { 0063 if( deviceId == -1 ) 0064 return '.' + absolutePath; 0065 else 0066 { 0067 QString mp = m_mountPoints.value( deviceId ); 0068 return '.' + absolutePath.right( mp.length() ); 0069 } 0070 } 0071 0072 IdList getMountedDeviceIds() const override 0073 { 0074 IdList result; 0075 result << -1; 0076 result << m_mountPoints.keys(); 0077 return result; 0078 } 0079 0080 QStringList collectionFolders() const override 0081 { 0082 return m_folders; 0083 } 0084 0085 void setCollectionFolders( const QStringList &folders ) override 0086 { 0087 m_folders = folders; 0088 } 0089 0090 void emitDeviceAdded( int id ) 0091 { 0092 Q_EMIT deviceAdded( id ); 0093 } 0094 0095 void emitDeviceRemoved( int id ) 0096 { 0097 Q_EMIT deviceRemoved( id ); 0098 } 0099 0100 QMap<int,QString> m_mountPoints; 0101 QStringList m_folders; 0102 }; 0103 0104 #endif // SQLMOUNTPOINTMANAGERMOCK_H