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

📄 nxschedule.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 5 页
字号:
    static int rec_array[255];    int jdx;    char *needle = strup(searchVal, strlen(searchVal));    if (0 == cur_record) {	for (int idx = 0; idx < 255; idx++) {	    rec_array[idx] = -1;	}	db->Select(SCHEDULE, rec_array, 255);    }    if (255 == cur_record) {	cur_record = 0;	delete[]needle;	needle = 0;	return NULL;    }    bool found = false;    NxTodo *note = new NxTodo;    while (cur_record < 255) {	found = false;	jdx = rec_array[cur_record];	if (-1 == jdx) {	    cur_record++;	    continue;	}	db->Extract(SCHEDULE, jdx, 10, note->szDescription);	char *haystack = strup(note->szDescription, DESC);	if (strstr(haystack, needle))	    found = true;	delete[]haystack;	haystack = 0;	if (true == found) {	    ExtractRecord(note, jdx);	    cur_record++;	    delete[]needle;	    needle = 0;	    return note;	} else {	    cur_record++;	    continue;	}    }    cur_record = 0;    delete[]note;    note = 0;    delete[]needle;    needle = 0;    return NULL;}bool NxSchedule::checkDate(NxTodo * note, time_t fromTime, time_t toTime){    DPRINT("In check date: fromTime[%ld], toTime[%ld\n", fromTime, toTime);    DPRINT("note startTime: [%ld] endTime: [%ld\n", note->startTime,	   note->endTime);    struct tm *	from_tm =	localtime(&fromTime);    int	fd =	from_tm->	tm_mday;    int	fm =	from_tm->	tm_mon;    int	fy =	from_tm->	tm_year;    struct tm *	to_tm =	localtime(&toTime);    int	td =	to_tm->	tm_mday;    int	tm =	to_tm->	tm_mon;    int	ty =	to_tm->	tm_year;    struct tm *	tt =	localtime(&note->startTime);    int	d =	tt->	tm_mday;    int	m =	tt->	tm_mon;    int	y =	tt->	tm_year;    struct tm *	tt2 =	localtime(&note->endTime);    int	d2 =	tt2->	tm_mday;    int	m2 =	tt2->	tm_mon;    int	y2 =	tt2->	tm_year;    if (((fd <= d) && (fm <= m) && (fy <= y))	&& ((td >= d2) && (tm >= m2) && (ty >= y2))) {	return true;    }    return false;}NxTodo *NxSchedule::searchDate(time_t fromTime, time_t toTime){    static int cur_record = 0;    static int rec_array[255];    int jdx;    if (0 == cur_record) {	for (int idx = 0; idx < 255; idx++) {	    rec_array[idx] = -1;	}	db->Select(SCHEDULE, rec_array, 255);    }    if (255 == cur_record) {	cur_record = 0;	return NULL;    }    NxTodo *note = new NxTodo;    while (cur_record < 255) {	jdx = rec_array[cur_record];	if (-1 == jdx) {	    cur_record++;	    continue;	}	ExtractRecord(note, jdx);	if (true == checkDate(note, fromTime, toTime)) {	    cur_record++;	    return note;	} else {	    cur_record++;	    continue;	}    }    cur_record = 0;    delete[]note;    note = 0;    return NULL;}voidNxSchedule::searchLookup_callback(Fl_Widget * fl, void *l){    if ((stringCheck->value() == 0) && (dateCheck->value() == 0)) {	NxApp::Instance()->show_window(errorWindow->GetWindowPtr(),				       DEACTIVATE,				       lookupWindow->GetWindowPtr());	return;    }    g_SearchFlag = true;    int total_found = 0;    char *needle = 0;    NxTodo *note = 0;    results_table->Init(255);    if (stringCheck->value() == true && dateCheck->value() == false) {	char *searchVal = (char *) lookup_input->value();	needle = strup(searchVal, strlen(searchVal));	while ((note = searchString(searchVal)) != NULL) {	    results_table->Add(total_found, note);	    char *label = formatString(note, results_table->text_width());	    results_table->set_value(total_found, 0, label);	    total_found++;	}    }    if (stringCheck->value() == false && dateCheck->value() == true) {	while ((note = searchDate(fromTime, toTime)) != NULL) {	    results_table->Add(total_found, note);	    char *label = formatString(note, results_table->text_width());	    results_table->set_value(total_found, 0, label);	    total_found++;	}    }    if (stringCheck->value() == true && dateCheck->value() == true) {	char *searchVal = (char *) lookup_input->value();	needle = strup(searchVal, strlen(searchVal));	while ((note = searchString(searchVal)) != NULL) {	    if (true == checkDate(note, fromTime, toTime)) {		results_table->Add(total_found, note);		char *label = formatString(note, results_table->text_width());		results_table->set_value(total_found, 0, label);		total_found++;	    }	}    }    delete[]needle;    needle = 0;    if (total_found == 0) {	results_message->show();	results_table->hide();    } else {	results_message->hide();	results_table->show();    }    results_table->rows(total_found);    NxApp::Instance()->show_window(dayWindow->GetWindowPtr());    NxApp::Instance()->show_window(resultsWindow->GetWindowPtr(),				   DEACTIVATE, dayWindow->GetWindowPtr());}voidNxSchedule::cancelLookup_callback(Fl_Widget * fl, void *l){    NxApp::Instance()->show_window(dayWindow->GetWindowPtr(), ACTIVATE);}voidNxSchedule::MakeResultsWindow(){    resultsWindow =	new NxPimPopWindow("Search Results",			   NxApp::Instance()->getGlobalColor(APP_FG), 5,			   (W_W / 3), W_W - 10, (W_H - (W_W / 2)));    add_window((Fl_Window *) resultsWindow->GetWindowPtr());    {	results_message = new NxOutput(4, 19, W_W - 19, 25);	results_message->value("Nothing Found.");	results_message->hide();	resultsWindow->add((Fl_Widget *) results_message);    }    {	results_table =	    new Flv_Table_Child(4, 19, (W_W - 19),				(W_H - (W_W / 2) - 3 * (BUTTON_HEIGHT)), 0,				(W_W - 25));	results_table->callback(resultsView_callback, this);	results_table->SetCols(1);	resultsWindow->add((Fl_Widget *) results_table);    }    {	NxButton *o =	    new NxButton(BUTTON_X, (W_H - (W_W / 2) - BUTTON_HEIGHT - 9),			 BUTTON_WIDTH, BUTTON_HEIGHT, "Done");	o->callback(doneLookup_callback);	resultsWindow->add((Fl_Widget *) o);    }}voidNxSchedule::doneLookup_callback(Fl_Widget * fl, void *l){    NxApp::Instance()->show_window(dayWindow->GetWindowPtr(), ACTIVATE);}voidNxSchedule::resultsView_callback(Fl_Widget * fl, void *l){    if (Fl::event_clicks()) {	resultsWindow->GetWindowPtr()->hide();	details_callback(fl, l);    }    Fl::event_clicks(0);}voidNxSchedule::MakeErrorWindow(){    errorWindow = new NxPimPopWindow("Error");    add_window((Fl_Window *) errorWindow->GetWindowPtr());    {	error_msg =	    new NxOutput(4, 19, errorWindow->GetWindowPtr()->w() - 5, 25);	error_msg->value("Error: No Search Constraint.");	errorWindow->add((Fl_Widget *) error_msg);    }    {	NxButton *o =	    new NxButton(BUTTON_X, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Ok");	o->callback(errorOk_callback);	errorWindow->add((Fl_Widget *) o);    }}voidNxSchedule::errorOk_callback(Fl_Widget * fl, void *l){    errorWindow->GetWindowPtr()->hide();    NxApp::Instance()->show_window(lookupWindow->GetWindowPtr(),				   DEACTIVATE, dayWindow->GetWindowPtr());}voidNxSchedule::edit_note(NxTodo * note, int recno){    char *record = Record(note->recno, 0, note->startTime, note->endTime,			  note->allDayFlag, note->repeatFlag_1,			  note->repeatFlag_2,			  note->repeatFlag_3, note->repeatWkMonFlag,			  note->entryType, note->szDescription,			  note->exception,			  note->recnoPtr, note->alarmInt, note->alarmFlags);    db->Edit(SCHEDULE, recno, record);    delete[]record;    record = 0;}voidNxSchedule::delete_note(NxTodo * note){    int ret[1];    char c_recno[8];    sprintf(c_recno, "%d", note->recno);    ret[0] = -1;    db->Select(SCHEDULE, c_recno, 0, ret, 1);    if (-1 != ret[0]) {	db->DeleteRec(SCHEDULE, ret[0]);    }}voidNxSchedule::save(NxTodo * note){    int ret[1];    char c_recno[8];    ret[0] = -1;    sprintf(c_recno, "%d", note->recno);    db->Select(SCHEDULE, c_recno, 0, ret, 1);    if (-1 != ret[0]) {	edit_note(note, ret[0]);    } else {	write_note(note);	delete note;    }}voidNxSchedule::write_note(NxTodo * note){    idNum = NxApp::Instance()->GetKey(db, SCHEDULE, 0) + 1;    char *record = Record(idNum, 0, note->startTime, note->endTime,			  note->allDayFlag, note->repeatFlag_1,			  note->repeatFlag_2,			  note->repeatFlag_3, note->repeatWkMonFlag,			  note->entryType, note->szDescription,			  note->exception, note->recnoPtr, note->alarmInt,			  note->alarmFlags);    db->Insert(SCHEDULE, record);    delete[]record;    record = 0;}voidNxSchedule::ExtractRecord(NxTodo * note, int nRecId){    //note->recno = nRecId;    char buf[16];    db->Extract(SCHEDULE, nRecId, 0, buf);    note->recno = atoi(buf);    db->Extract(SCHEDULE, nRecId, 1, buf);    // startHour    db->Extract(SCHEDULE, nRecId, 2, buf);    note->startTime = strtol(buf, NULL, 10);    // endHour    db->Extract(SCHEDULE, nRecId, 3, buf);    note->endTime = strtol(buf, NULL, 10);    // allDayFlag    db->Extract(SCHEDULE, nRecId, 4, buf);    note->allDayFlag = atoi(buf);    // repeatFlag #1    db->Extract(SCHEDULE, nRecId, 5, buf);    note->repeatFlag_1 = atoi(buf);    // repeatFlag #2    db->Extract(SCHEDULE, nRecId, 6, buf);    note->repeatFlag_2 = atoi(buf);    // repeatFlag #3    db->Extract(SCHEDULE, nRecId, 7, buf);    note->repeatFlag_3 = strtol(buf, NULL, 10);    // repeatWkMonFlag    db->Extract(SCHEDULE, nRecId, 8, buf);    note->repeatWkMonFlag = strtol(buf, NULL, 10);    // entryType    db->Extract(SCHEDULE, nRecId, 9, buf);    note->entryType = (entry_type) atoi(buf);    // szDescription    db->Extract(SCHEDULE, nRecId, 10, note->szDescription);    // exception    db->Extract(SCHEDULE, nRecId, 11, buf);    note->exception = atoi(buf);    // recnoPtr    db->Extract(SCHEDULE, nRecId, 12, buf);    note->recnoPtr = atoi(buf);    // alarm time    db->Extract(SCHEDULE, nRecId, 13, buf);    note->alarmInt = strtol(buf, NULL, 10);    // alarm flags    db->Extract(SCHEDULE, nRecId, 14, buf);    note->alarmFlags = atoi(buf);}voidNxSchedule::add_item(int i, Flv_Table_Child * t, NxTodo * note){    char buf[30];    // Add node to tree .. This allows the later retrieval of    // the note pointer.    t->Add(i, note);    // Add Table Cell    struct tm *tt = localtime(&note->startTime);    int h = tt->tm_hour;    int m = tt->tm_min;    struct tm *tt2 = localtime(&note->endTime);    sprintf(buf, "%d:%02d%s -\n%d:%02d%s", HR_12(h), m, AM_PM(h),	    HR_12(tt2->tm_hour), tt2->tm_min, AM_PM(tt2->tm_hour));    // This is the time range for the schedule item    t->set_value(i, 0, buf);    // This is the description for the schedule item    t->set_value(i, 1, note->szDescription);    // make sure that this description is aligned left and wrapped    t->col_style[1].align((Fl_Align) (FL_ALIGN_LEFT | FL_ALIGN_WRAP));    // Calculate the needed height of the inserted item    int wi = t->col_width(1), hi = 0;    fl_measure(note->szDescription, wi, hi);    int _wi = t->col_width(0), _hi = 0;    fl_measure(buf, _wi, _hi);    // Set the desired height for the row    t->row_height(hi > _hi ? hi : _hi, i);}// add items to the tree viewvoidNxSchedule::add_items(Flv_Table_Child * t){    // Fix me!    NxTodo *note;    int rec_array[255];    int idx = 0;    int num_recs = 0;    t->row(0);    //for (idx = 0; idx < 255; idx++) {    //  rec_array[idx] = -1;    //}    memset(rec_array, -1, sizeof(rec_array));    num_recs = db->Select(SCHEDULE, rec_array, 255);    int cnt = 0;    for (idx = 0; idx < num_recs; idx++) {	if (-1 != rec_array[idx]) {	    note = new NxTodo;	    ExtractRecord(note, rec_array[idx]);	    if (IsForToday(note))		cnt++;	    delete note;	}    }    NxTodo *notes[cnt];    for (idx = 0; idx < cnt; idx++)	notes[idx] = new NxTodo;    int num = 0;    for (idx = 0; idx < num_recs; idx++) {	if (-1 != rec_array[idx]) {	    note = new NxTodo;	    ExtractRecord(note, rec_array[idx]);	    if (IsForToday(note)) {		notes[num] = note;		num++;	    } else		delete note;	}    }    t->Init(cnt);    qsort(notes, cnt, sizeof(NxTodo *),	  (int (*)(const void *, const void *)) compar);    int li

⌨️ 快捷键说明

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