-void BufferView::contextMenuEvent(QContextMenuEvent *event) {
- QModelIndex index = indexAt(event->pos());
- if(!index.isValid())
- index = rootIndex();
- if(!index.isValid())
- return;
-
- const Network *network = Client::network(index.data(NetworkModel::NetworkIdRole).value<NetworkId>());
- Q_CHECK_PTR(network);
-
- QIcon connectionStateIcon;
- if(network) {
- if(network->connectionState() == Network::Initialized) {
- connectionStateIcon = QIcon(":/22x22/actions/network-connect");
- } else if(network->connectionState() == Network::Disconnected) {
- connectionStateIcon = QIcon(":/22x22/actions/network-disconnect");
- } else {
- connectionStateIcon = QIcon(":/22x22/actions/gear");
- }
- }
-
- QMenu contextMenu(this);
- NetworkModel::itemType itemType = static_cast<NetworkModel::itemType>(index.data(NetworkModel::ItemTypeRole).toInt());
-
- switch(itemType) {
- case NetworkModel::NetworkItemType:
- showChannelList.setData(index.data(NetworkModel::NetworkIdRole));
- _disconnectNetAction.setIcon(connectionStateIcon);
- _connectNetAction.setIcon(connectionStateIcon);
- addItemToMenu(showChannelList, contextMenu, index, ActiveState);
- addItemToMenu(_disconnectNetAction, contextMenu, network->connectionState() != Network::Disconnected);
- addItemToMenu(_connectNetAction, contextMenu, network->connectionState() == Network::Disconnected);
- addSeparatorToMenu(contextMenu, index, ActiveState);
- addItemToMenu(_joinChannelAction, contextMenu, index, ActiveState);
- break;
- case NetworkModel::BufferItemType:
- {
- BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
- switch(bufferInfo.type()) {
- case BufferInfo::ChannelBuffer:
- addItemToMenu(_joinBufferAction, contextMenu, index, InactiveState);
- addItemToMenu(_partBufferAction, contextMenu, index, ActiveState);
- addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
- addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
- addItemToMenu(_removeBufferAction, contextMenu, index, InactiveState);
- createHideEventsSubMenu(contextMenu);
- addItemToMenu(_ignoreListAction, contextMenu);
- break;
- case BufferInfo::QueryBuffer:
- addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
- addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
- addItemToMenu(_removeBufferAction, contextMenu);
- createHideEventsSubMenu(contextMenu);
- break;
- default:
- addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
- addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
- break;