2 kopetecommandhandler.h - Command Handler
4 Copyright (c) 2003 by Jason Keirstead <jason@keirstead.org>
5 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
7 *************************************************************************
9 * This library is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU Lesser General Public *
11 * License as published by the Free Software Foundation; either *
12 * version 2 of the License, or (at your option) any later version. *
14 *************************************************************************
17 #ifndef _KOPETECOMMANDHANDLER_H_
18 #define _KOPETECOMMANDHANDLER_H_
20 #include <QtCore/QMultiHash>
22 #include <kshortcut.h>
23 #include "kopetemessage.h"
25 #include "kopete_export.h"
29 struct CommandHandlerPrivate
;
32 class KopeteCommandGUIClient
;
42 typedef QMultiHash
<QString
, Command
*> CommandList
;
45 * @author Jason Keirstead <jason@keirstead.org>
47 * The Kopete::CommandHandler can handle /action like messages
49 class KOPETE_EXPORT CommandHandler
: public QObject
51 friend class ::KopeteCommandGUIClient
;
57 * an enum defining the type of a command
59 enum CommandType
{ Normal
, SystemAlias
, UserAlias
, Undefined
};
62 * Returns a pointer to the command handler
64 static CommandHandler
*commandHandler();
67 * \brief Register a command with the command handler.
69 * Command matching is case insensitive. All commands are registered,
70 * regardless of whether or not they are already handled by another
71 * handler. This is so that if the first plugin is unloaded, the next
72 * handler in the sequence will handle the command. However, there are
73 * certain commands which are reserved (internally handled by the
74 * Kopete::CommandHandler). These commands can also be overridden by
75 * registering a new duplicate command.
77 * @param parent The plugin who owns this command
78 * @param command The command we want to handle, not including the '/'
79 * @param handlerSlot The slot used to handle the command. This slot must
80 * accept two parameters, a QString of arguments, and a Kopete::ChatSession
81 * pointer to the manager under which the command was sent.
82 * @param help An optional help string to be shown when the user uses
84 * @param minArgs the minimum number of arguments for this command
85 * @param maxArgs the maximum number of arguments this command takes
86 * @param cut a default keyboard shortcut
87 * @param pix icon name, the icon will be shown in menus
89 void registerCommand( QObject
*parent
, const QString
&command
, const char* handlerSlot
,
90 const QString
&help
= QString(), uint minArgs
= 0, int maxArgs
= -1,
91 const KShortcut
&cut
= KShortcut(), const QString
&pix
= QString() );
94 * \brief Register a command alias.
96 * @param parent The plugin who owns this alias
97 * @param alias The command for the alias
98 * @param formatString This is the string that will be transformed into another
99 * command. The formatString should begin with an already existing command,
100 * followed by any other arguments. The variables %1, %2... %9 will be substituted
101 * with the arguments passed into the alias. The variable %s will be substituted with
102 * the entire argument string
103 * @param help An optional help string to be shown when the user uses
105 * @param minArgs the minimum number of arguments for this command
106 * @param maxArgs the maximum number of arguments this command takes
107 * @param cut a default keyboard shortcut
108 * @param pix icon name, the icon will be shown in menus
110 void registerAlias( QObject
*parent
,
111 const QString
&alias
,
112 const QString
&formatString
,
113 const QString
&help
= QString(),
114 CommandType
= SystemAlias
,
117 const KShortcut
&cut
= KShortcut(),
118 const QString
&pix
= QString() );
121 * \brief Unregister a command.
123 * When a plugin unloads, all commands are automaticlly unregistered and deleted.
124 * This function should only be called in the case of a plugin which loads and
125 * unloads commands dynamically.
127 * @param parent The plugin who owns this command
128 * @param command The command to unload
130 void unregisterCommand( QObject
*parent
, const QString
&command
);
133 * \brief Unregister an alias.
135 * \see unregisterCommand( QObject *parent, const QString &command )
136 * @param parent The plugin who owns this alias
137 * @param alias The alais to unload
139 void unregisterAlias( QObject
*parent
, const QString
&alias
);
142 * \brief Process a message to see if any commands should be handled
144 * @param msg The message to process
145 * @param manager The manager who owns this message
146 * @return True if the command was handled, false if not
148 bool processMessage( Message
&msg
, ChatSession
*manager
);
151 * \brief Process a message to see if any commands should be handled
153 * \see processMessage( Kopete::Message &msg, Kopete::ChatSession *manager)
154 * \param msg A QString contain the message
155 * \param manager the Kopete::ChatSession who will own the message
156 * \return true if the command was handled, false if the command was not handled.
158 bool processMessage( const QString
&msg
, ChatSession
*manager
);
161 * Parses a string of command arguments into a QStringList. Quoted
162 * blocks within the arguments string are treated as one argument.
164 static QStringList
parseArguments( const QString
&args
);
167 * \brief Check if a command is already handled
169 * @param command The command to check
170 * @return True if the command is already being handled, False if not
172 bool commandHandled( const QString
&command
);
175 * \brief Check if a command is already handled by a spesific protocol
177 * @param command The command to check
178 * @param protocol The protocol to check
179 * @return True if the command is already being handled, False if not
181 bool commandHandledByProtocol( const QString
&command
, Protocol
*protocol
);
184 void slotPluginLoaded( Kopete::Plugin
* );
185 void slotPluginDestroyed( QObject
* );
186 void slotExecReturnedData(K3Process
*proc
, char *buff
, int bufflen
);
187 void slotExecFinished(K3Process
*proc
);
188 void slotViewCreated( KopeteView
*view
);
190 void slotHelpCommand( const QString
& args
, Kopete::ChatSession
*manager
);
191 void slotClearCommand( const QString
& args
, Kopete::ChatSession
*manager
);
192 void slotPartCommand( const QString
& args
, Kopete::ChatSession
*manager
);
193 void slotCloseCommand( const QString
& args
, Kopete::ChatSession
*manager
);
194 //void slotMeCommand( const QString & args, Kopete::ChatSession *manager );
195 void slotExecCommand( const QString
& args
, Kopete::ChatSession
*manager
);
196 void slotAwayCommand( const QString
& args
, Kopete::ChatSession
*manager
);
197 void slotAwayAllCommand( const QString
& args
, Kopete::ChatSession
*manager
);
198 void slotSayCommand( const QString
& args
, Kopete::ChatSession
*manager
);
202 * Helper function. Returns all the commands that can be used by a KMM of this protocol
203 * (all non-protocol commands, plus this protocols commands)
205 CommandList
commands( Protocol
* );
208 * Helper function for commands()
210 void addCommands( CommandList
&from
, CommandList
&to
, CommandType type
= Undefined
);
215 static CommandHandlerPrivate
*p
;