void CircleWidget::dropEvent(QDropEvent* event) { setExpanded(true, false); // Check, that the element is dropped from qTox QObject* o = event->source(); FriendWidget* widget = qobject_cast<FriendWidget*>(o); if (!widget) return; // Check, that the user has a friend with the same ToxId ToxId toxId(event->mimeData()->text()); Friend* f = FriendList::findFriend(toxId.getPublicKey()); if (!f) return; // Save CircleWidget before changing the Id int circleId = Settings::getInstance().getFriendCircleID(toxId.getPublicKey()); CircleWidget* circleWidget = getFromID(circleId); addFriendWidget(widget, f->getStatus()); Settings::getInstance().savePersonal(); if (circleWidget != nullptr) { circleWidget->updateStatus(); Widget::getInstance()->searchCircle(circleWidget); } setContainerAttribute(Qt::WA_UnderMouse, false); }
void FriendListWidget::dragEnterEvent(QDragEnterEvent* event) { ToxId toxId(event->mimeData()->text()); Friend* frnd = FriendList::findFriend(toxId.getPublicKey()); if (frnd) event->acceptProposedAction(); }
/** * @brief Shows a dialog asking whether or not to add this tox address as a friend. * @note Will wait until the core is ready first. * @param toxURI Tox URI to try to add. * @return True, if tox URI is correct, false otherwise. */ bool handleToxURI(const QString& toxURI) { Nexus& nexus = Nexus::getInstance(); Core* core = nexus.getCore(); while (!core) { if (!nexus.isRunning()) return false; core = nexus.getCore(); qApp->processEvents(); QThread::msleep(10); } while (!core->isReady()) { if (!nexus.isRunning()) return false; qApp->processEvents(); QThread::msleep(10); } QString toxaddr = toxURI.mid(4); ToxId toxId(toxaddr); QString error = QString(); if (!toxId.isValid()) { toxId = Toxme::lookup(toxaddr); if (!toxId.isValid()) { error = QMessageBox::tr("%1 is not a valid Toxme address.").arg(toxaddr); } } else if (toxId == core->getSelfId()) { error = QMessageBox::tr("You can't add yourself as a friend!", "When trying to add your own Tox ID as friend"); } if (!error.isEmpty()) { GUI::showWarning(QMessageBox::tr("Couldn't add friend"), error); return false; } const QString defaultMessage = QObject::tr("%1 here! Tox me maybe?", "Default message in Tox URI friend requests. Write something appropriate!"); const QString username = Nexus::getCore()->getUsername(); ToxURIDialog* dialog = new ToxURIDialog(nullptr, toxaddr, defaultMessage.arg(username)); QObject::connect(dialog, &ToxURIDialog::finished, [=](int result) { if (result == QDialog::Accepted) { Core::getInstance()->requestFriendship(toxId, dialog->getRequestMessage()); } dialog->deleteLater(); }); dialog->open(); return true; }
void CircleWidget::dragEnterEvent(QDragEnterEvent* event) { ToxId toxId(event->mimeData()->text()); Friend* f = FriendList::findFriend(toxId.getPublicKey()); if (f != nullptr) event->acceptProposedAction(); setContainerAttribute(Qt::WA_UnderMouse, true); // Simulate hover. }
void FriendListWidget::dropEvent(QDropEvent* event) { // Check, that the element is dropped from qTox QObject* o = event->source(); FriendWidget* widget = qobject_cast<FriendWidget*>(o); if (!widget) return; // Check, that the user has a friend with the same ToxId ToxId toxId(event->mimeData()->text()); Friend* f = FriendList::findFriend(toxId.getPublicKey()); if (!f) return; // Save CircleWidget before changing the Id int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey()); CircleWidget* circleWidget = CircleWidget::getFromID(circleId); moveWidget(widget, f->getStatus(), true); if (circleWidget) circleWidget->updateStatus(); }