Example #1
0
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;
}
Example #2
0
void DialogFindFriends::slotFindFr() {
    emit findFriend(leFriendLogin->text());
}
main()
{
	int selection = 0;
	int entryNum = 0;
	entry *phoneBook;
	
	phoneBook = (entry*)malloc(sizeof(entry));
	do
	{
		
		printf("\n---------------------------------------------");
		printf("\nPhone Book\n[1]\tAdd Friend\n[2]\tDelete Friend\n[3]\tShow Phone Book\n[4]\tSearch Phone Book\n[5]\tRandom Entry\n[6]\tAlphebetical Phone Book\n[7]\tClear Phone Book\n[8]\tSave Phone Book\n[9]\tLoad Phone Book\n[0]\tExit\n:");
		scanf("%d",&selection);		
		switch(selection)
		{
		case 1:
			{
			 printf("\nYou have selected \"Add Friend\".");
			 
			 addFriend(phoneBook,&entryNum);
			 			 
			 break;
			}
		case 2:
			{
			 printf("\nYou have selected \"Delete Friend\".");
			 
			 delFriend(phoneBook,&entryNum);
			 break;
			}
		case 3:
			{
			 printf("\nYou have selected \"Show Phone Book\".");
			 showBook(phoneBook,&entryNum);
			 
			 break;
			}
		case 4:
			{
			 printf("\nYou have selected \"Search Phone Book\".");
			 findFriend(phoneBook,&entryNum);
			 
			 break;
			}
		case 5:
			{
			 printf("\nYou have selected \"Random Entry\".");
			 randEntry(phoneBook,&entryNum);
			 
			 break;
			}
		case 6:
			{
			 printf("\nYou have selected \"Alphabetical Phone Book\".");
			 alphaBook(phoneBook,&entryNum);
			 
			 break;
				
			}	
		case 7:
			{
			 printf("\nYou have selected \"Clear Phone Book\".");
			 clearBook(phoneBook,&entryNum);
			 
			 break;
				
			}
		case 8:
			{
			 printf("\nYou have selected \"Save Phone Book\".");
			 saveBook(phoneBook,&entryNum);
				
			 break;	
			}
		case 9:
			{
			 printf("\nYou have selected \"Load Phone Book\".");
			 phoneBook=loadBook(phoneBook,&entryNum);
				
			 break;	
			}
		case 0:
			{
			 printf("\nYou have selected \"Exit\".");
			 printf("\nHave a nice day!");
			 free(phoneBook);
			 break;
			}
		default:
			{
				printf("\nINVALID OPTION!");
				break;
			}
		
		}
		
		
	}while (selection!=0);
}
Example #4
0
ChatClient::ChatClient(ClientSocket *sockett, const QString& strHost, int nPort, int userIdx, const QString& pseud, QWidget *pwig):QWidget(pwig),
    userlist(new UserListWidget()), dialogFindFriends(NULL) {
    qDebug() << "chat client\n";
    pSocket = sockett;

    myId = userIdx;
    pseudonym = pseud;
    //infoAboutFriend = NULL;

    dialogFindFriends = new DialogFindFriends(this);
    connect(dialogFindFriends, SIGNAL(findFriend(QString)), this, SLOT(slotFindFriend(QString)));
    connect(dialogFindFriends, SIGNAL(add(User*)), this, SLOT(slotAddFriend(User*)));
    connect(dialogFindFriends, SIGNAL(write(User*)), this, SLOT(slotWriteToFriend(User*)));

    setWindowTitle("FriendlyChatClient");

    pButSend = new QPushButton("&Send", this);
    pButFind = new QPushButton("Find friends", this);

    QRect sizeOfMonitor = QApplication::desktop()->screenGeometry();
    qDebug() << "MONITOR " << sizeOfMonitor;
    setGeometry(sizeOfMonitor);

    QVBoxLayout *lytVBox = new QVBoxLayout();
    QHBoxLayout *lytHBox = new QHBoxLayout();
    QHBoxLayout *lytHButtonBox = new QHBoxLayout();

    tbwDialogs = new QTabWidget();///
    lytVBox->addWidget(tbwDialogs);

    lytHButtonBox->addWidget(pButSend);
    lytHButtonBox->addWidget(pButFind);

    lytVBox->addLayout(lytHButtonBox);
    pButSend->setMaximumSize(50, 40);
    pButSend->setEnabled(false);
    pButFind->setMaximumSize(100, 40);

    //listOfFriends->setIconSize(QSize(48, 48));
    userlist->setSelectionMode(QAbstractItemView::SingleSelection);
    QVector <User*> uss = pSocket->loadUserlist(myId);
    userlist->add(uss);
    for (int i = 0; i < uss.size(); ++i)
        connect(uss[i], SIGNAL(readMessages()), this, SLOT(slotReadMessageNotify()));
    notifs = Notification::convert(pSocket->loadNotifys(myId));

    connect(userlist, SIGNAL(doubleClickUser(Dialog*)), this, SLOT(slotDoubleClickDialog(Dialog*)));
    //pItem1->setBackgroundColor(QColor(255, 0, 0));
    //pItem1->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable);

    lytHBox->addLayout(lytVBox, 2);
    lytHBox->addWidget(userlist);
    setLayout(lytHBox);
    tbwDialogs->setMovable(true);
    tbwDialogs->setTabsClosable(true);
    connect(tbwDialogs, SIGNAL(tabCloseRequested(int)), this, SLOT(slotTabClosed(int)));
    connect(tbwDialogs, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentTabChanged(int)));

    connect(pButSend, SIGNAL(clicked()), this, SLOT(slotPrepareSendMessage()));
    connect(pButFind, SIGNAL(clicked()), this, SLOT(slotFindFriendsOpen()));
    //connect(listener, SIGNAL(messageRecieved(quint16,quint16,QDateTime,QString)), this, SLOT(slotMessageRecieved(quint16,quint16,QDateTime,QString)));
    connect(pSocket->listener(), SIGNAL(messageReceived(quint16,quint16,QDateTime,QString)), this, SLOT(slotMessageReceived(quint16,quint16,QDateTime,QString)), Qt::QueuedConnection);
    connect(pSocket->listener(), SIGNAL(youAddedInUserlist(quint16, QString)), this, SLOT(slotYouAreAddedInUserlist(quint16, QString)), Qt::QueuedConnection);
    connect(pSocket->listener(), SIGNAL(notifyOnOff(quint16,bool)), this, SLOT(slotNotifyOnOff(quint16, bool)));
    connect(pSocket->socket(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError)));
    connect(pSocket->listener(), SIGNAL(readAllYouMessageNotify(int)), SLOT(slotReadAllYouMessageNotify(int)));

    pSocket->initDateTime();
    showNotifications();
}