bool DocLnkSearch::searchFile( AppLnk *app ) { if (!actionSearchInFiles->isOn()) return false; DocLnk *doc = (DocLnk*)app; bool found = false; if ( doc->type().contains( "text" ) ) { #ifdef NEW_OWAIT QString ouput = QObject::tr("searching %1").arg( doc->file() ); OWait( output ); #endif QFile f(doc->file()); if ( f.open(IO_ReadOnly) ) { QTextStream t( &f ); while ( !t.eof() ) { if (m_search.match( t.readLine()) != -1) { found = true; break; } } } f.close(); } return found; }
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); } }
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; }
void MainView::setDocument( const QString& applnk_filename ) { DocLnk *file = new DocLnk( applnk_filename ); location->setEditText( file->file() ); goClicked(); }
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(); }
void MainWindow::slotRunScript(int id) { if (currentSession()) { int index = m_scriptsPop->indexOf(id); DocLnk *lnk = m_scriptsData.at(index); QString filePath = lnk->file(); Script script(filePath); currentSession()->emulationHandler()->runScript(&script); } }
void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) { depth++; if ( depth > 10 ) return; QDir dir( dr ); /* Opie got a different approach * I guess it's geek vs. consumer * in this case to be discussed */ if ( dir.exists( ".Qtopia-ignore" ) ) return; const QFileInfoList *list = dir.entryInfoList(); if ( list ) { QFileInfo* fi; for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { QString bn = fi->fileName(); if ( bn[0] != '.' ) { if ( fi->isDir() ) { if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) findChildren(fi->filePath(), mimeFilters, reference, depth); } else { if ( fi->extension(FALSE) == "desktop" ) { DocLnk* dl = new DocLnk( fi->filePath() ); QFileInfo fi2(dl->file()); bool match = FALSE; if ( !fi2.exists() ) { dir.remove( dl->file() ); } if ( mimeFilters.count() == 0 ) { add( dl ); match = TRUE; } else { for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { if ( (*it).match(dl->type()) >= 0 ) { add(dl); match = TRUE; } } } if ( !match ) delete dl; } else { if ( !reference.find(fi->fileName()) ) reference.insert(fi->filePath(), (void*)2); } } } } } }
void DocumentList::sendAllDocLinks() { if ( d->tid != 0 ) { // We are in the middle of scanning, set a flag so // we do this when we finish our scanning d->needToSendAllDocLinks = true; return; } QString contents; Categories cats; for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { DocLnk *doc = it.current(); QFileInfo fi( doc->file() ); if ( !fi.exists() ) continue; bool fake = !doc->linkFileKnown(); if ( !fake ) { QFile f( doc->linkFile() ); if ( f.open( IO_ReadOnly ) ) { QTextStream ts( &f ); ts.setEncoding( QTextStream::UnicodeUTF8 ); QString docLnk = ts.read(); // Strip out the (stale) LinkFile entry int start = docLnk.find( "\nLinkFile = " ) + 1; if ( start > 0 ) { int end = docLnk.find( "\n", start + 1 ) + 1; contents += docLnk.left(start); contents += docLnk.mid(end); } else { contents += docLnk; } contents += "LinkFile = " + doc->linkFile() + "\n"; f.close(); } else fake = TRUE; } if (fake) { contents += "[Desktop Entry]\n"; // No tr contents += "Categories = " + // No tr cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr contents += "Name = "+doc->name()+"\n"; // No tr contents += "Type = "+doc->type()+"\n"; // No tr } contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) contents += QString("Size = %1\n").arg( fi.size() ); // No tr } //odebug << "sending length " << contents.length() << "" << oendl; #ifndef QT_NO_COP QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); e << contents; #endif //odebug << "================ \n\n" << contents << "\n\n===============" << oendl; d->needToSendAllDocLinks = false; }
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(); }
void GliderEditorNumPad::readPolarData() { // qDebug ("GliderEditorNumPad::readPolarData "); #warning "location of glider.pol file is CUMULUS_ROOT/etc" // try to read more polars from document folder // these files are in winpilot format: one file per polar DocLnkSet docs; Global::findDocuments(&docs, "cumulus/polar"); QList<DocLnk*> list = docs.children(); // qDebug ("found %d polars in document folder", list.count()); for (DocLnk* doc = list.first(); doc; doc = list.next()) { QString path = doc->file(); // qDebug ("Doc: %s", path.toLatin1().data()); QFile file (path); QTextStream stream(&file); if (file.open(IO_ReadOnly)) { QString glidertype = QFileInfo(file).baseName(); while (!stream.eof()) { QString line = stream.readLine(); // ignore comments if (line[0] == '*') continue; QStringList list = QStringList::split(',',line,TRUE); m_openGliderList->addItem (glidertype); // vertical speeds are already negative in these files ! Speed v1,w1,v2,w2,v3,w3; double maxgross = list [0].toDouble(); int maxwater = list [1].toInt(); v1.setKph(list[2].toDouble()); w1.setMps(list[3].toDouble()); v2.setKph(list[4].toDouble()); w2.setMps(list[5].toDouble()); v3.setKph(list[6].toDouble()); w3.setMps(list[7].toDouble()); pol=new Polar(this, glidertype,v1,w1,v2,w2,v3,w3,0.0,0.0,0.0,maxgross); pol->setMaxWater(maxwater); m_polars.append(pol); break; } } } }
void DocumentList::linkChanged( QString arg ) { odebug << "linkchanged( " << arg << " )" << oendl; if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { reloadAppLnks(); } else { const QList<DocLnk> &list = d->dls.children(); QListIterator<DocLnk> it( list ); while ( it.current() ) { DocLnk *doc = it.current(); ++it; if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) || ( doc->fileKnown() && doc->file() == arg ) ) { //odebug << "found old link" << oendl; DocLnk* dl = new DocLnk( arg ); // add new one if it exists and matches the mimetype if ( d->store( dl ) ) { // Existing link has been changed, send old link ref and a ref // to the new link //odebug << "change case" << oendl; if ( d->serverGui ) d->serverGui->documentChanged( *doc, *dl ); } else { // Link has been removed or doesn't match the mimetypes any more // so we aren't interested in it, so take it away from the list //odebug << "removal case" << oendl; if ( d->serverGui ) d->serverGui->documentRemoved( *doc ); } d->dls.remove( doc ); // remove old link from docLnkSet delete doc; return; } } // Didn't find existing link, must be new DocLnk* dl = new DocLnk( arg ); if ( d->store( dl ) ) { // Add if it's a link we are interested in //odebug << "add case" << oendl; add( *dl ); } } }
void Gutenbrowser::setDocument(const QString & frozenBoogers) { qWarning("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSET DOCUMENT\n"); if(showMainList) { showMainList=FALSE; if(!mainList->isHidden()) mainList->hide(); if(Lview->isHidden()) Lview->show(); qApp->processEvents(); } DocLnk lnk; lnk = DocLnk(frozenBoogers); qWarning("open "+frozenBoogers); title=lnk.comment(); if(!load( lnk.file())) return; this->show(); }
/*! 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; } } }
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(); } } }
void TextEdit::openFile( const DocLnk &f ) { // clear(); FileManager fm; QString txt; currentFileName=f.file(); odebug << "openFile doclnk " + currentFileName << oendl; if ( !fm.loadFile( f, txt ) ) { // ####### could be a new file odebug << "Cannot open file" << oendl; } if ( doc ) delete doc; doc = new DocLnk(f); editor->setText(txt); resetEditStatus(); doc->setName(currentFileName); updateCaption(); setTimer(); checkEnableDelete(); }
/*! 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
void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { m_lneEdit->setText( lnk.name() ); emit fileSelected( lnk ); emit fileSelected( lnk.name() ); }
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; }
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; }
/*! \overload Uses the DocLnk::file() and DocLnk::type() of \a doc. \sa done() */ void Ir::send( const DocLnk &doc, const QString &description ) { send( doc.file(), description, doc.type() ); }
void DocumentList::add( const DocLnk& doc ) { if ( d->serverGui && QFile::exists( doc.file() ) ) d->serverGui->documentAdded( doc ); }