VBScript/soplayer

出典: OOoJa

本版は、VBScriptを使用していますので、Windows上でのみ動作します。
Linux上などでは、OpenOffice.org BASIC 版 エクステンション/soplayer をお試しください。

[編集] soplayer 0.2 (VBScript 版)

[編集] 概要

エクステンション/soplayerの「概要」をご覧ください。

[編集] 背景

エクステンション/soplayerの「背景」をご覧ください。

[編集] ダウンロード

  1. Media:soplayer-0.2-vbscript.txt (シフトJIS) を右クリックし、「対象をファイルに保存」を選択する。
  2. ファイル名の拡張子の.txt部分を.vbsへ変更して保存する


※上記のリンクをクリックすると、ブラウザの設定によっては、文字化けして表示されます。
文字化けした表示された場合は、文字コードを「日本語 (シフトJIS)」に変更すると文字化けは直ります。
わざわざそのようにしなくてもいいようにと、後述の「ソースコード」に内容を転記しておきました。

[編集] インストール方法

インストールの必要はありません。

[編集] 使い方

soplayer-0.2-vbscript.vbsのアイコン上へ、プレゼンテーションのファイルをドラッグアンドドロップします。または、このsoplayer-0.2-vbscript.vbsをダブルクリックすると、ファイルを開くダイアログが表示されますので、プレゼンテーションのファイルを選択し、「開く」ボタンを押します。

どちらの方法でも、1つ以上のファイルを指定できます。その場合は、その場合は、順番にプレゼンテーションが表示されます。

[編集] ソースコード

参考までに、soplayer-0.2-vbscript.txt の内容を以下に示します。

'
' soplayer.vbs - StarOffice Presentation Player
'
' Version 0.3 written in VBScript             - December 13, 2007  by Takamichi Akiyama <tora@openoffice.org> 
' Version 0.2 written in OpenOffice.org BASIC - December 13, 2007  by Takamichi Akiyama <tora@openoffice.org> 
' Version 0.1 - July 30, 2004 by Takamichi Akiyama <tora@openoffice.org> 
' License: GNU LGPL
'
' この VBScript は、プレゼンテーションのファイルを開いて、プレゼンテーションを開始します。
' プレゼンテーションが終了すると、自動的にファイルを閉じます。

' 使い方その1
' このファイルのアイコンへ、プレゼンテーションのファイルをドラッグアンドドロップします。
'
' 使い方その2
' このファイルを実行すると、ファイルを開くダイアログが表示されますので、プレゼンテーションのファイルを選択します。
'
' どちらの方法でも、1つ以上のファイルを指定できます。その場合は、順番にプレゼンテーションが表示されます。
'

Public oServiceManager, oCoreReflection, oDesktop
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oCoreReflection = oServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")

Call Main

Sub Main
	Dim oArgs, sPath, sURL, sURLs, sPDF, I
	Set oArgs = WScript.Arguments
	If oArgs.Count > 0 Then
		' Drag and Drop Interface
		For I = 0 to oArgs.Count - 1
			sPath = oArgs(I)
			sURL = convertToURL(sPath)
			play sURL
		Next
	Else
		' File Selection Dialog Interface
		sURLs = getURLs_for_Open()
		For I = 0 To UBound(sURLs)
			sURL = sURLs(I)
			play sURL
		Next
	End If
End Sub

Function convertToURL(sPath)
	Dim regEx, sURL
	Set regEx = New RegExp
	regEx.IgnoreCase = True
	regEx.Global = True
	regEx.Pattern = "\\"
	sURL = "file:///" + regEx.Replace(sPath, "/")
	convertToURL = sURL
End Function

