1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file UpOoBridge.cpp
22 * @brief Bridge to OpenOffice.org.
23 * @author James Hogan <james@albanarts.com>
26 #include "UpOoBridge.h"
29 #include <KStandardDirs>
35 #include <cppuhelper/bootstrap.hxx>
36 #include <osl/file.hxx>
37 #include <osl/process.h>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
40 #include <com/sun/star/frame/XComponentLoader.hpp>
41 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
42 #include <com/sun/star/registry/XSimpleRegistry.hpp>
44 using namespace com::sun::star::beans
;
45 using namespace com::sun::star::bridge
;
46 using namespace com::sun::star::frame
;
47 using namespace com::sun::star::lang
;
48 using namespace com::sun::star::registry
;
49 using namespace com::sun::star::uno
;
53 * Constructors + destructor
56 /// Primary constructor.
57 UpOoBridge::UpOoBridge()
60 QByteArray connectionBaCore
= "socket,host=localhost,port=2083;urp;StarOffice.ServiceManager";
61 QByteArray connectionBa
= "uno:" + connectionBaCore
;
62 #define TYPESDB "unipresent/openoffice.org/types.rdb"
63 #define BACKEND_NAME i18n("OpenOffice.org backend:")
64 QString rdbFileBa
= KStandardDirs::locate("data", TYPESDB
);
65 if (rdbFileBa
.isNull())
67 kdError() << BACKEND_NAME
<< i18n("couldn't find data %1").arg(TYPESDB
);
71 OUString
connectionString(OUString::createFromAscii(connectionBa
));
72 OUString
rdbFile(OUString::createFromAscii(rdbFileBa
.toAscii()));
73 bool tryAgain
= false;
77 Reference
<XSimpleRegistry
> registry
= ::cppu::createSimpleRegistry();
78 registry
->open(rdbFile
, sal_True
, sal_False
);
79 Reference
<XComponentContext
> componentContext
= ::cppu::bootstrap_InitialComponentContext(registry
);
80 Reference
<XMultiComponentFactory
> componentFactory
= componentContext
->getServiceManager();
81 Reference
<XUnoUrlResolver
> resolver(componentFactory
->createInstanceWithContext(
82 OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver"),
83 componentContext
), UNO_QUERY
);
86 kdError() << BACKEND_NAME
<< i18n("could not create instance of XUnoUrlResolver");
91 m_serviceManager
= resolver
->resolve(connectionString
);
94 catch (Exception
& exception
)
96 // If we've already tried it again, just give up.
97 if (unlikely(tryAgain
))
100 OUString message
= exception
.Message
;
101 kdDebug() << BACKEND_NAME
<< QString::fromUtf16((const sal_Unicode
*)message
, message
.getLength()) << i18n("(start OpenOffice.org with %1)").arg(QString()+"soffice \"-accept=" + connectionBaCore
+ "\"");
117 UpOoBridge::~UpOoBridge()
125 /// Find whether the bridge is valid.
126 bool UpOoBridge::isValid() const
131 /// Get the service manager.
132 XInterface
* UpOoBridge::serviceManager()
134 return m_serviceManager
.get();