Saturday, December 29, 2007

Adding a menu to KMainWindow programmatically

First of all, let me stress that I'm not an experienced KDE programmer: my only KDE application, for now, is SourceHighlightIDE, a sort of IDE for developing GNU Source-highlight language definition files. While I was adding new features to this program, for the next release, I wanted to add the typical "Window" menu that permits tile all the windows in the workspace or cascade them, or selecting a specific window (SourceHighlightIDE is a MDI application). I then simply added this code to the KMainWindow subclass:


windowsMenu = new KPopupMenu( this );
connect( windowsMenu, SIGNAL( aboutToShow() ),
this, SLOT( windowsMenuAboutToShow() ) );
menuBar()->activateItemAt(-1); //needed as insertItem might crash if a menu is activated

// position: 2, means the third menu (the fourth one is Help)
menuBar()->insertItem( "&Window", windowsMenu, -1, 2);

However, the "Window" menu was never added to the application.

Actually, I know that one should add additional menus to the .rc file, e.g.,
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="sourcehighlightide" version="1">
<MenuBar>
<Menu name="custom"><text>C&amp;ustom</text>
<Action name="custom_action" />
</Menu>
</MenuBar>
</kpartgui>

but I wanted a way to add the menu programmaticaly, so that I would not depend on the .rc file that must be installed.

Actually, the code added by me above works, but you must make sure to execute it after the call to setupGUI().

Hope this saves some headache to others wanting the same thing :-)

Saturday, December 15, 2007

doublecpp (dynamic overloading in C++)

Doublecpp is a preprocessor for C++ that handles a new linguistic construct for defining branches of a multi-method. The "right'' branch of such a method will be selected dynamically at run-time according to the actual type of the object on which the method is invoked and to the actual type of the first argument: double dispatch.

This way, you will have dynamic overloading (but only on the first argument, for the other arguments standard static overloading will be adopted).

The home page of the project is http://doublecpp.sourceforge.net. And the documentation can be found on-line at this link.

Doublecpp is based on our research on formalization and implementation of dynamic overloading in languages providing only static overloading. In particular, doublecpp will take as input a program written in C++ extended with the linguistic construct for dynamic overloading and will produce in output a standard C++ program with the same semantics.

The idea of the translation is based on the Visitor pattern, but it does not require the programmer to manually implement such pattern; furthermore, it performs all the type checks to assure type safety; thus, it is not merely an automatic implementation of this pattern.

Such implementation avoids down-casts and it is efficient since it uses dynamic binding twice, i.e., dynamic overloading takes place in constant time (other implementations rely on RTTI checks and require to inspect the class hierarchy, thus their complexity depends on the depth and width of the class hierarchy).

More importantly, our implementation of dynamic overloading is type safe: once the program is successfully compiled, no run-time errors (exceptions) will be raised during the execution of the program. Thus, all possible (static and dynamic) ambiguities are ruled out during the type checking.

The papers concerning this research are the following:

Translating Double-Dispatch into Single-Dispatch
Lorenzo Bettini, Sara Capecchi, Betti Venneri.
Proceedings of the Second Workshop on Object Oriented Developments (WOOD 2004). pp. 59-78. ENTCS vol. 138 no. 2. Elsevier. 2005. abstract doubledisp.pdf bibtex
Double Dispatch in C++
Lorenzo Bettini, Sara Capecchi, Betti Venneri.
Software - Practice and Experience. pp. 581 - 613. vol. 36 no. 6. 2006. abstract spelxb.ps.gz bibtex

Tuesday, November 20, 2007

Problems in restoring Palm

It's not the first time I forgot to recharge my Palm Tungsten E for a long time; usually I manage to recharge it before it's too late, but this time I actually left my palm on (with the gps application running) so it definitely exhausted all its charge and so it went dead.

So I had to restore it, and, in order to avoid reinstalling all the applications, before performing the first synchronization, I had set the synchronization program to overwrite everything on the palm using the backup on my PC, in particular, the application database.

It went fine, but when I restarted the palm (it was required by the synchronization process) I got the scary error message:

DataMgr.c, Line:xxxx, Index out of range

I don't remember the actual line, but this is quite a typical error message, that requires a reset (the palm does not even switch off).

Fortunately, as I said, this error is quite typical, and you find on google with many results. I was lucky enough to find this post on a forum, and the situation looked quite similar to mine.

The problem seems to be caused by the Saved_Preferences.prc file; so, I removed it from the backup folder on my PC, and tried to perform synchronization again (with the above settings, saying to replace all the applications from the backup of my PC into the palm).

It worked! :-)

Of course, my preferences were lost, but at least my palm was up and running again.

Hope I won't have to reinstall the applications again (at least not until the next time I'll forget to recharge the palm ;-)

Monday, October 29, 2007

Thunderbird won't open http links

Sometimes, in Linux, after an update or a brand new install, Thunderbird won't open http links (e.g., with Firefox). This might depend on some default configuration value of your distribution.

However, the quickest, and, as far as I know, distribution independent solution, is to manually set these preferences in the prefs.js file:

user_pref("network.protocol-handler.app.ftp", "firefox");
user_pref("network.protocol-handler.app.http", "firefox");
user_pref("network.protocol-handler.app.https", "firefox");
where "firefox" can be replaced with your preferred browser.

Alternatively, you might set these settings with the config editor available from the "advanced" tab. You'll probably need to create new entries for these preferences (of type string).

Hope this helps, at least until the problem is fixed in your distribution :-)

Wednesday, October 17, 2007

Wifi-radar and WPA

Under my Debian installation I'm using Wifi-radar, a nice utility for managing wireless networks (although it is a GNOME application, I'm using it under KDE without problems). I've always used for WEP networks, but now I needed to start using also for WPA networks, and in order to deal with such networks, wifi-radar relies on wpa-supplicant, which is also available for Debian.

Thus, you need to setup the configuration file of wpa-supplicant so that wifi-radar can use it (thus, you cannot set WPA parameters from within wifi-radar), but this is not hard to do; for instance, in wpa_supplicant.conf you can put such a stanza:

network={
ssid="network ssid"
key_mgmt=WPA-PSK
proto=WPA
psk="network password"
}
and then you can specify the driver for your card in the "WPA" section of the wifi-radar's configuration dialog (for instance, for my ipw2200 wireless card, I chose wext).

Unfortunately, if you try this way, you'll get an error from wifi-radar due to an undefined variable:

NameError: global name 'WPA_SUPPLICANT_ARGS' is not defined

to solve this problem, I actually modified the wifi-radar script (it's a python script) by changing the line:

wpa_args = WPA_SUPPLICANT_ARGS % ( INTERFACE, profile['wpa_driver'] )

with

wpa_args = "-B -i " + INTERFACE + " -c " + WPA_SUPPLICANT_CONF + " -D " + profile['wpa_driver'] + " -P " + WPA_SUPPLICANT_PIDFILE

and now it seems to work correctly.

Saturday, October 06, 2007

Firmware upgrade for router D-Link DSL-G604T

I've been using this ADSL wireless router, D-LINK DSL-G604T, for almost one year now and I was quite happy with it, unless I discovered that the wireless connection provided by this router was not very good: my ADSL is 4Mb (and indeed with the wired connection I was reaching the full speed, ~500K) but with the wireless connection I was hardly reaching 100K speed, so the wireless connection was pretty slow.

I also tried with some wireless settings of the router (also using WEP and WPA) but nothing was changing (and the wireless embedded card in my laptop is actually OK since I was reaching very high speed with other wireless networks).

I checked the D-Link home site only to discover that this router is not maintained any more (discontinued product) and indeed I couldn't find any updates for it. However, by googling I found this site that was referring to a D-Link site which still provides some information and software about this router: http://www.dlink.com.au/tech. In particular, here I found a quite new firmware version for my router revision (A): V2.00B12.AU 20070509.


I was quite skeptical in trying to update the firmware (the last I had tried this procedure I ruined my previous Atlantic router), furthermore, the firmware in this site is Australian and in the readme file you read that this was tested only for Australian router... However, since the router was not working perfectly for me I decided to have a try: if the router was ruined I was willing to buy a new one :-)

Since my firmware version was 1.x and I was updating to version 2.x, as reported in the documentation in that site, I could not use the web update procedure, but I should use the EXE version, so I downloaded this zip file, which contains the .exe program to update the firmware.

Then I followed this procedure (using instructions found on that site and some instructions found on some other forums):

  1. Factory reset of the router (using the button on the back, pressed for at least 10 seconds)
  2. Connect my computer directly to the router and remove all the other computers from the router
  3. Disable antivirus and firewall on my computer
  4. Give a static IP address to my computer in the range 192.168.1.x (the IP and subnet mask depends on the current firmware in your router; for instance, the site states that the router address is 10.1.1.1, subnet mask 255.0.0.0, but my router has the default IP address 192.168.1.1, subnet 255.255.255.0)
  5. Run the exe program and specify the IP address of the router, 192.168.1.1, and the admin password (which is admin, since it was reset to the default settings)
  6. I did not choose the "corrupted image" checkbox (although it was suggested on some forums)
The upgrade of the firmware started and correctly concluded.

At this point the new firmware is on and the router is still working! :-)

Now the router has to be configured from the start. Since the new firmware is Australian, the default IP of the router is 10.1.1.1 (subnet 255.0.0.0), so I had to configure my computer accordingly in order to access the web interface of the router and perform the configuration (first of all I switched back to the local network 192.168.1.x).

Guess what: the wireless network now works perfectly and at full speed! :-)

With this firmware the router should also support ADSL 2, but I can't confirm this since I still have ADSL 1.

There are some new menus which I still have to go through. However, one thing that changed is that you cannot save the new configuration without rebooting, which was a nice previous feature (at least, I wasn't able to find a way to).

Monday, October 01, 2007

Researcher in Turin

It's with great pleasure that I can announce that today I started to work as a Researcher (in Computer Science) at Dipartimento di Informatica, University of Turin! On 20th September 2007 I won the permanent position, and I'm very happy and proud to work in this department :-)