IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Discussion :

Passage de paramètres et résultat

  1. #1
    Membre habitué
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2011
    Messages : 316
    Points : 126
    Points
    126
    Par défaut Passage de paramètres et résultat
    Bonjour,

    fiere de cette nouvelle fonction (unzip), je l'ai presque immediatement intégré dans mon programme mais voila :

    le dossier utilisateur etant defini dans un QSetting

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    QDir::setCurrent(MyAppDirPath);
        MyAppDirPath =  QCoreApplication::applicationDirPath(); // recupere le chemin du programme
        ficheZip = MyAppDirPath + "/" + utilisateur + "/Zip/"+ fiche + ".zip";
        ficheExtract = MyAppDirPath + "/" + utilisateur;
        UnZip(ficheZip, ficheExtract);
        
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    //connect(unzipButton, SIGNAL(clicked()), this, SLOT(UnZip(ficheZip, ficheExtract)));
    void HttpWindow::UnZip (QString ficheZip , QString ficheExtract) { JlCompress::extractDir(ficheZip,ficheExtract); }
    mon premier probleme :

    si j'execute en mode debug
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    UnZip(ficheZip, ficheExtract);
    j'arrive bien dans :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    JlCompress::extractDir(ficheZip,ficheExtract);
    le fichier et le chemin de destination étant bien les bons, il ne me decompresse pas les fichiers !!!!

    le deuxieme, c'est que normalement, je voudrais faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    connect(unzipButton, SIGNAL(clicked()), this, SLOT(UnZip(ficheZip, ficheExtract)));
    et là par contre je ne me connecte pas a
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    JlCompress::extractDir(ficheZip,ficheExtract);
    pourquoi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SLOT(UnZip(ficheZip, ficheExtract)
    ne fonctionne pas?

    Cordialement

  2. #2
    Membre averti

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 184
    Points : 322
    Points
    322
    Par défaut
    Les signaux et les slots doivent avoir la même signature (ie les mêmes types de paramètres). Les slots peuvent avoir moins de paramètres que les signaux mais l'inverse ne fonctionne pas (ie un signal avec moins de paramètres que le slot).

  3. #3
    Membre habitué
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2011
    Messages : 316
    Points : 126
    Points
    126
    Par défaut
    bonsoir,


    Je peux bypasser cela en mettant une variable a la place auquel j'affecte UnZip(ficheZip, ficheExtract) ?

    Par contre, l'execution du sous programme directement avec les 2 parametres devrait normalement fonctionner. pourquoi cela ne marche pas?

    cordialement

  4. #4
    Membre habitué
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2011
    Messages : 316
    Points : 126
    Points
    126
    Par défaut
    Bonjour,

    merci dimitry

    j'ai trouvé une solution mais franchement ça fait bidouillage si quelqu'un peut m'orienter.

    ma solution :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    QDir::setCurrent(MyAppDirPath);
        MyAppDirPath =  QCoreApplication::applicationDirPath(); // recupere le chemin du programme
        ficheZip = MyAppDirPath + "/" + utilisateur + "/Zip/"+ fiche + ".zip";
        ficheExtract = MyAppDirPath + "/" + utilisateur;
        connect(unzipButton, SIGNAL(clicked()), this, SLOT(versunzip()));
    }
     
    void HttpWindow::versunzip ()
    {
       UnZip(ficheZip, ficheExtract);
    }
     
    void HttpWindow::UnZip (QString ficheZip , QString ficheExtract)
    {
        JlCompress::extractDir(ficheZip,ficheExtract);
    }

    quand a
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    UnZip(ficheZip, ficheExtract);
    cela marche très bien, c'est juste que je n'attendais pas que le fichier soit present !!!

    Cordialement

  5. #5
    Membre averti

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 184
    Points : 322
    Points
    322
    Par défaut
    C'est certain que si tu pouvais créer fichezip et ficheExtract directement dans ton slot, ce serait plus judicieux.

    Pourrais-tu donner un peu plus de code ?

  6. #6
    Membre habitué
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2011
    Messages : 316
    Points : 126
    Points
    126
    Par défaut
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    #include <QtGui>
    #include <QtNetwork>
    #include <JlCompress.h>
    #include "httpwindow.h"
    #include "ui_authenticationdialog.h"
     
    HttpWindow::HttpWindow(QWidget *parent)
        : QDialog(parent)
    {
        urlLineEdit = new QLineEdit("http://mc.deedyou.com/DATA/movies.txt");
        urlLabel = new QLabel(tr("&URL:"));
        urlLabel->setBuddy(urlLineEdit);
        statusLabel = new QLabel(tr("Entrer l'URL du fichier que vous voulez télécharger."));
        statusLabel->setWordWrap(true);
     
        downloadButton = new QPushButton(tr("Télécharger"));
        downloadButton->setDefault(true);
        quitButton = new QPushButton(tr("Quitter"));
        quitButton->setAutoDefault(false);
        unzipButton = new QPushButton(tr("UnZip"));
     
        buttonBox = new QDialogButtonBox;
        buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole);
        buttonBox->addButton(unzipButton, QDialogButtonBox::ActionRole);
        buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
        listeFilmOkMoviecovers = new QListWidget;
     
        QSettings settings("GestXavMedias", "GestXavMedias.ini");
        utilisateur = settings.value("NomUtilisateurDef").toString();
     
        connect(urlLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableDownloadButton()));
     
        connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
                this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*)));
    #ifndef QT_NO_OPENSSL
        connect(&qnam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
                this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
    #endif
        connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
        connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
        connect(listeFilmOkMoviecovers,SIGNAL(itemDoubleClicked(QListWidgetItem*)), this,SLOT(Telecharger_fiche()));
     
        urlLineEdit->adjustSize();
        listeFilmOkMoviecovers->setFixedSize(450,450);
        statusLabel->setMinimumHeight(50);
     
        QHBoxLayout *topLayout = new QHBoxLayout;
        topLayout->addWidget(urlLabel);
        topLayout->addWidget(urlLineEdit);
     
        QVBoxLayout *mainLayout = new QVBoxLayout;   
        mainLayout->addLayout(topLayout);
        mainLayout->addWidget(listeFilmOkMoviecovers);
        mainLayout->addWidget(statusLabel);
        mainLayout->addWidget(buttonBox);
        setLayout(mainLayout);
     
        setWindowTitle(tr("Téléchargement Fiches Films Moviecovers"));
        urlLineEdit->setFocus();
        downloadFile();
    }
     
    void HttpWindow::downloadFile()
    {
        url = urlLineEdit->text();
        MyAppDirPath =  QCoreApplication::applicationDirPath();
        QDir::setCurrent(MyAppDirPath + "/" + utilisateur + "/Zip");
        QFileInfo fileInfo(url.path());
        QString fileName = fileInfo.fileName();
        if (fileName.isEmpty())
            fileName = "index.html";
     
        if (QFile::exists(fileName)) {
            if (QMessageBox::question(this, tr("HTTP"),
                                      tr("Il existe déjà un fichier appeler : %1 dans "
                                         "le repertoire courant. Remplacer ?").arg(fileName),
                                      QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
                == QMessageBox::No){
                QFile fichier2(fileName);
                fichier2.open(QIODevice::ReadWrite | QIODevice::Text);
                QTextStream file2(&fichier2);
                while (! file2.atEnd())
                {
                QString line = file2.readLine();
                listeFilmOkMoviecovers->addItem(line);
                }
                fichier2.close();
                return;
            }
     
            QFile::remove(fileName);
        }
     
        file = new QFile(fileName);
        if (!file->open(QIODevice::WriteOnly)) {
            QMessageBox::information(this, tr("HTTP"),
                                     tr("Impossible de sauvegarder le fichier : %1: %2.")
                                     .arg(fileName).arg(file->errorString()));
            delete file;
            file = 0;
            return;
        }
     
        downloadButton->setEnabled(false);
     
        // schedule the request
        httpRequestAborted = false;
        startRequest(url);
    }
     
    void HttpWindow::startRequest(QUrl url)
    {
        reply = qnam.get(QNetworkRequest(url));
        connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));
        connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
        connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDataReadProgress(qint64,qint64)));
    }
     
    void HttpWindow::cancelDownload()
    {
        statusLabel->setText(tr("Téléchargement annulé."));
        httpRequestAborted = true;
        reply->abort();
        downloadButton->setEnabled(true);
    }
     
    void HttpWindow::httpFinished()
    {
        if (httpRequestAborted) {
            if (file) {
                file->close();
                file->remove();
                delete file;
                file = 0;
            }
            reply->deleteLater();
     
            return;
        }
     
        file->flush();
        file->close();
     
     
        QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
        if (reply->error()) {
            file->remove();
            QMessageBox::information(this, tr("HTTP"),
                                     tr("Problème de téléchargement: %1.")
                                     .arg(reply->errorString()));
            downloadButton->setEnabled(true);
        } else if (!redirectionTarget.isNull()) {        
            QUrl newUrl = url.resolved(redirectionTarget.toUrl());
            url = newUrl;
            reply->deleteLater();
            file->open(QIODevice::WriteOnly);
            file->resize(0);
            startRequest(url);
            return;
        } else {
            QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName();
            statusLabel->setText(tr("Téléchargement de %1 vers %2.").arg(fileName).arg(QDir::currentPath()+ " terminé"));
            downloadButton->setEnabled(true);
        }
     
        reply->deleteLater();
        reply = 0;
        delete file;
        file = 0;
    }
     
    void HttpWindow::httpReadyRead()
    {
        if (file)
            file->write(reply->readAll());
        Test();
    }
     
    void HttpWindow::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes)
    {
        if (httpRequestAborted)
            return;
     
        Q_UNUSED(bytesRead);
        Q_UNUSED(totalBytes);
    }
     
    void HttpWindow::enableDownloadButton()
    {
        downloadButton->setEnabled(!urlLineEdit->text().isEmpty());
    }
     
    void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator)
    {
        QDialog dlg;
        Ui::Dialog ui;
        ui.setupUi(&dlg);
        dlg.adjustSize();
        ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host()));
        ui.userEdit->setText(url.userName());
        ui.passwordEdit->setText(url.password());
     
        if (dlg.exec() == QDialog::Accepted) {
            authenticator->setUser(ui.userEdit->text());
            authenticator->setPassword(ui.passwordEdit->text());
        }
    }
     
    #ifndef QT_NO_OPENSSL
    void HttpWindow::sslErrors(QNetworkReply*,const QList<QSslError> &errors)
    {
        QString errorString;
        foreach (const QSslError &error, errors) {
            if (!errorString.isEmpty())
                errorString += ", ";
            errorString += error.errorString();
        }
     
        if (QMessageBox::warning(this, tr("HTTP"),
                                 tr("Une ou plusieurs erreurs SSL ont été trouvé: %1").arg(errorString),
                                 QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) {
            reply->ignoreSslErrors();
        }
    }
    #endif
     
    void HttpWindow::Test()
    {
    url = urlLineEdit->text();
    QFileInfo fileInfo(url.path());
    QString fileName = fileInfo.fileName();
    QFile file(fileName); // gestion de fichier
    file.open(QIODevice::ReadOnly); // on ouvre le fichier
    QTextStream files(&file);
    while (! files.atEnd())
    {
    QString line = files.readLine();
    listeFilmOkMoviecovers->addItem(line);
    }
    file.close();
    }
     
    void HttpWindow::Telecharger_fiche()
    {
        fiche = (listeFilmOkMoviecovers->currentItem()->text());
        if (fiche.contains("(L')", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (L')", "");
        fiche = ("L'" + fiche);
        }
        if (fiche.contains("(LE)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (LE)", "");
        fiche = ("LE " + fiche);
        }
        if (fiche.contains("(LA)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (LA)", "");
        fiche = ("LA " + fiche);
        }
        if (fiche.contains("(LES)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (LES)", "");
        fiche = ("LES " + fiche);
        }
        if (fiche.contains("(UN)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (UN)", "");
        fiche = ("UN " + fiche);
        }
        if (fiche.contains("(UNE)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (UNE)", "");
        fiche = ("UNE " + fiche);
        }
        if (fiche.contains("(THE)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (THE)", "");
        fiche = ("THE " + fiche);
        }
        if (fiche.contains("(AN)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (AN)", "");
        fiche = ("AN " + fiche);
        }
        if (fiche.contains("(A)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (A)", "");
        fiche = ("A " + fiche);
        }
        urlLineEdit = new QLineEdit("http://mc.deedyou.com/getzip.html/" + fiche + ".zip");
        downloadFile();
        QDir::setCurrent(MyAppDirPath);
        MyAppDirPath =  QCoreApplication::applicationDirPath();
        ficheZip = MyAppDirPath + "/" + utilisateur + "/Zip/"+ fiche + ".zip";
        ficheExtract = MyAppDirPath + "/" + utilisateur;
        connect(unzipButton, SIGNAL(clicked()), this, SLOT(versunzip()));
    }
     
    void HttpWindow::versunzip ()
    {
        UnZip(ficheZip, ficheExtract);
    }
     
    void HttpWindow::UnZip (QString ficheZip , QString ficheExtract)
    {
        JlCompress::extractDir(ficheZip,ficheExtract);
        bool valid  = QFile::exists(MyAppDirPath + "/" + utilisateur + "/"+ fiche + ".film");
        while (!valid){
        }
        statusLabel->setText(tr("Fichiers extraits"));
        QDir::setCurrent(MyAppDirPath);
        MyAppDirPath =  QCoreApplication::applicationDirPath();
        listFilter << "*.zip";
        QDirIterator dirIterator((MyAppDirPath + "/" + utilisateur + "/Zip"), listFilter ,QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
        while(dirIterator.hasNext())
        {
            dirIterator.next();
            QFile::remove(MyAppDirPath + "/" + utilisateur + "/Zip/"+ dirIterator.fileName());
        }
        listFilter << "*.txt";
        QDirIterator dirIterator2((MyAppDirPath + "/" + utilisateur), listFilter ,QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
        while(dirIterator2.hasNext())
        {
            dirIterator2.next();
            QFile::remove(MyAppDirPath + "/" + utilisateur + "/"+ dirIterator2.fileName());
        }
    }
    Je ne suis pas fiere de moi, mais ça fonctionne !!! en cliquant après sur unzipButton.

    je voudrais bien sûr ne pas cliquer sur unzipButton et directement dezziper mon fichier téléchargé (.zip) le supprimmer après, et supprimer le .txt parasite contenue dans les fichiers extraits(ce que je fais en deux étapes, et convaincu "de n'être pas propre".

    Cordialement

  7. #7
    Membre averti

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2011
    Messages
    184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 184
    Points : 322
    Points
    322
    Par défaut
    Si je résume, tu ne veux plus avoir à appuyer sur ton bouton unzip, c'est ça ?
    Du coup, pourquoi ne pas faire un appel à ta méthode unzip une fois le téléchargement terminé ?

  8. #8
    Membre habitué
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2011
    Messages : 316
    Points : 126
    Points
    126
    Par défaut
    j'ai essayé ça ne fonctionne pas car (je pense) je n'arrive pas a detecter la fin du telechargement du zip.
    si je fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
    urlLineEdit = new QLineEdit("http://mc.deedyou.com/getzip.html/" + fiche + ".zip");
        downloadFile();
        QDir::setCurrent(MyAppDirPath);
        MyAppDirPath =  QCoreApplication::applicationDirPath();
        ficheZip = MyAppDirPath + "/" + utilisateur + "/Zip/"+ fiche + ".zip";
        ficheExtract = MyAppDirPath + "/" + utilisateur;
        bool valid2  = QFile::exists(MyAppDirPath + "/" + utilisateur + "/Zip/"+ fiche + ".zip");
        while (!valid2){
        }
        UnZip (ficheZip, ficheExtract);
    }
     
    void HttpWindow::UnZip (QString ficheZip , QString ficheExtract)
    {
        JlCompress::extractDir(ficheZip,ficheExtract);
        bool valid  = QFile::exists(MyAppDirPath + "/" + utilisateur + "/"+ fiche + ".film");
        while (!valid){
        }
        statusLabel->setText(tr("Fichiers extraits"));
        QDir::setCurrent(MyAppDirPath);
        MyAppDirPath =  QCoreApplication::applicationDirPath();
        listFilter << "*.zip";
        QDirIterator dirIterator((MyAppDirPath + "/" + utilisateur + "/Zip"), listFilter ,QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
        while(dirIterator.hasNext())
        {
            dirIterator.next();
            QFile::remove(MyAppDirPath + "/" + utilisateur + "/Zip/"+ dirIterator.fileName());
        }
        listFilter << "*.txt";
        QDirIterator dirIterator2((MyAppDirPath + "/" + utilisateur), listFilter ,QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
        while(dirIterator2.hasNext())
        {
            dirIterator2.next();
            QFile::remove(MyAppDirPath + "/" + utilisateur + "/"+ dirIterator2.fileName());
        }
    }
    cela ne fonctionne pas !!! il voit le zip donc ne passe pas dans ma boucle d'attente, mais le zip ne doit pas être entierement chargé et donc il n'execute pas la fonction UnZip....

  9. #9
    Membre expérimenté

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2009
    Messages
    1 009
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2009
    Messages : 1 009
    Points : 1 738
    Points
    1 738
    Par défaut
    Bon j'espère que tu te rends compte que ta boucle d'attente est une grosse bêtise pour commencer, tu es en C++, pas en déclaratif comme le QML.

    "une fois le téléchargement terminé" => pourtant tu fais déjà plein de choses quand le téléchargement est terminé (fermer le fichier, ou l'effacer s'il n'est pas fini, indiquer que le téléchargement est terminé, etc), alors pourquoi ne pas faire ton UnZip ? On dirait que tu ne connais pas ton propre code. A partir du moment où downloadFile() est asynchrone, tu n'as pas à mettre du code dépendant de la fin de l'opération à la suite, vu que justement c'est asynchrone.

  10. #10
    Membre habitué
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2011
    Messages : 316
    Points : 126
    Points
    126
    Par défaut
    bonjour,

    Meeeeeeeeeeeeeeeeeeeeerci,

    ma soluce :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    #include <QtGui>
    #include <QtNetwork>
    #include <JlCompress.h>
    #include "httpwindow.h"
    #include "ui_authenticationdialog.h"
     
    HttpWindow::HttpWindow(QWidget *parent)
        : QDialog(parent)
    {
        urlLineEdit = new QLineEdit("http://mc.deedyou.com/DATA/movies.txt");
        urlLabel = new QLabel(tr("&URL:"));
        urlLabel->setBuddy(urlLineEdit);
        statusLabel = new QLabel(tr("Entrer l'URL du fichier que vous voulez télécharger."));
        statusLabel->setWordWrap(true);
     
        downloadButton = new QPushButton(tr("Télécharger"));
        downloadButton->setDefault(true);
        quitButton = new QPushButton(tr("Quitter"));
        quitButton->setAutoDefault(false);
        unzipButton = new QPushButton(tr("UnZip"));
     
        buttonBox = new QDialogButtonBox;
        buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole);
        buttonBox->addButton(unzipButton, QDialogButtonBox::ActionRole);
        buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
        listeFilmOkMoviecovers = new QListWidget;
     
        QSettings settings("GestXavMedias", "GestXavMedias.ini");
        utilisateur = settings.value("NomUtilisateurDef").toString();
     
        connect(urlLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableDownloadButton()));
     
        connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
                this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*)));
    #ifndef QT_NO_OPENSSL
        connect(&qnam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
                this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
    #endif
        connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
        connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
        connect(listeFilmOkMoviecovers,SIGNAL(itemDoubleClicked(QListWidgetItem*)), this,SLOT(Telecharger_fiche()));
     
        urlLineEdit->adjustSize();
        listeFilmOkMoviecovers->setFixedSize(450,450);
        statusLabel->setMinimumHeight(50);
     
        QHBoxLayout *topLayout = new QHBoxLayout;
        topLayout->addWidget(urlLabel);
        topLayout->addWidget(urlLineEdit);
     
        QVBoxLayout *mainLayout = new QVBoxLayout;   
        mainLayout->addLayout(topLayout);
        mainLayout->addWidget(listeFilmOkMoviecovers);
        mainLayout->addWidget(statusLabel);
        mainLayout->addWidget(buttonBox);
        setLayout(mainLayout);
     
        setWindowTitle(tr("Téléchargement Fiches Films Moviecovers"));
        urlLineEdit->setFocus();
        downloadFile();
    }
     
    void HttpWindow::downloadFile()
    {
        url = urlLineEdit->text();
        MyAppDirPath =  QCoreApplication::applicationDirPath();
        QDir::setCurrent(MyAppDirPath + "/" + utilisateur + "/Zip");
        QFileInfo fileInfo(url.path());
        QString fileName = fileInfo.fileName();
        if (fileName.isEmpty())
            fileName = "index.html";
     
        if (QFile::exists(fileName)) {
            if (QMessageBox::question(this, tr("HTTP"),
                                      tr("Il existe déjà un fichier appeler : %1 dans "
                                         "le repertoire courant. Remplacer ?").arg(fileName),
                                      QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
                == QMessageBox::No){
                QFile fichier2(fileName);
                fichier2.open(QIODevice::ReadWrite | QIODevice::Text);
                QTextStream file2(&fichier2);
                while (! file2.atEnd())
                {
                QString line = file2.readLine();
                listeFilmOkMoviecovers->addItem(line);
                }
                fichier2.close();
                return;
            }
     
            QFile::remove(fileName);
        }
     
        file = new QFile(fileName);
        if (!file->open(QIODevice::WriteOnly)) {
            QMessageBox::information(this, tr("HTTP"),
                                     tr("Impossible de sauvegarder le fichier : %1: %2.")
                                     .arg(fileName).arg(file->errorString()));
            delete file;
            file = 0;
            return;
        }
     
        downloadButton->setEnabled(false);
     
        // schedule the request
        httpRequestAborted = false;
        startRequest(url);
    }
     
    void HttpWindow::startRequest(QUrl url)
    {
        reply = qnam.get(QNetworkRequest(url));
        connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));
        connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
        connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDataReadProgress(qint64,qint64)));
    }
     
    void HttpWindow::cancelDownload()
    {
        statusLabel->setText(tr("Téléchargement annulé."));
        httpRequestAborted = true;
        reply->abort();
        downloadButton->setEnabled(true);
    }
     
    void HttpWindow::httpFinished()
    {
        if (httpRequestAborted) {
            if (file) {
                file->close();
                file->remove();
                delete file;
                file = 0;
            }
            reply->deleteLater();
     
            return;
        }
     
        file->flush();
        file->close();
     
     
        QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
        if (reply->error()) {
            file->remove();
            QMessageBox::information(this, tr("HTTP"),
                                     tr("Problème de téléchargement: %1.")
                                     .arg(reply->errorString()));
            downloadButton->setEnabled(true);
        } else if (!redirectionTarget.isNull()) {        
            QUrl newUrl = url.resolved(redirectionTarget.toUrl());
            url = newUrl;
            reply->deleteLater();
            file->open(QIODevice::WriteOnly);
            file->resize(0);
            startRequest(url);
            return;
        } else {
            QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName();
            statusLabel->setText(tr("Téléchargement de %1 vers %2.").arg(fileName).arg(QDir::currentPath()+ " terminé"));
            QDir::setCurrent(MyAppDirPath);
            MyAppDirPath =  QCoreApplication::applicationDirPath();
            ficheZip = MyAppDirPath + "/" + utilisateur + "/Zip/"+ fiche + ".zip";
            ficheExtract = MyAppDirPath + "/" + utilisateur;
            bool valid  = QFile::exists(ficheZip);
            if (valid){
                UnZip(ficheZip, ficheExtract);
            }
            downloadButton->setEnabled(true);
        }
     
        reply->deleteLater();
        reply = 0;
        delete file;
        file = 0;
    }
     
    void HttpWindow::httpReadyRead()
    {
        if (file)
            file->write(reply->readAll());
        Test();
    }
     
    void HttpWindow::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes)
    {
        if (httpRequestAborted)
            return;
     
        Q_UNUSED(bytesRead);
        Q_UNUSED(totalBytes);
    }
     
    void HttpWindow::enableDownloadButton()
    {
        downloadButton->setEnabled(!urlLineEdit->text().isEmpty());
    }
     
    void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator)
    {
        QDialog dlg;
        Ui::Dialog ui;
        ui.setupUi(&dlg);
        dlg.adjustSize();
        ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host()));
        ui.userEdit->setText(url.userName());
        ui.passwordEdit->setText(url.password());
     
        if (dlg.exec() == QDialog::Accepted) {
            authenticator->setUser(ui.userEdit->text());
            authenticator->setPassword(ui.passwordEdit->text());
        }
    }
     
    #ifndef QT_NO_OPENSSL
    void HttpWindow::sslErrors(QNetworkReply*,const QList<QSslError> &errors)
    {
        QString errorString;
        foreach (const QSslError &error, errors) {
            if (!errorString.isEmpty())
                errorString += ", ";
            errorString += error.errorString();
        }
     
        if (QMessageBox::warning(this, tr("HTTP"),
                                 tr("Une ou plusieurs erreurs SSL ont été trouvé: %1").arg(errorString),
                                 QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) {
            reply->ignoreSslErrors();
        }
    }
    #endif
     
    void HttpWindow::Test()
    {
    url = urlLineEdit->text();
    QFileInfo fileInfo(url.path());
    QString fileName = fileInfo.fileName();
    QFile file(fileName); // gestion de fichier
    file.open(QIODevice::ReadOnly); // on ouvre le fichier
    QTextStream files(&file);
    while (! files.atEnd())
    {
    QString line = files.readLine();
    listeFilmOkMoviecovers->addItem(line);
    }
    file.close();
    }
     
    void HttpWindow::Telecharger_fiche()
    {
        fiche = (listeFilmOkMoviecovers->currentItem()->text());
        if (fiche.contains("(L')", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (L')", "");
        fiche = ("L'" + fiche);
        }
        if (fiche.contains("(LE)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (LE)", "");
        fiche = ("LE " + fiche);
        }
        if (fiche.contains("(LA)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (LA)", "");
        fiche = ("LA " + fiche);
        }
        if (fiche.contains("(LES)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (LES)", "");
        fiche = ("LES " + fiche);
        }
        if (fiche.contains("(UN)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (UN)", "");
        fiche = ("UN " + fiche);
        }
        if (fiche.contains("(UNE)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (UNE)", "");
        fiche = ("UNE " + fiche);
        }
        if (fiche.contains("(THE)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (THE)", "");
        fiche = ("THE " + fiche);
        }
        if (fiche.contains("(AN)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (AN)", "");
        fiche = ("AN " + fiche);
        }
        if (fiche.contains("(A)", Qt::CaseInsensitive))
        {
        fiche = fiche.replace(" (A)", "");
        fiche = ("A " + fiche);
        }
        urlLineEdit = new QLineEdit("http://mc.deedyou.com/getzip.html/" + fiche + ".zip");
        downloadFile();
        //connect(unzipButton, SIGNAL(clicked()), this, SLOT(versunzip()));
    }
     
    /*void HttpWindow::versunzip ()
    {
        UnZip(ficheZip, ficheExtract);
    }*/
     
    void HttpWindow::UnZip (QString ficheZip , QString ficheExtract)
    {
        QDir::setCurrent(MyAppDirPath);
        MyAppDirPath =  QCoreApplication::applicationDirPath();
        JlCompress::extractDir(ficheZip,ficheExtract);
        bool valid  = QFile::exists(MyAppDirPath + "/" + utilisateur + "/"+ fiche + ".film");
        if (valid){
            statusLabel->setText(tr("Fichiers extraits"));
            listFilter << "*.zip";
            QDirIterator dirIterator((MyAppDirPath + "/" + utilisateur + "/Zip"), listFilter ,QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
            while(dirIterator.hasNext())
            {
                dirIterator.next();
                QFile::remove(MyAppDirPath + "/" + utilisateur + "/Zip/"+ dirIterator.fileName());
            }
            listFilter << "*.txt";
            QDirIterator dirIterator2((MyAppDirPath + "/" + utilisateur), listFilter ,QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
            while(dirIterator2.hasNext())
            {
                dirIterator2.next();
                QFile::remove(MyAppDirPath + "/" + utilisateur + "/"+ dirIterator2.fileName());
            }
        }
    }
    cordialement

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Forms]Passage de paramètre entre Forms et Reports
    Par jack554 dans le forum Reports
    Réponses: 4
    Dernier message: 30/03/2004, 13h58
  2. probleme lors du passage de paramètre
    Par maxmj dans le forum ASP
    Réponses: 4
    Dernier message: 18/11/2003, 00h15
  3. [XSL] Passage de paramètres à un template
    Par pantin dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 27/06/2003, 13h28
  4. passage de paramètres
    Par pram dans le forum XMLRAD
    Réponses: 5
    Dernier message: 18/02/2003, 17h28
  5. passage en paramètre d'un array dynamique 2D
    Par Guigui_ dans le forum Langage
    Réponses: 4
    Dernier message: 27/11/2002, 19h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo