1
/* ============================================================
3
* This file is a part of kipi-plugins project
4
* http://www.kipi-plugins.org
7
* Description : a kipi plugin to slide images.
9
* Copyright (C) 2008-2009 by Valerio Fuoglio <valerio dot fuoglio at gmail dot com>
10
* Copyright (C) 2009 by Andi Clemens <andi dot clemens at gmx dot net>
12
* This program is free software; you can redistribute it
13
* and/or modify it under the terms of the GNU General
14
* Public License as published by the Free Software Foundation;
15
* either version 2, or (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* ============================================================ */
24
#include "listsounditems.moc"
33
#include <QDragEnterEvent>
40
#include <kiconloader.h>
41
#include <kmessagebox.h>
44
namespace KIPIAdvancedSlideshowPlugin
47
SoundItem::SoundItem(QListWidget* parent, const KUrl& url)
48
: QListWidgetItem(parent)
51
setIcon(SmallIcon("audio-x-generic", KIconLoader::SizeLarge, KIconLoader::DisabledState));
53
m_totalTime = QTime(0, 0, 0);
54
m_mediaObject = new Phonon::MediaObject();
55
m_mediaObject->setCurrentSource(url);
57
connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
58
this, SLOT(slotMediaStateChanged(Phonon::State,Phonon::State)));
61
SoundItem::~SoundItem()
65
KUrl SoundItem::url() const
70
void SoundItem::setName(const QString& text)
75
QString SoundItem::artist() const
80
QString SoundItem::title() const
85
QTime SoundItem::totalTime() const
90
void SoundItem::slotMediaStateChanged(Phonon::State newstate, Phonon::State /*oldstate*/)
92
if ( newstate == Phonon::ErrorState )
94
KMessageBox::detailedError( (QWidget*)(this),
95
i18n("%1 is damaged and may not be playable.", m_url.fileName()),
96
m_mediaObject->errorString(),
99
m_artist = m_url.fileName();
100
m_title = i18n("This file is damaged and may not be playable.");
101
setText(artist().append(" - ").append(title()));
102
setBackground(QBrush(Qt::red));
103
setForeground(QBrush(Qt::white));
104
QFont errorFont = font();
105
errorFont.setBold(true);
106
errorFont.setItalic(true);
111
if ( newstate != Phonon::StoppedState )
114
long int total = m_mediaObject->totalTime();
115
int hours = (int)(total / (long int)( 60 * 60 * 1000 ));
116
int mins = (int)((total / (long int)( 60 * 1000 )) - (long int)(hours * 60));
117
int secs = (int)((total / (long int)1000) - (long int)(hours * 60 * 60) - (long int)(mins * 60));
118
m_totalTime = QTime(hours, mins, secs);
119
m_artist = (m_mediaObject->metaData(Phonon::ArtistMetaData)).join(",");
120
m_title = (m_mediaObject->metaData(Phonon::TitleMetaData)).join(",");
122
if ( m_artist.isEmpty() && m_title.isEmpty() )
123
setText(m_url.fileName());
125
setText(artist().append(" - ").append(title()));
127
emit signalTotalTimeReady(m_url, m_totalTime);
130
// ------------------------------------------------------------------
132
ListSoundItems::ListSoundItems(QWidget* parent)
133
: QListWidget(parent)
135
setSelectionMode(QAbstractItemView::SingleSelection);
136
setAcceptDrops(true);
137
setSortingEnabled(false);
138
setIconSize(QSize(32, 32));
141
void ListSoundItems::dragEnterEvent(QDragEnterEvent* e)
143
if (e->mimeData()->hasUrls())
144
e->acceptProposedAction();
147
void ListSoundItems::dragMoveEvent(QDragMoveEvent* e)
149
if (e->mimeData()->hasUrls())
150
e->acceptProposedAction();
153
void ListSoundItems::dropEvent(QDropEvent* e)
155
QList<QUrl> list = e->mimeData()->urls();
158
foreach (const QUrl &url, list)
160
QFileInfo fi(url.toLocalFile());
161
if (fi.isFile() && fi.exists())
162
urls.append(KUrl(url));
165
e->acceptProposedAction();
168
emit signalAddedDropItems(urls);
171
KUrl::List ListSoundItems::fileUrls()
175
for (int i = 0; i < count(); ++i)
177
SoundItem *sitem = dynamic_cast<SoundItem*>(item(i));
180
files << KUrl(sitem->url());
187
} // namespace KIPIAdvancedSlideshowPlugin