Skip to content
New issue

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

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

Already on GitHub? # to your account

Feature: Support listing/loading profiles #1155

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
@@ -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
28 changes: 28 additions & 0 deletions XBMC Remote/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -5665,6 +5665,7 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@"st_music_addon",
@"st_kodi_action",
@"st_kodi_window",
@"st_profile",
];

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

xbmcSettings.mainParameters = [@[
@@ -5787,6 +5791,20 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@"morelabel": LOCALIZED_STR(@"Activate a specific window"),
@"forceActionSheet": @YES,
},

@{
@"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 = @[
@@ -5871,6 +5889,12 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@"row8": @"addonid",
@"row9": @"addonid",
},

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

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

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

xbmcSettings.subItem.mainParameters = [@[
@@ -5921,6 +5947,7 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
@{},
@{},
@{},
@{},
] mutableCopy];

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

xbmcSettings.subItem.rowHeight = SETTINGS_ROW_HEIGHT;
46 changes: 45 additions & 1 deletion XBMC Remote/DetailViewController.m
Original file line number Diff line number Diff line change
@@ -337,14 +337,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];
}

@@ -1605,6 +1608,9 @@ - (void)didSelectItemAtIndexPath:(NSIndexPath*)indexPath item:(NSDictionary*)ite
else if ([parameters[@"forcePlayback"] boolValue]) {
[self startPlayback:item indexPath:indexPath shuffle:NO];
}
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];
@@ -2653,6 +2659,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;
@@ -4368,6 +4385,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];
@@ -4748,6 +4785,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];
elapsedTime = 0;
startTime = [NSDate timeIntervalSinceReferenceDate];
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
@@ -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
@@ -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
@@ -197,6 +197,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";

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

[self readShowEmptyTvShows];

[self readCurrentProfile];
}];
}

@@ -356,6 +358,24 @@ - (void)readSorttokens {
}
}

- (void)readCurrentProfile {
// Read current active user profile
if ([VersionCheck hasProfilesSupport]) {
[[Utilities getJsonRPC]
callMethod:@"Profiles.GetCurrentProfile"
withParameters:@{}
withTimeout:SERVER_CHECK_TIMER
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;