Permalink
Browse files

fixed UTF8 string issue.

  • Loading branch information...
1 parent d9559b5 commit b2ce995f90cfe5571685c75f5c13dce2bd8268be @mootoh committed Jul 11, 2009
@@ -11,6 +11,7 @@
@interface WelcomeViewController : UIViewController <UITextFieldDelegate>
{
IBOutlet UITextField *textField_;
+ IBOutlet UILabel *pasteLabel;
NumberLabel *numberLabels[4];
NumberLabel *currentNumber;
@@ -217,12 +217,15 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode
uint8_t buf[1024];
uint32_t len = [(NSInputStream *)stream read:buf maxLength:1024];
if (len) {
- char *char_buf[1024];
- sscanf(buf, "%s\n", char_buf);
- NSString *received = [NSString stringWithCString:char_buf encoding:NSUTF8StringEncoding];
+ const char *char_buf[1024];
+ int len;
+ sscanf((char *)buf, "%04d,", &len);
+ NSString *received = [[[NSString alloc] initWithBytes:buf+5 length:len encoding:NSUTF8StringEncoding] autorelease];
+
NSLog(@"received %@", received);
UIPasteboard *pb = [UIPasteboard generalPasteboard];
pb.string = received;
+ pasteLabel.text = received;
} else {
NSLog(@"no buffer");
}
@@ -26,7 +26,6 @@
1D6058910D05DD3D006BFB54 /* PushPaste.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PushPaste.app; sourceTree = BUILT_PRODUCTS_DIR; };
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
288765A40DF7441C002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
- 2899E5210DE3E06400AC0155 /* PushPasteView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PushPasteView.xib; sourceTree = "<group>"; };
28AD733E0D9D9553002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; };
28D7ACF60DDB3853001CB0EB /* PushPasteViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PushPasteViewController.h; sourceTree = "<group>"; };
28D7ACF70DDB3853001CB0EB /* PushPasteViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PushPasteViewController.m; sourceTree = "<group>"; };
@@ -102,7 +101,6 @@
isa = PBXGroup;
children = (
92D2C8C11002B31400D32C99 /* WelcomeView.xib */,
- 2899E5210DE3E06400AC0155 /* PushPasteView.xib */,
28AD733E0D9D9553002E5188 /* MainWindow.xib */,
8D1107310486CEB800E47090 /* PushPaste-Info.plist */,
);
View
@@ -5,7 +5,6 @@
# Created by Motohiro Takayama on 5/28/09.
# Copyright (c) 2009 deadbeaf.org. All rights reserved.
#
-require 'pp'
require "socket"
class Daemon < OSX::NSObject
@@ -91,18 +90,9 @@ def start_daemon_thread
while true
Thread.start(gs.accept) do |s| # save to dynamic variable
- puts "acceped"
@clients.push s
while msg = s.read(4)
- puts "msg = #{msg}"
- case msg
- when /^C/
- copy
- when /^V/
- paste
- else
- do_nothing
- end
+ puts "passcode = #{msg}"
s.write($_)
end
s.close
@@ -111,17 +101,6 @@ def start_daemon_thread
end
end
- def copy
- @tc.callHandler_withParameters("ShortcutCopy", nil)
- end
-
- def paste
- @tc.callHandler_withParameters("ShortcutPaste", nil)
- end
-
- def do_nothing
- end
-
#
# NSNetService
#
@@ -142,16 +121,14 @@ def netServiceDidStop(sender)
@net_service = nil
end
- # Pasteboard, send to iPhone
+ # get string from Pasteboard, then send it to clients
def trigger
pb = OSX::NSPasteboard.generalPasteboard
pb.availableTypeFromArray [OSX::NSStringPboardType]
pb_string = pb.stringForType(OSX::NSStringPboardType)
- puts pb_string
- pp @clients
@clients.each do |client|
- client.puts pb_string
+ client.write [sprintf("%04d", pb_string.lengthOfBytesUsingEncoding(OSX::NSUTF8StringEncoding)), pb_string.UTF8String].join(',')
end
end
View
@@ -71,7 +71,7 @@
<object class="IBUITextField" id="760996829">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">-2147483356</int>
- <string key="NSFrame">{{123, 399}, {97, 31}}</string>
+ <string key="NSFrame">{{104, 409}, {97, 31}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
@@ -96,7 +96,7 @@
<object class="IBUIButton" id="318642106">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{117, 272}, {72, 37}}</string>
+ <string key="NSFrame">{{107, 249}, {84, 37}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
@@ -108,7 +108,7 @@
<int key="NSfFlags">16</int>
</object>
<int key="IBUIButtonType">1</int>
- <string key="IBUINormalTitle">Mac</string>
+ <string key="IBUINormalTitle">Connect</string>
<object class="NSColor" key="IBUIHighlightedTitleColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
@@ -122,6 +122,20 @@
<bytes key="NSWhite">MC41AA</bytes>
</object>
</object>
+ <object class="IBUILabel" id="613530275">
+ <reference key="NSNextResponder" ref="191373211"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{79, 325}, {148, 21}}</string>
+ <reference key="NSSuperview" ref="191373211"/>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <bool key="IBUIUserInteractionEnabled">NO</bool>
+ <string key="IBUIText">Pasteboard content</string>
+ <reference key="IBUITextColor" ref="317115585"/>
+ <nil key="IBUIHighlightedColor"/>
+ <int key="IBUIBaselineAdjustment">1</int>
+ <float key="IBUIMinimumFontSize">1.000000e+01</float>
+ </object>
</object>
<string key="NSFrameSize">{320, 460}</string>
<reference key="NSSuperview"/>
@@ -161,6 +175,14 @@
</object>
<int key="connectionID">49</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">pasteLabel</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="613530275"/>
+ </object>
+ <int key="connectionID">51</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -182,6 +204,7 @@
<reference ref="353715608"/>
<reference ref="760996829"/>
<reference ref="318642106"/>
+ <reference ref="613530275"/>
</object>
<reference key="parent" ref="317526666"/>
</object>
@@ -216,6 +239,11 @@
<reference key="object" ref="318642106"/>
<reference key="parent" ref="191373211"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">50</int>
+ <reference key="object" ref="613530275"/>
+ <reference key="parent" ref="191373211"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -229,6 +257,7 @@
<string>22.IBPluginDependency</string>
<string>4.IBPluginDependency</string>
<string>48.IBPluginDependency</string>
+ <string>50.IBPluginDependency</string>
<string>6.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
@@ -241,6 +270,7 @@
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -263,7 +293,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">49</int>
+ <int key="maxID">51</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -276,8 +306,17 @@
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">textField_</string>
- <string key="NS.object.0">UITextField</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>pasteLabel</string>
+ <string>textField_</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>UILabel</string>
+ <string>UITextField</string>
+ </object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>

0 comments on commit b2ce995

Please sign in to comment.