1*0a1e2f0eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*0a1e2f0eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*0a1e2f0eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*0a1e2f0eSAndrew Rist * distributed with this work for additional information 6*0a1e2f0eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*0a1e2f0eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*0a1e2f0eSAndrew Rist * "License"); you may not use this file except in compliance 9*0a1e2f0eSAndrew Rist * with the License. You may obtain a copy of the License at 10*0a1e2f0eSAndrew Rist * 11*0a1e2f0eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*0a1e2f0eSAndrew Rist * 13*0a1e2f0eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*0a1e2f0eSAndrew Rist * software distributed under the License is distributed on an 15*0a1e2f0eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*0a1e2f0eSAndrew Rist * KIND, either express or implied. See the License for the 17*0a1e2f0eSAndrew Rist * specific language governing permissions and limitations 18*0a1e2f0eSAndrew Rist * under the License. 19*0a1e2f0eSAndrew Rist * 20*0a1e2f0eSAndrew Rist *************************************************************/ 21*0a1e2f0eSAndrew Rist 22*0a1e2f0eSAndrew Rist 23cdf0e10cSrcweir #ifndef _DESKTOP_MIGRATION_IMPL_HXX_ 24cdf0e10cSrcweir #define _DESKTOP_MIGRATION_IMPL_HXX_ 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <vector> 27cdf0e10cSrcweir #include <algorithm> 28cdf0e10cSrcweir #include <memory> 29cdf0e10cSrcweir #include <hash_map> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "migration.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <sal/types.h> 34cdf0e10cSrcweir #include <rtl/string.hxx> 35cdf0e10cSrcweir #include <rtl/ustring.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 40cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 41cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 42cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp> 43cdf0e10cSrcweir #include <com/sun/star/lang/XSingleComponentFactory.hpp> 44cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 45cdf0e10cSrcweir #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> 46cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManager.hpp> 47cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationPersistence.hpp> 48cdf0e10cSrcweir 49cdf0e10cSrcweir #define NS_CSS com::sun::star 50cdf0e10cSrcweir #define NS_UNO com::sun::star::uno 51cdf0e10cSrcweir 52cdf0e10cSrcweir namespace desktop 53cdf0e10cSrcweir { 54cdf0e10cSrcweir 55cdf0e10cSrcweir struct install_info 56cdf0e10cSrcweir { 57cdf0e10cSrcweir rtl::OUString productname; // human readeable product name 58cdf0e10cSrcweir rtl::OUString userdata; // file: url for user installation 59cdf0e10cSrcweir }; 60cdf0e10cSrcweir 61cdf0e10cSrcweir typedef std::vector< rtl::OUString > strings_v; 62cdf0e10cSrcweir typedef std::auto_ptr< strings_v > strings_vr; 63cdf0e10cSrcweir 64cdf0e10cSrcweir struct migration_step 65cdf0e10cSrcweir { 66cdf0e10cSrcweir rtl::OUString name; 67cdf0e10cSrcweir strings_v includeFiles; 68cdf0e10cSrcweir strings_v excludeFiles; 69cdf0e10cSrcweir strings_v includeConfig; 70cdf0e10cSrcweir strings_v excludeConfig; 71cdf0e10cSrcweir strings_v includeExtensions; 72cdf0e10cSrcweir strings_v excludeExtensions; 73cdf0e10cSrcweir rtl::OUString service; 74cdf0e10cSrcweir }; 75cdf0e10cSrcweir 76cdf0e10cSrcweir struct supported_migration 77cdf0e10cSrcweir { 78cdf0e10cSrcweir rtl::OUString name; 79cdf0e10cSrcweir sal_Int32 nPriority; 80cdf0e10cSrcweir strings_v supported_versions; 81cdf0e10cSrcweir }; 82cdf0e10cSrcweir 83cdf0e10cSrcweir typedef std::vector< migration_step > migrations_v; 84cdf0e10cSrcweir typedef std::auto_ptr< migrations_v > migrations_vr; 85cdf0e10cSrcweir typedef std::vector< supported_migration > migrations_available; 86cdf0e10cSrcweir 87cdf0e10cSrcweir //__________________________________________ 88cdf0e10cSrcweir /** 89cdf0e10cSrcweir define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information 90cdf0e10cSrcweir of the command URL, the previous sibling node and the parent node of a item 91cdf0e10cSrcweir */ 92cdf0e10cSrcweir struct MigrationItem 93cdf0e10cSrcweir { 94cdf0e10cSrcweir ::rtl::OUString m_sParentNodeName; 95cdf0e10cSrcweir ::rtl::OUString m_sPrevSibling; 96cdf0e10cSrcweir ::rtl::OUString m_sCommandURL; 97cdf0e10cSrcweir NS_UNO::Reference< NS_CSS::container::XIndexContainer > m_xPopupMenu; 98cdf0e10cSrcweir MigrationItemdesktop::MigrationItem99cdf0e10cSrcweir MigrationItem() 100cdf0e10cSrcweir :m_xPopupMenu(0) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir } 103cdf0e10cSrcweir MigrationItemdesktop::MigrationItem104cdf0e10cSrcweir MigrationItem(const ::rtl::OUString& sParentNodeName, 105cdf0e10cSrcweir const ::rtl::OUString& sPrevSibling, 106cdf0e10cSrcweir const ::rtl::OUString& sCommandURL, 107cdf0e10cSrcweir const NS_UNO::Reference< NS_CSS::container::XIndexContainer > xPopupMenu) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir m_sParentNodeName = sParentNodeName; 110cdf0e10cSrcweir m_sPrevSibling = sPrevSibling; 111cdf0e10cSrcweir m_sCommandURL = sCommandURL; 112cdf0e10cSrcweir m_xPopupMenu = xPopupMenu; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir operator =desktop::MigrationItem115cdf0e10cSrcweir MigrationItem& operator=(const MigrationItem& aMigrationItem) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir m_sParentNodeName = aMigrationItem.m_sParentNodeName; 118cdf0e10cSrcweir m_sPrevSibling = aMigrationItem.m_sPrevSibling; 119cdf0e10cSrcweir m_sCommandURL = aMigrationItem.m_sCommandURL; 120cdf0e10cSrcweir m_xPopupMenu = aMigrationItem.m_xPopupMenu; 121cdf0e10cSrcweir 122cdf0e10cSrcweir return *this; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir operator ==desktop::MigrationItem125cdf0e10cSrcweir sal_Bool operator==(const MigrationItem& aMigrationItem) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir return ( aMigrationItem.m_sParentNodeName == m_sParentNodeName && 128cdf0e10cSrcweir aMigrationItem.m_sPrevSibling == m_sPrevSibling && 129cdf0e10cSrcweir aMigrationItem.m_sCommandURL == m_sCommandURL && 130cdf0e10cSrcweir aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is() ); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir GetPrevSiblingdesktop::MigrationItem133cdf0e10cSrcweir ::rtl::OUString GetPrevSibling() const { return m_sPrevSibling; } 134cdf0e10cSrcweir }; 135cdf0e10cSrcweir 136cdf0e10cSrcweir typedef ::std::hash_map< ::rtl::OUString, 137cdf0e10cSrcweir ::std::vector< MigrationItem >, 138cdf0e10cSrcweir ::rtl::OUStringHash, 139cdf0e10cSrcweir ::std::equal_to< ::rtl::OUString > > MigrationHashMap; 140cdf0e10cSrcweir 141cdf0e10cSrcweir struct MigrationItemInfo 142cdf0e10cSrcweir { 143cdf0e10cSrcweir ::rtl::OUString m_sResourceURL; 144cdf0e10cSrcweir MigrationItem m_aMigrationItem; 145cdf0e10cSrcweir MigrationItemInfodesktop::MigrationItemInfo146cdf0e10cSrcweir MigrationItemInfo(){} 147cdf0e10cSrcweir MigrationItemInfodesktop::MigrationItemInfo148cdf0e10cSrcweir MigrationItemInfo(const ::rtl::OUString& sResourceURL, const MigrationItem& aMigratiionItem) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir m_sResourceURL = sResourceURL; 151cdf0e10cSrcweir m_aMigrationItem = aMigratiionItem; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir }; 154cdf0e10cSrcweir 155cdf0e10cSrcweir //__________________________________________ 156cdf0e10cSrcweir /** 157cdf0e10cSrcweir information for the UI elements to be migrated for one module 158cdf0e10cSrcweir */ 159cdf0e10cSrcweir struct MigrationModuleInfo 160cdf0e10cSrcweir { 161cdf0e10cSrcweir ::rtl::OUString sModuleShortName; 162cdf0e10cSrcweir sal_Bool bHasMenubar; 163cdf0e10cSrcweir ::std::vector< ::rtl::OUString > m_vToolbars; 164cdf0e10cSrcweir MigrationModuleInfodesktop::MigrationModuleInfo165cdf0e10cSrcweir MigrationModuleInfo():bHasMenubar(sal_False){}; 166cdf0e10cSrcweir }; 167cdf0e10cSrcweir 168cdf0e10cSrcweir //__________________________________________ 169cdf0e10cSrcweir /** 170cdf0e10cSrcweir get the information before copying the ui configuration files of old version to new version 171cdf0e10cSrcweir */ 172cdf0e10cSrcweir class NewVersionUIInfo 173cdf0e10cSrcweir { 174cdf0e10cSrcweir public: 175cdf0e10cSrcweir 176cdf0e10cSrcweir NS_UNO::Reference< NS_CSS::ui::XUIConfigurationManager > getConfigManager(const ::rtl::OUString& sModuleShortName) const; 177cdf0e10cSrcweir NS_UNO::Reference< NS_CSS::container::XIndexContainer > getNewMenubarSettings(const ::rtl::OUString& sModuleShortName) const; 178cdf0e10cSrcweir NS_UNO::Reference< NS_CSS::container::XIndexContainer > getNewToolbarSettings(const ::rtl::OUString& sModuleShortName, const ::rtl::OUString& sToolbarName) const; 179cdf0e10cSrcweir void init(const ::std::vector< MigrationModuleInfo >& vModulesInfo); 180cdf0e10cSrcweir 181cdf0e10cSrcweir private: 182cdf0e10cSrcweir 183cdf0e10cSrcweir NS_UNO::Sequence< NS_CSS::beans::PropertyValue > m_lCfgManagerSeq; 184cdf0e10cSrcweir NS_UNO::Sequence< NS_CSS::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq; 185cdf0e10cSrcweir NS_UNO::Sequence< NS_CSS::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq; 186cdf0e10cSrcweir }; 187cdf0e10cSrcweir 188cdf0e10cSrcweir class MigrationImpl 189cdf0e10cSrcweir { 190cdf0e10cSrcweir 191cdf0e10cSrcweir private: 192cdf0e10cSrcweir strings_vr m_vrVersions; 193cdf0e10cSrcweir NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory > m_xFactory; 194cdf0e10cSrcweir 195cdf0e10cSrcweir migrations_available m_vMigrationsAvailable; // list of all available migrations 196cdf0e10cSrcweir migrations_vr m_vrMigrations; // list of all migration specs from config 197cdf0e10cSrcweir install_info m_aInfo; // info about the version being migrated 198cdf0e10cSrcweir strings_vr m_vrFileList; // final list of files to be copied 199cdf0e10cSrcweir MigrationHashMap m_aOldVersionItemsHashMap; 200cdf0e10cSrcweir MigrationHashMap m_aNewVersionItemsHashMap; 201cdf0e10cSrcweir ::rtl::OUString m_sModuleIdentifier; 202cdf0e10cSrcweir 203cdf0e10cSrcweir // functions to control the migration process 204cdf0e10cSrcweir bool readAvailableMigrations(migrations_available&); 205cdf0e10cSrcweir migrations_vr readMigrationSteps(const ::rtl::OUString& rMigrationName); 206cdf0e10cSrcweir sal_Int32 findPreferedMigrationProcess(const migrations_available&); 207cdf0e10cSrcweir install_info findInstallation(const strings_v& rVersions); 208cdf0e10cSrcweir strings_vr compileFileList(); 209cdf0e10cSrcweir 210cdf0e10cSrcweir // helpers 211cdf0e10cSrcweir void substract(strings_v& va, const strings_v& vb_c) const; 212cdf0e10cSrcweir strings_vr getAllFiles(const rtl::OUString& baseURL) const; 213cdf0e10cSrcweir strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const; 214cdf0e10cSrcweir NS_UNO::Reference< NS_CSS::container::XNameAccess > getConfigAccess(const sal_Char* path, sal_Bool rw=sal_False); 215cdf0e10cSrcweir 216cdf0e10cSrcweir ::std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const; 217cdf0e10cSrcweir void compareOldAndNewConfig(const ::rtl::OUString& sParentNodeName, 218cdf0e10cSrcweir const NS_UNO::Reference< NS_CSS::container::XIndexContainer >& xOldIndexContainer, 219cdf0e10cSrcweir const NS_UNO::Reference< NS_CSS::container::XIndexContainer >& xNewIndexContainer, 220cdf0e10cSrcweir const ::rtl::OUString& sToolbarName); 221cdf0e10cSrcweir void mergeOldToNewVersion(const NS_UNO::Reference< NS_CSS::ui::XUIConfigurationManager >& xCfgManager, 222cdf0e10cSrcweir const NS_UNO::Reference< NS_CSS::container::XIndexContainer>& xIndexContainer, 223cdf0e10cSrcweir const ::rtl::OUString& sModuleIdentifier, 224cdf0e10cSrcweir const ::rtl::OUString& sResourceURL); 225cdf0e10cSrcweir 226cdf0e10cSrcweir // actual processing function that perform the migration steps 227cdf0e10cSrcweir void copyFiles(); 228cdf0e10cSrcweir void copyConfig(); 229cdf0e10cSrcweir void runServices(); 230cdf0e10cSrcweir void refresh(); 231cdf0e10cSrcweir 232cdf0e10cSrcweir void setMigrationCompleted(); 233cdf0e10cSrcweir sal_Bool checkMigrationCompleted(); 234cdf0e10cSrcweir 235cdf0e10cSrcweir public: 236cdf0e10cSrcweir MigrationImpl(const NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory >&); 237cdf0e10cSrcweir ~MigrationImpl(); 238cdf0e10cSrcweir sal_Bool doMigration(); 239cdf0e10cSrcweir sal_Bool checkMigration(); 240cdf0e10cSrcweir rtl::OUString getOldVersionName(); 241cdf0e10cSrcweir 242cdf0e10cSrcweir 243cdf0e10cSrcweir }; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir #undef NS_CSS 246cdf0e10cSrcweir #undef NS_UNO 247cdf0e10cSrcweir 248cdf0e10cSrcweir #endif 249