[prev in list] [next in list] [prev in thread] [next in thread]
List: gtk-app-devel
Subject: Re: File Manager...
From: Matt Hillebrand <hill9361 () uidaho ! edu>
Date: 2001-03-27 2:03:13
[Download RAW message or body]
I wrote a file manager type of app. I did use Glade to build the
interface, but Glade won't help you build a ctree. Here is some code I
wrote that scans the disk and builds a CTree relative to the char path[]
parameter.
void build_tree(GtkWidget *main_window, GtkWidget *parent, GtkWidget *sibling, char path[])
{
int n;
GtkWidget *node = NULL;
GtkWidget *window = NULL;
GtkWidget *local_ctree = NULL;
gchar *text[6];
gchar file_path[MAXSTR] = {'\0'};
struct stat status;
struct dirent **namelist;
GdkPixmap *open;
GdkPixmap *closed;
GdkPixmap *file;
GdkBitmap *mask_open;
GdkBitmap *mask_closed;
GdkBitmap *mask_file;
GdkColor transparent = { 0 };
window = lookup_widget(main_window, "main_window");
local_ctree = lookup_widget(main_window, "ctree1");
open = gdk_pixmap_create_from_xpm_d (window->window, &mask_open,
&transparent, dir_open_xpm);
closed = gdk_pixmap_create_from_xpm_d (window->window, &mask_closed,
&transparent, dir_closed_xpm);
file = gdk_pixmap_create_from_xpm_d (window->window, &mask_file,
&transparent, file_xpm);
gtk_clist_freeze(GTK_CLIST(local_ctree));
n = scandir(path, &namelist, 0, alphasort);
if (n < 0)
perror("scandir");
else
while(n--)
{
text[0] = (char *)malloc(strlen(namelist[n]->d_name)+1);
text[1] = (char *)malloc(10);
strcpy(text[0], namelist[n]->d_name);
if (text[0][0] != '.')
{
strcpy(file_path, path);
strcat(file_path, "/");
strcat(file_path, text[0]);
text[2] = (char *)malloc(strlen(file_path)+1);
text[3] = (char *)malloc(2);
strcpy(text[3], "F");
text[4] = (char *)malloc(2);
strcpy(text[4], "F");
text[5] = (char *)malloc(2);
strcpy(text[5], "F");
strcpy(text[2], file_path);
stat(file_path, &status);
// if directory entry is a file
if (!S_ISDIR(status.st_mode))
{
if( ((file_path[strlen(file_path)-1]=='c')
|| (file_path[strlen(file_path)-1]=='h'))
&& (file_path[strlen(file_path)-2]=='.') )
{
strcpy(text[1], "file");
gtk_ctree_insert_node(GTK_CTREE(local_ctree), GTK_CTREE_NODE(parent),
GTK_CTREE_NODE(node), text, 5, file, mask_file, file, mask_file, FALSE, FALSE);
}
}
else // if directory entry is a directory
{
char *new_path = (char *)malloc(strlen(path)+strlen(text[0])+3);
strcpy(text[1], "dir");
strcpy(new_path, path);
strcat(new_path, "/");
strcat(new_path, text[0]);
GTK_CTREE_NODE(node) = gtk_ctree_insert_node(GTK_CTREE(local_ctree), GTK_CTREE_NODE(parent),
GTK_CTREE_NODE(node), text, 5, closed,
mask_closed, open, mask_open, FALSE, FALSE);
build_tree(main_window, node, sibling, new_path);
free(new_path);
}
free(text[2]);
free(text[3]);
free(text[4]);
free(text[5]);
}
free(text[0]);
free(text[1]);
}
gtk_clist_thaw(GTK_CLIST(local_ctree));
}
Matthew P. Hillebrand
On Mon, 26 Mar 2001, Tony Preston wrote:
> I have to write something that will look like a file manager. The one half
> will be the linux disk, the other half will be to a file that is essentially
> a simulation of a disk for an emulator I work on. The idea is to transfer
> files to/from the simulated disk to the real linux disk.
>
> 1) Does anyone know of code for a file manager type program (I could probably
> adapt)?
>
> 2) Any suggestions on an easy way to do this? The functions will be simple,
> copy, move, delete... Alot can be done with the file requestor function.
>
> Would something like Glade be the right way to design the interface? Does
> someone have a similar interface I might adapt?
> --
> -- Tony Preston *Team Amiga* Linux Developer since 1993
> -- SR Principal Engineer/Scientist
> -- Atlantic Science & Technology Inc.
> -- The Amiga Zone BBS 609-654-7659, Citadel 68K
>
>
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic