aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp b/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp
index 60a1c27bd..997867caa 100644
--- a/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp
+++ b/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008 by Ilya Kotov *
+ * Copyright (C) 2008-2009 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -59,7 +59,7 @@ QStringList XSPFPlaylistFormat::decode(const QString & contents)
{
QUrl url (child.firstChildElement("location").text());
if (url.scheme() == "file") //remove scheme for local files only
- out << url.toString(QUrl::RemoveScheme);
+ out << QUrl::fromPercentEncoding(url.toString(QUrl::RemoveScheme).toAscii());
else
out << url.toString();
child = child.nextSiblingElement();
@@ -75,7 +75,7 @@ QString XSPFPlaylistFormat::encode(const QList<AbstractPlaylistItem*> & files)
QDomDocument doc;
QDomElement root = doc.createElement("playlist");
root.setAttribute("version",QString("1"));
- root.setAttribute("xmlns",QString("http://xspf.org/ns/0"));
+ root.setAttribute("xmlns",QString("http://xspf.org/ns/0/"));
QDomElement creator = doc.createElement("creator");
QDomText text = doc.createTextNode("qmmp-" + QString(QMMP_STR_VERSION));
@@ -92,9 +92,10 @@ QString XSPFPlaylistFormat::encode(const QList<AbstractPlaylistItem*> & files)
QDomElement ch = doc.createElement("location");
QDomText text;
if (f->url().contains("://"))
- text = doc.createTextNode(f->url());
+ text = doc.createTextNode(QUrl::toPercentEncoding(f->url(), ":/"));
else //append protocol
- text = doc.createTextNode(QString("file://") + QFileInfo(f->url()).absoluteFilePath());
+ text = doc.createTextNode(QUrl::toPercentEncoding(QString("file://") +
+ QFileInfo(f->url()).absoluteFilePath(), ":/"));
ch.appendChild(text);
track.appendChild(ch);
@@ -103,12 +104,28 @@ QString XSPFPlaylistFormat::encode(const QList<AbstractPlaylistItem*> & files)
ch.appendChild(text);
track.appendChild(ch);
+ ch = doc.createElement("creator");
+ text = doc.createTextNode(f->artist());
+ ch.appendChild(text);
+ track.appendChild(ch);
+
+ ch = doc.createElement("annotation");
+ text = doc.createTextNode(f->comment());
+ ch.appendChild(text);
+ track.appendChild(ch);
+
+ ch = doc.createElement("album");
+ text = doc.createTextNode(f->album());
+ ch.appendChild(text);
+ track.appendChild(ch);
+
ch = doc.createElement("trackNum");
text = doc.createTextNode(QString::number(counter));
ch.appendChild(text);
track.appendChild(ch);
- ch = doc.createElement("year");
+ ch = doc.createElement("meta");
+ ch.setAttribute("rel", "year");
text = doc.createTextNode(f->year());
ch.appendChild(text);
track.appendChild(ch);
d='n244' href='#n244'>244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
/***************************************************************************
 *   Copyright (C) 2006 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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <QPixmap>
#include <QResizeEvent>
#include <QPainter>
#include <QFont>
#include <QFontMetrics>
#include <QSettings>
#include <QMenu>
#include <QUrl>
#include <QApplication>

#include "mediafile.h"
#include "textscroller.h"
#include "listwidget.h"
#include "skin.h"
#include "playlistmodel.h"
#include "playlist.h"

#define INVALID_ROW -1

ListWidget::ListWidget(QWidget *parent)
        : QWidget(parent)
{
    m_update = FALSE;
    m_skin = Skin::getPointer();
    loadColors();
    setWindowFlags(Qt::FramelessWindowHint);
    m_menu = new QMenu(this);
    m_scroll_direction = NONE;
    m_prev_y = 0;
	 m_anchor_row = INVALID_ROW;

    m_first = 0;
    m_rows = 0;
    m_scroll = FALSE;
    m_select_on_release = FALSE;
    readSettings();
    connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin()));
    setAcceptDrops(true);
}


ListWidget::~ListWidget()
{}

void ListWidget::readSettings()
{
    QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat);
    QString fontname = settings.value("PlayList/Font","").toString();
    if (fontname.isEmpty ())
        fontname = QFont("Helvetica [Cronyx]", 10).toString();
    m_font.fromString(fontname);

    if (m_update)
    {
        delete m_metrics;
        m_metrics = new QFontMetrics(m_font);
        m_rows = (height() - 10) / m_metrics->ascent ();
        updateList();
    }
    else
    {
        m_update = TRUE;
        m_metrics = new QFontMetrics(m_font);
    }
}

void ListWidget::loadColors()
{
    m_normal.setNamedColor(m_skin->getPLValue("normal"));
    m_current.setNamedColor(m_skin->getPLValue("current"));
    m_normal_bg.setNamedColor(m_skin->getPLValue("normalbg"));
    m_selected_bg.setNamedColor(m_skin->getPLValue("selectedbg"));
}

void ListWidget::paintEvent(QPaintEvent *)
{

    QPainter m_painter(this);
    //m_painter.setPen(Qt::white);
    m_painter.setFont(m_font);
    m_painter.setBrush(QBrush(m_normal_bg));
    m_painter.drawRect(-1,-1,width()+1,height()+1);



    for (int i=0; i<m_titles.size(); ++i )
    {
        if (m_model->isSelected(i + m_first))
        {
            m_painter.setBrush(QBrush(m_selected_bg));
            m_painter.setPen(m_selected_bg);
            m_painter.drawRect ( 6, 15+(i-1)*m_metrics->ascent(),
                                 width() - 10, m_metrics->ascent());
        }

        if (m_model->currentRow() == i + m_first)
            m_painter.setPen(m_current);
        else
            m_painter.setPen(m_normal);  //243,58

        m_painter.drawText(10,14+i*m_metrics->ascent(),m_titles.at(i));

        if (m_model->isQueued(m_model->item(i + m_first)))
        {
            QString queue_string = "|" +
                                   QString::number(1 + m_model->queuedIndex(m_model->item(m_first + i))) + "|";

            int old_size = m_font.pointSize();
            m_font.setPointSize(old_size - 1 );
            m_painter.setFont(m_font);

            m_painter.drawText(width() - 10 - m_metrics->width(queue_string) - m_metrics->width(m_times.at(i)), 12+i*m_metrics->ascent (), queue_string);

            m_font.setPointSize(old_size);
            m_painter.setFont(m_font);


            m_painter.setBrush(QBrush(Qt::transparent));
            //m_painter.drawRect(width() - 10 - m_metrics->width(queue_string) - m_metrics->width(m_times.at(i)),
            //              /*14+*/i*m_metrics->ascent () + 3,10,12);
            m_painter.setBrush(QBrush(m_normal_bg));
        }


        m_painter.drawText(width() - 7 - m_metrics->width(m_times.at(i)),
                           14+i*m_metrics->ascent (), m_times.at(i));

    }

}

void ListWidget::mouseDoubleClickEvent (QMouseEvent *e)
{
    int y = e->y();
    int row = rowAt(y);
    if (INVALID_ROW != row)
    {
        m_model->setCurrent(row);
        emit selectionChanged();
        update();
    }
}


void ListWidget::mousePressEvent(QMouseEvent *e)
{
    m_scroll = TRUE;
    int y = e->y();
    int row = rowAt(y);

    if (INVALID_ROW != row && m_model->count() > row)
    {
        if (!(Qt::ControlModifier & e->modifiers () ||
                Qt::ShiftModifier & e->modifiers () ||
                m_model->isSelected(row)))
            m_model->clearSelection();

        if (m_model->isSelected(row) && (e->modifiers() == Qt::NoModifier))
            m_select_on_release = TRUE;
		  
		  //qWarning("m_prev_clicked_row: %d",m_prev_clicked_row);
		  
        m_pressed_row = row;
        if ((Qt::ShiftModifier & e->modifiers()))
        {
			  
			  if(m_pressed_row > m_anchor_row)
			  {
				  //int upper_selected = m_model->firstSelectedUpper(m_anchor_row);
				  //if (INVALID_ROW != upper_selected)
				  //{
					  /*for (int j = upper_selected;j < m_anchor_row;j++)
					  {
						  m_model->setSelected(j, false);
					  }*/
					  m_model->clearSelection();
					  for (int j = m_anchor_row;j <= m_pressed_row;j++)
					  {
						  m_model->setSelected(j, true);
					  }
				  //}
			  }
			  else
			  {
				  m_model->clearSelection();
				  for (int j = m_anchor_row;j >= m_pressed_row;j--)
				  {
					  m_model->setSelected(j, true);
				  }
			  }
			  
			  /*
            int upper_selected = m_model->firstSelectedUpper(row);
            int lower_selected = m_model->firstSelectedLower(row);
            if (INVALID_ROW != upper_selected)
            {
                for (int j = upper_selected;j <= row;j++)
                {
                    m_model->setSelected(j, true);
                }
            }
            else if (INVALID_ROW != lower_selected)
            {
                for (int j = row;j <= lower_selected;j++)
                {
                    m_model->setSelected(j, true);
                }
            }
            else
                m_model->setSelected(row, true);
			  */
        }
        else
        {
            if (!m_model->isSelected(row) || (Qt::ControlModifier & e->modifiers()))
                m_model->setSelected(row, !m_model->isSelected(row));
        }
		  
		  if(m_model->getSelection(m_pressed_row).count() == 1)
			  m_anchor_row = m_pressed_row;
		  //qWarning("m_anchor_row: %d",m_anchor_row);
		  
        update();
    }
    QWidget::mousePressEvent(e);
}

