PDA

View Full Version : Smart Folders/Playlists/Whatevers.




kalisphoenix
Mar 20, 2006, 05:32 PM
Let us bow our heads. Have mercy on the n00b. Amen.

I'm working on a new program that looks a lot like iTunes but really manages a whole bunch of text files. Or, actually, a whole bunch of text fields in a big database. Either way, I like smart folders and smart playlists. Is there any way to get that functionality? I haven't seen any palettes for Interface Builder or, God Forbid, an Honest-to-$DEITY tutorial for using them, so I'm assuming the worst.



HiRez
Mar 20, 2006, 08:06 PM
Let us bow our heads. Have mercy on the n00b. Amen.

I'm working on a new program that looks a lot like iTunes but really manages a whole bunch of text files. Or, actually, a whole bunch of text fields in a big database. Either way, I like smart folders and smart playlists. Is there any way to get that functionality? I haven't seen any palettes for Interface Builder or, God Forbid, an Honest-to-$DEITY tutorial for using them, so I'm assuming the worst.
You probably want to use the Spotlight API. If you're using Cocoa, you should have a look at NSMetadataQuery, NSMetadataItem, and NSPredicate (and there are Carbon equivalents). This should allow you do do live searching and smart-folder type things with text files. You can find a good tutorial on how to use it all here (http://www.oreillynet.com/pub/a/mac/2005/07/12/spotlight.html), although you'll need to have a fairly good understanding of Cocoa before reading it. It's not really hard to use, but it's not quite for Cocoa newbies either.

caveman_uk
Mar 21, 2006, 02:57 AM
For smart folders you have to roll-your-own solution. There is an example of how to do something similar in the developer examples installed with the tools involving building a search query. You'd then store that query so when the smart folder was opened you'd run the query.

There's a number of ways to do searching. Spotlight's cool but it's Tiger only and only works on individual files not files containing multiple records.(AFAIK). You could also take a look at SearchKit which works in 10.3 but was considerably updated in Tiger and is a bit more flexible.

Oh, and you'll need icons and stuff for the folders in the GUI. You shouldn't just pinch Apple's:rolleyes:

kalisphoenix
Mar 21, 2006, 03:15 PM
I'm not intending on distributing this, really. Although if I felt it was really good, I might either open-source it or sell it for a pittance, depending on whether or not my alternative is living on the street sucking **** for McDonald's money. That being said, I probably shouldn't show you my mock-up then ;) ;) ;)

Yeah, I'm a Cocoa newbie. More to the point, I'm an Objective-C newbie, a C newbie, and a programming newbie :( But I'll work pretty damned hard on this, I'll guarantee you that much. It's just difficult starting out because I don't have a strict "Method = ________, Instance Variable = _______" sorta sheet. I have an O'Reilly book on Cocoa, but it's pretty dense. I think I'm getting it, though.

caveman_uk
Mar 22, 2006, 03:37 AM
The best advice I can give to a new cocoa developer is read the bit about memory management really well. If you want to keep your hair I'd recommend using alloc and retain only when you really need to - often using a class method (like [NSArray array....]) is a better idea.