notify_notification_new not showing icon

542 Views Asked by At

I'm completely stumped. I have this little thing to ease the mounting of MTP units under linux, but for some reason I can't get libnotify to show my icon when using variables. If I hardcode the complete path, it works fine, but when using variables as getcwd and getenv, it won't show.

Here is a piece of the code:

char cwd[1024];
char *slash = "/";  
{
NotifyNotification *mount;
notify_init ("Galaxy Nexus mounter");
    if (getcwd(cwd, sizeof(cwd)) != NULL)
    {
        mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", ("%s%sandroid_on.png", cwd, slash));
        fprintf(stdout, "Icon used %s%sandroid_on.png\n", cwd, slash);
        system("jmtpfs ~/Nexus");
        notify_notification_set_timeout (mount, 2000);
        notify_notification_show (mount, NULL);
    }
    }

What am I doing wrong?

2

There are 2 best solutions below

1
On BEST ANSWER

This doesn't look right:

mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", ("%s%sandroid_on.png", cwd, slash));

Is the third parameter supposed to be a string? If so, you need to build it separately with snprintf:

char path[1000];
snprintf (path, sizeof(path), "%s%sandroid_on.png", cwd, slash);
mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", path);
fprintf(stdout, "Icon used %s\n", path);
0
On
("%s%sandroid_on.png", cwd, slash)

Are you aware that this expresion in C is equivalent to?

(slash)

The comma operator has no other effect!

You may want to do something like:

char png[1100];
sprintf(png, "%s%sandroid_on.png", cwd, slash);
mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", png);

Or simpler, particularly if you know you won't overflow the char array:

strcat(cwd, slash);
strcat(cwd, "android_on.png");
mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", cwd);