QYouTube
A Qt/C++ library and QML module to access the YouTube Data API.
 All Classes Functions Enumerations Properties Groups Pages
Public Slots | Signals | Public Member Functions | Properties | List of all members
QYouTube::ResourcesModel Class Reference

A list model for displaying YouTube resources. More...

Inheritance diagram for QYouTube::ResourcesModel:
QYouTube::Model

Public Slots

void list (const QString &resourcePath, const QStringList &part, const QVariantMap &filters=QVariantMap(), const QVariantMap &params=QVariantMap())
 Retrieves a list of YouTube resources belonging to resourcePath.
void insert (const QVariantMap &resource, const QStringList &part, const QVariantMap &params=QVariantMap())
 Inserts a new YouTube resource into the current resourcePath.
void insert (int row, const QString &resourcePath, const QStringList &part, const QVariantMap &params=QVariantMap())
 Inserts the YouTube resource at row into resourcePath.
void update (int row, const QVariantMap &resource, const QStringList &part)
 Updates the YouTube resource at row with resource.
void del (int row)
 Deletes the YouTube resource at row from the current resourcePath.
void del (int row, const QString &resourcePath)
 Deletes the YouTube resource at row from resourcePath.
void cancel ()
 Cancels the current request.
void reload ()
 Clears any existing data and retreives a new list of YouTube resources using the existing parameters.
- Public Slots inherited from QYouTube::Model
void clear ()
 Removes all items.

Signals

void apiKeyChanged ()
 Emitted when the apiKey changes.
void clientIdChanged ()
 Emitted when the clientId changes.
void clientSecretChanged ()
 Emitted when the clientSecret changes.
void accessTokenChanged (const QString &token)
 Emitted when the accessToken changes.
void refreshTokenChanged (const QString &token)
 Emitted when the refreshToken changes.
void statusChanged (QYouTube::ResourcesRequest::Status s)
 Emitted when the status changes.
- Signals inherited from QYouTube::Model
void countChanged (int c)
 Emitted when items are added/removed.

Public Member Functions

void setNetworkAccessManager (QNetworkAccessManager *manager)
 Sets the QNetworkAccessManager instance to be used when making requests to the YouTube Data API.
- Public Member Functions inherited from QYouTube::Model
int rowCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of items in the model.
QVariant data (const QModelIndex &index, int role) const
 Re-implemented from QAbstractListModel::data()
QMap< int, QVariant > itemData (const QModelIndex &index) const
 Re-implemented from QAbstractListModel::itemData()
bool setData (const QModelIndex &index, const QVariant &value, int role)
 Re-implemented from QAbstractListModel::setData()
bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 Re-implemented from QAbstractListModel::setItemData()
void append (const QMap< int, QVariant > &roles)
 Appends an item using the data in roles.
void insert (const QModelIndex &index, const QMap< int, QVariant > &roles)
 Inserts an item before index using the data in roles.
bool remove (const QModelIndex &index)
 Removes the item at index.
Q_INVOKABLE QVariantMap get (int row) const
 Returns the item at row.
Q_INVOKABLE bool setProperty (int row, const QString &property, const QVariant &value)
 Sets the property of the item at row to value.
Q_INVOKABLE bool set (int row, const QVariantMap &properties)
 Sets the properties of the item at row to properties.
Q_INVOKABLE void append (const QVariantMap &properties)
 Appends an item to the model using properties.
Q_INVOKABLE void insert (int row, const QVariantMap &properties)
 Inserts an item before row to the model using properties.
Q_INVOKABLE bool remove (int row)
 Removes the item at row.

Properties

QString apiKey
 The api key to be used when making requests to the YouTube Data API.
QString clientId
 The client id to be used when making requests to the YouTube Data API.
QString clientSecret
 The client secret to be used when making requests to the YouTube Data API.
QString accessToken
 The access token to be used when making requests to the YouTube Data API.
QString refreshToken
 The refresh token to be used when making requests to the YouTube Data API.
QYouTube::ResourcesRequest::Status status
 The current status of the model.
QVariant result
 The current result of the model.
QYouTube::ResourcesRequest::Error error
 The error type of the model.
QString errorString
 A description of the error of the model.
- Properties inherited from QYouTube::Model
int count
 The number of items in the model.

Detailed Description

A list model for displaying YouTube resources.

The ResourcesModel is a list model used for displaying YouTube resources in a list view. ResourcesModel provides the same methods that are available in ResourcesRequest, so it is better to simply use that class if you do not need the additional features provided by a data model.

Roles

The roles and role names of ResourcesModel are created dynamically when the model is populated with data. The roles are created by iterating through the keys of the first item in alphabetical order, starting at Qt::UserRole + 1. The role names are the keys themselves.

Example usage:

C++

using namespace QYouTube;
...
QListView *view = new QListView(this);
ResourcesModel *model = new ResourcesModel(this);
view->setModel(new ResourcesModel(this));
QVariantMap params;
params["maxResults"] = 10;
params["order"] = "date";
params["q"] = "Qt";
params["type"] = "video";
model->list("/search", QStringList() << "snippet", QVariantMap(), params);

QML

import QtQuick 1.0
import QYouTube 1.0
ListView {
id: view
width: 800
height: 480
model: ResourcesModel {
id: resourcesModel
}
delegate: Text {
width: view.width
height: 50
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
text: snippet.title
}
Component.onCompleted: resourcesModel.list("/search", ["snippet"], {},
{maxResults: 10, order: "date", q: "Qt", type: "video"})
}
See Also
ResourcesRequest

Member Function Documentation

void QYouTube::ResourcesModel::cancel ( )
slot

Cancels the current request.

See Also
ResourcesRequest::cancel()
void QYouTube::ResourcesModel::insert ( const QVariantMap &  resource,
const QStringList &  part,
const QVariantMap &  params = QVariantMap() 
)
slot

Inserts a new YouTube resource into the current resourcePath.

See Also
ResourcesRequest::insert()
void QYouTube::ResourcesModel::insert ( int  row,
const QString &  resourcePath,
const QStringList &  part,
const QVariantMap &  params = QVariantMap() 
)
slot

Inserts the YouTube resource at row into resourcePath.

See Also
ResourcesRequest::insert()
void QYouTube::ResourcesModel::list ( const QString &  resourcePath,
const QStringList &  part,
const QVariantMap &  filters = QVariantMap(),
const QVariantMap &  params = QVariantMap() 
)
slot

Retrieves a list of YouTube resources belonging to resourcePath.

See Also
ResourcesRequest::list()
void QYouTube::ResourcesModel::setNetworkAccessManager ( QNetworkAccessManager *  manager)

Sets the QNetworkAccessManager instance to be used when making requests to the YouTube Data API.

ResourcesModel does not take ownership of manager.

If no QNetworkAccessManager is set, one will be created when required.

See Also
ResourcesRequest::setNetworkAccessManager()

Property Documentation

QString QYouTube::ResourcesModel::accessToken
readwrite

The access token to be used when making requests to the YouTube Data API.

The access token is required when accessing a resource's protected resources.

See Also
ResourcesRequest::accessToken
QString QYouTube::ResourcesModel::apiKey
readwrite

The api key to be used when making requests to the YouTube Data API.

See Also
VideosRequest::apiKey
QString QYouTube::ResourcesModel::clientId
readwrite

The client id to be used when making requests to the YouTube Data API.

The client id is used only when the access token needs to be refreshed.

See Also
ResourcesRequest::clientId
QString QYouTube::ResourcesModel::clientSecret
readwrite

The client secret to be used when making requests to the YouTube Data API.

The client secret is used only when the access token needs to be refreshed.

See Also
ResourcesRequest::clientSecret
ResourcesRequest::Error QYouTube::ResourcesModel::error
read

The error type of the model.

See Also
ResourcesRequest::error
QString QYouTube::ResourcesModel::errorString
read

A description of the error of the model.

See Also
ResourcesRequest::status
QString QYouTube::ResourcesModel::refreshToken
readwrite

The refresh token to be used when making requests to the YouTube Data API.

The refresh token is used only when the accessToken needs to be refreshed.

See Also
ResourcesRequest::refreshToken
QVariant QYouTube::ResourcesModel::result
read

The current result of the model.

See Also
ResourcesRequest::result
ResourcesRequest::Status QYouTube::ResourcesModel::status
read

The current status of the model.

See Also
ResourcesRequest::status