Skip to content

Commit

Permalink
Groundwork for iCloud syncing support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Morris committed Oct 28, 2013
1 parent 09b1e4c commit f98e4a8
Show file tree
Hide file tree
Showing 23 changed files with 850 additions and 341 deletions.
3 changes: 3 additions & 0 deletions Classes/Controllers/TXMasterController.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ - (void)awakeFromNib
#endif

[TPCPreferences initPreferences];
[TPCPreferencesCloudSync initializeCloudSyncSession];

[self.mainWindow setMinSize:TPCPreferences.minimumWindowSize];

Expand Down Expand Up @@ -393,6 +394,8 @@ - (void)applicationWillTerminate:(NSNotification *)note
}

[TPCPreferences saveTimeIntervalSinceApplicationInstall];

[TPCPreferencesCloudSync closeCloudSyncSession];
}

- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag
Expand Down
17 changes: 1 addition & 16 deletions Classes/Controllers/TXMenuController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1166,14 +1166,12 @@ - (void)serverSheetOnOK:(TDCServerSheet *)sender
}

BOOL samencoding = (sender.config.primaryEncoding == u.config.primaryEncoding);

[u updateConfig:sender.config];

if (samencoding == NO) {
[self.worldController reloadTheme];
}

[u populateISONTrackedUsersList:sender.config.ignoreList];
}

[self.worldController save];
Expand Down Expand Up @@ -1435,19 +1433,6 @@ - (void)channelSheetOnOK:(TDChannelSheet *)sender
if (_noChannel) {
return;
}

BOOL oldKeyEmpty = NSObjectIsEmpty(c.config.encryptionKey);
BOOL newKeyEmpty = NSObjectIsEmpty(sender.config.encryptionKey);

if (oldKeyEmpty && newKeyEmpty == NO) {
[c.client printDebugInformation:TXTLS(@"BlowfishEncryptionStarted") channel:c];
} else if (oldKeyEmpty == NO && newKeyEmpty) {
[c.client printDebugInformation:TXTLS(@"BlowfishEncryptionStopped") channel:c];
} else if (oldKeyEmpty == NO && newKeyEmpty == NO) {
if ([c.config.encryptionKey isEqualToString:sender.config.encryptionKey] == NO) {
[c.client printDebugInformation:TXTLS(@"BlowfishEncryptionKeyChanged") channel:c];
}
}

[c updateConfig:sender.config];
}
Expand Down
147 changes: 53 additions & 94 deletions Classes/Dialogs/Preferences/TDCPreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ - (void)onChangedAlertDisableWhileAway:(id)sender
[alert setDisabledWhileAway:self.alertDisableWhileAwayButton.state];
}

- (void)onChangedAlertBounceDockIcon:(id)sender {
- (void)onChangedAlertBounceDockIcon:(id)sender
{
TXNotificationType alertType = (TXNotificationType)self.alertTypeChoiceButton.selectedItem.tag;

TDCPreferencesSoundWrapper *alert = [TDCPreferencesSoundWrapper soundWrapperWithEventType:alertType];
Expand Down Expand Up @@ -662,6 +663,9 @@ - (void)onChangedTheme:(id)sender

[self onChangedStyle:nil];

[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadServerListAction];
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadMemberListAction];

// ---- //

NSMutableString *sf = [NSMutableString string];
Expand Down Expand Up @@ -772,63 +776,6 @@ - (void)onAddExcludeKeyword:(id)sender
[self performSelector:@selector(editTable:) withObject:self.excludeKeywordsTable afterDelay:0.3];
}

- (void)onChangedInputHistoryScheme:(id)sender
{
TXMasterController *master = self.masterController;

if (master.inputHistory) {
master.inputHistory = nil;
}

for (IRCClient *c in self.worldController.clients) {
if (c.inputHistory) {
c.inputHistory = nil;
}

if ([TPCPreferences inputHistoryIsChannelSpecific]) {
c.inputHistory = [TLOInputHistory new];
}

for (IRCChannel *u in c.channels) {
if (u.inputHistory) {
u.inputHistory = nil;
}

if ([TPCPreferences inputHistoryIsChannelSpecific]) {
u.inputHistory = [TLOInputHistory new];
}
}
}

if ([TPCPreferences inputHistoryIsChannelSpecific] == NO) {
master.inputHistory = [TLOInputHistory new];
}
}

- (void)onChangedStyle:(id)sender
{
[self.worldController reloadTheme];

[self.masterController.inputTextField updateTextDirection];
}

- (void)onChangedMainWindowSegmentedController:(id)sender
{
[self.masterController reloadSegmentedControllerOrigin];
}

- (void)onChangedUserListModeColor:(id)sender
{
[self.masterController.memberList.badgeRenderer invalidateBadgeImageCacheAndRebuild];

[self.masterController.memberList reloadAllDrawings];
}

- (void)onChangedMainInputTextFieldFontSize:(id)sender
{
[self.masterController.inputTextField updateTextBoxBasedOnPreferredFontSize];
}

