# HG changeset patch # User insilmaril # Date 1183110233 0 # Node ID be24af55da408d6e6b728f94f701eda25b36007d # Parent 28be7520cb2116b872285d58747ce8c86ed74041 1.8.76 - Extended fileformat to ease tomboy export to vym diff -r 28be7520cb21 -r be24af55da40 linkablemapobj.cpp --- a/linkablemapobj.cpp Fri Jun 29 09:43:53 2007 +0000 +++ b/linkablemapobj.cpp Fri Jun 29 09:43:53 2007 +0000 @@ -91,6 +91,9 @@ relPos=QPointF(0,0); useRelPos=false; useOrientation=true; + + // Reset ID + id=""; } void LinkableMapObj::copy (LinkableMapObj* other) @@ -294,6 +297,15 @@ return linkpos; } +void LinkableMapObj::setID (const QString &s) +{ + id=s; +} + +QString LinkableMapObj::getID() +{ + return id; +} void LinkableMapObj::setLinkColor() { diff -r 28be7520cb21 -r be24af55da40 linkablemapobj.h --- a/linkablemapobj.h Fri Jun 29 09:43:53 2007 +0000 +++ b/linkablemapobj.h Fri Jun 29 09:43:53 2007 +0000 @@ -77,6 +77,9 @@ void setLinkPos (Position); Position getLinkPos (); + virtual void setID (const QString &s); + virtual QString getID (); + virtual void setLinkColor(); // sets color according to colorhint, overloaded virtual void setLinkColor(QColor); QColor getLinkColor(); @@ -157,5 +160,7 @@ //AnimPoint relPos; // position relative to childPos of parent bool useRelPos; bool useOrientation; + + QString id; // id set during load/save currently used for xLinks }; #endif diff -r 28be7520cb21 -r be24af55da40 mainwindow.cpp --- a/mainwindow.cpp Fri Jun 29 09:43:53 2007 +0000 +++ b/mainwindow.cpp Fri Jun 29 09:43:53 2007 +0000 @@ -2744,13 +2744,13 @@ { bool ok; QPoint p; - QString s=currentMapEditor()->getHeading(ok,p); + QString s=me->getHeading(ok,p); if (ok) { me->setStateEditHeading (true); #if defined(Q_OS_MACX) - p=currentMapEditor()->mapTo (this,p); + p=me->mapToGlobal (p); QDialog *d =new QDialog(NULL); QLineEdit *le=new QLineEdit (d); d->setWindowFlags (Qt::FramelessWindowHint); @@ -2761,12 +2761,12 @@ connect (le, SIGNAL (returnPressed()), d, SLOT (accept())); d->activateWindow(); d->exec(); - currentMapEditor()->setHeading (le->text()); + me->setHeading (le->text()); delete (le); delete (d); editHeadingFinished(); #else - p=currentMapEditor()->mapTo (this,p); + p=me->mapTo (this,p); lineedit->setGeometry(p.x(),p.y(),230,25); lineedit->setText(s); lineedit->setCursorPosition(1); @@ -3210,7 +3210,7 @@ void Main::networkConnect() { MapEditor *me=currentMapEditor(); - if (me) me->newServer(); + if (me) me->connectToServer(); } bool Main::settingsPDF() @@ -3271,7 +3271,7 @@ void Main::settingsAutosaveToggle() { - settings.setValue ("/mapeditor/autosave/used",actionSettingsAutosaveToggle->isOn() ); + settings.setValue ("/mapeditor/autosave/use",actionSettingsAutosaveToggle->isOn() ); } void Main::settingsAutosaveTime() @@ -3647,7 +3647,7 @@ void Main::testFunction2() { if (!currentMapEditor()) return; - currentMapEditor()->testFunction2(); + currentMapEditor()->connectToServer(); } void Main::testCommand() 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 "<<tcpServer->serverPort()<<endl; } +void MapEditor::connectToServer() +{ + port=54321; + server="salam.suse.de"; + server="localhost"; + clientSocket = new QTcpSocket (this); + clientSocket->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 "<<server.ascii()<<" port "<<port<<endl; + + +} + void MapEditor::newClient() { - QByteArray block; - QDataStream out(&block, QIODevice::WriteOnly); - out.setVersion(QDataStream::Qt_4_0); - out << (quint16)0; - out << xelection.getSelectString(); - out.device()->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 "<<newClient->peerAddress().toString().ascii()<<endl; clientList.append (newClient); - - newClient->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="<<bs<<" counter="<<sendCounter<<" s="<<s.ascii()<<endl; for (int i=0; i<clientList.size(); ++i) { - cout << "Sending to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl; + //cout << "Sending \""<<s.ascii()<<"\" to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl; clientList.at(i)->write (block); } } + +void MapEditor::readData () +{ + cout <<"readData bytesAvail="<<clientSocket->bytesAvailable()<<endl; + quint16 recCounter; + quint16 blockSize; + + QDataStream in(clientSocket); + in.setVersion(QDataStream::Qt_4_0); + + in >> blockSize; + in >> recCounter; + + char *sp; + uint l; + in.readBytes (sp,l); + cout << " sp="<<sp<<" l="<<l<<endl; + QString t; + in >>t; + cout << " t="<<t.ascii()<<endl; + + while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) ) + { + //cout <<"readData 1 bytesAvail="<<clientSocket->bytesAvailable()<<" readData bS="<<blockSize<<" rC="<<recCounter<<endl; + QString s; + in >> s; + //cout << "Received: "<< recCounter<< " "<<s.ascii() <<endl; + cout <<" bytesAvail="<<clientSocket->bytesAvailable()<<" bS="<<blockSize<<" counter="<<recCounter<<" s="<<s.ascii()<<endl; + parseAtom (s); + } +} + +void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError) +{ + switch (socketError) { + case QAbstractSocket::RemoteHostClosedError: + break; + case QAbstractSocket::HostNotFoundError: + QMessageBox::information(this, __VYM_NAME " Network client", + "The host was not found. Please check the " + "host name and port settings."); + break; + case QAbstractSocket::ConnectionRefusedError: + QMessageBox::information(this, __VYM_NAME " Network client", + "The connection was refused by the peer. " + "Make sure the fortune server is running, " + "and check that the host name and port " + "settings are correct."); + break; + default: + QMessageBox::information(this, __VYM_NAME " Network client", + QString("The following error occurred: %1.") + .arg(clientSocket->errorString())); + } +} + void MapEditor::autosave() { // Disable autosave, while we have gone back in history diff -r 28be7520cb21 -r be24af55da40 mapeditor.h --- a/mapeditor.h Fri Jun 29 09:43:53 2007 +0000 +++ b/mapeditor.h Fri Jun 29 09:43:53 2007 +0000 @@ -29,6 +29,15 @@ Idle, //!< Idle, waiting for user event EditHeading //!< Editing heading (dont't select another branch now) }; + /*! \brief Networking states + + In Network modus we want to switch of saveState, autosave, ... + */ + enum NetState { + Offline, //!< Offline + Client, //!< I am the client and connected to server + Server //!< I am the server + }; MapEditor(QWidget* parent=0); ~MapEditor(); MapCenterObj* getMapCenter(); //!< Return center of map @@ -336,10 +345,14 @@ public: void newServer(); + void connectToServer(); private slots: void newClient(); void sendData(const QString &s); + void readData(); + void displayNetworkError (QAbstractSocket::SocketError); + void autosave (); private: @@ -410,8 +423,16 @@ QPoint exportOffset; // set before export, used in save BranchObj::HideTmpMode hidemode; // true while exporting to hide some stuff + NetState netstate; // offline, client, server QTcpServer *tcpServer; // Act as server in conference mode (experimental) - QList <QTcpSocket*> clientList; + QList <QTcpSocket*> clientList; // List of connected clients + quint16 sendCounter; // Increased with every sent command + + QTcpSocket *clientSocket; // socket of this client + QString server; // server address of this client + int port; // server port of this client + void displayClientError(QAbstractSocket::SocketError socketError); + int timerId; // animation timer QList <MapObj*> animObjList;// list with animated objects diff -r 28be7520cb21 -r be24af55da40 parser.cpp --- a/parser.cpp Fri Jun 29 09:43:53 2007 +0000 +++ b/parser.cpp Fri Jun 29 09:43:53 2007 +0000 @@ -31,6 +31,8 @@ QRegExp re; int pos; + cout << "parseAtom s="<<s.ascii()<<endl; + // Strip WS at beginning re.setPattern ("\\w"); re.setMinimal (true); diff -r 28be7520cb21 -r be24af55da40 version.h --- a/version.h Fri Jun 29 09:43:53 2007 +0000 +++ b/version.h Fri Jun 29 09:43:53 2007 +0000 @@ -4,10 +4,10 @@ #include <QString> #define __VYM_NAME "VYM" -#define __VYM_VERSION "1.8.75" -#define __VYM_CODENAME "Codename: 1.9.0-beta-1" -//#define __VYM_CODENAME "Codename: development version" -#define __VYM_BUILD_DATE "June 22, 2007" +#define __VYM_VERSION "1.8.76" +//#define __VYM_CODENAME "Codename: 1.9.0-beta-1" +#define __VYM_CODENAME "Codename: development version" +#define __VYM_BUILD_DATE "June 29, 2007" bool checkVersion(const QString &);