-//void BufferView::showContextMenu(const QPoint &pos) {
-void BufferView::contextMenuEvent(QContextMenuEvent *event) {
- QModelIndex index = indexAt(event->pos());
- 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:
- _disconnectNetAction.setIcon(connectionStateIcon);
- _connectNetAction.setIcon(connectionStateIcon);
- addItemToMenu(_disconnectNetAction, contextMenu, index, ActiveState);
- addItemToMenu(_connectNetAction, contextMenu, index, InactiveState);
- 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(_hideBufferAction, contextMenu, (bool)config());
- addItemToMenu(_removeBufferAction, contextMenu, index, InactiveState);
- createHideEventsSubMenu(contextMenu);
- addItemToMenu(_ignoreListAction, contextMenu);
- break;
- case BufferInfo::QueryBuffer:
- addItemToMenu(_hideBufferAction, contextMenu, (bool)config());
- addItemToMenu(_removeBufferAction, contextMenu);
- createHideEventsSubMenu(contextMenu);
- break;
- default:
- addItemToMenu(_hideBufferAction, contextMenu, (bool)config());
- break;
- }
- }
- break;
- default:
- return;
- }
-
- if(contextMenu.actions().isEmpty())
- return;
- QAction *result = contextMenu.exec(QCursor::pos());
-
- // Handle Result
- if(network && result == &_connectNetAction) {
- network->requestConnect();
- return;
- }
-
- if(network && result == &_disconnectNetAction) {
- network->requestDisconnect();
- return;
- }
-
- if(result == &_joinChannelAction) {
- // FIXME no QInputDialog in Qtopia
-#ifndef Q_WS_QWS
- bool ok;
- QString channelName = QInputDialog::getText(this, tr("Join Channel"), tr("Input channel name:"), QLineEdit::Normal, QString(), &ok);
- if(ok && !channelName.isEmpty()) {
- BufferInfo bufferInfo = index.child(0,0).data(NetworkModel::BufferInfoRole).value<BufferInfo>();
- if(bufferInfo.isValid()) {
- Client::instance()->userInput(bufferInfo, QString("/J %1").arg(channelName));