关于ubuntu中气泡提示的使用

我学校用的是港湾验证,使用起来很让人不爽,于是下定决心自己写linux下面的港湾客户端,熬了几天,写好了。

写成daemon程序,发现ubuntu里面的这个气泡提示很好,就网上淘了些资料,现在整理出来。

 

ubuntu的气泡提示是使用notify-osd来实现的,我们需要下载libnotify,

         apt-get install notify-osd   (ubuntu 已经自带)

         apt-get install libnotify-dev

 

其实shell里面也可发送气泡提示,命令为notify-send,需要安装libnotify-bin

         apt-get install libnotify-bin

usage:
    notify-send Test "Hello World"
    notify-send "Message Title" "The message body is shown here" -i /usr/share/pixmaps/apple-green.png -t 1000

ps:icon can be a png, xpm or jpg file

截图来看看:

关于ubuntu中气泡提示的使用_第1张图片

 

 

 

C语言中,我们使用的是notify库,可查阅官方资料

Libnotify Reference Manual:

http://library.gnome.org/devel/libnotify/0.7/

一定要习惯阅读英文manual.多点看,慢慢就习惯了

 

我自己写的一个C文件:

/* * Copyright (C) 2011 crazyleen <[email protected]>, All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * HOWTO: * $(CC) $(Flags) -c mynotify.c -o mynotify.o `pkg-config --cflags --libs gtk+-2.0` -l notify */ #include <libnotify/notify.h> #include "mynotify.h" int notification_show(char *title, char *body, char *icon) { GError *error = NULL; NotifyNotification *notify_p; if (title == NULL) return -1; //you should init notify using app's name if(notify_is_initted() == FALSE) if(notify_init("argv[0]") == FALSE){ return -1; } notify_p = notify_notification_new(title, body, icon, NULL); //miliseconds, NOTIFY_EXPIRES_DEFAULT NOTIFY_EXPIRES_NEVER notify_notification_set_timeout(notify_p, 1000); //NOTIFY_URGENCY_LOW,NOTIFY_URGENCY_NORMAL, NOTIFY_URGENCY_CRITICAL, notify_notification_set_urgency (notify_p,NOTIFY_URGENCY_NORMAL); //notify_notification_update(title, body, icon, NULL); //notify_notification_close(notify_p, &error); if (notify_notification_show(notify_p, &error) == FALSE) return -1; //notify_uninit(); return 0; }  


测试一下函数:

/* file.c * Copyright (C) 2011 crazyleen <[email protected]>, All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <stdio.h> #include <string.h> #include <unistd.h> #include "mynotify.h" int main(char argc, char *argv[]) { notification_show("cheery", "here is body...", "/usr/share/pixmaps/apple-green.png"); sleep(10); notification_show("cheery", NULL, NULL); printf("UNIX/n"); return 0; }


效果还可以,正常显示,就是那个时间设置没起作用,每次都是系统默认的,这个气泡提示用于偶尔的消息通知挺好的,但是一定不能连续使用,因为这个冒泡显示是延时一点时间的,不能马上显示出下一条消息,必须等上一条消息淡化退出后才能显示下一条消息,这或许也算是一个bug吧

以下是我程序运行的效果


 

我把这个气泡提示用于mystar客户端,写成守护进程,开机自动运行,再也不用为linux下的802.1x验证而感到恼火了,呵呵

 

 

你可能感兴趣的:(linux,shell,ubuntu,null,reference,gtk)