2012-07-28 20:35:12 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
2012-11-28 14:43:03 +01:00
|
|
|
|
2012-07-28 20:35:12 +02:00
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2012-11-28 14:43:03 +01:00
|
|
|
|
2012-07-28 20:35:12 +02:00
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2012-11-28 14:43:03 +01:00
|
|
|
|
2012-07-28 20:35:12 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GOOGLEDRIVESTREAM_H
|
|
|
|
#define GOOGLEDRIVESTREAM_H
|
|
|
|
|
2012-11-28 14:43:03 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QList>
|
|
|
|
#include <QSslError>
|
2012-07-28 20:35:12 +02:00
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
#include <google/sparsetable>
|
|
|
|
#include <taglib/tiostream.h>
|
|
|
|
|
|
|
|
class QNetworkAccessManager;
|
|
|
|
|
2012-11-28 16:25:57 +01:00
|
|
|
class CloudStream : public QObject, public TagLib::IOStream {
|
2012-11-28 14:43:03 +01:00
|
|
|
Q_OBJECT
|
2012-07-28 20:35:12 +02:00
|
|
|
public:
|
2012-11-28 16:25:57 +01:00
|
|
|
CloudStream(const QUrl& url,
|
2012-07-28 20:35:12 +02:00
|
|
|
const QString& filename,
|
|
|
|
const long length,
|
|
|
|
const QString& auth,
|
|
|
|
QNetworkAccessManager* network);
|
|
|
|
|
|
|
|
// Taglib::IOStream
|
|
|
|
virtual TagLib::FileName name() const;
|
|
|
|
virtual TagLib::ByteVector readBlock(ulong length);
|
|
|
|
virtual void writeBlock(const TagLib::ByteVector&);
|
|
|
|
virtual void insert(const TagLib::ByteVector&, ulong, ulong);
|
|
|
|
virtual void removeBlock(ulong, ulong);
|
|
|
|
virtual bool readOnly() const;
|
|
|
|
virtual bool isOpen() const;
|
|
|
|
virtual void seek(long offset, TagLib::IOStream::Position p);
|
|
|
|
virtual void clear();
|
|
|
|
virtual long tell() const;
|
|
|
|
virtual long length();
|
|
|
|
virtual void truncate(long);
|
|
|
|
|
2012-07-30 13:41:29 +02:00
|
|
|
google::sparsetable<char>::size_type cached_bytes() const {
|
|
|
|
return cache_.num_nonempty();
|
|
|
|
}
|
|
|
|
|
|
|
|
int num_requests() const {
|
|
|
|
return num_requests_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use educated guess to request the bytes that TagLib will probably want.
|
|
|
|
void Precache();
|
|
|
|
|
2012-07-28 20:35:12 +02:00
|
|
|
private:
|
|
|
|
bool CheckCache(int start, int end);
|
|
|
|
void FillCache(int start, TagLib::ByteVector data);
|
|
|
|
TagLib::ByteVector GetCached(int start, int end);
|
|
|
|
|
2012-11-28 14:43:03 +01:00
|
|
|
private slots:
|
|
|
|
void SSLErrors(const QList<QSslError>& errors);
|
|
|
|
|
2012-07-28 20:35:12 +02:00
|
|
|
private:
|
|
|
|
const QUrl url_;
|
|
|
|
const QString filename_;
|
|
|
|
const QByteArray encoded_filename_;
|
|
|
|
const ulong length_;
|
|
|
|
const QString auth_;
|
|
|
|
|
|
|
|
int cursor_;
|
|
|
|
QNetworkAccessManager* network_;
|
|
|
|
|
|
|
|
google::sparsetable<char> cache_;
|
2012-07-30 13:41:29 +02:00
|
|
|
int num_requests_;
|
2012-07-28 20:35:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GOOGLEDRIVESTREAM_H
|