コード例 #1
0
ファイル: lnkproperties.cpp プロジェクト: opieproject/opie
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;
}
コード例 #2
0
ファイル: doclnksearch.cpp プロジェクト: opieproject/opie
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;
}
コード例 #3
0
ファイル: documentlist.cpp プロジェクト: opieproject/opie
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;
}
コード例 #4
0
ファイル: applnk.cpp プロジェクト: opieproject/opie
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);
        }
    }
      }
  }
    }
}
コード例 #5
0
ファイル: applnk.cpp プロジェクト: opieproject/opie
/*!
  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
ファイル: ir.cpp プロジェクト: opieproject/opie
/*!
  \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() );
}