Esempio n. 1
0
void PresentationAudioPage::slotSoundFilesButtonLoad()
{
    QPointer<QFileDialog> dlg = new QFileDialog(this, i18n("Load playlist"),
                                                QString(), i18n("Playlist (*.m3u)"));
    dlg->setAcceptMode(QFileDialog::AcceptOpen);
    dlg->setFileMode(QFileDialog::ExistingFile);

    if (dlg->exec() != QDialog::Accepted)
    {
        delete dlg;
        return;
    }

    QString filename = dlg->selectedFiles().isEmpty() ? QString() : dlg->selectedFiles().at(0);

    if (!filename.isEmpty())
    {
        QFile file(filename);

        if (file.open(QIODevice::ReadOnly|QIODevice::Text))
        {
            QTextStream in(&file);
            QList<QUrl> playlistFiles;

            while (!in.atEnd())
            {
                QString line = in.readLine();

                // we ignore the extended information of the m3u playlist file
                if (line.startsWith(QLatin1Char('#')) || line.isEmpty())
                    continue;

                QUrl fUrl(line);

                if (fUrl.isValid())
                {
                    if (fUrl.isLocalFile())
                    {
                        playlistFiles << fUrl;
                    }
                }
            }

            if (!playlistFiles.isEmpty())
            {
                m_SoundFilesListBox->clear();
                addItems(playlistFiles);
                updateFileList();
            }
        }
    }

    delete dlg;
}
Esempio n. 2
0
void SoundtrackDialog::slotSoundFilesButtonLoad()
{
    QPointer<KFileDialog> dlg = new KFileDialog(QString(), QString(), this);
    dlg->setOperationMode(KFileDialog::Opening);
    dlg->setMode(KFile::File);
    dlg->setFilter(QString("*.m3u|Playlist (*.m3u)"));
    dlg->setWindowTitle(i18n("Load playlist"));

    if (dlg->exec() != KFileDialog::Accepted)
    {

	delete dlg;
        return;
    }

    QString  filename = dlg->selectedFile();

    if (!filename.isEmpty())
    {
        QFile file(filename);
        if (file.open(QIODevice::ReadOnly|QIODevice::Text))
        {
            QTextStream in(&file);
            KUrl::List playlistFiles;

            while (!in.atEnd())
            {
                QString line = in.readLine();

                // we ignore the extended information of the m3u playlist file
                if (line.startsWith('#') || line.isEmpty())
                    continue;

                KUrl fUrl(line);
                if (fUrl.isValid())
                {
                    if (fUrl.isLocalFile())
                    {
                        playlistFiles << fUrl;
                    }
                }
            }

            if (!playlistFiles.isEmpty())
            {
                m_SoundFilesListBox->clear();
                addItems(playlistFiles);
                updateFileList();
            }
        }
    }

    delete dlg;
}
Esempio n. 3
0
void PresentationAudioPage::slotSoundFilesButtonSave()
{
    QPointer<QFileDialog> dlg = new QFileDialog(this, i18n("Save playlist"),
                                                QString(), i18n("Playlist (*.m3u)"));
    dlg->setAcceptMode(QFileDialog::AcceptSave);
    dlg->setFileMode(QFileDialog::AnyFile);

    if (dlg->exec() != QDialog::Accepted)
    {
        delete dlg;
        return;
    }

    QString filename = dlg->selectedFiles().isEmpty() ? QString() : dlg->selectedFiles().at(0);

    if (!filename.isEmpty())
    {
        QFile file(filename);

        if (file.open(QIODevice::WriteOnly|QIODevice::Text))
        {
            QTextStream out(&file);
            QList<QUrl> playlistFiles = m_SoundFilesListBox->fileUrls();

            for (int i = 0; i < playlistFiles.count(); ++i)
            {
                QUrl fUrl(playlistFiles.at(i));

                if (fUrl.isValid())
                {
                    if (fUrl.isLocalFile())
                    {
                        out << fUrl.toLocalFile() << endl;
                    }
                }
            }

            file.close();
        }
    }

    delete dlg;
}
Esempio n. 4
0
void SoundtrackDialog::slotSoundFilesButtonSave()
{
    QPointer<KFileDialog> dlg = new KFileDialog(QString(), QString(), this);
    dlg->setOperationMode(KFileDialog::Saving);
    dlg->setMode(KFile::File);
    dlg->setFilter(QString("*.m3u|Playlist (*.m3u)"));
    dlg->setWindowTitle(i18n("Save playlist"));

    if (dlg->exec() != KFileDialog::Accepted)
    {
	delete dlg;
        return;
    }

    QString filename = dlg->selectedFile();

    if (!filename.isEmpty())
    {
        QFile file(filename);
        if (file.open(QIODevice::WriteOnly|QIODevice::Text))
        {
            QTextStream out(&file);
            KUrl::List playlistFiles = m_SoundFilesListBox->fileUrls();

            for (int i = 0; i < playlistFiles.count(); ++i)
            {
                KUrl fUrl(playlistFiles.at(i));
                if (fUrl.isValid())
                {
                    if (fUrl.isLocalFile())
                    {
                        out << fUrl.toLocalFile() << endl;
                    }
                }
            }
            file.close();
        }
    }

    delete dlg;
}