diff options
author | Wolf Bergenheim <ext-wolf.2.bergenheim@nokia.com> | 2010-02-19 17:06:45 +0200 |
---|---|---|
committer | Wolf Bergenheim <ext-wolf.2.bergenheim@nokia.com> | 2010-02-19 17:06:45 +0200 |
commit | d6a687cdff25a69b3333a1e490934128b095f0db (patch) | |
tree | 22ad5401e417f5ab2706ae59f76ac5ebc74e9ed2 /libresourceqt | |
parent | da47faf6b036220e32e7ce90210530ba5ef9dc2b (diff) |
Changes based on Qt feedback. Removed addResources, it add no value
Diffstat (limited to 'libresourceqt')
-rw-r--r-- | libresourceqt/include/qt4/policy/audio-resource.h | 1 | ||||
-rw-r--r-- | libresourceqt/include/qt4/policy/resource-set.h | 57 | ||||
-rw-r--r-- | libresourceqt/include/qt4/policy/resource.h | 1 | ||||
-rw-r--r-- | libresourceqt/include/qt4/policy/resources.h | 12 | ||||
-rw-r--r-- | libresourceqt/src/audio-resource.cpp | 6 | ||||
-rw-r--r-- | libresourceqt/src/resource-set.cpp | 61 | ||||
-rw-r--r-- | libresourceqt/src/resources.cpp | 56 |
7 files changed, 86 insertions, 108 deletions
diff --git a/libresourceqt/include/qt4/policy/audio-resource.h b/libresourceqt/include/qt4/policy/audio-resource.h index a1c8443..99c2c7f 100644 --- a/libresourceqt/include/qt4/policy/audio-resource.h +++ b/libresourceqt/include/qt4/policy/audio-resource.h @@ -29,7 +29,6 @@ public: void setStreamTag(const QString &name, const QString &value); virtual ResourceType type() const; - virtual Resource * clone() const; private: QString group; quint32 pid; diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h index c6012c1..bc81b89 100644 --- a/libresourceqt/include/qt4/policy/resource-set.h +++ b/libresourceqt/include/qt4/policy/resource-set.h @@ -13,30 +13,34 @@ * * \section intro_section Introduction * - * This library is used to request resources from the Polict Resource Manager. + * This library is used to request resources from the Policy Resource Manager. * To use this library two classes are provided: \ref ResourcePolicy::Resource and * \ref ResourcePolicy::ResourceSet. * * \section library_use_section Library Usage * - * To use the Resource Policy Library, you first need to create a number of - * \ref Resource objects like this (given as an example of what a media player - * might want/need): + * To use the Resource Policy Library, you first need to create the + * \ref ResourcePolicy::ResourceSet like this: * \code - * ResourcePolicy::AudioResource *audioResource = new ResourcePolicy::AudioResource(); - * ResourcePolicy::VideoResource *audioResource = new ResourcePolicy::VideoResource(); - * videoResource->setOptional(); + * ResourcePolicy::ResourceSet *resources = new ResourcePolicy::ResourceSet("player"); * \endcode - * Then you need to create a \ref ResourcePolicy::ResourceSet like this: + * Then to add resources to the set use the \ref addResource() method to add + * resources to the \ref ResourceSet. Like this: * \code - * ResourcePolicy::ResourceSet *resources = new ResourcePolicy::ResourceSet("player"); - * resources->addResource(audioResource); - * resources->addResource(videoResource); + * resources->addResource(AudioPlaybackType); + * resources->addResource(VideoPlaybackType); + * \endcode + * If you want to pre-populate the AudioResource with the audio group (it is a good idea) + * and other oudio parameters you can create an audio object your self and then + * give that to the \ref ResourceSet. Note that you should NOT free this object. + * The \ref ResourceSet takes ownership of this pointer. + * \code + * ResourcePolicy::AudioResource *audioResource = new ResourcePolicy::AudioResource("fmradio"); + * resources->addResourceObject(audioResource); * \endcode - * The resource set now has control over the Resource object pointers. You can - * drop them, but should NOT delete them. Instead call the ResourcePolicy::ResourceSet::deleteResource() - * method. Then when you want to acquire the \ref ResourcePolicy::ResourceSet - * you simply use the \ref ResourcePolicy::ResourceSetacquire() method, like this: + * Calling the ResourcePolicy::ResourceSet::deleteResource() method will remove + * and delete the object. Then when you want to acquire the \ref ResourcePolicy::ResourceSet + * you simply use the \ref acquire() method, like this: * \code * QObject::connect(resources, SIGNAL(resourcesAcquired()), * this, SLOT(acquireOkHandler(QList<ResourcePolicy::Resource>))); @@ -50,6 +54,8 @@ * \endcode * This signal tells you when you should stop using the resources you have asked for. * So it is important that you connect to it. + * + * To modify the properties of the resources you can use the \ref resource() method. */ /** @@ -86,19 +92,20 @@ public: * This method adds a resource to the set. A set contains only a single * instance of a given resource. If the ResourceSet already contains a * resource of the given type it will be overridden. - * \param resource The resource to add to the set. A copy of this object + * \param resourceType The resource to add to the set. A copy of this object * is stored in the Set. */ - void addResource(Resource *resource); + bool addResource(ResourceType resourceType); + /** - * This method adds all resources in the list to the set. - * A set contains only a single instance of a given resource. If the - * ResourceSet already contains a resource of the given type it will be - * overridden. - * \param resources The list of resources to add to the set. These will - * be copied. - */ - void addResources(const QList<Resource *>resources); + * This method adds a resource to the set. A set contains only a single + * instance of a given resource. If the ResourceSet already contains a + * resource of the given type it will be overridden. + * \param resource The resource to add to the set. The \ref ResourseSet takes + * ownership of the pointer. Do NOT free! + */ + void addResourceObject(Resource *resource); + /** * This method removes the resource of the given type * \param type The type of the resource to remove from the set. diff --git a/libresourceqt/include/qt4/policy/resource.h b/libresourceqt/include/qt4/policy/resource.h index dd31a78..434f3dd 100644 --- a/libresourceqt/include/qt4/policy/resource.h +++ b/libresourceqt/include/qt4/policy/resource.h @@ -52,7 +52,6 @@ public: bool isGranted() const; virtual ResourceType type() const = 0; - virtual Resource * clone() const = 0; virtual ~Resource(); protected: Resource(); diff --git a/libresourceqt/include/qt4/policy/resources.h b/libresourceqt/include/qt4/policy/resources.h index 26ce014..c0d0eab 100644 --- a/libresourceqt/include/qt4/policy/resources.h +++ b/libresourceqt/include/qt4/policy/resources.h @@ -2,7 +2,6 @@ #define RESOURCES_H #include <policy/resource.h> -#include <QObject> #include <QString> namespace ResourcePolicy @@ -16,7 +15,6 @@ public: virtual ~AudioRecorderResource(); virtual ResourceType type() const; - virtual Resource * clone() const; private: QString group; quint32 pid; @@ -31,7 +29,6 @@ public: virtual ~BacklightResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; class LedsResource: public Resource @@ -42,7 +39,6 @@ public: virtual ~LedsResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; class VibraResource: public Resource @@ -53,7 +49,6 @@ public: virtual ~VibraResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; class VideoRecorderResource: public Resource @@ -64,7 +59,6 @@ public: virtual ~VideoRecorderResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; class VideoResource: public Resource @@ -75,7 +69,6 @@ public: virtual ~VideoResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; class SystemButtonResource: public Resource @@ -86,7 +79,6 @@ public: virtual ~SystemButtonResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; class LockButtonResource: public Resource @@ -97,7 +89,6 @@ public: virtual ~LockButtonResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; class ScaleButtonResource: public Resource @@ -108,7 +99,6 @@ public: virtual ~ScaleButtonResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; class SnapButtonResource: public Resource @@ -119,7 +109,6 @@ public: virtual ~SnapButtonResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; class LensCoverResource: public Resource @@ -130,7 +119,6 @@ public: virtual ~LensCoverResource(); virtual ResourceType type() const; - virtual Resource * clone() const; }; } #endif diff --git a/libresourceqt/src/audio-resource.cpp b/libresourceqt/src/audio-resource.cpp index f3c345e..10fe7e5 100644 --- a/libresourceqt/src/audio-resource.cpp +++ b/libresourceqt/src/audio-resource.cpp @@ -14,11 +14,6 @@ AudioResource::AudioResource(const AudioResource &other) { } -Resource * AudioResource::clone() const -{ - return new AudioResource(*this); -} - AudioResource::~AudioResource() { } @@ -86,4 +81,3 @@ ResourceType AudioResource::type() const { return AudioPlaybackType; } - diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp index 8d2668b..e45cb1c 100644 --- a/libresourceqt/src/resource-set.cpp +++ b/libresourceqt/src/resource-set.cpp @@ -18,9 +18,11 @@ ResourceSet::~ResourceSet() for (int i = 0;i < NumberOfTypes;i++) { delete resourceSet[i]; } - resourceEngine->disconnect(this); -// resourceEngine->disconnectFromManager(); - delete resourceEngine; + if(resourceEngine != NULL) { + resourceEngine->disconnect(this); + //resourceEngine->disconnectFromManager(); + delete resourceEngine; + } } bool ResourceSet::initialize() @@ -52,8 +54,10 @@ bool ResourceSet::initialize() return true; } -void ResourceSet::addResource(Resource *resource) +void ResourceSet::addResourceObject(Resource *resource) { + if(resource == NULL) + return; if (resource->type() == AudioPlaybackType) { qDebug("audioResource... %p", resource); audioResource = static_cast<AudioResource *>(resource); @@ -73,11 +77,54 @@ void ResourceSet::addResource(Resource *resource) resourceSet[resource->type()] = resource; } -void ResourceSet::addResources(const QList<Resource *>resources) +bool ResourceSet::addResource(ResourceType type) { - for (int i = 0; i < resources.size(); i++) { - addResource(resources.at(i)); + Resource *resource = NULL; + switch (type) { + case AudioPlaybackType: + resource = new AudioResource; + break; + case AudioRecorderType: + resource = new AudioRecorderResource; + break; + case VideoPlaybackType: + resource = new VideoResource; + break; + case VideoRecorderType: + resource = new VideoRecorderResource; + break; + case VibraType: + resource = new VibraResource; + break; + case LedsType: + resource = new LedsResource; + break; + case BacklightType: + resource = new BacklightResource; + break; + case SystemButtonType: + resource = new SystemButtonResource; + break; + case LockButtonType: + resource = new LockButtonResource; + break; + case ScaleButtonType: + resource = new ScaleButtonResource; + break; + case SnapButtonType: + resource = new SnapButtonResource; + break; + case LensCoverType: + resource = new LensCoverResource; + break; + default: + return false; + } + if (resource == NULL) { + return false; } + addResourceObject(resource); + return true; } void ResourceSet::deleteResource(ResourceType type) diff --git a/libresourceqt/src/resources.cpp b/libresourceqt/src/resources.cpp index f6a54d8..d0ac8f0 100644 --- a/libresourceqt/src/resources.cpp +++ b/libresourceqt/src/resources.cpp @@ -12,11 +12,6 @@ AudioRecorderResource::AudioRecorderResource(const AudioRecorderResource &other) { } -Resource * AudioRecorderResource::clone() const -{ - return new AudioRecorderResource(*this); -} - AudioRecorderResource::~AudioRecorderResource() { } @@ -36,11 +31,6 @@ VideoResource::VideoResource(const VideoResource &other) { } -Resource * VideoResource::clone() const -{ - return new VideoResource(*this); -} - VideoResource::~VideoResource() { } @@ -60,11 +50,6 @@ VideoRecorderResource::VideoRecorderResource(const VideoRecorderResource &other) { } -Resource * VideoRecorderResource::clone() const -{ - return new VideoRecorderResource(*this); -} - VideoRecorderResource::~VideoRecorderResource() { } @@ -84,11 +69,6 @@ VibraResource::VibraResource(const VibraResource &other) { } -Resource * VibraResource::clone() const -{ - return new VibraResource(*this); -} - VibraResource::~VibraResource() { } @@ -108,11 +88,6 @@ LedsResource::LedsResource(const LedsResource &other) { } -Resource * LedsResource::clone() const -{ - return new LedsResource(*this); -} - LedsResource::~LedsResource() { } @@ -132,11 +107,6 @@ BacklightResource::BacklightResource(const BacklightResource &other) { } -Resource * BacklightResource::clone() const -{ - return new BacklightResource(*this); -} - BacklightResource::~BacklightResource() { } @@ -156,11 +126,6 @@ SystemButtonResource::SystemButtonResource(const SystemButtonResource &other) { } -Resource * SystemButtonResource::clone() const -{ - return new SystemButtonResource(*this); -} - SystemButtonResource::~SystemButtonResource() { } @@ -180,11 +145,6 @@ LockButtonResource::LockButtonResource(const LockButtonResource &other) { } -Resource * LockButtonResource::clone() const -{ - return new LockButtonResource(*this); -} - LockButtonResource::~LockButtonResource() { } @@ -204,11 +164,6 @@ ScaleButtonResource::ScaleButtonResource(const ScaleButtonResource &other) { } -Resource * ScaleButtonResource::clone() const -{ - return new ScaleButtonResource(*this); -} - ScaleButtonResource::~ScaleButtonResource() { } @@ -228,11 +183,6 @@ SnapButtonResource::SnapButtonResource(const SnapButtonResource &other) { } -Resource * SnapButtonResource::clone() const -{ - return new SnapButtonResource(*this); -} - SnapButtonResource::~SnapButtonResource() { } @@ -252,11 +202,6 @@ LensCoverResource::LensCoverResource(const LensCoverResource &other) { } -Resource * LensCoverResource::clone() const -{ - return new LensCoverResource(*this); -} - LensCoverResource::~LensCoverResource() { } @@ -265,4 +210,3 @@ ResourceType LensCoverResource::type() const { return LensCoverType; } - |