diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-03-20 16:29:29 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-03-20 16:29:29 +0000 |
| commit | 33f5fbf18d1b39a5a7737d8e818027af7965e957 (patch) | |
| tree | b582eea9a7f86e48a0966c3e41c51af816ace161 | |
| parent | a36551de052fab40e9392d2d9673e0d7859637d6 (diff) | |
| download | qmmp-33f5fbf18d1b39a5a7737d8e818027af7965e957.tar.gz qmmp-33f5fbf18d1b39a5a7737d8e818027af7965e957.tar.bz2 qmmp-33f5fbf18d1b39a5a7737d8e818027af7965e957.zip | |
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
| -rw-r--r-- | src/ui/addurldialog.cpp | 48 | ||||
| -rw-r--r-- | src/ui/addurldialog.h | 10 | ||||
| -rw-r--r-- | 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 <QSettings> #include <QDir> +#include <QHttp> +#include <QUrl> +#include <QMessageBox> #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> 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 <QDialog> #include <QPointer> +class QHttp; class PlayListModel; +class QHttpResponseHeader; /** @author Vladimir Kuznetsov <vovanec@gmail.com> @@ -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<AddUrlDialog> 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 @@ <x>0</x> <y>0</y> <width>394</width> - <height>80</height> + <height>77</height> </rect> </property> <property name="windowTitle" > <string>Enter URL to add</string> </property> - <layout class="QVBoxLayout" > - <property name="margin" > - <number>9</number> + <layout class="QGridLayout" > + <property name="leftMargin" > + <number>5</number> </property> - <property name="spacing" > - <number>6</number> + <property name="topMargin" > + <number>5</number> </property> - <item> + <property name="rightMargin" > + <number>5</number> + </property> + <property name="bottomMargin" > + <number>5</number> + </property> + <item row="0" column="0" colspan="3" > <widget class="QComboBox" name="urlComboBox" > <property name="editable" > <bool>true</bool> </property> </widget> </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox" > + <item row="1" column="0" > + <spacer> <property name="orientation" > <enum>Qt::Horizontal</enum> </property> - <property name="standardButtons" > - <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> + <property name="sizeHint" > + <size> + <width>181</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="1" > + <widget class="QPushButton" name="addButton" > + <property name="text" > + <string>&Add</string> + </property> + </widget> + </item> + <item row="1" column="2" > + <widget class="QPushButton" name="cancelButton" > + <property name="text" > + <string>&Cancel</string> </property> </widget> </item> @@ -41,34 +64,34 @@ <resources/> <connections> <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> + <sender>addButton</sender> + <signal>clicked()</signal> <receiver>AddUrlDialog</receiver> <slot>accept()</slot> <hints> <hint type="sourcelabel" > <x>248</x> - <y>254</y> + <y>51</y> </hint> <hint type="destinationlabel" > - <x>157</x> - <y>274</y> + <x>184</x> + <y>72</y> </hint> </hints> </connection> <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> + <sender>cancelButton</sender> + <signal>clicked()</signal> <receiver>AddUrlDialog</receiver> <slot>reject()</slot> <hints> <hint type="sourcelabel" > - <x>316</x> - <y>260</y> + <x>343</x> + <y>62</y> </hint> <hint type="destinationlabel" > - <x>286</x> - <y>274</y> + <x>392</x> + <y>60</y> </hint> </hints> </connection> |
