xref: /trunk/main/desktop/source/migration/migration.cxx (revision 0a407c2a85aa3a829e52a449aa13b6528fbe055e)
12722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52722ceddSAndrew Rist  * distributed with this work for additional information
62722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
92722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142722ceddSAndrew Rist  * software distributed under the License is distributed on an
152722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
172722ceddSAndrew Rist  * specific language governing permissions and limitations
182722ceddSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202722ceddSAndrew Rist  *************************************************************/
212722ceddSAndrew Rist 
222722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <map>
28cdf0e10cSrcweir #include <new>
29cdf0e10cSrcweir #include <set>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "migration.hxx"
32cdf0e10cSrcweir #include "migration_impl.hxx"
33cdf0e10cSrcweir #include "cfgfilter.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <unotools/textsearch.hxx>
36cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
37cdf0e10cSrcweir #include <comphelper/sequence.hxx>
38cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
39cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
40cdf0e10cSrcweir #include <rtl/uri.hxx>
41cdf0e10cSrcweir #include <tools/config.hxx>
42cdf0e10cSrcweir #include <i18npool/lang.h>
43cdf0e10cSrcweir #include <tools/urlobj.hxx>
44cdf0e10cSrcweir #include <osl/file.hxx>
45cdf0e10cSrcweir #include <osl/mutex.hxx>
46cdf0e10cSrcweir #include <ucbhelper/content.hxx>
47cdf0e10cSrcweir #include <osl/security.hxx>
48cdf0e10cSrcweir #include <unotools/configmgr.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include <com/sun/star/configuration/Update.hpp>
51cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
52cdf0e10cSrcweir #include <com/sun/star/task/XJob.hpp>
53cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
54cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
55cdf0e10cSrcweir #include <com/sun/star/util/XRefreshable.hpp>
56cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp>
57cdf0e10cSrcweir #include <com/sun/star/util/XStringSubstitution.hpp>
58cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
59cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp>
60cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfiguration.hpp>
61cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
62cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir using namespace rtl;
65cdf0e10cSrcweir using namespace osl;
66cdf0e10cSrcweir using namespace std;
67cdf0e10cSrcweir using namespace com::sun::star::task;
68cdf0e10cSrcweir using namespace com::sun::star::lang;
69cdf0e10cSrcweir using namespace com::sun::star::beans;
70cdf0e10cSrcweir using namespace com::sun::star::util;
71cdf0e10cSrcweir using namespace com::sun::star::container;
72cdf0e10cSrcweir using com::sun::star::uno::Exception;
73cdf0e10cSrcweir using namespace com::sun::star;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir namespace desktop {
76cdf0e10cSrcweir 
77cdf0e10cSrcweir static const ::rtl::OUString ITEM_DESCRIPTOR_COMMANDURL = ::rtl::OUString::createFromAscii("CommandURL");
78cdf0e10cSrcweir static const ::rtl::OUString ITEM_DESCRIPTOR_CONTAINER = ::rtl::OUString::createFromAscii("ItemDescriptorContainer");
79cdf0e10cSrcweir static const ::rtl::OUString ITEM_DESCRIPTOR_LABEL = ::rtl::OUString::createFromAscii("Label");
80cdf0e10cSrcweir 
81cdf0e10cSrcweir static const ::rtl::OUString MENU_SEPERATOR = ::rtl::OUString::createFromAscii(" | ");
82cdf0e10cSrcweir static const ::rtl::OUString MENU_SUBMENU = ::rtl::OUString::createFromAscii("...");
83cdf0e10cSrcweir 
retrieveLabelFromCommand(const::rtl::OUString & sCommand,const::rtl::OUString & sModuleIdentifier)84cdf0e10cSrcweir ::rtl::OUString retrieveLabelFromCommand(const ::rtl::OUString& sCommand, const ::rtl::OUString& sModuleIdentifier)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     ::rtl::OUString sLabel;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xUICommands;
89cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xNameAccess( ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.UICommandDescription") ), uno::UNO_QUERY );
90cdf0e10cSrcweir     if ( xNameAccess.is() )
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         uno::Any a = xNameAccess->getByName( sModuleIdentifier );
93cdf0e10cSrcweir         a >>= xUICommands;
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir     if (xUICommands.is())
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         if ( sCommand.getLength() > 0 )
98cdf0e10cSrcweir         {
99cdf0e10cSrcweir             rtl::OUString aStr;
100cdf0e10cSrcweir             ::uno::Sequence< beans::PropertyValue > aPropSeq;
101cdf0e10cSrcweir             try
102cdf0e10cSrcweir             {
103cdf0e10cSrcweir                 uno::Any a( xUICommands->getByName( sCommand ));
104cdf0e10cSrcweir                 if ( a >>= aPropSeq )
105cdf0e10cSrcweir                 {
106cdf0e10cSrcweir                     for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
107cdf0e10cSrcweir                     {
108cdf0e10cSrcweir                         if ( aPropSeq[i].Name.equalsAscii( "Label" ))
109cdf0e10cSrcweir                         {
110cdf0e10cSrcweir                             aPropSeq[i].Value >>= aStr;
111cdf0e10cSrcweir                             break;
112cdf0e10cSrcweir                         }
113cdf0e10cSrcweir                     }
114cdf0e10cSrcweir                 }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir                 sLabel = aStr;
117cdf0e10cSrcweir             }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir             catch(container::NoSuchElementException&)
120cdf0e10cSrcweir             {
121cdf0e10cSrcweir                 sLabel = sCommand;
122cdf0e10cSrcweir                 sal_Int32 nIndex = sLabel.indexOf(':');
123cdf0e10cSrcweir                 if (nIndex>=0 && nIndex <= sLabel.getLength()-1)
124cdf0e10cSrcweir                     sLabel = sLabel.copy(nIndex+1);
125cdf0e10cSrcweir             }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     return sLabel;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
stripHotKey(const::rtl::OUString & str)133cdf0e10cSrcweir ::rtl::OUString stripHotKey( const ::rtl::OUString& str )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     sal_Int32 index = str.indexOf( '~' );
136cdf0e10cSrcweir     if ( index == -1 )
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         return str;
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir     else
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         return str.replaceAt( index, 1, ::rtl::OUString() );
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
mapModuleShortNameToIdentifier(const::rtl::OUString & sShortName)146cdf0e10cSrcweir ::rtl::OUString mapModuleShortNameToIdentifier(const ::rtl::OUString& sShortName)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     ::rtl::OUString sIdentifier;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     if (sShortName.equals(::rtl::OUString::createFromAscii("StartModule")))
151cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.frame.StartModule");
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("swriter")))
154cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.text.TextDocument");
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("scalc")))
157cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.sheet.SpreadsheetDocument");
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("sdraw")))
160cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.drawing.DrawingDocument");
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("simpress")))
163cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.presentation.PresentationDocument");
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("smath")))
166cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.formula.FormulaProperties");
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("schart")))
169cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.chart2.ChartDocument");
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("BasicIDE")))
172cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.script.BasicIDE");
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("dbapp")))
175cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.sdb.OfficeDatabaseDocument");
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("sglobal")))
178cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.text.GlobalDocument");
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("sweb")))
181cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.text.WebDocument");
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("swxform")))
184cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.xforms.XMLFormDocument");
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     else if (sShortName.equals(::rtl::OUString::createFromAscii("sbibliography")))
187cdf0e10cSrcweir         sIdentifier = ::rtl::OUString::createFromAscii("com.sun.star.frame.Bibliography");
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     return sIdentifier;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir static MigrationImpl *pImpl = 0;
193cdf0e10cSrcweir static Mutex aMutex;
getImpl()194cdf0e10cSrcweir static MigrationImpl *getImpl()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     MutexGuard aGuard(aMutex);
197cdf0e10cSrcweir     if (pImpl == 0)
198cdf0e10cSrcweir         pImpl = new MigrationImpl(comphelper::getProcessServiceFactory());
199cdf0e10cSrcweir     return pImpl;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
releaseImpl()202cdf0e10cSrcweir static void releaseImpl()
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     MutexGuard aGuard(aMutex);
205cdf0e10cSrcweir     if (pImpl != 0)
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         delete pImpl;
208cdf0e10cSrcweir         pImpl = 0;
209cdf0e10cSrcweir     }
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir // static main entry point for the migration process
doMigration()213cdf0e10cSrcweir void Migration::doMigration()
214cdf0e10cSrcweir {
215cdf0e10cSrcweir     sal_Bool bResult = sal_False;
216cdf0e10cSrcweir     try {
217cdf0e10cSrcweir         bResult = getImpl()->doMigration();
218cdf0e10cSrcweir     } catch (Exception& e)
219cdf0e10cSrcweir     {
220cdf0e10cSrcweir         OString aMsg("doMigration() exception: ");
221cdf0e10cSrcweir         aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
222cdf0e10cSrcweir         OSL_ENSURE(sal_False, aMsg.getStr());
223cdf0e10cSrcweir     }
22407a3d7f1SPedro Giffuni     OSL_ENSURE(bResult, "Migration has not been successful");
225cdf0e10cSrcweir     // shut down migration framework
226cdf0e10cSrcweir     releaseImpl();
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
cancelMigration()229cdf0e10cSrcweir void Migration::cancelMigration()
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     releaseImpl();
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
checkMigration()234cdf0e10cSrcweir sal_Bool Migration::checkMigration()
235cdf0e10cSrcweir {
236cdf0e10cSrcweir     return getImpl()->checkMigration();
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
getOldVersionName()239cdf0e10cSrcweir OUString Migration::getOldVersionName()
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     return getImpl()->getOldVersionName();
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
getOldVersionName()244cdf0e10cSrcweir OUString MigrationImpl::getOldVersionName()
245cdf0e10cSrcweir {
246cdf0e10cSrcweir     return m_aInfo.productname;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
checkMigration()249cdf0e10cSrcweir sal_Bool MigrationImpl::checkMigration()
250cdf0e10cSrcweir {
251cdf0e10cSrcweir     if (m_aInfo.userdata.getLength() > 0 && ! checkMigrationCompleted())
252cdf0e10cSrcweir         return sal_True;
253cdf0e10cSrcweir     else
254cdf0e10cSrcweir         return sal_False;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
MigrationImpl(const uno::Reference<XMultiServiceFactory> & xFactory)257cdf0e10cSrcweir MigrationImpl::MigrationImpl(const uno::Reference< XMultiServiceFactory >& xFactory)
258cdf0e10cSrcweir     : m_vrVersions(new strings_v)
259cdf0e10cSrcweir     , m_xFactory(xFactory)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir     readAvailableMigrations(m_vMigrationsAvailable);
262cdf0e10cSrcweir     sal_Int32 nIndex = findPreferedMigrationProcess(m_vMigrationsAvailable);
263cdf0e10cSrcweir     if ( nIndex >= 0 )
264cdf0e10cSrcweir         m_vrMigrations = readMigrationSteps(m_vMigrationsAvailable[nIndex].name);
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
~MigrationImpl()267cdf0e10cSrcweir MigrationImpl::~MigrationImpl()
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
doMigration()272cdf0e10cSrcweir sal_Bool MigrationImpl::doMigration()
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     // compile file list for migration
275cdf0e10cSrcweir     m_vrFileList = compileFileList();
276cdf0e10cSrcweir 
277cdf0e10cSrcweir     sal_Bool result = sal_False;
278cdf0e10cSrcweir     try
279cdf0e10cSrcweir     {
280cdf0e10cSrcweir         NewVersionUIInfo aNewVersionUIInfo;
281cdf0e10cSrcweir         ::std::vector< MigrationModuleInfo > vModulesInfo = dectectUIChangesForAllModules();
282cdf0e10cSrcweir         aNewVersionUIInfo.init(vModulesInfo);
283cdf0e10cSrcweir 
284cdf0e10cSrcweir         copyFiles();
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         const ::rtl::OUString sMenubarResourceURL = ::rtl::OUString::createFromAscii("private:resource/menubar/menubar");
287cdf0e10cSrcweir         const ::rtl::OUString sToolbarResourcePre = ::rtl::OUString::createFromAscii("private:resource/toolbar/");
288cdf0e10cSrcweir         for (sal_uInt32 i=0; i<vModulesInfo.size(); ++i)
289cdf0e10cSrcweir         {
290cdf0e10cSrcweir             ::rtl::OUString sModuleIdentifier = mapModuleShortNameToIdentifier(vModulesInfo[i].sModuleShortName);
291cdf0e10cSrcweir             if (sModuleIdentifier.getLength()==0)
292cdf0e10cSrcweir                 continue;
293cdf0e10cSrcweir 
294cdf0e10cSrcweir             uno::Sequence< uno::Any > lArgs(2);
295cdf0e10cSrcweir             ::rtl::OUString aOldCfgDataPath = m_aInfo.userdata + ::rtl::OUString::createFromAscii("/user/config/soffice.cfg/modules/");
296cdf0e10cSrcweir             lArgs[0] <<= aOldCfgDataPath + vModulesInfo[i].sModuleShortName;
297cdf0e10cSrcweir             lArgs[1] <<= embed::ElementModes::READ;
298cdf0e10cSrcweir 
299cdf0e10cSrcweir             uno::Reference< lang::XSingleServiceFactory > xStorageFactory(m_xFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.embed.FileSystemStorageFactory")), uno::UNO_QUERY);
300cdf0e10cSrcweir             uno::Reference< embed::XStorage >             xModules;
301cdf0e10cSrcweir 
302cdf0e10cSrcweir             xModules = uno::Reference< embed::XStorage >(xStorageFactory->createInstanceWithArguments(lArgs), uno::UNO_QUERY);
303cdf0e10cSrcweir             uno::Reference< ui::XUIConfigurationManager > xOldCfgManager( m_xFactory->createInstance( rtl::OUString::createFromAscii("com.sun.star.ui.UIConfigurationManager")), uno::UNO_QUERY );
304cdf0e10cSrcweir             uno::Reference< ui::XUIConfigurationStorage > xOldCfgStorage( xOldCfgManager, uno::UNO_QUERY );
305cdf0e10cSrcweir             uno::Reference< ui::XUIConfigurationPersistence > xOldCfgPersistence( xOldCfgManager, uno::UNO_QUERY );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir             if ( xOldCfgStorage.is() && xOldCfgPersistence.is() && xModules.is() )
308cdf0e10cSrcweir             {
309cdf0e10cSrcweir                     xOldCfgStorage->setStorage( xModules );
310cdf0e10cSrcweir                     xOldCfgPersistence->reload();
311cdf0e10cSrcweir             }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir             uno::Reference< ui::XUIConfigurationManager > xCfgManager = aNewVersionUIInfo.getConfigManager(vModulesInfo[i].sModuleShortName);
314cdf0e10cSrcweir 
315cdf0e10cSrcweir             if (vModulesInfo[i].bHasMenubar)
316cdf0e10cSrcweir             {
317cdf0e10cSrcweir                 uno::Reference< container::XIndexContainer > xOldVersionMenuSettings = uno::Reference< container::XIndexContainer >(xOldCfgManager->getSettings(sMenubarResourceURL, sal_True), uno::UNO_QUERY);
318cdf0e10cSrcweir                 uno::Reference< container::XIndexContainer > xNewVersionMenuSettings = aNewVersionUIInfo.getNewMenubarSettings(vModulesInfo[i].sModuleShortName);
319cdf0e10cSrcweir                 ::rtl::OUString sParent;
320cdf0e10cSrcweir                 compareOldAndNewConfig(sParent, xOldVersionMenuSettings, xNewVersionMenuSettings, sMenubarResourceURL);
321cdf0e10cSrcweir                 mergeOldToNewVersion(xCfgManager, xNewVersionMenuSettings, sModuleIdentifier, sMenubarResourceURL);
322cdf0e10cSrcweir             }
323cdf0e10cSrcweir 
324cdf0e10cSrcweir             sal_Int32 nToolbars = vModulesInfo[i].m_vToolbars.size();
325cdf0e10cSrcweir             if (nToolbars >0)
326cdf0e10cSrcweir             {
327cdf0e10cSrcweir                 for (sal_Int32 j=0; j<nToolbars; ++j)
328cdf0e10cSrcweir                 {
329cdf0e10cSrcweir                     ::rtl::OUString sToolbarName = vModulesInfo[i].m_vToolbars[j];
330cdf0e10cSrcweir                     ::rtl::OUString sToolbarResourceURL = sToolbarResourcePre + sToolbarName;
331cdf0e10cSrcweir 
332cdf0e10cSrcweir                     uno::Reference< container::XIndexContainer > xOldVersionToolbarSettings = uno::Reference< container::XIndexContainer >(xOldCfgManager->getSettings(sToolbarResourceURL, sal_True), uno::UNO_QUERY);
333cdf0e10cSrcweir                     uno::Reference< container::XIndexContainer > xNewVersionToolbarSettings = aNewVersionUIInfo.getNewToolbarSettings(vModulesInfo[i].sModuleShortName, sToolbarName);
334cdf0e10cSrcweir                     ::rtl::OUString sParent;
335cdf0e10cSrcweir                     compareOldAndNewConfig(sParent, xOldVersionToolbarSettings, xNewVersionToolbarSettings, sToolbarResourceURL);
336cdf0e10cSrcweir                     mergeOldToNewVersion(xCfgManager, xNewVersionToolbarSettings, sModuleIdentifier, sToolbarResourceURL);
337cdf0e10cSrcweir                 }
338cdf0e10cSrcweir             }
339cdf0e10cSrcweir 
340cdf0e10cSrcweir             m_aOldVersionItemsHashMap.clear();
341cdf0e10cSrcweir             m_aNewVersionItemsHashMap.clear();
342cdf0e10cSrcweir         }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir         // execute the migration items from Setup.xcu
345cdf0e10cSrcweir         copyConfig();
346cdf0e10cSrcweir 
347cdf0e10cSrcweir         // execute custom migration services from Setup.xcu
348cdf0e10cSrcweir         // and refresh the cache
349cdf0e10cSrcweir         runServices();
350cdf0e10cSrcweir         refresh();
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         result = sal_True;
353cdf0e10cSrcweir     } catch (...)
354cdf0e10cSrcweir     {
355cdf0e10cSrcweir         OString aMsg("An unexpected exception was thrown during migration");
356cdf0e10cSrcweir         aMsg += "\nOldVersion: " + OUStringToOString(m_aInfo.productname, RTL_TEXTENCODING_ASCII_US);
357cdf0e10cSrcweir         aMsg += "\nDataPath  : " + OUStringToOString(m_aInfo.userdata, RTL_TEXTENCODING_ASCII_US);
358cdf0e10cSrcweir         OSL_ENSURE(sal_False, aMsg.getStr());
359cdf0e10cSrcweir     }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir     // prevent running the migration multiple times
362cdf0e10cSrcweir     setMigrationCompleted();
363cdf0e10cSrcweir     return result;
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
refresh()366cdf0e10cSrcweir void MigrationImpl::refresh()
367cdf0e10cSrcweir {
368cdf0e10cSrcweir     uno::Reference< XRefreshable > xRefresh(m_xFactory->createInstance(
369cdf0e10cSrcweir                 OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")), uno::UNO_QUERY);
370cdf0e10cSrcweir     if (xRefresh.is())
371cdf0e10cSrcweir         xRefresh->refresh();
372cdf0e10cSrcweir     else
373cdf0e10cSrcweir         OSL_ENSURE(sal_False, "could not get XRefresh interface from default config provider. No refresh done.");
374cdf0e10cSrcweir 
375cdf0e10cSrcweir }
376cdf0e10cSrcweir 
setMigrationCompleted()377cdf0e10cSrcweir void MigrationImpl::setMigrationCompleted()
378cdf0e10cSrcweir {
379cdf0e10cSrcweir     try {
380cdf0e10cSrcweir         uno::Reference< XPropertySet > aPropertySet(getConfigAccess("org.openoffice.Setup/Office", true), uno::UNO_QUERY_THROW);
381cdf0e10cSrcweir         aPropertySet->setPropertyValue(OUString::createFromAscii("MigrationCompleted"), uno::makeAny(sal_True));
382cdf0e10cSrcweir         uno::Reference< XChangesBatch >(aPropertySet, uno::UNO_QUERY_THROW)->commitChanges();
383cdf0e10cSrcweir     } catch (...) {
384cdf0e10cSrcweir         // fail silently
385cdf0e10cSrcweir     }
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
checkMigrationCompleted()388cdf0e10cSrcweir sal_Bool MigrationImpl::checkMigrationCompleted()
389cdf0e10cSrcweir {
390cdf0e10cSrcweir     sal_Bool bMigrationCompleted = sal_False;
391cdf0e10cSrcweir     try {
392cdf0e10cSrcweir         uno::Reference< XPropertySet > aPropertySet(
393cdf0e10cSrcweir             getConfigAccess("org.openoffice.Setup/Office"), uno::UNO_QUERY_THROW);
394cdf0e10cSrcweir         aPropertySet->getPropertyValue(
395cdf0e10cSrcweir             OUString::createFromAscii("MigrationCompleted")) >>= bMigrationCompleted;
396cdf0e10cSrcweir     } catch (Exception&) {
397cdf0e10cSrcweir         // just return false...
398cdf0e10cSrcweir     }
399cdf0e10cSrcweir     return bMigrationCompleted;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
insertSorted(migrations_available & rAvailableMigrations,supported_migration & aSupportedMigration)402cdf0e10cSrcweir static void insertSorted(migrations_available& rAvailableMigrations, supported_migration& aSupportedMigration)
403cdf0e10cSrcweir {
404cdf0e10cSrcweir     bool                           bInserted( false );
405cdf0e10cSrcweir     migrations_available::iterator pIter = rAvailableMigrations.begin();
406cdf0e10cSrcweir     while ( !bInserted && pIter != rAvailableMigrations.end())
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir         if ( pIter->nPriority < aSupportedMigration.nPriority )
409cdf0e10cSrcweir         {
410cdf0e10cSrcweir             rAvailableMigrations.insert(pIter, aSupportedMigration );
411cdf0e10cSrcweir             bInserted = true;
412cdf0e10cSrcweir             break; // i111193: insert invalidates iterator!
413cdf0e10cSrcweir         }
414cdf0e10cSrcweir         ++pIter;
415cdf0e10cSrcweir     }
416cdf0e10cSrcweir     if ( !bInserted )
417cdf0e10cSrcweir         rAvailableMigrations.push_back( aSupportedMigration );
418cdf0e10cSrcweir }
419cdf0e10cSrcweir 
readAvailableMigrations(migrations_available & rAvailableMigrations)420cdf0e10cSrcweir bool MigrationImpl::readAvailableMigrations(migrations_available& rAvailableMigrations)
421cdf0e10cSrcweir {
422cdf0e10cSrcweir     // get supported version names
423cdf0e10cSrcweir     uno::Reference< XNameAccess > aMigrationAccess(getConfigAccess("org.openoffice.Setup/Migration/SupportedVersions"), uno::UNO_QUERY_THROW);
424cdf0e10cSrcweir     uno::Sequence< OUString > seqSupportedVersions = aMigrationAccess->getElementNames();
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     const OUString aVersionIdentifiers( RTL_CONSTASCII_USTRINGPARAM( "VersionIdentifiers" ));
427cdf0e10cSrcweir     const OUString aPriorityIdentifier( RTL_CONSTASCII_USTRINGPARAM( "Priority" ));
428cdf0e10cSrcweir 
429cdf0e10cSrcweir     for (sal_Int32 i=0; i<seqSupportedVersions.getLength(); i++)
430cdf0e10cSrcweir     {
431cdf0e10cSrcweir         sal_Int32                 nPriority( 0 );
432cdf0e10cSrcweir         uno::Sequence< OUString > seqVersions;
433cdf0e10cSrcweir         uno::Reference< XNameAccess > xMigrationData( aMigrationAccess->getByName(seqSupportedVersions[i]), uno::UNO_QUERY_THROW );
434cdf0e10cSrcweir         xMigrationData->getByName( aVersionIdentifiers ) >>= seqVersions;
435cdf0e10cSrcweir         xMigrationData->getByName( aPriorityIdentifier ) >>= nPriority;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir         supported_migration aSupportedMigration;
438cdf0e10cSrcweir         aSupportedMigration.name      = seqSupportedVersions[i];
439cdf0e10cSrcweir         aSupportedMigration.nPriority = nPriority;
440cdf0e10cSrcweir         for (sal_Int32 j=0; j<seqVersions.getLength(); j++)
441cdf0e10cSrcweir             aSupportedMigration.supported_versions.push_back(seqVersions[j].trim());
442cdf0e10cSrcweir         insertSorted( rAvailableMigrations, aSupportedMigration );
443cdf0e10cSrcweir     }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     return true;
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
readMigrationSteps(const::rtl::OUString & rMigrationName)448cdf0e10cSrcweir migrations_vr MigrationImpl::readMigrationSteps(const ::rtl::OUString& rMigrationName)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir     // get migration access
451cdf0e10cSrcweir     uno::Reference< XNameAccess > aMigrationAccess(getConfigAccess("org.openoffice.Setup/Migration/SupportedVersions"), uno::UNO_QUERY_THROW);
452cdf0e10cSrcweir     uno::Reference< XNameAccess > xMigrationData( aMigrationAccess->getByName(rMigrationName), uno::UNO_QUERY_THROW );
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     // get migration description from from org.openoffice.Setup/Migration
455cdf0e10cSrcweir     // and build vector of migration steps
456cdf0e10cSrcweir     OUString aMigrationSteps( RTL_CONSTASCII_USTRINGPARAM( "MigrationSteps" ));
457cdf0e10cSrcweir     uno::Reference< XNameAccess > theNameAccess(xMigrationData->getByName(aMigrationSteps), uno::UNO_QUERY_THROW);
458cdf0e10cSrcweir     uno::Sequence< OUString > seqMigrations = theNameAccess->getElementNames();
459cdf0e10cSrcweir     uno::Reference< XNameAccess > tmpAccess;
460cdf0e10cSrcweir     uno::Reference< XNameAccess > tmpAccess2;
461cdf0e10cSrcweir     uno::Sequence< OUString > tmpSeq;
462cdf0e10cSrcweir     migrations_vr vrMigrations(new migrations_v);
463cdf0e10cSrcweir     for (sal_Int32 i = 0; i < seqMigrations.getLength(); i++)
464cdf0e10cSrcweir     {
465cdf0e10cSrcweir         // get current migration step
466cdf0e10cSrcweir         theNameAccess->getByName(seqMigrations[i]) >>= tmpAccess;
467cdf0e10cSrcweir         // tmpStepPtr = new migration_step();
468cdf0e10cSrcweir         migration_step tmpStep;
469cdf0e10cSrcweir         tmpStep.name = seqMigrations[i];
470cdf0e10cSrcweir 
471cdf0e10cSrcweir         // read included files from current step description
472cdf0e10cSrcweir         ::rtl::OUString aSeqEntry;
473cdf0e10cSrcweir         if (tmpAccess->getByName(OUString::createFromAscii("IncludedFiles")) >>= tmpSeq)
474cdf0e10cSrcweir         {
475cdf0e10cSrcweir             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
476cdf0e10cSrcweir             {
477cdf0e10cSrcweir                 aSeqEntry = tmpSeq[j];
478cdf0e10cSrcweir                 tmpStep.includeFiles.push_back(aSeqEntry);
479cdf0e10cSrcweir             }
480cdf0e10cSrcweir         }
481cdf0e10cSrcweir 
482*33608c82Smseidel         // excluded files...
483cdf0e10cSrcweir         if (tmpAccess->getByName(OUString::createFromAscii("ExcludedFiles")) >>= tmpSeq)
484cdf0e10cSrcweir         {
485cdf0e10cSrcweir             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
486cdf0e10cSrcweir                 tmpStep.excludeFiles.push_back(tmpSeq[j]);
487cdf0e10cSrcweir         }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir         // included nodes...
490cdf0e10cSrcweir         if (tmpAccess->getByName(OUString::createFromAscii("IncludedNodes")) >>= tmpSeq)
491cdf0e10cSrcweir         {
492cdf0e10cSrcweir             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
493cdf0e10cSrcweir                 tmpStep.includeConfig.push_back(tmpSeq[j]);
494cdf0e10cSrcweir         }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir         // excluded nodes...
497cdf0e10cSrcweir         if (tmpAccess->getByName(OUString::createFromAscii("ExcludedNodes")) >>= tmpSeq)
498cdf0e10cSrcweir         {
499cdf0e10cSrcweir             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
500cdf0e10cSrcweir                 tmpStep.excludeConfig.push_back(tmpSeq[j]);
501cdf0e10cSrcweir         }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir         // included extensions...
504cdf0e10cSrcweir         if (tmpAccess->getByName(OUString::createFromAscii("IncludedExtensions")) >>= tmpSeq)
505cdf0e10cSrcweir         {
506cdf0e10cSrcweir             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
507cdf0e10cSrcweir                 tmpStep.includeExtensions.push_back(tmpSeq[j]);
508cdf0e10cSrcweir         }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir         // excluded extensions...
511cdf0e10cSrcweir         if (tmpAccess->getByName(OUString::createFromAscii("ExcludedExtensions")) >>= tmpSeq)
512cdf0e10cSrcweir         {
513cdf0e10cSrcweir             for (sal_Int32 j=0; j<tmpSeq.getLength(); j++)
514cdf0e10cSrcweir             {
515cdf0e10cSrcweir                 aSeqEntry = tmpSeq[j];
516cdf0e10cSrcweir                 tmpStep.excludeExtensions.push_back(aSeqEntry);
517cdf0e10cSrcweir             }
518cdf0e10cSrcweir         }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir         // generic service
521cdf0e10cSrcweir         tmpAccess->getByName(OUString::createFromAscii("MigrationService")) >>= tmpStep.service;
522cdf0e10cSrcweir 
523cdf0e10cSrcweir         vrMigrations->push_back(tmpStep);
524cdf0e10cSrcweir     }
525cdf0e10cSrcweir     return vrMigrations;
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
_checkAndCreateDirectory(INetURLObject & dirURL)528cdf0e10cSrcweir static FileBase::RC _checkAndCreateDirectory(INetURLObject& dirURL)
529cdf0e10cSrcweir {
530cdf0e10cSrcweir     FileBase::RC result = Directory::create(dirURL.GetMainURL(INetURLObject::DECODE_TO_IURI));
531cdf0e10cSrcweir     if (result == FileBase::E_NOENT)
532cdf0e10cSrcweir     {
533cdf0e10cSrcweir         INetURLObject baseURL(dirURL);
534cdf0e10cSrcweir         baseURL.removeSegment();
535cdf0e10cSrcweir         _checkAndCreateDirectory(baseURL);
536cdf0e10cSrcweir         return Directory::create(dirURL.GetMainURL(INetURLObject::DECODE_TO_IURI));
537cdf0e10cSrcweir     } else
538cdf0e10cSrcweir         return result;
539cdf0e10cSrcweir }
540cdf0e10cSrcweir 
findInstallation(const strings_v & rVersions)541cdf0e10cSrcweir install_info MigrationImpl::findInstallation(const strings_v& rVersions)
542cdf0e10cSrcweir {
543cdf0e10cSrcweir     rtl::OUString aProductName;
544cdf0e10cSrcweir     uno::Any aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME );
545cdf0e10cSrcweir     aRet >>= aProductName;
546cdf0e10cSrcweir     aProductName = aProductName.toAsciiLowerCase();
547cdf0e10cSrcweir 
548cdf0e10cSrcweir     install_info aInfo;
549cdf0e10cSrcweir     strings_v::const_iterator i_ver = rVersions.begin();
550cdf0e10cSrcweir     uno::Reference < util::XStringSubstitution > xSubst( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.PathSubstitution")), uno::UNO_QUERY );
551cdf0e10cSrcweir     while (i_ver != rVersions.end())
552cdf0e10cSrcweir     {
553cdf0e10cSrcweir         ::rtl::OUString aVersion, aProfileName;
554cdf0e10cSrcweir         sal_Int32 nSeparatorIndex = (*i_ver).indexOf('=');
555cdf0e10cSrcweir         if ( nSeparatorIndex != -1 )
556cdf0e10cSrcweir         {
557cdf0e10cSrcweir             aVersion = (*i_ver).copy( 0, nSeparatorIndex );
558cdf0e10cSrcweir             aProfileName = (*i_ver).copy( nSeparatorIndex+1 );
559cdf0e10cSrcweir         }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir         if ( aVersion.getLength() && aProfileName.getLength() &&
562cdf0e10cSrcweir                 ( !aInfo.userdata.getLength() || !aProfileName.toAsciiLowerCase().compareTo( aProductName, aProductName.getLength() ) )
563cdf0e10cSrcweir            )
564cdf0e10cSrcweir         {
565cdf0e10cSrcweir             ::rtl::OUString aUserInst;
566cdf0e10cSrcweir             osl::Security().getConfigDir( aUserInst );
567cdf0e10cSrcweir             if ( aUserInst.getLength() && aUserInst[ aUserInst.getLength()-1 ] != '/' )
568cdf0e10cSrcweir                 aUserInst += ::rtl::OUString::createFromAscii("/");
569cdf0e10cSrcweir #if defined UNX && ! defined MACOSX
570cdf0e10cSrcweir             // tribute to whoever had the "great" idea to use different names on Windows and Unix
571cdf0e10cSrcweir             aUserInst += ::rtl::OUString::createFromAscii(".");
572cdf0e10cSrcweir #endif
573cdf0e10cSrcweir             aUserInst += aProfileName;
574cdf0e10cSrcweir             try
575cdf0e10cSrcweir             {
576cdf0e10cSrcweir                 INetURLObject aObj(aUserInst);
577cdf0e10cSrcweir                 ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
578cdf0e10cSrcweir                 aCnt.isDocument();
579cdf0e10cSrcweir                 aInfo.userdata = aObj.GetMainURL( INetURLObject::NO_DECODE );
580cdf0e10cSrcweir                 aInfo.productname = aVersion;
581cdf0e10cSrcweir             }
582cdf0e10cSrcweir             catch( uno::Exception& ){}
583cdf0e10cSrcweir         }
584cdf0e10cSrcweir         ++i_ver;
585cdf0e10cSrcweir     }
586cdf0e10cSrcweir 
587cdf0e10cSrcweir     return aInfo;
588cdf0e10cSrcweir }
589cdf0e10cSrcweir 
findPreferedMigrationProcess(const migrations_available & rAvailableMigrations)590cdf0e10cSrcweir sal_Int32 MigrationImpl::findPreferedMigrationProcess(const migrations_available& rAvailableMigrations)
591cdf0e10cSrcweir {
592cdf0e10cSrcweir     sal_Int32    nIndex( -1 );
593cdf0e10cSrcweir     sal_Int32    i( 0 );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir     migrations_available::const_iterator rIter = rAvailableMigrations.begin();
596cdf0e10cSrcweir     while ( rIter != rAvailableMigrations.end() )
597cdf0e10cSrcweir     {
598cdf0e10cSrcweir         install_info aInstallInfo = findInstallation(rIter->supported_versions);
599cdf0e10cSrcweir         if (aInstallInfo.productname.getLength() > 0 )
600cdf0e10cSrcweir         {
601cdf0e10cSrcweir             m_aInfo = aInstallInfo;
602cdf0e10cSrcweir             nIndex  = i;
603cdf0e10cSrcweir             break;
604cdf0e10cSrcweir         }
605cdf0e10cSrcweir         ++i;
606cdf0e10cSrcweir         ++rIter;
607cdf0e10cSrcweir     }
608cdf0e10cSrcweir 
609cdf0e10cSrcweir     return nIndex;
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
applyPatterns(const strings_v & vSet,const strings_v & vPatterns) const612cdf0e10cSrcweir strings_vr MigrationImpl::applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const
613cdf0e10cSrcweir {
614cdf0e10cSrcweir     using namespace utl;
615cdf0e10cSrcweir     strings_vr vrResult(new strings_v);
616cdf0e10cSrcweir     strings_v::const_iterator i_set;
617cdf0e10cSrcweir     strings_v::const_iterator i_pat = vPatterns.begin();
618cdf0e10cSrcweir     while (i_pat != vPatterns.end())
619cdf0e10cSrcweir     {
620cdf0e10cSrcweir         // find matches for this pattern in input set
621cdf0e10cSrcweir         // and copy them to the result
622cdf0e10cSrcweir         SearchParam param(*i_pat, SearchParam::SRCH_REGEXP);
623cdf0e10cSrcweir         TextSearch ts(param, LANGUAGE_DONTKNOW);
624cdf0e10cSrcweir         i_set = vSet.begin();
625cdf0e10cSrcweir         xub_StrLen start = 0;
626cdf0e10cSrcweir         xub_StrLen end = 0;
627cdf0e10cSrcweir         while (i_set != vSet.end())
628cdf0e10cSrcweir         {
629cdf0e10cSrcweir             end = (xub_StrLen)(i_set->getLength());
630cdf0e10cSrcweir             if (ts.SearchFrwrd(*i_set, &start, &end))
631cdf0e10cSrcweir                 vrResult->push_back(*i_set);
632cdf0e10cSrcweir             i_set++;
633cdf0e10cSrcweir         }
634cdf0e10cSrcweir         i_pat++;
635cdf0e10cSrcweir     }
636cdf0e10cSrcweir     return vrResult;
637cdf0e10cSrcweir }
638cdf0e10cSrcweir 
getAllFiles(const OUString & baseURL) const639cdf0e10cSrcweir strings_vr MigrationImpl::getAllFiles(const OUString& baseURL) const
640cdf0e10cSrcweir {
641cdf0e10cSrcweir     using namespace osl;
642cdf0e10cSrcweir     strings_vr vrResult(new strings_v);
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     // get sub dirs
645cdf0e10cSrcweir     Directory dir(baseURL);
646cdf0e10cSrcweir     if (dir.open() == FileBase::E_None)
647cdf0e10cSrcweir     {
648cdf0e10cSrcweir         strings_v vSubDirs;
649cdf0e10cSrcweir         strings_vr vrSubResult;
650cdf0e10cSrcweir 
651cdf0e10cSrcweir         // work through directory contents...
652cdf0e10cSrcweir         DirectoryItem item;
653cdf0e10cSrcweir         FileStatus fs(FileStatusMask_Type | FileStatusMask_FileURL);
654cdf0e10cSrcweir         while (dir.getNextItem(item) == FileBase::E_None)
655cdf0e10cSrcweir         {
656cdf0e10cSrcweir             if (item.getFileStatus(fs) == FileBase::E_None)
657cdf0e10cSrcweir             {
658cdf0e10cSrcweir                 if (fs.getFileType() == FileStatus::Directory)
659cdf0e10cSrcweir                     vSubDirs.push_back(fs.getFileURL());
660cdf0e10cSrcweir                 else
661cdf0e10cSrcweir                     vrResult->push_back(fs.getFileURL());
662cdf0e10cSrcweir             }
663cdf0e10cSrcweir         }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir         // recurse subfolders
666cdf0e10cSrcweir         strings_v::const_iterator i = vSubDirs.begin();
667cdf0e10cSrcweir         while (i != vSubDirs.end())
668cdf0e10cSrcweir         {
669cdf0e10cSrcweir             vrSubResult = getAllFiles(*i);
670cdf0e10cSrcweir             vrResult->insert(vrResult->end(), vrSubResult->begin(), vrSubResult->end());
671cdf0e10cSrcweir             i++;
672cdf0e10cSrcweir         }
673cdf0e10cSrcweir     }
674cdf0e10cSrcweir     return vrResult;
675cdf0e10cSrcweir }
676cdf0e10cSrcweir 
compileFileList()677cdf0e10cSrcweir strings_vr MigrationImpl::compileFileList()
678cdf0e10cSrcweir {
679cdf0e10cSrcweir 
680cdf0e10cSrcweir     strings_vr vrResult(new strings_v);
681cdf0e10cSrcweir     strings_vr vrInclude;
682cdf0e10cSrcweir     strings_vr vrExclude;
683cdf0e10cSrcweir     strings_vr vrTemp;
684cdf0e10cSrcweir 
685cdf0e10cSrcweir #ifdef SAL_OS2
686cdf0e10cSrcweir     if (m_aInfo.userdata.getLength() == 0)
687cdf0e10cSrcweir         return vrResult;
688cdf0e10cSrcweir #endif
689cdf0e10cSrcweir 
690cdf0e10cSrcweir     // get a list of all files:
691cdf0e10cSrcweir     strings_vr vrFiles = getAllFiles(m_aInfo.userdata);
692cdf0e10cSrcweir 
693cdf0e10cSrcweir     // get a file list result for each migration step
694cdf0e10cSrcweir     migrations_v::const_iterator i_migr = m_vrMigrations->begin();
695cdf0e10cSrcweir     while (i_migr != m_vrMigrations->end())
696cdf0e10cSrcweir     {
697cdf0e10cSrcweir         vrInclude = applyPatterns(*vrFiles, i_migr->includeFiles);
698cdf0e10cSrcweir         vrExclude = applyPatterns(*vrFiles, i_migr->excludeFiles);
699cdf0e10cSrcweir         substract(*vrInclude, *vrExclude);
700cdf0e10cSrcweir         vrResult->insert(vrResult->end(), vrInclude->begin(), vrInclude->end());
701cdf0e10cSrcweir         i_migr++;
702cdf0e10cSrcweir     }
703cdf0e10cSrcweir     return vrResult;
704cdf0e10cSrcweir }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir namespace {
707cdf0e10cSrcweir 
708cdf0e10cSrcweir struct componentParts {
709cdf0e10cSrcweir     std::set< rtl::OUString > includedPaths;
710cdf0e10cSrcweir     std::set< rtl::OUString > excludedPaths;
711cdf0e10cSrcweir };
712cdf0e10cSrcweir 
713cdf0e10cSrcweir typedef std::map< rtl::OUString, componentParts > Components;
714cdf0e10cSrcweir 
getComponent(rtl::OUString const & path,rtl::OUString * component)715cdf0e10cSrcweir bool getComponent(rtl::OUString const & path, rtl::OUString * component) {
716cdf0e10cSrcweir     OSL_ASSERT(component != 0);
717cdf0e10cSrcweir     if (path.getLength() == 0 || path[0] != '/') {
718cdf0e10cSrcweir         OSL_TRACE(
719cdf0e10cSrcweir             ("configuration migration in/exclude path %s ignored (does not"
720cdf0e10cSrcweir              " start with slash)"),
721cdf0e10cSrcweir             rtl::OUStringToOString(path, RTL_TEXTENCODING_UTF8).getStr());
722cdf0e10cSrcweir         return false;
723cdf0e10cSrcweir     }
724cdf0e10cSrcweir     sal_Int32 i = path.indexOf('/', 1);
725cdf0e10cSrcweir     *component = i < 0 ? path.copy(1) : path.copy(1, i - 1);
726cdf0e10cSrcweir     return true;
727cdf0e10cSrcweir }
728cdf0e10cSrcweir 
setToSeq(std::set<rtl::OUString> const & set)729cdf0e10cSrcweir uno::Sequence< rtl::OUString > setToSeq(std::set< rtl::OUString > const & set) {
730cdf0e10cSrcweir     std::set< rtl::OUString >::size_type n = set.size();
731cdf0e10cSrcweir     if (n > SAL_MAX_INT32) {
732cdf0e10cSrcweir         throw std::bad_alloc();
733cdf0e10cSrcweir     }
734cdf0e10cSrcweir     uno::Sequence< rtl::OUString > seq(static_cast< sal_Int32 >(n));
735cdf0e10cSrcweir     sal_Int32 i = 0;
736cdf0e10cSrcweir     for (std::set< rtl::OUString >::const_iterator j(set.begin());
737cdf0e10cSrcweir          j != set.end(); ++j)
738cdf0e10cSrcweir     {
739cdf0e10cSrcweir         seq[i++] = *j;
740cdf0e10cSrcweir     }
741cdf0e10cSrcweir     return seq;
742cdf0e10cSrcweir }
743cdf0e10cSrcweir 
744cdf0e10cSrcweir }
745cdf0e10cSrcweir 
copyConfig()746cdf0e10cSrcweir void MigrationImpl::copyConfig() {
747cdf0e10cSrcweir     Components comps;
748cdf0e10cSrcweir     for (migrations_v::const_iterator i(m_vrMigrations->begin());
749cdf0e10cSrcweir          i != m_vrMigrations->end(); ++i)
750cdf0e10cSrcweir     {
751cdf0e10cSrcweir         for (strings_v::const_iterator j(i->includeConfig.begin());
752cdf0e10cSrcweir              j != i->includeConfig.end(); ++j)
753cdf0e10cSrcweir         {
754cdf0e10cSrcweir             rtl::OUString comp;
755cdf0e10cSrcweir             if (getComponent(*j, &comp)) {
756cdf0e10cSrcweir                 comps[comp].includedPaths.insert(*j);
757cdf0e10cSrcweir             }
758cdf0e10cSrcweir         }
759cdf0e10cSrcweir         for (strings_v::const_iterator j(i->excludeConfig.begin());
760cdf0e10cSrcweir              j != i->excludeConfig.end(); ++j)
761cdf0e10cSrcweir         {
762cdf0e10cSrcweir             rtl::OUString comp;
763cdf0e10cSrcweir             if (getComponent(*j, &comp)) {
764cdf0e10cSrcweir                 comps[comp].excludedPaths.insert(*j);
765cdf0e10cSrcweir             }
766cdf0e10cSrcweir         }
767cdf0e10cSrcweir     }
768cdf0e10cSrcweir     for (Components::const_iterator i(comps.begin()); i != comps.end(); ++i) {
769cdf0e10cSrcweir         if (!i->second.includedPaths.empty()) {
770cdf0e10cSrcweir             rtl::OUStringBuffer buf(m_aInfo.userdata);
7715e679a6cSOliver-Rainer Wittmann             if ( m_aInfo.productname.equals( OUString::createFromAscii("OpenOffice.org 3") ) )
7725e679a6cSOliver-Rainer Wittmann             {
7735e679a6cSOliver-Rainer Wittmann                 // OpenOffice.org 3 configuration file
7745e679a6cSOliver-Rainer Wittmann                 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("/user/registrymodifications.xcu"));
7755e679a6cSOliver-Rainer Wittmann             }
7765e679a6cSOliver-Rainer Wittmann             else
7775e679a6cSOliver-Rainer Wittmann             {
7785e679a6cSOliver-Rainer Wittmann                 // OpenOffice.org 2 configuration files
779cdf0e10cSrcweir                 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("/user/registry/data"));
780cdf0e10cSrcweir                 sal_Int32 n = 0;
781cdf0e10cSrcweir                 do {
782cdf0e10cSrcweir                     rtl::OUString seg(i->first.getToken(0, '.', n));
783cdf0e10cSrcweir                     rtl::OUString enc(
784cdf0e10cSrcweir                         rtl::Uri::encode(
785cdf0e10cSrcweir                             seg, rtl_UriCharClassPchar, rtl_UriEncodeStrict,
786cdf0e10cSrcweir                             RTL_TEXTENCODING_UTF8));
787cdf0e10cSrcweir                     if (enc.getLength() == 0 && seg.getLength() != 0) {
788cdf0e10cSrcweir                         OSL_TRACE(
789cdf0e10cSrcweir                             ("configuration migration component %s ignored (cannot"
790cdf0e10cSrcweir                              " be encoded as file path)"),
791cdf0e10cSrcweir                             rtl::OUStringToOString(
792cdf0e10cSrcweir                                 i->first, RTL_TEXTENCODING_UTF8).getStr());
793cdf0e10cSrcweir                         goto next;
794cdf0e10cSrcweir                     }
795cdf0e10cSrcweir                     buf.append(sal_Unicode('/'));
796cdf0e10cSrcweir                     buf.append(enc);
797cdf0e10cSrcweir                 } while (n >= 0);
798cdf0e10cSrcweir                 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(".xcu"));
7995e679a6cSOliver-Rainer Wittmann             }
800cdf0e10cSrcweir             configuration::Update::get(
801cdf0e10cSrcweir                 comphelper::getProcessComponentContext())->
802cdf0e10cSrcweir                 insertModificationXcuFile(
803cdf0e10cSrcweir                     buf.makeStringAndClear(), setToSeq(i->second.includedPaths),
804cdf0e10cSrcweir                     setToSeq(i->second.excludedPaths));
805cdf0e10cSrcweir         } else {
806cdf0e10cSrcweir             OSL_TRACE(
807cdf0e10cSrcweir                 ("configuration migration component %s ignored (only excludes,"
808cdf0e10cSrcweir                  " no includes)"),
809cdf0e10cSrcweir                 rtl::OUStringToOString(
810cdf0e10cSrcweir                     i->first, RTL_TEXTENCODING_UTF8).getStr());
811cdf0e10cSrcweir         }
812cdf0e10cSrcweir     next:;
813cdf0e10cSrcweir     }
814cdf0e10cSrcweir }
815cdf0e10cSrcweir 
816cdf0e10cSrcweir // removes elements of vector 2 in vector 1
substract(strings_v & va,const strings_v & vb_c) const817cdf0e10cSrcweir void MigrationImpl::substract(strings_v& va, const strings_v& vb_c) const
818cdf0e10cSrcweir {
819cdf0e10cSrcweir     strings_v vb(vb_c);
820cdf0e10cSrcweir     // ensure uniqueness of entries
821cdf0e10cSrcweir     sort(va.begin(), va.end());
822cdf0e10cSrcweir     sort(vb.begin(), vb.end());
823cdf0e10cSrcweir     unique(va.begin(), va.end());
824cdf0e10cSrcweir     unique(vb.begin(), vb.end());
825cdf0e10cSrcweir 
826cdf0e10cSrcweir     strings_v::const_iterator i_ex = vb.begin();
827cdf0e10cSrcweir     strings_v::iterator i_in;
828cdf0e10cSrcweir     strings_v::iterator i_next;
829cdf0e10cSrcweir     while (i_ex != vb.end())
830cdf0e10cSrcweir     {
831cdf0e10cSrcweir         i_in = va.begin();
832cdf0e10cSrcweir         while (i_in != va.end())
833cdf0e10cSrcweir         {
834cdf0e10cSrcweir             if ( *i_in == *i_ex)
835cdf0e10cSrcweir             {
836cdf0e10cSrcweir                 i_next = i_in+1;
837cdf0e10cSrcweir                 va.erase(i_in);
838cdf0e10cSrcweir                 i_in = i_next;
839cdf0e10cSrcweir                 // we can only find one match since we
840*33608c82Smseidel                 // ensured uniqueness of the entries. ergo:
841cdf0e10cSrcweir                 break;
842cdf0e10cSrcweir             }
843cdf0e10cSrcweir             else
844cdf0e10cSrcweir                 i_in++;
845cdf0e10cSrcweir         }
846cdf0e10cSrcweir         i_ex++;
847cdf0e10cSrcweir     }
848cdf0e10cSrcweir }
849cdf0e10cSrcweir 
getConfigAccess(const sal_Char * pPath,sal_Bool bUpdate)850cdf0e10cSrcweir uno::Reference< XNameAccess > MigrationImpl::getConfigAccess(const sal_Char* pPath, sal_Bool bUpdate)
851cdf0e10cSrcweir {
852cdf0e10cSrcweir     uno::Reference< XNameAccess > xNameAccess;
853cdf0e10cSrcweir     try{
854cdf0e10cSrcweir         OUString sConfigSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider");
855cdf0e10cSrcweir         OUString sAccessSrvc;
856cdf0e10cSrcweir         if (bUpdate)
857cdf0e10cSrcweir             sAccessSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationUpdateAccess");
858cdf0e10cSrcweir         else
859cdf0e10cSrcweir             sAccessSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess");
860cdf0e10cSrcweir 
861cdf0e10cSrcweir         OUString sConfigURL = OUString::createFromAscii(pPath);
862cdf0e10cSrcweir 
863cdf0e10cSrcweir         // get configuration provider
864cdf0e10cSrcweir         uno::Reference< XMultiServiceFactory > theMSF = comphelper::getProcessServiceFactory();
865cdf0e10cSrcweir         uno::Reference< XMultiServiceFactory > theConfigProvider = uno::Reference< XMultiServiceFactory > (
866cdf0e10cSrcweir                 theMSF->createInstance( sConfigSrvc ),uno::UNO_QUERY_THROW );
867cdf0e10cSrcweir 
868cdf0e10cSrcweir         // access the provider
869cdf0e10cSrcweir         uno::Sequence< uno::Any > theArgs(1);
870cdf0e10cSrcweir         theArgs[ 0 ] <<= sConfigURL;
871cdf0e10cSrcweir         xNameAccess = uno::Reference< XNameAccess > (
872cdf0e10cSrcweir                 theConfigProvider->createInstanceWithArguments(
873cdf0e10cSrcweir                 sAccessSrvc, theArgs ), uno::UNO_QUERY_THROW );
874cdf0e10cSrcweir     } catch (com::sun::star::uno::Exception& e)
875cdf0e10cSrcweir     {
876cdf0e10cSrcweir         OString aMsg = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
877cdf0e10cSrcweir         OSL_ENSURE(sal_False, aMsg.getStr());
878cdf0e10cSrcweir     }
879cdf0e10cSrcweir     return xNameAccess;
880cdf0e10cSrcweir }
881cdf0e10cSrcweir 
copyFiles()882cdf0e10cSrcweir void MigrationImpl::copyFiles()
883cdf0e10cSrcweir {
884cdf0e10cSrcweir     strings_v::const_iterator i_file = m_vrFileList->begin();
885cdf0e10cSrcweir     OUString localName;
886cdf0e10cSrcweir     OUString destName;
887cdf0e10cSrcweir     OUString userInstall;
888cdf0e10cSrcweir     utl::Bootstrap::PathStatus aStatus;
889cdf0e10cSrcweir     aStatus = utl::Bootstrap::locateUserInstallation(userInstall);
890cdf0e10cSrcweir     if (aStatus == utl::Bootstrap::PATH_EXISTS)
891cdf0e10cSrcweir     {
892cdf0e10cSrcweir         while (i_file != m_vrFileList->end())
893cdf0e10cSrcweir         {
894cdf0e10cSrcweir 
895cdf0e10cSrcweir             // remove installation prefix from file
896cdf0e10cSrcweir             localName = i_file->copy(m_aInfo.userdata.getLength());
897cdf0e10cSrcweir             destName = userInstall + localName;
898cdf0e10cSrcweir             INetURLObject aURL(destName);
899cdf0e10cSrcweir             // check whether destination directory exists
900cdf0e10cSrcweir             aURL.removeSegment();
901cdf0e10cSrcweir             _checkAndCreateDirectory(aURL);
902cdf0e10cSrcweir             FileBase::RC copyResult = File::copy(*i_file, destName);
903cdf0e10cSrcweir             if (copyResult != FileBase::E_None)
904cdf0e10cSrcweir             {
905cdf0e10cSrcweir                 OString msg("Cannot copy ");
906cdf0e10cSrcweir                 msg += OUStringToOString(*i_file, RTL_TEXTENCODING_UTF8) + " to "
907cdf0e10cSrcweir                     +  OUStringToOString(destName, RTL_TEXTENCODING_UTF8);
908cdf0e10cSrcweir                 OSL_ENSURE(sal_False, msg.getStr());
909cdf0e10cSrcweir             }
910cdf0e10cSrcweir             i_file++;
911cdf0e10cSrcweir         }
912cdf0e10cSrcweir     }
913cdf0e10cSrcweir     else
914cdf0e10cSrcweir     {
915cdf0e10cSrcweir         OSL_ENSURE(sal_False, "copyFiles: UserInstall does not exist");
916cdf0e10cSrcweir     }
917cdf0e10cSrcweir }
918cdf0e10cSrcweir 
runServices()919cdf0e10cSrcweir void MigrationImpl::runServices()
920cdf0e10cSrcweir {
921cdf0e10cSrcweir     // Build argument array
922cdf0e10cSrcweir     uno::Sequence< uno::Any > seqArguments(3);
923cdf0e10cSrcweir     seqArguments[0] = uno::makeAny(NamedValue(
924cdf0e10cSrcweir         OUString::createFromAscii("Productname"),
925cdf0e10cSrcweir         uno::makeAny(m_aInfo.productname)));
926cdf0e10cSrcweir     seqArguments[1] = uno::makeAny(NamedValue(
927cdf0e10cSrcweir         OUString::createFromAscii("UserData"),
928cdf0e10cSrcweir         uno::makeAny(m_aInfo.userdata)));
929cdf0e10cSrcweir 
930cdf0e10cSrcweir 
931cdf0e10cSrcweir     // create an instance of every migration service
932cdf0e10cSrcweir     // and execute the migration job
933cdf0e10cSrcweir     uno::Reference< XJob > xMigrationJob;
934cdf0e10cSrcweir 
935cdf0e10cSrcweir     migrations_v::const_iterator i_mig = m_vrMigrations->begin();
936cdf0e10cSrcweir     while (i_mig != m_vrMigrations->end())
937cdf0e10cSrcweir     {
938cdf0e10cSrcweir         if( i_mig->service.getLength() > 0)
939cdf0e10cSrcweir         {
940cdf0e10cSrcweir 
941cdf0e10cSrcweir             try
942cdf0e10cSrcweir             {
943cdf0e10cSrcweir                 // set black list for extension migration
944cdf0e10cSrcweir                 uno::Sequence< rtl::OUString > seqExtBlackList;
945cdf0e10cSrcweir                 sal_uInt32 nSize = i_mig->excludeExtensions.size();
946cdf0e10cSrcweir                 if ( nSize > 0 )
947cdf0e10cSrcweir                     seqExtBlackList = comphelper::arrayToSequence< ::rtl::OUString >(
948cdf0e10cSrcweir                         &i_mig->excludeExtensions[0], nSize );
949cdf0e10cSrcweir                 seqArguments[2] = uno::makeAny(NamedValue(
950cdf0e10cSrcweir                     OUString::createFromAscii("ExtensionBlackList"),
951cdf0e10cSrcweir                     uno::makeAny( seqExtBlackList )));
952cdf0e10cSrcweir 
953cdf0e10cSrcweir                 xMigrationJob = uno::Reference< XJob >(m_xFactory->createInstanceWithArguments(
954cdf0e10cSrcweir                     i_mig->service, seqArguments), uno::UNO_QUERY_THROW);
955cdf0e10cSrcweir 
956cdf0e10cSrcweir                 xMigrationJob->execute(uno::Sequence< NamedValue >());
957cdf0e10cSrcweir 
958cdf0e10cSrcweir 
959cdf0e10cSrcweir             } catch (Exception& e)
960cdf0e10cSrcweir             {
961cdf0e10cSrcweir                 OString aMsg("Execution of migration service failed (Exception caught).\nService: ");
962cdf0e10cSrcweir                 aMsg += OUStringToOString(i_mig->service, RTL_TEXTENCODING_ASCII_US) + "\nMessage: ";
963cdf0e10cSrcweir                 aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
964cdf0e10cSrcweir                 OSL_ENSURE(sal_False, aMsg.getStr());
965cdf0e10cSrcweir             } catch (...)
966cdf0e10cSrcweir             {
967cdf0e10cSrcweir                 OString aMsg("Execution of migration service failed (Exception caught).\nService: ");
968cdf0e10cSrcweir                 aMsg += OUStringToOString(i_mig->service, RTL_TEXTENCODING_ASCII_US) +
969cdf0e10cSrcweir                     "\nNo message available";
970cdf0e10cSrcweir                 OSL_ENSURE(sal_False, aMsg.getStr());
971cdf0e10cSrcweir             }
972cdf0e10cSrcweir 
973cdf0e10cSrcweir         }
974cdf0e10cSrcweir         i_mig++;
975cdf0e10cSrcweir     }
976cdf0e10cSrcweir }
977cdf0e10cSrcweir 
dectectUIChangesForAllModules() const978cdf0e10cSrcweir ::std::vector< MigrationModuleInfo > MigrationImpl::dectectUIChangesForAllModules() const
979cdf0e10cSrcweir {
980cdf0e10cSrcweir     ::std::vector< MigrationModuleInfo > vModulesInfo;
981cdf0e10cSrcweir     const ::rtl::OUString MENUBAR = ::rtl::OUString::createFromAscii("menubar");
982cdf0e10cSrcweir     const ::rtl::OUString TOOLBAR = ::rtl::OUString::createFromAscii("toolbar");
983cdf0e10cSrcweir 
984cdf0e10cSrcweir     uno::Sequence< uno::Any > lArgs(2);
985cdf0e10cSrcweir     lArgs[0] <<= m_aInfo.userdata + ::rtl::OUString::createFromAscii("/user/config/soffice.cfg/modules");
986cdf0e10cSrcweir     lArgs[1] <<= embed::ElementModes::READ;
987cdf0e10cSrcweir 
988cdf0e10cSrcweir     uno::Reference< lang::XSingleServiceFactory > xStorageFactory(m_xFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.embed.FileSystemStorageFactory")), uno::UNO_QUERY);
989cdf0e10cSrcweir     uno::Reference< embed::XStorage >             xModules;
990cdf0e10cSrcweir 
991cdf0e10cSrcweir     xModules = uno::Reference< embed::XStorage >(xStorageFactory->createInstanceWithArguments(lArgs), uno::UNO_QUERY);
992cdf0e10cSrcweir     if (!xModules.is())
993cdf0e10cSrcweir         return vModulesInfo;
994cdf0e10cSrcweir 
995cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xAccess = uno::Reference< container::XNameAccess >(xModules, uno::UNO_QUERY);
996cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > lNames = xAccess->getElementNames();
997cdf0e10cSrcweir     sal_Int32 nLength = lNames.getLength();
998cdf0e10cSrcweir     for (sal_Int32 i=0; i<nLength; ++i)
999cdf0e10cSrcweir     {
1000cdf0e10cSrcweir         ::rtl::OUString sModuleShortName = lNames[i];
1001cdf0e10cSrcweir         uno::Reference< embed::XStorage > xModule = xModules->openStorageElement(sModuleShortName, embed::ElementModes::READ);
1002cdf0e10cSrcweir         if (xModule.is())
1003cdf0e10cSrcweir         {
1004cdf0e10cSrcweir             MigrationModuleInfo aModuleInfo;
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir             uno::Reference< embed::XStorage > xMenubar = xModule->openStorageElement(MENUBAR, embed::ElementModes::READ);
1007cdf0e10cSrcweir             if (xMenubar.is())
1008cdf0e10cSrcweir             {
1009cdf0e10cSrcweir                 uno::Reference< container::XNameAccess > xNameAccess = uno::Reference< container::XNameAccess >(xMenubar, uno::UNO_QUERY);
1010cdf0e10cSrcweir                 if (xNameAccess->getElementNames().getLength() > 0)
1011cdf0e10cSrcweir                 {
1012cdf0e10cSrcweir                     aModuleInfo.sModuleShortName = sModuleShortName;
1013cdf0e10cSrcweir                     aModuleInfo.bHasMenubar = sal_True;
1014cdf0e10cSrcweir                 }
1015cdf0e10cSrcweir             }
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir             uno::Reference< embed::XStorage > xToolbar = xModule->openStorageElement(TOOLBAR, embed::ElementModes::READ);
1018cdf0e10cSrcweir             if (xToolbar.is())
1019cdf0e10cSrcweir             {
1020cdf0e10cSrcweir                 const ::rtl::OUString RESOURCEURL_CUSTOM_ELEMENT = ::rtl::OUString::createFromAscii("custom_");
1021cdf0e10cSrcweir                 sal_Int32 nCustomLen = 7;
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir                 uno::Reference< container::XNameAccess > xNameAccess = uno::Reference< container::XNameAccess >(xToolbar, uno::UNO_QUERY);
1024cdf0e10cSrcweir                 ::uno::Sequence< ::rtl::OUString > lToolbars = xNameAccess->getElementNames();
1025cdf0e10cSrcweir                 for (sal_Int32 j=0; j<lToolbars.getLength(); ++j)
1026cdf0e10cSrcweir                 {
1027cdf0e10cSrcweir                     ::rtl::OUString sToolbarName = lToolbars[j];
1028cdf0e10cSrcweir                     if (sToolbarName.getLength()>=nCustomLen &&
1029cdf0e10cSrcweir                         sToolbarName.copy(0, nCustomLen).equals(RESOURCEURL_CUSTOM_ELEMENT))
1030cdf0e10cSrcweir                         continue;
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir                     aModuleInfo.sModuleShortName = sModuleShortName;
1033cdf0e10cSrcweir                     sal_Int32 nIndex = sToolbarName.lastIndexOf('.');
1034cdf0e10cSrcweir                     if (nIndex > 0)
1035cdf0e10cSrcweir                     {
1036cdf0e10cSrcweir                         ::rtl::OUString sExtension(sToolbarName.copy(nIndex));
1037cdf0e10cSrcweir                         ::rtl::OUString sToolbarResourceName(sToolbarName.copy(0, nIndex));
1038cdf0e10cSrcweir                         if (sToolbarResourceName.getLength()>0 && sExtension.equalsAsciiL(".xml", 4))
1039cdf0e10cSrcweir                             aModuleInfo.m_vToolbars.push_back(sToolbarResourceName);
1040cdf0e10cSrcweir                     }
1041cdf0e10cSrcweir                 }
1042cdf0e10cSrcweir             }
1043cdf0e10cSrcweir 
1044cdf0e10cSrcweir             if (aModuleInfo.sModuleShortName.getLength()>0)
1045cdf0e10cSrcweir                 vModulesInfo.push_back(aModuleInfo);
1046cdf0e10cSrcweir         }
1047cdf0e10cSrcweir     }
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir     return vModulesInfo;
1050cdf0e10cSrcweir }
1051cdf0e10cSrcweir 
compareOldAndNewConfig(const::rtl::OUString & sParent,const uno::Reference<container::XIndexContainer> & xIndexOld,const uno::Reference<container::XIndexContainer> & xIndexNew,const::rtl::OUString & sResourceURL)1052cdf0e10cSrcweir void MigrationImpl::compareOldAndNewConfig(const ::rtl::OUString& sParent,
1053cdf0e10cSrcweir                                            const uno::Reference< container::XIndexContainer >& xIndexOld,
1054cdf0e10cSrcweir                                            const uno::Reference< container::XIndexContainer >& xIndexNew,
1055cdf0e10cSrcweir                                            const ::rtl::OUString& sResourceURL)
1056cdf0e10cSrcweir {
1057cdf0e10cSrcweir     ::std::vector< MigrationItem > vOldItems;
1058cdf0e10cSrcweir     ::std::vector< MigrationItem > vNewItems;
1059cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aProp;
1060cdf0e10cSrcweir     sal_Int32 nOldCount = xIndexOld->getCount();
1061cdf0e10cSrcweir     sal_Int32 nNewCount = xIndexNew->getCount();
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir     for (int n=0; n<nOldCount; ++n)
1064cdf0e10cSrcweir     {
1065cdf0e10cSrcweir         MigrationItem aMigrationItem;
1066cdf0e10cSrcweir         if (xIndexOld->getByIndex(n) >>= aProp)
1067cdf0e10cSrcweir         {
1068cdf0e10cSrcweir             for(int i=0; i<aProp.getLength(); ++i)
1069cdf0e10cSrcweir             {
1070cdf0e10cSrcweir                 if (aProp[i].Name.equals(ITEM_DESCRIPTOR_COMMANDURL))
1071cdf0e10cSrcweir                     aProp[i].Value >>= aMigrationItem.m_sCommandURL;
1072cdf0e10cSrcweir                 else if (aProp[i].Name.equals(ITEM_DESCRIPTOR_CONTAINER))
1073cdf0e10cSrcweir                     aProp[i].Value >>= aMigrationItem.m_xPopupMenu;
1074cdf0e10cSrcweir             }
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir             if (aMigrationItem.m_sCommandURL.getLength())
1077cdf0e10cSrcweir                 vOldItems.push_back(aMigrationItem);
1078cdf0e10cSrcweir         }
1079cdf0e10cSrcweir     }
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir     for (int n=0; n<nNewCount; ++n)
1082cdf0e10cSrcweir     {
1083cdf0e10cSrcweir         MigrationItem aMigrationItem;
1084cdf0e10cSrcweir         if (xIndexNew->getByIndex(n) >>= aProp)
1085cdf0e10cSrcweir         {
1086cdf0e10cSrcweir             for(int i=0; i<aProp.getLength(); ++i)
1087cdf0e10cSrcweir             {
1088cdf0e10cSrcweir                 if (aProp[i].Name.equals(ITEM_DESCRIPTOR_COMMANDURL))
1089cdf0e10cSrcweir                     aProp[i].Value >>= aMigrationItem.m_sCommandURL;
1090cdf0e10cSrcweir                 else if (aProp[i].Name.equals(ITEM_DESCRIPTOR_CONTAINER))
1091cdf0e10cSrcweir                     aProp[i].Value >>= aMigrationItem.m_xPopupMenu;
1092cdf0e10cSrcweir             }
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir             if (aMigrationItem.m_sCommandURL.getLength())
1095cdf0e10cSrcweir                 vNewItems.push_back(aMigrationItem);
1096cdf0e10cSrcweir         }
1097cdf0e10cSrcweir     }
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir     ::std::vector< MigrationItem >::iterator it;
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir     ::rtl::OUString sSibling;
1102cdf0e10cSrcweir     for (it = vOldItems.begin(); it!=vOldItems.end(); ++it)
1103cdf0e10cSrcweir     {
1104cdf0e10cSrcweir         ::std::vector< MigrationItem >::iterator pFound = ::std::find(vNewItems.begin(), vNewItems.end(), *it);
1105cdf0e10cSrcweir         if (pFound != vNewItems.end() && it->m_xPopupMenu.is())
1106cdf0e10cSrcweir         {
1107cdf0e10cSrcweir             ::rtl::OUString sName;
1108cdf0e10cSrcweir             if (sParent.getLength()>0)
1109cdf0e10cSrcweir                 sName = sParent + MENU_SEPERATOR + it->m_sCommandURL;
1110cdf0e10cSrcweir             else
1111cdf0e10cSrcweir                 sName = it->m_sCommandURL;
1112cdf0e10cSrcweir             compareOldAndNewConfig(sName, it->m_xPopupMenu, pFound->m_xPopupMenu, sResourceURL);
1113cdf0e10cSrcweir         }
1114cdf0e10cSrcweir         else if (pFound == vNewItems.end())
1115cdf0e10cSrcweir         {
1116cdf0e10cSrcweir             MigrationItem aMigrationItem(sParent, sSibling, it->m_sCommandURL, it->m_xPopupMenu);
1117cdf0e10cSrcweir             if (m_aOldVersionItemsHashMap.find(sResourceURL)==m_aOldVersionItemsHashMap.end())
1118cdf0e10cSrcweir             {
1119cdf0e10cSrcweir                 ::std::vector< MigrationItem > vMigrationItems;
1120cdf0e10cSrcweir                 m_aOldVersionItemsHashMap.insert(MigrationHashMap::value_type(sResourceURL, vMigrationItems));
1121cdf0e10cSrcweir                 m_aOldVersionItemsHashMap[sResourceURL].push_back(aMigrationItem);
1122cdf0e10cSrcweir             }
1123cdf0e10cSrcweir             else
1124cdf0e10cSrcweir             {
1125cdf0e10cSrcweir                 if (::std::find(m_aOldVersionItemsHashMap[sResourceURL].begin(), m_aOldVersionItemsHashMap[sResourceURL].end(), aMigrationItem)==m_aOldVersionItemsHashMap[sResourceURL].end())
1126cdf0e10cSrcweir                     m_aOldVersionItemsHashMap[sResourceURL].push_back(aMigrationItem);
1127cdf0e10cSrcweir             }
1128cdf0e10cSrcweir         }
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir         sSibling = it->m_sCommandURL;
1131cdf0e10cSrcweir     }
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir     ::rtl::OUString sNewSibling;
1134cdf0e10cSrcweir     uno::Reference< container::XIndexContainer > xPopup;
1135cdf0e10cSrcweir     for (it = vNewItems.begin(); it!=vNewItems.end(); ++it)
1136cdf0e10cSrcweir     {
1137cdf0e10cSrcweir         ::std::vector< MigrationItem >::iterator pFound = ::std::find(vOldItems.begin(), vOldItems.end(), *it);
1138cdf0e10cSrcweir         if (pFound != vOldItems.end() && it->m_xPopupMenu.is())
1139cdf0e10cSrcweir         {
1140cdf0e10cSrcweir             ::rtl::OUString sName;
1141cdf0e10cSrcweir             if (sParent.getLength()>0)
1142cdf0e10cSrcweir                 sName = sParent + MENU_SEPERATOR + it->m_sCommandURL;
1143cdf0e10cSrcweir             else
1144cdf0e10cSrcweir                 sName = it->m_sCommandURL;
1145cdf0e10cSrcweir             compareOldAndNewConfig(sName, pFound->m_xPopupMenu, it->m_xPopupMenu, sResourceURL);
1146cdf0e10cSrcweir         }
1147cdf0e10cSrcweir         else if (::std::find(vOldItems.begin(), vOldItems.end(), *it) == vOldItems.end())
1148cdf0e10cSrcweir         {
1149cdf0e10cSrcweir             MigrationItem aMigrationItem(sParent, sSibling, it->m_sCommandURL, it->m_xPopupMenu);
1150cdf0e10cSrcweir             if (m_aNewVersionItemsHashMap.find(sResourceURL)==m_aNewVersionItemsHashMap.end())
1151cdf0e10cSrcweir             {
1152cdf0e10cSrcweir                 ::std::vector< MigrationItem > vMigrationItems;
1153cdf0e10cSrcweir                 m_aNewVersionItemsHashMap.insert(MigrationHashMap::value_type(sResourceURL, vMigrationItems));
1154cdf0e10cSrcweir                 m_aNewVersionItemsHashMap[sResourceURL].push_back(aMigrationItem);
1155cdf0e10cSrcweir             }
1156cdf0e10cSrcweir             else
1157cdf0e10cSrcweir             {
1158cdf0e10cSrcweir                 if (::std::find(m_aNewVersionItemsHashMap[sResourceURL].begin(), m_aNewVersionItemsHashMap[sResourceURL].end(), aMigrationItem)==m_aNewVersionItemsHashMap[sResourceURL].end())
1159cdf0e10cSrcweir                     m_aNewVersionItemsHashMap[sResourceURL].push_back(aMigrationItem);
1160cdf0e10cSrcweir             }
1161cdf0e10cSrcweir         }
1162cdf0e10cSrcweir     }
1163cdf0e10cSrcweir }
1164cdf0e10cSrcweir 
mergeOldToNewVersion(const uno::Reference<ui::XUIConfigurationManager> & xCfgManager,const uno::Reference<container::XIndexContainer> & xIndexContainer,const::rtl::OUString & sModuleIdentifier,const::rtl::OUString & sResourceURL)1165cdf0e10cSrcweir void MigrationImpl::mergeOldToNewVersion(const uno::Reference< ui::XUIConfigurationManager >& xCfgManager,
1166cdf0e10cSrcweir                                          const uno::Reference< container::XIndexContainer>& xIndexContainer,
1167cdf0e10cSrcweir                                          const ::rtl::OUString& sModuleIdentifier,
1168cdf0e10cSrcweir                                          const ::rtl::OUString& sResourceURL)
1169cdf0e10cSrcweir {
1170cdf0e10cSrcweir     MigrationHashMap::iterator pFound = m_aOldVersionItemsHashMap.find(sResourceURL);
1171cdf0e10cSrcweir     if (pFound==m_aOldVersionItemsHashMap.end())
1172cdf0e10cSrcweir         return;
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir     ::std::vector< MigrationItem >::iterator it;
1175cdf0e10cSrcweir     for (it=pFound->second.begin(); it!=pFound->second.end(); ++it)
1176cdf0e10cSrcweir     {
1177cdf0e10cSrcweir         uno::Reference< container::XIndexContainer > xTemp = xIndexContainer;
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir         ::rtl::OUString sParentNodeName = it->m_sParentNodeName;
1180cdf0e10cSrcweir         sal_Int32 nIndex = 0;
1181cdf0e10cSrcweir         do
1182cdf0e10cSrcweir         {
1183cdf0e10cSrcweir             ::rtl::OUString sToken = sParentNodeName.getToken(0, '|', nIndex).trim();
1184cdf0e10cSrcweir             if (sToken.getLength()<=0)
1185cdf0e10cSrcweir                 break;
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir             sal_Int32 nCount = xTemp->getCount();
1188cdf0e10cSrcweir             for (sal_Int32 i=0; i<nCount; ++i)
1189cdf0e10cSrcweir             {
1190cdf0e10cSrcweir                 ::rtl::OUString sCommandURL;
1191cdf0e10cSrcweir                 ::rtl::OUString sLabel;
1192cdf0e10cSrcweir                 uno::Reference< container::XIndexContainer > xChild;
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir                 uno::Sequence< beans::PropertyValue > aPropSeq;
1195cdf0e10cSrcweir                 xTemp->getByIndex(i) >>= aPropSeq;
1196cdf0e10cSrcweir                 for (sal_Int32 j=0; j<aPropSeq.getLength(); ++j)
1197cdf0e10cSrcweir                 {
1198cdf0e10cSrcweir                     ::rtl::OUString sPropName = aPropSeq[j].Name;
1199cdf0e10cSrcweir                     if (sPropName.equals(ITEM_DESCRIPTOR_COMMANDURL))
1200cdf0e10cSrcweir                         aPropSeq[j].Value >>= sCommandURL;
1201cdf0e10cSrcweir                     else if (sPropName.equals(ITEM_DESCRIPTOR_LABEL))
1202cdf0e10cSrcweir                         aPropSeq[j].Value >>= sLabel;
1203cdf0e10cSrcweir                     else if (sPropName.equals(ITEM_DESCRIPTOR_CONTAINER))
1204cdf0e10cSrcweir                         aPropSeq[j].Value >>= xChild;
1205cdf0e10cSrcweir                 }
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir                 if (sCommandURL == sToken)
1208cdf0e10cSrcweir                 {
1209cdf0e10cSrcweir                     xTemp = xChild;
1210cdf0e10cSrcweir                     break;
1211cdf0e10cSrcweir                 }
1212cdf0e10cSrcweir             }
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir         } while (nIndex>=0);
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir         if (nIndex == -1)
1217cdf0e10cSrcweir         {
1218cdf0e10cSrcweir             uno::Sequence< beans::PropertyValue > aPropSeq(3);
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir             aPropSeq[0].Name = ITEM_DESCRIPTOR_COMMANDURL;
1221cdf0e10cSrcweir             aPropSeq[0].Value <<= it->m_sCommandURL;
1222cdf0e10cSrcweir             aPropSeq[1].Name = ITEM_DESCRIPTOR_LABEL;
1223cdf0e10cSrcweir             aPropSeq[1].Value <<= retrieveLabelFromCommand(it->m_sCommandURL, sModuleIdentifier);
1224cdf0e10cSrcweir             aPropSeq[2].Name = ITEM_DESCRIPTOR_CONTAINER;
1225cdf0e10cSrcweir             aPropSeq[2].Value <<= it->m_xPopupMenu;
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir             if (it->m_sPrevSibling.getLength() == 0)
1228cdf0e10cSrcweir                 xTemp->insertByIndex(0, uno::makeAny(aPropSeq));
1229cdf0e10cSrcweir             else if (it->m_sPrevSibling.getLength() > 0)
1230cdf0e10cSrcweir             {
1231cdf0e10cSrcweir                 sal_Int32 nCount = xTemp->getCount();
1232cdf0e10cSrcweir                 sal_Int32 i = 0;
1233cdf0e10cSrcweir                 for (; i<nCount; ++i)
1234cdf0e10cSrcweir                 {
1235cdf0e10cSrcweir                     ::rtl::OUString sCmd;
1236cdf0e10cSrcweir                     uno::Sequence< beans::PropertyValue > aTempPropSeq;
1237cdf0e10cSrcweir                     xTemp->getByIndex(i) >>= aTempPropSeq;
1238cdf0e10cSrcweir                     for (sal_Int32 j=0; j<aTempPropSeq.getLength(); ++j)
1239cdf0e10cSrcweir                     {
1240cdf0e10cSrcweir                         if (aTempPropSeq[j].Name.equals(ITEM_DESCRIPTOR_COMMANDURL))
1241cdf0e10cSrcweir                         {
1242cdf0e10cSrcweir                             aTempPropSeq[j].Value >>= sCmd;
1243cdf0e10cSrcweir                             break;
1244cdf0e10cSrcweir                         }
1245cdf0e10cSrcweir                     }
1246cdf0e10cSrcweir 
1247cdf0e10cSrcweir                     if (sCmd.equals(it->m_sPrevSibling))
1248cdf0e10cSrcweir                         break;
1249cdf0e10cSrcweir                 }
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir                 xTemp->insertByIndex(i+1, uno::makeAny(aPropSeq));
1252cdf0e10cSrcweir             }
1253cdf0e10cSrcweir         }
1254cdf0e10cSrcweir     }
1255cdf0e10cSrcweir 
1256cdf0e10cSrcweir     uno::Reference< container::XIndexAccess > xIndexAccess(xIndexContainer, uno::UNO_QUERY);
1257cdf0e10cSrcweir     if (xIndexAccess.is())
1258cdf0e10cSrcweir         xCfgManager->replaceSettings(sResourceURL, xIndexAccess);
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir     uno::Reference< ui::XUIConfigurationPersistence > xUIConfigurationPersistence(xCfgManager, uno::UNO_QUERY);
1261cdf0e10cSrcweir     if (xUIConfigurationPersistence.is())
1262cdf0e10cSrcweir         xUIConfigurationPersistence->store();
1263cdf0e10cSrcweir }
1264cdf0e10cSrcweir 
getConfigManager(const::rtl::OUString & sModuleShortName) const1265cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > NewVersionUIInfo::getConfigManager(const ::rtl::OUString& sModuleShortName) const
1266cdf0e10cSrcweir {
1267cdf0e10cSrcweir     uno::Reference< ui::XUIConfigurationManager > xCfgManager;
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir     for (sal_Int32 i=0; i<m_lCfgManagerSeq.getLength(); ++i)
1270cdf0e10cSrcweir     {
1271cdf0e10cSrcweir         if (m_lCfgManagerSeq[i].Name.equals(sModuleShortName))
1272cdf0e10cSrcweir         {
1273cdf0e10cSrcweir             m_lCfgManagerSeq[i].Value >>= xCfgManager;
1274cdf0e10cSrcweir             break;
1275cdf0e10cSrcweir         }
1276cdf0e10cSrcweir     }
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir     return xCfgManager;
1279cdf0e10cSrcweir }
1280cdf0e10cSrcweir 
getNewMenubarSettings(const::rtl::OUString & sModuleShortName) const1281cdf0e10cSrcweir uno::Reference< container::XIndexContainer > NewVersionUIInfo::getNewMenubarSettings(const ::rtl::OUString& sModuleShortName) const
1282cdf0e10cSrcweir {
1283cdf0e10cSrcweir     uno::Reference< container::XIndexContainer > xNewMenuSettings;
1284cdf0e10cSrcweir 
1285cdf0e10cSrcweir     for (sal_Int32 i=0; i<m_lNewVersionMenubarSettingsSeq.getLength(); ++i)
1286cdf0e10cSrcweir     {
1287cdf0e10cSrcweir         if (m_lNewVersionMenubarSettingsSeq[i].Name.equals(sModuleShortName))
1288cdf0e10cSrcweir         {
1289cdf0e10cSrcweir             m_lNewVersionMenubarSettingsSeq[i].Value >>= xNewMenuSettings;
1290cdf0e10cSrcweir             break;
1291cdf0e10cSrcweir         }
1292cdf0e10cSrcweir     }
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir     return xNewMenuSettings;
1295cdf0e10cSrcweir }
1296cdf0e10cSrcweir 
getNewToolbarSettings(const::rtl::OUString & sModuleShortName,const::rtl::OUString & sToolbarName) const1297cdf0e10cSrcweir uno::Reference< container::XIndexContainer > NewVersionUIInfo::getNewToolbarSettings(const ::rtl::OUString& sModuleShortName, const ::rtl::OUString& sToolbarName) const
1298cdf0e10cSrcweir {
1299cdf0e10cSrcweir     uno::Reference< container::XIndexContainer > xNewToolbarSettings;
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir     for (sal_Int32 i=0; i<m_lNewVersionToolbarSettingsSeq.getLength(); ++i)
1302cdf0e10cSrcweir     {
1303cdf0e10cSrcweir         if (m_lNewVersionToolbarSettingsSeq[i].Name.equals(sModuleShortName))
1304cdf0e10cSrcweir         {
1305cdf0e10cSrcweir             uno::Sequence< beans::PropertyValue > lToolbarSettingsSeq;
1306cdf0e10cSrcweir             m_lNewVersionToolbarSettingsSeq[i].Value >>= lToolbarSettingsSeq;
1307cdf0e10cSrcweir             for (sal_Int32 j=0; j<lToolbarSettingsSeq.getLength(); ++j)
1308cdf0e10cSrcweir             {
1309cdf0e10cSrcweir                 if (lToolbarSettingsSeq[j].Name.equals(sToolbarName))
1310cdf0e10cSrcweir                 {
1311cdf0e10cSrcweir                     lToolbarSettingsSeq[j].Value >>= xNewToolbarSettings;
1312cdf0e10cSrcweir                     break;
1313cdf0e10cSrcweir                 }
1314cdf0e10cSrcweir             }
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir             break;
1317cdf0e10cSrcweir         }
1318cdf0e10cSrcweir     }
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir     return xNewToolbarSettings;
1321cdf0e10cSrcweir }
1322cdf0e10cSrcweir 
init(const::std::vector<MigrationModuleInfo> & vModulesInfo)1323cdf0e10cSrcweir void NewVersionUIInfo::init(const ::std::vector< MigrationModuleInfo >& vModulesInfo)
1324cdf0e10cSrcweir {
1325cdf0e10cSrcweir     m_lCfgManagerSeq.realloc(vModulesInfo.size());
1326cdf0e10cSrcweir     m_lNewVersionMenubarSettingsSeq.realloc(vModulesInfo.size());
1327cdf0e10cSrcweir     m_lNewVersionToolbarSettingsSeq.realloc(vModulesInfo.size());
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir     const ::rtl::OUString sModuleCfgSupplier = ::rtl::OUString::createFromAscii("com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
1330cdf0e10cSrcweir     const ::rtl::OUString sMenubarResourceURL = ::rtl::OUString::createFromAscii("private:resource/menubar/menubar");
1331cdf0e10cSrcweir     const ::rtl::OUString sToolbarResourcePre = ::rtl::OUString::createFromAscii("private:resource/toolbar/");
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir     uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier = uno::Reference< ui::XModuleUIConfigurationManagerSupplier >(::comphelper::getProcessServiceFactory()->createInstance(sModuleCfgSupplier), uno::UNO_QUERY);
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir     for (sal_uInt32 i=0; i<vModulesInfo.size(); ++i)
1336cdf0e10cSrcweir     {
1337cdf0e10cSrcweir         ::rtl::OUString sModuleIdentifier = mapModuleShortNameToIdentifier(vModulesInfo[i].sModuleShortName);
1338cdf0e10cSrcweir         if (sModuleIdentifier.getLength() > 0)
1339cdf0e10cSrcweir         {
1340cdf0e10cSrcweir             uno::Reference< ui::XUIConfigurationManager > xCfgManager = xModuleCfgSupplier->getUIConfigurationManager(sModuleIdentifier);
1341cdf0e10cSrcweir             m_lCfgManagerSeq[i].Name = vModulesInfo[i].sModuleShortName;
1342cdf0e10cSrcweir             m_lCfgManagerSeq[i].Value <<= xCfgManager;
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir             if (vModulesInfo[i].bHasMenubar)
1345cdf0e10cSrcweir             {
1346cdf0e10cSrcweir                 m_lNewVersionMenubarSettingsSeq[i].Name = vModulesInfo[i].sModuleShortName;
1347cdf0e10cSrcweir                 m_lNewVersionMenubarSettingsSeq[i].Value <<= xCfgManager->getSettings(sMenubarResourceURL, sal_True);
1348cdf0e10cSrcweir             }
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir             sal_Int32 nToolbars = vModulesInfo[i].m_vToolbars.size();
1351cdf0e10cSrcweir             if (nToolbars > 0)
1352cdf0e10cSrcweir             {
1353cdf0e10cSrcweir                 uno::Sequence< beans::PropertyValue > lPropSeq(nToolbars);
1354cdf0e10cSrcweir                 for (sal_Int32 j=0; j<nToolbars; ++j)
1355cdf0e10cSrcweir                 {
1356cdf0e10cSrcweir                     ::rtl::OUString sToolbarName = vModulesInfo[i].m_vToolbars[j];
1357cdf0e10cSrcweir                     ::rtl::OUString sToolbarResourceURL = sToolbarResourcePre + sToolbarName;
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir                     lPropSeq[j].Name = sToolbarName;
1360cdf0e10cSrcweir                     lPropSeq[j].Value <<= xCfgManager->getSettings(sToolbarResourceURL, sal_True);
1361cdf0e10cSrcweir                 }
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir                 m_lNewVersionToolbarSettingsSeq[i].Name = vModulesInfo[i].sModuleShortName;
1364cdf0e10cSrcweir                 m_lNewVersionToolbarSettingsSeq[i].Value <<= lPropSeq;
1365cdf0e10cSrcweir             }
1366cdf0e10cSrcweir         }
1367cdf0e10cSrcweir     }
1368cdf0e10cSrcweir }
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir } // namespace desktop
1371