Skip to content

Commit f7ecab7

Browse files
committed
Add Option: Stop scrobbling to Last.Fm when screen saver running
1 parent 1a03876 commit f7ecab7

11 files changed

Lines changed: 114 additions & 31 deletions

File tree

Preferences/AccountPreferences.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ @interface AccountPreferences ()
1818
@property (weak) IBOutlet NSButton *lastFmEnabled;
1919
@property (weak) IBOutlet NSImageView *imageLastFm;
2020
@property (weak) IBOutlet NSTextField *descriptionLastFm;
21+
@property (weak) IBOutlet NSButton *stopScrobblingWhenScreenSaverRunning;
2122

2223
@property (assign) LFUser *user;
2324
@end
@@ -41,6 +42,11 @@ -(void)update:(BOOL)enabled
4142
self.descriptionLastFm.enabled = enabled;
4243
self.labelLastFmName.hidden = !enabled;
4344
self.btnConnect.hidden = !enabled;
45+
self.stopScrobblingWhenScreenSaverRunning.hidden = !enabled;
46+
47+
if (player().document.stopScrobblingWhenScreenSaverRunning)
48+
self.stopScrobblingWhenScreenSaverRunning.state = enabled?NSOnState:NSOffState;
49+
4450
}
4551

4652
-(void)updateUIUser:(LFUser*)user

src/PlayerDocument+ScreenSaver.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// PlayerDocument_ScreenSaver.h
3+
// uPlayer
4+
//
5+
// Created by liaogang on 16/3/28.
6+
// Copyright © 2016年 liaogang. All rights reserved.
7+
//
8+
9+
#import "PlayerDocument.h"
10+
11+
#ifndef PlayerDocument_ScreenSaver
12+
#define PlayerDocument_ScreenSaver
13+
@interface PlayerDocument (ScreenSaver)
14+
-(void)monitorScreenSaverEvent;
15+
@end
16+
#endif

src/PlayerDocument.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import "PlayerList.h"
1212
#import "PlayerQueue.h"
1313

14+
1415
@interface PlayerDocument : NSObject
1516

1617
/// value need to searialize.
@@ -20,16 +21,18 @@
2021
@property (nonatomic) int playOrder,//enum PlayOrder
2122
playState,//enum PlayStatus
2223
fontHeight,
23-
lastFmEnabled;
24+
lastFmEnabled,
25+
stopScrobblingWhenScreenSaverRunning;
26+
27+
// runtime property
28+
@property BOOL screenSaverRunning;
2429

2530
@property (nonatomic) int playingIndexList,playingIndexTrack;
2631

2732

2833
@property (nonatomic) NSTimeInterval playTime;
2934

3035

31-
32-
3336
@property (nonatomic,strong) PlayerQueue *playerQueue;
3437
@property (nonatomic,strong) PlayerlList *playerlList;
3538

@@ -38,6 +41,8 @@ lastFmEnabled;
3841
// value not
3942
@property (nonatomic) bool needBackupConfigFile;
4043

44+
-(BOOL)shouldScrobbleToLastFm;
45+
4146
@end
4247

4348

src/PlayerDocument.mm

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
#import "PlayerDocument.h"
1111
#import <Foundation/Foundation.h>
1212
#import "serialize.h"
13-
14-
15-
13+
#include "PlayerDocument+ScreenSaver.h"
1614

1715
@interface PlayerDocument ()
18-
@end
1916

17+
@end
2018

2119
@implementation PlayerDocument
2220

@@ -31,16 +29,39 @@ -(instancetype)init
3129
self.playTime = -1;
3230
self.trackSongsWhenPlayStarted = FALSE;
3331
self.lastFmEnabled = FALSE;
32+
self.stopScrobblingWhenScreenSaverRunning = TRUE;
3433
self.volume = 1.0;
3534
self.playerQueue=[[PlayerQueue alloc]init];
3635
self.playingIndexList = -1;
3736
self.playingIndexTrack = -1;
37+
38+
#ifdef PlayerDocument_ScreenSaver
39+
[self monitorScreenSaverEvent];
40+
#else
41+
#warning "ScreenSaver not motiter enabled"
42+
#endif
43+
3844
}
3945

4046
return self;
4147
}
4248

4349

44-
50+
-(BOOL)shouldScrobbleToLastFm
51+
{
52+
if( self.lastFmEnabled)
53+
{
54+
if (self.stopScrobblingWhenScreenSaverRunning )
55+
{
56+
if (self.screenSaverRunning) {
57+
return FALSE;
58+
}
59+
}
60+
61+
return TRUE;
62+
}
63+
else
64+
return FALSE;
65+
}
4566

4667
@end

src/PlayerSerialize.mm

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,16 @@ -(bool)load
413413
int playingIndexList,playingIndexTrack;
414414
NSTimeInterval playTime;
415415

416-
*file >> resumeAtReboot >> trackSongsWhenPlayStarted >> volume >> playOrder >>playState >> fontHeight >> lastFmEnabled >>playingIndexList >> playingIndexTrack >> playTime;
416+
*file >> resumeAtReboot
417+
>> trackSongsWhenPlayStarted
418+
>> volume
419+
>> playOrder
420+
>>playState
421+
>> fontHeight
422+
>> lastFmEnabled
423+
>>playingIndexList
424+
>> playingIndexTrack
425+
>> playTime;
417426

418427
self.resumeAtReboot=resumeAtReboot;
419428
self.trackSongsWhenPlayStarted = trackSongsWhenPlayStarted;
@@ -510,7 +519,16 @@ -(bool)saveConfig
510519

511520
NSLog(@"list: %d, index: %d",self.playingIndexList,self.playingIndexTrack);
512521

513-
*file << self.resumeAtReboot << self.trackSongsWhenPlayStarted << self.volume << self.playOrder << self.playState << self.fontHeight << self.lastFmEnabled <<self.playingIndexList << self.playingIndexTrack <<self.playTime ;
522+
*file << self.resumeAtReboot
523+
<< self.trackSongsWhenPlayStarted
524+
<< self.volume
525+
<< self.playOrder
526+
<< self.playState
527+
<< self.fontHeight
528+
<< self.lastFmEnabled
529+
<< self.playingIndexList
530+
<< self.playingIndexTrack
531+
<< self.playTime ;
514532

515533

516534
fclose(file);

