Changeset 247 in flair-src for trunk/tools/FlairGCS/src/Manager.cpp
- Timestamp:
- 05/28/18 18:23:35 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/FlairGCS/src/Manager.cpp
r244 r247 46 46 // tab bar for multiple connections 47 47 tabBar = new QTabBar(); 48 //tabBar->setTabsClosable(true); 48 49 managerLayout->addWidget(tabBar); 49 50 connect(tabBar, SIGNAL(currentChanged(int)), this, … … 95 96 } 96 97 98 99 icon_ok = QIcon(":green.png"); 100 icon_ko = QIcon(":red.png"); 101 102 97 103 QTimer *timer = new QTimer(this); 98 104 connect(timer, SIGNAL(timeout()), this, SLOT(acceptConnections())); … … 101 107 102 108 Manager::~Manager() { 103 for (int i = 0; i < udtSockets.count(); i++) {104 udtSockets.at(i)->kill();105 udtSockets.at(i)->thread()->wait();109 for (int i = 0; i < connections.count(); i++) { 110 connections.at(i).socket->kill(); 111 connections.at(i).socket->thread()->wait(); 106 112 } 107 113 … … 127 133 UdtSocket *udtSocket = new UdtSocket(socket,name); 128 134 udtSocket->moveToThread(thread); 129 udtSockets.append(udtSocket); 130 135 131 136 connect(udtSocket, SIGNAL(newFileUI(UDTSOCKET)), this, SLOT(newFileUI(UDTSOCKET))); 132 137 connect(udtSocket, SIGNAL(newConnectionLayout(QString)), this, SLOT(newConnectionLayout(QString)),Qt::BlockingQueuedConnection); … … 141 146 142 147 ConnectionLayout *newLayout = new ConnectionLayout(udtSocket, name); 143 connectionsLayout.append(newLayout);144 148 connect(udtSocket, SIGNAL(UDTStats(QString)), newLayout, SIGNAL(UDTStats(QString)));//connection in 2 steps to get udtsocket as sender 145 149 connect(newLayout, SIGNAL(UDTStats(QString)), this, SLOT(printUDTStats(QString))); … … 147 151 connect(newLayout, SIGNAL(destroyed(QObject *)), this, SLOT(layoutDestroyed(QObject *))); 148 152 connect(udtSocket, SIGNAL(destroyed(QObject *)), this, SLOT(udtSocketDestroyed(QObject *))); 149 connect(udtSocket, SIGNAL(destroyed()), newLayout, SLOT(deleteLater())); 150 151 // widget 153 154 // widget 152 155 QWidget *newWidget = new QWidget(); 153 connectionsWidget.append(newWidget);154 156 newWidget->setLayout(newLayout->getQGridLayout()); 155 157 managerLayout->insertWidget(1, newWidget); 156 158 newWidget->hide(); 157 159 160 connections_t connection; 161 connection.layout=newLayout; 162 connection.widget=newWidget; 163 connection.socket=udtSocket; 164 connections.append(connection); 165 158 166 //tab: avoid having only 1 tab (0, 2 or more) 159 if (connections Layout.count() == 1) { // first connection160 connectionsWidget.at(0)->show();167 if (connections.count() == 1) { // first connection 168 newWidget->show(); 161 169 hiddenTabName = name; 162 170 } 163 if (connections Layout.count() == 2) {164 tabBar->addTab( hiddenTabName);171 if (connections.count() == 2) { 172 tabBar->addTab(icon_ok,hiddenTabName); 165 173 currentTab = 0; 166 174 } 167 if (connections Layout.count() > 1) {168 tabBar->addTab( name);175 if (connections.count() > 1) { 176 tabBar->addTab(icon_ok,name); 169 177 } 170 178 } 171 179 172 180 void Manager::udtSocketDestroyed(QObject *obj) { 173 udtSockets.removeOne((UdtSocket *)obj); 181 fprintf(stderr,"sockets -1\n"); 182 //mark socket as not valid, it can be a connection lost 183 //in this case we keep the layout for reading, and mark it as problematic 184 fprintf(stderr,"change icon\n"); 185 for(int i=0;i<connections.count();i++) { 186 if(connections.at(i).socket==(UdtSocket *)obj) { 187 connections[i].socket=NULL; 188 break; 189 } 190 } 174 191 } 175 192 176 193 void Manager::layoutDestroyed(QObject *obj) { 177 int index = connectionsLayout.indexOf((ConnectionLayout *)obj); 178 179 delete connectionsWidget.at(index); 180 connectionsWidget.removeAt(index); 181 connectionsLayout.removeOne((ConnectionLayout *)obj); 182 183 //tab: avoid having only 1 tab (0, 2 or more) 194 fprintf(stderr,"layout -1\n"); 195 //remove the connection, it comes from a proper close 196 int index=-1; 197 for(int i=0;i<connections.count();i++) { 198 if(connections.at(i).layout==(ConnectionLayout *)obj) { 199 delete connections.at(i).widget; 200 //connections[i].widget=NULL; 201 //connections[i].layout=NULL; 202 connections.removeAt(i); 203 index=i; 204 break; 205 } 206 } 207 208 if(index==-1) { 209 fprintf(stderr,"layoutDestroyed: error, layout not found!\n"); 210 return; 211 } 212 213 //tab: avoid having only 1 tab (only 0, 2 or more) 184 214 if (tabBar->count() > 1) { 185 215 tabBar->removeTab(index); 186 216 } 187 217 188 if (connections Layout.count() == 1) {218 if (connections.count() == 1) { 189 219 hiddenTabName = tabBar->tabText(0); 190 220 tabBar->removeTab(0); 191 221 } 192 222 193 if (connections Layout.count() == 0) {223 if (connections.count() == 0) { 194 224 status->showMessage(""); 195 225 } 196 197 198 226 } 199 227 200 228 void Manager::newFileUI(UDTSOCKET socket) { 201 //remove udtsocket as it will be automatically destroyed202 udtSockets.removeOne((UdtSocket *)sender());203 204 229 QThread *thread = new QThread(this); 205 230 file_ui* fileUi = new file_ui(socket,name); … … 216 241 217 242 void Manager::printUDTStats(QString stats) { 218 int index = connectionsLayout.indexOf((ConnectionLayout *)sender()); 243 int index = -1; 244 for(int i=0;i<connections.count();i++) { 245 if(connections.at(i).layout==(ConnectionLayout *)sender()) { 246 index=i; 247 break; 248 } 249 } 250 219 251 if(index==-1) return; 220 252 … … 230 262 if (index >= 0) { 231 263 //if we are coming from layout destroyed 232 if(currentTab<connections Layout.count()) connectionsWidget.at(currentTab)->hide();233 connections Widget.at(index)->show();264 if(currentTab<connections.count()) connections.at(currentTab).widget->hide(); 265 connections.at(index).widget->show(); 234 266 currentTab = index; 235 267 } else { 236 268 currentTab = 0; 237 connectionsWidget.at(0)->show(); 238 } 269 connections.at(0).widget->show(); 270 } 271 QString msg="not connected"; 239 272 if (tabBar->count() == 0) { 240 status->showMessage(connectionsLayout.at(0)->getUDTStats()); 273 if(connections.at(0).socket!=NULL) msg=connections.at(0).socket->getUDTStats(); 274 241 275 } else { 242 status->showMessage(QString("%1: %2").arg(tabBar->tabText(index)).arg(connectionsLayout.at(index)->getUDTStats())); 243 } 276 if(connections.at(index).socket!=NULL) msg=QString("%1: %2").arg(tabBar->tabText(index)).arg(connections.at(index).socket->getUDTStats()); 277 } 278 status->showMessage(msg); 244 279 } 245 280 … … 249 284 250 285 if (dir_name != "") { 251 for (int i = 0; i < connections Layout.count(); i++) {286 for (int i = 0; i < connections.count(); i++) { 252 287 QFile *file; 253 288 file = new QFile(dir_name + "/" + 254 connections Layout.at(i)->getName() + ".xml");289 connections.at(i).layout->getName() + ".xml"); 255 290 if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { 256 291 QMessageBox::warning(this, "Warning", 257 292 "Enable to load " + 258 connections Layout.at(i)->getName() +293 connections.at(i).layout->getName() + 259 294 ".xml"); 260 295 continue; … … 268 303 QMessageBox::critical( 269 304 this, "Error", 270 "unable to read " + connections Layout.at(i)->getName() +305 "unable to read " + connections.at(i).layout->getName() + 271 306 ".xml" + " (" + errorMsg + " at " + QString::number(errorLine) + 272 307 "," + QString::number(errorColumn) + ")"); 273 308 } else { 274 connections Layout.at(i)->LoadXml(doc);309 connections.at(i).layout->LoadXml(doc); 275 310 } 276 311 delete file; … … 282 317 bool isUptodate = true; 283 318 284 for (int i = 0; i < connections Layout.count(); i++) {285 if (!connections Layout.at(i)->IsUptodate()) {319 for (int i = 0; i < connections.count(); i++) { 320 if (!connections.at(i).layout->IsUptodate()) { 286 321 isUptodate = false; 287 322 break; … … 319 354 QDir().mkdir(dir_name); 320 355 321 for (int i = 0; i < connections Layout.count(); i++) {356 for (int i = 0; i < connections.count(); i++) { 322 357 QDomDocument *xml = new QDomDocument("remote_ui_xml"); 323 358 324 connections Layout.at(i)->GetFullXml((QDomElement *)xml);325 326 QFile fichier(dir_name + "/" + connections Layout.at(i)->getName() +359 connections.at(i).layout->GetFullXml((QDomElement *)xml); 360 361 QFile fichier(dir_name + "/" + connections.at(i).layout->getName() + 327 362 ".xml"); 328 363 QString write_doc = (xml->ownerDocument()).toString(); … … 344 379 345 380 void Manager::send(void) { 346 for (int i = 0; i < connections Layout.count(); i++) {381 for (int i = 0; i < connections.count(); i++) { 347 382 QDomDocument doc("remote_ui_xml"); 348 connections Layout.at(i)->GetUpdateXml((QDomElement *)&doc);383 connections.at(i).layout->GetUpdateXml((QDomElement *)&doc); 349 384 // fprintf(stderr,"merge\n%s\n",doc.toString().toLocal8Bit().constData()); 350 385 351 connections Layout.at(i)->XmlToSend(doc);386 connections.at(i).layout->XmlToSend(doc); 352 387 } 353 388 } 354 389 355 390 void Manager::reset() { 356 for (int i = 0; i < connections Layout.count(); i++)357 connections Layout.at(i)->ResetAllChilds();358 } 391 for (int i = 0; i < connections.count(); i++) 392 connections.at(i).layout->ResetAllChilds(); 393 }
Note:
See TracChangeset
for help on using the changeset viewer.