From b40ffd288baf6dc5989cc09c5b5007eee97dd1bf Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Fri, 25 Oct 2013 13:56:34 -0200 Subject: fdo#60698: Move generic fpicker to svtools Signed-off-by: Stephan Bergmann Conflicts: dictionaries Change-Id: I6af478d7d6952e0e8f6c8f1b0575fcd50f2ba0e4 --- svtools/Library_svt.mk | 1 + svtools/source/uno/fpicker.cxx | 188 ++++++++++++++++++++++++++++++++++++ svtools/source/uno/fpicker.hxx | 47 +++++++++ svtools/source/uno/miscservices.cxx | 29 ++++-- svtools/util/svt.component | 6 ++ 5 files changed, 262 insertions(+), 9 deletions(-) create mode 100644 svtools/source/uno/fpicker.cxx create mode 100644 svtools/source/uno/fpicker.hxx (limited to 'svtools') diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk index b18370f2e794..11706c60969f 100644 --- a/svtools/Library_svt.mk +++ b/svtools/Library_svt.mk @@ -220,6 +220,7 @@ $(eval $(call gb_Library_add_exception_objects,svt,\ svtools/source/toolpanel/toolpaneldrawerpeer \ svtools/source/uno/addrtempuno \ svtools/source/uno/contextmenuhelper \ + svtools/source/uno/fpicker \ svtools/source/uno/framestatuslistener \ svtools/source/uno/generictoolboxcontroller \ svtools/source/uno/genericunodialog \ diff --git a/svtools/source/uno/fpicker.cxx b/svtools/source/uno/fpicker.cxx new file mode 100644 index 000000000000..81f2c6f1df9c --- /dev/null +++ b/svtools/source/uno/fpicker.cxx @@ -0,0 +1,188 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#include "sal/types.h" +#include "rtl/ustring.hxx" + +#include "com/sun/star/lang/XMultiComponentFactory.hpp" + +#include "svtools/miscopt.hxx" +#include "svl/pickerhistoryaccess.hxx" + +#include "vcl/svapp.hxx" + +#ifdef WNT +#include +#endif + +using css::uno::Reference; +using css::uno::Sequence; + +/* + * FilePicker implementation. + */ +static OUString FilePicker_getSystemPickerServiceName() +{ +#ifdef UNX + OUString aDesktopEnvironment (Application::GetDesktopEnvironment()); + if (aDesktopEnvironment.equalsIgnoreAsciiCase("tde")) + return OUString ("com.sun.star.ui.dialogs.TDEFilePicker"); + else if (aDesktopEnvironment.equalsIgnoreAsciiCase("kde")) + return OUString ("com.sun.star.ui.dialogs.KDEFilePicker"); + else if (aDesktopEnvironment.equalsIgnoreAsciiCase("kde4")) + return OUString ("com.sun.star.ui.dialogs.KDE4FilePicker"); + else if (aDesktopEnvironment.equalsIgnoreAsciiCase("macosx")) + return OUString ("com.sun.star.ui.dialogs.AquaFilePicker"); + else + return OUString ("com.sun.star.ui.dialogs.SystemFilePicker"); +#endif +#ifdef WNT + return OUString ("com.sun.star.ui.dialogs.Win32FilePicker"); +#endif +} + +Reference< css::uno::XInterface > FilePicker_CreateInstance ( + Reference< css::uno::XComponentContext > const & rxContext) +{ + Reference< css::uno::XInterface > xResult; + + if (!rxContext.is()) + return xResult; + + Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager()); + if (xFactory.is() && SvtMiscOptions().UseSystemFileDialog()) + { + xResult = Reference< css::uno::XInterface >( Application::createFilePicker( rxContext ) ); + + if (!xResult.is()) + { + try + { + xResult = xFactory->createInstanceWithContext ( + FilePicker_getSystemPickerServiceName(), + rxContext); + } + catch (css::uno::Exception const &) + { + // Handled below (see @ fallback). + } + } + } + + + if (!xResult.is() && xFactory.is()) + { + // Always fall back to OfficeFilePicker. + xResult = xFactory->createInstanceWithContext ( + OUString( "com.sun.star.ui.dialogs.OfficeFilePicker"), + rxContext); + } + if (xResult.is()) + { + // Add to FilePicker history. + svt::addFilePicker (xResult); + } + return xResult; +} + +OUString SAL_CALL FilePicker_getImplementationName() +{ + return OUString("com.sun.star.comp.svt.FilePicker"); +} + +Sequence< OUString > FilePicker_getSupportedServiceNames() +{ + Sequence< OUString > aServiceNames(1); + aServiceNames.getArray()[0] = + OUString( "com.sun.star.ui.dialogs.FilePicker"); + return aServiceNames; +} + +/* + * FolderPicker implementation. + */ +static OUString FolderPicker_getSystemPickerServiceName() +{ + OUString aDesktopEnvironment (Application::GetDesktopEnvironment()); +#ifdef UNX + if (aDesktopEnvironment.equalsIgnoreAsciiCase("tde")) + return OUString("com.sun.star.ui.dialogs.TDEFolderPicker"); + else if (aDesktopEnvironment.equalsIgnoreAsciiCase("kde")) + return OUString("com.sun.star.ui.dialogs.KDEFolderPicker"); + else if (aDesktopEnvironment.equalsIgnoreAsciiCase("macosx")) + return OUString("com.sun.star.ui.dialogs.AquaFolderPicker"); +#endif + return OUString("com.sun.star.ui.dialogs.SystemFolderPicker"); +} + +Reference< css::uno::XInterface > FolderPicker_CreateInstance ( + Reference< css::uno::XComponentContext > const & rxContext) +{ + Reference< css::uno::XInterface > xResult; + + if (!rxContext.is()) + return xResult; + + Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager()); + if (xFactory.is() && SvtMiscOptions().UseSystemFileDialog()) + { + xResult = Reference< css::uno::XInterface >( Application::createFolderPicker( rxContext ) ); + if (!xResult.is()) + { + try + { + xResult = xFactory->createInstanceWithContext ( + FolderPicker_getSystemPickerServiceName(), + rxContext); + } + catch (css::uno::Exception const &) + { + // Handled below (see @ fallback). + } + } + } + if (!xResult.is() && xFactory.is() ) + { + // Always fall back to OfficeFolderPicker. + xResult = xFactory->createInstanceWithContext ( + OUString( "com.sun.star.ui.dialogs.OfficeFolderPicker"), + rxContext); + } + if (xResult.is()) + { + // Add to FolderPicker history. + svt::addFolderPicker (xResult); + } + return xResult; +} + +OUString SAL_CALL FolderPicker_getImplementationName() +{ + return OUString("com.sun.star.comp.svt.FolderPicker"); +} + +Sequence< OUString > FolderPicker_getSupportedServiceNames() +{ + Sequence< OUString > aServiceNames(1); + aServiceNames.getArray()[0] = + OUString( "com.sun.star.ui.dialogs.FolderPicker"); + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/uno/fpicker.hxx b/svtools/source/uno/fpicker.hxx new file mode 100644 index 000000000000..6558bfc2d803 --- /dev/null +++ b/svtools/source/uno/fpicker.hxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SVT_SOURCE_UNO_FILEPICKER_HXX +#define INCLUDED_SVT_SOURCE_UNO_FILEPICKER_HXX + +#include "sal/config.h" + +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/Sequence.hxx" +#include "rtl/ustring.hxx" +#include "sal/types.h" + +namespace com { namespace sun { namespace star { +namespace lang { class XMultiServiceFactory; } +namespace uno { class XInterface; } +} } } + +css::uno::Reference SAL_CALL FilePicker_CreateInstance( +css::uno::Reference< css::uno::XComponentContext > const & context); +css::uno::Sequence FilePicker_getSupportedServiceNames(); +OUString FilePicker_getImplementationName(); + +css::uno::Reference SAL_CALL FolderPicker_CreateInstance( +css::uno::Reference< css::uno::XComponentContext > const & context); +css::uno::Sequence FolderPicker_getSupportedServiceNames(); +OUString FolderPicker_getImplementationName(); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/uno/miscservices.cxx b/svtools/source/uno/miscservices.cxx index 76bc5a6c7e0d..0414f5d46324 100644 --- a/svtools/source/uno/miscservices.cxx +++ b/svtools/source/uno/miscservices.cxx @@ -26,6 +26,7 @@ #include #include #include +#include "fpicker.hxx" #include "provider.hxx" #include "renderer.hxx" #include "unowizard.hxx" @@ -69,6 +70,18 @@ namespace ::svt::uno::Wizard::getSupportedServiceNames_static, ::cppu::createSingleComponentFactory, NULL, 0 }, + { + FilePicker_CreateInstance, + FilePicker_getImplementationName, + FilePicker_getSupportedServiceNames, + ::cppu::createSingleComponentFactory, 0, 0 + }, + { + FolderPicker_CreateInstance, + FolderPicker_getImplementationName, + FolderPicker_getSupportedServiceNames, + ::cppu::createSingleComponentFactory, 0, 0 + }, { 0, 0, 0, 0, 0, 0 } }; } @@ -90,6 +103,8 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL svt_component_getFactory ( void * pResult = 0; if ( _pServiceManager ) { + Reference< XMultiServiceFactory > xSMgr(reinterpret_cast< XMultiServiceFactory * >( _pServiceManager ) ); + Reference< XSingleServiceFactory > xFactory; if (rtl_str_compare ( pImplementationName, "com.sun.star.comp.svtools.OAddressBookSourceDialogUno") == 0) @@ -98,8 +113,7 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL svt_component_getFactory ( aServiceNames.getArray()[0] = OUString( "com.sun.star.ui.AddressBookSourceDialog" ); - xFactory = ::cppu::createSingleFactory ( - reinterpret_cast< XMultiServiceFactory* >( _pServiceManager ), + xFactory = ::cppu::createSingleFactory (xSMgr, OUString::createFromAscii( pImplementationName ), svt::OAddressBookSourceDialogUno_CreateInstance, aServiceNames); @@ -111,31 +125,28 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL svt_component_getFactory ( aServiceNames.getArray()[0] = OUString( "com.sun.star.ui.dialogs.FilterOptionsDialog" ); - xFactory = ::cppu::createSingleFactory ( - reinterpret_cast< XMultiServiceFactory* >( _pServiceManager ), + xFactory = ::cppu::createSingleFactory (xSMgr, OUString::createFromAscii( pImplementationName ), SvFilterOptionsDialog_CreateInstance, aServiceNames); } else if( 0 == GraphicProvider::getImplementationName_Static().compareToAscii( pImplementationName ) ) { - xFactory = ::cppu::createOneInstanceFactory( - reinterpret_cast< lang::XMultiServiceFactory * >( _pServiceManager ), + xFactory = ::cppu::createOneInstanceFactory(xSMgr, GraphicProvider::getImplementationName_Static(), GraphicProvider_CreateInstance, GraphicProvider::getSupportedServiceNames_Static() ); } else if( 0 == GraphicRendererVCL::getImplementationName_Static().compareToAscii( pImplementationName ) ) { - xFactory = ::cppu::createOneInstanceFactory( - reinterpret_cast< lang::XMultiServiceFactory * >( _pServiceManager ), + xFactory = ::cppu::createOneInstanceFactory(xSMgr, GraphicRendererVCL::getImplementationName_Static(), GraphicRendererVCL_CreateInstance, GraphicRendererVCL::getSupportedServiceNames_Static() ); } else { - pResult = component_getFactoryHelper( pImplementationName, reinterpret_cast< lang::XMultiServiceFactory * >( _pServiceManager ),reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ), serviceDecl ); + pResult = component_getFactoryHelper( pImplementationName, reinterpret_cast< lang::XMultiServiceFactory * >( _pServiceManager ), reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ), serviceDecl ); if ( !pResult ) pResult = ::cppu::component_getFactoryHelper( pImplementationName, _pServiceManager, pRegistryKey, s_aServiceEntries ); } diff --git a/svtools/util/svt.component b/svtools/util/svt.component index 4670a13605a7..249448b28305 100644 --- a/svtools/util/svt.component +++ b/svtools/util/svt.component @@ -37,4 +37,10 @@ + + + + + + -- cgit