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 #ifndef INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
20 #define INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
21 
22 #include <algorithm>
23 #include <memory>
24 #include <unordered_map>
25 #include <vector>
26 
27 #include <migration.hxx>
28 
29 #include <sal/types.h>
30 #include <rtl/string.hxx>
31 #include <rtl/ustring.hxx>
32 
33 #include <com/sun/star/uno/Reference.hxx>
34 
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>
43 
44 namespace desktop
45 {
46 
48 {
49  OUString productname; // human readable product name
50  OUString userdata; // file: url for user installation
51 };
52 
53 typedef std::vector< OUString > strings_v;
54 typedef std::unique_ptr< strings_v > strings_vr;
55 
57 {
58  strings_v includeFiles;
59  strings_v excludeFiles;
60  strings_v includeConfig;
61  strings_v excludeConfig;
62  strings_v excludeExtensions;
63  OUString service;
64 };
65 
67 {
68  OUString name;
69  sal_Int32 nPriority;
70  strings_v supported_versions;
71 };
72 
73 typedef std::vector< migration_step > migrations_v;
74 typedef std::unique_ptr< migrations_v > migrations_vr;
75 typedef std::vector< supported_migration > migrations_available;
76 
77 inline bool areBothOpenFrom(OUString const & cmd1, OUString const & cmd2)
78 {
79  return cmd1 == ".uno:Open" && cmd2.startsWith(".uno:OpenFrom");
80 }
81 
87 {
89  OUString m_sPrevSibling;
90  OUString m_sCommandURL;
91  css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu;
92 
94  {
95  }
96 
97  MigrationItem(const OUString& sParentNodeName,
98  const OUString& sPrevSibling,
99  const OUString& sCommandURL,
100  const css::uno::Reference< css::container::XIndexContainer > & xPopupMenu)
101  {
102  m_sParentNodeName = sParentNodeName;
103  m_sPrevSibling = sPrevSibling;
104  m_sCommandURL = sCommandURL;
105  m_xPopupMenu = xPopupMenu;
106  }
107 
108  bool operator==(const MigrationItem& aMigrationItem)
109  {
110  return
111  (aMigrationItem.m_sCommandURL == m_sCommandURL
112  || areBothOpenFrom(aMigrationItem.m_sCommandURL, m_sCommandURL)
113  || areBothOpenFrom(m_sCommandURL, aMigrationItem.m_sCommandURL))
114  && aMigrationItem.m_sParentNodeName == m_sParentNodeName
115  && aMigrationItem.m_sPrevSibling == m_sPrevSibling
116  && aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is();
117  }
118 };
119 
120 typedef std::unordered_map< OUString, std::vector< MigrationItem > > MigrationHashMap;
121 
126 {
129  std::vector< OUString > m_vToolbars;
130 
131  MigrationModuleInfo() : bHasMenubar(false) {};
132 };
133 
134 
139 {
140 public:
141 
142  css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(const OUString& sModuleShortName) const;
143  css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(const OUString& sModuleShortName) const;
144  css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(const OUString& sModuleShortName, const OUString& sToolbarName) const;
145  void init(const std::vector< MigrationModuleInfo >& vModulesInfo);
146 
147 private:
148 
149  std::vector< css::beans::PropertyValue > m_lCfgManagerSeq;
150  css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq;
151  css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq;
152 };
153 
155 {
156 
157 private:
158  migrations_available m_vMigrationsAvailable; // list of all available migrations
159  migrations_vr m_vrMigrations; // list of all migration specs from config
160  install_info m_aInfo; // info about the version being migrated
161  strings_vr m_vrFileList; // final list of files to be copied
162  MigrationHashMap m_aOldVersionItemsHashMap;
163 
164  // functions to control the migration process
165  static void readAvailableMigrations(migrations_available&);
166  bool alreadyMigrated();
167  static migrations_vr readMigrationSteps(const OUString& rMigrationName);
168  sal_Int32 findPreferredMigrationProcess(const migrations_available&);
169 #if defined UNX && ! defined MACOSX
170  static OUString preXDGConfigDir(const OUString& rConfigDir);
171 #endif
172  static void setInstallInfoIfExist(install_info& aInfo, const OUString& rConfigDir, const OUString& rVersion);
173  static install_info findInstallation(const strings_v& rVersions);
174  strings_vr compileFileList();
175 
176  // helpers
177  strings_vr getAllFiles(const OUString& baseURL) const;
178  static strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns);
179  static css::uno::Reference< css::container::XNameAccess > getConfigAccess(const sal_Char* path, bool rw=false);
180 
181  std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const;
182  void compareOldAndNewConfig(const OUString& sParentNodeName,
183  const css::uno::Reference< css::container::XIndexContainer >& xOldIndexContainer,
184  const css::uno::Reference< css::container::XIndexContainer >& xNewIndexContainer,
185  const OUString& sToolbarName);
186  void mergeOldToNewVersion(const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgManager,
187  const css::uno::Reference< css::container::XIndexContainer>& xIndexContainer,
188  const OUString& sModuleIdentifier,
189  const OUString& sResourceURL);
190 
191  // actual processing function that perform the migration steps
192  void copyFiles();
193  void copyConfig();
194  void runServices();
195 
196  static void setMigrationCompleted();
197  static bool checkMigrationCompleted();
198 
199 public:
200  MigrationImpl();
201  ~MigrationImpl();
202  bool initializeMigration();
203  bool doMigration();
204 };
205 }
206 
207 #endif
208 
209 /* 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:306
std::unordered_map< OUString, std::vector< MigrationItem > > MigrationHashMap
void init(const std::vector< MigrationModuleInfo > &vModulesInfo)
Definition: migration.cxx:1124
static install_info findInstallation(const strings_v &rVersions)
Definition: migration.cxx:492
define the item, e.g.
migrations_vr m_vrMigrations
static css::uno::Reference< css::container::XNameAccess > getConfigAccess(const sal_Char *path, bool rw=false)
Definition: migration.cxx:739
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:987
std::vector< OUString > m_vToolbars
css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(const OUString &sModuleShortName) const
Definition: migration.cxx:1088
std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const
Definition: migration.cxx:850
Definition: app.cxx:167
css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu
information for the UI elements to be migrated for one module
strings_vr compileFileList()
Definition: migration.cxx:625
char sal_Char
bool areBothOpenFrom(OUString const &cmd1, OUString const &cmd2)
std::vector< supported_migration > migrations_available
static void setInstallInfoIfExist(install_info &aInfo, const OUString &rConfigDir, const OUString &rVersion)
Definition: migration.cxx:475
static void readAvailableMigrations(migrations_available &)
Definition: migration.cxx:348
css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(const OUString &sModuleShortName, const OUString &sToolbarName) const
Definition: migration.cxx:1102
MigrationHashMap m_aOldVersionItemsHashMap
static strings_vr applyPatterns(const strings_v &vSet, const strings_v &vPatterns)
Definition: migration.cxx:552
static migrations_vr readMigrationSteps(const OUString &rMigrationName)
Definition: migration.cxx:374
strings_vr getAllFiles(const OUString &baseURL) const
Definition: migration.cxx:574
sal_Int32 findPreferredMigrationProcess(const migrations_available &)
Definition: migration.cxx:530
static OUString preXDGConfigDir(const OUString &rConfigDir)
Definition: migration.cxx:445
css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(const OUString &sModuleShortName) const
Definition: migration.cxx:1074
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
static bool checkMigrationCompleted()
Definition: migration.cxx:317
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:917
std::vector< migration_step > migrations_v
std::vector< css::beans::PropertyValue > m_lCfgManagerSeq
bool operator==(const MigrationItem &aMigrationItem)
std::vector< OUString > strings_v
css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq
std::unique_ptr< migrations_v > migrations_vr