Also implemented is a small message passing protocol that allows a non-primary application (ie one that discovers that there's already a copy of itself running) to easily send a message to the primary.
For example you can tell a program to open a particular file, or to open a new window or to perform a chosen action. Then put the action into a .kdelnk and then maybe drag it to your panel as abutton (to maybe open a blank document or something)
It can be used two ways:
However a better way of looking at this problem is to think about how your user thinks about the application - is it one thing (like their mail box) or several (like documents being edited) - if it looks like one thing then KUniqueApplication probably provides the expected behavior - if it's several it may be that you should implement your application as several cooperating programs (ie solve your locking problems otherwise. (a good example of this is kfm vs. netscape - netscape's windows are all interrelated and it behaves like one application while kfm's behave independantly)
void uniqueCalled(char *message);
Their contents and measnings are up to you to define - however the following are reccomended:
Normally you might process the program args something like:
for (i = 1; i <= argc; i++) if (strcmp(argv[i], "--new") == 0) newflg = 1; else if (strcmp(argv[i], "--check") == 0) chkflg = 1; etc app = new KApplication(argv, argv, "mail"); mail = new Mail(); if (newflg) mail->new(); if (chkflg) mail->chk(); mail->showbrowser();'Uniquifying' the app and implementing passing 'new' and 'check' as messages would result in:
char *message = "";
for (i = 1; i <= argc; i++)
if (strcmp(argv[i], "--new") == 0) {
newflg = 1
message = argv[i];
} else
if (strcmp(argv[i], "--check") == 0)
chkflg = 1;
message = argv[i];
} else
etc
app = new KUniqueApplication(message, argv, argv, "mail");
mail = new Mail();
if (newflg) mail->new();
if (chkflg) mail->chk();
mail->showbrowser();
QObject::connect(app, SIGNAL(uniqueCalled(char *)), mail, SLOT(uniqueMessage(char *)));
The only difference here being using the KUniqueApplication class, passing a code
indicating the flag to it, and connecting a slot to receive the message from other
applicationsIn the mail class you need to register a slot:
void mail::uniqueMessage(char *message)
{
if (strcmp(message, "") == 0) {
showbrowser(); // bring it to the front
} else
if (strcmp(message, "--new") == 0) {
new(); // create a new mail window
} else
if (strcmp(message, "--check") == 0) {
chk(); // check for mail
}
}