example/sampleplugin/sampleplugin.h
changeset 6 c39a6cfd1fb9
parent 5 edb9dc8273d9
child 7 be09cf1f39dd
equal deleted inserted replaced
5:edb9dc8273d9 6:c39a6cfd1fb9
     1 #ifndef _SAMPLEPLUGIN_H
       
     2 #define _SAMPLEPLUGIN_H
       
     3 
       
     4 // Include files
       
     5 #include <QVariant>
       
     6 #include <qplugin.h>
       
     7 
       
     8 #include "smfglobal.h"
       
     9 #include "smfpicture.h"
       
    10 #include "smfcomment.h"
       
    11 #include "smfpluginbase.h"
       
    12 #include "smfproviderbase.h"
       
    13 #include "smfgalleryplugin.h"
       
    14 #include "smfpluginutil.h"
       
    15 
       
    16 
       
    17 // Forward declarations
       
    18 class SampleProviderBase;
       
    19 
       
    20 
       
    21 // Class declaration
       
    22 class SamplePlugin : public SmfGalleryPlugin
       
    23 {
       
    24 	Q_OBJECT
       
    25 	Q_INTERFACES( SmfGalleryPlugin )
       
    26 
       
    27 public:
       
    28 	/**
       
    29 	 * Constructor with default argument
       
    30 	 * @param aUtil The SmfPluginUtil instance. The plugins can 
       
    31 	 * call the method getAuthKeys() of this class, with its pluginID to 
       
    32 	 * get the OAuth keys, keys are returned only if this plugin is 
       
    33 	 * authorised by Smf franework
       
    34 	 */
       
    35 	SamplePlugin( SmfPluginUtil *aUtil );
       
    36 	
       
    37 	/**
       
    38 	 * Destructor
       
    39 	 */
       
    40 	~SamplePlugin( );
       
    41 	
       
    42 public: // From SmfGalleryPlugin
       
    43 	
       
    44 	/**
       
    45 	 * Method to get a list of pictures
       
    46 	 * @param aRequest [out] The request data to be sent to network
       
    47 	 * @param aPageNum The page to be extracted
       
    48 	 * @param aItemsPerPage Number of items per page
       
    49 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    50 	 */
       
    51 	SmfPluginError pictures( SmfPluginRequestData &aRequest, 
       
    52 			const int aPageNum = SMF_FIRST_PAGE, 
       
    53 			const int aItemsPerPage = SMF_ITEMS_PER_PAGE );
       
    54 	
       
    55 	/**
       
    56 	 * Method to get a description
       
    57 	 * @param aRequest [out] The request data to be sent to network
       
    58 	 * @param aImage The image abot which the description is required
       
    59 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    60 	 */
       
    61 	SmfPluginError description( SmfPluginRequestData &aRequest,
       
    62 			const SmfPicture &aImage );
       
    63 	
       
    64 	/**
       
    65 	 * Method to upload a picture
       
    66 	 * @param aRequest [out] The request data to be sent to network
       
    67 	 * @param aImage The image to be uploaded
       
    68 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    69 	 */
       
    70 	SmfPluginError upload( SmfPluginRequestData &aRequest,
       
    71 			const SmfPicture &aImage );
       
    72 	
       
    73 	/**
       
    74 	 * Method to upload a list of pictures
       
    75 	 * @param aRequest [out] The request data to be sent to network
       
    76 	 * @param aImages The list of images to be uploaded
       
    77 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    78 	 */
       
    79 	SmfPluginError upload( SmfPluginRequestData &aRequest,
       
    80 			const QList<SmfPicture> &aImages );
       
    81 	
       
    82 	/**
       
    83 	 * Method to post comment on a picture is available
       
    84 	 * @param aRequest [out] The request data to be sent to network
       
    85 	 * @param aImage The image on which comment is to be posted
       
    86 	 * @param aComment The comment to be posted
       
    87 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
    88 	 */
       
    89 	SmfPluginError postComment( SmfPluginRequestData &aRequest,
       
    90 			const SmfPicture &aImage, 
       
    91 			const SmfComment &aComment );
       
    92 	
       
    93 public: // From SmfPluginBase
       
    94 	/**
       
    95 	 * Method to get the provider information
       
    96 	 * @return Instance of SmfProviderBase
       
    97 	 */
       
    98 	SmfProviderBase* getProviderInfo( );
       
    99 	
       
   100 	/**
       
   101 	 * Method to get the result for a network request.
       
   102 	 * @param aTransportResult The result of transport operation
       
   103 	 * @param aReply The QNetworkReply instance for the request
       
   104 	 * @param aResult [out] An output parameter to the plugin manager.If the 
       
   105 	 * return value is SmfSendRequestAgain, QVariant will be of type 
       
   106 	 * SmfPluginRequestData.
       
   107 	 * For SmfGalleryPlugin: If last operation was pictures(), aResult will 
       
   108 	 * be of type QList<SmfPicture>. If last operation was description(), 
       
   109 	 * aResult will be of type QString. If last operation was upload() or 
       
   110 	 * postComment(), aResult will be of type bool.
       
   111 	 * @param aRetType [out] SmfPluginRetType
       
   112 	 * @param aPageResult [out] The SmfResultPage structure variable
       
   113 	 */
       
   114 	SmfPluginError responseAvailable( 
       
   115 			const SmfTransportResult &aTransportResult, 
       
   116 			QNetworkReply *aReply, 
       
   117 			QVariant* aResult, 
       
   118 			SmfPluginRetType &aRetType,
       
   119 			SmfResultPage &aPageResult );
       
   120 	
       
   121 private:
       
   122 	/**
       
   123 	 * Method called by plugins to generate a request data
       
   124 	 * @param aRequest [out] The request data to be sent to network
       
   125 	 * @param aOperation The type of http operation
       
   126 	 * @param aSignatureMethod The signature method to be used
       
   127 	 * @param aParams A map of parameters to its values
       
   128 	 * @param aMode The mode of creation of the request
       
   129 	 * @param aPostData The data to be posted (for HTTP POST 
       
   130 	 * only, else it will be NULL)
       
   131 	 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
       
   132 	 */
       
   133 	SmfPluginError createRequest( SmfPluginRequestData &aRequest,
       
   134 			const QNetworkAccessManager::Operation aOperation, 
       
   135 			const SmfSignatureMethod aSignatureMethod, 
       
   136 			QMultiMap<QByteArray, QByteArray> &aParams, 
       
   137 			const SmfParsingMode aMode,
       
   138 			QBuffer *aPostData );
       
   139 	/**
       
   140 	 * Function to retrieve registration token supplied by SMF to authentication app.
       
   141 	 */
       
   142 	QString retrievePrivateRegToken();
       
   143 private:
       
   144 	SampleProviderBase *m_provider;
       
   145 	SmfPluginUtil *m_util;
       
   146 };
       
   147 
       
   148 
       
   149 // Class declaration
       
   150 class SampleProviderBase : public SmfProviderBase
       
   151 	{
       
   152 	Q_OBJECT
       
   153 
       
   154 public:
       
   155 	/**
       
   156 	 * Constructor with default argument
       
   157 	 * @param aParent The parent object
       
   158 	 */
       
   159 	SampleProviderBase( QObject* aParent = 0 );
       
   160 	
       
   161 	/**
       
   162 	 * Copy Constructor
       
   163 	 * @param aOther The reference object
       
   164 	 */
       
   165 	SampleProviderBase( const SampleProviderBase &aOther );
       
   166 	
       
   167 	/**
       
   168 	 * Destructor
       
   169 	 */
       
   170 	~SampleProviderBase( );
       
   171 
       
   172 	/**
       
   173 	 * Method to get the Localisable name of the service.
       
   174 	 * @return The Localisable name of the service.
       
   175 	 */
       
   176 	QString serviceName( ) const;
       
   177 	
       
   178 	/**
       
   179 	 * Method to get the Logo of the service
       
   180 	 * @return The Logo of the service
       
   181 	 */
       
   182 	QImage serviceIcon( ) const;
       
   183 	
       
   184 	/**
       
   185 	 * Method to get the Readable service description
       
   186 	 * @return The Readable service description
       
   187 	 */
       
   188 	QString description( ) const;
       
   189 	
       
   190 	/**
       
   191 	 * Method to get the Website of the service
       
   192 	 * @return The Website of the service
       
   193 	 */
       
   194 	QUrl serviceUrl( ) const;
       
   195 	
       
   196 	/**
       
   197 	 * Method to get the URL of the Application providing this service
       
   198 	 * @return The URL of the Application providing this service
       
   199 	 */
       
   200 	QUrl applicationUrl( ) const;
       
   201 	
       
   202 	/**
       
   203 	 * Method to get the Icon of the application
       
   204 	 * @return The Icon of the application
       
   205 	 */
       
   206 	QImage applicationIcon( ) const;
       
   207 	
       
   208 	/**
       
   209 	 * Method to get the Plugin specific ID
       
   210 	 * @return The Plugin specific ID
       
   211 	 */
       
   212 	QString pluginId( ) const;
       
   213 	
       
   214 	/**
       
   215 	 * Method to get the ID of the authentication application 
       
   216 	 * for this service
       
   217 	 * @param aProgram The authentication application name
       
   218 	 * @param aArguments List of arguments required for authentication app
       
   219 	 * @param aMode Strting mode for authentication application
       
   220 	 * @return The ID of the authentication application 
       
   221 	 */
       
   222 	QString authenticationApp( QString &aProgram, QStringList & aArguments, 
       
   223 			QIODevice::OpenModeFlag aMode = QIODevice::ReadWrite ) const;
       
   224 	
       
   225 	/**
       
   226 	 * Method to get the unique registration ID provided by the 
       
   227 	 * Smf for authorised plugins
       
   228 	 * @return The unique registration ID/token provided by the Smf for 
       
   229 	 * authorised plugins
       
   230 	 */
       
   231 	QString smfRegistrationId( ) const;
       
   232 	
       
   233 	/**
       
   234 	 * Method to get the data usage of each plugin
       
   235 	 * @return The data usage structure
       
   236 	 */
       
   237 	SmfPluginDataUsage getDataUsage( ) const;
       
   238 	
       
   239 private:
       
   240 	/**
       
   241 	 * Method to update the data usage of this plugin. This method is called 
       
   242 	 * after the plugin sends request to Plugin manager and after it receives 
       
   243 	 * data from plugin manager.
       
   244 	 * @param aBytesSent The number of bytes sent, when this argument has 
       
   245 	 * some value other than 1, aBytesReceived should be zero.
       
   246 	 * @param aBytesReceived The number of bytes received, when this argument 
       
   247 	 * has some value other than 1, aBytesSent  should be zero.
       
   248 	 * @return Returns true if success else returns false
       
   249 	 */
       
   250 	bool updateDataUsage( const uint &aBytesSent, const uint &aBytesReceived );
       
   251 
       
   252 	friend class SamplePlugin;
       
   253 	
       
   254 private:
       
   255 	QString m_serviceName;
       
   256 	QImage m_serviceIcon;
       
   257 	QString m_description;
       
   258 	QUrl m_serviceUrl;
       
   259 	QUrl m_applicationUrl;
       
   260 	QImage m_applicationIcon;
       
   261 	QString m_pluginId;
       
   262 	QString m_authAppId;
       
   263 	QString m_smfRegToken;
       
   264 	SmfPluginDataUsage m_dataUsage;
       
   265 	};
       
   266 
       
   267 #endif /*_SAMPLEPLUGIN_H*/