Rich Text File (RTF) Into NSTextView, Cocoa & Obj-C

I was searching for an example of how to do this for ages and came up with nothing. All the pros out there will probably say it is easy and give shorter ways of doing this but for noobs and people not in the know I wrote this little snippet. This is especially useful for creating easy to maintain change logs or for adding simple read-me and help files to your application.

First of all you will need to create a NIB file with some sort of controller class in it. In the controller class create an outlet of type ‘NSTextView’, for this example I will call it ‘controller_Out_TextView’. Then generate the files for this controller so they appear in your Xcode project.

Secondly, create a window and add an NSTextView to it from the palette, connect the NSTextView to the outlet in the controller.

You will then need to create your rich text file with the necessary text in it, make sure it is added to your project and will be copied to the application bundle. For this example the text file will be called (rather originally) file.rhtml.

Finally add the following code to the ControllerName.m file between the @implementation and @end, or in your awakeFromNib method, if you already have one.

- (void)awakeFromNib
{
  NSBundle * myMainBundle = [NSBundle mainBundle];
  NSString * rtfFilePath = [myMainBundle pathForResource:@"file" ofType:@"rtf"];
  [controller_Out_TextView readRTFDFromFile:rtfFilePath];
}

Compile and run, hoepfully all of your text will be displayed.

It's Finally Out The Door

At last iSyncIt 0.8 has been released. The main issue fixed with this version are the crashes that occurred, especially when syncing more than once, if you find any more problems don’t hesitate to contact me. I have also created new icons for the software, a more dock friendly (if you choose to put it on your dock) and more ‘Mac’ main icon and a more individual menu bar icon, unfortunately it is still not animated but i’m working on it. So download and enjoy.

It's All Gone Web 2.0 [Updated]

Along with solving the iSyncIt problems I have decided to give the website a makeover (not that it’s really out of date). The makeover is not a serious attempt at making the website look more professional, more of an attempt to make it as ridiculously Web 2.0 like as possible. The main aim is to give the software pages a better appearance and allow images to feature more heavily in the website.

P.S. For legalities sake and the fact I don’t really know what’s going on with the Web 2.0 name, as far as I know O’Reilly own some stake in the name so I thought best to give them a shout.

Update: Turns out O’Reilly only own the trademark “Web 2.0” in the context of conferences so I should be safe, phew.

iSyncIt Crashes

I have now got to the bottom (I think) of the iSyncIt crashes that seem to affect a few versions of the software. I am currently in the process of fixing the bugs and a new release should be out within the next few weeks. Development is a little bit slower than normal at the moment because my brain is still in holiday mode and I am making plans for university.

Textilize Alternative

The textilize methods in Rails has never really been what I wanted. When it wasn’t adding paragraphs it was messing with my line brakes but it made such a good job of making HTML and XHTML that validates. In order to make it work better I re-wrote the method to be more suitable.

Put the following in the application_helper.rb file and call it using custom_text(“String”).

def custom_text(text)
  if text.blank?
    ""
  else
    text = RedCloth.new(text).to_html
    if text[0..2] == "<p>" then text = text[3..-1] end
    if text[-4..-1] == "</p>" then text = text[0..-5] end
    text = text.gsub("<p>", "")
    text = text.gsub("</p>", "")
    return text
  end
end

Job done, you should get correct HTML and XHTML but no paragraphs and no messing with line breaks.

Ruby on Rails Update

For all of you Ruby on Rails users out there make sure you have upgraded Rails to version 1.1.6. I know that most people don’t like to install these incremental updates because they tend to break things quite easily but this one really is a major update.

For those of you that do not know, versions of Ruby on Rails up to version 1.1.5 have suffered from a problem by which even an amateur hacker can type a URL and create a process that hangs and basically shuts down the website. I’m not going to be irresponsible and publish the affected URL’s but make sure you upgrade.

I'm Back

Well, i’m back from my holiday and already working hard on iSyncIt (well not really, but in the next few days). I am also getting around to fixing the problem with month changes on the blog which are not currently handled very well. Just thought I had better keep you informed and show that I haven’t disappeared off the face of the planet.

Downtime & Absence

I’ve just received notice from my hosting provider that the website will experience some downtime tonight (27th July) between 23:00 and 3:00 GMT. Just thought it would be best to let you know so you’re not left wondering where this wonderful website has gone.

I am having a break for the next two weeks starting Saturday morning. During this time there will be no new posts or new software releases and I will not be contact-able through the contact form or by email. If you have any serious problems with any of the software or the website not functioning contact me in the next 24 hours and I will try and sort the problems before I leave.

Have a good summer everyone. I will be back soon.

Localization

Recently, I have had a closer look at the website logs and noticed, to my surprise that I am getting a lot of hits from German users, especially to the software pages. I have therefore decided to start work on localizing iSyncIt, my primary application, into German. I am aiming to have the localization integrated from the 1.0 releases for now, the 0.x releases will remain in English only.

If you are German speaking and what your name in the credits for iSyncIt then; use the application, translate all of the strings and messages in it and contact me with the localized strings. If nobody comes forward to help with this momentous task then I will be performing the translations with Babel Fish.

On a side note, iSyncIt 0.7 has just been released, there aren’t many changes in this release, just the ability to add iSyncIt to your ‘Login Items’. You can download it here.

An Email Form with Ruby on Rails

The one thing that I’ve been struggling with the most during my Ruby on Rails learning curve is how to create a simple email form for any web applications I may want to create. There was nothing to be found on Google so in my initial attempt I worked through the ActionMailer documentation on the RoR wiki website. I put it all together and, feeling really pleased with myself, clicked the send button. Nothing at all, just lists of errors, so I modified it and still more errors. After posting on Ruby Forum and with the help of a talented member I finally got it working.

This post is for all the people like me who don’t know what to do.

First of all, this tutorial assumes that you already have a basic RoR web application set up with a ‘Contact’ controller and a main view for the index in the controller.

Now the real work starts. Open up a terminal session (or SSH) and navigate to your rails application’s directory (for this tutorial the rail application will be ‘rails_app’).

cd /rails_app

Then create the mailer, ‘Emailer’ is the name of the model that will be produced.

./script/generate mailer Emailer

Now, that’s all the terminal work done. Lets start the setup.

In your chosen editor open the file ‘/rails_app/config/environment.rb’ and place the following inside the ‘Rails::Initializer’ block customizing all the necessaries to your SMTP server’s configuration.

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address => 'localhost',
  :domain => 'website.co.uk',
  :port => 25,
  :authentication => :login,
  :user_name => "smtp_username",
  :password => "smtp_password"
}

config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_charset = "utf-8"

Now open the file ‘/rails_app/app/models/emailer.rb’ and make it look like the below, again customizing the necessaries (but do not touch the variables).

class Emailer < ActionMailer::Base
  def contact_email(email_params)
    # You only need to customize @recipients.
    @recipients = "[email protected]"
    @from = email_params[:name] + " <" + email_params[:address] + ">"
    @subject = email_params[:subject]
    @sent_on = Time.now
    @body["email_body"] = email_params[:body]
    @body["email_name"] = email_params[:name]
    content_type "text/html"
  end
end

In the controller for your contact page you will need to make the following changes, basically, adding a definition for ‘send_mail’.

def send_mail
  Emailer::deliver_contact_email(params[:email])
end

Go to the ‘/rails_app/views/emailer’ folder and create a file called ‘contact_email.html.erb’. In this file place the following code.

<p>Name:</p>

<p><%= @email_name %></p>

<p>Message:</p>

<p><%= @email_body %></p>

The final step is to create a form on the ‘Contact’ page that will allow the website to user to input and submit the email. An example for is illustrated below.

<% form_for :email, :url => { :controller => 'contact', :action => 'send_mail' } do |f| %>
  <%= f.label :name %><br />
  <%= f.text_field :name, :size => 60 %><br />
  <%= f.label :address %><br />
  <%= f.text_field :address, :size => 60 %><br />
  <%= f.label :subject %><br />
  <%= f.text_field :subject, :size => 60 %><br />
  <%= f.label :body %><br />
  <%= f.text_area :body, :rols => 10, :cols => 60 %><br />
  <%= submit_tag "Send Email "%>
<% end %>

That’s about it really, you may want to add your own error handling as this example only covers the basics. If you go to the contact page you can see a working example of the above tutorial in action. There are probably easier ways of doing this than the method I have described, but I like my method and hopefully it will work for you.

