Linux x86 build fix
[LibreOffice.git] / desktop / source / migration / migration_impl.hxx
blob6b0fc45728a1032d6212f338ee397f81c8f64993
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 #ifndef INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
20 #define INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
22 #include <algorithm>
23 #include <memory>
24 #include <unordered_map>
25 #include <vector>
27 #include "migration.hxx"
29 #include <sal/types.h>
30 #include <rtl/string.hxx>
31 #include <rtl/ustring.hxx>
33 #include <com/sun/star/uno/Reference.hxx>
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>
44 namespace desktop
47 struct install_info
49 OUString productname; // human readeable product name
50 OUString userdata; // file: url for user installation
53 typedef std::vector< OUString > strings_v;
54 typedef std::unique_ptr< strings_v > strings_vr;
56 struct migration_step
58 OUString name;
59 strings_v includeFiles;
60 strings_v excludeFiles;
61 strings_v includeConfig;
62 strings_v excludeConfig;
63 strings_v includeExtensions;
64 strings_v excludeExtensions;
65 OUString service;
68 struct supported_migration
70 OUString name;
71 sal_Int32 nPriority;
72 strings_v supported_versions;
75 typedef std::vector< migration_step > migrations_v;
76 typedef std::unique_ptr< migrations_v > migrations_vr;
77 typedef std::vector< supported_migration > migrations_available;
79 namespace {
81 inline bool areBothOpenFrom(OUString const & cmd1, OUString const & cmd2)
83 return cmd1 == ".uno:Open" && cmd2.startsWith(".uno:OpenFrom");
88 /**
89 define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information
90 of the command URL, the previous sibling node and the parent node of a item
92 struct MigrationItem
94 OUString m_sParentNodeName;
95 OUString m_sPrevSibling;
96 OUString m_sCommandURL;
97 css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu;
99 MigrationItem()
100 :m_xPopupMenu(0)
104 MigrationItem(const OUString& sParentNodeName,
105 const OUString& sPrevSibling,
106 const OUString& sCommandURL,
107 const css::uno::Reference< css::container::XIndexContainer > xPopupMenu)
109 m_sParentNodeName = sParentNodeName;
110 m_sPrevSibling = sPrevSibling;
111 m_sCommandURL = sCommandURL;
112 m_xPopupMenu = xPopupMenu;
115 MigrationItem& operator=(const MigrationItem& aMigrationItem)
117 m_sParentNodeName = aMigrationItem.m_sParentNodeName;
118 m_sPrevSibling = aMigrationItem.m_sPrevSibling;
119 m_sCommandURL = aMigrationItem.m_sCommandURL;
120 m_xPopupMenu = aMigrationItem.m_xPopupMenu;
122 return *this;
125 bool operator==(const MigrationItem& aMigrationItem)
127 return
128 (aMigrationItem.m_sCommandURL == m_sCommandURL
129 || areBothOpenFrom(aMigrationItem.m_sCommandURL, m_sCommandURL)
130 || areBothOpenFrom(m_sCommandURL, aMigrationItem.m_sCommandURL))
131 && aMigrationItem.m_sParentNodeName == m_sParentNodeName
132 && aMigrationItem.m_sPrevSibling == m_sPrevSibling
133 && aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is();
137 typedef std::unordered_map< OUString, std::vector< MigrationItem >,
138 OUStringHash, std::equal_to< OUString > > MigrationHashMap;
140 struct MigrationItemInfo
142 OUString m_sResourceURL;
143 MigrationItem m_aMigrationItem;
145 MigrationItemInfo(){}
147 MigrationItemInfo(const OUString& sResourceURL, const MigrationItem& aMigrationItem)
148 : m_sResourceURL(sResourceURL), m_aMigrationItem(aMigrationItem)
155 information for the UI elements to be migrated for one module
157 struct MigrationModuleInfo
159 OUString sModuleShortName;
160 bool bHasMenubar;
161 ::std::vector< OUString > m_vToolbars;
163 MigrationModuleInfo() : bHasMenubar(false) {};
168 get the information before copying the ui configuration files of old version to new version
170 class NewVersionUIInfo
172 public:
174 css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(const OUString& sModuleShortName) const;
175 css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(const OUString& sModuleShortName) const;
176 css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(const OUString& sModuleShortName, const OUString& sToolbarName) const;
177 void init(const ::std::vector< MigrationModuleInfo >& vModulesInfo);
179 private:
181 css::uno::Sequence< css::beans::PropertyValue > m_lCfgManagerSeq;
182 css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq;
183 css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq;
186 class MigrationImpl
189 private:
190 strings_vr m_vrVersions;
192 migrations_available m_vMigrationsAvailable; // list of all available migrations
193 migrations_vr m_vrMigrations; // list of all migration specs from config
194 install_info m_aInfo; // info about the version being migrated
195 strings_vr m_vrFileList; // final list of files to be copied
196 MigrationHashMap m_aOldVersionItemsHashMap;
197 OUString m_sModuleIdentifier;
199 // functions to control the migration process
200 static bool readAvailableMigrations(migrations_available&);
201 bool alreadyMigrated();
202 static migrations_vr readMigrationSteps(const OUString& rMigrationName);
203 sal_Int32 findPreferredMigrationProcess(const migrations_available&);
204 #if defined UNX && ! defined MACOSX
205 static OUString preXDGConfigDir(const OUString& rConfigDir);
206 #endif
207 static void setInstallInfoIfExist(install_info& aInfo, const OUString& rConfigDir, const OUString& rVersion);
208 static install_info findInstallation(const strings_v& rVersions);
209 strings_vr compileFileList();
211 // helpers
212 strings_vr getAllFiles(const OUString& baseURL) const;
213 static strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns);
214 static css::uno::Reference< css::container::XNameAccess > getConfigAccess(const sal_Char* path, bool rw=false);
216 ::std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const;
217 void compareOldAndNewConfig(const OUString& sParentNodeName,
218 const css::uno::Reference< css::container::XIndexContainer >& xOldIndexContainer,
219 const css::uno::Reference< css::container::XIndexContainer >& xNewIndexContainer,
220 const OUString& sToolbarName);
221 void mergeOldToNewVersion(const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgManager,
222 const css::uno::Reference< css::container::XIndexContainer>& xIndexContainer,
223 const OUString& sModuleIdentifier,
224 const OUString& sResourceURL);
226 // actual processing function that perform the migration steps
227 void copyFiles();
228 void copyConfig();
229 void runServices();
230 static void refresh();
232 static void setMigrationCompleted();
233 static bool checkMigrationCompleted();
235 public:
236 MigrationImpl();
237 ~MigrationImpl();
238 bool initializeMigration();
239 bool doMigration();
240 OUString getOldVersionName();
244 #endif
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */