Skip to content

Commit 010873e

Browse files
committed
Update docs and tests
1 parent 6d15aa3 commit 010873e

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

source/mimeapps.d

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@ notmimetype=value
637637

638638
/**
639639
* Class represenation of single mimeinfo.cache file containing information about MIME type associations.
640+
* Note: Unlike $(D MimeAppsListFile) this class does not provide functions for associations update.
641+
* This is because mimeinfo.cache files should be updated by $(B update-desktop-database) utility from
642+
* $(LINK2 https://www.freedesktop.org/wiki/Software/desktop-file-utils/, desktop-file-utils).
640643
*/
641644
final class MimeInfoCacheFile : IniLikeFile
642645
{
@@ -747,10 +750,16 @@ notmimetype=value
747750
}).filter!(file => file !is null).array;
748751
}
749752

753+
///
754+
unittest
755+
{
756+
assert(mimeAppsListFiles(["test/applications/mimeapps.list"]).length == 1);
757+
}
758+
750759
static if (isFreedesktop)
751760
{
752761
/**
753-
* ditto, but automatically read MimeAppsListFile objects from determined system paths.
762+
* ditto, but automatically read $(D MimeAppsListFile) objects from determined system paths.
754763
* Note: Available only on Freedesktop.
755764
*/
756765
@safe MimeAppsListFile[] mimeAppsListFiles() nothrow {
@@ -771,6 +780,12 @@ static if (isFreedesktop)
771780
}).filter!(file => file !is null).array;
772781
}
773782

783+
///
784+
unittest
785+
{
786+
assert(mimeInfoCacheFiles(["test/applications/mimeinfo.cache"]).length == 1);
787+
}
788+
774789
static if (isFreedesktop)
775790
{
776791
/**
@@ -789,8 +804,8 @@ static if (isFreedesktop)
789804
interface IDesktopFileProvider
790805
{
791806
/**
792-
* Retrieve DesktopFile by desktopId
793-
* Returns: Found DesktopFile or null if not found.
807+
* Retrieve $(B DesktopFile) by desktopId
808+
* Returns: Found $(B DesktopFile) or null if not found.
794809
*/
795810
const(DesktopFile) getByDesktopId(string desktopId);
796811
}
@@ -826,6 +841,7 @@ public:
826841
this(applicationsPaths, binPaths().array, options);
827842
}
828843

