gnome_vfs_make_uri_from_shell_arg problem/question



Hi all.

I'm just starting back into the C realm (after 15 years), and my first
project is a Gnome wallpaper changer.

What I'm trying to accomplish is recursively getting a list of all the
files in a directory.  My problem is (or seems to be) that
gnome_vfs_make_uri_from_shell_arg isn't returning the proper URI
when it gets more than one directory down.  Here's my function (oh
gawd, word-wrapping hell!):

void getFilesByMimetype(GnomeVFSDirectoryHandle *directoryhandle, gchar *mimetype, int recursive) {
  const gchar		*mime_type;
  GnomeVFSFileInfo *fileinfo=NULL;
  gchar			*nextdir;

  // Allocate and initialize a new file information struct
  fileinfo = gnome_vfs_file_info_new();
	
  // Read files and directories until we reach the end
  while ((GNOME_VFS_OK == gnome_vfs_directory_read_next(directoryhandle, fileinfo))) {
    // Get mime type...
    mime_type = gnome_vfs_file_info_get_mime_type(fileinfo);
    // ...if it's of type "mimetype", do something with it.
    if (strstr(mime_type, mimetype) != NULL) {
      printf("Adding file: %s\n", fileinfo->name);
    } else {
      printf("Not Adding:  %s\n", fileinfo->name);
    }
		
    // If it's a directory, we'll want to recurse in it.
    if (fileinfo->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) {
      switch (fileinfo->type) {
        case GNOME_VFS_FILE_TYPE_DIRECTORY:
	  if (strcmp(fileinfo->name,".")!=0 && strcmp(fileinfo->name,"..")!=0) {
	  printf("Recursive: %s\n", fileinfo->name);
	  // Returns a full URI given a relative path
	  nextdir = gnome_vfs_make_uri_from_shell_arg(fileinfo->name);
	  printf("URI: %s\n", nextdir);
						
	  getFilesByMimetype(getDirectoryHandle(nextdir), "image", 1);
	}
	break;
      }
    }
  }
  g_free(fileinfo);
  return;
}

When run in the current directory, here is the output (I stuck some jpg's in
the source directory for testing :-):
Dir: file:///home/todd/Development/Nifty_Wallpaper
Not Adding:  .
Not Adding:  ..
Not Adding:  po
Recursive: po
URI: file:///home/todd/Development/Nifty_Wallpaper/po
Not Adding:  .
Not Adding:  ..
Not Adding:  Makefile
Not Adding:  POTFILES.in
Not Adding:  Makefile.in
Adding file: pic0036.jpg
Not Adding:  ChangeLog
Not Adding:  Makefile.in.in
Not Adding:  POTFILES
Not Adding:  src
Recursive: src
URI: file:///home/todd/Development/Nifty_Wallpaper/src
Not Adding:  .
Not Adding:  ..
Not Adding:  interface.c
Not Adding:  interface.h
Not Adding:  interface.o
Not Adding:  Makefile
Not Adding:  .deps
Recursive: .deps
URI: file:///home/todd/Development/Nifty_Wallpaper/.deps

At this point, I get the standard Gnome error dialog: 
The Application "nifty_wallpaper" has quit unexpectedly.

Now, the URI for the .deps directory is not correct!  The .deps
directory is in the src directory, so the correct URI should be:
file:///home/todd/Development/Nifty_Wallpaper/src/.deps
And, hence, my recursive call to getFilesByMimetype() is causing
the app to crash.

It appears that gnome_vfs_make_uri_from_shell_arg is not returning
what it should, or that I don't know/understand how to use it
properly (which is the more likely case.  :-)

Any suggestions/ideas would be appreciative.

Thanks all!



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]