[Pkg-owncloud-commits] [owncloud-client] 174/219: SocketApi: Port OS X to use local sockets

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Oct 11 14:43:23 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit f8b73eb9d970dbf0b530e13b34b0940750dc3926
Author: Markus Goetz <markus at woboq.com>
Date:   Tue Sep 30 07:36:20 2014 +0200

    SocketApi: Port OS X to use local sockets
---
 .../MacOSX/OwnCloudFinder/RequestManager.m         | 37 ++++++++++++++++++----
 src/mirall/socketapi.cpp                           |  8 +++++
 src/mirall/socketapi.h                             |  7 ++--
 3 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/shell_integration/MacOSX/OwnCloudFinder/RequestManager.m b/shell_integration/MacOSX/OwnCloudFinder/RequestManager.m
index fae7e77..4e6b2e1 100644
--- a/shell_integration/MacOSX/OwnCloudFinder/RequestManager.m
+++ b/shell_integration/MacOSX/OwnCloudFinder/RequestManager.m
@@ -183,9 +183,19 @@ static RequestManager* sharedInstance = nil;
 	return 0.0;
 }
 
+-(void)socket:(GCDAsyncSocket*)socket didConnectToUrl:(NSURL *)url {
+	NSLog(@"didConnectToUrl %@", url);
+	[self socketDidConnect:socket];
+}
+
 - (void)socket:(GCDAsyncSocket*)socket didConnectToHost:(NSString*)host port:(UInt16)port
 {
-	NSLog( @"Connected to host successfully!");
+	[self socketDidConnect:socket];
+}
+
+// Our impl
+- (void)socketDidConnect:(GCDAsyncSocket*)socket  {
+	NSLog( @"Connected to sync client successfully!");
 	_isConnected = YES;
 	_isRunning = NO;
 
@@ -234,12 +244,27 @@ static RequestManager* sharedInstance = nil;
 {
 	if (!_isRunning)
 	{
-		NSLog(@"Connect Socket!");
 		NSError *err = nil;
-		if (![_socket connectToHost:@"localhost" onPort:34001 withTimeout:5 error:&err]) // Asynchronous!
-		{
-			// If there was an error, it's likely something like "already connected" or "no delegate set"
-			NSLog(@"I goofed: %@", err);
+		BOOL useTcp = NO;
+		if (useTcp) {
+			NSLog(@"Connect Socket");
+		    if (![_socket connectToHost:@"localhost" onPort:34001 withTimeout:5 error:&err]) {
+				// If there was an error, it's likely something like "already connected" or "no delegate set"
+				NSLog(@"I goofed: %@", err);
+			}
+		} else if (!useTcp) {
+			NSURL *url;
+			NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+			if ([paths count])
+			{
+				// file:///Users/guruz/Library/Caches/SyncStateHelper/ownCloud.socket
+				// FIXME Generify this and support all sockets there since multiple sync clients might be running
+				url =[NSURL fileURLWithPath:[[[paths objectAtIndex:0] stringByAppendingPathComponent:@"SyncStateHelper"] stringByAppendingPathComponent:@"ownCloud.socket"]];
+			}
+			if (url) {
+				NSLog(@"Connect Socket to %@", url);
+				[_socket connectToUrl:url withTimeout:5 error:&err];
+			}
 		}
 		
 		 _isRunning = YES;
diff --git a/src/mirall/socketapi.cpp b/src/mirall/socketapi.cpp
index 81e2376..d8a2fe8 100644
--- a/src/mirall/socketapi.cpp
+++ b/src/mirall/socketapi.cpp
@@ -241,6 +241,14 @@ SocketApi::SocketApi(QObject* parent)
     if (Utility::isWindows()) {
         socketPath = QLatin1String("\\\\.\\pipe\\")
                 + Theme::instance()->appName();
+    } else if (Utility::isMac()) {
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+        // Always using Qt5 on OS X
+        QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
+        socketPath = runtimeDir + "/SyncStateHelper/" + Theme::instance()->appName() + ".socket";
+        // We use the generic SyncStateHelper name on OS X since the different branded clients
+        // should unfortunately not mention that they are ownCloud :-)
+#endif
     } else {
         QString runtimeDir;
 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
diff --git a/src/mirall/socketapi.h b/src/mirall/socketapi.h
index 61156b3..7006373 100644
--- a/src/mirall/socketapi.h
+++ b/src/mirall/socketapi.h
@@ -33,10 +33,9 @@ class QStringList;
 
 namespace Mirall {
 
-#if defined(Q_OS_MAC)
-// There is no easy way to use the socket API from non Qt mac applications
-#define SOCKETAPI_TCP
-#endif
+//Define this to use the old school TCP API. Maybe we should offer both APIs
+// and have the old TCP one be enableable via command line switch?
+//#define SOCKETAPI_TCP
 
 #ifdef SOCKETAPI_TCP
 typedef QTcpSocket SocketType;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list