示例#1
0
void OptionsSimple::profileRemove()
{
    const QString profileName = cProfile->currentText();

    const int ret = KMessageBox::questionYesNo( this, i18n("Do you really want to remove the profile: %1").arg(profileName), i18n("Remove profile?") );
    if( ret == KMessageBox::Yes )
    {
        QDomDocument list("soundkonverter_profilelist");

        QFile listFile( KStandardDirs::locateLocal("data","soundkonverter/profiles.xml") );
        if( listFile.open( QIODevice::ReadOnly ) )
        {
            if( list.setContent( &listFile ) )
            {
                QDomElement root = list.documentElement();
                if( root.nodeName() == "soundkonverter" && root.attribute("type") == "profilelist" )
                {
                    QDomElement profileElement;
                    QDomNodeList conversionOptionsElements = root.elementsByTagName("conversionOptions");
                    for( int i=0; i<conversionOptionsElements.count(); i++ )
                    {
                        if( conversionOptionsElements.at(i).toElement().attribute("profileName") == profileName )
                        {
                            delete config->data.profiles[profileName];
                            config->data.profiles.remove(profileName);
                            root.removeChild(conversionOptionsElements.at(i));
                            break;
                        }
                    }
                }
            }
            listFile.close();
        }

        if( listFile.open( QIODevice::WriteOnly ) )
        {
            updateProfiles();
            emit customProfilesEdited();

            QTextStream stream(&listFile);
            stream << list.toString();
            listFile.close();
        }
    }
}
示例#2
0
bool OptionsDetailed::saveCustomProfile( bool lastUsed )
{
    if( wPlugin && currentPlugin )
    {
        QString profileName;
        if( lastUsed )
        {
            profileName = "soundkonverter_last_used";
        }
        else
        {
            bool ok;
            profileName = KInputDialog::getText( i18n("New profile"), i18n("Enter a name for the new profile:"), "", &ok );
            if( !ok )
                return false;
        }

        if( profileName.isEmpty() )
        {
            KMessageBox::information( this, i18n("You cannot save a profile without a name."), i18n("Profile name is empty") );
            return false;
        }

        QStringList profiles;
        profiles += i18n("Very low");
        profiles += i18n("Low");
        profiles += i18n("Medium");
        profiles += i18n("High");
        profiles += i18n("Very high");
        profiles += i18n("Lossless");
        profiles += i18n("Hybrid");
        profiles += i18n("Last used");
        profiles += "Last used";
        profiles += i18n("User defined");
        if( !lastUsed )
            profiles += "soundkonverter_last_used";

        if( profiles.contains(profileName) )
        {
            KMessageBox::information( this, i18n("You cannot overwrite the built-in profiles."), i18n("Profile already exists") );
            return false;
        }

        QDomDocument list("soundkonverter_profilelist");
        QDomElement root;
        bool profileFound = false;

        QFile listFile( KStandardDirs::locateLocal("data","soundkonverter/profiles.xml") );
        if( listFile.open( QIODevice::ReadOnly ) )
        {
            if( list.setContent( &listFile ) )
            {
                root = list.documentElement();
                if( root.nodeName() == "soundkonverter" && root.attribute("type") == "profilelist" )
                {
                    QDomNodeList conversionOptionsElements = root.elementsByTagName("conversionOptions");
                    for( int i=0; i<conversionOptionsElements.count(); i++ )
                    {
                        if( conversionOptionsElements.at(i).toElement().attribute("profileName") == profileName )
                        {
                            int ret;
                            if( lastUsed )
                                ret = KMessageBox::Yes;
                            else
                                ret = KMessageBox::questionYesNo( this, i18n("A profile with this name already exists.\n\nDo you want to overwrite the existing one?"), i18n("Profile already exists") );

                            if( ret == KMessageBox::Yes )
                            {
                                ConversionOptions *conversionOptions = currentConversionOptions( false );
                                delete config->data.profiles[profileName];
                                config->data.profiles[profileName] = conversionOptions;
                                root.removeChild(conversionOptionsElements.at(i));
                                QDomElement profileElement = conversionOptions->toXml(list);
                                profileElement.setAttribute("profileName",profileName);
                                root.appendChild(profileElement);
                                profileFound = true;
                                break;
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                }
            }
            listFile.close();
        }

        if( listFile.open( QIODevice::WriteOnly ) )
        {
            if( list.childNodes().isEmpty() )
            {
                root = list.createElement("soundkonverter");
                root.setAttribute("type","profilelist");
                list.appendChild(root);
            }

            if( !profileFound )
            {
                ConversionOptions *conversionOptions = currentConversionOptions( false );
                config->data.profiles[profileName] = conversionOptions;
                QDomElement profileElement = conversionOptions->toXml(list);
                profileElement.setAttribute("profileName",profileName);
                root.appendChild(profileElement);
            }

            updateProfiles();
            emit customProfilesEdited();

            QTextStream stream(&listFile);
            stream << list.toString();
            listFile.close();

            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}