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  : m_sParentNodeName(sParentNodeName), m_sPrevSibling(sPrevSibling),
102  m_sCommandURL(sCommandURL), m_xPopupMenu(xPopupMenu)
103  {
104  }
105 
106  bool operator==(const MigrationItem& aMigrationItem)
107  {
108  return
109  (aMigrationItem.m_sCommandURL == m_sCommandURL
110  || areBothOpenFrom(aMigrationItem.m_sCommandURL, m_sCommandURL)
111  || areBothOpenFrom(m_sCommandURL, aMigrationItem.m_sCommandURL))
112  && aMigrationItem.m_sParentNodeName == m_sParentNodeName
113  && aMigrationItem.m_sPrevSibling == m_sPrevSibling
114  && aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is();
115  }
116 };
117 
118 typedef std::unordered_map< OUString, std::vector< MigrationItem > > MigrationHashMap;
119 
124 {
127  std::vector< OUString > m_vToolbars;
128 
129  MigrationModuleInfo() : bHasMenubar(false) {};
130 };
131 
132 
137 {
138 public:
139 
140  css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(const OUString& sModuleShortName) const;
141  css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(const OUString& sModuleShortName) const;
142  css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(const OUString& sModuleShortName, const OUString& sToolbarName) const;
143  void init(const std::vector< MigrationModuleInfo >& vModulesInfo);
144 
145 private:
146 
147  std::vector< css::beans::PropertyValue > m_lCfgManagerSeq;
148  css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq;
149  css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq;
150 };
151 
153 {
154 
155 private:
156  migrations_available m_vMigrationsAvailable; // list of all available migrations
157  migrations_vr m_vrMigrations; // list of all migration specs from config
158  install_info m_aInfo; // info about the version being migrated
159  strings_vr m_vrFileList; // final list of files to be copied
160  MigrationHashMap m_aOldVersionItemsHashMap;
161 
162  // functions to control the migration process
163  static void readAvailableMigrations(migrations_available&);
164  bool alreadyMigrated();
165  static migrations_vr readMigrationSteps(const OUString& rMigrationName);
166  sal_Int32 findPreferredMigrationProcess(const migrations_available&);
167 #if defined UNX && ! defined MACOSX
168  static OUString preXDGConfigDir(const OUString& rConfigDir);
169 #endif
170  static void setInstallInfoIfExist(install_info& aInfo, const OUString& rConfigDir, const OUString& rVersion);
171  static install_info findInstallation(const strings_v& rVersions);
172  strings_vr compileFileList();
173 
174  // helpers
175  strings_vr getAllFiles(const OUString& baseURL) const;
176  static strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns);
177  static css::uno::Reference< css::container::XNameAccess > getConfigAccess(const char* path, bool rw=false);
178 
179  std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const;
180  void compareOldAndNewConfig(const OUString& sParentNodeName,
181  const css::uno::Reference< css::container::XIndexContainer >& xOldIndexContainer,
182  const css::uno::Reference< css::container::XIndexContainer >& xNewIndexContainer,
183  const OUString& sToolbarName);
184  void mergeOldToNewVersion(const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgManager,
185  const css::uno::Reference< css::container::XIndexContainer>& xIndexContainer,
186  const OUString& sModuleIdentifier,
187  const OUString& sResourceURL);
188 
189  // actual processing function that perform the migration steps
190  void copyFiles();
191  void copyConfig();
192  void runServices();
193 
194  static void setMigrationCompleted();
195  static bool checkMigrationCompleted();
196 
197 public:
198  MigrationImpl();
199  ~MigrationImpl();
200  bool initializeMigration();
201  bool doMigration();
202 };
203 }
204 
205 #endif
206 
207 /* 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:1118
static install_info findInstallation(const strings_v &rVersions)
Definition: migration.cxx:493
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:982
std::vector< OUString > m_vToolbars
css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(const OUString &sModuleShortName) const
Definition: migration.cxx:1082
std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const
Definition: migration.cxx:848
Definition: app.cxx:168
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:626
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:476
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:1096
MigrationHashMap m_aOldVersionItemsHashMap
static strings_vr applyPatterns(const strings_v &vSet, const strings_v &vPatterns)
Definition: migration.cxx:553
static migrations_vr readMigrationSteps(const OUString &rMigrationName)
Definition: migration.cxx:374
strings_vr getAllFiles(const OUString &baseURL) const
Definition: migration.cxx:575
sal_Int32 findPreferredMigrationProcess(const migrations_available &)
Definition: migration.cxx:531
static OUString preXDGConfigDir(const OUString &rConfigDir)
Definition: migration.cxx:446
css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(const OUString &sModuleShortName) const
Definition: migration.cxx:1068
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:912
std::vector< migration_step > migrations_v
std::vector< css::beans::PropertyValue > m_lCfgManagerSeq
bool operator==(const MigrationItem &aMigrationItem)
static css::uno::Reference< css::container::XNameAccess > getConfigAccess(const char *path, bool rw=false)
Definition: migration.cxx:739
std::vector< OUString > strings_v
css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq
std::unique_ptr< migrations_v > migrations_vr