-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
maltanar
committed
Jun 14, 2011
1 parent
6d01205
commit 95ddadb
Showing
78 changed files
with
5,713 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#------------------------------------------------- | ||
# | ||
# Project created by QtCreator 2011-04-16T14:28:32 | ||
# | ||
#------------------------------------------------- | ||
|
||
QT += core gui network | ||
|
||
TARGET = collaboration_client_server | ||
TEMPLATE = app | ||
|
||
COMMON_SOURCES += ../common/wtmessage.cpp \ | ||
../common/wtloginmessage.cpp \ | ||
../common/wtsessionlistrequest.cpp \ | ||
../common/messagetransceiver.cpp \ | ||
../common/wtlogoutrequest.cpp \ | ||
../common/wtpicturerequest.cpp \ | ||
../common/wtpictureresponse.cpp \ | ||
../common/wtsessioncreaterequest.cpp \ | ||
../common/wtsessioncreateresponse.cpp \ | ||
../common/wtsessionjoinrequest.cpp \ | ||
../common/wtsessionjoinresponse.cpp \ | ||
../common/wtsessionleaverequest.cpp \ | ||
../common/wtsessionleaveresponse.cpp \ | ||
../common/wtsessionlistresponse.cpp \ | ||
../common/wtsessionmemberupdate.cpp \ | ||
../common/wtupdatedrawing.cpp \ | ||
../common/wtupdatedrawingserver.cpp \ | ||
../common/wtwritepermissionrequest.cpp \ | ||
../common/wtwritepermissionstatus.cpp \ | ||
../common/wtloginresponse.cpp \ | ||
../common/protocolhandler.cpp \ | ||
../common/wtpeerhandshake.cpp \ | ||
../common/collaborationsession.cpp \ | ||
|
||
CWIDGET_SOURCES += ../collaborative_drawing_widget/basedrawingwidget.cpp \ | ||
../collaborative_drawing_widget/drawingdata.cpp \ | ||
../collaborative_drawing_widget/collaborativedrawingwidget.cpp \ | ||
../collaborative_drawing_widget/drawingaction.cpp | ||
|
||
COMMON_HEADERS += ../common/wtmessage.h \ | ||
../common/wtloginmessage.h \ | ||
../common/wtsessionlistrequest.h \ | ||
../common/messagetransceiver.h \ | ||
../common/wtlogoutrequest.h \ | ||
../common/wtpicturerequest.h \ | ||
../common/wtpictureresponse.h \ | ||
../common/wtsessioncreaterequest.h \ | ||
../common/wtsessioncreateresponse.h \ | ||
../common/wtsessionjoinrequest.h \ | ||
../common/wtsessionjoinresponse.h \ | ||
../common/wtsessionleaverequest.h \ | ||
../common/wtsessionleaveresponse.h \ | ||
../common/wtsessionlistresponse.h \ | ||
../common/wtsessionmemberupdate.h \ | ||
../common/wtupdatedrawing.h \ | ||
../common/wtupdatedrawingserver.h \ | ||
../common/wtwritepermissionrequest.h \ | ||
../common/wtwritepermissionstatus.h \ | ||
../common/wtloginresponse.h \ | ||
../common/protocolhandler.h \ | ||
../common/wtpeerhandshake.h \ | ||
../common/collaborationsession.h | ||
|
||
CWIDGET_HEADERS += ../collaborative_drawing_widget/basedrawingwidget.h \ | ||
../collaborative_drawing_widget/drawingdata.h \ | ||
../collaborative_drawing_widget/collaborativedrawingwidget.h \ | ||
../collaborative_drawing_widget/drawingaction.h \ | ||
../collaborative_drawing_widget/appglobals.h | ||
|
||
INCLUDEPATH += . \ | ||
../common \ | ||
../client \ | ||
../server \ | ||
../collaborative_drawing_widget | ||
|
||
SOURCES += main.cpp\ | ||
mainwindow.cpp \ | ||
../server/collaborationserver.cpp \ | ||
../client/collaborationclient.cpp \ | ||
$$COMMON_SOURCES \ | ||
$$CWIDGET_SOURCES | ||
|
||
|
||
HEADERS += mainwindow.h \ | ||
../server/collaborationserver.h \ | ||
../client/collaborationclient.h \ | ||
$$COMMON_HEADERS \ | ||
$$CWIDGET_HEADERS | ||
|
||
FORMS += mainwindow.ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <QtGui/QApplication> | ||
#include "mainwindow.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
MainWindow w; | ||
w.show(); | ||
|
||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
#include "mainwindow.h" | ||
#include "ui_mainwindow.h" | ||
|
||
#include "drawingdata.h" | ||
|
||
#include <QFileDialog> | ||
#include <QInputDialog> | ||
#include <QMessageBox> | ||
|
||
MainWindow::MainWindow(QWidget *parent) : | ||
QMainWindow(parent), | ||
ui(new Ui::MainWindow) | ||
{ | ||
ui->setupUi(this); | ||
DrawingData *drawingData = new DrawingData(this); | ||
ui->graphicsView->setDrawingData(drawingData); | ||
connect(ui->actionUndo,SIGNAL(triggered()),ui->graphicsView->getDrawingData()->getUndoStack(), SLOT(undo())); | ||
connect(ui->actionRedo,SIGNAL(triggered()),ui->graphicsView->getDrawingData()->getUndoStack(), SLOT(redo())); | ||
|
||
ui->stackedWidget->setCurrentIndex(1); | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void MainWindow::on_actionRedPen_triggered() | ||
{ | ||
QPen current = ui->graphicsView->getDrawingPen(); | ||
current.setColor(Qt::red); | ||
ui->graphicsView->setDrawingPen(current); | ||
ui->graphicsView->setDrawingMode(DRAWINGMODE_FREEHAND); | ||
} | ||
|
||
void MainWindow::on_actionBlackPen_triggered() | ||
{ | ||
QPen current = ui->graphicsView->getDrawingPen(); | ||
current.setColor(Qt::black); | ||
ui->graphicsView->setDrawingPen(current); | ||
ui->graphicsView->setDrawingMode(DRAWINGMODE_FREEHAND); | ||
} | ||
|
||
void MainWindow::on_actionBluePen_triggered() | ||
{ | ||
QPen current = ui->graphicsView->getDrawingPen(); | ||
current.setColor(Qt::blue); | ||
ui->graphicsView->setDrawingPen(current); | ||
ui->graphicsView->setDrawingMode(DRAWINGMODE_FREEHAND); | ||
} | ||
|
||
void MainWindow::on_actionPenWidthInc_triggered() | ||
{ | ||
QPen current = ui->graphicsView->getDrawingPen(); | ||
current.setWidth(current.width()+1); | ||
ui->graphicsView->setDrawingPen(current); | ||
} | ||
|
||
void MainWindow::on_actionPenWidthDec_triggered() | ||
{ | ||
QPen current = ui->graphicsView->getDrawingPen(); | ||
current.setWidth(current.width()-1); | ||
ui->graphicsView->setDrawingPen(current); | ||
} | ||
|
||
void MainWindow::on_actionEraser_triggered() | ||
{ | ||
ui->graphicsView->setDrawingMode(DRAWINGMODE_ERASER); | ||
} | ||
|
||
void MainWindow::sessionJoinResult(QString sessionName, QChar result, QHash<QString, long> users) | ||
{ | ||
QMessageBox m; | ||
if(result == 1) { | ||
m.setText("Joined session " + sessionName + ", you may start drawing"); | ||
m.exec(); | ||
ui->stackedWidget->setCurrentIndex(0); | ||
} else { | ||
m.setText("Failed to join session " + sessionName + ", check the password"); | ||
m.exec(); | ||
ui->stackedWidget->setCurrentIndex(1); | ||
} | ||
|
||
qWarning() << "Session join result: " << sessionName << " : " << result << " : " << users.count(); | ||
} | ||
|
||
void MainWindow::drawingCommitted(QString sessionName, QPicture pictureData) | ||
{ | ||
QByteArray picData(pictureData.data(), pictureData.size()); | ||
client->sendDrawing(sessionName, picData); | ||
} | ||
|
||
void MainWindow::on_actionDrawing_triggered() | ||
{ | ||
ui->stackedWidget->setCurrentIndex(0); | ||
} | ||
|
||
void MainWindow::on_actionSessions_triggered() | ||
{ | ||
ui->stackedWidget->setCurrentIndex(1); | ||
} | ||
|
||
void MainWindow::on_startServerButton_clicked() | ||
{ | ||
mt = new MessageTransceiver(); | ||
ph = new ProtocolHandler(); | ||
ph->setMessageTransceiver(mt); | ||
server = new CollaborationServer(); | ||
server->setProtocolHandler(ph); | ||
client = new CollaborationClient(); | ||
client->setProtocolHandler(ph); | ||
|
||
connect(client, SIGNAL(sessionJoinResult(QString,QChar,QHash<QString,long>)), this, SLOT(sessionJoinResult(QString,QChar,QHash<QString,long>))); | ||
connect(ui->graphicsView, SIGNAL(drawingCommited(QString,QPicture)), this, SLOT(drawingCommitted(QString,QPicture))); | ||
connect(client, SIGNAL(drawingArrived(QString,QByteArray,bool)), ui->graphicsView, SLOT(drawingArrived(QString,QByteArray,bool))); | ||
|
||
connect(client, SIGNAL(sessionListAvailable(QStringList)), this, SLOT(gotSessionList(QStringList))); | ||
|
||
|
||
ui->startServerButton->setEnabled(false); | ||
ui->statusLabel->setText("Running"); | ||
server->setServerUserName(ui->userName->text()); | ||
mt->start(); | ||
|
||
client->loginToServer(QHostAddress("127.0.0.1"), ui->userName->text(), ui->userName->text()); | ||
client->refreshSessionList(); | ||
|
||
ui->sessionBox->setEnabled(true); | ||
} | ||
|
||
void MainWindow::gotSessionList(QStringList sessionList) | ||
{ | ||
ui->sessionList->clear(); | ||
ui->sessionList->addItems(sessionList); | ||
} | ||
|
||
void MainWindow::on_refreshList_clicked() | ||
{ | ||
client->refreshSessionList(); | ||
} | ||
|
||
void MainWindow::on_pushButton_clicked() | ||
{ | ||
client->joinSession(ui->sessionList->currentItem()->text(), ui->sessionPassword->text()); | ||
} | ||
|
||
void MainWindow::on_actionClear_triggered() | ||
{ | ||
ui->graphicsView->clear(); | ||
} | ||
|
||
void MainWindow::on_actionFreehand_triggered() | ||
{ | ||
ui->graphicsView->setDrawingMode(DRAWINGMODE_FREEHAND); | ||
} | ||
|
||
void MainWindow::on_actionRectangle_triggered() | ||
{ | ||
ui->graphicsView->setDrawingMode(DRAWINGMODE_RECTANGLE); | ||
} | ||
|
||
void MainWindow::on_actionStraightLine_triggered() | ||
{ | ||
ui->graphicsView->setDrawingMode(DRAWINGMODE_STRAIGHTLINE); | ||
} | ||
|
||
void MainWindow::on_btn_createSession_clicked() | ||
{ | ||
client->createSession("sessozz", "1234"); | ||
} | ||
|
||
void MainWindow::on_btn_leaveSession_clicked() | ||
{ | ||
client->leaveSession(client->getActiveSession()); | ||
ui->stackedWidget->setCurrentIndex(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef MAINWINDOW_H | ||
#define MAINWINDOW_H | ||
|
||
#include <QMainWindow> | ||
#include <QtNetwork/QTcpSocket> | ||
#include "collaborationclient.h" | ||
#include "collaborationserver.h" | ||
#include "sessionjoindialog.h" | ||
|
||
namespace Ui { | ||
class MainWindow; | ||
} | ||
|
||
class MainWindow : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit MainWindow(QWidget *parent = 0); | ||
~MainWindow(); | ||
|
||
private: | ||
Ui::MainWindow *ui; | ||
CollaborationClient *client; | ||
CollaborationServer *server; | ||
ProtocolHandler *ph; | ||
MessageTransceiver *mt; | ||
|
||
private slots: | ||
void on_btn_leaveSession_clicked(); | ||
void on_btn_createSession_clicked(); | ||
void on_actionStraightLine_triggered(); | ||
void on_actionRectangle_triggered(); | ||
void on_actionFreehand_triggered(); | ||
void on_actionClear_triggered(); | ||
void on_pushButton_clicked(); | ||
void on_refreshList_clicked(); | ||
void on_startServerButton_clicked(); | ||
void on_actionSessions_triggered(); | ||
void on_actionDrawing_triggered(); | ||
void on_actionPenWidthDec_triggered(); | ||
void on_actionPenWidthInc_triggered(); | ||
void on_actionBluePen_triggered(); | ||
void on_actionBlackPen_triggered(); | ||
void on_actionRedPen_triggered(); | ||
void on_actionEraser_triggered(); | ||
void sessionJoinResult(QString sessionName, QChar result, QHash<QString, long> users); | ||
void drawingCommitted(QString sessionName, QPicture pictureData); | ||
void gotSessionList(QStringList sessionList); | ||
}; | ||
|
||
#endif // MAINWINDOW_H |
Oops, something went wrong.