Commit a0832c09 authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: Fix issue with selection due to multiple local servers trying to use the same socket.

parent fcf8e390
......@@ -59,7 +59,6 @@ NavQt::NavQt(void* nav_parent_ctx, const char* nav_name,
form_widget = wrapInFrame(scrolledbrow);
server = new QLocalServer(trace_obj);
server->listen("STRING");
QObject::connect(
server, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
......@@ -107,6 +106,10 @@ void NavQtTraceObject::sel_convert_cb()
void NavQt::set_selection_owner(int set)
{
if (!server->isListening()) {
QLocalServer::removeServer("STRING");
server->listen("STRING");
}
selection_owner = set;
}
......
......@@ -59,7 +59,6 @@ PalQt::PalQt(void* pal_parent_ctx, const char* pal_name,
form_widget = wrapInFrame(scrolledbrow);
server = new QLocalServer(trace_obj);
server->listen("STRING");
QObject::connect(
server, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
......@@ -108,6 +107,10 @@ void PalQt::set_inputfocus(int focus)
void PalQt::set_selection_owner()
{
if (!server->isListening()) {
QLocalServer::removeServer("STRING");
server->listen("STRING");
}
selection_owner = 1;
brow_SetInverseColor(brow_ctx, flow_eDrawType_Line);
}
......
......@@ -95,19 +95,15 @@ WNavQt::WNavQt(void* xn_parent_ctx, QWidget* xn_parent_wid, const char* xn_name,
*w = form_widget;
serverString = new QLocalServer(trace_obj);
serverString->listen("STRING");
QObject::connect(
serverString, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
serverGraph = new QLocalServer(trace_obj);
serverGraph->listen("PWR_GRAPH");
QObject::connect(
serverGraph, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
serverObjId = new QLocalServer(trace_obj);
serverObjId->listen("PWR_OBJID");
QObject::connect(
serverObjId, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
serverAttrRef = new QLocalServer(trace_obj);
serverAttrRef->listen("PWR_ATTRREF");
QObject::connect(serverAttrRef, SIGNAL(newConnection()), trace_obj,
SLOT(sel_convert_cb()));
......@@ -197,6 +193,23 @@ int WNavQt::get_selection(char* str, int len)
void WNavQt::set_selection_owner()
{
if (!serverString->isListening()) {
QLocalServer::removeServer("STRING");
serverString->listen("STRING");
}
if (!serverGraph->isListening()) {
QLocalServer::removeServer("PWR_GRAPH");
serverGraph->listen("PWR_GRAPH");
}
if (!serverObjId->isListening()) {
QLocalServer::removeServer("PWR_OBJID");
serverObjId->listen("PWR_OBJID");
}
if (!serverAttrRef->isListening()) {
QLocalServer::removeServer("PWR_ATTRREF");
serverAttrRef->listen("PWR_ATTRREF");
}
selection_owner = 1;
}
......@@ -274,9 +287,11 @@ static void selection_data_set(
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.writeRawData(data, strlen(data));
out << QString(data);
QLocalSocket* clientConnection = server->nextPendingConnection();
QObject::connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));
clientConnection->write(block);
clientConnection->flush();
clientConnection->disconnectFromServer();
......
......@@ -72,15 +72,6 @@
#include <qlocalsocket.h>
typedef struct {
char str[200];
int len;
int received;
pwr_tStatus sts;
const char* atom;
int new_main;
} wow_sSelection;
typedef struct {
char title[80];
flow_tCtx flow_ctx;
......@@ -424,46 +415,33 @@ void CoWowQtObject::DisplayLicense()
int CoWowQt::GetSelection(char* str, int size, const char* atom)
{
log_debug("GetSelection str=%s, size=%d, arom=%s\n", str, size, atom);
static wow_sSelection data;
data.received = 0;
data.sts = 0;
data.atom = atom;
data.new_main = 0;
QLocalSocket* socket = new QLocalSocket();
socket->connectToServer(fl(atom));
if (!socket->waitForConnected()) {
log_debug("GetSelection failed, could not connect to local server %s: %s\n", fl(atom), qPrintable(socket->errorString()));
}
while (!data.received) {
QString rcvStr;
int received = 0;
while (!received) {
if (socket->waitForReadyRead(50)) {
if (socket->bytesAvailable() > 0) {
QDataStream in(socket);
if (socket->bytesAvailable() > int(sizeof(data.str) - 1)
|| in.atEnd()) {
data.sts = 0;
continue;
}
in.readRawData(data.str, socket->bytesAvailable());
data.str[socket->bytesAvailable()] = 0;
data.len = socket->bytesAvailable();
data.sts = 1;
} else {
data.sts = 0;
QDataStream in(socket);
if (socket->bytesAvailable() > 0 && !in.atEnd()) {
in >> rcvStr;
}
data.received = 1;
received = 1;
}
QApplication::processEvents();
}
socket->close();
delete socket;
if (data.sts && data.len < size) {
strcpy(str, data.str);
if (!rcvStr.isEmpty() && rcvStr.length() < size) {
strcpy(str, qPrintable(rcvStr));
}
return data.sts;
return !rcvStr.isEmpty();
}
void CoWowQt::CreateFileSelDia(const char* title, void* parent_ctx,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment