Source: Channel.h


Annotated List
Files
Globals
Hierarchy
Index
/***************************************************************************
 *
 * File:    Channel.h
 * Created: Sat Dec 4 1999
 * (C) 1999 by David M. <captjay@superlink.net>
 *
 ***************************************************************************/
/***************************************************************************
 *                                                                         *
 *   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 CHANNEL_H
#define CHANNEL_H

#include <qstring.h>
#include <qobject.h>
#include <qdict.h>
#include <qlist.h>

class ChanUser;
class Ban;

typedef QDictIterator<ChanUser> UserListIterator;
typedef QDictIterator<Ban> BanListIterator;

/**
* @author David M.
* @short Represent an IRC channel.
*
* Class Channel encapsulates information about an IRC channel, including
* its userlist, banlist and current modes.
*
* This class provides a public, read-only interface, and a protected modification
* interface.
*
* @see ChanUser
* @see Channels
*/
class Channel : public QObject {
public:
  /**
  * Create a channel with a specific name.
  *
  * @param name The name of the new channel.
  */
  explicit Channel(const QString& name);
  ~Channel();

  /**
  * Search the channel for a user with the specified
  * nickname.
  *
  * @param nickname The nickname of the user to find.
  *
  * @return A const pointer to the ChanUser object that
  *                   represents the specified user, or
  *                   0 if nickname is not on the channel.
  */
  const ChanUser* findUser(QString nickname) const;

  /**
  * Determines if the client is currently oped on the channel.
  *
  * @return true if the client is oped on the channel,
  *              false otherwise.
  */
  bool isOp() const;

  /**
  * Get the name of the channel object.
  *
  * @return The name of the channel.
  */
  const QString& getName() const;

  /**
  * Get the current modes on the channel.
  *
  * @return A bitwise OR of the different mode constants.
  *             See static const definitions for a list of
  *             mode constants.
  */
  const int getModes() const;

  /**
  * Get the current channel key, if any.
  *
  * @return The channel key if the channel has a key set,
  *                 an empty string otherwise.
  */
  const QString& getKey() const;

  /**
  * Get the current channel limit, if any.
  *
  * @return The channel limit if the channel has one,
  *             0 otherwise.
  */
  const int getLimit() const;

  /**
  * Get the @ref ChanUser object associated with the client on the channel.
  *
  * PRECONDITIONS: @ref setMe() was called with a valid ChanUser object.
  *
  * @return The ChanUser object that was set as associated with
  *                  the client.
  */
  const ChanUser* getMe() const;

  /**
  * Find a specific ban in the channel banlist.
  *
  * @param banMask the mask of the ban to search for.
  */
  const Ban* findBan(QString banMask) const;

  /**
  * Get a UserListIterator on the channel's list of users.
  * This allows to iterate over the channel's userlist.
  * The order the users are listed is arbitrary.
  *
  * NOTE: this method allocates memory for a new UserListIterator object.
  * The calling method is responsible for freeing that memory.
  *
  * @return A pointer to an iterator initialized to the first user
  * on the channel (in arbitrary order).
  */
  UserListIterator* createUserListIterator() const;

  /**
  * Get a BanListIterator on the channel's banlist
  * This allows to iterate over all the bans on the channel.
  * The order the bans are listed is arbitrary.
  *
  * NOTE: this method allocates memory for a new BanListIterator object.
  * The calling method is responsible for freeing that memory.
  *
  * @return A pointer to an iterator initialized to the first ban
  * on the channel (in arbitrary order).
  */
  BanListIterator* createBanListIterator() const;

  static const int ModeOp = 1;
  static const int ModeVoice = 2;
  static const int ModeBan = 4;
  static const int ModeRestrictTopic = 8;
  static const int ModeNoExternalMsg = 16;
  static const int ModeInviteOnly = 32;
  static const int ModeLimit = 64;
  static const int ModeKey = 128;
  static const int ModeModerated = 256;
  static const int ModePrivate = 512;
  static const int ModeSecret = 1024;

  /**
  * Temporary.
  */
  void list() const;

protected:

  /**
  * Add or remove a mode from the channel, depending
  * on the addDelete flag.
  *
  * @param mode The mode to change (as defined in Channel::Mode constants).
  * @param addDelete Either '+' or '-'. The mode will be added if addDelete is
  *  '+', or removed if addDelete is '-'.
  */
  void setModes(const int mode,char addDelete = '+');

  /**
  * Change the channel's key.
  * @param key The new channel key.
  */
  void setKey(const QString& key);

  /**
  * Add the specified mode to the channel.
  *
  * @param value The mode to add, as defined in Channel::Mode constants
  */
  void addMode(const int value);
  /**
  * Remove the specified mode to the channel.
  *
  * @param value The mode to remove, as defined in Channel::Mode constants
  */
  void remMode(const int value);
  /**
  * Change the channel's limit.
  * @param value The new channel limit.
  */
  void setLimit(const int value);

  /**
  * Change the channel's reference to which user is the program
  * using the IRCModule.
  *
  * PRECONDITIONS: value != 0
  * @param value A pointer to the ChanUser object representing
  * the client.
  */
  void setMe(ChanUser* value);

  /**
  * Adds a new ban to the channel's banlist.
  *
  * @param theBan A pointer to the ban object to add to the list.
  *               This pointer should not be deleted or referenced
  *               after being added to the banlist.
  */
  void addBan(Ban* theBan);
  /**
  * Remove a ban from the channel's banlist.
  *
  * PRECONDITIONS: banMask != ""
  * @param banMask the mask of the ban to remove.
  * The mask is case insensitive.
  */
  void remBan(QString banMask);

  /**
  * Same as @ref findUser , but returns a non-const
  * pointer to the found user.
  *
  * NOTE: The pointer returned by this method should not be
  * deleted!
  *
  * @param nickname The nick of the user to find.
  * @return A pointer to the ChanUser object representing nickname,
  * or 0 if the user was not found.
  */
  ChanUser* findUserForUpdate(QString nickname);

  /**
  * Add a user to the channel's userlist.
  *
  * @param user A pointer to the ChanUser to add. That pointer
  * must not be externaly deleted!
  */
  void addUser(ChanUser* user);
  /**
  * Remove a user from the channel's userlist.
  *
  * @param nickname The nick of the user to delete. Nothing happens
  * if the user is not found.
  */
  void remUser(const QString& nickname);

  friend class IRCModule;
  friend class Channels;

private:  //## implementation
  QString _name;
  int _modes;
  int _limit;
  QString _key;
  ChanUser* _me;
  QDict<ChanUser>* _userList;
  QDict<Ban>* _banList;
};






#endif






Generated by: nightsky@centauri on Sat Jan 15 23:06:10 2000, using kdoc 2.0a30.