void FileNameSearchProtocol::searchDirectory(const KUrl& directory)
{
    // Don't try to iterate the pseudo filesystem directories of Linux
    if (directory.path() == QLatin1String("/dev")
        || directory.path() == QLatin1String("/proc")
        || directory.path() == QLatin1String("/sys")) {
        return;
    }

    // Get all items of the directory
    KDirLister *dirLister = new KDirLister();
    dirLister->setDelayedMimeTypes(false);
    dirLister->setAutoErrorHandlingEnabled(false, 0);
    dirLister->openUrl(directory);

    QEventLoop eventLoop;
    QObject::connect(dirLister, SIGNAL(canceled()), &eventLoop, SLOT(quit()));
    QObject::connect(dirLister, SIGNAL(completed()), &eventLoop, SLOT(quit()));
    eventLoop.exec();

    // Visualize all items that match the search pattern
    QList<KUrl> pendingDirs;
    const KFileItemList items = dirLister->items();
    foreach (const KFileItem& item, items) {
        bool addItem = false;
        if (!m_regExp || item.name().contains(*m_regExp)) {
            addItem = true;
            if (!m_checkType.isEmpty()) {
                addItem = false;
                const QStringList types = m_checkType.split(";");
                const KSharedPtr<KMimeType> mime = item.determineMimeType();
                foreach (const QString& t, types) {
                    if (mime->is(t)) {
                        addItem = true;
                    }
                }
            }
Exemplo n.º 2
0
void StackFolder::init()
{
    connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()), SLOT(fontSettingsChanged()));
    connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(themeChanged()));
    m_previewPlugins      = QStringList() << "ffmpegthumbs"         // Video
                      << "imagethumbnail"           // Image
                      << "jpegthumbnail"            // Jpeg
                      << "svgthumbnail"             // Svg
                      << "windowsimagethumbnail"    // Windows images
                      << "gsthumbnail";             // PostScript, PDF, DVI
                      // << "djvuthumbnail"         // DjVu
                      // << "textthumbnail"         // Text
                      // << "opendocumentthumbnail" // ODF (OpenDocument Format)
                      // << "exrthumbnail"          // EXR images
                      // << "comicbookthumbnail"    // Comic books
                      // << "rawthumbnail"          // RAW
                      // << "windowsexethumbnail"   // Microsoft Windows exec
                      // << "desktopthumbnail"      // Desktop
                      // << "fontthumbnail"         // Fonts
                      // << "htmlthumbnail"         // HTML
                      // << "mobithumbnail"         // Mobipocket
                      // << "webarchivethumbnail"   // Web archives
                      // << "directorythumbnail"    // Directories
    m_sortDirsFirst       = true;
    m_sortColumn          = int(DirModel::Name);
    m_filterType          = 0;
    m_hideForChangeFolder = true;

    m_model->setFilterMode(ProxyModel::filterModeFromInt(m_filterType));
    m_model->setSortDirectoriesFirst(m_sortDirsFirst);
    m_model->setDynamicSortFilter(m_sortColumn != -1);
    m_model->sort(m_sortColumn != -1 ? m_sortColumn : DirModel::Name, Qt::AscendingOrder);

    KDirLister *lister = new DirLister(this);
    lister->setDelayedMimeTypes(true);
    lister->setAutoErrorHandlingEnabled(false, 0);

    m_dirModel->setDirLister(lister);
    connect(lister, SIGNAL(completed(const KUrl&)), SLOT(folderChanged(const KUrl&)));

    if (!m_url.isValid()) {
        QString path = QDir::homePath();
        m_url = config().readEntry("url", KUrl(path));
        QDir dir(m_url.path());
        if (!dir.exists()) {
            m_url = KUrl(path);
        }
    } else {
        config().writeEntry("url", m_url);
    }

    m_topUrl = m_url;

    QProcess proc;
    proc.start( QString::fromLatin1("xdg-user-dir"), QStringList() << QString::fromLatin1("DOWNLOAD") );
    if (proc.waitForStarted() && proc.waitForFinished()) {
        m_downloadUrl = KUrl(QString::fromLocal8Bit(proc.readAll()).trimmed());
    }
    else {
        m_downloadUrl = KUrl();
    }

    m_firstChangings = 0;
    m_folderChanging = false;
    m_needShow = false;
    m_hoverShow =  false;
    m_hoverState =  false;
}