void AddNewTorrentDialog::show(QString source, QWidget *parent)
{
    AddNewTorrentDialog *dlg = new AddNewTorrentDialog(parent);

    if (Utils::Misc::isUrl(source)) {
        // Launch downloader
        Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true);
        connect(handler, SIGNAL(downloadFinished(QString, QString)), dlg, SLOT(handleDownloadFinished(QString, QString)));
        connect(handler, SIGNAL(downloadFailed(QString, QString)), dlg, SLOT(handleDownloadFailed(QString, QString)));
        connect(handler, SIGNAL(redirectedToMagnet(QString, QString)), dlg, SLOT(handleRedirectedToMagnet(QString, QString)));
    }
    else {
        bool ok = false;
        BitTorrent::MagnetUri magnetUri(source);
        if (magnetUri.isValid())
            ok = dlg->loadMagnet(magnetUri);
        else
            ok = dlg->loadTorrent(source);

        if (ok)
            dlg->open();
        else
            delete dlg;
    }
}
void AddNewTorrentDialog::show(QString source, QWidget *parent)
{
    if (source.startsWith("bc://bt/", Qt::CaseInsensitive)) {
        qDebug("Converting bc link to magnet link");
        source = Utils::Misc::bcLinkToMagnet(source);
    }

    AddNewTorrentDialog *dlg = new AddNewTorrentDialog(parent);

    if (Utils::Misc::isUrl(source)) {
        // Launch downloader
        Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true);
        connect(handler, SIGNAL(downloadFinished(QString, QString)), dlg, SLOT(handleDownloadFinished(QString, QString)));
        connect(handler, SIGNAL(downloadFailed(QString, QString)), dlg, SLOT(handleDownloadFailed(QString, QString)));
        connect(handler, SIGNAL(redirectedToMagnet(QString, QString)), dlg, SLOT(handleRedirectedToMagnet(QString, QString)));
    }
    else {
        bool ok = false;
        if (source.startsWith("magnet:", Qt::CaseInsensitive))
            ok = dlg->loadMagnet(source);
        else
            ok = dlg->loadTorrent(source);

        if (ok)
            dlg->open();
        else
            delete dlg;
    }
}
void Helper::readCommand()
    {
    QString command = readLine();
    if( input.atEnd())
        {
#ifdef DEBUG_KDE
        QTextStream( stderr ) << "EOF, existing." << endl;
#endif
        QCoreApplication::exit();
        return;
        }
#ifdef DEBUG_KDE
    QTextStream( stderr ) << "COMMAND:" << command << endl;
#endif
    bool status;
    if( command == "CHECK" )
        status = handleCheck();
    else if( command == "GETPROXY" )
        status = handleGetProxy();
    else if( command == "HANDLEREXISTS" )
        status = handleHandlerExists();
    else if( command == "GETFROMEXTENSION" )
        status = handleGetFromExtension();
    else if( command == "GETFROMTYPE" )
        status = handleGetFromType();
    else if( command == "GETAPPDESCFORSCHEME" )
        status = handleGetAppDescForScheme();
    else if( command == "APPSDIALOG" )
        status = handleAppsDialog();
    else if( command == "GETOPENFILENAME" )
        status = handleGetOpenX( false );
    else if( command == "GETOPENURL" )
        status = handleGetOpenX( true );
    else if( command == "GETSAVEFILENAME" )
        status = handleGetSaveX( false );
    else if( command == "GETSAVEURL" )
        status = handleGetSaveX( true );
    else if( command == "GETDIRECTORYFILENAME" )
        status = handleGetDirectoryX( false );
    else if( command == "GETDIRECTORYURL" )
        status = handleGetDirectoryX( true );
    else if( command == "OPEN" )
        status = handleOpen();
    else if( command == "REVEAL" )
        status = handleReveal();
    else if( command == "RUN" )
        status = handleRun();
    else if( command == "GETDEFAULTFEEDREADER" )
        status = handleGetDefaultFeedReader();
    else if( command == "OPENMAIL" )
        status = handleOpenMail();
    else if( command == "OPENNEWS" )
        status = handleOpenNews();
    else if( command == "ISDEFAULTBROWSER" )
        status = handleIsDefaultBrowser();
    else if( command == "SETDEFAULTBROWSER" )
        status = handleSetDefaultBrowser();
    else if( command == "DOWNLOADFINISHED" )
        status = handleDownloadFinished();
    else
        {
        QTextStream( stderr ) << "Unknown command for KDE helper: " << command << endl;
        status = false;
        }
    // status done as \1 (==ok) and \0 (==not ok), because otherwise this cannot happen
    // in normal data (\ is escaped otherwise)
    outputLine( status ? "\\1" : "\\0", false ); // do not escape
    }