remove actions which are not supported, this way they are also not visible in shortcu...
[kdenetwork.git] / kopete / libkopete / kopetecommand.h
blobb94e51d28926945a05630e8bd9bc56422019086f
2 /*
3 kopetecommand.h - Command
5 Copyright (c) 2003 by Jason Keirstead <jason@keirstead.org>
6 Copyright (c) 2005 by Michel Hermier <michel.hermier@wanadoo.fr>
7 Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
9 *************************************************************************
10 * *
11 * This library is free software; you can redistribute it and/or *
12 * modify it under the terms of the GNU Lesser General Public *
13 * License as published by the Free Software Foundation; either *
14 * version 2 of the License, or (at your option) any later version. *
15 * *
16 *************************************************************************
19 #ifndef KOPETECOMMAND_H
20 #define KOPETECOMMAND_H
22 #include <QtCore/QObject>
24 #include <kaction.h>
25 #include "kopetecommandhandler.h"
27 namespace Kopete
30 class ChatSession;
32 class Command
33 : public KAction
35 Q_OBJECT
37 public:
38 /**
39 * an enum defining the type of a command
41 typedef enum Type
43 Normal = 0,
44 System = 1 << 1, // Not removable command
45 Alias = 1 << 2 // Is an alias
46 // Undefined
47 } Type;
48 Q_DECLARE_FLAGS(Types, Type)
50 /**
51 * Creates a Kopete::Command object
53 * @param parent The plugin who owns this command
54 * @param command The command we want to handle, not including the '/'
55 * @param handlerSlot The slot used to handle the command. This slot must
56 * accept two parameters, a QString of arguments, and a Kopete::ChatSession
57 * pointer to the Manager under which the command was sent.
58 * @param help An optional help string to be shown when the user uses
59 * /help <i>command</i>
60 * @param type If this command is an alias, and what type
61 * @param formatString The formatString of the alias if any
62 * @param minArgs Minimum number of arguments
63 * @param maxArgs Maximum number of arguments
64 * @param cut The shortcut for the command
65 * @param pix The icon to use for the command
67 Command( QObject *parent, const QString &command, const char* handlerSlot,
68 const QString &help = QString(), CommandHandler::CommandType type = CommandHandler::Normal, const QString &formatString = QString(),
69 uint minArgs = 0, int maxArgs = -1, const KShortcut &cut = KShortcut(),
70 const QString &pix = QString() );
71 ~Command();
73 /**
74 * Process this command
76 void processCommand( const QString &args, ChatSession *manager, bool gui = false );
78 /**
79 * Returns the command this object handles
81 const QString &command() const { return m_command; }
83 /**
84 * Returns the help string for this command
86 const QString &help() const { return m_help; }
88 /**
89 * Returns the type of the command
91 const CommandHandler::CommandType type() const { return m_type; }
93 signals:
94 /**
95 * Emitted whenever a command is handled by this object. When a command
96 * has been handled, all processing on it stops by the command handler
97 * (a command cannot be handled twice)
99 void handleCommand( const QString &args, Kopete::ChatSession *manager );
101 private slots:
103 * Connected to our activated() signal
105 void slotAction();
107 private:
108 void init( const QString &command, const char* slot, const QString &help,
109 CommandHandler::CommandType type, const QString &formatString,
110 uint minArgs, int maxArgs );
112 void printError( const QString &error, ChatSession *manager, bool gui = false ) const;
114 QString m_command;
115 QString m_help;
116 QString m_formatString;
117 int m_minArgs;
118 int m_maxArgs;
119 bool m_processing;
120 CommandHandler::CommandType m_type;
122 class Private;
123 Private * const d;
128 Q_DECLARE_OPERATORS_FOR_FLAGS(Kopete::Command::Types)
130 #endif