Wednesday 15 September 2010

New sort modes in KRename

An often requested feature in KRename was to have more possibilities to sort the files before renaming. This was indeed a major limitation, as it is often eligible to sort files by date or some other criteria.

Some time ago, I found finally time to add sorting by date and today I finished a new powerful custom sorting feature, which allows to use any token to be used for sorting, which is supported by one of the plugins provided by KRename. This means sorting is now possible by almost any criteria, like [filesize], [creationdate], [user] or even [##tagTrack]. Of course, you can choose whether you want to sort ascending, descending or by numbers.

The screenshot below shows the new selection of sorting options in KRename.



If you click on "Custom...", you get a dialog like the one below, to specify what sorting criteria you want to use.



The final result might look like this, see the screenshot of Dolphin as a proof that we really sort by [filesize]:


This feature is currently only available in KRename SVN trunk. Still, I would be interested in your feedback.

Tuesday 17 August 2010

KBarcode4-light released

Where is KBarcode for KDE4? Well, there are porting efforts under way in SVN, but these are sadly far from completion.

If you just want to create barcodes easily and save them as image or a PDF, rescue might be near in the form of KBarcode4-light. KBarcode4-light is a simple barcode generator for KDE4. It supports many 1D and 2D barcode formats and can export them as images or PDF files.

It is similar to KBarcode for KDE3, but less powerful. KBarcode4-light allows only to create single barcodes. As the port for KBarcode is not yet ready and no one knows when it will be ready, KBarcode4-light provides basic barcode generation for KDE. An additional benefit is that it provides an easy to use interface for Barcode Writer in Pure Postscript.



It is written in Python using the amazing PyQt4 Qt bindings and based on Barcode Writer in Pure Postscript by Terry Burton.

KBarcode4-light downloads are available. It requires Python and PyQt bindings for Qt4, as well as Ghostscript in your PATH. Please submit any feedback to the KBarcode mailing list.

UPDATE: Due to a small bug, a new fixed version 0.2 is available for downloads.

Saturday 7 August 2010

podofocrop: PDF cropping in 10 lines of code

The PoDoFo tools family got a new member during the last week: podofocrop. This little tool crops the white margins of pages in PDF files.

I use tools like these a lot, for example when writing scientific papers or the like, because I try to include all figures as PDF files to have better quality in the final PDF. To do so, it is often necessary to remove the margin around the figure before including it. This is exactly what podofocrop is doing.

The figure below illustrates what podofocrop is doing. Figure (a) shows the input PDF file, we can see a page with a little bit of text and a big white margin. In the next step, Figure (b), podofocrop calculates the bounding box for the final PDF, i.e. the area on the page that has content and the size to which we want to crop the PDF. Ghostscript is used for this step and has to be in your PATH. Finally, the PDF is cropped and the new page is much smaller without any disturbing margins.



If you are interested, get podofocrop from the PoDoFo SVN. In case of questions, please contact the mailing list.

Please note: Windows support is still experimental and untested so far. It will compile but there are no guarantees that it will work. Help with the Windows port would be greatly appreciated.

At the end, let we give you one little detail on the implementation, because it is so amazingly simple using PoDoFo. If you remove the code for parsing command line arguments, communication with Ghostscript and error handling, you see that the tool has only a few lines:


std::vector cropBoxes = get_crop_boxes_from_gs( pszInput );
PdfVariant var;
PdfMemDocument doc;
doc.Load( pszInput );

for( int i=0;i {
PdfPage* pPage = doc.GetPage( i );
cropBoxes[i].ToVariant( var );
pPage->GetObject()->GetDictionary().AddKey( PdfName("MediaBox"), var );
}

doc.Write( pszOutput );

Wednesday 21 July 2010

Saturday 29 May 2010

Organising publications using KRename

I have to work with lot's of scientific publications at the moment. That means, I have a large directory with many PDFs that are related to my work. Sometimes, it is cumbersome to find the right PDF or publication to look something up. Of course, I could rename every PDF after I downloaded it by hand, but - you might guess it - I am to lazy for this.

But help is in sight! I added a plugin to KRename, which can rename files based on meta-data included in PDF files. Organising a large set of publications is now a matter of adding the PDF files to KRename and using the template "[pdfAuthor] - [pdfTitle]". Convenient, isn't it? The screenshot below shows KRename while renaming a few PDF files.



The supported tags are [pdfPages] (number of pages), [pdfProducer], [pdfTitle], [pdfSubject], [pdfKeyword], [pdfCreator] and, [pdfAuthor]. If you have an idea for further meta-tags, do not hesitate to contact me. It should be quite easy to add more information, the current implementation is a matter of 10 lines thanks to the PoDoFo library used.




A pity is that many PDF authors do not add proper meta-data to their PDF files. So, if you are writing on a publication at the moment, please make sure you add your information to the PDF metatags.

This feature is currently only available in KRename SVN trunk.

Thursday 29 April 2010

PoDoFo Base 14 Font support

Today has seen a major contribution to the PoDoFo PDF library.

I integrated a patch by Ian Curington and his developers, which brings support for using the base 14 fonts in PDF files. What are the base 14 fonts, you might ask?

Every PDF viewer has to ship with these 14 fonts, therefore one can achieve much smaller file sizes, as these particular 14 fonts do not have to be embedded into the PDF. Still, the PDF is displayed the same on every system (should be displayed ...), as every PDF viewer has the same font metrics for these fonts. Among the base 14 fonts are Helvetica, Times, Courier and Symbol.

This contribution makes the base 14 fonts available to everyone creating PDFs using PoDoFo. As the base 14 fonts are automatically used, whenever you request a PdfFont like Helvetica, this should result in much smaller file sizes for PDFs created with PoDoFo, which only use these fonts. An example which does also compare one of the base 14 fonts (Helvetica) to a TrueType font (Arial) is also provided. Okular has some problem displaying the symbol fonts, which I have yet to investigate.

If you would like to try the change, please grab the latest PoDoFo from SVN. The change is not included in the latest 0.8.0 release.

Tuesday 6 April 2010

A web-radio plasmoid for your desktop

Since I am in Limerick, Ireland, I started to listen quite a lot to RTÉ 2XM, which is a great web-radio station of the public broadcasting service in Ireland (Click for webstream).

RTÉ has a quite nice applet for the Windows Vista or Windows 7 sidebar. Unfortunately, the do not yet offer one for KDE and Plasma. Instead of waiting for the applet, I wrote a little web-radio applet by myself yesterday.



The plamoid has a simple list of radio stations and a play and a stop button. Easy, isn't it? Of course you can configure the list of stations. If you download and install it, it comes preconfigured with all the RTÉ stations and my favourite Austrian station FM4.



You can download the plasmoid from here: http://krename.sourceforge.net/data/plasmaradio-0.1.tar.gz.

To install the plasmoid, follow the following steps after downloading it:

tar xvfz plasmaradio-0.1.tar.gz
cd plasmaradio-0.1
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$KDEDIRS ..
make
make install


I would be happy to receive some feedback on this little piece of code. By the way, I think it really shows what great stuff can be done in so little time using the KDE4 API.

Wednesday 24 February 2010

Detection of architecture violations in C/C++ applications

In a small project, I am experimenting with a cleaner and in this case layered architecture for certain parts of PoDoFo. I think it is a quite usual problem, to have an architecture and a grown application and you would like to check whether the sources adhere to the previously defined architecture. Therefore, it is important to have tools to check for architecture violations. These can be used to validate the architecture at certain points of time or even after each commit to the source repository on a continuous integration server.

I did not know any tool which can easily do this kind of validations for C/C++ source code, so I came up with a small bash script that does exactly this. The only configuration needed are some rules that define the architecture. Architecture is in this case a layered architecture where certain modules are only allowed to include certain other modules. See image 1 for a small UML diagram of the architecture.



These rules can be edited at the top of the script:

RULES="content->structure \
content->datatype \
content->io \
content->util \
structure->datatype \
structure->io \
structure->util \
datatype->io \
datatype->util \
io->util \
content->fontconfig \
content->Carbon \
util->\.\. \
src->.* \
.*->tr1 \
.*->sys"

As you can see, it is also possible to use regular expressions. Also, I had to add some rules for includes like fontconfig (external libraries) that are not available in the UML diagram above.

The script produces quite a lot of output, but grepping for "violation" shows only the important results:


If you are interested you can get the bash script from here: check_architecture.sh The script should be self-explaining and pretty easy to adapt to your needs.

Sunday 14 February 2010

Building KRename trunk from SVN

I just noticed that there is no up to date documentation on how to build KRename trunk from SVN on our website. Well, everyone who is interested in getting the latest version of KRename and does not want to wait for the next release - these are the steps to get KRename trunk from SVN and build it.


svn co https://krename.svn.sourceforge.net/svnroot/krename/trunk krename
cd krename
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$KDEDIR ../
make
sudo make install


This assumes that $KDEDIR is an environment variable pointing to your KDE installation. You can set $KDEDIR using the following bash command:

export KDEDIR=/usr


Most other KDE applications can be built the same way.

Saturday 6 February 2010

Generic web-service queries on your desktop using Plasma

Some days ago, I applied for a new passport. In Munich, where I currently live, you apply for the passport at the city hall and usually can pick the passport up there 3 weeks later. I was surprised to see that they have a new service: You get an ID number with which you can check the status of your passport via a web-service. So, if you check regularly, the web-service will tell you when your
passport is ready to pick it up.

What is the usual you do in cases like that? Of course, you write a Plasmoid that checks the web-service periodically and informs you when your passport is ready. This plasmoid - PersonalKwery - can be seen in screenshot 1.


Thinking further about this quick hack, I came to the conclusion that with only a little bit of work, I could create a generic plasmoid that can query webservices and display the result on your desktop. I managed to create a plasmoid that takes the following configuration:

  • Base URL of the web-service

  • Attributes to the URL (like the ID number of my passport, or arguments to a Google query)

  • An optional XSLT to transform the results

  • An interval, how often the query should be performed



With this little configuration you can easily query many web-services. Of course, most users won't be in the mood to create their own XSLT transformations! Therefore it is possible to store the configurations as XML and share them - for example over "get hot new stuff". In this case, users can
download predefined web-service queries and only have to enter a few necessary attribute values. The screenshot below shows the configuration dialog for a query:


Another small example is a simple query, that get's your current internet IP address.


Of course, the tool is not perfect yet and can be made more user friendly. If you are interested, you can get the tarball here: personalkwery-0.1.tar.gz.