예제 #1
0
QStringList KRecentDocument::recentDocuments()
{
    QDir d(recentDocumentDirectory(), QStringLiteral("*.desktop"), QDir::Time,
           QDir::Files | QDir::Readable | QDir::Hidden);

    if (!d.exists()) {
        d.mkdir(recentDocumentDirectory());
    }

    const QStringList list = d.entryList();
    QStringList fullList;

    for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
        QString fileName = *it;
        QString pathDesktop;
        if (fileName.startsWith(QLatin1String(":"))) {
            // See: https://bugreports.qt.io/browse/QTBUG-11223
            pathDesktop = KRecentDocument::recentDocumentDirectory() + *it;
        } else {
            pathDesktop = d.absoluteFilePath(*it);
        }
        KDesktopFile tmpDesktopFile(pathDesktop);
        QUrl urlDesktopFile(tmpDesktopFile.desktopGroup().readPathEntry("URL", QString()));
        if (urlDesktopFile.isLocalFile() && !QFile(urlDesktopFile.toLocalFile()).exists()) {
            d.remove(pathDesktop);
        } else {
            fullList.append(pathDesktop);
        }
    }

    return fullList;
}
예제 #2
0
TQStringList TDERecentDocument::recentDocuments()
{
    TQDir d(recentDocumentDirectory(), "*.desktop", TQDir::Time,
           TQDir::Files | TQDir::Readable | TQDir::Hidden);

    if (!d.exists())
        d.mkdir(recentDocumentDirectory());

    TQStringList list = d.entryList();
    TQStringList fullList;

    for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
       TQString pathDesktop = d.absFilePath( *it );
       KDesktopFile tmpDesktopFile( pathDesktop, false);
       KURL urlDesktopFile(tmpDesktopFile.readURL());
       if( urlDesktopFile.isLocalFile() && !TQFile(urlDesktopFile.path()).exists())
           d.remove(pathDesktop);
       else
           fullList.append( pathDesktop );
    }

    return fullList;
}
예제 #3
0
void KRecentDocument::add(const QUrl &url, const QString &desktopEntryName)
{
    if (url.isLocalFile() && url.toLocalFile().startsWith(QDir::tempPath())) {
        return;    // inside tmp resource, do not save
    }

    QString openStr = url.toDisplayString();
    openStr.replace(QRegExp(QStringLiteral("\\$")), QStringLiteral("$$"));   // Desktop files with type "Link" are $-variable expanded

    // qDebug() << "KRecentDocument::add for " << openStr;
    KConfigGroup config = KSharedConfig::openConfig()->group(QByteArray("RecentDocuments"));
    bool useRecent = config.readEntry(QStringLiteral("UseRecent"), true);
    int maxEntries = config.readEntry(QStringLiteral("MaxEntries"), 10);

    if (!useRecent || maxEntries <= 0) {
        return;
    }

    const QString path = recentDocumentDirectory();
    const QString fileName = url.fileName();
    // don't create a file called ".desktop", it will lead to an empty name in kio_recentdocuments
    const QString dStr = path + (fileName.isEmpty() ? QStringLiteral("unnamed") : fileName);

    QString ddesktop = dStr + QLatin1String(".desktop");

    int i = 1;
    // check for duplicates
    while (QFile::exists(ddesktop)) {
        // see if it points to the same file and application
        KDesktopFile tmp(ddesktop);
        if (tmp.desktopGroup().readPathEntry("URL", QString()) == url.toDisplayString()
                && tmp.desktopGroup().readEntry("X-KDE-LastOpenedWith") == desktopEntryName) {
            // Set access and modification time to current time
            ::utime(QFile::encodeName(ddesktop).constData(), NULL);
            return;
        }
        // if not append a (num) to it
        ++i;
        if (i > maxEntries) {
            break;
        }
        ddesktop = dStr + QStringLiteral("[%1].desktop").arg(i);
    }

    QDir dir(path);
    // check for max entries, delete oldest files if exceeded
    const QStringList list = dir.entryList(QDir::Files | QDir::Hidden, QFlags<QDir::SortFlag>(QDir::Time | QDir::Reversed));
    i = list.count();
    if (i > maxEntries - 1) {
        QStringList::ConstIterator it;
        it = list.begin();
        while (i > maxEntries - 1) {
            QFile::remove(dir.absolutePath() + QLatin1String("/") + (*it));
            --i, ++it;
        }
    }

    // create the applnk
    KDesktopFile configFile(ddesktop);
    KConfigGroup conf = configFile.desktopGroup();
    conf.writeEntry("Type", QStringLiteral("Link"));
    conf.writePathEntry("URL", openStr);
    // If you change the line below, change the test in the above loop
    conf.writeEntry("X-KDE-LastOpenedWith", desktopEntryName);
    conf.writeEntry("Name", url.fileName());
    conf.writeEntry("Icon", KIO::iconNameForUrl(url));
}
예제 #4
0
void TDERecentDocument::add(const KURL& url, const TQString& desktopEntryName)
{
	if ( url.isLocalFile() && !TDEGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/"))
		return;

    TQString openStr = url.url();
    openStr.replace( TQRegExp("\\$"), "$$" ); // Desktop files with type "Link" are $-variable expanded

    kdDebug(250) << "TDERecentDocument::add for " << openStr << endl;
    TDEConfig *config = TDEGlobal::config();
    TQString oldGrp = config->group();
    config->setGroup(TQString::fromLatin1("RecentDocuments"));
    bool useRecent = config->readBoolEntry(TQString::fromLatin1("UseRecent"), true);
    int maxEntries = config->readNumEntry(TQString::fromLatin1("MaxEntries"), 10);

    config->setGroup(oldGrp);
    if(!useRecent)
        return;

    TQString path = recentDocumentDirectory();

    TQString dStr = path + url.fileName();

    TQString ddesktop = dStr + TQString::fromLatin1(".desktop");

    int i=1;
    // check for duplicates
    while(TQFile::exists(ddesktop)){
        // see if it points to the same file and application
        KSimpleConfig tmp(ddesktop);
        tmp.setDesktopGroup();
        if(tmp.readEntry(TQString::fromLatin1("X-TDE-LastOpenedWith"))
	   == desktopEntryName)
	{
            utime(TQFile::encodeName(ddesktop), NULL);
            return;
        }
        // if not append a (num) to it
        ++i;
        if ( i > maxEntries )
            break;
        ddesktop = dStr + TQString::fromLatin1("[%1].desktop").arg(i);
    }

    TQDir dir(path);
    // check for max entries, delete oldest files if exceeded
    TQStringList list = dir.entryList(TQDir::Files | TQDir::Hidden, TQDir::Time | TQDir::Reversed);
    i = list.count();
    if(i > maxEntries-1){
        TQStringList::Iterator it;
        it = list.begin();
        while(i > maxEntries-1){
            TQFile::remove(dir.absPath() + TQString::fromLatin1("/") + (*it));
            --i, ++it;
        }
    }

    // create the applnk
    KSimpleConfig conf(ddesktop);
    conf.setDesktopGroup();
    conf.writeEntry( TQString::fromLatin1("Type"), TQString::fromLatin1("Link") );
    conf.writePathEntry( TQString::fromLatin1("URL"), openStr );
    // If you change the line below, change the test in the above loop
    conf.writeEntry( TQString::fromLatin1("X-TDE-LastOpenedWith"), desktopEntryName );
    TQString name = url.fileName();
    if (name.isEmpty())
      name = openStr;
    conf.writeEntry( TQString::fromLatin1("Name"), name );
    conf.writeEntry( TQString::fromLatin1("Icon"), KMimeType::iconForURL( url ) );
}