示例#1
0
void MainWindow::slotSaveHistory() {
    QMap<QString, QStringList> map;
    QStringList text;
    text << "text/plain";
    map.insert(tr("History"), text );
    QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
    if (filename.isEmpty() ) return;

    QFileInfo info(filename);

    DocLnk nf;
    nf.setType("text/plain");
    nf.setFile(filename);
    nf.setName(info.fileName());


    QFile file(filename);
    if ( !file.open(IO_WriteOnly ) ) return;

    QTextStream str(&file );
    if ( currentSession() )
        currentSession()->emulationHandler()->emulation()->streamHistory(&str);

    file.close();
    nf.writeLink();
}
示例#2
0
bool LnkProperties::copyFile( DocLnk &newdoc )
{
    const char *linkExtn = ".desktop";
    QString fileExtn;
    int extnPos = lnk->file().findRev( '.' );
    if ( extnPos > 0 )
	fileExtn = lnk->file().mid( extnPos );

    QString safename = newdoc.name();
    safename.replace(QRegExp("/"),"_");

    QString fn = locations[ d->locationCombo->currentItem() ]
		  + "/Documents/" + newdoc.type();
    if (!createMimedir(locations[ d->locationCombo->currentItem() ],newdoc.type())) {
        return FALSE;
    }
    fn+="/"+safename;
    if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) {
	int n=1;
	QString nn = fn + "_" + QString::number(n);
	while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) {
	    n++;
	    nn = fn + "_" + QString::number(n);
	}
	fn = nn;
    }
    newdoc.setFile( fn + fileExtn );
    newdoc.setLinkFile( fn + linkExtn );

    // Copy file
    FileManager fm;
    if ( !fm.copyFile( *lnk, newdoc ) )
	return FALSE;
    return TRUE;
}
示例#3
0
void MainWindow::slotSaveLog() {
    if( currentSession()->emulationHandler()->isLogging() ) {
        DocLnk nf;
        QString m_logName = currentSession()->emulationHandler()->logFileName();
        QFileInfo info(m_logName);
        nf.setType("text/plain");
        nf.setFile(m_logName);
        nf.setName(info.fileName());
        nf.writeLink();
        m_recordLog->setText( tr("Start log") );
        m_recordingLog = false;
        currentSession()->emulationHandler()->clearLog();
    }
    else {
        QMap<QString, QStringList> map;
        QStringList text;
        text << "text/plain";
        map.insert(tr("Log"), text );
        Opie::Core::OConfig cfg("opie-console");
        cfg.setGroup("defaults");
        QString startDir = cfg.readEntry("defaultlogdir", QPEApplication::documentDir() );
        QString m_logName = OFileDialog::getSaveFileName(2, startDir, QString::null, map, 0, startDir);
        if (m_logName.isEmpty() )
            return;

        m_recordLog->setText( tr("Stop log") );
        m_recordingLog = true;
        currentSession()->emulationHandler()->startLogging(m_logName);
    }
}
示例#4
0
void TextEdit::openFile( const QString &f )
{
    odebug << "filename is "+ f << oendl;
    QString filer;
    QFileInfo fi( f);
    if(f.find(".desktop",0,true) != -1 && !openDesktop ) {
        switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) {
        case 0: //desktop
            filer = f;
            break;
        case 1: //linked
            DocLnk sf(f);
            filer = sf.file();
            break;
        };
    }
    else if(fi.baseName().left(1) == "") {
        odebug << "opening dotfile" << oendl;
        currentFileName=f;
        openDotFile(currentFileName);
        return;
    }
    /*
     * The problem is a file where Config(f).isValid() and it does not
     * end with .desktop will be treated as desktop file
     */
    else if (f.find(".desktop",0,true) != -1 ) {
        DocLnk sf(f);
        filer = sf.file();
        if(filer.right(1) == "/")
            filer = f;
    }
    else
        filer = f;

    DocLnk nf;
    nf.setType("text/plain");
    nf.setFile(filer);
    currentFileName=filer;

    nf.setName(fi.baseName());
    openFile(nf);

    odebug << "openFile string "+currentFileName << oendl;

    showEditTools();
    // Show filename in caption
    updateCaption();
    checkEnableDelete();
}
示例#5
0
/*!
  Constructs a DocLnkSet that contains DocLnk objects representing all
  the files in the \a directory (and any subdirectories, recursively).

  If \a mimefilter is not null,
  only documents with a MIME type matching \a mimefilter are selected.
  The value may contain multiple wild-card patterns separated by ";",
  such as \c{*o/mpeg;audio/x-wav}.

  See also \link applnk.html#files-and-links Files and Links\endlink.

*/
DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) :
    AppLnkSet()
{
    QDir dir( directory );
    mFile = dir.dirName();
    QDict<void> reference(1021);

    QStringList subFilter = QStringList::split(";", mimefilter);
    QValueList<QRegExp> mimeFilters;
    for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it )
  mimeFilters.append( QRegExp(*it, FALSE, TRUE) );

    findChildren(directory, mimeFilters, reference);

    const QList<DocLnk> &list = children();
    for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
  reference.remove( (*it)->file() );
    }
    for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) {
  if ( dit.current() == (void*)2 ) {
      // Unreferenced, make an unwritten link
      DocLnk* dl = new DocLnk;
      QFileInfo fi( dit.currentKey() );
      dl->setFile(fi.filePath());
      dl->setName(fi.baseName());
      // #### default to current path?
      // dl->setCategories( ... );
      bool match = mimefilter.isNull();
      if ( !match )
    for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it )
        if ( (*it).match(dl->type()) >= 0 )
      match = TRUE;
      if ( match /* && dl->type() != "application/octet-stream" */
        && !!dl->exec() )
    add(dl);
      else
    delete dl;
  }
    }
}
示例#6
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();
        }
    }
}
示例#7
0
bool VMemo::startRecording()
{
    QString date = TimeString::dateString( QDateTime::currentDateTime(),false,true);
    date.replace(QRegExp("'"),"");
    date.replace(QRegExp(" "),"_");
    date.replace(QRegExp(":"),"-");
    date.replace(QRegExp(","),"");

    if( m_useAlerts ) {
        setupStatusWidget( "vm_"+ date ); // no tr
    }
    else {
        m_statusWidget = 0;
        m_timeLabel = 0;
    }

    Config config( "Vmemo" );
    config.setGroup( "System" );
    QString fileName = config.readEntry("RecLocation", QPEApplication::documentDir() );

    int s;
    s=fileName.find(':');
    if(s)
        fileName=fileName.right(fileName.length()-s-2);
    odebug << "pathname will be "+fileName << oendl;

    if( fileName.left(1).find('/') == -1)
        fileName="/"+fileName;
    if( fileName.right(1).find('/') == -1)
        fileName+="/";

    fileName += "vm_"+ date + ".wav";
    odebug << "filename is " + fileName << oendl;

    if( !m_recorder.setup( fileName, m_fileparams ) ) {
        QMessageBox::critical(0, "vmemo", "Could not start recording", "Abort");
        return false;
    }

    if( m_maxseconds > 0 || m_statusWidget )
        t_timer->start( 1000 );

    // FIXME error checking!
    m_elapsedseconds = 0;
    recording = true;
    repaint();
    m_recorder.record( this );

    QArray<int> cats(1);
    cats[0] = config.readNumEntry("Category", 0);

    QString dlName("vm_");
    dlName += date;
    DocLnk l;
    l.setFile(fileName);
    l.setName(dlName);
    l.setType("audio/x-wav");
    l.setCategories(cats);
    l.writeLink();
    return true;
}
示例#8
0
const DocLnk *DocumentListPrivate::iterate()
{
    if ( state == Find ) {
    //odebug << "state Find" << oendl;
    QString file = nextFile();
    while ( !file.isNull() ) {
        if ( file.right(8) == ".desktop" ) { // No tr
        DocLnk* dl = new DocLnk( file );
        if ( store(dl) )
            return dl;
        } else {
        reference.insert( file, MAGIC_NUMBER );
        }
        file = nextFile();
    }
    state = RemoveKnownFiles;

    if ( serverGui )
        serverGui->documentScanningProgress( 75 );
    }

    static int iterationI;
    static int iterationCount;

    if ( state == RemoveKnownFiles ) {
    //odebug << "state RemoveKnownFiles" << oendl;
    const QList<DocLnk> &list = dls.children();
    for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
        reference.remove( (*it)->file() );
        // ### does this need to be deleted?
    }
    dit = new QDictIterator<void>(reference);
    state = MakeUnknownFiles;

    iterationI = 0;
    iterationCount = dit->count();
    }

    if ( state == MakeUnknownFiles ) {
    //odebug << "state MakeUnknownFiles" << oendl;
    for (void* c; (c=dit->current()); ++(*dit) ) {
        if ( c == MAGIC_NUMBER ) {
        DocLnk* dl = new DocLnk;
        QFileInfo fi( dit->currentKey() );
        dl->setFile( fi.filePath() );
        dl->setName( fi.baseName() );
        if ( store(dl) ) {
            ++*dit;
            iterationI++;
            if ( serverGui )
            serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount );
            return dl;
        }
        }
        iterationI++;
    }

    delete dit;
    dit = 0;
    state = Done;
    }

    //odebug << "state Done" << oendl;
    return NULL;
}
示例#9
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