WindowsProgressDialog in process plugin (1 Viewer)

STSC

Portal Pro
December 4, 2004
139
0
Germany
Hi,

does anybody know how to call a WindowsProgressDialog in a process plugin?

I always get this error: System.InvalidCastException: Specified cast is not valid.

Here is my code:

Code:
Imports MediaPortal.Dialogs

Public Class DialogProgressPlugin
    Implements MediaPortal.GUI.Library.IPlugin, MediaPortal.GUI.Library.ISetupForm

    Public Const WINDOW_DialogProgressPLUGIN = 6202 'a window ID shouldn't be needed when a non visual plugin ?!
    Private EPGTimer As System.Threading.Timer

    Public Sub Start() Implements MediaPortal.GUI.Library.IPlugin.Start
        Dim timerDelegate As System.Threading.TimerCallback = AddressOf WindowsProgressDialog
        EPGTimer = New System.Threading.Timer(timerDelegate, Nothing, 500, 15000)

    End Sub

    Public Sub WindowsProgressDialog(ByVal stateInfo As Object)

        'Create dialog to show progress
        Try
            Dim dlgProgress As MediaPortal.Dialogs.GUIDialogProgress = CType(MediaPortal.GUI.Library.GUIWindowManager.GetWindow(CType(MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_DIALOG_PROGRESS, Integer)), MediaPortal.Dialogs.GUIDialogProgress)
            If (Not dlgProgress Is Nothing) Then
                dlgProgress.SetHeading("DialogHeading")
                dlgProgress.SetLine(1, "DialogLine1")
                dlgProgress.SetLine(2, "DialogLine2")
                dlgProgress.SetLine(3, "DialogLine3")
                dlgProgress.StartModal(MediaPortal.GUI.Library.GUIWindowManager.ActiveWindow)
                dlgProgress.SetPercentage(0)
                dlgProgress.Progress()
                dlgProgress.ShowProgressBar(True)
            End If

            Dim iCounter As Integer = 0

            While iCounter <= 100
                dlgProgress.SetPercentage(iCounter)
                Threading.Thread.Sleep(100)
                iCounter += 1
            End While


            dlgProgress.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)

        End Try

    End Sub
    Public Sub [Stop]() Implements MediaPortal.GUI.Library.IPlugin.Stop

    End Sub

    Public Function Author() As String Implements MediaPortal.GUI.Library.ISetupForm.Author
        Return "STSC"
    End Function

    Public Function CanEnable() As Boolean Implements MediaPortal.GUI.Library.ISetupForm.CanEnable
        Return True
    End Function

    Public Function DefaultEnabled() As Boolean Implements MediaPortal.GUI.Library.ISetupForm.DefaultEnabled
        Return True
    End Function

    Public Function Description() As String Implements MediaPortal.GUI.Library.ISetupForm.Description
        Return "DialogProgress"
    End Function

    Public Function GetHome(ByRef strButtonText As String, ByRef strButtonImage As String, ByRef strButtonImageFocus As String, ByRef strPictureImage As String) As Boolean Implements MediaPortal.GUI.Library.ISetupForm.GetHome
        strButtonText = "DialogProgress"
        strButtonImage = ""
        strButtonImageFocus = ""
        strPictureImage = ""
        Return False
    End Function

    Public Function GetWindowId() As Integer Implements MediaPortal.GUI.Library.ISetupForm.GetWindowId
        Return WINDOW_DialogProgressPLUGIN
    End Function

    Public Function HasSetup() As Boolean Implements MediaPortal.GUI.Library.ISetupForm.HasSetup
        Return False
    End Function

    Public Function PluginName() As String Implements MediaPortal.GUI.Library.ISetupForm.PluginName
        Return "DialogProgress"
    End Function

    Public Sub ShowPlugin() Implements MediaPortal.GUI.Library.ISetupForm.ShowPlugin
        'no setup form, therefore nothing to do
    End Sub
End Class

It seeme that this line causes trouble:


Dim dlgProgress As MediaPortal.Dialogs.GUIDialogProgress = CType(MediaPortal.GUI.Library.GUIWindowManager.GetWindow(CType(MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_DIALOG_PROGRESS, Integer)), MediaPortal.Dialogs.GUIDialogProgress)

What's wrong?

Thanks!!
 

STSC

Portal Pro
December 4, 2004
139
0
Germany
Ok,

I also wrote it in C#. I guess that this is better.

Code:
using System;
using System.Collections;
using System.Threading;
using System.Windows.Forms;
using MediaPortal.GUI.Library;
using MediaPortal.Util;
using MediaPortal.Dialogs;

namespace MPProgressPlugin
{
	/// <summary>
	/// Zusammenfassung für Class1.
	/// </summary>
	public class ProgressPlugin: IPlugin, ISetupForm
	{
		public ProgressPlugin()
		{
			//
			// TODO: Fügen Sie hier die Konstruktorlogik hinzu
			//
		}


		public void Start()
		{
			ProgressDialog();
		}

		void ProgressDialog()
		{
			try
			{
				GUIDialogProgress dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);
				if (dlgProgress != null)
				{
					dlgProgress.SetHeading("DialogHeading");
					dlgProgress.SetLine(1, "DialogLine1");
					dlgProgress.SetLine(2, "DialogLine2");
					dlgProgress.SetLine(3, "DialogLine3");
					dlgProgress.StartModal(MediaPortal.GUI.Library.GUIWindowManager.ActiveWindow);
					dlgProgress.SetPercentage(0);
					dlgProgress.Progress();
					dlgProgress.ShowProgressBar(true);
				}

			}
			catch(Exception e)
			{			
				MessageBox.Show(e.ToString(), "Error",
					MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				Log.Write(e.ToString());
			}


		}

		public void Stop()
		{	
		}

		#region ISetupForm Members

		public bool CanEnable()
		{
			return true;
		}

		public string PluginName()
		{
			return "Progress Dialog";
		}

		public bool HasSetup()
		{
			return true;
		}
		public bool DefaultEnabled()
		{
			return true;
		}

		public int GetWindowId()
		{
			return 23002;
		}

		public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage)
		{
			strButtonText = "Progress Dialog";
			strButtonImage = "";
			strButtonImageFocus = "";
			strPictureImage = "";
			return false;
		}

		public string Author()
		{
			return "STSC";
		}

		public string Description()
		{
			return "Progress Dialog";
		}

		public void ShowPlugin() // show the setup dialog
		{
		}		

		#endregion
	}
}

But this line

Code:
GUIDialogProgress dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);

still causes an System.InvalidCastException?

frodo: Do you know why it doesn't work?
 

Users who are viewing this thread

Top Bottom