Esempio n. 1
0
void VDirectoryTree::openDirectoryLocation() const
{
    QTreeWidgetItem *curItem = currentItem();
    V_ASSERT(curItem);
    QUrl url = QUrl::fromLocalFile(getVDirectory(curItem)->fetchBasePath());
    QDesktopServices::openUrl(url);
}
Esempio n. 2
0
QString VConfigManager::getConfigFolder() const
{
    V_ASSERT(userSettings);

    QString iniPath = userSettings->fileName();
    return VUtils::basePathFromPath(iniPath);
}
Esempio n. 3
0
void VNotebookSelector::showNavigation()
{
    if (!isVisible()) {
        return;
    }

    V_ASSERT(!m_naviLabel);
    m_naviLabel = new QLabel(m_majorKey, this);
    m_naviLabel->setStyleSheet(g_vnote->getNavigationLabelStyle(m_majorKey));
    m_naviLabel->show();
}
Esempio n. 4
0
bool VNoteFile::sortAttachments(const QVector<int> &p_sortedIdx)
{
    V_ASSERT(m_opened);
    V_ASSERT(p_sortedIdx.size() == m_attachments.size());

    auto ori = m_attachments;

    for (int i = 0; i < p_sortedIdx.size(); ++i) {
        m_attachments[i] = ori[p_sortedIdx[i]];
    }

    bool ret = true;
    if (!getDirectory()->updateFileConfig(this)) {
        qWarning() << "fail to reorder attachments in config" << p_sortedIdx;
        m_attachments = ori;
        ret = false;
    }

    return ret;
}
Esempio n. 5
0
QString VConfigManager::fetchDirConfigFilePath(const QString &p_path)
{
    QDir dir(p_path);
    QString fileName = c_dirConfigFile;

    if (dir.exists(c_obsoleteDirConfigFile)) {
        V_ASSERT(!dir.exists(c_dirConfigFile));
        if (!dir.rename(c_obsoleteDirConfigFile, c_dirConfigFile)) {
            fileName = c_obsoleteDirConfigFile;
        }
        qDebug() << "rename old directory config file:" << fileName;
    }

    QString filePath = QDir::cleanPath(dir.filePath(fileName));
    qDebug() << "use directory config file:" << filePath;
    return filePath;
}
Esempio n. 6
0
VBOOL VConsoleImp::startup(VCHAR *filename /* = VNULL */, VBOOL isFile /* = VFALSE */)
{
	if (isFile && VNULL != filename)
	{
		// 创建文件,强制输出到文件中
		mFile = new VFileAccess();
		VBOOL result = mFile->open(filename, IFileAccess::modeCreate|IFileAccess::modeWrite);
		if (!result)
		{
			return result;
		}
	}
	else
	{
		// 输出到console中,在windows是输出到output panel上
		V_ASSERT(VNULL == mFile);
	}

	return VTRUE;
}
Esempio n. 7
0
QString VConfigManager::getConfigFilePath() const
{
    V_ASSERT(userSettings);

    return userSettings->fileName();
}
Esempio n. 8
0
void VMdEditor::clearUnusedImages()
{
    QVector<ImageLink> images = VUtils::fetchImagesFromMarkdownFile(m_file,
                                                                    ImageLink::LocalRelativeInternal);

    QSet<QString> unusedImages;

    if (!m_insertedImages.isEmpty()) {
        for (int i = 0; i < m_insertedImages.size(); ++i) {
            const ImageLink &link = m_insertedImages[i];

            if (link.m_type != ImageLink::LocalRelativeInternal) {
                continue;
            }

            int j;
            for (j = 0; j < images.size(); ++j) {
                if (VUtils::equalPath(link.m_path, images[j].m_path)) {
                    break;
                }
            }

            // This inserted image is no longer in the file.
            if (j == images.size()) {
                unusedImages.insert(link.m_path);
            }
        }

        m_insertedImages.clear();
    }

    for (int i = 0; i < m_initImages.size(); ++i) {
        const ImageLink &link = m_initImages[i];

        V_ASSERT(link.m_type == ImageLink::LocalRelativeInternal);

        int j;
        for (j = 0; j < images.size(); ++j) {
            if (VUtils::equalPath(link.m_path, images[j].m_path)) {
                break;
            }
        }

        // Original local relative image is no longer in the file.
        if (j == images.size()) {
            unusedImages.insert(link.m_path);
        }
    }

    if (!unusedImages.isEmpty()) {
        if (g_config->getConfirmImagesCleanUp()) {
            QVector<ConfirmItemInfo> items;
            for (auto const & img : unusedImages) {
                items.push_back(ConfirmItemInfo(img,
                                                img,
                                                img,
                                                NULL));

            }

            QString text = tr("Following images seems not to be used in this note anymore. "
                              "Please confirm the deletion of these images.");

            QString info = tr("Deleted files could be found in the recycle "
                              "bin of this note.<br>"
                              "Click \"Cancel\" to leave them untouched.");

            VConfirmDeletionDialog dialog(tr("Confirm Cleaning Up Unused Images"),
                                          text,
                                          info,
                                          items,
                                          true,
                                          true,
                                          true,
                                          this);

            unusedImages.clear();
            if (dialog.exec()) {
                items = dialog.getConfirmedItems();
                g_config->setConfirmImagesCleanUp(dialog.getAskAgainEnabled());

                for (auto const & item : items) {
                    unusedImages.insert(item.m_name);
                }
            }
        }

        for (auto const & item : unusedImages) {
            bool ret = false;
            if (m_file->getType() == FileType::Note) {
                const VNoteFile *tmpFile = dynamic_cast<const VNoteFile *>((VFile *)m_file);
                ret = VUtils::deleteFile(tmpFile->getNotebook(), item, false);
            } else if (m_file->getType() == FileType::Orphan) {
                const VOrphanFile *tmpFile = dynamic_cast<const VOrphanFile *>((VFile *)m_file);
                ret = VUtils::deleteFile(tmpFile, item, false);
            } else {
                Q_ASSERT(false);
            }

            if (!ret) {
                qWarning() << "fail to delete unused original image" << item;
            } else {
                qDebug() << "delete unused image" << item;
            }
        }
    }

    m_initImages.clear();
}