summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/kopetemimetypehandler.h
blob: 3dc7445f7c667b33a8e28a83494e926707142980 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
    kopetemimetypehandler.h - Kopete Mime-type Handlers

    Copyright (c) 2004      by Richard Smith         <kde@metafoo.co.uk>

    Kopete    (c) 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 KOPETEMIMETYPEHANDLER_H
#define KOPETEMIMETYPEHANDLER_H

class KURL;
class TQString;
class TQStringList;

#include "kopete_export.h"

namespace Kopete
{

/**
 * @brief A handler for some set of mime-types
 * A mime type handler is responsible for handling requests to open files of
 * certain mime types presented to the main application.
 */
class KOPETE_EXPORT MimeTypeHandler
{
protected:
	MimeTypeHandler( bool canAcceptRemoteFiles = false );
public:
	virtual ~MimeTypeHandler();

	/**
	 * Finds a MimeTypeHandler for a given URL, and tells that handler to handle it
	 *
	 * @param url the url to dispatch
	 *
	 * @return true if a handler was registered for the mime type, false otherwise
	 */
	static bool dispatchURL( const KURL &url );

	/**
	 * Returns a list of mime types this object is registered to handle
	 */
	const TQStringList mimeTypes() const;

	/**
	 * Returns a list of protocols this object is registered to handle
	 */
	const TQStringList protocols() const;

	/**
	 * Returns true if this handler can accept remote files direcltly;
	 * If false, remote files are downloaded via TDEIO::NetAccess before
	 * being passed to handleURL
	 */
	bool canAcceptRemoteFiles() const;

	/**
	 * Handles the URL @p url
	 *
	 * @param url The url to handle
	 */
	virtual void handleURL( const KURL &url ) const;

	/**
	 * Handles the URL @p url, which has the mime type @p mimeType
	 *
	 * @param mimeType The mime type of the URL
	 * @param url The url to handle
	 */
	virtual void handleURL( const TQString &mimeType, const KURL &url ) const;

protected:
	/**
	 * Register this object as the handler of type @p mimeType.
	 * @param mimeType the mime type to handle
	 * @return true if registration succeeded, false if another handler is
	 *         already set for this mime type.
	 */
	bool registerAsMimeHandler( const TQString &mimeType );

	/**
	 * Register this object as the handler of type @p protocol.
	 * @param protocol the protocol to handle
	 * @return true if registration succeeded, false if another handler is
	 *         already set for this protocol.
	 */
	bool registerAsProtocolHandler( const TQString &protocol );

private:
	/**
	 * Helper function.
	 * Attempts to dispatch a given URL to a given handler
	 *
	 * @param url The url to dispatch
	 * @param mimeType The mime type of the url
	 * @param handler The handler to attempt
	 *
	 * @return true if a handler was able to process the URL, false otherwise
	 */
	static bool dispatchToHandler( const KURL &url, const TQString &mimeType, MimeTypeHandler *handler );

	class Private;
	Private *d;
};

/**
 * Mime-type handler class for Kopete emoticon files
 */
class KOPETE_EXPORT EmoticonMimeTypeHandler : public MimeTypeHandler
{
public:
	EmoticonMimeTypeHandler();

	const TQStringList mimeTypes() const;

	void handleURL( const TQString &mimeType, const KURL &url ) const;
};

} // Kopete

#endif