After wasting a lot of time myself, I thought this could serve some other people...

So here's how I did it :

  • First install the Subclipse plugin
    1. Run sudo eclipse (that will install plugins system-wide)
    2. Eclipse > Install new software > Add
    3. Name = "whatever"
    4. Location = http://subclipse.tigris.org/update_1.6.x
    5. OK
    6. Work with: "whatever"
    7. Select these to install :
      • CollabNet Merge Client
      • Subclipse
      • Subclipse Integration for Mylyn 3.x
      • Subversion Client Adapter
      • Subversion JavaHL Native Library Adapter
      • Subversion Revision Graph
    8. If you get a "Subversion 1.6 contains a bug that causes Eclipse to crash .... GNOME keyring ... we recommand ... ", choose OK.
  • Next install the Java bindings for SVN
    1. sudo apt-get install libsvn-java
    2. Eclipse > Window > Preferences > Team > SVN
    3. If that triggers a "Failed to load JavaHL Library." error, you need to add libsvnjavahl-1 in the Eclipse path :
    4. Just throw a symlink into one of the path in the error message :
    5. 1
      2
      3
      
               sudo ln -s /usr/lib/jni/libsvnjavahl-1.so /usr/lib/libsvnjavahl-1.so
               sudo ln -s /usr/lib/jni/libsvnjavahl-1.so.0.0.0 /usr/lib/libsvnjavahl-1.so.0.0.0
            
    6. Restart eclipse and step 3 should be solved.
  • Perhaps you want to use SVN with existing checkout project ?
    1. Right-click on your project in Eclipse
    2. Team > Share Project > svn > Validate Conneciton on Finish > Finish
  • Screenshots of what you can do with Subclipse
This article is part 2/2 of using QT Jambi within Eclipse. Click here to read the first part of this article, "Getting started with QT Jambi on Linux".

The present article you will learn how to design forms within eclipse and structure your QT code using the MVC pattern :

  1. File > New > Other > Qt Jambi Project (Using Designer Form)
  2. Name it JambiWeb
  3. Add a new QT Jambi Designer Form and ajust settings like on screenshot.
  4. This will create 3 files :
    FileDescription
    src/views/WebView.juiXML used by the Designer
    src/views/WebView.java This is the view from the MVC concept, it displays the widgets contained in Ui_WebView.java
    src/ui/views/Ui_WebView.javaJava file generated from the XML (you should not edit this file because it will be automatically replaced when you make changes to the form in the Designer). This file is more like a container for the widgets in the form, it does *not* displays the elements.
  5. Now in order to respect the MVC pattern, the view should not display itself, but rather we should have a controller to trigger the display of the view. Add WebController class in the controllers package and insert this code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    
    package controllers;
    
    import views.WebView;
    import com.trolltech.qt.gui.QApplication;
    
    public class WebController {
        private WebView webView;
    
        private Ui_WebView ui() { return webView.ui(); }
    
        public static void main(String[] args) {
            new WebController(args);
        }
      
        public WebController(String[] args) {
            QApplication.initialize(args);
    
            webView = new WebView(null);
            webView.show();
    
            initEvents();
            
            QApplication.exec();
        }
    
        private void initEvents() {
        }
    }
  6. Now delete the main() method in views/WebView.java, and the contents should be as follow:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    package views;
    
    import com.trolltech.qt.gui.*;
    
    public class WebView extends QMainWindow {
        private Ui_WebView ui = new Ui_WebView();
        
        public Ui_WebView ui() { return this.ui; }
    
        public WebView(QWidget parent) {
            super(parent);
            ui.setupUi(this);
    
            setWindowTitle("A custom browser for your application");
        }
    }
  7. Next let's design our interface
  8. Open on views/WebView.jui and choose the "QT Designer UI Perspective". This perspective should bring you a 3-tabbed panel on the right side of Eclipse view.
  9. So choose "QT Object Inspector" tab and right click on your QMainWindow item and choose "add toolbar".
  10. At the bottom of the screen, choose the "QT Action Editor" tab, and 2 actions (Reload, Stop), and drag & drop them unto the toolbar you are designing.
  11. Next choose "QT Widget Box" tab.
  12. Add a QWebView widget and name it "browser" (using QT Object Inspector tab)
  13. Add a QLineEdit widget anywhere in the window - we'll add it to the toolbar manually.
  14. Your view should be looking like this :
  15. Save WebView.jui and go back to the Java perspective to add these lines to views/WebView.java :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
        public WebView(QWidget parent) {
            // ...
            ui.toolBar.addWidget( ui.urlEdit );
            ui.toolBar.setFloatable(false);
            ui.toolBar.setMovable(false);
        }
    
       public Signal0 closed = new Signal0(); 
       
       @Override
        protected void closeEvent(QCloseEvent event) {
             this.closed.emit();
        }
  16. And let's add code to handle the events in controllers/WebController.java :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    
      private void initEvents() {
            ui().actionReload.triggered.connect(this, "onReloadClicked()");
            ui().actionStop.triggered.connect(this, "onStopClicked()");
        
            ui().urlEdit.returnPressed.connect(this, "onUrlEditReturnPressed()");
    
            ui().browser.loadStarted.connect(this, "onLoadStarted()");
            ui().browser.loadProgress.connect(this, "onLoadProgress(int)");
            ui().browser.loadFinished.connect(this, "onLoadDone()");
            ui().browser.urlChanged.connect(this, "onUrlChanged(QUrl)");
            
            webView.closed.connect(this, "onClosed()");
        }
      
      private void openURL() {
        String text = ui().urlEdit.text();
    
            if (text.indexOf("://") < 0)
                text = "http://" + text;
    
            ui().browser.load(new QUrl(text));
      }
      
      private void onReloadClicked() {
        ui().browser.reload();
      }
      
      private void onStopClicked() {
        ui().browser.stop();
      }
    
        private void onUrlEditReturnPressed() {
            openURL();
        }
    
        private void onUrlChanged(QUrl url) {
            ui().urlEdit.setText(url.toString());
        }
    
        private void onLoadStarted() {
            ui().statusbar.showMessage("Starting to load: " + ui().urlEdit.text());
        }
    
        private void onLoadDone() {
          ui().statusbar.showMessage("Loading done...");
        }
    
        private void onLoadProgress(int x) {
          ui().statusbar.showMessage("Loading: " + x + " %");
        }
        
        private void onClosed() {
          ui().browser.loadProgress.disconnect(this);
            ui().browser.loadFinished.disconnect(this);
        }
  17. In the code above you have an exemple of a custom signal (QT's observer/observable pattern). Here is how it works : when QMainWindow::closeEvent() is triggered by QT when the user closes the app, we then delegates the information to the WebController via the signal WebView::closed. For more details refer to QT Jambi article on signals & slots.
But wait a minute! Cool application use icons not text in the toolbar! Yes you can!
  1. Download these two images ( , ) and save them in a directory named "images" in your eclipse project.
  2. Next add your images directory in your classpath: Project > Properties > Java Build Path > Librairies > Add Class Folder = "images"
  3. Add set the icon manually in views/WebView.java :
    1
    2
    3
    4
    5
    
        public WebView(QWidget parent) {
            // ...
            ui.actionReload.setIcon(new QIcon("classpath:/refresh32.png"));
            ui.actionStop.setIcon(new QIcon("classpath:/stop32.png"));
        }
  4. Read on the QT Resource system to understand how this works.
Here you go! I hope this article will be usefull to someone!

Source code

final source code for this application

Credits

In this article I'll explain how to install QT Jambi and write your first Hello world program.
  1. Installation of QT Jambi SDK
  2. Quick Overview of the SDK
  3. Integration with Eclipse
  4. Your first Jambi Program
  5. Jambi Links

Installation of QT Jambi SDK

First, you need to download the "Qt Jambi - Java bindings Binaries" for your OS (about 100MB), get it from here. Since I am using Ubuntu, the following instructions will be for Linux. You can extract the archive where you want, but remember the path because we'll need it later on - I'll refer to ita s JAMBI_PATH (/usr/local/lib/qtjambi-linux32-lgpl-4.5.2_01 in this example).
1
2
tar -xzf qtjambi-linux32-lgpl-4.5.2_01.tar.gz
sudo mv qtjambi-linux32-lgpl-4.5.2_01 /usr/local/lib/
Next we need to create a script to get QT Designer to generate .jui files for Java (instead QT/C++ .ui files). Name it jambi-designer.sh and insert the following code:
1
2
3
4
  cd JAMBI_PATH
  export CLASSPATH=`pwd`/qtjambi-4.5.2_01.jar:`pwd`/qtjambi-examples-4.5.2_01.jar:`pwd`/qtjambi-linux32-gcc-4.5.2_01.jar
  export JAVADIR=/usr/lib/jvm/java-6-sun/jre
  ./designer.sh
Make it executable and make it available in your path. Copy also the juic (jambi user interface compiler) which is used to convert the files generated by the Designer to java code.
1
2
3
4
5
sudo chmod a+x jambi-designer.sh
sudo ln -s /JAMBI_PATH/jambi-designer.sh  /usr/local/bin/jambi-designer
cp bin/juic /usr/local/bin/
# try it :
jambi-designer  &

Quick Overview of the SDK

So here you go you got the SDK installed. Now what are these files, do i need to install this huge file on every computer my program will run unto?? Obviously not!

Well here, you to remember that when you'll distribute your application, you'll need to bundle it with the Jambi core package (qtjambi-4.5.2_01.jar) and the jambi os-dependant package (qtjambi-linux32-gcc-4.5.2_01.jar). That's it!

If you want the application to run on Windows as well, you only need to add one jar file per os (you'll need to download the whole sdk just to get the .jar your need for each os).

What else am I getting?
Directory / fileDetails
bin/Designer and UI Compiler binaries
com/trolltech/Jambi Core & Examples Source code
doc/Jambi HTML Documentation (use your browser)
qtjambi.shExecute this script to view the numeros code samples


Integration with Eclipse

So you want code auto-completion for Jambi classes in Eclipse? You're dreaming! Nope, actually you can! Just download the "eclipse integration package" and extract it in the plugin directory of your Eclipse installation.

Note : I haven't been able to install the integration plugin with default Eclipse package in Kubuntu 9.10 because it does not allow you to add plugins as root. So to get around this, just uninstall it from the package manager and install it manually (get eclipse here).
1
2
3
4
5
tar -xzf eclipse-java-galileo-SR1-linux-gtk.tar.gz
sudo mv eclipse /opt/eclipse-3.5.1
cd /opt/eclipse-3.5.1
sudo tar -xzf /path/to/qtjambi-eclipse-integration-linux32-4.5.2_01.tar.gz
./eclipse -clean
Next on Eclipse restart, go to Window > Preferences > QT Jambi Preference Page and use these settings :
  • Jambi Location = where you installed the first archive (JAMBI_PATH)
  • Generate files in separate folder = src/ui

Your first Jambi Program

  1. Click on File > New > Other > QT Jambi Project.
  2. Add a new class named "HelloWorld" and insert this code:
  3. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    import com.trolltech.qt.gui.*;
    
    public class HelloWorld extends QWidget{
    
        public static void main(String[] args) {
            // Instanciates a Jambi Application and pass it the command-line arguments to allow the QApplication
            // static instance to handle the arguments it recognizes, such as -font and -style.
            QApplication.initialize(args);
    
            // Creates an instance of our QWidget (could be also a QMainWindow, QDialog, etc.)
            // and set the parent to null
            HelloWorld helloWorld = new HelloWorld(null);
            
            // Create a new label and sets its parent to our view.
            QLabel label = new QLabel("Ping World!", helloWorld);
            
            // Show our view
            helloWorld.show();
    
            // Execute Jambi Application
            QApplication.exec();
        }
    
        public HelloWorld(QWidget parent){
            super(parent);
        }
    }
    

Jambi Links

MS SQL Server 2008 with PHP

February 18th, 2009

I personally choose not to use Micro$oft products when it is possible, but sometimes the choice is not given. For these unfortunate who have to deal with SQL Server 2008 (or 2005), here is how to get around without too many swear words and avoid licensing costs.

Requirements

  • Windows Vista (Win XP should do also)
  • .Net Framework 3.5 SP1
  • Windows Installer 4.5
  • Windows PowerShell 1.0
  • MS Core XML Services (MSXML) 6.0
Note: You need to have genuine windows copy to download PowerShell from Microsoft website; however it is possible to find it elsewhere if you google around.

Setup SQL Server

  1. Download and install MS SQL Server Express 2008 with Advanced Services and choose the following options:
  2. Single instance Install (not clustered !)
  3. Name the instance "SQLExpress"
  4. In the options box choose "SQL Server", and "Management Studio" (do not install full-text search, as it requires clustering)
  5. Set the Server Service Account Name to "NT AUTHORITY\NETWORK SERVICE", auto
  6. Set the SQL Server Browser to "NT AUTHORITY\NETWORK SERVICE", manual
  7. Choose mixed mode authentication
  8. Set SQL Server to listen on TCP port.
    1. Start "SQL Server Configuration Manager"
    2. Network Configuration -> Protocols : enable "Named Pipes" and "TCP/IP"
    3. Right-click "TCP/IP" -> Listen All = Yes"
    4. In tab "IP addresses" -> Section IPAll -> TCP Dynamic Ports = 1433
    5. Repeat these steps for SQL Native Client.
    6. Restart SQL Server
  9. Create your database and set the owner to user 'sa', and change the user sa password.

Setup PHP

This assumes you have wamp installed, otherwise just change the path.
  1. Download the good version of ntwdblib.dll (2000.80.194.0)
  2. Overwrite C:\wamp\bin\apache\apache2.2.8\bin\ntwdblib.dll
  3. Overwrite C:\wamp\bin\php\php5.2.6\ntwdblib.dll
  4. Enable php_mssql.dll in php.ini
  5. Restart Apache
  6. $server = 'BANGKOK\SQLEXPRESS';  // The format is "HOST\SERVERNAME[,PORT]"
    $username = 'sa';
    mssql_connect($server, $username, $password);
    

Debugging

  • You can test if SQL Server is listening on port 1433 by using NMap/Zenmap for Windows to do an "Intense scan, all TCP ports" on localhost, and you should see port 1433 open.
  • When trying to log within PHP you should see an entry in the log file:
    c:\program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Log\ERRORLOG
I hope this will save you some time and swears!

Introduction

I could not find an updated documentation on how to setup properly a rails application on Dreamhost, so I thought I'd share the information I gathered.. First off, thanks to the Phusion team, with Passenger (a.k.a. mod_rails), it's now very convenient, easy, and cheap to run a rails application on Dreamhost.

Also, special thanks to Todd Huss for discovering the multi dreamhost user hack. Basically, you need to run each of your rails application on Dreamhost under a different shell user. Their process monitor, will start killing your processes when the total memory per user exceeds 200 MB of virtual memory (VSZ).

So here's the guide, even perfect newbees and skript-kiddies should be able to follow :

The complete step by step

INFO : Let Capistrano create the directory structure on the server BEFORE you set the public dir of your application in the edit domain section of the Control Panel. This will avoid you conflicts when Capistrano attemps to create the symlinks.

  1. First, configure your new rails application using Dreamhost Control Panel :

    1. Create a new repository for your application (screenshot)

    2. Create a new shell / SSH user (read why here) with the same name as your application (screenshot)

    3. Create a new database (screenshot)

  2. Add your application to your repository
    1. Create your rails skeleton (if it's done yet), on your local machine (assuming you use *nix, but should be similar on Windows)
      
      
      $ rails myrailsapp --freeze
    2. Add your application to the repository
      1
      2
      3
      4
      5
      
      $ cd myrailsapp
      $ svn mkdir http://svn.myrailsappdomain/myrails/trunk
      $ svn checkout http://svn.myrailsappdomain/myrails/trunk ./
      $ svn add  *
      $ svn commit
    3. Exclude database configuration, temporary files, and any user upload directory from the source control :
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      
      $ svn copy config/database.yml config/database.yml.example
      $ svn remove config/database.yml -f
      $ svn propset svn:ignore "database.yml" config/
      $ svn remove tmp/*
      $ svn propset svn:ignore "*" tmp/
      # If you need to share unversionned user-uploaded files, between deploys :
      $ mkdir public/uploads
      $ svn add public/uploads
      $ svn propset svn:ignore "*" public/uploads/
      $ svn remove log/*
      $ svn propset svn:ignore "*" log/
      $ svn remove db/*.sqlite3
      $ svn propset svn:ignore "*.sqlite3" db/
      $ svn commit
  3. Next, create the Capistrano recipe :
    1. Create recipe skeleton :
      1
      2
      3
      4
      5
      
      $ cd /path/to/your/myrailsapp
      $ capify .
      [add] writing `./Capfile'
      [add] writing `./config/deploy.rb'
      [done] capified!
    2. Replace the content of config/deploy.rb with the following :
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      
      #############################################################
      ## General
      #############################################################
      set :application, "myrailsapp"
      
      
      #############################################################
      ## Servers 
      #############################################################
      set :use_sudo, false    # Dreamhost does not support sudo
      set :user, application  # Dreamhost SSH User
      set :domain, "myrailsapp.domain.com"
      
      server domain, :app, :web
      role :db, domain, :primary => true
      
      
      #############################################################
      ## Subversion
      #############################################################
      set :scm, :subversion
      set :scm_user, application   # Sets 'my_svn_user' instead, if you are using different name than your app.
      set :scm_auth_cache, true  # Prompts for password once
      set :scm_password, Proc.new { Capistrano::CLI.password_prompt("SCM password for #{scm_user}:") }
      set :repository,  "http://svn.myrailsappdomain/#{application}/trunk"
      set :deploy_to, "/home/#{user}/#{domain}"
      # keeps a local checkout of the repository on the server to get faster deployments
      set :deploy_via, :remote_cache
      
      
      #############################################################
      ## Tasks
      #############################################################
      
      namespace :deploy do
        desc "Restart Application (using tmp/restart.txt)"
        task :restart_passenger do
          run "touch #{current_path}/tmp/restart.txt"
        end
      
        desc "Restarts your application."
        task :restart do
          restart_passenger
        end
      
        desc "Link shared files"
        #task :before_symlink do
        before :symlink do
          run "rm -drf #{release_path}/public/uploads"
          run "ln -s #{shared_path}/uploads #{release_path}/public/uploads"
          run "rm -f #{release_path}/config/database.yml"
          run "ln -s #{shared_path}/database.yml #{release_path}/config/database.yml"
        end
      end
  4. Then, prepare the directory structure on the server :
    1. Create the Capistrano structure (releases/, shared/), by typing this on your local machine :
      
      
      $ cap deploy:setup
    2. Login to your server to manually create your shared directories and files (if any)
      1
      2
      
      $ ssh myrailsapp.domain.com
      [tootsie]$ cd myrailsapp/shared
    3. Configure your database on the server (you don't want this file in your repository) :
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      
      # config/database.yml
      
      development:
        adapter: sqlite3
        database: db/development.sqlite3
        timeout: 5000
      
      test:
        adapter: sqlite3
        database: db/test.sqlite3
        timeout: 5000
      
      production:
        adapter: mysql
        encoding: utf8
        database: myrailsapp
        username: myrailsapp
        password: [your_db_password]
        host: mysql.[myrailsapp.domain].com
        timeout: 5000
    4. Create your upload directory (OPTIONAL) :
      
      
      [tootsie]$ mkdir uploads
  5. Deploy your application. Note : it will only prompt for your SVN password at the first deploy.
    
    
    $ cap deploy
  6. And finally the most important, configure your domain like this :

[UPDATE 2008/07/01]

If you need to install custom gems on your account, you can find more info here, here and here.

References

  1. http://labs.peritor.com/webistrano/wiki/ConfigurationParameter
  2. http://groups.google.ca/group/capistrano/browse_thread/thread/6ef7c7c212547eab (for scm_password)
  3. http://groups.google.com/group/capistrano/browse_thread/thread/ae7b16a16abf4e5d (for task hookups with namespaces)
  4. http://groups.google.com/group/capistrano/web/deploying-on-dreamhost
  5. http://gabrito.com/post/ruby-on-rails-dreamhost-plugin
  6. http://www.railsforum.com/viewtopic.php?id=8118
  7. Dreamhost Wiki : Capistrano
  8. Dreamhost Wiki : Ruby_on_Rails
  9. Capistrano Manual

Hello !

June 2nd, 2008

I am David Lauzon, a freelance web developer since February 2005. I am usually based in Montréal (QC, Canada), but I will be blogging from Chiang Mai (Thailand) for the following months.

I will be writing about Ruby on Rails, Web 2.0, Linux, and general IT developments. I also will be releasing open source code here, so stay tuned !