LCOV - code coverage report
Current view: top level - libreoffice/desktop/source/migration - migration_impl.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 22 0.0 %
Date: 2012-12-17 Functions: 0 20 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 _DESKTOP_MIGRATION_IMPL_HXX_
      20             : #define _DESKTOP_MIGRATION_IMPL_HXX_
      21             : 
      22             : #include <vector>
      23             : #include <algorithm>
      24             : #include <memory>
      25             : #include <boost/unordered_map.hpp>
      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/lang/XMultiServiceFactory.hpp>
      36             : #include <com/sun/star/container/XNameAccess.hpp>
      37             : #include <com/sun/star/container/XIndexAccess.hpp>
      38             : #include <com/sun/star/container/XIndexContainer.hpp>
      39             : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
      40             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      41             : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
      42             : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
      43             : #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
      44             : 
      45             : #define NS_CSS com::sun::star
      46             : #define NS_UNO com::sun::star::uno
      47             : 
      48             : namespace desktop
      49             : {
      50             : 
      51           0 : struct install_info
      52             : {
      53             :     rtl::OUString productname;  // human readeable product name
      54             :     rtl::OUString userdata;     // file: url for user installation
      55             : };
      56             : 
      57             : typedef std::vector< rtl::OUString > strings_v;
      58             : typedef std::auto_ptr< strings_v > strings_vr;
      59             : 
      60           0 : struct migration_step
      61             : {
      62             :     rtl::OUString name;
      63             :     strings_v includeFiles;
      64             :     strings_v excludeFiles;
      65             :     strings_v includeConfig;
      66             :     strings_v excludeConfig;
      67             :     strings_v includeExtensions;
      68             :     strings_v excludeExtensions;
      69             :     rtl::OUString service;
      70             : };
      71             : 
      72           0 : struct supported_migration
      73             : {
      74             :     rtl::OUString name;
      75             :     sal_Int32     nPriority;
      76             :     strings_v     supported_versions;
      77             : };
      78             : 
      79             : typedef std::vector< migration_step > migrations_v;
      80             : typedef std::auto_ptr< migrations_v > migrations_vr;
      81             : typedef std::vector< supported_migration > migrations_available;
      82             : 
      83             : //__________________________________________
      84             : /**
      85             :     define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information
      86             :     of the command URL, the previous sibling node and the parent node of a item
      87             : */
      88           0 : struct MigrationItem
      89             : {
      90             :     ::rtl::OUString m_sParentNodeName;
      91             :     ::rtl::OUString m_sPrevSibling;
      92             :     ::rtl::OUString m_sCommandURL;
      93             :     NS_UNO::Reference< NS_CSS::container::XIndexContainer > m_xPopupMenu;
      94             : 
      95           0 :     MigrationItem()
      96           0 :         :m_xPopupMenu(0)
      97             :     {
      98           0 :     }
      99             : 
     100           0 :     MigrationItem(const ::rtl::OUString& sParentNodeName,
     101             :         const ::rtl::OUString& sPrevSibling,
     102             :         const ::rtl::OUString& sCommandURL,
     103             :         const NS_UNO::Reference< NS_CSS::container::XIndexContainer > xPopupMenu)
     104           0 :     {
     105           0 :         m_sParentNodeName = sParentNodeName;
     106           0 :         m_sPrevSibling    = sPrevSibling;
     107           0 :         m_sCommandURL     = sCommandURL;
     108           0 :         m_xPopupMenu      = xPopupMenu;
     109           0 :     }
     110             : 
     111             :     MigrationItem& operator=(const MigrationItem& aMigrationItem)
     112             :     {
     113             :         m_sParentNodeName = aMigrationItem.m_sParentNodeName;
     114             :         m_sPrevSibling    = aMigrationItem.m_sPrevSibling;
     115             :         m_sCommandURL     = aMigrationItem.m_sCommandURL;
     116             :         m_xPopupMenu      = aMigrationItem.m_xPopupMenu;
     117             : 
     118             :         return *this;
     119             :     }
     120             : 
     121           0 :     sal_Bool operator==(const MigrationItem& aMigrationItem)
     122             :     {
     123           0 :         return ( aMigrationItem.m_sParentNodeName == m_sParentNodeName &&
     124           0 :             aMigrationItem.m_sPrevSibling    == m_sPrevSibling     &&
     125           0 :             aMigrationItem.m_sCommandURL     == m_sCommandURL      &&
     126           0 :             aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is()    );
     127             :     }
     128             : 
     129             :     ::rtl::OUString GetPrevSibling() const { return m_sPrevSibling; }
     130             : };
     131             : 
     132             : typedef ::boost::unordered_map< ::rtl::OUString,
     133             :                          ::std::vector< MigrationItem >,
     134             :                          ::rtl::OUStringHash,
     135             :                          ::std::equal_to< ::rtl::OUString > > MigrationHashMap;
     136             : 
     137             : struct MigrationItemInfo
     138             : {
     139             :     ::rtl::OUString m_sResourceURL;
     140             :     MigrationItem m_aMigrationItem;
     141             : 
     142             :     MigrationItemInfo(){}
     143             : 
     144             :     MigrationItemInfo(const ::rtl::OUString& sResourceURL, const MigrationItem& aMigrationItem)
     145             :     : m_sResourceURL(sResourceURL), m_aMigrationItem(aMigrationItem)
     146             :     {
     147             :     }
     148             : };
     149             : 
     150             : //__________________________________________
     151             : /**
     152             :     information for the UI elements to be migrated for one module
     153             : */
     154           0 : struct MigrationModuleInfo
     155             : {
     156             :     ::rtl::OUString sModuleShortName;
     157             :     sal_Bool        bHasMenubar;
     158             :     ::std::vector< ::rtl::OUString > m_vToolbars;
     159             : 
     160           0 :     MigrationModuleInfo():bHasMenubar(sal_False){};
     161             : };
     162             : 
     163             : //__________________________________________
     164             : /**
     165             :     get the information before copying the ui configuration files of old version to new version
     166             : */
     167           0 : class NewVersionUIInfo
     168             : {
     169             : public:
     170             : 
     171             :     NS_UNO::Reference< NS_CSS::ui::XUIConfigurationManager > getConfigManager(const ::rtl::OUString& sModuleShortName) const;
     172             :     NS_UNO::Reference< NS_CSS::container::XIndexContainer > getNewMenubarSettings(const ::rtl::OUString& sModuleShortName) const;
     173             :     NS_UNO::Reference< NS_CSS::container::XIndexContainer > getNewToolbarSettings(const ::rtl::OUString& sModuleShortName, const ::rtl::OUString& sToolbarName) const;
     174             :     void init(const ::std::vector< MigrationModuleInfo >& vModulesInfo);
     175             : 
     176             : private:
     177             : 
     178             :     NS_UNO::Sequence< NS_CSS::beans::PropertyValue > m_lCfgManagerSeq;
     179             :     NS_UNO::Sequence< NS_CSS::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq;
     180             :     NS_UNO::Sequence< NS_CSS::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq;
     181             : };
     182             : 
     183             : class MigrationImpl
     184             : {
     185             : 
     186             : private:
     187             :     strings_vr m_vrVersions;
     188             :     NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory > m_xFactory;
     189             : 
     190             :     migrations_available m_vMigrationsAvailable; // list of all available migrations
     191             :     migrations_vr        m_vrMigrations;         // list of all migration specs from config
     192             :     install_info         m_aInfo;                // info about the version being migrated
     193             :     strings_vr           m_vrFileList;           // final list of files to be copied
     194             :      MigrationHashMap     m_aOldVersionItemsHashMap;
     195             :      MigrationHashMap     m_aNewVersionItemsHashMap;
     196             :      ::rtl::OUString      m_sModuleIdentifier;
     197             : 
     198             :     // functions to control the migration process
     199             :     bool          readAvailableMigrations(migrations_available&);
     200             :     bool          alreadyMigrated();
     201             :     migrations_vr readMigrationSteps(const ::rtl::OUString& rMigrationName);
     202             :     sal_Int32     findPreferedMigrationProcess(const migrations_available&);
     203             : #if defined UNX && ! defined MACOSX
     204             :     OUString preXDGConfigDir(const OUString& rConfigDir);
     205             : #endif
     206             :     void          setInstallInfoIfExist(install_info& aInfo,  const OUString& rConfigDir, const OUString& rVersion);
     207             :     install_info  findInstallation(const strings_v& rVersions);
     208             :     strings_vr    compileFileList();
     209             : 
     210             :     // helpers
     211             :     void subtract(strings_v& va, const strings_v& vb_c) const;
     212             :     strings_vr getAllFiles(const rtl::OUString& baseURL) const;
     213             :     strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const;
     214             :     NS_UNO::Reference< NS_CSS::container::XNameAccess > getConfigAccess(const sal_Char* path, sal_Bool rw=sal_False);
     215             : 
     216             :     ::std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const;
     217             :     void compareOldAndNewConfig(const ::rtl::OUString& sParentNodeName,
     218             :         const NS_UNO::Reference< NS_CSS::container::XIndexContainer >& xOldIndexContainer,
     219             :         const NS_UNO::Reference< NS_CSS::container::XIndexContainer >& xNewIndexContainer,
     220             :         const ::rtl::OUString& sToolbarName);
     221             :     void mergeOldToNewVersion(const NS_UNO::Reference< NS_CSS::ui::XUIConfigurationManager >& xCfgManager,
     222             :         const NS_UNO::Reference< NS_CSS::container::XIndexContainer>& xIndexContainer,
     223             :         const ::rtl::OUString& sModuleIdentifier,
     224             :         const ::rtl::OUString& sResourceURL);
     225             : 
     226             :     // actual processing function that perform the migration steps
     227             :     void copyFiles();
     228             :     void copyConfig();
     229             :     void runServices();
     230             :     void refresh();
     231             : 
     232             :     void setMigrationCompleted();
     233             :     bool checkMigrationCompleted();
     234             : 
     235             : public:
     236             :     MigrationImpl(const NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory >&);
     237             :     ~MigrationImpl();
     238             :     bool initializeMigration();
     239             :     sal_Bool doMigration();
     240             :     rtl::OUString getOldVersionName();
     241             : };
     242             : }
     243             : #undef NS_CSS
     244             : #undef NS_UNO
     245             : 
     246             : #endif
     247             : 
     248             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10