예제 #1
0
	void TransferApi::loadTransfers() noexcept {
		// add the existing connections
		{
			auto cm = ConnectionManager::getInstance();
			RLock l(cm->getCS());
			for (const auto& d : cm->getTransferConnections(true)) {
				auto info = addTransfer(d, "Inactive, waiting for status updates");
				updateQueueInfo(info);
			}

			for (const auto& u : cm->getTransferConnections(false)) {
				addTransfer(u, "Inactive, waiting for status updates");
			}
		}

		{
			auto um = UploadManager::getInstance();
			RLock l(um->getCS());
			for (const auto& u : um->getUploads()) {
				if (u->getUserConnection().getState() == UserConnection::STATE_RUNNING) {
					on(UploadManagerListener::Starting(), u);
				}
			}
		}

		{
			auto dm = DownloadManager::getInstance();
			RLock l(dm->getCS());
			for (const auto& d : dm->getDownloads()) {
				if (d->getUserConnection().getState() == UserConnection::STATE_RUNNING) {
					starting(d, "Downloading", true);
				}
			}
		}
	}
예제 #2
0
QPair<QED2KHandle, ErrorCode> QED2KSession::addLink(QString strLink, bool resumed /* = false */)
{
    Preferences pref;
    qDebug("Load ED2K link: %s", strLink.toUtf8().constData());

    libed2k::emule_collection_entry ece =
        libed2k::emule_collection::fromLink(libed2k::url_decode(strLink.toUtf8().constData()));
    QED2KHandle h;
    ErrorCode ec;

    if (ece.defined())
    {
        qDebug("Link is correct, add transfer");
        QString filepath = QDir(pref.inputDir()).filePath(
            QString::fromUtf8(ece.m_filename.c_str(), ece.m_filename.size()));
        libed2k::add_transfer_params atp;
        atp.file_hash = ece.m_filehash;
        atp.file_path = filepath.toUtf8().constData();
        atp.file_size = ece.m_filesize;
        atp.duplicate_is_error = true;

        try
        {
            h = addTransfer(atp);
        }
        catch(libed2k::libed2k_exception e)
        {
            ec = e.error();
        }
    }
    else
        ec = "Incorrect link";

    return qMakePair(h, ec);
}
예제 #3
0
QList<Transfer*> TransfersManager::getTransfers()
{
	if (!m_isInitilized)
	{
		QSettings history(SessionsManager::getWritableDataPath(QLatin1String("transfers.ini")), QSettings::IniFormat);
		const QStringList entries = history.childGroups();

		m_transfers.reserve(entries.count());

		for (int i = 0; i < entries.count(); ++i)
		{
			history.beginGroup(entries.at(i));

			if (!history.value(QLatin1String("source")).toString().isEmpty() && !history.value(QLatin1String("target")).toString().isEmpty())
			{
				addTransfer(new Transfer(history, m_instance));
			}

			history.endGroup();
		}

		m_isInitilized = true;

		connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), m_instance, SLOT(save()));
	}

	return m_transfers;
}
예제 #4
0
	void TransferApi::on(ConnectionManagerListener::Added, const ConnectionQueueItem* aCqi) noexcept {
		if (aCqi->getConnType() == CONNECTION_TYPE_PM)
			return;

		auto t = addTransfer(aCqi, STRING(CONNECTING));
		view.onItemAdded(t);
	}
예제 #5
0
Transfer* TransfersManager::startTransfer(QNetworkReply *reply, const QString &target, Transfer::TransferOptions options)
{
	Transfer *transfer = new Transfer(reply, target, options, m_instance);

	if (transfer->getState() == Transfer::CancelledState)
	{
		transfer->deleteLater();

		return NULL;
	}

	addTransfer(transfer);

	return transfer;
}
예제 #6
0
Transfer* TransfersManager::startTransfer(const QUrl &source, const QString &target, Transfer::TransferOptions options)
{
	Transfer *transfer = new Transfer(source, target, options, m_instance);

	if (transfer->getState() == Transfer::CancelledState)
	{
		transfer->deleteLater();

		return NULL;
	}

	addTransfer(transfer);

	return transfer;
}
예제 #7
0
void LinkImporter::checkClipboard(const QString &clipboardContent)
{
    QRegExp rx(REGULAR_EXPRESSION);

    int regexPos = 0;

    while ((regexPos = rx.indexIn(clipboardContent, regexPos)) > -1) {
        QString link = rx.capturedTexts()[0];

        addTransfer(link);

        regexPos += rx.matchedLength();
    }

    emit finished();
}
TransfersContentsWidget::TransfersContentsWidget(Window *window) : ContentsWidget(window),
	m_model(new QStandardItemModel(this)),
	m_isLoading(false),
	m_ui(new Ui::TransfersContentsWidget)
{
	m_ui->setupUi(this);

	QStringList labels;
	labels << QString() << tr("Filename") << tr("Size") << tr("Progress") << tr("Time") << tr("Speed") << tr("Started") << tr("Finished");

	m_model->setHorizontalHeaderLabels(labels);

	m_ui->transfersViewWidget->setModel(m_model);
	m_ui->transfersViewWidget->header()->setTextElideMode(Qt::ElideRight);
	m_ui->transfersViewWidget->header()->resizeSection(0, 30);
	m_ui->transfersViewWidget->header()->setSectionResizeMode(0, QHeaderView::Fixed);
	m_ui->transfersViewWidget->header()->setSectionResizeMode(1, QHeaderView::Stretch);
	m_ui->transfersViewWidget->setItemDelegate(new ItemDelegate(this));
	m_ui->transfersViewWidget->setItemDelegateForColumn(3, new ProgressBarDelegate(this));
	m_ui->transfersViewWidget->installEventFilter(this);
	m_ui->stopResumeButton->setIcon(Utils::getIcon(QLatin1String("task-ongoing")));
	m_ui->redownloadButton->setIcon(Utils::getIcon(QLatin1String("view-refresh")));
	m_ui->downloadLineEdit->installEventFilter(this);

	const QList<Transfer*> transfers = TransfersManager::getTransfers();

	for (int i = 0; i < transfers.count(); ++i)
	{
		addTransfer(transfers.at(i));
	}

	if (!window)
	{
		m_ui->detailsWidget->hide();
	}

	connect(TransfersManager::getInstance(), SIGNAL(transferStarted(Transfer*)), this, SLOT(addTransfer(Transfer*)));
	connect(TransfersManager::getInstance(), SIGNAL(transferRemoved(Transfer*)), this, SLOT(removeTransfer(Transfer*)));
	connect(TransfersManager::getInstance(), SIGNAL(transferChanged(Transfer*)), this, SLOT(updateTransfer(Transfer*)));
	connect(m_model, SIGNAL(modelReset()), this, SLOT(updateActions()));
	connect(m_ui->transfersViewWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openTransfer(QModelIndex)));
	connect(m_ui->transfersViewWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
	connect(m_ui->transfersViewWidget, SIGNAL(needsActionsUpdate()), this, SLOT(updateActions()));
	connect(m_ui->downloadLineEdit, SIGNAL(returnPressed()), this, SLOT(startQuickTransfer()));
	connect(m_ui->stopResumeButton, SIGNAL(clicked()), this, SLOT(stopResumeTransfer()));
	connect(m_ui->redownloadButton, SIGNAL(clicked()), this, SLOT(redownloadTransfer()));
}
void QgsPasteTransformations::restoreTransfers( const QString& sourceLayerName,
    const QString& destinationLayerName )
{
  QgsDebugMsg( "entered." );
  QSettings settings;
  QString baseKey = "/Qgis/paste-transformations";             // TODO: promote to static member

  settings.beginGroup( baseKey );
  QStringList sourceLayers = settings.childGroups();

  for ( QStringList::Iterator it  = sourceLayers.begin();
        it != sourceLayers.end();
        ++it )
  {
    QgsDebugMsg( QString( "testing source '%1' with '%2'." ).arg(( *it ) ).arg( sourceLayerName ) );
    if (( sourceLayerName == ( *it ) ) )
    {
      // Go through destination layers defined for this source layer.
      settings.beginGroup( *it );
      QStringList destinationLayers = settings.childGroups();
      for ( QStringList::Iterator it2  = destinationLayers.begin();
            it2 != destinationLayers.end();
            ++it2 )
      {
        QgsDebugMsg( QString( "testing destination '%1' with '%2'." ).arg(( *it2 ) ).arg( destinationLayerName ) );
        if (( destinationLayerName == ( *it2 ) ) )
        {
          QgsDebugMsg( "going through transfers." );
          // Go through Transfers for this source/destination layer pair.
          settings.beginGroup( *it2 );
          QStringList transfers = settings.childKeys();
          for ( QStringList::Iterator it3  = transfers.begin();
                it3 != transfers.end();
                ++it3 )
          {
            QgsDebugMsg( QString( "setting transfer for %1." ).arg(( *it3 ) ) );
            QString destinationField = settings.value( *it3 ).toString();
            addTransfer(( *it3 ), destinationField );
          }
          settings.endGroup();
        }
      }
      settings.endGroup();
    }
  }
  settings.endGroup();
}
예제 #10
0
void FileTransferManager::sendFile(UinType receiver, const QString &filename)
{
	kdebugf();

	FileTransfer *ft = search(FileTransfer::TypeSend, receiver, filename);

	if (!ft)
	{
		ft = new FileTransfer(this, DccUnknow, FileTransfer::TypeSend, receiver, filename);
		addTransfer(ft);
	}

	if (!fileTransferWindow)
		toggleFileTransferWindow(0, false);

	ft->start();

	kdebugf2();
}
예제 #11
0
void QED2KSession::addTransferFromFile(const QString& filename)
{
    if (QFile::exists(filename))
    {
        Preferences pref;
        libed2k::emule_collection ecoll = libed2k::emule_collection::fromFile(
            filename.toLocal8Bit().constData());

        foreach(const libed2k::emule_collection_entry& ece, ecoll.m_files)
        {
            QString filepath = QDir(pref.inputDir()).filePath(
                QString::fromUtf8(ece.m_filename.c_str(), ece.m_filename.size()));
            qDebug() << "add transfer " << filepath;
            libed2k::add_transfer_params atp;
            atp.file_hash = ece.m_filehash;
            atp.file_path = filepath.toUtf8().constData();
            atp.file_size = ece.m_filesize;
            addTransfer(atp);
        }
    }
}
예제 #12
0
/** Add a TransferVisual to the transfer list
  *
  * We need the filesize. If the file is sent to the server (STOR command)
  * it is get from a FSIZE telnet command.
  *
  * \param ip The client IP address
  * \param port The client port
  * \param filename The filename to transfer
  * \param commingIn Is the file comming in ?
  * \param filesize The size of the file
  *
  */
RainbruRPG::Network::Ftp::TransferVisual* 
RainbruRPG::Network::Ftp::FtpServer::
addTransferVisual(const QString& ip,const QString& port, 
		  const QString& filename, 
		  bool commingIn, int filesize){

  LOGI("FtpServer::addTransferVisual called");
  LOGCATS("Filesize is  :");
  LOGCATI(filesize);
  LOGCAT();

  TransferVisual* tv2=new TransferVisual(tree);
  tv2->setIp(ip);
  tv2->setPort(port);
  tv2->setFilename(filename, "");
  tv2->setFileSize(filesize);
  tv2->setCommingIn(commingIn);
  addTransfer(tv2);

  transfer->registerVisual(ip, port, tv2);

  return tv2;
}
예제 #13
0
void LinkImporter::slotReadFile(const QUrl &url)
{
    QRegExp rx(REGULAR_EXPRESSION);
    QFile file(url.toLocalFile());

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    QTextStream in(&file);
    quint64 size = file.size();
    quint64 position = 0;

    while (!in.atEnd()) {
        QString line = in.readLine();
        int regexPos = 0;
        quint64 lastPosition = position;

        while ((regexPos = rx.indexIn(line, regexPos)) > -1) {
            QString link = rx.capturedTexts()[0];

            addTransfer(link);

            regexPos += rx.matchedLength();
            position = lastPosition + regexPos;

            emit progress(position * 100 / size);
        }

        position += line.size();

        emit progress(position * 100 / size);
    }

    if(!m_url.isLocalFile()) {
        file.remove();
    }
}
void QgsPasteTransformations::addNewTransfer()
{
  // This ends up being a wrapper for addTransfer, but with no preselected fields
  addTransfer();
}
예제 #15
0
void QED2KSession::readAlerts()
{
    std::auto_ptr<libed2k::alert> a = m_session->pop_alert();

    while (a.get())
    {
        if (libed2k::server_name_resolved_alert* p =
            dynamic_cast<libed2k::server_name_resolved_alert*>(a.get()))
        {
            emit serverNameResolved(QString::fromUtf8(p->endpoint.c_str(), p->endpoint.size()));
        }
        if (libed2k::server_connection_initialized_alert* p =
            dynamic_cast<libed2k::server_connection_initialized_alert*>(a.get()))
        {
            emit serverConnectionInitialized(p->client_id, p->tcp_flags, p->aux_port);
            qDebug() << "server initialized: " << QString::fromStdString(p->name) << " " << QString::fromStdString(p->host) << " " << p->port;
        }
        else if (libed2k::server_status_alert* p = dynamic_cast<libed2k::server_status_alert*>(a.get()))
        {
            emit serverStatus(p->files_count, p->users_count);
        }
        else if (libed2k::server_identity_alert* p = dynamic_cast<libed2k::server_identity_alert*>(a.get()))
        {
            emit serverIdentity(QString::fromUtf8(p->server_name.c_str(), p->server_name.size()),
                                QString::fromUtf8(p->server_descr.c_str(), p->server_descr.size()));
        }
        else if (libed2k::server_message_alert* p = dynamic_cast<libed2k::server_message_alert*>(a.get()))
        {
            emit serverMessage(QString::fromUtf8(p->server_message.c_str(), p->server_message.size()));
        }
        else if (libed2k::server_connection_closed* p =
                 dynamic_cast<libed2k::server_connection_closed*>(a.get()))
        {
            emit serverConnectionClosed(QString::fromLocal8Bit(p->m_error.message().c_str()));
        }
        else if (libed2k::shared_files_alert* p = dynamic_cast<libed2k::shared_files_alert*>(a.get()))
        {
            QList<QED2KSearchResultEntry> vRes;
            vRes.reserve(p->m_files.m_collection.size());
            bool bMoreResult = p->m_more;

            for (size_t n = 0; n < p->m_files.m_collection.size(); ++n)
            {
                QED2KSearchResultEntry sre = QED2KSearchResultEntry::fromSharedFileEntry(p->m_files.m_collection[n]);
                if (sre.isCorrect()) vRes.push_back(sre);
            }

            // emit special signal for derived class
            if (libed2k::shared_directory_files_alert* p2 =
                dynamic_cast<libed2k::shared_directory_files_alert*>(p))
            {
                emit peerSharedDirectoryFiles(
                    p2->m_np, md4toQString(p2->m_hash),
                    QString::fromUtf8(p2->m_strDirectory.c_str(), p2->m_strDirectory.size()), vRes);
            }
            else if (libed2k::ismod_shared_directory_files_alert* p2 =
                     dynamic_cast<libed2k::ismod_shared_directory_files_alert*>(p))
            {
                emit peerIsModSharedFiles(p2->m_np, md4toQString(p2->m_hash), md4toQString(p2->m_dir_hash), vRes);
            }
            else
            {
                emit searchResult(p->m_np, md4toQString(p->m_hash), vRes, bMoreResult);
            }
        }
        else if (libed2k::listen_failed_alert* p = dynamic_cast<libed2k::listen_failed_alert*>(a.get()))
        {
            Q_UNUSED(p)
            // TODO - process signal - it means we have different client on same port
        }
        else if (libed2k::peer_connected_alert* p = dynamic_cast<libed2k::peer_connected_alert*>(a.get()))
        {
            emit peerConnected(p->m_np, md4toQString(p->m_hash), p->m_active);
        }
        else if (libed2k::peer_disconnected_alert* p = dynamic_cast<libed2k::peer_disconnected_alert*>(a.get()))
        {
            emit peerDisconnected(p->m_np, md4toQString(p->m_hash), p->m_ec);
        }
        else if (libed2k::peer_message_alert* p = dynamic_cast<libed2k::peer_message_alert*>(a.get()))
        {
            emit peerMessage(p->m_np, md4toQString(p->m_hash),
                             QString::fromUtf8(p->m_strMessage.c_str(), p->m_strMessage.size()));
        }
        else if (libed2k::peer_captcha_request_alert* p =
                 dynamic_cast<libed2k::peer_captcha_request_alert*>(a.get()))
        {
            QPixmap pm;
            if (!p->m_captcha.empty()) pm.loadFromData((const uchar*)&p->m_captcha[0], p->m_captcha.size()); // avoid windows rtl error
            emit peerCaptchaRequest(p->m_np, md4toQString(p->m_hash), pm);
        }
        else if (libed2k::peer_captcha_result_alert* p =
                 dynamic_cast<libed2k::peer_captcha_result_alert*>(a.get()))
        {
            emit peerCaptchaResult(p->m_np, md4toQString(p->m_hash), p->m_nResult);
        }
        else if (libed2k::shared_files_access_denied* p =
                 dynamic_cast<libed2k::shared_files_access_denied*>(a.get()))
        {
            emit peerSharedFilesAccessDenied(p->m_np, md4toQString(p->m_hash));
        }
        else if (libed2k::shared_directories_alert* p = dynamic_cast<libed2k::shared_directories_alert*>(a.get()))
        {
            QStringList qstrl;

            for (size_t n = 0; n < p->m_dirs.size(); ++n)
            {
                qstrl.append(QString::fromUtf8(p->m_dirs[n].c_str(), p->m_dirs[n].size()));
            }

            emit peerSharedDirectories(p->m_np, md4toQString(p->m_hash), qstrl);
        }
        else if (libed2k::added_transfer_alert* p =
                 dynamic_cast<libed2k::added_transfer_alert*>(a.get()))
        {
            QED2KHandle h(p->m_handle);
            if (!h.is_seed()) m_currentSessionTransfers.insert(h.hash());

            if (!m_addTimes.contains(h.hash())) {
                m_addTimes.insert(h.hash(), QDateTime::currentDateTime());
            }

            if (m_sharedFiles.contains(h.hash())) {
                emit transferShared(h);
            } else {
                emit transferAdded(QED2KHandle(h));
            }
        }
        else if (libed2k::paused_transfer_alert* p =
                 dynamic_cast<libed2k::paused_transfer_alert*>(a.get()))
        {
            emit transferPaused(QED2KHandle(p->m_handle));
        }
        else if (libed2k::resumed_transfer_alert* p =
                 dynamic_cast<libed2k::resumed_transfer_alert*>(a.get()))
        {
            emit transferResumed(QED2KHandle(p->m_handle));
        }
        else if (libed2k::deleted_transfer_alert* p =
                 dynamic_cast<libed2k::deleted_transfer_alert*>(a.get()))
        {            
            emit transferDeleted(QString::fromStdString(p->m_hash.toString()));
        }
        else if (libed2k::finished_transfer_alert* p =
                 dynamic_cast<libed2k::finished_transfer_alert*>(a.get()))
        {
            QED2KHandle h(p->m_handle);

            if (m_sharedFiles.contains(h.hash())) {
                emit transferRestored(h);
            } else {
                emit transferFinished(h);
            }
        }
        else if (libed2k::save_resume_data_alert* p = dynamic_cast<libed2k::save_resume_data_alert*>(a.get()))
        {
            Preferences pref;
            QED2KHandle h(p->m_handle);
            QDateTime t;
            writeResumeData(p, misc::metadataDirectory(pref.inputDir()), QFile::exists(h.filepath()), m_addTimes.value(h.hash(), t));
        }
        else if (libed2k::transfer_params_alert* p = dynamic_cast<libed2k::transfer_params_alert*>(a.get()))
        {
            QFileInfo info(misc::toQStringU(p->m_atp.file_path));
            if (info.absoluteDir() == QDir(m_currentPath)) {
                emit transferParametersReady(p->m_atp, p->m_ec);
                if (!p->m_ec) m_sharedFiles << addTransfer(p->m_atp).hash();
                else qDebug() << "transfer params error: " << misc::toQStringU(p->m_ec.message());
            } else {
                qDebug() << "ignore add transfer parameters for old directory: " << misc::toQStringU(p->m_atp.file_path);
            }
        }
        else if (libed2k::file_renamed_alert* p = dynamic_cast<libed2k::file_renamed_alert*>(a.get()))
        {
            emit transferSavePathChanged(QED2KHandle(p->m_handle));
        }
        else if (libed2k::storage_moved_alert* p = dynamic_cast<libed2k::storage_moved_alert*>(a.get()))
        {
            emit transferStorageMoved(QED2KHandle(p->m_handle));
        }
        else if (libed2k::file_error_alert* p = dynamic_cast<libed2k::file_error_alert*>(a.get()))
        {
            QED2KHandle h(p->m_handle);
            if (h.is_valid()) {
                emit fileError(h, QString::fromLocal8Bit(p->error.message().c_str(), p->error.message().size()));
                h.pause();
            }
        }
        else if (libed2k::portmap_error_alert* p = dynamic_cast<libed2k::portmap_error_alert*>(a.get()))
        {
            qDebug("UPnP Failure, msg: %s", p->message().c_str());
            //addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1")
            //                  .arg(misc::toQString(p->message())), "red");
        }
        else if (libed2k::portmap_alert* p = dynamic_cast<libed2k::portmap_alert*>(a.get()))
        {
            qDebug("UPnP Success, msg: %s", p->message().c_str());
            //addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1")
            //                  .arg(misc::toQString(p->message())), "blue");
        }

        a = m_session->pop_alert();
    }

    // deferred transfers loading and files sharing
    if (!m_fastTransfers.empty()) {
        QList<QString> keys = m_fastTransfers.keys();
        int counter = 10;

        while(!keys.empty() && counter != 0 ) {
            QString key = keys.takeFirst();
            libed2k::transfer_resume_data trd = m_fastTransfers.take(key);
            libed2k::add_transfer_params atp;
            QString filepath = QDir(m_currentPath).filePath(misc::toQStringU(trd.m_filename.m_collection));
            boost::shared_ptr<libed2k::base_tag> onDisk = trd.m_fast_resume_data.getTagByNameId(libed2k::CT_EMULE_RESERVED1);

            Q_ASSERT(onDisk);

            if (QFile::exists(filepath) || !onDisk->asBool()) {
                atp.seed_mode = false;
                // make full path for transfer startup
                atp.file_path = filepath.toUtf8().constData();
                atp.file_size = trd.m_filesize;
                atp.file_hash = trd.m_hash;

                if (trd.m_fast_resume_data.count() > 0) {
                    atp.resume_data = const_cast<std::vector<char>* >(
                        &trd.m_fast_resume_data.getTagByNameId(libed2k::FT_FAST_RESUME_DATA)->asBlob());
                }

                QED2KHandle h = addTransfer(atp);
                m_sharedFiles << h.hash();
                boost::shared_ptr<libed2k::base_tag> addDt = trd.m_fast_resume_data.getTagByNameId(libed2k::CT_EMULE_RESERVED2);

                if (addDt) {
                    m_addTimes.insert(h.hash(), QDateTime::fromString(misc::toQStringU(addDt->asString()), Qt::ISODate));
                }
            } else {
                qDebug() << "fast resume data file" << key << " lost target file, remove resume data";
                if (QFile::remove(QDir(misc::metadataDirectory(m_currentPath)).filePath(key))) {
                    qDebug() << "fast resume data file erased";
                }
            }

            --counter;
        }
    } else {
        int counter = 4;
        while(!m_pendingFiles.empty() && counter != 0) {
            makeTransferParametersAsync(m_pendingFiles.takeFirst());
            --counter;
        }
    }
}
예제 #16
0
void ClientTransferManager::onTransferInitDone()
{
    Transfer *transfer = qobject_cast<Transfer *>(sender());
    Q_ASSERT(transfer);
    addTransfer(transfer);
}
Kopete::Transfer* Kopete::TransferManager::addTransfer( Kopete::Contact *contact, const QString& file, const unsigned long size, const QString &recipient, Kopete::FileTransferInfo::KopeteTransferDirection di)
{
	return addTransfer( contact, QStringList(file), size, recipient, di );
}