- (void)onResetUserListModeColorsToDefaults:(id)sender
{
TVCMemberList *memberList = self.masterController.memberList;
Expand Down Expand Up @@ -857,17 +804,59 @@ - (void)onResetUserListModeColorsToDefaults:(id)sender
[self onChangedUserListModeColor:sender];
}

- (void)onChangedInputHistoryScheme:(id)sender
{
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadInputHistoryScopeAction];
}

- (void)onChangedSidebarColorInversion:(id)sender
{
[self.masterController.serverList updateBackgroundColor];
[self.masterController.serverList reloadAllDrawingsIgnoringOtherReloads];
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadServerListAction];
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadMemberListAction];

[self.masterController.memberList reloadAllUserInterfaceElements];
[self.worldController executeScriptCommandOnAllViews:@"sidebarInversionPreferenceChanged" arguments:@[] onQueue:NO];
}

[self.masterController.serverSplitView setNeedsDisplay:YES];
[self.masterController.memberSplitView setNeedsDisplay:YES];
- (void)onChangedStyle:(id)sender
{
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadStyleAction];
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadTextDirectionAction];
}

[self.worldController executeScriptCommandOnAllViews:@"sidebarInversionPreferenceChanged" arguments:@[] onQueue:NO];
- (void)onChangedMainWindowSegmentedController:(id)sender
{
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadTextFieldSegmentedControllerOriginAction];
}

- (void)onChangedUserListModeColor:(id)sender
{
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadMemberListUserBadgesAction];
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadMemberListAction];
}

- (void)onChangedMainInputTextFieldFontSize:(id)sender
{
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadTextFieldFontSizeAction];
}

- (void)onChangedHighlightLogging:(id)sender
{
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadHighlightLoggingAction];
}

- (void)onChangedUserListModeSortOrder:(id)sender
{
[TPCPreferences performReloadActionForActionType:TPCPreferencesKeyReloadMemberListSortOrderAction];
}

- (void)onOpenPathToScripts:(id)sender
{
[RZWorkspace() openFile:[TPCPreferences applicationSupportFolderPath]];
}

- (void)setTextualAsDefaultIRCClient:(id)sender
{
[TPCPreferences defaultIRCClientPrompt:YES];
}

- (void)openPathToThemesCallback:(TLOPopupPromptReturnType)returnCode
Expand Down Expand Up @@ -929,36 +918,6 @@ - (void)onOpenPathToThemes:(id)sender
}
}

- (void)onOpenPathToScripts:(id)sender
{
[RZWorkspace() openFile:[TPCPreferences applicationSupportFolderPath]];
}

- (void)onChangedHighlightLogging:(id)sender
{
IRCWorld *world = TPCPreferences.masterController.world;

if ([TPCPreferences logHighlights] == NO) {
for (IRCClient *u in world.clients) {
[u.highlights removeAllObjects];
}
}
}

- (void)setTextualAsDefaultIRCClient:(id)sender
{
[TPCPreferences defaultIRCClientPrompt:YES];
}

- (void)onChangedUserListModeSortOrder:(id)sender
{
IRCChannel *channel = self.worldController.selectedChannel;

if (channel) {
[channel reloadDataForTableViewBySortingMembers];
}
}

#pragma mark -
#pragma mark NSWindow Delegate

Expand Down
2 changes: 2 additions & 0 deletions Classes/Headers/IRCWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
- (void)addHighlightInChannel:(IRCChannel *)channel withLogLine:(TVCLogLine *)logLine;

- (void)reloadTheme;
- (void)reloadTheme:(BOOL)reloadUserInterface;

- (void)preferencesChanged;

- (void)changeTextSize:(BOOL)bigger;
Expand Down
1 change: 1 addition & 0 deletions Classes/Headers/StaticDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
#define RZUserNotificationCenter() [NSUserNotificationCenter defaultUserNotificationCenter]
#define RZWorkspace() [NSWorkspace sharedWorkspace]
#define RZWorkspaceNotificationCenter() [RZWorkspace() notificationCenter]
#define RZUbiquitousKeyValueStore() [NSUbiquitousKeyValueStore defaultStore]

/* Lazy-man defines. */
#define PointerIsEmpty(s) ((s) == NULL || (s) == nil)
Expand Down
23 changes: 23 additions & 0 deletions Classes/Headers/TPCPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ typedef enum TXMainTextBoxFontSize : NSInteger {
TXMainTextBoxFontExtraLargeSize = 3,
} TXMainTextBoxFontSize;

