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