зеркало из https://github.com/mozilla/gecko-dev.git
Implement nsIShellService for GNOME (bug 242254). r=biesi, sr=shaver. Note: set as wallpaper for images that use transparency will be broken until bug 250531 is fixed. This also makes toolkit/ always be pulled in preparation for migrating more code to the new GNOME XPCOM interfaces.
This commit is contained in:
Родитель
faca1b8a02
Коммит
d1e00151e6
|
@ -0,0 +1,81 @@
|
|||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is the Mozilla GNOME integration code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# IBM Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2004
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Brian Ryner <bryner@brianryner.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = mozgnome
|
||||
LIBRARY_NAME = mozgnome
|
||||
FORCE_SHARED_LIB = 1
|
||||
IS_COMPONENT = 1
|
||||
|
||||
REQUIRES = \
|
||||
xpcom \
|
||||
string \
|
||||
necko \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIGConfService.idl \
|
||||
nsIGnomeVFSService.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsGConfService.cpp \
|
||||
nsGnomeVFSService.cpp \
|
||||
nsGnomeModule.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
$(MOZ_GCONF_LIBS) \
|
||||
$(MOZ_GNOMEVFS_LIBS) \
|
||||
$(MOZ_LIBGNOME_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
CXXFLAGS += \
|
||||
$(MOZ_GCONF_CFLAGS) \
|
||||
$(MOZ_GNOMEVFS_CFLAGS) \
|
||||
$(MOZ_LIBGNOME_CFLAGS) \
|
||||
$(NULL)
|
||||
|
|
@ -0,0 +1,233 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla GNOME integration code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsGConfService.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include <gconf/gconf-client.h>
|
||||
|
||||
nsGConfService::~nsGConfService()
|
||||
{
|
||||
if (mClient)
|
||||
g_object_unref(mClient);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGConfService::Init()
|
||||
{
|
||||
mClient = gconf_client_get_default();
|
||||
return mClient ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsGConfService, nsIGConfService)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::GetBool(const nsACString &aKey, PRBool *aResult)
|
||||
{
|
||||
GError* error = nsnull;
|
||||
*aResult = gconf_client_get_bool(mClient, PromiseFlatCString(aKey).get(),
|
||||
&error);
|
||||
|
||||
if (error) {
|
||||
g_error_free(error);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::GetString(const nsACString &aKey, nsACString &aResult)
|
||||
{
|
||||
GError* error = nsnull;
|
||||
gchar *result = gconf_client_get_string(mClient,
|
||||
PromiseFlatCString(aKey).get(),
|
||||
&error);
|
||||
|
||||
if (error) {
|
||||
g_error_free(error);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// We do a string copy here so that the caller doesn't need to worry about
|
||||
// freeing the string with g_free().
|
||||
|
||||
aResult.Assign(result);
|
||||
g_free(result);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::GetInt(const nsACString &aKey, PRInt32* aResult)
|
||||
{
|
||||
GError* error = nsnull;
|
||||
*aResult = gconf_client_get_int(mClient, PromiseFlatCString(aKey).get(),
|
||||
&error);
|
||||
|
||||
if (error) {
|
||||
g_error_free(error);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::GetFloat(const nsACString &aKey, float* aResult)
|
||||
{
|
||||
GError* error = nsnull;
|
||||
*aResult = gconf_client_get_float(mClient, PromiseFlatCString(aKey).get(),
|
||||
&error);
|
||||
|
||||
if (error) {
|
||||
g_error_free(error);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::SetBool(const nsACString &aKey, PRBool aValue)
|
||||
{
|
||||
PRBool res = gconf_client_set_bool(mClient, PromiseFlatCString(aKey).get(),
|
||||
aValue, nsnull);
|
||||
|
||||
return res ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::SetString(const nsACString &aKey, const nsACString &aValue)
|
||||
{
|
||||
PRBool res = gconf_client_set_string(mClient, PromiseFlatCString(aKey).get(),
|
||||
PromiseFlatCString(aValue).get(),
|
||||
nsnull);
|
||||
|
||||
return res ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::SetInt(const nsACString &aKey, PRInt32 aValue)
|
||||
{
|
||||
PRBool res = gconf_client_set_int(mClient, PromiseFlatCString(aKey).get(),
|
||||
aValue, nsnull);
|
||||
|
||||
return res ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::SetFloat(const nsACString &aKey, float aValue)
|
||||
{
|
||||
PRBool res = gconf_client_set_float(mClient, PromiseFlatCString(aKey).get(),
|
||||
aValue, nsnull);
|
||||
|
||||
return res ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::GetAppForProtocol(const nsACString &aScheme, PRBool *aEnabled,
|
||||
nsACString &aHandler)
|
||||
{
|
||||
nsCAutoString key(NS_LITERAL_CSTRING("/desktop/gnome/url-handlers/")
|
||||
+ aScheme + NS_LITERAL_CSTRING("/command"));
|
||||
|
||||
GError *err = nsnull;
|
||||
gchar *command = gconf_client_get_string(mClient, key.get(), &err);
|
||||
if (!err && command) {
|
||||
key.Replace(key.Length() - 7, 7, NS_LITERAL_CSTRING("enabled"));
|
||||
*aEnabled = gconf_client_get_bool(mClient, key.get(), &err);
|
||||
} else {
|
||||
*aEnabled = PR_FALSE;
|
||||
}
|
||||
|
||||
aHandler.Assign(command);
|
||||
if (command)
|
||||
g_free(command);
|
||||
|
||||
if (err) {
|
||||
g_error_free(err);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::HandlerRequiresTerminal(const nsACString &aScheme,
|
||||
PRBool *aResult)
|
||||
{
|
||||
nsCAutoString key(NS_LITERAL_CSTRING("/desktop/gnome/url-handlers/")
|
||||
+ aScheme + NS_LITERAL_CSTRING("/requires_terminal"));
|
||||
|
||||
GError *err = nsnull;
|
||||
*aResult = gconf_client_get_bool(mClient, key.get(), &err);
|
||||
if (err) {
|
||||
g_error_free(err);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGConfService::SetAppForProtocol(const nsACString &aScheme,
|
||||
const nsACString &aCommand)
|
||||
{
|
||||
nsCAutoString key(NS_LITERAL_CSTRING("/desktop/gnome/url-handlers/")
|
||||
+ aScheme + NS_LITERAL_CSTRING("/command"));
|
||||
|
||||
PRBool res = gconf_client_set_string(mClient, key.get(),
|
||||
PromiseFlatCString(aCommand).get(),
|
||||
nsnull);
|
||||
if (res) {
|
||||
key.Replace(key.Length() - 7, 7, NS_LITERAL_CSTRING("enabled"));
|
||||
res = gconf_client_set_bool(mClient, key.get(), PR_TRUE, nsnull);
|
||||
if (res) {
|
||||
key.Replace(key.Length() - 7, 7, NS_LITERAL_CSTRING("needs_terminal"));
|
||||
res = gconf_client_set_bool(mClient, key.get(), PR_FALSE, nsnull);
|
||||
if (res) {
|
||||
key.Replace(key.Length() - 14, 14, NS_LITERAL_CSTRING("command-id"));
|
||||
res = gconf_client_unset(mClient, key.get(), nsnull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla GNOME integration code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsGConfService_h_
|
||||
#define nsGConfService_h_
|
||||
|
||||
#include "nsIGConfService.h"
|
||||
#include "gconf/gconf-client.h"
|
||||
|
||||
#define NS_GCONFSERVICE_CID \
|
||||
{0xd96d5985, 0xa13a, 0x4bdc, {0x93, 0x86, 0xef, 0x34, 0x8d, 0x7a, 0x97, 0xa1}}
|
||||
|
||||
class nsGConfService : public nsIGConfService
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGCONFSERVICE
|
||||
|
||||
nsGConfService() : mClient(nsnull) {}
|
||||
NS_HIDDEN_(nsresult) Init();
|
||||
|
||||
private:
|
||||
~nsGConfService() NS_HIDDEN;
|
||||
|
||||
GConfClient *mClient;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla GNOME integration code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsGConfService.h"
|
||||
#include "nsGnomeVFSService.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGConfService, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGnomeVFSService, Init)
|
||||
|
||||
static const nsModuleComponentInfo components[] = {
|
||||
{ "GConf Service",
|
||||
NS_GCONFSERVICE_CID,
|
||||
NS_GCONFSERVICE_CONTRACTID,
|
||||
nsGConfServiceConstructor },
|
||||
{ "GnomeVFS Service",
|
||||
NS_GNOMEVFSSERVICE_CID,
|
||||
NS_GNOMEVFSSERVICE_CONTRACTID,
|
||||
nsGnomeVFSServiceConstructor }
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(mozgnome, components)
|
|
@ -0,0 +1,277 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla GNOME integration code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsGnomeVFSService.h"
|
||||
#include "nsStringEnumerator.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
extern "C" {
|
||||
#include <libgnomevfs/gnome-vfs-application-registry.h>
|
||||
#include <libgnomevfs/gnome-vfs-init.h>
|
||||
#include <libgnomevfs/gnome-vfs-mime.h>
|
||||
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
|
||||
#include <libgnomevfs/gnome-vfs-mime-info.h>
|
||||
#include <libgnome/gnome-url.h>
|
||||
}
|
||||
|
||||
class nsGnomeVFSMimeApp : public nsIGnomeVFSMimeApp
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGNOMEVFSMIMEAPP
|
||||
|
||||
nsGnomeVFSMimeApp(GnomeVFSMimeApplication* aApp) : mApp(aApp) {}
|
||||
~nsGnomeVFSMimeApp() { gnome_vfs_mime_application_free(mApp); }
|
||||
|
||||
private:
|
||||
GnomeVFSMimeApplication *mApp;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsGnomeVFSMimeApp, nsIGnomeVFSMimeApp)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSMimeApp::GetId(nsACString& aId)
|
||||
{
|
||||
aId.Assign(mApp->id);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSMimeApp::GetName(nsACString& aName)
|
||||
{
|
||||
aName.Assign(mApp->name);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSMimeApp::GetCommand(nsACString& aCommand)
|
||||
{
|
||||
aCommand.Assign(mApp->command);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSMimeApp::GetCanOpenMultipleFiles(PRBool* aCanOpen)
|
||||
{
|
||||
*aCanOpen = mApp->can_open_multiple_files;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSMimeApp::GetExpectsURIs(PRInt32* aExpects)
|
||||
{
|
||||
*aExpects = mApp->expects_uris;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSMimeApp::GetSupportedURISchemes(nsIUTF8StringEnumerator** aSchemes)
|
||||
{
|
||||
*aSchemes = nsnull;
|
||||
|
||||
nsCStringArray *array = new nsCStringArray();
|
||||
NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
for (GList *list = mApp->supported_uri_schemes; list; list = list->next) {
|
||||
if (!array->AppendCString(nsDependentCString((char*) list->data))) {
|
||||
delete array;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_NewAdoptingUTF8StringEnumerator(aSchemes, array);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSMimeApp::GetRequiresTerminal(PRBool* aRequires)
|
||||
{
|
||||
*aRequires = mApp->requires_terminal;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGnomeVFSService::Init()
|
||||
{
|
||||
return gnome_vfs_init() ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsGnomeVFSService, nsIGnomeVFSService)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::GetMimeTypeFromExtension(const nsACString &aExtension,
|
||||
nsACString& aMimeType)
|
||||
{
|
||||
nsCAutoString fileExtToUse(NS_LITERAL_CSTRING(".") + aExtension);
|
||||
|
||||
const char *mimeType = gnome_vfs_mime_type_from_name(fileExtToUse.get());
|
||||
aMimeType.Assign(mimeType);
|
||||
|
||||
// |mimeType| points to internal gnome-vfs data, so don't free it.
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::GetAppForMimeType(const nsACString &aMimeType,
|
||||
nsIGnomeVFSMimeApp** aApp)
|
||||
{
|
||||
*aApp = nsnull;
|
||||
GnomeVFSMimeApplication *app =
|
||||
gnome_vfs_mime_get_default_application(PromiseFlatCString(aMimeType).get());
|
||||
|
||||
if (app) {
|
||||
nsGnomeVFSMimeApp *mozApp = new nsGnomeVFSMimeApp(app);
|
||||
NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(*aApp = mozApp);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::SetAppForMimeType(const nsACString &aMimeType,
|
||||
const nsACString &aId)
|
||||
{
|
||||
gnome_vfs_mime_set_default_application(PromiseFlatCString(aMimeType).get(),
|
||||
PromiseFlatCString(aId).get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::SetIconForMimeType(const nsACString &aMimeType,
|
||||
const nsACString &aIconName)
|
||||
{
|
||||
gnome_vfs_mime_set_icon(PromiseFlatCString(aMimeType).get(),
|
||||
PromiseFlatCString(aIconName).get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::GetDescriptionForMimeType(const nsACString &aMimeType,
|
||||
nsACString& aDescription)
|
||||
{
|
||||
const char *desc =
|
||||
gnome_vfs_mime_get_description(PromiseFlatCString(aMimeType).get());
|
||||
aDescription.Assign(desc);
|
||||
|
||||
// |desc| points to internal gnome-vfs data, so don't free it.
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::ShowURI(nsIURI *aURI)
|
||||
{
|
||||
nsCAutoString spec;
|
||||
aURI->GetSpec(spec);
|
||||
|
||||
if (gnome_url_show(spec.get(), NULL))
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::SetAppStringKey(const nsACString &aID,
|
||||
PRInt32 aKey,
|
||||
const nsACString &aValue)
|
||||
{
|
||||
const char *key;
|
||||
|
||||
if (aKey == APP_KEY_COMMAND)
|
||||
key = GNOME_VFS_APPLICATION_REGISTRY_COMMAND;
|
||||
else if (aKey == APP_KEY_NAME)
|
||||
key = GNOME_VFS_APPLICATION_REGISTRY_NAME;
|
||||
else if (aKey == APP_KEY_SUPPORTED_URI_SCHEMES)
|
||||
key = "supported_uri_schemes";
|
||||
else if (aKey == APP_KEY_EXPECTS_URIS)
|
||||
key = "expects_uris";
|
||||
else
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
gnome_vfs_application_registry_set_value(PromiseFlatCString(aID).get(), key,
|
||||
PromiseFlatCString(aValue).get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::SetAppBoolKey(const nsACString &aID,
|
||||
PRInt32 aKey,
|
||||
PRBool aValue)
|
||||
{
|
||||
const char *key;
|
||||
|
||||
if (aKey == APP_KEY_CAN_OPEN_MULTIPLE)
|
||||
key = GNOME_VFS_APPLICATION_REGISTRY_CAN_OPEN_MULTIPLE_FILES;
|
||||
else if (aKey == APP_KEY_REQUIRES_TERMINAL)
|
||||
key = GNOME_VFS_APPLICATION_REGISTRY_REQUIRES_TERMINAL;
|
||||
else
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
gnome_vfs_application_registry_set_bool_value(PromiseFlatCString(aID).get(),
|
||||
key, aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::AddMimeType(const nsACString &aID, const nsACString &aType)
|
||||
{
|
||||
gnome_vfs_application_registry_add_mime_type(PromiseFlatCString(aID).get(),
|
||||
PromiseFlatCString(aType).get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::SyncAppRegistry()
|
||||
{
|
||||
gnome_vfs_application_registry_sync();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGnomeVFSService::SetMimeExtensions(const nsACString &aMimeType,
|
||||
const nsACString &aExtensionsList)
|
||||
{
|
||||
GnomeVFSResult res =
|
||||
gnome_vfs_mime_set_extensions_list(PromiseFlatCString(aMimeType).get(),
|
||||
PromiseFlatCString(aExtensionsList).get());
|
||||
return (res == GNOME_VFS_OK) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla GNOME integration code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsGnomeVFSService_h_
|
||||
#define nsGnomeVFSService_h_
|
||||
|
||||
#include "nsIGnomeVFSService.h"
|
||||
|
||||
#define NS_GNOMEVFSSERVICE_CID \
|
||||
{0x5f43022c, 0x6194, 0x4b37, {0xb2, 0x6d, 0xe4, 0x10, 0x24, 0x62, 0x52, 0x64}}
|
||||
|
||||
class nsGnomeVFSService : public nsIGnomeVFSService
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGNOMEVFSSERVICE
|
||||
|
||||
NS_HIDDEN_(nsresult) Init();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,75 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla GNOME integration code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(01ac7b2e-c07c-465f-b35c-542eaef420a9)]
|
||||
interface nsIGConfService : nsISupports
|
||||
{
|
||||
/* Basic registry access */
|
||||
boolean getBool(in AUTF8String key);
|
||||
AUTF8String getString(in AUTF8String key);
|
||||
long getInt(in AUTF8String key);
|
||||
float getFloat(in AUTF8String key);
|
||||
|
||||
void setBool(in AUTF8String key, in boolean value);
|
||||
void setString(in AUTF8String key, in AUTF8String value);
|
||||
void setInt(in AUTF8String key, in long value);
|
||||
void setFloat(in AUTF8String key, in float value);
|
||||
|
||||
/*
|
||||
* Look up the handler for a protocol under the
|
||||
* /desktop/gnome/url-handlers hierarchy.
|
||||
*/
|
||||
AUTF8String getAppForProtocol(in AUTF8String scheme, out boolean enabled);
|
||||
|
||||
/*
|
||||
* Check whether the handler for a scheme requires a terminal to run.
|
||||
*/
|
||||
boolean handlerRequiresTerminal(in AUTF8String scheme);
|
||||
|
||||
/*
|
||||
* Set the handler for a protocol, marking it as enabled.
|
||||
* This removes any GnomeVFSMimeApp association for the protocol.
|
||||
*/
|
||||
void setAppForProtocol(in AUTF8String scheme, in AUTF8String command);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_GCONFSERVICE_CONTRACTID "@mozilla.org/gnome-gconf-service;1"
|
||||
%}
|
|
@ -0,0 +1,150 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla GNOME integration code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* IBM Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIUTF8StringEnumerator;
|
||||
interface nsIURI;
|
||||
|
||||
/* nsIGnomeVFSMimeApp holds information about an application that is looked up
|
||||
with nsIGnomeVFSService::GetAppForMimeType. */
|
||||
|
||||
[scriptable, uuid(99ae024f-e869-4973-958b-54768a84295a)]
|
||||
interface nsIGnomeVFSMimeApp : nsISupports
|
||||
{
|
||||
const long EXPECTS_URIS = 0;
|
||||
const long EXPECTS_PATHS = 1;
|
||||
const long EXPECTS_URIS_FOR_NON_FILES = 2;
|
||||
|
||||
readonly attribute AUTF8String id;
|
||||
readonly attribute AUTF8String name;
|
||||
readonly attribute AUTF8String command;
|
||||
readonly attribute boolean canOpenMultipleFiles;
|
||||
readonly attribute long expectsURIs; // see constants above
|
||||
readonly attribute nsIUTF8StringEnumerator supportedURISchemes;
|
||||
readonly attribute boolean requiresTerminal;
|
||||
};
|
||||
|
||||
/*
|
||||
* The VFS service makes use of two distinct registries.
|
||||
*
|
||||
* The application registry holds information about applications (uniquely
|
||||
* identified by id), such as which MIME types and URI schemes they are
|
||||
* capable of handling, whether they run in a terminal, etc.
|
||||
*
|
||||
* The MIME registry holds information about MIME types, such as which
|
||||
* extensions map to a given MIME type. The MIME registry also stores the
|
||||
* id of the application selected to handle each MIME type.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(4d6b9f23-8682-41b3-bbff-937a958e6496)]
|
||||
interface nsIGnomeVFSService : nsISupports
|
||||
{
|
||||
/*** Application registry methods ***/
|
||||
|
||||
/* string keys */
|
||||
const long APP_KEY_COMMAND = 0;
|
||||
const long APP_KEY_NAME = 1;
|
||||
const long APP_KEY_SUPPORTED_URI_SCHEMES = 2; /* comma-separated list */
|
||||
const long APP_KEY_EXPECTS_URIS = 3; /* "true", "false", or "non-file" */
|
||||
|
||||
/* Set one of the above string keys for the given application id.
|
||||
'id' can be an arbitrary, unique string to identify the application. */
|
||||
void setAppStringKey(in AUTF8String id,
|
||||
in long key, /* see enums above */
|
||||
in AUTF8String value);
|
||||
|
||||
/* boolean keys */
|
||||
const long APP_KEY_CAN_OPEN_MULTIPLE = 4;
|
||||
const long APP_KEY_REQUIRES_TERMINAL = 5;
|
||||
|
||||
/* Set one of the above boolean keys for the given application id.
|
||||
'id' can be an arbitrary, unique string to identify the application. */
|
||||
void setAppBoolKey(in AUTF8String id,
|
||||
in long key,
|
||||
in boolean value);
|
||||
|
||||
|
||||
/* Add a MIME type to the list of types that the application can handle */
|
||||
void addMimeType(in AUTF8String id,
|
||||
in AUTF8String mimeType);
|
||||
|
||||
/* Commit application registry changes to disk. This must be called
|
||||
to save changes. */
|
||||
void syncAppRegistry();
|
||||
|
||||
|
||||
/*** MIME registry methods ***/
|
||||
|
||||
/* Obtain the MIME type registered for an extension. The extension
|
||||
should not include a leading dot. */
|
||||
AUTF8String getMimeTypeFromExtension(in AUTF8String extension);
|
||||
|
||||
/* Obtain the preferred application for opening a given MIME type */
|
||||
nsIGnomeVFSMimeApp getAppForMimeType(in AUTF8String mimeType);
|
||||
|
||||
/* Set the preferred application for opening a given MIME type */
|
||||
void setAppForMimeType(in AUTF8String mimeType,
|
||||
in AUTF8String id);
|
||||
|
||||
/* Obtain a description for the given MIME type */
|
||||
AUTF8String getDescriptionForMimeType(in AUTF8String mimeType);
|
||||
|
||||
/* Set the icon for a MIME type, which will be searched for by the shell
|
||||
using the icon theme search path. */
|
||||
void setIconForMimeType(in AUTF8String mimeType,
|
||||
in AUTF8String iconPath);
|
||||
|
||||
/*
|
||||
* Set the list of extensions for a given MIME type.
|
||||
* Should be passed a space separated list of extensions with no
|
||||
* dot, i.e. "gif jpg png".
|
||||
*/
|
||||
void setMimeExtensions(in AUTF8String mimeType,
|
||||
in AUTF8String extensionsList);
|
||||
|
||||
|
||||
/*** Misc. methods ***/
|
||||
|
||||
/* Open the given URI in the default application */
|
||||
void showURI(in nsIURI uri);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_GNOMEVFSSERVICE_CONTRACTID "@mozilla.org/gnome-vfs-service;1"
|
||||
%}
|
Загрузка…
Ссылка в новой задаче