/*
* Copyright (C) 2003, 2004, 2005 Philip Blundell <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <libintl.h>
#include <langinfo.h>
#include <ctype.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gpe/tray.h>
#include <gpe/init.h>
#include <gpe/popup.h>
#include <gpe/errorbox.h>
#include <gpe/spacing.h>
#include <gpe/gtkdatecombo.h>
#include <gpe/gpetimesel.h>
#include <gpe/gpeclockface.h>
#include <gpe/schedule.h>
#include <gpe/launch.h>
#include <gpe/infoprint.h>
Display *dpy;
GtkWidget *panel_window, *time_label, *face, *menu;
GtkObject *hour_adj, *minute_adj;
#define _(x) gettext(x)
static gchar *alarm_file, *prefs_file;
#define FORMAT_12 0
#define FORMAT_24 1
#define FORMAT_ANALOGUE 2
static gboolean show_seconds;
static int format = FORMAT_24;
gboolean prefs_window_open;
gboolean alarm_window_open;
#define SHORT_TERM_ALARMS
struct alarm_state
{
gboolean active;
int hour, minute;
gboolean date_flag;
int day, month, year;
guint day_mask;
};
struct alarm_context
{
struct alarm_state state;
GtkWidget *window;
GtkWidget *active_button;
GtkWidget *date_combo, *time_sel;
GtkWidget *date_button, *days_button;
GtkWidget *day_button[7];
};
static struct alarm_state state;
void select_new_format (int new_format);
static void
set_defaults (void)
{
time_t t;
struct tm tm;
memset (&state, 0, sizeof (state));
time (&t);
localtime_r (&t, &tm);
state.hour = tm.tm_hour;
state.minute = tm.tm_min;
state.date_flag = TRUE;
state.year = tm.tm_year + 1900;
state.month = tm.tm_mon;
state.day = tm.tm_mday;
}
static void
flush_prefs (void)
{
FILE *fp;
fp = fopen (prefs_file, "w");
if (fp)
{
fprintf (fp, "%d %d\n", show_seconds, format);
fclose (fp);
}
}
static void
load_prefs (void)
{
FILE *fp;
fp = fopen (prefs_file, "r");
if (fp)
{
int seconds;
fscanf (fp, "%d %d", &seconds, &format);
show_seconds = (seconds != 0) ? TRUE : FALSE;
fclose (fp);
}
}
static void
flush_alarm_details (void)
{
FILE *fp;
fp = fopen (alarm_file, "w");
if (fp)
{
fprintf (fp, "ACTIVE: %d\n", state.active);
fprintf (fp, "TIME: %02d:%02d\n", state.hour, state.minute);
if (state.date_flag)
fprintf (fp, "DATE: %04d-%02d-%02d\n", state.year, state.month, state.day);
else
fprintf (fp, "DAYS: %02x\n", state.day_mask);
fclose (fp);
}
}
static gboolean
time_past_already (struct alarm_state *state, struct tm *tm, gboolean use_date)
{
if (use_date)
{
if (state->year < (tm->tm_year + 1900))
return TRUE;
if (state->year > (tm->tm_year + 1900))
return FALSE;
if (state->month < tm->tm_mon)
return TRUE;
if (state->month > tm->tm_mon)
return FALSE;
if (state->day < tm->tm_mday)
return TRUE;
if (state->day > tm->tm_mday)
return FALSE;
}
if (state->hour < tm->tm_hour)
return TRUE;
if (state->hour > tm->tm_hour)
return FALSE;
if (state->minute < tm->tm_min)
return TRUE;
/* if (state->minute > tm->tm_min) return FALSE; */
return FALSE;
}
static void
load_alarm_details (void)
{
FILE *fp;
fp = fopen (alarm_file, "r");
if (fp)
{
while (!feof (fp))
{
char buf[128];
if (fgets (buf, 128, fp))
{
char *p = strchr (buf, ':');
if (p)
{
*p++ = 0;
while (isspace (*p))
p++;
if (!strcasecmp (buf, "ACTIVE"))
{
state.active = atoi (p);
}
else if (!strcasecmp (buf, "TIME"))
{
sscanf (p, "%02d:%02d", &state.hour, &state.minute);
}
else if (!strcasecmp (buf, "DATE"))
{
state.date_flag = TRUE;
sscanf (p, "%04d-%02d-%02d", &state.year, &state.month, &state.day);
}
else if (!strcasecmp (buf, "DAYS"))
{
state.date_flag = FALSE;
sscanf (p, "%02x", &state.day_mask);
}
}
}
}
fclose (fp);
}
if (state.date_flag)
{
time_t now;
struct tm tm;
time (&now);
localtime_r (&now, &tm);
#ifdef SHORT_TERM_ALARMS
state.hour = tm.tm_hour;
state.minute = tm.tm_min;
#endif
if (time_past_already (&state, &tm, TRUE))
{
state.active = FALSE;
if (time_past_already (&state, &tm, FALSE))
{
/* Alarm time already passed for today. Set it for
tomorrow instead. */
now += 24 * 60 * 60;
localtime_r (&now, &tm);
}
state.day = tm.tm_mday;
state.month = tm.tm_mon;
state.year = tm.tm_year + 1900;
}
}
}
static time_t
extract_time (struct alarm_state *alarm)
{
struct tm tm;
time_t t;
int wasdst;
memset (&tm, 0, sizeof (tm));
tm.tm_year = alarm->year - 1900;
tm.tm_mon = alarm->month;
tm.tm_mday = alarm->day;
tm.tm_hour = alarm->hour;
tm.tm_min = alarm->minute;
t = mktime (&tm);
wasdst = tm.tm_isdst;
/* Break it out again to get DST right */
memset (&tm, 0, sizeof (tm));
localtime_r (&t, &tm);
tm.tm_year = alarm->year - 1900;
tm.tm_mon = alarm->month;
tm.tm_mday = alarm->day;
tm.tm_hour = alarm->hour;
tm.tm_min = alarm->minute;
tm.tm_isdst = wasdst;
return mktime (&tm);
}
static void
cancel_alarm (struct alarm_state *alarm)
{
if (alarm->active)
{
time_t t;
t = extract_time (alarm);
schedule_cancel_alarm (1, t);
}
}
static gboolean
day_matches (struct alarm_state *alarm, int day)
{
day = (day + 6) % 7;
return (alarm->day_mask & (1 << day)) ? TRUE : FALSE;
}
static void
set_alarm (struct alarm_state *alarm)
{
if (alarm->active)
{
time_t t;
if (alarm->date_flag)
{
t = extract_time (alarm);
}
else
{
struct tm tm;
time_t now;
if (alarm->day_mask == 0)
return;
time (&now);
localtime_r (&now, &tm);
tm.tm_hour = alarm->hour;
tm.tm_min = alarm->minute;
t = mktime (&tm);
while (t < now || !day_matches (alarm, tm.tm_mday))
{
t += 24 * 60 * 60;
localtime_r (&t, &tm);
}
alarm->year = tm.tm_year + 1900;
alarm->month = tm.tm_mon;
alarm->day = tm.tm_mday;
}
if (schedule_set_alarm (1, t, "gpe-announce\ngpe-clock --check-alarm\n", FALSE) == FALSE)
{
gpe_error_box (_("Unable to set alarm"));
alarm->active = FALSE;
}
}
}
static void
update_time_label (GtkWidget *label)
{
char buf[256];
static time_t t_stat = 0;
time_t t;
struct tm tm;
const char *time_format;
time (&t);
/* Check if we need to update, if not save power.
* Supress update if no seconds to show,
* set if time set back, 60 sec no update or new minute started. */
if (!show_seconds && t_stat && (t_stat > t) && (((t - t_stat) < 60) || (t % 60)))
return;
t_stat = t;
localtime_r (&t, &tm);
if (format == FORMAT_24)
{
time_format = show_seconds ? "<span font_desc=\"Sans\"><b>%H:%M:%S</b></span>": "<span font_desc=\"Sans\"><b>%H:%M</b></span>";
}
else
{
time_format = show_seconds ? "<span font_desc=\"Sans\"><b>%I:%M:%S%p</b></span>" : "<span font_desc=\"Sans\"><b>%I:%M%p</b></span>";
}
strftime (buf, sizeof (buf), time_format, &tm);
gtk_label_set_markup (GTK_LABEL (label), buf);
}
static void
update_time_face (void)
{
static time_t t_stat = 0;
time_t t;
struct tm tm;
const char *time_format;
time (&t);
/* Check if we need to update, if not save power.
* Supress update if no seconds to show,
* set if time set back, 60 sec no update or new minute started. */
if (!show_seconds && t_stat && (t_stat > t) && (((t - t_stat) < 60) || (t % 60)))
return;
t_stat = t;
没有合适的资源?快使用搜索试试~ 我知道了~
GPE例程GPE-CLOCK
需积分: 9 3 下载量 77 浏览量
2008-11-12
10:20:08
上传
评论
收藏 16KB GZ 举报
温馨提示
共20个文件
po:11个
dpkg_ipkg:1个
desktop:1个
GPE下用GTK+开发的例程,可方便移植到各种平台
资源推荐
资源详情
资源评论
收起资源包目录
gpe-clock-0.23.tar.gz (20个子文件)
gpe-clock-0.23
gpe-clock.png 785B
ChangeLog 772B
gpe-clock.desktop 166B
build
Makefile.dpkg_ipkg 5KB
Makefile.translation 4KB
familiar
control1 221B
po
sv.po 2KB
es.po 2KB
fr.po 2KB
de.po 2KB
sk.po 2KB
sr.po 2KB
gpe-clock.pot 1KB
ro.po 2KB
nl.po 2KB
ru.po 2KB
pt.po 2KB
cs.po 2KB
Makefile 1KB
clock.c 25KB
共 20 条
- 1
资源评论
lxrui229
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功