📄 nxtodo.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 <pixil_config.h>#include <FL/Fl.H>#include "nxtodo.h"#include <nxbox.h>#include <icons/echeck.xpm>#include <icons/check.xpm>#ifdef DEBUG#define DPRINT(str, args...) printf("NXTODO DEBUG: " str, ## args)#else#define DPRINT(args...)#endif#define TODO "td"#define PRIORITY "td_priority"#define CATEGORY "td_category"#define NX_INIFILE "td_"extern int exit_flag;about about_todo = { "About ToDo", "(c) 2001, Century Software.", "jeffm@censoft.com", "08/24/2001", "1.0"};////////////// Database// Contactsfield tdFields[] = { {'i', 1, 0}, // Field 0:Id {'i', 1, 0}, // 1:CategoryId {'i', 1, 0}, // 2:Complete {'i', 1, 0}, // 3:Priority {'c', TITLE, 0}, // 4:Title {'c', DESC, 0}, // 5:File Name {'l', 1, 0}, // 6:time {0}};// Databasefildes tdFile = { // system file 0, 0, 0, // database file "dbf", // extension 7, // nfields &tdFields[0] // fieldlist};// Priority Database#define PRI_TYPE 10// Infofield pFields[] = { {'i', 1, 0}, // Field 0:pri_id {'c', PRI_TYPE, 0}, // 1:pri_type {0}};// Databasefildes pFile = { 0, 0, 0, "dbf", 2, &pFields[0]};#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]};Fl_Menu_Item todoMenuItem[] = { {"Record", 0, 0, 0, FL_SUBMENU}, {"Delete Task", 0, NxTodoList::delList_callback}, {"Purge", 0, NxTodoList::purge_callback, 0, FL_MENU_DIVIDER}, {"Exit ToDo", 0, NxTodoList::exit_callback}, {0}, {"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}, // { "Select All"}, // { "Keyboard", 0, NxApp::keyboard_callback}, {0}, {"Options", 0, 0, 0, FL_SUBMENU}, //{ "Font"}, {"Search", 0, NxTodoList::lookup_callback}, {"About ToDo", 0, NxApp::show_about}, {0}, {0},};Fl_Menu_Item editMenuItem[] = { {"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}, {"Exit ToDo", 0, NxTodoList::exit_callback}, {0}, {"Options", 0, 0, 0, FL_SUBMENU}, //{ "Font"}, //{ "Phone Lookup"}, {"About ToDo", 0, NxApp::show_about}, {0}, {0},};NxWindow * NxTodoList::main_window;NxPimWindow * NxTodoList::todo_list_window;NxPimWindow * NxTodoList::todo_edit_window;//NxCalendar * NxTodoList::m_pDatePickerCalendar;NxPimPopWindow * NxTodoList::todo_dellist_window;NxPimPopWindow * NxTodoList::todo_results_window;//NxPimPopWindow * NxTodoList::todo_lookup_window;NxPimWindow * NxTodoList::todo_lookup_window;NxPimPopWindow * NxTodoList::due_date_window;//NxPimPopWindow * NxTodoList::date_window;NxPimWindow * NxTodoList::date_window;NxPimPopWindow * NxTodoList::error_window;int NxTodoList::fd;int NxTodoList::id;int NxTodoList::g_EditFlag;int NxTodoList::date_type;char * NxTodoList::nx_inidir;NxDb * NxTodoList::db;NxCategoryList * NxTodoList::cat_list[CAT_NUM];Fl_Editor * NxTodoList::g_editor;NxTodo * NxTodoList::g_CurrentNote;NxCategoryList * NxTodoList::note_category;NxCategoryList * NxTodoList::edit_category_list;Fl_Toggle_Tree * NxTodoList::tree;NxMenuButton * NxTodoList::edit_priority_list;NxInput * NxTodoList::edit_title;NxInput * NxTodoList::lookup_input;NxCheckButton * NxTodoList::edit_complete;NxScroll * NxTodoList::note_list;Fl_Pixmap * NxTodoList::echeck_pixmap;Fl_Pixmap * NxTodoList::check_pixmap;bool NxTodoList::g_SearchFlag;bool NxTodoList::AllFlag;Flv_Table_Child * NxTodoList::results_table;NxOutput * NxTodoList::results_message;NxOutput * NxTodoList::error_msg;NxButton * NxTodoList::due_date;NxButton * NxTodoList::chooseDate;NxButton * NxTodoList::toDateButton;NxButton * NxTodoList::fromDateButton;NxCheckButton * NxTodoList::stringCheck;NxCheckButton * NxTodoList::dateCheck;NxRadioRoundButton * NxTodoList::todayDateRadio;NxRadioRoundButton * NxTodoList::tomorrowDateRadio;NxRadioRoundButton * NxTodoList::noDateRadio;NxRadioRoundButton * NxTodoList::chooseDateRadio;NxRadioRoundButton * NxTodoList::EoWDateRadio;time_t NxTodoList::set_time;time_t NxTodoList::toTime;time_t NxTodoList::fromTime;NxTodoList::NxTodoList(int argc, char *argv[]) :NxApp(){ db = new NxDb(argc, argv); optind = 1; NxApp::Instance()->set_keyboard(argc, argv); nx_inidir = db->GetPath(); NxApp::Instance()->set_about(about_todo); g_EditFlag = 0; // Open or Create contacts database if (!db->Open(TODO, &tdFile, tdFields, 0)) { if (db->Create(TODO, &tdFile, tdFields, 0)) { if (!db->Open(TODO, &tdFile, tdFields, 0)) { exit(-1); } } else { exit(-1); } } // Database opened or created successfully, get number of records. int recno = db->NumRecs(TODO); id = recno; if (recno > 1) { char buf[4]; db->Extract(TODO, recno, 0, buf); id = atoi(buf); } // Open or Create priority database if (!db->Open(PRIORITY, &pFile, pFields, 0)) { if (db->Create(PRIORITY, &pFile, pFields, 0)) { if (!db->Open(PRIORITY, &pFile, pFields, 0)) { exit(-1); } char *record = 0; record = Record(0, "High", 0); db->Insert(PRIORITY, record); record = Record(1, "Medium", 0); db->Insert(PRIORITY, record); record = Record(2, "Normal", 0); db->Insert(PRIORITY, record); record = Record(3, "Low", 0); db->Insert(PRIORITY, record); record = Record(4, "Very Low", 0); db->Insert(PRIORITY, record); delete[]record; record = 0; } else { exit(-1); } } // Open or Create category database if (!db->Open(CATEGORY, &catFile, catFields, 0)) { if (db->Create(CATEGORY, &catFile, catFields, 0)) { if (!db->Open(CATEGORY, &catFile, catFields, 0)) { exit(-1); } char *record = 0; record = Record(0, "Unfiled"); db->Insert(CATEGORY, record); record = Record(1, "Business"); db->Insert(CATEGORY, record); record = Record(2, "Personal"); db->Insert(CATEGORY, record); delete[]record; record = 0; } else { exit(-1); } } main_window = new NxWindow(W_W, W_H, APP_NAME); make_list_window(); make_edit_window(); make_dellist_window(); make_lookup_window(); make_results_window(); make_due_date_window(); //m_pDatePickerCalendar->MakeDateWindow(); //date_window = m_pDatePickerCalendar->GetDateWindow(); //dd_window((Fl_Window*)date_window->GetWindowPtr()); MakeCalendarWindow(); make_error_window(); main_window->end(); note_category = todo_list_window->category_list; note_category->select(category_callback); edit_category_list = todo_edit_window->category_list; edit_category_list->select(list_callback); set_shown_window(todo_list_window->GetWindowPtr()); echeck_pixmap = new Fl_Pixmap(echeck_xpm); check_pixmap = new Fl_Pixmap(check_xpm); cat_list[0] = note_category; cat_list[1] = edit_category_list; fill_categories(); add_items(tree, "All"); set_catlist_window((Fl_Window *) todo_list_window-> GetEditCategoryWindowPtr()); date_type = TODAY; int file_fields[1]; file_fields[0] = 5; SyncRegisterDB(db, tdFields, TODO, 1, file_fields, 1); SyncRegisterDB(db, catFields, CATEGORY, 0, NULL, 0); SyncRegisterDB(db, pFields, PRIORITY, 2, NULL, 0);#ifdef CONFIG_COLOSSEUM // FLNX-Colosseum IPC fd = Add_Fd("nxtodo", _ClientIPCHandler);#else ExecuteShow();#endif}NxTodoList::~NxTodoList(){ db->Close(TODO); db->Close(PRIORITY); db->Close(CATEGORY); delete db; db = 0;}voidNxTodoList::Refresh(){ set_category(edit_category_list->label());}//// FLNX-Colosseum IPC Methods//#ifdef CONFIG_COLOSSEUMvoidNxTodoList::RestartIPC(void *o){ DPRINT("ReconnectIPC()...\n"); fd = NxApp::Instance()->Add_Fd("nxtodo", _ClientIPCHandler); if (fd < 0) { Fl::add_timeout(10.0, RestartIPC); }}voidNxTodoList::ClientIPCHandler(int fd, void *o, int ipc_id){ DPRINT("\n"); DPRINT("ClientIPCHandler has now been started with message %s.\n", (char *) o); char *tokenMsg = new char[MAX_LENGTH]; char *passMsg = new char[MAX_LENGTH]; if (o == NULL) { DPRINT("Read_Fd() called.\n"); int length = MAX_LENGTH - 1; ipc_id = NxApp::Instance()->Read_Fd(passMsg, &length); if (ipc_id < 0) { NxApp::Instance()->Remove_Fd(fd); Fl::add_timeout(10.0, RestartIPC); return; } DPRINT("And this is the message... %s, %d bytes.\n", passMsg, length); if ((passMsg == NULL) || (passMsg[0] == 0)) return; else strcpy(tokenMsg, passMsg); } else if (ipc_id == -1) { strcpy(tokenMsg, (char *) o); strcpy(passMsg, (char *) o); ipc_id = NxApp::Instance()->Find_Fd("nxtodo"); DPRINT("And this is the message... %s.\n", passMsg); } else { strcpy(tokenMsg, (char *) o); strcpy(passMsg, (char *) o); } // Explode Message char *service = new char[MAX_LENGTH]; char *msg_cmd = new char[MAX_LENGTH]; char *data_item = new char[MAX_LENGTH]; // SERVICE char *tmp = strtok(tokenMsg, TOKEN); strcpy(service, tmp); // MSG_CMD tmp = strtok(NULL, TOKEN); if (NULL != tmp) strcpy(msg_cmd, tmp); // DATA_ITEM tmp = strtok(NULL, TOKEN); if (NULL != tmp) strcpy(data_item, tmp); DPRINT("Expoding Message... %s, %s, %s.\n", service, msg_cmd, data_item); if (strcmp(msg_cmd, "EXECUTE") == 0) { DPRINT("EXECUTE message command recv.\n"); if (!NxApp::Instance()->VerifyClient(service)) return; if (strcmp(data_item, "search") == 0) { DPRINT("%s, %s, %s\n", service, msg_cmd, data_item); char *searchStr = new char[MAX_LENGTH]; char *width = new char[4]; char *startStr = new char[16]; char *endStr = new char[16]; tmp = strtok(NULL, TOKEN); if (NULL != tmp) strcpy(searchStr, tmp); tmp = strtok(NULL, TOKEN); if (NULL != tmp) strcpy(width, tmp); tmp = strtok(NULL, TOKEN); if (NULL == tmp) ExecuteStringSearch(ipc_id, searchStr, atoi(width)); else { strcpy(startStr, tmp); long startTime = strtol(startStr, NULL, 10); tmp = strtok(NULL, TOKEN); if (NULL != tmp) strcpy(endStr, tmp); long endTime = strtol(endStr, NULL, 10); ExecuteStringDateSearch(ipc_id, searchStr, atoi(width), startTime, endTime); } delete[]startStr; delete[]endStr; delete[]searchStr; delete[]width; searchStr = width = endStr = startStr = NULL; } if (strcmp(data_item, "datesearch") == 0) { char *startStr = new char[16]; char *endStr = new char[16]; char *width = new char[8]; tmp = strtok(NULL, TOKEN); if (NULL != tmp) strcpy(width, tmp); tmp = strtok(NULL, TOKEN); if (NULL != tmp) strcpy(startStr, tmp); tmp = strtok(NULL, TOKEN); if (NULL != tmp) strcpy(endStr, tmp); long startTime = strtol(startStr, NULL, 10); long endTime = strtol(endStr, NULL, 10); ExecuteDateSearch(ipc_id, atoi(width), startTime, endTime); delete[]startStr; delete[]endStr; delete[]width; startStr = endStr = width = 0; } if (0 == strcmp(data_item, "showrecord")) { int recno = 0; char *data = strtok(NULL, TOKEN); recno = atoi(data); viewRecord(recno); } } // Memory Mangement delete[]service; delete[]msg_cmd; delete[]data_item; delete[]tokenMsg; service = msg_cmd = data_item = tokenMsg = NULL; NxApp::Instance()->ServerIPCHandler(fd, ipc_id, (char *) passMsg); delete[]passMsg; passMsg = NULL;}voidNxTodoList::ExecuteStringSearch(int ipc_id, char *searchStr, int width){ if (searchStr == NULL) return; char *msg = new char[MAX_LENGTH]; NxTodo *note; while ((note = searchString(searchStr)) != NULL) { char *result = formatLabel(note, width, true); // Send DATA message to client // (e.g. "nxtodo^DATA^1^Century *Software* is neato^") strcpy(msg, "nxtodo^DATA^search^"); //strcat(msg, note->szId); char id[4]; sprintf(id, "%d", note->nId); strcat(msg, id); strcat(msg, "^"); strcat(msg, result); strcat(msg, "^"); int length = MAX_LENGTH; NxApp::Instance()->Write_Fd(ipc_id, msg, length); } strcpy(msg, "nxtodo^ACK^DATA^search^"); NxApp::Instance()->Write_Fd(ipc_id, msg, MAX_LENGTH); delete[]msg; msg = NULL;}voidNxTodoList::ExecuteStringDateSearch(int ipc_id, char *searchStr, int width, long startTime, long endTime){ if (NULL == searchStr) return; char *msg = new char[MAX_LENGTH]; NxTodo *note; while ((note = searchString(searchStr)) != NULL) { if (true == checkDate(note, (time_t) startTime, (time_t) endTime)) { char *result = formatLabel(note, width, true); // Send DATE message to client strcpy(msg, "nxtodo^DATA^search^");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -