File: dbuscollectionproxy.cpp

package info (click to toggle)
juk 4%3A25.08.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,236 kB
  • sloc: cpp: 14,818; xml: 763; makefile: 5; sh: 2
file content (150 lines) | stat: -rw-r--r-- 4,046 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
 * Copyright (C) 2009 Michael Pyne <mpyne@kde.org>
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include "dbuscollectionproxy.h"

#include <QStringList>
#include <QFile>
#include <QPixmap>
#include <QDBusConnection>
#include <QTemporaryFile>

#include "collectionadaptor.h"
#include "playlistcollection.h"
#include "collectionlist.h"
#include "coverinfo.h"
#include "filehandle.h"
#include "juk_debug.h"

DBusCollectionProxy::DBusCollectionProxy (QObject *parent, PlaylistCollection *collection) :
    QObject(parent), m_collection(collection)
{
    setObjectName( QLatin1String("DBusCollectionProxy" ));

    new CollectionAdaptor(this);
    QDBusConnection::sessionBus().registerObject("/Collection",this);
}

DBusCollectionProxy::~DBusCollectionProxy()
{
    // Clean's the way to be
    if(!m_lastCover.isEmpty())
        QFile::remove(m_lastCover);
}

void DBusCollectionProxy::openFile(const QString &file)
{
    m_collection->open(QStringList(file));
}

void DBusCollectionProxy::openFile(const QStringList &files)
{
    m_collection->open(files);
}

void DBusCollectionProxy::openFile(const QString &playlist, const QString &file)
{
    m_collection->open(playlist, QStringList(file));
}

void DBusCollectionProxy::openFile(const QString &playlist, const QStringList &files)
{
    m_collection->open(playlist, files);
}

QString DBusCollectionProxy::visiblePlaylist()
{
    return m_collection->playlist();
}

QString DBusCollectionProxy::playingPlaylist()
{
    return m_collection->playingPlaylist();
}

QStringList DBusCollectionProxy::playlists()
{
    return m_collection->playlists();
}

QStringList DBusCollectionProxy::playlistTracks(const QString &playlist)
{
    return m_collection->playlistTracks(playlist);
}

QString DBusCollectionProxy::trackProperty(const QString &file, const QString &property)
{
    return m_collection->trackProperty(file, property);
}

void DBusCollectionProxy::createPlaylist(const QString &name)
{
    m_collection->createPlaylist(name);
}

void DBusCollectionProxy::setPlaylist(const QString &name)
{
    m_collection->setPlaylist(name);
}

void DBusCollectionProxy::remove()
{
    m_collection->remove();
}

void DBusCollectionProxy::removeTrack(const QString &playlist, const QStringList &files)
{
    m_collection->removeTrack(playlist, files);
}

QString DBusCollectionProxy::trackCover(const QString &track)
{
    // Let's see if a cover is embedded.
    CollectionListItem *collectionItem = CollectionList::instance()->lookup(track);

    if(!collectionItem)
        return QString();

    CoverInfo *coverInfo = collectionItem->file().coverInfo();
    if(!coverInfo)
        return QString();

    QPixmap cover = coverInfo->pixmap(CoverInfo::FullSize);
    if(cover.isNull())
        return QString();

    // We have a cover, extract it and save it to a temporary file.
    QTemporaryFile tempFile;

    tempFile.setFileTemplate(QStringLiteral("juk_cover_XXXXXX.png"));
    tempFile.setAutoRemove(false);

    if(!tempFile.open()) {
        qCCritical(JUK_LOG) << "Unable to open temporary file for embedded cover art.";
        return QString();
    }

    // Save last file name cover, remove it if it's there so that we don't fill
    // the temp directory with pixmaps.
    if(!m_lastCover.isEmpty())
        QFile::remove(m_lastCover);
    m_lastCover = tempFile.fileName();

    cover.save(&tempFile, "PNG");
    return tempFile.fileName();
}

// vim: set et sw=4 tw=0 sta: