GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Jul 24, 2014 1:01 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [Solved] How to copy file with C and GTK+2.0?
PostPosted: Mon Jan 14, 2008 1:51 pm 
Offline

Joined: Mon Jan 14, 2008 1:49 pm
Posts: 4
Hi.
I'm doing a little PSP managing utility (along the lines of qpspmanager, for those who know it) using GTK with C.
I'm in a part where I need to copy files from the PC to the PSP (not local, then) and, if possible, show a little progress bar.
Thing is, the only way I can copy the files is using a system call to exec cp. I've tried the copy char by char variant with no success, it works fine for files in the desktop but once you do that to a PSP with files over 1GB it's not *that* productive.
I was wondering if someone here knew a better way to do this, like nautilus does, exactly.

Another doubt I have is how can I see the total or free space (any, or both, will do) in a given dir/drive with a C function?

Thank you very very much!


Last edited by Arlanthir on Wed Feb 27, 2008 12:05 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 7:03 pm 
Offline
GTK+ Guru

Joined: Fri Jan 04, 2008 3:17 pm
Posts: 183
Location: France (92340 Bourg La Reine)
To copy a file with visual feedback in a progress bar, you could perhaps use an idle routine which copies a chunk of it (perhaps 1Kbyte), and then update the progress bar and eventually is called again (by GTK loop) ....

To get the total or free space is probably OS specific.but I suggest using the g_stat wrapper to the stat (POSIX) function

I am not sure that asking for free space on a given drive makes any sense. I don't know Windows, but POSIX systems do not have any drive notion.

Maybe you want the statfs system call or an equivalent to ask about s filesystem.

_________________
Basile Starynkevitch (France)
http://starynkevitch.net/Basile/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 8:15 pm 
Offline

Joined: Mon Jan 14, 2008 1:49 pm
Posts: 4
I tried the copy char by char method but it doesn't seem to work very efficiently. I'd really like to know how nautilus does it =/

Regarding the free space, maybe drive was a bad choice of word.
Partition size is better, I think. I think nautilus shows the free space in the current folder (read: free space in partition where folder is) in the bottom of the screen.

I'd like to point out I'm doing this in Linux (Ubuntu) and have no intention of porting it to Windows.

Again, Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 6:50 am 
Offline
GTK+ Guru

Joined: Fri Jan 04, 2008 3:17 pm
Posts: 183
Location: France (92340 Bourg La Reine)
Arlanthir wrote:
I tried the copy char by char method but it doesn't seem to work very efficiently.

char by char copy is really inefficient (just because of the overhead of every system call). You really should buffer it, and I suggested kilobytes by kilobytes copy. Maybe a 4Kb or 16Kb buffer is better than a 1Kb one but you really should avoid copying one byte per one byte.

Arlanthir wrote:
I think nautilus shows the free space in the current folder (read: free space in partition where folder is) in the bottom of the screen.


You can get the information with the stat(2) and statfs(2) system calls. RTFM, so look at the output of
Code:
man 2 stat
man 2 statfs

_________________
Basile Starynkevitch (France)
http://starynkevitch.net/Basile/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 10:45 am 
Offline

Joined: Mon Jan 14, 2008 1:49 pm
Posts: 4
I get it ;)
Will try, thank you once more!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 12:04 am 
Offline

Joined: Mon Jan 14, 2008 1:49 pm
Posts: 4
Just summing up: All went good from there, everything working as it should now ;)

Thank you very much.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


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