forked from Miroirs/x49gp
Don't copy style. Try to load them locally, then globally, then run style-less
This commit is contained in:
parent
6aacf694a9
commit
fdcef2c099
3 changed files with 51 additions and 30 deletions
|
@ -13,34 +13,37 @@
|
||||||
#include "x49gp.h"
|
#include "x49gp.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
#ifdef X49GP_DATADIR
|
|
||||||
# define GLOBAL_DATADIR X49GP_DATADIR
|
|
||||||
#else
|
|
||||||
# define GLOBAL_DATADIR x49gp->progpath
|
|
||||||
#endif
|
|
||||||
#define STATE_FILE_NAME "state"
|
#define STATE_FILE_NAME "state"
|
||||||
|
|
||||||
static int copy_file_from_global_datadir_to_user_datadir( const char* filename )
|
/* #ifdef X49GP_DATADIR */
|
||||||
{
|
/* # define GLOBAL_DATADIR X49GP_DATADIR */
|
||||||
GError* gerror = NULL;
|
/* #else */
|
||||||
if ( !g_file_test( g_build_filename( opt.datadir, filename, NULL ), G_FILE_TEST_EXISTS ) ) {
|
/* # define GLOBAL_DATADIR x49gp->progpath */
|
||||||
if ( opt.verbose )
|
/* #endif */
|
||||||
fprintf( stderr, "Copying %s to %s\n", g_build_filename( GLOBAL_DATADIR, filename, NULL ),
|
|
||||||
g_build_filename( opt.datadir, filename, NULL ) );
|
|
||||||
|
|
||||||
if ( !g_file_test( g_build_filename( GLOBAL_DATADIR, filename, NULL ), G_FILE_TEST_EXISTS ) )
|
/* static int copy_file_from_global_datadir_to_user_datadir( const char* filename ) */
|
||||||
return EXIT_FAILURE;
|
/* { */
|
||||||
|
/* GError* gerror = NULL; */
|
||||||
|
/* if ( !g_file_test( g_build_filename( opt.datadir, filename, NULL ), G_FILE_TEST_EXISTS ) ) { */
|
||||||
|
/* if ( opt.verbose ) */
|
||||||
|
/* fprintf( stderr, "Copying %s to %s\n", g_build_filename( GLOBAL_DATADIR, filename, NULL ), */
|
||||||
|
/* g_build_filename( opt.datadir, filename, NULL ) ); */
|
||||||
|
|
||||||
if ( !g_file_copy( g_file_new_build_filename( GLOBAL_DATADIR, filename, NULL ),
|
/* if ( !g_file_test( g_build_filename( GLOBAL_DATADIR, filename, NULL ), G_FILE_TEST_EXISTS ) ) */
|
||||||
g_file_new_build_filename( opt.datadir, filename, NULL ), G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &gerror ) ) {
|
/* return EXIT_FAILURE; */
|
||||||
fprintf( stderr, "Unable to copy style: %s\n", gerror->message );
|
|
||||||
g_error_free( gerror );
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
/* if ( !g_file_copy( g_file_new_build_filename( GLOBAL_DATADIR, filename, NULL ), */
|
||||||
}
|
/* g_file_new_build_filename( opt.datadir, filename, NULL ), G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &gerror ) )
|
||||||
|
*/
|
||||||
|
/* { */
|
||||||
|
/* fprintf( stderr, "Unable to copy style: %s\n", gerror->message ); */
|
||||||
|
/* g_error_free( gerror ); */
|
||||||
|
/* return -errno; */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* return EXIT_SUCCESS; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
int x49gp_modules_init( x49gp_t* x49gp )
|
int x49gp_modules_init( x49gp_t* x49gp )
|
||||||
{
|
{
|
||||||
|
@ -134,8 +137,8 @@ int x49gp_modules_load( x49gp_t* x49gp )
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_file_from_global_datadir_to_user_datadir( "style-50g.css" );
|
/* copy_file_from_global_datadir_to_user_datadir( "style-50g.css" ); */
|
||||||
copy_file_from_global_datadir_to_user_datadir( "style-49gp.css" );
|
/* copy_file_from_global_datadir_to_user_datadir( "style-49gp.css" ); */
|
||||||
|
|
||||||
x49gp->state = g_key_file_new();
|
x49gp->state = g_key_file_new();
|
||||||
if ( NULL == x49gp->state ) {
|
if ( NULL == x49gp->state ) {
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
# define PATCHLEVEL 0
|
# define PATCHLEVEL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef X49GP_DATADIR
|
||||||
|
# define GLOBAL_DATADIR X49GP_DATADIR
|
||||||
|
#else
|
||||||
|
# define GLOBAL_DATADIR x49gp->progpath
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef enum { MODEL_49GP = 0, MODEL_50G } x50ng_model_t;
|
typedef enum { MODEL_49GP = 0, MODEL_50G } x50ng_model_t;
|
||||||
|
|
||||||
struct options {
|
struct options {
|
||||||
|
|
|
@ -1689,14 +1689,26 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Apply CSS
|
// Apply CSS
|
||||||
GtkCssProvider* style_provider = gtk_css_provider_new();
|
char* style_full_path = g_build_filename( opt.datadir, opt.style_filename, NULL );
|
||||||
|
if ( !g_file_test( style_full_path, G_FILE_TEST_EXISTS ) )
|
||||||
|
style_full_path = g_build_filename( GLOBAL_DATADIR, opt.style_filename, NULL );
|
||||||
|
|
||||||
gtk_css_provider_load_from_path( style_provider, g_build_filename( opt.datadir, opt.style_filename, NULL ), NULL );
|
if ( !g_file_test( style_full_path, G_FILE_TEST_EXISTS ) )
|
||||||
|
fprintf( stderr, "Can't load style %s neither from %s/%s nor form %s/%s\n", opt.style_filename, opt.datadir, opt.style_filename,
|
||||||
|
GLOBAL_DATADIR, opt.style_filename );
|
||||||
|
else {
|
||||||
|
GtkCssProvider* style_provider = gtk_css_provider_new();
|
||||||
|
gtk_css_provider_load_from_path( style_provider, g_build_filename( GLOBAL_DATADIR, opt.style_filename, NULL ), NULL );
|
||||||
|
|
||||||
gtk_style_context_add_provider_for_screen( gdk_screen_get_default(), GTK_STYLE_PROVIDER( style_provider ),
|
gtk_style_context_add_provider_for_screen( gdk_screen_get_default(), GTK_STYLE_PROVIDER( style_provider ),
|
||||||
GTK_STYLE_PROVIDER_PRIORITY_USER + 1 );
|
GTK_STYLE_PROVIDER_PRIORITY_USER + 1 );
|
||||||
|
|
||||||
g_object_unref( style_provider );
|
g_object_unref( style_provider );
|
||||||
|
|
||||||
|
if ( opt.verbose )
|
||||||
|
fprintf( stderr, "Loaded style from %s\n", style_full_path );
|
||||||
|
}
|
||||||
|
free( style_full_path );
|
||||||
|
|
||||||
// finally show the window
|
// finally show the window
|
||||||
gtk_widget_realize( ui->window );
|
gtk_widget_realize( ui->window );
|
||||||
|
|
Loading…
Reference in a new issue