File indexing completed on 2024-05-05 04:48:23

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Maximilian Kossick <maximilian.kossick@googlemail.com>            *
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 "CollectionDBusHandler.h"
0018 
0019 #include "CollectionAdaptor.h"
0020 #include "core-impl/collections/support/XmlQueryReader.h"
0021 #include "dbus/DBusQueryHelper.h"
0022 #include "core/support/Debug.h"
0023 
0024 class QueryMaker;
0025 
0026 CollectionDBusHandler::CollectionDBusHandler( QObject *parent )
0027     : QObject( parent )
0028     , QDBusContext()
0029 {
0030     setObjectName(QStringLiteral("CollectionDBusHandler"));
0031     qDBusRegisterMetaType<VariantMapList>();
0032     
0033     new CollectionAdaptor( this );
0034     bool result = QDBusConnection::sessionBus().registerObject(QStringLiteral("/Collection"), this);
0035     debug() << "Register object: " << result;
0036 }
0037 
0038 VariantMapList
0039 CollectionDBusHandler::Query( const QString &xmlQuery )
0040 {
0041     if( !calledFromDBus() )
0042         return VariantMapList();
0043 
0044     Collections::QueryMaker* qm = XmlQueryReader::getQueryMaker( xmlQuery, XmlQueryReader::IgnoreReturnValues );
0045     
0046     //probably invalid XML
0047     if( !qm )
0048     {
0049         debug() << "Invalid XML query: " << xmlQuery;
0050         sendErrorReply( QDBusError::InvalidArgs, "Invalid XML: " + xmlQuery );
0051         return VariantMapList();
0052     }
0053 
0054     setDelayedReply( true );
0055 
0056     new DBusQueryHelper( this, qm, connection(), message(), false );
0057     
0058     return VariantMapList();
0059 }
0060 
0061 VariantMapList
0062 CollectionDBusHandler::MprisQuery( const QString &xmlQuery )
0063 {
0064     if( !calledFromDBus() )
0065         return VariantMapList();
0066 
0067     Collections::QueryMaker* qm = XmlQueryReader::getQueryMaker( xmlQuery, XmlQueryReader::IgnoreReturnValues );
0068 
0069     //probably invalid XML
0070     if( !qm )
0071     {
0072         debug() << "Invalid XML query: " << xmlQuery;
0073         sendErrorReply( QDBusError::InvalidArgs, "Invalid XML: " + xmlQuery );
0074         return VariantMapList();
0075     }
0076 
0077     setDelayedReply( true );
0078 
0079     new DBusQueryHelper( this, qm, connection(), message(), true );
0080 
0081     return VariantMapList();
0082 }