Qt4 Imap API

August 1, 2009 | Filed Under Qt4 | 1 Comment

Pushed in my GitHub repo the first draft of the Qt4 Imap (RFC 3501 Interne Message Access Protocol) Library.
I’ve implemented a sync communication because it’s much easier to use, so if you want to use it in async way you need to implement a thread class that wrap the Imap class and throws the events that you need.

Imap imap;
if (!imap.connectToHost(IMAP_HOST, IMAP_PORT, IMAP_USE_SSL))
   IMAP_MAIN_ABORT("connectToHost()", imap.errorString());

if (!imap.login(IMAP_USERNAME, IMAP_PASSWORD, IMAP_LOGIN_TYPE))
   IMAP_MAIN_ABORT("login()", imap.errorString());

ImapMailbox *mailbox = imap.select("INBOX");
qDebug() << "INBOX";
qDebug() << " - Exists:" << mailbox->exists();
qDebug() << " - Unseen:" << mailbox->unseen();

QList<int> messageList = imap.searchRecentUnseen();
imap.fetch(mailbox, messageList);
foreach (int msgId, messageList) {
   ImapMessage *message = mailbox->findById(msgId);
   if (message == NULL) continue;

   imap.fetchBodyStructure(message);

   qDebug() << "FROM" << message->fromAddress().toString();
   foreach (ImapAddress address, message->toAddresses())
      qDebug() << " - TO" << address.toString();
   qDebug() << "SUBJECT" << message->subject();

   for (int i = 0; i < message->bodyPartCount(); ++i) {
      ImapMessageBodyPart *bodyPart = message->bodyPartAt(i);
      imap.fetchBodyPart(message, i);

      qDebug() << bodyPart->isAttachment() << bodyPart->contentType();
      qDebug() << bodyPart->data();
   }
}

delete mailbox;

imap.logout();
imap.disconnectFromHost();

Qt4 Google Contacts APIs

July 24, 2009 | Filed Under Qt4 | No Comments

Just pushed at GitHub the first draft of the Qt4 Google Contacts Service…

Contacts APIs allows client applications to view and update Contacts content in the form of Google Data API feeds. Your client application can request a list of a user’s contacts, edit or delete content in an existing contact.

// Setup Contact
THGoogleContact *contact = new THGoogleContact;
contact->setFullName("John Doe");

THGoogleIm *im = new THGoogleIm;
im->setRel(THGoogleIm::relWork());
im->setAddress("john.doe@aim.com");
im->setProtocol(THGoogleIm::protocolAim());
contact->addImAddress(im);

THGoogleEmail *email = new THGoogleEmail;
email->setAddress("john.doe@mail.com");
email->setRel(THGoogleEmail::relWork());
contact->addEmailAddress(email);

// Insert Contact
THGoogleContactsService *gContacts = new THGoogleContactsService;
gContacts->setAuthToken(...);
gContacts->insertContact(contact);


Take a look at contacttest.cpp for a more complete usage example.

Qt4 Google MapView

July 12, 2009 | Filed Under Qt4 | No Comments

I’ve received a couple of requests about Google Maps and Qt4. Today I’ve written a simple Widget that allows you to interact with Google Maps and Google Geocoder. You can set Map Type (Roadmap, Satellite, Terrain and Hybrid), you can set your center Coordinate, add Markers, add Info Windows get the User Click Coordinates and other things that Google Maps allows to do.

Qt4 Google MapView

With few lines of code, you can interact with Google Maps, and below you can see how to do it. (Other methods and overloads are available, check the GKMapView.h in the Source Code packet, link is at the end of the post).

GKMapView mapView;

// Change the Default MapType (Roadmap, Satellite, Terrain, Hybrid)
mapView.setMapType(GKMapTypeSatellite);

// Use Geocoder to Get Location from Address or Viceversa.
// See the Signals locationFound, locationNotFound() and
// addressFound(), addressNotFound() to get your results.
mapView.locationFromAddress("San Mateo");
mapView.addressFromLocation(32.718834, -117.164);

// Add Marker With Info Window at Specified Address (or Location)
mapView.addMarkerWithWindow("Bedford MA Marker",
                            "<b>Bedford MA</b> Marker",
                            "Bedford MA");

// Add Info Window without Marker using Address or Coordinates
mapView.addInfoWindow("Hello from <b>San Mateo</b>", "San Mateo");
mapView.addInfoWindow("Hello from <b>San Diego</b>", 32.718834, -117.164);

// Change your Current Location
mapView.setLocation("Phoenix AZ");

The Source Code is available Here with a small example: Qt4 Google Map View Source Code.

Qt4 Canvas Plugins

June 28, 2009 | Filed Under Qt4 | No Comments

Today, during my Sunday morning bike trip I’ve had an Idea on how to simply implement a Canvas Plugins in Qt Applications, to give you an idea of How browser external plugins like flash or others works. The Code is really simple there’s a class CanvasPlugin with a couple of Abstract Methods Init, UnInit, Resize, MouseEvent and a signal that says “Hey, Paint this Image!”. To give you an Idea of the result below you can see a Window with two Widgets, a CanvasPluginViewer and a Label. Canvas Plugin Viewer load an external Library (.so) passed to the command line as first argument.

Qt Canvas Plugin Example
You can interact with the canvas like a normal widget (the red square moves along the window and you can stop and resume its animation). But you can extend the sample sending and receiving information from a server, or you can do other crazy external things. (See flash usage for more ideas).

That’s all folks, it’s lunch time. If you’ve any question send me a mail or write a comment, and remember that this is just a couple of minutes coded example, so don’t use in your highly stable app. :)

The Source Code is Available Here: Qt4 Canvas Plugins Source Code.

Qt4 iPhone Like Cut/Copy/Paste Widget

June 13, 2009 | Filed Under Qt4 | No Comments

I’m watching the WWDC Keynote podcast, Just finished the Bertrand Serlet Talk, about Snow Leopard. Now before watching Scott Forstall with the new iPhone 3GS, a little break with an example of Cut, Copy and Paste like Widget. (In the Snow Leopard dock demo, I’ve seen “the same” widget used to do expose)

Qt Cut Copy and Paste IPhone Like
It’s a really simple example but it can be useful to someone to understand how to add actions to a custom shape.

The Source Code is available Here: Qt4 iPhone Like Cut, Copy Paste Source Code.

Qt4 Geo IP Location

June 12, 2009 | Filed Under Qt4 | 2 Comments

In a time of Google Maps, Geo Location and other services like this… Here an example of Geo IP Location Service (http://www.hostip.info/) is really far from perfect, but it’s just an example.

Qt Geo IP Location

The sample uses QNetworkAccessManager to get the Geo Location of the IP, and Webkit to display the address on the Google Map.

The Source Code is available Here: Qt4 Geo IP Location Source Code.

Qt4 Google Services: Translator, Spell Checker and more…

June 6, 2009 | Filed Under Qt4 | No Comments

Last month I’ve made a simple wrapper for Google Authentication, Today I’ve written other 4 classes to wrap the Google’s Translator, Language Detector, Suggestions and the Spell Checker Services.

Translator Example

QEventLoop l;
THGoogleTranslator gTranslator;
connect(&gTranslator, SIGNAL(finished(bool)), &l, SLOT(quit()));
gTranslator.setDestinationLanguage("en");
gTranslator.translate("Ciao");
l.exec();

qDebug() << gTranslator.translatedText(); // Maybe "Hello"
qDebug() << gTranslator.detectedSourceLanguage(); // Maybe "it"

Suggest Example

QEventLoop l;
THGoogleSuggest gSuggest;
connect(&gSuggest, SIGNAL(finished(bool)), &l, SLOT(quit()));
gSuggest.suggest("Qt Softw");
l.exec();

qDebug() << gSuggest.suggestions();
// ("qt software", "qt software download", "qt software gpl exception", ...)

Spell Checker Example

QEventLoop l;
THGoogleSpellChecker gSpellChecker;
connect(&gSpellChecker, SIGNAL(finished(bool)), &l, SLOT(quit()));
gSpellChecker.spellCheck("Gogl Spll");
l.exec();

// "Gogl" ("Google", "Gogol", "Gog", "Goal", "Gog's")
// "Spll" ("Spell", "Sp ll", "Sp-ll", "Spill", "Sell")
foreach (QString original, gSpellChecker.keys())
    qDebug() << original << gSpellChecker.suggestions(original);

Language Detector Example

QEventLoop l;
THGoogleDetectLanguage gDetectLang;
connect(&gDetectLang, SIGNAL(finished(bool)), &l, SLOT(quit()));
gDetectLang.detectLanguage("Ciao");
l.exec();

qDebug() << "Query" << gDetectLang.query();
qDebug() << "Language" << gDetectLang.language(); // Maybe "it"
qDebug() << "Is Reliable" << gDetectLang.isReliable();
qDebug() << "Confidence" << gDetectLang.confidence();

You can find the source at GitHub (Git WebView) or you can download the source code Here: Qt4 Google Services Take 2 Source Code.

Qt4 Jump Away Animation

May 16, 2009 | Filed Under Qt4 | No Comments

When I’ve started working on Mac OS X with Core Animation, I was impressed by an Example (I don’t remember the link, if someone knows it, post it in the comments! thanks)… Very few lines of code for a great effect.

After a year, or probably more.. this example was came back to my mind, so I’ve decided to clone using Qt. And below you can see a short Demonstration Video. Your desktop jump away.. full screen is fantastic :)

The Source Code is Available Here: Qt4 Jump Away Animation Source Code.

Next Page »