@@ -637,6 +637,9 @@ notmimetype=value
637
637
638
638
/**
639
639
* 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).
640
643
*/
641
644
final class MimeInfoCacheFile : IniLikeFile
642
645
{
@@ -747,10 +750,16 @@ notmimetype=value
747
750
}).filter! (file => file ! is null ).array;
748
751
}
749
752
753
+ // /
754
+ unittest
755
+ {
756
+ assert (mimeAppsListFiles([" test/applications/mimeapps.list" ]).length == 1 );
757
+ }
758
+
750
759
static if (isFreedesktop)
751
760
{
752
761
/**
753
- * ditto, but automatically read MimeAppsListFile objects from determined system paths.
762
+ * ditto, but automatically read $(D MimeAppsListFile) objects from determined system paths.
754
763
* Note: Available only on Freedesktop.
755
764
*/
756
765
@safe MimeAppsListFile[] mimeAppsListFiles() nothrow {
@@ -771,6 +780,12 @@ static if (isFreedesktop)
771
780
}).filter! (file => file ! is null ).array;
772
781
}
773
782
783
+ // /
784
+ unittest
785
+ {
786
+ assert (mimeInfoCacheFiles([" test/applications/mimeinfo.cache" ]).length == 1 );
787
+ }
788
+
774
789
static if (isFreedesktop)
775
790
{
776
791
/**
@@ -789,8 +804,8 @@ static if (isFreedesktop)
789
804
interface IDesktopFileProvider
790
805
{
791
806
/**
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.
794
809
*/
795
810
const (DesktopFile) getByDesktopId (string desktopId);
796
811
}
@@ -826,6 +841,7 @@ public:
826
841
this (applicationsPaths, binPaths().array, options);
827
842
}
828
843
844
+ // /
829
845
override const (DesktopFile) getByDesktopId (string desktopId)
830
846
{
831
847
auto itemIn = desktopId in _cache;
@@ -946,9 +962,9 @@ private const(DesktopFile)[] findAssociatedApplicationsImpl(ListRange, CacheRang
946
962
* Find associated applications for mimeType.
947
963
* Params:
948
964
* 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.
952
968
* Returns: Array of found $(B DesktopFile) object capable of opening file of given MIME type or url of given scheme.
953
969
* Note: If no applications found for this mimeType, you may consider to use this function on parent MIME type.
954
970
* See_Also: $(LINK2 https://specifications.freedesktop.org/mime-apps-spec/latest/ar01s03.html, Adding/removing associations)
@@ -979,9 +995,9 @@ unittest
979
995
* Find all known associated applications for mimeType, including explicitly removed by user.
980
996
* Params:
981
997
* 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.
985
1001
* Returns: Array of found $(B DesktopFile) object capable of opening file of given MIME type or url of given scheme.
986
1002
*/
987
1003
const (DesktopFile)[] findKnownAssociatedApplications (ListRange, CacheRange)(string mimeType, ListRange mimeAppsListFiles, CacheRange mimeInfoCacheFiles, IDesktopFileProvider desktopFileProvider)
@@ -1006,9 +1022,9 @@ unittest
1006
1022
* Find default application for mimeType.
1007
1023
* Params:
1008
1024
* 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.
1012
1028
* Returns: Found $(B DesktopFile) or null if not found.
1013
1029
* Note: You probably will need to call this function on parent MIME type if it fails for original mimeType.
1014
1030
* See_Also: $(LINK2 https://specifications.freedesktop.org/mime-apps-spec/latest/ar01s04.html, Default Application)
@@ -1077,31 +1093,31 @@ struct AssociationUpdateQuery
1077
1093
}
1078
1094
1079
1095
/**
1080
- * See_Also: $(D mimeAppsList .addAssociation)
1096
+ * See_Also: $(D MimeAppsListFile .addAssociation)
1081
1097
*/
1082
1098
@safe ref typeof (this ) addAssociation(string mimeType, string desktopId) nothrow
1083
1099
{
1084
1100
_operations ~= Operation(mimeType, desktopId, Operation.Type.add);
1085
1101
return this ;
1086
1102
}
1087
1103
/**
1088
- * See_Also: $(D mimeAppsList .setAddedAssocations)
1104
+ * See_Also: $(D MimeAppsListFile .setAddedAssocations)
1089
1105
*/
1090
1106
@safe ref typeof (this ) setAddedAssocations(Range )(string mimeType, Range desktopIds) if (isInputRange! Range && is (ElementType! Range : string ))
1091
1107
{
1092
1108
_operations ~= Operation(mimeType, MimeAppsGroup.joinApps(desktopIds), Operation.Type.setAdded);
1093
1109
return this ;
1094
1110
}
1095
1111
/**
1096
- * See_Also: $(D mimeAppsList .removeAssociation)
1112
+ * See_Also: $(D MimeAppsListFile .removeAssociation)
1097
1113
*/
1098
1114
@safe ref typeof (this ) removeAssociation(string mimeType, string desktopId) nothrow
1099
1115
{
1100
1116
_operations ~= Operation(mimeType, desktopId, Operation.Type.remove);
1101
1117
return this ;
1102
1118
}
1103
1119
/**
1104
- * See_Also: $(D mimeAppsList .setDefaultApplication)
1120
+ * See_Also: $(D MimeAppsListFile .setDefaultApplication)
1105
1121
*/
1106
1122
@safe ref typeof (this ) setDefaultApplication(string mimeType, string desktopId) nothrow
1107
1123
{
@@ -1110,7 +1126,7 @@ struct AssociationUpdateQuery
1110
1126
}
1111
1127
1112
1128
/**
1113
- * Apply query to MimeAppsListFile.
1129
+ * Apply query to $(D MimeAppsListFile) .
1114
1130
*/
1115
1131
@safe void apply(MimeAppsListFile file) const
1116
1132
{
@@ -1157,6 +1173,9 @@ unittest
1157
1173
/**
1158
1174
* Apply query for file with fileName. This should be mimeapps.list file.
1159
1175
* 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.
1160
1179
*/
1161
1180
@trusted void updateAssociations(string fileName, ref AssociationUpdateQuery query)
1162
1181
{
0 commit comments