/* These actions are used for import purposes. */
typedef enum TPCPreferencesKeyReloadAction : NSInteger {
TPCPreferencesKeyReloadDockIconBadgesAction,
TPCPreferencesKeyReloadHighlightKeywordsAction,
TPCPreferencesKeyReloadHighlightLoggingAction,
TPCPreferencesKeyReloadInputHistoryScopeAction,
TPCPreferencesKeyReloadMainWindowTransparencyLevelAction,
TPCPreferencesKeyReloadMemberListAction,
TPCPreferencesKeyReloadMemberListSortOrderAction,
TPCPreferencesKeyReloadMemberListUserBadgesAction,
TPCPreferencesKeyReloadPreferencesChangedAction,
TPCPreferencesKeyReloadServerListAction,
TPCPreferencesKeyReloadStyleAction,
TPCPreferencesKeyReloadTextDirectionAction,
TPCPreferencesKeyReloadTextFieldFontSizeAction,
TPCPreferencesKeyReloadTextFieldSegmentedControllerOriginAction
} TPCPreferencesKeyReloadAction;

@interface TPCPreferences : NSObject
+ (BOOL)isDefaultIRCClient;

Expand Down Expand Up @@ -164,6 +182,8 @@ typedef enum TXMainTextBoxFontSize : NSInteger {

+ (BOOL)giveFocusOnMessageCommand;

+ (BOOL)syncPreferencesToTheCloud; /* ZE CLOUD! */

+ (BOOL)amsgAllConnections;
+ (BOOL)awayAllConnections;
+ (BOOL)nickAllConnections;
Expand Down Expand Up @@ -318,4 +338,7 @@ typedef enum TXMainTextBoxFontSize : NSInteger {
+ (BOOL)textFieldTextReplacement;
+ (void)setTextFieldTextReplacement:(BOOL)value;

/* The following should only be called by TPCPreferencesImportExport */
+ (void)performReloadActionForKeyValues:(NSArray *)prefKeys;
+ (void)performReloadActionForActionType:(TPCPreferencesKeyReloadAction)reloadAction;
@end
44 changes: 44 additions & 0 deletions Classes/Headers/TPCPreferencesCloudSync.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* *********************************************************************
_____ _ _ ___ ____ ____
|_ _|___ _| |_ _ _ __ _| | |_ _| _ \ / ___|
| |/ _ \ \/ / __| | | |/ _` | | | || |_) | |
| | __/> <| |_| |_| | (_| | | | || _ <| |___
|_|\___/_/\_\\__|\__,_|\__,_|_| |___|_| \_\\____|

Copyright (c) 2010 — 2013 Codeux Software & respective contributors.
Contributors.rtfd and Acknowledgements.rtfd

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Textual IRC Client & Codeux Software nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

*********************************************************************** */

#import "TextualApplication.h"

@interface TPCPreferencesCloudSync : NSObject
+ (void)initializeCloudSyncSession;
+ (void)refreshCloudSyncSession:(BOOL)destroyExistingRemoteKeys;
+ (void)closeCloudSyncSession;
@end
7 changes: 7 additions & 0 deletions Classes/Headers/TPCPreferencesImportExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@

#import "TextualApplication.h"

#define TPCPreferencesImportExportVersionKeyName @"Dictionary Version"
#define TPCPreferencesImportExportVersionKeyValue @"2.0"

/* Absolutely no plugin should call this class. */
@interface TPCPreferencesImportExport : NSObject
+ (void)import;
+ (void)export;

/* For iCloud purposes. */
+ (void)importContentsOfDictionary:(NSDictionary *)aDict;
+ (NSDictionary *)exportedPreferencesDictionaryRepresentation;
@end
2 changes: 2 additions & 0 deletions Classes/Headers/TextualApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
@class TLOTimerCommand;
@class TLOpenLink;
@class TPCPreferences;
@class TPCPreferencesCloudSync;
@class TPCPreferencesImportExport;
@class TPCResourceManager;
@class TPCThemeController;
Expand Down Expand Up @@ -267,6 +268,7 @@
/* Preferences. */

#import "TPCPreferences.h"
#import "TPCPreferencesCloudSync.h"
#import "TPCPreferencesImportExport.h"
#import "TPCResourceManager.h"
#import "TPCThemeController.h"
Expand Down
15 changes: 14 additions & 1 deletion Classes/IRC/IRCChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,20 @@ - (void)setup:(IRCChannelConfig *)seed
- (void)updateConfig:(IRCChannelConfig *)seed
{
PointerIsEmptyAssert(seed);


BOOL oldKeyEmpty = NSObjectIsEmpty(self.config.encryptionKey);
BOOL newKeyEmpty = NSObjectIsEmpty(seed.encryptionKey);

if (oldKeyEmpty && newKeyEmpty == NO) {
[self.client printDebugInformation:TXTLS(@"BlowfishEncryptionStarted") channel:self];
} else if (oldKeyEmpty == NO && newKeyEmpty) {
[self.client printDebugInformation:TXTLS(@"BlowfishEncryptionStopped") channel:self];
} else if (oldKeyEmpty == NO && newKeyEmpty == NO) {
if ([self.config.encryptionKey isEqualToString:seed.encryptionKey] == NO) {
[self.client printDebugInformation:TXTLS(@"BlowfishEncryptionKeyChanged") channel:self];
}
}

self.config = [seed mutableCopy];
}

Expand Down
Loading

0 comments on commit f98e4a8

Please sign in to comment.