Esempio n. 1
0
void HttpWindow::downloadFile()
{
    const QString urlSpec = "http://www.youtubeinmp3.com/fetch/?video=" + urlLineEdit->text().trimmed();
    if (urlSpec.isEmpty())
        return;

    const QUrl newUrl = QUrl::fromUserInput(urlSpec);
    if (!newUrl.isValid()) {
        QMessageBox::information(this, tr("Error"),
                                 tr("Invalid URL: %1: %2").arg(urlSpec, newUrl.errorString()));
        return;
    }

    QString fileName = newUrl.fileName();
    if (fileName.isEmpty())
        fileName = defaultFileLineEdit->text().trimmed();
    if (fileName.isEmpty())
        fileName = defaultFileName;
    QString downloadDirectory = QDir::cleanPath(downloadDirectoryLineEdit->text().trimmed());
    if (!downloadDirectory.isEmpty() && QFileInfo(downloadDirectory).isDir())
        fileName.prepend(downloadDirectory + '/');
    if (QFile::exists(fileName)) {
        if (QMessageBox::question(this, tr("Overwrite Existing File"),
                                  tr("There already exists a file called %1 in "
                                     "the current directory. Overwrite?").arg(fileName),
                                  QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
            == QMessageBox::No)
            return;
        QFile::remove(fileName);
    }

    file = openFileForWrite(fileName);
    if (!file)
        return;

    downloadButton->setEnabled(false);

    // schedule the request
    //Download QQueue
    if (songBeingDownloaded == true)//song is being downloaded currently
        songsThatNeedToBeDownloaded.enqueue(newUrl);
    else
        startRequest(newUrl);
    /**
    else if (!songsThatNeedToBeDownloaded.isEmpty())
    {
        songsThatNeedToBeDownloaded.enqueue(newUrl);
        while (!songsThatNeedToBeDownloaded.isEmpty() && songBeingDownloaded == false)
        {
        QUrl tempURL = songsThatNeedToBeDownloaded.dequeue();
        startRequest(tempURL);
        }
    }
    else
        startRequest(newUrl);
        */
}
void JUnitTestOutput::writeTestGroupToFile()
{
	openFileForWrite(createFileName(impl_->results_.group_));
	writeXmlHeader();
	writeTestSuiteSummery();
	writeProperties();
	writeTestCases();
	writeFileEnding();
	closeFile();
}
Esempio n. 3
0
void HttpWindow::httpFinished()
{
    songBeingDownloaded = false;
    if (!songsThatNeedToBeDownloaded.isEmpty())
    {
    QUrl tempURL = songsThatNeedToBeDownloaded.dequeue();
    startRequest(tempURL);
    }
    QFileInfo fi;

    if (file) {
        fi.setFile(file->fileName());
        file->close();
        delete file;
        file = Q_NULLPTR;
    }

    if (httpRequestAborted) {
        reply->deleteLater();
        reply = Q_NULLPTR;
        return;
    }

    if (reply->error()) {
        QFile::remove(fi.absoluteFilePath());
        statusLabel->setText(tr("Download failed:\n%1.").arg(reply->errorString()));
        downloadButton->setEnabled(true);
        reply->deleteLater();
        reply = Q_NULLPTR;
        return;
    }

    const QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);

    reply->deleteLater();
    reply = Q_NULLPTR;

    if (!redirectionTarget.isNull()) {
        const QUrl redirectedUrl = url.resolved(redirectionTarget.toUrl());
        file = openFileForWrite(fi.absoluteFilePath());
        if (!file) {
            downloadButton->setEnabled(true);
            return;
        }
        startRequest(redirectedUrl);
        return;
    }

    if (fi.size() < 21000){
        statusLabel->setText("Error downloading song, try again or try a new link.");
}
    else{
    statusLabel->setText(tr("Downloaded %1 bytes to %2\nin\n%3")
                         .arg(fi.size()).arg(fi.fileName(), QDir::toNativeSeparators(fi.absolutePath())));
}
    songNameList.append(fi.fileName());

    if (launchCheckBox->isChecked()){
    //Just added these below so you aren't forced to have the launchBox checked
     //playlist->addMedia(QUrl::fromLocalFile(fi.absoluteFilePath()));//**********
     //player->setVolume(50);
     //player->setPlaylist(playlist);

     //All these if/elses were some of my attempts to hold the player state when songs are being downloaded
     /**
     if(songIndex == 0)
     {
        firstSongAdded = QUrl::fromLocalFile(fi.absoluteFilePath());
     }

     if (QMediaPlayer::NoMedia == 1)//playing (0 = stopped, 1 = playing, 2 = paused)
     {
         if(!songsThatNeedToBeAdded.isEmpty()){
             while(!songsThatNeedToBeAdded.isEmpty())
             {
                 playlist->addMedia((songsThatNeedToBeAdded.dequeue()));
             }
            player->setPlaylist(playlist);
         }
         else{
             player->setPlaylist(playlist);
         }
     }
     else
     {
         songsThatNeedToBeAdded.enqueue(QUrl::fromLocalFile(fi.absoluteFilePath()));
     }
     */
}
    //newlyAddedSong = QUrl::fromLocalFile(fi.absoluteFilePath());
    //player->setMedia(currentSong);
    tempPlaylist.append(QUrl::fromLocalFile(fi.absoluteFilePath()));
    playlist->addMedia(QUrl::fromLocalFile(fi.absoluteFilePath()));
    player->setVolume(50);
    player->setPlaylist(playlist);
    downloadButton->setEnabled(true);
    //songIndex++;
    totalNumberOfSongs++;
}