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

📄 sync_ui.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/*                                                                        * 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 <par/par.h>#include <wm/scrtoplib.h>#include <sync/coder.h>#include <sync/msg_defs.h>#include "sync.h"#include <stdio.h>//#define DEBUG#ifdef DEBUG#define DPRINT(str, args...) printf("SYNC DEBUG: " str, ## args)#else#define DPRINT(args...)#endifabout about_sync = {    "About Synchronization",    "(c) 2001, Century Software.",    "trumanl@censoft.com",    "11/30/01",    "1.0"};Fl_Menu_Item syncMenuItems[] = {    {"Exit Synchronization", 0, Sync::exit_callback}    ,    {"Options", 0, 0, 0, FL_SUBMENU}    ,    {"About Synchronization", 0, NxApp::show_about}    ,    {0}    ,    {0}};NxWindow *    Sync::mainWindow;NxPimWindow *    Sync::syncWindow;NxPimPopWindow *    Sync::statusWindow;Fl_Toggle_Tree *    Sync::syncTree;Fl_Toggle_Node *    Sync::curNode;NxScroll *    Sync::syncScroll;NxButton *    Sync::syncButton;NxButton *    Sync::abortButton;NxButton *    Sync::okButton;NxOutput *    Sync::statusMsg;NxSlider *    Sync::statusSlider = 0;Fl_Pixmap *    Sync::echeckPixmap;Fl_Pixmap *    Sync::checkPixmap;bool Sync::first_app;Sync::Sync(char *app):NxApp(app){  printf("STATE -> SYNC_WAIT\n");    syncState = SYNC_WAIT;    NxApp::Instance()->set_about(about_sync);    mainWindow = new NxWindow(W_W, W_H, app);    MakeSyncWindow();    MakeStatusWindow();    mainWindow->end();    set_shown_window(mainWindow);    echeckPixmap = new Fl_Pixmap(echeck_xpm);    checkPixmap = new Fl_Pixmap(check_xpm);    add_apps(syncTree);    curNode = NULL;    Add_Fd("nxsync", _ClientIPCHandler);    sync_id = -1;    //msgState = SYNC_WAIT;        cur_app = "";    first_app = false;}Sync::~Sync(){}int Sync::agent_connect(void) {  int agent_id = StartApp("syncagent", 0, 0);  printf("Got %d while starting %s\n", agent_id, "syncagent");  if (agent_id == -1) return -1;  /* Now, connect the agent to the remote system */  /* FIXME:  This is hard coded here for now, because its easier */  printf("SENDING connect to %d\n", agent_id);  Write_Fd(agent_id, "1000^TCPIP^LOCALHOST^2000", 25);  return 0;}int Sync::agent_disconnect(void) {  int agent_id = Find_Fd("syncagent");  if (agent_id == -1) return -1;    Write_Fd(agent_id, "1005^", 5);  return 0;}voidSync::ClientIPCHandler(int fd, void *o, int ipc_id){    char *passMsg = new char[CL_MAX_MSG_LEN];  memset(passMsg, 0, CL_MAX_MSG_LEN);  printf("SYNC->CLIENTIPCHANDLER (%d, %x, %d)\n", fd, 0, ipc_id);  if (!o) {    int length = CL_MAX_MSG_LEN - 1;    ipc_id = NxApp::Instance()->Read_Fd(passMsg, &length);    if (passMsg[0] == 0) return;  }  else if (ipc_id == -1) {    strcpy(passMsg, (char *) o);    ipc_id = NxApp::Instance()->Find_Fd("nxsync");  } else {    strcpy(passMsg, (char *) o);  }  short msg_id = -1;  const string passString = passMsg;  string msg_id_str;  bool err = false;  coder.vmessages.clear();  coder.DecodeMsg(passString);    msg_id_str = coder.vmessages[0];  msg_id = atoi(msg_id_str.c_str());  printf("MESSAGE: {%s] from [%d]\n", passMsg, ipc_id);  printf("INCOMING:  SYNC STATE [%d] MSG ID [%d]\n", syncState, msg_id);  switch(syncState) {  case SYNC_CONNECT:    if (msg_id == OK) {      printf("STATE -> SYNC_START\n");      syncState = SYNC_START;    }    else       do_error("Unable to connect to the remote agent");        delete[]passMsg;    return;  case SYNC_PENDING:    if (msg_id == OK) {      printf("STATE -> SYNC_EXE\n");      syncState = SYNC_EXE;                 delete[]passMsg;      return;    }    else if (msg_id == ERR)      do_error("Error while starting sync");    else if (msg_id == ABORT)      do_abort();        break;  case SYNC_EXE:        if (msg_id == INFO) {      printf("STATE -> SYNC_DONE\n");      syncState = SYNC_DONE;    }    else if (msg_id == ERR) {      do_error(coder.vmessages[2]);      err = true;    }    else if (msg_id == ABORT) {      do_abort();      err = true;    }    break;      case SYNC_DONE:    break;      case SYNC_ABORT:    if (msg_id == ERR) {      do_error("Syncronization aborted!");      err = true;    }        break;  }    if (err == false)    ServerIPCHandler(fd, ipc_id, (char *) passMsg);    delete[]passMsg;}voidSync::MakeSyncWindow(){    syncWindow = new NxPimWindow(APP_NAME, syncMenuItems, 0, "", "", 0);    add_window((Fl_Window *) syncWindow->GetWindowPtr());    {	NxScroll *o = syncScroll =	    new NxScroll(-1, 15 + BUTTON_HEIGHT, W_W + 2, 230);	o->resize(false);	{	    syncTree = new Fl_Toggle_Tree(0, 15 + BUTTON_HEIGHT, W_W, 10);	    syncTree->callback(checkIt_callback);	}	o->end();	syncWindow->add((Fl_Widget *) o);    }    syncButton =	new NxButton((W_W / 2) - ((BUTTON_WIDTH + 15) / 2), BUTTON_Y,		     BUTTON_WIDTH + 15, BUTTON_HEIGHT, "Synchronize");    syncButton->movable(false);    syncButton->callback(sync_callback);    syncWindow->add((Fl_Widget *) syncButton);}voidSync::MakeStatusWindow(){    statusWindow = new NxPimPopWindow("Status");    add_window((Fl_Window *) statusWindow->GetWindowPtr());    {	statusMsg =	    new NxOutput(4, 19, statusWindow->GetWindowPtr()->w() - 6, 25);	statusMsg->value("Synchronizing");	statusWindow->add((Fl_Widget *) statusMsg);    }    {	abortButton =	    new NxButton(BUTTON_X, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Abort");	abortButton->callback(abort_callback);	statusWindow->add((Fl_Widget *) abortButton);    }    {	okButton =	    new NxButton(BUTTON_X, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Ok");	okButton->callback(ok_callback);	statusWindow->add((Fl_Widget *) okButton);	okButton->hide();    }    {      //statusSlider = new NxSlider(5, 55,      //		    statusWindow->GetWindowPtr()->w() - 10,      //			    BUTTON_HEIGHT);      //statusSlider->box(FL_BORDER_BOX);      //statusSlider->minimum(0.0);      //statusSlider->maximum(100.0);      //statusSlider->step(1.0);      //statusSlider->type(FL_HOR_FILL_SLIDER);      //statusSlider->value(0.0);      //statusSlider->deactivate();      //statusWindow->add((Fl_Widget *) statusSlider);    }    statusWindow->GetWindowPtr()->hide();}voidSync::ok_callback(Fl_Widget * fl, void *l){    NxApp::Instance()->show_window(syncWindow->GetWindowPtr(), ACTIVATE);    curNode = NULL;    first_app = false;}voidSync::abort_callback(Fl_Widget * fl, void *l){    Sync *pThis = (Sync *) (NxApp::Instance());    char *msg = new char[CL_MAX_MSG_LEN];    strcpy(msg, pThis->coder.Abort().c_str());    curNode = NULL;    statusMsg->value("Synchronizing aborted!");    abortButton->hide();    okButton->show();    first_app = false;    if (pThis->syncState != SYNC_ERROR) {	pThis->Write_Fd(pThis->sync_id, msg, strlen(msg));	pThis->sync_abort();    }    printf("STATE -> SYNC_ABORT\n");    pThis->syncState = SYNC_ABORT;    //pThis->msgState = SYNC_ABORT;    delete[]msg;    msg = 0;}voidSync::sync_callback(Fl_Widget * fl, void *l){    NxApp::Instance()->show_window(statusWindow->GetWindowPtr(),				   DEACTIVATE, syncWindow->GetWindowPtr());    Sync *pThis = (Sync *) (NxApp::Instance());    if (!(pThis->get_next_app())) {	abortButton->hide();	okButton->show();	//statusSlider->hide();	statusMsg->value("No application selected to sync.");	curNode = NULL;    } else {	first_app = false;	curNode = NULL;	okButton->hide();	abortButton->show();	//statusSlider->show();	//statusSlider->value(0.0);	statusMsg->value("Starting sync");	printf("STATE -> SYNC_PRECONNECT\n");	((Sync *) (NxApp::Instance()))->syncState = SYNC_PRECONNECT;	Fl::add_timeout(0.05, timer_callback);    }}voidSync::timer_callback(void *){  char msg[255];	    Sync *pThis = (Sync *) NxApp::Instance();    int state = pThis->syncState;    double timeout = 0.5;    printf("TIMER [%d]\n", state);    switch(state) {    case SYNC_WAIT:      printf("STATE -> SYNC_PRECONNNECT\n");      pThis->syncState = SYNC_PRECONNECT;      break;    case SYNC_PRECONNECT:      printf("PRECONNECT->CONNECT\n");      if (pThis->agent_connect() == -1) {	sprintf(msg, "Error - Unable to start the sync agent");	statusMsg->value(msg);	

⌨️ 快捷键说明

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