Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sal/config.h>
21 :
22 : #include "desktopdllapi.h"
23 :
24 : #include "app.hxx"
25 : #include "exithelper.h"
26 : #include "cmdlineargs.hxx"
27 : #include "cmdlinehelp.hxx"
28 :
29 : #include <osl/file.hxx>
30 : #include <rtl/bootstrap.hxx>
31 : #include <tools/extendapplicationenvironment.hxx>
32 : #include <vcl/svmain.hxx>
33 :
34 : #include <com/sun/star/beans/NamedValue.hpp>
35 : #include <com/sun/star/frame/Desktop.hpp>
36 : #include <com/sun/star/frame/XComponentLoader.hpp>
37 : #include <com/sun/star/frame/XStorable2.hpp>
38 : #include <comphelper/storagehelper.hxx>
39 : #include <cppuhelper/bootstrap.hxx>
40 : #include <unotools/mediadescriptor.hxx>
41 :
42 :
43 : #ifdef ANDROID
44 : # include <jni.h>
45 : # include <android/log.h>
46 : # include <salhelper/thread.hxx>
47 :
48 : # define LOGTAG "LibreOffice/sofficemain"
49 : # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
50 : #endif
51 :
52 : #ifdef IOS
53 : #include <touch/touch.h>
54 : #endif
55 :
56 160 : extern "C" int DESKTOP_DLLPUBLIC soffice_main()
57 : {
58 : #if defined ANDROID
59 : try {
60 : rtl::Bootstrap::setIniFilename("file:///assets/program/lofficerc");
61 : #endif
62 160 : tools::extendApplicationEnvironment();
63 :
64 : SAL_INFO("desktop.app", "PERFORMANCE - enter Main()" );
65 :
66 160 : desktop::Desktop aDesktop;
67 : // This string is used during initialization of the Gtk+ VCL module
68 160 : Application::SetAppName( OUString("soffice") );
69 : #ifdef UNX
70 : // handle --version and --help already here, otherwise they would be handled
71 : // after VCL initialization that might fail if $DISPLAY is not set
72 160 : const desktop::CommandLineArgs& rCmdLineArgs = desktop::Desktop::GetCommandLineArgs();
73 320 : OUString aUnknown( rCmdLineArgs.GetUnknown() );
74 160 : if ( !aUnknown.isEmpty() )
75 : {
76 0 : desktop::Desktop::InitApplicationServiceManager();
77 0 : desktop::displayCmdlineHelp( aUnknown );
78 0 : return EXIT_FAILURE;
79 : }
80 160 : if ( rCmdLineArgs.IsHelp() )
81 : {
82 0 : desktop::Desktop::InitApplicationServiceManager();
83 0 : desktop::displayCmdlineHelp( OUString() );
84 0 : return EXIT_SUCCESS;
85 : }
86 160 : if ( rCmdLineArgs.IsVersion() )
87 : {
88 0 : desktop::Desktop::InitApplicationServiceManager();
89 0 : desktop::displayVersion();
90 0 : return EXIT_SUCCESS;
91 : }
92 : #endif
93 320 : return SVMain();
94 : #if defined ANDROID
95 : } catch (const ::com::sun::star::uno::Exception &e) {
96 : LOGI("Unhandled UNO exception: '%s'",
97 : OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
98 : throw; // to get exception type printed
99 : }
100 : #endif
101 480 : }
102 :
103 : #if defined(ANDROID) || defined(IOS)
104 :
105 : #ifdef ANDROID
106 : extern "C" SAL_JNI_EXPORT void JNICALL
107 : Java_org_libreoffice_android_AppSupport_runMain(JNIEnv* /* env */,
108 : jobject /* clazz */)
109 : #else
110 : extern "C"
111 : void
112 : touch_lo_runMain()
113 : #endif
114 : {
115 : int nRet;
116 : do {
117 : nRet = soffice_main();
118 : #ifdef ANDROID
119 : LOGI("soffice_main returned %d", nRet);
120 : #endif
121 : } while (nRet == EXITHELPER_NORMAL_RESTART ||
122 : nRet == EXITHELPER_CRASH_WITH_RESTART); // pretend to re-start.
123 :
124 : }
125 :
126 : extern "C" void PtylTestEncryptionAndExport(const char *pathname)
127 : {
128 : OUString sUri(pathname, strlen(pathname), RTL_TEXTENCODING_UTF8);
129 : sUri = "file://" + sUri;
130 :
131 : css::uno::Reference<css::frame::XComponentLoader> loader(css::frame::Desktop::create(cppu::defaultBootstrap_InitialComponentContext()), css::uno::UNO_QUERY);
132 : css::uno::Reference<css::lang::XComponent> component;
133 : component.set(loader->loadComponentFromURL(sUri, "_default", 0, {}));
134 :
135 : utl::MediaDescriptor media;
136 : media[utl::MediaDescriptor::PROP_FILTERNAME()] <<= OUString("MS Word 2007 XML");
137 : OUString password("myPassword");
138 : css::uno::Sequence<css::beans::NamedValue> encryptionData(1);
139 : encryptionData[0].Name = "OOXPassword";
140 : encryptionData[0].Value = css::uno::makeAny(password);
141 : media[utl::MediaDescriptor::PROP_ENCRYPTIONDATA()] <<= encryptionData;
142 :
143 : css::uno::Reference<css::frame::XModel> model(component, css::uno::UNO_QUERY);
144 : css::uno::Reference<css::frame::XStorable2> storable2(model, css::uno::UNO_QUERY);
145 : OUString saveAsUri(sUri + ".new.docx");
146 : SAL_INFO("desktop.app", "Trying to store as " << saveAsUri);
147 : OUString testPathName;
148 : osl::File::getSystemPathFromFileURL(saveAsUri+".txt", testPathName);
149 : storable2->storeToURL(saveAsUri, media.getAsConstPropertyValueList());
150 : }
151 :
152 : #endif
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|