mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-11 17:04:31 -05:00
Merge pull request #2819 from thunder2/fix-chatlobby-traymenu
Fixed memory leak when using tray menu of chat lobby and removed doub…
This commit is contained in:
commit
91dd22d8d3
@ -187,7 +187,7 @@ void ChatLobbyUserNotify::iconClicked()
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
/// Tray icon Menu ///
|
/// Tray icon Menu ///
|
||||||
QMenu* trayMenu = new QMenu(MainWindow::getInstance());
|
QMenu* trayMenu = createMenu();
|
||||||
std::list<ChatLobbyId> lobbies;
|
std::list<ChatLobbyId> lobbies;
|
||||||
rsMsgs->getChatLobbyList(lobbies);
|
rsMsgs->getChatLobbyList(lobbies);
|
||||||
bool doUpdate=false;
|
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");
|
QString strName=tr("Remove All");
|
||||||
QAction *pAction = new QAction( QIcon(), strName, trayMenu);
|
QAction *pAction = new QAction( QIcon(), strName, trayMenu);
|
||||||
ActionTag actionTag={0x0, "", true};
|
ActionTag actionTag={0x0, "", true};
|
||||||
pAction->setData(qVariantFromValue(actionTag));
|
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->addAction(pAction);
|
||||||
|
|
||||||
trayMenu->exec(QCursor::pos());
|
trayMenu->exec(QCursor::pos());
|
||||||
|
delete(trayMenu);
|
||||||
if (doUpdate) updateIcon();
|
if (doUpdate) updateIcon();
|
||||||
|
|
||||||
#endif
|
#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)
|
void ChatLobbyUserNotify::makeSubMenu(QMenu* parentMenu, QIcon icoLobby, QString strLobbyName, ChatLobbyId id)
|
||||||
{
|
{
|
||||||
lobby_map::iterator itCL=_listMsg.find(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();
|
unsigned int msgCount=msgMap.size();
|
||||||
|
|
||||||
if(!parentMenu) parentMenu = new QMenu(MainWindow::getInstance());
|
|
||||||
QMenu *lobbyMenu = parentMenu->addMenu(icoLobby, strLobbyName);
|
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));
|
lobbyMenu->setToolTip(getNotifyMessage(msgCount>1).arg(msgCount));
|
||||||
|
|
||||||
for (msg_map::iterator itMsg=msgMap.begin(); itMsg!=msgMap.end(); ++itMsg) {
|
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};
|
ActionTag actionTag={itCL->first, "", true};
|
||||||
pAction->setData(qVariantFromValue(actionTag));
|
pAction->setData(qVariantFromValue(actionTag));
|
||||||
lobbyMenu->addAction(pAction);
|
lobbyMenu->addAction(pAction);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLobbyUserNotify::iconHovered()
|
void ChatLobbyUserNotify::iconHovered()
|
||||||
|
@ -49,6 +49,7 @@ public:
|
|||||||
ChatLobbyUserNotify(QObject *parent = 0);
|
ChatLobbyUserNotify(QObject *parent = 0);
|
||||||
|
|
||||||
virtual bool hasSetting(QString *name, QString *group);
|
virtual bool hasSetting(QString *name, QString *group);
|
||||||
|
QMenu* createMenu();
|
||||||
void makeSubMenu(QMenu* parentMenu, QIcon icoLobby, QString strLobbyName, ChatLobbyId id);
|
void makeSubMenu(QMenu* parentMenu, QIcon icoLobby, QString strLobbyName, ChatLobbyId id);
|
||||||
void chatLobbyNewMessage(ChatLobbyId lobby_id, QDateTime time, QString senderName, QString msg);
|
void chatLobbyNewMessage(ChatLobbyId lobby_id, QDateTime time, QString senderName, QString msg);
|
||||||
void chatLobbyCleared(ChatLobbyId lobby_id, QString anchor, bool onlyUnread=false);
|
void chatLobbyCleared(ChatLobbyId lobby_id, QString anchor, bool onlyUnread=false);
|
||||||
|
@ -982,11 +982,12 @@ void ChatWidget::on_notifyButton_clicked()
|
|||||||
if(!notify) return;
|
if(!notify) return;
|
||||||
if (chatType() != CHATTYPE_LOBBY) return;
|
if (chatType() != CHATTYPE_LOBBY) return;
|
||||||
|
|
||||||
QMenu* menu = new QMenu(MainWindow::getInstance());
|
QMenu* menu = notify->createMenu();
|
||||||
QIcon icoLobby=(ui->notifyButton->icon());
|
QIcon icoLobby=(ui->notifyButton->icon());
|
||||||
|
|
||||||
notify->makeSubMenu(menu, icoLobby, title, chatId.toLobbyId());
|
notify->makeSubMenu(menu, icoLobby, title, chatId.toLobbyId());
|
||||||
menu->exec(ui->notifyButton->mapToGlobal(QPoint(0,ui->notifyButton->geometry().height())));
|
menu->exec(ui->notifyButton->mapToGlobal(QPoint(0,ui->notifyButton->geometry().height())));
|
||||||
|
delete(menu);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user