Exemple #1
0
int main(void) {
  window_open();

  glutils_init();

  Settings settings;
  settings.first_run = true;
  Level level;

  bool leave = false;
  while(!leave) {
    if(!menu_run(&settings)) {
      leave = true;
      break;
    }

    theme_load(settings.theme);
    level_load(settings.level_set, settings.level, &level);

    level_run(&level, &settings);
  }

  /*
   * unload the last used theme
   * if we loaded several themes one after another,
   * they have been automatically freed by theme_load
   */
  theme_unload();

  return EXIT_SUCCESS;
}
Exemple #2
0
static void read_settings(void)
{
	int old_autolog = autolog_level;

	g_free_not_null(autolog_path);
	autolog_path = g_strdup(settings_get_str("autolog_path"));

	autolog_level = !settings_get_bool("autolog") ? 0 :
		settings_get_level("autolog_level");

	if (old_autolog && !autolog_level)
		autologs_close_all();

	/* write to log files with different theme? */
	if (log_theme_name != NULL)
		signal_remove("print format", (SIGNAL_FUNC) sig_print_format);

	g_free_not_null(log_theme_name);
	log_theme_name = g_strdup(settings_get_str("log_theme"));

	if (*log_theme_name == '\0') {
		g_free(log_theme_name);
		log_theme_name = NULL;
	}
	else
		signal_add("print format", (SIGNAL_FUNC) sig_print_format);

	log_theme = log_theme_name == NULL ? NULL :
		theme_load(log_theme_name);

	if (autolog_ignore_targets != NULL)
		g_strfreev(autolog_ignore_targets);

	autolog_ignore_targets = g_strsplit(settings_get_str("autolog_ignore_targets"), " ", -1);
}
Exemple #3
0
static void sig_print_format(THEME_REC *theme, const char *module,
			     TEXT_DEST_REC *dest, void *formatnum, char **args)
{
	char *str, *linestart, *tmp;

	if (log_theme == NULL) {
		/* theme isn't loaded for some reason (/reload destroys it),
		   reload it. */
		log_theme = theme_load(log_theme_name);
		if (log_theme == NULL) return;
	}

	if (theme == log_theme)
		return;

	str = format_get_text_theme_charargs(log_theme, module, dest,
					     GPOINTER_TO_INT(formatnum), args);
	skip_next_printtext = TRUE;

	if (*str != '\0') {
                /* add the line start format */
		linestart = format_get_level_tag(log_theme, dest);
                tmp = str;
		str = format_add_linestart(tmp, linestart);
		g_free_not_null(linestart);
		g_free(tmp);

		/* strip colors from text, log it. */
		log_line(dest, str);
	}
	g_free(str);

}
Exemple #4
0
void themes_reload(void)
{
	GSList *refs;
	char *fname;

	/* increase every theme's refcount, and destroy them. this way if
	   we want to use the theme before it's reloaded we don't crash. */
	refs = NULL;
	while (themes != NULL) {
		THEME_REC *theme = themes->data;

		refs = g_slist_prepend(refs, theme);

		theme->refcount++;
		theme_destroy(theme);
	}

	/* first there's default theme.. */
	current_theme = theme_load("default");
	if (current_theme == NULL) {
		fname = g_strdup_printf("%s/default.theme", get_irssi_dir());
		current_theme = theme_create(fname, "default");
		current_theme->default_color = -1;
                theme_read(current_theme, NULL);
		g_free(fname);
	}

        window_themes_update();
	change_theme(settings_get_str("theme"), FALSE);

	while (refs != NULL) {
		theme_unref(refs->data);
		refs = g_slist_remove(refs, refs->data);
	}
}
Exemple #5
0
void windows_layout_restore(void)
{
	WINDOW_REC *window;
	CONFIG_NODE *node;
	GSList *tmp;

	node = iconfig_node_traverse("windows", FALSE);
	if (node == NULL) return;

	for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
		CONFIG_NODE *node = tmp->data;

		window = window_create(NULL, TRUE);
		window_set_refnum(window, atoi(node->key));
                window->sticky_refnum = config_node_get_bool(node, "sticky_refnum", FALSE);
		window_set_name(window, config_node_get_str(node, "name", NULL));
		window_set_level(window, level2bits(config_node_get_str(node, "level", "")));

		window->servertag = g_strdup(config_node_get_str(node, "servertag", NULL));
		window->theme_name = g_strdup(config_node_get_str(node, "theme", NULL));
		if (window->theme_name != NULL)
			window->theme = theme_load(window->theme_name);

		window_add_items(window, config_node_section(node, "items", -1));
		signal_emit("window restore", 2, window, node);
	}

	signal_emit("windows restored", 0);
}
Exemple #6
0
static void read_settings(void)
{
	int old_autolog = autolog_level;
        int log_file_create_mode;

	autolog_path = settings_get_str("autolog_path");
	autolog_level = !settings_get_bool("autolog") ? 0 :
		settings_get_level("autolog_level");

	if (old_autolog && !autolog_level)
		autologs_close_all();

	/* write to log files with different theme? */
	if (log_theme_name != NULL)
		signal_remove("print format", (SIGNAL_FUNC) sig_print_format);
	log_theme_name = settings_get_str("log_theme");
	if (*log_theme_name == '\0')
		log_theme_name = NULL;
	else
		signal_add("print format", (SIGNAL_FUNC) sig_print_format);

	log_theme = log_theme_name == NULL ? NULL :
		theme_load(log_theme_name);

	log_file_create_mode = octal2dec(settings_get_int("log_create_mode"));
        log_dir_create_mode = log_file_create_mode;
        if (log_file_create_mode & 0400) log_dir_create_mode |= 0100;
        if (log_file_create_mode & 0040) log_dir_create_mode |= 0010;
        if (log_file_create_mode & 0004) log_dir_create_mode |= 0001;
}
Exemple #7
0
static void sig_layout_restore(void)
{
	WINDOW_REC *window;
	CONFIG_NODE *node;
	GSList *tmp;

	node = iconfig_node_traverse("windows", FALSE);
	if (node == NULL) return;

	tmp = config_node_first(node->value);
	for (; tmp != NULL; tmp = config_node_next(tmp)) {
		CONFIG_NODE *node = tmp->data;

		window = window_find_refnum(atoi(node->key));
		if (window == NULL)
			window = window_create(NULL, TRUE);

		window_set_refnum(window, atoi(node->key));
                window->sticky_refnum = config_node_get_bool(node, "sticky_refnum", FALSE);
                window->immortal = config_node_get_bool(node, "immortal", FALSE);
		window_set_name(window, config_node_get_str(node, "name", NULL));
		window_set_history(window, config_node_get_str(node, "history_name", NULL));
		window_set_level(window, level2bits(config_node_get_str(node, "level", "")));

		window->servertag = g_strdup(config_node_get_str(node, "servertag", NULL));
		window->theme_name = g_strdup(config_node_get_str(node, "theme", NULL));
		if (window->theme_name != NULL)
			window->theme = theme_load(window->theme_name);

		window_add_items(window, config_node_section(node, "items", -1));
		signal_emit("layout restore window", 2, window, node);
	}
}
Exemple #8
0
void
ui_handle_login_account_success(ProfAccount *account, gboolean secured)
{
    if (account->theme) {
        if (theme_load(account->theme)) {
            ui_load_colours();
            if (prefs_get_boolean(PREF_ROSTER)) {
                ui_show_roster();
            } else {
                ui_hide_roster();
            }
            if (prefs_get_boolean(PREF_OCCUPANTS)) {
                ui_show_all_room_rosters();
            } else {
                ui_hide_all_room_rosters();
            }
            ui_resize();
        } else {
            cons_show("Couldn't find account theme: %s", account->theme);
        }
    }

    resource_presence_t resource_presence = accounts_get_login_presence(account->name);
    contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence);
    cons_show_login_success(account, secured);
    title_bar_set_presence(contact_presence);
    title_bar_set_connected(TRUE);
    title_bar_set_tls(secured);

    status_bar_print_message(connection_get_fulljid());
    status_bar_update_virtual();
}
Exemple #9
0
static void window_themes_update(void)
{
	GSList *tmp;

	for (tmp = windows; tmp != NULL; tmp = tmp->next) {
		WINDOW_REC *rec = tmp->data;

		if (rec->theme_name != NULL)
                        rec->theme = theme_load(rec->theme_name);
	}
}
Exemple #10
0
/* change theme */
void cb_change_theme()
{
    Menu *menu;
    theme_load( theme_names[config.theme_id] );
    hint_set_bkgnd( mbkgnd );
    /* apply the new background to all items */
    list_reset( menus );
    while ( ( menu = list_next( menus ) ) ) {
        menu_set_bkgnd( menu, mbkgnd );
        menu_set_fonts( menu, mcfont, mfont, mhfont );
    }
    stk_surface_blit( mbkgnd, 0,0,-1,-1, stk_display, 0,0 );
    stk_display_update( STK_UPDATE_ALL );
}
Exemple #11
0
/* SYNTAX: WINDOW THEME <name> */
static void cmd_window_theme(const char *data)
{
	g_free_not_null(active_win->theme_name);
	active_win->theme_name = g_strdup(data);

	active_win->theme = theme_load(data);
	if (active_win->theme != NULL) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
			    IRCTXT_WINDOW_THEME_CHANGED, data);
	} else {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
			    IRCTXT_THEME_NOT_FOUND, data);
	}
}
Exemple #12
0
/* SYNTAX: WINDOW THEME <name> */
static void cmd_window_theme(const char *data)
{
	THEME_REC *theme;

	g_free_not_null(active_win->theme_name);
	active_win->theme_name = g_strdup(data);

	active_win->theme = theme = theme_load(data);
	if (theme != NULL) {
		printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
				   TXT_WINDOW_THEME_CHANGED,
				   theme->name, theme->path);
	} else {
		printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
				   TXT_THEME_NOT_FOUND, data);
	}
}
Exemple #13
0
/* SYNTAX: WINDOW THEME [-delete] [<name>] */
static void cmd_window_theme(const char *data)
{
	THEME_REC *theme;
	GHashTable *optlist;
        char *name;
	void *free_arg;

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
			    "window theme", &optlist, &name))
		return;

	if (g_hash_table_lookup(optlist, "delete") != NULL) {
		g_free_and_null(active_win->theme_name);

		printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
				   TXT_WINDOW_THEME_REMOVED);
	} else if (*name == '\0') {
		if (active_win->theme == NULL) {
			printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
					   TXT_WINDOW_THEME_DEFAULT);
		} else {
                        theme = active_win->theme;
			printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
					   TXT_WINDOW_THEME,
					   theme->name, theme->path);
		}
	} else {
		g_free_not_null(active_win->theme_name);
		active_win->theme_name = g_strdup(data);

		active_win->theme = theme = theme_load(data);
		if (theme != NULL) {
			printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
					   TXT_WINDOW_THEME_CHANGED,
					   theme->name, theme->path);
		} else {
			printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
					   TXT_THEME_NOT_FOUND, data);
		}
	}

	cmd_params_free(free_arg);
}
Exemple #14
0
static void change_theme(const char *name, int verbose)
{
	THEME_REC *rec;

	rec = theme_load(name);
	if (rec != NULL) {
		current_theme = rec;
                signal_emit("theme changed", 1, rec);

		if (verbose) {
			printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
				    TXT_THEME_CHANGED,
				    rec->name, rec->path);
		}
	} else if (verbose) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
			    TXT_THEME_NOT_FOUND, name);
	}
}
Exemple #15
0
static void dropdown_theme_onselect(uint16_t i, const DROPDOWN* UNUSED(dm))
{
    theme_load(i);
}
Exemple #16
0
int main(int argc, char *argv[])
{
    int result = ACTION_NONE;
    int leave = 0;
    char *editor_file = 0;
    char path[512];
    SDL_Surface *loading;
#ifdef __unix__
    gid_t realgid;

    hi_dir_chart_file = fopen(HI_DIR "/" CHART_FILE_NAME, "r+");

    /* This is where we drop our setuid/setgid privileges.
     */
    realgid = getgid();
    if (setresgid(-1, realgid, realgid) != 0) {
        perror("Could not drop setgid privileges.  Aborting.");
        exit(1);
    }
#endif
   
/* i18n */
#ifdef ENABLE_NLS
    setlocale (LC_ALL, "");
    bindtextdomain (PACKAGE, LOCALEDIR);
    textdomain (PACKAGE);
#endif
    
#ifdef _WIN32    
    /* Get Windows to open files in binary mode instead of default text mode */
    _fmode = _O_BINARY;
#endif    
    
    /* lbreakout info */
    printf( "LBreakout2 %s\nCopyright 2001-2010 Michael Speck\nPublished under GNU GPL\n---\n", VERSION );
    printf( "Looking up data in: %s\n", SRC_DIR );
    printf( "Looking up highscores in: %s\n", HI_DIR );
    printf( "Looking up custom levels in: %s/%s/lbreakout2-levels\n", (getenv( "HOME" )?getenv( "HOME" ):"."), CONFIG_DIR_NAME );
#ifndef AUDIO_ENABLED
    printf( "Compiled without sound and music\n" );
#endif

    set_random_seed(); /* set random seed */

    config_load();
    
    stk_init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK );
    if ( config.fullscreen )
        stk_display_open( SDL_SWSURFACE | SDL_FULLSCREEN, 640, 480, 16 );
    else
        stk_display_open( SDL_SWSURFACE, 640, 480, 16 );
    stk_audio_open( 0,0,0,config.audio_buffer_size );
    SDL_WM_SetCaption( "LBreakout2", 0 );
    SDL_SetEventFilter( event_filter );
    stk_audio_enable_sound( config.sound );
    stk_audio_set_sound_volume( config.volume * 16 );
    
    /* load a little loading pic */
    stk_surface_set_path( SRC_DIR "/gfx" );
    loading = stk_surface_load( SDL_SWSURFACE, "loading.png" );
    stk_surface_blit( loading, 0,0,-1,-1, stk_display, 
                      (stk_display->w-loading->w)/2, 
                      (stk_display->h-loading->h)/2 );
    stk_display_update( STK_UPDATE_ALL );
    
    /* load the GUI graphics from SRC_DIR/gui_theme */
    stk_surface_set_path( SRC_DIR );
    stk_audio_set_path( SRC_DIR );
    gui_init( "gui_theme" );

    stk_surface_set_path( SRC_DIR "/gfx" );
    stk_audio_set_path( SRC_DIR "/sounds" );
    
    /* load resources */
    /* for simplicity all functions are kept but anything
     * that is now themeable is loaded in
     * theme_load instead of the original function
     * (deleting resources works analouge)
     */
    theme_get_list();
    if ( config.theme_count != theme_count ) {
        if ( config.theme_id >= theme_count )
            config.theme_id = 0;
        config.theme_count = theme_count;
    }
    theme_load( theme_names[config.theme_id] );
    /* old functions still with initialzations of
     * lists or variables 
     */
    client_game_create();
    hint_load_res();
    chart_load();
    manager_create();
    client_create();
    exp_load();
    editor_create();
	help_create();
    /* run game */
    manager_fade( STK_FADE_IN );
    while( !leave && !stk_quit_request ) {
        result = manager_run();
        switch( result ) {
            case ACTION_QUIT: leave = 1; break;
            case ACTION_RESUME_0:
                manager_fade( STK_FADE_OUT );
		if ( client_game_resume_local( 0 ) )
			client_game_run();
                client_game_finalize();
                manager_fade( STK_FADE_IN );
                break;
            case ACTION_PLAY_LBR:
                manager_fade( STK_FADE_OUT );
                gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */
		if ( client_game_init_local( "LBreakout2" ) )
			client_game_run();
                client_game_finalize();
                manager_fade( STK_FADE_IN );
                break;
            case ACTION_PLAY_CUSTOM:
                manager_fade( STK_FADE_OUT );
                gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */
                if (gameSeed==0) gameSeed=1; /* not allowed because.... A HACK!!! 0 means to have
                                                no bonus levels to save a parameter */
		if ( client_game_init_local( levelset_names_local[config.levelset_id_local] ) )
			client_game_run();
                client_game_finalize();
                manager_fade( STK_FADE_IN );
                break;
            case ACTION_EDIT:
                /* new set? */
                if ( strequal( NEW_SET, edit_set ) ) {
                    editor_file = calloc( 16, sizeof( char ) );
                    snprintf( path, sizeof(path)-1, "%s/%s/lbreakout2-levels", getenv( "HOME" )? getenv("HOME"):".", CONFIG_DIR_NAME );
                    if ( !enter_string( font, _("Set Name:"), editor_file, 12 ) || !file_check( path, editor_file, "w" ) ) {
                        free( editor_file );
                        break;
                    }
                    else
                        manager_update_set_list();
                }
                else
                    editor_file = strdup( edit_set );
                if ( editor_init( editor_file ) ) {
                    manager_fade( STK_FADE_OUT );
                    editor_run();
                    editor_clear();
                    manager_fade( STK_FADE_IN );
                }
                free( editor_file ); editor_file = 0;
                break;
			case ACTION_QUICK_HELP:
				help_run();
				break;
            case ACTION_CLIENT:
                manager_fade( STK_FADE_OUT );
                client_run();
                manager_fade( STK_FADE_IN );
                break;
            default: break;
        }
    }
    manager_fade( STK_FADE_OUT );
    /* delete stuff */
    help_delete();
	manager_delete();
	chart_save();
    chart_delete();
    editor_delete();
    exp_delete();
    client_game_delete();
    hint_delete_res();
    theme_delete();
    theme_delete_list();
    stk_surface_free( &loading );
    
    config_save();
    
    if (hi_dir_chart_file)
        fclose(hi_dir_chart_file);

    return EXIT_SUCCESS;
}
Exemple #17
0
static GuiWidget *create_widget_list(GuiWidget *parent_widget, xmlNodePtr root)
{
	GuiWidget *widget = NULL, *first_widget = NULL;

	xmlNodePtr cur = XML_GET_CHILD(root);
	while(cur != NULL) {
		if ( xmlStrcmp(cur->name, WIDGET_STR) == 0 ) {
			xmlChar *widget_name  = xmlGetProp(cur, NAME_STR );
			xmlChar *classid      = xmlGetProp(cur, CLASS_STR);
			xmlChar *widget_style = xmlGetProp(cur, STYLE_STR);
//			printf("XmlParser: widget_name=%s\n",(char *)widget_name);

			widget = widget_new_child(parent_widget, (char *)widget_name, (char *)classid, (char *)widget_style);
			if (widget_name)  xmlFree(widget_name);
			if (classid)      xmlFree(classid);
			if (widget_style) xmlFree(widget_style);

			if (widget == NULL) goto next;
			if (first_widget == NULL) first_widget = widget;

			xmlNodePtr node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if ( xmlStrcmp(node->name, PROPERTY_STR) == 0 ) {
					xmlChar *key   = xmlGetProp(node, NAME_STR);
					xmlChar *value = xmlGetProp(node, VALUE_STR);//xmlNodeGetContent(node);
					if (xmlStrcmp(key, (xmlChar*)"tabstop") == 0)
						widget->tabstop= atoidef((char *)value, 1);
					else
						widget_set_property(widget, (char *)key, (char *)value);
					if (key)   xmlFree(key);
					if (value) xmlFree(value);
				}
				else if (xmlStrcmp(node->name, SIGNAL_STR) == 0 ) {
					xmlChar *name    = xmlGetProp(node, NAME_STR);
					xmlChar *handler = xmlGetProp(node, HANDLER_STR);
					signal_new(widget, (char *)name, (char *)handler);
					if (name)    xmlFree(name);
					if (handler) xmlFree(handler);
				}
				else if (xmlStrcmp(node->name, CHILDREN_STR) == 0 )
					create_widget_list(widget, node);
				node = node->next;
			}
		}
		else if ( xmlStrcmp(cur->name, FILES_STR) == 0 ) {
			int i=0;

			gui->search_num = 0;

			xmlNodePtr node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if (xmlStrcmp(node->name, SEARCH_STR) == 0)
					gui->search_num++;
				node = node->next;
			}

			gui->search_path = (char **)malloc(sizeof(char*) *gui->search_num + 1);
			node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if (xmlStrcmp(node->name, SEARCH_STR) == 0)
					gui->search_path[i++] = strdup( (char *)xmlGetProp(node, PATH_STR) );
				node = node->next;
			}
			gui->search_path[i] = NULL;

			node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if (xmlStrcmp(node->name, FONT_STR) == 0) {
					xmlChar *font_name = xmlGetProp(node, NAME_STR);
					xmlChar *file_name = xmlGetProp(node, FILE_STR);
					if (file_name && font_name)
						create_fontdesc((char *)font_name, (char *)file_name);
					if (file_name) xmlFree(file_name);
					if (font_name) xmlFree(font_name);
				}
				else if (xmlStrcmp(node->name, IMAGE_STR) == 0) {
					xmlChar *image_name = xmlGetProp(node, NAME_STR);
					xmlChar* file_name  = xmlGetProp(node, FILE_STR);
					if (file_name && image_name)
						create_imagedesc((char *)image_name, (char *)file_name);
					if (file_name)  xmlFree(file_name);
					if (image_name) xmlFree(image_name);
				}
				node = node->next;
			}
		}
		else if ( xmlStrcmp(cur->name, I18N_STR) == 0 ) {
			xmlNodePtr node = XML_GET_CHILD(cur);
			while (node != NULL) {
				GuiI18n *i18n;
				if (xmlStrcmp(node->name, LANGUAGE_STR) == 0) {
					xmlChar *language = xmlGetProp(node, NAME_STR);
					if (language) {
						i18n = i18n_add_language((char *)language);
						xmlFree(language);
						if (i18n) {
							xmlNodePtr text_node = XML_GET_CHILD(node);
							while (text_node != NULL) {
								if (xmlStrcmp(text_node->name, TRAN_STR) == 0) {
									xmlChar *key   = xmlGetProp(text_node, ID_STR);
									xmlChar *value = xmlNodeGetContent(text_node);
									i18n_add_tran(i18n, (char *)key, (char *)value);
									if (key)   xmlFree(key);
									if (value) xmlFree(value);
								}
								text_node = text_node->next;
							}
						}
					}
				}
				node = node->next;
			}
		}
		else if ( xmlStrcmp(cur->name, THEMES_STR) == 0) {
			xmlNodePtr node = XML_GET_CHILD(cur);
			while (node != NULL) {
				if (xmlStrcmp(node->name, THEME_STR) == 0) {
					Theme *theme = (Theme *)malloc(sizeof(Theme));
					if (theme == NULL) {
						printf("memory out\n");
						node = node->next;
						continue;
					}
					char *filename = (char *)xmlGetProp(node, FILE_STR);
					if (file_exists(filename) == -1) {
						char *oldfile = filename;
						filename = gui_search_file(filename);
						free(oldfile);
					}

					if (filename) {
						xmlChar *theme_name = xmlGetProp(node, NAME_STR);
						if (theme_load(theme, filename) == 0) {
							if (gui->current_theme == NULL)
								gui->current_theme = theme;
							hash_add(gui->theme_hash, (char *)theme_name, theme);
						}
						xmlFree(theme_name);
						free(filename);
					}
				}
				node = node->next;
			}
		}
next:
		cur = cur->next;
	}

	return first_widget;
}