void MeanwhileSession::handleAwareListAware(struct mwAwareSnapshot *snapshot)
{
    HERE;
    MeanwhileContact *contact = static_cast<MeanwhileContact *>
		(account->contacts().value(snapshot->id.user));

    if (contact == 0L)
        return;

    /* use the setUserStatus callback for status updates for myself. */
    if (contact == account->myself())
        return;

    /* ### TODO!!
    contact->setProperty(get_protocol()->statusMessage, snapshot->status.desc);
    contact->setProperty(get_protocol()->awayMessage, snapshot->status.desc);
    */

    Kopete::OnlineStatus onlinestatus;
    if (snapshot->online) {
        onlinestatus = convertStatus(snapshot->status.status);
        resolveContactNickname(contact);
    } else {
        onlinestatus = convertStatus(0);
    }

    contact->setOnlineStatus(onlinestatus);

#if 0
    /* Commented out in previous kopete/meanwhile plugin for some reason,
     * but has still been ported to the new API.
     */
    time_t idletime = 0;
    if (snapshot->status.status == mwStatus_IDLE) {
	idletime = (snapshot->status.time == 0xdeadbeef) ?
            0 : snapshot->status.time;
        if (idletime != 0) {
        contact->setStatusDescription(statusDesc + '[' +
                QString::number(idletime/60)+" mins]");
        }
    } else
        contact->setStatusDescription(snapshot->status.desc);
#endif
}
Exemplo n.º 2
0
void ServiceClient::parseBuffer(const QByteArray& buff)
{
    //qDebug() << "Recieved! size=" << m_uiBlockSize;
    //QByteArray buff = m_qTcpSocket->read(m_uiBlockSize);

    ::uploadercontrol::ServiceResponse serverResponse;
    bool bParse = serverResponse.ParseFromArray(buff, m_uiBlockSize);//bytes.data(), bytes.size());
    if(!bParse)
    {
        //QMessageBox::information(0, "", "Ошибка чтения данных!");
        qDebug() << "Error of read!";
        m_flagForWaitBytes = WAIT_ID;
        m_uiBlockSize = 0;

        //
        /*QString rn = QString::number(200 * ((double)qrand()/RAND_MAX));
        FileUploadInfoModel fu1;
        fu1.setProgress(50);
        fu1.setFileName(rn);
        fu1.setIsBackup(false);
        fu1.setUploadStatus(FileUploadInfoModel::Pending);
        fu1.setCheckSum(rn);
        fu1.setIsArchive(false);
        fu1.setTask("fgfg");
        fu1.setDateTime(QDateTime::currentDateTime());
        fu1.setAttemptsRemaining(22);
        fu1.setResult("");
        fu1.setIndexed(false);
        emit dataUpload(fu1);

        fu1.setCheckSum("dfdfdfdf");
        fu1.setFileName("111111111111");
        fu1.setUploadStatus(FileUploadInfoModel::Pending);
        fu1.setIsBackup(true);
        emit dataUpload(fu1);*/
        //

        return;
    }
    //разбор байтов и определение типа

    switch(serverResponse.messagetype())
    {
        case ::uploadercontrol::ServiceResponse::AUTHORIZATION_STATUS:
        {
            //если пользователь еще не авторизован, то принимаем класс AutorizationResponce
            m_Credentials.setAdmin(serverResponse.authorization().isadmin());
            m_Credentials.setAlreadyAuthorized(serverResponse.authorization().alreadyauthorized());
            if(!serverResponse.authorization().isok())
                Disconnect();

            emit isLogon(m_Credentials, serverResponse.authorization().isok());

            break;
        }
        case ::uploadercontrol::ServiceResponse::FILE_STATUS:
        {
            //если пользователь авторизован, то другой тип сообщения
            FileUploadInfoModel fu;
            if(serverResponse.filestatus().has_login())
                fu.setLogin(QString::fromStdString(serverResponse.filestatus().login()));
            for(const auto& item : serverResponse.filestatus().infos())
            {
                int progress = 0;
                if(item.size() != 0)
                    progress = (100 * item.bytesprocessed()) / ((double)item.size());

                fu.setProgress(progress);
                fu.setFileName(QString::fromStdString(item.pathname()));
                fu.setIsBackup(item.isbackup());
                fu.setUploadStatus(convertStatus(item.status()));
                fu.setCheckSum(QString::fromStdString(item.checksum()));
                fu.setIsArchive(serverResponse.filestatus().responsetype() == ::uploadercontrol::Archive);
                fu.setTask(QString::fromStdString(item.task()));
                fu.setDateTime(QDateTime::fromTime_t(item.uploaddate()));
                fu.setAttemptsRemaining(item.retriescount());
                fu.setResult(QString::fromStdString(item.additionalmessage()));
                fu.setIndexed(item.has_fileid());

                //qDebug() << fu.fileName();
                emit dataUpload(fu);
            }
            break;
        }
        case ::uploadercontrol::ServiceResponse::COPYING_STATUS:
        {
            //информация о том сколько байтов скопировано при промежуточном копировании
            FileUploadInfoModel fu;
            fu.setFileSize(serverResponse.copyingstatus().filestotal());
            fu.setProgress(serverResponse.copyingstatus().filescopied());
            emit dataInfoCopying(fu);
            break;
        }
        case ::uploadercontrol::ServiceResponse::MAINTENANCE_STATUS:
        {
            //
            emit isPaused(serverResponse.maintenancestatus().ispaused());
            break;
        }
        case ::uploadercontrol::ServiceResponse::FILELIST:
        {
            //emit isPaused(serverResponse.maintenancestatus().ispaused());
            QList<FileSystemRemoteItemModel> fileList;
            for(int i = 0; i < serverResponse.filelist().list_size(); i++)
            {
                FileSystemRemoteItemModel item;
                item.setIsFolder(serverResponse.filelist().list(i).isfolder());
                item.setName(QString::fromStdString(serverResponse.filelist().list(i).name()));
                fileList.append(item);
            }
            responseFolderContents(fileList, serverResponse.filelist().foldercontentrecursively());
            break;
        }
        case ::uploadercontrol::ServiceResponse::ERRORMESSAGE:
        {
            //
            emit questionsAboutDownloading(QString::fromStdString(serverResponse.error().message()));
            break;
        }
        default:
        {
            qDebug() << "default messagetype = " << serverResponse.messagetype();
        }
    }
    //Обнуляем переменную
    m_flagForWaitBytes = WAIT_ID;
    m_uiBlockSize = 0;
}
void MeanwhileSession::handleSessionSetUserStatus()
{
    struct mwUserStatus *userstatus = mwSession_getUserStatus(session);
    emit sessionStateChange(convertStatus((unsigned int)userstatus->status));
}
Exemplo n.º 4
0
/*
 * Returns a new instance of an LDM proxy. Can take a while because it
 * establishes a connection to the LDM.
 *
 * Arguments:
 *      host            Identifier of the host on which an LDM server is
 *                      running.
 *      instance        Pointer to a pointer to the new instance. "*instance"
 *                      is set upon successful return.
 * Returns:
 *      0               Success. "*instance" is set.
 *      LP_SYSTEM       System error. "log_start()" called.
 *      LP_TIMEDOUT     Connection attempt timed-out. "log_start()" called.
 *      LP_HOSTUNREACH  Host is unreachable. "log_start()" called.
 *      LP_RPC_ERROR    RPC error. "log_start()" called.
 *      LP_LDM_ERROR    LDM error. "log_start()" called.
 */
