File indexing completed on 2025-01-05 04:26:50

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Ian Monroe <ian@monroe.nu>                                        *
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) version 3 or        *
0007  * any later version accepted by the membership of KDE e.V. (or its successor approved  *
0008  * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of  *
0009  * version 3 of the license.                                                            *
0010  *                                                                                      *
0011  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0013  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0014  *                                                                                      *
0015  * You should have received a copy of the GNU General Public License along with         *
0016  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0017  ****************************************************************************************/
0018 
0019 #include "AmarokInfoScript.h"
0020 
0021 #include "core/support/Amarok.h"
0022 #include "scripting/scriptengine/ScriptingDefines.h"
0023 
0024 #include <KIconLoader>
0025 
0026 #include <QMetaEnum>
0027 #include <QJSEngine>
0028 
0029 using namespace AmarokScript;
0030 
0031 InfoScript::InfoScript( const QUrl &scriptUrl, AmarokScriptEngine *engine )
0032     : QObject( engine )
0033     , m_scriptUrl( scriptUrl )
0034 {
0035     QJSValue scriptObject = engine->newQObject( this );
0036     engine->globalObject().property( QStringLiteral("Amarok") ).setProperty( QStringLiteral("Info"), scriptObject );
0037 
0038     const QMetaEnum iconEnum = metaObject()->enumerator( metaObject()->indexOfEnumerator("IconSizes") );
0039     Q_ASSERT( iconEnum.isValid() );
0040     scriptObject.setProperty( QStringLiteral("IconSizes"), engine->enumObject( iconEnum ) );
0041 }
0042 
0043 QString
0044 InfoScript::version() const
0045 {
0046     return AMAROK_VERSION;
0047 }
0048 
0049 QString
0050 InfoScript::scriptPath() const
0051 {
0052     return m_scriptUrl.adjusted(QUrl::RemoveFilename).path();
0053 }
0054 
0055 QString
0056 InfoScript::iconPath( const QString& name, int size ) const
0057 {
0058     //if size was positive it would refer to KIconLoader::Group
0059     return KIconLoader::global()->iconPath( name, -size );
0060 }
0061 
0062 QString
0063 InfoScript::scriptConfigPath( const QString& name ) const
0064 {
0065     return Amarok::saveLocation( "scripts/" + name );
0066 }