1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_fpicker.hxx" 30*cdf0e10cSrcweir #include "sal/types.h" 31*cdf0e10cSrcweir #include "rtl/ustring.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ 34*cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx" 35*cdf0e10cSrcweir #endif 36*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp" 37*cdf0e10cSrcweir #include "svtools/miscopt.hxx" 38*cdf0e10cSrcweir #include "svl/pickerhistoryaccess.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #ifndef _SV_APP_HXX 41*cdf0e10cSrcweir #include "vcl/svapp.hxx" 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace css = com::sun::star; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using css::uno::Reference; 47*cdf0e10cSrcweir using css::uno::Sequence; 48*cdf0e10cSrcweir using rtl::OUString; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir /* 51*cdf0e10cSrcweir * FilePicker implementation. 52*cdf0e10cSrcweir */ 53*cdf0e10cSrcweir static OUString FilePicker_getSystemPickerServiceName() 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir OUString aDesktopEnvironment (Application::GetDesktopEnvironment()); 56*cdf0e10cSrcweir if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("gnome")) 57*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.GtkFilePicker")); 58*cdf0e10cSrcweir else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("kde")) 59*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDEFilePicker")); 60*cdf0e10cSrcweir else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("kde4")) 61*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDE4FilePicker")); 62*cdf0e10cSrcweir else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("macosx")) 63*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.AquaFilePicker")); 64*cdf0e10cSrcweir else 65*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.SystemFilePicker")); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir static Reference< css::uno::XInterface > FilePicker_createInstance ( 69*cdf0e10cSrcweir Reference< css::uno::XComponentContext > const & rxContext) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir Reference< css::uno::XInterface > xResult; 72*cdf0e10cSrcweir if (rxContext.is()) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager()); 75*cdf0e10cSrcweir if (xFactory.is()) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir if (SvtMiscOptions().UseSystemFileDialog()) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir try 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir xResult = xFactory->createInstanceWithContext ( 82*cdf0e10cSrcweir FilePicker_getSystemPickerServiceName(), 83*cdf0e10cSrcweir rxContext); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir catch (css::uno::Exception const &) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir // Handled below (see @ fallback). 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir if (!xResult.is()) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir // Always fall back to OfficeFilePicker. 93*cdf0e10cSrcweir xResult = xFactory->createInstanceWithContext ( 94*cdf0e10cSrcweir OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFilePicker")), 95*cdf0e10cSrcweir rxContext); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir if (xResult.is()) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir // Add to FilePicker history. 100*cdf0e10cSrcweir svt::addFilePicker (xResult); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir return xResult; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir static OUString FilePicker_getImplementationName() 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.comp.fpicker.FilePicker")); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir static Sequence< OUString > FilePicker_getSupportedServiceNames() 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir Sequence< OUString > aServiceNames(1); 115*cdf0e10cSrcweir aServiceNames.getArray()[0] = 116*cdf0e10cSrcweir OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker")); 117*cdf0e10cSrcweir return aServiceNames; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir /* 121*cdf0e10cSrcweir * FolderPicker implementation. 122*cdf0e10cSrcweir */ 123*cdf0e10cSrcweir static OUString FolderPicker_getSystemPickerServiceName() 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir OUString aDesktopEnvironment (Application::GetDesktopEnvironment()); 126*cdf0e10cSrcweir if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("gnome")) 127*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.GtkFolderPicker")); 128*cdf0e10cSrcweir else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("kde")) 129*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDEFolderPicker")); 130*cdf0e10cSrcweir else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("macosx")) 131*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.AquaFolderPicker")); 132*cdf0e10cSrcweir else 133*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.SystemFolderPicker")); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir static Reference< css::uno::XInterface > FolderPicker_createInstance ( 137*cdf0e10cSrcweir Reference< css::uno::XComponentContext > const & rxContext) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir Reference< css::uno::XInterface > xResult; 140*cdf0e10cSrcweir if (rxContext.is()) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager()); 143*cdf0e10cSrcweir if (xFactory.is()) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir if (SvtMiscOptions().UseSystemFileDialog()) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir try 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir xResult = xFactory->createInstanceWithContext ( 150*cdf0e10cSrcweir FolderPicker_getSystemPickerServiceName(), 151*cdf0e10cSrcweir rxContext); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir catch (css::uno::Exception const &) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir // Handled below (see @ fallback). 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir if (!xResult.is()) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir // Always fall back to OfficeFolderPicker. 161*cdf0e10cSrcweir xResult = xFactory->createInstanceWithContext ( 162*cdf0e10cSrcweir OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFolderPicker")), 163*cdf0e10cSrcweir rxContext); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir if (xResult.is()) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir // Add to FolderPicker history. 168*cdf0e10cSrcweir svt::addFolderPicker (xResult); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir return xResult; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir static OUString FolderPicker_getImplementationName() 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.comp.fpicker.FolderPicker")); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir static Sequence< OUString > FolderPicker_getSupportedServiceNames() 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir Sequence< OUString > aServiceNames(1); 183*cdf0e10cSrcweir aServiceNames.getArray()[0] = 184*cdf0e10cSrcweir OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker")); 185*cdf0e10cSrcweir return aServiceNames; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir /* 189*cdf0e10cSrcweir * Implementation entries. 190*cdf0e10cSrcweir */ 191*cdf0e10cSrcweir static cppu::ImplementationEntry g_entries[] = 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir FilePicker_createInstance, 195*cdf0e10cSrcweir FilePicker_getImplementationName, 196*cdf0e10cSrcweir FilePicker_getSupportedServiceNames, 197*cdf0e10cSrcweir cppu::createSingleComponentFactory, 0, 0 198*cdf0e10cSrcweir }, 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir FolderPicker_createInstance, 201*cdf0e10cSrcweir FolderPicker_getImplementationName, 202*cdf0e10cSrcweir FolderPicker_getSupportedServiceNames, 203*cdf0e10cSrcweir cppu::createSingleComponentFactory, 0, 0 204*cdf0e10cSrcweir }, 205*cdf0e10cSrcweir { 0, 0, 0, 0, 0, 0 } 206*cdf0e10cSrcweir }; 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir /* 209*cdf0e10cSrcweir * Public (exported) interface. 210*cdf0e10cSrcweir */ 211*cdf0e10cSrcweir extern "C" 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment ( 214*cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory ( 220*cdf0e10cSrcweir const sal_Char * pImplementationName, void * pServiceManager, void * pRegistryKey) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir return cppu::component_getFactoryHelper ( 223*cdf0e10cSrcweir pImplementationName, pServiceManager, pRegistryKey, g_entries); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir } // extern "C" 227