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 .
22 #include <string_view>
23 #include <unordered_map>
27 #include <o3tl/string_view.hxx>
28 #include <sal/types.h>
29 #include <rtl/ustring.hxx>
31 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #include <com/sun/star/container/XIndexContainer.hpp>
35 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
42 OUString productname
; // human readable product name
43 OUString userdata
; // file: url for user installation
46 typedef std::vector
< OUString
> strings_v
;
47 typedef std::unique_ptr
< strings_v
> strings_vr
;
51 strings_v includeFiles
;
52 strings_v excludeFiles
;
53 strings_v includeConfig
;
54 strings_v excludeConfig
;
55 strings_v excludeExtensions
;
59 struct supported_migration
63 strings_v supported_versions
;
66 typedef std::vector
< migration_step
> migrations_v
;
67 typedef std::unique_ptr
< migrations_v
> migrations_vr
;
68 typedef std::vector
< supported_migration
> migrations_available
;
70 inline bool areBothOpenFrom(std::u16string_view cmd1
, std::u16string_view cmd2
)
72 return cmd1
== u
".uno:Open" && o3tl::starts_with(cmd2
, u
".uno:OpenFrom");
76 define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information
77 of the command URL, the previous sibling node and the parent node of an item
81 OUString m_sParentNodeName
;
82 OUString m_sPrevSibling
;
83 OUString m_sCommandURL
;
84 css::uno::Reference
< css::container::XIndexContainer
> m_xPopupMenu
;
90 MigrationItem(OUString sParentNodeName
,
91 OUString sPrevSibling
,
93 css::uno::Reference
< css::container::XIndexContainer
> xPopupMenu
)
94 : m_sParentNodeName(std::move(sParentNodeName
)), m_sPrevSibling(std::move(sPrevSibling
)),
95 m_sCommandURL(std::move(sCommandURL
)), m_xPopupMenu(std::move(xPopupMenu
))
99 bool operator==(const MigrationItem
& aMigrationItem
) const
102 (aMigrationItem
.m_sCommandURL
== m_sCommandURL
103 || areBothOpenFrom(aMigrationItem
.m_sCommandURL
, m_sCommandURL
)
104 || areBothOpenFrom(m_sCommandURL
, aMigrationItem
.m_sCommandURL
))
105 && aMigrationItem
.m_sParentNodeName
== m_sParentNodeName
106 && aMigrationItem
.m_sPrevSibling
== m_sPrevSibling
107 && aMigrationItem
.m_xPopupMenu
.is() == m_xPopupMenu
.is();
111 typedef std::unordered_map
< OUString
, std::vector
< MigrationItem
> > MigrationHashMap
;
114 information for the UI elements to be migrated for one module
116 struct MigrationModuleInfo
118 OUString sModuleShortName
;
120 std::vector
< OUString
> m_vToolbars
;
122 MigrationModuleInfo() : bHasMenubar(false) {};
127 get the information before copying the ui configuration files of old version to new version
129 class NewVersionUIInfo
133 css::uno::Reference
< css::ui::XUIConfigurationManager
> getConfigManager(std::u16string_view sModuleShortName
) const;
134 css::uno::Reference
< css::container::XIndexContainer
> getNewMenubarSettings(std::u16string_view sModuleShortName
) const;
135 css::uno::Reference
< css::container::XIndexContainer
> getNewToolbarSettings(std::u16string_view sModuleShortName
, std::u16string_view sToolbarName
) const;
136 void init(const std::vector
< MigrationModuleInfo
>& vModulesInfo
);
140 std::vector
< css::beans::PropertyValue
> m_lCfgManagerSeq
;
141 css::uno::Sequence
< css::beans::PropertyValue
> m_lNewVersionMenubarSettingsSeq
;
142 css::uno::Sequence
< css::beans::PropertyValue
> m_lNewVersionToolbarSettingsSeq
;
149 migrations_available m_vMigrationsAvailable
; // list of all available migrations
150 migrations_vr m_vrMigrations
; // list of all migration specs from config
151 install_info m_aInfo
; // info about the version being migrated
152 strings_vr m_vrFileList
; // final list of files to be copied
153 MigrationHashMap m_aOldVersionItemsHashMap
;
155 // functions to control the migration process
156 static void readAvailableMigrations(migrations_available
&);
157 bool alreadyMigrated();
158 static migrations_vr
readMigrationSteps(const OUString
& rMigrationName
);
159 sal_Int32
findPreferredMigrationProcess(const migrations_available
&);
160 #if defined UNX && ! defined MACOSX
161 static OUString
preXDGConfigDir(const OUString
& rConfigDir
);
163 static void setInstallInfoIfExist(install_info
& aInfo
, std::u16string_view rConfigDir
, const OUString
& rVersion
);
164 static install_info
findInstallation(const strings_v
& rVersions
);
165 strings_vr
compileFileList();
168 strings_vr
getAllFiles(const OUString
& baseURL
) const;
169 static strings_vr
applyPatterns(const strings_v
& vSet
, const strings_v
& vPatterns
);
170 static css::uno::Reference
< css::container::XNameAccess
> getConfigAccess(const char* path
, bool rw
=false);
172 std::vector
< MigrationModuleInfo
> detectUIChangesForAllModules() const;
173 void compareOldAndNewConfig(const OUString
& sParentNodeName
,
174 const css::uno::Reference
< css::container::XIndexContainer
>& xOldIndexContainer
,
175 const css::uno::Reference
< css::container::XIndexContainer
>& xNewIndexContainer
,
176 const OUString
& sToolbarName
);
177 void mergeOldToNewVersion(const css::uno::Reference
< css::ui::XUIConfigurationManager
>& xCfgManager
,
178 const css::uno::Reference
< css::container::XIndexContainer
>& xIndexContainer
,
179 const OUString
& sModuleIdentifier
,
180 const OUString
& sResourceURL
);
182 // actual processing function that perform the migration steps
187 static void setMigrationCompleted();
188 static bool checkMigrationCompleted();
193 bool initializeMigration();
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */