Beispiel #1
0
void Transfers::addDownloadTransfer(const QString &service, const QString &trackId, const QString &streamId,
                                    const QUrl &streamUrl, const QString &title, const QString &category,
                                    const QString &customCommand, bool customCommandOverrideEnabled) {
    Logger::log(QString("Transfers::addDownloadTransfer(). Service: %1, Track ID: %2, Stream ID: %3, Stream URL: %4, Title: %5, Category: %6, Command: %7").arg(service).arg(trackId).arg(streamId).arg(streamUrl.toString())
                .arg(title).arg(category).arg(customCommand));
    Transfer *transfer = createTransfer(service, this);
    transfer->setNetworkAccessManager(m_nam);
    transfer->setId(Utils::createId());
    transfer->setDownloadPath(Settings::downloadPath() + ".incomplete/" + transfer->id());
    transfer->setFileName(title);
    transfer->setCategory(category);
    transfer->setTrackId(trackId);
    transfer->setStreamId(streamId);
    transfer->setStreamUrl(streamUrl);
    transfer->setTitle(title);
    transfer->setCustomCommand(customCommand);
    transfer->setCustomCommandOverrideEnabled(customCommandOverrideEnabled);
    
    connect(transfer, SIGNAL(statusChanged()), this, SLOT(onTransferStatusChanged()));
    
    m_transfers << transfer;
    emit countChanged(count());
    emit transferAdded(transfer);
    
    if (Settings::startTransfersAutomatically()) {
        transfer->queue();
    }
}
Beispiel #2
0
void TransferManager::addTransfer(Transfer *transfer)
{
    QUuid uuid = transfer->uuid();
    if (_transfers.contains(uuid)) {
        qWarning() << "Cannot add the same file transfer twice!";
        transfer->deleteLater();
        return;
    }
    transfer->setParent(this);
    _transfers[uuid] = transfer;

    SYNC_OTHER(onCoreTransferAdded, ARG(uuid));
    emit transferAdded(uuid);
}
Beispiel #3
0
void Transfers::addEnclosureDownload(const QString &url, const QString &subscriptionId) {
    Logger::log(QString("Transfers::addEnclosureDownload(). URL: %1, Subscription ID: %2").arg(url).arg(subscriptionId),
                Logger::LowVerbosity);
    EnclosureDownload *transfer = new EnclosureDownload(this);
    transfer->setNetworkAccessManager(m_nam);
    transfer->setId(Utils::createId());
    transfer->setDownloadPath(Settings::downloadPath() + ".incomplete/" + transfer->id());
    transfer->setFileName(url.mid(url.lastIndexOf("/") + 1));
    transfer->setName(transfer->fileName());
    transfer->setSubscriptionId(subscriptionId);
    transfer->setUrl(url);
    connect(transfer, SIGNAL(statusChanged()), this, SLOT(onTransferStatusChanged()));
    
    m_transfers << transfer;
    emit countChanged(count());
    emit transferAdded(transfer);
    
    if (Settings::startTransfersAutomatically()) {
        transfer->queue();
    }
}
void DBusTransferGroupObserver::addedTransferEvent(TransferHandler *transfer, TransferHandler *after)
{
    Q_UNUSED(after);
    emit transferAdded(transfer);
}
Beispiel #5
0
// Constructor
MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine)
    :
      QMainWindow(parent),
      m_posInitialized(false),
      force_exit(false),
      icon_TrayConn(res::trayConnected()),
      icon_TrayDisconn(res::trayDisconnected()),
      icon_CurTray(icon_TrayDisconn)
{
    setupUi(this);
    stackedWidget->addWidget(new transfers_widget(this));
    stackedWidget->addWidget(new search_widget(this));
    stackedWidget->addWidget(new preferences_widget(this));
    stackedWidget->setCurrentIndex(0);
    setWindowTitle(tr("qDonkey %1").arg(misc::versionString()));
    QCoreApplication::instance()->installEventFilter(this);

    //QApplication::setOverrideCursor(Qt::WaitCursor);
    m_last_file_error = QDateTime::currentDateTime().addSecs(-1); // imagine last file error event was 1 seconds in past

#ifdef Q_WS_WIN
    m_nTaskbarButtonCreated = RegisterWindowMessage(L"TaskbarButtonCreated");
#else
    m_nTaskbarButtonCreated = 0;
#endif

    Preferences pref;

    // Clean exit on log out
    connect(static_cast<SessionApplication*>(qApp), SIGNAL(sessionIsShuttingDown()), this, SLOT(deleteSession()));

    this->setWindowIcon(QIcon(res::favicon()));

#ifdef Q_WS_MAC
    connect(static_cast<QMacApplication*>(qApp), SIGNAL(newFileOpenMacEvent(QString)), this, SLOT(processParams(QString)));
#endif

    statusBar = new status_bar(this, QMainWindow::statusBar());
    m_pwr = new PowerManagement(this);

    // Configure session according to options
    loadPreferences(false);

    // Start connection checking timer
    guiUpdater = new QTimer(this);
    connect(guiUpdater, SIGNAL(timeout()), this, SLOT(updateGUI()));
    guiUpdater->start(2000);

    // Accept drag 'n drops
    //setAcceptDrops(true);
    createKeyboardShortcuts();

#ifdef Q_WS_MAC
    setUnifiedTitleAndToolBarOnMac(true);
#endif

    // View settings



    // Auto shutdown actions
/*    QActionGroup * autoShutdownGroup = new QActionGroup(this);
    autoShutdownGroup->setExclusive(true);
    autoShutdownGroup->addAction(actionAutoShutdown_Disabled);
    autoShutdownGroup->addAction(actionAutoExit_mule);
    autoShutdownGroup->addAction(actionAutoShutdown_system);
    autoShutdownGroup->addAction(actionAutoSuspend_system);

#if !defined(Q_WS_X11) || defined(QT_DBUS_LIB)
    actionAutoShutdown_system->setChecked(pref.shutdownWhenDownloadsComplete());
    actionAutoSuspend_system->setChecked(pref.suspendWhenDownloadsComplete());
#else
    actionAutoShutdown_system->setDisabled(true);
    actionAutoSuspend_system->setDisabled(true);
#endif

    actionAutoExit_mule->setChecked(pref.shutdownqBTWhenDownloadsComplete());

    if (!autoShutdownGroup->checkedAction())
        actionAutoShutdown_Disabled->setChecked(true);
*/

    readSettings();

    show();
    activateWindow();
    raise();

    // Start watching the executable for updates
    executable_watcher = new QFileSystemWatcher();
    connect(executable_watcher, SIGNAL(fileChanged(QString)), this, SLOT(notifyOfUpdate(QString)));
    executable_watcher->addPath(qApp->applicationFilePath());

    // Add torrent given on command line
    processParams(torrentCmdLine);
#ifdef Q_WS_MAC
    //qt_mac_set_dock_menu(icon_CurTray);
#endif

    // Make sure the Window is visible if we don't have a tray icon
    if (!systrayIcon && isHidden())  {
        show();
        activateWindow();
        raise();
    }

    connect(Session::instance(), SIGNAL(serverNameResolved(QString)), this, SLOT(handleServerNameResolved(QString)));
    connect(Session::instance(), SIGNAL(serverConnectionInitialized(quint32,quint32,quint32)), this, SLOT(handleServerConnectionInitialized(quint32,quint32,quint32)));
    connect(Session::instance(), SIGNAL(serverConnectionClosed(QString)), this, SLOT(handleServerConnectionClosed(QString)));
    connect(Session::instance(), SIGNAL(serverStatus(int,int)), this, SLOT(handleServerStatus(int,int)));
    connect(Session::instance(), SIGNAL(serverMessage(QString)), this, SLOT(handleServerMessage(QString)));
    connect(Session::instance(), SIGNAL(serverIdentity(QString,QString)), this, SLOT(handleServerIdentity(QString,QString)));

    connect(Session::instance(), SIGNAL(transferAdded(QED2KHandle)), SLOT(addedTransfer(QED2KHandle)));
    connect(Session::instance(), SIGNAL(transferFinished(QED2KHandle)), SLOT(finishedTransfer(QED2KHandle)));

    //Tray actions.
    //connect(actionToggleVisibility, SIGNAL(triggered()), this, SLOT(toggleVisibility()));
    //connect(actionStart_All, SIGNAL(triggered()), Session::instance(), SLOT(resumeAllTransfers()));
    //connect(actionPause_All, SIGNAL(triggered()), Session::instance(), SLOT(pauseAllTransfers()));

    actionConnect->trigger();
    Session::instance()->loadDirectory(pref.inputDir());
}
Beispiel #6
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;
        }
    }
}