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, ...@@ -59,7 +59,6 @@ NavQt::NavQt(void* nav_parent_ctx, const char* nav_name,
form_widget = wrapInFrame(scrolledbrow); form_widget = wrapInFrame(scrolledbrow);
server = new QLocalServer(trace_obj); server = new QLocalServer(trace_obj);
server->listen("STRING");
QObject::connect( QObject::connect(
server, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb())); server, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
...@@ -107,6 +106,10 @@ void NavQtTraceObject::sel_convert_cb() ...@@ -107,6 +106,10 @@ void NavQtTraceObject::sel_convert_cb()
void NavQt::set_selection_owner(int set) void NavQt::set_selection_owner(int set)
{ {
if (!server->isListening()) {
QLocalServer::removeServer("STRING");
server->listen("STRING");
}
selection_owner = set; selection_owner = set;
} }
......
...@@ -59,7 +59,6 @@ PalQt::PalQt(void* pal_parent_ctx, const char* pal_name, ...@@ -59,7 +59,6 @@ PalQt::PalQt(void* pal_parent_ctx, const char* pal_name,
form_widget = wrapInFrame(scrolledbrow); form_widget = wrapInFrame(scrolledbrow);
server = new QLocalServer(trace_obj); server = new QLocalServer(trace_obj);
server->listen("STRING");
QObject::connect( QObject::connect(
server, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb())); server, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
...@@ -108,6 +107,10 @@ void PalQt::set_inputfocus(int focus) ...@@ -108,6 +107,10 @@ void PalQt::set_inputfocus(int focus)
void PalQt::set_selection_owner() void PalQt::set_selection_owner()
{ {
if (!server->isListening()) {
QLocalServer::removeServer("STRING");
server->listen("STRING");
}
selection_owner = 1; selection_owner = 1;
brow_SetInverseColor(brow_ctx, flow_eDrawType_Line); 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, ...@@ -95,19 +95,15 @@ WNavQt::WNavQt(void* xn_parent_ctx, QWidget* xn_parent_wid, const char* xn_name,
*w = form_widget; *w = form_widget;
serverString = new QLocalServer(trace_obj); serverString = new QLocalServer(trace_obj);
serverString->listen("STRING");
QObject::connect( QObject::connect(
serverString, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb())); serverString, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
serverGraph = new QLocalServer(trace_obj); serverGraph = new QLocalServer(trace_obj);
serverGraph->listen("PWR_GRAPH");
QObject::connect( QObject::connect(
serverGraph, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb())); serverGraph, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
serverObjId = new QLocalServer(trace_obj); serverObjId = new QLocalServer(trace_obj);
serverObjId->listen("PWR_OBJID");
QObject::connect( QObject::connect(
serverObjId, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb())); serverObjId, SIGNAL(newConnection()), trace_obj, SLOT(sel_convert_cb()));
serverAttrRef = new QLocalServer(trace_obj); serverAttrRef = new QLocalServer(trace_obj);
serverAttrRef->listen("PWR_ATTRREF");
QObject::connect(serverAttrRef, SIGNAL(newConnection()), trace_obj, QObject::connect(serverAttrRef, SIGNAL(newConnection()), trace_obj,
SLOT(sel_convert_cb())); SLOT(sel_convert_cb()));
...@@ -197,6 +193,23 @@ int WNavQt::get_selection(char* str, int len) ...@@ -197,6 +193,23 @@ int WNavQt::get_selection(char* str, int len)
void WNavQt::set_selection_owner() 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; selection_owner = 1;
} }
...@@ -274,9 +287,11 @@ static void selection_data_set( ...@@ -274,9 +287,11 @@ static void selection_data_set(
{ {
QByteArray block; QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly); QDataStream out(&block, QIODevice::WriteOnly);
out.writeRawData(data, strlen(data)); out << QString(data);
QLocalSocket* clientConnection = server->nextPendingConnection(); QLocalSocket* clientConnection = server->nextPendingConnection();
QObject::connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));
clientConnection->write(block); clientConnection->write(block);
clientConnection->flush(); clientConnection->flush();
clientConnection->disconnectFromServer(); clientConnection->disconnectFromServer();
......
...@@ -72,15 +72,6 @@ ...@@ -72,15 +72,6 @@
#include <qlocalsocket.h> #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 { typedef struct {
char title[80]; char title[80];
flow_tCtx flow_ctx; flow_tCtx flow_ctx;
...@@ -424,46 +415,33 @@ void CoWowQtObject::DisplayLicense() ...@@ -424,46 +415,33 @@ void CoWowQtObject::DisplayLicense()
int CoWowQt::GetSelection(char* str, int size, const char* atom) 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(); QLocalSocket* socket = new QLocalSocket();
socket->connectToServer(fl(atom)); 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->waitForReadyRead(50)) {
if (socket->bytesAvailable() > 0) {
QDataStream in(socket); QDataStream in(socket);
if (socket->bytesAvailable() > int(sizeof(data.str) - 1) if (socket->bytesAvailable() > 0 && !in.atEnd()) {
|| in.atEnd()) { in >> rcvStr;
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;
} }
received = 1;
data.received = 1;
} }
QApplication::processEvents(); QApplication::processEvents();
} }
socket->close();
delete socket; delete socket;
if (data.sts && data.len < size) { if (!rcvStr.isEmpty() && rcvStr.length() < size) {
strcpy(str, data.str); strcpy(str, qPrintable(rcvStr));
} }
return data.sts; return !rcvStr.isEmpty();
} }
void CoWowQt::CreateFileSelDia(const char* title, void* parent_ctx, 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