Commit 4579c42b authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Remove dependence on Boost

parent c6016059
Pipeline #119060 passed with stage
in 10 minutes and 5 seconds
......@@ -86,20 +86,6 @@ set_package_properties(Qt5Designer PROPERTIES
option(BUILD_DESIGNERPLUGIN "Build plugin for Qt Designer" ON)
add_feature_info(DESIGNERPLUGIN ${BUILD_DESIGNERPLUGIN} "Build plugin for Qt Designer")
set(Boost_MINIMUM_VERSION "1.34.0")
# The Boost CMake config files have been incompatible with the CMake files for
# a long time. We'll only use what CMake's FindBoost.cmake module provides
# until the minimum Boost version is raised to 1.70.
set(Boost_NO_BOOST_CMAKE ON)
find_package(Boost ${Boost_MINIMUM_VERSION} MODULE REQUIRED)
set_package_properties(Boost PROPERTIES
DESCRIPTION "Boost C++ Libraries"
URL "https://www.boost.org"
TYPE REQUIRED
)
set(AccountsQt5_MINIMUM_VERSION "1.16")
find_package(AccountsQt5 ${AccountsQt5_MINIMUM_VERSION})
set_package_properties(AccountsQt5 PROPERTIES
......
......@@ -30,11 +30,6 @@ if(BUILD_TESTING)
find_dependency(Qt5Test "@QT_REQUIRED_VERSION@")
endif()
set(Boost_NO_BOOST_CMAKE ON)
find_dependency(Boost "@Boost_MINIMUM_VERSION@")
# Reset Boost_NO_BOOST_CMAKE now that we found what we need
unset(Boost_NO_BOOST_CMAKE)
include(${CMAKE_CURRENT_LIST_DIR}/KF5AkonadiTargets.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/KF5AkonadiMacros.cmake)
......
......@@ -435,7 +435,6 @@ PUBLIC
KF5::CoreAddons # for KJob
KF5::ItemModels
Qt::Gui # for QColor
Boost::boost
PRIVATE
Qt::Network
Qt::Widgets
......
......@@ -19,12 +19,10 @@
#include <QMimeDatabase>
#include <QMimeType>
#include <QRegularExpression>
#include <QStack>
#include <QString>
#include <QStringList>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/topological_sort.hpp>
// temporary
#include "pluginloader_p.h"
......@@ -294,6 +292,35 @@ public:
}
private:
// Returns plugin matches for a mimetype in best->worst order, in terms of mimetype specificity
void findSuitablePlugins(QMimeType mimeType, QSet<QMimeType> &checkedMimeTypes, QVector<int> &matchingIndexes, const QMimeDatabase &mimeDb) const
{
// Avoid adding duplicates to our matchingIndexes
if (checkedMimeTypes.contains(mimeType)) {
return;
}
checkedMimeTypes.insert(mimeType);
// Check each of the mimetypes we have plugins for to find a match
for (int i = 0, end = allMimeTypes.size(); i < end; ++i) {
const QMimeType pluginMimeType = mimeDb.mimeTypeForName(allMimeTypes[i].type()); // Convert from Akonadi::MimeTypeEntry
if (!pluginMimeType.isValid() || pluginMimeType != mimeType) {
continue;
}
matchingIndexes.append(i); // We found a match! This mimetype is supported by one of our plugins
}
auto parentTypes = mimeType.parentMimeTypes();
// Recursively move up the mimetype tree (checking less specific mimetypes)
for (const auto &parent : parentTypes) {
QMimeType parentType = mimeDb.mimeTypeForName(parent);
findSuitablePlugins(parentType, checkedMimeTypes, matchingIndexes, mimeDb);
}
};
QObject *findBestMatchImpl(const QString &type, const QVector<int> &metaTypeIds, int &chosen) const
{
const QMimeDatabase mimeDb;
......@@ -303,53 +330,23 @@ private:
return mDefaultPlugin.plugin();
}
// step 1: find all plugins that match at all
QSet<QMimeType> checkedMimeTypes;
QVector<int> matchingIndexes;
for (int i = 0, end = allMimeTypes.size(); i < end; ++i) {
if (mimeType.inherits(allMimeTypes[i].type())) {
matchingIndexes.append(i);
}
}
// step 2: if we have more than one match, find the most specific one using topological sort
QVector<int> order;
if (matchingIndexes.size() <= 1) {
order.push_back(0);
} else {
boost::adjacency_list<> graph(matchingIndexes.size());
for (int i = 0, end = matchingIndexes.size(); i != end; ++i) {
const QMimeType mimeType = mimeDb.mimeTypeForName(allMimeTypes[matchingIndexes[i]].type());
if (!mimeType.isValid()) {
continue;
}
for (int j = 0; j != end; ++j) {
if (i != j && mimeType.inherits(allMimeTypes[matchingIndexes[j]].type())) {
boost::add_edge(j, i, graph);
}
}
}
order.reserve(matchingIndexes.size());
try {
boost::topological_sort(graph, std::back_inserter(order));
} catch (const boost::not_a_dag &e) {
qCWarning(AKONADICORE_LOG) << "Mimetype tree is not a DAG!";
return mDefaultPlugin.plugin();
}
}
findSuitablePlugins(mimeType, checkedMimeTypes, matchingIndexes, mimeDb);
// step 3: ask each one in turn if it can handle any of the metaTypeIds:
// Ask each one in turn if it can handle any of the metaTypeIds:
// qCDebug(AKONADICORE_LOG) << "Looking for " << format( type, metaTypeIds );
for (QVector<int>::const_iterator it = order.constBegin(), end = order.constEnd(); it != end; ++it) {
for (QVector<int>::const_iterator it = matchingIndexes.constBegin(), end = matchingIndexes.constEnd(); it != end; ++it) {
// qCDebug(AKONADICORE_LOG) << " Considering serializer plugin for type" << allMimeTypes[matchingIndexes[*it]].type()
// // << "as the closest match";
const MimeTypeEntry &mt = allMimeTypes[matchingIndexes[*it]];
const MimeTypeEntry &mt = allMimeTypes[*it];
if (metaTypeIds.empty()) {
if (const PluginEntry *const entry = mt.defaultPlugin()) {
// qCDebug(AKONADICORE_LOG) << " -> got " << entry->pluginClassName() << " and am happy with it.";
// FIXME ? in qt5 we show "application/octet-stream" first so if will use default plugin. Exclude it until we look at all mimetype and use
// default at the end if necessary
if (allMimeTypes[matchingIndexes[*it]].type() != QLatin1String("application/octet-stream")) {
if (allMimeTypes[*it].type() != QLatin1String("application/octet-stream")) {
return entry->plugin();
}
} else {
......@@ -368,7 +365,7 @@ private:
return mDefaultPlugin.plugin();
}
std::vector<MimeTypeEntry> allMimeTypes;
std::vector<MimeTypeEntry> allMimeTypes; // All the mimetypes that we have plugins for
QHash<QString, QMap<int, QObject *>> cachedPlugins;
QHash<QString, QObject *> cachedDefaultPlugins;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment