void
ProtocolDataTransfer::recvList()
{
        emit sigStart();

        int tmp = 0;
        int siz = 0;
        tmp = sock_.recv_n(&siz, sizeof(int));
        if (tmp != sizeof(int))
        {
                sock_.close();
                emit sigError(tr("Error occurred while receiving file list size."));
                return;
        }

        char* buf = new char[siz];
        tmp = sock_.recv_n(buf, siz);
        if (tmp != siz)
        {
                sock_.close();
                emit sigError(tr("Error occurred while receiving file list."));
                return;
        }
        sock_.close();

        QByteArray bArray(buf, siz);

        QStringList fileList = QString(bArray).split("/*/");

        delete buf;
        emit sigError(tr("List OK."));
}
Esempio n. 2
0
void PCapThread::slotStart(const QString &devDesc)
{
    /* Start the poll timer, kBps update timer, and the elapsed timer */
    spTimer_ = QSharedPointer<QTimer>(new QTimer);
    spTimer_->setInterval(0);
    spkBpsTimer_ = QSharedPointer<QTimer>(new QTimer);
    spkBpsTimer_->setInterval(500);
    spElapsed_ = QSharedPointer<QElapsedTimer>(new QElapsedTimer);
    connect(spTimer_.data(), SIGNAL(timeout()), this, SLOT(slotPoll()) );
    connect(spkBpsTimer_.data(), SIGNAL(timeout()), this, SLOT(slotKbps()) );
    std::string errmsg;
    std::map<std::string, std::string>::iterator it;
    if ( devMap_.end() == ( it = devMap_.find( devDesc.toUtf8().constData() ) ) )
    {
        emit sigError("Device not found");
        emit sigDone();
    }   
    else if ( spPCapImpl_->init(it->second, errmsg) )
    {   
        emit sigError("Error initializing " + devDesc + " " + QString::fromStdString(errmsg) ); 
        emit sigDone();
    }
    else
    {
        spkBpsTimer_->start();
        spElapsed_->start();
        spTimer_->start();
    }
}
Esempio n. 3
0
void PCapThread::slotStop()
{
    /* Stop the two timers and disconnect their signals */
    spTimer_->stop();
    spkBpsTimer_->stop();
    if ( !disconnect(spTimer_.data(), SIGNAL(timeout()), this, SLOT(slotPoll())) )
        emit sigError("Error Disconnecting timer slot");
    if (!disconnect(spkBpsTimer_.data(), SIGNAL(timeout()), this, SLOT(slotKbps())) )
        emit sigError("Error Disconnecting kBps slot");
    spPCapImpl_->shutDown();
    emit sigDone();
}
Esempio n. 4
0
void DBGConnection::slotError(int error)
{
  switch(error) {
  case QSocket::ErrConnectionRefused:
    emit sigError(QString("Connection refused"));
    break;
  case QSocket::ErrHostNotFound:
    emit sigError(QString("Host not found"));
    break;
  case QSocket::ErrSocketRead:
    emit sigError(QString("Error reading network data"));
    break;
  }
}
Esempio n. 5
0
/* Called directly from the main thread */
QStringList PCapThread::getDeviceList()
{
    QStringList qlist;
    devMap_.clear();
    std::string errmsg;
    spPCapImpl_->getDeviceList(devMap_, errmsg);
    if (!errmsg.empty())
        emit sigError(QString::fromStdString(errmsg));
    else if (devMap_.empty())
        emit sigError("No devices found (are you root?)");
    else
        for (std::map<std::string, std::string>::iterator it = devMap_.begin(); it != devMap_.end(); ++it)
            qlist << QString::fromStdString(it->first);
    return qlist;
}
Esempio n. 6
0
    void PCMThread::run()
    {
        try
        {
            init ();

            while (!quit_)
            {
                QByteArray bytes;
                bytes.reserve (periodSize_ * spSettings_->frameSize_);
                snd_pcm_sframes_t nframes;

                while ( (nframes = snd_pcm_readi (*spPCMHandle_, bytes.data(),
                                                  periodSize_)) < 0)
                {
                    snd_pcm_prepare (*spPCMHandle_);
                    emit sigDebug ("<<<<<<<<<<<<<<< Buffer Overrun >>>>>>>>>>>>>>>");
                }

                bytes.resize (nframes * spSettings_->frameSize_);
                emit sigTimeSeriesReady (bytes);
            }
        }
        catch
            (const std::exception& e)
        {
            emit sigError (QString {"pcm error: "} + e.what());
        }
    }
