View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002214 | Scribus | Internal | public | 2005-07-09 23:03 | 2005-08-25 20:08 |
Reporter | jghali | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Platform | Windows | OS | Windows | OS Version | 2000 SP4 |
Product Version | 1.3.0cvs | ||||
Fixed in Version | 1.3.0cvs | ||||
Summary | 0002214: Platform independent implementation of PicStatus | ||||
Description | The proposed patch remove the need of piped (popen, pclose...) by implementing recursive file search using QDir. For now, on win32, the SearchPic() function use "home" directory ( ex: C:\Documents and Settings\user_name ) for searching pictures. Use of MyDocuments folder would be certainly better, but in my opinion, on Windows, there's no real reason to use a particular directory for performing search as users tend to use quite often files completely outside "home" directory. So on Windows, just showing the file search dialog is maybe a better option ... | ||||
Tags | No tags attached. | ||||
Patch | |||||
2005-07-09 23:03
|
picstatus_platf_indep_13x.diff (2,492 bytes)
Index: picstatus.cpp =================================================================== RCS file: /cvs/Scribus/scribus/picstatus.cpp,v retrieving revision 1.12.2.8 diff -u -r1.12.2.8 picstatus.cpp --- picstatus.cpp 14 Jun 2005 12:35:53 -0000 1.12.2.8 +++ picstatus.cpp 10 Jul 2005 00:35:18 -0000 @@ -216,6 +216,7 @@ \param None \retval None */ + void PicStatus::SearchPic() { uint ZNr = QString(sender()->name()).toUInt(); @@ -227,13 +228,8 @@ qApp->setOverrideCursor(QCursor(waitCursor), true); qApp->processEvents(); QString home = QDir::homeDirPath(); - FILE *fp = popen("find "+home+" -name " + BildNam, "r"); qApp->setOverrideCursor(QCursor(arrowCursor), true); - if (fp == NULL) - return; - QTextStream ts(fp, IO_ReadOnly); - QString tmp = ts.read(); - Pfade = QStringList::split("\n", tmp); + findFile( home, BildNam, Pfade); if (Pfade.count() > 1) { PicSearch *dia = new PicSearch(this, BildNam, Pfade); @@ -298,7 +294,42 @@ view->DrawNew(); } } - pclose(fp); +} + +void PicStatus::findFile( QString dirName, QString fileName, QStringList& fileList, bool init) +{ + if( init ) + fileList.clear(); + + // Search file in specified dir; + QDir df( dirName, fileName, QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks ); + if( df.exists() ) + { + if( df.count() > 0 ) + { + for( unsigned int i = 0; i < df.count(); i++ ) + { + fileList.push_back( df[i] ); + } + } + } + + // Search file in sub-directories + QDir dd( dirName, "*", QDir::Name, QDir::Dirs | QDir::Readable | QDir::NoSymLinks ); + if( dd.exists() ) + { + if( dd.count() > 0 ) + { + for( unsigned int j = 0; j < dd.count(); j++ ) + { + QString subdir = dd[j]; + if( subdir == "." || subdir == "..") + continue; + subdir = dirName + "/" + subdir; + findFile( subdir, fileName, fileList, false); + } + } + } } /*! Index: picstatus.h =================================================================== RCS file: /cvs/Scribus/scribus/picstatus.h,v retrieving revision 1.2.2.3 diff -u -r1.2.2.3 picstatus.h --- picstatus.h 4 May 2005 23:27:10 -0000 1.2.2.3 +++ picstatus.h 9 Jul 2005 23:52:07 -0000 @@ -40,6 +40,8 @@ QVBoxLayout* PicStatusLayout; QHBoxLayout* Layout2; + void findFile( QString dirName, QString fileName, QStringList& fileList, bool init = true); + signals: void selectPage(int); void selectMasterPage(QString); |
2005-07-09 23:09
|
picstatus_platf_indep_13x_v2.diff (2,442 bytes)
Index: picstatus.cpp =================================================================== RCS file: /cvs/Scribus/scribus/picstatus.cpp,v retrieving revision 1.12.2.8 diff -u -r1.12.2.8 picstatus.cpp --- picstatus.cpp 14 Jun 2005 12:35:53 -0000 1.12.2.8 +++ picstatus.cpp 10 Jul 2005 01:05:31 -0000 @@ -216,6 +216,7 @@ \param None \retval None */ + void PicStatus::SearchPic() { uint ZNr = QString(sender()->name()).toUInt(); @@ -227,13 +228,8 @@ qApp->setOverrideCursor(QCursor(waitCursor), true); qApp->processEvents(); QString home = QDir::homeDirPath(); - FILE *fp = popen("find "+home+" -name " + BildNam, "r"); qApp->setOverrideCursor(QCursor(arrowCursor), true); - if (fp == NULL) - return; - QTextStream ts(fp, IO_ReadOnly); - QString tmp = ts.read(); - Pfade = QStringList::split("\n", tmp); + findFile( home, BildNam, Pfade); if (Pfade.count() > 1) { PicSearch *dia = new PicSearch(this, BildNam, Pfade); @@ -298,7 +294,38 @@ view->DrawNew(); } } - pclose(fp); +} + +void PicStatus::findFile( QString dirName, QString fileName, QStringList& fileList, bool init) +{ + if( init ) + fileList.clear(); + + // Search file in specified dir; + QDir df( dirName, fileName, QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks ); + if( !df.exists() ) return; + + if( df.count() > 0 ) + { + for( unsigned int i = 0; i < df.count(); i++ ) + { + fileList.push_back( df[i] ); + } + } + + // Search file in sub-directories + QDir dd( dirName, "*", QDir::Name, QDir::Dirs | QDir::Readable | QDir::NoSymLinks ); + if( dd.count() > 0 ) + { + for( unsigned int j = 0; j < dd.count(); j++ ) + { + QString subdir = dd[j]; + if( subdir == "." || subdir == "..") + continue; + subdir = dirName + "/" + subdir; + findFile( subdir, fileName, fileList, false); + } + } } /*! Index: picstatus.h =================================================================== RCS file: /cvs/Scribus/scribus/picstatus.h,v retrieving revision 1.2.2.3 diff -u -r1.2.2.3 picstatus.h --- picstatus.h 4 May 2005 23:27:10 -0000 1.2.2.3 +++ picstatus.h 9 Jul 2005 23:52:07 -0000 @@ -40,6 +40,8 @@ QVBoxLayout* PicStatusLayout; QHBoxLayout* Layout2; + void findFile( QString dirName, QString fileName, QStringList& fileList, bool init = true); + signals: void selectPage(int); void selectMasterPage(QString); |
|
Use picstatus_platf_indep_13x_v2.diff please... |
|
That's a recursive implementation. Any idea what the stack limit is or if there's any chance we'll hit it (eg searching eight-bajillion-deep dir trees in the user's Application Data, or dotfiles on UNIX) ? I might put one together that isn't recursive and is resumable, so it can be done without entirely blocking events. |
|
Yep, it's a recursive implementation and there is a chance we hit stack limit although I never did. So if you have a non recursive one, it would be a better solution. Anyway I'd like to see it, 'cause I don't have any idea how you can do it the non recursive way... |
|
Well, it's a tree search. As far as I know, the three traditional approaches to searching a tree are: - recurse down the tree depth first - non-recursive depth-first search - non-recursive breadth first search That's pretty much in order of difficulty too, I think. (as for breadth first recursive searching, even thinking about it hurts my poor little brain). I actually prefer the recursive approach, but in this case there are two issues: - C somewhat sucks at recursion, mostly due to the stack limit - it's hard to make a recursive search work in small, resumable chunks. I'd prefer to avoid a hack like using a QTimer to call processEvents(...) while doing the search. With this approach, that'd be necessary just to keep the GUI updating. Instead, I'd prefer bundling the search into a class that can do the search under the control of the Qt event loop. That way, it's possible to provide a progress dialog and make sure the GUI redraws, so it doesn't look like Scribus has gone into an infinite loop or otherwise become unusable. I'm going to have a bash at this one. I'll let you know how I go. By the way, I don't suppose there's any chance of catching you on IRC at some point? Peter Linnell and Craig Bradney have both asked if you use IRC recently. |
|
>> Peter Linnell and Craig Bradney have both asked if you use IRC recently. Almost never. I should... |
|
An alternate implementation is now in CVS. PicStatus still needs a bunch of work to be nice, but now doesn't block the GUI and is portable. |
Date Modified | Username | Field | Change |
---|---|---|---|
2005-07-09 23:03 | jghali | New Issue | |
2005-07-09 23:03 | jghali | File Added: picstatus_platf_indep_13x.diff | |
2005-07-09 23:09 | jghali | File Added: picstatus_platf_indep_13x_v2.diff | |
2005-07-09 23:10 | jghali | Note Added: 0005473 | |
2005-07-10 02:50 |
|
Relationship added | related to 0002046 |
2005-07-11 11:57 |
|
Status | new => assigned |
2005-07-11 11:57 |
|
Assigned To | => ringerc |
2005-07-11 12:39 |
|
Note Added: 0005515 | |
2005-07-11 12:48 | jghali | Note Added: 0005516 | |
2005-07-11 13:06 |
|
Note Added: 0005517 | |
2005-07-11 13:09 | jghali | Note Added: 0005518 | |
2005-07-13 13:10 |
|
Status | assigned => resolved |
2005-07-13 13:10 |
|
Resolution | open => fixed |
2005-07-13 13:10 |
|
Note Added: 0005558 | |
2005-07-13 13:12 |
|
Fixed in Version | => 1.3.0cvs |
2005-07-15 07:38 |
|
Relationship added | related to 0000015 |
2005-07-15 07:41 |
|
Relationship replaced | child of 0000015 |
2005-08-25 20:08 | jghali | Status | resolved => closed |