Ejemplo n.º 1
0
void DownloadItem::requestFinished() {
    if (!m_startedSaving) {
        qDebug() << "Request finished but never started saving";
        tryAgain();
        return;
    }

    if (m_bytesReceived <= 0) {
        qDebug() << "Request finished but saved 0 bytes";
        tryAgain();
        return;
    }

    m_finishedDownloading = true;

    if (m_status == Starting) {
        m_status = Downloading;
        emit statusChanged();
    }
    m_file.close();
    m_status = Finished;
    m_totalTime = m_downloadTime.elapsed() / 1000.0;
    emit statusChanged();
    emit finished();
    m_reply->deleteLater();
    m_reply = 0;
}
Ejemplo n.º 2
0
/*!
    DownloadItem is a widget that is displayed in the download manager list.
    It moves the data from the QNetworkReply into the QFile as well
    as update the information/progressbar and report errors.
 */
DownloadItem::DownloadItem(QNetworkReply *reply, bool requestFileName, QWidget *parent)
    : QWidget(parent)
    , m_reply(reply)
    , m_requestFileName(requestFileName)
    , m_bytesReceived(0)
    , m_gettingFileName(false)
{
    setupUi(this);
    QPalette p = downloadInfoLabel->palette();
    p.setColor(QPalette::Text, Qt::darkGray);
    downloadInfoLabel->setPalette(p);
    progressBar->setMaximum(0);
    tryAgainButton->hide();
    connect(stopButton, SIGNAL(clicked()), this, SLOT(stop()));
    connect(openButton, SIGNAL(clicked()), this, SLOT(open()));
    connect(tryAgainButton, SIGNAL(clicked()), this, SLOT(tryAgain()));

    if (!requestFileName) {
        QSettings settings;
        settings.beginGroup(QLatin1String("downloadmanager"));
        m_requestFileName = settings.value(QLatin1String("alwaysPromptForFileName"), false).toBool();
    }

    init();
}
Ejemplo n.º 3
0
/*!
    DownloadItem is a widget that is displayed in the download manager list.
    It moves the data from the QNetworkReply into the QFile as well
    as update the information/progressbar and report errors.
 */
DownloadItem::DownloadItem(QNetworkReply *reply, bool requestFileName, QWidget *parent)
    : QWidget(parent)
    , m_reply(reply)
    , m_to_delete(false)
    , m_requestFileName(requestFileName)
    , m_bytesReceived(0)
    , m_finished(false)
{
    setupUi(this);
    QPalette p = downloadInfoLabel->palette();
    p.setColor(QPalette::Text, Qt::darkGray);
    downloadInfoLabel->setPalette(p);
    progressBar->setMaximum(0);
    tryAgainButton->hide();
    stopButton->setIcon(style()->standardIcon(QStyle::SP_BrowserStop));
    tryAgainButton->setIcon(style()->standardIcon(QStyle::SP_BrowserReload));

    connect(stopButton, SIGNAL(clicked()), this, SLOT(stop()));
    connect(openButton, SIGNAL(clicked()), this, SLOT(open()));
    connect(tryAgainButton, SIGNAL(clicked()), this, SLOT(tryAgain()));
    connect(deleteButton, SIGNAL(clicked()), this, SLOT(remove()));
    
    m_success_init = false;
    m_must_be_deleted = true;

    if (!requestFileName) {
        QSettings settings;
        settings.beginGroup(QLatin1String("downloadmanager"));
        m_requestFileName = settings.value(QLatin1String("askForFileName"), false).toBool();
    }

    init();
}
    virtual void startClient(const QStringList &mechlist, bool allowClientSendFirst) {
        Q_UNUSED(allowClientSendFirst);

        mechanism_ = QString();
        foreach(QString mech, mechlist) {
            if (mech == "DIGEST-MD5") {
                mechanism_ = "DIGEST-MD5";
                break;
            }
#ifdef SIMPLESASL_PLAIN
            if (mech == "PLAIN" && allow_plain)
                mechanism_ = "PLAIN";
#endif
        }

        if(!capable || mechanism_.isEmpty()) {
            authCondition_ = QCA::SASL::NoMechanism;
            result_ = Error;
            if (!capable)
                qWarning("simplesasl.cpp: Not enough capabilities");
            if (mechanism_.isEmpty())
                qWarning("simplesasl.cpp: No mechanism available");
            QMetaObject::invokeMethod(this, "resultsReady", Qt::QueuedConnection);
            return;
        }

        resetState();
        result_ = Continue;
        step = 0;
        tryAgain();
    }
Ejemplo n.º 5
0
void
Handshake::success( QByteArray data )
{
    Q_DEBUG_BLOCK << data;

    QString const result( data );

    LOGL( 3, "Handshake response:\n" << result );

    m_session = parameter( "session", result );
    m_baseHost = parameter( "base_url", result );
    m_basePath = parameter( "base_path", result );
    m_streamUrl.setUrl( parameter( "stream_url", result ) );
    m_isSubscriber = parameter( "subscriber", result ) == "1";
    m_message = parameter( "info_message", result );
    m_permitBootstrap = parameter( "permit_bootstrap", result ) == "1";
    bool const is_banned = parameter( "banned", result ) == "1";
    m_fingerprintUploadUrl = parameter( "fingerprint_upload_url", result );
    m_freeTrial = parameter( "freetrial", result ).toInt();

    if ( m_session.toLower() == "failed" )
    {
        LOGL( 1, "Radio handshake failed: session == 'failed'" );

        QString msg = parameter( "msg", result ).toLower();

        if ( msg == "no such user" || msg == "padd md5 not 32 len" )
            setFailed( Request_WrongUserNameOrPassword );
        else
            setFailed( Handshake_SessionFailed,
                tr("Could not connect to server.") );
    }
    else if ( is_banned )
    {
        LOGL( 1, "Client version is banned" );

        setFailed( Handshake_Banned,
           tr( "This client version is obsolete. Please update." ) );
    }
    else if ( m_session.isEmpty() ||
              m_baseHost.isEmpty() || 
              m_basePath.isEmpty() ||
              m_streamUrl.isEmpty() )
    {
        setFailed( Handshake_SessionFailed, tr("Could not connect to server.") );
    }
    else if ( m_session.length() != 32 )
    {
        LOGL( 1, "Radio handshake failed: session length not 32 bytes. Retrying." );
        tryAgain();
    }
    else
    {
        Request::setBaseHost( m_baseHost );

        LOGL( 3, "Radio handshake successful. Host: " << m_baseHost << ", path: " << m_basePath );
    }
}
Ejemplo n.º 6
0
void PolkitListener::finishObtainPrivilege(){
    // Number of tries increase only when some user is selected
#ifdef LIBPOLKIT_QT_1_1
    if(selectedUser.isValid()){
#else
    if(selectedUser!=0){
#endif // LIBPOLKIT_QT
        numTries++;
    }
    syslog(LOG_DEBUG,"Finishing obtaining privileges (G:%u, C:%u, D:%u).",gainedAuthorization,wasCancelled,(dialog!=NULL));
    if(!gainedAuthorization&&!wasCancelled&&(dialog!=NULL)){
        dialog->authenticationFailure();
        if(numTries<3){
            session.data()->deleteLater();
            tryAgain();
            return;
        }
    }
    if(!session.isNull()){
        session.data()->result()->setCompleted();
    }
    else{
        result->setCompleted();
    }
#ifdef LIBPOLKIT_QT_1_1
    session.data()->deleteLater();
#endif // LIBPOLKIT_QT
    if(dialog){
        delete(dialog);
        dialog=NULL;
    }
    inProgress=false;
    syslog(LOG_DEBUG,"Finish obtain authorization: %u",gainedAuthorization);
}

void PolkitListener::tryAgain(){
    syslog(LOG_DEBUG,"Trying again.");
    // We will create a new session only when some user is selected
#ifdef LIBPOLKIT_QT_1_1
    if(selectedUser.isValid()){
        session=new Session(selectedUser,cookie,result);
        connect(session.data(),SIGNAL(request(QString,bool)),this,SLOT(request(QString,bool)));
        connect(session.data(),SIGNAL(completed(bool)),this,SLOT(completed(bool)));
        connect(session.data(),SIGNAL(showError(QString)),this,SLOT(showError(QString)));
        session.data()->initiate();
#else
    if(selectedUser!=0){
        session=new Session(selectedUser,cookie,result);
        connect(session,SIGNAL(request(QString,bool)),this,SLOT(request(QString,bool)));
        connect(session,SIGNAL(completed(bool)),this,SLOT(completed(bool)));
        connect(session,SIGNAL(showError(QString)),this,SLOT(showError(QString)));
        session->initiate();
#endif // LIBPOLKIT_QT
    }
Ejemplo n.º 7
0
	virtual void startClient(const QStringList &mechlist, bool) {
		if (!mechlist.contains(QLatin1String("X-OAUTH2"))) {
			qWarning("No X-OAUTH2 auth method");
			authCondition_ = QCA::SASL::NoMechanism;
			QMetaObject::invokeMethod(this, "resultsReady", Qt::QueuedConnection);
			return;
		}
		authCondition_ = QCA::SASL::AuthFail;
		result_ = QCA::SASLContext::Continue;
		data.clear();
		tryAgain();
	}
Ejemplo n.º 8
0
void DownloadItem::metaDataChanged() {
    if (!m_reply) return;
    QVariant locationHeader = m_reply->header(QNetworkRequest::LocationHeader);
    if (locationHeader.isValid()) {
        m_url = locationHeader.toUrl();
        qDebug() << "Redirecting to" << m_url;
        tryAgain();
        return;
    }

#ifdef DOWNLOADMANAGER_DEBUG
    qDebug() << "DownloadItem::" << __FUNCTION__ << "not handled.";
#endif
}
Ejemplo n.º 9
0
/*!
    DownloadItem is a widget that is displayed in the download manager list.
    It moves the data from the QNetworkReply into the QFile as well
    as update the information/progressbar and report errors.
 */
DownloadItem::DownloadItem(QNetworkReply *reply, bool requestFileName, QWidget *parent)
    : QWidget(parent)
    , m_reply(reply)
    , m_requestFileName(requestFileName)
    , m_bytesReceived(0)
{
    setupUi(this);
    QPalette p = downloadInfoLabel->palette();
    p.setColor(QPalette::Text, Qt::darkGray);
    downloadInfoLabel->setPalette(p);
    progressBar->setMaximum(0);
    tryAgainButton->hide();
    connect(stopButton, SIGNAL(clicked()), this, SLOT(stop()));
    connect(openButton, SIGNAL(clicked()), this, SLOT(open()));
    connect(tryAgainButton, SIGNAL(clicked()), this, SLOT(tryAgain()));

    init();
}
Ejemplo n.º 10
0
int main()
{

    int n, ok;                  /* Saisie et vérification de saisie */
    char again = 'n';           /* Vérification pour recommencer */

    do
    {
        system("cls");
        do
        {
            printf("Saississez le nombre de termes de Fibonacci a calculer : ");
            ok = scanf("%d",&n);
            while(getchar() != '\n');
        }
        while (!ok || n < 0);

        printf("\n");
        calculFibo(n);          /* Appel de la procédure */
        again = tryAgain();     /* Appel de la fonction pour recommencer */
    }
    while (again == 'o');
    return 0;
}
Ejemplo n.º 11
0
	int nextStep(const QByteArray &in)
	{
		in_buf = in;
		return tryAgain();
	}
 virtual void nextStep(const QByteArray &from_net) {
     in_buf = from_net;
     tryAgain();
 }
Ejemplo n.º 13
0
void PolkitListener::initiateAuthentication(
        const QString &actionId,
        const QString &message,
        const QString &iconName,
        const PolkitQt1::Details &details,
        const QString &cookie,
        const PolkitQt1::Identity::List &identities,
        PolkitQt1::Agent::AsyncResult* result){
#else
void PolkitListener::initiateAuthentication(
        const QString &actionId,
        const QString &message,
        const QString &iconName,
        PolkitQt1::Details *details,
        const QString &cookie,
        QList<PolkitQt1::Identity *> identities,
        PolkitQt1::Agent::AsyncResult* result){
#endif // LIBPOLKIT_QT
    syslog(LOG_DEBUG,"Initiating authentication");
    if(inProgress){
        syslog(LOG_ERR,"Another client is already authenticating, please try again later.");
        result->setError("Another client is already authenticating, please try again later.");
        result->setCompleted();
        return;
    }
    this->identities=identities;
    this->cookie=cookie;
    this->result=result;
#ifdef LIBPOLKIT_QT_1_1
    session.clear();
#else
    session=0;
#endif // LIBPOLKIT_QT
    if(identities.length()==1){
        this->selectedUser=identities[0];
    }
    else{
#ifdef LIBPOLKIT_QT_1_1
        selectedUser=PolkitQt1::Identity();
#else
        selectedUser=0;
#endif // LIBPOLKIT_QT
    }

    inProgress=true;
    // Create the polkit dialog
    dialog=new PolkitDialogImpl(actionId,message,iconName,details,identities);
    connect(dialog->okButton,SIGNAL(clicked()),this,SLOT(dialogAccepted()));
    connect(dialog->passwordEdit,SIGNAL(returnPressed()),this,SLOT(dialogAccepted()));
    connect(dialog->cancelButton,SIGNAL(clicked()),this,SLOT(dialogCanceled()));
    connect(dialog,SIGNAL(rejected()),this,SLOT(dialogCanceled()));
#ifdef LIBPOLKIT_QT_1_1
    connect(dialog,SIGNAL(adminUserSelected(PolkitQt1::Identity)),SLOT(userSelected(PolkitQt1::Identity)));
#else
    connect(dialog,SIGNAL(adminUserSelected(PolkitQt1::Identity *)),SLOT(userSelected(PolkitQt1::Identity *)));
#endif // LIBPOLKIT_QT

    dialog->setOptions();
    dialog->show();
    dialog->raise();
    numTries=0;
    wasCancelled=false;
    if(!dialog->preselectUser()){
        tryAgain();
    }
}
Ejemplo n.º 14
0
	virtual void nextStep(const QByteArray &) {
		tryAgain();
	}