1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
20 #define INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
24 #include <unordered_map>
27 #include <migration.hxx>
29 #include <sal/types.h>
30 #include <rtl/string.hxx>
31 #include <rtl/ustring.hxx>
33 #include <com/sun/star/uno/Reference.hxx>
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>
49 OUString productname
; // human readable product name
50 OUString userdata
; // file: url for user installation
53 typedef std::vector
< OUString
> strings_v
;
54 typedef std::unique_ptr
< strings_v
> strings_vr
;
59 strings_v includeFiles
;
60 strings_v excludeFiles
;
61 strings_v includeConfig
;
62 strings_v excludeConfig
;
63 strings_v includeExtensions
;
64 strings_v excludeExtensions
;
68 struct supported_migration
72 strings_v supported_versions
;
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
;
79 inline bool areBothOpenFrom(OUString
const & cmd1
, OUString
const & cmd2
)
81 return cmd1
== ".uno:Open" && cmd2
.startsWith(".uno:OpenFrom");
85 define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information
86 of the command URL, the previous sibling node and the parent node of a item
90 OUString m_sParentNodeName
;
91 OUString m_sPrevSibling
;
92 OUString m_sCommandURL
;
93 css::uno::Reference
< css::container::XIndexContainer
> m_xPopupMenu
;
99 MigrationItem(const OUString
& sParentNodeName
,
100 const OUString
& sPrevSibling
,
101 const OUString
& sCommandURL
,
102 const css::uno::Reference
< css::container::XIndexContainer
> & xPopupMenu
)
104 m_sParentNodeName
= sParentNodeName
;
105 m_sPrevSibling
= sPrevSibling
;
106 m_sCommandURL
= sCommandURL
;
107 m_xPopupMenu
= xPopupMenu
;
110 bool operator==(const MigrationItem
& aMigrationItem
)
113 (aMigrationItem
.m_sCommandURL
== m_sCommandURL
114 || areBothOpenFrom(aMigrationItem
.m_sCommandURL
, m_sCommandURL
)
115 || areBothOpenFrom(m_sCommandURL
, aMigrationItem
.m_sCommandURL
))
116 && aMigrationItem
.m_sParentNodeName
== m_sParentNodeName
117 && aMigrationItem
.m_sPrevSibling
== m_sPrevSibling
118 && aMigrationItem
.m_xPopupMenu
.is() == m_xPopupMenu
.is();
122 typedef std::unordered_map
< OUString
, std::vector
< MigrationItem
> > MigrationHashMap
;
125 information for the UI elements to be migrated for one module
127 struct MigrationModuleInfo
129 OUString sModuleShortName
;
131 std::vector
< OUString
> m_vToolbars
;
133 MigrationModuleInfo() : bHasMenubar(false) {};
138 get the information before copying the ui configuration files of old version to new version
140 class NewVersionUIInfo
144 css::uno::Reference
< css::ui::XUIConfigurationManager
> getConfigManager(const OUString
& sModuleShortName
) const;
145 css::uno::Reference
< css::container::XIndexContainer
> getNewMenubarSettings(const OUString
& sModuleShortName
) const;
146 css::uno::Reference
< css::container::XIndexContainer
> getNewToolbarSettings(const OUString
& sModuleShortName
, const OUString
& sToolbarName
) const;
147 void init(const std::vector
< MigrationModuleInfo
>& vModulesInfo
);
151 std::vector
< css::beans::PropertyValue
> m_lCfgManagerSeq
;
152 css::uno::Sequence
< css::beans::PropertyValue
> m_lNewVersionMenubarSettingsSeq
;
153 css::uno::Sequence
< css::beans::PropertyValue
> m_lNewVersionToolbarSettingsSeq
;
160 migrations_available m_vMigrationsAvailable
; // list of all available migrations
161 migrations_vr m_vrMigrations
; // list of all migration specs from config
162 install_info m_aInfo
; // info about the version being migrated
163 strings_vr m_vrFileList
; // final list of files to be copied
164 MigrationHashMap m_aOldVersionItemsHashMap
;
166 // functions to control the migration process
167 static void readAvailableMigrations(migrations_available
&);
168 bool alreadyMigrated();
169 static migrations_vr
readMigrationSteps(const OUString
& rMigrationName
);
170 sal_Int32
findPreferredMigrationProcess(const migrations_available
&);
171 #if defined UNX && ! defined MACOSX
172 static OUString
preXDGConfigDir(const OUString
& rConfigDir
);
174 static void setInstallInfoIfExist(install_info
& aInfo
, const OUString
& rConfigDir
, const OUString
& rVersion
);
175 static install_info
findInstallation(const strings_v
& rVersions
);
176 strings_vr
compileFileList();
179 strings_vr
getAllFiles(const OUString
& baseURL
) const;
180 static strings_vr
applyPatterns(const strings_v
& vSet
, const strings_v
& vPatterns
);
181 static css::uno::Reference
< css::container::XNameAccess
> getConfigAccess(const sal_Char
* path
, bool rw
=false);
183 std::vector
< MigrationModuleInfo
> dectectUIChangesForAllModules() const;
184 void compareOldAndNewConfig(const OUString
& sParentNodeName
,
185 const css::uno::Reference
< css::container::XIndexContainer
>& xOldIndexContainer
,
186 const css::uno::Reference
< css::container::XIndexContainer
>& xNewIndexContainer
,
187 const OUString
& sToolbarName
);
188 void mergeOldToNewVersion(const css::uno::Reference
< css::ui::XUIConfigurationManager
>& xCfgManager
,
189 const css::uno::Reference
< css::container::XIndexContainer
>& xIndexContainer
,
190 const OUString
& sModuleIdentifier
,
191 const OUString
& sResourceURL
);
193 // actual processing function that perform the migration steps
198 static void setMigrationCompleted();
199 static bool checkMigrationCompleted();
204 bool initializeMigration();
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */