Keeping information about the home directory inside the Desktop class
This commit is contained in:
parent
a6031b3804
commit
af31e5686d
@ -1,5 +1,5 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/* Copyright (c) 2008 Pierre Pronchery <khorben@defora.org> */
|
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||||
/* This file is part of DeforaOS Desktop Browser */
|
/* This file is part of DeforaOS Desktop Browser */
|
||||||
/* This program is free software: you can redistribute it and/or modify
|
/* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -47,6 +47,7 @@ struct _Desktop
|
|||||||
DesktopIcon ** icon;
|
DesktopIcon ** icon;
|
||||||
size_t icon_cnt;
|
size_t icon_cnt;
|
||||||
Mime * mime;
|
Mime * mime;
|
||||||
|
char const * home;
|
||||||
char * path;
|
char * path;
|
||||||
size_t path_cnt;
|
size_t path_cnt;
|
||||||
DIR * refresh_dir;
|
DIR * refresh_dir;
|
||||||
@ -608,8 +609,8 @@ void desktopicon_show(DesktopIcon * desktopicon)
|
|||||||
/* functions */
|
/* functions */
|
||||||
/* desktop_new */
|
/* desktop_new */
|
||||||
static Desktop * _new_error(Desktop * desktop, char const * message);
|
static Desktop * _new_error(Desktop * desktop, char const * message);
|
||||||
static int _new_create_desktop(Desktop * desktop, char const * home);
|
static int _new_create_desktop(Desktop * desktop);
|
||||||
static void _new_add_home(Desktop * desktop, char const * home);
|
static void _new_add_home(Desktop * desktop);
|
||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
/* FIXME implement desktop resizing callback */
|
/* FIXME implement desktop resizing callback */
|
||||||
@ -617,7 +618,6 @@ static void _new_add_home(Desktop * desktop, char const * home);
|
|||||||
Desktop * desktop_new(void)
|
Desktop * desktop_new(void)
|
||||||
{
|
{
|
||||||
Desktop * desktop;
|
Desktop * desktop;
|
||||||
char * home;
|
|
||||||
char * file[] = { "gnome-fs-regular",
|
char * file[] = { "gnome-fs-regular",
|
||||||
#if GTK_CHECK_VERSION(2, 6, 0)
|
#if GTK_CHECK_VERSION(2, 6, 0)
|
||||||
GTK_STOCK_FILE,
|
GTK_STOCK_FILE,
|
||||||
@ -651,11 +651,12 @@ Desktop * desktop_new(void)
|
|||||||
for(p = folder; *p != NULL && desktop->folder == NULL; p++)
|
for(p = folder; *p != NULL && desktop->folder == NULL; p++)
|
||||||
desktop->folder = gtk_icon_theme_load_icon(desktop->theme,
|
desktop->folder = gtk_icon_theme_load_icon(desktop->theme,
|
||||||
*p, DESKTOPICON_ICON_SIZE, 0, NULL);
|
*p, DESKTOPICON_ICON_SIZE, 0, NULL);
|
||||||
if((home = getenv("HOME")) == NULL)
|
if((desktop->home = getenv("HOME")) == NULL
|
||||||
return _new_error(desktop, "HOME");
|
&& (desktop->home = g_get_home_dir()) == NULL)
|
||||||
if(_new_create_desktop(desktop, home) != 0)
|
desktop->home = "/";
|
||||||
|
if(_new_create_desktop(desktop) != 0)
|
||||||
return _new_error(desktop, "Creating desktop");
|
return _new_error(desktop, "Creating desktop");
|
||||||
_new_add_home(desktop, home);
|
_new_add_home(desktop);
|
||||||
desktop_refresh(desktop);
|
desktop_refresh(desktop);
|
||||||
return desktop;
|
return desktop;
|
||||||
}
|
}
|
||||||
@ -667,14 +668,15 @@ static Desktop * _new_error(Desktop * desktop, char const * message)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _new_create_desktop(Desktop * desktop, char const * home)
|
static int _new_create_desktop(Desktop * desktop)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
desktop->path_cnt = strlen(home) + strlen("/" DESKTOP) + 1;
|
desktop->path_cnt = strlen(desktop->home) + strlen("/" DESKTOP) + 1;
|
||||||
if((desktop->path = malloc(desktop->path_cnt)) == NULL)
|
if((desktop->path = malloc(desktop->path_cnt)) == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
sprintf(desktop->path, "%s%s", home, "/" DESKTOP);
|
snprintf(desktop->path, desktop->path_cnt, "%s%s", desktop->home,
|
||||||
|
"/" DESKTOP);
|
||||||
if(lstat(desktop->path, &st) == 0)
|
if(lstat(desktop->path, &st) == 0)
|
||||||
{
|
{
|
||||||
if(!S_ISDIR(st.st_mode))
|
if(!S_ISDIR(st.st_mode))
|
||||||
@ -688,12 +690,13 @@ static int _new_create_desktop(Desktop * desktop, char const * home)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _new_add_home(Desktop * desktop, char const * home)
|
static void _new_add_home(Desktop * desktop)
|
||||||
{
|
{
|
||||||
DesktopIcon * desktopicon;
|
DesktopIcon * desktopicon;
|
||||||
GdkPixbuf * icon;
|
GdkPixbuf * icon;
|
||||||
|
|
||||||
if((desktopicon = desktopicon_new(desktop, "Home", home)) == NULL)
|
if((desktopicon = desktopicon_new(desktop, "Home", desktop->home))
|
||||||
|
== NULL)
|
||||||
return;
|
return;
|
||||||
desktop_icon_add(desktop, desktopicon);
|
desktop_icon_add(desktop, desktopicon);
|
||||||
icon = gtk_icon_theme_load_icon(desktop->theme, "gnome-home",
|
icon = gtk_icon_theme_load_icon(desktop->theme, "gnome-home",
|
||||||
|
Loading…
Reference in New Issue
Block a user