diff options
author | sb <sb@openoffice.org> | 2010-04-07 13:14:23 +0200 |
---|---|---|
committer | sb <sb@openoffice.org> | 2010-04-07 13:14:23 +0200 |
commit | 75ba0870517ea585027812c48dcfbc0827280a84 (patch) | |
tree | 5df4d546e2fab9c70bf902a0afe27292a36d0812 /desktop/source | |
parent | 5521c8065f538b8cedaf2db2dbff9a265394a6b3 (diff) | |
parent | 7a7f37e3ba0ba89628fb30b035440ff5f91ab551 (diff) |
sb118: merged in re/DEV300_next towards DEV300_m76
Diffstat (limited to 'desktop/source')
27 files changed, 1633 insertions, 163 deletions
diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx index 0b3813f42971..0625191ee2ea 100644 --- a/desktop/source/app/cmdlineargs.cxx +++ b/desktop/source/app/cmdlineargs.cxx @@ -227,7 +227,7 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) bViewEvent = sal_False; bStartEvent = sal_False; bDisplaySpec = sal_False; - } + } else if ( aArgStr.EqualsIgnoreCaseAscii( "-view" )) { // open in viewmode @@ -239,31 +239,43 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) bViewEvent = sal_True; bStartEvent = sal_False; bDisplaySpec = sal_False; - } + } else if ( aArgStr.EqualsIgnoreCaseAscii( "-show" )) { - // open in viewmode - bOpenEvent = sal_False; - bViewEvent = sal_False; - bStartEvent = sal_True; - bPrintEvent = sal_False; - bPrintToEvent = sal_False; - bForceNewEvent = sal_False; - bForceOpenEvent = sal_False; - bDisplaySpec = sal_False; + // open in viewmode + bOpenEvent = sal_False; + bViewEvent = sal_False; + bStartEvent = sal_True; + bPrintEvent = sal_False; + bPrintToEvent = sal_False; + bForceNewEvent = sal_False; + bForceOpenEvent = sal_False; + bDisplaySpec = sal_False; } else if ( aArgStr.EqualsIgnoreCaseAscii( "-display" )) { - // open in viewmode - bOpenEvent = sal_False; - bPrintEvent = sal_False; - bForceOpenEvent = sal_False; - bPrintToEvent = sal_False; - bForceNewEvent = sal_False; - bViewEvent = sal_False; - bStartEvent = sal_False; - bDisplaySpec = sal_True; + // set display + bOpenEvent = sal_False; + bPrintEvent = sal_False; + bForceOpenEvent = sal_False; + bPrintToEvent = sal_False; + bForceNewEvent = sal_False; + bViewEvent = sal_False; + bStartEvent = sal_False; + bDisplaySpec = sal_True; + } + else if ( aArgStr.EqualsIgnoreCaseAscii( "-language" )) + { + bOpenEvent = sal_False; + bPrintEvent = sal_False; + bForceOpenEvent = sal_False; + bPrintToEvent = sal_False; + bForceNewEvent = sal_False; + bViewEvent = sal_False; + bStartEvent = sal_False; + bDisplaySpec = sal_False; } + #ifdef MACOSX /* #i84053# ignore -psn on Mac Platform dependent #ifdef here is ugly, however this is currently @@ -272,15 +284,15 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) */ else if ( aArgStr.CompareToAscii( "-psn", 4 ) == COMPARE_EQUAL ) { - // finder argument from MacOSX - bOpenEvent = sal_False; - bPrintEvent = sal_False; - bForceOpenEvent = sal_False; - bPrintToEvent = sal_False; - bForceNewEvent = sal_False; - bViewEvent = sal_False; - bStartEvent = sal_False; - bDisplaySpec = sal_False; + // finder argument from MacOSX + bOpenEvent = sal_False; + bPrintEvent = sal_False; + bForceOpenEvent = sal_False; + bPrintToEvent = sal_False; + bForceNewEvent = sal_False; + bViewEvent = sal_False; + bStartEvent = sal_False; + bDisplaySpec = sal_False; } #endif } @@ -509,7 +521,12 @@ sal_Bool CommandLineArgs::InterpretCommandLineParameter( const ::rtl::OUString& } else if ( aArgStr.Copy(0, 9).EqualsIgnoreCaseAscii( "-version=" )) { - AddStringListParam_Impl( CMD_STRINGPARAM_VERSION, aArgStr.Copy( 15 ) ); + AddStringListParam_Impl( CMD_STRINGPARAM_VERSION, aArgStr.Copy( 9 ) ); + return sal_True; + } + else if ( aArgStr.Copy(0, 10).EqualsIgnoreCaseAscii( "-language=" )) + { + AddStringListParam_Impl( CMD_STRINGPARAM_LANGUAGE, aArgStr.Copy( 10 ) ); return sal_True; } else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-writer" )) == sal_True ) @@ -858,6 +875,13 @@ sal_Bool CommandLineArgs::GetPrinterName( ::rtl::OUString& rPara ) const return m_aStrSetParams[ CMD_STRINGPARAM_PRINTERNAME ]; } +sal_Bool CommandLineArgs::GetLanguage( ::rtl::OUString& rPara ) const +{ + osl::MutexGuard aMutexGuard( m_aMutex ); + rPara = m_aStrParams[ CMD_STRINGPARAM_LANGUAGE ]; + return m_aStrSetParams[ CMD_STRINGPARAM_LANGUAGE ]; +} + sal_Bool CommandLineArgs::IsEmpty() const { osl::MutexGuard aMutexGuard( m_aMutex ); diff --git a/desktop/source/app/cmdlineargs.hxx b/desktop/source/app/cmdlineargs.hxx index 894259ffc30b..615577098c2d 100644 --- a/desktop/source/app/cmdlineargs.hxx +++ b/desktop/source/app/cmdlineargs.hxx @@ -91,6 +91,7 @@ class CommandLineArgs CMD_STRINGPARAM_PRINTTOLIST, CMD_STRINGPARAM_PRINTERNAME, CMD_STRINGPARAM_DISPLAY, + CMD_STRINGPARAM_LANGUAGE, CMD_STRINGPARAM_COUNT // must be last element! }; @@ -167,6 +168,7 @@ class CommandLineArgs sal_Bool GetPrintList( ::rtl::OUString& rPara) const; sal_Bool GetPrintToList( ::rtl::OUString& rPara ) const; sal_Bool GetPrinterName( ::rtl::OUString& rPara ) const; + sal_Bool GetLanguage( ::rtl::OUString& rPara ) const; // Special analyzed states (does not match directly to a command line parameter!) sal_Bool IsPrinting() const; diff --git a/desktop/source/app/langselect.cxx b/desktop/source/app/langselect.cxx index 8ce57eb3451f..7969371f56d9 100644 --- a/desktop/source/app/langselect.cxx +++ b/desktop/source/app/langselect.cxx @@ -52,6 +52,7 @@ #include <rtl/locale.hxx> #include <rtl/instance.hxx> #include <osl/process.h> +#include <osl/file.hxx> using namespace rtl; using namespace com::sun::star::uno; @@ -62,10 +63,54 @@ using namespace com::sun::star::util; namespace desktop { +static char const SOFFICE_BOOTSTRAP[] = "Bootstrap"; +static char const SOFFICE_STARTLANG[] = "STARTLANG"; sal_Bool LanguageSelection::bFoundLanguage = sal_False; OUString LanguageSelection::aFoundLanguage; const OUString LanguageSelection::usFallbackLanguage = OUString::createFromAscii("en-US"); + +static sal_Bool existsURL( OUString const& sURL ) +{ + using namespace osl; + DirectoryItem aDirItem; + + if (sURL.getLength() != 0) + return ( DirectoryItem::get( sURL, aDirItem ) == DirectoryItem::E_None ); + + return sal_False; +} + +// locate soffice.ini/.rc file +static OUString locateSofficeIniFile() +{ + OUString aUserDataPath; + OUString aSofficeIniFileURL; + + // Retrieve the default file URL for the soffice.ini/rc + rtl::Bootstrap().getIniName( aSofficeIniFileURL ); + + if ( utl::Bootstrap::locateUserData( aUserDataPath ) == utl::Bootstrap::PATH_EXISTS ) + { + const char CONFIG_DIR[] = "/config"; + + sal_Int32 nIndex = aSofficeIniFileURL.lastIndexOf( '/'); + if ( nIndex > 0 ) + { + OUString aUserSofficeIniFileURL; + OUStringBuffer aBuffer( aUserDataPath ); + aBuffer.appendAscii( CONFIG_DIR ); + aBuffer.append( aSofficeIniFileURL.copy( nIndex )); + aUserSofficeIniFileURL = aBuffer.makeStringAndClear(); + + if ( existsURL( aUserSofficeIniFileURL )) + return aUserSofficeIniFileURL; + } + } + // Fallback try to use the soffice.ini/rc from program folder + return aSofficeIniFileURL; +} + Locale LanguageSelection::IsoStringToLocale(const OUString& str) { Locale l; @@ -119,8 +164,51 @@ bool LanguageSelection::prepareLanguage() catch (Exception&) { } + // get the selected UI language as string - OUString aLocaleString = getLanguageString(); + bool bCmdLanguage( false ); + bool bIniLanguage( false ); + OUString aEmpty; + OUString aLocaleString = getUserUILanguage(); + + if ( aLocaleString.getLength() == 0 ) + { + CommandLineArgs* pCmdLineArgs = Desktop::GetCommandLineArgs(); + if ( pCmdLineArgs ) + { + pCmdLineArgs->GetLanguage(aLocaleString); + if (isInstalledLanguage(aLocaleString, sal_False)) + { + bCmdLanguage = true; + bFoundLanguage = true; + aFoundLanguage = aLocaleString; + } + else + aLocaleString = aEmpty; + } + + if ( !bCmdLanguage ) + { + OUString aSOfficeIniURL = locateSofficeIniFile(); + Config aConfig(aSOfficeIniURL); + aConfig.SetGroup( SOFFICE_BOOTSTRAP ); + OString sLang = aConfig.ReadKey( SOFFICE_STARTLANG ); + aLocaleString = OUString( sLang.getStr(), sLang.getLength(), RTL_TEXTENCODING_ASCII_US ); + if (isInstalledLanguage(aLocaleString, sal_False)) + { + bIniLanguage = true; + bFoundLanguage = true; + aFoundLanguage = aLocaleString; + } + else + aLocaleString = aEmpty; + } + } + + // user further fallbacks for the UI language + if ( aLocaleString.getLength() == 0 ) + aLocaleString = getLanguageString(); + if ( aLocaleString.getLength() > 0 ) { try @@ -136,9 +224,21 @@ bool LanguageSelection::prepareLanguage() flush(); theConfigProvider->setLocale(loc); - Reference< XPropertySet > xProp(getConfigAccess("org.openoffice.Setup/L10N/", sal_True), UNO_QUERY_THROW); - xProp->setPropertyValue(OUString::createFromAscii("ooLocale"), makeAny(aLocaleString)); - Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges(); + if ( !bCmdLanguage ) + { + // Store language only + Reference< XPropertySet > xProp(getConfigAccess("org.openoffice.Setup/L10N/", sal_True), UNO_QUERY_THROW); + xProp->setPropertyValue(OUString::createFromAscii("ooLocale"), makeAny(aLocaleString)); + Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges(); + } + + if ( bIniLanguage ) + { + // Store language only + Reference< XPropertySet > xProp(getConfigAccess("org.openoffice.Office.Linguistic/General/", sal_True), UNO_QUERY_THROW); + xProp->setPropertyValue(OUString::createFromAscii("UILocale"), makeAny(aLocaleString)); + Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges(); + } MsLangId::setConfiguredSystemUILanguage( MsLangId::convertLocaleToLanguage(loc) ); @@ -197,11 +297,8 @@ void LanguageSelection::setDefaultLanguage(const OUString& sLocale) } } -OUString LanguageSelection::getLanguageString() +OUString LanguageSelection::getUserUILanguage() { - // did we already find a language? - if (bFoundLanguage) - return aFoundLanguage; // check whether the user has selected a specific language OUString aUserLanguage = getUserLanguage(); if (aUserLanguage.getLength() > 0 ) @@ -219,6 +316,21 @@ OUString LanguageSelection::getLanguageString() resetUserLanguage(); } } + + return aUserLanguage; +} + +OUString LanguageSelection::getLanguageString() +{ + // did we already find a language? + if (bFoundLanguage) + return aFoundLanguage; + + // check whether the user has selected a specific language + OUString aUserLanguage = getUserUILanguage(); + if (aUserLanguage.getLength() > 0 ) + return aUserLanguage ; + // try to use system default aUserLanguage = getSystemLanguage(); if (aUserLanguage.getLength() > 0 ) diff --git a/desktop/source/app/langselect.hxx b/desktop/source/app/langselect.hxx index 58b98fa88102..60308164690f 100644 --- a/desktop/source/app/langselect.hxx +++ b/desktop/source/app/langselect.hxx @@ -50,6 +50,7 @@ private: static com::sun::star::uno::Sequence< rtl::OUString > getInstalledLanguages(); static sal_Bool isInstalledLanguage(rtl::OUString& usLocale, sal_Bool bExact=sal_False); static rtl::OUString getFirstInstalledLanguage(); + static rtl::OUString getUserUILanguage(); static rtl::OUString getUserLanguage(); static rtl::OUString getSystemLanguage(); static void resetUserLanguage(); diff --git a/desktop/source/deployment/gui/dp_gui_dialog2.cxx b/desktop/source/deployment/gui/dp_gui_dialog2.cxx index 31019948f043..2d0733dfbae3 100644 --- a/desktop/source/deployment/gui/dp_gui_dialog2.cxx +++ b/desktop/source/deployment/gui/dp_gui_dialog2.cxx @@ -90,8 +90,7 @@ using ::rtl::OUString; namespace dp_gui { -#define ICON_OFFSET 50 -#define TOP_OFFSET 3 +#define TOP_OFFSET 5 #define LINE_SIZE 4 #define PROGRESS_WIDTH 60 #define PROGRESS_HEIGHT 14 diff --git a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx index b95a7e5f8cfb..2e02a90f59fd 100644 --- a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx +++ b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx @@ -520,10 +520,10 @@ void ExtensionBox_Impl::DrawRow( const Rectangle& rRect, const TEntry_Impl pEntr else aImage = isHCMode() ? pEntry->m_aIconHC : pEntry->m_aIcon; Size aImageSize = aImage.GetSizePixel(); - if ( ( aImageSize.Width() <= ICON_HEIGHT ) && ( aImageSize.Height() <= ICON_HEIGHT ) ) - DrawImage( Point( aPos.X()+((ICON_HEIGHT-aImageSize.Width())/2), aPos.Y()+((ICON_HEIGHT-aImageSize.Height())/2) ), aImage ); + if ( ( aImageSize.Width() <= ICON_WIDTH ) && ( aImageSize.Height() <= ICON_HEIGHT ) ) + DrawImage( Point( aPos.X()+((ICON_WIDTH-aImageSize.Width())/2), aPos.Y()+((ICON_HEIGHT-aImageSize.Height())/2) ), aImage ); else - DrawImage( aPos, Size( ICON_HEIGHT, ICON_HEIGHT ), aImage ); + DrawImage( aPos, Size( ICON_WIDTH, ICON_HEIGHT ), aImage ); // Setup fonts Font aStdFont( GetFont() ); diff --git a/desktop/source/deployment/gui/dp_gui_extlistbox.hxx b/desktop/source/deployment/gui/dp_gui_extlistbox.hxx index 18487dffe6e1..ad62bfd1a2d8 100644 --- a/desktop/source/deployment/gui/dp_gui_extlistbox.hxx +++ b/desktop/source/deployment/gui/dp_gui_extlistbox.hxx @@ -45,9 +45,10 @@ namespace dp_gui { #define SMALL_ICON_SIZE 16 -#define TOP_OFFSET 3 +#define TOP_OFFSET 5 #define ICON_HEIGHT 42 -#define ICON_OFFSET 50 +#define ICON_WIDTH 47 +#define ICON_OFFSET 72 #define RIGHT_ICON_OFFSET 5 #define SPACE_BETWEEN 3 diff --git a/desktop/source/deployment/inc/dp_descriptioninfoset.hxx b/desktop/source/deployment/inc/dp_descriptioninfoset.hxx index f9b3e1d989f1..38a1870782ed 100644 --- a/desktop/source/deployment/inc/dp_descriptioninfoset.hxx +++ b/desktop/source/deployment/inc/dp_descriptioninfoset.hxx @@ -53,6 +53,15 @@ namespace rtl { class OUString; } namespace dp_misc { +struct DESKTOP_DEPLOYMENTMISC_DLLPUBLIC SimpleLicenseAttributes +{ + ::rtl::OUString acceptBy; + //Attribute suppress-on-update. Default is false. + bool suppressOnUpdate; + //Attribute suppress-if-required. Default is false. + bool suppressIfRequired; +}; + /** Access to the content of an XML <code>description</code> element. @@ -132,6 +141,13 @@ public: */ ::rtl::OUString getLocalizedLicenseURL() const; + /** returns the attributes of the simple-license element + + As long as there is a simple-license element, the function will return + the structure. If it does not exist, then the optional object is uninitialized. + */ + ::boost::optional<SimpleLicenseAttributes> getSimpleLicenseAttributes() const; + /** returns the localized display name of the extensions. In case there is no localized display-name then an empty string is returned. diff --git a/desktop/source/deployment/misc/dp_descriptioninfoset.cxx b/desktop/source/deployment/misc/dp_descriptioninfoset.cxx index 587e31bebfb9..28f45918e9e2 100644 --- a/desktop/source/deployment/misc/dp_descriptioninfoset.cxx +++ b/desktop/source/deployment/misc/dp_descriptioninfoset.cxx @@ -370,6 +370,50 @@ css::uno::Sequence< ::rtl::OUString > DescriptionInfoset::getUrls( } +::boost::optional<SimpleLicenseAttributes> +DescriptionInfoset::getSimpleLicenseAttributes() const +{ + //Check if the node exist + css::uno::Reference< css::xml::dom::XNode > n; + if (m_element.is()) { + try { + n = m_xpath->selectSingleNode(m_element, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "/desc:description/desc:registration/desc:simple-license/@accept-by"))); + } catch (css::xml::xpath::XPathException &) { + // ignore + } + if (n.is()) + { + SimpleLicenseAttributes attributes; + attributes.acceptBy = + getNodeValueFromExpression(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "/desc:description/desc:registration/desc:simple-license/@accept-by"))); + + ::boost::optional< ::rtl::OUString > suppressOnUpdate = getOptionalValue( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "/desc:description/desc:registration/desc:simple-license/@suppress-on-update"))); + if (suppressOnUpdate) + attributes.suppressOnUpdate = (*suppressOnUpdate).trim().equalsIgnoreAsciiCase( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"))); + else + attributes.suppressOnUpdate = false; + + ::boost::optional< ::rtl::OUString > suppressIfRequired = getOptionalValue( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "/desc:description/desc:registration/desc:simple-license/@suppress-if-required"))); + if (suppressIfRequired) + attributes.suppressIfRequired = (*suppressIfRequired).trim().equalsIgnoreAsciiCase( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"))); + else + attributes.suppressIfRequired = false; + + return ::boost::optional<SimpleLicenseAttributes>(attributes); + } + } + return ::boost::optional<SimpleLicenseAttributes>(); +} + ::rtl::OUString DescriptionInfoset::getLocalizedDescriptionURL() const { return getLocalizedHREFAttrFromChild(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( diff --git a/desktop/source/deployment/registry/package/dp_package.cxx b/desktop/source/deployment/registry/package/dp_package.cxx index cfe5be59dad0..e45f7fb7ef73 100644 --- a/desktop/source/deployment/registry/package/dp_package.cxx +++ b/desktop/source/deployment/registry/package/dp_package.cxx @@ -70,7 +70,7 @@ #include "com/sun/star/xml/dom/XDocumentBuilder.hpp" #include "com/sun/star/xml/xpath/XXPathAPI.hpp" #include "com/sun/star/deployment/XPackageManager.hpp" - +#include "boost/optional.hpp" #include <vector> #include <stdio.h> @@ -583,21 +583,12 @@ bool BackendImpl::PackageImpl::checkDependencies( { try { - css::uno::Reference<css::xml::dom::XNode> xRoot = desc.getRootElement(); - css::uno::Reference<css::xml::xpath::XXPathAPI> xPath = - getDescriptionInfoset().getXpath(); - - css::uno::Reference<css::xml::dom::XNode> nodeSimpleLic; - try { - nodeSimpleLic = xPath->selectSingleNode(xRoot, - OUSTR("/desc:description/desc:registration/desc:simple-license")); - } catch (css::xml::xpath::XPathException &) { - // ignore - } - - if (!nodeSimpleLic.is()) + DescriptionInfoset info = getDescriptionInfoset(); + ::boost::optional<SimpleLicenseAttributes> simplLicAttr + = info.getSimpleLicenseAttributes(); + if (! simplLicAttr) return true; - OUString sLic = getDescriptionInfoset().getLocalizedLicenseURL(); + OUString sLic = info.getLocalizedLicenseURL(); //If we do not get a localized licence then there is an error in the description.xml //This should be handled by using a validating parser. Therefore we assume that no //license is available. @@ -606,23 +597,20 @@ bool BackendImpl::PackageImpl::checkDependencies( OUSTR("Could not obtain path to license. Possible error in description.xml"), 0, Any()); OUString sHref = desc.getExtensionRootUrl() + OUSTR("/") + sLic; OUString sLicense = getTextFromURL(xCmdEnv, sHref); - //determine who has to agree to the license - css::uno::Reference<css::xml::xpath::XXPathObject> nodeAttribWho3 = - xPath->eval(nodeSimpleLic, - OUSTR("@accept-by")); - OUString sAccept = nodeAttribWho3->getString().trim(); + ////determine who has to agree to the license //check correct value for attribute - if ( ! (sAccept.equals(OUSTR("user")) || sAccept.equals(OUSTR("admin")))) + if ( ! (simplLicAttr->acceptBy.equals(OUSTR("user")) || simplLicAttr->acceptBy.equals(OUSTR("admin")))) throw css::deployment::DeploymentException( OUSTR("Could not obtain attribute simple-lincense@accept-by or it has no valid value"), 0, Any()); //If if @accept-by="user" then every user needs to accept the license before it can be installed. - //Therefore we must prevent the installation as shared extension. + //Therefore we must prevent the installation as shared extension unless suppress-if-required="true" OSL_ASSERT(aContextName.getLength()); - if (sAccept.equals(OUSTR("user")) && aContextName.equals(OUSTR("shared"))) + if (simplLicAttr->acceptBy.equals(OUSTR("user")) && aContextName.equals(OUSTR("shared"))) { - css::deployment::LicenseIndividualAgreementException exc = - css::deployment::LicenseIndividualAgreementException(OUString(), 0, m_name); + css::deployment::LicenseIndividualAgreementException + exc = css::deployment::LicenseIndividualAgreementException( + OUString(), 0, m_name, simplLicAttr->suppressIfRequired); bool approve = false; bool abort = false; @@ -632,32 +620,24 @@ bool BackendImpl::PackageImpl::checkDependencies( OUSTR("Could not interact with user."), 0, Any()); if (abort == true) return false; - //We should always prevent installation - OSL_ASSERT(0); - } - //determine optional attribute simple-license@suppressOnUpdate - css::uno::Reference<css::xml::dom::XElement> elemSimpleLic(nodeSimpleLic, css::uno::UNO_QUERY_THROW); - sal_Bool bSuppress = sal_False; - if (elemSimpleLic->hasAttribute(OUSTR("suppress-on-update"))) - { - if (elemSimpleLic->getAttribute(OUSTR("suppress-on-update")).equals(OUSTR("true"))) - bSuppress = sal_True; + //If the unopkg --suppress-license was used and simplLicAttr->suppressIfRequired == true, + //then the user implicitely accepts the license } //Only use interaction if there is no version of this extension already installed //and the suppress-on-update flag is not set for the new extension - // bInstalled | bSuppress | show license + // bInstalled | bSuppressOnUpdate | show license //---------------------------------------- - // 0 | 0 | 1 - // 0 | 1 | 1 - // 1 | 0 | 1 - // 1 | 1 | 0 + // 0 | 0 | 1 + // 0 | 1 | 1 + // 1 | 0 | 1 + // 1 | 1 | 0 - if ( !(bInstalled && bSuppress)) + if ( !(bInstalled && simplLicAttr->suppressOnUpdate)) { - css::deployment::LicenseException licExc = - css::deployment::LicenseException(OUString(), 0, m_name, sLicense); + css::deployment::LicenseException licExc( + OUString(), 0, m_name, sLicense, simplLicAttr->suppressIfRequired); bool approve = false; bool abort = false; if (! interactContinuation( diff --git a/desktop/source/migration/migration.cxx b/desktop/source/migration/migration.cxx index 250fe58841f8..2181daab7454 100644 --- a/desktop/source/migration/migration.cxx +++ b/desktop/source/migration/migration.cxx @@ -34,6 +34,7 @@ #include <unotools/textsearch.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <unotools/bootstrap.hxx> #include <rtl/bootstrap.hxx> #include <tools/config.hxx> @@ -91,7 +92,6 @@ static void releaseImpl() } } - // static main entry point for the migration process void Migration::doMigration() { @@ -140,11 +140,11 @@ sal_Bool MigrationImpl::checkMigration() MigrationImpl::MigrationImpl(const uno::Reference< XMultiServiceFactory >& xFactory) : m_vrVersions(new strings_v) , m_xFactory(xFactory) - , m_vrMigrations(readMigrationSteps()) - , m_aInfo(findInstallation()) - , m_vrFileList(compileFileList()) - , m_vrServiceList(compileServiceList()) { + readAvailableMigrations(m_vMigrationsAvailable); + sal_Int32 nIndex = findPreferedMigrationProcess(m_vMigrationsAvailable); + if ( nIndex >= 0 ) + m_vrMigrations = readMigrationSteps(m_vMigrationsAvailable[nIndex].name); } MigrationImpl::~MigrationImpl() @@ -154,6 +154,10 @@ MigrationImpl::~MigrationImpl() sal_Bool MigrationImpl::doMigration() { + // compile file and service list for migration + m_vrFileList = compileFileList(); + m_vrServiceList = compileServiceList(); + sal_Bool result = sal_False; try{ copyFiles(); @@ -218,20 +222,61 @@ sal_Bool MigrationImpl::checkMigrationCompleted() return bMigrationCompleted; } - -migrations_vr MigrationImpl::readMigrationSteps() +static void insertSorted(migrations_available& rAvailableMigrations, supported_migration& aSupportedMigration) { + bool bInserted( false ); + migrations_available::iterator pIter = rAvailableMigrations.begin(); + while ( !bInserted && pIter != rAvailableMigrations.end()) + { + if ( pIter->nPriority < aSupportedMigration.nPriority ) + { + rAvailableMigrations.insert(pIter, aSupportedMigration ); + bInserted = true; + } + ++pIter; + } + if ( !bInserted ) + rAvailableMigrations.push_back( aSupportedMigration ); +} +bool MigrationImpl::readAvailableMigrations(migrations_available& rAvailableMigrations) +{ // get supported version names - uno::Reference< XNameAccess > aMigrationAccess(getConfigAccess("org.openoffice.Setup/Migration"), uno::UNO_QUERY_THROW); - uno::Sequence< OUString > seqVersions; - aMigrationAccess->getByName(OUString::createFromAscii("SupportedVersions")) >>= seqVersions; - for (sal_Int32 i=0; i<seqVersions.getLength(); i++) - m_vrVersions->push_back(seqVersions[i].trim()); + uno::Reference< XNameAccess > aMigrationAccess(getConfigAccess("org.openoffice.Setup/Migration/SupportedVersions"), uno::UNO_QUERY_THROW); + uno::Sequence< OUString > seqSupportedVersions = aMigrationAccess->getElementNames(); + + const OUString aVersionIdentifiers( RTL_CONSTASCII_USTRINGPARAM( "VersionIdentifiers" )); + const OUString aPriorityIdentifier( RTL_CONSTASCII_USTRINGPARAM( "Priority" )); + + for (sal_Int32 i=0; i<seqSupportedVersions.getLength(); i++) + { + sal_Int32 nPriority( 0 ); + uno::Sequence< OUString > seqVersions; + uno::Reference< XNameAccess > xMigrationData( aMigrationAccess->getByName(seqSupportedVersions[i]), uno::UNO_QUERY_THROW ); + xMigrationData->getByName( aVersionIdentifiers ) >>= seqVersions; + xMigrationData->getByName( aPriorityIdentifier ) >>= nPriority; + + supported_migration aSupportedMigration; + aSupportedMigration.name = seqSupportedVersions[i]; + aSupportedMigration.nPriority = nPriority; + for (sal_Int32 j=0; j<seqVersions.getLength(); j++) + aSupportedMigration.supported_versions.push_back(seqVersions[j].trim()); + insertSorted( rAvailableMigrations, aSupportedMigration ); + } + + return true; +} + +migrations_vr MigrationImpl::readMigrationSteps(const ::rtl::OUString& rMigrationName) +{ + // get migration access + uno::Reference< XNameAccess > aMigrationAccess(getConfigAccess("org.openoffice.Setup/Migration/SupportedVersions"), uno::UNO_QUERY_THROW); + uno::Reference< XNameAccess > xMigrationData( aMigrationAccess->getByName(rMigrationName), uno::UNO_QUERY_THROW ); // get migration description from from org.openoffice.Setup/Migration // and build vector of migration steps - uno::Reference< XNameAccess > theNameAccess(getConfigAccess("org.openoffice.Setup/Migration/MigrationSteps"), uno::UNO_QUERY_THROW); + OUString aMigrationSteps( RTL_CONSTASCII_USTRINGPARAM( "MigrationSteps" )); + uno::Reference< XNameAccess > theNameAccess(xMigrationData->getByName(aMigrationSteps), uno::UNO_QUERY_THROW); uno::Sequence< OUString > seqMigrations = theNameAccess->getElementNames(); uno::Reference< XNameAccess > tmpAccess; uno::Reference< XNameAccess > tmpAccess2; @@ -273,6 +318,20 @@ migrations_vr MigrationImpl::readMigrationSteps() tmpStep.excludeConfig.push_back(tmpSeq[j]); } + // included extensions... + if (tmpAccess->getByName(OUString::createFromAscii("IncludedExtensions")) >>= tmpSeq) + { + for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) + tmpStep.includeExtensions.push_back(tmpSeq[j]); + } + + // excluded extensions... + if (tmpAccess->getByName(OUString::createFromAscii("ExcludedExtensions")) >>= tmpSeq) + { + for (sal_Int32 j=0; j<tmpSeq.getLength(); j++) + tmpStep.excludeExtensions.push_back(tmpSeq[j]); + } + // config components if (tmpAccess->getByName(OUString::createFromAscii("ServiceConfigComponents")) >>= tmpSeq) { @@ -280,7 +339,6 @@ migrations_vr MigrationImpl::readMigrationSteps() tmpStep.configComponents.push_back(tmpSeq[j]); } - // generic service tmpAccess->getByName(OUString::createFromAscii("MigrationService")) >>= tmpStep.service; @@ -302,7 +360,7 @@ static FileBase::RC _checkAndCreateDirectory(INetURLObject& dirURL) return result; } -install_info MigrationImpl::findInstallation() +install_info MigrationImpl::findInstallation(const strings_v& rVersions) { rtl::OUString aProductName; uno::Any aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME ); @@ -310,9 +368,9 @@ install_info MigrationImpl::findInstallation() aProductName = aProductName.toAsciiLowerCase(); install_info aInfo; - strings_v::const_iterator i_ver = m_vrVersions->begin(); + strings_v::const_iterator i_ver = rVersions.begin(); uno::Reference < util::XStringSubstitution > xSubst( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.PathSubstitution")), uno::UNO_QUERY ); - while (i_ver != m_vrVersions->end()) + while (i_ver != rVersions.end()) { ::rtl::OUString aVersion, aProfileName; sal_Int32 nSeparatorIndex = (*i_ver).indexOf('='); @@ -330,7 +388,7 @@ install_info MigrationImpl::findInstallation() osl::Security().getConfigDir( aUserInst ); if ( aUserInst.getLength() && aUserInst[ aUserInst.getLength()-1 ] != '/' ) aUserInst += ::rtl::OUString::createFromAscii("/"); -#ifdef UNX +#if defined UNX && ! defined MACOSX // tribute to whoever had the "great" idea to use different names on Windows and Unix aUserInst += ::rtl::OUString::createFromAscii("."); #endif @@ -345,12 +403,34 @@ install_info MigrationImpl::findInstallation() } catch( uno::Exception& ){} } - i_ver++; + ++i_ver; } return aInfo; } +sal_Int32 MigrationImpl::findPreferedMigrationProcess(const migrations_available& rAvailableMigrations) +{ + sal_Int32 nIndex( -1 ); + sal_Int32 i( 0 ); + + migrations_available::const_iterator rIter = rAvailableMigrations.begin(); + while ( rIter != rAvailableMigrations.end() ) + { + install_info aInstallInfo = findInstallation(rIter->supported_versions); + if (aInstallInfo.productname.getLength() > 0 ) + { + m_aInfo = aInstallInfo; + nIndex = i; + break; + } + ++i; + ++rIter; + } + + return nIndex; +} + strings_vr MigrationImpl::applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const { using namespace utl; @@ -517,8 +597,6 @@ void MigrationImpl::copyConfig() aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); OSL_ENSURE(sal_False, aMsg.getStr()); } - - } // removes elements of vector 2 in vector 1 @@ -626,7 +704,6 @@ void MigrationImpl::copyFiles() void MigrationImpl::runServices() { - //create stratum for old user layer OUString aOldLayerURL = m_aInfo.userdata; aOldLayerURL += OUString::createFromAscii("/user/registry"); @@ -637,7 +714,7 @@ void MigrationImpl::runServices() aStratumSvc, stratumArgs), uno::UNO_QUERY); // Build argument array - uno::Sequence< uno::Any > seqArguments(3); + uno::Sequence< uno::Any > seqArguments(4); seqArguments[0] = uno::makeAny(NamedValue( OUString::createFromAscii("Productname"), uno::makeAny(m_aInfo.productname))); @@ -673,11 +750,22 @@ void MigrationImpl::runServices() i_comp++; i++; } + // set old config argument seqArguments[2] = uno::makeAny(NamedValue( OUString::createFromAscii("OldConfiguration"), uno::makeAny(seqComponents))); + // set black list for extension migration + uno::Sequence< rtl::OUString > seqExtBlackList; + sal_uInt32 nSize = i_mig->excludeExtensions.size(); + if ( nSize > 0 ) + seqExtBlackList = comphelper::arrayToSequence< ::rtl::OUString >( + &i_mig->excludeExtensions[0], nSize ); + seqArguments[3] = uno::makeAny(NamedValue( + OUString::createFromAscii("ExtensionBlackList"), + uno::makeAny( seqExtBlackList ))); + xMigrationJob = uno::Reference< XJob >(m_xFactory->createInstanceWithArguments( i_mig->service, seqArguments), uno::UNO_QUERY_THROW); diff --git a/desktop/source/migration/migration_impl.hxx b/desktop/source/migration/migration_impl.hxx index 95b0c3535a80..b40de510261d 100644 --- a/desktop/source/migration/migration_impl.hxx +++ b/desktop/source/migration/migration_impl.hxx @@ -65,11 +65,21 @@ struct migration_step strings_v includeConfig; strings_v excludeConfig; strings_v configComponents; + strings_v includeExtensions; + strings_v excludeExtensions; rtl::OUString service; }; +struct supported_migration +{ + rtl::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; class MigrationImpl { @@ -77,18 +87,22 @@ class MigrationImpl private: strings_vr m_vrVersions; NS_UNO::Reference< NS_CSS::lang::XMultiServiceFactory > m_xFactory; - 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 - strings_vr m_vrConfigList; // final list of nodes to be copied - strings_vr m_vrServiceList; // final list of services to be called - - // initializer functions... - migrations_vr readMigrationSteps(); - install_info findInstallation(); - strings_vr compileFileList(); - strings_vr compileConfigList(); - strings_vr compileServiceList(); + + 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 + strings_vr m_vrConfigList; // final list of nodes to be copied + strings_vr m_vrServiceList; // final list of services to be called + + // functions to control the migration process + bool readAvailableMigrations(migrations_available&); + migrations_vr readMigrationSteps(const ::rtl::OUString& rMigrationName); + sal_Int32 findPreferedMigrationProcess(const migrations_available&); + install_info findInstallation(const strings_v& rVersions); + strings_vr compileFileList(); + strings_vr compileConfigList(); + strings_vr compileServiceList(); // helpers void substract(strings_v& va, const strings_v& vb_c) const; diff --git a/desktop/source/migration/pages.cxx b/desktop/source/migration/pages.cxx index 0aadc92827bb..11cc61ed84ff 100644 --- a/desktop/source/migration/pages.cxx +++ b/desktop/source/migration/pages.cxx @@ -55,6 +55,7 @@ #include <rtl/bootstrap.hxx> #include <rtl/ustrbuf.hxx> #include <osl/file.hxx> +#include <osl/thread.hxx> #include <unotools/bootstrap.hxx> #include <tools/config.hxx> @@ -62,6 +63,7 @@ using namespace rtl; using namespace osl; using namespace utl; using namespace svt; +using namespace com::sun::star; using namespace com::sun::star::frame; using namespace com::sun::star::lang; using namespace com::sun::star::util; @@ -305,12 +307,46 @@ void LicenseView::Notify( SfxBroadcaster&, const SfxHint& rHint ) // ------------------------------------------------------------------- -MigrationPage::MigrationPage( svt::OWizardMachine* parent, const ResId& resid) +class MigrationThread : public ::osl::Thread +{ + public: + MigrationThread(); + + virtual void SAL_CALL run(); + virtual void SAL_CALL onTerminated(); +}; + +MigrationThread::MigrationThread() +{ +} + +void MigrationThread::run() +{ + try + { + Migration::doMigration(); + } + catch ( uno::Exception& ) + { + } +} + +void MigrationThread::onTerminated() +{ +} + +// ------------------------------------------------------------------- + +MigrationPage::MigrationPage( + svt::OWizardMachine* parent, + const ResId& resid, + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XThrobber > xThrobber) : OWizardPage(parent, resid) , m_ftHead(this, WizardResId(FT_MIGRATION_HEADER)) , m_ftBody(this, WizardResId(FT_MIGRATION_BODY)) , m_cbMigration(this, WizardResId(CB_MIGRATION)) , m_bMigrationDone(sal_False) + , m_xThrobber(xThrobber) { FreeResource(); _setBold(m_ftHead); @@ -325,9 +361,28 @@ sal_Bool MigrationPage::commitPage( CommitPageReason _eReason ) { if (_eReason == eTravelForward && m_cbMigration.IsChecked() && !m_bMigrationDone) { - EnterWait(); - Migration::doMigration(); - LeaveWait(); + GetParent()->EnterWait(); + FirstStartWizard* pWizard = dynamic_cast< FirstStartWizard* >( GetParent() ); + if ( pWizard ) + pWizard->DisableButtonsWhileMigration(); + + uno::Reference< awt::XWindow > xWin( m_xThrobber, uno::UNO_QUERY ); + xWin->setVisible( true ); + m_xThrobber->start(); + MigrationThread* pMigThread = new MigrationThread(); + pMigThread->create(); + + while ( pMigThread->isRunning() ) + { + Application::Reschedule(); + } + + m_xThrobber->stop(); + GetParent()->LeaveWait(); + // Next state will enable buttons - so no EnableButtons necessary! + xWin->setVisible( false ); + pMigThread->join(); + delete pMigThread; m_bMigrationDone = sal_True; } else diff --git a/desktop/source/migration/pages.hxx b/desktop/source/migration/pages.hxx index c1e8b2c62e42..9740773fe602 100644 --- a/desktop/source/migration/pages.hxx +++ b/desktop/source/migration/pages.hxx @@ -38,6 +38,8 @@ #include <svl/lstner.hxx> #include <svtools/xtextedt.hxx> +#include <com/sun/star/awt/XThrobber.hpp> + namespace desktop { class WelcomePage : public svt::OWizardPage @@ -120,8 +122,9 @@ private: FixedText m_ftBody; CheckBox m_cbMigration; sal_Bool m_bMigrationDone; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XThrobber > m_xThrobber; public: - MigrationPage( svt::OWizardMachine* parent, const ResId& resid); + MigrationPage( svt::OWizardMachine* parent, const ResId& resid, ::com::sun::star::uno::Reference< ::com::sun::star::awt::XThrobber > xThrobber ); virtual sal_Bool commitPage( CommitPageReason _eReason ); protected: diff --git a/desktop/source/migration/services/cexportsoo3.cxx b/desktop/source/migration/services/cexportsoo3.cxx new file mode 100755 index 000000000000..20b8232044e9 --- /dev/null +++ b/desktop/source/migration/services/cexportsoo3.cxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cexports.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "cppuhelper/implementationentry.hxx" +#include "oo3extensionmigration.hxx" + +extern "C" +{ + +::cppu::ImplementationEntry entries [] = +{ + { + migration::OO3ExtensionMigration_create, migration::OO3ExtensionMigration_getImplementationName, + migration::OO3ExtensionMigration_getSupportedServiceNames, ::cppu::createSingleComponentFactory, + 0, 0 + }, + { 0, 0, 0, 0, 0, 0 } +}; + + +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + return ::cppu::component_writeInfoHelper( + pServiceManager, pRegistryKey, entries ); +} + +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + return ::cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, entries ); +} + +} diff --git a/desktop/source/migration/services/makefile.mk b/desktop/source/migration/services/makefile.mk index 514132037368..55ecff6bc06f 100644 --- a/desktop/source/migration/services/makefile.mk +++ b/desktop/source/migration/services/makefile.mk @@ -31,6 +31,7 @@ PRJNAME=desktop TARGET = migrationoo2.uno ENABLE_EXCEPTIONS=TRUE COMP1TYPELIST = migrationoo2 +LIBTARGET=NO # --- Settings ----------------------------------------------------- .INCLUDE : ..$/..$/deployment/inc/dp_misc.mk @@ -50,7 +51,18 @@ SLOFILES= \ $(SLO)$/cexports.obj \ $(SLO)$/basicmigration.obj \ $(SLO)$/wordbookmigration.obj \ - $(SLO)$/extensionmigration.obj + $(SLO)$/extensionmigration.obj \ + $(SLO)$/autocorrmigration.obj \ + $(SLO)$/oo3extensionmigration.obj \ + $(SLO)$/cexportsoo3.obj + +SHL1OBJS= \ + $(SLO)$/jvmfwk.obj \ + $(SLO)$/cexports.obj \ + $(SLO)$/basicmigration.obj \ + $(SLO)$/wordbookmigration.obj \ + $(SLO)$/extensionmigration.obj \ + $(SLO)$/autocorrmigration.obj SHL1TARGET=$(TARGET) SHL1VERSIONMAP = $(SOLARENV)/src/component.map @@ -67,16 +79,42 @@ SHL1STDLIBS= \ $(JVMFWKLIB) \ $(XMLSCRIPTLIB) \ $(BERKELEYLIB) - - SHL1DEPN= -SHL1IMPLIB=i$(TARGET) -SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1IMPLIB=imigrationoo2 +#SHL1LIBS=$(SLB)$/$(TARGET).lib SHL1DEF=$(MISC)$/$(SHL1TARGET).def DEF1NAME=$(SHL1TARGET) +COMP2TYPELIST = migrationoo3 +SHL2TARGET=migrationoo3.uno +SHL2VERSIONMAP = migrationoo3.map + +SHL2OBJS= \ + $(SLO)$/cexportsoo3.obj \ + $(SLO)$/oo3extensionmigration.obj + +SHL2STDLIBS= \ + $(DEPLOYMENTMISCLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) \ + $(UCBHELPERLIB) \ + $(UNOTOOLSLIB) \ + $(TOOLSLIB) \ + $(I18NISOLANGLIB) \ + $(JVMFWKLIB) \ + $(XMLSCRIPTLIB) \ + $(BERKELEYLIB) + +SHL2DEPN= +SHL2IMPLIB=imigrationoo3 +#SHL2LIBS=$(SLB)$/$(SHL2TARGET).lib +SHL2DEF=$(MISC)$/$(SHL2TARGET).def + +DEF2NAME=$(SHL2TARGET) + # --- Targets ------------------------------------------------------ .INCLUDE : target.mk diff --git a/desktop/source/migration/services/migrationoo3.map b/desktop/source/migration/services/migrationoo3.map new file mode 100755 index 000000000000..ac2c3750bfe0 --- /dev/null +++ b/desktop/source/migration/services/migrationoo3.map @@ -0,0 +1,8 @@ +UDK_3_0_0 { + global: + component_getImplementationEnvironment; + component_writeInfo; + component_getFactory; + local: + *; +}; diff --git a/desktop/source/migration/services/oo3extensionmigration.cxx b/desktop/source/migration/services/oo3extensionmigration.cxx new file mode 100755 index 000000000000..11bf8129cc04 --- /dev/null +++ b/desktop/source/migration/services/oo3extensionmigration.cxx @@ -0,0 +1,656 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: extensionmigration.cxx,v $ + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_desktop.hxx" + +#include "oo3extensionmigration.hxx" +#include <rtl/instance.hxx> +#include <osl/file.hxx> +#include <osl/thread.h> +#include <tools/urlobj.hxx> +#include <unotools/bootstrap.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <unotools/textsearch.hxx> +#include <comphelper/sequence.hxx> +#include <comphelper/processfactory.hxx> +#include <ucbhelper/content.hxx> + +#include <com/sun/star/deployment/thePackageManagerFactory.hpp> +#include <com/sun/star/deployment/XPackageManagerFactory.hpp> +#include <com/sun/star/task/XInteractionApprove.hpp> +#include <com/sun/star/task/XInteractionAbort.hpp> +#include <com/sun/star/ucb/XCommandInfo.hpp> +#include <com/sun/star/ucb/TransferInfo.hpp> +#include <com/sun/star/ucb/NameClash.hpp> +#include <com/sun/star/ucb/XCommandEnvironment.hpp> +#include <com/sun/star/xml/xpath/XXPathAPI.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace migration +{ + +static ::rtl::OUString sExtensionSubDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/uno_packages/" ) ); +static ::rtl::OUString sSubDirName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cache" ) ); +static ::rtl::OUString sConfigDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data" ) ); +static ::rtl::OUString sOrgDir = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) ); +static ::rtl::OUString sExcludeDir1 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org" ) ); +static ::rtl::OUString sExcludeDir2 = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/registry/data/org/openoffice" ) ); +static ::rtl::OUString sDescriptionXmlFile = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/description.xml" ) ); +static ::rtl::OUString sExtensionRootSubDirName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/uno_packages" ) ); + +static ::rtl::OUString sConfigurationDataType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-data")); +static ::rtl::OUString sConfigurationSchemaType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.configuration-schema")); + +// ============================================================================= +// component operations +// ============================================================================= + +::rtl::OUString OO3ExtensionMigration_getImplementationName() +{ + static ::rtl::OUString* pImplName = 0; + if ( !pImplName ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pImplName ) + { + static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.OOo3Extensions" ) ); + pImplName = &aImplName; + } + } + return *pImplName; +} + +// ----------------------------------------------------------------------------- + +Sequence< ::rtl::OUString > OO3ExtensionMigration_getSupportedServiceNames() +{ + static Sequence< ::rtl::OUString >* pNames = 0; + if ( !pNames ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pNames ) + { + static Sequence< ::rtl::OUString > aNames(1); + aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Extensions" ) ); + pNames = &aNames; + } + } + return *pNames; +} + +// ============================================================================= +// ExtensionMigration +// ============================================================================= + +OO3ExtensionMigration::OO3ExtensionMigration(Reference< XComponentContext > const & ctx) : +m_ctx(ctx) +{ +} + +// ----------------------------------------------------------------------------- + +OO3ExtensionMigration::~OO3ExtensionMigration() +{ +} + +::osl::FileBase::RC OO3ExtensionMigration::checkAndCreateDirectory( INetURLObject& rDirURL ) +{ + ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + if ( aResult == ::osl::FileBase::E_NOENT ) + { + INetURLObject aBaseURL( rDirURL ); + aBaseURL.removeSegment(); + checkAndCreateDirectory( aBaseURL ); + return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + } + else + { + return aResult; + } +} + +void OO3ExtensionMigration::registerConfigurationPackage( const uno::Reference< deployment::XPackage > & xPkg) +{ + const ::rtl::OUString sMediaType = xPkg->getPackageType()->getMediaType(); + if ( (sMediaType.equals(sConfigurationDataType) || sMediaType.equals(sConfigurationSchemaType) ) ) + { + xPkg->revokePackage(uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + xPkg->registerPackage(uno::Reference< task::XAbortChannel >(), uno::Reference< ucb::XCommandEnvironment> ()); + } +} + + void OO3ExtensionMigration::scanUserExtensions( const ::rtl::OUString& sSourceDir, TStringVector& aMigrateExtensions ) +{ + osl::Directory aScanRootDir( sSourceDir ); + osl::FileStatus fs(FileStatusMask_Type | FileStatusMask_FileURL); + osl::FileBase::RC nRetCode = aScanRootDir.open(); + if ( nRetCode == osl::Directory::E_None ) + { + sal_uInt32 nHint( 0 ); + osl::DirectoryItem aItem; + while ( aScanRootDir.getNextItem( aItem, nHint ) == osl::Directory::E_None ) + { + if (( aItem.getFileStatus(fs) == osl::FileBase::E_None ) && + ( fs.getFileType() == osl::FileStatus::Directory )) + { + //Check next folder as the "real" extension folder is below a temp folder! + ::rtl::OUString sExtensionFolderURL = fs.getFileURL(); + + osl::DirectoryItem aExtDirItem; + osl::Directory aExtensionRootDir( sExtensionFolderURL ); + + nRetCode = aExtensionRootDir.open(); + if (( nRetCode == osl::Directory::E_None ) && + ( aExtensionRootDir.getNextItem( aExtDirItem, nHint ) == osl::Directory::E_None )) + { + bool bFileStatus = aExtDirItem.getFileStatus(fs) == osl::FileBase::E_None; + bool bIsDir = fs.getFileType() == osl::FileStatus::Directory; + + if ( bFileStatus && bIsDir ) + { + sExtensionFolderURL = fs.getFileURL(); + ScanResult eResult = scanExtensionFolder( sExtensionFolderURL ); + if ( eResult == SCANRESULT_MIGRATE_EXTENSION ) + aMigrateExtensions.push_back( sExtensionFolderURL ); + } + } + } + } + } +} + +OO3ExtensionMigration::ScanResult OO3ExtensionMigration::scanExtensionFolder( const ::rtl::OUString& sExtFolder ) +{ + ScanResult aResult = SCANRESULT_NOTFOUND; + osl::Directory aDir(sExtFolder); + + // get sub dirs + if (aDir.open() == osl::FileBase::E_None) + { + // work through directory contents... + osl::DirectoryItem item; + osl::FileStatus fs(FileStatusMask_Type | FileStatusMask_FileURL); + TStringVector aDirectories; + while ((aDir.getNextItem(item) == osl::FileBase::E_None ) && + ( aResult == SCANRESULT_NOTFOUND )) + { + if (item.getFileStatus(fs) == osl::FileBase::E_None) + { + ::rtl::OUString aDirEntryURL; + if (fs.getFileType() == osl::FileStatus::Directory) + aDirectories.push_back( fs.getFileURL() ); + else + { + aDirEntryURL = fs.getFileURL(); + if ( aDirEntryURL.indexOf( sDescriptionXmlFile ) > 0 ) + aResult = scanDescriptionXml( aDirEntryURL ) ? SCANRESULT_MIGRATE_EXTENSION : SCANRESULT_DONTMIGRATE_EXTENSION; + } + } + } + + TStringVector::const_iterator pIter = aDirectories.begin(); + while ( pIter != aDirectories.end() && aResult == SCANRESULT_NOTFOUND ) + { + aResult = scanExtensionFolder( *pIter ); + ++pIter; + } + } + return aResult; +} + +bool OO3ExtensionMigration::scanDescriptionXml( const ::rtl::OUString& sDescriptionXmlURL ) +{ + if ( !m_xDocBuilder.is() ) + { + m_xDocBuilder = uno::Reference< xml::dom::XDocumentBuilder >( + m_ctx->getServiceManager()->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.dom.DocumentBuilder")), + m_ctx ), uno::UNO_QUERY ); + } + + if ( !m_xSimpleFileAccess.is() ) + { + m_xSimpleFileAccess = uno::Reference< ucb::XSimpleFileAccess >( + m_ctx->getServiceManager()->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")), + m_ctx ), uno::UNO_QUERY ); + } + + ::rtl::OUString aExtIdentifier; + if ( m_xDocBuilder.is() && m_xSimpleFileAccess.is() ) + { + try + { + uno::Reference< io::XInputStream > xIn = + m_xSimpleFileAccess->openFileRead( sDescriptionXmlURL ); + + if ( xIn.is() ) + { + uno::Reference< xml::dom::XDocument > xDoc = m_xDocBuilder->parse( xIn ); + if ( xDoc.is() ) + { + uno::Reference< xml::dom::XElement > xRoot = xDoc->getDocumentElement(); + if ( xRoot.is() && + xRoot->getTagName().equals(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("description"))) ) + { + uno::Reference< xml::xpath::XXPathAPI > xPath( + m_ctx->getServiceManager()->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.xpath.XPathAPI")), + m_ctx), + uno::UNO_QUERY); + + xPath->registerNS( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("desc")), + xRoot->getNamespaceURI()); + xPath->registerNS( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xlink")), + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http://www.w3.org/1999/xlink"))); + + try + { + uno::Reference< xml::dom::XNode > xRootNode( xRoot, uno::UNO_QUERY ); + uno::Reference< xml::dom::XNode > xNode( + xPath->selectSingleNode( + xRootNode, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("desc:identifier/@value")) )); + if ( xNode.is() ) + aExtIdentifier = xNode->getNodeValue(); + } + catch ( xml::xpath::XPathException& ) + { + } + catch ( xml::dom::DOMException& ) + { + } + } + } + } + + if ( aExtIdentifier.getLength() > 0 ) + { + // scan extension identifier and try to match with our black list entries + for ( sal_uInt32 i = 0; i < m_aBlackList.size(); i++ ) + { + utl::SearchParam param(m_aBlackList[i], utl::SearchParam::SRCH_REGEXP); + utl::TextSearch ts(param, LANGUAGE_DONTKNOW); + + xub_StrLen start = 0; + xub_StrLen end = static_cast<USHORT>(aExtIdentifier.getLength()); + if (ts.SearchFrwrd(aExtIdentifier, &start, &end)) + return false; + } + } + } + catch ( ucb::CommandAbortedException& ) + { + } + catch ( uno::RuntimeException& ) + { + } + + if ( aExtIdentifier.getLength() == 0 ) + { + // Fallback: + // Try to use the folder name to match our black list + // as some extensions don't provide an identifier in the + // description.xml! + for ( sal_uInt32 i = 0; i < m_aBlackList.size(); i++ ) + { + utl::SearchParam param(m_aBlackList[i], utl::SearchParam::SRCH_REGEXP); + utl::TextSearch ts(param, LANGUAGE_DONTKNOW); + + xub_StrLen start = 0; + xub_StrLen end = static_cast<USHORT>(sDescriptionXmlURL.getLength()); + if (ts.SearchFrwrd(sDescriptionXmlURL, &start, &end)) + return false; + } + } + } + + return true; +} + +bool OO3ExtensionMigration::migrateExtension( const ::rtl::OUString& sSourceDir ) +{ + if ( !m_xPackageManager.is() ) + { + try + { + m_xPackageManager = deployment::thePackageManagerFactory::get( m_ctx )->getPackageManager( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "user" )) ); + } + catch ( ucb::CommandFailedException & ){} + catch ( uno::RuntimeException & ) {} + } + + if ( m_xPackageManager.is() ) + { + try + { + TmpRepositoryCommandEnv* pCmdEnv = new TmpRepositoryCommandEnv(); + + uno::Reference< ucb::XCommandEnvironment > xCmdEnv( + static_cast< cppu::OWeakObject* >( pCmdEnv ), uno::UNO_QUERY ); + uno::Reference< task::XAbortChannel > xAbortChannel; + uno::Reference< deployment::XPackage > xPackage = + m_xPackageManager->addPackage( sSourceDir, ::rtl::OUString(), xAbortChannel, xCmdEnv ); + + if ( xPackage.is() ) + return true; + } + catch ( ucb::CommandFailedException& ) + { + } + catch ( ucb::CommandAbortedException& ) + { + } + catch ( lang::IllegalArgumentException& ) + { + } + } + + return false; +} + +bool OO3ExtensionMigration::copy( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ) +{ + bool bRet = false; + + INetURLObject aSourceObj( sSourceDir ); + INetURLObject aDestObj( sTargetDir ); + String aName = aDestObj.getName(); + aDestObj.removeSegment(); + aDestObj.setFinalSlash(); + + try + { + ::ucbhelper::Content aDestPath( aDestObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () ); + uno::Reference< ucb::XCommandInfo > xInfo = aDestPath.getCommands(); + ::rtl::OUString aTransferName = ::rtl::OUString::createFromAscii( "transfer" ); + if ( xInfo->hasCommandByName( aTransferName ) ) + { + aDestPath.executeCommand( aTransferName, uno::makeAny( + ucb::TransferInfo( sal_False, aSourceObj.GetMainURL( INetURLObject::NO_DECODE ), aName, ucb::NameClash::OVERWRITE ) ) ); + bRet = true; + } + } + catch( uno::Exception& ) + { + } + + return bRet; +} + + +// ----------------------------------------------------------------------------- +// XServiceInfo +// ----------------------------------------------------------------------------- + +::rtl::OUString OO3ExtensionMigration::getImplementationName() throw (RuntimeException) +{ + return OO3ExtensionMigration_getImplementationName(); +} + +// ----------------------------------------------------------------------------- + +sal_Bool OO3ExtensionMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) +{ + Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); + const ::rtl::OUString* pNames = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pNames + aNames.getLength(); + for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) + ; + + return pNames != pEnd; +} + +// ----------------------------------------------------------------------------- + +Sequence< ::rtl::OUString > OO3ExtensionMigration::getSupportedServiceNames() throw (RuntimeException) +{ + return OO3ExtensionMigration_getSupportedServiceNames(); +} + +// ----------------------------------------------------------------------------- +// XInitialization +// ----------------------------------------------------------------------------- + +void OO3ExtensionMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + const Any* pIter = aArguments.getConstArray(); + const Any* pEnd = pIter + aArguments.getLength(); + for ( ; pIter != pEnd ; ++pIter ) + { + beans::NamedValue aValue; + *pIter >>= aValue; + if ( aValue.Name.equalsAscii( "UserData" ) ) + { + if ( !(aValue.Value >>= m_sSourceDir) ) + { + OSL_ENSURE( false, "ExtensionMigration::initialize: argument UserData has wrong type!" ); + } + } + else if ( aValue.Name.equalsAscii( "ExtensionBlackList" ) ) + { + Sequence< ::rtl::OUString > aBlackList; + if ( (aValue.Value >>= aBlackList ) && ( aBlackList.getLength() > 0 )) + { + m_aBlackList.resize( aBlackList.getLength() ); + ::comphelper::sequenceToArray< ::rtl::OUString >( &m_aBlackList[0], aBlackList ); + } + } + } +} + +// ----------------------------------------------------------------------------- + +TStringVectorPtr getContent( const ::rtl::OUString& rBaseURL ) +{ + TStringVectorPtr aResult( new TStringVector ); + ::osl::Directory aDir( rBaseURL); + if ( aDir.open() == ::osl::FileBase::E_None ) + { + // iterate over directory content + TStringVector aSubDirs; + ::osl::DirectoryItem aItem; + while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileURL ); + if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ) + aResult->push_back( aFileStatus.getFileURL() ); + } + } + + return aResult; +} + +// ----------------------------------------------------------------------------- +// XJob +// ----------------------------------------------------------------------------- + +void OO3ExtensionMigration::copyConfig( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ) +{ + ::rtl::OUString sEx1( m_sSourceDir ); + sEx1 += sExcludeDir1; + ::rtl::OUString sEx2( m_sSourceDir ); + sEx2 += sExcludeDir2; + + TStringVectorPtr aList = getContent( sSourceDir ); + TStringVector::const_iterator aI = aList->begin(); + while ( aI != aList->end() ) + { + ::rtl::OUString sSourceLocalName = aI->copy( sSourceDir.getLength() ); + ::rtl::OUString aTemp = aI->copy( m_sSourceDir.getLength() ); + if ( aTemp != sExcludeDir1 && aTemp != sExcludeDir2 ) + { + ::rtl::OUString sTargetName = sTargetDir + sSourceLocalName; + copy( (*aI), sTargetName ); + } + ++aI; + } +} + +Any OO3ExtensionMigration::execute( const Sequence< beans::NamedValue >& ) + throw (lang::IllegalArgumentException, Exception, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( m_sTargetDir ); + if ( aStatus == ::utl::Bootstrap::PATH_EXISTS ) + { + // copy all extensions + ::rtl::OUString sSourceDir( m_sSourceDir ); + sSourceDir += sExtensionSubDir; + sSourceDir += sSubDirName; + sSourceDir += sExtensionRootSubDirName; + TStringVector aExtensionToMigrate; + scanUserExtensions( sSourceDir, aExtensionToMigrate ); + if ( aExtensionToMigrate.size() > 0 ) + { + TStringVector::iterator pIter = aExtensionToMigrate.begin(); + while ( pIter != aExtensionToMigrate.end() ) + { + migrateExtension( *pIter ); + ++pIter; + } + } + } + + return Any(); +} + +// ----------------------------------------------------------------------------- +// TmpRepositoryCommandEnv +// ----------------------------------------------------------------------------- + +TmpRepositoryCommandEnv::TmpRepositoryCommandEnv() +{ +} + +TmpRepositoryCommandEnv::TmpRepositoryCommandEnv( + uno::Reference< task::XInteractionHandler> const & handler) + : m_forwardHandler(handler) +{ +} + +TmpRepositoryCommandEnv::~TmpRepositoryCommandEnv() +{ +} +// XCommandEnvironment +//______________________________________________________________________________ +uno::Reference< task::XInteractionHandler > TmpRepositoryCommandEnv::getInteractionHandler() +throw ( uno::RuntimeException ) +{ + return this; +} + +//______________________________________________________________________________ +uno::Reference< ucb::XProgressHandler > TmpRepositoryCommandEnv::getProgressHandler() +throw ( uno::RuntimeException ) +{ + return this; +} + +// XInteractionHandler +void TmpRepositoryCommandEnv::handle( + uno::Reference< task::XInteractionRequest> const & xRequest ) + throw ( uno::RuntimeException ) +{ + uno::Any request( xRequest->getRequest() ); + OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); + + bool approve = true; + bool abort = false; + + // select: + uno::Sequence< Reference< task::XInteractionContinuation > > conts( + xRequest->getContinuations() ); + Reference< task::XInteractionContinuation > const * pConts = + conts.getConstArray(); + sal_Int32 len = conts.getLength(); + for ( sal_Int32 pos = 0; pos < len; ++pos ) + { + if (approve) { + uno::Reference< task::XInteractionApprove > xInteractionApprove( + pConts[ pos ], uno::UNO_QUERY ); + if (xInteractionApprove.is()) { + xInteractionApprove->select(); + // don't query again for ongoing continuations: + approve = false; + } + } + else if (abort) { + uno::Reference< task::XInteractionAbort > xInteractionAbort( + pConts[ pos ], uno::UNO_QUERY ); + if (xInteractionAbort.is()) { + xInteractionAbort->select(); + // don't query again for ongoing continuations: + abort = false; + } + } + } +} + +// XProgressHandler +void TmpRepositoryCommandEnv::push( uno::Any const & /*Status*/ ) +throw (uno::RuntimeException) +{ +} + + +void TmpRepositoryCommandEnv::update( uno::Any const & /*Status */) +throw (uno::RuntimeException) +{ +} + +void TmpRepositoryCommandEnv::pop() throw (uno::RuntimeException) +{ +} + +// ============================================================================= +// component operations +// ============================================================================= + +Reference< XInterface > SAL_CALL OO3ExtensionMigration_create( + Reference< XComponentContext > const & ctx ) + SAL_THROW( () ) +{ + return static_cast< lang::XTypeProvider * >( new OO3ExtensionMigration( + ctx) ); +} + +// ----------------------------------------------------------------------------- + +} // namespace migration diff --git a/desktop/source/migration/services/oo3extensionmigration.hxx b/desktop/source/migration/services/oo3extensionmigration.hxx new file mode 100755 index 000000000000..a001f41d92c5 --- /dev/null +++ b/desktop/source/migration/services/oo3extensionmigration.hxx @@ -0,0 +1,171 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: extensionmigration.hxx,v $ + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DESKTOP_OO3EXTENSIONMIGRATION_HXX_ +#define _DESKTOP_OO3EXTENSIONMIGRATION_HXX_ + +#include "misc.hxx" +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/xml/dom/XDocumentBuilder.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/deployment/XPackageManager.hpp> + +#include <osl/mutex.hxx> +#include <osl/file.hxx> +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/compbase3.hxx> +#include <ucbhelper/content.hxx> +#include <xmlscript/xmllib_imexp.hxx> + +namespace com { namespace sun { namespace star { + namespace uno { + class XComponentContext; + } + namespace deployment { + class XPackage; + } +}}} + +class INetURLObject; + + +namespace migration +{ + + ::rtl::OUString SAL_CALL OO3ExtensionMigration_getImplementationName(); + ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OO3ExtensionMigration_getSupportedServiceNames(); + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL OO3ExtensionMigration_create( + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext ) + SAL_THROW( (::com::sun::star::uno::Exception) ); + + + // ============================================================================= + // class ExtensionMigration + // ============================================================================= + + typedef ::cppu::WeakImplHelper3< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::task::XJob > ExtensionMigration_BASE; + + class OO3ExtensionMigration : public ExtensionMigration_BASE + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_ctx; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XDocumentBuilder > m_xDocBuilder; + ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > m_xSimpleFileAccess; + ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackageManager > m_xPackageManager; + ::osl::Mutex m_aMutex; + ::rtl::OUString m_sSourceDir; + ::rtl::OUString m_sTargetDir; + TStringVector m_aBlackList; + + enum ScanResult + { + SCANRESULT_NOTFOUND, + SCANRESULT_MIGRATE_EXTENSION, + SCANRESULT_DONTMIGRATE_EXTENSION + }; + + ::osl::FileBase::RC checkAndCreateDirectory( INetURLObject& rDirURL ); + void copyConfig( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ); + bool copy( const ::rtl::OUString& sSourceDir, const ::rtl::OUString& sTargetDir ); + ScanResult scanExtensionFolder( const ::rtl::OUString& sExtFolder ); + void scanUserExtensions( const ::rtl::OUString& sSourceDir, TStringVector& aMigrateExtensions ); + bool scanDescriptionXml( const ::rtl::OUString& sDescriptionXmlFilePath ); + bool migrateExtension( const ::rtl::OUString& sSourceDir ); + /* fills m_scriptElements and m_dialogElements + */ + void registerConfigurationPackage( + const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > & xPkg); + + public: + OO3ExtensionMigration(::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & ctx); + virtual ~OO3ExtensionMigration(); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& rServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw (::com::sun::star::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XJob + virtual ::com::sun::star::uno::Any SAL_CALL execute( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + }; + + class TmpRepositoryCommandEnv + : public ::cppu::WeakImplHelper3< ::com::sun::star::ucb::XCommandEnvironment, + ::com::sun::star::task::XInteractionHandler, + ::com::sun::star::ucb::XProgressHandler > + { + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler> m_forwardHandler; + public: + virtual ~TmpRepositoryCommandEnv(); + TmpRepositoryCommandEnv(); + TmpRepositoryCommandEnv( + ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler> const & handler); + + // XCommandEnvironment + virtual ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > SAL_CALL + getInteractionHandler() throw ( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XProgressHandler > + SAL_CALL getProgressHandler() throw ( ::com::sun::star::uno::RuntimeException ); + + // XInteractionHandler + virtual void SAL_CALL handle( + ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest > const & xRequest ) + throw (::com::sun::star::uno::RuntimeException); + + // XProgressHandler + virtual void SAL_CALL push( ::com::sun::star::uno::Any const & Status ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL update( ::com::sun::star::uno::Any const & Status ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL pop() throw (::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace migration +//......................................................................... + +#endif // _DESKTOP_OO3EXTENSIONMIGRATION_HXX_ diff --git a/desktop/source/migration/wizard.cxx b/desktop/source/migration/wizard.cxx index eeea969c6175..48ee2abc71ca 100644 --- a/desktop/source/migration/wizard.cxx +++ b/desktop/source/migration/wizard.cxx @@ -61,11 +61,14 @@ #include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/util/XChangesBatch.hpp> #include <com/sun/star/container/XNameReplace.hpp> +#include <com/sun/star/awt/WindowDescriptor.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> using namespace svt; using namespace rtl; using namespace osl; using namespace utl; +using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; @@ -77,13 +80,38 @@ using namespace com::sun::star::container; namespace desktop { -const FirstStartWizard::WizardState FirstStartWizard::STATE_WELCOME = 0; -const FirstStartWizard::WizardState FirstStartWizard::STATE_LICENSE = 1; -const FirstStartWizard::WizardState FirstStartWizard::STATE_MIGRATION = 2; -const FirstStartWizard::WizardState FirstStartWizard::STATE_USER = 3; +const FirstStartWizard::WizardState FirstStartWizard::STATE_WELCOME = 0; +const FirstStartWizard::WizardState FirstStartWizard::STATE_LICENSE = 1; +const FirstStartWizard::WizardState FirstStartWizard::STATE_MIGRATION = 2; +const FirstStartWizard::WizardState FirstStartWizard::STATE_USER = 3; const FirstStartWizard::WizardState FirstStartWizard::STATE_UPDATE_CHECK = 4; const FirstStartWizard::WizardState FirstStartWizard::STATE_REGISTRATION = 5; +static uno::Reference< uno::XComponentContext > getComponentContext( const uno::Reference< lang::XMultiServiceFactory >& rFactory ) +{ + uno::Reference< uno::XComponentContext > rContext; + uno::Reference< beans::XPropertySet > rPropSet( rFactory, uno::UNO_QUERY ); + uno::Any a = rPropSet->getPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ); + a >>= rContext; + return rContext; +} + +static sal_Int32 getBuildId() +{ + ::rtl::OUString aDefault; + ::rtl::OUString aBuildIdData = utl::Bootstrap::getBuildIdData( aDefault ); + sal_Int32 nBuildId( 0 ); + sal_Int32 nIndex1 = aBuildIdData.indexOf(':'); + sal_Int32 nIndex2 = aBuildIdData.indexOf(')'); + if (( nIndex1 > 0 ) && ( nIndex2 > 0 ) && ( nIndex2-1 > nIndex1+1 )) + { + ::rtl::OUString aBuildId = aBuildIdData.copy( nIndex1+1, nIndex2-nIndex1-1 ); + nBuildId = aBuildId.toInt32(); + } + return nBuildId; +} + WizardResId::WizardResId( USHORT nId ) : ResId( nId, *FirstStartWizard::GetResManager() ) { @@ -118,7 +146,47 @@ FirstStartWizard::FirstStartWizard( Window* pParent, sal_Bool bLicenseNeedsAccep // enableState(STATE_USER, sal_False); // enableState(STATE_REGISTRATION, sal_False); - ShowButtonFixedLine(sal_True); + try + { + Point pos(5, 210 ); + Size size(11, 11 ); + + pos = LogicToPixel( pos, MAP_APPFONT ); + size = LogicToPixel( size, MAP_APPFONT ); + + uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + uno::Reference< awt::XToolkit > xToolkit( + uno::Reference< lang::XMultiComponentFactory >( + xFactory, uno::UNO_QUERY_THROW)-> + createInstanceWithContext( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.Toolkit")), + getComponentContext(xFactory)), + uno::UNO_QUERY_THROW); + + m_xThrobber = uno::Reference< awt::XThrobber >( + xToolkit->createWindow( + awt::WindowDescriptor( + awt::WindowClass_SIMPLE, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Throbber")), + GetComponentInterface(), 0, + awt::Rectangle( + pos.X(), pos.Y(), size.Width(), size.Height()), + awt::WindowAttribute::SHOW)), + uno::UNO_QUERY_THROW); + } + catch (uno::RuntimeException &) + { + throw; + } + catch (Exception& ) + { + } + + uno::Reference< awt::XWindow > xThrobberWin( m_xThrobber, uno::UNO_QUERY ); + if ( xThrobberWin.is() ) + xThrobberWin->setVisible( false ); + Size aTPSize(TP_WIDTH, TP_HEIGHT); SetPageSizePixel(LogicToPixel(aTPSize, MAP_APPFONT)); @@ -151,6 +219,16 @@ FirstStartWizard::FirstStartWizard( Window* pParent, sal_Bool bLicenseNeedsAccep defaultButton(WZB_NEXT); } +void FirstStartWizard::EnableButtonsWhileMigration() +{ + enableButtons(0xff, sal_True); +} + +void FirstStartWizard::DisableButtonsWhileMigration() +{ + enableButtons(0xff, sal_False); +} + ::svt::RoadmapWizardTypes::PathId FirstStartWizard::defineWizardPagesDependingFromContext() { ::svt::RoadmapWizardTypes::PathId aDefaultPath = 0; @@ -280,7 +358,7 @@ TabPage* FirstStartWizard::createPage(WizardState _nState) pTabPage = new LicensePage(this, WizardResId(TP_LICENSE), m_aLicensePath); break; case STATE_MIGRATION: - pTabPage = new MigrationPage(this, WizardResId(TP_MIGRATION)); + pTabPage = new MigrationPage(this, WizardResId(TP_MIGRATION), m_xThrobber ); break; case STATE_USER: pTabPage = new UserPage(this, WizardResId(TP_USER)); @@ -350,6 +428,14 @@ sal_Bool FirstStartWizard::prepareLeaveCurrentState( CommitPageReason _eReason ) sal_Bool FirstStartWizard::leaveState(WizardState) { + if (( getCurrentState() == STATE_MIGRATION ) && m_bLicenseWasAccepted ) + { + // Store accept date and patch level now as it has been + // overwritten by the migration process! + storeAcceptDate(); + setPatchLevel(); + } + return sal_True; } @@ -436,6 +522,30 @@ void FirstStartWizard::storeAcceptDate() } +void FirstStartWizard::setPatchLevel() +{ + try { + Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + // get configuration provider + Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory >( + xFactory->createInstance(sConfigSrvc), UNO_QUERY_THROW); + Sequence< Any > theArgs(1); + NamedValue v(OUString::createFromAscii("NodePath"), + makeAny(OUString::createFromAscii("org.openoffice.Office.Common/Help/Registration"))); + theArgs[0] <<= v; + Reference< XPropertySet > pset = Reference< XPropertySet >( + theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs), UNO_QUERY_THROW); + Any result = pset->getPropertyValue(OUString::createFromAscii("ReminderDate")); + + OUString aPatchLevel( RTL_CONSTASCII_USTRINGPARAM( "Patch" )); + aPatchLevel += OUString::valueOf( getBuildId(), 10 ); + pset->setPropertyValue(OUString::createFromAscii("ReminderDate"), makeAny(aPatchLevel)); + Reference< XChangesBatch >(pset, UNO_QUERY_THROW)->commitChanges(); + } catch (const Exception&) + { + } +} + #ifdef WNT typedef int ( __stdcall * CleanCurUserRegProc ) ( wchar_t* ); #endif diff --git a/desktop/source/migration/wizard.hrc b/desktop/source/migration/wizard.hrc index 56bc61184fda..fdad97a8174b 100644 --- a/desktop/source/migration/wizard.hrc +++ b/desktop/source/migration/wizard.hrc @@ -78,6 +78,7 @@ #define ED_USER_LAST 17 #define ED_USER_FATHER 18 #define ED_USER_INITIALS 19 +#define TR_WAITING 20 // global strings #define STR_STATE_WELCOME RID_FIRSTSTSTART_START+100 diff --git a/desktop/source/migration/wizard.hxx b/desktop/source/migration/wizard.hxx index b84b461937e7..e41bfe373cde 100644 --- a/desktop/source/migration/wizard.hxx +++ b/desktop/source/migration/wizard.hxx @@ -32,6 +32,7 @@ #include <svtools/roadmapwizard.hxx> #include <vcl/window.hxx> #include <tools/resid.hxx> +#include <com/sun/star/awt/XThrobber.hpp> namespace desktop { @@ -61,6 +62,9 @@ public: virtual short Execute(); virtual long PreNotify( NotifyEvent& rNEvt ); + void EnableButtonsWhileMigration(); + void DisableButtonsWhileMigration(); + private: sal_Bool m_bOverride; WizardState _currentState; @@ -73,10 +77,12 @@ private: sal_Bool m_bLicenseWasAccepted; sal_Bool m_bAutomaticUpdChk; Link m_lnkCancel; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XThrobber > m_xThrobber; rtl::OUString m_aLicensePath; void storeAcceptDate(); + void setPatchLevel(); void disableWizard(); void enableQuickstart(); diff --git a/desktop/source/pkgchk/unopkg/unopkg_app.cxx b/desktop/source/pkgchk/unopkg/unopkg_app.cxx index 02fde984141c..2acd4f79a781 100644 --- a/desktop/source/pkgchk/unopkg/unopkg_app.cxx +++ b/desktop/source/pkgchk/unopkg/unopkg_app.cxx @@ -82,6 +82,8 @@ const char s_usingText [] = " -V, --version version information\n" " -v, --verbose verbose output to stdout\n" " -f, --force force overwriting existing extensions\n" +" -s, --suppress-license prevents showing the license provided that\n" +" the extension allows it\n" " --log-file <file> custom log file; default: <cache-dir>/log.txt\n" " --shared expert feature: operate on shared installation\n" " deployment context;\n" @@ -103,6 +105,7 @@ const OptionInfo s_option_infos [] = { { RTL_CONSTASCII_STRINGPARAM("shared"), '\0', false }, { RTL_CONSTASCII_STRINGPARAM("deployment-context"), '\0', true }, { RTL_CONSTASCII_STRINGPARAM("bundled"), '\0', false}, + { RTL_CONSTASCII_STRINGPARAM("suppress-license"), 's', false}, { 0, 0, '\0', false } }; @@ -207,6 +210,7 @@ extern "C" int unopkg_main() bool option_force = false; bool option_verbose = false; bool option_bundled = false; + bool option_suppressLicense = false; bool subcmd_add = false; bool subcmd_gui = false; OUString logFile; @@ -230,6 +234,9 @@ extern "C" int unopkg_main() s_option_infos, OUSTR("version") ); OptionInfo const * info_bundled = getOptionInfo( s_option_infos, OUSTR("bundled") ); + OptionInfo const * info_suppressLicense = getOptionInfo( + s_option_infos, OUSTR("suppress-license") ); + Reference<XComponentContext> xComponentContext; Reference<XComponentContext> xLocalComponentContext; @@ -271,6 +278,7 @@ extern "C" int unopkg_main() !readOption( &option_shared, info_shared, &nPos ) && !readOption( &option_force, info_force, &nPos ) && !readOption( &option_bundled, info_bundled, &nPos ) && + !readOption( &option_suppressLicense, info_suppressLicense, &nPos ) && !readArgument( &deploymentContext, info_context, &nPos ) && !isBootstrapVariable(&nPos)) { @@ -342,7 +350,8 @@ extern "C" int unopkg_main() Reference< ::com::sun::star::ucb::XCommandEnvironment > xCmdEnv( createCmdEnv( xComponentContext, logFile, - option_force, option_verbose, option_bundled) ); + option_force, option_verbose, option_bundled, + option_suppressLicense) ); if (subcmd_add || subCommand.equalsAsciiL( diff --git a/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx b/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx index 414a80eccc79..e4a503d98732 100644 --- a/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx +++ b/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx @@ -86,6 +86,7 @@ class CommandEnvironmentImpl bool m_option_force_overwrite; bool m_option_verbose; bool m_option_bundled; + bool m_option_suppressLicense; Reference< XComponentContext > m_xComponentContext; Reference< XProgressHandler > m_xLogFile; @@ -99,7 +100,8 @@ public: OUString const & log_file, bool option_force_overwrite, bool option_verbose, - bool option_bundled); + bool option_bundled, + bool option_suppressLicense); // XCommandEnvironment virtual Reference< task::XInteractionHandler > SAL_CALL @@ -124,11 +126,13 @@ CommandEnvironmentImpl::CommandEnvironmentImpl( OUString const & log_file, bool option_force_overwrite, bool option_verbose, - bool option_bundled) + bool option_bundled, + bool option_suppressLicense) : m_logLevel(0), m_option_force_overwrite( option_force_overwrite ), m_option_verbose( option_verbose ), m_option_bundled( option_bundled), + m_option_suppressLicense( option_suppressLicense), m_xComponentContext(xComponentContext) { if (log_file.getLength() > 0) { @@ -279,15 +283,25 @@ void CommandEnvironmentImpl::handle( } else if (request >>= licAgreementExc) { - String sResMsg( ResId( RID_STR_UNOPKG_NO_SHARED_ALLOWED, *DeploymentResMgr::get() ) ); - sResMsg.SearchAndReplaceAllAscii( "%NAME", licAgreementExc.ExtensionName ); - dp_misc::writeConsole(OUSTR("\n") + sResMsg + OUSTR("\n\n")); - abort = true; + if (m_option_suppressLicense && licAgreementExc.SuppressIfRequired) + { + approve = true; + } + else + { + String sResMsg( ResId( RID_STR_UNOPKG_NO_SHARED_ALLOWED, *DeploymentResMgr::get() ) ); + sResMsg.SearchAndReplaceAllAscii( "%NAME", licAgreementExc.ExtensionName ); + dp_misc::writeConsole(OUSTR("\n") + sResMsg + OUSTR("\n\n")); + abort = true; + } } else if (request >>= licExc) { bLicenseException = true; - printLicense(licExc.Text, approve, abort); + if (m_option_suppressLicense && licExc.SuppressIfRequired) + approve = true; + else + printLicense(licExc.Text, approve, abort); } else if (request >>= instExc) { @@ -432,10 +446,12 @@ Reference< XCommandEnvironment > createCmdEnv( OUString const & logFile, bool option_force_overwrite, bool option_verbose, - bool option_bundled) + bool option_bundled, + bool option_suppressLicense) { return new CommandEnvironmentImpl( - xContext, logFile, option_force_overwrite, option_verbose, option_bundled); + xContext, logFile, option_force_overwrite, option_verbose, option_bundled, + option_suppressLicense); } } // unopkg diff --git a/desktop/source/pkgchk/unopkg/unopkg_shared.h b/desktop/source/pkgchk/unopkg/unopkg_shared.h index cd082231774d..6e9d30cf0d42 100644 --- a/desktop/source/pkgchk/unopkg/unopkg_shared.h +++ b/desktop/source/pkgchk/unopkg/unopkg_shared.h @@ -163,7 +163,8 @@ css::uno::Reference<css::ucb::XCommandEnvironment> createCmdEnv( ::rtl::OUString const & logFile, bool option_force_overwrite, bool option_verbose, - bool option_bundled); + bool option_bundled, + bool option_suppressLicense); //============================================================================== void printf_packages( diff --git a/desktop/source/splash/splash.cxx b/desktop/source/splash/splash.cxx index 6e949c1bf00c..5fee3028b4f6 100644 --- a/desktop/source/splash/splash.cxx +++ b/desktop/source/splash/splash.cxx @@ -44,6 +44,8 @@ #include <rtl/logfile.hxx> #include <rtl/ustrbuf.hxx> #include <rtl/math.hxx> +#include <vcl/graph.hxx> +#include <svtools/filter.hxx> #define NOT_LOADED ((long)-1) @@ -58,6 +60,7 @@ SplashScreen::SplashScreen(const Reference< XMultiServiceFactory >& rSMgr) , _vdev(*((IntroWindow*)this)) , _cProgressFrameColor(sal::static_int_cast< ColorData >(NOT_LOADED)) , _cProgressBarColor(sal::static_int_cast< ColorData >(NOT_LOADED)) + , _bNativeProgress(true) , _iMax(100) , _iProgress(0) , _eBitmapMode(BM_DEFAULTMODE) @@ -295,6 +298,9 @@ void SplashScreen::loadConfig() OUString( RTL_CONSTASCII_USTRINGPARAM( "ProgressPosition" ) ) ); OUString sFullScreenSplash = implReadBootstrapKey( OUString( RTL_CONSTASCII_USTRINGPARAM( "FullScreenSplash" ) ) ); + OUString sNativeProgress = implReadBootstrapKey( + OUString( RTL_CONSTASCII_USTRINGPARAM( "NativeProgress" ) ) ); + // Determine full screen splash mode _bFullScreenSplash = (( sFullScreenSplash.getLength() > 0 ) && @@ -345,6 +351,11 @@ void SplashScreen::loadConfig() } } + if( sNativeProgress.getLength() ) + { + _bNativeProgress = sNativeProgress.toBoolean(); + } + if ( sSize.getLength() ) { sal_Int32 idx = 0; @@ -418,9 +429,15 @@ bool SplashScreen::loadBitmap( SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ ); if ( !aStrm.GetError() ) { + // Use graphic class to also support more graphic formats (bmp,png,...) + Graphic aGraphic; + + GraphicFilter* pGF = GraphicFilter::GetGraphicFilter(); + pGF->ImportGraphic( aGraphic, String(), aStrm, GRFILTER_FORMAT_DONTKNOW ); + // Default case, we load the intro bitmap from a seperate file // (e.g. staroffice_intro.bmp or starsuite_intro.bmp) - aStrm >> _aIntroBmp; + _aIntroBmp = aGraphic.GetBitmapEx(); return true; } @@ -438,8 +455,14 @@ bool SplashScreen::findBitmap(rtl::OUString const & path) { haveBitmap = findAppBitmap(path); } if ( !haveBitmap ) + { haveBitmap = loadBitmap( - path, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("intro.bmp"))); + path, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("intro.png"))); + if ( !haveBitmap ) + haveBitmap = loadBitmap( + path, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("intro.bmp"))); + } + return haveBitmap; } @@ -469,21 +492,34 @@ bool SplashScreen::findScreenBitmap(rtl::OUString const & path) aStrBuf.append( OUString::valueOf( nWidth )); aStrBuf.appendAscii( "x" ); aStrBuf.append( OUString::valueOf( nHeight )); - aStrBuf.appendAscii( ".bmp" ); - OUString aBmpFileName = aStrBuf.makeStringAndClear(); + + OUString aRootIntroFileName = aStrBuf.makeStringAndClear(); + OUString aBmpFileName = aRootIntroFileName + OUString::createFromAscii(".png"); bool haveBitmap = loadBitmap( path, aBmpFileName ); if ( !haveBitmap ) { + aBmpFileName = aRootIntroFileName + OUString::createFromAscii(".bmp"); + haveBitmap = loadBitmap( path, aBmpFileName ); + } + + if ( !haveBitmap ) + { aStrBuf.appendAscii( "intro_" ); aStrBuf.appendAscii( "_" ); aStrBuf.append( OUString::valueOf( nWidth )); aStrBuf.appendAscii( "x" ); aStrBuf.append( OUString::valueOf( nHeight )); - aStrBuf.appendAscii( ".bmp" ); - aBmpFileName = aStrBuf.makeStringAndClear(); + + aRootIntroFileName = aStrBuf.makeStringAndClear(); + aBmpFileName = aRootIntroFileName + OUString::createFromAscii(".png"); haveBitmap = loadBitmap( path, aBmpFileName ); + if ( !haveBitmap ) + { + aBmpFileName = aRootIntroFileName + OUString::createFromAscii(".bmp"); + haveBitmap = loadBitmap( path, aBmpFileName ); + } } return haveBitmap; } @@ -498,9 +534,16 @@ bool SplashScreen::findAppBitmap(rtl::OUString const & path) aStrBuf.appendAscii( "intro_" ); aStrBuf.appendAscii( "_" ); aStrBuf.append( _sAppName ); - aStrBuf.appendAscii( ".bmp" ); - OUString aBmpFileName = aStrBuf.makeStringAndClear(); + + OUString aRootIntroFileName = aStrBuf.makeStringAndClear(); + + OUString aBmpFileName = aRootIntroFileName + OUString::createFromAscii( ".png" ); haveBitmap = loadBitmap( path, aBmpFileName ); + if ( !haveBitmap ) + { + aBmpFileName = aRootIntroFileName + OUString::createFromAscii( ".bmp" ); + haveBitmap = loadBitmap( path, aBmpFileName ); + } } return haveBitmap; } @@ -584,9 +627,9 @@ void SplashScreen::Paint( const Rectangle&) BOOL bNativeOK = FALSE; // in case of native controls we need to draw directly to the window - if( IsNativeControlSupported( CTRL_INTROPROGRESS, PART_ENTIRE_CONTROL ) ) + if( _bNativeProgress && IsNativeControlSupported( CTRL_INTROPROGRESS, PART_ENTIRE_CONTROL ) ) { - DrawBitmap( Point(), _aIntroBmp ); + DrawBitmapEx( Point(), _aIntroBmp ); ImplControlValue aValue( _iProgress * _barwidth / _iMax); Rectangle aDrawRect( Point(_tlx, _tly), Size( _barwidth, _barheight ) ); @@ -612,7 +655,7 @@ void SplashScreen::Paint( const Rectangle&) //non native drawing // draw bitmap if (_bPaintBitmap) - _vdev.DrawBitmap( Point(), _aIntroBmp ); + _vdev.DrawBitmapEx( Point(), _aIntroBmp ); if (_bPaintProgress) { // draw progress... diff --git a/desktop/source/splash/splash.hxx b/desktop/source/splash/splash.hxx index f56fff54b931..99677aa107f1 100644 --- a/desktop/source/splash/splash.hxx +++ b/desktop/source/splash/splash.hxx @@ -34,7 +34,7 @@ #include <cppuhelper/implbase2.hxx> #include <cppuhelper/interfacecontainer.h> #include <vcl/introwin.hxx> -#include <vcl/bitmap.hxx> +#include <vcl/bitmapex.hxx> #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <osl/mutex.hxx> #include <vcl/virdev.hxx> @@ -86,9 +86,10 @@ private: Reference< XMultiServiceFactory > _rFactory; VirtualDevice _vdev; - Bitmap _aIntroBmp; + BitmapEx _aIntroBmp; Color _cProgressFrameColor; Color _cProgressBarColor; + bool _bNativeProgress; OUString _sAppName; std::vector< FullScreenProgressRatioValue > _sFullScreenProgressRatioValues; |