CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2005
    Posts
    1

    Writing a flexible thumbnailer

    I've been trying to write a thumbnailer that can turn pretty much anything into an image. I've used Imagemagick for this sort of thing in the past, but the range of file types it's useful for is too limiting this time :-(

    I tried my hand at using KDE's thumbnail generator ... It seems to be quite good at generating nice images for all sorts of things ... but I'm a C++ noob, so I ran into difficulty.

    I wrote a small CLI app that extends (or is that Java terminology?!) KApplication. Of course, that means the script running the app needs access to an X display to work ... yuck! I read something somewhere about using the KInstance class instead of KApplication to avoid this, but I haven't been able to make it go.

    I imagine that doing it right is childsplay for someone with KDE experience, so let me apologise in advance for the undoubtedly terrifyingly ugly code snippet ...

    Code:
    #include <kio/previewjob.h>
    #include <kfileitem.h>
    #include <kurl.h>
    
    #include <qimage.h>
    #include <qpixmap.h>
    
    #include "thumbnailer.h"
    
    Thingy::Thingy()
    {
    }
    
    Thingy::~Thingy()
    {
    }
    
    void Thingy::whoopie(QString url)
    {
    	KURL::List urlList;
    	urlList.append(url);
    	
    	KIO::PreviewJob* job = KIO::filePreview(urlList, 256, 256, 0, 0, true, false);
    	
    	connect(job, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)),
    		SLOT(slotGotThumbnailKDE(const KFileItem*, const QPixmap&)));
    	connect(job, SIGNAL(failed(const KFileItem*)),
    		SLOT(slotFailedThumbnailKDE(const KFileItem*)));
    }
    
    void Thingy::slotGotThumbnailKDE(const KFileItem* item, const QPixmap& pix)
    {
    	QImage img=pix.convertToImage();
    	bool result=img.save(item->url().path()+".png","PNG");
    	if (!result) { printf("IO Failure"); exit(2); }
    	else { printf("Success"); exit(0); }
    }
    
    void Thingy::slotFailedThumbnailKDE(const KFileItem* item)
    {
    	printf("Generate Failure");
    	exit(1);
    }
    In my defence, I'm really a Java baby, so menial concerns like being careful with memory are frankly alien to me! I didn't even know what moc was until last week, so any tips or suggestions would be greatly appreciated :-)

  2. #2
    Join Date
    May 2005
    Posts
    47

    Question Re: Writing a flexible thumbnailer

    You have explained pretty clearly everything you are trying to accomplish, but what you posted doesn't seem to cause any errors or may it be that I misunderstand what you are trying to question, so could you also just include the thumbnailer.h header file ?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured