diff options
author | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2017-03-20 11:50:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-20 11:50:45 +0100 |
commit | 11e0aef7d5f561d0dbbf7ef1eca54bf9b6c46f37 (patch) | |
tree | 7fd04e9063391e8e0023d91eebf5237e63196193 | |
parent | f2a657ded56dbf569ab15fcded482bb38f3ea0bb (diff) | |
parent | a8853ed9af4b49bc24d3d608fc33e444c8e5ffcc (diff) |
Merge pull request #11863 from ksooo/pvr-async-gui-actions
[PVR] GUI Actions: Execute recordings actions async
-rw-r--r-- | xbmc/dialogs/GUIDialogBusy.cpp | 8 | ||||
-rw-r--r-- | xbmc/dialogs/GUIDialogBusy.h | 8 | ||||
-rw-r--r-- | xbmc/pvr/PVRGUIActions.cpp | 77 |
3 files changed, 77 insertions, 16 deletions
diff --git a/xbmc/dialogs/GUIDialogBusy.cpp b/xbmc/dialogs/GUIDialogBusy.cpp index c8fe0706d1..198af6fb78 100644 --- a/xbmc/dialogs/GUIDialogBusy.cpp +++ b/xbmc/dialogs/GUIDialogBusy.cpp @@ -31,12 +31,12 @@ class CBusyWaiter : public CThread public: CBusyWaiter(IRunnable *runnable) : CThread(runnable, "waiting"), m_done(new CEvent()) { } - bool Wait() + bool Wait(unsigned int displaytime, bool allowCancel) { std::shared_ptr<CEvent> e_done(m_done); Create(); - return CGUIDialogBusy::WaitOnEvent(*e_done); + return CGUIDialogBusy::WaitOnEvent(*e_done, displaytime, allowCancel); } // 'this' is actually deleted from the thread where it's on the stack @@ -50,12 +50,12 @@ public: }; -bool CGUIDialogBusy::Wait(IRunnable *runnable) +bool CGUIDialogBusy::Wait(IRunnable *runnable, unsigned int displaytime /* = 100 */, bool allowCancel /* = true */) { if (!runnable) return false; CBusyWaiter waiter(runnable); - return waiter.Wait(); + return waiter.Wait(displaytime, allowCancel); } bool CGUIDialogBusy::WaitOnEvent(CEvent &event, unsigned int displaytime /* = 100 */, bool allowCancel /* = true */) diff --git a/xbmc/dialogs/GUIDialogBusy.h b/xbmc/dialogs/GUIDialogBusy.h index 53ba8b9cd5..4e6290c4b3 100644 --- a/xbmc/dialogs/GUIDialogBusy.h +++ b/xbmc/dialogs/GUIDialogBusy.h @@ -44,18 +44,20 @@ public: Creates a thread to run the given runnable, and while waiting it displays the busy dialog. \param runnable the IRunnable to run. + \param displaytime the time in ms to wait prior to showing the busy dialog (defaults to 100ms) + \param allowCancel whether the user can cancel the wait, defaults to true. \return true if the runnable completes, false if the user cancels early. */ - static bool Wait(IRunnable *runnable); + static bool Wait(IRunnable *runnable, unsigned int displaytime = 100, bool allowCancel = true); /*! \brief Wait on an event while displaying the busy dialog. Throws up the busy dialog after the given time. - \param even the CEvent to wait on. + \param event the CEvent to wait on. \param displaytime the time in ms to wait prior to showing the busy dialog (defaults to 100ms) \param allowCancel whether the user can cancel the wait, defaults to true. \return true if the event completed, false if cancelled. */ - static bool WaitOnEvent(CEvent &event, unsigned int timeout = 100, bool allowCancel = true); + static bool WaitOnEvent(CEvent &event, unsigned int displaytime = 100, bool allowCancel = true); protected: virtual void Open_Internal(const std::string ¶m = ""); bool m_bCanceled; diff --git a/xbmc/pvr/PVRGUIActions.cpp b/xbmc/pvr/PVRGUIActions.cpp index 4a8c92a13c..e6f749da76 100644 --- a/xbmc/pvr/PVRGUIActions.cpp +++ b/xbmc/pvr/PVRGUIActions.cpp @@ -19,6 +19,7 @@ */ #include "Application.h" +#include "dialogs/GUIDialogBusy.h" #include "dialogs/GUIDialogKaiToast.h" #include "dialogs/GUIDialogNumeric.h" #include "dialogs/GUIDialogOK.h" @@ -51,6 +52,7 @@ #include "ServiceBroker.h" #include "settings/MediaSettings.h" #include "settings/Settings.h" +#include "threads/Thread.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" #include "utils/log.h" @@ -63,6 +65,68 @@ using namespace KODI::MESSAGING; namespace PVR { + class AsyncRecordingAction : private IRunnable + { + public: + bool Execute(const CFileItemPtr &item); + + protected: + AsyncRecordingAction() : m_bSuccess(false) {} + + private: + // IRunnable implementation + void Run() override; + + // the worker function + virtual bool DoRun(const CFileItemPtr &item) = 0; + + CFileItemPtr m_item; + bool m_bSuccess; + }; + + bool AsyncRecordingAction::Execute(const CFileItemPtr &item) + { + m_item = item; + CGUIDialogBusy::Wait(this, 100, false); + return m_bSuccess; + } + + void AsyncRecordingAction::Run() + { + m_bSuccess = DoRun(m_item); + + if (m_bSuccess) + g_PVRManager.TriggerRecordingsUpdate(); + } + + class AsyncRenameRecording : public AsyncRecordingAction + { + public: + AsyncRenameRecording(const std::string &strNewName) : m_strNewName(strNewName) {} + + private: + bool DoRun(const CFileItemPtr &item) override { return g_PVRRecordings->RenameRecording(*item, m_strNewName); } + std::string m_strNewName; + }; + + class AsyncDeleteRecording : public AsyncRecordingAction + { + private: + bool DoRun(const CFileItemPtr &item) override { return g_PVRRecordings->Delete(*item); } + }; + + class AsyncEmptyRecordingsTrash : public AsyncRecordingAction + { + private: + bool DoRun(const CFileItemPtr &item) override { return g_PVRRecordings->DeleteAllRecordingsFromTrash(); } + }; + + class AsyncUndeleteRecording : public AsyncRecordingAction + { + private: + bool DoRun(const CFileItemPtr &item) override { return g_PVRRecordings->Undelete(*item); } + }; + CPVRGUIActions& CPVRGUIActions::GetInstance() { static CPVRGUIActions instance; @@ -710,13 +774,12 @@ namespace PVR if (!CGUIKeyboardFactory::ShowAndGetInput(strNewName, CVariant{g_localizeStrings.Get(19041)}, false)) return false; - if (!g_PVRRecordings->RenameRecording(*item, strNewName)) + if (!AsyncRenameRecording(strNewName).Execute(item)) { CGUIDialogOK::ShowAndGetInput(CVariant{257}, CVariant{19111}); // "Error", "PVR backend error. Check the log for more information about this message." return false; } - g_PVRManager.TriggerRecordingsUpdate(); return true; } @@ -728,13 +791,12 @@ namespace PVR if (!ConfirmDeleteRecording(item)) return false; - if (!g_PVRRecordings->Delete(*item)) + if (!AsyncDeleteRecording().Execute(item)) { CGUIDialogOK::ShowAndGetInput(CVariant{257}, CVariant{19111}); // "Error", "PVR backend error. Check the log for more information about this message." return false; } - g_PVRManager.TriggerRecordingsUpdate(); return true; } @@ -755,10 +817,9 @@ namespace PVR if (!ConfirmDeleteAllRecordingsFromTrash()) return false; - if (!g_PVRRecordings->DeleteAllRecordingsFromTrash()) + if (!AsyncEmptyRecordingsTrash().Execute(CFileItemPtr())) return false; - g_PVRManager.TriggerRecordingsUpdate(); return true; } @@ -773,14 +834,12 @@ namespace PVR if (!item->IsDeletedPVRRecording()) return false; - /* undelete the recording */ - if (!g_PVRRecordings->Undelete(*item)) + if (!AsyncUndeleteRecording().Execute(item)) { CGUIDialogOK::ShowAndGetInput(CVariant{257}, CVariant{19111}); // "Error", "PVR backend error. Check the log for more information about this message." return false; } - g_PVRManager.TriggerRecordingsUpdate(); return true; } |