void
ProtocolDataTransfer::recvFile()
{
        QString const& fName = m_fileName;
        QFile file(fName);
        if (!file.open(QIODevice::WriteOnly))
        {
                sock_.close();
                m_CtrlID = DoError;
                emit sigError(tr("Unable to read the file %1: %2")
                        .arg(fName).arg(file.errorString()));
                return;
        }

        char buf[PayloadSize];

        emit sigStart();

        while (bytesTransfered < totalBytes
                && m_CtrlID == DoStart)
        {
                quint64 left = totalBytes - bytesTransfered;
                int len = sock_.recv_n(buf, (left>PayloadSize)?PayloadSize:left);
                bytesTransfered += len;
                file.write(buf, len);
        }
        file.close();
        sock_.close();
        acceptor_.close();

        if (bytesTransfered == totalBytes)
        {
                m_CtrlID = DoFinish;
                emit sigComplete();
        }
        else if (m_CtrlID == DoCancel)
        {
                file.remove();
                emit sigError(tr("Canceled"));
        }
        else
        {
                file.remove();
                emit sigError(tr("Error"));
        }
}
Esempio n. 8
0
int OPipe::available() {
#ifdef __windows__
	DWORD sum = 0;
	if(!PeekNamedPipe(fdes[0], NULL, NULL, NULL, &sum, NULL)) {
		sigError();
		return 0;
	}
#else
	int sum = 0;
	//an error was generated so handle it
	if(ioctl(fdes[0], FIONREAD, &sum) < 0) {
		sigError();
		return 0;
	}
#endif

	return sum;
}
void
ProtocolDataTransfer::sendFile()
{
        QString const& fName = m_fileName;
        QFile file(fName);
        if (!file.open(QIODevice::ReadOnly))
        {
                sock_.close();
                m_CtrlID = DoError;
                emit sigError(tr("Unable to read the file %1: %2")
                        .arg(fName).arg(file.errorString()));
                return;
        }

        char buf[PayloadSize];
        totalBytes = file.size();

        emit sigStart();

        while (bytesTransfered < totalBytes
                && m_CtrlID == DoStart)
        {
                int len = file.read(buf, PayloadSize);
                bytesTransfered += sock_.send_n(buf, len);
        }

        file.close();
        sock_.close();
        acceptor_.close();

        if (bytesTransfered == totalBytes)
        {
                emit sigComplete();
        }
        else if (m_CtrlID == DoCancel)
        {
                emit sigError(tr("Canceled"));
        }
        else
        {
                emit sigError(tr("Error"));
        }
}
Esempio n. 10
0
int OPipe::write(OByteArray &data, int len) {
#ifdef __windows__
	DWORD written = 0;
	if(!WriteFile(fdes[1], data.tellData(), len, &written, NULL)) {
		if(written <= 0) {
			sigError();
		}
	}
#else
	int written = 0;
	if((written = ::write(fdes[1], data.data(), len)) < 0) {
		sigError();
	}
#endif
	
	data.seek(written, OO::cur);
	
	return written;
}
Esempio n. 11
0
void
ProtocolDataTransfer::sendList()
{
        emit sigStart();

        totalBytes = 0;
        QStringList fileList = DataAccess::GetFileList(m_dirName, &totalBytes);

        QFileInfo finfo(m_dirName);
        QString const& headkey = fileList[0];
        QStringList headkeys = ParseFileInfoString(headkey);
        headkeys[2] = finfo.fileName();
        fileList[0] = headkeys.join("$");

        QString const& fstr = fileList.join("/*/");
        QByteArray const& bArray = fstr.toUtf8();

        int tmp = 0;
        int siz = bArray.size() + 1;
        tmp = sock_.send_n(&siz, sizeof(siz));
        if (tmp != sizeof(siz))
        {
                sock_.close();
                emit sigError(tr("Error occurred while sending file list size."));
                return;
        }

        tmp = sock_.send_n(bArray.data(), siz);
        if (tmp != siz)
        {
                sock_.close();
                emit sigError(tr("Error occurred while sending file list."));

                return;
        }
        sock_.close();

        emit sigError(tr("List OK."));
}
void PostEntry::submitPost( int blogId, const BilboPost &postData )
{
    kDebug();
    setCurrentPostFromEditor();
    if ( d->mCurrentPost.content().isEmpty() || d->mCurrentPost.title().isEmpty() ) {
        if ( KMessageBox::warningContinueCancel( this,
            i18n( "Your post title or body is empty.\nAre you sure you want to submit this post?" )
            ) == KMessageBox::Cancel )
            return;
    }
    bool isNew = false;
    if(d->mCurrentPost.status() == BilboPost::New)
        isNew = true;
    QPointer<SendToBlogDialog> dia = new SendToBlogDialog( isNew, d->mCurrentPost.isPrivate(), this);
    dia->setAttribute(Qt::WA_DeleteOnClose, false);
    if( dia->exec() == KDialog::Accepted ) {
        this->setCursor( Qt::BusyCursor );
        d->mCurrentPost.setProperties( postData );
        d->mCurrentPostBlogId = blogId;

        QString msgType;
        if(dia->isPrivate()) {
            msgType =  i18nc("Post status, e.g Draft or Published Post", "draft");
            d->mCurrentPost.setPrivate(true);
        } else {
            msgType =  i18nc("Post status, e.g Draft or Published Post", "post");
            d->mCurrentPost.setPrivate(false);
        }

        QString statusMsg;
        if(dia->isNew()) {
            statusMsg = i18n("Submitting new %1...", msgType);
            d->isNewPost = true;
        } else {
            statusMsg = i18n("Modifying %1...", msgType);
            d->isNewPost = false;
        }

        emit showStatusMessage(statusMsg, true);
        Backend *b = new Backend(d->mCurrentPostBlogId, this);
        connect( b, SIGNAL(sigError(QString)), this, SLOT(slotError(QString)) );
        if ( uploadMediaFiles(b) ) {
            kDebug()<<"Uploading";
            showProgressBar();
            connect( b, SIGNAL(sigPostPublished(int,BilboPost*)),
                     this, SLOT(slotPostPublished(int,BilboPost*)) );
            if(d->isNewPost)
                b->publishPost( &d->mCurrentPost );
            else
                b->modifyPost( &d->mCurrentPost );
        } else {
Esempio n. 13
0
int
ProtocolDataTransfer::connectTo()
{
        if (connector_.connect(sock_,
                Address(m_hostPort, m_hostAddress.toAscii().data())) == -1)
        {
                ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("(%P|%t) %p\n"),
                        ACE_TEXT ("Socket connection failed")));
                emit sigError(tr("Socket connection failed"));
                return -1;
        }
        return 0;
}
Esempio n. 14
0
int
ProtocolDataTransfer::accept()
{
        Address raddr;
        if (acceptor_.open(Address(m_hostPort)) == -1)
        {
                ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("(%P|%t) %p\n"),
                        ACE_TEXT ("Socket open failed")));
                emit sigError(tr("Socket open failed"));
                return -1;
        }
        if (acceptor_.accept(sock_, &raddr) == -1)
        {
                ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("(%P|%t) %p\n"),
                        ACE_TEXT ("Socket accept failed")));
                sock_.close();
                emit sigError(tr("Socket accept failed"));
                return -1;
        }
        return 0;
}
Esempio n. 15
0
DBGResponseTag* DBGReceiver::buildTag(int frameName, char* buffer)
{
  DBGResponseTag* tag = NULL;
  switch(frameName) {
    case FRAME_SID:
      tag = new DBGResponseTagSid(buffer);
      break;
    case FRAME_RAWDATA:
      tag = new DBGTagRawdata(buffer);
      break;
    case FRAME_VER:
      tag = new DBGResponseTagVersion(buffer);
      break;
    case FRAME_STACK:
      tag = new DBGResponseTagStack(buffer);
      break;
    case FRAME_BPL:
      tag = new DBGTagBreakpoint(buffer);
      break;
    case FRAME_EVAL:
      tag = new DBGResponseTagEval(buffer);
      break;
    case FRAME_SRC_TREE:
      tag = new DBGResponseTagSrcTree(buffer);
      break;
    case FRAME_LOG:
      tag = new DBGResponseTagLog(buffer);
      break;
    case FRAME_ERROR:
      tag = new DBGResponseTagError(buffer);
      break;
    case FRAME_PROF:
      tag = new DBGResponseTagProf(buffer);
      break;
    case FRAME_PROF_C:
      tag = new DBGResponseTagProfC(buffer);
      break;
    case FRAME_SRCLINESINFO:
      tag = new DBGResponseTagSrcLinesInfo(buffer);
      break;
    case FRAME_SRCCTXINFO:
      tag = new DBGResponseTagSrcCtxInfo(buffer);
      break;
    default:
      emit sigError("Error receiving network data.");
      break;
  }
  return tag;
}
Esempio n. 16
0
void PCapThread::slotPoll()
{
    /* Get the next DNS entry string */
    std::string pktStr;
    int ret = spPCapImpl_->getNextPacket(pktStr);
    if ( 0 > ret )
    {
        emit sigError("Error reading from interface");
        spTimer_->stop();
        emit sigDone();
    }
    else if ( 0 < ret && !pktStr.empty() )
    {
        QString qStr =  QString::fromStdString(pktStr);
        emit sigDataReady(qStr);
    }
}
Esempio n. 17
0
QString MediaManagement::getImageLocalPathDownloadIfNotExist(const QString &username, const QString & remotePath, QWidget *window)
{
// 	kDebug();
	QString path = map->readEntry(remotePath, QString());
	if(path.isEmpty()){
// 		QString mediaDir = MEDIA_DIR;
		path = DATA_DIR + "/" + username;
		if(KIO::NetAccess::download(remotePath, path, window)){
			map->writeEntry(remotePath, path);
			return path;
		} else{
			QString err = KIO::NetAccess::lastErrorString();
			emit sigError(err);
			return QString();
		}
	} else {
		return path;
	}
}
void Backend::postPublished( KBlog::BlogPost *post )
{
    kDebug() << "Blog Id: " << d->bBlog->id();
    if ( post->status() == KBlog::BlogPost::Error ) {
        kDebug() << "Publishing/Modifying Failed";
        const QString tmp( i18n( "Publishing/Modifying post failed: %1", post->error() ) );
        kDebug() << "Emitting sigError...";
        Q_EMIT sigError( tmp );
        return;
    }
    kDebug()<<"isPrivate: "<<post->isPrivate();
    if(post->isPrivate() && d->bBlog->api() == BilboBlog::GDATA_API){
        //GData do not support fetching drafts!
        savePostInDbAndEmitResult(post);
        return;
    }
    d->mSubmitPostStatusMap[ post ] = post->status();
    connect( d->kBlog, SIGNAL(fetchedPost(KBlog::BlogPost*)),
             this, SLOT(savePostInDbAndEmitResult(KBlog::BlogPost*)) );
    d->kBlog->fetchPost( post );
}
Esempio n. 19
0
DownloadsWidget::DownloadsWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DownloadsWidget)
{
    ui->setupUi(this);

    ui->tablePackages->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
    ui->tableImports->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
    ui->tablePackages->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
    ui->tablePackages->setColumnWidth(3, 200);
    ui->tableImports->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);

