[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdelibs/KDE/4.8] kdecore: Implement missing KService::mimeTypes() method.
From: David Faure <faure () kde ! org>
Date: 2012-04-17 16:01:20
Message-ID: 20120417160120.C9E4CA60A9 () git ! kde ! org
[Download RAW message or body]
Git commit e6f1d1a5da1a67b594cdd7377ae13daca86ff698 by David Faure.
Committed on 17/04/2012 at 18:01.
Pushed by dfaure into branch 'KDE/4.8'.
Implement missing KService::mimeTypes() method.
Needed already now (by Sho), doesn't have to wait for KF5.
M +13 -0 kdecore/services/kservice.cpp
M +8 -2 kdecore/services/kservice.h
M +2 -0 kdecore/tests/kservicetest.cpp
http://commits.kde.org/kdelibs/e6f1d1a5da1a67b594cdd7377ae13daca86ff698
diff --git a/kdecore/services/kservice.cpp b/kdecore/services/kservice.cpp
index f661003..fbd2e47 100644
--- a/kdecore/services/kservice.cpp
+++ b/kdecore/services/kservice.cpp
@@ -937,6 +937,19 @@ QStringList KService::serviceTypes() const
return d->serviceTypes();
}
+QStringList KService::mimeTypes() const
+{
+ Q_D(const KService);
+ QStringList ret;
+ QVector<KService::ServiceTypeAndPreference>::const_iterator it = d->m_serviceTypes.begin();
+ for ( ; it < d->m_serviceTypes.end(); ++it ) {
+ const QString sv = (*it).serviceType;
+ if (KMimeType::mimeType(sv)) // keep only mimetypes, filter out servicetypes
+ ret.append(sv);
+ }
+ return ret;
+}
+
bool KService::allowAsDefault() const
{
Q_D(const KService);
diff --git a/kdecore/services/kservice.h b/kdecore/services/kservice.h
index d8beae9..3843bad 100644
--- a/kdecore/services/kservice.h
+++ b/kdecore/services/kservice.h
@@ -91,8 +91,6 @@ public:
virtual ~KService();
- // TODO KDE5: add mimeTypes() accessor
-
/**
* Services are either applications (executables) or dlopened libraries (plugins).
* @return true if this service is an application, i.e. it has Type=Application in its
@@ -263,6 +261,14 @@ public:
QStringList categories() const;
/**
+ * Returns the list of mime types that this service supports.
+ * Note that this doesn't include inherited mimetypes,
+ * only the mimetypes types listed in the .desktop file.
+ * @since 4.8.3
+ */
+ QStringList mimeTypes() const;
+
+ /**
* Returns the service types that this service supports.
* @return the list of service types that are supported
* Note that this doesn't include inherited servicetypes or mimetypes,
diff --git a/kdecore/tests/kservicetest.cpp b/kdecore/tests/kservicetest.cpp
index 370ba19..057b9f7 100644
--- a/kdecore/tests/kservicetest.cpp
+++ b/kdecore/tests/kservicetest.cpp
@@ -356,6 +356,7 @@ void KServiceTest::testHasServiceType1() // with services constructed with a ful
KService fakepart( fakepartPath );
QVERIFY( fakepart.hasServiceType( "KParts/ReadOnlyPart" ) );
QVERIFY( fakepart.hasServiceType( "KParts/ReadWritePart" ) );
+ QCOMPARE(fakepart.mimeTypes(), QStringList() << "text/plain");
QString faketextPluginPath = KStandardDirs::locate( "services", "faketextplugin.desktop" );
QVERIFY( !faketextPluginPath.isEmpty() );
@@ -370,6 +371,7 @@ void KServiceTest::testHasServiceType2() // with services coming from ksycoca
QVERIFY( !fakepart.isNull() );
QVERIFY( fakepart->hasServiceType( "KParts/ReadOnlyPart" ) );
QVERIFY( fakepart->hasServiceType( "KParts/ReadWritePart" ) );
+ QCOMPARE(fakepart->mimeTypes(), QStringList() << "text/plain");
KService::Ptr faketextPlugin = KService::serviceByDesktopPath( "faketextplugin.desktop" );
QVERIFY( !faketextPlugin.isNull() );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic