mapeditor.cpp
changeset 528 36d140349897
parent 527 f19bbd639726
child 531 be24af55da40
     1.1 --- a/mapeditor.cpp	Thu Jun 21 14:27:46 2007 +0000
     1.2 +++ b/mapeditor.cpp	Mon Jun 25 12:54:19 2007 +0000
     1.3 @@ -319,8 +319,11 @@
     1.4  
     1.5  void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
     1.6  {
     1.7 +	sendData(redoCom);	//FIXME testing
     1.8 +
     1.9  	// Main saveState
    1.10  
    1.11 +
    1.12  	if (blockSaveState) return;
    1.13  
    1.14  	if (debug) cout << "ME::saveState() for  "<<mapName.ascii()<<endl;
    1.15 @@ -2555,6 +2558,7 @@
    1.16  		xelection.select(lmo);
    1.17  		xelection.update();
    1.18  		ensureSelectionVisible();
    1.19 +		sendSelection ();
    1.20  		return true;
    1.21  	} 
    1.22  	return false;
    1.23 @@ -2571,6 +2575,7 @@
    1.24  	{
    1.25  		xelection.select(lmo);
    1.26  		xelection.update();
    1.27 +		sendSelection ();
    1.28  	}	
    1.29  }
    1.30  
    1.31 @@ -2793,6 +2798,7 @@
    1.32  					xelection.select(bo);
    1.33  					xelection.update();
    1.34  					ensureSelectionVisible();
    1.35 +					sendSelection();
    1.36  				}
    1.37  			}	
    1.38  		} else
    1.39 @@ -2806,6 +2812,7 @@
    1.40  					xelection.select(par);
    1.41  					xelection.update();
    1.42  					ensureSelectionVisible();
    1.43 +					sendSelection();
    1.44  				}
    1.45  			} else
    1.46  			{
    1.47 @@ -2817,6 +2824,7 @@
    1.48  						xelection.select(bo);
    1.49  						xelection.update();
    1.50  						ensureSelectionVisible();
    1.51 +					sendSelection();
    1.52  					}
    1.53  				}
    1.54  			}
    1.55 @@ -2847,6 +2855,7 @@
    1.56  					xelection.select(bo);
    1.57  					xelection.update();
    1.58  					ensureSelectionVisible();
    1.59 +					sendSelection();
    1.60  				}
    1.61  			}
    1.62  		} else
    1.63 @@ -2860,6 +2869,7 @@
    1.64  					xelection.select(par);
    1.65  					xelection.update();
    1.66  					ensureSelectionVisible();
    1.67 +					sendSelection();
    1.68  				}
    1.69  			} else
    1.70  			{
    1.71 @@ -2871,6 +2881,7 @@
    1.72  						xelection.select(bo);
    1.73  						xelection.update();
    1.74  						ensureSelectionVisible();
    1.75 +					sendSelection();
    1.76  					}
    1.77  				}
    1.78  			}
    1.79 @@ -2891,6 +2902,7 @@
    1.80  			xelection.select(bo2);
    1.81  			xelection.update();
    1.82  			ensureSelectionVisible();
    1.83 +			sendSelection();
    1.84  		}
    1.85  	}		
    1.86  }
    1.87 @@ -2909,6 +2921,7 @@
    1.88  			xelection.select(bo2);
    1.89  			xelection.update();
    1.90  			ensureSelectionVisible();
    1.91 +			sendSelection();
    1.92  		}
    1.93  	}		
    1.94  }
    1.95 @@ -3137,6 +3150,33 @@
    1.96  	}
    1.97  }
    1.98  
    1.99 +void MapEditor::editLocalURL()
   1.100 +{
   1.101 +	BranchObj *bo=xelection.getBranch();
   1.102 +	if (bo)
   1.103 +	{		
   1.104 +		QStringList filters;
   1.105 +		filters <<"All files (*)";
   1.106 +		filters << tr("Text","Filedialog") + " (*.txt)";
   1.107 +		filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
   1.108 +		filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
   1.109 +		filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
   1.110 +		QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
   1.111 +		fd->setFilters (filters);
   1.112 +		fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
   1.113 +		fd->setDirectory (lastFileDir);
   1.114 +		if (! bo->getVymLink().isEmpty() )
   1.115 +			fd->selectFile( bo->getURL() );
   1.116 +		fd->show();
   1.117 +
   1.118 +		if ( fd->exec() == QDialog::Accepted )
   1.119 +		{
   1.120 +			lastFileDir=QDir (fd->directory().path());
   1.121 +			setURL (fd->selectedFile() );
   1.122 +		}
   1.123 +	}
   1.124 +}
   1.125 +
   1.126  QString MapEditor::getURL()
   1.127  {
   1.128  	BranchObj *bo=xelection.getBranch();
   1.129 @@ -4043,18 +4083,7 @@
   1.130  
   1.131  void MapEditor::testFunction1()
   1.132  {
   1.133 -
   1.134 -    tcpServer = new QTcpServer(this);
   1.135 -    if (!tcpServer->listen(QHostAddress::Any,54321)) {
   1.136 -        QMessageBox::critical(this, tr("Fortune Server"),
   1.137 -                              tr("Unable to start the server: %1.")
   1.138 -                              .arg(tcpServer->errorString()));
   1.139 -        close();
   1.140 -        return;
   1.141 -    }
   1.142 -	connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
   1.143 -	if (debug)
   1.144 -		cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
   1.145 +	newServer();
   1.146  
   1.147  /*
   1.148  	BranchObj *bo=xelection.getBranch();
   1.149 @@ -4103,19 +4132,7 @@
   1.150  	
   1.151  void MapEditor::testFunction2()
   1.152  {
   1.153 -   QByteArray block;
   1.154 -    QDataStream out(&block, QIODevice::WriteOnly);
   1.155 -    out.setVersion(QDataStream::Qt_4_0);
   1.156 -    out << (quint16)0;
   1.157 -    out << xelection.getSelectString();
   1.158 -    out.device()->seek(0);
   1.159 -    out << (quint16)(block.size() - sizeof(quint16));
   1.160 -
   1.161 -	for (int i=0; i<clientList.size(); ++i)
   1.162 -	{
   1.163 -		cout << "Sending to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
   1.164 -		clientList.at(i)->write (block);
   1.165 -	}
   1.166 +	sendData("Foo");
   1.167  }
   1.168  
   1.169  void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
   1.170 @@ -4756,15 +4773,24 @@
   1.171  	mapCenter->reposition();
   1.172  }
   1.173  
   1.174 -void MapEditor::autosave()
   1.175 +
   1.176 +void MapEditor::sendSelection()
   1.177  {
   1.178 -	// Disable autosave, while we have gone back in history
   1.179 -	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
   1.180 -	if (redosAvail>0) return;
   1.181 -
   1.182 -
   1.183 -	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
   1.184 -		mainWindow->fileSave (this);
   1.185 +	sendData (xelection.getSelectString() );
   1.186 +}
   1.187 +
   1.188 +void MapEditor::newServer()
   1.189 +{
   1.190 +    tcpServer = new QTcpServer(this);
   1.191 +    if (!tcpServer->listen(QHostAddress::Any,54321)) {
   1.192 +        QMessageBox::critical(this, "vym server",
   1.193 +                              QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
   1.194 +        close();
   1.195 +        return;
   1.196 +    }
   1.197 +	connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
   1.198 +	if (debug)
   1.199 +		cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
   1.200  }
   1.201  
   1.202  void MapEditor::newClient()
   1.203 @@ -4789,6 +4815,42 @@
   1.204      //newClient->disconnectFromHost();
   1.205  }
   1.206  
   1.207 +
   1.208 +void MapEditor::sendData(const QString &s)
   1.209 +{
   1.210 +	// Create bytearray to send
   1.211 +	QByteArray block;
   1.212 +    QDataStream out(&block, QIODevice::WriteOnly);
   1.213 +    out.setVersion(QDataStream::Qt_4_0);
   1.214 +
   1.215 +	// Reserve some space for blocksize
   1.216 +    out << (quint16)0;
   1.217 +
   1.218 +	// Write data
   1.219 +    out << s;
   1.220 +
   1.221 +	// Go back and write blocksize so far
   1.222 +    out.device()->seek(0);
   1.223 +    out << (quint16)(block.size() - sizeof(quint16));
   1.224 +
   1.225 +	for (int i=0; i<clientList.size(); ++i)
   1.226 +	{
   1.227 +		cout << "Sending to "<<clientList.at(i)->peerAddress().toString().ascii()<<endl;
   1.228 +		clientList.at(i)->write (block);
   1.229 +	}
   1.230 +}
   1.231 +void MapEditor::autosave()
   1.232 +{
   1.233 +	// Disable autosave, while we have gone back in history
   1.234 +	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
   1.235 +	if (redosAvail>0) return;
   1.236 +
   1.237 +
   1.238 +	if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
   1.239 +		mainWindow->fileSave (this);
   1.240 +}
   1.241 +
   1.242 +
   1.243  /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event) 
   1.244  {
   1.245