Example #1
0
void VDirectoryTree::buildSubTree(QTreeWidgetItem *p_parent, int p_depth)
{
    if (p_depth == 0) {
        return;
    }

    Q_ASSERT(p_parent);

    VDirectory *dir = getVDirectory(p_parent);
    if (!dir->open()) {
        VUtils::showMessage(QMessageBox::Warning,
                            tr("Warning"),
                            tr("Fail to open folder <span style=\"%1\">%2</span>.")
                              .arg(g_config->c_dataTextStyle)
                              .arg(dir->getName()),
                            tr("Please check if directory <span style=\"%1\">%2</span> exists.")
                              .arg(g_config->c_dataTextStyle)
                              .arg(dir->fetchPath()),
                            QMessageBox::Ok,
                            QMessageBox::Ok,
                            this);
        return;
    }

    if (p_parent->childCount() > 0) {
        // This directory has been built before. Try its children directly.
        int cnt = p_parent->childCount();
        for (int i = 0; i < cnt; ++i) {
            buildSubTree(p_parent->child(i), p_depth -1);
        }
    } else {
        const QVector<VDirectory *> &subDirs = dir->getSubDirs();
        for (int i = 0; i < subDirs.size(); ++i) {
            VDirectory *subDir = subDirs[i];
            QTreeWidgetItem *item = new QTreeWidgetItem(p_parent);
            fillTreeItem(item, subDir);
            buildSubTree(item, p_depth - 1);
        }
    }

    if (dir->isExpanded()) {
        expandItem(p_parent);
    }
}
Example #2
0
void VDirectoryTree::updateDirectoryTree()
{
    clear();

    VDirectory *rootDir = m_notebook->getRootDir();
    const QVector<VDirectory *> &subDirs = rootDir->getSubDirs();
    for (int i = 0; i < subDirs.size(); ++i) {
        VDirectory *dir = subDirs[i];
        QTreeWidgetItem *item = new QTreeWidgetItem(this);

        fillTreeItem(item, dir);

        buildSubTree(item, 1);
    }

    if (!restoreCurrentItem() && topLevelItemCount() > 0) {
        setCurrentItem(topLevelItem(0));
    }
}
Example #3
0
bool VListFolderUE::listFolder(const QString &p_path, const QString &p_cmd)
{
    VDirectory *dir = g_vnote->getInternalDirectory(p_path);
    if (!dir) {
        // See if it is a notebook.
        VNotebook *nb = g_vnote->getNotebook(p_path);
        if (!nb) {
            return false;
        }

        dir = nb->getRootDir();
    }

    m_panel->clearTitle();
    m_listWidget->clearAll();
    m_data.clear();

    m_currentFolderPath = dir->fetchPath();
    m_panel->setTitle(m_currentFolderPath);

    if (!dir->open()) {
        return true;
    }

    if (p_cmd.isEmpty()) {
        // List the content.
        for (auto const & it : dir->getSubDirs()) {
            QSharedPointer<VSearchResultItem> item(new VSearchResultItem(VSearchResultItem::Folder,
                                                                         VSearchResultItem::LineNumber,
                                                                         it->getName(),
                                                                         it->fetchPath()));
            addResultItem(item);
        }

        for (auto const & file : dir->getFiles()) {
            QSharedPointer<VSearchResultItem> item(new VSearchResultItem(VSearchResultItem::Note,
                                                                         VSearchResultItem::LineNumber,
                                                                         file->getName(),
                                                                         file->fetchPath()));
            addResultItem(item);
        }
    } else {
        // Search the content.
        VSearchConfig config(VSearchConfig::CurrentFolder,
                             VSearchConfig::Name,
                             VSearchConfig::Note | VSearchConfig::Folder,
                             VSearchConfig::Internal,
                             VSearchConfig::NoneOption,
                             p_cmd,
                             QString());

        for (auto const & it : dir->getSubDirs()) {
            QString name = it->getName();
            if (!config.m_token.matched(name)) {
                continue;
            }

            QSharedPointer<VSearchResultItem> item(new VSearchResultItem(VSearchResultItem::Folder,
                                                                         VSearchResultItem::LineNumber,
                                                                         name,
                                                                         it->fetchPath()));
            addResultItem(item);
        }

        for (auto const & file : dir->getFiles()) {
            QString name = file->getName();
            if (!config.m_token.matched(name)) {
                continue;
            }

            QSharedPointer<VSearchResultItem> item(new VSearchResultItem(VSearchResultItem::Note,
                                                                         VSearchResultItem::LineNumber,
                                                                         name,
                                                                         file->fetchPath()));
            addResultItem(item);
        }
    }

    return true;
}