/* * Copyright 2008 Ben Boeckel * * 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 3 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 . */ // Header include #include "SoundUI.h" // Pokemod includes #include "../pokemod/Sound.h" #include "../pokemod/Pokemod.h" // Qt includes // #include #include #include // KDE includes #include #include SoundUI::SoundUI(Sound* sound, QWidget* parent) : ObjectUI(parent), m_media(new Phonon::MediaObject) { setupUi(this); setObjects(sound, new Sound(*sound)); } SoundUI::~SoundUI() { delete m_media; } void SoundUI::initGui() { seeker->setMediaObject(m_media); connect(m_media, SIGNAL(finished()), buttonStop, SIGNAL(clicked())); buttonPlayPause->setIcon(KIcon("media-playback-start")); buttonStop->setIcon(KIcon("media-playback-stop")); buttonBrowse->setIcon(KIcon("document-open")); } void SoundUI::refreshGui() { on_buttonStop_clicked(); QBuffer* buffer = new QBuffer; buffer->setData(static_cast(modified())->data()); m_media->setCurrentSource(Phonon::MediaSource(buffer)); delete buffer; } void SoundUI::setGui() { varName->setText(static_cast(modified())->name()); } void SoundUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void SoundUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void SoundUI::on_varName_textChanged(const QString& name) { static_cast(modified())->setName(name); } void SoundUI::on_buttonPlayPause_clicked() { if (m_media->state() == Phonon::PlayingState) { buttonPlayPause->setIcon(KIcon("media-playback-start")); buttonPlayPause->setEnabled(true); m_media->pause(); } else if (m_media->state() == Phonon::PausedState) { buttonPlayPause->setIcon(KIcon("media-playback-pause")); buttonPlayPause->setEnabled(true); m_media->play(); } else if (m_media->state() == Phonon::ErrorState) { buttonPlayPause->setIcon(KIcon("media-playback-start")); buttonPlayPause->setEnabled(false); m_media->stop(); } } void SoundUI::on_buttonStop_clicked() { buttonPlayPause->setIcon(KIcon("media-playback-start")); m_media->stop(); } void SoundUI::on_buttonBrowse_clicked() { QFile file(KFileDialog::getOpenFileName(KUrl("kfiledialog:///audio"), "*.ogg|OGG files", this)); if (file.open(QIODevice::ReadOnly)) { static_cast(modified())->setData(file.readAll()); file.close(); refreshGui(); } }