void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) { QModelIndex index = indexAt(event->pos()); if (!index.isValid()) { return; } RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); QMenu contextMenu; if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { QAction* editContact = contextMenu.addAction(tr("Edit")); QAction* removeContact = contextMenu.addAction(tr("Remove")); #ifdef SWIFT_EXPERIMENTAL_FT QAction* sendFile = NULL; if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) { sendFile = contextMenu.addAction(tr("Send File")); } #endif QAction* result = contextMenu.exec(event->globalPos()); if (result == editContact) { eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID())); } else if (result == removeContact) { if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) { eventStream_->send(boost::make_shared<RemoveRosterItemUIEvent>(contact->getJID())); } } #ifdef SWIFT_EXPERIMENTAL_FT else if (sendFile && result == sendFile) { QString fileName = QFileDialog::getOpenFileName(this, tr("Send File"), "", tr("All Files (*);;")); if (!fileName.isEmpty()) { eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(fileName))); } } #endif } else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) { QAction* renameGroupAction = contextMenu.addAction(tr("Rename")); QAction* result = contextMenu.exec(event->globalPos()); if (result == renameGroupAction) { renameGroup(group); } } }
void CtrlrLuaMethodEditor::itemClicked (const MouseEvent &e, ValueTree &item) { if (e.mods.isPopupMenu()) { if ( item.hasType (Ids::luaManagerMethods) || item.hasType (Ids::luaMethodGroup) ) { PopupMenu m; m.addSectionHeader ("Group operations"); m.addItem (1, "Add method"); m.addItem (2, "Add files"); m.addItem (3, "Add group"); m.addSeparator(); if (item.hasType (Ids::luaMethodGroup)) { m.addItem (4, "Remove group"); m.addItem (5, "Rename group"); } m.addSeparator(); m.addItem (6, "Sort by name"); m.addItem (7, "Sort by size"); const int ret = m.show(); if (ret == 1) { addNewMethod (item); } else if (ret == 2) { addMethodFromFile (item); } else if (ret == 3) { addNewGroup (item); } else if (ret == 4) { removeGroup (item); } else if (ret == 5) { renameGroup (item); } else if (ret == 6) { ChildSorter sorter(true); getMethodManager().getManagerTree().sort (sorter, nullptr, false); triggerAsyncUpdate(); } else if (ret == 7) { ChildSorter sorter(false); getMethodManager().getManagerTree().sort (sorter, nullptr, false); triggerAsyncUpdate(); } } else if (item.hasType(Ids::luaMethod)) { PopupMenu m; m.addSectionHeader ("Method " + item.getProperty(Ids::luaMethodName).toString()); if ((int)item.getProperty(Ids::luaMethodSource) == CtrlrLuaMethod::codeInFile) { if (!File(item.getProperty(Ids::luaMethodSourcePath)).existsAsFile()) { m.addItem (12, "Locate file on disk"); } } m.addSeparator(); m.addItem (2,"Remove method"); const int ret = m.show(); if (ret == 11) { /* convert a in-memory method to a file based one */ } else if (ret == 12) { /* locate a missing file on disk */ } else if (ret == 10) { /* convert a method from a file to a in-memory property */ } else if (ret == 2) { /* remove a method */ if (SURE("Delete the selected method?", this)) { { methodEditArea->closeTabWithMethod (item); getMethodManager().removeMethod (item.getProperty(Ids::uuid).toString()); } triggerAsyncUpdate(); } } } } }
void *UserView::processEvent(Event *e) { switch (e->type()){ case EventInit: m_bInit = true; fill(); break; case EventContactOnline: if (m_bInit){ Contact *contact = (Contact*)(e->param()); bool bStart = blinks.empty(); list<BlinkCount>::iterator it; for (it = blinks.begin(); it != blinks.end(); ++it){ if ((*it).id == contact->id()) break; } if (it != blinks.end()){ (*it).count = BLINK_COUNT; return NULL; } BlinkCount bc; bc.id = contact->id(); bc.count = BLINK_COUNT; blinks.push_back(bc); if (bStart) blinkTimer->start(BLINK_TIMEOUT); return NULL; } break; case EventMessageDeleted: case EventMessageRead: case EventMessageReceived:{ Message *msg = (Message*)(e->param()); addContactForUpdate(msg->contact()); break; } case EventCommandExec:{ CommandDef *cmd = (CommandDef*)(e->param()); if (cmd->menu_id == MenuContact){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ if (cmd->id == CmdContactDelete){ QListViewItem *item = findContactItem(contact->id()); if (item){ ensureItemVisible(item); QRect rc = itemRect(item); QPoint p = viewport()->mapToGlobal(rc.topLeft()); rc = QRect(p.x(), p.y(), rc.width(), rc.height()); BalloonMsg::ask((void*)contact->id(), i18n("Delete \"%1\"?") .arg(contact->getName()), this, SLOT(deleteContact(void*)), NULL, &rc); } return e->param(); } if (cmd->id == CmdContactRename){ QListViewItem *item = findContactItem(contact->id()); if (item){ setCurrentItem(item); renameContact(); } return e->param(); } if (cmd->id == CmdShowAlways){ ListUserData *data = (ListUserData*)(contact->getUserData(CorePlugin::m_plugin->list_data_id, true)); if (data){ bool bShow = false; if (cmd->flags & COMMAND_CHECKED) bShow = true; if ((data->ShowAlways != 0) != bShow){ data->ShowAlways = bShow; Event e(EventContactChanged, contact); e.process(); } } return e->param(); } if (cmd->id == CmdClose){ UserWnd *wnd = NULL; QWidgetList *list = QApplication::topLevelWidgets(); QWidgetListIt it(*list); QWidget * w; while ((w = it.current()) != NULL){ if (w->inherits("Container")){ Container *c = static_cast<Container*>(w); wnd = c->wnd((unsigned)(cmd->param)); if (wnd) break; } ++it; } delete list; if (wnd){ delete wnd; return e->param(); } } if (cmd->id > CmdSendMessage){ Command c; c->id = cmd->id - CmdSendMessage; c->menu_id = MenuMessage; c->param = (void*)(contact->id()); Event eCmd(EventCommandExec, c); if (eCmd.process()) return e->param(); } } } if (cmd->menu_id == MenuContactGroup){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ Group *grp = getContacts()->group(cmd->id - CmdContactGroup); if (grp && (grp->id() != contact->getGroup())){ contact->setGroup(grp->id()); Event eChanged(EventContactChanged, contact); eChanged.process(); return e->param(); } } } if (cmd->menu_id == MenuContainer){ Contact *contact = getContacts()->contact((unsigned)(cmd->param)); if (contact){ Container *from = NULL; Container *to = NULL; QWidgetList *list = QApplication::topLevelWidgets(); QWidgetListIt it(*list); QWidget * w; unsigned max_id = 0; while ((w = it.current()) != NULL){ if (w->inherits("Container")){ Container *c = static_cast<Container*>(w); if (c->getId() == cmd->id) to = c; if (c->wnd(contact->id())) from = c; if (!(c->getId() & CONTAINER_GRP)){ if (max_id < c->getId()) max_id = c->getId(); } } ++it; } if (from && to && (from == to)) return e->param(); UserWnd *userWnd = NULL; if (from){ userWnd = from->wnd(contact->id()); from->removeUserWnd(userWnd); } if (userWnd == NULL) userWnd = new UserWnd(contact->id(), NULL, true); if (to == NULL) to = new Container(max_id + 1); to->addUserWnd(userWnd); to->setNoSwitch(); raiseWindow(to); } return e->param(); } if (cmd->id == CmdOnline){ CorePlugin::m_plugin->setShowOnLine((cmd->flags & COMMAND_CHECKED) != 0); m_bShowOnline = (cmd->flags & COMMAND_CHECKED); if (cmd->menu_id){ CommandDef c = *cmd; c.bar_id = ToolBarMain; c.bar_grp = 0x4000; Event eCmd(EventCommandChange, &c); eCmd.process(); } fill(); } if (cmd->id == CmdGrpOff) setGroupMode(0); if (cmd->id == CmdGrpMode1) setGroupMode(1); if (cmd->id == CmdGrpMode2) setGroupMode(2); if (cmd->id == CmdGrpCreate){ if (CorePlugin::m_plugin->getGroupMode()){ Group *g = getContacts()->group(0, true); drawUpdates(); QListViewItem *item = findGroupItem(g->id()); if (item){ setCurrentItem(item); QTimer::singleShot(0, this, SLOT(renameGroup())); } } return e->param(); } if (cmd->id == CmdGrpRename){ QListViewItem *item = findGroupItem((unsigned)(cmd->param)); if (item){ setCurrentItem(item); renameGroup(); } return e->param(); } if (cmd->id == CmdGrpUp){ unsigned grp_id = (unsigned)(cmd->param); getContacts()->moveGroup(grp_id, true); QListViewItem *item = findGroupItem(grp_id); if (item){ ensureItemVisible(item); setCurrentItem(item); } return e->param(); } if (cmd->id == CmdGrpDown){ unsigned grp_id = (unsigned)(cmd->param); getContacts()->moveGroup(grp_id, false); QListViewItem *item = findGroupItem(grp_id); if (item){ ensureItemVisible(item); setCurrentItem(item); } return e->param(); } if (cmd->id == CmdGrpDelete){ unsigned grp_id = (unsigned)(cmd->param); QListViewItem *item = findGroupItem(grp_id); Group *g = getContacts()->group(grp_id); if (item && g){ ensureItemVisible(item); QRect rc = itemRect(item); QPoint p = viewport()->mapToGlobal(rc.topLeft()); rc = QRect(p.x(), p.y(), rc.width(), rc.height()); BalloonMsg::ask((void*)grp_id, i18n("Delete \"%1\"?") .arg(g->getName()), this, SLOT(deleteGroup(void*)), NULL, &rc); }