Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
20 : #define INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
21 :
22 : #include <vector>
23 : #include <algorithm>
24 : #include <memory>
25 : #include <boost/unordered_map.hpp>
26 :
27 : #include "migration.hxx"
28 :
29 : #include <sal/types.h>
30 : #include <rtl/string.hxx>
31 : #include <rtl/ustring.hxx>
32 :
33 : #include <com/sun/star/uno/Reference.hxx>
34 :
35 : #include <com/sun/star/container/XNameAccess.hpp>
36 : #include <com/sun/star/container/XIndexAccess.hpp>
37 : #include <com/sun/star/container/XIndexContainer.hpp>
38 : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
39 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40 : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
41 : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
42 : #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
43 :
44 : namespace desktop
45 : {
46 :
47 256 : struct install_info
48 : {
49 : OUString productname; // human readeable product name
50 : OUString userdata; // file: url for user installation
51 : };
52 :
53 : typedef std::vector< OUString > strings_v;
54 : typedef std::unique_ptr< strings_v > strings_vr;
55 :
56 0 : struct migration_step
57 : {
58 : OUString name;
59 : strings_v includeFiles;
60 : strings_v excludeFiles;
61 : strings_v includeConfig;
62 : strings_v excludeConfig;
63 : strings_v includeExtensions;
64 : strings_v excludeExtensions;
65 : OUString service;
66 : };
67 :
68 256 : struct supported_migration
69 : {
70 : OUString name;
71 : sal_Int32 nPriority;
72 : strings_v supported_versions;
73 : };
74 :
75 : typedef std::vector< migration_step > migrations_v;
76 : typedef std::unique_ptr< migrations_v > migrations_vr;
77 : typedef std::vector< supported_migration > migrations_available;
78 :
79 :
80 : /**
81 : define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information
82 : of the command URL, the previous sibling node and the parent node of a item
83 : */
84 0 : struct MigrationItem
85 : {
86 : OUString m_sParentNodeName;
87 : OUString m_sPrevSibling;
88 : OUString m_sCommandURL;
89 : css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu;
90 :
91 0 : MigrationItem()
92 0 : :m_xPopupMenu(0)
93 : {
94 0 : }
95 :
96 0 : MigrationItem(const OUString& sParentNodeName,
97 : const OUString& sPrevSibling,
98 : const OUString& sCommandURL,
99 : const css::uno::Reference< css::container::XIndexContainer > xPopupMenu)
100 0 : {
101 0 : m_sParentNodeName = sParentNodeName;
102 0 : m_sPrevSibling = sPrevSibling;
103 0 : m_sCommandURL = sCommandURL;
104 0 : m_xPopupMenu = xPopupMenu;
105 0 : }
106 :
107 : MigrationItem& operator=(const MigrationItem& aMigrationItem)
108 : {
109 : m_sParentNodeName = aMigrationItem.m_sParentNodeName;
110 : m_sPrevSibling = aMigrationItem.m_sPrevSibling;
111 : m_sCommandURL = aMigrationItem.m_sCommandURL;
112 : m_xPopupMenu = aMigrationItem.m_xPopupMenu;
113 :
114 : return *this;
115 : }
116 :
117 0 : bool operator==(const MigrationItem& aMigrationItem)
118 : {
119 0 : return ( aMigrationItem.m_sParentNodeName == m_sParentNodeName &&
120 0 : aMigrationItem.m_sPrevSibling == m_sPrevSibling &&
121 0 : aMigrationItem.m_sCommandURL == m_sCommandURL &&
122 0 : aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is() );
123 : }
124 :
125 : OUString GetPrevSibling() const { return m_sPrevSibling; }
126 : };
127 :
128 : typedef ::boost::unordered_map< OUString,
129 : ::std::vector< MigrationItem >,
130 : OUStringHash,
131 : ::std::equal_to< OUString > > MigrationHashMap;
132 :
133 : struct MigrationItemInfo
134 : {
135 : OUString m_sResourceURL;
136 : MigrationItem m_aMigrationItem;
137 :
138 : MigrationItemInfo(){}
139 :
140 : MigrationItemInfo(const OUString& sResourceURL, const MigrationItem& aMigrationItem)
141 : : m_sResourceURL(sResourceURL), m_aMigrationItem(aMigrationItem)
142 : {
143 : }
144 : };
145 :
146 :
147 : /**
148 : information for the UI elements to be migrated for one module
149 : */
150 0 : struct MigrationModuleInfo
151 : {
152 : OUString sModuleShortName;
153 : bool bHasMenubar;
154 : ::std::vector< OUString > m_vToolbars;
155 :
156 0 : MigrationModuleInfo() : bHasMenubar(false) {};
157 : };
158 :
159 :
160 : /**
161 : get the information before copying the ui configuration files of old version to new version
162 : */
163 0 : class NewVersionUIInfo
164 : {
165 : public:
166 :
167 : css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(const OUString& sModuleShortName) const;
168 : css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(const OUString& sModuleShortName) const;
169 : css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(const OUString& sModuleShortName, const OUString& sToolbarName) const;
170 : void init(const ::std::vector< MigrationModuleInfo >& vModulesInfo);
171 :
172 : private:
173 :
174 : css::uno::Sequence< css::beans::PropertyValue > m_lCfgManagerSeq;
175 : css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq;
176 : css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq;
177 : };
178 :
179 : class MigrationImpl
180 : {
181 :
182 : private:
183 : strings_vr m_vrVersions;
184 :
185 : migrations_available m_vMigrationsAvailable; // list of all available migrations
186 : migrations_vr m_vrMigrations; // list of all migration specs from config
187 : install_info m_aInfo; // info about the version being migrated
188 : strings_vr m_vrFileList; // final list of files to be copied
189 : MigrationHashMap m_aOldVersionItemsHashMap;
190 : MigrationHashMap m_aNewVersionItemsHashMap;
191 : OUString m_sModuleIdentifier;
192 :
193 : // functions to control the migration process
194 : bool readAvailableMigrations(migrations_available&);
195 : bool alreadyMigrated();
196 : migrations_vr readMigrationSteps(const OUString& rMigrationName);
197 : sal_Int32 findPreferredMigrationProcess(const migrations_available&);
198 : #if defined UNX && ! defined MACOSX
199 : OUString preXDGConfigDir(const OUString& rConfigDir);
200 : #endif
201 : void setInstallInfoIfExist(install_info& aInfo, const OUString& rConfigDir, const OUString& rVersion);
202 : install_info findInstallation(const strings_v& rVersions);
203 : strings_vr compileFileList();
204 :
205 : // helpers
206 : strings_vr getAllFiles(const OUString& baseURL) const;
207 : strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const;
208 : css::uno::Reference< css::container::XNameAccess > getConfigAccess(const sal_Char* path, bool rw=false);
209 :
210 : ::std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const;
211 : void compareOldAndNewConfig(const OUString& sParentNodeName,
212 : const css::uno::Reference< css::container::XIndexContainer >& xOldIndexContainer,
213 : const css::uno::Reference< css::container::XIndexContainer >& xNewIndexContainer,
214 : const OUString& sToolbarName);
215 : void mergeOldToNewVersion(const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgManager,
216 : const css::uno::Reference< css::container::XIndexContainer>& xIndexContainer,
217 : const OUString& sModuleIdentifier,
218 : const OUString& sResourceURL);
219 :
220 : // actual processing function that perform the migration steps
221 : void copyFiles();
222 : void copyConfig();
223 : void runServices();
224 : void refresh();
225 :
226 : void setMigrationCompleted();
227 : bool checkMigrationCompleted();
228 :
229 : public:
230 : MigrationImpl();
231 : ~MigrationImpl();
232 : bool initializeMigration();
233 : bool doMigration();
234 : OUString getOldVersionName();
235 : };
236 : }
237 :
238 : #endif
239 :
240 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|