LdmProxyStatus
lp_new(
    const char* const   host,
    LdmProxy** const    instance)
{
    LdmProxyStatus      status = 0;     /* success */
    size_t              nbytes = sizeof(LdmProxy);
    LdmProxy*           proxy = (LdmProxy*)malloc(nbytes);

    if (NULL == proxy) {
        log_serror("Couldn't allocate %lu bytes for new LdmProxy", nbytes);
        status = LP_SYSTEM;
    }
    else {
        proxy->host = strdup(host);

        if (NULL == proxy->host) {
            LOG_SERROR1("Couldn't duplicate string \"%s\"", host);
            status = LP_SYSTEM;
        }
        else {
            CLIENT*         clnt = NULL;
            ErrorObj*       error = ldm_clnttcp_create_vers(host, LDM_PORT, 6,
                    &clnt, NULL, NULL);

            if (!error) {
                proxy->version = 6;
                proxy->hiya = my_hiya_6;
                proxy->send = my_send_6;
                proxy->flush = my_flush_6;
            }
            else if (LDM_CLNT_BAD_VERSION == err_code(error)) {
                /* Couldn't connect due to protocol version. */
                err_free(error);

                error = ldm_clnttcp_create_vers(host, LDM_PORT, 5,
                        &clnt, NULL, NULL);

                if (!error) {
                    proxy->version = 5;
                    proxy->hiya = my_hiya_5;
                    proxy->send = my_send_5;
                    proxy->flush = my_flush_5;
                }
            }

            if (error) {
                LOG_START1("%s", err_message(error));
                err_free(error);
                free(proxy->host);
                status = convertStatus(error);
            }
            else {
                proxy->clnt = clnt;
                proxy->rpcTimeout = rpcTimeout;
            }
        }                                       /* "proxy->host" allocated */

        if (LP_OK == status) {
            *instance = proxy;
        }
        else {
            free(proxy);
        }
    }                                           /* "proxy" allocated */

    return status;
}