fix default search provider icon handling

This commit is contained in:
Vincent Sanders 2014-06-03 15:01:14 +01:00
parent f29d741b48
commit e2633a9a63
3 changed files with 90 additions and 44 deletions

View File

@ -37,7 +37,7 @@ struct search_provider {
hlcache_handle *ico_handle; hlcache_handle *ico_handle;
}; };
static struct { static struct search_web_ctx_s {
struct search_provider *providers; /* web search providers */ struct search_provider *providers; /* web search providers */
size_t providers_count; /* number of providers */ size_t providers_count; /* number of providers */
@ -50,42 +50,13 @@ static struct {
static const char *default_providers = "Google|www.google.com|http://www.google.com/search?q=%s|http://www.google.com/favicon.ico|\n"; static const char *default_providers = "Google|www.google.com|http://www.google.com/search?q=%s|http://www.google.com/favicon.ico|\n";
static const char *default_search_icon_url = "resource:default.ico"; static const char *default_search_icon_url = "resource:icons/search.png";
/**
* callback for hlcache icon fetch events.
*/
static nserror search_web_ico_callback(hlcache_handle *ico,
const hlcache_event *event, void *pw)
{
hlcache_handle **pico = pw;
switch (event->type) {
case CONTENT_MSG_DONE:
LOG(("icon '%s' retrived", nsurl_access(hlcache_handle_get_url(ico))));
guit->search_web->provider_update(search_web_ctx.providers[search_web_ctx.current].name, content_get_bitmap(ico));
break;
case CONTENT_MSG_ERROR:
LOG(("icon %s error: %s",
nsurl_access(hlcache_handle_get_url(ico)),
event->data.error));
hlcache_handle_release(ico);
*pico = NULL; /* clear reference to released handle */
break;
default:
break;
}
return NSERROR_OK;
}
/** /**
* Read providers file. * Read providers file.
* *
* Allocates stoage of sufficient size for teh providers fiel and * Allocates stoage of sufficient size for the providers file and
* reads the entire file in. * reads the entire file in.
* *
* \param fname The filename to read. * \param fname The filename to read.
@ -153,7 +124,7 @@ read_providers(const char *fname,
/** /**
* parse search providers from a memory block. * parse search providers from a memory block.
* *
* \parm providersd The provider info data. * \param providersd The provider info data.
* \param providers_size The size of the provider data. * \param providers_size The size of the provider data.
* \param providers_out The resulting provider array. * \param providers_out The resulting provider array.
* \param providers_count The number of providers in the output array. * \param providers_count The number of providers in the output array.
@ -301,6 +272,41 @@ make_search_nsurl(struct search_provider *provider,
return NSERROR_OK; return NSERROR_OK;
} }
/**
* callback for hlcache icon fetch events.
*/
static nserror
search_web_ico_callback(hlcache_handle *ico,
const hlcache_event *event,
void *pw)
{
struct search_provider *provider = pw;
switch (event->type) {
case CONTENT_MSG_DONE:
LOG(("icon '%s' retrived",
nsurl_access(hlcache_handle_get_url(ico))));
guit->search_web->provider_update(provider->name,
content_get_bitmap(ico));
break;
case CONTENT_MSG_ERROR:
LOG(("icon %s error: %s",
nsurl_access(hlcache_handle_get_url(ico)),
event->data.error));
hlcache_handle_release(ico);
/* clear reference to released handle */
provider->ico_handle = NULL;
break;
default:
break;
}
return NSERROR_OK;
}
/* exported interface documented in desktop/searchweb.h */ /* exported interface documented in desktop/searchweb.h */
nserror nserror
search_web_omni(const char *term, search_web_omni(const char *term,
@ -405,7 +411,7 @@ nserror search_web_select_provider(int selection)
ret = hlcache_handle_retrieve(icon_nsurl, 0, NULL, NULL, ret = hlcache_handle_retrieve(icon_nsurl, 0, NULL, NULL,
search_web_ico_callback, search_web_ico_callback,
&provider->ico_handle, provider,
NULL, CONTENT_IMAGE, NULL, CONTENT_IMAGE,
&provider->ico_handle); &provider->ico_handle);
nsurl_unref(icon_nsurl); nsurl_unref(icon_nsurl);
@ -418,6 +424,46 @@ nserror search_web_select_provider(int selection)
return NSERROR_OK; return NSERROR_OK;
} }
/**
* callback for hlcache icon fetch events.
*/
static nserror
default_ico_callback(hlcache_handle *ico,
const hlcache_event *event,
void *pw)
{
struct search_web_ctx_s *ctx = pw;
switch (event->type) {
case CONTENT_MSG_DONE:
LOG(("default icon '%s' retrived",
nsurl_access(hlcache_handle_get_url(ico))));
/* only set to default icon if providers icon has no handle */
if (ctx->providers[search_web_ctx.current].ico_handle == NULL) {
guit->search_web->provider_update(
ctx->providers[search_web_ctx.current].name,
content_get_bitmap(ico));
}
break;
case CONTENT_MSG_ERROR:
LOG(("icon %s error: %s",
nsurl_access(hlcache_handle_get_url(ico)),
event->data.error));
hlcache_handle_release(ico);
/* clear reference to released handle */
ctx->default_ico_handle = NULL;
break;
default:
break;
}
return NSERROR_OK;
}
/* exported interface documented in desktop/searchweb.h */ /* exported interface documented in desktop/searchweb.h */
nserror search_web_init(const char *provider_fname) nserror search_web_init(const char *provider_fname)
{ {
@ -454,8 +500,8 @@ nserror search_web_init(const char *provider_fname)
/* get default search icon */ /* get default search icon */
ret = hlcache_handle_retrieve(icon_nsurl, 0, NULL, NULL, ret = hlcache_handle_retrieve(icon_nsurl, 0, NULL, NULL,
search_web_ico_callback, default_ico_callback,
&search_web_ctx.default_ico_handle, &search_web_ctx,
NULL, CONTENT_IMAGE, NULL, CONTENT_IMAGE,
&search_web_ctx.default_ico_handle); &search_web_ctx.default_ico_handle);
nsurl_unref(icon_nsurl); nsurl_unref(icon_nsurl);

View File

@ -2,15 +2,13 @@ Google|www.google.com|http://www.google.com/search?q=%s|http://www.google.com/fa
Yahoo|search.yahoo.com|http://search.yahoo.com/search?p=%s|http://www.yahoo.com/favicon.ico| Yahoo|search.yahoo.com|http://search.yahoo.com/search?p=%s|http://www.yahoo.com/favicon.ico|
Bing|www.bing.com|http://www.bing.com/search?q=%s|http://www.bing.com/favicon.ico| Bing|www.bing.com|http://www.bing.com/search?q=%s|http://www.bing.com/favicon.ico|
Business.com|www.business.com|http://www.business.com/search/rslt_default.asp?query=%s|http://www.business.com/favicon.ico| Business.com|www.business.com|http://www.business.com/search/rslt_default.asp?query=%s|http://www.business.com/favicon.ico|
Omgili|www.omgili.com|http://www.omgili.com/AAAAA/%s.html|http://www.omgili.com/favicon.ico| Omgili|www.omgili.com|http://www.omgili.com/AAAAA/%s.html|http://omgili.com/public/images/favicon.ico|
BBC News|search.bbc.co.uk|http://search.bbc.co.uk/search?q=%s&tab=ns|http://news.bbc.co.uk/favicon.ico| BBC News|search.bbc.co.uk|http://search.bbc.co.uk/search?q=%s&tab=ns|http://www.bbc.co.uk/favicon.ico|
Ubuntu Packages|packages.ubuntu.com|http://packages.ubuntu.com/search?keywords=%s|http://packages.ubuntu.com/favicon.ico| Ubuntu Packages|packages.ubuntu.com|http://packages.ubuntu.com/search?keywords=%s|http://packages.ubuntu.com/favicon.ico|
Creative Commons|creativecommons.org|http://creativecommons.org/?s=%s|http://creativecommons.org/favicon.ico| Creative Commons|creativecommons.org|http://creativecommons.org/?s=%s|http://creativecommons.org/favicon.ico|fixme:favicon does not work as it is served as x-icon and is a png
Ask.com|www.ask.com|http://www.ask.com/web?q=%s|http://www.ask.com/favicon.ico| Ask.com|www.ask.com|http://www.ask.com/web?q=%s|http://sp.uk.ask.com/sh/i/a14/favicon/favicon.ico|fixme:favicon is served as text/plain
Answers.com|www.answers.com|http://www.answers.com/%s|http://www.answers.com/favicon.ico|
Dictionary.com|dictionary.reference.com|http://dictionary.reference.com/browse/%s?jss=0|http://dictionary.reference.com/favicon.ico| Dictionary.com|dictionary.reference.com|http://dictionary.reference.com/browse/%s?jss=0|http://dictionary.reference.com/favicon.ico|
Youtube|www.youtube.com|http://www.youtube.com/results?search_query=%s|http://www.youtube.com/favicon.ico| Youtube|www.youtube.com|http://www.youtube.com/results?search_query=%s|http://www.youtube.com/favicon.ico|
AeroMp3|www.aeromp3.com|http://www.aeromp3.com/search?q=%s|http://www.aeromp3.com/favicon.ico|
AOL|search.aol.com|http://search.aol.com/aol/search?query=%s|http://www.aol.com/favicon.ico| AOL|search.aol.com|http://search.aol.com/aol/search?query=%s|http://www.aol.com/favicon.ico|
Baidu|www.baidu.com|http://www.baidu.com/s?wd=%s|http://www.baidu.com/favicon.ico| Baidu|www.baidu.com|http://www.baidu.com/s?wd=%s|http://www.baidu.com/favicon.ico|
Amazon|www.amazon.com|http://www.amazon.com/s/ref=nb_ss_gw?field-keywords=%s|http://www.amazon.com/favicon.ico| Amazon|www.amazon.com|http://www.amazon.com/s/ref=nb_ss_gw?field-keywords=%s|http://www.amazon.com/favicon.ico|
@ -18,5 +16,5 @@ Ebay|shop.ebay.com|http://shop.ebay.com/items/%s|http://www.ebay.com/favicon.ico
IMDB|www.imdb.com|http://www.imdb.com/find?q=%s|http://www.imdb.com/favicon.ico| IMDB|www.imdb.com|http://www.imdb.com/find?q=%s|http://www.imdb.com/favicon.ico|
ESPN|search.espn.go.com|http://search.espn.go.com/%s/|http://www.espn.go.com/favicon.ico| ESPN|search.espn.go.com|http://search.espn.go.com/%s/|http://www.espn.go.com/favicon.ico|
Wikipedia|en.wikipedia.org|http://en.wikipedia.org/w/index.php?title=Special%%3ASearch&search=%s|http://en.wikipedia.org/favicon.ico| Wikipedia|en.wikipedia.org|http://en.wikipedia.org/w/index.php?title=Special%%3ASearch&search=%s|http://en.wikipedia.org/favicon.ico|
DuckDuckGo|www.duckduckgo.com|http://www.duckduckgo.com/?q=%s|http://www.duckduckgo.com/favicon.ico| DuckDuckGo|www.duckduckgo.com|http://www.duckduckgo.com/html/?q=%s|http://www.duckduckgo.com/favicon.ico|fixme:Their ico upsets the current implementation
Seeks|www.seeks-project.info|https://www.seeks-project.info/search.php/search?q=%s|http://www.seeks-project.info/search.php/public/images/seek_icon_32x32_transparent.png| Seeks|www.seeks-project.info|https://www.seeks-project.info/search.php/search?q=%s|http://www.seeks-project.info/search.php/public/images/seek_icon_32x32_transparent.png|fixme:they have no icon

View File

@ -2212,6 +2212,8 @@ gui_search_web_provider_update(const char *provider_name,
GdkPixbuf *srch_pixbuf = NULL; GdkPixbuf *srch_pixbuf = NULL;
char *searchcontent; char *searchcontent;
LOG(("name:%s bitmap %p", provider_name, provider_bitmap));
if (provider_bitmap != NULL) { if (provider_bitmap != NULL) {
srch_pixbuf = nsgdk_pixbuf_get_from_surface(provider_bitmap->surface, 16, 16); srch_pixbuf = nsgdk_pixbuf_get_from_surface(provider_bitmap->surface, 16, 16);