/*! * \param wid Window ID * * Runs when the specified Window ID is closed. */ void IdealIRC::subWinClosed(int wid) { subwindow_t empty; empty.wid = -1; subwindow_t sw = winlist.value(wid, empty); if (sw.wid == -1) return; // Nope. if (sw.type == WT_STATUS) { int statusCount = 0; QHashIterator<int,subwindow_t> i(winlist); while (i.hasNext()) if (i.next().value().type == WT_STATUS) ++statusCount; if (statusCount <= 1) return; // Nope. } std::cout << "Closing " << sw.widget->objectName().toStdString().c_str() << " (" << wid << ")" << std::endl; scriptParent.resetMenuPtrList(); if (sw.type == WT_STATUS) { // Closing a status window. QList<QMdiSubWindow*> closeList; // List of subwindows for this status to close QHashIterator<int,subwindow_t> i(winlist); // Iterate all windows IConnection *con = conlist.value(wid); // Remember window id of status is always equal to connection id. KISS! while (i.hasNext()) { i.next(); subwindow_t s = i.value(); // This item may not be a subwindow of the status that's closing. if (s.parent == wid) { // This item is a child of the status closeList.push_back(s.subwin); con->freeWindow( s.widget->objectName() ); } } if (con->isSocketOpen()) con->closeConnection(); // Begin closing the socket. // Close all its subwindows int count = closeList.count()-1; std::cout << " count : " << count << std::endl; for (int i = 0; i <= count; i++) { QMdiSubWindow *w = closeList.at(i); w->close(); } con->freeWindow("STATUS"); // Free status window lastly if (! con->isSocketOpen()) delete con; // Socket wasn't open, delete connection object } else { IConnection *con = conlist.value(sw.parent, NULL); if (con != NULL) con->freeWindow( sw.widget->objectName() ); winlist.remove(sw.wid); } if (sw.type == WT_CHANNEL) { IConnection *con = conlist.value(sw.parent); con->sockwrite("PART :" + sw.widget->objectName() ); } if (sw.type == WT_STATUS) wsw.delGroup(sw.wid); else wsw.delWindow(sw.wid); ui->treeWidget->removeItemWidget(sw.treeitem, 0); delete sw.treeitem; delete sw.widget; winlist.remove(wid); /** @note Do we need to delete the other pointers from subwindow_t ? **/ }