summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/kopetesimplemessagehandler.h
blob: 2a09aebec963a74438acb7001723695592a7a473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
    kopetesimplemessagehandler.h - Kopete Message Filtering - simple interface

    Copyright (c) 2004      by Richard Smith         <kde@metafoo.co.uk>
    Kopete    (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * This library is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU Lesser General Public            *
    * License as published by the Free Software Foundation; either          *
    * version 2 of the License, or (at your option) any later version.      *
    *                                                                       *
    *************************************************************************
*/

#ifndef KOPETESIMPLEMESSAGEHANDLER_H
#define KOPETESIMPLEMESSAGEHANDLER_H

#include "kopete_export.h"
#include "kopetemessagehandler.h"

namespace Kopete
{

/**
 * @brief A MessageHandlerFactory that creates synchronous MessageHandlers that just call a slot
 *
 * A concrete MessageHandlerFactory. This class is intended to make writing MessageHandlers simpler;
 * all that is required is to implement a message processing function and place an instance of this
 * class in your Plugin-derived class.
 *
 * Whenever a message passes through a handler created by this factory, the slot passed to the
 * constructor will be called. The slot should take a single argument of type (non-@p const)
 * <tt>Message &</tt>.
 */
class KOPETE_EXPORT SimpleMessageHandlerFactory : public MessageHandlerFactory
{
public:
	/**
	 * @param direction The direction this factory should create message handlers for
	 * @param position Where in the chain the handler should be installed
	 * @param target The object to call back to when handling a message
	 * @param slot The slot on @p target to call when handling a message
	 * @see Kopete::MessageHandlerFactory::filterPosition
	 */
	SimpleMessageHandlerFactory( Message::MessageDirection direction, int position,
	                             TQObject *target, const char *slot );
	~SimpleMessageHandlerFactory();
	
	/**
	 * Creates and returns a SimpleMessageHandler object.
	 */
	MessageHandler *create( ChatSession *manager, Message::MessageDirection direction );
	/**
	 * Returns the filter position passed to the constructor if @p direction matches the
	 * direction passed to the constructor, otherwise returns @c StageDoNotCreate.
	 */
	int filterPosition( ChatSession *manager, Message::MessageDirection direction );
	
private:
	class Private;
	Private *d;
};

/**
 * @internal This class is used to implement SimpleMessageHandlerFactory.
 */
class SimpleMessageHandler : public MessageHandler
{
	TQ_OBJECT
  
public:
	SimpleMessageHandler();
	~SimpleMessageHandler();
	
	void handleMessage( MessageEvent *event );
	
signals:
	void handle( Kopete::Message &message );
	
private:
	class Private;
	Private *d;
};

}

#endif