summaryrefslogtreecommitdiffstats
path: root/kopete/plugins/history/historyplugin.h
blob: 85aa2a3e245c9c72a9ccb7f14a7b517e7aba5406 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
    historyplugin.h

    Copyright (c) 2003-2005 by Olivier Goffart       <ogoffart at kde.org>
              (c) 2003 by Stefan Gehn                 <metz AT gehn.net>
    Kopete    (c) 2003-2004 by the Kopete developers  <kopete-devel@kde.org>

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

#ifndef HISTORYPLUGIN_H
#define HISTORYPLUGIN_H

#include <tqobject.h>
#include <tqmap.h>
#include <tqstring.h>

#include "kopeteplugin.h"

#include "kopetemessage.h"
#include "kopetemessagehandler.h"

class KopeteView;
class KActionCollection;

namespace Kopete
{
class MetaContact;
class ChatSession;
}

class HistoryPreferences;
class HistoryGUIClient;
class HistoryPlugin;

/**
 * @author Richard Smith
 */
class HistoryMessageLogger : public Kopete::MessageHandler
{
	HistoryPlugin *history;
public:
	HistoryMessageLogger( HistoryPlugin *history ) : history(history) {}
	void handleMessage( Kopete::MessageEvent *event );
};

class HistoryMessageLoggerFactory : public Kopete::MessageHandlerFactory
{
	HistoryPlugin *history;
public:
	HistoryMessageLoggerFactory( HistoryPlugin *history ) : history(history) {}
	Kopete::MessageHandler *create( Kopete::ChatSession * /*manager*/, Kopete::Message::MessageDirection direction )
	{
		if( direction != Kopete::Message::Inbound )
			return 0;
		return new HistoryMessageLogger(history);
	}
	int filterPosition( Kopete::ChatSession *, Kopete::Message::MessageDirection )
	{
		return Kopete::MessageHandlerFactory::InStageToSent+5;
	}
};

/**
  * @author Olivier Goffart
  */
class HistoryPlugin : public Kopete::Plugin
{
	Q_OBJECT
  
	public:
		HistoryPlugin( TQObject *parent, const char *name, const TQStringList &args );
		~HistoryPlugin();

		/**
		 * convert the Kopete 0.6 / 0.5 history to the new format
		 */
		static void convertOldHistory();
		/**
		 * return true if an old history has been detected, and no new ones
		 */
		static bool detectOldHistory();
		
		void messageDisplayed(const Kopete::Message &msg);
		
	private slots:
		void slotViewCreated( KopeteView* );
		void slotViewHistory();
		void slotKMMClosed( Kopete::ChatSession* );
		void slotSettingsChanged();

	private:
		HistoryMessageLoggerFactory m_loggerFactory;
		TQMap<Kopete::ChatSession*,HistoryGUIClient*> m_loggers;
		Kopete::Message m_lastmessage;
};

#endif