Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support listing/loading profiles #1155

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions XBMC Remote/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
@property (nonatomic, assign) BOOL isGroupSingleItemSetsEnabled;
@property (nonatomic, assign) BOOL isShowEmptyTvShowsEnabled;
@property (nonatomic, copy) NSArray *KodiSorttokens;
@property (nonatomic, copy) NSString *currentProfile;
@property (nonatomic, strong) GlobalData *obj;

@end
29 changes: 29 additions & 0 deletions XBMC Remote/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -5671,6 +5671,7 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@"st_music_addon",
@"st_kodi_action",
@"st_kodi_window",
@"st_profile",
];

xbmcSettings.mainMethod = [@[
Expand All @@ -5692,6 +5693,9 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@{
@"method": @"JSONRPC.Introspect",
},
@{
@"method": @"Profiles.GetProfiles",
},
] mutableCopy];

xbmcSettings.mainParameters = [@[
Expand Down Expand Up @@ -5788,6 +5792,20 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@"thumbWidth": @0,
@"morelabel": LOCALIZED_STR(@"Activate a specific window"),
},

@{
@"parameters": @{
@"properties": @[
@"lockmode",
@"thumbnail",
],
},
@"label": LOCALIZED_STR(@"Profiles"),
@"defaultThumb": @"nocover_profile",
@"rowHeight": @FILEMODE_ROW_HEIGHT,
@"thumbWidth": @FILEMODE_THUMB_WIDTH,
@"morelabel": LOCALIZED_STR(@"Profiles"),
},
] mutableCopy];

xbmcSettings.mainFields = @[
Expand Down Expand Up @@ -5872,6 +5890,12 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@"row8": @"addonid",
@"row9": @"addonid",
},

@{
@"itemid": @"profiles",
@"row1": @"label",
@"row8": @"profile",
},
];

xbmcSettings.sheetActions = @[
Expand All @@ -5896,6 +5920,7 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
LOCALIZED_STR(@"Activate window"),
LOCALIZED_STR(@"Add window activation button"),
],
@[],
];

xbmcSettings.subItem.disableNowPlaying = YES;
Expand All @@ -5908,6 +5933,7 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@{},
@{},
@{},
@{},
] mutableCopy];

xbmcSettings.subItem.mainParameters = [@[
Expand Down Expand Up @@ -5937,6 +5963,8 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@{
@"forceActionSheet": @YES,
},

@{},
] mutableCopy];

xbmcSettings.subItem.mainFields = @[
Expand All @@ -5957,6 +5985,7 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@{},
@{},
@{},
@{},
];

xbmcSettings.subItem.rowHeight = SETTINGS_ROW_HEIGHT;
Expand Down
46 changes: 45 additions & 1 deletion XBMC Remote/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,17 @@ - (NSString*)getCacheKey:(NSString*)fieldA parameters:(NSMutableDictionary*)fiel
// Which version does the serer have?
NSString *serverVersion = [NSString stringWithFormat:@"%d.%d", serverMajorVersion, serverMinorVersion];

// Which user profile is active?
NSString *currentProfile = [NSString stringWithFormat:@"%@", AppDelegate.instance.currentProfile];

// Which App version are we running?
NSString *appVersion = [Utilities getAppVersionString];

// Which JSON request's results do we cache??
NSString *jsonRequest = [NSString stringWithFormat:@"%@ %@", fieldA, fieldB];

// Get SHA256 hash for the combination given above
NSString *text = [NSString stringWithFormat:@"%@%@%@%@", serverInfo, serverVersion, appVersion, jsonRequest];
NSString *text = [NSString stringWithFormat:@"%@%@%@%@%@", serverInfo, serverVersion, currentProfile, appVersion, jsonRequest];
return [text SHA256String];
}

Expand Down Expand Up @@ -1607,6 +1610,9 @@ - (void)didSelectItemAtIndexPath:(NSIndexPath*)indexPath item:(NSDictionary*)ite
[Utilities showMessage:message color:[Utilities getSystemRed:0.95]];
}
}
else if ([item[@"family"] isEqualToString:@"profile"]) {
[self loadProfile:item];
}
else if (methods[@"method"] != nil && ![parameters[@"forceActionSheet"] boolValue] && !stackscrollFullscreen) {
// There is a child and we want to show it (only when not in fullscreen)
[self viewChild:indexPath item:item displayPoint:point];
Expand Down Expand Up @@ -2655,6 +2661,17 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
runtimeyear.hidden = YES;
title.frame = CGRectMake(title.frame.origin.x, (int)(cellHeight / 2 - title.frame.size.height / 2), title.frame.size.width, title.frame.size.height);
}
else if ([item[@"family"] isEqualToString:@"profile"]) {
if ([item[@"label"] isEqualToString:AppDelegate.instance.currentProfile]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
genre.hidden = YES;
runtimeyear.hidden = YES;
title.frame = CGRectMake(title.frame.origin.x, (int)(cellHeight / 2 - title.frame.size.height / 2), title.frame.size.width, title.frame.size.height);
}
else if ([item[@"family"] isEqualToString:@"channelid"]) {
runtimeyear.hidden = YES;
rating.hidden = YES;
Expand Down Expand Up @@ -4455,6 +4472,26 @@ - (void)SimpleAction:(NSString*)action params:(NSDictionary*)parameters success:
}];
}

- (void)loadProfile:(NSDictionary*)item {
NSString *profileName = item[@"label"];
if ([profileName isEqualToString:AppDelegate.instance.currentProfile]) {
return;
}
// Load user profile
[[Utilities getJsonRPC]
callMethod:@"Profiles.LoadProfile"
withParameters:@{
@"profile": profileName,
@"prompt": @YES,
}
onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) {
if (!error && !methodError) {
AppDelegate.instance.currentProfile = profileName;
[dataList reloadData];
}
}];
}

- (void)displayInfoView:(NSDictionary*)item {
if (IS_IPHONE) {
ShowInfoViewController *showInfoViewController = [[ShowInfoViewController alloc] initWithNibName:@"ShowInfoViewController" bundle:nil];
Expand Down Expand Up @@ -4835,6 +4872,13 @@ - (void)retrieveData:(NSString*)methodToCall parameters:(NSDictionary*)parameter
}
}

// Profiles functions not supported with older Kodi versions
if ([methodToCall containsString:@"Profiles."] && ![VersionCheck hasProfilesSupport]) {
[Utilities showMessage:LOCALIZED_STR(@"Cannot do that") color:[Utilities getSystemRed:0.95]];
[self animateNoResultsFound];
return;
}

[Utilities alphaView:noFoundView AnimDuration:0.2 Alpha:0.0];
// NSLog(@"START");
elapsedTime = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "st_profile.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "st_profile@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "nocover_profile.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "nocover_profile@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions XBMC Remote/VersionCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
+ (BOOL)hasInputButtonEventSupport;
+ (BOOL)hasPlayUsingSupport;
+ (BOOL)hasPlayerOpenOptions;
+ (BOOL)hasProfilesSupport;

@end
5 changes: 5 additions & 0 deletions XBMC Remote/VersionCheck.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ + (BOOL)hasPlayerOpenOptions {
return AppDelegate.instance.serverVersion > 11;
}

+ (BOOL)hasProfilesSupport {
// Profiles methods are supported from API 8 on
return AppDelegate.instance.APImajorVersion >= 8;
}

@end
1 change: 1 addition & 0 deletions XBMC Remote/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
"Button Pad/Gesture Zone" = "Button Pad/Gesture Zone";
"Slide your finger up or down to adjust the scrubbing rate." = "Slide your finger up or down to adjust the scrubbing rate.";

"Profiles" = "Profiles";
"Programs" = "Programs";
"XBMC Settings" = "Kodi Settings";

Expand Down
20 changes: 20 additions & 0 deletions XBMC Remote/tcpJSONRPC.m
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ - (void)readJSONRPCAPIVersion {
[self readGroupSingleItemSets];

[self readShowEmptyTvShows];

[self readCurrentProfile];
}];
}

Expand Down Expand Up @@ -362,6 +364,24 @@ - (void)readSorttokens {
}
}

- (void)readCurrentProfile {
// Read current active user profile
if ([VersionCheck hasProfilesSupport]) {
[[Utilities getJsonRPC]
callMethod:@"Profiles.GetCurrentProfile"
withParameters:@{}
withTimeout: SERVER_TIMEOUT
onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) {
if (!error && !methodError && [methodResult isKindOfClass:[NSDictionary class]]) {
AppDelegate.instance.currentProfile = methodResult[@"label"];
}
}];
}
else {
AppDelegate.instance.currentProfile = @"";
}
}

- (void)dealloc {
// NSStream delegate uses "assign" in XCode 15.4 SDK. So we nil it.
inStream.delegate = nil;
Expand Down