1.8.76 - Extended fileformat to ease tomboy export to vym
authorinsilmaril
Fri, 29 Jun 2007 09:43:53 +0000
changeset 531be24af55da40
parent 530 28be7520cb21
child 532 50dc461a95e0
1.8.76 - Extended fileformat to ease tomboy export to vym
linkablemapobj.cpp
linkablemapobj.h
mainwindow.cpp
mapeditor.cpp
mapeditor.h
parser.cpp
version.h
     1.1 --- a/linkablemapobj.cpp	Fri Jun 29 09:43:53 2007 +0000
     1.2 +++ b/linkablemapobj.cpp	Fri Jun 29 09:43:53 2007 +0000
     1.3 @@ -91,6 +91,9 @@
     1.4  	relPos=QPointF(0,0);
     1.5  	useRelPos=false;
     1.6  	useOrientation=true;
     1.7 +
     1.8 +	// Reset ID
     1.9 +	id="";
    1.10  }
    1.11  
    1.12  void LinkableMapObj::copy (LinkableMapObj* other)
    1.13 @@ -294,6 +297,15 @@
    1.14  	return linkpos;
    1.15  }
    1.16  
    1.17 +void LinkableMapObj::setID (const QString &s)
    1.18 +{
    1.19 +	id=s;
    1.20 +}
    1.21 +
    1.22 +QString LinkableMapObj::getID()
    1.23 +{
    1.24 +	return id;
    1.25 +}
    1.26  
    1.27  void LinkableMapObj::setLinkColor()
    1.28  {
     2.1 --- a/linkablemapobj.h	Fri Jun 29 09:43:53 2007 +0000
     2.2 +++ b/linkablemapobj.h	Fri Jun 29 09:43:53 2007 +0000
     2.3 @@ -77,6 +77,9 @@
     2.4  	void setLinkPos (Position);
     2.5  	Position getLinkPos ();
     2.6  
     2.7 +	virtual void setID (const QString &s);
     2.8 +	virtual QString getID ();
     2.9 +
    2.10  	virtual void setLinkColor();					// sets color according to colorhint, overloaded
    2.11  	virtual void setLinkColor(QColor);
    2.12  	QColor getLinkColor();
    2.13 @@ -157,5 +160,7 @@
    2.14  	//AnimPoint relPos;				// position relative to childPos of parent
    2.15  	bool useRelPos;
    2.16  	bool useOrientation;
    2.17 +
    2.18 +	QString id;						// id set during load/save currently used for xLinks
    2.19  };
    2.20  #endif
     3.1 --- a/mainwindow.cpp	Fri Jun 29 09:43:53 2007 +0000
     3.2 +++ b/mainwindow.cpp	Fri Jun 29 09:43:53 2007 +0000
     3.3 @@ -2744,13 +2744,13 @@
     3.4  		{
     3.5  			bool ok;
     3.6  			QPoint p;
     3.7 -			QString s=currentMapEditor()->getHeading(ok,p);
     3.8 +			QString s=me->getHeading(ok,p);
     3.9  
    3.10  			if (ok)
    3.11  			{
    3.12  				me->setStateEditHeading (true);
    3.13  #if defined(Q_OS_MACX)
    3.14 -				p=currentMapEditor()->mapTo (this,p);
    3.15 +				p=me->mapToGlobal (p);
    3.16  				QDialog *d =new QDialog(NULL);
    3.17  				QLineEdit *le=new QLineEdit (d);
    3.18  				d->setWindowFlags (Qt::FramelessWindowHint);
    3.19 @@ -2761,12 +2761,12 @@
    3.20  				connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
    3.21  				d->activateWindow();
    3.22  				d->exec();
    3.23 -				currentMapEditor()->setHeading (le->text());
    3.24 +				me->setHeading (le->text());
    3.25  				delete (le);
    3.26  				delete (d);
    3.27  				editHeadingFinished();
    3.28  #else
    3.29 -				p=currentMapEditor()->mapTo (this,p);
    3.30 +				p=me->mapTo (this,p);
    3.31  				lineedit->setGeometry(p.x(),p.y(),230,25);
    3.32  				lineedit->setText(s);
    3.33  				lineedit->setCursorPosition(1);
    3.34 @@ -3210,7 +3210,7 @@
    3.35  void Main::networkConnect()
    3.36  {
    3.37  	MapEditor *me=currentMapEditor();
    3.38 -	if (me) me->newServer();
    3.39 +	if (me) me->connectToServer();
    3.40  }
    3.41  
    3.42  bool Main::settingsPDF()
    3.43 @@ -3271,7 +3271,7 @@
    3.44  
    3.45  void Main::settingsAutosaveToggle()
    3.46  {
    3.47 -	settings.setValue ("/mapeditor/autosave/used",actionSettingsAutosaveToggle->isOn() );
    3.48 +	settings.setValue ("/mapeditor/autosave/use",actionSettingsAutosaveToggle->isOn() );
    3.49  }
    3.50  
    3.51  void Main::settingsAutosaveTime()
    3.52 @@ -3647,7 +3647,7 @@
    3.53  void Main::testFunction2()
    3.54  {
    3.55  	if (!currentMapEditor()) return;
    3.56 -	currentMapEditor()->testFunction2();
    3.57 +	currentMapEditor()->connectToServer();
    3.58  }
    3.59  
    3.60  void Main::testCommand()
     4.1 --- a/mapeditor.cpp	Fri Jun 29 09:43:53 2007 +0000
     4.2 +++ b/mapeditor.cpp	Fri Jun 29 09:43:53 2007 +0000
     4.3 @@ -149,6 +149,9 @@
     4.4  	// autosave
     4.5  	autosaveTimer=new QTimer (this);
     4.6  	connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
     4.7 +
     4.8 +	// Network
     4.9 +	netstate=Offline;
    4.10  }
    4.11  
    4.12  MapEditor::~MapEditor()
    4.13 @@ -1549,8 +1552,6 @@
    4.14  
    4.15  int MapEditor::save (const SaveMode &savemode)
    4.16  {
    4.17 -	int returnCode=0;
    4.18 -
    4.19  	// Create mapName and fileDir
    4.20  	makeSubDirs (fileDir);
    4.21  	QString fname;
    4.22 @@ -1572,20 +1573,17 @@
    4.23  			saveFloatImage();
    4.24  		else	
    4.25  			saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());	
    4.26 +		return 0;	
    4.27  	}	
    4.28  
    4.29  	if (!saveStringToDisk(fileDir+fname,saveFile))
    4.30  		return 1;
    4.31  
    4.32 -	if (returnCode==0)
    4.33 -	{
    4.34 -		mapChanged=false;
    4.35 -		mapUnsaved=false;
    4.36 -		autosaveTimer->stop();
    4.37 -		updateActions();
    4.38 -	}
    4.39 -
    4.40 -	return returnCode;
    4.41 +	mapChanged=false;
    4.42 +	mapUnsaved=false;
    4.43 +	autosaveTimer->stop();
    4.44 +	updateActions();
    4.45 +	return 0;
    4.46  }
    4.47  
    4.48  void MapEditor::setZipped (bool z)
    4.49 @@ -2448,6 +2446,15 @@
    4.50  				QString ("Add new branch to %1").arg(getName(bo)));	
    4.51  
    4.52  			mapCenter->reposition();
    4.53 +			// In Network mode, the client needs to know where the new branch is,
    4.54 +			// so we have to pass on this information via saveState.
    4.55 +			// TODO: Get rid of this positioning workaround
    4.56 +			QString ps=qpointfToString (newbo->getAbsPos());
    4.57 +			saveState(
    4.58 +				newbo, "move "+ps, 
    4.59 +				newbo, "move "+ps, 
    4.60 +				QString("Move %1 to  %2").arg(getName(newbo)).arg(ps));
    4.61 +
    4.62  			xelection.update();
    4.63  		}
    4.64  	}	
    4.65 @@ -4689,7 +4696,7 @@
    4.66  			event->acceptProposedAction();
    4.67  }
    4.68  
    4.69 -void MapEditor::dragMoveEvent(QDragMoveEvent *event)
    4.70 +void MapEditor::dragMoveEvent(QDragMoveEvent *)
    4.71  {
    4.72  }
    4.73  
    4.74 @@ -4776,33 +4783,46 @@
    4.75  
    4.76  void MapEditor::sendSelection()
    4.77  {
    4.78 -	sendData (xelection.getSelectString() );
    4.79 +	if (netstate!=Server) return;
    4.80 +	sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
    4.81  }
    4.82  
    4.83  void MapEditor::newServer()
    4.84  {
    4.85 +	port=54321;
    4.86 +	sendCounter=0;
    4.87      tcpServer = new QTcpServer(this);
    4.88 -    if (!tcpServer->listen(QHostAddress::Any,54321)) {
    4.89 +    if (!tcpServer->listen(QHostAddress::Any,port)) {
    4.90          QMessageBox::critical(this, "vym server",
    4.91                                QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
    4.92          close();
    4.93          return;
    4.94      }
    4.95  	connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
    4.96 +	netstate=Server;
    4.97  	if (debug)
    4.98  		cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
    4.99  }
   4.100  
   4.101 +void MapEditor::connectToServer()
   4.102 +{
   4.103 +	port=54321;
   4.104 +	server="salam.suse.de";
   4.105 +	server="localhost";
   4.106 +	clientSocket = new QTcpSocket (this);
   4.107 +	clientSocket->abort();
   4.108 +    clientSocket->connectToHost(server ,port);
   4.109 +	connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
   4.110 +    connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
   4.111 +            this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
   4.112 +	netstate=Client;		
   4.113 +	cout<<"connected to "<<server.ascii()<<" port "<<port<<endl;
   4.114 +
   4.115 +	
   4.116 +}
   4.117 +
   4.118  void MapEditor::newClient()
   4.119  {
   4.120 -    QByteArray block;
   4.121 -    QDataStream out(&block, QIODevice::WriteOnly);
   4.122 -    out.setVersion(QDataStream::Qt_4_0);
   4.123 -    out << (quint16)0;
   4.124 -    out << xelection.getSelectString();
   4.125 -    out.device()->seek(0);
   4.126 -    out << (quint16)(block.size() - sizeof(quint16));
   4.127 -
   4.128      QTcpSocket *newClient = tcpServer->nextPendingConnection();
   4.129      connect(newClient, SIGNAL(disconnected()),
   4.130              newClient, SLOT(deleteLater()));
   4.131 @@ -4810,9 +4830,6 @@
   4.132  	cout <<"ME::newClient  at "<<newClient->peerAddress().toString().ascii()<<endl;
   4.133  
   4.134  	clientList.append (newClient);
   4.135 -
   4.136 -    newClient->write(block);
   4.137 -    //newClient->disconnectFromHost();
   4.138  }
   4.139  
   4.140  
   4.141 @@ -4826,19 +4843,81 @@
   4.142  	// Reserve some space for blocksize
   4.143      out << (quint16)0;
   4.144  
   4.145 +	// Write sendCounter
   4.146 +    out << sendCounter++;
   4.147 +
   4.148  	// Write data
   4.149      out << s;
   4.150  
   4.151  	// Go back and write blocksize so far
   4.152      out.device()->seek(0);
   4.153 -    out << (quint16)(block.size() - sizeof(quint16));
   4.154 +    quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
   4.155 +	out << bs;
   4.156 +
   4.157 +	cout << "ME::sendData  bs="<<bs<<"  counter="<<sendCounter<<"  s="<<s.ascii()<<endl;
   4.158  
   4.159  	for (int i=0; i<clientList.size(); ++i)
   4.160  	{
   4.161 -		cout << "Sending to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
   4.162 +		//cout << "Sending \""<<s.ascii()<<"\" to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
   4.163  		clientList.at(i)->write (block);
   4.164  	}
   4.165  }
   4.166 +
   4.167 +void MapEditor::readData ()
   4.168 +{
   4.169 +	cout <<"readData  bytesAvail="<<clientSocket->bytesAvailable()<<endl;
   4.170 +    quint16 recCounter;
   4.171 +	quint16 blockSize;
   4.172 +
   4.173 +    QDataStream in(clientSocket);
   4.174 +    in.setVersion(QDataStream::Qt_4_0);
   4.175 +
   4.176 +    in >> blockSize;
   4.177 +    in >> recCounter;
   4.178 +	
   4.179 +	char *sp; 
   4.180 +	uint l;
   4.181 +	in.readBytes (sp,l);
   4.182 +	cout << "  sp="<<sp<<"  l="<<l<<endl;
   4.183 +	QString t;
   4.184 +	in >>t;
   4.185 +	cout << "  t="<<t.ascii()<<endl;
   4.186 +
   4.187 +	while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
   4.188 +	{
   4.189 +		//cout <<"readData 1 bytesAvail="<<clientSocket->bytesAvailable()<<"  readData bS="<<blockSize<<"  rC="<<recCounter<<endl;
   4.190 +		QString s;
   4.191 +		in >> s;
   4.192 +		//cout << "Received: "<< recCounter<< "  "<<s.ascii() <<endl;
   4.193 +	cout <<"  bytesAvail="<<clientSocket->bytesAvailable()<<"   bS="<<blockSize<<"  counter="<<recCounter<<"  s="<<s.ascii()<<endl;
   4.194 +		parseAtom (s);
   4.195 +	}
   4.196 +}
   4.197 +
   4.198 +void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
   4.199 +{
   4.200 +    switch (socketError) {
   4.201 +    case QAbstractSocket::RemoteHostClosedError:
   4.202 +        break;
   4.203 +    case QAbstractSocket::HostNotFoundError:
   4.204 +        QMessageBox::information(this, __VYM_NAME " Network client",
   4.205 +                                 "The host was not found. Please check the "
   4.206 +                                    "host name and port settings.");
   4.207 +        break;
   4.208 +    case QAbstractSocket::ConnectionRefusedError:
   4.209 +        QMessageBox::information(this, __VYM_NAME " Network client",
   4.210 +                                 "The connection was refused by the peer. "
   4.211 +                                    "Make sure the fortune server is running, "
   4.212 +                                    "and check that the host name and port "
   4.213 +                                    "settings are correct.");
   4.214 +        break;
   4.215 +    default:
   4.216 +        QMessageBox::information(this, __VYM_NAME " Network client",
   4.217 +                                 QString("The following error occurred: %1.")
   4.218 +                                 .arg(clientSocket->errorString()));
   4.219 +    }
   4.220 +}
   4.221 +
   4.222  void MapEditor::autosave()
   4.223  {
   4.224  	// Disable autosave, while we have gone back in history
     5.1 --- a/mapeditor.h	Fri Jun 29 09:43:53 2007 +0000
     5.2 +++ b/mapeditor.h	Fri Jun 29 09:43:53 2007 +0000
     5.3 @@ -29,6 +29,15 @@
     5.4  		Idle,			//!< Idle, waiting for user event
     5.5  		EditHeading		//!< Editing heading (dont't select another branch now)
     5.6  	};
     5.7 +    /*! \brief Networking states
     5.8 +		
     5.9 +		In Network modus we want to switch of saveState, autosave, ...
    5.10 +	*/
    5.11 +	enum NetState {
    5.12 +		Offline,			//!< Offline
    5.13 +		Client,				//!< I am the client and connected to server
    5.14 +		Server				//!< I am the server
    5.15 +	};
    5.16      MapEditor(QWidget* parent=0);
    5.17  	~MapEditor();
    5.18      MapCenterObj* getMapCenter();		//!< Return center of map
    5.19 @@ -336,10 +345,14 @@
    5.20  
    5.21  public:
    5.22  	void newServer();
    5.23 +	void connectToServer();
    5.24  
    5.25  private slots:	
    5.26  	void newClient();
    5.27  	void sendData(const QString &s);
    5.28 +	void readData();
    5.29 +	void displayNetworkError (QAbstractSocket::SocketError);
    5.30 +
    5.31  	void autosave ();
    5.32  
    5.33  private:
    5.34 @@ -410,8 +423,16 @@
    5.35  	QPoint exportOffset;		// set before export, used in save
    5.36  	BranchObj::HideTmpMode hidemode;	// true while exporting to hide some stuff
    5.37  
    5.38 +	NetState netstate;			// offline, client, server
    5.39  	QTcpServer *tcpServer;		// Act as server in conference mode (experimental)
    5.40 -	QList <QTcpSocket*> clientList;
    5.41 +	QList <QTcpSocket*> clientList;		// List of connected clients
    5.42 +	quint16 sendCounter;		// Increased with every sent command
    5.43 +
    5.44 +	QTcpSocket	*clientSocket;	// socket of this client
    5.45 +	QString server;				// server address of this client
    5.46 +	int port;					// server port of this client
    5.47 +	void displayClientError(QAbstractSocket::SocketError socketError);
    5.48 +
    5.49  
    5.50  	int timerId;				// animation timer
    5.51  	QList <MapObj*> animObjList;// list with animated objects
     6.1 --- a/parser.cpp	Fri Jun 29 09:43:53 2007 +0000
     6.2 +++ b/parser.cpp	Fri Jun 29 09:43:53 2007 +0000
     6.3 @@ -31,6 +31,8 @@
     6.4  	QRegExp re;
     6.5  	int pos;
     6.6  
     6.7 +	cout << "parseAtom s="<<s.ascii()<<endl;
     6.8 +
     6.9  	// Strip WS at beginning
    6.10  	re.setPattern ("\\w");
    6.11  	re.setMinimal (true);
     7.1 --- a/version.h	Fri Jun 29 09:43:53 2007 +0000
     7.2 +++ b/version.h	Fri Jun 29 09:43:53 2007 +0000
     7.3 @@ -4,10 +4,10 @@
     7.4  #include <QString>
     7.5  
     7.6  #define __VYM_NAME "VYM"
     7.7 -#define __VYM_VERSION "1.8.75"
     7.8 -#define __VYM_CODENAME "Codename: 1.9.0-beta-1"
     7.9 -//#define __VYM_CODENAME "Codename: development version"
    7.10 -#define __VYM_BUILD_DATE "June 22, 2007"
    7.11 +#define __VYM_VERSION "1.8.76"
    7.12 +//#define __VYM_CODENAME "Codename: 1.9.0-beta-1"
    7.13 +#define __VYM_CODENAME "Codename: development version"
    7.14 +#define __VYM_BUILD_DATE "June 29, 2007"
    7.15  
    7.16  
    7.17  bool checkVersion(const QString &);