#ifdef Q_OS_WIN32
    ui->tableImports->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    ui->tablePackages->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
#endif

#ifndef Q_OS_MAC
    QFont titleFont = ui->labelArchives->font();
    titleFont.setPointSize(titleFont.pointSize()-4);
    ui->labelArchives->setFont(titleFont);
    ui->labelImportable->setFont(titleFont);
#endif

    m_extractor = new Extractor(this);
    m_watcher = new QFileSystemWatcher(this);

    connect(m_extractor, SIGNAL(sigError(QString,QString)), this, SLOT(onExtractorError(QString,QString)));
    connect(m_extractor, SIGNAL(sigFinished(QString, bool)), this, SLOT(onExtractorFinished(QString, bool)));
    connect(m_extractor, SIGNAL(sigProgress(QString,int)), this, SLOT(onExtractorProgress(QString,int)));
    connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(scanDownloadFolders()));

    connect(Manager::instance()->tvShowFileSearcher(), SIGNAL(tvShowsLoaded(int)), this, SLOT(scanDownloadFolders()));

    scanDownloadFolders();

    Helper::applyStyle(ui->tablePackages, true, false);
    Helper::applyStyle(ui->tableImports, true, false);
}
Esempio n. 20
0
OByteArray OPipe::read(int len) {
	OByteArray data;
	data.resize(len);

#ifdef __windows__
	DWORD recvlen = 0;
	if(!ReadFile(fdes[0], data.data(), len, &recvlen, NULL)) {
		return data;
	}
	data.resize(data.size() - (len - recvlen));
	
#else
	int recvlen;
	if((recvlen = ::read(fdes[0], data.data(), len)) > 0) {
		data.resize(data.size() - (len - recvlen));
		return data;
	} else {
		sigError();
	}
#endif

	return OByteArray();
}
Esempio n. 21
0
void XDNet::error(const QString& msg)
{
  emit sigError(msg);
  m_con->closeClient();
}
Esempio n. 22
0
bool CategoryModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
    if (role==Qt::DecorationRole && index.column()==0){
        catData[index.row()]["icon"]=value.toString();
    }
    bool result(true);
    if (role==Qt::EditRole){
        switch (index.column()){
            case 1:
            {
                QString str;
                QStringList tags=value.toStringList();
                for (int i=0; i<tags.size(); ++i) str.push_back(tags.at(i)+",");
                str.truncate(str.size()-1);
                catData[index.row()]["tags"]=str;
                break;
            }
            case 3:
            {
                bool findName(false);
                int i(0);
                while (i<catData.size()&& !findName){
                    findName=(catData.at(i).value("name[en]")==value.toString())&& i!=index.row();
                    ++i;
                }
                if (!findName){
                    catData[index.row()]["name[en]"]=value.toString();
                } else {
                    result=false;
                    emit sigError(tr("Category with the same name already exists"));
                }
                break;
            }
            case 4:
            {
                QStringList str=value.toStringList();
                QRegExp reg("^[ ]*(\\[[^\\]]+\\])([^\\]]+)$");
                QMap<QString, QString>::const_iterator iter = catData[index.row()].constBegin();
                while (iter != catData[index.row()].constEnd()) {
                    QString key=iter.key();
                    if (key.contains(QRegExp("name\\[[^\\]]*\\]$")) && key!="name[en]"){
                        catData[index.row()].remove(key);
                    }
                    ++iter;
                }
                for (int i=0; i<str.size(); ++i){
                    if (reg.indexIn(str.at(i))!=-1){
                        QString lang=reg.cap(1);
                        QString val=reg.cap(2);
                        //qDebug()<<"LANG= "<<lang<<"VAL= "<<val;
                        if (lang!="[en]") catData[index.row()]["name"+lang]=val;
                    }
                }
                break;
            }
            default:
                return false;
                break;
        }
    } else
        return false;
    emit dataChanged(index,index);
    return result;
}
Esempio n. 23
0
int CManageGroupChat::slotError(const QString &szId, CGroupChat::Condition c, int errorcode)
{
    emit sigError(szId, c, errorcode);
    return 0;
}
Esempio n. 24
0
void
ProtocolDataTransfer::recvDir()
{
        char buf[PayloadSize];
        int tmp = 0;
        int siz = 0;

		emit sigListStart();

        // list
        tmp = sock_.recv_n(&siz, sizeof(int));
        if (tmp != sizeof(int))
        {
                sock_.close();
                emit sigError(tr("Error occurred while receiving file list size."));
                return;
        }
        char* listBuf = new char[siz];
        tmp = sock_.recv_n(listBuf, siz);
        if (tmp != siz)
        {
                sock_.close();
                delete listBuf;
                emit sigError(tr("Error occurred while receiving file list."));
                return;
        }
        QString const& strBuf = QString::fromUtf8(listBuf, siz);
        QStringList fileList = strBuf.split("/*/");
        if (m_item)
        {
	        emit sigListReady(fileList);
	        m_lock.lock();
	        m_waitCondition.wait(&m_lock);
	        m_lock.unlock();
        }

        if (m_CtrlID != DoStart)
        {
                delete listBuf;
                return;
        }

		emit sigStart();

        QString const& headkey = fileList.takeAt(0);
        QStringList const& headkeys = ParseFileInfoString(headkey);
        totalBytes = headkeys[1].toULongLong();

        // files
        while (m_CtrlID == DoStart)
        {
                if (fileList.isEmpty())
                {
                        m_CtrlID = DoError;
                        sock_.close();
                        delete listBuf;
                        emit sigError(tr("File list became empty while receiving."));
                        return;
                }
                QString const& key = fileList.takeAt(0);
                QStringList keys = ParseFileInfoString(key);
                if (keys.size() < 3)
                {
                        m_CtrlID = DoError;
                        sock_.close();
                        acceptor_.close();
                        delete listBuf;
                        emit sigError(tr("Error occurred while parsing file information: %1.").arg(key));
                        return;
                }

                QString saveName = m_dirName + keys[2];
                if (keys[0] == "DIR")
                {
                        QDir dir;
                        dir.mkpath(saveName);
                        if (updateDirFileItemInfo)
                        {
	                        emit sigDirFileTransOK(0, keys[2]);
                        }
                }
                else if (keys[0] == "FILE")
                {
                        quint64 bytesRecvedOfFile = 0;
                        quint64 fsize = keys[1].toULongLong();
                        QFile file(saveName);
                        if (!file.open(QIODevice::WriteOnly))
                        {
                                m_CtrlID = DoError;
                                sock_.close();
                                acceptor_.close();
                                emit sigDirFileTransError(tr("Unable to save the file %1: %2")
                                        .arg(saveName).arg(file.errorString()), keys[2]);
                                delete listBuf;
                                return;
                        }

                        if (updateDirFileItemInfo)
                        {
	                        emit sigDirFileTransStart(keys[2]);
                        }
                        m_currentFileName = keys[2];
                        m_currentFilePos = 0;
                        tmp = sock_.recv_n(buf, (fsize)>PayloadSize?PayloadSize:fsize);
                        file.write(buf, tmp);
                        bytesRecvedOfFile += tmp;

                        while (bytesRecvedOfFile < fsize
                                && m_CtrlID == DoStart)
                        {
                                siz = (fsize-bytesRecvedOfFile)>PayloadSize?PayloadSize:(fsize-bytesRecvedOfFile);
                                tmp = sock_.recv_n(buf, siz);
                                file.write(buf, tmp);
                                bytesRecvedOfFile += tmp;
                                m_currentFilePos = bytesRecvedOfFile;
                        }
                        file.close();
                        m_currentFilePos = bytesRecvedOfFile;
                        bytesTransfered += bytesRecvedOfFile;
                        if (bytesRecvedOfFile < fsize 
                                && m_CtrlID == DoCancel)
                        {
                                file.remove();
                                goto callend;
                        }
                        if (updateDirFileItemInfo)
                        {
	                        emit sigDirFileTransOK(fsize, keys[2]);
                        }

                        if (bytesTransfered == totalBytes)
                        {
                                m_CtrlID = DoFinish;
                                goto callend;
                        }
                }
        }
callend:
        sock_.close();
        acceptor_.close();
        if (m_CtrlID == DoFinish)
        {
                emit sigComplete();
        }
        else if (m_CtrlID == DoCancel)
        {
                emit sigError(tr("Canceled"));
        }
        else
        {
                emit sigError(tr("Error"));
        }
        delete listBuf;
}
Esempio n. 25
0
void
ProtocolDataTransfer::sendDir()
{
        emit sigListStart();
        totalBytes = 0;
        QStringList fileList = DataAccess::GetFileList(m_dirName, &totalBytes);

        if (m_item)
        {
	        emit sigListReady(fileList);
	        m_lock.lock();
	        m_waitCondition.wait(&m_lock);
	        m_lock.unlock();
        }

        if (m_CtrlID != DoStart)
        {
                return;
        }
        QFileInfo finfo(m_dirName);
        QString const& headkey = fileList[0];
        QStringList headkeys = ParseFileInfoString(headkey);
        if (headkeys.size() < 3)
        {
                m_CtrlID = DoError;
                sock_.close();
                acceptor_.close();
                emit sigError(tr("Error occurred while parsing file information: %1.").arg(headkey));
                return;
        }

        headkeys[2] = finfo.fileName();
        fileList[0] = headkeys.join("$");

        QString const& fstr = fileList.join("/*/");
        std::string bArray = fstr.toUtf8().data();

        emit sigStart();

        // list
        int tmp = 0;
        int siz = bArray.length() + 1;
        tmp = sock_.send_n(&siz, sizeof(siz));
        if (tmp != sizeof(siz))
        {
                sock_.close();
                emit sigError(tr("Error occurred while sending file list size."));
                return;
        }

        tmp = sock_.send_n(bArray.c_str(), siz);
        if (tmp != siz)
        {
                sock_.close();
                emit sigError(tr("Error occurred while sending file list."));
                return;
        }

        fileList.removeAt(0);
        // files
        char buf[PayloadSize];
        while (m_CtrlID == DoStart)
        {
                if (fileList.isEmpty())
                {
                        m_CtrlID = DoError;
                        sock_.close();
                        emit sigError(tr("File list became empty while sending."));
                        return;
                }
                QString const& key = fileList.takeAt(0);
                QStringList keys = ParseFileInfoString(key);
                if (keys.size() < 3)
                {
                        m_CtrlID = DoError;
                        sock_.close();
                        acceptor_.close();
                        emit sigError(tr("Error occurred while parsing file information: %1.").arg(key));
                        return;
                }

                if (keys[0] == "DIR")
                {
                        if (updateDirFileItemInfo)
                        {
	                        emit sigDirFileTransOK(0, keys[2]);
                        }
                        continue;
                }
                else if (keys[0] == "FILE")
                {
                        quint64 bytesSentOfFile = 0;
                        quint64 fsize = keys[1].toULongLong();
                        QString const& fname = m_dirName + keys[2];
                        QFile file(fname);
                        if (!file.open(QIODevice::ReadOnly))
                        {
                                m_CtrlID = DoError;
                                sock_.close();
                                emit sigDirFileTransError(tr("Unable to read the file %1: %2")
                                        .arg(fname).arg(file.errorString()), keys[2]);
                                return;
                        }
                        if (updateDirFileItemInfo)
                        {
	                        emit sigDirFileTransStart(keys[2]);
                        }
                        m_currentFileName = keys[2];
                        m_currentFilePos = 0;

                        tmp = file.read(buf, PayloadSize);
                        tmp = sock_.send(buf, tmp);
                        bytesSentOfFile += tmp;

                        while (bytesSentOfFile < fsize
                                && m_CtrlID == DoStart)
                        {
                                tmp = file.read(buf, PayloadSize);
                                tmp = sock_.send(buf, tmp);
                                bytesSentOfFile += tmp;
                                m_currentFilePos = bytesSentOfFile;
                        }
                        file.close();
                        m_currentFilePos = bytesSentOfFile;
                        bytesTransfered += bytesSentOfFile;
                        if (bytesSentOfFile < fsize 
                                && m_CtrlID == DoCancel)
                        {
                                goto callend;
                        }
                        if (updateDirFileItemInfo)
                        {
	                        emit sigDirFileTransOK(fsize, keys[2]);
                        }

                        if (bytesTransfered == totalBytes)
                        {
                                m_CtrlID = DoFinish;
                                goto callend;
                        }
                }
        }
callend:
        sock_.close();
        acceptor_.close();
        if (m_CtrlID == DoFinish)
        {
                emit sigComplete();
        }
        else if (m_CtrlID == DoCancel)
        {
                emit sigError(tr("Canceled"));
        }
        else
        {
                emit sigError(tr("Error"));
        }
}