示例#1
0
void ChatClient::slotWriteToFriend(User* us) {
    User *fr = pSocket->addUserById(myId, us->id(), ServerFlags::InUserlist);
    connect(fr, SIGNAL(readMessages()), this, SLOT(slotReadMessageNotify()));
    Dialog *dg = userlist->userById(us->id());

    if (dg == NULL) {
        userlist->add(fr);
        dg = fr;
        connect(fr, SIGNAL(readMessages()), this, SLOT(slotReadMessageNotify()));
    }

    createDialog(dg);
    activateTab(dg);
    dialogFindFriends->close();
}
// MESSAGE FUNCTIONS
// Read messages and cleans up the oldies
MessageList readMessages(MessageList M, char* buffer, int length) {
    if (M is_not None && (difftime(time(NULL), M->timer) < 600)) {
        char date[80];
        struct tm ts = *localtime(&M->timer);
        strftime(date, sizeof(date), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
        length += sprintf(buffer+length, " - [ FROM %s @ %s ] \n   -> %s \n", M->from->username, date, M->message);
        M->next = readMessages(M->next, buffer, length);
        return M;
    } else if (M is_not None && (difftime(time(NULL), M->timer) >= 600)){
        MessageList tmp = M->next;
        free(M);
        return readMessages(tmp, buffer, length);
    }
    return None;
}
示例#3
0
文件: Batch.c 项目: Daymannovaes/cpp
Batch *readBatch(char *str, FILE *file) {
    int id = getBatchId(str);
    Batch *batch = createBatch(id);

    readMessages(batch, file);
    return batch;
}
/**
 * Method handling the stadium manager
 *all options are delegated to theyr respective handlers
 */
void CLIStadiumView::run()
{
	clScreen();
	Menu _menu;
	_menu.addToDisplay("    - upgrade an installation\n");
	_menu.addToDisplay("    - downgrade an installation\n");
	_menu.addToDisplay("    - quit to management menu\n");
	int option;
	_wait = false;
	do
	{
		loadInstallations();
		_wait = true;
		do {
			minisleep(0.1);
			readMessages();
		}
		while (_wait == true);
		printInstallationsList();
		option = _menu.run();
		switch(option)
		{
			case 1:
				showUpgradeInstallation();
				break;
			case 2:
				showDowngradeInstallation();
				break;
			default:
				break;
		}
	}
	while (option != 3);
}
示例#5
0
文件: dialog.cpp 项目: pva701/codes
void Dialog::slotFinishReadMessage() {
    int un = unreadMessage;
    for (int i = 0; i < un; ++i) {
        queUnreadWrote.front()->setStyleSheet("QTextEdit { background-color: #FFFFFF; }");
        queUnreadWrote.pop_front();
    }
    dgReadByUser = true;
    setUnreadMessage(0);
    if (un > 0)
        emit readMessages();
    tmrNotActive.start(INTERVAL_NOT_ACTIVE);
}
示例#6
0
void ChatClient::slotAddFriend(User* us) {
    User *fndUs = userlist->userById(us->id());
    if (fndUs != NULL) {
        pSocket->talker()->changeStatus(myId, us->id(), ServerFlags::Friend);
        fndUs->setFriend(true);
        return;
    }
    User *fr = pSocket->addUserById(myId, us->id(), ServerFlags::Friend);
    userlist->add(fr);
    connect(fr, SIGNAL(readMessages()), this, SLOT(slotReadMessageNotify()));
    dialogFindFriends->close();
}
void ListenerSocketConnection::threadClientFunction( void *p_arg ) {
	// startup sockets
	SocketProtocol::initSocketLib();

	// read messages
	readMessages();

	SocketListener *listener = getListener();
	listener -> removeListenerConnection( this );

	// cleanup sockets
	SocketProtocol::exitSocketLib();
}
示例#8
0
void ChatClient::showNotifications() {
    for (int i = 0; i < notifs.size(); ++i)
        if (notifs[i]->type() == ServerFlags::RequestAddToFriends)
            slotYouAreAddedInUserlist(notifs[i]->field[1].toInt(), notifs[i]->field[2].toString());
        else if (notifs[i]->type() == ServerFlags::UnreadMessages) {
            User *us = userlist->userByDialog(notifs[i]->field[1].toInt());
            if (us == NULL) {
                us = pSocket->addUserByDialog(myId, notifs[i]->field[1].toInt(), ServerFlags::InUserlist);
                userlist->add(us);
                connect(us, SIGNAL(readMessages()), this, SLOT(slotReadMessageNotify()));
            }
            us->setUnreadMessage(notifs[i]->field[2].toInt());
        } else if (notifs[i]->type() == ServerFlags::SendMessages) {
            User *us = userlist->userByDialog(notifs[i]->field[1].toInt());
            if (us == NULL) {
                us = pSocket->addUserByDialog(myId, notifs[i]->field[1].toInt(), ServerFlags::InUserlist);
                userlist->add(us);
                connect(us, SIGNAL(readMessages()), this, SLOT(slotReadMessageNotify()));
            }
            us->setWroteMessage(notifs[i]->field[2].toInt());
        }
}
示例#9
0
void ChatClient::slotMessageReceived(quint16 dialogNum, quint16 fromId, QDateTime sendTime, const QString &message) {
    Dialog *dg = userlist->userByDialog(dialogNum);////WRONG
    if (dg == NULL) {
        User *us = pSocket->addUserById(myId, fromId, ServerFlags::InUserlist);
        dg = us;
        userlist->add(us);
        connect(us, SIGNAL(readMessages()), this, SLOT(slotReadMessageNotify()));
    }
    bool wasCr = dg->createdWidget();
    createDialog(dg, wasCr);////no
    QString name = (fromId == myId ? "You" : dg->name());
    dg->appendToHistory(name, sendTime, Dialog::toDocumentFromString(message), Dialog::ReceivedMessage);
}
示例#10
0
task main()
{
  while(true){
	//
	// Test Ability to Turn Bluetooth On or Off
	//
	checkBTLinkConnected();
	eraseDisplay();
	bNxtLCDStatusDisplay = true; // Enable top status line display


	readMessages();
	wait1Msec(100);
	return;
}
}
示例#11
0
bool SocketConnection::read( SocketConnector& s )
{
  if ( !m_pSession ) return false;

  try
  {
    readFromSocket();
    readMessages( s.getMonitor() );
  }
  catch( SocketRecvFailed& e )
  {
    m_pSession->getLog()->onEvent( e.what() );
    return false;
  }
  return true;
}
示例#12
0
MessagesMessages TelegramCache::readMessages(const InputPeer &peer, int offset, int limit) const
{
    return readMessages(TelegramTools::inputPeerPeer(peer), offset, limit);
}
示例#13
0
void WebSocket::run() {
    acceptConnections();
    //handShake();
    readMessages();
}
示例#14
0
bool SocketConnection::read( SocketAcceptor& a, SocketServer& s )
{
  std::string msg;
  try
  {
    if ( !m_pSession )
    {
      struct timeval timeout = { 1, 0 };
      fd_set readset = m_fds;

      while( !readMessage( msg ) )
      {
        int result = select( 1 + m_socket, &readset, 0, 0, &timeout );
        if( result > 0 )
          readFromSocket();
        else if( result == 0 )
          return false;
        else if( result < 0 )
          return false;
      }

      m_pSession = Session::lookupSession( msg, true );
      if( !isValidSession() )
      {
        m_pSession = 0;
        if( a.getLog() )
        {
          a.getLog()->onEvent( "Session not found for incoming message: " + msg );
          a.getLog()->onIncoming( msg );
        }
      }
      if( m_pSession )
        m_pSession = a.getSession( msg, *this );
      if( m_pSession )
        m_pSession->next( msg, UtcTimeStamp() );
      if( !m_pSession )
      {
        s.getMonitor().drop( m_socket );
        return false;
      }

      Session::registerSession( m_pSession->getSessionID() );
      return true;
    }
    else
    {
      readFromSocket();
      readMessages( s.getMonitor() );
      return true;
    }
  }
  catch ( SocketRecvFailed& e )
  {
    if( m_pSession )
      m_pSession->getLog()->onEvent( e.what() );
    s.getMonitor().drop( m_socket );
  }
  catch ( InvalidMessage& )
  {
    s.getMonitor().drop( m_socket );
  }
  return false;
}
示例#15
0
bool SocketConnection::read( SocketAcceptor& a, SocketServer& s )
{
  std::string msg;
  try
  {
    if ( !m_pSession )
    {
      int timeout = 1000; // 1000ms = 1 second
      struct pollfd pfd = { m_socket, POLLIN | POLLPRI, 0 };

      while( !readMessage( msg ) )
      {
        int result = poll( &pfd, 1, timeout );
        if( result > 0 )
          readFromSocket();
        else if( result == 0 )
          return false;
        else if( result < 0 )
          return false;
      }

      m_pSession = Session::lookupSession( msg, true );
      if( !isValidSession() )
      {
        m_pSession = 0;
        if( a.getLog() )
        {
          a.getLog()->onEvent( "Session not found for incoming message: " + msg );
          a.getLog()->onIncoming( msg );
        }
      }
      if( m_pSession )
        m_pSession = a.getSession( msg, *this );
      if( m_pSession )
        m_pSession->next( msg, UtcTimeStamp() );
      if( !m_pSession )
      {
        s.getMonitor().drop( m_socket );
        return false;
      }

      Session::registerSession( m_pSession->getSessionID() );
      return true;
    }
    else
    {
      readFromSocket();
      readMessages( s.getMonitor() );
      return true;
    }
  }
  catch ( SocketRecvFailed& e )
  {
    if( m_pSession )
      m_pSession->getLog()->onEvent( e.what() );
    s.getMonitor().drop( m_socket );
  }
  catch ( InvalidMessage& )
  {
    s.getMonitor().drop( m_socket );
  }
  return false;
}
示例#16
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();
}