mediafiles.cpp 3.23 KB
Newer Older
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
/***************************************************************************
                          mediafiles.cpp
                             -------------------
    begin                : Fri Sep 13 2002
    copyright            : (C) 2002 by Scott Wheeler
    email                : wheeler@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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <kfiledialog.h>
#include <klocale.h>


#include "mediafiles.h"

namespace MediaFiles {
    QStringList mimeTypes();

27 28 29
    static const char mp3Type[]  = "audio/x-mp3";
    static const char oggType[]  = "application/ogg";
    static const char flacType[] = "audio/x-flac";
30
    static const char m3uType[]  = "audio/mpegurl";
31

32 33 34 35 36 37 38
    static const char playlistExtension[] = ".m3u";
}

QStringList MediaFiles::openDialog(QWidget *parent)
{
    KFileDialog dialog(QString::null, QString::null, parent, "filedialog", true);
    dialog.setOperationMode(KFileDialog::Opening);
39

40 41 42 43 44 45 46 47 48 49 50 51 52
    dialog.setCaption(i18n("Open"));
    dialog.setMode(KFile::Files | KFile::LocalOnly);
    // dialog.ops->clearHistory();
    dialog.setMimeFilter(mimeTypes());

    dialog.exec();

    return dialog.selectedFiles();
}

QString MediaFiles::savePlaylistDialog(const QString &playlistName, QWidget *parent)
{
    QString fileName = KFileDialog::getSaveFileName(playlistName + playlistExtension,
53 54 55
                                                    QString("*").append(playlistExtension),
                                                    parent,
                                                    i18n("Playlists"));
56 57
    if(!fileName.isEmpty() && !fileName.endsWith(playlistExtension))
       fileName.append(playlistExtension);
58

59 60 61 62 63 64
    return fileName;
}

bool MediaFiles::isMediaFile(const QString &fileName)
{
    KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
65

66
    return result->is(mp3Type) || result->is(oggType) || result->is(flacType);
67 68 69 70 71
}

bool MediaFiles::isPlaylistFile(const QString &fileName)
{
    KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
72
    return result->is(m3uType);
73 74 75 76 77
}

bool MediaFiles::isMP3(const QString &fileName)
{
    KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
78
    return result->is(mp3Type);
79 80 81 82 83
}

bool MediaFiles::isOgg(const QString &fileName)
{
    KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
84
    return result->is(oggType);
85 86
}

87 88 89 90 91 92
bool MediaFiles::isFLAC(const QString &fileName)
{
    KMimeType::Ptr result = KMimeType::findByPath(fileName, 0, true);
    return result->is(flacType);
}

93 94 95 96
QStringList MediaFiles::mimeTypes()
{
    QStringList l;

97
    l << mp3Type << oggType << flacType << m3uType;
98 99 100

    return l;
}