Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[python] adds a background progress dialog
  • Loading branch information
nuka1195 committed Mar 22, 2013
1 parent c4d4916 commit 1a6fe7c
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
62 changes: 61 additions & 1 deletion xbmc/interfaces/legacy/Dialog.cpp
Expand Up @@ -305,6 +305,66 @@ namespace XBMCAddon
{
return dlg->IsCanceled();
}

DialogProgressBG::~DialogProgressBG() { TRACE; deallocating(); }

void DialogProgressBG::deallocating()
{
TRACE;

if (dlg)
{
DelayedCallGuard dg;
dlg->Close();
}
}

void DialogProgressBG::create(const String& heading, const String& message) throw (WindowException)
{
DelayedCallGuard dcguard(languageHook);
CGUIDialogExtendedProgressBar* pDialog =
(CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS);

if (pDialog == NULL)
throw WindowException("Error: Window is NULL, this is not possible :-)");

CGUIDialogProgressBarHandle* pHandle = pDialog->GetHandle(heading);

dlg = pDialog;
handle = pHandle;

pHandle->SetTitle(heading);
if (!message.empty())
pHandle->SetText(message);
}

void DialogProgressBG::update(int percent, const String& heading, const String& message) throw (WindowException)
{
DelayedCallGuard dcguard(languageHook);
CGUIDialogExtendedProgressBar* pDialog = dlg;
CGUIDialogProgressBarHandle* pHandle = handle;

if (pDialog == NULL)
throw WindowException("Error: Window is NULL, this is not possible :-)");

if (percent >= 0 && percent <= 100)
pHandle->SetPercentage((float)percent);
if (!heading.empty())
pHandle->SetTitle(heading);
if (!message.empty())
pHandle->SetText(message);
}

void DialogProgressBG::close()
{
DelayedCallGuard dcguard(languageHook);
handle->MarkFinished();
}

bool DialogProgressBG::isFinished()
{
return handle->IsFinished();
}

}
}

64 changes: 64 additions & 0 deletions xbmc/interfaces/legacy/Dialog.h
Expand Up @@ -28,6 +28,7 @@
#include "AddonString.h"
#include "ApplicationMessenger.h"
#include "dialogs/GUIDialogProgress.h"
#include "dialogs/GUIDialogExtendedProgressBar.h"
#include "Alternative.h"

namespace XBMCAddon
Expand Down Expand Up @@ -285,5 +286,68 @@ namespace XBMCAddon
bool iscanceled();
};

/**
* DialogProgressBG class
*/
class DialogProgressBG : public AddonClass
{
CGUIDialogExtendedProgressBar* dlg;
CGUIDialogProgressBarHandle* handle;

protected:
virtual void deallocating();

public:

DialogProgressBG() : AddonClass("DialogProgressBG"), dlg(NULL), handle(NULL) {}
virtual ~DialogProgressBG();


/**
* create(heading[, message]) -- Create and show a background progress dialog.\n
*\n
* heading : string or unicode - dialog heading\n
* message : [opt] string or unicode - message text\n
*\n
* *Note, 'heading' is used for the dialog's id. Use a unique heading.\n
* Use update() to update heading, message and progressbar.\n
*\n
* example:\n
* - pDialog = xbmcgui.DialogProgressBG()\n
* - pDialog.create('Movie Trailers', 'Downloading Monsters Inc. ...')\n
*/
void create(const String& heading, const String& message = emptyString) throw (WindowException);

/**
* update([percent, heading, message]) -- Updates the background progress dialog.\n
*\n
* percent : [opt] integer - percent complete. (0:100)\n
* heading : [opt] string or unicode - dialog heading\n
* message : [opt] string or unicode - message text\n
*\n
* *Note, To clear heading or message, you must pass a blank character.\n
*\n
* example:\n
* - pDialog.update(25, message='Downloading Finding Nemo ...')\n
*/
void update(int percent = 0, const String& heading = emptyString, const String& message = emptyString) throw (WindowException);

/**
* close() -- Close the background progress dialog\n
*\n
* example:\n
* - pDialog.close()\n
*/
void close();

/**
* isFinished() -- Returns True if the background dialog is active.\n
*\n
* example:\n
* - if (pDialog.isFinished()): return\n
*/
bool isFinished();
};

}
}

1 comment on commit 1a6fe7c

@jimfcarroll
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have just used 'git reset --hard' to drop your last few commits if all you wanted to do was return to the first one.

Have you built and tested this particular commit? If so, I'll put it in.

Please sign in to comment.