LCOV - code coverage report
Current view: top level - desktop/source/migration - migration_impl.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 2 26 7.7 %
Date: 2015-06-13 12:38:46 Functions: 5 22 22.7 %
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 INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
      20             : #define INCLUDED_DESKTOP_SOURCE_MIGRATION_MIGRATION_IMPL_HXX
      21             : 
      22             : #include <algorithm>
      23             : #include <memory>
      24             : #include <unordered_map>
      25             : #include <vector>
      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/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>
      43             : 
      44             : namespace desktop
      45             : {
      46             : 
      47         212 : struct install_info
      48             : {
      49             :     OUString productname;  // human readeable product name
      50             :     OUString userdata;     // file: url for user installation
      51             : };
      52             : 
      53             : typedef std::vector< OUString > strings_v;
      54             : typedef std::unique_ptr< strings_v > strings_vr;
      55             : 
      56           0 : struct migration_step
      57             : {
      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;
      66             : };
      67             : 
      68         212 : struct supported_migration
      69             : {
      70             :     OUString name;
      71             :     sal_Int32     nPriority;
      72             :     strings_v     supported_versions;
      73             : };
      74             : 
      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;
      78             : 
      79             : namespace {
      80             : 
      81           0 : inline bool areBothOpenFrom(OUString const & cmd1, OUString const & cmd2)
      82             : {
      83           0 :     return cmd1 == ".uno:Open" && cmd2.startsWith(".uno:OpenFrom");
      84             : }
      85             : 
      86             : }
      87             : 
      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
      91             : */
      92           0 : struct MigrationItem
      93             : {
      94             :     OUString m_sParentNodeName;
      95             :     OUString m_sPrevSibling;
      96             :     OUString m_sCommandURL;
      97             :     css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu;
      98             : 
      99           0 :     MigrationItem()
     100           0 :         :m_xPopupMenu(0)
     101             :     {
     102           0 :     }
     103             : 
     104           0 :     MigrationItem(const OUString& sParentNodeName,
     105             :         const OUString& sPrevSibling,
     106             :         const OUString& sCommandURL,
     107             :         const css::uno::Reference< css::container::XIndexContainer > xPopupMenu)
     108           0 :     {
     109           0 :         m_sParentNodeName = sParentNodeName;
     110           0 :         m_sPrevSibling    = sPrevSibling;
     111           0 :         m_sCommandURL     = sCommandURL;
     112           0 :         m_xPopupMenu      = xPopupMenu;
     113           0 :     }
     114             : 
     115             :     MigrationItem& operator=(const MigrationItem& aMigrationItem)
     116             :     {
     117             :         m_sParentNodeName = aMigrationItem.m_sParentNodeName;
     118             :         m_sPrevSibling    = aMigrationItem.m_sPrevSibling;
     119             :         m_sCommandURL     = aMigrationItem.m_sCommandURL;
     120             :         m_xPopupMenu      = aMigrationItem.m_xPopupMenu;
     121             : 
     122             :         return *this;
     123             :     }
     124             : 
     125           0 :     bool operator==(const MigrationItem& aMigrationItem)
     126             :     {
     127             :         return
     128           0 :             (aMigrationItem.m_sCommandURL == m_sCommandURL
     129           0 :              || areBothOpenFrom(aMigrationItem.m_sCommandURL, m_sCommandURL)
     130           0 :              || areBothOpenFrom(m_sCommandURL, aMigrationItem.m_sCommandURL))
     131           0 :             && aMigrationItem.m_sParentNodeName == m_sParentNodeName
     132           0 :             && aMigrationItem.m_sPrevSibling    == m_sPrevSibling
     133           0 :             && aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is();
     134             :     }
     135             : };
     136             : 
     137             : typedef std::unordered_map< OUString, std::vector< MigrationItem >,
     138             :                             OUStringHash, std::equal_to< OUString > > MigrationHashMap;
     139             : 
     140             : struct MigrationItemInfo
     141             : {
     142             :     OUString m_sResourceURL;
     143             :     MigrationItem m_aMigrationItem;
     144             : 
     145             :     MigrationItemInfo(){}
     146             : 
     147             :     MigrationItemInfo(const OUString& sResourceURL, const MigrationItem& aMigrationItem)
     148             :     : m_sResourceURL(sResourceURL), m_aMigrationItem(aMigrationItem)
     149             :     {
     150             :     }
     151             : };
     152             : 
     153             : 
     154             : /**
     155             :     information for the UI elements to be migrated for one module
     156             : */
     157           0 : struct MigrationModuleInfo
     158             : {
     159             :     OUString sModuleShortName;
     160             :     bool     bHasMenubar;
     161             :     ::std::vector< OUString > m_vToolbars;
     162             : 
     163           0 :     MigrationModuleInfo() : bHasMenubar(false) {};
     164             : };
     165             : 
     166             : 
     167             : /**
     168             :     get the information before copying the ui configuration files of old version to new version
     169             : */
     170           0 : class NewVersionUIInfo
     171             : {
     172             : public:
     173             : 
     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);
     178             : 
     179             : private:
     180             : 
     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;
     184             : };
     185             : 
     186             : class MigrationImpl
     187             : {
     188             : 
     189             : private:
     190             :     strings_vr m_vrVersions;
     191             : 
     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;
     198             : 
     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();
     210             : 
     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);
     215             : 
     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);
     225             : 
     226             :     // actual processing function that perform the migration steps
     227             :     void copyFiles();
     228             :     void copyConfig();
     229             :     void runServices();
     230             :     static void refresh();
     231             : 
     232             :     static void setMigrationCompleted();
     233             :     static bool checkMigrationCompleted();
     234             : 
     235             : public:
     236             :     MigrationImpl();
     237             :     ~MigrationImpl();
     238             :     bool initializeMigration();
     239             :     bool doMigration();
     240             :     OUString getOldVersionName();
     241             : };
     242             : }
     243             : 
     244             : #endif
     245             : 
     246             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11