adium 4377:08aede6296fd: Refactoring of ESiTunesPlugin:
commits at adium.im
commits at adium.im
Tue Dec 13 22:09:27 UTC 2011
details: http://hg.adium.im/adium/rev/08aede6296fd
revision: 4377:08aede6296fd
branch: (none)
author: Patrick Steinhardt <steinhardt.p at me.com>
date: Tue Dec 13 23:01:27 2011 +0100
Refactoring of ESiTunesPlugin:
- Use same menu in menu bar, context menu and toolbar.
- Fix bug when replacing tokens with empty strings.
- Make tokens un-localizable.
- Cleanup.
diffs (809 lines):
diff -r a2a2054b9dc8 -r 08aede6296fd Plugins/Purple Service/CBPurpleAccount.m
--- a/Plugins/Purple Service/CBPurpleAccount.m Tue Dec 13 22:36:35 2011 +0100
+++ b/Plugins/Purple Service/CBPurpleAccount.m Tue Dec 13 23:01:27 2011 +0100
@@ -2394,19 +2394,19 @@
{
NSMutableDictionary *arguments = nil;
- if (tuneinfo && [[tuneinfo objectForKey:ITUNES_PLAYER_STATE] isEqualToString:@"Playing"]) {
+ if (tuneinfo && [[tuneinfo objectForKey:KEY_ITUNES_PLAYER_STATE] isEqualToString:@"Playing"]) {
arguments = [NSMutableDictionary dictionary];
- NSString *artist = [tuneinfo objectForKey:ITUNES_ARTIST];
- NSString *name = [tuneinfo objectForKey:ITUNES_NAME];
+ NSString *artist = [tuneinfo objectForKey:KEY_ITUNES_ARTIST];
+ NSString *name = [tuneinfo objectForKey:KEY_ITUNES_NAME];
[arguments setObject:(artist ? artist : @"") forKey:[NSString stringWithUTF8String:PURPLE_TUNE_ARTIST]];
[arguments setObject:(name ? name : @"") forKey:[NSString stringWithUTF8String:PURPLE_TUNE_TITLE]];
- [arguments setObject:([tuneinfo objectForKey:ITUNES_ALBUM] ? [tuneinfo objectForKey:ITUNES_ALBUM] : @"") forKey:[NSString stringWithUTF8String:PURPLE_TUNE_ALBUM]];
- [arguments setObject:([tuneinfo objectForKey:ITUNES_GENRE] ? [tuneinfo objectForKey:ITUNES_GENRE] : @"") forKey:[NSString stringWithUTF8String:PURPLE_TUNE_GENRE]];
- [arguments setObject:([tuneinfo objectForKey:ITUNES_TOTAL_TIME] ? [tuneinfo objectForKey:ITUNES_TOTAL_TIME]:[NSNumber numberWithInteger:-1]) forKey:[NSString stringWithUTF8String:PURPLE_TUNE_TIME]];
- [arguments setObject:([tuneinfo objectForKey:ITUNES_YEAR] ? [tuneinfo objectForKey:ITUNES_YEAR]:[NSNumber numberWithInteger:-1]) forKey:[NSString stringWithUTF8String:PURPLE_TUNE_YEAR]];
- [arguments setObject:([tuneinfo objectForKey:ITUNES_STORE_URL] ? [tuneinfo objectForKey:ITUNES_STORE_URL] : @"") forKey:[NSString stringWithUTF8String:PURPLE_TUNE_URL]];
+ [arguments setObject:([tuneinfo objectForKey:KEY_ITUNES_ALBUM] ? [tuneinfo objectForKey:KEY_ITUNES_ALBUM] : @"") forKey:[NSString stringWithUTF8String:PURPLE_TUNE_ALBUM]];
+ [arguments setObject:([tuneinfo objectForKey:KEY_ITUNES_GENRE] ? [tuneinfo objectForKey:KEY_ITUNES_GENRE] : @"") forKey:[NSString stringWithUTF8String:PURPLE_TUNE_GENRE]];
+ [arguments setObject:([tuneinfo objectForKey:KEY_ITUNES_TOTAL_TIME] ? [tuneinfo objectForKey:KEY_ITUNES_TOTAL_TIME]:[NSNumber numberWithInteger:-1]) forKey:[NSString stringWithUTF8String:PURPLE_TUNE_TIME]];
+ [arguments setObject:([tuneinfo objectForKey:KEY_ITUNES_YEAR] ? [tuneinfo objectForKey:KEY_ITUNES_YEAR]:[NSNumber numberWithInteger:-1]) forKey:[NSString stringWithUTF8String:PURPLE_TUNE_YEAR]];
+ [arguments setObject:([tuneinfo objectForKey:KEY_ITUNES_STORE_URL] ? [tuneinfo objectForKey:KEY_ITUNES_STORE_URL] : @"") forKey:[NSString stringWithUTF8String:PURPLE_TUNE_URL]];
[arguments setObject:[NSString stringWithFormat:@"%@%@%@", (name ? name : @""), (name && artist ? @" - " : @""), (artist ? artist : @"")]
forKey:[NSString stringWithUTF8String:PURPLE_TUNE_FULL]];
diff -r a2a2054b9dc8 -r 08aede6296fd Source/ESStatusAdvancedPreferences.m
--- a/Source/ESStatusAdvancedPreferences.m Tue Dec 13 22:36:35 2011 +0100
+++ b/Source/ESStatusAdvancedPreferences.m Tue Dec 13 23:01:27 2011 +0100
@@ -63,28 +63,28 @@
[label_title setLocalizedString:AILocalizedString(@"Title", nil)];
[label_year setLocalizedString:AILocalizedString(@"Year", nil)];
- NSString *displayFormat = [adium.preferenceController preferenceForKey:KEY_CURRENT_TRACK_FORMAT
+ NSString *displayFormat = [adium.preferenceController preferenceForKey:KEY_ITUNES_TRACK_FORMAT
group:PREF_GROUP_STATUS_PREFERENCES];
if (!displayFormat || ![displayFormat length]) {
- displayFormat = [NSString stringWithFormat:@"%@ - %@", TRACK_TRIGGER, ARTIST_TRIGGER];
+ displayFormat = [NSString stringWithFormat:@"%@ - %@", TRIGGER_TRACK, TRIGGER_ARTIST];
}
[tokenField_format setObjectValue:[self separateStringIntoTokens:displayFormat]];
[tokenField_format setTokenizingCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@""]];
[tokenField_format setDelegate:self];
- [tokenField_album setStringValue:ALBUM_TRIGGER];
+ [tokenField_album setStringValue:TRIGGER_ALBUM];
[tokenField_album setDelegate:self];
- [tokenField_artist setStringValue:ARTIST_TRIGGER];
+ [tokenField_artist setStringValue:TRIGGER_ARTIST];
[tokenField_artist setDelegate:self];
- [tokenField_composer setStringValue:COMPOSER_TRIGGER];
+ [tokenField_composer setStringValue:TRIGGER_COMPOSER];
[tokenField_composer setDelegate:self];
- [tokenField_genre setStringValue:GENRE_TRIGGER];
+ [tokenField_genre setStringValue:TRIGGER_GENRE];
[tokenField_genre setDelegate:self];
- [tokenField_status setStringValue:STATUS_TRIGGER];
+ [tokenField_status setStringValue:TRIGGER_STATUS];
[tokenField_status setDelegate:self];
- [tokenField_title setStringValue:TRACK_TRIGGER];
+ [tokenField_title setStringValue:TRIGGER_TRACK];
[tokenField_title setDelegate:self];
- [tokenField_year setStringValue:YEAR_TRIGGER];
+ [tokenField_year setStringValue:TRIGGER_YEAR];
[tokenField_year setDelegate:self];
[super viewDidLoad];
@@ -93,7 +93,7 @@
- (IBAction)changeFormat:(id)sender
{
[adium.preferenceController setPreference:[[sender objectValue] componentsJoinedByString:@""]
- forKey:KEY_CURRENT_TRACK_FORMAT
+ forKey:KEY_ITUNES_TRACK_FORMAT
group:PREF_GROUP_STATUS_PREFERENCES];
[[NSNotificationCenter defaultCenter] postNotificationName:Adium_CurrentTrackFormatChangedNotification
object:[[sender objectValue] componentsJoinedByString:@""]];
@@ -129,19 +129,19 @@
- (NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject
{
- if ([representedObject isEqualToString:ALBUM_TRIGGER]) {
+ if ([representedObject isEqualToString:TRIGGER_ALBUM]) {
return AILocalizedString(@"Let It Be", @"Example for album title");
- } else if ([representedObject isEqualToString:ARTIST_TRIGGER]) {
+ } else if ([representedObject isEqualToString:TRIGGER_ARTIST]) {
return AILocalizedString(@"The Beatles", @"Example for song artist");
- } else if ([representedObject isEqualToString:COMPOSER_TRIGGER]) {
+ } else if ([representedObject isEqualToString:TRIGGER_COMPOSER]) {
return AILocalizedString(@"Harrison", @"Example for song composer");
- } else if ([representedObject isEqualToString:GENRE_TRIGGER]) {
+ } else if ([representedObject isEqualToString:TRIGGER_GENRE]) {
return AILocalizedString(@"Rock", @"Example for song genre");
- } else if ([representedObject isEqualToString:STATUS_TRIGGER]) {
+ } else if ([representedObject isEqualToString:TRIGGER_STATUS]) {
return AILocalizedString(@"Paused", @"Example for music players' status (e.g. playing, paused)");
- } else if ([representedObject isEqualToString:TRACK_TRIGGER]) {
+ } else if ([representedObject isEqualToString:TRIGGER_TRACK]) {
return AILocalizedString(@"I Me Mine", @"Example for song title");
- } else if ([representedObject isEqualToString:YEAR_TRIGGER]) {
+ } else if ([representedObject isEqualToString:TRIGGER_YEAR]) {
return AILocalizedString(@"1970", @"Example for a songs debut-year");
} else {
return nil;
@@ -170,20 +170,20 @@
// Evaluate if it known token
if ([[string substringFromIndex:i] hasPrefix:@"%_"]) {
NSString *substringFromIndex = [string substringFromIndex:i];
- if ([substringFromIndex hasPrefix:ALBUM_TRIGGER]) {
- i += [ALBUM_TRIGGER length];
- } else if ([substringFromIndex hasPrefix:ARTIST_TRIGGER]) {
- i += [ARTIST_TRIGGER length];
- } else if ([substringFromIndex hasPrefix:COMPOSER_TRIGGER]) {
- i += [COMPOSER_TRIGGER length];
- } else if ([substringFromIndex hasPrefix:GENRE_TRIGGER]) {
- i += [GENRE_TRIGGER length];
- } else if ([substringFromIndex hasPrefix:STATUS_TRIGGER]) {
- i += [STATUS_TRIGGER length];
- } else if ([substringFromIndex hasPrefix:TRACK_TRIGGER]) {
- i += [TRACK_TRIGGER length];
- } else if ([substringFromIndex hasPrefix:YEAR_TRIGGER]) {
- i += [YEAR_TRIGGER length];
+ if ([substringFromIndex hasPrefix:TRIGGER_ALBUM]) {
+ i += [TRIGGER_ALBUM length];
+ } else if ([substringFromIndex hasPrefix:TRIGGER_ARTIST]) {
+ i += [TRIGGER_ARTIST length];
+ } else if ([substringFromIndex hasPrefix:TRIGGER_COMPOSER]) {
+ i += [TRIGGER_COMPOSER length];
+ } else if ([substringFromIndex hasPrefix:TRIGGER_GENRE]) {
+ i += [TRIGGER_GENRE length];
+ } else if ([substringFromIndex hasPrefix:TRIGGER_STATUS]) {
+ i += [TRIGGER_STATUS length];
+ } else if ([substringFromIndex hasPrefix:TRIGGER_TRACK]) {
+ i += [TRIGGER_TRACK length];
+ } else if ([substringFromIndex hasPrefix:TRIGGER_YEAR]) {
+ i += [TRIGGER_YEAR length];
} else {
for (; i < [string length]; i++) {
if ([[string substringFromIndex:(i + 1)] hasPrefix:@"%_"]) {
diff -r a2a2054b9dc8 -r 08aede6296fd Source/ESiTunesPlugin.h
--- a/Source/ESiTunesPlugin.h Tue Dec 13 22:36:35 2011 +0100
+++ b/Source/ESiTunesPlugin.h Tue Dec 13 23:01:27 2011 +0100
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
+
#import <Adium/AIContentControllerProtocol.h>
typedef enum {
@@ -26,29 +26,29 @@
#define Adium_iTunesTrackChangedNotification @"Adium_iTunesTrackChangedNotification"
#define Adium_CurrentTrackFormatChangedNotification @"Adium_CurrentTrackFormatChangedNotification"
-#define KEY_CURRENT_TRACK_FORMAT @"Current Track Format"
+#define TRIGGER_ALBUM @"%_album"
+#define TRIGGER_ARTIST @"%_artist"
+#define TRIGGER_COMPOSER @"%_composer"
+#define TRIGGER_GENRE @"%_genre"
+#define TRIGGER_STATUS @"%_status"
+#define TRIGGER_TRACK @"%_track"
+#define TRIGGER_YEAR @"%_year"
+#define TRIGGER_STORE_URL @"%_iTMS"
+#define TRIGGER_MUSIC @"%_music"
+#define TRIGGER_CURRENT_TRACK @"%_iTunes"
-#define ALBUM_TRIGGER AILocalizedString(@"%_album","Trigger for the album of the currently playing iTunes song")
-#define ARTIST_TRIGGER AILocalizedString(@"%_artist","Trigger for the artist of the currently playing iTunes song")
-#define COMPOSER_TRIGGER AILocalizedString(@"%_composer","Trigger for the composer of the currently playing iTunes song")
-#define GENRE_TRIGGER AILocalizedString(@"%_genre","Trigger for the genre of the currently playing iTunes song")
-#define STATUS_TRIGGER AILocalizedString(@"%_status","Trigger for the genre of the currently playing iTunes song")
-#define TRACK_TRIGGER AILocalizedString(@"%_track","Trigger for the name of the currently playing iTunes song")
-#define YEAR_TRIGGER AILocalizedString(@"%_year","Trigger for the year of the currently playing iTunes song")
-#define STORE_URL_TRIGGER AILocalizedString(@"%_iTMS","Trigger for an iTunes Music Store link to the currently playing iTunes song")
-#define MUSIC_TRIGGER AILocalizedString(@"%_music","Command which triggers *is listening to %_track by %_artist*")
-#define CURRENT_TRACK_TRIGGER AILocalizedString(@"%_iTunes","Trigger for the song - artist of the currently playing iTunes song")
-
-#define ITUNES_ALBUM @"Album"
-#define ITUNES_ARTIST @"Artist"
-#define ITUNES_COMPOSER @"Composer"
-#define ITUNES_GENRE @"Genre"
-#define ITUNES_PLAYER_STATE @"Player State"
-#define ITUNES_NAME @"Name"
-#define ITUNES_STREAM_TITLE @"Stream Title"
-#define ITUNES_STORE_URL @"Store URL"
-#define ITUNES_TOTAL_TIME @"Total Time"
-#define ITUNES_YEAR @"Year"
+#define KEY_TRIGGERS_TOOLBAR @"iTunesItem"
+#define KEY_ITUNES_TRACK_FORMAT @"Current Track Format"
+#define KEY_ITUNES_ALBUM @"Album"
+#define KEY_ITUNES_ARTIST @"Artist"
+#define KEY_ITUNES_COMPOSER @"Composer"
+#define KEY_ITUNES_GENRE @"Genre"
+#define KEY_ITUNES_PLAYER_STATE @"Player State"
+#define KEY_ITUNES_NAME @"Name"
+#define KEY_ITUNES_STREAM_TITLE @"Stream Title"
+#define KEY_ITUNES_STORE_URL @"Store URL"
+#define KEY_ITUNES_TOTAL_TIME @"Total Time"
+#define KEY_ITUNES_YEAR @"Year"
@interface ESiTunesPlugin : AIPlugin <AIContentFilter> {
NSDictionary *iTunesCurrentInfo;
diff -r a2a2054b9dc8 -r 08aede6296fd Source/ESiTunesPlugin.m
--- a/Source/ESiTunesPlugin.m Tue Dec 13 22:36:35 2011 +0100
+++ b/Source/ESiTunesPlugin.m Tue Dec 13 23:01:27 2011 +0100
@@ -33,28 +33,30 @@
#import <Adium/AIStatus.h>
#import <WebKit/WebKit.h>
-#define ITUNES_MINIMUM_VERSION 4.6f
-#define ITUNES_STATUS_ID -8000
+#define STRING_TRIGGERS_MENU AILocalizedString(@"Insert iTunes Token", "Label used for edit and contextual menus of iTunes triggers")
+#define STRING_TRIGGERS_TOOLBAR AILocalizedString(@"iTunes","Label for iTunes toolbar menu item.")
+#define STRING_ALBUM AILocalizedString(@"Album", "Album of current song")
+#define STRING_ARTIST AILocalizedString(@"Artist", "Artist of current song")
+#define STRING_COMPOSER AILocalizedString(@"Composer", "Composer of current song")
+#define STRING_GENRE AILocalizedString(@"Genre", "Genre of current song")
+#define STRING_STATUS AILocalizedString(@"Player State", "Playing-status of current song (e.g. paused, playing)")
+#define STRING_TRACK AILocalizedString(@"Track", "Track name of current song")
+#define STRING_YEAR AILocalizedString(@"Year", "Year of current song")
+#define STRING_STORE_URL AILocalizedString(@"iTunes Music Store Link", "iTUnes Music Store link for current song")
+#define STRING_MUSIC AILocalizedString(@"Listening Status", "Listening status string (*is listening to XXX by YYY)")
+#define STRING_CURRENT_TRACK AILocalizedString(@"Current Track", "Current track information (Track - Artist)")
#pragma mark -
-#define PLAYER_STATE @"Player State"
-#define KEY_PLAYING @"Playing"
-#define KEY_PAUSED @"Paused"
-#define KEY_STOPPED @"Stopped"
-#define ITMS_SEARCH_URL @"itms://itunes.com/link?"
- //itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/search?"
-#pragma mark -
-
-#define MUSICAL_NOTE [NSString stringWithUTF8String:"\342\231\253"]
-#define CURRENT_ITUNES_TRACK [NSString stringWithFormat:@"%@ iTunes", MUSICAL_NOTE]
-
-#define TOOLBAR_LABEL AILocalizedString(@"iTunes","Label for iTunes toolbar menu item.")
+#define ITUNES_MINIMUM_VERSION 4.6f
+#define ITUNES_STATUS_ID -8000
+#define ITUNES_ITMS_SEARCH_URL @"itms://itunes.com/link?"
#pragma mark -
-#define ITUNES_TOOLBAR_ITEM @"iTunesItem"
-#define INSERT_TRIGGERS_MENU AILocalizedString(@"Insert iTunes Token", "Label used for edit and contextual menus of iTunes triggers")
+#define KEY_ITUNES_PLAYING @"Playing"
+#define KEY_ITUNES_PAUSED @"Paused"
+#define KEY_ITUNES_STOPPED @"Stopped"
#pragma mark -
@@ -64,16 +66,21 @@
- (void)updateiTunesCurrentTrackFormat;
- (void)createiTunesToolbarItemWithPath:(NSString *)path;
- (void)createiTunesToolbarItemMenuItems:(NSMenu *)iTunesMenu;
-- (void)createTriggersMenu;
-- (void)filterAndInsertString:(NSString *)inString;
+- (NSMenu *)createTriggerMenu;
+- (void)insertTriggerMenu;
- (void)insertStringIntoMessageEntryView:(NSString *)inString;
- (void)insertAttributedStringIntoMessageEntryView:(NSAttributedString *)inString;
- (void)loadiTunesCurrentInfoViaApplescript;
+- (void)insertFilteredString:(id)sender;
+- (void)filterAndInsertString:(NSString *)inString;
+- (NSAttributedString *)filterAttributedString:(NSAttributedString *)inAttributedString context:(id)context;
+- (CGFloat)filterPriority;
+
- (void)fireUpdateiTunesInfo;
- (void)iTunesUpdate:(NSNotification *)aNotification;
- (void)currentTrackFormatDidChange:(NSNotification *)aNotification;
-- (void)insertFilteredString:(id)sender;
+- (void)insertUnfilteredString:(id)sender;
- (void)insertiTMSLink;
- (void)gatherSelection;
- (void)bringiTunesToFront;
@@ -147,9 +154,9 @@
NSMutableDictionary *mutableNewInfo = [newInfo mutableCopy];
//If we get a stream title, use that as the track name
- if ([mutableNewInfo objectForKey:ITUNES_STREAM_TITLE] && [(NSString *)[mutableNewInfo objectForKey:ITUNES_STREAM_TITLE] length])
- [mutableNewInfo setObject:[mutableNewInfo objectForKey:ITUNES_STREAM_TITLE]
- forKey:ITUNES_NAME];
+ if ([mutableNewInfo objectForKey:KEY_ITUNES_STREAM_TITLE] && [(NSString *)[mutableNewInfo objectForKey:KEY_ITUNES_STREAM_TITLE] length])
+ [mutableNewInfo setObject:[mutableNewInfo objectForKey:KEY_ITUNES_STREAM_TITLE]
+ forKey:KEY_ITUNES_NAME];
NSEnumerator *enumerator = [newInfo keyEnumerator];
NSString *key;
@@ -168,8 +175,10 @@
}
iTunesCurrentInfo = mutableNewInfo;
- [self setiTunesIsStopped:[[iTunesCurrentInfo objectForKey:PLAYER_STATE] isEqualToString:KEY_STOPPED]];
- [self setiTunesIsPaused:[[iTunesCurrentInfo objectForKey:PLAYER_STATE] isEqualToString:KEY_PAUSED]];
+ [self setiTunesIsStopped:[[iTunesCurrentInfo objectForKey:KEY_ITUNES_PLAYER_STATE]
+ isEqualToString:KEY_ITUNES_STOPPED]];
+ [self setiTunesIsPaused:[[iTunesCurrentInfo objectForKey:KEY_ITUNES_PLAYER_STATE]
+ isEqualToString:KEY_ITUNES_PAUSED]];
//Cancel any requests we had to fire updates.
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(fireUpdateiTunesInfo) object:nil];
@@ -200,13 +209,11 @@
iTunesCurrentInfo = nil;
//Only install our items if a copy of iTunes which meets the minimum requirements is found
- if ([[[NSBundle bundleWithPath:itunesPath] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] doubleValue] > ITUNES_MINIMUM_VERSION) {
-
+ if ([[[NSBundle bundleWithPath:itunesPath] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] doubleValue] > ITUNES_MINIMUM_VERSION) {
//Perform substitutions on outgoing content
- [adium.contentController registerContentFilter:self
- ofType:AIFilterContent
- direction:AIFilterOutgoing];
-
+ [adium.contentController registerContentFilter:self
+ ofType:AIFilterContent
+ direction:AIFilterOutgoing];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(iTunesUpdate:)
name:@"com.apple.iTunes.playerInfo"
@@ -217,14 +224,14 @@
object:nil];
substitutionDict = [[NSDictionary alloc] initWithObjectsAndKeys:
- ITUNES_ALBUM, ALBUM_TRIGGER,
- ITUNES_ARTIST, ARTIST_TRIGGER,
- ITUNES_COMPOSER, COMPOSER_TRIGGER,
- ITUNES_GENRE, GENRE_TRIGGER,
- ITUNES_PLAYER_STATE, STATUS_TRIGGER,
- ITUNES_NAME, TRACK_TRIGGER,
- ITUNES_YEAR, YEAR_TRIGGER,
- ITUNES_STORE_URL, STORE_URL_TRIGGER,
+ KEY_ITUNES_ALBUM, TRIGGER_ALBUM,
+ KEY_ITUNES_ARTIST, TRIGGER_ARTIST,
+ KEY_ITUNES_COMPOSER, TRIGGER_COMPOSER,
+ KEY_ITUNES_GENRE, TRIGGER_GENRE,
+ KEY_ITUNES_PLAYER_STATE, TRIGGER_STATUS,
+ KEY_ITUNES_NAME, TRIGGER_TRACK,
+ KEY_ITUNES_YEAR, TRIGGER_YEAR,
+ KEY_ITUNES_STORE_URL, TRIGGER_STORE_URL,
nil];
//Update the format for "Current iTunes Track"
@@ -237,7 +244,7 @@
[self createiTunesToolbarItemWithPath:itunesPath];
//Create the Edit > Insert and contextual menus
- [self createTriggersMenu];
+ [self insertTriggerMenu];
}
}
@@ -290,14 +297,14 @@
//create the dictionary
[self setiTunesCurrentInfo:[NSDictionary dictionaryWithObjects:iTunesValues
forKeys:[NSArray arrayWithObjects:
- ITUNES_ALBUM,
- ITUNES_ARTIST,
- ITUNES_COMPOSER,
- ITUNES_GENRE,
- ITUNES_PLAYER_STATE,
- ITUNES_NAME,
- ITUNES_YEAR,
- ITUNES_STORE_URL,
+ KEY_ITUNES_ALBUM,
+ KEY_ITUNES_ARTIST,
+ KEY_ITUNES_COMPOSER,
+ KEY_ITUNES_GENRE,
+ KEY_ITUNES_PLAYER_STATE,
+ KEY_ITUNES_NAME,
+ KEY_ITUNES_YEAR,
+ KEY_ITUNES_STORE_URL,
nil]]];
} else {
NSLog(@"iTunesValues was %@ (%lu items), but I was expecting %lu. Perhaps CurrentTunes is not updated to match ESiTunesPlugin?",
@@ -306,7 +313,7 @@
} else {
//create a dictionary saying that iTunes is stopped
- [self setiTunesCurrentInfo:[NSDictionary dictionaryWithObjectsAndKeys:KEY_STOPPED, PLAYER_STATE, nil]];
+ [self setiTunesCurrentInfo:[NSDictionary dictionaryWithObjectsAndKeys:KEY_ITUNES_STOPPED, KEY_ITUNES_PLAYER_STATE, nil]];
}
[playingScript release];
@@ -326,9 +333,9 @@
AIStatus *currentiTunesStatusState = [[AIStatus statusOfType:AIAvailableStatusType] retain];
//set status attributes
- NSAttributedString *trackAndArtist = [NSAttributedString stringWithString:CURRENT_TRACK_TRIGGER];
+ NSAttributedString *trackAndArtist = [NSAttributedString stringWithString:TRIGGER_CURRENT_TRACK];
[currentiTunesStatusState setStatusMessage:trackAndArtist];
- [currentiTunesStatusState setTitle:CURRENT_ITUNES_TRACK];
+ [currentiTunesStatusState setTitle:STRING_CURRENT_TRACK];
[currentiTunesStatusState setMutabilityType:AISecondaryLockedStatusState];
[currentiTunesStatusState setUniqueStatusID:[NSNumber numberWithInteger:ITUNES_STATUS_ID]];
[currentiTunesStatusState setSpecialStatusType:AINowPlayingSpecialStatusType];
@@ -345,10 +352,10 @@
NSString *currentITunesTrackFormat = nil;
slashMusicDict = [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSString stringWithFormat:AILocalizedString(@"*is listening to %@ by %@*","Phrase sent in response to %_music. The first %%@ is the track; the second %%@ is the artist."), TRACK_TRIGGER, ARTIST_TRIGGER],
- KEY_PLAYING,
+ [NSString stringWithFormat:AILocalizedString(@"*is listening to %@ by %@*","Phrase sent in response to %_music. The first %%@ is the track; the second %%@ is the artist."), TRIGGER_TRACK, TRIGGER_ARTIST],
+ KEY_ITUNES_PLAYING,
AILocalizedString(@"*is listening to nothing*","Phrase sent in response to %_music when nothing is playing."),
- KEY_STOPPED,
+ KEY_ITUNES_STOPPED,
nil];
/* Provide flexibility with the %_iTunes substitution. By default, just store @"" for this key.
@@ -356,31 +363,31 @@
* doesn't have its format broken if the locale switches...
* since the format specifiers are themselves localized.
*/
- currentITunesTrackFormat = [adium.preferenceController preferenceForKey:KEY_CURRENT_TRACK_FORMAT
+ currentITunesTrackFormat = [adium.preferenceController preferenceForKey:KEY_ITUNES_TRACK_FORMAT
group:PREF_GROUP_STATUS_PREFERENCES];
if (!currentITunesTrackFormat) {
[adium.preferenceController setPreference:@""
- forKey:KEY_CURRENT_TRACK_FORMAT
+ forKey:KEY_ITUNES_TRACK_FORMAT
group:PREF_GROUP_STATUS_PREFERENCES];
currentITunesTrackFormat = @"";
}
if (![currentITunesTrackFormat length]) {
- currentITunesTrackFormat = [NSString stringWithFormat:@"%@ - %@", TRACK_TRIGGER, ARTIST_TRIGGER];
+ currentITunesTrackFormat = [NSString stringWithFormat:@"%@ - %@", TRIGGER_TRACK, TRIGGER_ARTIST];
}
conditionalArtistTrackDict = [[NSDictionary alloc] initWithObjectsAndKeys:
currentITunesTrackFormat,
- KEY_PLAYING,
+ KEY_ITUNES_PLAYING,
@"",
- KEY_STOPPED,
+ KEY_ITUNES_STOPPED,
nil];
phraseSubstitutionDict = [[NSDictionary alloc] initWithObjectsAndKeys:
slashMusicDict,
- MUSIC_TRIGGER,
+ TRIGGER_MUSIC,
conditionalArtistTrackDict,
- CURRENT_TRACK_TRIGGER,
+ TRIGGER_CURRENT_TRACK,
nil];
[self fireUpdateiTunesInfo];
@@ -393,6 +400,18 @@
#pragma mark Filter Protocol methods
/*!
+ * @brief Filter and insert current iTunes song display into message entry
+ *
+ * Toolbar method. Take the trigger and filter it with real values
+ *
+ * @param sender An NSMenuItem whose representedObject is the appropriate trigger to filter
+ */
+- (void)insertFilteredString:(id)sender
+{
+ [self filterAndInsertString:[sender representedObject]];
+}
+
+/*!
* @brief Filter messages for keywords to replace
*
* Replace any iTunes triggers with the appropriate information
@@ -422,20 +441,20 @@
//get the format for the current trigger
replacementDict = [phraseSubstitutionDict objectForKey:trigger];
-
+
//replacement of phrase should reflect iTunes player state
if (![self iTunesIsStopped] && ![self iTunesIsPaused]) {
- replacement = [replacementDict objectForKey:KEY_PLAYING];
-
+ replacement = [replacementDict objectForKey:KEY_ITUNES_PLAYING];
+
/* If the trigger is the trigger used for the Current iTunes Track status, we'll want to add a subtext of the store link
* so account code can send it out later on.
*/
- if ([trigger isEqualToString:CURRENT_TRACK_TRIGGER]) {
+ if ([trigger isEqualToString:TRIGGER_CURRENT_TRACK]) {
addStoreLinkAsSubtext = YES;
}
-
+
} else {
- replacement = [replacementDict objectForKey:KEY_STOPPED];
+ replacement = [replacementDict objectForKey:KEY_ITUNES_STOPPED];
}
//create a attributedstring if it hasn't been created already
@@ -460,19 +479,19 @@
//Find if the current trigger is in the string
if (([stringMessage rangeOfString:trigger options:(NSLiteralSearch | NSCaseInsensitiveSearch)].location != NSNotFound)) {
- NSString *replacement;
-
//Get the info if we don't already have it
if (!iTunesCurrentInfo) [self loadiTunesCurrentInfoViaApplescript];
-
- //Attempt to replace it with its proper value
- if (!(replacement = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:trigger]])) {
+
+ NSString *replacement = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:trigger]];
+ if (replacement == nil) {
//If no replacement is found, replace the trigger with an empty string
replacement = @"";
}
//if a mutable attributed string for the string to be filtered doesn't exist, create it.
- if (!filteredMessage) filteredMessage = [[inAttributedString mutableCopy] autorelease];
+ if (filteredMessage == nil) {
+ filteredMessage = [[inAttributedString mutableCopy] autorelease];
+ }
//Replace the current trigger with the value we found above
[filteredMessage replaceOccurrencesOfString:trigger
@@ -483,7 +502,7 @@
}
if (addStoreLinkAsSubtext && filteredMessage) {
- NSString *storeLinkForSubtext = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:STORE_URL_TRIGGER]];
+ NSString *storeLinkForSubtext = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:TRIGGER_STORE_URL]];
if (storeLinkForSubtext) {
[filteredMessage addAttribute:@"AIMessageSubtext"
value:storeLinkForSubtext
@@ -491,7 +510,7 @@
}
}
}
-
+
//Give back the processed string
return (filteredMessage ? filteredMessage : inAttributedString);
}
@@ -550,9 +569,9 @@
[button setImage:[[NSWorkspace sharedWorkspace] iconForFile:iTunesPath]];
[self createiTunesToolbarItemMenuItems:menu];
- NSToolbarItem * iTunesItem = [AIToolbarUtilities toolbarItemWithIdentifier:ITUNES_TOOLBAR_ITEM
- label:TOOLBAR_LABEL
- paletteLabel:TOOLBAR_LABEL
+ NSToolbarItem * iTunesItem = [AIToolbarUtilities toolbarItemWithIdentifier:KEY_TRIGGERS_TOOLBAR
+ label:STRING_TRIGGERS_TOOLBAR
+ paletteLabel:STRING_TRIGGERS_TOOLBAR
toolTip:AILocalizedString(@"Insert current iTunes track information.","Label for iTunes toolbar menu item.")
target:self
settingSelector:@selector(setView:)
@@ -568,7 +587,7 @@
//Add menu to toolbar item (for text mode)
NSMenuItem *mItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] init] autorelease];
[mItem setSubmenu:menu];
- [mItem setTitle:TOOLBAR_LABEL];
+ [mItem setTitle:STRING_TRIGGERS_TOOLBAR];
[iTunesItem setMenuFormRepresentation:mItem];
//give it to adium to use
@@ -585,57 +604,14 @@
- (void)createiTunesToolbarItemMenuItems:(NSMenu *)iTunesMenu
{
- NSMenu *insertTrackSubmenu = [[NSMenu alloc] init];
-
- [iTunesMenu addItem:[self menuItemWithTitle:CURRENT_ITUNES_TRACK
- action:@selector(insertFilteredString:)
- representedObject:CURRENT_TRACK_TRIGGER
- kind:ENABLED_IF_ITUNES_PLAYING]];
- [iTunesMenu addItem:[self menuItemWithTitle:MUSIC_TRIGGER
- action:@selector(insertFilteredString:)
- representedObject:MUSIC_TRIGGER
- kind:ENABLED_IF_ITUNES_PLAYING]];
- [iTunesMenu addItem:[NSMenuItem separatorItem]];
+
//submenu of actions related to a track
NSMenuItem *submenuRoot = [[NSMenuItem alloc] initWithTitle:AILocalizedString(@"Track Information","Submenu for iTunes toolbar item menu for inserting current track information.")
action:NULL
keyEquivalent:@""];
-
- [insertTrackSubmenu addItem:[self menuItemWithTitle:AILocalizedString(@"Album","Insert Current iTunes track album toolbar menu item.")
- action:@selector(insertFilteredString:)
- representedObject:ALBUM_TRIGGER
- kind:ENABLED_IF_ITUNES_PLAYING]];
- [insertTrackSubmenu addItem:[self menuItemWithTitle:AILocalizedString(@"Artist","Insert Current iTunes track artist toolbar menu item.")
- action:@selector(insertFilteredString:)
- representedObject:ARTIST_TRIGGER
- kind:ENABLED_IF_ITUNES_PLAYING]];
- [insertTrackSubmenu addItem:[self menuItemWithTitle:AILocalizedString(@"Composer","Insert Current iTunes track composer toolbar menu item.")
- action:@selector(insertFilteredString:)
- representedObject:COMPOSER_TRIGGER
- kind:ENABLED_IF_ITUNES_PLAYING]];
- [insertTrackSubmenu addItem:[self menuItemWithTitle:AILocalizedString(@"Genre","Insert Current iTunes track genre toolbar menu item.")
- action:@selector(insertFilteredString:)
- representedObject:GENRE_TRIGGER
- kind:ENABLED_IF_ITUNES_PLAYING]];
- [insertTrackSubmenu addItem:[self menuItemWithTitle:AILocalizedString(@"Name","Insert Current iTunes track name toolbar menu item.")
- action:@selector(insertFilteredString:)
- representedObject:TRACK_TRIGGER
- kind:ENABLED_IF_ITUNES_PLAYING]];
- [insertTrackSubmenu addItem:[self menuItemWithTitle:AILocalizedString(@"Year","Insert Current iTunes track year toolbar menu item.")
- action:@selector(insertFilteredString:)
- representedObject:YEAR_TRIGGER
- kind:ENABLED_IF_ITUNES_PLAYING]];
-
- [insertTrackSubmenu addItem:[self menuItemWithTitle:AILocalizedString(@"iTunes Music Store Link","Insert Current iTunes track store link toolbar menu item.")
- action:@selector(insertiTMSLink)
- representedObject:nil
- kind:ENABLED_IF_ITUNES_PLAYING]];
-
[iTunesMenu addItem:submenuRoot];
- [iTunesMenu setSubmenu:insertTrackSubmenu forItem:submenuRoot];
- [submenuRoot release];
- [insertTrackSubmenu release];
+ [iTunesMenu setSubmenu:[self createTriggerMenu] forItem:submenuRoot];
[iTunesMenu addItem:[NSMenuItem separatorItem]];
//this isn't implemented yet, need some advice on this one
@@ -649,6 +625,8 @@
action:@selector(bringiTunesToFront)
representedObject:nil
kind:ALWAYS_ENABLED]];
+
+ [submenuRoot release];
}
/*!
@@ -681,11 +659,11 @@
NSString *urlLabel = nil;
//get current information
- NSString *artist = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:ARTIST_TRIGGER]];
- NSString *trackName = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:TRACK_TRIGGER]];
+ NSString *artist = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:TRIGGER_ARTIST]];
+ NSString *trackName = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:TRIGGER_TRACK]];
//see if we have a URL for us
- NSString *storeURL = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:STORE_URL_TRIGGER]];
+ NSString *storeURL = [iTunesCurrentInfo objectForKey:[substitutionDict objectForKey:TRIGGER_STORE_URL]];
if ([storeURL length]) {
[url appendString:storeURL];
}
@@ -695,7 +673,7 @@
//if iTunes is playing or paused something
if (![self iTunesIsStopped] || ![self iTunesIsPaused]) {
- [url appendString:ITMS_SEARCH_URL];
+ [url appendString:ITUNES_ITMS_SEARCH_URL];
//if there is a name given to this song put it in the url
if ([trackName length]) {
@@ -720,7 +698,7 @@
}
//if something has been added to our search request, create a lovely label for it
- if (![url isEqualToString:ITMS_SEARCH_URL] && [url length]) {
+ if (![url isEqualToString:ITUNES_ITMS_SEARCH_URL] && [url length]) {
urlLabel = [[NSString alloc] initWithFormat:@"%@ - %@", trackName, artist];
} else {
[url release]; url = nil;
@@ -740,18 +718,6 @@
}
/*!
- * @brief Filter and insert current iTunes song display into message entry
- *
- * Toolbar method. Take the trigger and filter it with real values
- *
- * @param sender An NSMenuItem whose representedObject is the appropriate trigger to filter
- */
-- (void)insertFilteredString:(id)sender
-{
- [self filterAndInsertString:[sender representedObject]];
-}
-
-/*!
* @brief Search iTMS for inputtted data
*
* Build the necessary url and execute it
@@ -806,14 +772,18 @@
* Converts the string to an attributed string and filters it, then inserting it into the message entry view
* Used by all the toolbar item actions.
*/
-
- (void)filterAndInsertString:(NSString *)inString
{
id responder = [[[NSApplication sharedApplication] keyWindow] firstResponder];
if (responder && [responder isKindOfClass:[NSTextView class]]) {
NSAttributedString *attributedResult = [[NSAttributedString alloc] initWithString:inString
attributes:[(NSTextView *)responder typingAttributes]];
- [self insertAttributedStringIntoMessageEntryView:[self filterAttributedString:attributedResult context:nil]];
+ NSAttributedString *filteredString = [self filterAttributedString:attributedResult context:nil];
+
+ if (filteredString && [filteredString length] > 0) {
+ [self insertAttributedStringIntoMessageEntryView:filteredString];
+ }
+
[attributedResult release];
}
}
@@ -824,7 +794,6 @@
* Converts the string to an attributed string and inserts it into the message entry view.
* Used with the insertUnfiltered... methods which are used by edit and contextual menus.
*/
-
- (void)insertStringIntoMessageEntryView:(NSString *)inString
{
id responder = [[[NSApplication sharedApplication] keyWindow] firstResponder];
@@ -862,32 +831,53 @@
* Build the menus for the iTunes triggers that autodisables when a first responder isn't a textView
*/
-- (NSMenu *)menuOfTriggers
+- (NSMenu *)createTriggerMenu
{
- NSMenu *triggersMenu = [[NSMenu alloc] init];
- NSEnumerator *enumerator;
- NSString *trigger;
+ NSMenu *triggersMenu = [[NSMenu alloc] init];
- [triggersMenu addItem:[self menuItemWithTitle:CURRENT_TRACK_TRIGGER
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_CURRENT_TRACK
action:@selector(insertUnfilteredString:)
- representedObject:CURRENT_TRACK_TRIGGER
+ representedObject:TRIGGER_CURRENT_TRACK
kind:AUTODISABLES]];
- [triggersMenu addItem:[self menuItemWithTitle:MUSIC_TRIGGER
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_MUSIC
action:@selector(insertUnfilteredString:)
- representedObject:MUSIC_TRIGGER
+ representedObject:TRIGGER_MUSIC
kind:AUTODISABLES]];
-
[triggersMenu addItem:[NSMenuItem separatorItem]];
- //Simple triggers
- enumerator = [substitutionDict keyEnumerator];
- while ((trigger = [enumerator nextObject])) {
- [triggersMenu addItem:[self menuItemWithTitle:trigger
- action:@selector(insertUnfilteredString:)
- representedObject:trigger
- kind:AUTODISABLES]];
- }
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_TRACK
+ action:@selector(insertUnfilteredString:)
+ representedObject:TRIGGER_TRACK
+ kind:AUTODISABLES]];
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_ARTIST
+ action:@selector(insertUnfilteredString:)
+ representedObject:TRIGGER_ARTIST
+ kind:AUTODISABLES]];
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_COMPOSER
+ action:@selector(insertUnfilteredString:)
+ representedObject:TRIGGER_COMPOSER
+ kind:AUTODISABLES]];
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_ALBUM
+ action:@selector(insertUnfilteredString:)
+ representedObject:TRIGGER_ALBUM
+ kind:AUTODISABLES]];
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_GENRE
+ action:@selector(insertUnfilteredString:)
+ representedObject:TRIGGER_GENRE
+ kind:AUTODISABLES]];
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_YEAR
+ action:@selector(insertUnfilteredString:)
+ representedObject:TRIGGER_YEAR
+ kind:AUTODISABLES]];
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_STATUS
+ action:@selector(insertUnfilteredString:)
+ representedObject:TRIGGER_STATUS
+ kind:AUTODISABLES]];
+ [triggersMenu addItem:[self menuItemWithTitle:STRING_STORE_URL
+ action:@selector(insertiTMSLink)
+ representedObject:TRIGGER_STORE_URL
+ kind:AUTODISABLES]];
return [triggersMenu autorelease];
}
@@ -897,16 +887,16 @@
*
* Users can then insert %_<token name> into any text view
*/
-- (void)createTriggersMenu
+- (void)insertTriggerMenu
{
- NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:INSERT_TRIGGERS_MENU target:self action:NULL keyEquivalent:@""];
- NSMenu *menuOfTriggers = [self menuOfTriggers];
+ NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:STRING_TRIGGERS_MENU target:self action:NULL keyEquivalent:@""];
+ NSMenu *menuOfTriggers = [self createTriggerMenu];
[menuItem setSubmenu:menuOfTriggers];
[adium.menuController addMenuItem:menuItem toLocation:LOC_Edit_Additions];
[menuItem release];
- menuItem = [[NSMenuItem alloc] initWithTitle:INSERT_TRIGGERS_MENU target:self action:NULL keyEquivalent:@""];
+ menuItem = [[NSMenuItem alloc] initWithTitle:STRING_TRIGGERS_MENU target:self action:NULL keyEquivalent:@""];
[menuItem setSubmenu:[[menuOfTriggers copy] autorelease]];
[adium.menuController addContextualMenuItem:menuItem toLocation:Context_TextView_Edit];
[menuItem release];
More information about the commits
mailing list