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