⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nxschedule.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 5 页
字号:
    return rec;}char *NxSchedule::Record(int catid, string cat_name){    char *rec = new char[MAXRECSIZ];    memset(rec, 0, sizeof(rec));    put16(&rec[catFields[0].offset], catid);    strcpy(&rec[catFields[1].offset], cat_name.c_str());    return rec;}//// Window Methods//Fl_Window *NxSchedule::get_main_window(){    if (mainWindow)	return mainWindow;    else	return 0;}voidNxSchedule::show_default_window(){    //    dayWindow->add((Fl_Widget*)buttonGroup);    show_window(dayWindow->GetWindowPtr());}#ifdef DO_ALARMvoidNxSchedule::MakeAlarmViewWindow(){    alarmViewWindow = new NxPimPopWindow("Alarm");    add_window((Fl_Window *) alarmViewWindow->GetWindowPtr());    {	alarm_msg =	    new NxBox(4, 19, alarmViewWindow->GetWindowPtr()->w() - 5, 25);	alarm_msg->label("Jun 9, 1974 \n One Great Date");	alarm_msg->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);	alarmViewWindow->add((Fl_Widget *) alarm_msg);    }    {	NxButton *o =	    new NxButton(BUTTON_X, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Ok");	o->callback(alarmOk_callback, this);	alarmViewWindow->add((Fl_Widget *) o);    }    {	NxButton *o = new NxButton(BUTTON_X + 5 + BUTTON_WIDTH, 90,				   BUTTON_WIDTH, BUTTON_HEIGHT, "Snooze");	o->callback(alarmSnooze_callback, this);	alarmViewWindow->add((Fl_Widget *) o);    }}voidNxSchedule::alarmSnooze_callback(Fl_Widget * w, void *l){    NxSchedule *pThis = (NxSchedule *) l;    NxTodo *note = new NxTodo;    time_t alarmTime = 0;    DPRINT("alarmSnooze_callback alarm_count [%d]\n", alarm_count_);    ExtractRecord(note, alarms[alarm_count_]);    alarmTime = time(0);    // snooze for five more minutes    alarmTime += (60 * 5);    pThis->SetAlarm(note, alarmTime);    pThis->formatAlarmMsg(alarms[--alarm_count_]);    if (0 > alarm_count_) {	alarm_count_ = -1;	pThis->show_window(dayWindow->GetWindowPtr());    } else {	pThis->show_window(alarmViewWindow->GetWindowPtr(),			   DEACTIVATE, dayWindow->GetWindowPtr());    }}voidNxSchedule::alarmOk_callback(Fl_Widget * w, void *l){    NxSchedule *pThis = (NxSchedule *) l;    DPRINT("alarmOk_callback alarm_count [%d]\n", alarm_count_);    pThis->formatAlarmMsg(alarms[--alarm_count_]);    if (0 > alarm_count_) {	alarm_count_ = -1;	pThis->show_window(dayWindow->GetWindowPtr());    } else {	pThis->show_window(alarmViewWindow->GetWindowPtr(),			   DEACTIVATE, dayWindow->GetWindowPtr());    }}voidNxSchedule::formatAlarmMsg(int recno){    NxTodo *note = new NxTodo;    char buf[30];    char tmp_buf[DESC];    char desc_buf[DESC];    DPRINT("formatAlarmMsg recno [%d]\n", recno);    ExtractRecord(note, recno);    struct tm *tt = localtime(&note->startTime);    //strftime(buf, 29,"%b %d, %y", tt);    GetDateString(buf, tt, sizeof(buf), SHORT_YEAR);    int h = tt->tm_hour;    int m = tt->tm_min;    struct tm *tt2 = localtime(&note->endTime);    sprintf(alarm_buf, "%s %d:%02d%s - %d:%02d%s\n", buf, HR_12(h), m,	    AM_PM(h), HR_12(tt2->tm_hour), tt2->tm_min, AM_PM(tt2->tm_hour));    int len = strlen(note->szDescription);    int width = 0;    int dot_width = 0;    dot_width = (int) fl_width("...");    width = (int) fl_width(note->szDescription);    if (width <= alarm_msg->w()) {	strcat(alarm_buf, note->szDescription);    } else {	strcpy(desc_buf, note->szDescription);	for (int idx = 0; idx < len; idx++) {	    if (desc_buf[idx] == '\n')		desc_buf[idx] = ' ';	    memset(tmp_buf, 0, sizeof(tmp_buf));	    strncpy(tmp_buf, desc_buf, idx);	    width = (int) fl_width(tmp_buf);	    if (width + dot_width >= alarm_msg->w() - 5) {		strcat(tmp_buf, "...");		strcat(alarm_buf, tmp_buf);		break;	    }	}    }    alarm_msg->label(alarm_buf);    alarm_msg->hide();    alarm_msg->show();    delete note;    note = 0;}voidNxSchedule::setNextAlarm(NxTodo * note){    time_t today;    time_t new_time;    time_t nEarlyDay;    time_t nLateDay;    time_t alarm_time;    int interval = 0;    int days = 0;    int weeks = 0;    int mon = 0;    int min = 0;    int sec = 0;    int hour = 0;    tm *tt;    bool found = false;    today = time(NULL);    // find next day that an alarm needs to be set    // need to check for dummy and for end date    switch (note->repeatFlag_1) {    case REPEAT_DAILY:	interval = note->repeatFlag_2;	new_time = today + (interval * 86400);	CreateDateRange(&nEarlyDay, &nLateDay, new_time, new_time);	if (0 != note->repeatFlag_3) {	    while (nEarlyDay <= note->repeatFlag_3) {		if (IsForToday(note, nEarlyDay, nLateDay)) {		    found = true;		    break;		} else {		    new_time = new_time + (interval * 86400);		    CreateDateRange(&nEarlyDay, &nLateDay, new_time,				    new_time);		}	    }	} else {	    while (nLateDay <= LONG_MAX) {		if (IsForToday(note, nEarlyDay, nLateDay)) {		    found = true;		    break;		} else {		    new_time = new_time + (interval * 86400);		    CreateDateRange(&nEarlyDay, &nLateDay, new_time,				    new_time);		}	    }	}	break;    case REPEAT_WEEKLY:	interval = note->repeatFlag_2;	weeks += interval;	tt = localtime(&today);	tt->tm_mday -= tt->tm_wday;	new_time = mktime(tt);	new_time = new_time + (interval * 86400 * 7);	days = 0;	CreateDateRange(&nEarlyDay, &nLateDay, new_time, new_time);	if (0 != note->repeatFlag_3) {	    while (nEarlyDay <= note->repeatFlag_3) {		if (IsForToday(note, nEarlyDay, nLateDay)) {		    found = true;		    break;		} else {		    if (6 == days) {	// go to next week interval			new_time = new_time + (interval * 86400 * 7);			days = 0;			weeks += interval;		    } else {			new_time += 86400;			days++;		    }		    CreateDateRange(&nEarlyDay, &nLateDay, new_time,				    new_time);		}	    }	} else {	    while (nLateDay <= LONG_MAX) {		if (IsForToday(note, nEarlyDay, nLateDay)) {		    found = true;		    break;		} else {		    if (6 == days) {	// go to next week interval			new_time = new_time + (interval * 86400 * 7);			days = 0;			weeks += interval;		    } else {			new_time += 86400;			days++;		    }		    CreateDateRange(&nEarlyDay, &nLateDay, new_time,				    new_time);		}	    }	}	break;    case REPEAT_MONTHLY:	interval = note->repeatFlag_2;	tt = localtime(&today);	tt->tm_mday = 1;	tt->tm_mon += interval;	new_time = mktime(tt);	mon = tt->tm_mon;	CreateDateRange(&nEarlyDay, &nLateDay, new_time, new_time);	if (0 != note->repeatFlag_3) {	    while (nEarlyDay <= note->repeatFlag_3) {		if (IsForToday(note, nEarlyDay, nLateDay)) {		    found = true;		    break;		} else {		    tt = localtime(&new_time);		    if (tt->tm_mon != mon) {			tt->tm_mon += interval;			new_time = mktime(tt);		    } else {			new_time += 86400;		    }		    CreateDateRange(&nEarlyDay, &nLateDay, new_time,				    new_time);		}	    }	} else {	    while (nLateDay <= LONG_MAX) {		if (IsForToday(note, nEarlyDay, nLateDay)) {		    found = true;		    break;		} else {		    tt = localtime(&new_time);		    if (tt->tm_mon != mon) {			tt->tm_mon += interval;			new_time = mktime(tt);		    } else {			new_time += 86400;		    }		    CreateDateRange(&nEarlyDay, &nLateDay, new_time,				    new_time);		}	    }	}	break;    case REPEAT_YEARLY:	interval = note->repeatFlag_2;	tt = localtime(&today);	tt->tm_year += interval;	new_time = mktime(tt);	CreateDateRange(&nEarlyDay, &nLateDay, new_time, new_time);	if (0 != note->repeatFlag_3) {	    while (nEarlyDay <= note->repeatFlag_3) {		if (IsForToday(note, nEarlyDay, nLateDay)) {		    found = true;		    break;		} else {		    tt = localtime(&new_time);		    tt->tm_year += interval;		    new_time = mktime(tt);		    CreateDateRange(&nEarlyDay, &nLateDay, new_time,				    new_time);		}	    }	} else {	    while (nLateDay <= LONG_MAX) {		if (IsForToday(note, nEarlyDay, nLateDay)) {		    found = true;		    break;		} else {		    tt = localtime(&new_time);		    tt->tm_year += interval;		    new_time = mktime(tt);		    CreateDateRange(&nEarlyDay, &nLateDay, new_time,				    new_time);		}	    }	}	break;    default:	break;    }    if (found) {	tt = localtime(&note->startTime);	hour = tt->tm_hour;	min = tt->tm_min;	sec = tt->tm_sec;	tt = localtime(&new_time);	tt->tm_hour = hour;	tt->tm_min = min;	tt->tm_sec = sec;	note->startTime = mktime(tt);;	alarm_time = GetAlarmTime(note);	SetAlarm(note, alarm_time);    }}voidNxSchedule::playAlarm(){    pid_t childpid;    db_handle *par_db = 0;    char buf[255];    int ret = 0;    char *args[4];    char *wave_path = "/usr/local/pixil/bin/waveplay";    par_db = db_openDB(db_getDefaultDB(), PAR_DB_MODE_RDONLY);    if (!par_db) {	printf("Error - Couldn't open the par database %s\n",	       db_getDefaultDB());	return;    }    ret =	par_getAppPref(par_db, "nxschedule", "alarm", "alarm", buf,		       sizeof(buf));    if (0 > ret) {	printf("Error - Couldn't get preference from par database\n");	db_closeDB(par_db);	return;    }    db_closeDB(par_db);    DPRINT("buf is [%s]\n", buf);    args[0] = wave_path;    args[1] = buf;    args[2] = "100";    args[3] = NULL;    if ((childpid = fork()) == 0) {	execv(wave_path, args);    }}voidNxSchedule::viewAlarm(int recno){    NxSchedule *pThis = (NxSchedule *) (NxApp::Instance());    db_handle *par_db = 0;    char val;    int ret;    DPRINT("in View alarm\n");    // if repeating event set next alarm    NxTodo *note = new NxTodo;    pThis->ExtractRecord(note, recno);    if (REPEAT_NONE != note->repeatFlag_1) {	pThis->setNextAlarm(note);    }    delete note;    note = 0;    if (MAX_ALARMS == pThis->alarm_count_) {	return;    }    pThis->alarms[++alarm_count_] = recno;    DPRINT("viewAlarm alarm_count_ [%d]\n", alarm_count_);    pThis->formatAlarmMsg(recno);    pThis->show_window(alarmViewWindow->GetWindowPtr(),		       DEACTIVATE, dayWindow->GetWindowPtr());    //play some musac!    par_db = db_openDB(db_getDefaultDB(), PAR_DB_MODE_RDONLY);    if (!par_db) {	printf("Error - Couldn't ope the par database %s\n",	       db_getDefaultDB());    } else {	ret =	    par_getGlobalPref(par_db, "alarms", "sound", PAR_BOOL, &val,			      sizeof(val));	if (0 > ret) {	    printf("Error - Couldn't get preference from par database\n");	    db_closeDB(par_db);	} else {	    if (val == 1)		pThis->playAlarm();	}	db_closeDB(par_db);    }}#endif /* DO_ALARM */voidNxSchedule::viewRecord(int recno){    NxTodo *note = new NxTodo;    int rec_array[1];    rec_array[0] = -1;    char c_recno[16];    sprintf(c_recno, "%d", recno);    DPRINT("c_recno: [%s]\n", c_recno);    db->Select(SCHEDULE, c_recno, 0, rec_array, 1);    if (-1 != rec_array[0]) {	recno = rec_array[0];	note->recno = recno;	((NxSchedule *) (NxApp::Instance()))->	    set_date_picker(((NxSchedule *) (NxApp::Instance()))->			    m_pCalendar);	ExtractRecord(note, recno);	NxApp::Instance()->show_window(detailsWindow->GetWindowPtr(),				       DEACTIVATE, dayWindow->GetWindowPtr());	((NxSchedule *) (NxApp::Instance()))->FillDetailForm(note,							     DESC_UPDATE);    }}voidNxSchedule::details_callback(Fl_Widget * w, void *l){    NxSchedule *pThis = (NxSchedule *) l;    NxTodo *n = 0;    if (g_SearchFlag) {	n = (NxTodo *) results_table->selected();	g_SearchFlag = false;    } else	n = (NxTodo *) table->selected();    if (n) {	n->fakeTime = pThis->m_CurrentDay;	pThis->set_date_picker(m_pCalendar);	pThis->FillDetailForm(n, DESC_UPDATE);	pThis->detailsDeleteButton->activate();	NxApp::Instance()->show_window(detailsWindow->GetWindowPtr(),				       DEACTIVATE, dayWindow->GetWindowPtr());    }}static void_FillDefaults(NxTodo * n, time_t current_day){    time_t t;    tm *tt = localtime(&current_day);    //tm * tt;    memset(n, 0, sizeof(NxTodo));    t = time(0);    //tt = localtime(&t);    tt->tm_hour = 8;    tt->tm_min = 0;    n->startTime = mktime(tt);    tt->tm_hour = 18;    tt->tm_min = 0;    n->endTime = mktime(tt);    n->fakeTime = current_day;    n->alarmInt = NO_ALARM;}voidNxSchedule::view_callback(Fl_Widget * w, void *l){    if (Fl::event_clicks()) {	if ((Fl::event_x() >= table->x()	     && Fl::event_x() <= (table->x() + table->w()))	    && (Fl::event_y() >= table->y()		&& Fl::event_y() <= (table->y() + table->h())))	    details_callback(w, l);    }    Fl::event_clicks(0);}voidNxSchedule::new_callback(Fl_Widget * w, void *l){    NxSchedule *pThis = (NxSchedule *) l;    NxTodo *n = new NxTodo;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -