LibreOffice Module desktop (master) 1
migration_impl.hxx
Go to the documentation of this file.
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#pragma once
20
21#include <memory>
22#include <string_view>
23#include <unordered_map>
24#include <utility>
25#include <vector>
26
27#include <o3tl/string_view.hxx>
28#include <sal/types.h>
29#include <rtl/ustring.hxx>
30
31#include <com/sun/star/uno/Reference.hxx>
32
33#include <com/sun/star/container/XNameAccess.hpp>
34#include <com/sun/star/container/XIndexContainer.hpp>
35#include <com/sun/star/ui/XUIConfigurationManager.hpp>
36
37namespace desktop
38{
39
41{
42 OUString productname; // human readable product name
43 OUString userdata; // file: url for user installation
44};
45
46typedef std::vector< OUString > strings_v;
47typedef std::unique_ptr< strings_v > strings_vr;
48
50{
56 OUString service;
57};
58
60{
61 OUString name;
62 sal_Int32 nPriority;
64};
65
66typedef std::vector< migration_step > migrations_v;
67typedef std::unique_ptr< migrations_v > migrations_vr;
68typedef std::vector< supported_migration > migrations_available;
69
70inline bool areBothOpenFrom(std::u16string_view cmd1, std::u16string_view cmd2)
71{
72 return cmd1 == u".uno:Open" && o3tl::starts_with(cmd2, u".uno:OpenFrom");
73}
74
80{
83 OUString m_sCommandURL;
84 css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu;
85
87 {
88 }
89
90 MigrationItem(OUString sParentNodeName,
91 OUString sPrevSibling,
92 OUString sCommandURL,
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))
96 {
97 }
98
99 bool operator==(const MigrationItem& aMigrationItem) const
100 {
101 return
102 (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();
108 }
109};
110
111typedef std::unordered_map< OUString, std::vector< MigrationItem > > MigrationHashMap;
112
117{
120 std::vector< OUString > m_vToolbars;
121
123};
124
125
130{
131public:
132
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);
137
138private:
139
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;
143};
144
146{
147
148private:
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
154
155 // functions to control the migration process
157 bool alreadyMigrated();
158 static migrations_vr readMigrationSteps(const OUString& rMigrationName);
160#if defined UNX && ! defined MACOSX
161 static OUString preXDGConfigDir(const OUString& rConfigDir);
162#endif
163 static void setInstallInfoIfExist(install_info& aInfo, std::u16string_view rConfigDir, const OUString& rVersion);
164 static install_info findInstallation(const strings_v& rVersions);
166
167 // helpers
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);
171
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);
181
182 // actual processing function that perform the migration steps
183 void copyFiles();
184 void copyConfig();
185 void runServices();
186
187 static void setMigrationCompleted();
188 static bool checkMigrationCompleted();
189
190public:
193 bool initializeMigration();
194 bool doMigration();
195};
196}
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static css::uno::Reference< css::container::XNameAccess > getConfigAccess(const char *path, bool rw=false)
Definition: migration.cxx:795
strings_vr getAllFiles(const OUString &baseURL) const
Definition: migration.cxx:531
static void setInstallInfoIfExist(install_info &aInfo, std::u16string_view rConfigDir, const OUString &rVersion)
Definition: migration.cxx:432
migrations_available m_vMigrationsAvailable
static bool checkMigrationCompleted()
Definition: migration.cxx:273
void mergeOldToNewVersion(const css::uno::Reference< css::ui::XUIConfigurationManager > &xCfgManager, const css::uno::Reference< css::container::XIndexContainer > &xIndexContainer, const OUString &sModuleIdentifier, const OUString &sResourceURL)
Definition: migration.cxx:1034
static migrations_vr readMigrationSteps(const OUString &rMigrationName)
Definition: migration.cxx:330
migrations_vr m_vrMigrations
MigrationHashMap m_aOldVersionItemsHashMap
static install_info findInstallation(const strings_v &rVersions)
Definition: migration.cxx:449
void compareOldAndNewConfig(const OUString &sParentNodeName, const css::uno::Reference< css::container::XIndexContainer > &xOldIndexContainer, const css::uno::Reference< css::container::XIndexContainer > &xNewIndexContainer, const OUString &sToolbarName)
Definition: migration.cxx:964
static void readAvailableMigrations(migrations_available &)
Definition: migration.cxx:304
sal_Int32 findPreferredMigrationProcess(const migrations_available &)
Definition: migration.cxx:487
static OUString preXDGConfigDir(const OUString &rConfigDir)
Definition: migration.cxx:402
std::vector< MigrationModuleInfo > detectUIChangesForAllModules() const
Definition: migration.cxx:905
static strings_vr applyPatterns(const strings_v &vSet, const strings_v &vPatterns)
Definition: migration.cxx:509
strings_vr compileFileList()
Definition: migration.cxx:580
static void setMigrationCompleted()
Definition: migration.cxx:262
get the information before copying the ui configuration files of old version to new version
css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(std::u16string_view sModuleShortName, std::u16string_view sToolbarName) const
Definition: migration.cxx:1149
void init(const std::vector< MigrationModuleInfo > &vModulesInfo)
Definition: migration.cxx:1171
css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(std::u16string_view sModuleShortName) const
Definition: migration.cxx:1135
std::vector< css::beans::PropertyValue > m_lCfgManagerSeq
css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(std::u16string_view sModuleShortName) const
Definition: migration.cxx:1121
css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq
css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq
float u
Definition: app.cxx:167
std::unordered_map< OUString, std::vector< MigrationItem > > MigrationHashMap
std::vector< migration_step > migrations_v
std::vector< supported_migration > migrations_available
std::unique_ptr< migrations_v > migrations_vr
std::unique_ptr< strings_v > strings_vr
std::vector< OUString > strings_v
bool areBothOpenFrom(std::u16string_view cmd1, std::u16string_view cmd2)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
define the item, e.g.
bool operator==(const MigrationItem &aMigrationItem) const
css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu
MigrationItem(OUString sParentNodeName, OUString sPrevSibling, OUString sCommandURL, css::uno::Reference< css::container::XIndexContainer > xPopupMenu)
information for the UI elements to be migrated for one module
std::vector< OUString > m_vToolbars