📄 nxsunclock.cxx
字号:
nxb->label(button_label[me->_ePtMode]); return;} // end of nxSunclock::set_tz_cb(Fl_Widget *, void *)#endif/*******************************************************************************\**** Function: void show_sc_win_cb()** Desc: Hides the time window and shows the sunclock window** Accepts: Fl_Widget *w = Ptr to the widget responsible for the branch** void *d = Ptr to any ancillary data** Returns: Nothing (void)**\*******************************************************************************/voidnxSunclock::show_sc_win_cb(Fl_Widget * w, void *d){ time_t nowt, // Now ctime value newt; // New ctime value struct tm curtm; // Current date/time value struct timeval tv; // Timeval structure nxSunclock *me = (nxSunclock *) d; NxButton *nxb = (NxButton *) w;#ifdef NOTUSED // Determine if anything needs to be set permanently#ifdef PROMPT_FOR_DST bool *dstval; // Dst value if (me->_eCurTzMode == tzHOME) dstval = &me->_app_settings.use_dst[(int) tzHOME]; else dstval = &me->_app_settings.use_dst[(int) tzVISIT];#endif // PROMPT_FOR_DST#endif if (!(memcmp(nxb->label(), "Save", 4))) {#ifdef PROMPT_FOR_DST // This is the ok button -- need to update everything: // 1) Check the value of the dst flag if (me->_dstbtn->value() && *dstval == false) { *dstval = true; me->_app_settings.dirty_flgs |= APP_DFLGS_DST; } // end of if else if (!(me->_dstbtn->value()) && *dstval == true) { *dstval = false; me->_app_settings.dirty_flgs |= APP_DFLGS_DST; } // end of else-if#endif // PROMPT_FOR_DST // 2) Get the date and time values from the clock/calendar widgets time(&nowt); me->_timeui->GetTime(&curtm); curtm.tm_mon = me->_cal->month() - 1; curtm.tm_mday = me->_cal->day(); curtm.tm_year = me->_cal->year() - 1900; newt = mktime(&curtm);#ifdef PROMPT_FOR_DST // Check if we need to adjust the time for dst purposes if (curtm.tm_isdst && *dstval == false) { newt -= (60 * 60); } // end of if#endif tv.tv_sec = newt; // 3) Set the system date/time if (settimeofday(&tv, 0) == -1) { } // end of if // Inform all apps via colosseum broadcast message that the system time changed char col_msg[CL_MAX_MSG_LEN] = { '\0' }; int col_len = sprintf(col_msg, "sc_clock^SYSCON_TM_CHANGE"); sysconf_ipc_write(CL_MSG_BROADCAST_ID, col_msg, col_len); } // end of if // reset the edit flag me->_clckedit = 0;#ifdef NOTUSED // Finally, hide this window and show the other. me->_timewin->hide(); me->_sunwin->show();#endif return;} // end of nxSunclock::show_sc_win_cb(Fl_Widget *, void *)#ifdef NOTUSED/*******************************************************************************\**** Function: void Sunclock_Timeout()** Desc: Response to a timer "timeout" to recalculat the position of the** sun and redraw the image on the screen.** Accepts: void *d = Ptr to any ancillary data** Returns: Nothing (void)**\*******************************************************************************/voidnxSunclock::Sunclock_Timeout(void *d){ nxSunclock *me = (nxSunclock *) d; // Draw the current sun/shadow state on the map only if the browser isn't being shown// if (!me->_selcity->Fl_Widget::visible())// { me->SetSunclock();// } // end of if Fl::add_timeout(SUNCLOCK_TIMEOUT, Sunclock_Timeout, (void *) me); return;} // end of nxSunclock::Sunclock_Timeout(void *)#endif/*******************************************************************************\**** Function: void Timer_Timeout()** Desc: Response to a timer "timeout" to allow the current time to be** updated on the screen properly** Accepts: void *d = Ptr to any ancillary data** Returns: Nothing (void)**\*******************************************************************************/voidnxSunclock::Timer_Timeout(void *d){ // Needs to set the current time for both timezones nxSunclock *me = (nxSunclock *) d; me->SetTimes(); Fl::add_timeout(0.5, Timer_Timeout, (void *) me); return;} // end of nxSunclock::Timer_Timeout(void *)#ifdef NOTUSED/*******************************************************************************\**** Function: void Toggle_tz_cb()** Desc: Toggles the current timezone between the Home/Visiting timezones** Accepts: Fl_Widget *w = Ptr to the widget responsible for the branch** void *d = Ptr to any ancillary data** Returns: Nothing (void)**\*******************************************************************************/voidnxSunclock::Toggle_tz_cb(Fl_Widget * w, void *d){ NxButton *nxb = (NxButton *) w; // So I don't have to cast... nxSunclock *me; // The object... me = (nxSunclock *) d; if (nxb == me->_tzbtns[(int) tzHOME] && me->_eCurTzMode == tzVISIT) { // Force me to be active... //me->_tzbtns[(int) tzHOME]->labelcolor(NxApp::Instance()-> // getGlobalColor(BUTTON_TEXT)); //me->_tzbtns[(int) tzVISIT]->labelcolor(NxApp::Instance()-> // getGlobalColor(APP_FG)); me->_eCurTzMode = tzHOME; me->_app_settings.home_current = true; me->_app_settings.dirty_flgs |= APP_DFLGS_CUR; } // end of if else if (nxb == me->_tzbtns[(int) tzVISIT] && me->_eCurTzMode == tzHOME) { //me->_tzbtns[(int) tzVISIT]->labelcolor(NxApp::Instance()-> //getGlobalColor(BUTTON_TEXT)); //me->_tzbtns[(int) tzHOME]->labelcolor(NxApp::Instance()-> //getGlobalColor(APP_FG)); me->_eCurTzMode = tzVISIT; me->_app_settings.home_current = false; me->_app_settings.dirty_flgs |= APP_DFLGS_CUR; } // end of else // Modify the timezone info ONLY if there is a zoneinfo // timezone available... if (me->_app_settings.cities[(int) me->_eCurTzMode].tz[0] > ' ') { // And, of course, we have access to it.... if (!access("/etc", W_OK | X_OK)) { char sysbuf[128]; // Buffer for a system() call int rc; // Result code unlink("/etc/localtime"); sprintf(sysbuf, "ln -sf /usr/share/zoneinfo/%s /etc/localtime", me->_app_settings.cities[(int) me->_eCurTzMode].tz); if ((rc = system(sysbuf)) != -1 && rc != 0x7f) { // The system call succeeded, send a colosseum message... } // end of if } // end of if } // end of if return;} // end of nxSunclock::Toggle_tz_cb(Fl_Widget *, void *)#endif/*******************************************************************************\**** Function: void upd_tm_cb()** Desc: Updates the clock with the current values of _timeui** Accepts: Fl_Widget *w = Ptr to the widget responsible for branch** void *d = Ptr to any ancillary data** Returns: Nothing (void)**\*******************************************************************************/voidnxSunclock::upd_tm_cb(Fl_Widget * w, void *d){ struct tm tmv; nxSunclock *me = (nxSunclock *) d;// NxTmUnit *tu = (NxTmUnit *)w; // Stop update of the clock me->_clckedit = 1; me->_timeui->GetTime(&tmv); me->_tclock->value(tmv.tm_hour, tmv.tm_min, tmv.tm_sec); return;} // end of #ifdef NOTUSED//-------------------------------------------------------------------------------//// Non-Class functions////-------------------------------------------------------------------------------/*******************************************************************************\**** Function: void ExpandTimeZone()** Desc: Expands the timezone from the hashdb values to the zoneinfo** values.** Accepts: char *dst = Storage for the new timezone** char *src = Encoded timezone value (2 char dir, 5 char file)** int dzise = Size of the destination** Returns: Nothing (void)**\*******************************************************************************/voidExpandTimeZone(char *dst, char *src, int dsize){ char dirbuf[255]; // Directory buffer int len = 0; // Length DIR *tzdir; // Directory handle struct dirent *dir; // Directory entry // Open the main directory, and find the matching one strcpy(dirbuf, "/usr/share/zoneinfo"); tzdir = opendir(dirbuf); while (tzdir && (dir = readdir(tzdir)) != NULL) { if (!memcmp(dir->d_name, src, 2)) { strcat(dirbuf, "/"); strcat(dirbuf, dir->d_name); len = snprintf(dst + len, dsize - len, "%s", dir->d_name); closedir(tzdir); tzdir = opendir(dirbuf); while (tzdir && (dir = readdir(tzdir)) != NULL) { if (!memcmp(dir->d_name, src + 2, 5)) { snprintf(dst + len, dsize - len, "/%s", dir->d_name); break; } // end of if } // end of while */ break; } // end of if } // end of while closedir(tzdir); return;} // end of ExpandTimeZone(char *, char *)/*******************************************************************************\**** Function: void parsecity** Desc: Parses the city timezone info as stored in par for the home** and visiting timezone records.** Accepts: char *data = data to parse** city_rec_t *crec = Ptr to a city record structure** Returns: Nothing (void)**\*******************************************************************************/static voidparsecity(char *data, city_rec_t * crec){ char *cp, // Generic pointer *vect[3]; // Vector int cnt, // Number of fields i; // Loop iterate if (!data || !crec) return; vect[0] = crec->name; vect[1] = crec->reg; vect[2] = crec->tz; for (cnt = 1, cp = data; *cp; cp++) { if (*cp == ',') { *cp = '\0'; cnt++; } // end of if } // end of for for (i = 0, cp = data; i < cnt; i++, cp += strlen(cp) + 1) { strcpy(vect[i], cp); } // end of for return;} // end of void/*******************************************************************************\**** Function: GetCityList()** Desc: Gets a list of cities that are within +- 5 degrees lat,long of ** the current point.** Accepts: char *zndb = Path to the database** int latitude = latitude of current point** int longitude = longitude of current point** Returns: int; number of cities found.**\*******************************************************************************/static intGetCityList(char *zndb, int latitude, int longitude){ int cnt = 0, // Number of records found i, // Loop iterator lon_val, // Longitude value mode; // Find mode hashdb_t *hdbd; // Handle to the hashdb h_data_rec record; // Record struct // Clean out the static list if (city_size) memset(city_list, 0, (city_size * sizeof(h_data_rec))); // Open the database if ((hdbd = h_opendb(zndb, O_RDONLY)) == NULL) return (-1); for (i = latitude - DEG_ADJ_VAL; i < latitude + DEG_ADJ_VAL; i++) { mode = HDB_KEY_HASH; while (h_getrecord(mode, hdbd, (mode == HDB_KEY_HASH ? i + 90 : record.next), &record) != -1) { mode = HDB_KEY_DATA; lon_val = record.lon / 60; if (lon_val >= longitude - DEG_ADJ_VAL && lon_val <= longitude + DEG_ADJ_VAL) { /* Add city to list */ if (cnt + 1 >= city_size) { if (city_size == 0) { city_list = (h_data_rec *) calloc(5, sizeof(h_data_rec)); if (city_list == NULL) return (-1); } // end of if else { h_data_rec *tmp; tmp = (h_data_rec *) realloc(city_list, (city_size + 5) * sizeof(record)); if (tmp == NULL) return (-1); city_list = tmp; } // end of else city_size += 5; } // end of if memcpy(&city_list[cnt], &record, sizeof(h_data_rec)); cnt++; } /* end of if */ } /* end of while */ } /* end of for */ h_closedb(hdbd); // Possibly sort the list??? return (cnt);} // end of void GetCityList(char *, int, int)#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -