void CppHelperPluginConfigPage::updateSuggestions() { // Obtain a list of currecntly opened documents auto documents = m_plugin->application()->documentManager()->documents(); // Collect paths auto dirs = QStringList{}; const auto should_check_vcs = m_favorite_sets->vcsOnly->isChecked(); for (auto* current_doc : documents) { // Get current document's URI const auto current_doc_uri = current_doc->url(); // Check if valid if (current_doc_uri.isValid() && !current_doc_uri.isEmpty()) { // Traverse over all parent dirs for ( KUrl url = current_doc_uri.directory() ; url.hasPath() && url.path() != QDir::rootPath() ; url = url.upUrl() ) { auto dir = QDir::cleanPath(url.path()); // Obtain path as string // Check uniqueness and other constraints const bool should_add = dirs.indexOf(dir) == -1 && !contains(dir, m_system_list->pathsList) && !contains(dir, m_session_list->pathsList) && ( (should_check_vcs && hasVCSDir(dir)) || (!should_check_vcs && !isOneOfWellKnownPaths(dir) && !isFirstLevelPath(dir)) ) ; if (should_add) // Add current path only if not added yet dirs << dir; } } } qSort(dirs); kDebug(DEBUG_AREA) << "Suggestions list:" << dirs; // Update combobox w/ collected list m_favorite_sets->suggestionsList->clear(); m_favorite_sets->suggestionsList->addItems(dirs); // Enable/disable controls according documents list emptyness const auto is_enabled = !dirs.isEmpty(); m_favorite_sets->addSuggestedDirButton->setEnabled(is_enabled); m_favorite_sets->suggestionsList->setEnabled(is_enabled); }
static QString generateKey(const KUrl& url) { QString key; if (url.isValid()) { key = url.protocol(); key += QLatin1Char(':'); if (url.hasHost()) { key += url.host(); key += QLatin1Char(':'); } if (url.hasPath()) { key += url.path(); } } return key; }