diff options
author | Mavridis Philippe <[email protected]> | 2021-02-10 23:03:30 +0200 |
---|---|---|
committer | Mavridis Philippe <[email protected]> | 2021-02-10 23:03:30 +0200 |
commit | 3747174d7835e7ea2332065c6948dbfbb1d26449 (patch) | |
tree | 0a23633dd2d6030956e72cb5a2d3fde73a06b84d /src/directorylist.cpp | |
parent | 6e18c223b2c9e5b598298824dd775117218b0c94 (diff) | |
download | klamav-3747174d7835e7ea2332065c6948dbfbb1d26449.tar.gz klamav-3747174d7835e7ea2332065c6948dbfbb1d26449.zip |
Moved pruneSelectedDirs() from Klamscan to the widget class itself.
This makes more sense and will permit to use this method in other
scenarios.
Signed-off-by: Mavridis Philippe <[email protected]>
Diffstat (limited to 'src/directorylist.cpp')
-rw-r--r-- | src/directorylist.cpp | 72 |
1 files changed, 63 insertions, 9 deletions
diff --git a/src/directorylist.cpp b/src/directorylist.cpp index 6eff239..c4ff438 100644 --- a/src/directorylist.cpp +++ b/src/directorylist.cpp @@ -52,7 +52,7 @@ CollectionSetup::CollectionSetup( TQWidget *parent, bool recursive ) m_recursive = recursive; // m_monitor = new TQCheckBox( i18n("&Watch folders for changes"), this ); // m_playlists = new TQCheckBox( i18n("&Import playlists"), this ); -// +// // TQToolTip::add( m_recursive, i18n( "If selected, amaroK reads all folders recursively." ) ); // TQToolTip::add( m_monitor, i18n( "If selected, folders will automatically get rescanned when the content is modified, e.g. when a new file was added." ) ); // TQToolTip::add( m_playlists, i18n( "If selected, playlist files (.m3u) will automatically be added to the Playlist-Browser." ) ); @@ -69,7 +69,7 @@ CollectionSetup::CollectionSetup( TQWidget *parent, bool recursive ) new Item( m_view, i18n( "System Folder" ), "/", "folder_red" ); new Item( m_view, i18n( "Home Folder" ), TQDir::homeDirPath(), "folder_home" ); new DeviceItem( m_view ); - + setSpacing( 6 ); } @@ -121,7 +121,7 @@ TQString Item::fullPath() const { TQString path; - + for ( const TQListViewItem *item = this; dynamic_cast<const TQListViewItem*>( item ); item = item->parent() ) { path.prepend( '/' ); @@ -275,7 +275,7 @@ DeviceItem::DeviceItem( TQListViewItem *parent, const TQString &name, const KURL mediacall="mountwatcher"; devicecall="basicDeviceInfo"; } - + DCOPRef mediamanager("kded", mediacall); DCOPReply reply = mediamanager.call( devicecall, url.fileName() ); @@ -287,7 +287,7 @@ DeviceItem::DeviceItem( TQListViewItem *parent, const TQString &name, const KURL retVal = reply; //KAutoMount* am = new KAutoMount( true, "", retVal[5], "","", false ); ////kdDebug() << retVal[6] << endl; - + setText(1, KURL(retVal[6]).path()); setText(2, url.fileName()); kdDebug() << "Device Item: " << name << " " << url.fileName() << " " << text(1) << endl; @@ -328,7 +328,7 @@ DeviceItem::stateChange( bool b ) if( CollectionSetup::instance()->recursive() ) for( TQListViewItem *item = firstChild(); item; item = item->nextSibling() ) static_cast<TQCheckListItem*>(item)->TQCheckListItem::setOn( b ); - + if (text(1) != "devices") { // Update folder list @@ -352,7 +352,7 @@ DeviceItem::stateChange( bool b ) CollectionSetup::instance()->m_refcount.remove(text(1)); } } - } + } // Redraw parent items listView()->triggerUpdate(); @@ -378,7 +378,7 @@ DeviceItem::newItems( const KFileItemList &list ) //SLOT item->setOn( CollectionSetup::instance()->recursive() && isOn() || CollectionSetup::instance()->m_dirs.contains( item->fullPath() ) ); - + item->setPixmap( 0, (*it)->pixmap( TDEIcon::SizeSmall ) ); } } @@ -389,7 +389,7 @@ void DeviceItem::paintCell( TQPainter * p, const TQColorGroup & cg, int column, int width, int align ) { bool dirty = false; - + TQColorGroup _cg = cg; ////kdDebug() << text(1) << endl; @@ -472,6 +472,60 @@ DeviceItem::mountDevice( const TQString & device) } } +TQStringList CollectionSetup::pruneSelectedDirs(){ + // This gets rid of redundant sub-directories + // from the list of dirs to be scanned. + + TQStringList filepattern; + + TQStringList listOfUrls = dirs(); + listOfUrls.sort(); + + TQString prev; + TQStringList prevdirs; + struct stat sb; + for (TQStringList::Iterator it = listOfUrls.begin(); it != listOfUrls.end(); it++ ){ + //kdDebug() << "dir: " << (*it) << endl; + (*it) = (*it).stripWhiteSpace(); + + // replace block devices with mountpoints + lstat( (*it).ascii(), &sb ); + if ( (sb.st_mode & S_IFMT) == S_IFBLK ) { + // This is actually from directorylist.cpp + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call( "properties", (*it) ); + + TQStringList properties; + reply.get( properties, "TQStringList" ); + + (*it) = * (properties.at(7) ); + } else { + (*it) = (*it) + "/"; + } + + if (prevdirs.isEmpty()){ + //kdDebug() << (*it) << endl; + filepattern.append(*it); + prevdirs.append((*it)); + }else{ + filepattern.append(*it); + bool shouldappend = true; + for (TQStringList::Iterator it2 = prevdirs.begin(); it2 != prevdirs.end(); it2++ ){ + if ((*it).contains(*it2)){ + //kdDebug() << (*it) << endl; + filepattern.remove((*it)); + shouldappend = false; + break; + } + } + + if (shouldappend) + prevdirs.append((*it)); + } + } + + return filepattern; +} #include "directorylist.moc" |