xref: /AOO41X/main/fpicker/source/unx/gnome/FPentry.cxx (revision b557fc96600fce3029f73c89748b6c08fd00b34d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_fpicker.hxx"
26 
27 //----------------------------------------------
28 //  includes of other projects
29 //----------------------------------------------
30 #include <cppuhelper/factory.hxx>
31 #include <com/sun/star/container/XSet.hpp>
32 #include <osl/diagnose.h>
33 #include "SalGtkFilePicker.hxx"
34 #include "SalGtkFolderPicker.hxx"
35 #include <vcl/svapp.hxx>
36 #include "FPServiceInfo.hxx"
37 
38 #include <glib-object.h>
39 
40 extern      const guint gtk_major_version;
41 extern      const guint gtk_minor_version;
42 
43 //-----------------------------------------------
44 // namespace directives
45 //-----------------------------------------------
46 
47 using namespace ::rtl;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::container;
50 using namespace ::com::sun::star::lang;
51 using namespace ::com::sun::star::registry;
52 using namespace ::cppu;
53 using ::com::sun::star::ui::dialogs::XFilePicker;
54 using ::com::sun::star::ui::dialogs::XFilePicker2;
55 using ::com::sun::star::ui::dialogs::XFolderPicker;
56 
57 //------------------------------------------------
58 //
59 //------------------------------------------------
60 
createFileInstance(const Reference<XMultiServiceFactory> & rServiceManager)61 static Reference< XInterface > SAL_CALL createFileInstance(
62     const Reference< XMultiServiceFactory >& rServiceManager )
63 {
64     return Reference< XInterface >(
65         static_cast< XFilePicker2* >(
66             new SalGtkFilePicker( rServiceManager ) ) );
67 }
68 
createFolderInstance(const Reference<XMultiServiceFactory> & rServiceManager)69 static Reference< XInterface > SAL_CALL createFolderInstance(
70     const Reference< XMultiServiceFactory >& rServiceManager )
71 {
72     return Reference< XInterface >(
73         static_cast< XFolderPicker* >(
74             new SalGtkFolderPicker( rServiceManager ) ) );
75 }
76 
77 //------------------------------------------------
78 // the three uno functions that will be exported
79 //------------------------------------------------
80 
81 extern "C"
82 {
83 
84 //------------------------------------------------
85 // component_getImplementationEnvironment
86 //------------------------------------------------
87 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)88 void SAL_CALL component_getImplementationEnvironment(
89     const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
90 {
91     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
92 }
93 
94 //------------------------------------------------
95 //
96 //------------------------------------------------
97 
component_getFactory(const sal_Char * pImplName,uno_Interface * pSrvManager,uno_Interface *)98 void* SAL_CALL component_getFactory(
99     const sal_Char* pImplName, uno_Interface* pSrvManager, uno_Interface* /*pRegistryKey*/ )
100 {
101     void* pRet = 0;
102 
103     if( pSrvManager )
104     {
105             if (
106                  /* crude gtkplug check */ !g_type_from_name( "GdkDisplay" ) ||
107                  /* old version */ !( gtk_major_version >= 2 && gtk_minor_version >= 4 )
108                )
109             {
110                     return 0;
111             }
112 
113             Reference< XSingleServiceFactory > xFactory;
114 
115             if (0 == rtl_str_compare(pImplName, FILE_PICKER_IMPL_NAME))
116             {
117                 Sequence< OUString > aSNS( 1 );
118                 aSNS.getArray( )[0] =
119                     OUString::createFromAscii(FILE_PICKER_SERVICE_NAME);
120 
121                 xFactory = createSingleFactory(
122                     reinterpret_cast< XMultiServiceFactory* > ( pSrvManager ),
123                     OUString::createFromAscii( pImplName ),
124                     createFileInstance,
125                     aSNS );
126             }
127             else if (0 == rtl_str_compare(pImplName, FOLDER_PICKER_IMPL_NAME))
128             {
129                 Sequence< OUString > aSNS( 1 );
130                 aSNS.getArray( )[0] =
131                     OUString::createFromAscii(FOLDER_PICKER_SERVICE_NAME);
132 
133                 xFactory = createSingleFactory(
134                     reinterpret_cast< XMultiServiceFactory* > ( pSrvManager ),
135                     OUString::createFromAscii( pImplName ),
136                     createFolderInstance,
137                     aSNS );
138             }
139 
140             if ( xFactory.is() )
141             {
142                 xFactory->acquire();
143                 pRet = xFactory.get();
144             }
145     }
146 
147     return pRet;
148 }
149 
150 } // extern "C"
151 
152