GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 21, 2014 4:30 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How to browse directory content?
PostPosted: Mon Jun 11, 2012 10:06 pm 
Offline

Joined: Mon Jun 11, 2012 9:33 pm
Posts: 2
I've been reading tutorial from http://developer.gnome.org/gnome-devel-demos/unstable/image-viewer.vala.html.en. I am curently trying to do the task "Have the user select a directory rather than a file, and provide controls to cycle through all of the images in a directory." I am using FileChooserDialog to get the proper folder, but I have no idea how to operate on it.
I found out that there is enumerate_children of object File, which allows me to invent the way of loading the image.
Code:
//(Vala)
dirname = dialog.get_filename ();
File directory = File.new_for_path(dirname);
enumerator = directory.enumerate_children(FileAttribute.STANDARD_NAME, 0);
image.set_from_file (dirname+"/"+enumerator.next_file().get_name());


Although there are warnings:
Code:
warning: unhandled error `GLib.Error'

at each line, this method works fine. Unfortunately enumerator doesn't seem to be the good way of dealing with that problem as it only allows to move in one direction. Those warnings also makes me feel that something is wrong.

I didn't find any other way to browse directory content except of enumerating. Could you point me right direction?

@Edit:
GDir is the solution. I added GTK to each google query so it didn't find it as it's from Glib. (don't know why enumarate has been found).

@2Edit:
In fact GDir is not the solution. It seems that I have to use an array.


Top
 Profile  
 
 Post subject: Re: How to browse directory content?
PostPosted: Wed Jun 13, 2012 7:17 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 776
Location: UK
Hi,

I do not know Vala, but a quick search on the manual page came up with this http://references.valadoc.org/#!api=glib-2.0/GLib.Dir. This is the Vala version of GDir for reading the file names of a directory. Note again that you can only move forward or rewind to the start. This is a limitation due to these calls being based on a much lower level POSIX call. If you want random access to the file names of the directory you will need to read them all into an array and that way you can then move backwards and forwards.

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to browse directory content?
PostPosted: Wed Jun 20, 2012 9:43 pm 
Offline

Joined: Mon Jun 11, 2012 9:33 pm
Posts: 2
That what I've figured out. It looked quite bad for me at first, because array stores information of folder at time I have updated it. Quite unpleasant when I'll add or remove some files externally. Fortunately I've found Monitor which allows me to see when the update is needed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group