michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: interface nsIFile; michael@0: michael@0: /** michael@0: * The nsIRelativeFilePref interface is a wrapper for an nsIFile and michael@0: * and a directory service key. When used as a pref value, it stores a michael@0: * relative path to the file from the location pointed to by the directory michael@0: * service key. The path has the same syntax across all platforms. michael@0: * michael@0: * @see nsIPrefBranch::getComplexValue michael@0: * @see nsIPrefBranch::setComplexValue michael@0: * michael@0: */ michael@0: michael@0: [scriptable, uuid(2f977d4e-5485-11d4-87e2-0010a4e75ef2)] michael@0: interface nsIRelativeFilePref : nsISupports michael@0: { michael@0: /** michael@0: * file michael@0: * michael@0: * The file whose location is stored or retrieved. michael@0: */ michael@0: attribute nsIFile file; michael@0: michael@0: /** michael@0: * relativeToKey michael@0: * michael@0: * A directory service key for the directory michael@0: * from which the file path is relative. michael@0: */ michael@0: attribute ACString relativeToKey; michael@0: michael@0: }; michael@0: michael@0: %{C++ michael@0: michael@0: #define NS_RELATIVEFILEPREF_CID \ michael@0: { /* {2f977d4f-5485-11d4-87e2-0010a4e75ef2} */ \ michael@0: 0x2f977d4f, \ michael@0: 0x5485, \ michael@0: 0x11d4, \ michael@0: { 0x87, 0xe2, 0x00, 0x10, 0xa4, 0xe7, 0x5e, 0xf2 } \ michael@0: } michael@0: michael@0: #define NS_RELATIVEFILEPREF_CONTRACTID "@mozilla.org/pref-relativefile;1" michael@0: michael@0: #include "nsComponentManagerUtils.h" michael@0: michael@0: inline nsresult michael@0: NS_NewRelativeFilePref(nsIFile* aFile, const nsACString& relativeToKey, nsIRelativeFilePref** result) michael@0: { michael@0: nsresult rv; michael@0: nsCOMPtr local(do_CreateInstance(NS_RELATIVEFILEPREF_CONTRACTID, &rv)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: (void)local->SetFile(aFile); michael@0: (void)local->SetRelativeToKey(relativeToKey); michael@0: michael@0: *result = local; michael@0: NS_ADDREF(*result); michael@0: return NS_OK; michael@0: } michael@0: michael@0: %}