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
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'ext/spotlight/spotlight.c', line 207
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
228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'ext/spotlight/spotlight.c', line 228
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
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'ext/spotlight/spotlight.c', line 154
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
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'ext/spotlight/spotlight.c', line 242
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
258 259 260 261 262 263 264 |
# File 'ext/spotlight/spotlight.c', line 258
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);
return Qnil;
}
|