class WordleDialog : public QDialog
{
QTextEdit* output;
public:
WordleDialog( QWidget* parent = 0 ) : QDialog( parent )
{
new QVBoxLayout( this );
layout()->addWidget( output = new QTextEdit());
output->setReadOnly( true );
QLabel* hint;
layout()->addWidget( hint = new QLabel);
hint->setOpenExternalLinks( true );
hint->setTextFormat( Qt::RichText );
hint->setText( tr("We copied the wordlist to your clipboard already.
"
"So just visit Wordle Advanced and paste!
"
"Why not save your Wordle with username \"boffin\" and your
"
"Last.fm username as the title so we can start a community?
") );
QDialogButtonBox* buttons;
layout()->addWidget( buttons = new QDialogButtonBox( QDialogButtonBox::Ok ));
connect( buttons, SIGNAL(accepted()), SLOT( accept()));
buttons->button( QDialogButtonBox::Ok )->setText( tr("Close") );
setWindowTitle( tr("Your Wordlized Tags") );
}
void setText( const QString& t )
{
output->setText( t );
//output->selectAll(); //looks wrong
QApplication::clipboard()->setText( t );
}
};
#endif //WORDLE_DIALOG_H
================================================
FILE: app/boffin/XspfDialog.cpp
================================================
/***************************************************************************
* Copyright 2009 Last.fm Ltd. *
* *
* 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
#include
#include
#include "XspfDialog.h"
#include "XspfReader.h"
#include "playdar/PlaydarConnection.h"
#include "playdar/TrackResolveRequest.h"
#include "playdar/BoffinPlayableItem.h"
XspfDialog::XspfDialog(QString path, PlaydarConnection* playdar, QWidget *parent)
:QDialog(parent)
,m_playdar(playdar)
{
QLayout* layout = new QHBoxLayout();
m_treewidget = new QTreeWidget();
m_treewidget->setColumnCount(12);
QStringList labels;
labels << "Position" << "Artist" << "Album" << "Title" << "Length" << "Url"
<< "Score" << "Pref" << "Source" << "Bitrate" << "Size" << "Mimetype";
m_treewidget->setHeaderLabels(labels);
layout->addWidget(m_treewidget);
setLayout(layout);
setSizeGripEnabled(true);
m_reader = new XspfReader(path);
connect(m_reader, SIGNAL(xspf(lastfm::Xspf)), SLOT(onXspf(lastfm::Xspf)));
}
void
XspfDialog::onXspf(const lastfm::Xspf& xspf)
{
setWindowTitle(xspf.title());
int i = 0;
foreach(const lastfm::Track& t, xspf.tracks()) {
TrackResolveRequest* req = m_playdar->trackResolve(t.artist(), t.album(), t.title());
QTreeWidgetItem* item = new QTreeWidgetItem();
m_reqmap[req->qid()] = item;
item->setData(0, Qt::DisplayRole, QString::number(i));
item->setData(1, Qt::DisplayRole, (QString)t.artist());
item->setData(2, Qt::DisplayRole, (QString)t.album());
item->setData(3, Qt::DisplayRole, (QString)t.title());
item->setData(4, Qt::DisplayRole, t.duration());
item->setData(5, Qt::DisplayRole, t.url().toString());
m_treewidget->addTopLevelItem(item);
connect(req, SIGNAL(result(BoffinPlayableItem)), SLOT(onResolveResult(BoffinPlayableItem)));
i++;
}
}
void
XspfDialog::onResolveResult(const BoffinPlayableItem& item)
{
TrackResolveRequest* req = qobject_cast(sender());
if (req) {
QMap::const_iterator it = m_reqmap.constFind(req->qid());
if (it != m_reqmap.constEnd()) {
QTreeWidgetItem* child = new QTreeWidgetItem();
child->setFirstColumnSpanned(true);
child->setData(1, Qt::DisplayRole, item.artist());
child->setData(2, Qt::DisplayRole, item.album());
child->setData(3, Qt::DisplayRole, item.track());
child->setData(4, Qt::DisplayRole, item.duration());
child->setData(5, Qt::DisplayRole, item.url());
child->setData(6, Qt::DisplayRole, item.score());
child->setData(7, Qt::DisplayRole, item.preference());
child->setData(8, Qt::DisplayRole, item.source());
child->setData(9, Qt::DisplayRole, item.bitrate());
child->setData(10, Qt::DisplayRole, item.size());
child->setData(11, Qt::DisplayRole, item.mimetype());
it.value()->addChild(child);
} else {
qDebug() << "unknown qid " << req->qid();
}
}
}
================================================
FILE: app/boffin/XspfDialog.h
================================================
/***************************************************************************
* Copyright 2009 Last.fm Ltd. *
* *
* 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. *
***************************************************************************/
#ifndef XSPF_DIALOG_H
#define XSPF_DIALOG_H
#include
#include
#include
class QTreeWidget;
class QTreeWidgetItem;
class XspfReader;
class PlaydarConnection;
class BoffinPlayableItem;
class XspfDialog : public QDialog
{
Q_OBJECT
public:
XspfDialog(QString url, PlaydarConnection* playdar, QWidget *parent = 0);
private slots:
void onXspf(const lastfm::Xspf& xspf);
void onResolveResult(const BoffinPlayableItem& item);
private:
XspfReader* m_reader;
QTreeWidget* m_treewidget;
PlaydarConnection* m_playdar;
QMap m_reqmap; // map request qid to index
};
#endif
================================================
FILE: app/boffin/XspfReader.cpp
================================================
/***************************************************************************
* Copyright 2005-2009 Last.fm Ltd. *
* *
* 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 "XspfReader.h"
#include
#include
#include
XspfReader::XspfReader(QUrl url)
: m_url(url)
{
m_reply = (new lastfm::NetworkAccessManager(this))->get(QNetworkRequest(m_url));
connect(m_reply, SIGNAL(finished()), SLOT(onFinished()));
}
void
XspfReader::onFinished()
{
QDomDocument xmldoc;
xmldoc.setContent(m_reply);
QDomElement docElement(xmldoc.documentElement());
if (docElement.tagName() == "playlist") {
handleXspf(docElement);
} else if (docElement.tagName() == "lfm") {
handleXspf(docElement.firstChildElement("playlist"));
} else {
// todo
}
m_reply->deleteLater();
m_reply = 0;
}
void
XspfReader::handleXspf(const QDomElement& playlistElement)
{
Xspf xspf(playlistElement);
emit XspfReader::xspf(xspf);
}
================================================
FILE: app/boffin/XspfReader.h
================================================
/***************************************************************************
* Copyright 2005-2009 Last.fm Ltd. *
* *
* 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. *
***************************************************************************/
#ifndef XSPF_READER
#define XSPF_READER
#include
#include
class XspfReader : public QObject
{
Q_OBJECT
QUrl m_url;
class QNetworkReply *m_reply;
QList