Function getURLs_for_Open()
	Dim oFilePicker, sFiles
	Set oFilePicker = oServiceManager.createInstance("com.sun.star.ui.dialogs.FilePicker")
	Dim args(0)
	args(0) = 0 'com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
	With oFilePicker
		.initialize(args)
		.setTitle "プレゼンテーションのファイルを選んでください。ShiftやCtrlキーを押しながら、複数のファイルを一度に選択できます。"
		.AppendFilter "プレゼンテーションのファイル (*.odp;*.sxi;*.ppt)", "*.odp;*.sxi;*.ppt"
		.SetCurrentFilter "プレゼンテーションのファイル (*.odp;*.sxi;*.ppt)"
		.setMultiSelectionMode(True)
	End With
	If oFilePicker.execute() = False Then
		Wscript.Quit
	End If
	sFiles = oFilePicker.getFiles()
	Dim sPath
	If UBound(sFiles) > 1 Then
		ReDim sPath(UBound(sFiles) - 1)
		For I = 1 To UBound(sFiles)
			sPath(I - 1) = sFiles(0) & sFiles(I)
		Next
	Else
		ReDim sPath(0)
		sPath(0) = sFiles(0)
	End If
	getURLs_for_Open = sPath
End Function

Sub play(sURL)
	'MsgBox sURL

	Dim classSize
	Set classSize = oCoreReflection.forName("com.sun.star.beans.PropertyValue")

	Dim oDoc

	Dim args1(0)
	classSize.createObject args1(0)
	args1(0).Name = "Hidden"
	args1(0).Value = false

	On Error Resume Next
	Set oDoc = oDesktop.loadComponentFromURL(sURL, "_default", 0, args1)
	On Error Goto 0

	If Not IsObject(oDoc) Then
		MsgBox "ファイル " & sURL & " を開けませんでした。", vbOKOnly + vbCritical, "エラー発生!"
		Exit Sub
	End If

	If Not oDoc.supportsService("com.sun.star.presentation.PresentationDocument") Then
		oDoc.close False
		MsgBox "ファイル " & sURL & " は、プレゼンテーションのファイルではありません。", bOKOnly + vbCritical, "エラー発生!"
		Exit Sub
	End If

	StartPresentation oDoc
	if (oDoc.Presentation.IsFullScreen) Then
		do
			WScript.Sleep 1000
		loop While (isOnGoing(oDoc))
		oDoc.close True
	End If

End Sub

Function isOnGoing(oDoc)
	Dim sTitle
	Dim oComponents
	Dim nCount
	Dim oEnumeration
	Dim oElement

	sTitle = getTitle(oDoc)
	nCount = 0
	Set oComponents = oDesktop.getComponents()
	if oComponents.hasElements() Then
		Set oEnumeration = oComponents.createEnumeration()
		do while (oEnumeration.hasMoreElements())
			Set oElement = oEnumeration.nextElement()
			if oElement.supportsService("com.sun.star.presentation.PresentationDocument") Then
				If getTitle(oElement) = sTitle Then
					nCount = nCount + 1
				End If
			end if
		loop
	End If
	isOnGoing = (nCount >= 2)
End Function

Function getTitle(oElement)
	Dim xController
	Dim xFrame

	Set xController = oElement.getCurrentController()
	Set xFrame = xController.getFrame()
	getTitle = xFrame.Title
End Function

Sub StartPresentation(oDoc)
	Dim oPresentation
	Set oPresentation = oDoc.getPresentation()
	' http://api.openoffice.org/docs/common/ref/com/sun/star/presentation/Presentation.html
	oPresentation.AllowAnimations = True
	oPresentation.CustomShow = ""
	oPresentation.FirstPage = ""
	oPresentation.IsAlwaysOnTop = True
	oPresentation.IsAutomatic = False
	oPresentation.IsEndless = False
	oPresentation.IsFullScreen = True
	'oPresentation.IsLivePresentation = 
	oPresentation.IsMouseVisible = True
	'oPresentation.IsShowAll = True
	oPresentation.IsTransitionOnClick = True
	oPresentation.IsShowLogo = False
	oPresentation.Pause = 1
	oPresentation.StartWithNavigator = False
	oPresentation.UsePen = True
	oPresentation.Start()
End Sub