diff -r 28be7520cb21 -r be24af55da40 mapeditor.cpp --- a/mapeditor.cpp Fri Jun 29 09:43:53 2007 +0000 +++ b/mapeditor.cpp Fri Jun 29 09:43:53 2007 +0000 @@ -149,6 +149,9 @@ // autosave autosaveTimer=new QTimer (this); connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave())); + + // Network + netstate=Offline; } MapEditor::~MapEditor() @@ -1549,8 +1552,6 @@ int MapEditor::save (const SaveMode &savemode) { - int returnCode=0; - // Create mapName and fileDir makeSubDirs (fileDir); QString fname; @@ -1572,20 +1573,17 @@ saveFloatImage(); else saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); + return 0; } if (!saveStringToDisk(fileDir+fname,saveFile)) return 1; - if (returnCode==0) - { - mapChanged=false; - mapUnsaved=false; - autosaveTimer->stop(); - updateActions(); - } - - return returnCode; + mapChanged=false; + mapUnsaved=false; + autosaveTimer->stop(); + updateActions(); + return 0; } void MapEditor::setZipped (bool z) @@ -2448,6 +2446,15 @@ QString ("Add new branch to %1").arg(getName(bo))); mapCenter->reposition(); + // In Network mode, the client needs to know where the new branch is, + // so we have to pass on this information via saveState. + // TODO: Get rid of this positioning workaround + QString ps=qpointfToString (newbo->getAbsPos()); + saveState( + newbo, "move "+ps, + newbo, "move "+ps, + QString("Move %1 to %2").arg(getName(newbo)).arg(ps)); + xelection.update(); } } @@ -4689,7 +4696,7 @@ event->acceptProposedAction(); } -void MapEditor::dragMoveEvent(QDragMoveEvent *event) +void MapEditor::dragMoveEvent(QDragMoveEvent *) { } @@ -4776,33 +4783,46 @@ void MapEditor::sendSelection() { - sendData (xelection.getSelectString() ); + if (netstate!=Server) return; + sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) ); } void MapEditor::newServer() { + port=54321; + sendCounter=0; tcpServer = new QTcpServer(this); - if (!tcpServer->listen(QHostAddress::Any,54321)) { + if (!tcpServer->listen(QHostAddress::Any,port)) { QMessageBox::critical(this, "vym server", QString("Unable to start the server: %1.").arg(tcpServer->errorString())); close(); return; } connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient())); + netstate=Server; if (debug) cout<<"Server is running on port "<serverPort()<abort(); + clientSocket->connectToHost(server ,port); + connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData())); + connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)), + this, SLOT(displayNetworkError(QAbstractSocket::SocketError))); + netstate=Client; + cout<<"connected to "<seek(0); - out << (quint16)(block.size() - sizeof(quint16)); - QTcpSocket *newClient = tcpServer->nextPendingConnection(); connect(newClient, SIGNAL(disconnected()), newClient, SLOT(deleteLater())); @@ -4810,9 +4830,6 @@ cout <<"ME::newClient at "<peerAddress().toString().ascii()<write(block); - //newClient->disconnectFromHost(); } @@ -4826,19 +4843,81 @@ // Reserve some space for blocksize out << (quint16)0; + // Write sendCounter + out << sendCounter++; + // Write data out << s; // Go back and write blocksize so far out.device()->seek(0); - out << (quint16)(block.size() - sizeof(quint16)); + quint16 bs=(quint16)(block.size() - 2*sizeof(quint16)); + out << bs; + + cout << "ME::sendData bs="<peerAddress().toString().ascii()<peerAddress().toString().ascii()<write (block); } } + +void MapEditor::readData () +{ + cout <<"readData bytesAvail="<bytesAvailable()<> blockSize; + in >> recCounter; + + char *sp; + uint l; + in.readBytes (sp,l); + cout << " sp="<errorString())); + } +} + void MapEditor::autosave() { // Disable autosave, while we have gone back in history