ubuntu下漂亮的冒泡提示 (2011-11-07 20:49)

 

 
UBUNTU 下漂亮的冒泡提示,可定制图标。挺好玩的,很久以前弄的一个小程序。
得先安装依赖库libnotify
 
/*  
 *  Copyright (C) 2011 crazyleen <357228736@qq.com>, 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;
}

/* mynotify.h
 * this function is to display a notification on the screan,
 *
 * 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.
 *
 * Copyright (C) 2011 crazyleen <357228736@qq.com>, All Rights Reserved.
 */

#ifndef MYNOTIFY_H
#define MYNOTIFY_H

/* body & icoon are both optional
 * Returns : error: -1, success return 0
 */
int notification_show(char *title, char *body, char *icon);

#endi

/* file.c
 * Copyright (C) 2011 crazyleen <357228736@qq.com>, 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(5);
	notification_show("cheery", NULL, NULL);
	printf("UNIX\n");
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值