summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2021-02-10 23:03:30 +0200
committerMavridis Philippe <mavridisf@gmail.com>2021-02-10 23:03:30 +0200
commit3747174d7835e7ea2332065c6948dbfbb1d26449 (patch)
tree0a23633dd2d6030956e72cb5a2d3fde73a06b84d /src
parent6e18c223b2c9e5b598298824dd775117218b0c94 (diff)
downloadklamav-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 <mavridisf@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/directorylist.cpp72
-rw-r--r--src/directorylist.h7
-rw-r--r--src/klamscan.cpp109
-rw-r--r--src/klamscan.h3
4 files changed, 95 insertions, 96 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"
diff --git a/src/directorylist.h b/src/directorylist.h
index 6c6b451..c1820c8 100644
--- a/src/directorylist.h
+++ b/src/directorylist.h
@@ -22,6 +22,7 @@
#include <tqcheckbox.h> //inlined functions
#include <tqlistview.h> //baseclass
#include <tqvbox.h> //baseclass
+#include <tqstringlist.h>
#include <kdirlister.h> //stack allocated
#include <kurl.h> //stack allocated
@@ -47,6 +48,8 @@ public:
TQStringList m_dirs;
TQMap<TQString,int> m_refcount;
+ TQStringList pruneSelectedDirs();
+
signals:
void dirsSelected(TQStringList& dirs);
@@ -99,11 +102,11 @@ class DeviceItem : public TQObject, public TQCheckListItem
public:
DeviceItem( TQListView *parent );
DeviceItem( TQListViewItem *parent, const TQString &name, const KURL &url );
-
+
TQCheckListItem *parent() const { return (TQCheckListItem*)TQListViewItem::parent(); }
bool isDisabled() const { return CollectionSetup::instance()->recursive() && parent() && parent()->isOn(); }
TQString fullPath() const;
-
+
void setOpen( bool b ); // reimpl.
void stateChange( bool ); // reimpl.
void activate(); // reimpl.
diff --git a/src/klamscan.cpp b/src/klamscan.cpp
index 2a945e3..0e0812e 100644
--- a/src/klamscan.cpp
+++ b/src/klamscan.cpp
@@ -44,7 +44,7 @@ Klamscan::Klamscan(TQWidget *parent, const char *name)
-/* scanInProgress = FALSE;
+/* scanInProgress = FALSE;
multiScan = FALSE; */
setDefaults();
TQBoxLayout *top = new TQVBoxLayout(this,10,10);
@@ -54,9 +54,9 @@ Klamscan::Klamscan(TQWidget *parent, const char *name)
tabBrowser->setMargin(5);
top->addWidget(tabBrowser);
-
+
/* dblayout->addMultiCellWidget( tabBrowser, 0, 1, 1, 1 );*/
-
+
//TQGridLayout *layout = new TQGridLayout(this, 6, 3, 10, 4);
TQWidget* privateLayoutWidget2 = new TQWidget( this, "dblayout" );
@@ -70,9 +70,9 @@ Klamscan::Klamscan(TQWidget *parent, const char *name)
layout->setRowStretch(2, 10);
layout->addRowSpacing(4, 10);
layout->setRowStretch(4, 0);
-
-
-
+
+
+
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
@@ -91,7 +91,7 @@ Klamscan::Klamscan(TQWidget *parent, const char *name)
//check_combo->setFixedSize(check_combo->size());
layout->addWidget(check_combo,0,1);
-
+
recursive_box = new TQCheckBox(i18n("&Scan Folders Recursively"), privateLayoutWidget2);
recursive_box->setMinimumWidth(recursive_box->sizeHint().width());
recursive_box->setChecked(true);
@@ -129,7 +129,7 @@ Klamscan::Klamscan(TQWidget *parent, const char *name)
connect( recursive_box, SIGNAL(toggled(bool)),setup,
SLOT(slotRecursiveToggled(bool)) );
-
+
TQHBox* controls = new TQHBox(tabBrowser);
//controls->setSpacing(5);
@@ -192,7 +192,7 @@ Klamscan::Klamscan(TQWidget *parent, const char *name)
if( args->isSet( "scanthis" ) ) {
slotScan();
}
-
+
}
@@ -212,10 +212,10 @@ bool Klamscan::scanGoingOn() {
void Klamscan::scan( TQStringList filepattern ) {
ScanViewer* homepage = new ScanViewer(this, "page");
-
+
connect( homepage, SIGNAL( scanFinished(TQWidget *) ), this,
SLOT( slotManageButtons(TQWidget *) ) );
-
+
connect( homepage, SIGNAL( scanStartingAgain(TQWidget *) ), this,
SLOT( slotManageButtons(TQWidget *) ) );
@@ -227,7 +227,7 @@ void Klamscan::scan( TQStringList filepattern ) {
TQString suffix = TQString("%1 %2")
.arg(today.toString("ddd MMMM d yyyy"))
.arg(now.toString("hh:mm ap"));
-
+
tabBrowser->addTab(homepage,suffix);
tabBrowser->setCurrentPage(tabBrowser->count() - 1);
@@ -242,7 +242,7 @@ void Klamscan::slotScan()
TQStringList filepattern;
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
-
+
if( args->isSet( "scanthis" ) ) {
listOfUrlsToScan.clear();
for( int i = 0; i < args->count(); i++ ) {
@@ -252,8 +252,8 @@ void Klamscan::slotScan()
}
prevdir = listOfUrlsToScan.first();
- }else{
- filepattern = pruneSelectedDirs();
+ }else{
+ filepattern = setup->pruneSelectedDirs();
}
scan( filepattern );
@@ -289,20 +289,20 @@ void Klamscan::slotAdvOptions(){
/* KlamscanOptions *dialog = new KlamscanOptions( this, "settings");
-
+
dialog->show();
dialog->raise();
dialog->setActiveWindow();*/
tdemain->slotConfigKlamav( "Scanning Backend" );
-
+
}
void Klamscan::slotSchedule(){
- TQStringList filepattern = pruneSelectedDirs();
+ TQStringList filepattern = setup->pruneSelectedDirs();
if (filepattern.isEmpty()){
@@ -314,7 +314,7 @@ void Klamscan::slotSchedule(){
dialog->show();
dialog->raise();
dialog->setActiveWindow();
-
+
}
@@ -323,7 +323,7 @@ void Klamscan::setDefaults(){
config = TDEGlobal::config();
config->setGroup("ScanPaths");
-
+
config->setGroup("Klamscan");
if ((config->readEntry("NoFilesToExtract")).isEmpty())
@@ -334,7 +334,7 @@ void Klamscan::setDefaults(){
// if ((config->readEntry("MBsToExtract")).isEmpty())
// config->writeEntry("MBsToExtract","10M");
-//
+//
// if ((config->readEntry("CompressionRatio")).isEmpty())
// config->writeEntry("CompressionRatio","250");
@@ -390,23 +390,23 @@ void Klamscan::scanURLs(const TQString &urls)
//urlsToScan = temp;
ScanViewer* homepage = new ScanViewer(this, "page");
-
+
connect( homepage, SIGNAL( scanFinished(TQWidget *) ), this,
SLOT( slotManageButtons(TQWidget *) ) );
connect( homepage, SIGNAL( scanStartingAgain(TQWidget *) ), this,
SLOT( slotManageButtons(TQWidget *) ) );
-
+
TQDate today = TQDate::currentDate();
TQTime now = TQTime::currentTime();
TQString suffix = TQString("%1 %2")
.arg(today.toString("ddd MMMM d yyyy"))
.arg(now.toString("hh:mm ap"));
-
+
tabBrowser->addTab(homepage,suffix);
tabBrowser->setCurrentPage(tabBrowser->count() - 1);
CollectionDB::instance()->insertEvent("Manual Scan",TQString("Commencing Scan"),urlsToScan.join(" "));
-
+
homepage->slotScan(urlsToScan, check_combo->currentItem(),setup->recursive(),true);
}
@@ -458,7 +458,7 @@ void Klamscan::slotManageButtons(TQWidget * current){
m_tabsClose->setEnabled(false);
return;
}
-
+
if (cur->scanGoingOn()){
play->setEnabled(false);
stop->setEnabled(true);
@@ -470,61 +470,4 @@ void Klamscan::slotManageButtons(TQWidget * current){
}
-TQStringList Klamscan::pruneSelectedDirs(){
-
-
- //This gets rid of redundant sub-directories from the list of dirs to be scanned.
-
- TQStringList filepattern;
- TQStringList listOfUrlsToScan = setup->dirs();
- listOfUrlsToScan.sort();
- TQString prev;
- TQStringList prevdirs;
- struct stat sb;
- for (TQStringList::Iterator it = listOfUrlsToScan.begin(); it != listOfUrlsToScan.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 "klamscan.moc"
diff --git a/src/klamscan.h b/src/klamscan.h
index cc3a60e..b74d214 100644
--- a/src/klamscan.h
+++ b/src/klamscan.h
@@ -63,7 +63,7 @@ public:
/**
* Use this method to load whatever file/URL you have
*/
-
+
void setDirName(TQString);
bool isMultiScan();
bool scanGoingOn();
@@ -112,7 +112,6 @@ private slots:
void slotManageButtons(TQWidget *current);
private:
void setDefaults();
- TQStringList pruneSelectedDirs();
TQLineEdit *template_edit;
TQComboBox *files_combo, *pattern_combo, *check_combo;
TQCheckBox *recursive_box;