~ubuntu-branches/ubuntu/saucy/quassel/saucy-proposed

« back to all changes in this revision

Viewing changes to src/common/basichandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-02-17 12:49:50 UTC
  • mto: This revision was merged to the branch mainline in revision 59.
  • Revision ID: james.westby@ubuntu.com-20100217124950-v9hajw5d2xa6fszn
Tags: upstream-0.6~beta1
ImportĀ upstreamĀ versionĀ 0.6~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005-10 by the Quassel Project                          *
 
3
 *   devel@quassel-irc.org                                                 *
 
4
 *                                                                         *
 
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.                                           *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
#include "basichandler.h"
 
21
 
 
22
#include <QMetaMethod>
 
23
 
 
24
#include "logger.h"
 
25
 
 
26
BasicHandler::BasicHandler(QObject *parent)
 
27
  : QObject(parent),
 
28
    defaultHandler(-1),
 
29
    initDone(false)
 
30
{
 
31
}
 
32
 
 
33
QStringList BasicHandler::providesHandlers() {
 
34
  return handlerHash().keys();
 
35
}
 
36
 
 
37
const QHash<QString, int> &BasicHandler::handlerHash() {
 
38
  if(!initDone) {
 
39
    for(int i = metaObject()->methodOffset(); i < metaObject()->methodCount(); i++) {
 
40
      QString methodSignature(metaObject()->method(i).signature());
 
41
      if(methodSignature.startsWith("defaultHandler")) {
 
42
        defaultHandler = i;
 
43
        continue;
 
44
      }
 
45
      
 
46
      if(!methodSignature.startsWith("handle"))
 
47
        continue;
 
48
      
 
49
      methodSignature = methodSignature.section('(',0,0);  // chop the attribute list
 
50
      methodSignature = methodSignature.mid(6); // strip "handle"
 
51
      _handlerHash[methodSignature] = i;
 
52
    }
 
53
    initDone = true;
 
54
  }
 
55
  return _handlerHash;
 
56
}
 
57
 
 
58
void BasicHandler::handle(const QString &member, QGenericArgument val0,
 
59
                          QGenericArgument val1, QGenericArgument val2,
 
60
                          QGenericArgument val3, QGenericArgument val4,
 
61
                          QGenericArgument val5, QGenericArgument val6,
 
62
                          QGenericArgument val7, QGenericArgument val8) {
 
63
  // Now we try to find a handler for this message. BTW, I do love the Trolltech guys ;-)
 
64
  // and now we even have a fast lookup! Thanks thiago!
 
65
 
 
66
  QString handler = member.toLower();
 
67
  handler[0] = handler[0].toUpper();
 
68
 
 
69
  if(!handlerHash().contains(handler)) {
 
70
    if(defaultHandler == -1) {
 
71
      qWarning() << QString("No such Handler: %1::handle%2").arg(metaObject()->className(), handler);
 
72
      return;
 
73
    } else {
 
74
      void *param[] = {0, Q_ARG(QString, member).data(), val0.data(), val1.data(), val2.data(), val3.data(), val4.data(),
 
75
                       val5.data(), val6.data(), val7.data(), val8.data(), val8.data()};
 
76
      qt_metacall(QMetaObject::InvokeMetaMethod, defaultHandler, param);
 
77
      return;
 
78
    }
 
79
  }
 
80
 
 
81
  void *param[] = {0, val0.data(), val1.data(), val2.data(), val3.data(), val4.data(),
 
82
                   val5.data(), val6.data(), val7.data(), val8.data(), val8.data(), 0};
 
83
  qt_metacall(QMetaObject::InvokeMetaMethod, handlerHash()[handler], param);
 
84
}