コード例 #1
0
ファイル: commandmanager.cpp プロジェクト: Guid75/showdevant
Command *CommandManager::pushCommand(const QString &path, const QString &cmd, const QVariantMap &arguments)
{
	Q_ASSERT(nam != NULL);

	QString normPath(path);

	// ensure the path is normalized (with starting and ending slashes)
	if (normPath.length() > 0) {
		if (!normPath.startsWith('/'))
			normPath.prepend('/');
		if (!normPath.endsWith('/'))
			normPath.append('/');
	}

	QUrlQuery query;

	foreach (const QString &key, arguments.keys()) {
		query.addQueryItem(key, arguments[key].toString());
	}

	// add some application and authentication keys
	query.addQueryItem("key", apiKey);
	if (!authToken.isEmpty())
		query.addQueryItem("token", authToken);

	QUrl url(QString("%1%2%3.json").arg(websiteUrl).arg(normPath).arg(cmd));
	url.setQuery(query);

	QNetworkRequest request(url);
	request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);

	QNetworkReply *reply = nam->get(request);
	Command *command = new Command(this);
	commands.insert(reply, command);

	connect(reply, &QNetworkReply::finished, this, &CommandManager::httpFinished);
	connect(reply, &QNetworkReply::readyRead, this, &CommandManager::httpReadyRead);
	connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &CommandManager::httpError);

	return command;
}
コード例 #2
0
ファイル: nutconfdoc.cpp プロジェクト: niziak/ethernut-4.9
/*!
 * \brief Create a document from a specified file.
 *
 * \param path Pathname of the configuration file.
 */
bool CNutConfDoc::OnCreate(const wxString & path, long flags)
{
    bool rc = false;
    wxString normPath(path);
    CSettings *cfg = wxGetApp().GetSettings();

    normPath.Replace(wxT("\\"), wxT("/"));
    cfg->m_configname = normPath;

    wxGetApp().m_currentDoc = this;

    /*
     * The repository may refer to certain configuration values. Thus, 
     * it must be loaded before reading the repository.
     */
    cfg->Load(cfg->m_configname);
    if ((rc = ReadRepository(cfg->m_repositoryname, normPath)) == true) {

        Modify(false);
        SetDocumentSaved(false);

        rc = wxDocument::OnCreate(path, flags);
        if (rc) {
            if (flags & wxDOC_NEW) {
                wxBusyCursor wait;

                CNutConfHint hint(NULL, nutSelChanged);
                UpdateAllViews(NULL, &hint);

                SetFilename(GetFilename(), true);
            }
        }
    }

    if(!rc) {
        wxGetApp().m_currentDoc = NULL;
    }
    return rc;
}
コード例 #3
0
ファイル: vsearch.cpp プロジェクト: getwindow/vnote
void VSearch::searchFirstPhase(const QString &p_basePath,
                               const QString &p_directoryPath,
                               const QSharedPointer<VSearchResult> &p_result)
{
    Q_ASSERT(testTarget(VSearchConfig::Note) || testTarget(VSearchConfig::Folder));
    Q_ASSERT(!p_directoryPath.isEmpty());

    QDir dir(p_directoryPath);
    if (!dir.exists()) {
        p_result->logError(QString("Directory %1 does not exist.").arg(p_directoryPath));
        p_result->m_state = VSearchState::Fail;
        return;
    }

    Q_ASSERT(dir.isAbsolute());

    if (testTarget(VSearchConfig::Folder)) {
        QString name = dir.dirName();
        if (testObject(VSearchConfig::Name)) {
            if (matchNonContent(name)) {
                VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
                                                                VSearchResultItem::LineNumber,
                                                                name,
                                                                p_directoryPath);
                QSharedPointer<VSearchResultItem> pitem(item);
                emit resultItemAdded(pitem);
            }
        }

        if (testObject(VSearchConfig::Path)) {
            QString normPath(QDir(p_basePath).relativeFilePath(p_directoryPath));
            removeSlashFromPath(normPath);
            if (matchNonContent(normPath)) {
                VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
                                                                VSearchResultItem::LineNumber,
                                                                name,
                                                                p_directoryPath);
                QSharedPointer<VSearchResultItem> pitem(item);
                emit resultItemAdded(pitem);
            }
        }
    }

    if (testTarget(VSearchConfig::Note)) {
        QStringList files = dir.entryList(QDir::Files);
        for (auto const & file : files) {
            if (askedToStop()) {
                qDebug() << "asked to cancel the search";
                p_result->m_state = VSearchState::Cancelled;
                return;
            }

            searchFirstPhaseFile(p_basePath, dir.absoluteFilePath(file), p_result);
        }
    }

    // Search subfolders.
    QStringList subdirs = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
    for (auto const & sub : subdirs) {
        if (askedToStop()) {
            qDebug() << "asked to cancel the search";
            p_result->m_state = VSearchState::Cancelled;
            return;
        }

        searchFirstPhase(p_basePath, dir.absoluteFilePath(sub), p_result);
    }
}
コード例 #4
0
ファイル: vsearch.cpp プロジェクト: getwindow/vnote
void VSearch::searchFirstPhase(VDirectory *p_directory,
                               const QSharedPointer<VSearchResult> &p_result)
{
    Q_ASSERT(testTarget(VSearchConfig::Note) || testTarget(VSearchConfig::Folder));

    bool opened = p_directory->isOpened();
    if (!opened && !p_directory->open()) {
        p_result->logError(QString("Fail to open folder %1.").arg(p_directory->fetchRelativePath()));
        p_result->m_state = VSearchState::Fail;
        return;
    }

    if (testTarget(VSearchConfig::Folder)) {
        QString name = p_directory->getName();
        QString dirPath = p_directory->fetchPath();
        if (testObject(VSearchConfig::Name)) {
            if (matchNonContent(name)) {
                VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
                                                                VSearchResultItem::LineNumber,
                                                                name,
                                                                dirPath);
                QSharedPointer<VSearchResultItem> pitem(item);
                emit resultItemAdded(pitem);
            }
        }

        if (testObject(VSearchConfig::Path)) {
            QString normPath(p_directory->fetchRelativePath());
            removeSlashFromPath(normPath);
            if (matchNonContent(normPath)) {
                VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
                                                                VSearchResultItem::LineNumber,
                                                                name,
                                                                dirPath);
                QSharedPointer<VSearchResultItem> pitem(item);
                emit resultItemAdded(pitem);
            }
        }
    }

    // Search files.
    if (testTarget(VSearchConfig::Note)) {
        for (auto const & file : p_directory->getFiles()) {
            if (askedToStop()) {
                qDebug() << "asked to cancel the search";
                p_result->m_state = VSearchState::Cancelled;
                goto exit;
            }

            searchFirstPhase(file, p_result);
        }
    }

    // Search subfolders.
    for (auto const & dir : p_directory->getSubDirs()) {
        if (askedToStop()) {
            qDebug() << "asked to cancel the search";
            p_result->m_state = VSearchState::Cancelled;
            goto exit;
        }

        searchFirstPhase(dir, p_result);
    }

exit:
    if (!opened) {
        p_directory->close();
    }
}