Пример #1
0
void SearchDialog::saveCoverNow(){
    int ind = searchResults->currentRow();
    if(ind==-1){
        return;
    }
    Album album = albums_[searchResults->currentItem()->data(Qt::UserRole).toString()];
    if(album.images().size()==0){
        return;
    }
    QList<QUrl> images = album.images();
    saveCover( images[currentCoverInd] );
}
Пример #2
0
void SearchDialog::showCover( int ind ){

    int aind = searchResults->currentRow();
    if(aind==-1){
        return;
    }
    Album album = albums_[searchResults->currentItem()->data(Qt::UserRole).toString()];

    QList<QUrl> images = album.images();
    int n = images.size();
    //qDebug()<<"Trying to set cover "<<ind<<" of "<<n;
    if( n==0 ){
        currentCoverInd=0;
        return;
    }
    if( ind<0 ){
        ind=0;
    }
    if( ind>=n ){
        ind=n-1;
    }
    setCover( images[ind] );
    //qDebug()<<"Set cover "<<ind<<" of "<<n;
    currentCoverInd = ind;
    coverLabel->setText("Cover "+QString::number(ind+1)+" of "+QString::number(n));
}
Пример #3
0
void SearchDialog::saveCoverFromReply(QNetworkReply* reply){
    //image to be saved must exist in albumLineEdit.images

    QByteArray data = reply->readAll();
    QImage p;
    p.loadFromData(data);
    p.convertToFormat(QImage::Format_RGB32);
    reply->deleteLater();


    int aind = searchResults->currentRow();
    if(aind==-1){
        return;
    }    
    Album album = albums_[searchResults->currentItem()->data(Qt::UserRole).toString()];

    QList<QUrl> images = album.images();
    QString url = reply->url().toString();
    int cInd=-1;
    for(int i=0;i<images.size();i++){
        if(url==images[i].toString()){
            cInd=i;
            break;
        }
    }
    if(cInd==-1){
        return;
    }

    QString name = images[cInd].toString();
    //qDebug()<<name;
    int ind = name.lastIndexOf("/");
    if(ind==-1){
        ind = name.lastIndexOf("\\");
    }
    name = name.remove(0,ind+1);
    if(coverFormatCheckBox->isChecked()){
        int suffInd = name.lastIndexOf(".");
        QString ext = name.right(name.size()-suffInd);
        name = createCoverName( cInd+1, ext );
    }
    //qDebug()<<name;
    QString path = items_[0]->fileInfo().absoluteDir().absolutePath();
    name = path+"/"+name;
    int quality = settings->value("SearchDialog/coverQuality",-1).toInt();
    bool ok = p.save( name, 0, quality );
    if(!ok){
        QMessageBox::critical(this, "Could not save cover",
                              "Could not save cover "+url+" as "+name, QMessageBox::Ok, QMessageBox::Ok);
    }else{
        qDebug()<<"saved"<<name;
    }
}
Пример #4
0
void SearchDialog::showAlbumAndCover( const Album &album ){

    if(album.images().size()==0){
        //if( databaseComboBox->itemData(databaseComboBox->currentIndex()).toInt()==SearchDialog::MUSICBRAINZ ){
        if( database_->type()==MusicDatabase::MUSICBRAINZ ){
            cover->setText("Covers are not available from MusicBrainz");
        }else{
            cover->setText("No cover found...");
        }
        coverLabel->setText("");
    }else{
        showCover( 0 );
    }
    showAlbumInfo( album );

}
Пример #5
0
void SearchDialog::save(){


    QString log;
    int aind = searchResults->currentRow();
    if(aind==-1){
        QMessageBox::critical(this, "Save", "Please select a serach result first", QMessageBox::Ok, QMessageBox::Ok);
        return;
    }
    Album album = albums_[searchResults->currentItem()->data(Qt::UserRole).toString()];
    //save tags
    bool trackOk;bool yearOk; QHash<QString,QString> commentsList;
    for(int i=0;i<albumInfo->rowCount();i++){
        qDebug()<<i;
        if( !albumInfo->item(i,TableWidget::FILE_NAME) ){
            continue;
        }
        if( albumInfo->item(i,TableWidget::FILE_NAME)->text().isEmpty() ){
            continue;
        }
        if(albumInfo->item(i,TableWidget::FILE_NAME)->checkState()!=Qt::Checked){
            continue;
        }
        QString fullfile = albumInfo->item(i,TableWidget::FILE_NAME)->data(Qt::UserRole).toString();
        TagItem* tagItem = 0;
        for(int j=0;j<items_.size();j++){
            qDebug()<<items_[j]->fileInfo().filePath().toLower()<<fullfile;
            if(items_[j]->fileInfo().filePath().toLower()==fullfile.toLower()){
                tagItem = items_[j];
                break;
            }
        }
        if(tagItem==0){
            qDebug()<<"BUG!!!!! COULD NOT FIND "+fullfile;
            continue;
        }

        if( !tagItem->tagOk() ){
            log.append("\nCould not read tag for "+fullfile);
            continue;
        }

        qDebug()<<"saving "<<fullfile;
        //title
        if(albumInfo->item(i,TableWidget::TITLE)){
            tagItem->setTitle( albumInfo->item(i,TableWidget::TITLE)->text() );
        }

        //track
        if(albumInfo->item(i,TableWidget::TRACK)){
            int tmp = albumInfo->item(i,TableWidget::TRACK)->text().toInt(&trackOk,10);
            if(trackOk){
                tagItem->setTrack( tmp );
            }
        }
        //add extra info to comments if checked
        QString comments = "";
        if( albumInfo->item(i,TableWidget::COMMENT) && !clearPreviousComentsCheckBox->isChecked() ){
            comments = albumInfo->item(i,TableWidget::COMMENT)->text();
        }
        QString tmp="Format: "+formatLineEdit->text();
        if(formatLabel->isVisible() && formatLabel->isChecked() && !comments.contains(tmp) && !formatLineEdit->text().isEmpty() ){
            if(!comments.isEmpty()){ comments.append("\n"); }
            comments.append(tmp);
        }
        tmp="Country: "+countryLineEdit->text();
        if(countryLabel->isVisible() && countryLabel->isChecked() && !comments.contains(tmp) && !countryLineEdit->text().isEmpty() ){
            if(!comments.isEmpty()){ comments.append("\n"); }
            comments.append(tmp);
        }
        tmp="Label: "+labelLineEdit->text();
        if(labelLabel->isVisible() && labelLabel->isChecked() && !comments.contains(tmp) && !labelLineEdit->text().isEmpty() ){
            if(!comments.isEmpty()){ comments.append("\n"); }
            comments.append(tmp);
        }
        tmp="Roles: "+rolesTextEdit->toPlainText();
        if(rolesLabel->isVisible() && rolesLabel->isChecked() && !comments.contains(tmp) && !rolesTextEdit->toPlainText().isEmpty() ){
            if(!comments.isEmpty()){ comments.append("\n"); }
            comments.append(tmp);
        }
        tmp="Notes: "+notesTextEdit->toPlainText();
        if(notesLabel->isVisible() && notesLabel->isChecked() && !comments.contains(tmp) && !notesTextEdit->toPlainText().isEmpty() ){
            if(!comments.isEmpty()){ comments.append("\n"); }
            comments.append(tmp);
        }
        commentsList.insert(fullfile,comments);
        //comments
        if(albumInfo->item(i,TableWidget::COMMENT)){
            tagItem->setComment( comments );
        }
        //album
        if(albumLabel->isChecked()){
            tagItem->setAlbum( albumLineEdit->text() );
        }
        //artist
        if(artistLabel->isChecked()){
            tagItem->setArtist( artistLineEdit->text() );
        }
        //genre
        if(genreLabel->isVisible() && genreLabel->isChecked()){
            tagItem->setGenre( genreLineEdit->text() );
        }
        //year
        if(yearLabel->isChecked()){
            int tmp = yearLineEdit->text().toInt(&yearOk,10);
            if(yearOk){                
                tagItem->setYear( tmp );
            }            
        }
        bool saveOk = tagItem->saveTag();
        if(!saveOk){
            log.append("\nCould not save tag for "+fullfile);
        }
    }

    //at last, update saved data in table and labels
    setItems();

    //save covers at last, in case tags are used to name covers
    if( saveCoverCheckBox->isChecked() && !saveAllCoversCheckBox->isChecked() ){
        if( currentCoverInd>=0 && currentCoverInd<album.images().size() ){
            QList<QUrl> images = album.images();
            saveCover( images[currentCoverInd] );
        }
    }else if( saveAllCoversCheckBox->isChecked() ){
	//save all covers
        QList<QUrl> images = album.images();
        for(int i=0;i<images.size();i++){
            saveCover( images[i] );
        }
    }
    //show log if any
    if(!log.isEmpty()){
        TextViewer t(log);
        t.exec();
    }
    info->setText("Tags saved");
    //albumInfo->setSortingEnabled(enabled);
}