mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Fixed memory leak when using tray menu of chat lobby and removed double connect of signals
This commit is contained in:
parent
73f1da20f0
commit
f00e8ba18e
@ -187,7 +187,7 @@ void ChatLobbyUserNotify::iconClicked()
|
||||
#else
|
||||
|
||||
/// Tray icon Menu ///
|
||||
QMenu* trayMenu = new QMenu(MainWindow::getInstance());
|
||||
QMenu* trayMenu = createMenu();
|
||||
std::list<ChatLobbyId> lobbies;
|
||||
rsMsgs->getChatLobbyList(lobbies);
|
||||
bool doUpdate=false;
|
||||
@ -226,30 +226,27 @@ void ChatLobbyUserNotify::iconClicked()
|
||||
}
|
||||
}
|
||||
|
||||
if (notifyCombined()) {
|
||||
QSystemTrayIcon* trayIcon=getTrayIcon();
|
||||
if (trayIcon!=NULL) trayIcon->setContextMenu(trayMenu);
|
||||
} else {
|
||||
QAction* action=getNotifyIcon();
|
||||
if (action!=NULL) {
|
||||
action->setMenu(trayMenu);
|
||||
}
|
||||
}
|
||||
|
||||
QString strName=tr("Remove All");
|
||||
QAction *pAction = new QAction( QIcon(), strName, trayMenu);
|
||||
ActionTag actionTag={0x0, "", true};
|
||||
pAction->setData(qVariantFromValue(actionTag));
|
||||
connect(trayMenu, SIGNAL(triggered(QAction*)), this, SLOT(subMenuClicked(QAction*)));
|
||||
connect(trayMenu, SIGNAL(hovered(QAction*)), this, SLOT(subMenuHovered(QAction*)));
|
||||
trayMenu->addAction(pAction);
|
||||
|
||||
trayMenu->exec(QCursor::pos());
|
||||
delete(trayMenu);
|
||||
if (doUpdate) updateIcon();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
QMenu* ChatLobbyUserNotify::createMenu()
|
||||
{
|
||||
QMenu* menu = new QMenu(MainWindow::getInstance());
|
||||
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(subMenuClicked(QAction*)));
|
||||
connect(menu, SIGNAL(hovered(QAction*)), this, SLOT(subMenuHovered(QAction*)));
|
||||
return menu;
|
||||
}
|
||||
|
||||
void ChatLobbyUserNotify::makeSubMenu(QMenu* parentMenu, QIcon icoLobby, QString strLobbyName, ChatLobbyId id)
|
||||
{
|
||||
lobby_map::iterator itCL=_listMsg.find(id);
|
||||
@ -258,11 +255,7 @@ void ChatLobbyUserNotify::makeSubMenu(QMenu* parentMenu, QIcon icoLobby, QString
|
||||
|
||||
unsigned int msgCount=msgMap.size();
|
||||
|
||||
if(!parentMenu) parentMenu = new QMenu(MainWindow::getInstance());
|
||||
QMenu *lobbyMenu = parentMenu->addMenu(icoLobby, strLobbyName);
|
||||
connect(lobbyMenu, SIGNAL(triggered(QAction*)), this, SLOT(subMenuClicked(QAction*)));
|
||||
connect(lobbyMenu, SIGNAL(hovered(QAction*)), this, SLOT(subMenuHovered(QAction*)));
|
||||
|
||||
lobbyMenu->setToolTip(getNotifyMessage(msgCount>1).arg(msgCount));
|
||||
|
||||
for (msg_map::iterator itMsg=msgMap.begin(); itMsg!=msgMap.end(); ++itMsg) {
|
||||
@ -284,7 +277,6 @@ void ChatLobbyUserNotify::makeSubMenu(QMenu* parentMenu, QIcon icoLobby, QString
|
||||
ActionTag actionTag={itCL->first, "", true};
|
||||
pAction->setData(qVariantFromValue(actionTag));
|
||||
lobbyMenu->addAction(pAction);
|
||||
|
||||
}
|
||||
|
||||
void ChatLobbyUserNotify::iconHovered()
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
ChatLobbyUserNotify(QObject *parent = 0);
|
||||
|
||||
virtual bool hasSetting(QString *name, QString *group);
|
||||
QMenu* createMenu();
|
||||
void makeSubMenu(QMenu* parentMenu, QIcon icoLobby, QString strLobbyName, ChatLobbyId id);
|
||||
void chatLobbyNewMessage(ChatLobbyId lobby_id, QDateTime time, QString senderName, QString msg);
|
||||
void chatLobbyCleared(ChatLobbyId lobby_id, QString anchor, bool onlyUnread=false);
|
||||
|
@ -982,11 +982,12 @@ void ChatWidget::on_notifyButton_clicked()
|
||||
if(!notify) return;
|
||||
if (chatType() != CHATTYPE_LOBBY) return;
|
||||
|
||||
QMenu* menu = new QMenu(MainWindow::getInstance());
|
||||
QMenu* menu = notify->createMenu();
|
||||
QIcon icoLobby=(ui->notifyButton->icon());
|
||||
|
||||
notify->makeSubMenu(menu, icoLobby, title, chatId.toLobbyId());
|
||||
menu->exec(ui->notifyButton->mapToGlobal(QPoint(0,ui->notifyButton->geometry().height())));
|
||||
delete(menu);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user