~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to extra/kipi-plugins/advancedslideshow/widgets/listsounditems.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-09-23 18:18:55 UTC
  • mfrom: (1.2.36 upstream)
  • Revision ID: package-import@ubuntu.com-20110923181855-ifs67wxkugshev9k
Tags: 2:2.1.1-0ubuntu1
[ Rohan Garg ]
* New upstream release (LP: #834190)
  - debian/control
    + Build with libqtwebkit-dev
 - debian/kipi-plugins-common
    + Install libkvkontakte required by kipi-plugins
 - debian/digikam
    + Install panoramagui

[ Philip Muškovac ]
* New upstream release
  - debian/control:
    + Add libcv-dev, libcvaux-dev, libhighgui-dev, libboost-graph1.46-dev,
      libksane-dev, libxml2-dev, libxslt-dev, libqt4-opengl-dev, libqjson-dev,
      libgpod-dev and libqca2-dev to build-deps
    + Add packages for kipi-plugins, libmediawiki, libkface, libkgeomap and
      libkvkontakte
  - debian/rules:
    + Don't build with gphoto2 since it doesn't build with it.
  - Add kubuntu_fix_test_linking.diff to fix linking of the dngconverter test
  - update install files
  - update kubuntu_01_mysqld_executable_name.diff for new cmake layout
    and rename to kubuntu_mysqld_executable_name.diff
* Fix typo in digikam-data description (LP: #804894)
* Fix Vcs links

[ Felix Geyer ]
* Move library data files to the new packages libkface-data, libkgeomap-data
  and libkvkontakte-data.
* Override version of the embedded library packages to 1.0~digikam<version>.
* Exclude the library packages from digikam-dbg to prevent file conflicts in
  the future.
* Call dh_install with --list-missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of kipi-plugins project
 
4
 * http://www.kipi-plugins.org
 
5
 *
 
6
 * Date        : 2008-09-14
 
7
 * Description : a kipi plugin to slide images.
 
8
 *
 
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>
 
11
 *
 
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.
 
16
 *
 
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.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
#include "listsounditems.moc"
 
25
 
 
26
// Qt includes
 
27
 
 
28
#include <QString>
 
29
#include <QWidget>
 
30
#include <QEvent>
 
31
#include <QFileInfo>
 
32
#include <QDropEvent>
 
33
#include <QDragEnterEvent>
 
34
#include <QIcon>
 
35
#include <QBrush>
 
36
 
 
37
// KDE includes
 
38
 
 
39
#include <kurl.h>
 
40
#include <kiconloader.h>
 
41
#include <kmessagebox.h>
 
42
#include <klocale.h>
 
43
 
 
44
namespace KIPIAdvancedSlideshowPlugin
 
45
{
 
46
 
 
47
SoundItem::SoundItem(QListWidget* parent, const KUrl& url)
 
48
         : QListWidgetItem(parent)
 
49
{
 
50
    m_url = url;
 
51
    setIcon(SmallIcon("audio-x-generic", KIconLoader::SizeLarge, KIconLoader::DisabledState));
 
52
 
 
53
    m_totalTime   = QTime(0, 0, 0);
 
54
    m_mediaObject = new Phonon::MediaObject();
 
55
    m_mediaObject->setCurrentSource(url);
 
56
 
 
57
    connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
 
58
            this, SLOT(slotMediaStateChanged(Phonon::State,Phonon::State)));
 
59
}
 
60
 
 
61
SoundItem::~SoundItem()
 
62
{
 
63
}
 
64
 
 
65
KUrl SoundItem::url() const
 
66
{
 
67
    return m_url;
 
68
}
 
69
 
 
70
void SoundItem::setName(const QString& text)
 
71
{
 
72
    setText(text);
 
73
}
 
74
 
 
75
QString SoundItem::artist() const
 
76
{
 
77
    return m_artist;
 
78
}
 
79
 
 
80
QString SoundItem::title() const
 
81
{
 
82
    return m_title;
 
83
}
 
84
 
 
85
QTime SoundItem::totalTime() const
 
86
{
 
87
    return m_totalTime;
 
88
}
 
89
 
 
90
void SoundItem::slotMediaStateChanged(Phonon::State newstate, Phonon::State /*oldstate*/)
 
91
{
 
92
    if ( newstate == Phonon::ErrorState )
 
93
    {
 
94
        KMessageBox::detailedError( (QWidget*)(this),
 
95
                                    i18n("%1 is damaged and may not be playable.", m_url.fileName()),
 
96
                                    m_mediaObject->errorString(),
 
97
                                    i18n("Phonon error")
 
98
                                  );
 
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);
 
107
        setFont(errorFont);
 
108
        return;
 
109
    }
 
110
 
 
111
    if ( newstate != Phonon::StoppedState )
 
112
        return;
 
113
 
 
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(",");
 
121
 
 
122
    if ( m_artist.isEmpty() && m_title.isEmpty() )
 
123
        setText(m_url.fileName());
 
124
    else
 
125
        setText(artist().append(" - ").append(title()));
 
126
 
 
127
    emit signalTotalTimeReady(m_url, m_totalTime);
 
128
}
 
129
 
 
130
// ------------------------------------------------------------------
 
131
 
 
132
ListSoundItems::ListSoundItems(QWidget* parent)
 
133
              : QListWidget(parent)
 
134
{
 
135
    setSelectionMode(QAbstractItemView::SingleSelection);
 
136
    setAcceptDrops(true);
 
137
    setSortingEnabled(false);
 
138
    setIconSize(QSize(32, 32));
 
139
}
 
140
 
 
141
void ListSoundItems::dragEnterEvent(QDragEnterEvent* e)
 
142
{
 
143
    if (e->mimeData()->hasUrls())
 
144
        e->acceptProposedAction();
 
145
}
 
146
 
 
147
void ListSoundItems::dragMoveEvent(QDragMoveEvent* e)
 
148
{
 
149
    if (e->mimeData()->hasUrls())
 
150
        e->acceptProposedAction();
 
151
}
 
152
 
 
153
void ListSoundItems::dropEvent(QDropEvent* e)
 
154
{
 
155
    QList<QUrl> list = e->mimeData()->urls();
 
156
    KUrl::List urls;
 
157
 
 
158
    foreach (const QUrl &url, list)
 
159
    {
 
160
        QFileInfo fi(url.toLocalFile());
 
161
        if (fi.isFile() && fi.exists())
 
162
            urls.append(KUrl(url));
 
163
    }
 
164
 
 
165
    e->acceptProposedAction();
 
166
 
 
167
    if (!urls.isEmpty())
 
168
        emit signalAddedDropItems(urls);
 
169
}
 
170
 
 
171
KUrl::List ListSoundItems::fileUrls()
 
172
{
 
173
    KUrl::List files;
 
174
 
 
175
    for (int i = 0; i < count(); ++i)
 
176
    {
 
177
        SoundItem *sitem = dynamic_cast<SoundItem*>(item(i));
 
178
        if (sitem)
 
179
        {
 
180
            files << KUrl(sitem->url());
 
181
        }
 
182
    }
 
183
 
 
184
    return files;
 
185
}
 
186
 
 
187
}  // namespace KIPIAdvancedSlideshowPlugin