📄 qwscommand_qws.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qwscommand_qws_p.h"#include "qtransportauth_qws.h"#include "qtransportauth_qws_p.h"#include <sys/uio.h>// #define QWSCOMMAND_DEBUG 1 // Uncomment to debug client/server communication#ifdef QWSCOMMAND_DEBUG# include <qdebug.h># include "qfile.h"# include <ctype.h>// QWSHexDump -[ start ]---------------------------------------------# define QWSHEXDUMP_MAX 32class QWSHexDump{public: QWSHexDump(const void *address, int len, int wrapAt = 16) : wrap(wrapAt), dataSize(len) { init(); data = reinterpret_cast<const char*>(address); if (len < 0) dataSize = 0; } QWSHexDump(const char *str, int len = -1, int wrapAt = 16) : wrap(wrapAt), dataSize(len) { init(); data = str; if (len == -1) dataSize = str ? strlen(str) : 0; } QWSHexDump(const QByteArray &array, int wrapAt = 16) : wrap(wrapAt) { init(); data = array.data(); dataSize = array.size(); } // Sets a customized prefix for the hexdump void setPrefix(const char *str) { prefix = str; } // Sets number of bytes to cluster together void setClusterSize(uint num) { clustering = num; } // Output hexdump to a text stream void intoTextStream(QTextStream &strm) { outstrm = &strm; hexDump(); } // Output hexdump to a QString QString toString();protected: void init(); void hexDump(); void sideviewDump(int at);private: uint wrap; uint clustering; uint dataSize; int dataWidth; const char *data; const char *prefix; bool dirty; char sideviewLayout[QWSHEXDUMP_MAX + 1]; char sideview[15]; QTextStream *outstrm;};void QWSHexDump::init(){ prefix = "> "; // Standard line prefix clustering = 2; // Word-size clustering by default if (wrap > QWSHEXDUMP_MAX) // No wider than QWSHexDump_MAX bytes wrap = QWSHEXDUMP_MAX;}void QWSHexDump::hexDump(){ *outstrm << "(" << dataSize << " bytes):\n" << prefix; sprintf(sideviewLayout, " [%%-%us]", wrap); dataWidth = (2 * wrap) + (wrap / clustering); dirty = false; uint wrapIndex = 0; for (uint i = 0; i < dataSize; i++) { uint c = static_cast<uchar>(data[i]); sideview[wrapIndex = i%wrap] = isprint(c) ? c : '.'; if (wrapIndex && (wrapIndex % clustering == 0)) *outstrm << " "; outstrm->setFieldWidth(2); outstrm->setPadChar('0'); outstrm->setNumberFlags( QTextStream::ShowBase ); *outstrm << hex << c; dirty = true; if (wrapIndex == wrap-1) { sideviewDump(wrapIndex); wrapIndex = 0; if (i+1 < dataSize) *outstrm << endl << prefix; } } sideviewDump(wrapIndex);}void QWSHexDump::sideviewDump(int at){ if (dirty) { dirty = false; ++at; sideview[at] = '\0'; int currentWidth = (2 * at) + (at / clustering) - (at%clustering?0:1); int missing = qMax(dataWidth - currentWidth, 0); while (missing--) *outstrm << " "; *outstrm << " ["; outstrm->setPadChar(' '); outstrm->setFieldWidth(wrap); outstrm->setFieldAlignment( QTextStream::AlignLeft ); *outstrm << sideview; *outstrm << "]"; }}// Output hexdump to a QStringQString QWSHexDump::toString() { QString result; QTextStream strm(&result, QFile::WriteOnly); outstrm = &strm; hexDump(); return result;}#ifndef QT_NO_DEBUGQDebug &operator<<(QDebug &dbg, QWSHexDump *hd) { if (!hd) return dbg << "QWSHexDump(0x0)"; QString result = hd->toString(); dbg.nospace() << result; return dbg.space();}// GCC & Intel wont handle references hereQDebug operator<<(QDebug dbg, QWSHexDump hd) { return dbg << &hd;}#endif// QWSHexDump -[ end ]-----------------------------------------------QDebug &operator<<(QDebug &dbg, QWSCommand::Type tp){ dbg << qws_getCommandTypeString( tp ); return dbg;}#define N_EVENTS 19const char * eventNames[N_EVENTS] = { "NoEvent", "Connected", "Mouse", "Focus", "Key", "Region", "Creation", "PropertyNotify", "PropertyReply", "SelectionClear", "SelectionRequest", "SelectionNotify", "MaxWindowRect", "QCopMessage", "WindowOperation", "IMEvent", "IMQuery", "IMInit", "Font" };class QWSServer;extern QWSServer *qwsServer;#endifconst char *qws_getCommandTypeString( QWSCommand::Type tp ){ const char *typeStr; switch(tp) { case QWSCommand::Create: typeStr = "Create"; break; case QWSCommand::Shutdown: typeStr = "Shutdown"; break; case QWSCommand::Region: typeStr = "Region"; break; case QWSCommand::RegionMove: typeStr = "RegionMove"; break; case QWSCommand::RegionDestroy: typeStr = "RegionDestroy"; break; case QWSCommand::SetProperty: typeStr = "SetProperty"; break; case QWSCommand::AddProperty: typeStr = "AddProperty"; break; case QWSCommand::RemoveProperty: typeStr = "RemoveProperty"; break; case QWSCommand::GetProperty: typeStr = "GetProperty"; break; case QWSCommand::SetSelectionOwner: typeStr = "SetSelectionOwner"; break; case QWSCommand::ConvertSelection: typeStr = "ConvertSelection"; break; case QWSCommand::RequestFocus: typeStr = "RequestFocus"; break; case QWSCommand::ChangeAltitude: typeStr = "ChangeAltitude"; break; case QWSCommand::SetOpacity: typeStr = "SetOpacity"; break; case QWSCommand::DefineCursor: typeStr = "DefineCursor"; break; case QWSCommand::SelectCursor: typeStr = "SelectCursor"; break; case QWSCommand::PositionCursor: typeStr = "PositionCursor"; break; case QWSCommand::GrabMouse: typeStr = "GrabMouse"; break; case QWSCommand::PlaySound: typeStr = "PlaySound"; break; case QWSCommand::QCopRegisterChannel: typeStr = "QCopRegisterChannel"; break; case QWSCommand::QCopSend: typeStr = "QCopSend"; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -