X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=blobdiff_plain;f=config-ui%2Fsave-config.c;h=6cb7d5ca6d1983fc761b5458e471915b05a1eba7;hp=6b010e544ad35971deef18a069c9ab3822738fad;hb=fd200ff52e139d2180003a8711cbde56dd7e8126;hpb=ec8b58af1b1cf22f34478faf476047e7ce996245 diff --git a/config-ui/save-config.c b/config-ui/save-config.c index 6b010e5..6cb7d5c 100644 --- a/config-ui/save-config.c +++ b/config-ui/save-config.c @@ -27,9 +27,47 @@ #include #include +#ifdef FREMANTLE +#include +#endif + #include "configfile.h" #include "config.h" +extern struct swb_config_option swb_config_options[]; + +/* Outputs a config file line for the named option to a file descriptor */ +static void swb_config_output_option(FILE *fp, unsigned int *oldcfg_seen, + struct swb_config *cfg, char *name) { + struct swb_config_option *opt; + void *entry; + + for (opt = swb_config_options; opt->name; ++opt) { + if (strcmp(opt->name, name)) + continue; + + entry = (char *)cfg + opt->offset; + if (!(*oldcfg_seen & opt->set_mask) && + (cfg->flags & opt->set_mask)) { + switch (opt->type) { + case SWB_CONFIG_OPT_STRING: + fprintf(fp, "%s = \"%s\"\n", + opt->name, + *(char **)entry); + *oldcfg_seen |= opt->set_mask; + break; + case SWB_CONFIG_OPT_INT: + fprintf(fp, "%s = %d\n", + opt->name, + *(int *)entry); + *oldcfg_seen |= opt->set_mask; + break; + } + } + break; + } +} + /* Save the settings in the provided swb_config struct to the config file Returns true on success, false otherwise */ int swb_config_save(struct swb_config *cfg) { @@ -39,6 +77,7 @@ int swb_config_save(struct swb_config *cfg) { int retval = 1; struct swb_config_line line; unsigned int oldcfg_seen = 0; + int i; /* If CONFIGFILE_DIR doesn't exist already, try to create it */ if (!(homedir = getenv("HOME"))) @@ -78,46 +117,8 @@ int swb_config_save(struct swb_config *cfg) { while (!parse_config_file_line(fp, &line)) { if (line.parsed) { /* Is a config line, print the new value here */ - if (!strcmp(line.key, "continuous_mode")) { - if (!(oldcfg_seen & - SWB_CONFIG_CONTINUOUS_MODE_SET)) { - fprintf(tmpfp, "%s = %d\n", - line.key, - cfg->continuous_mode); - oldcfg_seen |= - SWB_CONFIG_CONTINUOUS_MODE_SET; - } - } else if (!strcmp(line.key, - "default_browser")) { - if (!(oldcfg_seen & - SWB_CONFIG_DEFAULT_BROWSER_SET)) { - fprintf(tmpfp, "%s = \"%s\"\n", - line.key, - cfg->default_browser); - oldcfg_seen |= - SWB_CONFIG_DEFAULT_BROWSER_SET; - } - } else if (!strcmp(line.key, - "other_browser_cmd")) { - if (!(oldcfg_seen & - SWB_CONFIG_OTHER_BROWSER_CMD_SET)) { - fprintf(tmpfp, "%s = \"%s\"\n", - line.key, - cfg->other_browser_cmd); - oldcfg_seen |= - SWB_CONFIG_OTHER_BROWSER_CMD_SET; - } - } else if (!strcmp(line.key, - "logging")) { - if (!(oldcfg_seen & - SWB_CONFIG_LOGGING_SET)) { - fprintf(tmpfp, "%s = \"%s\"\n", - line.key, - cfg->logging); - oldcfg_seen |= - SWB_CONFIG_LOGGING_SET; - } - } + swb_config_output_option(tmpfp, &oldcfg_seen, + cfg, line.key); } else { /* Just copy the old line over */ fprintf(tmpfp, "%s\n", line.key); @@ -129,22 +130,9 @@ int swb_config_save(struct swb_config *cfg) { } /* If we haven't written them yet, write out any new config values */ - if (!(oldcfg_seen & SWB_CONFIG_CONTINUOUS_MODE_SET) && - (cfg->flags & SWB_CONFIG_CONTINUOUS_MODE_SET)) - fprintf(tmpfp, "%s = %d\n", - "continuous_mode", cfg->continuous_mode); - if (!(oldcfg_seen & SWB_CONFIG_DEFAULT_BROWSER_SET) && - (cfg->flags & SWB_CONFIG_DEFAULT_BROWSER_SET)) - fprintf(tmpfp, "%s = \"%s\"\n", - "default_browser", cfg->default_browser); - if (!(oldcfg_seen & SWB_CONFIG_OTHER_BROWSER_CMD_SET) && - (cfg->flags & SWB_CONFIG_OTHER_BROWSER_CMD_SET)) - fprintf(tmpfp, "%s = \"%s\"\n", - "other_browser_cmd", cfg->other_browser_cmd); - if (!(oldcfg_seen & SWB_CONFIG_LOGGING_SET) && - (cfg->flags & SWB_CONFIG_LOGGING_SET)) - fprintf(tmpfp, "%s = \"%s\"\n", - "logging", cfg->logging); + for (i = 0; swb_config_options[i].name; ++i) + swb_config_output_option(tmpfp, &oldcfg_seen, cfg, + swb_config_options[i].name); /* Replace the old config file with the new one */ fclose(tmpfp); @@ -160,3 +148,48 @@ out: fclose(fp); return retval; } + +/* Reconfigure a running browser-switchboard process with new settings */ +void swb_reconfig(struct swb_config *old, struct swb_config *new) { +#ifdef FREMANTLE + int microb_was_autostarted, microb_should_autostart; + pid_t pid; + int status; +#endif + + /* Try to send SIGHUP to any running browser-switchboard process + This causes it to reread config files if in continuous_mode, or + die so that the config will be reloaded on next start otherwise */ + system("kill -HUP `pidof browser-switchboard` > /dev/null 2>&1"); + +#ifdef FREMANTLE + if (!old || !new) + return; + + microb_was_autostarted = (old->autostart_microb == 1) || + (!strcmp(old->default_browser, "microb") && + old->autostart_microb); + microb_should_autostart = (new->autostart_microb == 1) || + (!strcmp(new->default_browser, "microb") && + new->autostart_microb); + if (!microb_was_autostarted && microb_should_autostart) { + /* MicroB should be started if it's not running */ + status = system("pidof browser > /dev/null"); + if (WIFEXITED(status) && WEXITSTATUS(status)) { + if ((pid = fork()) == -1) + return; + + if (!pid) { + /* Child process, start MicroB */ + execl("/usr/bin/maemo-invoker", "browser", + (char *)NULL); + } + } + } + /* XXX: We'd like to stop MicroB if (microb_was_autostarted && + !microb_should_autostart), but we don't know if the open MicroB + process has open windows. */ +#endif /* FREMANTLE */ + + return; +}