コード例 #1
0
void MainWindow::closeEvent(QCloseEvent *event)
{
    QSettings settings;
    if(m_confirmClose && settings.value(m_settingsName+QLatin1String("/confirmClose"),true).toBool())
    {
        QMessageBox msg(this);
        msg.setText(m_confirmCloseMessage);
        msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        msg.setDefaultButton(QMessageBox::Yes);
        msg.setIcon(QMessageBox::Question);

        QCheckBox dontPrompt(tr("Do not ask again"), &msg);
        dontPrompt.blockSignals(true);

        msg.addButton(&dontPrompt, QMessageBox::ActionRole);

        int ret = msg.exec();
        if(ret == QMessageBox::No) {
            event->ignore();
        }
        else {
            event->accept();
            if(dontPrompt.checkState() == Qt::Checked) {
                settings.setValue(m_settingsName+QLatin1String("/confirmClose"),false);
            }
        }
    }
    else {
        event->accept();
    }
}
コード例 #2
0
ファイル: ClosableImage.cpp プロジェクト: hathagat/MediaElch
bool ClosableImage::confirmDeleteImage()
{
    if (Settings::instance()->dontShowDeleteImageConfirm())
        return true;

    QMessageBox msgBox;
    msgBox.setIcon(QMessageBox::Question);
    msgBox.setWindowTitle(tr("Really delete image?"));
    msgBox.setText(tr("Are you sure you want to delete this image?"));
    msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    QCheckBox dontPrompt(QObject::tr("Do not ask again"), &msgBox);
    dontPrompt.blockSignals(true);
    msgBox.addButton(&dontPrompt, QMessageBox::ActionRole);
    int ret = msgBox.exec();
    if (dontPrompt.checkState() == Qt::Checked && ret == QMessageBox::Yes)
        Settings::instance()->setDontShowDeleteImageConfirm(true);
    return (ret == QMessageBox::Yes);
}
コード例 #3
0
ファイル: tagEditor.cpp プロジェクト: ivareske/TagEditor
void TagEditor::saveTag(){

    //QModelIndexList indexes = TreeWidget_->selectionModel()->selectedRows();
    QModelIndexList indexes = TreeWidget_->selectionModel()->selectedRows(0);
    qDebug()<<indexes.size();

    if( indexes.size()>1 && showSaveTagWarning ){
        QMessageBox msgBox; QCheckBox dontPrompt("Do not prompt again", &msgBox);
        /*int nrows = (dynamic_cast<QGridLayout*>(msgBox.layout()))->rowCount();
		int ncols = (dynamic_cast<QGridLayout*>(msgBox.layout()))->columnCount();
		dynamic_cast<QGridLayout*>(msgBox.layout())->addWidget(&dontPrompt, nrows, 0, 1, ncols );
		*/
        dontPrompt.blockSignals(true);
        msgBox.addButton(&dontPrompt, QMessageBox::ActionRole);
        msgBox.setText("More than one file is selected");
        msgBox.setInformativeText("Save shown data for all files?");
        msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
        msgBox.setDefaultButton(QMessageBox::Save);
        int ret = msgBox.exec();
        showSaveTagWarning = !dontPrompt.isChecked();
        if(ret==QMessageBox::Cancel){
            statusBar()->showMessage("Aborted", 8000);
            return;
        }
    }
    //aply to all selected files
    QString log;
    int n = indexes.size();
    QProgressDialog *p=0;
    if(n>1){
        p = new QProgressDialog("Saving tags...", "Cancel", 0, indexes.size(), this);
        p->setWindowModality(Qt::WindowModal);
    }
    for(int i=0;i<n;i++){

        if(n>1){
            p->setValue(i);
            if( p->wasCanceled() ){
                break;
            }
        }
	
        int row = indexes[i].row();
        //TagItem *item = (TagItem*)TreeWidget_->topLevelItem( row );
        TagItem *item = TreeWidget_->tagItem(row);
        QString fullfile = item->fileInfo().absoluteFilePath();
        qDebug()<<fullfile;
        //TagLib::FileRef f( fullfile.toStdString().c_str() );
        if( !item->tagOk() ){
            log.append("\nCould not read tag for "+fullfile);
            continue;
        }

        if(ArtistCheckbox->isChecked()){
            //f.tag()->setArtist( Artist->text().toStdString().c_str() );
            //item->setTag( Global::Artist, Artist->text() );
            item->setArtist(Artist->text());
        }
        if(TitleCheckbox->isChecked()){
            //f.tag()->setTitle( Title->text().toStdString().c_str() );
            //item->setTag( Global::Title, Title->text() );
            item->setTitle(Title->text());
        }
        if(AlbumCheckbox->isChecked()){
            //f.tag()->setAlbum( Album->text().toStdString().c_str() );
            //item->setTag( Global::AlbumField, Album->text() );
            item->setAlbum(Album->text());
        }
        if(YearCheckbox->isChecked()){
            bool ok;
            uint year = Year->text().toUInt(&ok);
            qDebug()<<"converted to uint: "<<ok<<year;
            if(!ok){
                //statusBar()->showMessage(fullfile+": Year has to be an positive integer value!", 8000);
                QMessageBox::critical(this, "",
                                      fullfile+":\nYear has to be an positive integer value!",
                                      QMessageBox::Ok, QMessageBox::Ok);
                //Year->setText( item->getTag("year").toString() );
                Year->setText( QString::number(item->year()) );
            }else{
                //f.tag()->setYear( year );
                //item->setTag( Global::Year, year );
                item->setYear(year);
            }
        }
        if(TrackCheckbox->isChecked()){
            bool ok;
            uint track = Track->text().toUInt(&ok);
            if(!ok){
                //statusBar()->showMessage(fullfile+": Track has to be an positive integer value!", 8000);
                QMessageBox::critical(this, "",
                                      fullfile+":\nTrack has to be an positive integer value!",
                                      QMessageBox::Ok, QMessageBox::Ok);
                Track->setText( QString::number(item->track()) );
            }else{
                //f.tag()->setTrack( track );
                //item->setTag( Global::Track, track );
                item->setTrack(track);
            }
        }
        if(GenreCheckbox->isChecked()){
            //f.tag()->setGenre( Genre->text().toStdString().c_str() );
            //item->setTag( Global::Genre, Genre->text() );
            item->setGenre(Genre->text());
        }
        if(CommentCheckbox->isChecked()){
            //f.tag()->setComment( Comment->toPlainText().toStdString().c_str() );
            //item->setTag( Global::Comment, Comment->toPlainText() );
            item->setComment(Comment->toPlainText());
        }

        bool ok = item->saveTag();//f.save();
        if(!ok){
            log.append("\nCould not save tag for "+fullfile);
        }
    }
    if(n>1){
        p->setValue(n);
    }
    if(indexes.size()>1){
        statusBar()->showMessage("Fisnihed saving tags", 8000);
    }else{
        statusBar()->showMessage("Tag saved", 8000);
    }
    if(!log.isEmpty()){
        TextViewer t(log);
        t.exec();        
    }
}