Fixing problem with Subclipse and svn+ssh repositories

I was trying to synchronise a Java project with a SVN repository that runs over a SSH tunnel. It was working right in the command line, but in Subclipse it was showing a “network connection closed unexpectedly” error.

It was fixed changing the SVN interface from JavaHL to SVNKit in Eclipse preferences (click to zoom):

Changing SVN interface in Eclipse

How to fix ugly fonts in Qt-based applications

I was using Qt Creator and tried to change the editor’s font to Monaco, 9. But hey, Monaco is not that ugly:

Monaco before fix

So I googled a way to fix for this problem, and found the fix at Arch Linux forums. You’ll need to create a file called .fonts.conf in your home directory with this content:

[sourcecode language=”xml”]
<?xml version=’1.0′?>
<!DOCTYPE fontconfig SYSTEM ‘fonts.dtd’>
<fontconfig>
<match target="font" >
<edit mode="assign" name="rgba" >
<const>rgb</const>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="hinting" >
<bool>true</bool>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="hintstyle" >
<const>hintslight</const>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="antialias" >
<bool>true</bool>
</edit>
</match>
</fontconfig>
[/sourcecode]

I closed Qt Creator and reopened it. The result was this:

Monaco after fix

Why I chose Qt

A few months ago, I planned to learn some graphic toolkit. As a GNOME user, GTK was my natural choice. Although I’m a Python lover, I chose C++ because I just wanted to learn a new language and stop being afraid of pointers. So I started to read the gtkmm documentation, like tutorials and API, and to program a simple music player. I was learning gtkmm and it all seemed okay.

But I read a little about Qt and, after talking with some friends about the pros and cons of GTK and Qt, I decided to do with Qt the same things that I’ve already done with GTK up to that point. So I would know what choice was better for me. Notice that I’m not saying that Qt is better for everybody and that GTK must die, but that Qt looked better for me and my personal project. After this disclaimer, and can tell my reasons:

  • Look & feel. I’m a look&feel fanatic, and sometimes I move from GNOME to KDE only to check its new features. But I hate how GTK applications look in KDE. You can use gtk-qt-engine, but you’ll still notice the differences. You can set GTK to use the excellent QtCurve theme, that have identical versions to Qt and GTK, but you’ll get tied to a theme. But look what you have if you run a Qt application in GNOME (gedit is a GTK-based application and Picard is a Qt-based application):

    Thanks to QGtkStyle, Qt applications detect if you are in GNOME and your Qt application gets an almost perfect GTK look & feel. And yeah, it includes open and save dialogs.
  • Documentation. Qt has a very, very rich and well-organised documentation, with tutorials, API references, and examples. gtkmm also have all these items, but they didn’t look very friendly to me. And the documentation of Qt 4.7, still in development, will be even better.
  • A simple, but good IDE. A good programmer must not be dependent on IDEs, but they really help you. I tried to use Anjuta (unstable sometimes), MonoDevelop (very good for .NET platform, but not a good IDE for C/C++ development) and Netbeans as IDE when I was using gtkmm, and I was not satisfied with them. But Qt has its official IDE, Qt Creator:

    Qt Creator is clean, simple, and complete. It has quick access to documentation, breakpoints, project configuration, native support for CVS, Subversion and Git, good code completion, a good GUI designer (like the GTK’s Glade), among other features.
  • Runs well on many platforms. Qt is smart enough to run well – and with native look & feel, I really like this – in Linux, Mac, Windows, and others.

But Qt still has some cons:

  • Users should have it installed to run Qt applications, and this is not very usual in Linux environments based on GNOME, neither on Windows systems.
  • Qt is free only if you’re using it in a free project. For commercial applications, you must obtain a commercial Qt licenceUpdate: this is not exactly a con. You still can use Qt under LGPL in commercial applications, but if you make any change to Qt you must publish them or purchase a commercial Qt licence (thanks, krok, for the comment).

If you’re beginning to learn to program for graphical environments or you’re looking for a good graphical library to use in your project, you really should give Qt a try, implement some examples and feel which option is better for you.


Conectando o PHP ao Oracle

Nota: fiz esse tutorial há 3 anos, não garanto que ele continue funcionando!

Depois de muito apanhar, aprendi uma maneira fácil de pôr o PHP pra se comunicar com o Oracle. A maioria das soluções que achei envolvia recompilar o PHP, mudar variáveis de ambiente, scripts de inicialização etc. Uma delas até deu certo, mas mudar as variáveis de ambiente fez o suporte a LDAP do PHP parar de funcionar, por razões que desconheço.

A solução que explico abaixo faz a mesma coisa, mas sem recompilar pacotes ou fazer gambiarras. Deu certo milagrosamente, após juntar a solução proposta por vários sites. O máximo que será feito é compilar a extensão oci8 para o PHP do Debian ou Ubuntu, que é feito automaticamente e em poucos segundos. A parte chata é baixar os arquivos do site do Oracle, que exige criação de conta.

Todos os comandos abaixo são executados como root. Boa sorte! 🙂

  1. No site de downloads do Oracle para Linux, baixe os arquivos instantclient-basic-linux32-10.2.0.3-20061115.zipinstantclient-sdk-linux32-10.2.0.3-20061115.zip. Você vai precisar criar uma conta no site da Oracle para isso. Após o download, extraia-os para o diretório /usr/local/oracle.
  2. Em /usr/local/oracle, crie o seguinte link: # ln -s libclntsh.so.10.1 libclntsh.so
  3. Instale os pacotes php5-devphp5-pear pelo apt-get ou aptitude (aptitude install php5-dev php5-pear). Caso não exista o php5-pear, procure por php-pear.
  4. Agora execute (lembre-se: sempre como root): # pecl install oci8
  5. Surgirá um prompt perguntando onde estão as bibliotecas do Oracle. Sua resposta será instantclient,/usr/local/oracle , como no exemplo:Please provide the path to ORACLE_HOME dir. Use ”instantclient,/path/to/instant/client/lib” if you”re compiling against Oracle Instant Client [autodetect] : instantclient,/usr/local/oracle
  6. No diretório /etc/php5/conf.d , crie um arquivo oci8.ini, com o seguinte conteúdo:extension=oci8.so
  7. O PHP deverá estar com suporte a Oracle (extensão oci8). Reinicie o seu servidor web (caso seja o Apache, apache2ctl restart).

Fontes: Installing PHP and the Oracle 10g Instant Client for Linux and WindowsHow to: Installing Oracle XE on Ubuntu with PHP

Cortando strings muito longas no Android

Eu estava fazendo uma aplicação para Android quando me deparei com um problema: cortar strings muito longas. Um bom exemplo é a string da figura aí de baixo.

Essa é a string na qual vamos nos basear. Ela é gerada pelo código

[sourcecode language=”xml”]<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="20px"/>[/sourcecode]

Há duas maneiras de corrigir o problema. Uma delas é o seguinte código:

[sourcecode language=”xml”]<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="20px"
android:singleLine="true"/>[/sourcecode]

Porém, a diretiva android:singleLine é descrita na IDE como em desuso (deprecated). Um código que surte o mesmo efeito é

[sourcecode language=”xml”]<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="22px"
android:ellipsize="end"
android:scrollHorizontally="true"
android:lines="1"/>[/sourcecode]

O resultado é este: