Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85ffe0d
Showing
20 changed files
with
1,166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import QtQuick 1.1 | ||
|
||
Item { | ||
id: delegate | ||
focus: true | ||
width: delegate.ListView.view.width | ||
height: 130 | ||
|
||
Image { | ||
id: thumb | ||
height: parent.height - 10; y: 5 | ||
width: 140 | ||
smooth: true | ||
source: image | ||
|
||
anchors { | ||
left: parent.left | ||
leftMargin: 5 | ||
topMargin: 5 | ||
} | ||
} | ||
|
||
Text { | ||
id: text | ||
text: title | ||
color: delegate.ListView.isCurrentItem ? "white" : "gray" | ||
wrapMode: Text.WordWrap | ||
font { family: "Helvetica"; pixelSize: 16; bold: true } | ||
|
||
anchors { | ||
top: thumb.top | ||
left: thumb.right | ||
leftMargin: 5 | ||
} | ||
} | ||
|
||
Text { | ||
id: desc | ||
text: description | ||
height: parent.height | ||
color: delegate.ListView.isCurrentItem ? "white" : "gray" | ||
font { family: "Helvetica"; pixelSize: 12 } | ||
wrapMode: Text.WordWrap | ||
anchors { | ||
top: text.bottom | ||
left: thumb.right | ||
bottom: thumb.bottom | ||
right: parent.right | ||
margins: 5, 5, 5, 5 | ||
} | ||
} | ||
|
||
MouseArea { | ||
anchors.fill: delegate | ||
onClicked: { | ||
delegate.ListView.view.currentIndex = index | ||
window.currentUrl = url | ||
window.currentThumb = image | ||
} | ||
} | ||
|
||
Keys.onReleased: { | ||
window.currentThumb = thumb | ||
|
||
if (event.key == Qt.Key_Return) { | ||
window.currentUrl = url | ||
} | ||
} | ||
|
||
Keys.onPressed: { | ||
window.ensureHudVisible(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
#include "Download.h" | ||
|
||
|
||
|
||
Download::Download(QObject *parent) | ||
: QObject(parent) | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef _Download_h | ||
#define _Download | ||
|
||
#include <QObject> | ||
#include <QNetworkReply> | ||
#include <QNetworkRequest> | ||
#include <QFile> | ||
|
||
|
||
|
||
class Download : public QObject | ||
{ | ||
public: | ||
explicit Download(QObject *parent = 0); | ||
|
||
public slots: | ||
|
||
private: | ||
Q_OBJECT | ||
|
||
QNetworkReply *reply; | ||
|
||
QFile *file; | ||
}; | ||
|
||
// Q_DECLARE_METATYPE(Download) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include "DownloadManager.h" | ||
|
||
|
||
|
||
DownloadManager::DownloadManager(QObject *parent) | ||
: QObject(parent) | ||
{ | ||
cache.setMaximumCacheSize(CACHE_SIZE); | ||
cache.setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation) + "/omnimedia"); | ||
manager.setCache(&cache); | ||
} | ||
|
||
void DownloadManager::append(const QStringList& urls) | ||
{ | ||
foreach (QUrl url, urls) { | ||
append(url, QString(url.toLocalFile())); | ||
} | ||
} | ||
|
||
void DownloadManager::append(const QUrl& url, const QString& filename) | ||
{ | ||
queue.enqueue(qMakePair(url, filename)); | ||
nextDownload(); | ||
} | ||
|
||
void DownloadManager::remove(const QString& filename) | ||
{ | ||
QFile *file = downloads[filename]; | ||
file->close(); | ||
file->deleteLater(); | ||
downloads.remove(filename); | ||
} | ||
|
||
void DownloadManager::nextDownload() | ||
{ | ||
if (downloads.size() < MAX_DOWNLOADS && !queue.empty()) { | ||
QPair<QUrl, QString> download = queue.dequeue(); | ||
QUrl url = download.first; | ||
QString filename = download.second; | ||
|
||
if (downloads.contains(filename)) | ||
return; | ||
|
||
QFile *file = new QFile(filename); | ||
|
||
if (!file->open(QIODevice::WriteOnly)) { | ||
qErrnoWarning("Error while opening %s for write", qPrintable(filename)); | ||
delete file; | ||
return; | ||
} | ||
|
||
QNetworkRequest request(url); | ||
request.setAttribute(QNetworkRequest::User, filename); | ||
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); | ||
|
||
QNetworkReply *reply = manager.get(request); | ||
connect(reply, SIGNAL(readyRead()), SLOT(readReady())); | ||
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(downloadProgress(qint64,qint64))); | ||
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(error(QNetworkReply::NetworkError))); | ||
connect(reply, SIGNAL(finished()), SLOT(finished())); | ||
|
||
downloads.insert(filename, file); | ||
} | ||
} | ||
|
||
void DownloadManager::readReady() | ||
{ | ||
if (QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender())) { | ||
QString filename = reply->request().attribute(QNetworkRequest::User).toString(); | ||
if (downloads.contains(filename)) { | ||
QFile *file = downloads.value(filename); | ||
file->write(reply->readAll()); | ||
} | ||
} | ||
} | ||
|
||
void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) | ||
{ | ||
Q_UNUSED(bytesReceived); | ||
Q_UNUSED(bytesTotal); | ||
} | ||
|
||
void DownloadManager::error(QNetworkReply::NetworkError code) | ||
{ | ||
Q_UNUSED(code); | ||
if (QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender())) { | ||
qErrnoWarning("Error!"); | ||
|
||
QString filename = reply->request().attribute(QNetworkRequest::User).toString(); | ||
remove(filename); | ||
reply->deleteLater(); | ||
} | ||
} | ||
|
||
void DownloadManager::finished() | ||
{ | ||
if (QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender())) { | ||
QString filename = reply->request().attribute(QNetworkRequest::User).toString(); | ||
remove(filename); | ||
reply->deleteLater(); | ||
|
||
nextDownload(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef _DownloadManager_h | ||
#define _DownloadManager_h | ||
|
||
#include <QObject> | ||
|
||
#include <QNetworkAccessManager> | ||
#include <QNetworkDiskCache> | ||
#include <QNetworkReply> | ||
#include <QFile> | ||
#include <QFileInfo> | ||
#include <QDesktopServices> | ||
#include <QQueue> | ||
#include <QFileInfo> | ||
#include <QStringList> | ||
#include <QVariant> | ||
#include <QPair> | ||
#include <QUrl> | ||
|
||
#define CACHE_SIZE 128 * 1024 * 1024 | ||
#define MAX_DOWNLOADS 16 | ||
|
||
|
||
|
||
class DownloadManager : public QObject | ||
{ | ||
public: | ||
explicit DownloadManager(QObject *parent = 0); | ||
|
||
public slots: | ||
void append(const QStringList& urls); | ||
void append(const QUrl& url, const QString& filename); | ||
void remove(const QString& filename); | ||
|
||
protected slots: | ||
void nextDownload(); | ||
void readReady(); | ||
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); | ||
void error(QNetworkReply::NetworkError code); | ||
void finished(); | ||
|
||
private: | ||
Q_OBJECT | ||
Q_DISABLE_COPY(DownloadManager) | ||
|
||
QNetworkAccessManager manager; | ||
QNetworkDiskCache cache; | ||
QQueue<QPair<QUrl, QString> > queue; | ||
QHash<QString, QFile *> downloads; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
#include "Instance.h" | ||
|
||
#include <vlc/vlc.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
|
||
|
||
MonoInstance Instance::m_instance; | ||
|
||
MonoInstance::MonoInstance() | ||
{ | ||
static const char * const argv[] = { | ||
"--intf=dummy", | ||
"--no-video-title-show", | ||
"--no-stats", | ||
"--no-snapshot-preview", | ||
"--verbose=1", | ||
}; | ||
|
||
setenv("VLC_PLUGIN_PATH", "/Users/Skhaz/Workspace/vlc/modules", 1); // XXX | ||
|
||
m_vlc_instance = libvlc_new(sizeof(argv) / sizeof(* argv), argv); | ||
} | ||
|
||
MonoInstance::~MonoInstance() | ||
{ | ||
libvlc_release(m_vlc_instance); | ||
} | ||
|
||
Instance::Instance() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
#ifndef _Instance_h | ||
#define _Instance_h | ||
|
||
|
||
|
||
struct libvlc_instance_t; | ||
|
||
class MonoInstance | ||
{ | ||
friend class Instance; | ||
|
||
MonoInstance(); | ||
|
||
~MonoInstance(); | ||
|
||
libvlc_instance_t * m_vlc_instance; | ||
}; | ||
|
||
class Instance | ||
{ | ||
public: | ||
Instance(); | ||
|
||
operator libvlc_instance_t *() { return m_instance.m_vlc_instance; } | ||
|
||
private: | ||
static MonoInstance m_instance; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
#include <QtGui> | ||
#include <QtDeclarative> | ||
#include <QGLWidget> | ||
|
||
#include "Player.h" | ||
|
||
#include "DownloadManager.h" | ||
|
||
#include <QtDebug> | ||
#include <QFile> | ||
#include <QtXmlPatterns> | ||
#include <QStringList> | ||
|
||
#include "Media.h" | ||
#include "MediaModel.h" | ||
|
||
#include "YouTubeSearch.h" | ||
|
||
|
||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication app(argc, argv); | ||
|
||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | ||
|
||
qmlRegisterType<Player>("OmniMedia", 1, 0, "Player"); | ||
|
||
QDeclarativeView view; | ||
QObject::connect(view.engine(), SIGNAL(quit()), qApp, SLOT(quit())); | ||
|
||
YouTubeSearch *youtube = new YouTubeSearch(&view); | ||
youtube->search("starcraft"); | ||
|
||
QDeclarativeContext *context = view.rootContext(); | ||
context->setContextProperty("youtubeModel", youtube->model()); | ||
|
||
view.setResizeMode(QDeclarativeView::SizeRootObjectToView); | ||
view.setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); | ||
view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); | ||
view.setSource(QUrl::fromLocalFile("Main.qml")); | ||
view.setWindowTitle("OmniMedia"); | ||
view.show(); | ||
|
||
return app.exec(); | ||
} |
Oops, something went wrong.