void ListWidget::resizeEvent(QResizeEvent *e)
{
    m_rows = (e->size().height() - 10) / m_metrics->ascent ();

    m_scroll = TRUE;

    updateList();
    QWidget::resizeEvent(e);
}

void ListWidget::wheelEvent (QWheelEvent *e)
{
    if (m_model->count() <= m_rows)
        return;
    if ((m_first == 0 && e->delta() > 0) ||
            ((m_first == m_model->count() - m_rows) && e->delta() < 0))
        return;
    m_first -= e->delta()/40;  //40*3 TODO: add step to config
    if (m_first < 0)
        m_first = 0;

    if (m_first > m_model->count() - m_rows)
        m_first = m_model->count() - m_rows;

    m_scroll = FALSE;
    updateList();
}

void ListWidget::updateList()
{
    if (m_model->count() < (m_rows+m_first+1) && m_rows< m_model->count())
    {
        m_first = m_model->count() - m_rows;
    }
    if (m_model->count() < m_rows + 1)
    {
        m_first = 0;
        emit positionChanged(0,0);
    }
    else
    {
        //int pos = m_first*99/(m_model->count() - m_rows);
        //emit positionChanged(pos);
        emit positionChanged(m_first, m_model->count() - m_rows);
    }
    if (m_model->count() <= m_first)
    {
        m_first = 0;
        emit positionChanged(0, qMax(0, m_model->count() - m_rows));
    }

    m_titles = m_model->getTitles(m_first, m_rows );
    m_times  = m_model->getTimes(m_first, m_rows );
    m_scroll = FALSE;
    //add numbers
    for (int i = 0; i < m_titles.size(); ++i)
    {
        QString title = m_titles.at(i);
        m_titles.replace(i, title.prepend(QString("%1").arg(m_first+i+1)+". "));

    }
    if (m_model->currentItem())
    {
        TextScroller::getPointer()->setText("***  "+m_model->currentItem()->title());
        parentWidget()->parentWidget()->setWindowTitle(m_model->currentItem()->title());
    }
    cut();
    update();
}

void ListWidget::setModel(PlayListModel *model)
{
    m_model = model;
    connect (m_model, SIGNAL(listChanged()), SLOT(updateList()));
    connect (m_model, SIGNAL(currentChanged()), SLOT(recenterCurrent()));
    updateList();
}

void ListWidget::scroll(int sc)
{
    if (m_model->count() <= m_rows)
        return;
    m_first = sc; //*(m_model->count() - m_rows)/99;
    m_scroll = TRUE;
    updateList();
}

void ListWidget::cut()
{
    bool cut;
    for (int i=0; i<m_titles.size(); ++i )
    {
        QString name;
        cut = FALSE;

        int queue_number_space = 0;
        if (m_model->isQueued(m_model->item(i + m_first)))
        {
            int index = m_model->queuedIndex(m_model->item(m_first + i));
            QString queue_string = "|"+QString::number(index)+"|";
            queue_number_space = m_metrics->width(queue_string);
        }
        while ( m_metrics->width(m_titles.at(i)) > (this->width() - 54 - queue_number_space))
        {
            cut = TRUE;
            name = m_titles.at(i);
            m_titles.replace(i, name.left(name.length()-1) );
        }
        if (cut)
        {
            m_titles.replace(i, name.left(name.length()-3).trimmed()+"...");