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 <vector>
25 
26 #include <o3tl/string_view.hxx>
27 #include <sal/types.h>
28 #include <rtl/ustring.hxx>
29 
30 #include <com/sun/star/uno/Reference.hxx>
31 
32 #include <com/sun/star/container/XNameAccess.hpp>
33 #include <com/sun/star/container/XIndexContainer.hpp>
34 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
35 
36 namespace desktop
37 {
38 
40 {
41  OUString productname; // human readable product name
42  OUString userdata; // file: url for user installation
43 };
44 
45 typedef std::vector< OUString > strings_v;
46 typedef std::unique_ptr< strings_v > strings_vr;
47 
49 {
50  strings_v includeFiles;
51  strings_v excludeFiles;
52  strings_v includeConfig;
53  strings_v excludeConfig;
54  strings_v excludeExtensions;
55  OUString service;
56 };
57 
59 {
60  OUString name;
61  sal_Int32 nPriority;
62  strings_v supported_versions;
63 };
64 
65 typedef std::vector< migration_step > migrations_v;
66 typedef std::unique_ptr< migrations_v > migrations_vr;
67 typedef std::vector< supported_migration > migrations_available;
68 
69 inline bool areBothOpenFrom(std::u16string_view cmd1, std::u16string_view cmd2)
70 {
71  return cmd1 == u".uno:Open" && o3tl::starts_with(cmd2, u".uno:OpenFrom");
72 }
73 
79 {
81  OUString m_sPrevSibling;
82  OUString m_sCommandURL;
83  css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu;
84 
86  {
87  }
88 
89  MigrationItem(const OUString& sParentNodeName,
90  const OUString& sPrevSibling,
91  const OUString& sCommandURL,
92  const css::uno::Reference< css::container::XIndexContainer > & xPopupMenu)
93  : m_sParentNodeName(sParentNodeName), m_sPrevSibling(sPrevSibling),
94  m_sCommandURL(sCommandURL), m_xPopupMenu(xPopupMenu)
95  {
96  }
97 
98  bool operator==(const MigrationItem& aMigrationItem) const
99  {
100  return
101  (aMigrationItem.m_sCommandURL == m_sCommandURL
102  || areBothOpenFrom(aMigrationItem.m_sCommandURL, m_sCommandURL)
103  || areBothOpenFrom(m_sCommandURL, aMigrationItem.m_sCommandURL))
104  && aMigrationItem.m_sParentNodeName == m_sParentNodeName
105  && aMigrationItem.m_sPrevSibling == m_sPrevSibling
106  && aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is();
107  }
108 };
109 
110 typedef std::unordered_map< OUString, std::vector< MigrationItem > > MigrationHashMap;
111 
116 {
119  std::vector< OUString > m_vToolbars;
120 
121  MigrationModuleInfo() : bHasMenubar(false) {};
122 };
123 
124 
129 {
130 public:
131 
132  css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(std::u16string_view sModuleShortName) const;
133  css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(std::u16string_view sModuleShortName) const;
134  css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(std::u16string_view sModuleShortName, std::u16string_view sToolbarName) const;
135  void init(const std::vector< MigrationModuleInfo >& vModulesInfo);
136 
137 private:
138 
139  std::vector< css::beans::PropertyValue > m_lCfgManagerSeq;
140  css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq;
141  css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq;
142 };
143 
145 {
146 
147 private:
148  migrations_available m_vMigrationsAvailable; // list of all available migrations
149  migrations_vr m_vrMigrations; // list of all migration specs from config
150  install_info m_aInfo; // info about the version being migrated
151  strings_vr m_vrFileList; // final list of files to be copied
152  MigrationHashMap m_aOldVersionItemsHashMap;
153 
154  // functions to control the migration process
155  static void readAvailableMigrations(migrations_available&);
156  bool alreadyMigrated();
157  static migrations_vr readMigrationSteps(const OUString& rMigrationName);
158  sal_Int32 findPreferredMigrationProcess(const migrations_available&);
159 #if defined UNX && ! defined MACOSX
160  static OUString preXDGConfigDir(const OUString& rConfigDir);
161 #endif
162  static void setInstallInfoIfExist(install_info& aInfo, const OUString& rConfigDir, const OUString& rVersion);
163  static install_info findInstallation(const strings_v& rVersions);
164  strings_vr compileFileList();
165 
166  // helpers
167  strings_vr getAllFiles(const OUString& baseURL) const;
168  static strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns);
169  static css::uno::Reference< css::container::XNameAccess > getConfigAccess(const char* path, bool rw=false);
170 
171  std::vector< MigrationModuleInfo > detectUIChangesForAllModules() const;
172  void compareOldAndNewConfig(const OUString& sParentNodeName,
173  const css::uno::Reference< css::container::XIndexContainer >& xOldIndexContainer,
174  const css::uno::Reference< css::container::XIndexContainer >& xNewIndexContainer,
175  const OUString& sToolbarName);
176  void mergeOldToNewVersion(const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgManager,
177  const css::uno::Reference< css::container::XIndexContainer>& xIndexContainer,
178  const OUString& sModuleIdentifier,
179  const OUString& sResourceURL);
180 
181  // actual processing function that perform the migration steps
182  void copyFiles();
183  void copyConfig();
184  void runServices();
185 
186  static void setMigrationCompleted();
187  static bool checkMigrationCompleted();
188 
189 public:
190  MigrationImpl();
191  ~MigrationImpl();
192  bool initializeMigration();
193  bool doMigration();
194 };
195 }
196 
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< strings_v > strings_vr
MigrationItem(const OUString &sParentNodeName, const OUString &sPrevSibling, const OUString &sCommandURL, const css::uno::Reference< css::container::XIndexContainer > &xPopupMenu)
static void setMigrationCompleted()
Definition: migration.cxx:261
std::unordered_map< OUString, std::vector< MigrationItem > > MigrationHashMap
void init(const std::vector< MigrationModuleInfo > &vModulesInfo)
Definition: migration.cxx:1069
static install_info findInstallation(const strings_v &rVersions)
Definition: migration.cxx:448
define the item, e.g.
migrations_vr m_vrMigrations
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:932
std::vector< OUString > m_vToolbars
bool areBothOpenFrom(std::u16string_view cmd1, std::u16string_view cmd2)
Definition: app.cxx:164
css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(std::u16string_view sModuleShortName, std::u16string_view sToolbarName) const
Definition: migration.cxx:1047
information for the UI elements to be migrated for one module
strings_vr compileFileList()
Definition: migration.cxx:581
std::vector< supported_migration > migrations_available
static void setInstallInfoIfExist(install_info &aInfo, const OUString &rConfigDir, const OUString &rVersion)
Definition: migration.cxx:431
css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(std::u16string_view sModuleShortName) const
Definition: migration.cxx:1033
static void readAvailableMigrations(migrations_available &)
Definition: migration.cxx:303
MigrationHashMap m_aOldVersionItemsHashMap
float u
static strings_vr applyPatterns(const strings_v &vSet, const strings_v &vPatterns)
Definition: migration.cxx:508
static migrations_vr readMigrationSteps(const OUString &rMigrationName)
Definition: migration.cxx:329
strings_vr getAllFiles(const OUString &baseURL) const
Definition: migration.cxx:530
sal_Int32 findPreferredMigrationProcess(const migrations_available &)
Definition: migration.cxx:486
static OUString preXDGConfigDir(const OUString &rConfigDir)
Definition: migration.cxx:401
css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq
get the information before copying the ui configuration files of old version to new version ...
migrations_available m_vMigrationsAvailable
std::vector< MigrationModuleInfo > detectUIChangesForAllModules() const
Definition: migration.cxx:803
bool operator==(const MigrationItem &aMigrationItem) const
css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(std::u16string_view sModuleShortName) const
Definition: migration.cxx:1019
static bool checkMigrationCompleted()
Definition: migration.cxx:272
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:862
std::vector< migration_step > migrations_v
std::vector< css::beans::PropertyValue > m_lCfgManagerSeq
static css::uno::Reference< css::container::XNameAccess > getConfigAccess(const char *path, bool rw=false)
Definition: migration.cxx:694
std::vector< OUString > strings_v
css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq
std::unique_ptr< migrations_v > migrations_vr