1 /***************************************************************************
2 * Copyright (C) 2005-2016 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "basichandler.h"
23 #include <QMetaMethod>
27 BasicHandler::BasicHandler(QObject *parent)
31 _methodPrefix("handle")
36 BasicHandler::BasicHandler(const QString &methodPrefix, QObject *parent)
40 _methodPrefix(methodPrefix)
45 QStringList BasicHandler::providesHandlers()
47 return handlerHash().keys();
51 const QHash<QString, int> &BasicHandler::handlerHash()
54 for (int i = metaObject()->methodOffset(); i < metaObject()->methodCount(); i++) {
55 #if QT_VERSION >= 0x050000
56 QString methodSignature = metaObject()->method(i).methodSignature();
58 QString methodSignature = metaObject()->method(i).signature();
60 if (methodSignature.startsWith("defaultHandler")) {
65 if (!methodSignature.startsWith(_methodPrefix))
68 methodSignature = methodSignature.section('(', 0, 0); // chop the attribute list
69 methodSignature = methodSignature.mid(_methodPrefix.length()); // strip "handle" or whatever the prefix is
70 _handlerHash[methodSignature] = i;
78 void BasicHandler::handle(const QString &member, QGenericArgument val0,
79 QGenericArgument val1, QGenericArgument val2,
80 QGenericArgument val3, QGenericArgument val4,
81 QGenericArgument val5, QGenericArgument val6,
82 QGenericArgument val7, QGenericArgument val8)
84 // Now we try to find a handler for this message. BTW, I do love the Trolltech guys ;-)
85 // and now we even have a fast lookup! Thanks thiago!
87 QString handler = member.toLower();
88 handler[0] = handler[0].toUpper();
90 if (!handlerHash().contains(handler)) {
91 if (_defaultHandler == -1) {
92 qWarning() << QString("No such Handler: %1::%2%3").arg(metaObject()->className(), _methodPrefix, handler);
96 void *param[] = { 0, Q_ARG(QString, member).data(), val0.data(), val1.data(), val2.data(), val3.data(), val4.data(),
97 val5.data(), val6.data(), val7.data(), val8.data(), val8.data() };
98 qt_metacall(QMetaObject::InvokeMetaMethod, _defaultHandler, param);
103 void *param[] = { 0, val0.data(), val1.data(), val2.data(), val3.data(), val4.data(),
104 val5.data(), val6.data(), val7.data(), val8.data(), val8.data(), 0 };
105 qt_metacall(QMetaObject::InvokeMetaMethod, handlerHash()[handler], param);