Use glib functions instead of C functions for
wxDir. This works on the iPaq as well. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@22321 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -36,10 +36,13 @@
|
|||||||
#include "wx/dir.h"
|
#include "wx/dir.h"
|
||||||
#include "wx/filefn.h" // for wxMatchWild
|
#include "wx/filefn.h" // for wxMatchWild
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
#include "glib.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -64,13 +67,21 @@ public:
|
|||||||
void SetFileSpec(const wxString& filespec) { m_filespec = filespec; }
|
void SetFileSpec(const wxString& filespec) { m_filespec = filespec; }
|
||||||
void SetFlags(int flags) { m_flags = flags; }
|
void SetFlags(int flags) { m_flags = flags; }
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
void Rewind() { g_dir_rewind(m_dir); }
|
||||||
|
#else
|
||||||
void Rewind() { rewinddir(m_dir); }
|
void Rewind() { rewinddir(m_dir); }
|
||||||
|
#endif
|
||||||
bool Read(wxString *filename);
|
bool Read(wxString *filename);
|
||||||
|
|
||||||
const wxString& GetName() const { return m_dirname; }
|
const wxString& GetName() const { return m_dirname; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
GDir *m_dir;
|
||||||
|
#else
|
||||||
DIR *m_dir;
|
DIR *m_dir;
|
||||||
|
#endif
|
||||||
|
|
||||||
wxString m_dirname;
|
wxString m_dirname;
|
||||||
wxString m_filespec;
|
wxString m_filespec;
|
||||||
@@ -103,23 +114,36 @@ wxDirData::wxDirData(const wxString& dirname)
|
|||||||
m_dirname.Truncate(n + 1);
|
m_dirname.Truncate(n + 1);
|
||||||
|
|
||||||
// do open the dir
|
// do open the dir
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
GError *error = NULL;
|
||||||
|
m_dir = g_dir_open( m_dirname.fn_str(), 0, &error );
|
||||||
|
#else
|
||||||
m_dir = opendir(m_dirname.fn_str());
|
m_dir = opendir(m_dirname.fn_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDirData::~wxDirData()
|
wxDirData::~wxDirData()
|
||||||
{
|
{
|
||||||
if ( m_dir )
|
if ( m_dir )
|
||||||
{
|
{
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
g_dir_close(m_dir);
|
||||||
|
#else
|
||||||
if ( closedir(m_dir) != 0 )
|
if ( closedir(m_dir) != 0 )
|
||||||
{
|
{
|
||||||
wxLogLastError(_T("closedir"));
|
wxLogLastError(_T("closedir"));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDirData::Read(wxString *filename)
|
bool wxDirData::Read(wxString *filename)
|
||||||
{
|
{
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
const char *de;
|
||||||
|
#else
|
||||||
dirent *de = (dirent *)NULL; // just to silence compiler warnings
|
dirent *de = (dirent *)NULL; // just to silence compiler warnings
|
||||||
|
#endif
|
||||||
bool matches = FALSE;
|
bool matches = FALSE;
|
||||||
|
|
||||||
// speed up string concatenation in the loop a bit
|
// speed up string concatenation in the loop a bit
|
||||||
@@ -128,23 +152,37 @@ bool wxDirData::Read(wxString *filename)
|
|||||||
path.reserve(path.length() + 255);
|
path.reserve(path.length() + 255);
|
||||||
|
|
||||||
wxString de_d_name;
|
wxString de_d_name;
|
||||||
|
|
||||||
while ( !matches )
|
while ( !matches )
|
||||||
{
|
{
|
||||||
de = readdir(m_dir);
|
#ifdef __WXGTK20__
|
||||||
|
de = g_dir_read_name( m_dir );
|
||||||
|
|
||||||
if ( !de )
|
if ( !de )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
de_d_name = wxConvLibc.cMB2WC( de );
|
||||||
|
|
||||||
|
// don't return "." and ".." unless asked for
|
||||||
|
if ( de[0] == '.' &&
|
||||||
|
((de[1] == '.' && de[2] == '\0') ||
|
||||||
|
(de[1] == '\0')) )
|
||||||
|
#else
|
||||||
|
de = readdir(m_dir);
|
||||||
|
|
||||||
|
if ( !de )
|
||||||
|
return FALSE;
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
de_d_name = wxConvLibc.cMB2WC( de->d_name );
|
de_d_name = wxConvLibc.cMB2WC( de->d_name );
|
||||||
#else
|
#else
|
||||||
de_d_name = de->d_name;
|
de_d_name = de->d_name;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// don't return "." and ".." unless asked for
|
// don't return "." and ".." unless asked for
|
||||||
if ( de->d_name[0] == '.' &&
|
if ( de->d_name[0] == '.' &&
|
||||||
((de->d_name[1] == '.' && de->d_name[2] == '\0') ||
|
((de->d_name[1] == '.' && de->d_name[2] == '\0') ||
|
||||||
(de->d_name[1] == '\0')) )
|
(de->d_name[1] == '\0')) )
|
||||||
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
if ( !(m_flags & wxDIR_DOTDOT) )
|
if ( !(m_flags & wxDIR_DOTDOT) )
|
||||||
continue;
|
continue;
|
||||||
@@ -168,7 +206,11 @@ bool wxDirData::Read(wxString *filename)
|
|||||||
// finally, check the name
|
// finally, check the name
|
||||||
if ( m_filespec.empty() )
|
if ( m_filespec.empty() )
|
||||||
{
|
{
|
||||||
|
#ifdef __WXGTK20__
|
||||||
|
matches = m_flags & wxDIR_HIDDEN ? TRUE : de[0] != '.';
|
||||||
|
#else
|
||||||
matches = m_flags & wxDIR_HIDDEN ? TRUE : de->d_name[0] != '.';
|
matches = m_flags & wxDIR_HIDDEN ? TRUE : de->d_name[0] != '.';
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user