aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/ConnectionView.xib113
-rw-r--r--Source/SPConnectionController.h4
-rw-r--r--Source/SPConnectionController.m17
-rw-r--r--Source/SPConnectionControllerDelegate.h2
-rw-r--r--Source/SPConnectionControllerDelegate.m16
-rw-r--r--Source/SPConstants.h3
-rw-r--r--Source/SPConstants.m3
-rw-r--r--Source/SPFavoritesController.m4
-rw-r--r--Source/SPFavoritesExportProtocol.h42
-rw-r--r--Source/SPFavoritesExporter.h52
-rw-r--r--Source/SPFavoritesExporter.m107
-rw-r--r--Source/SPFavoritesImporter.h31
-rw-r--r--Source/SPFavoritesImporter.m30
-rw-r--r--sequel-pro.xcodeproj/project.pbxproj32
14 files changed, 433 insertions, 23 deletions
diff --git a/Interfaces/English.lproj/ConnectionView.xib b/Interfaces/English.lproj/ConnectionView.xib
index 7a3664ef..3f8c1525 100644
--- a/Interfaces/English.lproj/ConnectionView.xib
+++ b/Interfaces/English.lproj/ConnectionView.xib
@@ -2,10 +2,10 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1050</int>
- <string key="IBDocument.SystemVersion">10J567</string>
- <string key="IBDocument.InterfaceBuilderVersion">823</string>
+ <string key="IBDocument.SystemVersion">10J869</string>
+ <string key="IBDocument.InterfaceBuilderVersion">851</string>
<string key="IBDocument.AppKitVersion">1038.35</string>
- <string key="IBDocument.HIToolboxVersion">462.00</string>
+ <string key="IBDocument.HIToolboxVersion">461.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
@@ -15,12 +15,14 @@
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
- <string>823</string>
+ <string>851</string>
<string>1.2.5</string>
</object>
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="5812"/>
+ <integer value="5468"/>
<integer value="4910"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
@@ -155,7 +157,7 @@
</object>
</object>
<double key="NSRowHeight">17</double>
- <int key="NSTvFlags">390070272</int>
+ <int key="NSTvFlags">524288000</int>
<reference key="NSDelegate"/>
<reference key="NSDataSource"/>
<string key="NSAutosaveName">ConnectionView</string>
@@ -317,7 +319,6 @@
<reference key="NSMenu" ref="949612237"/>
<bool key="NSIsDisabled">YES</bool>
<bool key="NSIsSeparator">YES</bool>
- <bool key="NSIsHidden">YES</bool>
<string key="NSTitle"/>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
@@ -328,8 +329,6 @@
</object>
<object class="NSMenuItem" id="885080859">
<reference key="NSMenu" ref="949612237"/>
- <bool key="NSIsDisabled">YES</bool>
- <bool key="NSIsHidden">YES</bool>
<string key="NSTitle">Import...</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
@@ -340,8 +339,6 @@
</object>
<object class="NSMenuItem" id="509439698">
<reference key="NSMenu" ref="949612237"/>
- <bool key="NSIsDisabled">YES</bool>
- <bool key="NSIsHidden">YES</bool>
<string key="NSTitle">Export...</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
@@ -464,7 +461,6 @@
<string key="NSKeyEquiv"/>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
- <int key="NSState">1</int>
<reference key="NSImage" ref="1057150516"/>
<reference key="NSOnImage" ref="1022504326"/>
<reference key="NSMixedImage" ref="329345764"/>
@@ -2455,7 +2451,6 @@
<reference key="NSMenu" ref="9858888"/>
<bool key="NSIsDisabled">YES</bool>
<bool key="NSIsSeparator">YES</bool>
- <bool key="NSIsHidden">YES</bool>
<string key="NSTitle"/>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
@@ -2464,8 +2459,6 @@
</object>
<object class="NSMenuItem" id="1069447512">
<reference key="NSMenu" ref="9858888"/>
- <bool key="NSIsDisabled">YES</bool>
- <bool key="NSIsHidden">YES</bool>
<string key="NSTitle">Export...</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
@@ -2574,6 +2567,32 @@
<string key="NSFrameSize">{579, 51}</string>
<string key="NSClassName">NSView</string>
</object>
+ <object class="NSCustomView" id="927914916">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">268</int>
+ <object class="NSMutableArray" key="NSSubviews">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSTextField" id="102429131">
+ <reference key="NSNextResponder" ref="927914916"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{-3, 12}, {371, 34}}</string>
+ <reference key="NSSuperview" ref="927914916"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="557766306">
+ <int key="NSCellFlags">67239424</int>
+ <int key="NSCellFlags2">138412032</int>
+ <string key="NSContents">Note that for security reasons, your connection favorite passwords are not included in the export.</string>
+ <reference key="NSSupport" ref="807120225"/>
+ <reference key="NSControlView" ref="102429131"/>
+ <reference key="NSBackgroundColor" ref="644242225"/>
+ <reference key="NSTextColor" ref="434026568"/>
+ </object>
+ </object>
+ </object>
+ <string key="NSFrameSize">{365, 52}</string>
+ <reference key="NSSuperview"/>
+ <string key="NSClassName">NSView</string>
+ </object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
@@ -4691,6 +4710,14 @@
</object>
<int key="connectionID">5811</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">exportPanelAccessoryView</string>
+ <reference key="source" ref="545410097"/>
+ <reference key="destination" ref="927914916"/>
+ </object>
+ <int key="connectionID">5815</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -6389,6 +6416,30 @@
<reference key="object" ref="773701029"/>
<reference key="parent" ref="192444974"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">5812</int>
+ <reference key="object" ref="927914916"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="102429131"/>
+ </object>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">AccessoryView</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">5813</int>
+ <reference key="object" ref="102429131"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="557766306"/>
+ </object>
+ <reference key="parent" ref="927914916"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">5814</int>
+ <reference key="object" ref="557766306"/>
+ <reference key="parent" ref="102429131"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -6675,6 +6726,11 @@
<string>5790.IBPluginDependency</string>
<string>5791.IBPluginDependency</string>
<string>5793.IBPluginDependency</string>
+ <string>5812.IBEditorWindowLastContentRect</string>
+ <string>5812.IBPluginDependency</string>
+ <string>5813.IBPluginDependency</string>
+ <string>5813.IBViewBoundsToFrameTransform</string>
+ <string>5814.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -7007,7 +7063,7 @@
<string>com.brandonwalkin.BWToolkit</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{725, 739}, {142, 123}}</string>
+ <string>{{461, 362}, {142, 123}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.brandonwalkin.BWToolkit</string>
@@ -7015,7 +7071,7 @@
<bytes key="NSTransformStruct">P4AAAL+AAAC/gAAAwagAAA</bytes>
</object>
<string>com.brandonwalkin.BWToolkit</string>
- <string>{{129, -14}, {131, 169}}</string>
+ <string>{{0, -14}, {131, 169}}</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.brandonwalkin.BWToolkit</string>
@@ -7171,11 +7227,18 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.brandonwalkin.BWToolkit</string>
- <string>{{160, 101}, {128, 54}}</string>
+ <string>{{31, 101}, {128, 54}}</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.brandonwalkin.BWToolkit</string>
+ <string>{{140, 543}, {365, 52}}</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <object class="NSAffineTransform">
+ <bytes key="NSTransformStruct">P4AAAL+AAADAQAAAwmgAAA</bytes>
+ </object>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -7194,7 +7257,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">5811</int>
+ <int key="maxID">5815</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -7244,6 +7307,13 @@
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">Frameworks/PSMTabBar/PSMTabBarController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier" id="968459546">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">Source/SPConnectionController.h</string>
@@ -7608,6 +7678,7 @@
<string>delegate</string>
<string>errorDetailText</string>
<string>errorDetailWindow</string>
+ <string>exportPanelAccessoryView</string>
<string>favoritesOutlineView</string>
<string>favoritesSortByMenuItem</string>
<string>helpButton</string>
@@ -7655,6 +7726,7 @@
<string>id</string>
<string>NSTextView</string>
<string>NSWindow</string>
+ <string>NSView</string>
<string>SPFavoritesOutlineView</string>
<string>NSMenuItem</string>
<string>NSButton</string>
@@ -7705,6 +7777,7 @@
<string>delegate</string>
<string>errorDetailText</string>
<string>errorDetailWindow</string>
+ <string>exportPanelAccessoryView</string>
<string>favoritesOutlineView</string>
<string>favoritesSortByMenuItem</string>
<string>helpButton</string>
@@ -7786,6 +7859,10 @@
<string key="candidateClassName">NSWindow</string>
</object>
<object class="IBToOneOutletInfo">
+ <string key="name">exportPanelAccessoryView</string>
+ <string key="candidateClassName">NSView</string>
+ </object>
+ <object class="IBToOneOutletInfo">
<string key="name">favoritesOutlineView</string>
<string key="candidateClassName">SPFavoritesOutlineView</string>
</object>
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h
index a1a99526..83c38172 100644
--- a/Source/SPConnectionController.h
+++ b/Source/SPConnectionController.h
@@ -24,6 +24,7 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <MCPKit/MCPKit.h>
+#import "SPFavoritesExportProtocol.h"
#import "SPConnectionControllerDelegateProtocol.h"
#ifndef SP_REFACTOR /* headers */
@@ -51,7 +52,7 @@
#endif
-@interface SPConnectionController : NSObject
+@interface SPConnectionController : NSObject
{
id <SPConnectionControllerDelegateProtocol, NSObject> delegate;
@@ -160,6 +161,7 @@
IBOutlet NSProgressIndicator *progressIndicator;
IBOutlet NSTextField *progressIndicatorText;
IBOutlet NSMenuItem *favoritesSortByMenuItem;
+ IBOutlet NSView *exportPanelAccessoryView;
BOOL isEditing;
BOOL reverseFavoritesSort;
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 0f12303f..6ed6e392 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -38,6 +38,8 @@
#import "SPGeneralPreferencePane.h"
#import "SPDatabaseViewController.h"
#import "SPTreeNode.h"
+#import "SPFavoritesExporter.h"
+#import "SPFavoritesImporter.h"
// Constants
static NSString *SPRemoveNode = @"RemoveNode";
@@ -989,6 +991,8 @@ static NSComparisonResult compareFavoritesUsingKey(id favorite1, id favorite2, v
{
NSSavePanel *savePanel = [NSSavePanel savePanel];
+ [savePanel setAccessoryView:exportPanelAccessoryView];
+
[savePanel beginSheetForDirectory:nil
file:SPExportFavoritesFilename
modalForWindow:[dbDocument parentWindow]
@@ -1131,9 +1135,20 @@ static NSComparisonResult compareFavoritesUsingKey(id favorite1, id favorite2, v
/**
* Called when the user dismisses either the import of export favorites panels.
*/
-- (void)importExportFavoritesSheetDidEnd:(NSOpenPanel *)openPanel returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
+- (void)importExportFavoritesSheetDidEnd:(NSOpenPanel *)panel returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
{
+ NSError *error = nil;
+ if (contextInfo == SPExportFavorites) {
+ SPFavoritesExporter *exporter = [[[SPFavoritesExporter alloc] init] autorelease];
+
+ [exporter setDelegate:self];
+
+ [exporter writeFavorites:[self selectedFavoriteNodes] toFile:[panel filename] error:&error];
+ }
+ else if (contextInfo == SPImportFavorites) {
+ //SPFavoritesImporter *importer = [[SPFavoritesImporter alloc] init];
+ }
}
/**
diff --git a/Source/SPConnectionControllerDelegate.h b/Source/SPConnectionControllerDelegate.h
index 4936ee19..25d0a02d 100644
--- a/Source/SPConnectionControllerDelegate.h
+++ b/Source/SPConnectionControllerDelegate.h
@@ -32,6 +32,6 @@
*
* Connection controller delegate category.
*/
-@interface SPConnectionController (SPConnectionControllerDelegate)
+@interface SPConnectionController (SPConnectionControllerDelegate) <SPFavoritesExportProtocol>
@end
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m
index b86e716f..03dbd930 100644
--- a/Source/SPConnectionControllerDelegate.m
+++ b/Source/SPConnectionControllerDelegate.m
@@ -492,4 +492,20 @@ static NSString *SPDatabaseImage = @"database-small";
return YES;
}
+#pragma mark -
+#pragma mark Favorites import/export delegate methods
+
+/**
+ * Called by the favorites exporter when the export completes.
+ */
+- (void)favoritesExportCompletedWithError:(NSError *)error
+{
+ if (error) {
+ [[NSAlert alertWithError:error] beginSheetModalForWindow:[dbDocument parentWindow]
+ modalDelegate:self
+ didEndSelector:NULL
+ contextInfo:NULL];
+ }
+}
+
@end
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index 4ff7ee31..502f0d81 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -448,6 +448,9 @@ extern NSString *SPFavoriteSSLCertificateFileLocationKey;
extern NSString *SPFavoriteSSLCACertFileLocationEnabledKey;
extern NSString *SPFavoriteSSLCACertFileLocationKey;
+// Favorites import/export
+extern NSString *SPFavoritesDataRootKey;
+
// Bundle Files and Bundle Editor
extern NSString *SPBundleScopeQueryEditor;
extern NSString *SPBundleScopeDataTable;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index f8e3fe4f..ecb91e41 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -254,6 +254,9 @@ NSString *SPFavoriteSSLCertificateFileLocationKey = @"sslCertificateFileL
NSString *SPFavoriteSSLCACertFileLocationEnabledKey = @"sslCACertFileLocationEnabled";
NSString *SPFavoriteSSLCACertFileLocationKey = @"sslCACertFileLocation";
+// Favorites import/export
+NSString *SPFavoritesDataRootKey = @"SPConnectionFavorites";
+
// Bundle Files and Bundle Editor
NSString *SPBundleScopeQueryEditor = @"editor";
NSString *SPBundleScopeDataTable = @"datatable";
diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m
index 23be83d7..1ac410e5 100644
--- a/Source/SPFavoritesController.m
+++ b/Source/SPFavoritesController.m
@@ -104,7 +104,9 @@ static SPFavoritesController *sharedFavoritesController = nil;
{
pthread_mutex_lock(&favoritesLock);
- [NSThread detachNewThreadSelector:@selector(_saveFavoritesDataInBackground:) toTarget:self withObject:[[[favoritesTree childNodes] objectAtIndex:0] dictionaryRepresentation]];
+ [NSThread detachNewThreadSelector:@selector(_saveFavoritesDataInBackground:)
+ toTarget:self
+ withObject:[[[favoritesTree childNodes] objectAtIndex:0] dictionaryRepresentation]];
pthread_mutex_unlock(&favoritesLock);
}
diff --git a/Source/SPFavoritesExportProtocol.h b/Source/SPFavoritesExportProtocol.h
new file mode 100644
index 00000000..59daf996
--- /dev/null
+++ b/Source/SPFavoritesExportProtocol.h
@@ -0,0 +1,42 @@
+//
+// $Id$
+//
+// SPFavoritesExportProtocol.h
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on June 11, 2011
+// Copyright (c) 2011 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+/**
+ * @protocol SPFavoritesExportProtocol SPFavoritesExportProtocol.h
+ *
+ * @author Stuart Connolly http://stuconnolly.com/
+ *
+ * Favorites exporter delegate protocol.
+ */
+@protocol SPFavoritesExportProtocol
+
+/**
+ * Invoked when the favorites export proccess completes
+ *
+ * @param error An error instance. Anything other than nil indicates an error occurred.
+ */
+- (void)favoritesExportCompletedWithError:(NSError *)error;
+
+@end
diff --git a/Source/SPFavoritesExporter.h b/Source/SPFavoritesExporter.h
new file mode 100644
index 00000000..058c5a42
--- /dev/null
+++ b/Source/SPFavoritesExporter.h
@@ -0,0 +1,52 @@
+//
+// $Id$
+//
+// SPFavoritesExporter.h
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on May 14, 2011
+// Copyright (c) 2011 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import "SPFavoritesExportProtocol.h"
+
+@interface SPFavoritesExporter : NSObject
+{
+ NSObject <SPFavoritesExportProtocol> *delegate;
+
+ NSError *exportError;
+
+ NSString *exportPath;
+ NSArray *exportFavorites;
+}
+
+@property (readwrite, assign) NSObject <SPFavoritesExportProtocol> *delegate;
+
+/**
+ * @property exportPath The file path to export to
+ */
+@property (readwrite, retain) NSString *exportPath;
+
+/**
+ * @property exportFavorites The array of favorites to be exported
+ */
+@property (readwrite, retain) NSArray *exportFavorites;
+
+- (void)writeFavorites:(NSArray *)favorites toFile:(NSString *)path error:(NSError **)error;
+
+@end
diff --git a/Source/SPFavoritesExporter.m b/Source/SPFavoritesExporter.m
new file mode 100644
index 00000000..a818fdcf
--- /dev/null
+++ b/Source/SPFavoritesExporter.m
@@ -0,0 +1,107 @@
+//
+// $Id$
+//
+// SPFavoritesExporter.m
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on May 14, 2011
+// Copyright (c) 2011 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import "SPFavoritesExporter.h"
+#import "SPTreeNode.h"
+
+@interface SPFavoritesExporter ()
+
+- (void)_writeFavoritesInBackground;
+
+@end
+
+@implementation SPFavoritesExporter
+
+@synthesize delegate;
+@synthesize exportPath;
+@synthesize exportFavorites;
+
+/***
+ * Write the supplied array of favorites to the file at the supplied path.
+ *
+ * @param favorites The array of favorites to be written
+ * @param path The file system path that the file is to be written to
+ * @param filename The filename of the file to be written
+ * @param error Upon return if an error occurred contains the NSError instance
+ *
+ * @return A BOOL indicating the success of the operation
+ */
+- (void)writeFavorites:(NSArray *)favorites toFile:(NSString *)path error:(NSError **)error
+{
+ [self setExportFavorites:favorites];
+ [self setExportPath:path];
+
+ [NSThread detachNewThreadSelector:@selector(_writeFavoritesInBackground) toTarget:self withObject:nil];
+}
+
+/**
+ * Writes the favorites array to disk in plist format on separate thread.
+ */
+- (void)_writeFavoritesInBackground
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSError *error = nil;
+ NSString *errorString = nil;
+
+ NSMutableArray *favorites = [[NSMutableArray alloc] init];
+
+ // Get a dictionary representation of all favorites
+ for (SPTreeNode *node in [self exportFavorites])
+ {
+ [favorites addObject:[node dictionaryRepresentation]];
+ }
+
+ NSDictionary *dictionary = [NSDictionary dictionaryWithObject:favorites forKey:SPFavoritesDataRootKey];
+
+ [favorites release];
+
+ // Convert the current favorites tree to a dictionary representation to create the plist data
+ NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictionary
+ format:NSPropertyListXMLFormat_v1_0
+ errorDescription:&errorString];
+
+ if (plistData) {
+ [plistData writeToFile:[self exportPath] options:NSAtomicWrite error:&error];
+
+ if (error) {
+ NSLog(@"Error writing favorites data: %@", [error localizedDescription]);
+ }
+ }
+ else if (errorString) {
+ NSLog(@"Error converting favorites data to plist format: %@", errorString);
+
+ [errorString release];
+ }
+
+ // Inform the delegate that the export has completed and pass the error instance
+ if ([self delegate] && [[self delegate] respondsToSelector:@selector(favoritesExportCompletedWithError:)]) {
+ [[self delegate] performSelectorOnMainThread:@selector(favoritesExportCompletedWithError:) withObject:error waitUntilDone:NO];
+ }
+
+ [pool release];
+}
+
+@end
diff --git a/Source/SPFavoritesImporter.h b/Source/SPFavoritesImporter.h
new file mode 100644
index 00000000..fefc54e4
--- /dev/null
+++ b/Source/SPFavoritesImporter.h
@@ -0,0 +1,31 @@
+//
+// $Id$
+//
+// SPFavoritesImporter.h
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on May 14, 2011
+// Copyright (c) 2011 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+@interface SPFavoritesImporter : NSObject
+{
+
+}
+
+@end
diff --git a/Source/SPFavoritesImporter.m b/Source/SPFavoritesImporter.m
new file mode 100644
index 00000000..4b62d5d0
--- /dev/null
+++ b/Source/SPFavoritesImporter.m
@@ -0,0 +1,30 @@
+//
+// $Id$
+//
+// SPFavoritesImporter.m
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on May 14, 2011
+// Copyright (c) 2011 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import "SPFavoritesImporter.h"
+
+@implementation SPFavoritesImporter
+
+@end
diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj
index 314c3882..bbad5a65 100644
--- a/sequel-pro.xcodeproj/project.pbxproj
+++ b/sequel-pro.xcodeproj/project.pbxproj
@@ -34,6 +34,8 @@
11C211301180EC9A00758039 /* SPDatabaseRename.m in Sources */ = {isa = PBXBuildFile; fileRef = 11C2109D1180E70800758039 /* SPDatabaseRename.m */; };
11D44DF0118F5887002AA43C /* OCMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 11D44DEF118F5887002AA43C /* OCMock.framework */; };
170EAA301311B7AA000AE5FE /* SPConnectionControllerDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 170EAA2F1311B7AA000AE5FE /* SPConnectionControllerDataSource.m */; };
+ 17123A1C137F09C200D06442 /* SPFavoritesExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 17123A1B137F09C100D06442 /* SPFavoritesExporter.m */; };
+ 17123A1F137F09E500D06442 /* SPFavoritesImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 17123A1E137F09E500D06442 /* SPFavoritesImporter.m */; };
171312CE109D23C700FB465F /* SPTableTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 171312CD109D23C700FB465F /* SPTableTextFieldCell.m */; };
17148565125F5FF500321285 /* SPDatabaseCharacterSets.m in Sources */ = {isa = PBXBuildFile; fileRef = 17148564125F5FF500321285 /* SPDatabaseCharacterSets.m */; };
1723F08B12F1F9350008253B /* SPWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 1723F08A12F1F9350008253B /* SPWindow.m */; };
@@ -572,6 +574,10 @@
11D44DEF118F5887002AA43C /* OCMock.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCMock.framework; path = Frameworks/OCMock.framework; sourceTree = "<group>"; };
170EAA2E1311B7AA000AE5FE /* SPConnectionControllerDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPConnectionControllerDataSource.h; sourceTree = "<group>"; };
170EAA2F1311B7AA000AE5FE /* SPConnectionControllerDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPConnectionControllerDataSource.m; sourceTree = "<group>"; };
+ 17123A1A137F09C100D06442 /* SPFavoritesExporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFavoritesExporter.h; sourceTree = "<group>"; };
+ 17123A1B137F09C100D06442 /* SPFavoritesExporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFavoritesExporter.m; sourceTree = "<group>"; };
+ 17123A1D137F09E500D06442 /* SPFavoritesImporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFavoritesImporter.h; sourceTree = "<group>"; };
+ 17123A1E137F09E500D06442 /* SPFavoritesImporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFavoritesImporter.m; sourceTree = "<group>"; };
17128B8A0FE6E0210035DD75 /* QLPreviewPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QLPreviewPanel.h; sourceTree = "<group>"; };
1713122F109C7DF600FB465F /* build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
171312CC109D23C700FB465F /* SPTableTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableTextFieldCell.h; sourceTree = "<group>"; };
@@ -857,6 +863,7 @@
17F90E471210B42700274C98 /* SPExportFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPExportFile.m; sourceTree = "<group>"; };
17F90E491210B43A00274C98 /* SPExportFileUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPExportFileUtilities.h; sourceTree = "<group>"; };
17F90E4A1210B43A00274C98 /* SPExportFileUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPExportFileUtilities.m; sourceTree = "<group>"; };
+ 17F9185C13A415C5005EE9BD /* SPFavoritesExportProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFavoritesExportProtocol.h; sourceTree = "<group>"; };
17FDB04A1280778B00DBBBC2 /* SPFontPreviewTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFontPreviewTextField.h; sourceTree = "<group>"; };
17FDB04B1280778B00DBBBC2 /* SPFontPreviewTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFontPreviewTextField.m; sourceTree = "<group>"; };
296DC89E0F8FD336002A3258 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = /System/Library/Frameworks/WebKit.framework; sourceTree = "<absolute>"; };
@@ -1369,6 +1376,17 @@
name = "Database Actions";
sourceTree = "<group>";
};
+ 17123A19137F098700D06442 /* Import & Export */ = {
+ isa = PBXGroup;
+ children = (
+ 17123A1D137F09E500D06442 /* SPFavoritesImporter.h */,
+ 17123A1E137F09E500D06442 /* SPFavoritesImporter.m */,
+ 17123A1A137F09C100D06442 /* SPFavoritesExporter.h */,
+ 17123A1B137F09C100D06442 /* SPFavoritesExporter.m */,
+ );
+ name = "Import & Export";
+ sourceTree = "<group>";
+ };
17128B890FE6DFFA0035DD75 /* QuickLook */ = {
isa = PBXGroup;
children = (
@@ -1784,7 +1802,8 @@
17D3C6031289BF350047709F /* SPConnectionControllerDelegate.m */,
170EAA2E1311B7AA000AE5FE /* SPConnectionControllerDataSource.h */,
170EAA2F1311B7AA000AE5FE /* SPConnectionControllerDataSource.m */,
- 17D38FC3127B0CFC00672B13 /* SPConnectionControllerDelegateProtocol.h */,
+ 17123A19137F098700D06442 /* Import & Export */,
+ 17F9187013A4274A005EE9BD /* Delegate Protocols */,
);
name = "Connection View";
sourceTree = "<group>";
@@ -2262,6 +2281,15 @@
name = Model;
sourceTree = "<group>";
};
+ 17F9187013A4274A005EE9BD /* Delegate Protocols */ = {
+ isa = PBXGroup;
+ children = (
+ 17F9185C13A415C5005EE9BD /* SPFavoritesExportProtocol.h */,
+ 17D38FC3127B0CFC00672B13 /* SPConnectionControllerDelegateProtocol.h */,
+ );
+ name = "Delegate Protocols";
+ sourceTree = "<group>";
+ };
17FDB0AC1280938000DBBBC2 /* Controls */ = {
isa = PBXGroup;
children = (
@@ -3236,6 +3264,8 @@
1791352712F9ED16000B27C1 /* SPMutableArrayAdditions.m in Sources */,
170EAA301311B7AA000AE5FE /* SPConnectionControllerDataSource.m in Sources */,
582F02311370B52600B30621 /* SPExportFileNameTokenObject.m in Sources */,
+ 17123A1C137F09C200D06442 /* SPFavoritesExporter.m in Sources */,
+ 17123A1F137F09E500D06442 /* SPFavoritesImporter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};