Update: The code in this post was updated for Rails 2.0.x on 17th March 2008.

Update: Modified the settings code to be ‘smtp_settings’ rather than ‘server_settings’, thanks goes to Lyle for discovering the problem (below).

Update: Modified the code to work for Rails 2.3.x onwards (but not Rails 3).

Little Snitch, iSyncIt & The Website

The first topic of todays post is Little Snitch. For those of you that do not know this Mac OS X software, it is a small utility that warns of outgoing connections and allows them to be blocked if necessary. It can be downloaded here. The main reason I am mentioning it is that I have received an email today from a worried user of iSyncIt that was informed by Little Snitch of iSyncIt checking in with boycie.primehosting.co.uk. This is perfectly normal as this is the websites hosting server so it is OK to allow the connection with Little Snitch, iSyncIt is just checking for updates.

Version 0.6 of iSyncIt is out with the advertised bug fixes. I have also rewritten all the code so the memory footprint is much smaller. The general appearance of the application (especially the preferences panel) has also been improved.

I have also received an email from my web host to inform me that my account may be moved to a different hosting server. This may cause a very short amount of downtime in the coming days. It could also cause Little Snitch to report a different server, but it is still OK.

I Use This

Whist I was browsing my favorite blog (TUAW) today an interesting post popped up. It seems that some guys known only as Arne and Marcus have started a website that is sort of a cross between MacUpdate and del.icio.us. I think it’s a brilliant idea and should be supported so hop on over to iusethis.com, get registered and get adding. Plus if your a user of iSyncIt you can let me know. (See there is always another motive for blog posts).

Feature Frozen

Version 0.5 of iSyncIt is now in the wild. I can’t actually think of anything else to add to it at the moment so this will be the feature frozen release for now. Any subsequent releases, probably up to version 1.0 (if I get that far) will just be bug fix releases, I also plan on optimizing the code in these releases to give a smaller memory footprint and a faster run time.

Hidden Dock Icon

Unfortunately (primarily due to my lack of programming knowledge) I have not yet found a way to give the user an option of choosing whether or not to show the dock icon. I personally think that the menu bar item is more useful for iSyncIt so the dock icon will remain hidden for now. If any programmers out there know how to achieve the choice of dock hiding in Obj-C then feel free to contact me.

On that bombshell, iSyncIt 0.4 has now been released. All of you using automatic updates in 0.3 should receive it straight away but for everyone else it is available from the software section or you can get it from MacUpdate and let me keep track of the number of downloads. All the changes in this version are on the software page.

iSyncIt 0.3

iSyncIt 0.3 is now available in the wild. The most obvious changes in this release are the removal of iSyncIt’s dock presence and the introduction of a menu bar item instead. This also means that iSyncIt can be added to your login items and you can have much easier access to your syncing. Future updates of iSyncIt will now be handled through the Sparkle update engine. View more about iSyncIt here.

Everything on MacUpdate & iSyncIt

I have now uploaded all of my applications onto MacUpdate and to my surprise they appear to be getting quite alot of downloads. Luckily it does not appear to be affecting my bandwidth yet even though my hit count has risen rapidly.

I am now in the progress of updating iSyncIt to version 0.3. The major changes that will feature in the next release are; a dock menu and menu bar item for easier syncing and a properly compiled application instead of an AppleScript application.

(Apologies to anyone who has already recieved this post, or something similar too it, the original disappeared off the server for some reason so I have had to re-write it to restore it.)

Web Server Management Released

I have just released a small Automator utility into the wild. The purpose of this piece of software is to easily allow you to manage your web server components from a single interface. The initial release has support for OS X’s built in Apache web server and recent releases of MySQL that install to ‘/usr/local’. You can view more about the application here.

Minor Comment Problem [Updated]

I’ve just noticed a small problem with the AJAX on the commenting system. The page resets back to the top when the link to add a comment or show and hide comments is clicked. This issue will be sorted as soon as I find a better way to implement the link.

Update: The problem has been sorted. When you click the add comment or show and hide comment links and the bottom of a post the page should not refresh back up to the top so you can’t write anything.

Mini-ITX Testing Server [Updated]

This is my first in hopefully a long line of tech based posts about my experiences and things that I see on the internet. I thought I would write this post in the form of a story. So I’ll begin.

