1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #ifndef _DESKTOP_MIGRATION_IMPL_HXX_
28*cdf0e10cSrcweir #define _DESKTOP_MIGRATION_IMPL_HXX_
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <vector>
31*cdf0e10cSrcweir #include <algorithm>
32*cdf0e10cSrcweir #include <memory>
33*cdf0e10cSrcweir #include <hash_map>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "migration.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <sal/types.h>
38*cdf0e10cSrcweir #include <rtl/string.hxx>
39*cdf0e10cSrcweir #include <rtl/ustring.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleComponentFactory.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManager.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #define NS_CSS com::sun::star
54*cdf0e10cSrcweir #define NS_UNO com::sun::star::uno
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir namespace desktop
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir struct install_info
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     rtl::OUString productname;  // human readeable product name
62*cdf0e10cSrcweir     rtl::OUString userdata;     // file: url for user installation
63*cdf0e10cSrcweir };
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir typedef std::vector< rtl::OUString > strings_v;
66*cdf0e10cSrcweir typedef std::auto_ptr< strings_v > strings_vr;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir struct migration_step
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir     rtl::OUString name;
71*cdf0e10cSrcweir     strings_v includeFiles;
72*cdf0e10cSrcweir     strings_v excludeFiles;
73*cdf0e10cSrcweir     strings_v includeConfig;
74*cdf0e10cSrcweir     strings_v excludeConfig;
75*cdf0e10cSrcweir     strings_v includeExtensions;
76*cdf0e10cSrcweir     strings_v excludeExtensions;
77*cdf0e10cSrcweir     rtl::OUString service;
78*cdf0e10cSrcweir };
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir struct supported_migration
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir     rtl::OUString name;
83*cdf0e10cSrcweir     sal_Int32     nPriority;
84*cdf0e10cSrcweir     strings_v     supported_versions;
85*cdf0e10cSrcweir };
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir typedef std::vector< migration_step > migrations_v;
88*cdf0e10cSrcweir typedef std::auto_ptr< migrations_v > migrations_vr;
89*cdf0e10cSrcweir typedef std::vector< supported_migration > migrations_available;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir //__________________________________________
92*cdf0e10cSrcweir /**
93*cdf0e10cSrcweir 	define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information
94*cdf0e10cSrcweir 	of the command URL, the previous sibling node and the parent node of a item
95*cdf0e10cSrcweir */
96*cdf0e10cSrcweir struct MigrationItem
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir 	::rtl::OUString m_sParentNodeName;
99*cdf0e10cSrcweir 	::rtl::OUString m_sPrevSibling;
100*cdf0e10cSrcweir 	::rtl::OUString m_sCommandURL;
101*cdf0e10cSrcweir 	NS_UNO::Reference< NS_CSS::container::XIndexContainer > m_xPopupMenu;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	MigrationItem()
104*cdf0e10cSrcweir 		:m_xPopupMenu(0)
105*cdf0e10cSrcweir 	{
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	MigrationItem(const ::rtl::OUString& sParentNodeName,
109*cdf0e10cSrcweir 		const ::rtl::OUString& sPrevSibling,
110*cdf0e10cSrcweir 		const ::rtl::OUString& sCommandURL,
111*cdf0e10cSrcweir 		const NS_UNO::Reference< NS_CSS::container::XIndexContainer > xPopupMenu)
112*cdf0e10cSrcweir 	{
113*cdf0e10cSrcweir 		m_sParentNodeName = sParentNodeName;
114*cdf0e10cSrcweir 		m_sPrevSibling	  = sPrevSibling;
115*cdf0e10cSrcweir 		m_sCommandURL	  = sCommandURL;
116*cdf0e10cSrcweir 		m_xPopupMenu	  = xPopupMenu;
117*cdf0e10cSrcweir 	}
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	MigrationItem& operator=(const MigrationItem& aMigrationItem)
120*cdf0e10cSrcweir 	{
121*cdf0e10cSrcweir 		m_sParentNodeName = aMigrationItem.m_sParentNodeName;
122*cdf0e10cSrcweir 		m_sPrevSibling	  = aMigrationItem.m_sPrevSibling;
123*cdf0e10cSrcweir 		m_sCommandURL     = aMigrationItem.m_sCommandURL;
124*cdf0e10cSrcweir 		m_xPopupMenu      = aMigrationItem.m_xPopupMenu;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 		return *this;
127*cdf0e10cSrcweir 	}
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	sal_Bool operator==(const MigrationItem& aMigrationItem)
130*cdf0e10cSrcweir 	{
131*cdf0e10cSrcweir 		return ( aMigrationItem.m_sParentNodeName == m_sParentNodeName &&
132*cdf0e10cSrcweir 			aMigrationItem.m_sPrevSibling    == m_sPrevSibling	   &&
133*cdf0e10cSrcweir 			aMigrationItem.m_sCommandURL     == m_sCommandURL	   &&
134*cdf0e10cSrcweir 			aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is()    );
135*cdf0e10cSrcweir 	}
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	::rtl::OUString GetPrevSibling() const { return m_sPrevSibling; }
138*cdf0e10cSrcweir };
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir typedef ::std::hash_map< ::rtl::OUString,
141*cdf0e10cSrcweir 						 ::std::vector< MigrationItem >,
142*cdf0e10cSrcweir 						 ::rtl::OUStringHash,
143*cdf0e10cSrcweir 						 ::std::equal_to< ::rtl::OUString > > MigrationHashMap;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir struct MigrationItemInfo
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir 	::rtl::OUString m_sResourceURL;
148*cdf0e10cSrcweir 	MigrationItem m_aMigrationItem;
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	MigrationItemInfo(){}
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	MigrationItemInfo(const ::rtl::OUString& sResourceURL, const MigrationItem& aMigratiionItem)
153*cdf0e10cSrcweir 	{
154*cdf0e10cSrcweir 		m_sResourceURL = sResourceURL;
155*cdf0e10cSrcweir 		m_aMigrationItem = aMigratiionItem;
156*cdf0e10cSrcweir 	}
157*cdf0e10cSrcweir };
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir //__________________________________________
160*cdf0e10cSrcweir /**
161*cdf0e10cSrcweir 	information for the UI elements to be migrated for one module
162*cdf0e10cSrcweir */
163*cdf0e10cSrcweir struct MigrationModuleInfo
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir 	::rtl::OUString sModuleShortName;
166*cdf0e10cSrcweir 	sal_Bool		bHasMenubar;
167*cdf0e10cSrcweir 	::std::vector< ::rtl::OUString > m_vToolbars;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	MigrationModuleInfo():bHasMenubar(sal_False){};
170*cdf0e10cSrcweir };
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir //__________________________________________
173*cdf0e10cSrcweir /**
174*cdf0e10cSrcweir 	get the information before copying the ui configuration files of old version to new version
175*cdf0e10cSrcweir */
176*cdf0e10cSrcweir class NewVersionUIInfo
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir public:
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	NS_UNO::Reference< NS_CSS::ui::XUIConfigurationManager > getConfigManager(const ::rtl::OUString& sModuleShortName) const;
181*cdf0e10cSrcweir 	NS_UNO::Reference< NS_CSS::container::XIndexContainer > getNewMenubarSettings(const ::rtl::OUString& sModuleShortName) const;
182*cdf0e10cSrcweir 	NS_UNO::Reference< NS_CSS::container::XIndexContainer > getNewToolbarSettings(const ::rtl::OUString& sModuleShortName, const ::rtl::OUString& sToolbarName) const;
183*cdf0e10cSrcweir 	void init(const ::std::vector< MigrationModuleInfo >& vModulesInfo);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir private:
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 	NS_UNO::Sequence< NS_CSS::beans::PropertyValue > m_lCfgManagerSeq;
188*cdf0e10cSrcweir 	NS_UNO::Sequence< NS_CSS::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq;
189*cdf0e10cSrcweir 	NS_UNO::Sequence< NS_CSS::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq;
190*cdf0e10cSrcweir };
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir class MigrationImpl
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir private:
196*cdf0e10cSrcweir     strings_vr m_vrVersions;
197*cdf0e10cSrcweir     NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory > m_xFactory;
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     migrations_available m_vMigrationsAvailable; // list of all available migrations
200*cdf0e10cSrcweir     migrations_vr        m_vrMigrations;         // list of all migration specs from config
201*cdf0e10cSrcweir     install_info         m_aInfo;                // info about the version being migrated
202*cdf0e10cSrcweir     strings_vr           m_vrFileList;           // final list of files to be copied
203*cdf0e10cSrcweir  	MigrationHashMap     m_aOldVersionItemsHashMap;
204*cdf0e10cSrcweir  	MigrationHashMap     m_aNewVersionItemsHashMap;
205*cdf0e10cSrcweir  	::rtl::OUString      m_sModuleIdentifier;
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     // functions to control the migration process
208*cdf0e10cSrcweir     bool          readAvailableMigrations(migrations_available&);
209*cdf0e10cSrcweir     migrations_vr readMigrationSteps(const ::rtl::OUString& rMigrationName);
210*cdf0e10cSrcweir     sal_Int32     findPreferedMigrationProcess(const migrations_available&);
211*cdf0e10cSrcweir     install_info  findInstallation(const strings_v& rVersions);
212*cdf0e10cSrcweir     strings_vr    compileFileList();
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir     // helpers
215*cdf0e10cSrcweir     void substract(strings_v& va, const strings_v& vb_c) const;
216*cdf0e10cSrcweir     strings_vr getAllFiles(const rtl::OUString& baseURL) const;
217*cdf0e10cSrcweir     strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const;
218*cdf0e10cSrcweir     NS_UNO::Reference< NS_CSS::container::XNameAccess > getConfigAccess(const sal_Char* path, sal_Bool rw=sal_False);
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	::std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const;
221*cdf0e10cSrcweir 	void compareOldAndNewConfig(const ::rtl::OUString& sParentNodeName,
222*cdf0e10cSrcweir 		const NS_UNO::Reference< NS_CSS::container::XIndexContainer >& xOldIndexContainer,
223*cdf0e10cSrcweir 		const NS_UNO::Reference< NS_CSS::container::XIndexContainer >& xNewIndexContainer,
224*cdf0e10cSrcweir 		const ::rtl::OUString& sToolbarName);
225*cdf0e10cSrcweir 	void mergeOldToNewVersion(const NS_UNO::Reference< NS_CSS::ui::XUIConfigurationManager >& xCfgManager,
226*cdf0e10cSrcweir 		const NS_UNO::Reference< NS_CSS::container::XIndexContainer>& xIndexContainer,
227*cdf0e10cSrcweir 		const ::rtl::OUString& sModuleIdentifier,
228*cdf0e10cSrcweir 		const ::rtl::OUString& sResourceURL);
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     // actual processing function that perform the migration steps
231*cdf0e10cSrcweir     void copyFiles();
232*cdf0e10cSrcweir     void copyConfig();
233*cdf0e10cSrcweir     void runServices();
234*cdf0e10cSrcweir     void refresh();
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir     void setMigrationCompleted();
237*cdf0e10cSrcweir     sal_Bool checkMigrationCompleted();
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir public:
240*cdf0e10cSrcweir     MigrationImpl(const NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory >&);
241*cdf0e10cSrcweir     ~MigrationImpl();
242*cdf0e10cSrcweir     sal_Bool doMigration();
243*cdf0e10cSrcweir     sal_Bool checkMigration();
244*cdf0e10cSrcweir     rtl::OUString getOldVersionName();
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir };
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir #undef NS_CSS
250*cdf0e10cSrcweir #undef NS_UNO
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir #endif
253