PDA

View Full Version : Handle :mailto links



Nyphel
30th May 2007, 08:46
Hi,

I would like to write a very simple application that would handle/hook the clics on :mailto links under Windows, and open the FreFox navigator instead of the default mail client.

The links I want to handle are thoses of other applications, and if possible thoses of the web navigator. I know how to call Firefox (QDesktop or QProcess) but I've no idea about detecting a clic on a :mailto link, no more than how to cancel the default mail client opening.

Is it possible to do it with Qt ?

Thanks for your help :)

jpn
30th May 2007, 08:49
Take a look at QDesktopServices::setUrlHandler().

Nyphel
30th May 2007, 09:23
I don't understand how it could help me :confused:.

I think I didn't explained my goal correctly ;).
I want to write a small application that would run all the day during (launched at Windows startup). This application would detect when the computer user clic on a :mailto link of other application (Microsoft Word, Open Office, for example) and prevent the default mail client from opening. Instead, it would launch the web navigator with a given URL.

jpn
30th May 2007, 09:31
Oh, sorry for misunderstanding. QDesktopServices indeed works only in your application. This does not sound like a job for Qt anyway.

Nyphel
30th May 2007, 09:38
Ok JPN, thanks anyway :)

wysota
31st May 2007, 01:20
I think all you need is to register your application as the default mail handler in your system. Then all requests for sending mails will be passed to your application.

Nyphel
1st June 2007, 10:17
Yes, this is exactly what I've done :)

The problem is that I need to pass arguments to my application (title of the mail, for example, and destinary). I've seen that the Windows Registry can pass mailto arguments, and I'm trying to deal with...

In reality I've another strange problem : in order to test the arguments and to see if they are passed to my application, in write them in a file.
Here is my main :



#include <QApplication>
#include <QtGui>
#include <iostream>

#include <QString>
#include <fstream>
#include <iostream>
using namespace std;

#include "Mailto_Handler.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

//Mailto_Handler * mon_gestionnaire = new Mailto_Handler();

QString argument_1 = argv[1];
QString argument_2 = argv[2];
QString argument_3 = argv[3];
QString argument_4 = argv[4];
QString argument_5 = argv[5];

ofstream mon_fichier ("parametres.txt");
if (mon_fichier.is_open())
{
mon_fichier << "Argument 1 : \t" << argument_1.toStdString() << endl;
mon_fichier << "Argument 2 : \t" << argument_2.toStdString() << endl;
mon_fichier << "Argument 3 : \t" << argument_3.toStdString() << endl;
mon_fichier << "Argument 4 : \t" << argument_4.toStdString() << endl;
mon_fichier << "Argument 5 : \t" << argument_5.toStdString() << endl;

mon_fichier.close();
}

//exit(0);
return app.exec();
}

This works well if I call my application :
- by double-clicking it
- by calling it from a Batch file
- by calling it from MSYS command line

But if I call it from the registry, when I use a mailto link, I've a problem : the file is not written. The application is launched, that is sure : I see it in the task monitor. But the file is n't written...

Have you got an idea ?

wysota
1st June 2007, 10:21
Use an absolute path to the file.

Nyphel
1st June 2007, 10:41
Oups yes... :o

Thanks Wysota :)