📄 nxschedule.cxx
字号:
/* * Copyright (c) 2003 Century Software, Inc. All Rights Reserved. * * This file is part of the PIXIL Operating Environment * * The use, copying and distribution of this file is governed by one * of two licenses, the PIXIL Commercial License, or the GNU General * Public License, version 2. * * Licensees holding a valid PIXIL Commercial License may use this file * in accordance with the PIXIL Commercial License Agreement provided * with the Software. Others are governed under the terms of the GNU * General Public License version 2. * * This file may be distributed and/or modified under the terms of the * GNU General Public License version 2 as published by the Free * Software Foundation and appearing in the file LICENSE.GPL included * in the packaging of this file. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the government is subject to * restriction as set forth in paragraph (b)(3)(b) of the Rights in * Technical Data and Computer Software clause in DAR 7-104.9(a). * * See http://www.pixil.org/gpl/ for GPL licensing * information. * * See http://www.pixil.org/license.html or * email cetsales@centurysoftware.com for information about the PIXIL * Commercial License Agreement, or if any conditions of this licensing * are not clear to you. */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <signal.h>#include <ctype.h>#include <pixil_config.h>#include <par/par.h>#include "nxschedule.h"#if defined(CONFIG_APP_ALARM) && defined(CONFIG_COLOSSEUM)#define DO_ALARM 1#endif#ifdef DEBUG#define DPRINT(str, args...) printf("DEBUG: " str, ## args)#else#define DPRINT(args...)#endifextern int exit_flag;about about_schedule = { "About Scheduler", "(c) 2001, Century Software.", "jasonk@censoft.com", "08/24/01", "1.1"};////////////// Database // Schedulefield sFields[] = { {'i', 1, 0}, // Field 0:id {'i', 1, 0}, // 1:categoryId {'l', 1, 0}, // 2:startTime {'l', 1, 0}, // 3:endTime {'i', 1, 0}, // 4:allDayFlag {'i', 1, 0}, // 5:repeatFlag 1 (day, week, month, year) {'i', 1, 0}, // 6:repeatFlag 2 {'l', 1, 0}, // 7:repeatFlag 3 {'l', 1, 0}, // 8:repeatWkMonFlag {'i', 1, 0}, // 9:entryType {'c', DESC, 0}, // 10:description {'i', 1, 0}, // 11:execption {'i', 1, 0}, // 12:recno pointer {'i', 1, 0}, // 13:alarm interval {'i', 1, 0}, // 14:alarm_flags {0}};// Databasefildes sFile = { // system file 0, 0, 0, // database file "dbf", // extension 15, // nfields &sFields[0] // fieldlist};#define CAT_NAME 10// Category Listfield catFields[] = { {'i', 1, 0}, // Field 0:catid {'c', CAT_NAME, 0}, // 1:cat_name {0}};// Databasefildes catFile = { 0, 0, 0, "dbf", 2, &catFields[0]};// MenusFl_Menu_Item schedMenuItems[] = { {"Edit", 0, 0, 0, FL_SUBMENU}, {"Undo", 0, NxApp::undo_callback}, {"Cut", 0, NxApp::cut_callback}, {"Copy", 0, NxApp::copy_callback}, {"Paste", 0, NxApp::paste_callback, 0, FL_MENU_DIVIDER}, // { "Select All"}, // { "Keyboard", 0, NxApp::keyboard_callback, 0, FL_MENU_DIVIDER}, {"Exit Scheduler", 0, NxSchedule::exit_callback}, {0}, {"Options", 0, 0, 0, FL_SUBMENU}, //{ "Font"}, //{ "Phone Lookup"}, {"Search", 0, NxSchedule::lookup_callback}, {"About Scheduler", 0, NxApp::show_about}, {0}, {0},};NxDb * NxSchedule::db;int NxSchedule::idNum;int NxSchedule::g_EditFlag;#ifdef DO_ALARMint NxSchedule::alarm_count_;int NxSchedule::alarms[MAX_ALARMS];char NxSchedule::alarm_buf[255];#endifNxWindow * NxSchedule::mainWindow;NxPimWindow * NxSchedule::dayWindow;NxPimWindow * NxSchedule::monthWindow;NxPimWindow * NxSchedule::setTimeWindow;NxPimWindow * NxSchedule::weekViewWindow;NxPimWindow * NxSchedule::monthViewWindow;NxPimWindow * NxSchedule::yearViewWindow;//NxPimPopWindow * NxSchedule::repeatWindow;NxPimWindow * NxSchedule::repeatWindow;NxPimPopWindow * NxSchedule::detailsWindow;//NxPimPopWindow * NxSchedule::timeWindow;NxPimWindow * NxSchedule::timeWindow;//NxPimPopWindow * NxSchedule::dateWindow;NxPimWindow * NxSchedule::dateWindow;//NxPimPopWindow * NxSchedule::weekDateWindow;NxPimWindow * NxSchedule::weekDateWindow;NxPimPopWindow * NxSchedule::deleteWindow;NxPimPopWindow * NxSchedule::resultsWindow;//NxPimPopWindow * NxSchedule::lookupWindow;NxPimWindow * NxSchedule::lookupWindow;NxPimPopWindow * NxSchedule::errorWindow;NxPimPopWindow * NxSchedule::repeatEventWindow;#ifdef DO_ALARMNxPimPopWindow * NxSchedule::alarmViewWindow;#endifFlv_Table_Child * NxSchedule::table;Flv_Table_Child * NxSchedule::results_table;NxCategoryList * NxSchedule::dayCat;NxCategoryList * NxSchedule::weekCat;NxCategoryList * NxSchedule::detailsCat;NxCategoryList * NxSchedule::setTimeCat;NxCategoryList * NxSchedule::cat_list[CAT_NUM];NxCalendar * NxSchedule::pCalendar;NxCalendar * NxSchedule::m_pCalendar;NxWeekCalendar * NxSchedule::w_pCalendar;NxMonthCalendar * NxSchedule::pMonthCal;NxYearCal * NxSchedule::pYearCal;NxInput * NxSchedule::lookup_input;NxIntInput * NxSchedule::every_input;#ifdef DO_ALARMNxIntInput * NxSchedule::m_pDetailsAlarmInput;#endifNxMenuButton * NxSchedule::end_list;#ifdef DO_ALARMNxMenuButton * NxSchedule::m_pDetailsAlarmInt;#endifNxOutput * NxSchedule::results_message;NxOutput * NxSchedule::error_msg;NxBox * NxSchedule::monYearBox;#ifdef DO_ALARMNxBox * NxSchedule::alarm_msg;#endifNxBox * NxSchedule::weekBox;NxBox * NxSchedule::repeat_output;NxBox * NxSchedule::message_output;NxBox * NxSchedule::every_box;NxBox * NxSchedule::list_box;NxBox * NxSchedule::week_box;NxBox * NxSchedule::month_box;NxCheckButton * NxSchedule::stringCheck;NxCheckButton * NxSchedule::dateCheck;#ifdef DO_ALARMNxCheckButton * NxSchedule::m_pDetailsAlarmCheck;#endifNxButton * NxSchedule::fromDateButton;NxButton * NxSchedule::toDateButton;//NxButton * NxSchedule::dailyButton;//NxButton * NxSchedule::weeklyButton;//NxButton * NxSchedule::monthlyButton;//NxButton * NxSchedule::yearlyButton;NxButton * NxSchedule::no_repeat;NxButton * NxSchedule::day_repeat;NxButton * NxSchedule::week_repeat;NxButton * NxSchedule::month_repeat;NxButton * NxSchedule::year_repeat;NxButton * NxSchedule::month_day;NxButton * NxSchedule::month_date;NxButton * NxSchedule::detailsDeleteButton;//Fl_Group * NxSchedule::buttonGroup;time_t NxSchedule::fromTime;time_t NxSchedule::toTime;bool NxSchedule::g_SearchFlag;// This will update the day display with the information contained// in m_CurrentDay (a time_t) This is only applicable for the day// display window. This will also add items to the main display.voidNxSchedule::UpdateDateDisplay(){ tm *tt = localtime(&m_CurrentDay); static char buf[30]; //strftime(buf,29,"%b %d, %y",tt); GetDateString(buf, tt, sizeof(buf), SHORT_YEAR); dayWindow->menu_button->label(buf); dayWindow->menu_button->redraw(); // reset all the day buttons to be off for (int i = 0; i < 7; i++) m_DayButtons[i]->value(0); // set the new day button on m_DayButtons[tt->tm_wday]->value(1); UpdateWeekView(); if (weekGrid) { weekGrid->redraw(); weekGrid->hide(); weekGrid->show(); } add_items(table);}voidNxSchedule::UpdateWeekView(){ static char temp_date[30]; static char date[30]; static char week_num[30]; static char month_str[75]; int week = 0; int wday = 0; int idx = 0; time_t new_time; struct tm *tt = localtime(&m_CurrentDay); int month = tt->tm_mon; struct tm *temp_tt = localtime(&m_CurrentDay); wday = tt->tm_wday; strftime(date, 29, "%b '%Y", tt); strftime(week_num, 29, "%V", tt); week = atoi(week_num); // check forward from day sprintf(month_str, "%s", date); for (idx = wday; idx < 7; idx++) { if (idx - 1 < wday) continue; else { temp_tt->tm_mday++; new_time = mktime(temp_tt); temp_tt = localtime(&new_time); if (month != temp_tt->tm_mon) { if (week == 1 || week == 53) { strftime(temp_date, 29, "%b '%Y", temp_tt); tt = localtime(&m_CurrentDay); strftime(date, 29, "%b '%Y", tt); sprintf(month_str, "%s - %s", date, temp_date); break; } else { strftime(temp_date, 29, "%b '%Y", temp_tt); tt = localtime(&m_CurrentDay); strftime(date, 29, "%b", tt); sprintf(month_str, "%s - %s", date, temp_date); break; } } } } // check backward from day tt = localtime(&m_CurrentDay); temp_tt = localtime(&m_CurrentDay); for (idx = wday; idx >= 0; idx--) { if (idx + 1 > wday) continue; else { temp_tt->tm_mday--; new_time = mktime(temp_tt); temp_tt = localtime(&new_time); if (month != temp_tt->tm_mon) { if (week == 1 || week == 53) { strftime(temp_date, 29, "%b '%Y", tt); tt = localtime(&m_CurrentDay); strftime(date, 29, "%b '%Y", tt); sprintf(month_str, "%s - %s", temp_date, date); break; } else { strftime(temp_date, 29, "%b", temp_tt); tt = localtime(&m_CurrentDay); strftime(date, 29, "%b '%Y", tt); sprintf(month_str, "%s - %s", temp_date, date); break; } } } } monYearBox->label(month_str); monYearBox->redraw(); sprintf(week_num, "Week %d", week); weekBox->label(week_num); weekBox->redraw(); UpdateWeekViewButtons();}voidNxSchedule::UpdateFromButton(){ static char buf[30]; tm *tt = localtime(&fromTime); //strftime(buf, 29, "%b %d, %y", tt); GetDateString(buf, tt, sizeof(buf), SHORT_YEAR); fromDateButton->label(buf); fromDateButton->redraw();}voidNxSchedule::UpdateToButton(){ static char buf[30]; tm *tt = localtime(&toTime); //strftime(buf, 29, "%b %d, %y", tt); GetDateString(buf, tt, sizeof(buf), SHORT_YEAR); toDateButton->label(buf); toDateButton->redraw();}NxSchedule::NxSchedule(int argc, char *argv[]) :NxApp(){ NxApp::Instance()->set_about(about_schedule); m_CurrentDay = time(0);#ifdef DO_ALARM alarm_count_ = -1; memset(alarms, 0, sizeof(alarms));#endif db = new NxDb(argc, argv); optind = 1; NxApp::Instance()->set_keyboard(argc, argv); g_EditFlag = 0; idNum = 0; // Open or Create schedule database if (!db->Open(SCHEDULE, &sFile, sFields, 0)) { if (db->Create(SCHEDULE, &sFile, sFields, 0)) { if (!db->Open(SCHEDULE, &sFile, sFields, 0)) { exit(-1); }#ifdef CONFIG_SAMPLES time_t t; t = time(0); char *record = 0; record = Record(0, // id 0, // catid t, // startTime t + 3600, // endTime 0, // allDayFlag 0, 0, 0, 0, // repeatWkMonflag APPT, // eventType "Meeting with Gandalf.", 0, 0, 0, 0); db->Insert(SCHEDULE, record);#ifdef NOTUSED put16(&record[sFields[0].offset], 1); db->Insert(SCHEDULE, record); put16(&record[sFields[0].offset], 2); db->Insert(SCHEDULE, record); put16(&record[sFields[0].offset], 3); db->Insert(SCHEDULE, record); put16(&record[sFields[0].offset], 4); db->Insert(SCHEDULE, record); put16(&record[sFields[0].offset], 5); db->Insert(SCHEDULE, record); put16(&record[sFields[0].offset], 6); db->Insert(SCHEDULE, record); put16(&record[sFields[0].offset], 7); db->Insert(SCHEDULE, record); put32(&record[sFields[2].offset], t + 86400); put16(&record[sFields[0].offset], 8); db->Insert(SCHEDULE, record); put16(&record[sFields[0].offset], 9); db->Insert(SCHEDULE, record); put16(&record[sFields[0].offset], 10); db->Insert(SCHEDULE, record);#endif delete[]record; record = 0;#endif } else { exit(-1); } } // Database opened or created successfully, get number of records. idNum = GetKey(db, SCHEDULE, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -