Archive for the ‘Development’ Category

Firefox 4.0 pre-beta released

Sunday, July 4th, 2010

Lifehacker shown a screenshot of the new Firefox 4.0 pre-beta for Windows. Here it is (Mozilla names Firefox beta versions “Minefield”):

Nice, isn’t it? So, I downloaded the new beta for Linux, and it looks like the screenshot below. I had to set the tabs to be on top; Windows version brings this for default (at least the one that I installed using Wine).

Firefox 4.0 pre-beta on Linux

Compare. The screenshot below is Firefox 3.6.4.

Firefox 3.6.4 on Linux

It’s a little far from the mockups of Firefox for Linux at Mozilla’s site. I hope I can see it soon. :)

VolumeSlider’s tooltip misbehaviour

Tuesday, June 29th, 2010

I was developing a Qt application that makes use of a Phonon::VolumeSlider object. But after clicking the mute button beside of the VolumeSlider and verifying its tooltip, I noticed it was showing the wrong volume. A video can explain this better than me:

If you want to reproduce this problem, you can download its source code as a Qt Creator project. Please keep in mind that it’s the source code with errors!  But there’s a workaround to this problem:

1. In the class where you create the Phonon::AudioOutput whose volume is handled by the VolumeSlider, put this:

connect(audioOutput, SIGNAL(mutedChanged(bool)), this, SLOT(handleMute(bool)));
connect(audioOutput, SIGNAL(volumeChanged(qreal)), this, SLOT(handleVolume(qreal)));

2. Create the slots you used above using the following code:

void MainWindow::handleMute(bool mute) {
    if (!mute) {
        audioOutput->setVolume(outputVolume);
    }
}
void MainWindow::handleVolume(qreal volume) {
    outputVolume = volume;
}

3. Declare the slots and the outputVolume variable in your header file:

private:
    qreal outputVolume;

private slots:
    void handleMute(bool mute);
    void handleVolume(qreal volume);

You can download the fixed source code. I don’t know if this behaviour is the expected in Qt, but I filed a bug for it.

Fixing problem with Subclipse and svn+ssh repositories

Thursday, May 27th, 2010

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

Thursday, May 20th, 2010

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:

<?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>

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

Monaco after fix

Why I chose Qt

Thursday, May 13th, 2010

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

Saturday, April 24th, 2010

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

Monday, April 19th, 2010

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

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:textSize="20px"/>

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

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:textSize="20px"
    android:singleLine="true"/>

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

<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"/>

O resultado é este:

Cheat sheets do git

Thursday, March 25th, 2010

Cheat sheets são as melhores amigas de quem precisa fazer tarefas repetitivas no computador mas não quer perder tempo olhando o tempo todo pra guias de consulta rápida. Pra quem gosta do git (mais pessoas deveriam gostar do git…), aqui vão duas cheat sheets ótimas.

A primeira, de apenas uma folha mas bastante útil, está disponível no site do autor da mesmano próprio wiki do git. Ela traz um fluxo de uso do git que pode ser muito útil, que mostra quais passos você efetuar a cada comando do git executado:

A segunda, de duas folhas, também traz um fluxo. Na primeira página traz explicações gerais sobre git e na segunda os comandos que você precisa: