'encoding UTF-8 Do not remove or change this line! '************************************************************** ' ' 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 ' ' Unless required by applicable law or agreed to in writing, ' software distributed under the License is distributed on an ' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ' KIND, either express or implied. See the License for the ' specific language governing permissions and limitations ' under the License. ' '************************************************************** '* '* short description : Tools to ease working with the extension manager '* '\****************************************************************************** function hExtensionAddGUI( _path as string, _flags as string ) as integer '///

Install an extension using the OpenOffice.org Extension Manager UI

'///

This function is intended for use with the new Extension Manager UI '///+ and replaces an older function with the same name. Please note that '///+ the interface has changed significantly.
This has become necessary '///+ because the Extension Manager can turn up with a really huge number '///+ of different dialogs, warnings, errormessages etc.
'///+ As this function is designed to handle the most common installation '///+ scenarios it needs quite a number of differnt options.
'///+ Please have a look at the usage sample:

'///+

hExtensionAddGUI( sMyExtension, '///+ "InstallForAll,BrokenDeps,DenyUpdate" )
'///Input:
'///

    '///+
  1. Path to extension (String)
  2. '/// '///+
  3. Flags (String), defaults underlined
  4. '/// '///
'///Return Value:
'///
    '///+
  1. Installation status (Integer)
  2. '/// '///
dim flags as string : flags = lcase( _flags ) dim path as string : path = convertpath( _path ) dim bLogs as boolean : bLogs = FALSE const CFN = "hExtensionAddGUI()::" '///Description '/// end function '******************************************************************************* function hExtensionRemoveGUI( cExtensionName as string ) as integer '///

Remove an extension via Extension Manager

'///Input value(s):
'///
    '///+
  1. UI Name of the extension (string)
  2. '///
'///Return Value:
'///
    '///+
  1. Errorcode (integer)
  2. '/// '///
const CFN = "hExtensionRemoveGUI(): " printlog( "Removing extension by name: " & cExtensionName ) ToolsPackageManager kontext "PackageManager" if ( PackageManager.exists( 2 ) ) then try BrowsePackages.select( cExtensionName ) if ( Remove.exists() ) then if ( Remove.isEnabled() ) then Remove.click() kontext "Active" if ( Active.exists( 3 ) ) then printlog( Active.getText() ) Active.OK() WaitSlot() else warnlog( CFN & "Expected confirmation dialog is missing" ) endif hExtensionRemoveGUI() = 0 else hExtensionRemoveGUI() = 2 endif else hExtensionRemoveGUI() = 4 endif catch hExtensionRemoveGUI() = 3 endcatch kontext "PackageManager" hCloseDialog( PackageManager , "close" ) else hExtensionRemoveGUI() = 1 endif end function '******************************************************************************* function sExtensionCLI(sCommand as string, sExtensionName as string, optional sExtensionPath as string) as string '/// Add/remove an extension with the command line tool 'unopkg'///' '/// INPUT: sCommand: string of command from "add remove list reinstall" ///' '/// INPUT: sExtensionName: name of the extension ///' '/// INPUT: optional sExtensionPath: path to the extension ///' '/// RETURN: currently nothing ///' dim sLokalExtensionPath as string dim sCommands as string dim sUnoPkg as string dim i, a, b as integer dim args as string Dim sFile as string Dim sEnv as string Dim sContent(5) as string Dim sPlatformProgramPath as string if isMissing(sExtensionPath) then sLokalExtensionPath = "" else sLokalExtensionPath = sExtensionPath endif sCommands = "add remove list reinstall" a = len(sAppExe) if a > 12 then b = inStr(a-12, sAppExe, "soffice") sUnoPkg = left(sAppExe, b-1) + "unopkg" + mid(sAppExe, b+len("soffice")) 'printlog sUnoPkg 'sUnoPkg = convertToUrl(sUnoPkg) else qaErrorLog ("Need to think about another solution..." + sAppExe) endif args = sCommand+" "+sLokalExtensionPath + sExtensionName printlog "Executing: "+sUnopkg+" "+args if gPlatGroup <> "unx" then shell(sUnoPkg,2,args) else sFile = ConvertPath (gOfficePath + "user/work/uno.sh") if gPlatform = lcase("osx") then sPlatformProgramPath = "MacOS" else sPlatformProgramPath = "program" end if sEnv = convertToURL(convertPath(gNetzOfficePath + sPlatformProgramPath + "/fundamentalrc") listAppend(sContent(), "export URE_BOOTSTRAP=" + sEnv) listAppend(sContent(), sUnoPkg + " " + args) listWrite(sContent(), sFile) shell("bash",1,sFile) endif end function '******************************************************************************* function hExtensionGetItemList( cItemList() as string ) as integer '///

Get the list of all items in the extensions list

'///The array contains the list of all items in the extension manager GUI, '///+ including all components of the extensions. Consider this when defining '///+ the size of the array to be passed to this function as problems here are '///+ hard to debug.
'///+ Starting point is any document, the function will return to the '///+ calling document on completion


'///Input: '///
    '///+
  1. Array for the list items (string)
  2. '///
'///Return Value:
'///
    '///+
  1. Number of items (integer)
  2. '/// '///
dim iItemCount as integer dim iCurrentExtension as integer printlog( "Retrieving extension list" ) ToolsPackageManager kontext "PackageManager" if ( PackageManager.exists( 2 ) ) then iItemCount = BrowsePackages.getItemCount() for iCurrentExtension = 1 to iItemCount cItemList( iCurrentExtension ) = BrowsePackages.getItemText( iCurrentExtension , 1 ) printlog( " * " & cItemList( iCurrentExtension ) next iCurrentExtension hExtensionGetItemList() = iItemCount cItemList( 0 ) = iItemCount hCloseDialog( PackageManager , "close" ) else hExtensionGetItemList() = 0 endif end function '******************************************************************************* function hSelectExtensionID( iPos as integer ) as string '///

Select an item by index in the list of available extensions

'///This function needs the Extension Manager to be open. It will only '///+ select extensions but not their components.

'///Input: '///
    '///+
  1. Absolute position of the extension to be selected (Integer)
  2. '///
'///Return Value:
'///
    '///+
  1. Name of the selected extension (String)
  2. '///+
  3. Empty string on index out of range or Extension Manager not open
  4. '///
printlog( "Selecting extension at pos. " & iPos ) ToolsPackageManager kontext "PackageManager" if ( PackageManager.exists( 2 ) ) then try BrowsePackages.select( iPos ) hSelectExtensionID() = BrowsePackages.getItemText( iPos , 1 ) catch hSelectExtensionID() = "" endcatch hCloseDialog( PackageManager , "close" ) else hSelectExtensionID() = "" endif end function '******************************************************************************* function hSelectExtensionName( cName as string ) as integer '///

Select an item by name in the list of available extensions

'///This function needs the Extension Manager to be open. It will only '///+ select extensions but not their components.

'///Input: '///
    '///+
  1. Name of the extension (String)
  2. '/// '///
'///Return Value:
'///
    '///+
  1. Absolute position of the selected extension (Integer)
  2. '/// '///
printlog( "Selecting extension by display name: " & cName ) ToolsPackageManager kontext "PackageManager" if ( PackageManager.exists( 2 ) ) then try BrowsePackages.select( cName ) hSelectExtensionName() = BrowsePackages.getSelIndex() catch hSelectExtensionName() = 0 endcatch hCloseDialog( PackageManager , "close" ) else hSelectExtensionName() = -1 endif end function '******************************************************************************* function hSelectOptionsItem( cName as string, iIndex as integer ) as integer '///

Select an item in Tools/Options and verify

'///You need to open the Tools/Options dialog before using this function, '///+ it will not close the dialog either. No warnlogs are printed so evaluation '///+ of the return value is mandatory

'///Parameter(s):
'///
    '///+
  1. Name of the extension node (string)
  2. '/// '///+
  3. Position of the node (absolute) (integer)
  4. '/// '///
'///Returns:
'///
    '///+
  1. Errorcondition (integer)
  2. '/// '///
const CFN = "hSelectOptionsItem::" printlog( CFN & "Enter with option (Name).: " & cName ) printlog( CFN & "Enter with option (Index): " & iIndex ) dim brc as boolean ' a multi purpose boolean returnvalue dim irc as integer ' a multi purpose integer returnvalue dim crc as string ' a multi purpose string returnvalue '///Description: '/// end function '******************************************************************************* function hIsExtensionAlreadyInstalled( cName as string ) as boolean '///

Check if an extension is already installed

'///The function opents the Extension Manager, finds (or not) the extension '///+ and returns an appropriate return value. The Extension Manager is '///+ closed again at the end.

'///Input: '///
    '///+
  1. Name of the extension (String)
  2. '///
'///Return Value:
'///
    '///+
  1. is the extension allredy installed (boolean)
  2. '/// '///
printlog( "Checking if extension is already installed: " & cname ) dim iCountExtensions as integer dim i as integer hIsExtensionAlreadyInstalled() = FALSE ToolsPackageManager kontext "PackageManager" iCountExtensions = BrowsePackages.getItemCount() for i = 1 to iCountExtensions if(Instr(BrowsePackages.getItemText(i,1),cname) <> 0) then hIsExtensionAlreadyInstalled() = TRUE endif next hCloseDialog( PackageManager , "close" ) end function '******************************************************************************* function hDisableUserExtensionGUI( extension_name as string ) as integer '///

Disable a userspace extension by name via GUI

'///This function tries to disable an Extension specified by name. There '///+ are several reasons why this might fail so it is required to evaluate the '///+ returnvalue as the function will not print any warnings. If the function '///+ fails this is most likely caused by a) the extension already being '///+ disabled or b) the extension belonging to the shared layer.
'///+ The Extension Manager needs to be open when function is called.


'///Parameter(s):
'///
    '///+
  1. Name of the extension to be disabled (string)
  2. '/// '///
'///Returns:
'///
    '///+
  1. Errorcondition (integer)
  2. '/// printlog( "Disabling user extension" ) ToolsPackageManager kontext "PackageManager" if ( PackageManager.exists( 2 ) ) then try BrowsePackages.select( extension_name ) if ( Disable.exists() and Disable.isEnabled() ) then hDisableUserExtensionGUI() = 0 else hDisableUserExtensionGUI() = 2 endif hCloseDialog( PackageManager , "close" ) catch hDisableUserExtensionGUI() = 1 endcatch else hDisableUserExtensionGUI() = 3 endif end function '******************************************************************************* function hGetExtensionCount() as integer printlog( "Getting number of installed extensions." ) ToolsPackageManager kontext "PackageManager" if ( PackageManager.exists( 2 ) ) then try hGetExtensionCount() = BrowsePackages.getItemCount() hCloseDialog( PackageManager , "close" ) catch hGetExtensionCount() = -2 endcatch else hGetExtensionCount() = -1 endif end function