Also handle mailto: urls.

This commit is contained in:
Hans Leidekker 2005-11-24 19:27:41 +01:00 committed by Alexandre Julliard
parent d160c8b926
commit 46e018ad37
2 changed files with 143 additions and 77 deletions

View File

@ -1,7 +1,8 @@
/*
* winebrowser - winelib app to launch native OS browser
* winebrowser - winelib app to launch native OS browser or mail client.
*
* Copyright (C) 2004 Chris Morgan
* Copyright (C) 2005 Hans Leidekker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -19,9 +20,19 @@
*
* NOTES:
* Winebrowser is a winelib application that will start the appropriate
* native browser up for a wine installation that lacks a windows browser.
* Thus you will be able to open urls via native mozilla if no browser
* has yet been installed in wine.
* native browser or mail client for a wine installation that lacks a
* windows browser/mail client. For example, you will be able to open
* urls via native mozilla if no browser has yet been installed in wine.
*
* The application to launch is chosen from a default set or, if set,
* taken from a registry key.
*
* The argument may be a regular Windows file name, an http(s) URL or a
* mailto URL. In the first two cases the argument will be fed to a web
* browser. In the third case the argument is fed to a mail client.
* A mailto URL is composed as follows:
*
* mailto:[E-MAIL]?subject=[TOPIC]&cc=[E-MAIL]&bcc=[E-MAIL]&body=[TEXT]
*/
#include "config.h"
@ -32,85 +43,139 @@
#include <stdlib.h>
#include <errno.h>
typedef LPSTR (*wine_get_unix_file_name_t) ( LPCWSTR dos );
typedef LPSTR (*wine_get_unix_file_name_t)(LPCWSTR unixname);
/* try to launch an app from a comma separated string of app names */
static int launch_app( char *candidates, const char *argv1 )
{
char *app;
const char *argv_new[3];
app = strtok( candidates, "," );
while (app)
{
argv_new[0] = app;
argv_new[1] = argv1;
argv_new[2] = NULL;
fprintf( stderr, "Considering: %s\n", app );
fprintf( stderr, "argv[1]: %s\n", argv1 );
spawnvp( _P_OVERLAY, app, argv_new ); /* only returns on error */
app = strtok( NULL, "," ); /* grab the next app */
}
fprintf( stderr, "winebrowser: could not find a suitable app to run\n" );
return 1;
}
static int open_http_url( const char *url )
{
static const char *defaultbrowsers =
"firefox,konqueror,mozilla,netscape,galeon,opera,dillo";
char browsers[256];
DWORD length, type;
HKEY key;
LONG r;
length = sizeof(browsers);
/* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
if (RegCreateKeyEx( HKEY_CURRENT_USER, "Software\\Wine\\WineBrowser", 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL))
{
fprintf( stderr, "winebrowser: cannot create config key\n" );
return 1;
}
r = RegQueryValueExA( key, "Browsers", 0, &type, (LPBYTE)browsers, &length );
if (r != ERROR_SUCCESS)
{
/* set value to the default */
RegSetValueExA( key, "Browsers", 0, REG_SZ, (LPBYTE)defaultbrowsers,
lstrlen( defaultbrowsers ) + 1 );
strcpy( browsers, defaultbrowsers );
}
RegCloseKey( key );
return launch_app( browsers, url );
}
static int open_mailto_url( const char *url )
{
static const char *defaultmailers =
"mozilla-thunderbird,thunderbird,evolution";
char mailers[256];
DWORD length, type;
HKEY key;
LONG r;
length = sizeof(mailers);
/* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
if (RegCreateKeyEx( HKEY_CURRENT_USER, "Software\\Wine\\WineBrowser", 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL ))
{
fprintf( stderr, "winebrowser: cannot create config key\n" );
return 1;
}
r = RegQueryValueExA( key, "Mailers", 0, &type, (LPBYTE)mailers, &length );
if (r != ERROR_SUCCESS)
{
/* set value to the default */
RegSetValueExA( key, "Mailers", 0, REG_SZ, (LPBYTE)defaultmailers,
lstrlen( defaultmailers ) + 1 );
strcpy( mailers, defaultmailers );
}
RegCloseKey( key );
return launch_app( mailers, url );
}
/*****************************************************************************
* Main entry point. This is a console application so we have a main() not a
* winmain().
*/
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{
const char *argv_new[3];
DWORD maxLength;
CHAR szBrowsers[256];
DWORD type;
const CHAR *defaultBrowsers =
"mozilla,firefox,netscape,konqueror,galeon,opera,dillo";
char *browser;
HKEY hkey;
LONG r;
wine_get_unix_file_name_t wine_get_unix_file_name_ptr;
wine_get_unix_file_name_t wine_get_unix_file_name_ptr;
if (argc <= 1)
{
fprintf( stderr, "Usage: winebrowser URL\n" );
if (argc == 1)
{
fprintf( stderr, "Usage: winebrowser URL\n" );
return 1;
}
/* check if the argument is a local file */
wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
GetProcAddress( GetModuleHandle( "KERNEL32" ), "wine_get_unix_file_name" );
if (wine_get_unix_file_name_ptr == NULL)
{
fprintf( stderr,
"winebrowser: cannot get the address of 'wine_get_unix_file_name'\n" );
}
else
{
char *unixpath;
WCHAR unixpathW[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, argv[1], -1, unixpathW, MAX_PATH );
if ((unixpath = wine_get_unix_file_name_ptr( unixpathW )))
{
struct stat dummy;
if (stat( unixpath, &dummy ) >= 0)
return open_http_url( unixpath );
}
}
if (!strncasecmp( argv[1], "http:", 5 ) || !strncasecmp( argv[1], "https:", 6 ))
return open_http_url( argv[1] );
if (!strncasecmp( argv[1], "mailto:", 7 ))
return open_mailto_url( argv[1] );
fprintf( stderr, "winebrowser: cannot handle this type of URL\n" );
return 1;
}
/* check if the argument is a local file */
wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
GetProcAddress( GetModuleHandle( "KERNEL32"), "wine_get_unix_file_name");
if( wine_get_unix_file_name_ptr == NULL) {
fprintf( stderr, "%s: cannot get the address of "
"'wine_get_unix_file_name'\n", argv[0]);
} else {
WCHAR dospathW[ MAX_PATH];
char *p;
MultiByteToWideChar( CP_ACP, 0, argv[1], -1, dospathW, MAX_PATH);
if((p = wine_get_unix_file_name_ptr( dospathW))) {
struct stat dummy;
if(stat( p, &dummy) >= 0 ) argv[1] = p;
}
}
maxLength = sizeof(szBrowsers);
/* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
if(RegCreateKeyEx( HKEY_CURRENT_USER,
"Software\\Wine\\WineBrowser", 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hkey, NULL))
{
fprintf( stderr, "winebrowser: cannot create config key\n" );
return 1;
}
r = RegQueryValueExA( hkey, "Browsers", 0, &type, (LPBYTE)szBrowsers, &maxLength);
if(r != ERROR_SUCCESS)
{
/* set value to the default */
RegSetValueExA(hkey, "Browsers", 0, REG_SZ,
(LPBYTE)defaultBrowsers, lstrlen(defaultBrowsers) + 1);
strcpy( szBrowsers, defaultBrowsers );
}
RegCloseKey(hkey);
/* now go through the list of browsers until we run out or we find one that */
/* works */
browser = strtok(szBrowsers, ",");
while(browser)
{
argv_new[0] = browser;
argv_new[1] = argv[1];
argv_new[2] = NULL;
spawnvp(_P_OVERLAY, browser, argv_new); /* only returns on error */
browser = strtok(NULL, ","); /* grab the next browser */
}
fprintf( stderr, "winebrowser: could not find a browser to run\n" );
return 1;
}

View File

@ -110,6 +110,7 @@ HKCR,Msi.Package\shell\Uninstall\command,,,"msiexec /x %1"
HKCR,txtfile\shell\open\command,,,"%11%\notepad.exe %1"
HKCR,txtfile\shell\print\command,,,"%11%\notepad.exe /p %1"
HKCR,http\shell\open\command,,,"winebrowser %1"
HKCR,mailto\shell\open\command,,,"winebrowser %1"
; FIXME: the following should be done by the dll registration
HKCR,AVIFile\Compressors\auds,,,"{0002000F-0000-0000-C000-000000000046}"
HKCR,AVIFile\Compressors\vids,,,"{00020001-0000-0000-C000-000000000046}"