void KonqSidebarTree::rescanConfiguration() { kdDebug(1201) << "KonqSidebarTree::rescanConfiguration()" << endl; m_autoOpenTimer->stop(); clearTree(); if (m_dirtreeDir.type==VIRT_Folder) { kdDebug(1201)<<"KonqSidebarTree::rescanConfiguration()-->scanDir"<<endl; scanDir( 0, m_dirtreeDir.dir.path(), true); } else { kdDebug(1201)<<"KonqSidebarTree::rescanConfiguration()-->loadTopLevel"<<endl; loadTopLevelItem( 0, m_dirtreeDir.dir.path() ); } }
void KonqSidebarTree::scanDir( KonqSidebarTreeItem *parent, const QString &path, bool isRoot ) { QDir dir( path ); if ( !dir.isReadable() ) return; kdDebug(1201) << "scanDir " << path << endl; QStringList entries = dir.entryList( QDir::Files ); QStringList dirEntries = dir.entryList( QDir::Dirs | QDir::NoSymLinks ); dirEntries.remove( "." ); dirEntries.remove( ".." ); if ( isRoot ) { bool copyConfig = ( entries.count() == 0 && dirEntries.count() == 0 ); if (!copyConfig) { // Check version number // Version 1 was the dirtree of KDE 2.0.x (no versioning at that time, so default) // Version 2 includes the history // Version 3 includes the bookmarks // Version 4 includes lan.desktop and floppy.desktop, Alex // Version 5 includes the audiocd browser // Version 6 includes the printmanager and lan browser const int currentVersion = 6; QString key = QString::fromLatin1("X-KDE-DirTreeVersionNumber"); KSimpleConfig versionCfg( path + "/.directory" ); int versionNumber = versionCfg.readNumEntry( key, 1 ); kdDebug(1201) << "KonqSidebarTree::scanDir found version " << versionNumber << endl; if ( versionNumber < currentVersion ) { versionCfg.writeEntry( key, currentVersion ); versionCfg.sync(); copyConfig = true; } } if (copyConfig) { // We will copy over the configuration for the dirtree, from the global directory QStringList dirtree_dirs = KGlobal::dirs()->findDirs("data","konqsidebartng/virtual_folders/"+m_dirtreeDir.relDir+"/"); // QString dirtree_dir = KGlobal::dirs()->findDirs("data","konqsidebartng/virtual_folders/"+m_dirtreeDir.relDir+"/").last(); // most global // kdDebug(1201) << "KonqSidebarTree::scanDir dirtree_dir=" << dirtree_dir << endl; /* // debug code QStringList blah = m_part->getInterfaces->getInstance()->dirs()->dirs()->findDirs( "data", "konqueror/dirtree" ); QStringList::ConstIterator eIt = blah.begin(); QStringList::ConstIterator eEnd = blah.end(); for (; eIt != eEnd; ++eIt ) kdDebug(1201) << "KonqSidebarTree::scanDir findDirs got me " << *eIt << endl; // end debug code */ for (QStringList::const_iterator ddit=dirtree_dirs.begin();ddit!=dirtree_dirs.end();++ddit) { QString dirtree_dir=*ddit; if (dirtree_dir==path) continue; // if ( !dirtree_dir.isEmpty() && dirtree_dir != path ) { QDir globalDir( dirtree_dir ); Q_ASSERT( globalDir.isReadable() ); // Only copy the entries that don't exist yet in the local dir QStringList globalDirEntries = globalDir.entryList(); QStringList::ConstIterator eIt = globalDirEntries.begin(); QStringList::ConstIterator eEnd = globalDirEntries.end(); for (; eIt != eEnd; ++eIt ) { //kdDebug(1201) << "KonqSidebarTree::scanDir dirtree_dir contains " << *eIt << endl; if ( *eIt != "." && *eIt != ".." && !entries.contains( *eIt ) && !dirEntries.contains( *eIt ) ) { // we don't have that one yet -> copy it. QString cp("cp -R -- "); cp += KProcess::quote(dirtree_dir + *eIt); cp += " "; cp += KProcess::quote(path); kdDebug(1201) << "KonqSidebarTree::scanDir executing " << cp << endl; ::system( QFile::encodeName(cp) ); } } } } // hack to make QDir refresh the lists dir.setPath(path); entries = dir.entryList( QDir::Files ); dirEntries = dir.entryList( QDir::Dirs ); dirEntries.remove( "." ); dirEntries.remove( ".." ); } } QStringList::ConstIterator eIt = entries.begin(); QStringList::ConstIterator eEnd = entries.end(); for (; eIt != eEnd; ++eIt ) { QString filePath = QString( *eIt ).prepend( path ); KURL u; u.setPath( filePath ); if ( KMimeType::findByURL( u, 0, true )->name() == "application/x-desktop" ) loadTopLevelItem( parent, filePath ); } eIt = dirEntries.begin(); eEnd = dirEntries.end(); for (; eIt != eEnd; eIt++ ) { QString newPath = QString( path ).append( *eIt ).append( '/' ); if ( newPath == KGlobalSettings::autostartPath() ) continue; loadTopLevelGroup( parent, newPath ); } }
void KonqSidebarTree::scanDir( KonqSidebarTreeItem *parent, const QString &path, bool isRoot ) { QDir dir( path ); if ( !dir.isReadable() ) return; kDebug(1201) << "scanDir" << path; QStringList entries = dir.entryList( QDir::Files ); QStringList dirEntries = dir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot); if ( isRoot ) { bool copyConfig = (entries.isEmpty() && dirEntries.isEmpty()); if (!copyConfig) { // Check version number // Version 1 was the dirtree of KDE 2.0.x (no versioning at that time, so default) // Version 2 includes the history // Version 3 includes the bookmarks // Version 4 includes lan.desktop and floppy.desktop, Alex // Version 5 includes the audiocd browser // Version 6 includes the printmanager and lan browser const int currentVersion = 6; QString key = QString::fromLatin1("X-KDE-DirTreeVersionNumber"); KConfig versionCfg( path + "/.directory", KConfig::SimpleConfig); KConfigGroup generalGroup( &versionCfg, "General" ); int versionNumber = generalGroup.readEntry( key, 1 ); kDebug(1201) << "found version " << versionNumber; if ( versionNumber < currentVersion ) { generalGroup.writeEntry( key, currentVersion ); versionCfg.sync(); copyConfig = true; } } if (copyConfig) { // We will copy over the configuration for the dirtree, from the global directory const QStringList dirtree_dirs = KGlobal::dirs()->findDirs("data","konqsidebartng/virtual_folders/"+m_dirtreeDir.relDir+'/'); // QString dirtree_dir = KGlobal::dirs()->findDirs("data","konqsidebartng/virtual_folders/"+m_dirtreeDir.relDir+"/").last(); // most global // kDebug(1201) << "dirtree_dir=" << dirtree_dir; /* // debug code const QStringList blah = m_sidebarModule->getInterfaces->componentData()->dirs()->dirs()->findDirs( "data", "konqueror/dirtree" ); QStringList::ConstIterator eIt = blah.constBegin(); QStringList::ConstIterator eEnd = blah.constEnd(); for (; eIt != eEnd; ++eIt ) kDebug(1201) << "findDirs got me " << *eIt; // end debug code */ for (QStringList::const_iterator ddit=dirtree_dirs.constBegin(); ddit!=dirtree_dirs.constEnd(); ++ddit) { QString dirtree_dir=*ddit; if (dirtree_dir==path) continue; // if ( !dirtree_dir.isEmpty() && dirtree_dir != path ) { QDir globalDir( dirtree_dir ); Q_ASSERT( globalDir.isReadable() ); // Only copy the entries that don't exist yet in the local dir const QStringList globalDirEntries = globalDir.entryList(); QStringList::ConstIterator eIt = globalDirEntries.constBegin(); QStringList::ConstIterator eEnd = globalDirEntries.constEnd(); for (; eIt != eEnd; ++eIt ) { //kDebug(1201) << "dirtree_dir contains " << *eIt; if ( *eIt != "." && *eIt != ".." && !entries.contains( *eIt ) && !dirEntries.contains( *eIt ) ) { // we don't have that one yet -> copy it. QString cp("cp -R -- "); cp += KShell::quoteArg(dirtree_dir + *eIt); cp += ' '; cp += KShell::quoteArg(path); kDebug(1201) << "executing " << cp; ::system( QFile::encodeName(cp) ); } } } } // hack to make QDir refresh the lists dir.setPath(path); entries = dir.entryList( QDir::Files ); dirEntries = dir.entryList( QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot ); } } // TODO: currently the filename order is used. Implement SortOrder? #69667 QStringList::ConstIterator eIt = entries.constBegin(); QStringList::ConstIterator eEnd = entries.constEnd(); for (; eIt != eEnd; ++eIt ) { const QString filePath = path + *eIt; if (KDesktopFile::isDesktopFile(filePath)) { loadTopLevelItem(parent, filePath); } } eIt = dirEntries.constBegin(); eEnd = dirEntries.constEnd(); for (; eIt != eEnd; eIt++ ) { const QString newPath = QString( path ).append( *eIt ).append( QLatin1Char( '/' ) ); loadTopLevelGroup( parent, newPath ); } }