Logo Search packages:      
Sourcecode: qchat version File versions  Download package

globals.h

/***************************************************************************
 *   Copyright (C) 2007 by Anistratov Oleg                                 *
 *   ower@users.sourceforge.net                                            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2        *
 *   as published by the Free Software Foundation;                         *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 ***************************************************************************/

#ifndef GLOBALS_H
#define GLOBALS_H

#include "preferences.h"
#include "logwgt.h"

#include <QByteArray>
#include <QColor>
#include <QHostAddress>
#include <QString>
#include <QNetworkInterface>

#define DEBUG 0

class UserInfo;

const unsigned short MAX_PACKET_LEN    = 65535 - 1024;

//\*****************************************************************************
struct QC_DatagramHeader
{
  unsigned short     programVersion;
  unsigned short     protocolVersion;
  unsigned long long dest_ip;
  unsigned long long src_ip;
  unsigned char      type;  /// tip paketa(iz enum DataType)
  unsigned long      id;    /// id paketa(dlya fragmentirovannyh paketov),esli 0,to paket fragment odin
  unsigned long      num;   /// nomer paketa (pakety s dannymi nachinayutsya s 1(pervogo:) !!!
  unsigned long long tm;    /// vremya otpravki
  unsigned long long receive_tm;/// vremya polucheniya
  unsigned long      chnnl_id;///id kanala, v kotryi poslano soobsch. etc
  unsigned char      comp_name_len;
  unsigned char      name_len;
  unsigned long      msg_len;
  unsigned long      parametrs_len;
  QString            name;
  QString            comp_name;
  QString            msg;
  QString            versionName;
  QColor             color;
  quint16            status;
  QByteArray         parametrs;/// soderzhit razlichnye dopolnitel'nye parametry

  QC_DatagramHeader(){}

};
//*****************************************************************************

class Globals
{
  public:
    static int g_debug      ;
    static int g_force_debug;

    static const int   ProtocolVersionID;
    static const char* ProgramID;
    static const int   VersionID;
    static const short ProtocolLen;
    static const int   Protocol[18];
    static const char* VersionsTable[14];
    static QString     VersionStr;
    static QString     StatusStr[7];

    static QString      gm_profileName;
    static Preferences* gm_prefs;
    static UserInfo*    gm_info;

    static QString      profileName() {return gm_profileName;}
    static Preferences* prefs()       {return gm_prefs;}
    static UserInfo*    info()        {return gm_info;}

    static void         setProfileName(const QString & name){gm_profileName = name;}
    static void         setInfo (UserInfo* info)            {gm_info = info;}
    static void         setPrefs(Preferences* prefs)        {gm_prefs = prefs;}

    static LogWgt*      m_log;

    static void addMessage(const QString & str, const QColor & color = QColor(Qt::black))
    {if(m_log) m_log->addMessage(str, color);}
    static void addInfo   (const QString & str)
    {if(m_log) m_log->addInfo(str);}
    static void addError  (const QString & str)
    {if(m_log) m_log->addError(str);}

    Globals(){}
    ~Globals(){}

    static quint32 localIp(QHostAddress* br);
    static QList<QNetworkInterface> validInterfeices();

    enum DataType
    {
      MESSAGE = 0,
      INFORMATION,
      CONNECTED,
      DISCONNECTED,
      AVATAR_REQUEST,
      AVATAR_ANSWER,
      STATUS_REQUEST,
      STATUS_ANSWER,
      INFO_REQUEST,
      INFO_ANSWER,
      INF_STATUS_CHNGD,
      FRAGMENTS_REQUEST,
      SINGLE_MESSAGE,
      FILE,
      ACCEPT,
      REJECT,
      CONFIRM,
      FINISHED,
      PRIVATE_CHAT_REQUEST,
      MSGS_HISTORY_REQUEST,
      MSGS_HISTORY_ANSWER,
      MSGS_NUM_REQUEST,
      MSGS_NUM_ANSWER,
    };

    enum StatusID{BUSY = 0, FREE = 1, READY4CHAT = 2, DND = 3, INACTIVE = 4, AWAY = 5, INVISIBLE = 6};
};

bool isSystemMsg(quint16 type);
char* datadup(const char* src, int n);
unsigned long long str2ULL(const char* str);
unsigned long      str2UL (const char* str);
unsigned short     str2US (const char* str);
int catULL2str(char* str, unsigned long long num);
int catUL2str (char* str, unsigned long      num);
int catUS2str (char* str, unsigned short     num);

#endif

Generated by  Doxygen 1.6.0   Back to index