Linux The Road to KDE and Qt Development

vishalrao

Global Moral Police
Level J
This thread is inspired by some recent news, blog posts and other thread posts here on TE. Lets collect links/snippets to information, tips, tutorials, stories etc. for development on the KDE and Qt platforms. For full blown reviews, tutorials etc. there'll be separate threads of course.

klogoofficialoxygen128x.png
..................
qtlogo.png

Some links/blogs/posts/news to start off:

Nokia acquires Trolltech (developers of Qt) and renames them to Qt Software and releases the Qt toolkit under new licenses like the LGPL: About us - Qt - A cross-platform application and UI framework

The KDE 4 discussion thread: http://www.techenclave.com/open-source-and-linux/kde-4-x-discussion-thread-135756.html

My first little KDE development excursion:

You gotta love Free software | veracity

You gotta love Free software cogito ergo vagus

http://www.techenclave.com/open-source-and-linux/why-you-gotta-love-free-software-132700.html

Some blog posts:

The Road to KDE Devland – step 0 Who Says Penguins Can’t Fly?

The Road to KDE Devland – step 1 Who Says Penguins Can’t Fly?

The Road to KDE Devland ? step 2 Who Says Penguins Can’t Fly?

And finally, one of the main links to get started off with: KDE TechBase and tutorials at: http://techbase.kde.org/Development/Tutorials

This thread and main post can be updated with some of the more interesting posts/links in the future...
 
Hey Darky, can you add a little spacing between the two logos? I put in ellipses (...) to try to space them. Also, is this thread worthy of being stickied?

I know you are also interested in KDE/Qt development so do post any interesting short links/blogs/info... for detailed stuff you can do your own posts for reviews/tutorials etc.

So, on my side I had posted a brainstorm idea in the KDE forum requesting there should be a right-click utility menu in Dolphin for files which will do MD5/SHA1/SHA256 checksum of files so no need to do it in the command prompt or download separate programs like you need to in Windows: [File-Manager] Checksum tools on right-click menu - KDE Community Forums

It turns out we have "service menus" which you can write your own, so I am going to try a quick and simple solution now and post back. I got following links while searching for info:

Development/Tutorials/Creating Konqueror Service Menus - KDE TechBase

Service Menu Manager KDE-Apps.org

So I'll be trying it now... (wont cheat by using the service menu manager app!) :)
 
Thanks for stickying it (whoever did it) and spacing it with white dots haha :ohyeah:

So! A quick solution for the checksum right-click menu:

Code:
[Desktop Entry]

Type=Service

Icon=security-high

Actions=ShowMD5Hash;ShowSHA1Hash;ShowSHA256Hash

ServiceTypes=KonqPopupMenu/Plugin

MimeType=all/allfiles

[Desktop Action ShowMD5Hash]

Exec=md5sum %U | xargs kdialog --title "MD5 hash" --msgbox

Icon=security-high

Name=Show MD5 hash

[Desktop Action ShowSHA1Hash]

Exec=sha1sum %U | xargs kdialog --title "SHA1 hash" --msgbox

Icon=security-high

Name=Show SHA1 hash

[Desktop Action ShowSHA256Hash]

Exec=sha256sum %U | xargs kdialog --title "SHA256 hash" --msgbox

Icon=security-high

Name=Show SHA256 hash

  1. Put that in a file called, say, checksum.desktop.
  2. Run "kde4-config --path services" to find out the location to place it.
  3. Usually one path is per user (yours) and other is for all users.
  4. Create a "ServiceMenus" subfolder under your chosen location.
  5. For me it was "/home/myusername/.kde4/share/kde4/services/ServiceMenus"
  6. Copy the file there and the right-click menu should start working.
  7. If not you might need to log out and log back in, or even restart KDE.

Some mistakes I made along the way which caused it not to work at first:

  1. I used commas instead of semicolons for the Actions list.
  2. Specified mime type as application/octet-stream instead of all/all-files.
  3. Did not create the "ServiceMenus" subfolder and copied the file to the main "services" folder.

TODO:

I have to get better at shell scripting etc. so that I can improve the dialog box to display the filename and the checksum on separate lines. Then I need to figure out a quick and simple way (without writing too much code/scripts) to actually verify a checksum instead of just displaying it, right now I manually check the first few and last few digits with the actual checksum to see if the file is okay :)

Please do suggest improvements...

edit: added screenshot:
 

Attachments

  • checksum-clipped.jpg
    checksum-clipped.jpg
    74 KB · Views: 212
^^OMG ! Thats awesome :O

I am still finding my way through QT :P This thread would be a savior for me :P

Any tutorials for detailed start up with QT IDE ? I am stuck with it. All I learnt is GUI interface designer :P After that I haven't played much :..
 
Thanks! :ohyeah: I changed the icon from boring "dolphin" to "security-high" for better look. One minor issue is that if you run the action on a large file (like a 700mb iso) then it appears like nothing is happening until the dialog appears after some time, so gotta figure out how to include a progress "please wait" dialog in there...

I'm sure there are tutorials for KDE and Qt development out there of course (including the techbase link), sadly till now I've just been casually browsing the APIs etc. and haven't tried any development myself. Will try plain Qt and also KDE development using the standard/recommended tools. I think KDevelop is one, not sure what is the recommended one for Qt... this weekend is over, so will return to some self learning next weekend, and hopefully I can maintain the enthu to continue every weekend!

PS: Gotta learn Python too like you are doing since that is also very popular these days heh.
 
Improvements to the checksum tool to add 2 new features: Actually try to verify the file integrity by searching for stored checksum files and also display a progress dialog (throbber) while the checksum is being verified so you know something is happening :)

Copy the following code as root/sudo into a script file, say checkhash.sh, into /usr/bin after making it executable.

Code:
#! /bin/sh

toolname=`echo $1 | sed "s/\(.*\)/\L\1sum/"`

filepath=`echo $2 | sed "s/\(.*\/\).*/\1/"`

hashfile=`echo $1 | sed "s/\(.*\)/\U\1SUMS/"`

dialogtitle=`echo $1 | sed "s/\(.*\)/\U\1/"`

dcopRef=`kdialog --progressbar "Checking $dialogtitle hash, please wait..." 0 --title "Check $dialogtitle Hash"`

result=`$toolname $2`

filename=`echo $result | sed "s/^\([0-9a-z]*\) .*\/\(.*\)/\2/g"`

checksum=`echo $result | sed "s/^\([0-9a-z]*\) .*\/\(.*\)/\1/g"`

lookup=`grep ${filename} ${filepath}*${hashfile}* 2>/dev/null | grep ${checksum} 2>/dev/null`

findhash=`grep ${checksum} ${filepath}*${hashfile}* 2>/dev/null`

findfile=`grep ${filename} ${filepath}*${hashfile}* 2>/dev/null`

integrity=`if [ "${findfile}file" = "file" ]; then echo unknown; else if [ "${lookup}sum" = "sum" ]; then echo bad; else echo good; fi; fi;`

qdbus $dcopRef org.kde.kdialog.ProgressDialog.close

kdialog --title "Check $dialogtitle Hash" --msgbox "Filename: ${filename}\nChecksum: ${checksum}\nIntegrity: ${integrity}"

Change the checksum.desktop file mentioned in earlier post to have the following code instead:

Code:
[Desktop Entry]

Type=Service

Icon=security-high

Actions=CheckMD5Hash;CheckSHA1Hash;CheckSHA256Hash

ServiceTypes=KonqPopupMenu/Plugin

MimeType=all/allfiles

[Desktop Action CheckMD5Hash]

Exec=checkhash.sh md5 %U

Icon=security-high

Name=Check MD5 Hash

[Desktop Action CheckSHA1Hash]

Exec=checkhash.sh sha1 %U

Icon=security-high

Name=Check SHA1 Hash

[Desktop Action CheckSHA256Hash]

Exec=checkhash.sh sha256 %U

Icon=security-high

Name=Check SHA256 Hash

This is to showcase my lame shell scripting skillz, I'm sure this can be cleaned up some more and bugs found and fixed.

Right now, based on convention, it will try to generate the checksum and compare it with any checksums stored in files with SHA256SUMS or MD5SUMS etc in the name. Usually when you download an ISO or something the same web location has the SHA1SUMS file which you normally download to the same local folder.

Works well for me after some quick testing, hope it works for you...
 
bug bug bug - it cant handle spaces in the paths :ohyeah: will fix it soon...

edit: i think its this line which is the offender, but i'll fix it probably this weekend:

Code:
filepath=`echo $2 | sed "s/\(.*\/\).*/\1/"`

edit2: a kde forum user helped by pointing out you use double quotes, so the fix is to modify the following lines in the checkhash.sh script:

Code:
result=`$toolname "$2"`

filepath=`echo "$2" | sed "s/\(.*\/\).*/\1/"`

lookup=`grep "${filename}" ${filepath}*${hashfile}* 2>/dev/null | grep ${checksum} 2>/dev/null`

findfile=`grep "${filename}" ${filepath}*${hashfile}* 2>/dev/null`

notice double quotes added around the $2 (filename parameter sent from caller) and filename variables.
 
So Darky, what are the standard/recommended tools for KDE/Qt development? I'm assuming they are KDevelop and QtCreator so I will install these and play around with them.

My next weekend project is related to another KDE brainstorm idea I'd posted: [KDELibs] Use motion dynamics for progress bar movement - KDE Community Forums

Using "motion dynamics" for smooth progress bar movements like you have in other GUIs (Vista/Win7 that I have seen) :D

I'll have to wade through the source code to figure out where (KDE library, Qt library or KDE themes etc.) to make any changes. Plus there is current KDE 4.3 codebase then there is upcoming KDE 4.4 codebase which I believe will start using Qt Kinetic features to already implement such stuff! Let's see how it goes...

BTW, the KDE forum has a nice developer section and there is also this nice Qt community site which also has a forum: Qt Centre

See this old blog: Qt Labs Blogs Welcome to Kinetic
 
^^Kdevelop is it. But since it has been under development for KDE4 people tend to use QT IDE i.e. QT Creator.

When I started learning QT, I only installed the GUI creator and got stuck as there is no code implementation option in GUI manager .. :P

Awesome work up there :O

How to get started with shell scripting :? It looks pretty weird to me :S
 
yea shell scripting is all greek to me too.... i guess searching for "bash scripting tutorials" should give some links... i also looked up random sites to figure out those ugly script commands - mainly "sed" :)
 
Since the weekend is here I downloaded QtCreator IDE and sources for Qt library itself. Download took under just 1 hour on my 512 kbps connection and compiling the library also took just under 1 hour on my quad core desktop :D

First wrote a simple Qt dialog app with a progress bar with buttons to increase/decrease the progress using the Qt library I downloaded.

Result:

[youtube]x_GmgFVVCuM[/youtube]

Then I modified the Qt library qprogressbar.cpp file to try to add "smooth effects" well simple/crude step-scrolling - yet to add real motion dynamics (im totally useless at physics/math here so will take me time - or i can steal code online).

Result:

[youtube]uLV6OEwb32Q[/youtube]

Captured the videos with recordmydesktop package (you can see the code in the left side heh) which youtube accepts the .ogv files. The QtCreator IDE is pretty slick if a little unstable/slow... is fun working with it :)

edit: of course you need to add " -j 4 " to the call to "make" if you want to use all 4 cores so "make -j 4" when building code generally.
 
I also went through the same issues-wanted to learn Qt, but no experience in C++. So, currently in week 1 of Sams Teach Yourself C++ in 21 days.
 
OK, back to the topic at hand and this time it's KTorrent :ohyeah:

Whenever I'm downloading torrents and need to do other stuff like browsing/online radio then I used to set the download speed limit. Afterwards I would set the download speed back to zero (unlimited) and would notice that the speed would shoot up to 2-3 mbps for a few seconds even though I have a 512 kbps connection. This would happen in Transmission, KTorrent, utorrent etc.

Now why not make this download speed setting change automatic and continuous so that you get that speed boost frequently while the torrents are downloading?!

How to make it automatic? With open source and Free software you have da powa!

So I downloaded ktorrent source from ktorrent.org (or you can get it from KDE source code repository playground area) and after some code browsing to get familiar with it then made the following quick changes:

Added the following quick-n-dirty code and includes in gui.cpp and gui.h in ktorrent source:

Code:
....

#include <QThread>

....

class SpeedThread : public QThread

{

  Q_OBJECT

  protected:

    void run();

};

....

#include <interfaces/functions.h>

....

void SpeedThread::run()

{

  while (true)

  {

    Settings::setMaxDownloadRate(40);

    kt::ApplySettings();

    sleep(60);

    Settings::setMaxDownloadRate(0);

    kt::ApplySettings();

    sleep(10);

  }

}

....

SpeedThread * speedthread = new SpeedThread();

speedthread->start();

What that does is create and start a thread (it gets leaked though) that automatically changes the download speed settings, it keeps it at 40 kBps (320 kbps) for 1 minute (60 seconds) then makes it unlimited for 10 seconds. I've noticed if you keep the speed a little low for some time, say a minute, then change it to unlimited, it actually goes faster (1-2 mbps) for a few seconds before settling down to the normal speed.

So unless KTorrent (and Transmission and utorrent) are playing tricks on me, I would roughly calculate that this gives a 25% speed boost on average, meaning an extra 128 kbps on my 512 kbps connection!

Now I have yet to test whether this really works, will need to start a big download and manually measure the time taken and see if it was faster than expected ...
 
vishalrao said:
So unless KTorrent (and Transmission and utorrent) are playing tricks on me, I would roughly calculate that this gives a 25% speed boost on average, meaning an extra 128 kbps on my 512 kbps connection!

Now I have yet to test whether this really works, will need to start a big download and manually measure the time taken and see if it was faster than expected ...

The speed boost is temporary/ not a bost at all. When you are reducing the speed of the torrent the peers are still sending in data at the same/ unlimited rate. By the time bandwidth throttling kicks in to set the desired download speed there is data downloaded as buffer. When you set it back to ulkimited the download speed is shown higher as to compensate for the data downloaded.

I know i dont make any sense :rofl:
You can test the results by having some download/bandwidthmonitor and checking the average speed. It should be almost same.
 
Back
Top