You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bluesky-commits@incubator.apache.org by ma...@apache.org on 2010/12/14 01:35:56 UTC
svn commit: r1048897 -
/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/
Author: mabowen
Date: Tue Dec 14 01:35:55 2010
New Revision: 1048897
URL: http://svn.apache.org/viewvc?rev=1048897&view=rev
Log:
current student source code, gradually add protocol now.
Added:
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro.user
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.cpp
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.h
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.cpp
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.h
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.cpp
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.h
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/main.cpp
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.cpp
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.h
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.ui
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.cpp
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.h
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/protocol.h
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/qthreadex.h
incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/ui_mainwindow.h
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro Tue Dec 14 01:35:55 2010
@@ -0,0 +1,28 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-11-30T20:24:50
+#
+#-------------------------------------------------
+
+QT += core gui network xml
+
+TARGET = CommClient
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+ mainwindow.cpp \
+ msgagent.cpp \
+ commevent.cpp \
+ clientsocket.cpp \
+ Message.cpp
+
+HEADERS += mainwindow.h \
+ protocol.h \
+ msgagent.h \
+ commevent.h \
+ clientsocket.h \
+ qthreadex.h \
+ Message.h
+
+FORMS += mainwindow.ui
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro.user
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro.user?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro.user (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/CommClient.pro.user Tue Dec 14 01:35:55 2010
@@ -0,0 +1,113 @@
+<!DOCTYPE QtCreatorProject>
+<qtcreator>
+ <data>
+ <variable>ProjectExplorer.Project.ActiveTarget</variable>
+ <value type="int">0</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.EditorSettings</variable>
+ <valuemap type="QVariantMap">
+ <value key="EditorConfiguration.Codec" type="QByteArray">System</value>
+ </valuemap>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Target.0</variable>
+ <valuemap type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Desktop</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Target.DesktopTarget</value>
+ <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">0</value>
+ <value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
+ <valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">qmake</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
+ <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
+ </valuemap>
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
+ <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
+ <value type="QString">clean</value>
+ </valuelist>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
+ <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
+ <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Debug</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">E:/Qt/2010.04/qt/examples/CommClientUi/CommClient-build-desktop</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">2</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
+ </valuemap>
+ <valuemap key="ProjectExplorer.Target.BuildConfiguration.1" type="QVariantMap">
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">qmake</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
+ <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
+ </valuemap>
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
+ <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
+ <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
+ <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
+ <value type="QString">clean</value>
+ </valuelist>
+ <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
+ <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
+ <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Release</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">E:/Qt/2010.04/qt/examples/CommClientUi/CommClient-build-desktop</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">2</value>
+ <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
+ </valuemap>
+ <value key="ProjectExplorer.Target.BuildConfigurationCount" type="int">2</value>
+ <valuemap key="ProjectExplorer.Target.RunConfiguration.0" type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">CommClient</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4RunConfiguration</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.BaseEnvironmentBase" type="int">2</value>
+ <valuelist key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments" type="QVariantList"/>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.ProFile" type="QString">CommClient.pro</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix" type="bool">false</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal" type="bool">false</value>
+ <valuelist key="Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UserSetName" type="bool">false</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UserSetWorkingDirectory" type="bool">false</value>
+ <value key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory" type="QString"></value>
+ </valuemap>
+ <value key="ProjectExplorer.Target.RunConfigurationCount" type="int">1</value>
+ </valuemap>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.TargetCount</variable>
+ <value type="int">1</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
+ <value type="int">4</value>
+ </data>
+</qtcreator>
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.cpp?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.cpp (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.cpp Tue Dec 14 01:35:55 2010
@@ -0,0 +1,382 @@
+//////////////////////////////////////////////////////////////////////
+// æ件åï¼Message.cpp
+//
+// åãè½ï¼XMLæ ¼å¼çææ¬éä¿¡æ¶æ¯çå°è£
å解æ(æºæ件)
+//
+// çãæ¬ï¼1.0
+//
+// ä½ãè
ï¼ææ°
+//
+// æè¿ä¿®æ¹æ¥æï¼2007-09-18
+//////////////////////////////////////////////////////////////////////
+
+#include "Message.h"
+
+#ifdef _DEBUG
+#undef THIS_FILE
+static char THIS_FILE[]=__FILE__;
+#define new DEBUG_NEW
+#endif
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+// æé å½æ°
+// åå§åå个æååé
+QMessage::QMessage()
+{
+ //æ¶æ¯ççæ¬åå符éä¿¡æ¯
+ strText = "<?xml version=\"1.0\" encoding=\"GB2312\" ?>";
+ strCmd = "NULL";
+ strID = "NULL";
+ strName = "NULL";
+ strType = "NULL";
+ bIsCrypt = false;
+ bIsCompress = false;
+ strCreateDate = "NULL";
+ bHasBody = false;
+}
+
+// ææå½æ°
+// éæ¾åå¨å
ä½æå çMapæ ç空é´
+QMessage::~QMessage()
+{
+}
+
+//设置æ¶æ¯å·
+void QMessage::SetCmd(LPCTSTR pa)
+{
+ strCmd = pa;
+}
+
+//亩åéè
ID
+void QMessage::SetID(LPCTSTR pa)
+{
+ strID = pa;
+}
+
+//设置åéè
ç¨æ·å
+void QMessage::SetName(LPCTSTR pa)
+{
+ strName = pa;
+}
+
+//设置åéè
ç±»å
+void QMessage::SetType(LPCTSTR pa)
+{
+ strType = pa;
+}
+
+//设置æ¯å¦å å¯ç
+void QMessage::SetCrypt(bool pa)
+{
+ bIsCrypt = pa;
+}
+
+//设置æ¯å¦å缩
+void QMessage::SetCompress(bool pa)
+{
+ bIsCompress = pa;
+}
+
+//设置æ¥æ
+void QMessage::SetCreateDate(LPCTSTR pa)
+{
+ strCreateDate = pa;
+}
+
+//设置æ¯å¦æå
ä½
+void QMessage::SetHasBody(bool pa)
+{
+ if(pa)
+ bHasBody = true;
+ else bHasBody = false;
+}
+
+//设置å
ä½æéææåç Mapæ çæ æ ¹
+void QMessage::SetBody(QMap<QString,QVariant> pa)
+{
+ if(!pa.isEmpty())
+ {
+ bHasBody = true;
+ pBodyMap = pa;
+ }
+}
+
+//å¤ææ¯å¦æ¯strå¼å¤´çç®åå符串èç¹
+bool QMessage::IsStringNode(QString strNodeName)
+{
+ if (strNodeName.toLower().left(3)=="str")
+ return true;
+ else return false;
+}
+
+//å¤ææ¯å¦æ¯lstå¼å¤´çå¤æèç¹
+bool QMessage::IsListNode(QString strNodeName)
+{
+ //strNodeName.MakeLower();
+ if (strNodeName.toLower().left(3)=="lst")
+ return true;
+ else return false;
+}
+
+//æMap对象åå
¶ä»¥ä¸çæ 转æ¢æMarkupä¸çä¸ç³»åèç¹ (éå½å½æ°)
+void QMessage::MapToMarkup(QMap<QString,QVariant> &ChildMap){
+ QMap<QString,QVariant>::iterator iter;
+ QMap<QString,QVariant> list1;
+ QString key;
+ QString temp;
+ QDomElement root = nowroot;
+ for(iter = ChildMap.begin(); iter != ChildMap.end(); iter++)
+ {
+ key=iter.key();
+ cout<<key.toStdString()<<":";
+ //å¦æ 该èç¹æ¯å¤æçå表èç¹, éå½è°ç¨è¯¥å½æ°æ¥éæ¾å¯¹è±¡ç©ºé´
+ if( IsListNode(key) )
+ {
+ list1=iter.value().toMap();
+ QDomElement element= doc.createElement(key);
+ nowroot.appendChild(element);
+ nowroot=element;
+ MapToMarkup(list1);
+ nowroot=root;
+ }
+ //å¦ææ¯ç®åçææ¬èç¹,å读åå称åææ¬å
容
+ else if(IsStringNode(key))
+ {
+ temp =iter.value().toString();
+ cout<<temp.toStdString()<<endl;
+ QDomElement element= doc.createElement(key);
+ QDomText text = doc.createTextNode(temp);
+ element.appendChild(text);
+ nowroot.appendChild(element);
+ }
+ }
+}
+
+//æmarkupä¸å½åçå¤æç»ç¹å å
¥childmap
+//è¿æ¯ä¸ä¸ªéå½å½æ°ï¼éå½æç´¢CMarkupä¸çå个æ ç»ç¹
+void QMessage::MarkupToMap(QMap<QString,QVariant> &ChildMap)
+{
+ QMap<QString,QVariant> mapNode;
+ QString qsNode;
+ if(nowroot.isNull()){
+ nowroot=doc.documentElement();
+ }
+ QDomNode n = nowroot.firstChild();
+ while(!n.isNull()) {
+ QDomElement e = n.toElement(); // try to convert the node to an element.
+ if(!e.isNull()) {
+ if(e.firstChild().isText())
+ {//ç®åèç¹
+ qsNode=e.text();
+ ChildMap.insert(e.tagName(),qsNode);
+ cout<<e.tagName().toStdString()<<":"<<e.text().toStdString()<<endl;
+ }
+ else
+ {
+ mapNode=QMap<QString,QVariant>();
+ ChildMap.insert(e.tagName(),mapNode);
+ cout<<e.tagName().toStdString()<<endl;
+ nowroot=e;
+ MarkupToMap(ChildMap);
+ }
+ }
+ n = n.nextSibling();
+ }
+}
+
+
+//å°è£
ä¸ä¸ªæ¶æ¯å°å符串ã
+//å¦æUrl为空ï¼ååªè¿åå°è£
åæ¶æ¯å符串ï¼
+//å¦æUrlæå®ç¡®å®å¼ï¼åè¿è¦ææ¶æ¯å
容åå°è¯¥Urlæå®çææ¬æ件ã
+QString& QMessage::CreateMsg(LPCTSTR Url)
+{
+ QString strTemp;
+ QDomElement head;
+ QDomElement temp;
+ //TODO éè¦éæ
+ nowroot=doc.createElement("Message");
+ doc.appendChild(nowroot);
+ head=doc.createElement("Head");
+ nowroot.appendChild(head);
+ temp=doc.createElement("Cmd");
+ head.appendChild(temp);
+ temp.appendChild(doc.createTextNode(strCmd));
+ temp=doc.createElement("ID");
+ head.appendChild(temp);
+ temp.appendChild(doc.createTextNode(strID));
+ temp=doc.createElement("Name");
+ head.appendChild(temp);
+ temp.appendChild(doc.createTextNode(strName));
+ temp=doc.createElement("Type");
+ head.appendChild(temp);
+ temp.appendChild(doc.createTextNode(strType));
+ temp=doc.createElement("IsCrypt");
+ head.appendChild(temp);
+ temp.appendChild(doc.createTextNode(bIsCrypt ? "true":"false"));
+ temp=doc.createElement("IsCompress");
+ head.appendChild(temp);
+ temp.appendChild(doc.createTextNode(bIsCompress ? "true":"false"));
+ temp=doc.createElement("CreateDate");
+ head.appendChild(temp);
+ temp.appendChild(doc.createTextNode(strCreateDate));
+ temp=doc.createElement("HasBody");
+ head.appendChild(temp);
+ temp.appendChild(doc.createTextNode(bHasBody ? "true":"false"));
+
+ //å¦ææ å¿æ示æå
ä½å
容ï¼ä¸å
ä½å
容æéä¸ä¸ºç©ºï¼å读åå
¶å
容
+ if(bHasBody && !pBodyMap.isEmpty())
+ {
+ QDomElement body=doc.createElement("Body");
+ doc.appendChild(body);
+ nowroot=body;
+ MapToMarkup(pBodyMap);
+ }
+ strText=doc.toString();
+#ifdef _DEBUG
+ //å¦ææUrlåæ°ï¼åææ¶æ¯å
容ä¿åå°å
¶æå®çä½ç½®
+// if(Url) doc->Save(Url);
+
+ strText += doc->GetDoc();
+#endif
+ return strText;
+}
+
+//è·åæ¶æ¯å·
+QString QMessage::GetCmd()
+{
+ return strCmd;
+}
+
+//亩åéè
ID
+QString QMessage::GetID()
+{
+ return strID;
+}
+
+//è·ååéè
ç¨æ·å
+QString QMessage::GetName()
+{
+ return strName;
+}
+
+//è·ååéè
ç±»å
+QString QMessage::GetType()
+{
+ return strType;
+}
+
+//è·åæ¯å¦å å¯ç
+bool QMessage::IsCrypt()
+{
+ return bIsCrypt;
+}
+
+//è·åæ¯å¦å缩
+bool QMessage::IsCompress()
+{
+ return bIsCompress;
+}
+
+//è·åæ¥æ
+QString QMessage::GetCreateDate()
+{
+ return strCreateDate;
+}
+
+//è·åæ¯å¦æå
ä½
+bool QMessage::HasBody()
+{
+ return bHasBody;
+}
+
+//è·åå
ä½æéææåç Mapæ çæ æ ¹
+QMap<QString,QVariant> QMessage::GetBody()
+{
+ return pBodyMap;
+}
+
+//解æææ¬æ¶æ¯ï¼æå个æ¶æ¯å
容åå
¥ç¸å¯¹çåé
+bool QMessage::ParseMsg(LPCTSTR msg, int file)//
+{
+ strText = QString(msg);
+ //å¦æè°ç¨å½æ°æ¶æfileåæ°ï¼ä»æ件载å
¥XMLæ¶æ¯ã
+ if(file){
+ QFile file(msg);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ return false;
+ }
+ QString errorStr;
+ int errorLine;
+ int errorColumn;
+
+ if (!doc.setContent(&file, false, &errorStr, &errorLine, &errorColumn)) {
+ return false;
+ }
+ file.close();
+ }
+ else doc.setContent(QString(msg));
+ //å¦æè°ç¨å½æ°æ¶æ²¡æfileåæ°ï¼ä»å符串载å
¥XMLæ¶æ¯ã
+ nowroot=doc.documentElement();
+ if(!doc.elementsByTagName("Message").isEmpty())
+ {
+ //解ææ¶æ¯å
头é¨åï¼ææ¶æ¯å¤´çå个åå
容æ¾å
¥ç¸åºåé
+ if(!doc.elementsByTagName("Head").isEmpty())
+ {
+ //TODO éè¦éæ
+ //è¿å
¥å
头
+ if(!doc.elementsByTagName("Cmd").isEmpty())
+ {
+ strCmd = doc.elementsByTagName("Cmd").at(0).toElement().text();
+ }
+ if(!doc.elementsByTagName("ID").isEmpty())
+ {
+ strID = doc.elementsByTagName("ID").at(0).toElement().text();
+ }
+ if(!doc.elementsByTagName("Name").isEmpty())
+ {
+ strName = doc.elementsByTagName("Name").at(0).toElement().text();
+ }
+ if(!doc.elementsByTagName("Type").isEmpty())
+ {
+ strType = doc.elementsByTagName("Type").at(0).toElement().text();
+ }
+ if(!doc.elementsByTagName("IsCrypt").isEmpty())
+ {
+ if(doc.elementsByTagName("IsCrypt").at(0).toElement().text() == "true")
+ bIsCrypt = true;
+ else bIsCrypt = false;
+ }
+ if(!doc.elementsByTagName("IsCompress").isEmpty())
+ {
+ if(doc.elementsByTagName("IsCompress").at(0).toElement().text() == "true")
+ bIsCompress = true;
+ else bIsCompress = false;
+ }
+ if(!doc.elementsByTagName("CreateDate").isEmpty())
+ {
+ strCreateDate = doc.elementsByTagName("CreateDate").at(0).toElement().text();
+ }
+ if(!doc.elementsByTagName("HasBody").isEmpty())
+ {
+ QString temp;
+ temp = doc.elementsByTagName("HasBody").at(0).toElement().text();
+ if(temp == "true")
+ bHasBody = true;
+ else bHasBody = false;
+ }
+ //éåºå
头
+ }
+ //å¦ææå
ä½ï¼åæ ¹æ®å
ä½çæ ç»æå建ä¸æ£µç±QMap<QString,QVariant>对象ææçå
ä½æ ï¼å¹¶ææ ¹æéèµç»BodyMap
+ if(bHasBody)//HasBody
+ {
+ nowroot=doc.elementsByTagName("Body").at(0).toElement();
+ pBodyMap = QMap<QString,QVariant>();
+ MarkupToMap(pBodyMap);
+ }
+ }
+ return true;
+
+}
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.h?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.h (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/Message.h Tue Dec 14 01:35:55 2010
@@ -0,0 +1,120 @@
+//////////////////////////////////////////////////////////////////////
+// æ件åï¼Message.h
+//
+// åãè½ï¼XMLæ ¼å¼çææ¬éä¿¡æ¶æ¯çå°è£
å解æ(头æ件)
+//
+// çãæ¬ï¼1.0
+//
+// ä½ãè
ï¼ææ°
+//
+// QTçæ¬ï¼0.2
+//
+// ä½ãè
ï¼é广ç¨
+//
+// æè¿ä¿®æ¹æ¥æï¼2010-11-17
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_MESSAGE_H__0AB58702_913F_4B17_9788_C79DE8DDDD5C__INCLUDED_)
+#define AFX_MESSAGE_H__0AB58702_913F_4B17_9788_C79DE8DDDD5C__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+#ifdef _UNICODE
+ typedef const wchar_t * LPCTSTR;
+#else
+ typedef const char * LPCTSTR;
+#endif
+
+#include <QMap>
+#include <QVariant>
+#include <QString>
+#include <QFile>
+#include <QDomDocument>
+#include <iostream>
+ using namespace std;
+//#include "Markup.h"
+
+//模åéä¿¡æ¶æ¯ç±»
+class QMessage
+{
+public:
+ QMessage();
+ ~QMessage();
+
+public:
+
+ //å°è£
XMLåè®®æ¶æ¯çæ¹æ³
+ //设置æ¶æ¯å·
+ void SetCmd(LPCTSTR pa);
+ //设置åéæ¹ID
+ void SetID(LPCTSTR pa);
+ //设置åéæ¹ç¨æ·å
+ void SetName(LPCTSTR pa);
+ //设置åéæ¹ç±»å
+ void SetType(LPCTSTR pa);
+ //设置æ¯å¦å å¯
+ void SetCrypt(bool pa);
+ //设置æ¯å¦å缩
+ void SetCompress(bool pa);
+ //设置å建æ¥æ
+ void SetCreateDate(LPCTSTR pa);
+ //设置æ¯å¦æå
ä½æ å¿
+ void SetHasBody(bool pa);
+ //设置å
ä½æé
+ void SetBody(QMap<QString,QVariant> pa);
+ //å°è£
ä¸ä¸ªæ¶æ¯å°å符串ã
+ //å¦æUrl为空ï¼ååªè¿åå°è£
åæ¶æ¯å符串ï¼
+ //å¦æUrlæå®ç¡®å®å¼ï¼åè¿è¦ææ¶æ¯å
容åå°è¯¥Urlæå®çææ¬æ件ã
+ QString& CreateMsg(LPCTSTR Url = NULL);
+
+
+ //解æXMLåè®®æ¶æ¯çæ¹æ³
+ //å¦æè°ç¨æ¤å½æ°æ¶åªå¸¦ä¸ä¸ªå符串åæ°,å解æ该å符串;
+ //å¦ææ³è§£æä¸ä¸ªææ¬æ件,å第ä¸ä¸ªåæ°ä¸ºæ件路å¾,第äºä¸ªä¸º1
+ bool ParseMsg(LPCTSTR msg, int file=0);//
+ //è·åæ¶æ¯å·
+ QString GetCmd();
+ //è·åæ¶æ¯åéæ¹ID
+ QString GetID();
+ //è·åæ¶æ¯åéæ¹ç¨æ·å
+ QString GetName();
+ //è·ååéæ¹ç±»å
+ QString GetType();
+ //è·åæ¯å¦å å¯
+ bool IsCrypt();
+ //è·åæ¯å¦å缩
+ bool IsCompress();
+ //è·åå建æ¥æ
+ QString GetCreateDate();
+ //è·åæ¯å¦æå
ä½æ å¿
+ bool HasBody();
+ //è·åæ¶æ¯å
ä½æé
+ QMap<QString,QVariant> GetBody();
+
+
+
+
+private:
+ QDomDocument doc; //XML解æ转æ¢ç±»Markup对象æé
+ QDomElement nowroot;
+ QString strCmd; //map<QString,void *>æ¶æ¯ç¼å·
+ QString strID; //åéæ¹ID
+ QString strName; //åéæ¹ç¨æ·å
+ QString strType; //åéæ¹ç±»å
+ QString strText; //æ¶æ¯ææ¬
+ bool bIsCrypt; //æ¯å¦å å¯
+ bool bIsCompress; //æ¯å¦å缩
+ QString strCreateDate; //å建æ¥æ
+ bool bHasBody; //æ¯å¦æå
ä½ä¿¡æ¯æ å¿
+ QMap<QString,QVariant> pBodyMap; //å
ä½å
容æé
+ void MapToMarkup(QMap<QString,QVariant> &ChildMap);
+ void MarkupToMap(QMap<QString,QVariant> &ChildMap);
+
+
+ bool IsStringNode(QString strNodeName);
+ bool IsListNode(QString strNodeName);
+
+};
+
+#endif // !defined(AFX_MESSAGE_H__0AB58702_913F_4B17_9788_C79DE8DDDD5C__INCLUDED_)
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.cpp?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.cpp (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.cpp Tue Dec 14 01:35:55 2010
@@ -0,0 +1,130 @@
+
+#include <QCoreApplication>
+#include "clientsocket.h"
+#include "commevent.h"
+#include <iostream>
+
+
+
+ClientSocket::ClientSocket(QObject* pmsgagent,QObject * parent)
+ :QTcpSocket(parent),
+ nextMessageSize(0),
+ m_pmsgagent(pmsgagent)
+{
+ connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
+ connect(this, SIGNAL(disconnected()), this, SLOT(clientDisconnect()));
+ connect(this, SIGNAL(error(QAbstractSocket::SocketError)),
+ this, SLOT(gotError()));
+
+ //connect(this,SIGNAL(onReceived(char*)),m_pmsgserver,SLOT(onReceived(char*)));
+}
+
+ClientSocket::~ClientSocket()
+{
+ delete m_pmsgagent;
+}
+
+void ClientSocket::readClient()
+{
+ //get the total length of the msg
+ char head[8];
+ memset(head, 0, 8);
+ if(read(head, 8) == -1)
+ {
+ return;
+ }
+ int totallength = atoi(head);
+
+ char recvbuffer[10000];
+ memset(recvbuffer, 0, 10000);
+ //where to write
+ int index = 0;
+ //each time how many chars reved
+ int recvlength = 0;
+ //
+ int torecvlength = totallength - 8;
+
+ do
+ {
+ recvlength = read(recvbuffer+index, torecvlength);
+ if(recvlength == -1)
+ {
+ return;
+ }
+ index += recvlength;
+ torecvlength -= recvlength;
+ }
+ while(torecvlength != 0);
+
+ CommEvent* ce = new CommEvent(SkyClass::GotMessage,
+ new QString(recvbuffer));
+ QCoreApplication::postEvent(m_pmsgagent,ce);
+}
+
+
+void ClientSocket::clientDisconnect()
+{
+// CommEvent* ce = new CommEvent(SkyClass::ClientDisconnect,
+// 0);
+ CommEvent* ce = new CommEvent(SkyClass::ClientDisconnect,
+ new QString("client log out!"));
+ QCoreApplication::postEvent(m_pmsgagent,ce);
+}
+
+void ClientSocket::gotError()
+{
+ this->error();
+ if(this->error() != QTcpSocket::RemoteHostClosedError)
+ {
+ clientDisconnect();
+ }
+}
+
+void ClientSocket::Connect(QString* pip,int port)
+{
+ this->connectToHost(*pip, port);
+}
+void ClientSocket::Send(QString* msg)
+{
+ char strmsg[10000];
+ memset(strmsg, 0, 10000);
+ sprintf(strmsg,"%08d%s",msg->length()+8,msg->toLatin1().data());
+ this->write(strmsg);
+}
+void ClientSocket::DisConnect()
+{
+ this->disconnectFromHost();
+}
+
+bool ClientSocket::event(QEvent * event)
+{
+ if(event->type() == QEvent::User)
+ {
+ CommEvent * ue = static_cast<CommEvent *>(event);
+ switch(ue->commType)
+ {
+ case SkyClass::DoConnect:
+ Connect(ue->m_pMsg,ue->m_n);
+ delete ue->m_pMsg;
+ break;
+ case SkyClass::SendMessage:
+ Send(ue->m_pMsg);
+ delete ue->m_pMsg;
+ break;
+ //add by kevin
+ case SkyClass::DoDisconnect:
+ Send(ue->m_pMsg);
+ this->DisConnect();
+ delete ue->m_pMsg;
+ std::cout << "client disconnect!" << std::endl;
+ break;
+ default:
+ return false;
+ }
+ }
+ else
+ {
+ return QObject::event(event);
+ }
+ return true;
+}
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.h?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.h (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/clientsocket.h Tue Dec 14 01:35:55 2010
@@ -0,0 +1,43 @@
+#ifndef CLIENTSOCKET_H
+#define CLIENTSOCKET_H
+
+
+#include <QTcpSocket>
+#include <QPointer>
+#include "protocol.h"
+
+
+class ClientSocket : public QTcpSocket
+{
+ Q_OBJECT
+public:
+ ClientSocket(QObject* pmsgagent,QObject *parent = 0);
+ ~ClientSocket();
+
+private slots:
+ void readClient();
+ void clientDisconnect();
+ void gotError();
+
+
+ bool event(QEvent * event);
+
+public slots:
+ void Connect(QString* pip,int port);
+ void Send(QString* msg);
+ void DisConnect();
+
+
+signals:
+ void onReceived(char* msg);
+ void onConnectionClosed();
+
+
+private:
+ quint32 nextMessageSize;
+ QObject* m_pmsgagent;
+};
+
+typedef QPointer<ClientSocket> pClientSocket;
+
+#endif // CLIENTSOCKET_H
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.cpp?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.cpp (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.cpp Tue Dec 14 01:35:55 2010
@@ -0,0 +1,6 @@
+#include "commevent.h"
+
+CommEvent::CommEvent(SkyClass::EventType ut,QString* pmsg)
+ :QEvent(QEvent::User),commType(ut),m_pMsg(pmsg)
+{
+}
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.h?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.h (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/commevent.h Tue Dec 14 01:35:55 2010
@@ -0,0 +1,24 @@
+#ifndef COMMEVENT_H
+#define COMMEVENT_H
+
+#include <QEvent>
+#include <QString>
+
+#include "protocol.h"
+#include "clientsocket.h"
+
+
+class CommEvent : public QEvent
+{
+public:
+ CommEvent(SkyClass::EventType commType,QString* pmsg);
+ SkyClass::EventType commType;
+
+ //dest ip or msg
+ QString* m_pMsg;
+
+ //dest port
+ int m_n;
+};
+
+#endif // COMMEVENT_H
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/main.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/main.cpp?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/main.cpp (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/main.cpp Tue Dec 14 01:35:55 2010
@@ -0,0 +1,28 @@
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+#include "msgagent.h"
+#include "qthreadex.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+
+ MsgAgent agent;
+ MainWindow w(&agent);
+ ClientSocket socket(&agent);
+
+ agent.m_peventui = &w;
+ agent.m_peventsocket = &socket;
+
+ QThreadEx agentthread;
+ QThreadEx socketthread;
+
+ agent.moveToThread(&agentthread);
+ socket.moveToThread(&socketthread);
+
+ agentthread.start();
+ socketthread.start();
+ w.show();
+
+ return a.exec();
+}
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.cpp?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.cpp (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.cpp Tue Dec 14 01:35:55 2010
@@ -0,0 +1,76 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+#include "commevent.h"
+#include <QMutexLocker>
+#include <QDateTime>
+#include <QWidget>
+#include <iostream>
+MainWindow::MainWindow(QObject* msgagent,QWidget *parent) :
+ m_peventmsgagent(msgagent),
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+ //Ó³ÉäÍ˳ö¶¯×÷
+// connect(ui->logoutButton, SIGNAL(clicked()), this, SLOT(on_logoutButton_clicked()));
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::on_connectButton_clicked()
+{
+ CommEvent* ce = new CommEvent(SkyClass::DoConnect,
+ new QString("127.0.0.1"));
+ ce->m_n = 7000;
+ QCoreApplication::postEvent(m_peventmsgagent,ce);
+}
+
+void MainWindow::on_loginButton_clicked()
+{
+ //get some info from ui
+ //to do
+ //create a xml message
+ CommEvent* ce = new CommEvent(SkyClass::SendMessage,
+ new QString("this is from test client!"));
+ QCoreApplication::postEvent(m_peventmsgagent,ce);
+}
+
+void MainWindow::on_logoutButton_clicked()
+{
+ CommEvent* ce = new CommEvent(SkyClass::ClientDisconnect,
+ new QString("client log out"));
+ QCoreApplication::postEvent(m_peventmsgagent,ce);
+
+}
+/*
+bool MainWindow::event(QEvent * event)
+{
+ if(event->type() == QEvent::User)
+ {
+ //ue will be deleted automaticly
+ //a new event
+ CommEvent * ue = static_cast<CommEvent *>(event);
+ QListWidgetItem *lst;
+ switch(ue->commType)
+ {
+ case SkyClass::LogEvent:
+ lst = new QListWidgetItem(QDateTime::currentDateTime().toString(Qt::ISODate)+": " + *(ue->m_pMsg));//, listWidget);
+
+ ui->listWidget->insertItem(1,lst);
+
+ delete ue->m_pMsg;
+ break;
+ default:
+ return false;
+ }
+ }
+ else
+ {
+ return QObject::event(event);
+ }
+ return true;
+}
+*/
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.h?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.h (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.h Tue Dec 14 01:35:55 2010
@@ -0,0 +1,33 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QMutex>
+
+namespace Ui {
+ class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QObject* msgagent,QWidget *parent = 0);
+ ~MainWindow();
+
+private:
+ Ui::MainWindow *ui;
+ QObject* m_peventmsgagent;
+
+ //bool event(QEvent * event);
+ QMutex m_logmutex;
+
+ public slots:
+ void on_loginButton_clicked();
+ void on_connectButton_clicked();
+ //add by kevin
+ void on_logoutButton_clicked();
+};
+
+#endif // MAINWINDOW_H
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.ui
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.ui?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.ui (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/mainwindow.ui Tue Dec 14 01:35:55 2010
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>ClientWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <widget class="QPushButton" name="connectButton">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>20</y>
+ <width>75</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Connect</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="loginButton">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>60</y>
+ <width>75</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Login</string>
+ </property>
+ </widget>
+ <widget class="QListWidget" name="listWidget">
+ <property name="geometry">
+ <rect>
+ <x>145</x>
+ <y>20</y>
+ <width>231</width>
+ <height>231</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="logoutButton">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>170</y>
+ <width>75</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Logout</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>20</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.cpp?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.cpp (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.cpp Tue Dec 14 01:35:55 2010
@@ -0,0 +1,82 @@
+#include <QCoreApplication>
+#include <QMutexLocker>
+#include "msgagent.h"
+#include "commevent.h"
+#include "clientsocket.h"
+#include <QtGlobal>
+
+MsgAgent::MsgAgent(QObject *parent) :
+ QObject(parent)
+{
+}
+
+
+bool MsgAgent::event(QEvent * event)
+{
+ if(event->type() == QEvent::User)
+ {
+ //ue will be deleted automaticly
+ //a new event
+ CommEvent * ue = static_cast<CommEvent *>(event);
+ CommEvent* ce;
+ switch(ue->commType)
+ {
+ case SkyClass::DoConnect:
+ ce = new CommEvent(SkyClass::DoConnect, ue->m_pMsg);
+ ce->m_n = ue->m_n;
+ QCoreApplication::postEvent(m_peventsocket, ce);
+ break;
+ case SkyClass::SendMessage:
+ ce = new CommEvent(SkyClass::SendMessage, ue->m_pMsg);
+ QCoreApplication::postEvent(m_peventsocket, ce);
+ break;
+ case SkyClass::GotMessage:
+ parserequst(ue->m_pMsg);
+ delete ue->m_pMsg;
+ break;
+ case SkyClass::ClientDisconnect:
+ onConnectionClosed(ue->m_pMsg);
+ qDebug("dissconnect message send!");
+ break;
+ default:
+ return false;
+ }
+ }
+ else
+ {
+ return QObject::event(event);
+ }
+ return true;
+}
+
+bool MsgAgent::onConnectionClosed(QString *pMsg)
+{
+ CommEvent* ce = new CommEvent(SkyClass::DoDisconnect,
+ new QString(*pMsg));
+ QCoreApplication::postEvent(m_peventui,ce);
+
+ return true;
+}
+
+bool MsgAgent::parserequst(QString* pmsg)
+{
+ //to do
+
+
+ //show this message
+ CommEvent* ce = new CommEvent(SkyClass::LogEvent,
+ new QString(*pmsg));
+ QCoreApplication::postEvent(m_peventui,ce);
+
+
+
+
+
+ //SendMyMsg(*pmsg,psocket);
+
+
+
+ return true;
+}
+
+
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.h?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.h (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/msgagent.h Tue Dec 14 01:35:55 2010
@@ -0,0 +1,30 @@
+#ifndef MSGAGENT_H
+#define MSGAGENT_H
+
+#include <QObject>
+#include <QList>
+#include <QMutex>
+
+#include "commevent.h"
+
+class MsgAgent : public QObject
+{
+ Q_OBJECT
+public:
+ MsgAgent(QObject *parent = 0);
+
+ QObject* m_peventui;
+ QObject* m_peventsocket;
+
+private:
+ bool event(QEvent * event);
+ bool onConnectionClosed(QString *pMsg);
+
+ bool parserequst(QString* pmsg);
+
+private:
+
+
+};
+
+#endif // MSGAGENT_H
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/protocol.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/protocol.h?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/protocol.h (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/protocol.h Tue Dec 14 01:35:55 2010
@@ -0,0 +1,49 @@
+#ifndef PROTOCOL_H
+#define PROTOCOL_H
+
+#include <QObject>
+
+namespace SkyClass
+{
+ const quint32 ServerId = 0;
+ const quint32 CenterId = 1;
+ const quint32 SystemId = 2;
+
+ const quint8 UserInfoUpdateAction = 0;
+ const quint8 UserInfoNewAction = 1;
+ const quint8 UserInfoLeaveAction = 2;
+
+ enum ClientType {ClientTypeBegin = 7000,
+ UnKnown,
+ Teacher,
+ Student,
+ DTU};
+
+ enum EventType {EventTypeBegin = 8000,
+ LogEvent,
+ ErrorEvent,
+ ClientConnected,
+ ClientReg,
+ ClientDisconnect,
+ ServerConnected,
+ ServerDisconnect,
+ DoConnect,
+ DoDisconnect,
+ GotMessage,
+ SendMessage,
+ GotUserInfo,
+ SendUserInfo,
+ GotClientInfo,
+ SendClientInfo,
+ EventTypeEnd};
+ namespace MsgType{
+ enum MsgType{
+ MsgTypeBegin,
+ ClientInfo,
+ UserInfo,
+ Message,
+ MsgTypeEnd};
+ }
+}
+
+#endif // PROTOCOL_H
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/qthreadex.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/qthreadex.h?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/qthreadex.h (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/qthreadex.h Tue Dec 14 01:35:55 2010
@@ -0,0 +1,12 @@
+#ifndef QTHREADEX_H
+#define QTHREADEX_H
+
+#include <QThread>
+
+class QThreadEx : public QThread
+{
+protected:
+ void run(){exec();}
+};
+
+#endif // QTHREADEX_H
Added: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/ui_mainwindow.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/ui_mainwindow.h?rev=1048897&view=auto
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/ui_mainwindow.h (added)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/StudentQT-0.2.0/ui_mainwindow.h Tue Dec 14 01:35:55 2010
@@ -0,0 +1,92 @@
+/********************************************************************************
+** Form generated from reading UI file 'mainwindow.ui'
+**
+** Created: Mon Dec 13 20:12:14 2010
+** by: Qt User Interface Compiler version 4.6.3
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UI_MAINWINDOW_H
+#define UI_MAINWINDOW_H
+
+#include <QtCore/QVariant>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QButtonGroup>
+#include <QtGui/QHeaderView>
+#include <QtGui/QListWidget>
+#include <QtGui/QMainWindow>
+#include <QtGui/QMenuBar>
+#include <QtGui/QPushButton>
+#include <QtGui/QStatusBar>
+#include <QtGui/QToolBar>
+#include <QtGui/QWidget>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_MainWindow
+{
+public:
+ QWidget *centralWidget;
+ QPushButton *connectButton;
+ QPushButton *loginButton;
+ QListWidget *listWidget;
+ QPushButton *logoutButton;
+ QMenuBar *menuBar;
+ QToolBar *mainToolBar;
+ QStatusBar *statusBar;
+
+ void setupUi(QMainWindow *MainWindow)
+ {
+ if (MainWindow->objectName().isEmpty())
+ MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
+ MainWindow->resize(400, 300);
+ centralWidget = new QWidget(MainWindow);
+ centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
+ connectButton = new QPushButton(centralWidget);
+ connectButton->setObjectName(QString::fromUtf8("connectButton"));
+ connectButton->setGeometry(QRect(30, 20, 75, 23));
+ loginButton = new QPushButton(centralWidget);
+ loginButton->setObjectName(QString::fromUtf8("loginButton"));
+ loginButton->setGeometry(QRect(30, 60, 75, 23));
+ listWidget = new QListWidget(centralWidget);
+ listWidget->setObjectName(QString::fromUtf8("listWidget"));
+ listWidget->setGeometry(QRect(145, 20, 231, 231));
+ logoutButton = new QPushButton(centralWidget);
+ logoutButton->setObjectName(QString::fromUtf8("logoutButton"));
+ logoutButton->setGeometry(QRect(30, 170, 75, 23));
+ MainWindow->setCentralWidget(centralWidget);
+ menuBar = new QMenuBar(MainWindow);
+ menuBar->setObjectName(QString::fromUtf8("menuBar"));
+ menuBar->setGeometry(QRect(0, 0, 400, 20));
+ MainWindow->setMenuBar(menuBar);
+ mainToolBar = new QToolBar(MainWindow);
+ mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
+ MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
+ statusBar = new QStatusBar(MainWindow);
+ statusBar->setObjectName(QString::fromUtf8("statusBar"));
+ MainWindow->setStatusBar(statusBar);
+
+ retranslateUi(MainWindow);
+
+ QMetaObject::connectSlotsByName(MainWindow);
+ } // setupUi
+
+ void retranslateUi(QMainWindow *MainWindow)
+ {
+ MainWindow->setWindowTitle(QApplication::translate("MainWindow", "ClientWindow", 0, QApplication::UnicodeUTF8));
+ connectButton->setText(QApplication::translate("MainWindow", "Connect", 0, QApplication::UnicodeUTF8));
+ loginButton->setText(QApplication::translate("MainWindow", "Login", 0, QApplication::UnicodeUTF8));
+ logoutButton->setText(QApplication::translate("MainWindow", "Logout", 0, QApplication::UnicodeUTF8));
+ } // retranslateUi
+
+};
+
+namespace Ui {
+ class MainWindow: public Ui_MainWindow {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_MAINWINDOW_H