diff options
Diffstat (limited to 'unotools/source/config/accelcfg.cxx')
-rw-r--r-- | unotools/source/config/accelcfg.cxx | 202 |
1 files changed, 0 insertions, 202 deletions
diff --git a/unotools/source/config/accelcfg.cxx b/unotools/source/config/accelcfg.cxx deleted file mode 100644 index 9c48b7f5e06e..000000000000 --- a/unotools/source/config/accelcfg.cxx +++ /dev/null | |||
@@ -1,202 +0,0 @@ | |||
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 | |||
21 | #include "rtl/instance.hxx" | ||
22 | #include <com/sun/star/uno/Any.hxx> | ||
23 | #include <com/sun/star/uno/Sequence.hxx> | ||
24 | #include <com/sun/star/io/XActiveDataSource.hpp> | ||
25 | #include <com/sun/star/io/XInputStream.hpp> | ||
26 | #include <com/sun/star/io/XOutputStream.hpp> | ||
27 | #include <com/sun/star/xml/sax/Parser.hpp> | ||
28 | #include <com/sun/star/xml/sax/Writer.hpp> | ||
29 | #include <unotools/configmgr.hxx> | ||
30 | #include <unotools/configitem.hxx> | ||
31 | |||
32 | #include <osl/mutex.hxx> | ||
33 | #include <tools/string.hxx> | ||
34 | #include <tools/urlobj.hxx> | ||
35 | #include <unotools/streamwrap.hxx> | ||
36 | #include <unotools/ucbstreamhelper.hxx> | ||
37 | #include <comphelper/processfactory.hxx> | ||
38 | |||
39 | #include <unotools/accelcfg.hxx> | ||
40 | #include <unotools/xmlaccelcfg.hxx> | ||
41 | #include <unotools/pathoptions.hxx> | ||
42 | #include "itemholder1.hxx" | ||
43 | |||
44 | |||
45 | using namespace utl; | ||
46 | using namespace com::sun::star::uno; | ||
47 | using namespace com::sun::star::io; | ||
48 | using namespace com::sun::star::xml::sax; | ||
49 | |||
50 | using ::rtl::OUString; | ||
51 | |||
52 | |||
53 | static SvtAcceleratorConfig_Impl* pOptions = NULL; | ||
54 | static sal_Int32 nRefCount = 0; | ||
55 | |||
56 | class SvtAcceleratorConfig_Impl | ||
57 | { | ||
58 | public: | ||
59 | |||
60 | SvtAcceleratorItemList aList; | ||
61 | bool bModified; | ||
62 | |||
63 | SvtAcceleratorConfig_Impl() | ||
64 | : bModified( sal_False ) | ||
65 | {} | ||
66 | |||
67 | SvtAcceleratorConfig_Impl( Reference< XInputStream >& xInputStream ); | ||
68 | bool Commit( Reference< XOutputStream >& xOutputStream ); | ||
69 | }; | ||
70 | |||
71 | // ----------------------------------------------------------------------- | ||
72 | |||
73 | SvtAcceleratorConfig_Impl::SvtAcceleratorConfig_Impl( Reference< XInputStream >& rInputStream ) | ||
74 | : bModified( false ) | ||
75 | { | ||
76 | Reference< XParser > xParser = Parser::create( ::comphelper::getProcessComponentContext() ); | ||
77 | |||
78 | // connect stream to input stream to the parser | ||
79 | InputSource aInputSource; | ||
80 | aInputSource.aInputStream = rInputStream; | ||
81 | |||
82 | // get filter | ||
83 | Reference< XDocumentHandler > xFilter( new OReadAccelatorDocumentHandler( aList )); | ||
84 | |||
85 | // connect parser and filter | ||
86 | xParser->setDocumentHandler( xFilter ); | ||
87 | xParser->parseStream( aInputSource ); | ||
88 | } | ||
89 | |||
90 | bool SvtAcceleratorConfig_Impl::Commit( Reference< XOutputStream >& rOutputStream ) | ||
91 | { | ||
92 | Reference< XWriter > xWriter = Writer::create( ::comphelper::getProcessComponentContext() ); | ||
93 | |||
94 | xWriter->setOutputStream( rOutputStream ); | ||
95 | try | ||
96 | { | ||
97 | OWriteAccelatorDocumentHandler aWriteHandler( aList, Reference<XDocumentHandler>(xWriter, UNO_QUERY_THROW) ); | ||
98 | aWriteHandler.WriteAcceleratorDocument(); | ||
99 | rOutputStream->flush(); | ||
100 | return true; | ||
101 | } | ||
102 | catch ( RuntimeException& ) | ||
103 | { | ||
104 | } | ||
105 | catch ( SAXException& ) | ||
106 | { | ||
107 | } | ||
108 | catch ( ::com::sun::star::io::IOException& ) | ||
109 | { | ||
110 | } | ||
111 | |||
112 | return false; | ||
113 | } | ||
114 | |||
115 | namespace | ||
116 | { | ||
117 | class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton > | ||
118 | { | ||
119 | }; | ||
120 | } | ||
121 | |||
122 | SvtAcceleratorConfiguration::SvtAcceleratorConfiguration() | ||
123 | { | ||
124 | // Global access, must be guarded (multithreading) | ||
125 | ::osl::MutexGuard aGuard( LocalSingleton::get() ); | ||
126 | if ( !pOptions ) | ||
127 | { | ||
128 | SvStream* pStream = GetDefaultStream( STREAM_STD_READ ); | ||
129 | ::utl::OInputStreamWrapper aHelper( *pStream ); | ||
130 | com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > xOut( &aHelper ); | ||
131 | |||
132 | try | ||
133 | { | ||
134 | pOptions = new SvtAcceleratorConfig_Impl( xOut ); | ||
135 | } | ||
136 | catch ( RuntimeException& ) | ||
137 | { | ||
138 | pOptions = new SvtAcceleratorConfig_Impl(); | ||
139 | } | ||
140 | catch( SAXException& ) | ||
141 | { | ||
142 | pOptions = new SvtAcceleratorConfig_Impl(); | ||
143 | } | ||
144 | catch( ::com::sun::star::io::IOException& ) | ||
145 | { | ||
146 | pOptions = new SvtAcceleratorConfig_Impl(); | ||
147 | } | ||
148 | |||
149 | if (pOptions) | ||
150 | ItemHolder1::holdConfigItem(E_ACCELCFG); | ||
151 | |||
152 | delete pStream; | ||
153 | } | ||
154 | |||
155 | ++nRefCount; | ||
156 | pImp = pOptions; | ||
157 | } | ||
158 | |||
159 | // ----------------------------------------------------------------------- | ||
160 | |||
161 | SvtAcceleratorConfiguration::~SvtAcceleratorConfiguration() | ||
162 | { | ||
163 | if ( pImp == pOptions ) | ||
164 | { | ||
165 | // Global access, must be guarded (multithreading) | ||
166 | ::osl::MutexGuard aGuard( LocalSingleton::get() ); | ||
167 | if ( !--nRefCount ) | ||
168 | { | ||
169 | if ( pImp->bModified ) | ||
170 | { | ||
171 | String aUserConfig = SvtPathOptions().GetUserConfigPath(); | ||
172 | INetURLObject aObj( aUserConfig ); | ||
173 | aObj.insertName( rtl::OUString("GlobalKeyBindings.xml") ); | ||
174 | SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READWRITE|STREAM_TRUNC ); | ||
175 | com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > xOut( new utl::OOutputStreamWrapper( *pStream ) ); | ||
176 | pImp->Commit( xOut ); | ||
177 | delete pStream; | ||
178 | } | ||
179 | |||
180 | DELETEZ( pOptions ); | ||
181 | } | ||
182 | } | ||
183 | else | ||
184 | { | ||
185 | delete pImp; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | String SvtAcceleratorConfiguration::GetStreamName() | ||
190 | { | ||
191 | return rtl::OUString("KeyBindings.xml"); | ||
192 | } | ||
193 | |||
194 | SvStream* SvtAcceleratorConfiguration::GetDefaultStream( StreamMode nMode ) | ||
195 | { | ||
196 | String aUserConfig = SvtPathOptions().GetUserConfigPath(); | ||
197 | INetURLObject aObj( aUserConfig ); | ||
198 | aObj.insertName( GetStreamName() ); | ||
199 | return ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL( INetURLObject::NO_DECODE ), nMode ); | ||
200 | } | ||
201 | |||
202 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ | ||