File indexing completed on 2024-10-06 04:25:58
0001 /* 0002 SPDX-FileCopyrightText: 2010 Michal Malek <michalm@jabster.pl> 0003 SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "k3bdataprojectinterface.h" 0009 #include "k3bdataprojectinterfaceadaptor.h" 0010 #include "k3bdatadoc.h" 0011 #include "k3bdiritem.h" 0012 #include "k3bisooptions.h" 0013 #include <QList> 0014 0015 namespace K3b { 0016 0017 0018 DataProjectInterface::DataProjectInterface( DataDoc* doc, const QString& dbusPath ) 0019 : 0020 ProjectInterface( doc, dbusPath ), 0021 m_dataDoc(doc) 0022 { 0023 new K3bDataProjectInterfaceAdaptor( this ); 0024 } 0025 0026 0027 bool DataProjectInterface::createFolder( const QString& name ) 0028 { 0029 return createFolder( name, "/" ); 0030 } 0031 0032 0033 bool DataProjectInterface::createFolder( const QString& name, const QString& dir ) 0034 { 0035 DataItem* p = m_dataDoc->root()->findByPath( dir ); 0036 if( p && p->isDir() && !static_cast<DirItem*>(p)->find( name ) ) { 0037 m_dataDoc->addEmptyDir( name, static_cast<DirItem*>(p) ); 0038 return true; 0039 } 0040 return false; 0041 } 0042 0043 0044 void DataProjectInterface::addUrl( const QString& url, const QString& dir ) 0045 { 0046 addUrls( QStringList(url), dir ); 0047 } 0048 0049 0050 void DataProjectInterface::addUrls( const QStringList& urls, const QString& dir ) 0051 { 0052 DataItem* p = m_dataDoc->root()->findByPath( dir ); 0053 QList<QUrl> urlList; 0054 for( auto& url : urls ) { urlList.push_back( QUrl::fromUserInput( url ) ); } 0055 if( p && p->isDir() ) 0056 m_dataDoc->addUrlsToDir( urlList, static_cast<DirItem*>(p) ); 0057 } 0058 0059 0060 bool DataProjectInterface::removeItem( const QString& path ) 0061 { 0062 DataItem* p = m_dataDoc->root()->findByPath( path ); 0063 if( p && p->isRemoveable() ) { 0064 m_dataDoc->removeItem( p ); 0065 return true; 0066 } 0067 else 0068 return false; 0069 } 0070 0071 0072 bool DataProjectInterface::renameItem( const QString& path, const QString& newName ) 0073 { 0074 DataItem* p = m_dataDoc->root()->findByPath( path ); 0075 if( p && p->isRenameable() && !newName.isEmpty() ) { 0076 p->setK3bName( newName ); 0077 return true; 0078 } 0079 else 0080 return false; 0081 } 0082 0083 0084 void DataProjectInterface::setVolumeID( const QString& id ) 0085 { 0086 m_dataDoc->setVolumeID( id ); 0087 } 0088 0089 bool DataProjectInterface::isFolder( const QString& path ) const 0090 { 0091 DataItem* p = m_dataDoc->root()->findByPath( path ); 0092 if( p ) 0093 return p->isDir(); 0094 else 0095 return false; 0096 } 0097 0098 0099 QStringList DataProjectInterface::children( const QString& path ) const 0100 { 0101 QStringList l; 0102 DataItem* item = m_dataDoc->root()->findByPath( path ); 0103 if( item && item->isDir() ) { 0104 QList<DataItem*> const& cl = static_cast<DirItem*>(item)->children(); 0105 Q_FOREACH( DataItem* item, cl ) { 0106 l.append( item->k3bName() ); 0107 } 0108 } 0109 0110 return l; 0111 } 0112 0113 0114 bool DataProjectInterface::setSortWeight( const QString& path, long weight ) const 0115 { 0116 K3b::DataItem* item = m_dataDoc->root()->findByPath( path ); 0117 if( item ) { 0118 item->setSortWeight( weight ); 0119 return true; 0120 } 0121 else 0122 return false; 0123 } 0124 0125 } // namespace K3b 0126 0127 #include "moc_k3bdataprojectinterface.cpp"