2002-11-01 16:09:43 +00:00
# include <config.h>
# include <string.h>
# include <libwindow-settings/gnome-wm-manager.h>
# include "gnome-theme-installer.h"
2005-02-08 22:42:10 +00:00
# include "gnome-theme-details.h"
2002-11-01 16:09:43 +00:00
# include <gconf/gconf-client.h>
# include <glade/glade.h>
# include <libgnomevfs/gnome-vfs-async-ops.h>
# include <libgnomevfs/gnome-vfs-ops.h>
# include <libgnomevfs/gnome-vfs-utils.h>
2006-04-25 21:30:45 +00:00
# include <glib.h>
2002-11-01 16:09:43 +00:00
# include "gnome-theme-info.h"
# include "capplet-util.h"
# include "activate-settings-daemon.h"
# include "gconf-property-editor.h"
# include "file-transfer-dialog.h"
# include "gnome-theme-installer.h"
2006-06-13 20:51:44 +00:00
# include "gnome-theme-manager.h"
2002-11-01 16:09:43 +00:00
2005-02-01 22:33:47 +00:00
enum {
THEME_INVALID ,
THEME_ICON ,
THEME_GNOME ,
THEME_GTK ,
THEME_ENGINE ,
THEME_METACITY
} ;
enum {
TARGZ ,
TARBZ
} ;
typedef struct {
gint theme_type ;
gint filetype ;
gchar * filename ;
gchar * target_dir ;
gchar * theme_tmp_dir ;
gchar * target_tmp_dir ;
gchar * user_message ;
} theme_properties ;
static void
cleanup_tmp_dir ( theme_properties * theme_props )
{
GList * list ;
if ( gnome_vfs_remove_directory ( theme_props - > target_tmp_dir ) = = GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY ) {
list = g_list_prepend ( NULL , gnome_vfs_uri_new ( theme_props - > target_tmp_dir ) ) ;
gnome_vfs_xfer_delete_list ( list , GNOME_VFS_XFER_RECURSIVE ,
GNOME_VFS_XFER_ERROR_MODE_ABORT , NULL , NULL ) ;
gnome_vfs_uri_list_free ( list ) ;
}
}
static int
file_theme_type ( gchar * dir )
{
gchar * file_contents ;
gchar * filename = NULL ;
gint file_size ;
GPatternSpec * pattern ;
char * uri ;
GnomeVFSURI * src_uri ;
filename = g_strdup_printf ( " %s/index.theme " , dir ) ;
src_uri = gnome_vfs_uri_new ( filename ) ;
if ( gnome_vfs_uri_exists ( src_uri ) ) {
uri = gnome_vfs_get_uri_from_local_path ( filename ) ;
gnome_vfs_read_entire_file ( uri , & file_size , & file_contents ) ;
pattern = g_pattern_spec_new ( " *[Icon Theme]* " ) ;
if ( g_pattern_match_string ( pattern , file_contents ) ) {
2005-02-08 22:42:10 +00:00
g_free ( filename ) ;
gnome_vfs_uri_unref ( src_uri ) ;
2005-02-01 22:33:47 +00:00
return THEME_ICON ;
}
pattern = g_pattern_spec_new ( " *[X-GNOME-Metatheme]* " ) ;
if ( g_pattern_match_string ( pattern , file_contents ) ) {
2005-02-08 22:42:10 +00:00
g_free ( filename ) ;
gnome_vfs_uri_unref ( src_uri ) ;
2005-02-01 22:33:47 +00:00
return THEME_GNOME ;
}
}
2005-02-08 22:42:10 +00:00
g_free ( filename ) ;
gnome_vfs_uri_unref ( src_uri ) ;
2005-02-01 22:33:47 +00:00
filename = g_strdup_printf ( " %s/gtk-2.0/gtkrc " , dir ) ;
src_uri = gnome_vfs_uri_new ( filename ) ;
2005-02-08 22:42:10 +00:00
g_free ( filename ) ;
2005-02-01 22:33:47 +00:00
if ( gnome_vfs_uri_exists ( src_uri ) ) {
2005-02-08 22:42:10 +00:00
gnome_vfs_uri_unref ( src_uri ) ;
2005-02-01 22:33:47 +00:00
return THEME_GTK ;
}
filename = g_strdup_printf ( " %s/metacity-1/metacity-theme-1.xml " , dir ) ;
src_uri = gnome_vfs_uri_new ( filename ) ;
2005-02-08 22:42:10 +00:00
g_free ( filename ) ;
2005-02-01 22:33:47 +00:00
if ( gnome_vfs_uri_exists ( src_uri ) ) {
2005-02-08 22:42:10 +00:00
gnome_vfs_uri_unref ( src_uri ) ;
2005-02-01 22:33:47 +00:00
return THEME_METACITY ;
}
filename = g_strdup_printf ( " %s/configure.in " , dir ) ;
src_uri = gnome_vfs_uri_new ( filename ) ;
2005-02-08 22:42:10 +00:00
g_free ( filename ) ;
2005-02-01 22:33:47 +00:00
if ( gnome_vfs_uri_exists ( src_uri ) ) {
2005-02-08 22:42:10 +00:00
gnome_vfs_uri_unref ( src_uri ) ;
2005-02-01 22:33:47 +00:00
return THEME_ENGINE ;
}
return THEME_INVALID ;
}
2002-11-01 16:09:43 +00:00
static void
transfer_cancel_cb ( GtkWidget * dlg , gchar * path )
{
gnome_vfs_unlink ( path ) ;
g_free ( path ) ;
gtk_widget_destroy ( dlg ) ;
}
/* this works around problems when doing fork/exec in a threaded app
* with some locks being held / waited on in different threads .
*
* we do the idle callback so that the async xfer has finished and
* cleaned up its vfs job . otherwise it seems the slave thread gets
* woken up and it removes itself from the job queue before it is
* supposed to . very strange .
*
* see bugzilla . gnome . org # 86141 for details
*/
static gboolean
transfer_done_targz_idle_cb ( gpointer data )
{
int status ;
2006-04-10 17:56:59 +00:00
gchar * command , * filename , * gzip , * tar ;
2005-02-01 22:33:47 +00:00
theme_properties * theme_props = data ;
2006-04-10 17:56:59 +00:00
if ( ! ( gzip = g_find_program_in_path ( " gzip " ) ) ) {
return FALSE ;
}
if ( ! ( tar = g_find_program_in_path ( " tar " ) ) ) {
g_free ( gzip ) ;
return FALSE ;
}
2002-11-01 16:09:43 +00:00
/* this should be something more clever and nonblocking */
2005-02-01 22:33:47 +00:00
filename = g_shell_quote ( theme_props - > filename ) ;
2006-04-10 17:56:59 +00:00
command = g_strdup_printf ( " sh -c 'cd \" %s \" ; %s -d -c < \" %s \" | %s xf - ' " ,
theme_props - > target_tmp_dir , gzip , filename , tar ) ;
2005-02-01 22:33:47 +00:00
g_free ( filename ) ;
if ( g_spawn_command_line_sync ( command , NULL , NULL , & status , NULL ) & & status = = 0 ) {
g_free ( command ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return TRUE ;
} else {
g_free ( command ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return FALSE ;
}
2002-11-01 16:09:43 +00:00
}
/* this works around problems when doing fork/exec in a threaded app
* with some locks being held / waited on in different threads .
*
* we do the idle callback so that the async xfer has finished and
* cleaned up its vfs job . otherwise it seems the slave thread gets
* woken up and it removes itself from the job queue before it is
* supposed to . very strange .
*
* see bugzilla . gnome . org # 86141 for details
*/
static gboolean
transfer_done_tarbz2_idle_cb ( gpointer data )
{
int status ;
2006-04-10 17:56:59 +00:00
gchar * command , * filename , * bzip2 , * tar ;
2005-02-01 22:33:47 +00:00
theme_properties * theme_props = data ;
2006-04-10 17:56:59 +00:00
if ( ! ( bzip2 = g_find_program_in_path ( " bzip2 " ) ) ) {
return FALSE ;
}
if ( ! ( tar = g_find_program_in_path ( " tar " ) ) ) {
g_free ( bzip2 ) ;
return FALSE ;
}
2005-02-01 22:33:47 +00:00
filename = g_shell_quote ( theme_props - > filename ) ;
2002-11-01 16:09:43 +00:00
/* this should be something more clever and nonblocking */
2006-04-10 17:56:59 +00:00
command = g_strdup_printf ( " sh -c 'cd \" %s \" ; %s -d -c < \" %s \" | %s xf - ' " ,
theme_props - > target_tmp_dir , bzip2 , filename , tar ) ;
2005-02-01 22:33:47 +00:00
g_free ( filename ) ;
if ( g_spawn_command_line_sync ( command , NULL , NULL , & status , NULL ) & & status = = 0 ) {
2006-04-10 17:56:59 +00:00
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
g_free ( command ) ;
return TRUE ;
} else {
2006-04-10 17:56:59 +00:00
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
g_free ( command ) ;
return FALSE ;
}
2002-11-01 16:09:43 +00:00
}
static void
transfer_done_cb ( GtkWidget * dlg , gchar * path )
{
2006-06-13 20:51:44 +00:00
GtkWidget * dialog , * apply_button ;
2002-11-01 16:09:43 +00:00
int len = strlen ( path ) ;
2006-04-10 17:56:59 +00:00
gchar * command , * * dir , * first_line , * filename , * gzip , * bzip2 , * tar ;
2005-02-01 22:33:47 +00:00
int status , theme_type ;
theme_properties * theme_props ;
GnomeVFSURI * theme_source_dir , * theme_dest_dir ;
2006-06-13 20:51:44 +00:00
2004-10-28 18:20:17 +00:00
gtk_widget_destroy ( dlg ) ;
2005-02-01 22:33:47 +00:00
theme_props = g_new ( theme_properties , 1 ) ;
theme_props - > target_tmp_dir = g_strdup_printf ( " %s/.themes/.theme-%u " ,
g_get_home_dir ( ) ,
g_random_int ( ) ) ;
2006-04-10 17:56:59 +00:00
gzip = g_find_program_in_path ( " gzip " ) ;
bzip2 = g_find_program_in_path ( " bzip2 " ) ;
tar = g_find_program_in_path ( " tar " ) ;
if ( tar & & gzip & & path & & len > 7 & & ( ( ! strcmp ( path + len - 7 , " .tar.gz " ) ) | | ( ! strcmp ( path + len - 4 , " .tgz " ) ) ) ) {
filename = g_shell_quote ( path ) ;
2006-07-14 16:10:41 +00:00
command = g_strdup_printf ( " sh -c '%s -d -c < \" %s \" | %s ft - | head -n 1' " ,
2006-04-10 17:56:59 +00:00
gzip , filename , tar ) ;
theme_props - > filetype = TARGZ ;
g_free ( filename ) ;
} else if ( tar & & bzip2 & & path & & len > 8 & & ! strcmp ( path + len - 8 , " .tar.bz2 " ) ) {
filename = g_shell_quote ( path ) ;
2006-07-14 16:10:41 +00:00
command = g_strdup_printf ( " sh -c '%s -d -c < \" %s \" | %s ft - | head -n 1' " ,
2006-04-10 17:56:59 +00:00
bzip2 , filename , tar ) ;
2005-02-01 22:33:47 +00:00
theme_props - > filetype = TARBZ ;
g_free ( filename ) ;
} else {
2004-10-28 18:20:17 +00:00
dialog = gtk_message_dialog_new ( NULL ,
2005-02-01 22:33:47 +00:00
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " This theme is not in a supported format. " ) ) ;
2004-10-28 18:20:17 +00:00
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
2005-02-01 22:33:47 +00:00
gtk_widget_destroy ( dialog ) ;
gnome_vfs_unlink ( path ) ;
2005-02-08 22:42:10 +00:00
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
2004-10-28 18:20:17 +00:00
}
2005-02-01 22:33:47 +00:00
if ( ( gnome_vfs_make_directory ( theme_props - > target_tmp_dir , 0700 ) ) ! = GNOME_VFS_OK ) {
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
2005-02-07 21:39:30 +00:00
_ ( " Failed to create temporary directory " ) ) ;
2005-02-01 22:33:47 +00:00
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
2005-02-08 22:42:10 +00:00
g_free ( command ) ;
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
}
/* Uncompress the file in the temp directory */
theme_props - > filename = g_strdup ( path ) ;
if ( theme_props - > filetype = = TARBZ ) {
2006-04-10 17:56:59 +00:00
if ( ! bzip2 ) {
2005-02-01 22:33:47 +00:00
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
2005-02-07 21:39:30 +00:00
_ ( " Can not install theme. \n The bzip2 utility is not installed. " ) ) ;
2005-02-01 22:33:47 +00:00
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
gnome_vfs_unlink ( path ) ;
2005-02-08 22:42:10 +00:00
g_free ( command ) ;
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props - > filename ) ;
g_free ( theme_props ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
}
if ( ! transfer_done_tarbz2_idle_cb ( theme_props ) ) {
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " Installation Failed " ) ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
2005-02-08 22:42:10 +00:00
cleanup_tmp_dir ( theme_props ) ;
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props - > filename ) ;
g_free ( theme_props ) ;
g_free ( command ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
}
}
if ( theme_props - > filetype = = TARGZ ) {
2006-04-10 17:56:59 +00:00
if ( ! gzip ) {
2005-02-01 22:33:47 +00:00
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
2005-02-07 21:39:30 +00:00
_ ( " Can not install themes. \n The gzip utility is not installed. " ) ) ;
2005-02-01 22:33:47 +00:00
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
2005-02-08 22:42:10 +00:00
gtk_widget_destroy ( dialog ) ;
2005-02-01 22:33:47 +00:00
gnome_vfs_unlink ( path ) ;
2005-02-08 22:42:10 +00:00
g_free ( command ) ;
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props - > filename ) ;
g_free ( theme_props ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
}
if ( ! transfer_done_targz_idle_cb ( theme_props ) ) {
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " Installation Failed " ) ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
2005-02-08 22:42:10 +00:00
gtk_widget_destroy ( dialog ) ;
cleanup_tmp_dir ( theme_props ) ;
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props - > filename ) ;
g_free ( theme_props ) ;
g_free ( command ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
}
}
/* What type of theme it is ? */
if ( g_spawn_command_line_sync ( command , & first_line , NULL , & status , NULL ) & & status = = 0 ) {
dir = g_strsplit ( g_strchomp ( first_line ) , " / " , 0 ) ;
2005-02-08 22:42:10 +00:00
theme_props - > theme_tmp_dir = g_build_filename ( theme_props - > target_tmp_dir , dir [ 0 ] , NULL ) ;
2005-02-01 22:33:47 +00:00
theme_type = file_theme_type ( theme_props - > theme_tmp_dir ) ;
gnome_vfs_unlink ( theme_props - > filename ) ;
if ( theme_type = = THEME_ICON ) {
theme_props - > target_dir = g_strdup_printf ( " %s/.icons/%s " , g_get_home_dir ( ) , dir [ 0 ] ) ;
} else if ( theme_type = = THEME_GNOME ) {
theme_props - > target_dir = g_strdup_printf ( " %s/.themes/%s " , g_get_home_dir ( ) , dir [ 0 ] ) ;
2006-06-13 20:51:44 +00:00
theme_props - > user_message = g_strdup_printf ( _ ( " GNOME Theme %s correctly installed " ) , dir [ 0 ] ) ;
2005-02-01 22:33:47 +00:00
} else if ( theme_type = = THEME_METACITY ) {
theme_props - > target_dir = g_strdup_printf ( " %s/.themes/%s " , g_get_home_dir ( ) , dir [ 0 ] ) ;
} else if ( theme_type = = THEME_GTK ) {
theme_props - > target_dir = g_strdup_printf ( " %s/.themes/%s " , g_get_home_dir ( ) , dir [ 0 ] ) ;
} else if ( theme_type = = THEME_ENGINE ) {
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
2005-02-07 21:39:30 +00:00
_ ( " The theme is an engine. You need to compile the theme. " ) ) ;
2005-02-01 22:33:47 +00:00
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
2005-02-08 22:42:10 +00:00
gtk_widget_destroy ( dialog ) ;
cleanup_tmp_dir ( theme_props ) ;
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props - > filename ) ;
g_free ( theme_props - > theme_tmp_dir ) ;
g_free ( theme_props ) ;
g_free ( command ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
} else {
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " The file format is invalid " ) ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
2005-02-08 22:42:10 +00:00
gtk_widget_destroy ( dialog ) ;
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props - > filename ) ;
g_free ( theme_props - > theme_tmp_dir ) ;
g_free ( theme_props ) ;
g_free ( command ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
}
/* Move the Dir to the target dir */
theme_source_dir = gnome_vfs_uri_new ( theme_props - > theme_tmp_dir ) ;
theme_dest_dir = gnome_vfs_uri_new ( theme_props - > target_dir ) ;
if ( gnome_vfs_xfer_uri ( theme_source_dir , theme_dest_dir ,
GNOME_VFS_XFER_DELETE_ITEMS | GNOME_VFS_XFER_RECURSIVE | GNOME_VFS_XFER_REMOVESOURCE ,
GNOME_VFS_XFER_ERROR_MODE_ABORT ,
GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE ,
NULL , NULL ) ! = GNOME_VFS_OK ) {
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " Installation Failed " ) ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
cleanup_tmp_dir ( theme_props ) ;
2005-02-08 22:42:10 +00:00
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props - > filename ) ;
g_free ( theme_props - > theme_tmp_dir ) ;
g_free ( theme_props - > target_dir ) ;
g_free ( theme_props - > user_message ) ;
g_free ( theme_props ) ;
g_free ( command ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
} else {
2006-06-13 20:51:44 +00:00
/* Ask to apply theme (if we can) */
if ( theme_type = = THEME_GTK | | theme_type = = THEME_METACITY | | theme_type = = THEME_ICON )
{
/* TODO: currently cannot apply "gnome themes" */
2006-07-14 16:10:41 +00:00
theme_props - > user_message = g_strdup_printf ( _ ( " <span weight= \" bold \" size= \" larger \" >The theme \" %s \" has been installed.</span> \n \n Would you like to apply it now, or keep your current theme? " ) , dir [ 0 ] ) ;
dialog = gtk_message_dialog_new_with_markup ( NULL , GTK_DIALOG_MODAL , GTK_MESSAGE_INFO , GTK_BUTTONS_NONE , theme_props - > user_message ) ;
2006-06-13 20:51:44 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( dialog ) , _ ( " Keep Current Theme " ) , GTK_RESPONSE_CLOSE ) ;
apply_button = gtk_button_new_with_label ( _ ( " Apply New Theme " ) ) ;
gtk_button_set_image ( GTK_BUTTON ( apply_button ) , gtk_image_new_from_stock ( GTK_STOCK_APPLY , GTK_ICON_SIZE_BUTTON ) ) ;
gtk_dialog_add_action_widget ( GTK_DIALOG ( dialog ) , apply_button , GTK_RESPONSE_APPLY ) ;
GTK_WIDGET_SET_FLAGS ( apply_button , GTK_CAN_DEFAULT ) ;
gtk_widget_show ( apply_button ) ;
gtk_dialog_set_default_response ( GTK_DIALOG ( dialog ) , GTK_RESPONSE_APPLY ) ;
if ( gtk_dialog_run ( GTK_DIALOG ( dialog ) ) = = GTK_RESPONSE_APPLY )
{
/* apply theme here! */
GConfClient * gconf_client ;
gconf_client = gconf_client_get_default ( ) ;
switch ( theme_type )
{
case THEME_GTK : gconf_client_set_string ( gconf_client , GTK_THEME_KEY , dir [ 0 ] , NULL ) ; break ;
case THEME_METACITY : gconf_client_set_string ( gconf_client , METACITY_THEME_KEY , dir [ 0 ] , NULL ) ; break ;
case THEME_ICON : gconf_client_set_string ( gconf_client , ICON_THEME_KEY , dir [ 0 ] , NULL ) ; break ;
}
g_object_unref ( gconf_client ) ;
}
} else
{
dialog = gtk_message_dialog_new ( NULL ,
2005-02-01 22:33:47 +00:00
GTK_DIALOG_MODAL ,
GTK_MESSAGE_INFO ,
GTK_BUTTONS_OK ,
theme_props - > user_message ) ;
2006-06-13 20:51:44 +00:00
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
}
2005-02-01 22:33:47 +00:00
gtk_widget_destroy ( dialog ) ;
cleanup_tmp_dir ( theme_props ) ;
2005-02-08 22:42:10 +00:00
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props - > filename ) ;
g_free ( theme_props - > theme_tmp_dir ) ;
g_free ( theme_props - > target_dir ) ;
g_free ( theme_props - > user_message ) ;
g_free ( theme_props ) ;
g_free ( command ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2005-02-01 22:33:47 +00:00
return ;
}
}
2005-02-08 22:42:10 +00:00
g_free ( command ) ;
g_free ( theme_props - > target_tmp_dir ) ;
g_free ( theme_props - > filename ) ;
g_free ( theme_props ) ;
2006-04-10 17:56:59 +00:00
g_free ( gzip ) ;
g_free ( bzip2 ) ;
g_free ( tar ) ;
2002-11-01 16:09:43 +00:00
}
2006-04-25 21:30:45 +00:00
void
gnome_theme_install_from_uri ( gchar * theme_filename )
2002-11-01 16:09:43 +00:00
{
GtkWidget * dlg ;
2006-04-25 21:30:45 +00:00
gchar * filename , * path , * base ;
2002-11-01 16:09:43 +00:00
GList * src , * target ;
GnomeVFSURI * src_uri ;
2006-04-25 21:30:45 +00:00
gboolean icon_theme = FALSE ;
2003-12-05 04:35:15 +00:00
gchar * temppath ;
2004-11-02 22:13:05 +00:00
2002-11-01 16:09:43 +00:00
2006-04-25 21:30:45 +00:00
if ( theme_filename = = NULL | | strlen ( theme_filename ) < = 0 ) {
2004-11-02 22:13:05 +00:00
GtkWidget * dialog ;
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " No theme file location specified to install " ) ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
2002-11-01 16:09:43 +00:00
return ;
2003-12-05 05:20:39 +00:00
}
2006-04-25 21:30:45 +00:00
filename = g_strdup ( theme_filename ) ;
2005-10-24 09:29:34 +00:00
2003-12-05 05:20:39 +00:00
if ( filename = = NULL ) {
2004-11-02 22:13:05 +00:00
GtkWidget * dialog ;
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " The theme file location specified to install is invalid " ) ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
2002-11-01 16:09:43 +00:00
return ;
2003-12-05 05:20:39 +00:00
}
2004-11-02 22:13:05 +00:00
2002-11-01 16:09:43 +00:00
src_uri = gnome_vfs_uri_new ( filename ) ;
base = gnome_vfs_uri_extract_short_name ( src_uri ) ;
src = g_list_append ( NULL , src_uri ) ;
2003-01-16 07:40:29 +00:00
if ( icon_theme )
2005-01-06 11:54:55 +00:00
path = g_build_filename ( g_get_home_dir ( ) , " .icons " , NULL ) ;
2003-01-16 07:40:29 +00:00
else
2005-01-06 11:54:55 +00:00
path = g_build_filename ( g_get_home_dir ( ) , " .themes " , NULL ) ;
2003-12-05 04:35:15 +00:00
2004-11-02 22:13:05 +00:00
if ( access ( path , X_OK | W_OK ) ! = 0 ) {
GtkWidget * dialog ;
dialog = gtk_message_dialog_new ( NULL , GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " Insufficient permissions to install the theme in: \n %s " ) , path ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
2005-02-08 22:42:10 +00:00
g_free ( path ) ;
2004-11-02 22:13:05 +00:00
return ;
}
2005-01-03 18:08:23 +00:00
while ( TRUE ) {
gchar * file_tmp ;
2005-02-08 22:42:10 +00:00
GtkWidget * dialog ;
2005-01-03 18:08:23 +00:00
int len = strlen ( base ) ;
2005-02-01 22:33:47 +00:00
if ( base & & len > 7 & & ( ( ! strcmp ( base + len - 7 , " .tar.gz " ) ) | | ( ! strcmp ( base + len - 4 , " .tgz " ) ) ) )
2005-01-03 18:08:23 +00:00
file_tmp = g_strdup_printf ( " gnome-theme-%d.tar.gz " , rand ( ) ) ;
else if ( base & & len > 8 & & ! strcmp ( base + len - 8 , " .tar.bz2 " ) )
file_tmp = g_strdup_printf ( " gnome-theme-%d.tar.bz2 " , rand ( ) ) ;
2005-02-01 22:33:47 +00:00
else {
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " The file format is invalid. " ) ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
2005-02-08 22:42:10 +00:00
g_free ( path ) ;
2005-01-03 18:08:23 +00:00
return ;
2005-02-01 22:33:47 +00:00
}
2005-01-03 18:08:23 +00:00
2005-02-01 22:33:47 +00:00
path = g_build_filename ( g_get_home_dir ( ) , " .themes " , file_tmp , NULL ) ;
2005-01-03 18:08:23 +00:00
g_free ( file_tmp ) ;
if ( ! gnome_vfs_uri_exists ( gnome_vfs_uri_new ( path ) ) )
break ;
}
2004-11-02 22:13:05 +00:00
/* To avoid the copy of /root/.themes to /root/.themes/.themes
* which causes an infinite loop . The user asks to transfer the all
* contents of a folder , to a folder under itseld . So ignore the
* situation .
2003-12-05 04:35:15 +00:00
*/
temppath = g_build_filename ( filename , " .themes " , NULL ) ;
if ( ! strcmp ( temppath , path ) ) {
2004-11-02 22:13:05 +00:00
GtkWidget * dialog ;
dialog = gtk_message_dialog_new ( NULL ,
GTK_DIALOG_MODAL ,
GTK_MESSAGE_ERROR ,
GTK_BUTTONS_OK ,
_ ( " %s is the path where the theme files will be installed. This can not be selected as the source location " ) , filename ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
2003-12-05 04:35:15 +00:00
g_free ( base ) ;
g_free ( filename ) ;
2004-11-02 22:13:05 +00:00
g_free ( temppath ) ;
2005-02-08 22:42:10 +00:00
g_free ( path ) ;
2003-12-05 04:35:15 +00:00
return ;
}
g_free ( temppath ) ;
2004-11-02 22:13:05 +00:00
2003-12-05 04:35:15 +00:00
2002-11-01 16:09:43 +00:00
target = g_list_append ( NULL , gnome_vfs_uri_new ( path ) ) ;
2004-11-02 22:13:05 +00:00
2002-11-01 16:09:43 +00:00
dlg = file_transfer_dialog_new ( ) ;
file_transfer_dialog_wrap_async_xfer ( FILE_TRANSFER_DIALOG ( dlg ) ,
src , target ,
GNOME_VFS_XFER_RECURSIVE ,
GNOME_VFS_XFER_ERROR_MODE_QUERY ,
GNOME_VFS_XFER_OVERWRITE_MODE_QUERY ,
GNOME_VFS_PRIORITY_DEFAULT ) ;
gnome_vfs_uri_list_unref ( src ) ;
gnome_vfs_uri_list_unref ( target ) ;
g_free ( base ) ;
g_free ( filename ) ;
g_signal_connect ( G_OBJECT ( dlg ) , " cancel " ,
G_CALLBACK ( transfer_cancel_cb ) , path ) ;
g_signal_connect ( G_OBJECT ( dlg ) , " done " ,
G_CALLBACK ( transfer_done_cb ) , path ) ;
gtk_widget_show ( dlg ) ;
}
2006-04-19 10:48:04 +00:00
void
gnome_theme_installer_run_cb ( GtkWidget * button ,
2006-04-25 21:30:45 +00:00
GtkWindow * parent_window )
2006-04-19 10:48:04 +00:00
{
gnome_theme_installer_run ( parent_window , NULL ) ;
}
2002-11-01 16:09:43 +00:00
void
2006-04-25 21:30:45 +00:00
gnome_theme_installer_run ( GtkWindow * parent , gchar * filename )
2002-11-01 16:09:43 +00:00
{
static gboolean running_theme_install = FALSE ;
2006-04-25 21:30:45 +00:00
GtkWidget * dialog ;
static char old_folder [ 1024 ] = " " ;
gchar * filename_selected , * folder ;
if ( filename = = NULL )
filename = old_folder ;
2004-11-02 22:13:05 +00:00
2002-11-01 16:09:43 +00:00
if ( running_theme_install )
return ;
running_theme_install = TRUE ;
2006-04-25 21:30:45 +00:00
dialog = gtk_file_chooser_dialog_new ( " Select Theme " , parent , GTK_FILE_CHOOSER_ACTION_OPEN , GTK_STOCK_CANCEL , GTK_RESPONSE_REJECT , GTK_STOCK_OPEN , GTK_RESPONSE_ACCEPT , NULL ) ;
gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( dialog ) , old_folder ) ;
if ( gtk_dialog_run ( GTK_DIALOG ( dialog ) ) = = GTK_RESPONSE_ACCEPT )
{
filename_selected = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( dialog ) ) ;
gnome_theme_install_from_uri ( filename_selected ) ;
g_free ( filename_selected ) ;
}
2004-11-02 22:13:05 +00:00
2002-11-01 16:09:43 +00:00
2006-04-25 21:30:45 +00:00
folder = gtk_file_chooser_get_current_folder ( GTK_FILE_CHOOSER ( dialog ) ) ;
g_strlcpy ( old_folder , folder , 255 ) ;
g_free ( folder ) ;
2002-11-01 16:09:43 +00:00
2005-02-08 22:42:10 +00:00
gnome_theme_details_reread_themes_from_disk ( ) ;
2006-04-25 21:30:45 +00:00
gtk_widget_destroy ( dialog ) ;
2002-11-01 16:09:43 +00:00
running_theme_install = FALSE ;
}