From 1a6fe7c7b5788df7e65fff41dd7f9b31ac3b46c1 Mon Sep 17 00:00:00 2001 From: Scott Johns Date: Fri, 22 Mar 2013 11:31:59 -0400 Subject: [PATCH] [python] adds a background progress dialog --- xbmc/interfaces/legacy/Dialog.cpp | 62 +++++++++++++++++++++++++++++- xbmc/interfaces/legacy/Dialog.h | 64 +++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/xbmc/interfaces/legacy/Dialog.cpp b/xbmc/interfaces/legacy/Dialog.cpp index af0941c1b6546..dd2d0e4fa0534 100644 --- a/xbmc/interfaces/legacy/Dialog.cpp +++ b/xbmc/interfaces/legacy/Dialog.cpp @@ -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(); + } + } } - diff --git a/xbmc/interfaces/legacy/Dialog.h b/xbmc/interfaces/legacy/Dialog.h index 66c62697176f0..f64b6eb1a72b5 100644 --- a/xbmc/interfaces/legacy/Dialog.h +++ b/xbmc/interfaces/legacy/Dialog.h @@ -28,6 +28,7 @@ #include "AddonString.h" #include "ApplicationMessenger.h" #include "dialogs/GUIDialogProgress.h" +#include "dialogs/GUIDialogExtendedProgressBar.h" #include "Alternative.h" namespace XBMCAddon @@ -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(); + }; + } }