diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-12-22 19:16:29 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-12-22 19:16:29 +0000 |
| commit | aecf8592751e7beb682fcd5bc8c5b1d38335fa84 (patch) | |
| tree | cf267363944faafb7b29370d27f6ae19fbcc7647 /src/qmmpui/addurldialog.cpp | |
| parent | 954146ff9b69591f0cf3895e96922bb55ad88502 (diff) | |
| download | qmmp-aecf8592751e7beb682fcd5bc8c5b1d38335fa84.tar.gz qmmp-aecf8592751e7beb682fcd5bc8c5b1d38335fa84.tar.bz2 qmmp-aecf8592751e7beb682fcd5bc8c5b1d38335fa84.zip | |
libqmmpui: added URL dialog implementation, added PlayListDownloader
class
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3089 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui/addurldialog.cpp')
| -rw-r--r-- | src/qmmpui/addurldialog.cpp | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/qmmpui/addurldialog.cpp b/src/qmmpui/addurldialog.cpp new file mode 100644 index 000000000..cf845fe68 --- /dev/null +++ b/src/qmmpui/addurldialog.cpp @@ -0,0 +1,127 @@ +/*************************************************************************** + * Copyright (C) 2006-2012 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include <QSettings> +#include <QDir> +#include <QMessageBox> +#include <QClipboard> +#include <qmmpui/playlistparser.h> +#include <qmmpui/playlistformat.h> +#include <qmmpui/playlistmodel.h> +#include <qmmpui/playlistdownloader.h> +#include <qmmp/qmmpsettings.h> +#include <qmmp/metadatamanager.h> +#include <qmmp/qmmp.h> +#include "addurldialog_p.h" + +#define HISTORY_SIZE 10 + +AddUrlDialog::AddUrlDialog(QWidget *parent) : QDialog(parent) +{ + setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + setAttribute(Qt::WA_QuitOnClose, false); + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + m_history = settings.value("URLDialog/history").toStringList(); + urlComboBox->addItems(m_history); + if(settings.value("URLDialog/use_clipboard", false).toBool()) + { + QUrl url(QApplication::clipboard()->text().trimmed()); + if(url.isValid() && MetaDataManager::instance()->protocols().contains(url.scheme())) + urlComboBox->setEditText(QApplication::clipboard()->text().trimmed()); + } + m_downloader = new PlayListDownloader(this); + connect(m_downloader, SIGNAL(done(QStringList)), SLOT(add(QStringList))); + connect(m_downloader, SIGNAL(error(QString)), SLOT(showError(QString))); +} + +AddUrlDialog::~AddUrlDialog() +{ + while (m_history.size() > HISTORY_SIZE) + m_history.removeLast(); + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.setValue("URLDialog/history", m_history); +} + +QPointer<AddUrlDialog> AddUrlDialog::m_instance = 0; + +void AddUrlDialog::popup(QWidget* parent, PlayListModel* model) +{ + if (!m_instance) + { + m_instance = new AddUrlDialog(parent); + m_instance->setModel(model); + } + m_instance->show(); + m_instance->raise(); +} + +void AddUrlDialog::accept() +{ + addButton->setEnabled(false); + if(urlComboBox->currentText().isEmpty()) + { + QDialog::accept(); + return; + } + + QString s = urlComboBox->currentText().trimmed(); + + if(!s.startsWith("http://") && !s.contains("://")) + s.prepend("http://"); + + if(!MetaDataManager::instance()->protocols().contains(QUrl(s).scheme())) + { + qWarning("AddUrlDialog: unsupported protocol"); + QDialog::accept(); + return; + } + + m_history.removeAll(s); + m_history.prepend(s); + + if (s.startsWith("http://")) //try to download playlist + { + m_downloader->start(QUrl(s)); + return; + } + m_model->add(s); + QDialog::accept(); +} + +void AddUrlDialog::setModel(PlayListModel *m) +{ + m_model = m; +} + +void AddUrlDialog::add(const QStringList &urls) +{ + addButton->setEnabled(true); + m_model->add(urls); + QDialog::accept(); +} + +void AddUrlDialog::showError(const QString &message) +{ + QMessageBox::warning(this, tr("Error"), message); + addButton->setEnabled(true); +} + + |
