nss: upgrade to release 3.73
[LibreOffice.git] / desktop / source / migration / migration_impl.hxx
blob0a1e7d8dc61bee1026de3aac75460de93532e1f6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include <memory>
22 #include <unordered_map>
23 #include <vector>
25 #include <sal/types.h>
26 #include <rtl/ustring.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 #include <com/sun/star/container/XIndexContainer.hpp>
32 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
34 namespace desktop
37 struct install_info
39 OUString productname; // human readable product name
40 OUString userdata; // file: url for user installation
43 typedef std::vector< OUString > strings_v;
44 typedef std::unique_ptr< strings_v > strings_vr;
46 struct migration_step
48 strings_v includeFiles;
49 strings_v excludeFiles;
50 strings_v includeConfig;
51 strings_v excludeConfig;
52 strings_v excludeExtensions;
53 OUString service;
56 struct supported_migration
58 OUString name;
59 sal_Int32 nPriority;
60 strings_v supported_versions;
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;
67 inline bool areBothOpenFrom(OUString const & cmd1, OUString const & cmd2)
69 return cmd1 == ".uno:Open" && cmd2.startsWith(".uno:OpenFrom");
72 /**
73 define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information
74 of the command URL, the previous sibling node and the parent node of an item
76 struct MigrationItem
78 OUString m_sParentNodeName;
79 OUString m_sPrevSibling;
80 OUString m_sCommandURL;
81 css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu;
83 MigrationItem()
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)
96 bool operator==(const MigrationItem& aMigrationItem) const
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();
108 typedef std::unordered_map< OUString, std::vector< MigrationItem > > MigrationHashMap;
111 information for the UI elements to be migrated for one module
113 struct MigrationModuleInfo
115 OUString sModuleShortName;
116 bool bHasMenubar;
117 std::vector< OUString > m_vToolbars;
119 MigrationModuleInfo() : bHasMenubar(false) {};
124 get the information before copying the ui configuration files of old version to new version
126 class NewVersionUIInfo
128 public:
130 css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(const OUString& sModuleShortName) const;
131 css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(const OUString& sModuleShortName) const;
132 css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(const OUString& sModuleShortName, const OUString& sToolbarName) const;
133 void init(const std::vector< MigrationModuleInfo >& vModulesInfo);
135 private:
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;
142 class MigrationImpl
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;
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();
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);
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);
179 // actual processing function that perform the migration steps
180 void copyFiles();
181 void copyConfig();
182 void runServices();
184 static void setMigrationCompleted();
185 static bool checkMigrationCompleted();
187 public:
188 MigrationImpl();
189 ~MigrationImpl();
190 bool initializeMigration();
191 bool doMigration();
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */