File indexing completed on 2025-01-05 04:25:41

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  * Copyright (c) 2007 Leo Franchi <lfranchi@gmail.com>                                  *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #include "InfoEngine.h"
0019 
0020 #include "core/support/Amarok.h"
0021 #include "core/support/Debug.h"
0022 #include "browsers/InfoProxy.h"
0023 #include "PaletteHandler.h"
0024 
0025 QString InfoEngine::s_standardContent = "<html>"
0026                                         "    <head>"
0027                                         "        <style type=\"text/css\">body {text-align:center}</style>"
0028                                         "    </head>"
0029                                         "    <body>"
0030                                         "        <b>%%SUBJECT_NAME%%</b>"
0031                                         "    </body>"
0032                                         "</html>";
0033 
0034 InfoEngine::InfoEngine( QObject* parent )
0035     : QObject( parent )
0036 {
0037     DEBUG_BLOCK
0038 
0039     The::infoProxy()->subscribe( this );
0040 
0041     connect( The::paletteHandler(), &PaletteHandler::newPalette, this, &InfoEngine::serviceChanged );
0042 }
0043 
0044 InfoEngine::~InfoEngine()
0045 {
0046     The::infoProxy()->unsubscribe( this );
0047 }
0048 
0049 QString InfoEngine::mainInfo() const
0050 {
0051     QString main_info;
0052 
0053     if( m_storedInfo.contains("main_info") )
0054     {
0055         auto palette = The::paletteHandler()->palette();
0056         main_info = m_storedInfo.value("main_info").toString();
0057         main_info.replace("{text_color}", palette.windowText().color().name());
0058         main_info.replace("{content_background_color}", palette.window().color().name());
0059         main_info.replace("{background_color}", palette.window().color().name());
0060         main_info.replace("{border_color}", palette.text().color().name());
0061     }
0062 
0063     if( main_info.isEmpty() )
0064         main_info = s_standardContent.replace("%%SUBJECT_NAME%%", serviceName());
0065 
0066     return main_info;
0067 }
0068 
0069 void InfoEngine::infoChanged( QVariantMap infoMap )
0070 {
0071     m_storedInfo = infoMap;
0072     emit serviceChanged();
0073 }
0074