File indexing completed on 2024-05-05 04:49:15

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "InfoParserBase.h"
0018 
0019 #include "core/support/Debug.h"
0020 
0021 #include <QStandardPaths>
0022 #include <QUrl>
0023 
0024 #include <QFile>
0025 #include <QPalette>
0026 
0027 QString InfoParserBase::s_loadingBaseHtml;
0028 
0029 InfoParserBase::InfoParserBase()
0030   : QObject()
0031 {}
0032 
0033 void InfoParserBase::showLoading( const QString &message )
0034 {
0035     DEBUG_BLOCK
0036 
0037     if( s_loadingBaseHtml.isEmpty() )
0038     {
0039         const QUrl url( QStandardPaths::locate( QStandardPaths::GenericDataLocation, QStringLiteral("amarok/data/") ) );
0040         QString htmlFile = url.path() + "InfoParserLoading.html";
0041 
0042         if( !QFile::exists( htmlFile ) )
0043         {
0044             debug() << "file " << htmlFile << "does not exist";
0045             return;
0046         }
0047 
0048         QFile file( htmlFile );
0049         if( !file.open( QIODevice::ReadOnly ) )
0050         {
0051             debug() << "error reading file " << htmlFile;
0052             return;
0053         }
0054 
0055         s_loadingBaseHtml = file.readAll();
0056     }
0057 
0058     QString currentHtml = s_loadingBaseHtml;
0059 
0060     const QUrl url( QStandardPaths::locate( QStandardPaths::GenericDataLocation, QStringLiteral("amarok/images/") ) );
0061     currentHtml = currentHtml.replace( QLatin1String("%%IMAGEPATH%%"), url.url() );
0062     currentHtml = currentHtml.replace( QLatin1String("%%TEXT%%"), message );
0063 
0064     // debug() << "showing html: " << currentHtml;
0065     Q_EMIT ( info( currentHtml ) );
0066 }
0067 
0068