From 0c19b1730cae2062c9a796bd5c8d75e590ea8257 Mon Sep 17 00:00:00 2001 From: RJ Date: Wed, 6 Jan 2010 16:57:36 +0000 Subject: [PATCH] comet testing --- mainwindow.cpp | 45 +++++++++++++++++++++++++++++++----- mainwindow.h | 10 ++++++-- musickit.pro | 14 ++++++----- www/player/scripts/player.js | 17 +++++++++++--- 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 2772ed5..08f8eec 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -8,11 +8,15 @@ #include #include #include -#include -#include +#include +#include +#include +//#include +//#include -MainWindow::MainWindow(QWidget *parent) + +MainWindow::MainWindow() { /*QXmppLogger::getLogger()->setLoggingType(QXmppLogger::FILE); @@ -28,7 +32,7 @@ MainWindow::MainWindow(QWidget *parent) jabber->connectToServer(server, jid, pass); */ - setParent(parent); + source = 0; audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); mediaObject = new Phonon::MediaObject(this); @@ -56,8 +60,20 @@ MainWindow::MainWindow(QWidget *parent) connect(webkitApi, SIGNAL(stopRequested()), this, SLOT(stop())); connect(audioOutput, SIGNAL(volumeChanged(qreal)), this, SLOT(volumeChanged(qreal))); - QString url("./www/player/index.html"); + //QString url("http://localhost:8000/"); + QString url("file:///home/rj/src/musickit/www/player/index.html"); + //QString url("http://ideamonk.madetokill.com/bakabot/"); +/* + + webView->page()->currentFrame()->securityOrigin().addLocalScheme("http"); + webView->page()->currentFrame()->securityOrigin().addLocalScheme("ws"); + webView->page()->currentFrame()->securityOrigin().addLocalScheme("http:"); + webView->page()->currentFrame()->securityOrigin().addLocalScheme("ws:"); +*/ webView->load(QUrl(url)); + + qDebug() << "SEC:" << webView->page()->currentFrame()->securityOrigin().host() << ":" << + webView->page()->currentFrame()->securityOrigin().port(); } MainWindow::~MainWindow() @@ -66,11 +82,22 @@ MainWindow::~MainWindow() void MainWindow::setupUi() { + fileMenu = menuBar()->addMenu("&File"); + QAction * exAct = new QAction("E&xit", this); + connect(exAct, SIGNAL(triggered()), this, SLOT(close())); + + fileMenu->addAction(exAct); + + + QGridLayout *layout = new QGridLayout(); webView = new QWebView(); + webView->setPage(new Webpage); webView->settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,true); // needs QT >= 4.6 + webView->settings()->globalSettings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, true); + webView->settings()->globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); // QNetworkCookieJar jar; //QList cookies; @@ -90,7 +117,13 @@ void MainWindow::setupUi() */ //layout->setSpacing(0); layout->setContentsMargins(QMargins(0,0,0,0)); - setLayout(layout); + + QWidget *widget = new QWidget; + widget->setLayout(layout); + setCentralWidget(widget); + + + //setLayout(layout); show(); connect(playurlBtn, SIGNAL(clicked()), this, SLOT(on_streambutton_clicked())); diff --git a/mainwindow.h b/mainwindow.h index 684b893..cf68650 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "WebkitApi.h" @@ -22,12 +23,15 @@ class Webpage : public QWebPage } }; -class MainWindow : QWidget { +class MainWindow : QMainWindow { Q_OBJECT public: - MainWindow(QWidget *parent = 0); + MainWindow(); ~MainWindow(); friend class WebkitApi; + QSize sizeHint() const { + return QSize(800, 480); + } protected: void changeEvent(QEvent *e); @@ -56,6 +60,8 @@ private slots: QPushButton *playurlBtn; QPushButton *playfileBtn; QPushButton *reloadBtn; + QMenu * fileMenu; + void setupUi(); void play(QUrl); diff --git a/musickit.pro b/musickit.pro index 3a9f578..c0dd579 100644 --- a/musickit.pro +++ b/musickit.pro @@ -1,12 +1,7 @@ # ------------------------------------------------- # Project created by QtCreator 2009-12-22T13:28:55 # ------------------------------------------------- -QT += network \ - script \ - scripttools \ - webkit \ - xml \ - phonon +QT += webkit phonon TARGET = musickit TEMPLATE = app @@ -18,5 +13,12 @@ HEADERS += mainwindow.h \ +#QMAKE_LFLAGS += -static # to try and build everything (not just qt) statically + + +#CONFIG += static warn_off # for static qt + +#LIBS += -lgloox + # explicitly link to winsock (not sure why this is needed) #windows:LIBS += -lws2_32 diff --git a/www/player/scripts/player.js b/www/player/scripts/player.js index 2e23e33..323fbe2 100755 --- a/www/player/scripts/player.js +++ b/www/player/scripts/player.js @@ -1,3 +1,7 @@ +//if ("WebSocket" in window) alert('yes'); else alert('no'); + +function myalert(json) { alert( JSON.stringify(json) ); } + Player = function(){} Player.prototype = { @@ -10,6 +14,7 @@ Player.prototype = { Playdar.USE_STATUS_BAR=false; Playdar.USE_SCROBBLER = false; Playdar.MAX_POLLS = 20; + Playdar.USE_COMET = true; Playdar.setupClient({ onAuth: function () { @@ -87,6 +92,11 @@ Player.prototype = { p.play({'artist':'Mokele', 'track':'Hiding in your insides', 'url':'http://www.playdar.org/hiding.mp3'}, 'http://www.playdar.org/hiding.mp3'); }); + // toggle unplayable visibility + $('#rand').click(function(){ + $('tr.unplayable').toggleClass('hidden'); + }); + this.playlists = {}; // Wire up events from musickit container: @@ -208,8 +218,9 @@ $(document).ready(function(){ p.go(); var req = new XMLHttpRequest(); - req.open("GET", "http://ws.audioscrobbler.com/1.0/tag/metal/toptracks.xspf", false); - //req.open("GET", "toptracks.xspf", false); +// req.open("GET", "http://ws.audioscrobbler.com/1.0/tag/metal/toptracks.xspf", false); + //req.open("GET", "http://localhost:60210/static/toptracks.xspf", false); + req.open("GET", "file:///home/rj/src/playdar-core/priv/www/static/toptracks.xspf", false); req.send(""); var doc = req.responseXML;//.documentElement; var jspf = XSPF.toJSPF(doc); @@ -363,7 +374,7 @@ Playlist.prototype = { }) .find("td.track").text(trk.track).end() .find("td.artist").text(trk.artist).end() - .find("td.duration").text(Playdar.Util.mmss(trk.duration)).end() + .find("td.duration").text(Playdar.Util.mmss(parseInt(trk.duration))).end() .find("td.status").text("Searching").end() .find("td.alt").text('').end() .appendTo(this.list);