MLLabel.m 2.37 KB
Newer Older
1 2 3 4 5
/*****************************************************************************
 * MLLabel.m
 * Lunettes
 *****************************************************************************
 * Copyright (C) 2010 Pierre d'Herbemont
6
 * Copyright (C) 2010-2015 VLC authors and VideoLAN
7 8 9
 * $Id$
 *
 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10
 *          Felix Paul Kühne <fkuehne # videolan.org>
11
 *
12 13 14
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
15 16 17 18
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
21
 *
22 23 24
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25
 *****************************************************************************/
Pierre's avatar
Pierre committed
26

Pierre's avatar
Pierre committed
27
#import "MLLabel.h"
28
#import "MLMediaLibrary.h"
Pierre's avatar
Pierre committed
29
#import "MLFile.h"
Pierre's avatar
Pierre committed
30

Pierre's avatar
Pierre committed
31
@implementation MLLabel
Pierre's avatar
Pierre committed
32

33 34 35 36
+ (NSArray *)allLabels
{
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
37 38 39
    if (!moc || moc.persistentStoreCoordinator == nil)
        return [NSArray array];

40 41 42 43 44 45 46 47 48 49 50
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Label" inManagedObjectContext:moc];
    [request setEntity:entity];

    NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
    [request setSortDescriptors:@[descriptor]];

    NSArray *labels = [moc executeFetchRequest:request error:nil];

    return labels;
}

Pierre's avatar
Pierre committed
51 52 53
@dynamic name;
@dynamic files;

54 55 56 57 58 59 60 61
- (NSArray *)sortedFolderItems
{
    NSArray *folderItems = [[self valueForKey:@"files"] allObjects];

    NSSortDescriptor *folderItemDescriptor =
    [[NSSortDescriptor alloc] initWithKey:@"folderTrackNumber"
                                ascending:YES
                                 selector:@selector(compare:)];
Carola Nitz's avatar
Carola Nitz committed
62 63
    NSArray *items = [folderItems sortedArrayUsingDescriptors:@[folderItemDescriptor]];
    return items;
64 65
}

Pierre's avatar
Pierre committed
66
@end