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