icecast.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2008-2010  Lukas Sommer < SommerLuk at gmail dot com >
00003 
00004     This program is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU General Public License as
00006     published by the Free Software Foundation; either version 2 of
00007     the License or (at your option) version 3 or any later version
00008     accepted by the membership of KDE e.V. (or its successor approved
00009     by the membership of KDE e.V.), which shall act as a proxy
00010     defined in Section 14 of version 3 of the license.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "icecast.h"
00022 #include <KUrl>
00023 #include "includekio.h"
00024 
00025 icecast::icecast(QObject *parent) : streamDirectoryModel(parent)
00026 {
00027   qRegisterMetaType<icecast_internalThread::streamEntryList>();
00028   m_copyjob = KIO::copy(KUrl("http://dir.xiph.org/yp.xml"),
00029                         KUrl::fromPath(m_tempdir.name()),
00030                         KIO::HideProgressInfo);
00031   connect(m_copyjob,
00032           SIGNAL(result(KJob *)),
00033           this,
00034           SLOT(process_file(KJob *)));
00035 };
00036 
00037 icecast::~icecast()
00038 {
00039   if (!m_copyjob.isNull()) {
00040     m_copyjob->kill();
00041   };
00042 }
00043 
00044 void icecast::process_file(KJob *job)
00045 {
00046   if (job->error() == 0) {
00047     connect(&m_thread,
00048             SIGNAL(streamlist_ready(icecast_internalThread::streamEntryList)),
00049             this,
00050             SLOT(use_data(icecast_internalThread::streamEntryList)));
00051     m_thread.setFilename(m_tempdir.name() + "/yp.xml");
00052     m_thread.start();
00053   }
00054 }
00055 
00056 void icecast::use_data(icecast_internalThread::streamEntryList list)
00057 {
00058   m_tempdir.unlink(); // remove the temp dir with all its content
00059   beginInsertRows(QModelIndex(), 0, list.count()-1);
00060   foreach (streamDirectoryEntry_stream *entry, list) {
00061     rootEntry->appendChild(entry);
00062   };
00063   endInsertRows();
00064   disconnect(this, SLOT(use_data(icecast_internalThread::streamEntryList)));
00065 }

doxygen