Module: Spotlight::Intern
- Defined in:
- ext/spotlight/spotlight.c
Class Method Summary collapse
- .attributes(path) ⇒ Object
- .get_attribute(path, name) ⇒ Object
- .search(queryString, scopeDirectories) ⇒ Object
- .set_attribute(path, name, value) ⇒ Object
- .set_attributes(path, attributes) ⇒ Object
Class Method Details
.attributes(path) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'ext/spotlight/spotlight.c', line 199
VALUE method_attributes(VALUE self, VALUE path) {
int i;
CFStringRef attrNameRef;
CFTypeRef attrValueRef;
MDItemRef mdi = createMDItemByPath(path);
CFArrayRef attrNamesRef = MDItemCopyAttributeNames(mdi);
VALUE result = rb_hash_new();
for (i = 0; i < CFArrayGetCount(attrNamesRef); i++) {
attrNameRef = CFArrayGetValueAtIndex(attrNamesRef, i);
attrValueRef = MDItemCopyAttribute(mdi, attrNameRef);
rb_hash_aset(result, cfstring2rbstr(attrNameRef), convert2rb_type(attrValueRef));
RELEASE_IF_NOT_NULL(attrValueRef);
}
RELEASE_IF_NOT_NULL(mdi);
RELEASE_IF_NOT_NULL(attrNamesRef);
return result;
}
|
.get_attribute(path, name) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'ext/spotlight/spotlight.c', line 220
VALUE method_get_attribute(VALUE self, VALUE path, VALUE name) {
MDItemRef mdi = createMDItemByPath(path);
CFStringRef nameRef = rbstr2cfstring(name);
CFTypeRef valueRef = MDItemCopyAttribute(mdi, nameRef);
VALUE result = convert2rb_type(valueRef);
RELEASE_IF_NOT_NULL(valueRef);
RELEASE_IF_NOT_NULL(nameRef);
RELEASE_IF_NOT_NULL(mdi);
return result;
}
|
.search(queryString, scopeDirectories) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'ext/spotlight/spotlight.c', line 148
VALUE method_search(VALUE self, VALUE queryString, VALUE scopeDirectories) {
VALUE result = Qnil;
int i;
CFStringRef path;
MDItemRef item;
CFStringRef qs = rbstr2cfstring(queryString);
MDQueryRef query = MDQueryCreate(kCFAllocatorDefault, qs, NULL, NULL);
RELEASE_IF_NOT_NULL(qs);
if (query) {
set_search_scope(query, scopeDirectories);
if (MDQueryExecute(query, kMDQuerySynchronous)) {
result = rb_ary_new();
for(i = 0; i < MDQueryGetResultCount(query); ++i) {
item = (MDItemRef) MDQueryGetResultAtIndex(query, i);
if (item) {
path = MDItemCopyAttribute(item, kMDItemPath);
rb_ary_push(result, cfstring2rbstr(path));
RELEASE_IF_NOT_NULL(path);
}
}
}
RELEASE_IF_NOT_NULL(query);
}
return result;
}
|
.set_attribute(path, name, value) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'ext/spotlight/spotlight.c', line 234
VALUE method_set_attribute(VALUE self, VALUE path, VALUE name, VALUE value) {
MDItemRef mdi = createMDItemByPath(path);
CFStringRef nameRef = rbstr2cfstring(name);
CFTypeRef valueRef = convert2cf_type(value);
if(!MDItemSetAttribute(mdi, nameRef, valueRef)) {
printf("set %s failed\n", StringValuePtr(name));
}
RELEASE_IF_NOT_NULL(valueRef);
RELEASE_IF_NOT_NULL(nameRef);
RELEASE_IF_NOT_NULL(mdi);
return Qtrue;
}
|
.set_attributes(path, attributes) ⇒ Object
250 251 252 253 254 |
# File 'ext/spotlight/spotlight.c', line 250
VALUE method_set_attributes(VALUE self, VALUE path, VALUE attributes) {
MDItemRef mdi = createMDItemByPath(path);
rb_hash_foreach(attributes, each_attribute, (VALUE) mdi);
RELEASE_IF_NOT_NULL(mdi);
}
|