Example #1
0
void QtThumbnailManager::customEvent(QEvent* genericEvent) {
	Q_ASSERT(genericEvent->type() == QEvent::User);

	ThumbnailEvent* event = static_cast<ThumbnailEvent*>(genericEvent);

	QString path = event->_path;
	QFileInfo fileInfo(path);
	_map[path] = QPixmap::fromImage(event->_image);
	thumbnailUpdated(fileInfo);
}
Example #2
0
void YouTubeProvider::parserFinished(Joschy::AbstractJob *job)
{

    JOSCHY_DEBUG() << "parser finsihed....";

    Joschy::ResponseParser *parser = static_cast<Joschy::ResponseParser*>(job);
    const QString id = parser->id();
    const ResponseParser::Type type = m_actions.take(id);
    const QString errorString = parser->errorString();
    const Plugin::ErrorType errorType = parser->errorType();
    const bool hasError = parser->error();


    if (hasError) {
        emit error(id, errorType, errorString);
    } else {
        switch (type) {
        case ResponseParser::AuthenticationType: {
                m_tokens.insert(parser->login(), parser->token());
                emit authenticated(id);
                break;
            }
        case ResponseParser::UploadType: {
                emit uploadFinished(id, parser->getVideo());
                break;
            }
        case ResponseParser::SearchType: {
                QList<Joschy::Video> videos = parser->getVideos();
                emit searchFinished(id, videos);
                break;
            }
        case ResponseParser::UpdateThumbnailType: {
                const QString thumbnail = m_thumbnails.take(id);

                QFile file(thumbnail);
                if (!file.open(QIODevice::WriteOnly)) {
                    JOSCHY_DEBUG() << "open failed:" << thumbnail << file.errorString();
                    emit error(id, Plugin::CannotOpenError, file.errorString());
                } else {
                    if (file.write(parser->image()) == -1) {
                        file.close();
                        JOSCHY_DEBUG() << file.error() << file.errorString();
                        emit error(id, Plugin::UnknownError, file.errorString());
                    } else {
                        file.close();
                        emit thumbnailUpdated(id);
                    }
                }
                break;
            }
        case ResponseParser::UpdateCategorysType: {
                m_categorys = parser->getCategorys();

                QHash<QString, QVariant> hash;
                QHashIterator<QString, QString> it(m_categorys);
                while (it.hasNext()) {
                    it.next();
                    hash[it.key()] = it.value();
                }

                save("YouTube-Categorys", QVariant(hash));
                save("YouTube-CategoryDate", QVariant(QDateTime::currentDateTime()));

                emit categorysChanged(categorys());
                break;
            }
        default: break;
        }
    }
    m_parser.removeAll(parser);
    delete parser;
    layer()->freeId(id);

}