This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 10 - Pages: 1 - Last Post: 21 Sep 23, 19:08 Last Post By: davidekholm
JeffTucker

Posts: 7,990
Registered: 31-Jan-2006
A new object category
Posted: 20 Sep 23, 22:28
 
  Click to reply to this thread Reply
We've currently got Category.image, Category.video, etc. The troublesome one is Category.other. Many skins support images, videos, web locations, and PDF's, but not things like Word documents or zip files. As a result, a lot of otherwise simple tests become clumsy compound affairs:
isPDF = fileCategory == Category.other && fileName.toLowerCase().endsWith(".pdf");
Ugh. And if you want to know if there are any PDF's in a directory, this won't do the job:
cc = JAlbumUtilities.countCategories(currentFolder, false);
anyPDFs = cc.getCount(Category.other) > 0;
That ends up counting all the other stuff, too, like Word docs and zip files.

It would be very handy to have a Category.pdf available.

To avoid badly breaking existing skins, Category.other should still include the PDF's.
RobM

Posts: 3,797
Registered: 4-Aug-2006
Re: A new object category
Posted: 20 Sep 23, 23:01   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Not sure if it is possible but if a skin's property file could define a list of 'other' categories that would be more flexible.
JeffTucker

Posts: 7,990
Registered: 31-Jan-2006
Re: A new object category
Posted: 20 Sep 23, 23:13   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Not sure I understand the use case for that. If you look at the list of jAlbum supported file types, once you get past images, videos, audios, web locations, and PDF's, it's a pretty motley collection - mostly things I've never encountered in a live album. And it includes some things like DjVu files, which haven't been seen in the wild in almost two decades. ;)
RobM

Posts: 3,797
Registered: 4-Aug-2006
Re: A new object category
Posted: 21 Sep 23, 00:12   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
I was thinking that since you mentioned Word and zip files as well as PDF there might be a requirement for more than just a PDF object category. Most 'other' file types might be oddball and not often used, at the moment, but an extensible object category would add a bit of future proofing.

Users can already extend the supported file types using their own custom filetype.xml file. Object categories could similarly be extended either via the skin or the user's config directory.
davidekholm

Posts: 3,433
Registered: 18-Oct-2002
Re: A new object category
Posted: 21 Sep 23, 07:30   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Adding new categories is sadly a brittle endeavor: They are Enums, and once you've added a new one, loading such a project into an older jAlbum will break it.
JeffTucker

Posts: 7,990
Registered: 31-Jan-2006
Re: A new object category
Posted: 21 Sep 23, 08:13   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Unfortunate. It’s not aesthetically pleasing, but how about a new method, like countPDFs()?

ETA: And, of course, isPDF().

Then we can get after the HTML gods to give us a <pdf> tag. ;)
JeffTucker

Posts: 7,990
Registered: 31-Jan-2006
Re: A new object category
Posted: 21 Sep 23, 08:58   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Actually, I don’t need counts. I just need to know if there are any in a folder, with a Boolean to indicate whether to recurse. Hell, even a hack like me can write that!

ETA: Sometimes I forget that if the core doesn't provide the method I need, I really can just sugar my own churro.
JeffTucker

Posts: 7,990
Registered: 31-Jan-2006
Re: A new object category
Posted: 21 Sep 23, 14:06   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
About ten minutes of coding and testing. It would have been quicker, but at this hour of the morning my eyes don't work very well, and sometimes can't tell the difference between a minus sign and an equals sign. ;)

Case closed.
davidekholm

Posts: 3,433
Registered: 18-Oct-2002
Re: A new object category
Posted: 21 Sep 23, 17:50   in response to: JeffTucker in response to: JeffTucker
Helpful
  Click to reply to this thread Reply
In Groovy, you can write stuff like this to check if a folder has pdf files:
currentFolder.children.stream().anyMatch(f -> f.name.toLowerCase().endsWith(".pdf"))

In Java, it's like this:
currentFolder.getChildren().stream().anyMatch(f -> f.getName().toLowerCase().endsWith(".pdf"))


That only looks inside the 1:st level of that folder. If you want to know whether a pdf is lurking at any depth under a folder, just change getChildren() to getDescendants().
JeffTucker

Posts: 7,990
Registered: 31-Jan-2006
Re: A new object category
Posted: 21 Sep 23, 18:16   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
More concise than my version, but mine was already pretty lean. :)
davidekholm

Posts: 3,433
Registered: 18-Oct-2002
Re: A new object category
Posted: 21 Sep 23, 19:08   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
I happen to love the Stream API, but I usually need to look up the details. Add the word parallel() to the chain, and the whole thing is solved by multiple CPU cores as well :-) That helps speeding up traversing deeper folder structures.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums