-void NickView::showContextMenu(const QPoint & pos ) {
- QModelIndex index = indexAt(pos);
- QString username = index.sibling(index.row(), 0).data().toString();
- BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
-
- QMenu nickContextMenu(this);
-
- QAction *whoisAction = nickContextMenu.addAction(tr("WHOIS"));
- QAction *versionAction = nickContextMenu.addAction(tr("VERSION"));
- QAction *pingAction = nickContextMenu.addAction(tr("PING"));
- nickContextMenu.addSeparator();
-
- QMenu *modeMenu = nickContextMenu.addMenu(tr("modi"));
- QAction *opAction = modeMenu->addAction(tr("OP %1").arg(username));
- QAction *deOpAction = modeMenu->addAction(tr("de-OP %1").arg(username));
- QAction *voiceAction = modeMenu->addAction(tr("VOICE %1").arg(username));
- QAction *deVoiceAction = modeMenu->addAction(tr("de-VOICE %1").arg(username));
- nickContextMenu.addSeparator();
-
- QMenu *kickBanMenu = nickContextMenu.addMenu(tr("kick / ban"));
- QAction *kickAction = kickBanMenu->addAction(tr("KICK %1").arg(username));
- QAction *kickBanAction = kickBanMenu->addAction(tr("KICK+BAN %1").arg(username));
- nickContextMenu.addSeparator();
-
- QAction *result = nickContextMenu.exec(QCursor::pos());
-
- if (result == whoisAction) { Client::instance()->userInput(bufferInfo, "/WHOIS "+username); }
- if (result == versionAction) { Client::instance()->userInput(bufferInfo, "/CTCP "+username+" VERSION"); }
- if (result == pingAction) { Client::instance()->userInput(bufferInfo, "/CTCP "+username+" PING"); }
-
- if (result == opAction) { Client::instance()->userInput(bufferInfo, "/OP "+username); }
- if (result == deOpAction) { Client::instance()->userInput(bufferInfo, "/DEOP "+username); }
- if (result == voiceAction) { Client::instance()->userInput(bufferInfo, "/VOICE "+username); }
- if (result == deVoiceAction) { Client::instance()->userInput(bufferInfo, "/DEVOICE "+username); }
-
- if (result == kickAction) { Client::instance()->userInput(bufferInfo, "/KICK "+username); }
- if (result == kickBanAction) { Client::instance()->userInput(bufferInfo, "/KICKBAN "+username); }
+void NickView::startQuery(const QModelIndex &index) {
+ if(index.data(NetworkModel::ItemTypeRole) != NetworkModel::IrcUserItemType)
+ return;
+
+ IrcUser *ircUser = qobject_cast<IrcUser *>(index.data(NetworkModel::IrcUserRole).value<QObject *>());
+ NetworkId networkId = index.data(NetworkModel::NetworkIdRole).value<NetworkId>();
+ if(!ircUser || !networkId.isValid())
+ return;
+
+ Client::bufferModel()->switchToOrStartQuery(networkId, ircUser->nick());
+}
+
+void NickView::customEvent(QEvent *event) {
+ // THIS IS A REPLACEMENT FOR expandAll()
+ /* WARNING: do not call expandAll()!
+ * it fucks up big time in combination with sorting and changing the rootIndex
+ * the following sequence of commands leads to unexpected behavior when inserting new items
+ * setSortingEnabled(true);
+ * setModel();
+ * expandAll();
+ * setRootIndex();
+ */
+ if(event->type() != QEvent::User)
+ return;
+
+ if(!model())
+ return;
+
+ QModelIndex topLevelIdx;
+ for(int i = 0; i < model()->rowCount(rootIndex()); i++) {
+ topLevelIdx = model()->index(i, 0, rootIndex());
+ if(isExpanded(topLevelIdx))
+ continue;
+ else {
+ expand(topLevelIdx);
+ if(i < model()->rowCount(rootIndex()) - 1)
+ QCoreApplication::postEvent(this, new ExpandAllEvent);
+ break;
+ }
+ }
+ event->accept();