Add torrents to Transmission from anywhere

January 8, 2012 Leave a comment

Requirements:

Configuring Transmission to automagically start downloading:
  1. Open Transmission preferences;
  2. Check “Start transfers when added”;
  3. Uncheck “Display a window when opening a torrent file”;
  4. Check “Watch for torrent files in : {a folder on your dropbox}”
Now if you add a torrent to that folder while you are away from the computer, Transmission will start downloading automatically.
<3 Dropbox
*Tested on Mac OSX Lion
Categories: Cloud, Dropbox, Install, Torrents

Installing Redis on Mac OS X

July 23, 2011 4 comments

Get source and install

$ wget http://redis.googlecode.com/files/redis-2.2.12.tar.gz 
$ tar xzf redis-2.2.12.tar.gz 
$ cd redis-2.2.12 
$ make
$ make install 

And it should be up and running on:

/usr/local/bin/redis-server

For Redis server to start on boot

$ sudo nano /Library/LaunchDaemons/org.redis.redis-server.plist

Copy the  following to the the file you just created.

Create the log dir if it doesn’t exists yet

sudo mkdir /var/log/redis

Load and launch the Daemon:

sudo launchctl load /Library/LaunchDaemons/org.redis.redis-server.plist
sudo launchctl start org.redis.redis-server

Hope it helps ;)

Categories: Development, Install, Redis

Capturing touch events

July 20, 2010 3 comments

While developing an iPhone application I needed to detect all touch events. I found some tips on how to do it in objective-c but I’m mostly using MonoTouch.

Here is my solution:

Since I’m doing a Window based application, I thought that I could probably get the touch events by overriding the standard UIWindow with my own version.

Taking a look to the default generated code (MainWindow.xib) we can see that the application is based on a UIWindow:

// Base type probably should be MonoTouch.Foundation.NSObject or subclass
[MonoTouch.Foundation.Register("AppDelegate")]
public partial class AppDelegate {

	private UIWindow __mt_window;

	#pragma warning disable 0169
	[MonoTouch.Foundation.Connect("window")]
	private UIWindow window {
		get {
			this.__mt_window = ((UIWindow)(this.GetNativeField("window")));
			return this.__mt_window;
		}
		set {
			this.__mt_window = value;
			this.SetNativeField("window", value);
		}
	}
}

To create our custom windows class we can double-click the MainWindows.xib file and do it on InterfaceBuilder.

Step by step what to do on Interface Builder:

  1. Click on the Window and change the class to “EventUIWindow”;
  2. In the “Library” select “EventUIWindow”
  3. Set the inheritance super class to UIWindow
  4. Save and close Interface Builder

Now if we look at the generated code we have this:


// Base type probably should be MonoTouch.Foundation.NSObject or subclass
[MonoTouch.Foundation.Register("EventUIWindow")]
public partial class EventUIWindow { }

[MonoTouch.Foundation.Register("AppDelegate")]
public partial class AppDelegate {

	private EventUIWindow __mt_window;

	#pragma warning disable 0169
	[MonoTouch.Foundation.Connect("window")]
	private UIWindow window {
		get {
			this.__mt_window = ((EventUIWindow)(this.GetNativeField("window")));
			return this.__mt_window;
		}
		set {
			this.__mt_window = value;
			this.SetNativeField("window", value);
		}
	}
}

Now the only thing we need to do is to implement the EventUIWindow. We can do this since it is a partial class. On the implementation we need to override the SendEvent method.

Some sample code:

public partial class EventUIWindow : UIWindow
	{
		public EventUIWindow () : base() {}

		public EventUIWindow (IntPtr handle) : base(handle) {}

		public override void SendEvent (UIEvent evt)
		{
			// Send the event to its original destination
			base.SendEvent (evt);
			// Get touchs from the event
			var touchs = evt.AllTouches;
			// Count will be one most of the time (single touch) but multitouch will appear here. E.g. Pinch touchs.Count = 2
			if (touchs.Count > 0)
			{
				// Get one touch event from the array
				UITouch touch = touchs.AnyObject as UITouch;
				if (touch != null)
				{
					// You can get the touch phase
					// UITouchPhase.Began || UITouchPhase.Cancelled || UITouchPhase.Ended || UITouchPhase.Moved || UITouchPhase.Stationary
					// touch.Phase;

					// How many taps the click had
					// touch.TapCount

					// Target view
					// touch.View

					// Target Window
					// touch.Window

					// Touch event timestamp
					// touch.Timestamp

					// And a few more things
				}
			}
		}
	}

You can find the full source code for this sample at http://github.com/reistiago/monotouch-samples/

Hope it helps

Categories: Development, iPhone, MonoTouch
Follow

Get every new post delivered to your Inbox.