Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, September 2002
[PATCH] hidden files: OS indipendent support


Message 1 in thread

Hi, the attached patch adds the isHidden() function for qfile_unix.cpp (I 
think a win version would be very simply, just check
if "attrib & AT_HIDDEN == true".

I patched also QDir to use .isHidden() instead of dealing with chars.
I think there is no longer the need to keep QDir::readDirEntries in the
OS-dependent files.

Are there possibilities to see this Qt 3.1??

Simple test output:

  [gioele@snoopy 16:35:49 ~/tmp/.qt-hidden]
  $ ./hidden
  "/home/gioele/.kde" isHidden: 1 isDir: 1
  abs path: /home/gioele/.kde
  ------------------
  "." isHidden: 1 isDir: 1
  abs path: /home/gioele/tmp/.qt-hidden
  ------------------
  "/home/gioele/.quakeforgerc" isHidden: 1 isDir: 0
  abs path: /home/gioele/.quakeforgerc
  ------------------
  ".." isHidden: 0 isDir: 1
  abs path: /home/gioele/tmp
  ------------------
  "/home/gioele" isHidden: 0 isDir: 1
  abs path: /home/gioele
  ------------------
  ".cip" isHidden: 1 isDir: 1
  abs path: /home/gioele/tmp/.qt-hidden/.cip
  ------------------
  "ciop" isHidden: 0 isDir: 0
  abs path: /home/gioele/tmp/.qt-hidden/ciop
Index: src/tools/qdir_unix.cpp
===================================================================
RCS file: /home/kde/qt-copy/src/tools/qdir_unix.cpp,v
retrieving revision 1.43
diff -u -3 -p -r1.43 qdir_unix.cpp
--- src/tools/qdir_unix.cpp	2002/07/12 21:52:54	1.43
+++ src/tools/qdir_unix.cpp	2002/09/04 16:46:50
@@ -220,9 +220,7 @@ bool QDir::readDirEntries( const QString
 	             (doWritable && !fi.isWritable()) ||
 	             (doExecable && !fi.isExecutable()) )
 	            continue;
-	    if ( !doHidden && fn[0] == '.' &&
-	         fn != QString::fromLatin1(".")
-	         && fn != QString::fromLatin1("..") )
+	    if ( fi.isHidden() )
 	        continue;
 	    fiList->append( new QFileInfo( fi ) );
 	}
Index: src/tools/qfileinfo.h
===================================================================
RCS file: /home/kde/qt-copy/src/tools/qfileinfo.h,v
retrieving revision 1.41
diff -u -3 -p -r1.41 qfileinfo.h
--- src/tools/qfileinfo.h	2002/03/15 19:32:02	1.41
+++ src/tools/qfileinfo.h	2002/09/04 16:46:51
@@ -112,6 +112,7 @@ public:
     uint	groupId()	const;
 
     bool	permission( int permissionSpec ) const;
+    bool	isHidden() const;
 
     uint	size()		const;
 
Index: src/tools/qfileinfo_unix.cpp
===================================================================
RCS file: /home/kde/qt-copy/src/tools/qfileinfo_unix.cpp,v
retrieving revision 1.39
diff -u -3 -p -r1.39 qfileinfo_unix.cpp
--- src/tools/qfileinfo_unix.cpp	2002/03/15 19:32:02	1.39
+++ src/tools/qfileinfo_unix.cpp	2002/09/04 16:46:51
@@ -232,6 +232,23 @@ bool QFileInfo::permission( int permissi
     }
 }
 
+/*!
+  \fn bool QFileInfo::isHidden() const
+
+  Returns TRUE is the file or a dir is hidden; otherwise returns FALSE.
+  On Unix system hiddens files are those with a leading dot in their names.
+
+  \sa isReadable(), isWritable(), isExecutable()
+*/
+
+bool QFileInfo::isHidden() const
+{
+    QString fullName = absFilePath();
+    int delim = fullName.findRev("/");
+
+    return (fullName.mid(delim + 1).left(1) == ".");
+}
+
 void QFileInfo::doStat() const
 {
     QFileInfo *that = ((QFileInfo*)this);	// mutable function