844+
///
829845
override const(DesktopFile) getByDesktopId(string desktopId)
830846
{
831847
auto itemIn = desktopId in _cache;
@@ -946,9 +962,9 @@ private const(DesktopFile)[] findAssociatedApplicationsImpl(ListRange, CacheRang
946962
* Find associated applications for mimeType.
947963
* Params:
948964
* mimeType = MIME type or uri scheme handler in question.
949-
* mimeAppsListFiles = Range of MimeAppsListFile objects to use in searching.
950-
* mimeInfoCacheFiles = Range of MimeInfoCacheFile objects to use in searching.
951-
* desktopFileProvider = desktop file provider instance.
965+
* mimeAppsListFiles = Range of $(D MimeAppsListFile) objects to use in searching.
966+
* mimeInfoCacheFiles = Range of $(D MimeInfoCacheFile) objects to use in searching.
967+
* desktopFileProvider = Desktop file provider instance.
952968
* Returns: Array of found $(B DesktopFile) object capable of opening file of given MIME type or url of given scheme.
953969
* Note: If no applications found for this mimeType, you may consider to use this function on parent MIME type.
954970
* See_Also: $(LINK2 https://specifications.freedesktop.org/mime-apps-spec/latest/ar01s03.html, Adding/removing associations)
@@ -979,9 +995,9 @@ unittest
979995
* Find all known associated applications for mimeType, including explicitly removed by user.
980996
* Params:
981997
* mimeType = MIME type or uri scheme handler in question.
982-
* mimeAppsListFiles = Range of MimeAppsListFile objects to use in searching.
983-
* mimeInfoCacheFiles = Range of MimeInfoCacheFile objects to use in searching.
984-
* desktopFileProvider = desktop file provider instance.
998+
* mimeAppsListFiles = Range of $(D MimeAppsListFile) objects to use in searching.
999+
* mimeInfoCacheFiles = Range of $(D MimeInfoCacheFile) objects to use in searching.
1000+
* desktopFileProvider = Desktop file provider instance.
9851001
* Returns: Array of found $(B DesktopFile) object capable of opening file of given MIME type or url of given scheme.
9861002
*/
9871003
const(DesktopFile)[] findKnownAssociatedApplications(ListRange, CacheRange)(string mimeType, ListRange mimeAppsListFiles, CacheRange mimeInfoCacheFiles, IDesktopFileProvider desktopFileProvider)
@@ -1006,9 +1022,9 @@ unittest
10061022
* Find default application for mimeType.
10071023
* Params:
10081024
* mimeType = MIME type or uri scheme handler in question.
1009-
* mimeAppsListFiles = Range of MimeAppsListFile objects to use in searching.
1010-
* mimeInfoCacheFiles = Range of MimeInfoCacheFile objects to use in searching.
1011-
* desktopFileProvider = desktop file provider instance. Must be non-null.
1025+
* mimeAppsListFiles = Range of $(D MimeAppsListFile) objects to use in searching.
1026+
* mimeInfoCacheFiles = Range of $(D MimeInfoCacheFile) objects to use in searching.
1027+
* desktopFileProvider = Desktop file provider instance. Must be non-null.
10121028
* Returns: Found $(B DesktopFile) or null if not found.
10131029
* Note: You probably will need to call this function on parent MIME type if it fails for original mimeType.
10141030
* See_Also: $(LINK2 https://specifications.freedesktop.org/mime-apps-spec/latest/ar01s04.html, Default Application)
@@ -1077,31 +1093,31 @@ struct AssociationUpdateQuery
10771093
}
10781094

10791095
/**
1080-
* See_Also: $(D mimeAppsList.addAssociation)
1096+
* See_Also: $(D MimeAppsListFile.addAssociation)
10811097
*/
10821098
@safe ref typeof(this) addAssociation(string mimeType, string desktopId) nothrow
10831099
{
10841100
_operations ~= Operation(mimeType, desktopId, Operation.Type.add);
10851101
return this;
10861102
}
10871103
/**
1088-
* See_Also: $(D mimeAppsList.setAddedAssocations)
1104+
* See_Also: $(D MimeAppsListFile.setAddedAssocations)
10891105
*/
10901106
@safe ref typeof(this) setAddedAssocations(Range)(string mimeType, Range desktopIds) if (isInputRange!Range && is(ElementType!Range : string))
10911107
{
10921108
_operations ~= Operation(mimeType, MimeAppsGroup.joinApps(desktopIds), Operation.Type.setAdded);
10931109
return this;
10941110
}
10951111
/**
1096-
* See_Also: $(D mimeAppsList.removeAssociation)
1112+
* See_Also: $(D MimeAppsListFile.removeAssociation)
10971113
*/
10981114
@safe ref typeof(this) removeAssociation(string mimeType, string desktopId) nothrow
10991115
{
11001116
_operations ~= Operation(mimeType, desktopId, Operation.Type.remove);
11011117
return this;
11021118
}
11031119
/**
1104-
* See_Also: $(D mimeAppsList.setDefaultApplication)
1120+
* See_Also: $(D MimeAppsListFile.setDefaultApplication)
11051121
*/
11061122
@safe ref typeof(this) setDefaultApplication(string mimeType, string desktopId) nothrow
11071123
{
@@ -1110,7 +1126,7 @@ struct AssociationUpdateQuery
11101126
}
11111127

11121128
/**
1113-
* Apply query to MimeAppsListFile.
1129+
* Apply query to $(D MimeAppsListFile).
11141130
*/
11151131
@safe void apply(MimeAppsListFile file) const
11161132
{
@@ -1157,6 +1173,9 @@ unittest
11571173
/**
11581174
* Apply query for file with fileName. This should be mimeapps.list file.
11591175
* If file does not exist it will be created.
1176+
* Throws:
1177+
* $(D IniLikeReadException) if errors occured duting reading of file.
1178+
* $(B ErrnoException) if errors occured during file writing.
11601179
*/
11611180
@trusted void updateAssociations(string fileName, ref AssociationUpdateQuery query)
11621181
{

0 commit comments

Comments
 (0)