[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Error using storedPut to save text to files
From:       Stephen Kelly <steveire () gmail ! com>
Date:       2007-12-10 2:01:14
Message-ID: fji6la$t9a$1 () ger ! gmane ! org
[Download RAW message or body]

Thanks to irc dwellers and richmoore for help with this. It was solved by
changing the save function to:

bool MainWindow::saveText()
{
//     KUrl url = KFileDialog::getSaveUrl();
    KUrl url = KUrl("file:/home/kde-devel/test");
    QByteArray data;
    data += ui.messageText->toPlainText();

    if ( KIO::NetAccess::exists( url, KIO::NetAccess::DestinationSide, 0 ) )
{
        const QString title = i18n( "File Exists" );
        const QString text = i18n( "<qt>Do you really want to overwrite
<b>%1</b>?</qt>" , url.prettyUrl());
qDebug() << url.path();
        if (KMessageBox::Continue != KMessageBox::warningContinueCancel( 0,
text, title, KGuiItem(i18n("Overwrite")) ) )
        {
            return false;
        }
    }

    bool ok = false;

    if ( url.isLocalFile() ) {
        KSaveFile saveFile( url.path() );
        if ( saveFile.open() ) {
            saveFile.write(data);
            if ( saveFile.finalize() ){
                ok = true;
            }
        }
    }
    else
    {
        KTemporaryFile tmpFile;
        if ( tmpFile.open() ) {
            tmpFile.write(data);
            if ( KIO::NetAccess::upload( tmpFile.fileName(), url, 0 ) )
            {
                ok = true;
            }
        }
    }

    QApplication::restoreOverrideCursor();
    if ( !ok ) {
        kWarning() << "Unable to save the file" ;

        QString caption = i18n("Unable to save file");
        QString text = i18n("Unable to save the file to\n%1.",
url.prettyUrl());
        KMessageBox::error(0, text, caption);
    }

    return ok;
}



 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic