int main() { Friend app; app.Run(); return 0; }
void Widget::onFriendMessageReceived(int friendId, const QString& message, bool isAction) { Friend* f = FriendList::findFriend(friendId); if (!f) return; QDateTime timestamp = QDateTime::currentDateTime(); f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp); if (isAction) HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, "/me " + message, f->getToxID().publicKey, timestamp); else HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, message, f->getToxID().publicKey, timestamp); if (activeChatroomWidget != nullptr) { if ((static_cast<GenericChatroomWidget*>(f->getFriendWidget()) != activeChatroomWidget) || isMinimized() || !isActiveWindow()) { f->setEventFlag(true); newMessageAlert(); } } else { f->setEventFlag(true); newMessageAlert(); } f->getFriendWidget()->updateStatusLight(); }
void Toolbar::setEntity(Entity *pEntity) { int hp = pEntity->getHp(); int fullHp = pEntity->getFullHp(); int attackHurt1 = 0; int attackHurt2 = 0; Friend *pFriend = dynamic_cast<Friend*>(pEntity); if(pFriend != NULL) { attackHurt1 = pFriend->getAttack1Hurt(); attackHurt2 = pFriend->getAttack2Hurt(); } else { Enermy *pEnermy = dynamic_cast<Enermy*>(pEntity); if(pEnermy != NULL) { attackHurt1 = pEnermy->getAttackHurt(); } } mHp->setString(CCString::createWithFormat("%d/%d", hp, fullHp)->getCString()); mAttackHurt->setString(CCString::createWithFormat("%d",attackHurt1)->getCString()); mFriendAttackHurt->setString(CCString::createWithFormat("%d",attackHurt2)->getCString()); }
void Widget::onFriendTypingChanged(int friendId, bool isTyping) { Friend* f = FriendList::findFriend(friendId); if (!f) return; f->getChatForm()->setFriendTyping(isTyping); }
bool FriendHandler::removeFriend(std::string friendID){ Yb::Session session(Yb::init_schema(), engine); Friend friendDel = query<Friend>(session).filter_by(Friend::c.friend_id==friendID).one(); friendDel.delete_object(); session.commit(); return true; }
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); }
Friend::Friend(const Friend &f) { strcpy(Nume,f.getNume()); strcpy(Prenume,f.getPrenume()); strcpy(NrTel,f.getNrTel()); strcpy(Data,f.getData()); }
void FriendListWidget::moveWidget(FriendWidget* widget, Status s, bool add) { if (mode == Name) { Friend* f = FriendList::findFriend(widget->friendId); int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey()); CircleWidget* circleWidget = CircleWidget::getFromID(circleId); if (circleWidget == nullptr || add) { if (circleId != -1) Settings::getInstance().setFriendCircleID(f->getPublicKey(), -1); listLayout->addFriendWidget(widget, s); return; } circleWidget->addFriendWidget(widget, s); } else { Friend* contact = FriendList::findFriend(widget->friendId); QDate activityDate = getDateFriend(contact); int time = static_cast<int>(getTime(activityDate)); QWidget* w = activityLayout->itemAt(time)->widget(); CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(w); categoryWidget->addFriendWidget(widget, contact->getStatus()); categoryWidget->show(); } }
void FriendListWidget::moveWidget(FriendWidget* w, Status s, bool add) { if (mode == Name) { int circleId = Settings::getInstance().getFriendCircleID(FriendList::findFriend(w->friendId)->getToxId()); CircleWidget* circleWidget = CircleWidget::getFromID(circleId); if (circleWidget == nullptr || add) { if (circleId != -1) Settings::getInstance().setFriendCircleID(FriendList::findFriend(w->friendId)->getToxId(), -1); listLayout->addFriendWidget(w, s); return; } circleWidget->addFriendWidget(w, s); } else { Friend* contact = FriendList::findFriend(w->friendId); QDate activityDate = getDateFriend(contact); Time time = getTime(activityDate); CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget()); categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus()); categoryWidget->show(); } }
void Widget::onReceiptRecieved(int friendId, int receipt) { Friend* f = FriendList::findFriend(friendId); if (!f) return; f->getChatForm()->dischargeReceipt(receipt); }
void Widget::onFriendUsernameLoaded(int friendId, const QString& username) { Friend* f = FriendList::findFriend(friendId); if (!f) return; f->setName(username); }
void Widget::onFriendStatusMessageLoaded(int friendId, const QString& message) { Friend* f = FriendList::findFriend(friendId); if (!f) return; f->setStatusMessage(message); }
void FriendWidget::setAlias(const QString& _alias) { QString alias = _alias.left(128); // same as TOX_MAX_NAME_LENGTH Friend* f = FriendList::findFriend(friendId); f->setAlias(alias); Settings::getInstance().setFriendAlias(f->getToxId(), alias); Settings::getInstance().savePersonal(); }
void Widget::copyFriendIdToClipboard(int friendId) { Friend* f = FriendList::findFriend(friendId); if (f != nullptr) { QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(core->getFriendAddress(f->getFriendID()), QClipboard::Clipboard); } }
void Widget::onFriendUsernameChanged(int friendId, const QString& username) { Friend* f = FriendList::findFriend(friendId); if (!f) return; QString str = username; str.replace('\n', ' '); str.remove('\r'); str.remove(QChar((char)0)); // null terminator... f->setName(str); }
void Widget::onMessageSendResult(int friendId, const QString& message, int messageId) { Q_UNUSED(message) Friend* f = FriendList::findFriend(friendId); if (!f) return; if (!messageId) f->getChatForm()->addSystemInfoMessage(tr("Message failed to send"), "red", QDateTime::currentDateTime()); }
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message) { Friend* f = FriendList::findFriend(friendId); if (!f) return; QString str = message; str.replace('\n', ' '); str.remove('\r'); str.remove(QChar((char)0)); // null terminator... f->setStatusMessage(str); }
QString FriendList::decideNickname(const ToxPk& friendPk, const QString& origName) { Friend* f = FriendList::findFriend(friendPk); if (f != nullptr) { return f->getDisplayedName(); } else if (!origName.isEmpty()) { return origName; } else { return friendPk.toString(); } }
void Group::updatePeer(int peerId, QString name) { ToxPk peerKey = Core::getInstance()->getGroupPeerPk(groupId, peerId); toxpks[peerKey] = name; Friend* f = FriendList::findFriend(peerKey); if (f != nullptr) { // use the displayed name from the friends list toxpks[peerKey] = f->getDisplayedName(); } else { emit userListChanged(groupId, toxpks); } }
void GameScene::initPlayer() { CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); // 创建Controller mGameController = GameController::create(); CCLayer::addChild(mGameController); // 创建2个Friends CCPoint pos[3]; char *friendFileName[3] = {"Hero.png", "Friend1.png", "Friend2.png"}; for(int i=0; i<3; ++i) { pos[i].x = visibleSize.width/6*(2*i+1); pos[i].y = FRIEND_SIZE +400; } for(int i=0; i<3; ++i) { Friend *pFriend = new Friend(friendFileName[i]); addFriend(pFriend, pos[i]); pFriend->increaseLevel(); pFriend->setSize(FRIEND_RADIUS); pFriend->setController(mGameController); } mGameController->setAttackingEntity(mFriendVec[0]); mFriendVec[1]->increaseLevel(); mFriendVec[2]->increaseLevel(); mFriendVec[2]->increaseLevel(); // 创建二个敌人 Enermy *pEnermy = new Enermy("Enermy1.png"); CCPoint epos; pEnermy->setHp(200); pEnermy->setType(1); pEnermy->setAttackHurt(30); pEnermy->setSize(ENERMY1_RADIUS); pEnermy->setController(mGameController); epos.y = visibleSize.height-480; epos.x = visibleSize.width*0.25; addEnermy(pEnermy, epos); pEnermy = new Enermy("Enermy2.png"); pEnermy->setHp(200); pEnermy->setSize(ENERMY2_RADIUS); pEnermy->setAttackHurt(40); pEnermy->setType(2); pEnermy->setController(mGameController); epos.y = visibleSize.height-480; epos.x = visibleSize.width*0.75; addEnermy(pEnermy, epos); }
Friend* FriendList::findFriend(const ToxID& userId) { auto id = tox2id.find(userId.publicKey); if (id != tox2id.end()) { Friend *f = findFriend(*id); if (!f) return nullptr; if (f->getToxID() == userId) return f; } return nullptr; }
void Widget::onFriendStatusChanged(int friendId, Status status) { Friend* f = FriendList::findFriend(friendId); if (!f) return; contactListWidget->moveWidget(f->getFriendWidget(), status); bool isActualChange = f->getStatus() != status; f->setStatus(status); f->getFriendWidget()->updateStatusLight(); //won't print the message if there were no messages before if(!f->getChatForm()->isEmpty() && Settings::getInstance().getStatusChangeNotificationEnabled() == true) { QString fStatus = ""; switch(f->getStatus()){ case Status::Away: fStatus = tr("away", "contact status"); break; case Status::Busy: fStatus = tr("busy", "contact status"); break; case Status::Offline: fStatus = tr("offline", "contact status"); break; default: fStatus = tr("online", "contact status"); break; } if (isActualChange) f->getChatForm()->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getDisplayedName()).arg(fStatus), "white", QDateTime::currentDateTime()); } }
void ContentDialogManager::updateFriendStatus(const ToxPk& friendPk) { auto dialog = contactDialogs.value(friendPk); if (dialog == nullptr) { return; } dialog->updateContactStatusLight(friendPk); if (dialog->isContactWidgetActive(friendPk)) { dialog->updateTitleAndStatusIcon(); } Friend* f = FriendList::findFriend(friendPk); dialog->updateFriendStatus(friendPk, f->getStatus()); }
Friend* FriendList::addFriend(int friendId, const ToxID& userId) { auto friendChecker = friendList.find(friendId); if (friendChecker != friendList.end()) qWarning() << "addFriend: friendId already taken"; Friend* newfriend = new Friend(friendId, userId); friendList[friendId] = newfriend; tox2id[userId.publicKey] = friendId; // Must be done AFTER adding to the friendlist // or we won't find the friend and history will have blank names newfriend->loadHistory(); return newfriend; }
int lookAround(Friend & friends, int ii, int jj, Circles & circles, Circle & discovered) { cout << "looking for a friend at " << ii << ", " << jj << endl; dumpCircles(circles); if (ii < 0 || jj < 0 || ii > friends.size() - 1 || jj > friends[0].length() - 1) { // cout << "out of bounds" << endl; return 0; // out of bounds } // cout << "bounds ok" << endl; if (friends[ii][jj] == 'N') { // cout << "not a friend" << endl; return 0; // no friends here } // cout << "I am someones friend" << endl; if (std::find(discovered.begin(), discovered.end(), make_pair(ii, jj)) != discovered.end()) { cout << "already a friend" << endl; return 0; // already a friend } // cout << "I am a new friend" << endl; circles.back().push_back(make_pair(ii, jj)); discovered.push_back(make_pair(ii, jj)); int newFriends( + lookAround(friends, ii, jj - 1, circles, discovered) // look left + lookAround(friends, ii, jj + 1, circles, discovered) // look right + lookAround(friends, ii - 1, jj, circles, discovered) // look up + lookAround(friends, ii + 1, jj, circles, discovered)); // look down return newFriends; }
QString FriendWidget::getStatusString() const { Friend* f = FriendList::findFriend(friendId); Status status = f->getStatus(); if (f->getEventFlag() == 1) return tr("New message"); else if (status == Status::Online) return tr("Online"); else if (status == Status::Away) return tr("Away"); else if (status == Status::Busy) return tr("Busy"); else if (status == Status::Offline) return tr("Offline"); return QString::null; }
Friend::Friend(const Friend &f) : QObject(f.parent()) { this->uid = f.uid; this->firstName = f.firstName; this->lastName = f.lastName; this->smallPhotoUrl = f.smallPhotoUrl; this->mediumPhotoUrl = f.mediumPhotoUrl; this->bigPhotoUrl = f.bigPhotoUrl; }
void FriendListWidget::removeFriendWidget(FriendWidget* w) { Friend* contact = FriendList::findFriend(w->friendId); if (mode == Activity) { QDate activityDate = getDateFriend(contact); int time = static_cast<int>(getTime(activityDate)); QWidget* widget = activityLayout->itemAt(time)->widget(); CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget); categoryWidget->removeFriendWidget(w, contact->getStatus()); categoryWidget->setVisible(categoryWidget->hasChatrooms()); } else { int id = Settings::getInstance().getFriendCircleID(contact->getPublicKey()); CircleWidget* circleWidget = CircleWidget::getFromID(id); if (circleWidget != nullptr) { circleWidget->removeFriendWidget(w, contact->getStatus()); Widget::getInstance()->searchCircle(circleWidget); } } }
void FriendListWidget::moveFriends(QLayout* layout) { for (int i = 0; i < layout->count(); i++) { QWidget* widget = layout->itemAt(i)->widget(); FriendWidget* friendWidget = qobject_cast<FriendWidget*>(widget); CircleWidget* circleWidget = qobject_cast<CircleWidget*>(widget); if (circleWidget) { circleWidget->moveFriendWidgets(this); } else if (friendWidget) { int friendId = friendWidget->friendId; Friend* contact = FriendList::findFriend(friendId); QDate activityDate = getDateFriend(contact); int time = static_cast<int>(getTime(activityDate)); QWidget* w = activityLayout->itemAt(time)->widget(); CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(w); categoryWidget->addFriendWidget(friendWidget, contact->getStatus()); } } }
void FriendListWidget::dropEvent(QDropEvent* event) { if (event->mimeData()->hasFormat("friend")) { int friendId = event->mimeData()->data("friend").toInt(); Friend* f = FriendList::findFriend(friendId); assert(f != nullptr); FriendWidget* widget = f->getFriendWidget(); assert(widget != nullptr); // Update old circle after moved. CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(f->getToxId())); moveWidget(widget, f->getStatus(), true); if (circleWidget != nullptr) circleWidget->updateStatus(); } }