ProgressResource.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef PROGRESSRESOURCE_H__
00011 #define PROGRESSRESOURCE_H__
00012
00013 #include "ApplicationServices.h"
00014 #include "Progress.h"
00015 #include "Resource.h"
00016 #include "DesktopServices.h"
00017 #include "UtilityServices.h"
00018
00019 #include <string>
00020
00021
00022
00023
00024
00025
00026 class ProgressObject
00027 {
00028 public:
00029
00030
00031
00032 struct Args
00033 {
00034 bool mThreadSafe;
00035 bool mCreateDialog;
00036 std::string mCaption;
00037 Progress *mpProgress;
00038 Args(bool threadSafe, bool createDialog, const std::string &caption) :
00039 mThreadSafe(threadSafe), mCreateDialog(createDialog), mCaption(caption), mpProgress(NULL) {}
00040 Args(Progress *pProgress, bool createDialog, const std::string &caption) :
00041 mThreadSafe(false), mCreateDialog(createDialog), mCaption(caption), mpProgress(pProgress) {}
00042 };
00043
00044 Progress *obtainResource(const Args &args) const
00045 {
00046 Progress *pProgress = args.mpProgress;
00047 if (pProgress == NULL)
00048 {
00049 pProgress = Service<UtilityServices>()->getProgress(args.mThreadSafe);
00050 }
00051
00052 if (pProgress != NULL && args.mCreateDialog == true && Service<ApplicationServices>()->isInteractive() == true)
00053 {
00054 if (Service<DesktopServices>()->createProgressDialog(args.mCaption, pProgress) == false)
00055 {
00056 releaseResource(args, pProgress);
00057 pProgress = NULL;
00058 }
00059 }
00060
00061 return pProgress;
00062 }
00063
00064 void releaseResource(const Args &args, Progress *pProgress) const
00065 {
00066 Service<UtilityServices>()->destroyProgress(pProgress);
00067 }
00068 };
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 class ProgressResource : public Resource<Progress,ProgressObject>
00079 {
00080 public:
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 explicit ProgressResource(const std::string &caption = std::string(), bool threadSafe = false) :
00094 Resource<Progress,ProgressObject>(ProgressObject::Args(threadSafe,
00095 !caption.empty() && Service<ApplicationServices>()->isInteractive(), caption)) {}
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 explicit ProgressResource(Progress &progress, const std::string &caption = std::string()) :
00109 Resource<Progress,ProgressObject>(ProgressObject::Args(&progress,
00110 !caption.empty() && Service<ApplicationServices>()->isInteractive(), caption)) {}
00111 };
00112
00113 #endif