From 33f5fbf18d1b39a5a7737d8e818027af7965e957 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Thu, 20 Mar 2008 16:29:29 +0000 Subject: playlist support for the url dialog git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@286 90c681e8-e032-0410-971d-27865f9a5e38 --- src/ui/addurldialog.cpp | 48 ++++++++++++++++++++++++++++++- src/ui/addurldialog.h | 10 +++++++ src/ui/forms/addurldialog.ui | 67 +++++++++++++++++++++++++++++--------------- 3 files changed, 102 insertions(+), 23 deletions(-) diff --git a/src/ui/addurldialog.cpp b/src/ui/addurldialog.cpp index 6fab029ea..fd460ba01 100644 --- a/src/ui/addurldialog.cpp +++ b/src/ui/addurldialog.cpp @@ -20,7 +20,11 @@ #include #include +#include +#include +#include #include "addurldialog.h" +#include "playlistformat.h" #include "playlistmodel.h" #define HISTORY_SIZE 10 @@ -29,9 +33,14 @@ AddUrlDialog::AddUrlDialog( QWidget * parent, Qt::WindowFlags f) : QDialog(paren { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); + setAttribute(Qt::WA_QuitOnClose, FALSE); QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); m_history = settings.value("URLDialog/history").toStringList(); urlComboBox->addItems(m_history); + m_http = new QHttp(this); + connect(m_http, SIGNAL(requestFinished (int, bool)), SLOT(processResponse(int, bool))); + connect(m_http, SIGNAL(readyRead (const QHttpResponseHeader&)), + SLOT(readResponse(const QHttpResponseHeader&))); } AddUrlDialog::~AddUrlDialog() @@ -40,6 +49,7 @@ AddUrlDialog::~AddUrlDialog() m_history.removeLast(); QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); settings.setValue("URLDialog/history", m_history); + m_http->close(); } QPointer AddUrlDialog::instance = 0; @@ -62,9 +72,45 @@ void AddUrlDialog::accept( ) QString s = urlComboBox->currentText(); if (!s.startsWith("http://")) s.prepend("http://"); - m_model->addFile(s); m_history.removeAll(s); m_history.prepend(s); + //TODO this code should be removed + foreach(PlaylistFormat* prs, m_model->registeredPlaylistFormats()) + { + if (prs->hasFormat(QFileInfo(s).suffix().toLower())) + { + //download playlist; + QUrl url(s); + m_http->setHost(url.host(), url.port(80)); + m_http->get(url.path()); //TODO proxy support + addButton->setEnabled(FALSE); + return; + } + } + m_model->addFile(s); + } + QDialog::accept(); +} + +void AddUrlDialog::processResponse(int, bool error) +{ + if (error) + { + QMessageBox::critical (this, tr("Error"), m_http->errorString ()); + QDialog::accept(); + } +} + +void AddUrlDialog::readResponse(const QHttpResponseHeader&) +{ + QString s = urlComboBox->currentText(); + foreach(PlaylistFormat* prs, m_model->registeredPlaylistFormats()) + { + if (prs->hasFormat(QFileInfo(s).suffix().toLower())) + { + m_model->addFiles(prs->decode(m_http->readAll())); + break; + } } QDialog::accept(); } diff --git a/src/ui/addurldialog.h b/src/ui/addurldialog.h index e3bcdf22e..fdb0f61ce 100644 --- a/src/ui/addurldialog.h +++ b/src/ui/addurldialog.h @@ -25,8 +25,10 @@ #include #include +class QHttp; class PlayListModel; +class QHttpResponseHeader; /** @author Vladimir Kuznetsov @@ -37,16 +39,24 @@ class AddUrlDialog : public QDialog , private Ui::AddUrlDialog Q_OBJECT public: static void popup(QWidget* parent ,PlayListModel*); + protected: AddUrlDialog( QWidget * parent = 0, Qt::WindowFlags f = 0 ); ~AddUrlDialog(); + protected slots: virtual void accept(); + +private slots: + void processResponse(int, bool); + void readResponse(const QHttpResponseHeader&); + private: void setModel(PlayListModel*); static QPointer instance; PlayListModel* m_model; QStringList m_history; + QHttp *m_http; }; #endif //ADDURLDIALOG_H diff --git a/src/ui/forms/addurldialog.ui b/src/ui/forms/addurldialog.ui index 46031b849..64ac928fc 100644 --- a/src/ui/forms/addurldialog.ui +++ b/src/ui/forms/addurldialog.ui @@ -6,33 +6,56 @@ 0 0 394 - 80 + 77 Enter URL to add - - - 9 + + + 5 - - 6 + + 5 - + + 5 + + + 5 + + true - - + + Qt::Horizontal - - QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + 181 + 20 + + + + + + + + &Add + + + + + + + &Cancel @@ -41,34 +64,34 @@ - buttonBox - accepted() + addButton + clicked() AddUrlDialog accept() 248 - 254 + 51 - 157 - 274 + 184 + 72 - buttonBox - rejected() + cancelButton + clicked() AddUrlDialog reject() - 316 - 260 + 343 + 62 - 286 - 274 + 392 + 60 -- cgit v1.2.3-13-gbd6f