office-gobmx/desktop/source/migration/migration_impl.hxx
Luboš Luňák 1946794ae0 mass removal of rtl:: prefixes for O(U)String*
Modules sal, salhelper, cppu, cppuhelper, codemaker (selectively) and odk
have kept them, in order not to break external API (the automatic using declaration
is LO-internal).

Change-Id: I588fc9e0c45b914f824f91c0376980621d730f09
2013-04-07 14:23:11 +02:00

240 lines
8.1 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef _DESKTOP_MIGRATION_IMPL_HXX_
#define _DESKTOP_MIGRATION_IMPL_HXX_
#include <vector>
#include <algorithm>
#include <memory>
#include <boost/unordered_map.hpp>
#include "migration.hxx"
#include <sal/types.h>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
#include <com/sun/star/ui/XUIConfigurationManager.hpp>
#include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
namespace desktop
{
struct install_info
{
OUString productname; // human readeable product name
OUString userdata; // file: url for user installation
};
typedef std::vector< OUString > strings_v;
typedef std::auto_ptr< strings_v > strings_vr;
struct migration_step
{
OUString name;
strings_v includeFiles;
strings_v excludeFiles;
strings_v includeConfig;
strings_v excludeConfig;
strings_v includeExtensions;
strings_v excludeExtensions;
OUString service;
};
struct supported_migration
{
OUString name;
sal_Int32 nPriority;
strings_v supported_versions;
};
typedef std::vector< migration_step > migrations_v;
typedef std::auto_ptr< migrations_v > migrations_vr;
typedef std::vector< supported_migration > migrations_available;
//__________________________________________
/**
define the item, e.g.:menuitem, toolbaritem, to be migrated. we keep the information
of the command URL, the previous sibling node and the parent node of a item
*/
struct MigrationItem
{
OUString m_sParentNodeName;
OUString m_sPrevSibling;
OUString m_sCommandURL;
css::uno::Reference< css::container::XIndexContainer > m_xPopupMenu;
MigrationItem()
:m_xPopupMenu(0)
{
}
MigrationItem(const OUString& sParentNodeName,
const OUString& sPrevSibling,
const OUString& sCommandURL,
const css::uno::Reference< css::container::XIndexContainer > xPopupMenu)
{
m_sParentNodeName = sParentNodeName;
m_sPrevSibling = sPrevSibling;
m_sCommandURL = sCommandURL;
m_xPopupMenu = xPopupMenu;
}
MigrationItem& operator=(const MigrationItem& aMigrationItem)
{
m_sParentNodeName = aMigrationItem.m_sParentNodeName;
m_sPrevSibling = aMigrationItem.m_sPrevSibling;
m_sCommandURL = aMigrationItem.m_sCommandURL;
m_xPopupMenu = aMigrationItem.m_xPopupMenu;
return *this;
}
sal_Bool operator==(const MigrationItem& aMigrationItem)
{
return ( aMigrationItem.m_sParentNodeName == m_sParentNodeName &&
aMigrationItem.m_sPrevSibling == m_sPrevSibling &&
aMigrationItem.m_sCommandURL == m_sCommandURL &&
aMigrationItem.m_xPopupMenu.is() == m_xPopupMenu.is() );
}
OUString GetPrevSibling() const { return m_sPrevSibling; }
};
typedef ::boost::unordered_map< OUString,
::std::vector< MigrationItem >,
OUStringHash,
::std::equal_to< OUString > > MigrationHashMap;
struct MigrationItemInfo
{
OUString m_sResourceURL;
MigrationItem m_aMigrationItem;
MigrationItemInfo(){}
MigrationItemInfo(const OUString& sResourceURL, const MigrationItem& aMigrationItem)
: m_sResourceURL(sResourceURL), m_aMigrationItem(aMigrationItem)
{
}
};
//__________________________________________
/**
information for the UI elements to be migrated for one module
*/
struct MigrationModuleInfo
{
OUString sModuleShortName;
sal_Bool bHasMenubar;
::std::vector< OUString > m_vToolbars;
MigrationModuleInfo():bHasMenubar(sal_False){};
};
//__________________________________________
/**
get the information before copying the ui configuration files of old version to new version
*/
class NewVersionUIInfo
{
public:
css::uno::Reference< css::ui::XUIConfigurationManager > getConfigManager(const OUString& sModuleShortName) const;
css::uno::Reference< css::container::XIndexContainer > getNewMenubarSettings(const OUString& sModuleShortName) const;
css::uno::Reference< css::container::XIndexContainer > getNewToolbarSettings(const OUString& sModuleShortName, const OUString& sToolbarName) const;
void init(const ::std::vector< MigrationModuleInfo >& vModulesInfo);
private:
css::uno::Sequence< css::beans::PropertyValue > m_lCfgManagerSeq;
css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionMenubarSettingsSeq;
css::uno::Sequence< css::beans::PropertyValue > m_lNewVersionToolbarSettingsSeq;
};
class MigrationImpl
{
private:
strings_vr m_vrVersions;
migrations_available m_vMigrationsAvailable; // list of all available migrations
migrations_vr m_vrMigrations; // list of all migration specs from config
install_info m_aInfo; // info about the version being migrated
strings_vr m_vrFileList; // final list of files to be copied
MigrationHashMap m_aOldVersionItemsHashMap;
MigrationHashMap m_aNewVersionItemsHashMap;
OUString m_sModuleIdentifier;
// functions to control the migration process
bool readAvailableMigrations(migrations_available&);
bool alreadyMigrated();
migrations_vr readMigrationSteps(const OUString& rMigrationName);
sal_Int32 findPreferedMigrationProcess(const migrations_available&);
#if defined UNX && ! defined MACOSX
OUString preXDGConfigDir(const OUString& rConfigDir);
#endif
void setInstallInfoIfExist(install_info& aInfo, const OUString& rConfigDir, const OUString& rVersion);
install_info findInstallation(const strings_v& rVersions);
strings_vr compileFileList();
// helpers
strings_vr getAllFiles(const OUString& baseURL) const;
strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const;
css::uno::Reference< css::container::XNameAccess > getConfigAccess(const sal_Char* path, sal_Bool rw=sal_False);
::std::vector< MigrationModuleInfo > dectectUIChangesForAllModules() const;
void compareOldAndNewConfig(const OUString& sParentNodeName,
const css::uno::Reference< css::container::XIndexContainer >& xOldIndexContainer,
const css::uno::Reference< css::container::XIndexContainer >& xNewIndexContainer,
const OUString& sToolbarName);
void mergeOldToNewVersion(const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgManager,
const css::uno::Reference< css::container::XIndexContainer>& xIndexContainer,
const OUString& sModuleIdentifier,
const OUString& sResourceURL);
// actual processing function that perform the migration steps
void copyFiles();
void copyConfig();
void runServices();
void refresh();
void setMigrationCompleted();
bool checkMigrationCompleted();
public:
MigrationImpl();
~MigrationImpl();
bool initializeMigration();
sal_Bool doMigration();
OUString getOldVersionName();
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */