From: Steven Luo Date: Sat, 28 Aug 2010 03:42:18 +0000 (-0700) Subject: Fremantle: Prestart MicroB if appropriate when reconfiguring browser-switchboard X-Git-Tag: v3.3b2~6 X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=commitdiff_plain;h=6bbfa71a0fb705e38f30e69fdad8177906050015;ds=sidebyside Fremantle: Prestart MicroB if appropriate when reconfiguring browser-switchboard If, in changing the browser-switchboard configuration, we go from a configuration where MicroB is not left running to one where it is, we should start MicroB in the background in order to make sure that the MicroB browser window comes up quickly when requested. Make a best-effort attempt at this in both the command-line utility and the GUI, refactoring to give a swb_reconfig() function that can be shared between the two along the way. Ideally, we'd also kill MicroB when making a config change in the other direction, but we don't have an easy way of knowing whether MicroB is actually in use and we don't want to kill MicroB if it's in use at the time. --- diff --git a/config-ui/Makefile b/config-ui/Makefile index 6798080..4c843d9 100644 --- a/config-ui/Makefile +++ b/config-ui/Makefile @@ -28,12 +28,15 @@ all: @echo ' make util -- build command-line configuration utility' @echo ' make diablo-hildon-app -- build standalone Diablo Hildon application' @echo ' make diablo-plugin -- build Diablo hildon-control-panel plugin' + @echo ' make fremantle-util -- build command-line configuration utility for Fremantle' @echo ' make fremantle-hildon-app -- build standalone Fremantle Hildon application' @echo ' make fremantle-plugin -- build Fremantle hildon-control-panel plugin' app: $(APP) util: $(UTIL) diablo-hildon-app: $(HILDON_APP) diablo-plugin: $(PLUGIN) +fremantle-util: + @$(MAKE) EXTRA_CPPFLAGS='-DFREMANTLE $(EXTRA_CPPFLAGS)' $(UTIL) fremantle-hildon-app: @$(MAKE) EXTRA_CPPFLAGS='-DFREMANTLE $(EXTRA_CPPFLAGS)' $(HILDON_APP) fremantle-plugin: diff --git a/config-ui/browser-switchboard-config.c b/config-ui/browser-switchboard-config.c index 7d644c6..e42c564 100644 --- a/config-ui/browser-switchboard-config.c +++ b/config-ui/browser-switchboard-config.c @@ -29,6 +29,7 @@ #include #include "config.h" +#include "save-config.h" #include "browsers.h" extern struct swb_config_option swb_config_options[]; @@ -103,16 +104,18 @@ static int get_default_browser(void) { } static int set_config_value(char *name, char *value) { - struct swb_config cfg; + struct swb_config orig_cfg, cfg; struct swb_config_option *optinfo; ptrdiff_t i; int retval = 1; - swb_config_init(&cfg); + swb_config_init(&orig_cfg); - if (!swb_config_load(&cfg)) + if (!swb_config_load(&orig_cfg)) return 1; + swb_config_copy(&cfg, &orig_cfg); + for (optinfo = swb_config_options; optinfo->name; ++optinfo) { if (strcmp(name, optinfo->name)) continue; @@ -157,12 +160,11 @@ static int set_config_value(char *name, char *value) { if (!swb_config_save(&cfg)) retval = 1; - swb_config_free(&cfg); + /* Reconfigure a running browser-switchboard, if present */ + swb_reconfig(&orig_cfg, &cfg); - /* 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"); + swb_config_free(&orig_cfg); + swb_config_free(&cfg); return retval; } diff --git a/config-ui/browser-switchboard-cp.c b/config-ui/browser-switchboard-cp.c index d4e89fd..02a4a07 100644 --- a/config-ui/browser-switchboard-cp.c +++ b/config-ui/browser-switchboard-cp.c @@ -52,6 +52,7 @@ #endif /* HILDON */ #include "config.h" +#include "save-config.h" #include "browsers.h" #define CONTINUOUS_MODE_DEFAULT 0 @@ -185,15 +186,9 @@ static void save_config(void) { } swb_config_save(&new_cfg); -} - -static void do_reconfig(void) { - save_config(); - /* 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"); + /* Reconfigure a running browser-switchboard, if present */ + swb_reconfig(&orig_cfg, &new_cfg); } @@ -422,7 +417,7 @@ osso_return_t execute(osso_context_t *osso, response = gtk_dialog_run(dialog); if (response == GTK_RESPONSE_OK) - do_reconfig(); + save_config(); gtk_widget_destroy(GTK_WIDGET(dialog)); @@ -451,7 +446,7 @@ int main(int argc, char *argv[]) { response = gtk_dialog_run(dialog); if (response == GTK_RESPONSE_OK) - do_reconfig(); + save_config(); gtk_widget_destroy(GTK_WIDGET(dialog)); diff --git a/config-ui/save-config.c b/config-ui/save-config.c index a80e089..1787f0e 100644 --- a/config-ui/save-config.c +++ b/config-ui/save-config.c @@ -28,6 +28,10 @@ #include #include +#ifdef FREMANTLE +#include +#endif + #include "configfile.h" #include "config.h" @@ -145,3 +149,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; +} diff --git a/config-ui/save-config.h b/config-ui/save-config.h new file mode 100644 index 0000000..e25d783 --- /dev/null +++ b/config-ui/save-config.h @@ -0,0 +1,31 @@ +/* + * save-config.h -- definitions for saving Browser Switchboard configuration + * + * Copyright (C) 2009-2010 Steven Luo + * Derived from a Python implementation by Jason Simpson and Steven Luo + * + * 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 the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ + +#ifndef _SAVE_CONFIG_H +#define _SAVE_CONFIG_H + +#include "config.h" + +int swb_config_save(struct swb_config *cfg); +void swb_reconfig(struct swb_config *old, struct swb_config *new); + +#endif /* _SAVE_CONFIG_H */ diff --git a/config.h b/config.h index 1ca50a3..31149f6 100644 --- a/config.h +++ b/config.h @@ -58,6 +58,4 @@ void swb_config_free(struct swb_config *cfg); int swb_config_load(struct swb_config *cfg); -int swb_config_save(struct swb_config *cfg); - #endif /* _CONFIG_H */