When I first started developing websites they were small, primarily static websites that would run quite comfortably on an Apache testing server on the computer I was also developing the website on. Unfortunately, my interests widened and large Ruby on Rails or ColdFusion websites would consume all of the computers resources preventing me from doing any developing what so ever. This led me to the decision that I needed an independent server to test websites on.

The first server that I set up was based on a Dell Optiplex GLx Pentium II. I even had to rip the CD-ROM out of it to fit a second hard drive in so that I would have enough space for the OS (Debian 3.1 Sarge) this was great until I needed to access the server remotely and run FastCGI, in the end this server slowed down to a snails pace.

I based my second attempt on a specification as I thought it would lead me to a better result. The specification I thought of was as follows:

  • Small footprint.
  • Quiet operation.
  • Low running temperature.
  • USB for backup.
  • Plenty of storage space.

After my searching’s through the internet I came across the Mini-ITX form factor and decided this would be my best option. All the components that I used were sourced from LinITX and eBay and assembled by myself. The end specification including software is:

Hardware:

  • Motherboard:VIAEPIA 5000 Eden
  • Processor:VIA Eden 533Mhz EBGA, Fanless
  • Memory: 256MB Kingston Low Profile PC133
  • Storage: Seagate ST92011A – 20GB (IDE), IBM DMCA21440 – 1.4GB (USB), 24×8×4 Slim CD-RW (IDE)
  • Case: Cubid 3688 (Black), 1x Case Fan, 12V Power Board

System Software:

  • OS: Ubuntu 6.06 LTS Server
  • Kernel: 2.6.15
  • Bootloader: Grub 0.9.7

Server Software:

  • Webserver: Apache 2.0.55
  • PHP: 5.1.2
  • Database: MySQL 5.0.12
  • CGI: FastCGI 2.4.2
  • Ruby: 1.8.4 inc. Rails 1.1.2

The server runs very quickly, very quietly and as you can see from the image above it is very small.

The aim of this post is to help anyone in the same situation as me to get a setup that works. Hope it helps.

Back soon.

Update: Something I forget to mention in the original post that I remembered when re-installing the other day is that the default kernel with the Ubuntu 6.06 Server disk does not function correctly with the VIA Eden processor. If you use this disk you must install, re-boot from CD and select repair installation, then using ‘apt-get’ or Aptitude install the kernel ‘i386 – 2.6.15’ from one of the Ubuntu repositories. When you restart everything should be working fine.

Softpedia

It would appear that Softpedia has now also got hold of iSyncIt and they have certified it as 100% clean software. This means that you can be safe in the knowledge that it will not infect your computer with any unwanted software. You can check out the certification here and download the Softpedia linked version here.

iSyncIt on MacUpdate

I took the plunge and submitted iSyncIt to MacUpdate in the version 0.2 form. It’s actually doing better than I expected and has 77 downloads at the time of writing this. Luckily the file is hosted on Google Pages rather than this website so my bandwidth isn’t suffering yet. If you want to view the listing and perhaps contrubute to the number of downloads go to MacUpdate. Hopefully the software will continue to function with the next release of iSync.

Two New Pieces Of Killer Software

I have posted up two new pieces of software, both pieces of software are based on Automator actions and AppleScript. The first piece of software is Kill Dashboard, this allows the Dashboard in OS X to be shut down to free up system resources. The second piece is Kill Front Row, this allows Front Row to be shut down to also free up resources. Enjoy.

New Month, New Problem

It’s a new month and another problem with the website has been corrected. Now, if you view a post through the archive system the main post actually shows up instead of disappearing into obilivion. I’m hoping that this will be the last issue with the website and I should now be able to use it as my actual blog. I believe the website development speak is over for now.

Reshuffle Complete

Well, the reshuffle went quicker than expected. I only had to change a few aliases on the server and a couple of graphics and it was done, digitalp.co.uk is going to be used for different purposes now but digital:pardoe will remain as the home of iSyncIt and will become my personal tech blog. Hope you kept up.

Website Reshuffle

I am going to be resuffling my domain names soon. This site will be migrated to digitalpardoe.co.uk which currently points to this website anyway and digitalp.co.uk will become my portfolio and more business oriented site. I will post here before the change is made just to inform you.