-void BufferView::showContextMenu(const QPoint &pos) {
- QModelIndex index = indexAt(pos);
- if(!index.isValid()) return;
- QMenu contextMenu(this);
- QAction *connectNetAction = new QAction(tr("Connect"), this);
- QAction *disconnectNetAction = new QAction(tr("Disconnect"), this);
-
- QAction *joinBufferAction = new QAction(tr("Join"), this);
- QAction *partBufferAction = new QAction(tr("Part"), this);
- QAction *removeBufferAction = new QAction(tr("Delete buffer"), this);
-
- QMenu *hideEventsMenu = new QMenu(tr("Hide Events"), this);
- QAction *hideJoinAction = hideEventsMenu->addAction(tr("Join Events"));
- QAction *hidePartAction = hideEventsMenu->addAction(tr("Part Events"));
- QAction *hideKillAction = hideEventsMenu->addAction(tr("Kill Events"));
- QAction *hideQuitAction = hideEventsMenu->addAction(tr("Quit Events"));
- QAction *hideModeAction = hideEventsMenu->addAction(tr("Mode Events"));
- hideJoinAction->setCheckable(true);
- hidePartAction->setCheckable(true);
- hideKillAction->setCheckable(true);
- hideQuitAction->setCheckable(true);
- hideModeAction->setCheckable(true);
- hideJoinAction->setEnabled(false);
- hidePartAction->setEnabled(false);
- hideKillAction->setEnabled(false);
- hideQuitAction->setEnabled(false);
- hideModeAction->setEnabled(false);
-
- QAction *ignoreListAction = new QAction(tr("Ignore list"), this);
- ignoreListAction->setEnabled(false);
- QAction *whoBufferAction = new QAction(tr("WHO"), this);
-
- if(index.data(NetworkModel::ItemTypeRole) == NetworkModel::NetworkItemType) {
- if(index.data(NetworkModel::ItemActiveRole).toBool()) {
- contextMenu.addAction(disconnectNetAction);
+bool BufferView::checkRequirements(const QModelIndex &index, itemActiveStates requiredActiveState) {
+ if(!index.isValid())
+ return false;
+
+// NetworkModel::itemTypes itemType = static_cast<NetworkModel::itemTypes>(index.data(NetworkModel::ItemTypeRole).toInt());
+// if(!(itemType & validItemTypes))
+// return false;
+
+ itemActiveStates isActive = index.data(NetworkModel::ItemActiveRole).toBool()
+ ? activeState
+ : inactiveState;
+
+ if(!(isActive & requiredActiveState))
+ return false;
+
+ return true;
+}
+
+void BufferView::addItemToMenu(QAction &action, QMenu &menu, const QModelIndex &index, itemActiveStates requiredActiveState) {
+ if(checkRequirements(index, requiredActiveState)) {
+ menu.addAction(&action);
+ action.setVisible(true);
+ } else {
+ action.setVisible(false);
+ }
+}
+
+void BufferView::addItemToMenu(QAction &action, QMenu &menu, bool condition) {
+ if(condition) {
+ menu.addAction(&action);
+ action.setVisible(true);
+ } else {
+ action.setVisible(false);
+ }
+}
+
+
+void BufferView::addItemToMenu(QMenu &subMenu, QMenu &menu, const QModelIndex &index, itemActiveStates requiredActiveState) {
+ if(checkRequirements(index, requiredActiveState)) {
+ menu.addMenu(&subMenu);
+ subMenu.setVisible(true);
+ } else {
+ subMenu.setVisible(false);
+ }
+}
+
+void BufferView::addSeparatorToMenu(QMenu &menu, const QModelIndex &index, itemActiveStates requiredActiveState) {
+ if(checkRequirements(index, requiredActiveState)) {
+ menu.addSeparator();
+ }
+}
+
+QMenu *BufferView::createHideEventsSubMenu(QMenu &menu) {
+ // QMenu *hideEventsMenu = new QMenu(tr("Hide Events"), &menu);
+ QMenu *hideEventsMenu = menu.addMenu(tr("Hide Events"));
+ hideEventsMenu->addAction(&_hideJoinAction);
+ hideEventsMenu->addAction(&_hidePartAction);
+ hideEventsMenu->addAction(&_hideKillAction);
+ hideEventsMenu->addAction(&_hideQuitAction);
+ hideEventsMenu->addAction(&_hideModeAction);
+ return hideEventsMenu;
+}
+
+//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");