Ejemplo n.º 1
0
void MainWindow::slotSaveScript() {
    if (currentSession() && currentSession()->emulationHandler()->isRecording()) {
        QMap<QString, QStringList> map;
        QStringList text;
        text << "text/plain";
        map.insert(tr("Script"), text );
        QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
        if (!filename.isEmpty()) {
            QFileInfo info(filename);
            if (info.extension(FALSE) != "script")
                filename += ".script";
            DocLnk nf;
            nf.setType("text/plain");
            nf.setFile(filename);
            nf.setName(info.fileName());
            FileManager fm;
            fm.saveFile(nf, currentSession()->emulationHandler()->script()->script());
            currentSession()->emulationHandler()->clearScript();
            m_saveScript->setEnabled(false);
            m_recordScript->setEnabled(true);
            populateScripts();
        }
    }
}
Ejemplo n.º 2
0
/*!
  prompted save */
bool TextEdit::saveAs()
{
    odebug << "saveAsFile " + currentFileName << oendl;

    QString rt = editor->text();
    odebug << currentFileName << oendl;

    QString docname;
    if( currentFileName.isEmpty()
        || currentFileName == tr("Unnamed")
        || currentFileName == tr("Text Editor"))
    {
        odebug << "do silly TT filename thing" << oendl;
        QString pt = rt.simplifyWhiteSpace();
        int i = pt.find( ' ' );
        docname = pt;
        if ( i > 0 )
            docname = pt.left( i );

        while( docname.startsWith( "." ) )
            docname = docname.mid( 1 );
        docname.replace( QRegExp("/"), "_" );
        // Cut the length. Filenames longer than 40 are not helpful
        // and something goes wrong when they get too long.
        if ( docname.length() > 40 ) docname = docname.left(40);

        if ( docname.isEmpty() ) docname = tr("Unnamed");
    }

    QMap<QString, QStringList> map;
    map.insert(tr("All"), QStringList() );
    QStringList text;
    text << "text/*";
    map.insert(tr("Text"), text );
    text << "*";
    map.insert(tr("All"), text );

    QFileInfo cuFi( docname);
    QString filee = cuFi.fileName();
    QString dire = cuFi.dirPath();
    if(dire==".")
        dire = QPEApplication::documentDir();

    QString str;
    if( !featureAutoSave) {
        str = OFileDialog::getSaveFileName( 2, dire, filee, map);
        if(!str.isEmpty() && QFile::exists(str)) {
            switch ( QMessageBox::warning(this,tr("Text Editor"),tr("<p>The selected file already exists. Overwrite it?</p>"),tr("Overwrite"),tr("Cancel"),0,1) ) {
            case 0: //Overwrite
                break;
            case 1: //Cancel
                return false;
                break;
            }
        }
    }
    else
        str = docname;

    if(!str.isEmpty()) {
        QString fileNm=str;

        odebug << "saving filename "+fileNm << oendl;
        QFileInfo fi(fileNm);
        currentFileName=fi.fileName();
        if(doc)
            delete doc;

        DocLnk nf;
        nf.setType("text/plain");
        nf.setFile( fileNm);
        doc = new DocLnk(nf);
        odebug << "Saving file as " << currentFileName << oendl;
        doc->setName( fi.baseName() );

        FileManager fm;
        if ( !fm.saveFile( *doc, rt ) ) {
            QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
            return false;
        }

        if( filePerms ) {
            filePermissions *filePerm;
            filePerm = new filePermissions(this, tr("Permissions"),true, 0,
                                           (const QString &)fileNm);
            QPEApplication::execDialog( filePerm );

            delete  filePerm;
        }
        updateCaption();
        resetEditStatus();
        if(caption().left(1)=="*")
            setCaption(caption().right(caption().length()-1));
        checkEnableDelete();

        return true;
    }
    odebug << "returning false" << oendl;
    return false;
} //end saveAs
Ejemplo n.º 3
0
/*!
  unprompted save */
bool TextEdit::save()
{
    QString name, file;
    odebug << "saveAsFile " + currentFileName << oendl;
    if(currentFileName.isEmpty()) {
        return saveAs();
    }
    if(doc) {
        file = doc->file();
        odebug << "saver file "+file << oendl;
        name = doc->name();
        odebug << "File named "+name << oendl;
    } else {
        file = currentFileName;
        name = QFileInfo(currentFileName).baseName();
    }

    QString rt = editor->text();
    if( !rt.isEmpty() ) {
        if(name.isEmpty())
            saveAs();
        else {
            currentFileName = name;
            odebug << "saveFile "+currentFileName << oendl;

            if(doc) {
                int docFd;
                // Save file permissions
                struct stat buf;
                mode_t mode;
                bool setmode = true;
                if((docFd = open(file, 0)) < 0)
                    setmode = false;

                if(setmode) {
                    if (fstat(docFd, &buf)) {
                        ::close(docFd);
                        setmode = false;
                    }
                    else
                        mode = buf.st_mode;
                }

                doc->setName(name);
                FileManager fm;
                if ( !fm.saveFile( *doc, rt ) ) {
                    QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
                    return false;
                }

                // Restore file permissions
                if(setmode) {
                    fchmod(docFd, mode);
                    ::close(docFd);
                }
            } else {
                odebug << "regular save file" << oendl;
                QFile f(file);
                if( f.open(IO_WriteOnly)) {
                    QCString crt = rt.utf8();
                    f.writeBlock(crt,crt.length());
                } else {
                    QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
                    return false;
                }
            }
            resetEditStatus();
            if(caption().left(1)=="*")
                setCaption(caption().right(caption().length()-1));
        }
        return true;
    }
    return false;
}