Fix a number of problems with the forwarding slave and dirlister

Fix TDE HW library not detecting mounted drives
pull/16/head
Timothy Pearson 12 years ago
parent 43e139235d
commit 4d6667159e

@ -298,7 +298,9 @@ static void kDebugBackend( unsigned short nLevel, unsigned int nArea, const char
} }
case 2: // Shell case 2: // Shell
{ {
write( 2, buf, strlen( buf ) ); //fputs( buf, stderr ); if (write( 2, buf, strlen( buf ) ) < 0) { //fputs( buf, stderr );
// ERROR
}
break; break;
} }
case 3: // syslog case 3: // syslog

@ -400,6 +400,12 @@ static TQString cleanpath(const TQString &_path, bool cleanDirSeparator, bool de
return result; return result;
} }
class KURLPrivate
{
public:
TQString m_strInternalReferenceURL;
};
bool KURL::isRelativeURL(const TQString &_url) bool KURL::isRelativeURL(const TQString &_url)
{ {
int len = _url.length(); int len = _url.length();
@ -454,6 +460,7 @@ TQStringList KURL::List::toStringList() const
KURL::KURL() KURL::KURL()
{ {
d = new KURLPrivate();
reset(); reset();
} }
@ -464,25 +471,30 @@ KURL::~KURL()
KURL::KURL( const TQString &url, int encoding_hint ) KURL::KURL( const TQString &url, int encoding_hint )
{ {
d = new KURLPrivate();
reset(); reset();
parse( url, encoding_hint ); parse( url, encoding_hint );
} }
KURL::KURL( const char * url, int encoding_hint ) KURL::KURL( const char * url, int encoding_hint )
{ {
d = new KURLPrivate();
reset(); reset();
parse( TQString::fromLatin1(url), encoding_hint ); parse( TQString::fromLatin1(url), encoding_hint );
} }
KURL::KURL( const TQCString& url, int encoding_hint ) KURL::KURL( const TQCString& url, int encoding_hint )
{ {
d = new KURLPrivate();
reset(); reset();
parse( TQString::fromLatin1(url), encoding_hint ); parse( TQString::fromLatin1(url), encoding_hint );
} }
KURL::KURL( const KURL& _u ) KURL::KURL( const KURL& _u )
{ {
d = new KURLPrivate();
*this = _u; *this = _u;
d->m_strInternalReferenceURL = _u.d->m_strInternalReferenceURL;
} }
TQDataStream & operator<< (TQDataStream & s, const KURL & a) TQDataStream & operator<< (TQDataStream & s, const KURL & a)
@ -521,12 +533,16 @@ TQDataStream & operator>> (TQDataStream & s, KURL & a)
#ifndef QT_NO_NETWORKPROTOCOL #ifndef QT_NO_NETWORKPROTOCOL
KURL::KURL( const TQUrl &u ) KURL::KURL( const TQUrl &u )
{ {
d = new KURLPrivate();
*this = u; *this = u;
} }
#endif #endif
KURL::KURL( const KURL& _u, const TQString& _rel_url, int encoding_hint ) KURL::KURL( const KURL& _u, const TQString& _rel_url, int encoding_hint )
{ {
d = new KURLPrivate();
d->m_strInternalReferenceURL = _u.d->m_strInternalReferenceURL;
if (_u.hasSubURL()) // Operate on the last suburl, not the first if (_u.hasSubURL()) // Operate on the last suburl, not the first
{ {
KURL::List lst = split( _u ); KURL::List lst = split( _u );
@ -534,6 +550,7 @@ KURL::KURL( const KURL& _u, const TQString& _rel_url, int encoding_hint )
lst.remove( lst.last() ); lst.remove( lst.last() );
lst.append( u ); lst.append( u );
*this = join( lst ); *this = join( lst );
d->m_strInternalReferenceURL = _u.d->m_strInternalReferenceURL;
return; return;
} }
// WORKAROUND THE RFC 1606 LOOPHOLE THAT ALLOWS // WORKAROUND THE RFC 1606 LOOPHOLE THAT ALLOWS
@ -1077,6 +1094,7 @@ KURL& KURL::operator=( const KURL& _u )
m_bIsMalformed = _u.m_bIsMalformed; m_bIsMalformed = _u.m_bIsMalformed;
m_iPort = _u.m_iPort; m_iPort = _u.m_iPort;
m_iUriMode = _u.m_iUriMode; m_iUriMode = _u.m_iUriMode;
d->m_strInternalReferenceURL = _u.d->m_strInternalReferenceURL;
return *this; return *this;
} }
@ -1137,7 +1155,8 @@ bool KURL::operator==( const KURL& _u ) const
m_strPath_encoded == _u.m_strPath_encoded ) && m_strPath_encoded == _u.m_strPath_encoded ) &&
m_strQuery_encoded == _u.m_strQuery_encoded && m_strQuery_encoded == _u.m_strQuery_encoded &&
m_strRef_encoded == _u.m_strRef_encoded && m_strRef_encoded == _u.m_strRef_encoded &&
m_iPort == _u.m_iPort ) m_iPort == _u.m_iPort &&
d->m_strInternalReferenceURL == _u.d->m_strInternalReferenceURL )
{ {
return true; return true;
} }
@ -2295,6 +2314,13 @@ TQString KURL::relativePath(const TQString &base_dir, const TQString &path, bool
return result; return result;
} }
void KURL::setInternalReferenceURL( const TQString& url ) {
d->m_strInternalReferenceURL = url;
}
TQString KURL::internalReferenceURL( void ) const {
return d->m_strInternalReferenceURL;
}
TQString KURL::relativeURL(const KURL &base_url, const KURL &url, int encoding_hint) TQString KURL::relativeURL(const KURL &base_url, const KURL &url, int encoding_hint)
{ {

@ -590,6 +590,16 @@ public:
*/ */
bool hasPath() const { return !m_strPath.isEmpty(); } bool hasPath() const { return !m_strPath.isEmpty(); }
/**
* @brief @internal
*/
void setInternalReferenceURL( const TQString& url );
/**
* @brief @internal
*/
TQString internalReferenceURL( void ) const;
/** /**
* @brief Resolves @c "." and @c ".." components in path * @brief Resolves @c "." and @c ".." components in path
* *

@ -868,7 +868,7 @@ TQString TDEStorageDevice::mountPath() {
TQStringList mountInfo = TQStringList::split(" ", line, true); TQStringList mountInfo = TQStringList::split(" ", line, true);
TQString testNode = *mountInfo.at(0); TQString testNode = *mountInfo.at(0);
// Check for match // Check for match
if ((testNode == deviceNode()) || (testNode == dmaltname)) { if ((testNode == deviceNode()) || (testNode == dmaltname) || (testNode == ("/dev/disk/by-uuid/" + diskUUID()))) {
TQString ret = *mountInfo.at(1); TQString ret = *mountInfo.at(1);
ret.replace("\\040", " "); ret.replace("\\040", " ");
return ret; return ret;

@ -63,8 +63,8 @@ KDirListerCache::KDirListerCache( int maxCount )
urlsCurrentlyHeld.setAutoDelete( true ); urlsCurrentlyHeld.setAutoDelete( true );
pendingUpdates.setAutoDelete( true ); pendingUpdates.setAutoDelete( true );
connect( kdirwatch, TQT_SIGNAL( dirty( const TQString& ) ), connect( kdirwatch, TQT_SIGNAL( dirty( const KURL& ) ),
this, TQT_SLOT( slotFileDirty( const TQString& ) ) ); this, TQT_SLOT( slotFileDirty( const KURL& ) ) );
connect( kdirwatch, TQT_SIGNAL( created( const TQString& ) ), connect( kdirwatch, TQT_SIGNAL( created( const TQString& ) ),
this, TQT_SLOT( slotFileCreated( const TQString& ) ) ); this, TQT_SLOT( slotFileCreated( const TQString& ) ) );
connect( kdirwatch, TQT_SIGNAL( deleted( const TQString& ) ), connect( kdirwatch, TQT_SIGNAL( deleted( const TQString& ) ),
@ -99,7 +99,6 @@ bool KDirListerCache::listDir( KDirLister *lister, const KURL& _u,
// Strangely, slotUpdateResult *is* called if the user instead right-clicks on the unmounted media device and selects Mount from the context menu // Strangely, slotUpdateResult *is* called if the user instead right-clicks on the unmounted media device and selects Mount from the context menu
if ((_u.protocol() == "media") && (_u.path() == "/")) { if ((_u.protocol() == "media") && (_u.path() == "/")) {
_reload = true; _reload = true;
_keep = false;
} }
// like this we don't have to worry about trailing slashes any further // like this we don't have to worry about trailing slashes any further
@ -162,8 +161,9 @@ bool KDirListerCache::listDir( KDirLister *lister, const KURL& _u,
emit lister->started( _url ); emit lister->started( _url );
if ( !lister->d->rootFileItem && lister->d->url == _url ) if ( !lister->d->rootFileItem && lister->d->url == _url ) {
lister->d->rootFileItem = itemU->rootItem; lister->d->rootFileItem = itemU->rootItem;
}
lister->addNewItems( *(itemU->lstItems) ); lister->addNewItems( *(itemU->lstItems) );
lister->emitItems(); lister->emitItems();
@ -174,9 +174,10 @@ bool KDirListerCache::listDir( KDirLister *lister, const KURL& _u,
lister->d->complete = oldState; lister->d->complete = oldState;
emit lister->completed( _url ); lister->emitCompleted( _url );
if ( lister->d->complete ) if ( lister->d->complete ) {
emit lister->completed(); emit lister->completed();
}
if ( _reload || !itemU->complete ) { if ( _reload || !itemU->complete ) {
updateDirectory( _url ); updateDirectory( _url );
@ -209,9 +210,10 @@ bool KDirListerCache::listDir( KDirLister *lister, const KURL& _u,
lister->d->complete = oldState; lister->d->complete = oldState;
emit lister->completed( _url ); lister->emitCompleted( _url );
if ( lister->d->complete ) if ( lister->d->complete ) {
emit lister->completed(); emit lister->completed();
}
if ( !itemC->complete ) { if ( !itemC->complete ) {
updateDirectory( _url ); updateDirectory( _url );
@ -237,8 +239,9 @@ bool KDirListerCache::listDir( KDirLister *lister, const KURL& _u,
// else // else
// { // {
if ( lister->d->url == _url ) if ( lister->d->url == _url ) {
lister->d->rootFileItem = 0; lister->d->rootFileItem = 0;
}
TDEIO::ListJob* job = TDEIO::listDir( _url, false /* no default GUI */ ); TDEIO::ListJob* job = TDEIO::listDir( _url, false /* no default GUI */ );
jobs.insert( job, TQValueList<TDEIO::UDSEntry>() ); jobs.insert( job, TQValueList<TDEIO::UDSEntry>() );
@ -246,8 +249,9 @@ bool KDirListerCache::listDir( KDirLister *lister, const KURL& _u,
lister->jobStarted( job ); lister->jobStarted( job );
lister->connectJob( job ); lister->connectJob( job );
if ( lister->d->window ) if ( lister->d->window ) {
job->setWindow( lister->d->window ); job->setWindow( lister->d->window );
}
connect( job, TQT_SIGNAL( entries( TDEIO::Job *, const TDEIO::UDSEntryList & ) ), connect( job, TQT_SIGNAL( entries( TDEIO::Job *, const TDEIO::UDSEntryList & ) ),
this, TQT_SLOT( slotEntries( TDEIO::Job *, const TDEIO::UDSEntryList & ) ) ); this, TQT_SLOT( slotEntries( TDEIO::Job *, const TDEIO::UDSEntryList & ) ) );
@ -285,8 +289,9 @@ bool KDirListerCache::listDir( KDirLister *lister, const KURL& _u,
} }
// automatic updating of directories // automatic updating of directories
if ( lister->d->autoUpdate ) if ( lister->d->autoUpdate ) {
itemU->incAutoUpdate(); itemU->incAutoUpdate();
}
return true; return true;
} }
@ -744,10 +749,12 @@ void KDirListerCache::FilesRemoved( const KURL::List &fileList )
if ( fileitem ) if ( fileitem )
{ {
TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDir.url()]; TQPtrList<KDirLister> *listers = urlsCurrentlyHeld[parentDir.url()];
if ( listers ) if ( listers ) {
for ( KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) for ( KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
kdl->emitDeleteItem( fileitem ); kdl->emitDeleteItem( fileitem );
} }
}
}
// If we found a fileitem, we can test if it's a dir. If not, we'll go to deleteDir just in case. // If we found a fileitem, we can test if it's a dir. If not, we'll go to deleteDir just in case.
if ( !fileitem || fileitem->isDir() ) if ( !fileitem || fileitem->isDir() )
@ -893,26 +900,26 @@ bool KDirListerCache::exists()
// private slots // private slots
// _file can also be a directory being currently held! // _file can also be a directory being currently held!
void KDirListerCache::slotFileDirty( const TQString& _file ) void KDirListerCache::slotFileDirty( const KURL& _url )
{ {
kdDebug(7004) << k_funcinfo << _file << endl; kdDebug(7004) << k_funcinfo << _url << endl;
if ( !pendingUpdates[_file] ) if ( !pendingUpdates[_url.path()] )
{ {
KURL dir; KURL dir;
dir.setPath( _file ); dir.setPath( _url.path() );
if ( checkUpdate( dir.url(-1) ) ) { if ( checkUpdate( dir.url(-1) ) ) {
updateDirectory( dir ); updateDirectory( _url );
} }
// the parent directory of _file // the parent directory of _url.path()
dir.setPath( dir.directory() ); dir.setPath( dir.directory() );
if ( checkUpdate( dir.url() ) ) if ( checkUpdate( dir.url() ) )
{ {
// Nice hack to save memory: use the qt object name to store the filename // Nice hack to save memory: use the qt object name to store the filename
TQTimer *timer = new TQTimer( this, _file.utf8() ); TQTimer *timer = new TQTimer( this, _url.path().utf8() );
connect( timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotFileDirtyDelayed()) ); connect( timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotFileDirtyDelayed()) );
pendingUpdates.insert( _file, timer ); pendingUpdates.insert( _url.path(), timer );
timer->start( 500, true ); timer->start( 500, true );
} }
} }
@ -976,8 +983,9 @@ void KDirListerCache::slotEntries( TDEIO::Job *job, const TDEIO::UDSEntryList &e
// check if anyone wants the mimetypes immediately // check if anyone wants the mimetypes immediately
bool delayedMimeTypes = true; bool delayedMimeTypes = true;
for ( KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) for ( KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
delayedMimeTypes = delayedMimeTypes && kdl->d->delayedMimeTypes; delayedMimeTypes = delayedMimeTypes && kdl->d->delayedMimeTypes;
}
// avoid creating these QStrings again and again // avoid creating these QStrings again and again
static const TQString& dot = TDEGlobal::staticQString("."); static const TQString& dot = TDEGlobal::staticQString(".");
@ -992,16 +1000,17 @@ void KDirListerCache::slotEntries( TDEIO::Job *job, const TDEIO::UDSEntryList &e
// find out about the name // find out about the name
TDEIO::UDSEntry::ConstIterator entit = (*it).begin(); TDEIO::UDSEntry::ConstIterator entit = (*it).begin();
for( ; entit != (*it).end(); ++entit ) for( ; entit != (*it).end(); ++entit ) {
if ( (*entit).m_uds == TDEIO::UDS_NAME ) if ( (*entit).m_uds == TDEIO::UDS_NAME ) {
{
name = (*entit).m_str; name = (*entit).m_str;
break; break;
} }
}
Q_ASSERT( !name.isEmpty() ); Q_ASSERT( !name.isEmpty() );
if ( name.isEmpty() ) if ( name.isEmpty() ) {
continue; continue;
}
if ( name == dot ) if ( name == dot )
{ {
@ -1082,7 +1091,7 @@ void KDirListerCache::slotResult( TDEIO::Job *j )
for ( kdl = listers->first(); kdl; kdl = listers->next() ) for ( kdl = listers->first(); kdl; kdl = listers->next() )
{ {
kdl->jobDone( job ); kdl->jobDone( job );
emit kdl->completed( jobUrl ); kdl->emitCompleted( jobUrl );
if ( kdl->numJobs() == 0 ) if ( kdl->numJobs() == 0 )
{ {
kdl->d->complete = true; kdl->d->complete = true;
@ -1500,6 +1509,7 @@ void KDirListerCache::slotUpdateResult( TDEIO::Job * j )
KURL jobUrl = joburl( job ); KURL jobUrl = joburl( job );
jobUrl.adjustPath(-1); // need remove trailing slashes again, in case of redirections jobUrl.adjustPath(-1); // need remove trailing slashes again, in case of redirections
TQString jobUrlStr = jobUrl.url(); TQString jobUrlStr = jobUrl.url();
TQString jobReferenceUrlStr = jobUrl.internalReferenceURL();
kdDebug(7004) << k_funcinfo << "finished update " << jobUrl << endl; kdDebug(7004) << k_funcinfo << "finished update " << jobUrl << endl;
@ -1674,7 +1684,7 @@ void KDirListerCache::slotUpdateResult( TDEIO::Job * j )
kdl->jobDone( job ); kdl->jobDone( job );
emit kdl->completed( jobUrl ); kdl->emitCompleted( jobUrl );
if ( kdl->numJobs() == 0 ) if ( kdl->numJobs() == 0 )
{ {
kdl->d->complete = true; kdl->d->complete = true;
@ -1705,11 +1715,13 @@ TDEIO::ListJob *KDirListerCache::jobForUrl( const TQString& url, TDEIO::ListJob
const KURL& KDirListerCache::joburl( TDEIO::ListJob *job ) const KURL& KDirListerCache::joburl( TDEIO::ListJob *job )
{ {
if ( job->redirectionURL().isValid() ) if ( job->redirectionURL().isValid() ) {
return job->redirectionURL(); return job->redirectionURL();
else }
else {
return job->url(); return job->url();
} }
}
void KDirListerCache::killJob( TDEIO::ListJob *job ) void KDirListerCache::killJob( TDEIO::ListJob *job )
{ {
@ -1727,11 +1739,13 @@ void KDirListerCache::deleteUnmarkedItems( TQPtrList<KDirLister> *listers, KFile
if ( !item->isMarked() ) if ( !item->isMarked() )
{ {
//kdDebug() << k_funcinfo << item->name() << endl; //kdDebug() << k_funcinfo << item->name() << endl;
for ( KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) for ( KDirLister *kdl = listers->first(); kdl; kdl = listers->next() ) {
kdl->emitDeleteItem( item ); kdl->emitDeleteItem( item );
}
if ( item->isDir() ) if ( item->isDir() ) {
deleteDir( item->url() ); deleteDir( item->url() );
}
// finally actually delete the item // finally actually delete the item
lstItems->take(); lstItems->take();
@ -1907,45 +1921,50 @@ bool KDirLister::openURL( const KURL& _url, bool _keep, bool _reload )
<< " keep=" << _keep << " reload=" << _reload << endl; << " keep=" << _keep << " reload=" << _reload << endl;
// emit the current changes made to avoid an inconsistent treeview // emit the current changes made to avoid an inconsistent treeview
if ( d->changes != NONE && _keep ) if ( d->changes != NONE && _keep ) {
emitChanges(); emitChanges();
}
d->changes = NONE; d->changes = NONE;
// If a local path is available, monitor that instead of the given remote URL... // If a local path is available, monitor that instead of the given remote URL...
KURL realURL = _url; if (!_url.isLocalFile()) {
d->providedURL = _url;
if (!realURL.isLocalFile()) {
TDEIO::LocalURLJob* localURLJob = TDEIO::localURL(_url); TDEIO::LocalURLJob* localURLJob = TDEIO::localURL(_url);
if (localURLJob) { if (localURLJob) {
connect(localURLJob, TQT_SIGNAL(localURL(TDEIO::Job*, const KURL&, bool)), this, TQT_SLOT(slotLocalURL(TDEIO::Job*, const KURL&, bool))); d->openURL_url[localURLJob] = _url;
d->openURL_keep[localURLJob] = _keep;
d->openURL_reload[localURLJob] = _reload;
connect(localURLJob, TQT_SIGNAL(localURL(TDEIO::Job*, const KURL&, bool)), this, TQT_SLOT(slotOpenURLGotLocalURL(TDEIO::Job*, const KURL&, bool)));
connect(localURLJob, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotLocalURLKIODestroyed())); connect(localURLJob, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotLocalURLKIODestroyed()));
d->localURLSlotFired = false;
while (!d->localURLSlotFired) {
tqApp->eventLoop()->processEvents(TQEventLoop::ExcludeUserInput);
usleep(1000);
} }
if (d->localURLResultIsLocal) { return true;
realURL = d->localURLResultURL;
} }
else {
return s_pCache->listDir( this, _url, _keep, _reload );
} }
} }
d->listerURL = realURL; void KDirLister::slotOpenURLGotLocalURL(TDEIO::Job *job, const KURL& url, bool isLocal) {
return s_pCache->listDir( this, realURL, _keep, _reload ); KURL realURL = d->openURL_url[job];
if (isLocal) {
realURL = url;
realURL.setInternalReferenceURL(d->openURL_url[job].url());
d->m_referenceURLMap[d->openURL_url[job].url()] = url.path();
} }
s_pCache->listDir( this, realURL, d->openURL_keep[job], d->openURL_reload[job] );
void KDirLister::slotLocalURL(TDEIO::Job *job, const KURL& url, bool isLocal) { d->openURL_url.remove(job);
d->localURLSlotFired = true; d->openURL_keep.remove(job);
d->localURLResultURL = url; d->openURL_reload.remove(job);
d->localURLResultIsLocal = isLocal;
} }
void KDirLister::slotLocalURLKIODestroyed() { void KDirLister::slotLocalURLKIODestroyed() {
if (!d->localURLSlotFired) { TDEIO::LocalURLJob* terminatedJob = const_cast<TDEIO::LocalURLJob*>(static_cast<const TDEIO::LocalURLJob*>(sender()));
d->localURLSlotFired = true;
d->localURLResultURL = KURL(); if (d->openURL_url.contains(terminatedJob)) {
d->localURLResultIsLocal = false; s_pCache->listDir( this, d->openURL_url[terminatedJob], d->openURL_keep[terminatedJob], d->openURL_reload[terminatedJob] );
d->openURL_url.remove(terminatedJob);
d->openURL_keep.remove(terminatedJob);
d->openURL_reload.remove(terminatedJob);
} }
} }
@ -1953,12 +1972,14 @@ void KDirLister::stop()
{ {
kdDebug(7003) << k_funcinfo << endl; kdDebug(7003) << k_funcinfo << endl;
s_pCache->stop( this ); s_pCache->stop( this );
d->m_referenceURLMap.clear();
} }
void KDirLister::stop( const KURL& _url ) void KDirLister::stop( const KURL& _url )
{ {
kdDebug(7003) << k_funcinfo << _url.prettyURL() << endl; kdDebug(7003) << k_funcinfo << _url.prettyURL() << endl;
s_pCache->stop( this, _url ); s_pCache->stop( this, _url );
d->m_referenceURLMap.remove(_url.url());
} }
bool KDirLister::autoUpdate() const bool KDirLister::autoUpdate() const
@ -2319,15 +2340,20 @@ void KDirLister::addNewItem( const KFileItem *item )
return; // No reason to continue... bailing out here prevents a mimetype scan. return; // No reason to continue... bailing out here prevents a mimetype scan.
} }
if (d->listerURL != d->providedURL) { if ((item->url().internalReferenceURL() != "")
&& (d->m_referenceURLMap.contains(item->url().internalReferenceURL()))) {
// Likely a media:/ tdeioslave URL or similar // Likely a media:/ tdeioslave URL or similar
// Rewrite the URL to ensure that the user remains within the media:/ tree! // Rewrite the URL to ensure that the user remains within the media:/ tree!
TQString itemPath = item->url().path(); TQString itemPath = item->url().path();
if (itemPath.startsWith(d->listerURL.path())) { if (itemPath.startsWith(d->m_referenceURLMap[item->url().internalReferenceURL()])) {
itemPath = itemPath.remove(0, d->listerURL.path().length()); itemPath = itemPath.remove(0, d->m_referenceURLMap[item->url().internalReferenceURL()].length());
itemPath = d->providedURL.pathOrURL() + itemPath; TQString newPath = item->url().internalReferenceURL();
if (!newPath.endsWith("/")) newPath = newPath + "/";
while (itemPath.startsWith("/")) itemPath = itemPath.remove(0,1);
while (itemPath.endsWith("/")) itemPath.truncate(itemPath.length()-1);
newPath = newPath + itemPath;
const_cast<KFileItem*>(item)->setListerURL(item->url()); const_cast<KFileItem*>(item)->setListerURL(item->url());
const_cast<KFileItem*>(item)->setURL(itemPath); const_cast<KFileItem*>(item)->setURL(newPath);
} }
} }
@ -2375,6 +2401,23 @@ void KDirLister::addRefreshItem( const KFileItem *item )
{ {
bool isExcluded = (d->dirOnlyMode && !item->isDir()) || !matchesFilter( item ); bool isExcluded = (d->dirOnlyMode && !item->isDir()) || !matchesFilter( item );
if ((item->url().internalReferenceURL() != "")
&& (d->m_referenceURLMap.contains(item->url().internalReferenceURL()))) {
// Likely a media:/ tdeioslave URL or similar
// Rewrite the URL to ensure that the user remains within the media:/ tree!
TQString itemPath = item->url().path();
if (itemPath.startsWith(d->m_referenceURLMap[item->url().internalReferenceURL()])) {
itemPath = itemPath.remove(0, d->m_referenceURLMap[item->url().internalReferenceURL()].length());
TQString newPath = item->url().internalReferenceURL();
if (!newPath.endsWith("/")) newPath = newPath + "/";
while (itemPath.startsWith("/")) itemPath = itemPath.remove(0,1);
while (itemPath.endsWith("/")) itemPath.truncate(itemPath.length()-1);
newPath = newPath + itemPath;
const_cast<KFileItem*>(item)->setListerURL(item->url());
const_cast<KFileItem*>(item)->setURL(newPath);
}
}
if ( !isExcluded && matchesMimeFilter( item ) ) if ( !isExcluded && matchesMimeFilter( item ) )
{ {
if ( d->refreshItemWasFiltered ) if ( d->refreshItemWasFiltered )
@ -2422,7 +2465,31 @@ void KDirLister::emitItems()
if ( tmpNew ) if ( tmpNew )
{ {
emit newItems( *tmpNew ); // For historical reasons, items with different protocols and/or prefixes must be emitted separately
TQString protocol;
TQString prefix;
TQString prevProtocol;
TQString prevPrefix;
KFileItemList emitList;
for ( KFileItemListIterator kit( *tmpNew ); kit.current(); ++kit )
{
KFileItem *item = *kit;
protocol = item->url().protocol();
prefix = TQStringList::split("/", item->url().path())[0];
if ((protocol != prevProtocol) || (prefix != prevPrefix)) {
if (emitList.count() > 0) {
emit newItems( emitList );
emitList.clear();
}
}
emitList.append(item);
prevProtocol = protocol;
prevPrefix = prefix;
}
if (emitList.count() > 0) {
emit newItems( emitList );
}
delete tmpNew; delete tmpNew;
} }
@ -2449,11 +2516,14 @@ void KDirLister::emitItems()
void KDirLister::emitDeleteItem( KFileItem *item ) void KDirLister::emitDeleteItem( KFileItem *item )
{ {
if ( ( d->dirOnlyMode && !item->isDir() ) || !matchesFilter( item ) ) if ( ( d->dirOnlyMode && !item->isDir() ) || !matchesFilter( item ) ) {
return; // No reason to continue... bailing out here prevents a mimetype scan. return; // No reason to continue... bailing out here prevents a mimetype scan.
if ( matchesMimeFilter( item ) ) }
if ( matchesMimeFilter( item ) ) {
emit deleteItem( item ); emit deleteItem( item );
} }
}
// ================ private slots ================ // // ================ private slots ================ //
@ -2567,6 +2637,29 @@ void KDirLister::connectJob( TDEIO::ListJob *job )
this, TQT_SLOT(slotSpeed( TDEIO::Job *, unsigned long )) ); this, TQT_SLOT(slotSpeed( TDEIO::Job *, unsigned long )) );
} }
void KDirLister::emitCompleted( const KURL& _url )
{
KURL emitURL = _url;
if ((_url.internalReferenceURL() != "")
&& (d->m_referenceURLMap.contains(_url.internalReferenceURL()))) {
// Likely a media:/ tdeioslave URL or similar
// Rewrite the URL to ensure that the user remains within the media:/ tree!
TQString itemPath = _url.path();
if (itemPath.startsWith(d->m_referenceURLMap[_url.internalReferenceURL()])) {
itemPath = itemPath.remove(0, d->m_referenceURLMap[_url.internalReferenceURL()].length());
TQString newPath = _url.internalReferenceURL();
if (!newPath.endsWith("/")) newPath = newPath + "/";
while (itemPath.startsWith("/")) itemPath = itemPath.remove(0,1);
while (itemPath.endsWith("/")) itemPath.truncate(itemPath.length()-1);
newPath = newPath + itemPath;
emitURL = newPath;
}
}
emit completed( emitURL );
}
void KDirLister::setMainWindow( TQWidget *window ) void KDirLister::setMainWindow( TQWidget *window )
{ {
d->window = window; d->window = window;

@ -100,7 +100,7 @@ public:
* Use only when opening a dir not yet listed by this lister * Use only when opening a dir not yet listed by this lister
* without using the cache. Otherwise use updateDirectory. * without using the cache. Otherwise use updateDirectory.
* @return true if successful, * @return true if successful,
* false otherwise (e.g. invalid @p _url) * false otherwise (e.g. unable to communicate with tdeio slave)
*/ */
virtual bool openURL( const KURL& _url, bool _keep = false, bool _reload = false ); virtual bool openURL( const KURL& _url, bool _keep = false, bool _reload = false );
@ -609,7 +609,7 @@ private slots:
void slotTotalSize( TDEIO::Job *, TDEIO::filesize_t ); void slotTotalSize( TDEIO::Job *, TDEIO::filesize_t );
void slotProcessedSize( TDEIO::Job *, TDEIO::filesize_t ); void slotProcessedSize( TDEIO::Job *, TDEIO::filesize_t );
void slotSpeed( TDEIO::Job *, unsigned long ); void slotSpeed( TDEIO::Job *, unsigned long );
void slotLocalURL( TDEIO::Job *, const KURL&, bool ); void slotOpenURLGotLocalURL( TDEIO::Job *, const KURL&, bool );
void slotLocalURLKIODestroyed( ); void slotLocalURLKIODestroyed( );
private: private:
@ -619,6 +619,9 @@ private:
uint numJobs(); uint numJobs();
public:
void emitCompleted( const KURL& _url );
private: private:
virtual void addNewItem( const KFileItem *item ); virtual void addNewItem( const KFileItem *item );
virtual void addNewItems( const KFileItemList& items ); virtual void addNewItems( const KFileItemList& items );

@ -36,7 +36,6 @@ class TQTimer;
class KDirLister; class KDirLister;
namespace TDEIO { class Job; class ListJob; } namespace TDEIO { class Job; class ListJob; }
class KDirLister::KDirListerPrivate class KDirLister::KDirListerPrivate
{ {
public: public:
@ -112,11 +111,11 @@ public:
TQStringList mimeFilter, oldMimeFilter; TQStringList mimeFilter, oldMimeFilter;
TQStringList mimeExcludeFilter, oldMimeExcludeFilter; TQStringList mimeExcludeFilter, oldMimeExcludeFilter;
bool localURLSlotFired; TQMap<TDEIO::Job*, KURL> openURL_url;
KURL localURLResultURL; TQMap<TDEIO::Job*, bool> openURL_keep;
bool localURLResultIsLocal; TQMap<TDEIO::Job*, bool> openURL_reload;
KURL providedURL;
KURL listerURL; TQMap<TQString,TQString> m_referenceURLMap;
}; };
/** /**
@ -191,7 +190,7 @@ public:
static bool exists(); static bool exists();
private slots: private slots:
void slotFileDirty( const TQString &_file ); void slotFileDirty( const KURL &_url );
void slotFileCreated( const TQString &_file ); void slotFileCreated( const TQString &_file );
void slotFileDeleted( const TQString &_file ); void slotFileDeleted( const TQString &_file );
@ -249,7 +248,7 @@ private:
if ( autoUpdates ) if ( autoUpdates )
{ {
if ( KDirWatch::exists() && url.isLocalFile() ) if ( KDirWatch::exists() && url.isLocalFile() )
kdirwatch->removeDir( url.path() ); kdirwatch->removeDir( url );
sendSignal( false, url ); sendSignal( false, url );
} }
delete rootItem; delete rootItem;
@ -272,11 +271,11 @@ private:
if ( autoUpdates ) if ( autoUpdates )
{ {
if ( url.isLocalFile() ) if ( url.isLocalFile() )
kdirwatch->removeDir( url.path() ); kdirwatch->removeDir( url );
sendSignal( false, url ); sendSignal( false, url );
if ( newUrl.isLocalFile() ) if ( newUrl.isLocalFile() )
kdirwatch->addDir( newUrl.path() ); kdirwatch->addDir( newUrl );
sendSignal( true, newUrl ); sendSignal( true, newUrl );
} }
@ -291,7 +290,7 @@ private:
if ( autoUpdates++ == 0 ) if ( autoUpdates++ == 0 )
{ {
if ( url.isLocalFile() ) if ( url.isLocalFile() )
kdirwatch->addDir( url.path() ); kdirwatch->addDir( url );
sendSignal( true, url ); sendSignal( true, url );
} }
} }
@ -301,7 +300,7 @@ private:
if ( --autoUpdates == 0 ) if ( --autoUpdates == 0 )
{ {
if ( url.isLocalFile() ) if ( url.isLocalFile() )
kdirwatch->removeDir( url.path() ); kdirwatch->removeDir( url );
sendSignal( false, url ); sendSignal( false, url );
} }

@ -60,6 +60,7 @@
#include <tdeglobal.h> #include <tdeglobal.h>
#include <kstaticdeleter.h> #include <kstaticdeleter.h>
#include <kde_file.h> #include <kde_file.h>
#include <kurl.h>
// debug // debug
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -429,9 +430,9 @@ void KDirWatchPrivate::slotActivated()
kdDebug(7001) << "-->got deleteself signal for " << e->path << endl; kdDebug(7001) << "-->got deleteself signal for " << e->path << endl;
e->m_status = NonExistent; e->m_status = NonExistent;
if (e->isDir) if (e->isDir)
addEntry(0, TQDir::cleanDirPath(e->path+"/.."), e, true); addEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e, true);
else else
addEntry(0, TQFileInfo(e->path).dirPath(true), e, true); addEntry(0, TQFileInfo(e->path.path()).dirPath(true), e, true);
} }
if ( event->mask & IN_IGNORED ) { if ( event->mask & IN_IGNORED ) {
e->wd = 0; e->wd = 0;
@ -439,10 +440,10 @@ void KDirWatchPrivate::slotActivated()
if ( event->mask & (IN_CREATE|IN_MOVED_TO) ) { if ( event->mask & (IN_CREATE|IN_MOVED_TO) ) {
Entry *sub_entry = e->m_entries.first(); Entry *sub_entry = e->m_entries.first();
for(;sub_entry; sub_entry = e->m_entries.next()) for(;sub_entry; sub_entry = e->m_entries.next())
if (sub_entry->path == e->path + "/" + path) break; if (sub_entry->path == e->path.path() + "/" + path) break;
if (sub_entry /*&& sub_entry->isDir*/) { if (sub_entry /*&& sub_entry->isDir*/) {
removeEntry(0,e->path, sub_entry); removeEntry(0,e->path.path(), sub_entry);
KDE_struct_stat stat_buf; KDE_struct_stat stat_buf;
TQCString tpath = TQFile::encodeName(path); TQCString tpath = TQFile::encodeName(path);
KDE_stat(tpath, &stat_buf); KDE_stat(tpath, &stat_buf);
@ -539,19 +540,19 @@ int KDirWatchPrivate::Entry::clients()
} }
KDirWatchPrivate::Entry* KDirWatchPrivate::entry(const TQString& _path) KDirWatchPrivate::Entry* KDirWatchPrivate::entry(const KURL& _path)
{ {
// we only support absolute paths // we only support absolute paths
if (TQDir::isRelativePath(_path)) { if (TQDir::isRelativePath(_path.path())) {
return 0; return 0;
} }
TQString path = _path; TQString path = _path.path();
if ( path.length() > 1 && path.right(1) == "/" ) if ( path.length() > 1 && path.right(1) == "/" )
path.truncate( path.length() - 1 ); path.truncate( path.length() - 1 );
EntryMap::Iterator it = m_mapEntries.find( path ); EntryMap::Iterator it = m_mapEntries.find( _path );
if ( it == m_mapEntries.end() ) if ( it == m_mapEntries.end() )
return 0; return 0;
else else
@ -588,10 +589,10 @@ bool KDirWatchPrivate::useFAM(Entry* e)
if (e->isDir) { if (e->isDir) {
if (e->m_status == NonExistent) { if (e->m_status == NonExistent) {
// If the directory does not exist we watch the parent directory // If the directory does not exist we watch the parent directory
addEntry(0, TQDir::cleanDirPath(e->path+"/.."), e, true); addEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e, true);
} }
else { else {
int res =FAMMonitorDirectory(&fc, TQFile::encodeName(e->path), int res =FAMMonitorDirectory(&fc, TQFile::encodeName(e->path.path()),
&(e->fr), e); &(e->fr), e);
if (res<0) { if (res<0) {
e->m_mode = UnknownMode; e->m_mode = UnknownMode;
@ -600,16 +601,16 @@ bool KDirWatchPrivate::useFAM(Entry* e)
} }
kdDebug(7001) << " Setup FAM (Req " kdDebug(7001) << " Setup FAM (Req "
<< FAMREQUEST_GETREQNUM(&(e->fr)) << FAMREQUEST_GETREQNUM(&(e->fr))
<< ") for " << e->path << endl; << ") for " << e->path.path() << endl;
} }
} }
else { else {
if (e->m_status == NonExistent) { if (e->m_status == NonExistent) {
// If the file does not exist we watch the directory // If the file does not exist we watch the directory
addEntry(0, TQFileInfo(e->path).dirPath(true), e, true); addEntry(0, TQFileInfo(e->path.path()).dirPath(true), e, true);
} }
else { else {
int res = FAMMonitorFile(&fc, TQFile::encodeName(e->path), int res = FAMMonitorFile(&fc, TQFile::encodeName(e->path.path()),
&(e->fr), e); &(e->fr), e);
if (res<0) { if (res<0) {
e->m_mode = UnknownMode; e->m_mode = UnknownMode;
@ -619,7 +620,7 @@ bool KDirWatchPrivate::useFAM(Entry* e)
kdDebug(7001) << " Setup FAM (Req " kdDebug(7001) << " Setup FAM (Req "
<< FAMREQUEST_GETREQNUM(&(e->fr)) << FAMREQUEST_GETREQNUM(&(e->fr))
<< ") for " << e->path << endl; << ") for " << e->path.path() << endl;
} }
} }
@ -644,7 +645,7 @@ bool KDirWatchPrivate::useDNotify(Entry* e)
if (e->isDir) { if (e->isDir) {
if (e->m_status == Normal) { if (e->m_status == Normal) {
int fd = KDE_open(TQFile::encodeName(e->path).data(), O_RDONLY); int fd = KDE_open(TQFile::encodeName(e->path.path()).data(), O_RDONLY);
// Migrate fd to somewhere above 128. Some libraries have // Migrate fd to somewhere above 128. Some libraries have
// constructs like: // constructs like:
// fd = socket(...) // fd = socket(...)
@ -688,16 +689,16 @@ bool KDirWatchPrivate::useDNotify(Entry* e)
e->dn_fd = fd; e->dn_fd = fd;
kdDebug(7001) << " Setup DNotify (fd " << fd kdDebug(7001) << " Setup DNotify (fd " << fd
<< ") for " << e->path << endl; << ") for " << e->path.path() << endl;
} }
else { // NotExisting else { // NotExisting
addEntry(0, TQDir::cleanDirPath(e->path+"/.."), e, true); addEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e, true);
} }
} }
else { // File else { // File
// we always watch the directory (DNOTIFY can't watch files alone) // we always watch the directory (DNOTIFY can't watch files alone)
// this notifies us about changes of files therein // this notifies us about changes of files therein
addEntry(0, TQFileInfo(e->path).dirPath(true), e, true); addEntry(0, TQFileInfo(e->path.path()).dirPath(true), e, true);
} }
return true; return true;
@ -726,14 +727,14 @@ bool KDirWatchPrivate::useINotify( Entry* e )
} }
if ( ( e->wd = inotify_add_watch( m_inotify_fd, if ( ( e->wd = inotify_add_watch( m_inotify_fd,
TQFile::encodeName( e->path ), mask) ) > 0 ) TQFile::encodeName( e->path.path() ), mask) ) > 0 )
return true; return true;
if ( e->m_status == NonExistent ) { if ( e->m_status == NonExistent ) {
if (e->isDir) if (e->isDir)
addEntry(0, TQDir::cleanDirPath(e->path+"/.."), e, true); addEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e, true);
else else
addEntry(0, TQFileInfo(e->path).dirPath(true), e, true); addEntry(0, TQFileInfo(e->path.path()).dirPath(true), e, true);
return true; return true;
} }
@ -743,8 +744,8 @@ bool KDirWatchPrivate::useINotify( Entry* e )
bool KDirWatchPrivate::useStat(Entry* e) bool KDirWatchPrivate::useStat(Entry* e)
{ {
if ( e->path.startsWith("/media/") || (e->path == "/media") if ( e->path.path().startsWith("/media/") || (e->path.path() == "/media")
|| (TDEIO::probably_slow_mounted(e->path)) ) || (TDEIO::probably_slow_mounted(e->path.path())) )
useFreq(e, m_nfsPollInterval); useFreq(e, m_nfsPollInterval);
else else
useFreq(e, m_PollInterval); useFreq(e, m_PollInterval);
@ -761,7 +762,7 @@ bool KDirWatchPrivate::useStat(Entry* e)
} }
kdDebug(7001) << " Setup Stat (freq " << e->freq kdDebug(7001) << " Setup Stat (freq " << e->freq
<< ") for " << e->path << endl; << ") for " << e->path.path() << endl;
return true; return true;
} }
@ -772,17 +773,17 @@ bool KDirWatchPrivate::useStat(Entry* e)
* Sometimes, entries are dependant on each other: if <sub_entry> !=0, * Sometimes, entries are dependant on each other: if <sub_entry> !=0,
* this entry needs another entry to watch himself (when notExistent). * this entry needs another entry to watch himself (when notExistent).
*/ */
void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path, void KDirWatchPrivate::addEntry(KDirWatch* instance, const KURL& _path,
Entry* sub_entry, bool isDir) Entry* sub_entry, bool isDir)
{ {
TQString path = _path; TQString path = _path.path();
if (path.startsWith("/dev/") || (path == "/dev")) if (path.startsWith("/dev/") || (path == "/dev"))
return; // Don't even go there. return; // Don't even go there.
if ( path.length() > 1 && path.right(1) == "/" ) if ( path.length() > 1 && path.right(1) == "/" )
path.truncate( path.length() - 1 ); path.truncate( path.length() - 1 );
EntryMap::Iterator it = m_mapEntries.find( path ); EntryMap::Iterator it = m_mapEntries.find( _path );
if ( it != m_mapEntries.end() ) if ( it != m_mapEntries.end() )
{ {
if (sub_entry) { if (sub_entry) {
@ -820,7 +821,7 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
mask |= IN_ONLYDIR; mask |= IN_ONLYDIR;
inotify_rm_watch (m_inotify_fd, e->wd); inotify_rm_watch (m_inotify_fd, e->wd);
e->wd = inotify_add_watch( m_inotify_fd, TQFile::encodeName( e->path ), mask); e->wd = inotify_add_watch( m_inotify_fd, TQFile::encodeName( e->path.path() ), mask);
} }
} }
#endif #endif
@ -842,9 +843,9 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
bool exists = (KDE_stat(tpath, &stat_buf) == 0); bool exists = (KDE_stat(tpath, &stat_buf) == 0);
Entry newEntry; Entry newEntry;
m_mapEntries.insert( path, newEntry ); m_mapEntries.insert( _path, newEntry );
// the insert does a copy, so we have to use <e> now // the insert does a copy, so we have to use <e> now
Entry* e = &(m_mapEntries[path]); Entry* e = &(m_mapEntries[_path]);
if (exists) { if (exists) {
e->isDir = S_ISDIR(stat_buf.st_mode); e->isDir = S_ISDIR(stat_buf.st_mode);
@ -867,7 +868,7 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
e->m_nlink = 0; e->m_nlink = 0;
} }
e->path = path; e->path = _path;
if (sub_entry) if (sub_entry)
e->m_entries.append(sub_entry); e->m_entries.append(sub_entry);
else else
@ -875,7 +876,7 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
kdDebug(7001) << "Added " << (e->isDir ? "Dir ":"File ") << path kdDebug(7001) << "Added " << (e->isDir ? "Dir ":"File ") << path
<< (e->m_status == NonExistent ? " NotExisting" : "") << (e->m_status == NonExistent ? " NotExisting" : "")
<< (sub_entry ? TQString(TQString(" for %1").arg(sub_entry->path)) : TQString("")) << (sub_entry ? TQString(TQString(" for %1").arg(sub_entry->path.path())) : TQString(""))
<< (instance ? TQString(TQString(" [%1]").arg(instance->name())) : TQString("")) << (instance ? TQString(TQString(" [%1]").arg(instance->name())) : TQString(""))
<< endl; << endl;
@ -904,7 +905,7 @@ void KDirWatchPrivate::addEntry(KDirWatch* instance, const TQString& _path,
void KDirWatchPrivate::removeEntry( KDirWatch* instance, void KDirWatchPrivate::removeEntry( KDirWatch* instance,
const TQString& _path, Entry* sub_entry ) const KURL& _path, Entry* sub_entry )
{ {
kdDebug(7001) << "KDirWatchPrivate::removeEntry for '" << _path << "' sub_entry: " << sub_entry << endl; kdDebug(7001) << "KDirWatchPrivate::removeEntry for '" << _path << "' sub_entry: " << sub_entry << endl;
Entry* e = entry(_path); Entry* e = entry(_path);
@ -919,7 +920,7 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
e->removeClient(instance); e->removeClient(instance);
if (e->m_clients.count() || e->m_entries.count()) { if (e->m_clients.count() || e->m_entries.count()) {
kdDebug(7001) << "removeEntry: unwatched " << e->path << " " << _path << endl; kdDebug(7001) << "removeEntry: unwatched " << e->path.path() << " " << _path << endl;
return; return;
} }
@ -937,13 +938,13 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
FAMCancelMonitor(&fc, &(e->fr) ); FAMCancelMonitor(&fc, &(e->fr) );
kdDebug(7001) << "Cancelled FAM (Req " kdDebug(7001) << "Cancelled FAM (Req "
<< FAMREQUEST_GETREQNUM(&(e->fr)) << FAMREQUEST_GETREQNUM(&(e->fr))
<< ") for " << e->path << endl; << ") for " << e->path.path() << endl;
} }
else { else {
if (e->isDir) if (e->isDir)
removeEntry(0, TQDir::cleanDirPath(e->path+"/.."), e); removeEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e);
else else
removeEntry(0, TQFileInfo(e->path).dirPath(true), e); removeEntry(0, TQFileInfo(e->path.path()).dirPath(true), e);
} }
} }
#endif #endif
@ -955,13 +956,13 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
(void) inotify_rm_watch( m_inotify_fd, e->wd ); (void) inotify_rm_watch( m_inotify_fd, e->wd );
kdDebug(7001) << "Cancelled INotify (fd " << kdDebug(7001) << "Cancelled INotify (fd " <<
m_inotify_fd << ", " << e->wd << m_inotify_fd << ", " << e->wd <<
") for " << e->path << endl; ") for " << e->path.path() << endl;
} }
else { else {
if (e->isDir) if (e->isDir)
removeEntry(0, TQDir::cleanDirPath(e->path+"/.."), e); removeEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e);
else else
removeEntry(0, TQFileInfo(e->path).dirPath(true), e); removeEntry(0, TQFileInfo(e->path.path()).dirPath(true), e);
} }
} }
#endif #endif
@ -969,7 +970,7 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
#ifdef HAVE_DNOTIFY #ifdef HAVE_DNOTIFY
if (e->m_mode == DNotifyMode) { if (e->m_mode == DNotifyMode) {
if (!e->isDir) { if (!e->isDir) {
removeEntry(0, TQFileInfo(e->path).dirPath(true), e); removeEntry(0, TQFileInfo(e->path.path()).dirPath(true), e);
} }
else { // isDir else { // isDir
// must close the FD. // must close the FD.
@ -979,13 +980,13 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
fd_Entry.remove(e->dn_fd); fd_Entry.remove(e->dn_fd);
kdDebug(7001) << "Cancelled DNotify (fd " << e->dn_fd kdDebug(7001) << "Cancelled DNotify (fd " << e->dn_fd
<< ") for " << e->path << endl; << ") for " << e->path.path() << endl;
e->dn_fd = 0; e->dn_fd = 0;
} }
} }
else { else {
removeEntry(0, TQDir::cleanDirPath(e->path+"/.."), e); removeEntry(0, TQDir::cleanDirPath(e->path.path()+"/.."), e);
} }
} }
} }
@ -999,8 +1000,8 @@ void KDirWatchPrivate::removeEntry( KDirWatch* instance,
} }
} }
kdDebug(7001) << "Removed " << (e->isDir ? "Dir ":"File ") << e->path kdDebug(7001) << "Removed " << (e->isDir ? "Dir ":"File ") << e->path.path()
<< (sub_entry ? TQString(TQString(" for %1").arg(sub_entry->path)) : TQString("")) << (sub_entry ? TQString(TQString(" for %1").arg(sub_entry->path.path())) : TQString(""))
<< (instance ? TQString(TQString(" [%1]").arg(instance->name())) : TQString("")) << (instance ? TQString(TQString(" [%1]").arg(instance->name())) : TQString(""))
<< endl; << endl;
m_mapEntries.remove( e->path ); // <e> not valid any more m_mapEntries.remove( e->path ); // <e> not valid any more
@ -1052,7 +1053,7 @@ bool KDirWatchPrivate::stopEntryScan( KDirWatch* instance, Entry* e)
stillWatching += c->count; stillWatching += c->count;
} }
kdDebug(7001) << instance->name() << " stopped scanning " << e->path kdDebug(7001) << instance->name() << " stopped scanning " << e->path.path()
<< " (now " << stillWatching << " watchers)" << endl; << " (now " << stillWatching << " watchers)" << endl;
if (stillWatching == 0) { if (stillWatching == 0) {
@ -1082,7 +1083,7 @@ bool KDirWatchPrivate::restartEntryScan( KDirWatch* instance, Entry* e,
if (newWatching == 0) if (newWatching == 0)
return false; return false;
kdDebug(7001) << (instance ? instance->name() : "all") << " restarted scanning " << e->path kdDebug(7001) << (instance ? instance->name() : "all") << " restarted scanning " << e->path.path()
<< " (now " << wasWatching+newWatching << " watchers)" << endl; << " (now " << wasWatching+newWatching << " watchers)" << endl;
// restart watching and emit pending events // restart watching and emit pending events
@ -1091,7 +1092,7 @@ bool KDirWatchPrivate::restartEntryScan( KDirWatch* instance, Entry* e,
if (wasWatching == 0) { if (wasWatching == 0) {
if (!notify) { if (!notify) {
KDE_struct_stat stat_buf; KDE_struct_stat stat_buf;
bool exists = (KDE_stat(TQFile::encodeName(e->path), &stat_buf) == 0); bool exists = (KDE_stat(TQFile::encodeName(e->path.path()), &stat_buf) == 0);
if (exists) { if (exists) {
e->m_ctime = stat_buf.st_ctime; e->m_ctime = stat_buf.st_ctime;
e->m_mtime = stat_buf.st_mtime; e->m_mtime = stat_buf.st_mtime;
@ -1170,7 +1171,7 @@ int KDirWatchPrivate::scanEntry(Entry* e)
if (e->m_mode == DNotifyMode || e->m_mode == INotifyMode ) { if (e->m_mode == DNotifyMode || e->m_mode == INotifyMode ) {
// we know nothing has changed, no need to stat // we know nothing has changed, no need to stat
if(!e->dirty) return NoChange; if(!e->dirty) return NoChange;
kdDebug(7001) << "scanning " << e->path << " " << e->m_status << " " << e->m_ctime << " " << e->m_mtime << endl; kdDebug(7001) << "scanning " << e->path.path() << " " << e->m_status << " " << e->m_ctime << " " << e->m_mtime << endl;
e->dirty = false; e->dirty = false;
} }
#endif #endif
@ -1186,7 +1187,7 @@ int KDirWatchPrivate::scanEntry(Entry* e)
} }
KDE_struct_stat stat_buf; KDE_struct_stat stat_buf;
bool exists = (KDE_stat(TQFile::encodeName(e->path), &stat_buf) == 0); bool exists = (KDE_stat(TQFile::encodeName(e->path.path()), &stat_buf) == 0);
if (exists) { if (exists) {
if (e->m_status == NonExistent) { if (e->m_status == NonExistent) {
@ -1232,18 +1233,18 @@ int KDirWatchPrivate::scanEntry(Entry* e)
* and stored pending events. When watching is stopped, the event is * and stored pending events. When watching is stopped, the event is
* added to the pending events. * added to the pending events.
*/ */
void KDirWatchPrivate::emitEvent(Entry* e, int event, const TQString &fileName) void KDirWatchPrivate::emitEvent(Entry* e, int event, const KURL &fileName)
{ {
TQString path = e->path; TQString path = e->path.path();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
if (!TQDir::isRelativePath(fileName)) if (!TQDir::isRelativePath(fileName.path()))
path = fileName; path = fileName.path();
else else
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
path += "/" + fileName; path += "/" + fileName.path();
#elif defined(Q_WS_WIN) #elif defined(Q_WS_WIN)
//current drive is passed instead of / //current drive is passed instead of /
path += TQDir::currentDirPath().left(2) + "/" + fileName; path += TQDir::currentDirPath().left(2) + "/" + fileName.path();
#endif #endif
} }
@ -1279,8 +1280,10 @@ void KDirWatchPrivate::emitEvent(Entry* e, int event, const TQString &fileName)
// possible emit Change event after creation // possible emit Change event after creation
} }
if (event & Changed) if (event & Changed) {
c->instance->setDirty(path); c->instance->setDirty(path);
c->instance->setDirty(e->path);
}
} }
} }
@ -1386,11 +1389,11 @@ void KDirWatchPrivate::slotRescan()
// Scan parent of deleted directories for new creation // Scan parent of deleted directories for new creation
Entry* e; Entry* e;
for(e=dList.first();e;e=dList.next()) for(e=dList.first();e;e=dList.next())
addEntry(0, TQDir::cleanDirPath( e->path+"/.."), e, true); addEntry(0, TQDir::cleanDirPath( e->path.path()+"/.."), e, true);
// Remove watch of parent of new created directories // Remove watch of parent of new created directories
for(e=cList.first();e;e=cList.next()) for(e=cList.first();e;e=cList.next())
removeEntry(0, TQDir::cleanDirPath( e->path+"/.."), e); removeEntry(0, TQDir::cleanDirPath( e->path.path()+"/.."), e);
#endif #endif
if ( timerRunning ) if ( timerRunning )
@ -1492,7 +1495,7 @@ void KDirWatchPrivate::checkFAMEvent(FAMEvent* fe)
} }
if (e->m_status == NonExistent) { if (e->m_status == NonExistent) {
kdDebug(7001) << "FAM event for nonExistent entry " << e->path << endl; kdDebug(7001) << "FAM event for nonExistent entry " << e->path.path() << endl;
return; return;
} }
@ -1515,9 +1518,9 @@ void KDirWatchPrivate::checkFAMEvent(FAMEvent* fe)
FAMCancelMonitor(&fc, &(e->fr) ); // needed ? FAMCancelMonitor(&fc, &(e->fr) ); // needed ?
kdDebug(7001) << "Cancelled FAMReq " kdDebug(7001) << "Cancelled FAMReq "
<< FAMREQUEST_GETREQNUM(&(e->fr)) << FAMREQUEST_GETREQNUM(&(e->fr))
<< " for " << e->path << endl; << " for " << e->path.path() << endl;
// Scan parent for a new creation // Scan parent for a new creation
addEntry(0, TQDir::cleanDirPath( e->path+"/.."), e, true); addEntry(0, TQDir::cleanDirPath( e->path.path()+"/.."), e, true);
} }
break; break;
@ -1525,9 +1528,9 @@ void KDirWatchPrivate::checkFAMEvent(FAMEvent* fe)
// check for creation of a directory we have to watch // check for creation of a directory we have to watch
Entry *sub_entry = e->m_entries.first(); Entry *sub_entry = e->m_entries.first();
for(;sub_entry; sub_entry = e->m_entries.next()) for(;sub_entry; sub_entry = e->m_entries.next())
if (sub_entry->path == e->path + "/" + fe->filename) break; if (sub_entry->path.path() == e->path.path() + "/" + fe->filename) break;
if (sub_entry && sub_entry->isDir) { if (sub_entry && sub_entry->isDir) {
TQString path = e->path; KURL path = e->path;
removeEntry(0,e->path,sub_entry); // <e> can be invalid here!! removeEntry(0,e->path,sub_entry); // <e> can be invalid here!!
sub_entry->m_status = Normal; sub_entry->m_status = Normal;
if (!useFAM(sub_entry)) if (!useFAM(sub_entry))
@ -1560,7 +1563,7 @@ void KDirWatchPrivate::statistics()
it = m_mapEntries.begin(); it = m_mapEntries.begin();
for( ; it != m_mapEntries.end(); ++it ) { for( ; it != m_mapEntries.end(); ++it ) {
Entry* e = &(*it); Entry* e = &(*it);
kdDebug(7001) << " " << e->path << " (" kdDebug(7001) << " " << e->path.path() << " ("
<< ((e->m_status==Normal)?"":"Nonexistent ") << ((e->m_status==Normal)?"":"Nonexistent ")
<< (e->isDir ? "Dir":"File") << ", using " << (e->isDir ? "Dir":"File") << ", using "
<< ((e->m_mode == FAMMode) ? "FAM" : << ((e->m_mode == FAMMode) ? "FAM" :
@ -1648,15 +1651,23 @@ KDirWatch::~KDirWatch()
// TODO: add watchFiles/recursive support // TODO: add watchFiles/recursive support
void KDirWatch::addDir( const TQString& _path, void KDirWatch::addDir( const TQString& _path, bool watchFiles, bool recursive)
bool watchFiles, bool recursive)
{ {
if (watchFiles || recursive) { if (watchFiles || recursive) {
kdDebug(7001) << "addDir - recursive/watchFiles not supported yet in KDE 3.x" << endl; kdDebug(7001) << "addDir - recursive/watchFiles not supported yet in TDE 3.x" << endl;
} }
if (d) d->addEntry(this, _path, 0, true); if (d) d->addEntry(this, _path, 0, true);
} }
// TODO: add watchFiles/recursive support
void KDirWatch::addDir( const KURL& _url, bool watchFiles, bool recursive)
{
if (watchFiles || recursive) {
kdDebug(7001) << "addDir - recursive/watchFiles not supported yet in TDE 3.x" << endl;
}
if (d) d->addEntry(this, _url, 0, true);
}
void KDirWatch::addFile( const TQString& _path ) void KDirWatch::addFile( const TQString& _path )
{ {
if (d) d->addEntry(this, _path, 0, false); if (d) d->addEntry(this, _path, 0, false);
@ -1679,6 +1690,11 @@ void KDirWatch::removeDir( const TQString& _path )
if (d) d->removeEntry(this, _path, 0); if (d) d->removeEntry(this, _path, 0);
} }
void KDirWatch::removeDir( const KURL& _url )
{
if (d) d->removeEntry(this, _url, 0);
}
void KDirWatch::removeFile( const TQString& _path ) void KDirWatch::removeFile( const TQString& _path )
{ {
if (d) d->removeEntry(this, _path, 0); if (d) d->removeEntry(this, _path, 0);
@ -1752,6 +1768,12 @@ void KDirWatch::setDirty( const TQString & _file )
emit dirty( _file ); emit dirty( _file );
} }
void KDirWatch::setDirty( const KURL & _url )
{
kdDebug(7001) << name() << " emitting dirty " << _url << endl;
emit dirty( _url );
}
void KDirWatch::setDeleted( const TQString & _file ) void KDirWatch::setDeleted( const TQString & _file )
{ {
kdDebug(7001) << name() << " emitting deleted " << _file << endl; kdDebug(7001) << name() << " emitting deleted " << _file << endl;

@ -22,6 +22,8 @@
#include <tqdatetime.h> #include <tqdatetime.h>
#include <tqmap.h> #include <tqmap.h>
#include <kurl.h>
#include <tdelibs_export.h> #include <tdelibs_export.h>
#define kdirwatch KDirWatch::self() #define kdirwatch KDirWatch::self()
@ -96,8 +98,9 @@ class TDEIO_EXPORT KDirWatch : public TQObject
* @param watchFiles if true, the KDirWatch will also watch files - NOT IMPLEMENTED YET * @param watchFiles if true, the KDirWatch will also watch files - NOT IMPLEMENTED YET
* @param recursive if true, all sub directories are also watched - NOT IMPLEMENTED YET * @param recursive if true, all sub directories are also watched - NOT IMPLEMENTED YET
*/ */
void addDir(const TQString& path, void addDir(const TQString& path, bool watchFiles = false, bool recursive = false);
bool watchFiles = false, bool recursive = false);
void addDir(const KURL& url, bool watchFiles = false, bool recursive = false);
/** /**
* Adds a file to be watched. * Adds a file to be watched.
@ -120,6 +123,8 @@ class TDEIO_EXPORT KDirWatch : public TQObject
*/ */
void removeDir(const TQString& path); void removeDir(const TQString& path);
void removeDir(const KURL& path);
/** /**
* Removes a file from the list of watched files. * Removes a file from the list of watched files.
* *
@ -212,6 +217,8 @@ class TDEIO_EXPORT KDirWatch : public TQObject
* @param path the path of the file or directory * @param path the path of the file or directory
*/ */
void setDirty( const TQString &path ); void setDirty( const TQString &path );
void setDirty( const KURL &url );
/** /**
* Emits deleted(). * Emits deleted().
* @param path the path of the file or directory * @param path the path of the file or directory
@ -264,6 +271,8 @@ class TDEIO_EXPORT KDirWatch : public TQObject
*/ */
void dirty (const TQString &path); void dirty (const TQString &path);
void dirty (const KURL &url);
/** /**
* Emitted when a file or directory is created. * Emitted when a file or directory is created.
* @param path the path of the file or directory * @param path the path of the file or directory

@ -53,7 +53,7 @@ public:
TQPtrList<Client> m_clients; TQPtrList<Client> m_clients;
// nonexistent entries of this directory // nonexistent entries of this directory
TQPtrList<Entry> m_entries; TQPtrList<Entry> m_entries;
TQString path; KURL path;
int msecLeft, freq; int msecLeft, freq;
@ -77,15 +77,15 @@ public:
#endif #endif
}; };
typedef TQMap<TQString,Entry> EntryMap; typedef TQMap<KURL,Entry> EntryMap;
KDirWatchPrivate(); KDirWatchPrivate();
~KDirWatchPrivate(); ~KDirWatchPrivate();
void resetList (KDirWatch*,bool); void resetList (KDirWatch*,bool);
void useFreq(Entry* e, int newFreq); void useFreq(Entry* e, int newFreq);
void addEntry(KDirWatch*,const TQString&, Entry*, bool); void addEntry(KDirWatch*,const KURL&, Entry*, bool);
void removeEntry(KDirWatch*,const TQString&, Entry*); void removeEntry(KDirWatch*,const KURL&, Entry*);
bool stopEntryScan(KDirWatch*, Entry*); bool stopEntryScan(KDirWatch*, Entry*);
bool restartEntryScan(KDirWatch*, Entry*, bool ); bool restartEntryScan(KDirWatch*, Entry*, bool );
void stopScan(KDirWatch*); void stopScan(KDirWatch*);
@ -94,9 +94,9 @@ public:
void removeEntries(KDirWatch*); void removeEntries(KDirWatch*);
void statistics(); void statistics();
Entry* entry(const TQString&); Entry* entry(const KURL&);
int scanEntry(Entry* e); int scanEntry(Entry* e);
void emitEvent(Entry* e, int event, const TQString &fileName = TQString::null); void emitEvent(Entry* e, int event, const KURL &fileName = KURL());
// Memory management - delete when last KDirWatch gets deleted // Memory management - delete when last KDirWatch gets deleted
void ref() { m_ref++; } void ref() { m_ref++; }

@ -262,9 +262,10 @@ void KFileItem::readUDSEntry( bool _urlIsDirectory )
// avoid creating these QStrings again and again // avoid creating these QStrings again and again
static const TQString& dot = TDEGlobal::staticQString("."); static const TQString& dot = TDEGlobal::staticQString(".");
if ( _urlIsDirectory && !UDS_URL_seen && !m_strName.isEmpty() && m_strName != dot ) if ( _urlIsDirectory && !UDS_URL_seen && !m_strName.isEmpty() && m_strName != dot ) {
m_url.addPath( m_strName ); m_url.addPath( m_strName );
} }
}
void KFileItem::refresh() void KFileItem::refresh()
{ {

Loading…
Cancel
Save