uPlayer.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
1ECEB7621A9053A2006E8C23 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1ECEB7601A9053A2006E8C23 /* [email protected] */; };
6363
1ED021AA1A7B3383008526E8 /* PlayerList.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ED021A91A7B3383008526E8 /* PlayerList.m */; };
6464
1ED021AD1A7B3C89008526E8 /* PlayerSerachMng.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ED021AC1A7B3C89008526E8 /* PlayerSerachMng.m */; };
65+
1ED32D961CA9059C00D0C87D /* PlayerDocument+ScreenSaver.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ED32D951CA9059C00D0C87D /* PlayerDocument+ScreenSaver.m */; };
6566
1ED6B0A51AEA043F00DBEEE4 /* id3Info.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1ED6B0A41AEA043F00DBEEE4 /* id3Info.mm */; };
6667
1EDAAD451AB6F17E009DB36A /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1EDAAD471AB6F17E009DB36A /* Localizable.strings */; };
6768
1EDE8FA91A773D810086677B /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1EDE8FA81A773D810086677B /* AppDelegate.mm */; };
@@ -216,6 +217,9 @@
216217
1ED021A91A7B3383008526E8 /* PlayerList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlayerList.m; sourceTree = "<group>"; };
217218
1ED021AB1A7B3C89008526E8 /* PlayerSerachMng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlayerSerachMng.h; sourceTree = "<group>"; };
218219
1ED021AC1A7B3C89008526E8 /* PlayerSerachMng.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlayerSerachMng.m; sourceTree = "<group>"; };
220+
1ED32D931CA9054E00D0C87D /* PlayerDocument+ScreenSaver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PlayerDocument+ScreenSaver.h"; sourceTree = "<group>"; };
221+
1ED32D951CA9059C00D0C87D /* PlayerDocument+ScreenSaver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PlayerDocument+ScreenSaver.m"; sourceTree = "<group>"; };
222+
1ED32D971CA90FC000D0C87D /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
219223
1ED6B0A31AEA043F00DBEEE4 /* id3Info.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = id3Info.h; path = ../src/id3Info.h; sourceTree = "<group>"; };
220224
1ED6B0A41AEA043F00DBEEE4 /* id3Info.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = id3Info.mm; path = ../src/id3Info.mm; sourceTree = "<group>"; };
221225
1EDAAD461AB6F17E009DB36A /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
@@ -296,6 +300,8 @@
296300
1E5F9EC41A7A1979000360D7 /* PlayerEngine.mm */,
297301
1E0B2BED1A77536800B4FE14 /* PlayerDocument.h */,
298302
1E0B2BEE1A77536800B4FE14 /* PlayerDocument.mm */,
303+
1ED32D931CA9054E00D0C87D /* PlayerDocument+ScreenSaver.h */,
304+
1ED32D951CA9059C00D0C87D /* PlayerDocument+ScreenSaver.m */,
299305
1E5F9EC91A7A2DB2000360D7 /* PlayerSerialize.h */,
300306
1E5F9EC81A7A2DB2000360D7 /* PlayerSerialize.mm */,
301307
1E0B2BFE1A77575400B4FE14 /* PlayerTypeDefines.h */,
@@ -434,6 +440,7 @@
434440
1EDE8F991A773D810086677B = {
435441
isa = PBXGroup;
436442
children = (
443+
1ED32D971CA90FC000D0C87D /* README.md */,
437444
1E4A13B01BA94C600008CBEE /* lyricsFetcher */,
438445
1EDE8FA41A773D810086677B /* uPlayer */,
439446
1E0B2BEC1A77536800B4FE14 /* src */,
@@ -745,6 +752,7 @@
745752
1E4A13C61BA94C730008CBEE /* stringConv.cpp in Sources */,
746753
1E0B2BFD1A7755C400B4FE14 /* PlayerImpl.mm in Sources */,
747754
1E1719841BCE36B90048C3EB /* AlbumViewController.m in Sources */,
755+
1ED32D961CA9059C00D0C87D /* PlayerDocument+ScreenSaver.m in Sources */,
748756
1E5F9EC51A7A1979000360D7 /* PlayerEngine.mm in Sources */,
749757
1E4A13C51BA94C730008CBEE /* lrcFch_ting.cpp in Sources */,
750758
1EAA25C11AD67405008F44EC /* MemoryFileBuffer.cpp in Sources */,

uPlayer/AppDelegate.mm

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
381381

382382
}
383383

384+
384385
-(void)loadiTunesMedia
385386
{
386387
PlayerDocument *d = player().document;
@@ -460,7 +461,7 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification
460461

461462
-(void)scrobblerSong:(TrackInfo*)info
462463
{
463-
if( player().document.lastFmEnabled)
464+
if( [player().document shouldScrobbleToLastFm])
464465
{
465466
dojobInBkgnd(^{
466467
string artist(info.artist.UTF8String);
@@ -474,7 +475,7 @@ -(void)scrobblerSong:(TrackInfo*)info
474475

475476
-(void)scrobbler:(NSNotification*)n
476477
{
477-
if( player().document.lastFmEnabled)
478+
if( [player().document shouldScrobbleToLastFm])
478479
{
479480
LFUser *user = lastFmUser();
480481
if (user->isConnected)
@@ -515,10 +516,6 @@ -(BOOL)importDirectoryEnabled
515516
return player().document.playerlList.selectItem.type != type_temporary ;
516517
}
517518

518-
-(bool)lastFmEnabled
519-
{
520-
return player().document.lastFmEnabled;
521-
}
522519

523520
- (IBAction)cmdLastFm_Love:(id)sender
524521
{

uPlayer/Base.lproj/AccountPreferences.xib

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6751" systemVersion="14D87h" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9532" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6751"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
5+
<capability name="box content view" minToolsVersion="7.0"/>
56
</dependencies>
67
<objects>
78
<customObject id="-2" userLabel="File's Owner" customClass="AccountPreferences">
@@ -12,6 +13,7 @@
1213
<outlet property="imageLastFm" destination="r0b-Pd-U7B" id="vZ2-0w-8xn"/>
1314
<outlet property="labelLastFmName" destination="xIa-IC-jrq" id="9Ve-jJ-nRq"/>
1415
<outlet property="lastFmEnabled" destination="0tW-R3-Bno" id="G9s-yX-t5H"/>
16+
<outlet property="stopScrobblingWhenScreenSaverRunning" destination="av8-8y-sOU" id="9jD-S4-zqO"/>
1517
</connections>
1618
</customObject>
1719
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
@@ -28,7 +30,7 @@
2830
<box autoresizesSubviews="NO" borderType="none" id="Evs-lC-hgm">
2931
<rect key="frame" x="-3" y="-4" width="486" height="274"/>
3032
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
31-
<view key="contentView">
33+
<view key="contentView" id="uNX-mB-N2x">
3234
<rect key="frame" x="0.0" y="0.0" width="486" height="259"/>
3335
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
3436
<subviews>
@@ -47,7 +49,7 @@
4749
</textFieldCell>
4850
</textField>
4951
<button verticalHuggingPriority="750" id="7WZ-g5-1gW">
50-
<rect key="frame" x="35" y="130" width="193" height="32"/>
52+
<rect key="frame" x="35" y="55" width="193" height="32"/>
5153
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
5254
<buttonCell key="cell" type="push" title="Connect to your account" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="nHj-hg-UQI">
5355
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -69,22 +71,30 @@
6971
</connections>
7072
</button>
7173
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="xIa-IC-jrq">
72-
<rect key="frame" x="228" y="140" width="194" height="17"/>
74+
<rect key="frame" x="228" y="65" width="194" height="17"/>
7375
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
7476
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" id="7ru-dY-wGx">
7577
<font key="font" metaFont="system"/>
7678
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
7779
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
7880
</textFieldCell>
7981
</textField>
82+
<button id="av8-8y-sOU">
83+
<rect key="frame" x="39" y="138" width="429" height="18"/>
84+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
85+
<buttonCell key="cell" type="check" title="Stop scrobbling when screen saver running" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="lNm-oT-Hic">
86+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
87+
<font key="font" metaFont="system" size="14"/>
88+
</buttonCell>
89+
</button>
8090
</subviews>
8191
</view>
8292
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
8393
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
8494
</box>
8595
</subviews>
8696
</view>
87-
<point key="canvasLocation" x="264" y="271"/>
97+
<point key="canvasLocation" x="681" y="173"/>
8898
</window>
8999
</objects>
90100
<resources>

uPlayer/Base.lproj/Main.storyboard

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="14F1504" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
55
</dependencies>
66
<scenes>
77
<!--Application-->
@@ -495,11 +495,11 @@
495495
<scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Sof-Yj-DjO">
496496
<rect key="frame" x="0.0" y="0.0" width="610" height="303"/>
497497
<clipView key="contentView" id="rHG-2U-uEe">
498-
<rect key="frame" x="1" y="16" width="608" height="284"/>
498+
<rect key="frame" x="1" y="0.0" width="608" height="302"/>
499499
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
500500
<subviews>
501501
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" headerView="UNq-A6-I6m" viewBased="YES" id="1Gu-As-ZBl">
502-
<rect key="frame" x="0.0" y="0.0" width="607" height="0.0"/>
502+
<rect key="frame" x="0.0" y="0.0" width="608" height="279"/>
503503
<autoresizingMask key="autoresizingMask"/>
504504
<size key="intercellSpacing" width="3" height="2"/>
505505
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@@ -619,7 +619,7 @@
619619
<autoresizingMask key="autoresizingMask"/>
620620
</scroller>
621621
<tableHeaderView key="headerView" id="UNq-A6-I6m">
622-
<rect key="frame" x="0.0" y="0.0" width="608" height="17"/>
622+
<rect key="frame" x="0.0" y="0.0" width="608" height="23"/>
623623
<autoresizingMask key="autoresizingMask"/>
624624
<connections>
625625
<outlet property="menu" destination="0L1-7k-cmQ" id="e8q-uI-Ax3"/>

uPlayer/Base.lproj/StatusMenu.xib

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14D130a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9532" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
55
</dependencies>
66
<objects>
77
<customObject id="-2" userLabel="File's Owner" customClass="AppDelegate"/>
@@ -34,7 +34,6 @@
3434
<modifierMask key="keyEquivalentModifierMask"/>
3535
<connections>
3636
<action selector="cmdLastFm_Love:" target="-2" id="m92-ak-Fmy"/>
37-
<binding destination="-2" name="enabled" keyPath="lastFmEnabled" id="eWr-Gn-Z51"/>
3837
</connections>
3938
</menuItem>
4039
<menuItem isSeparatorItem="YES" id="M9L-oc-J6c"/>

0 commit comments

Comments
 (0)