📄 ui.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 <nxscroll.h>#include <FL/Fl_Pixmap.H>#include "ui.h"#include "callbacks.h"#include "menu_defs.h"#include "db_defs.h"////////////////////////////////////////////////////////////////////////////////// Global Access PointNxMail * NxMail::_inst = 0;extern int exit_flag;#ifdef NOTUSEDNxCategoryList * NxMail::main_category;NxCategoryList * NxMail::editor_category;NxCategoryList * NxMail::view_category;#endif////////////////////////////////////////////////////////////////////////////////// NxMail ConstructorNxMail::NxMail(int argc, char *argv[]) :NxApp(){ //////////////////////////////////////// // Global Access Point Initialization _inst = this; NxApp::Instance()->set_keyboard(argc, argv); NxApp::Instance()->set_about(about_email); //////////////////////////////////////// // Initialize databases#ifdef NOTUSED db = new NxDb(argc, argv); // Open or Create category database if (!db->Open((string) CAT_DB, &catFile, catFields, 0)) { if (db->Create((string) CAT_DB, &catFile, catFields, 0)) { if (!db->Open((string) CAT_DB, &catFile, catFields, 0)) { exit(-1); }#if DATABASE_OPTION_SUPPORTED char *record1 = 0; record1 = CatRecord(0, "Inbox"); db->Insert(CAT_DB, record1); delete[]record1; char *record2 = 0; record2 = CatRecord(1, "Outbox"); db->Insert(CAT_DB, record2); delete[]record2; char *record3 = 0; record3 = CatRecord(2, "Deleted"); db->Insert(CAT_DB, record3); delete[]record3; char *record4 = 0; record4 = CatRecord(3, "Filed"); db->Insert(CAT_DB, record4); delete[]record4; char *record5 = 0; record5 = CatRecord(4, "Draft"); db->Insert(CAT_DB, record5); delete[]record5;#endif } else { exit(-1); } }#endif //////////////////////////////////////// // First, create the windows containerWindow = new NxWindow(W_W, W_H, APP); MakeMainWindow(); MakeEditorWindow(); MakeSettingsWindow(); MakeViewWindow(); containerWindow->end(); //////////////////////////////////////// // Now, set up the signals to catch // exceptions // signal(SIGINT , CloseNanoMail); // signal(SIGTERM, CloseNanoMail); // signal(SIGHUP , CloseNanoMail); //////////////////////////////////////// // Now, make the calsses for the // settings and the mail server settings = new mailSettings(); settings->load_settings(); current_account = 0; engine = new mailEngine(settings-> get_value(settings->get_account_name(current_account), "server"), atoi(settings-> get_value(settings-> get_account_name(current_account), "port")), MAIL_POP3); printf("2\n"); //////////////////////////////////////// // Category lists#ifdef NOTUSED main_category = mainWindow->category_list; main_category->select(ChangeCatCB); editor_category = editorWindow->category_list; editor_category->select(ChangeCatCB); settings_category = settingsWindow->category_list; settings_category->select(ChangeAcctCB); view_category = viewWindow->category_list; view_category->select(ChangeCatCB);#endif#ifdef NOTUSED cat_list[0] = main_category; cat_list[1] = editor_category; cat_list[2] = settings_category; cat_list[3] = view_category; // add_items(table, "All"); cat_list[0]->label("All"); cat_list[1]->label("All"); cat_list[3]->label("All"); set_catlist_window((Fl_Window *) mainWindow->GetEditCategoryWindowPtr());#endif //////////////////////////////////////// // FLNX-Colosseum IPC set_shown_window(mainWindow->GetWindowPtr()); Add_Fd("nxmail", _ClientIPCHandler);}NxMail::~NxMail(){#ifdef NOTUSED db->Close(CAT_DB); delete db;#endif db = 0; if (accountArray) free(accountArray);}voidNxMail::exit_callback(Fl_Widget * fl, void *o){ exit_flag = 1; NxMail::Inst()->containerWindow->hide(); exit(0);}////////////////////////////////////////////////////////////////////////////////// Window MessagesFl_Window *NxMail::GetMainWindow(){ if (containerWindow) return containerWindow; else return 0;}voidNxMail::ShowDefaultWindow(){ show_window(mainWindow->GetWindowPtr());}////////////////////////////////////////////////////////////////////////////////// Global Access PointNxMail *NxMail::Inst(){ if (_inst == NULL) { printf("_inst is really messed up. Bail!\n"); exit(-1); } return _inst;}////////////////////////////////////////////////////////////////////////////////// Mail Engine Messageschar *NxMail::EngineGetSettings(char *szSetting){ return (settings->get_value(settings->get_account_name(current_account), szSetting));}MAILERROR NxMail::EngineOpenSession(){ return (engine-> open_session(EngineGetSettings("username"), EngineGetSettings("password")));}voidNxMail::MainShowWindow(){#ifdef NOTUSED set_catlist_window((Fl_Window *) mainWindow->GetEditCategoryWindowPtr());#endif show_window(mainWindow->GetWindowPtr());}voidNxMail::EditorShowWindow(){#ifdef NOTUSED set_catlist_window((Fl_Window *) editorWindow-> GetEditCategoryWindowPtr());#endif show_window(editorWindow->GetWindowPtr());}voidNxMail::SettingsShowWindow(){ show_window(settingsWindow->GetWindowPtr());}voidNxMail::ViewerShowWindow(){#ifdef NOTUSED set_catlist_window((Fl_Window *) viewWindow->GetEditCategoryWindowPtr());#endif show_window(viewWindow->GetWindowPtr());}MAILERROR NxMail::EngineSendMessage(char *server, int port, nxmail_header_t * header, char *body, int size){ return engine->send_message(server, port, header, body, size);}////////////////////////////////////////////////////////////////////////////////// Exception handlingvoidNxMail::CloseNanoMail(int signal){ extern char *listBuffer; printf("Shutting down Nanomail right now!\n"); m_List->clear(); if (listBuffer) free(listBuffer); delete engine; exit(0);}////////////////////////////////////////////////////////////////////////////////// Database messageschar *NxMail::CatRecord(int catid, string cat_name){ char *rec = new char[MAXRECSIZ]; memset(rec, 0, MAXRECSIZ); put16(&rec[catFields[0].offset], catid); strcpy(&rec[catFields[1].offset], cat_name.c_str()); return rec;}////////////////////////////////////////////////////////////////////////////////// FLNX-Colosseum IPC messagesvoidNxMail::ClientIPCHandler(int fd, void *o, int ipc_id){ char *tokenMsg = new char[MAX_LENGTH]; char *passMsg = new char[MAX_LENGTH]; if (o == NULL) { int length = MAX_LENGTH; ipc_id = NxApp::Instance()->Read_Fd(passMsg, &length); if (passMsg == NULL) return; else strcpy(tokenMsg, passMsg); } else if (ipc_id == -1) { strcpy(tokenMsg, (char *) o); strcpy(passMsg, (char *) o); ipc_id = NxApp::Instance()->Find_Fd("nxaddress"); } 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); strcpy(msg_cmd, tmp); // DATA_ITEM tmp = strtok(NULL, TOKEN); strcpy(data_item, tmp); // DPRINT("Expoding Message... %s, %s, %s.\n", service, msg_cmd, data_item); if (strcmp(msg_cmd, "EXECUTE") == 0) { if (!NxApp::Instance()->VerifyClient(service)) return; if (strcmp(data_item, "search") == 0) { char *searchStr = new char[MAX_LENGTH]; char *width = new char[4]; char *data = strtok(NULL, TOKEN); strcpy(searchStr, data); data = strtok(NULL, TOKEN); strcpy(width, data); // NxMail::Inst()->ExecuteSearch(ipc_id, searchStr, atoi(width)); delete[]searchStr; delete[]width; searchStr = width = NULL; } if (strcmp(data_item, "showrecord") == 0) { 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);}voidNxMail::ExecuteSearch(int ipc_id, char *searchStr, int width){}////////////////////////////////////////////////////////////////////////////////// Make Windows messagesvoidNxMail::MakeMainWindow(){ // Make a NxPimWindow printf("Opening category database [%s]\n", CAT_DB); mainWindow = new NxPimWindow(APP, mainMenuItems, 0, "", "", (void (*)(const char *)) MainSetCategory); add_window((Fl_Window *) mainWindow->GetWindowPtr()); // Message list // We're going to switch this one out with Flv_Table_Child ... later... later.HEIGHT m_List = new NxBrowser(1, 30, W_W - 5, W_H - 85); m_List->type(FL_HOLD_BROWSER); m_List->movable(false); //m_List->color(NxApp::Instance()->getGlobalColor(APP_BG)); //m_List->textcolor(NxApp::Instance()->getGlobalColor(APP_FG)); m_List->callback((Fl_Callback *) get_message_callback); mainWindow->add((Fl_Widget *) m_List); l_Status = new NxOutput(1, BUTTON_Y - BUTTON_HEIGHT - 15, W_W - 4, 15); l_Status->value("Welcome!"); l_Status->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); mainWindow->add((Fl_Widget *) l_Status); // Buttons { NxButton *o = new NxButton(BUTTON_X, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT, "New Mail"); o->callback((Fl_Callback *) new_message_callback); NxApp::Instance()->def_font((Fl_Widget *) o); mainWindow->add((Fl_Widget *) o); } { NxButton *o = new NxButton(BUTTON_X + 63, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT, "Get Mail"); o->callback((Fl_Callback *) check_mail_callback); NxApp::Instance()->def_font((Fl_Widget *) o); mainWindow->add((Fl_Widget *) o); } { NxButton *o = new NxButton(BUTTON_X + 126, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT, "Delete"); o->callback((Fl_Callback *) delete_message_callback); NxApp::Instance()->def_font((Fl_Widget *) o); mainWindow->add((Fl_Widget *) o); }}#define PDAvoidNxMail::MakeEditorWindow(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -