예제 #1
0
static LONG_PTR WINAPI InfoMenuProc(HANDLE hDlg,int Msg,int Param1,LONG_PTR Param2)
{
  InfoMenuData *DlgParams=(InfoMenuData *)Info.SendDlgMessage(hDlg,DM_GETDLGDATA,0,0);
  switch(Msg)
  {
    case DN_DRAGGED:
      return FALSE;
    case DN_CTLCOLORDIALOG:
      return Info.AdvControl(Info.ModuleNumber,ACTL_GETCOLOR,(void *)COL_MENUTEXT);
    case DN_CTLCOLORDLGLIST:
      if(Param1==0)
      {
        FarListColors *Colors=(FarListColors *)Param2;
        int ColorIndex[]={COL_MENUTEXT,COL_MENUTEXT,COL_MENUTITLE,COL_MENUTEXT,COL_MENUHIGHLIGHT,COL_MENUTEXT,COL_MENUSELECTEDTEXT,COL_MENUSELECTEDHIGHLIGHT,COL_MENUSCROLLBAR,COL_MENUDISABLEDTEXT};
        int Count=sizeofa(ColorIndex);
        if(Count>Colors->ColorCount) Count=Colors->ColorCount;
        for(int i=0;i<Count;i++)
          Colors->Colors[i]=(BYTE)Info.AdvControl(Info.ModuleNumber,ACTL_GETCOLOR,(void *)(INT_PTR)(ColorIndex[i]));
        return TRUE;
      }
      break;
    case DN_INITDIALOG:
      {
        FarListTitles titles;
        titles.Title=(TCHAR *)GetMsg(mName);
        titles.TitleLen=(int)_tcslen(titles.Title);
        titles.Bottom=(TCHAR *)GetMsg(mInfoBottom);
        titles.BottomLen=(int)_tcslen(titles.Bottom);
        Info.SendDlgMessage(hDlg,DM_LISTSETTITLES,0,(LONG_PTR)&titles);
      }
      break;
    case DN_DRAWDIALOG:
      if(DlgParams->firsttime)
      {
        Info.SendDlgMessage(hDlg,DN_TIMER,0,0);
        Info.SendDlgMessage(hDlg,DN_TIMER,0,0);
      }
      break;
    case DN_TIMER:
      {
        HANDLE console=CreateFileW(L"CONOUT$",GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
        if(console!=INVALID_HANDLE_VALUE)
        {
          DWORD size,height=0,width=0,path_width,length; SmallInfoRec *receive;
          if(GetJobList(&size,&receive)||DlgParams->firsttime)
          {
            bool refresh=true;
            if(!DlgParams->forcerefresh)
            {
              if(DlgParams->count==size)
              {
                refresh=false;
                for(DWORD i=0;i<size;i++)
                  if(DlgParams->id[i].ThreadId!=receive[i].ThreadId)
                  {
                    refresh=true;
                    break;
                  }
              }
            }
            if(refresh)
            {
              DWORD old_pos=0; bool restore_pos=false;
              if(DlgParams->count)
              {
                DWORD pos=(DWORD)Info.SendDlgMessage(hDlg,DM_LISTGETCURPOS,0,(LONG_PTR)NULL);
                if(pos<DlgParams->count)
                {
                  old_pos=DlgParams->id[pos].ThreadId;
                  restore_pos=true;
                }
              }
              free(DlgParams->id);
              DlgParams->id=receive;
              DlgParams->count=size;
              Info.SendDlgMessage(hDlg,DM_ENABLEREDRAW,FALSE,0);
              for(DWORD i=0;i<size;i++)
              {
                length=(DWORD)wcslen(receive[i].Src);
                if(length>width) width=length;
              }
              width+=(DWORD)_tcslen(GetMsg(mInfoCopy));
              width+=(DWORD)(2*_tcslen(GetMsg(mInfoSep)))-1+4; // -1 for headers, 4 for percents
              length=(DWORD)_tcslen(GetMsg(mName));
              if(length>width) width=length;
              length=(DWORD)_tcslen(GetMsg(mInfoBottom));
              if(length>width) width=length;
              width+=12;
              height=size+4;
              { //normalize according console size
                COORD console_size={80,25};
#ifdef UNICODE
                SMALL_RECT console_rect;
                if(Info.AdvControl(Info.ModuleNumber,ACTL_GETFARRECT,(void*)&console_rect))
                {
                  console_size.X=console_rect.Right-console_rect.Left+1;
                  console_size.Y=console_rect.Bottom-console_rect.Top+1;
                }
#else
                CONSOLE_SCREEN_BUFFER_INFO console_info;
                if(GetConsoleScreenBufferInfo(console,&console_info))
                {
                  console_size=console_info.dwSize;
                }
#endif
                if(width>(DWORD)(console_size.X-4))
                  width=console_size.X-4;
                if(height>(DWORD)(console_size.Y-2))
                  height=console_size.Y-2;
              }
              //calculate path width
              path_width=WidthToPathWidth(width);
              { //minimize listbox
                SMALL_RECT listbox_size={3,1,4,2};
                Info.SendDlgMessage(hDlg,DM_SETITEMPOSITION,0,(LONG_PTR)&listbox_size);
              }
              { //resize and move dialog
                COORD dialog_size={(SHORT)width,(SHORT)height};
                Info.SendDlgMessage(hDlg,DM_RESIZEDIALOG,0,(LONG_PTR)&dialog_size);
                COORD position={-1,-1};
                Info.SendDlgMessage(hDlg,DM_MOVEDIALOG,TRUE,(LONG_PTR)&position);
              }
              { //resize listbox
                SMALL_RECT listbox_size={3,1,(SHORT)(width-4),(SHORT)(height-2)};
                Info.SendDlgMessage(hDlg,DM_SETITEMPOSITION,0,(LONG_PTR)&listbox_size);
              }
              { //refresh listbox
                FarListPos new_pos={0,-1};
                FarListDelete clear={0,0};
                FarListItem *list_items=(FarListItem *)malloc(sizeof(FarListItem)*size);
                FarList list={(int)size,list_items};
                if(list_items)
                {
                  Info.SendDlgMessage(hDlg,DM_LISTDELETE,0,(LONG_PTR)&clear);
                  for(DWORD i=0;i<size;i++)
                  {
                    UpdateItem(list_items+i,receive+i,path_width);
                    if(restore_pos&&receive[i].ThreadId==old_pos) new_pos.SelectPos=i;
                  }
                  Info.SendDlgMessage(hDlg,DM_LISTADD,0,(LONG_PTR)&list);
                  FreeItems(list_items,size);
                  free(list_items);
                  if(restore_pos) Info.SendDlgMessage(hDlg,DM_LISTSETCURPOS,0,(LONG_PTR)&new_pos);
                }
              }
              Info.SendDlgMessage(hDlg,DM_ENABLEREDRAW,TRUE,0);
              if(DlgParams->firsttime)
              {
                DlgParams->firsttime=false;
                if((PlgOpt.InfoMenu&INFO_MENU_ALT_1)&&(DlgParams->count==1))
                  Info.SendDlgMessage(hDlg,DM_CLOSE,-1,0);
              }
              else
              {
                DlgParams->forcerefresh=false;
                if((DlgParams->count==0)&&(!(PlgOpt.InfoMenu&INFO_MENU_ALT_0)))
                  Info.SendDlgMessage(hDlg,DM_CLOSE,-1,0);
              }
            }
            else
            {
              SMALL_RECT in;
              Info.SendDlgMessage(hDlg,DM_GETDLGRECT,0,(LONG_PTR)&in);
              path_width=WidthToPathWidth(in.Right-in.Left+1);
              for(DWORD i=0;i<size;i++)
              {
                if(receive[i].pause!=DlgParams->id[i].pause||receive[i].Ask!=DlgParams->id[i].Ask||receive[i].percent!=DlgParams->id[i].percent)
                {
                  FarListGetItem item;
                  item.ItemIndex=i;
                  Info.SendDlgMessage(hDlg,DM_LISTGETITEM,0,(LONG_PTR)&item);
                  UpdateItem(&(item.Item),receive+i,path_width);
                  Info.SendDlgMessage(hDlg,DM_LISTUPDATE,0,(LONG_PTR)&item);
                  FreeItems(&(item.Item),1);
                }
              }
              free(DlgParams->id);
              DlgParams->id=receive;
            }
          }
          CloseHandle(console);
        }
      }
      break;
    case DN_RESIZECONSOLE:
      DlgParams->forcerefresh=true;
      Info.SendDlgMessage(hDlg,DN_TIMER,0,0);
      break;
    case DN_CLOSE:
      {
        DWORD pos=(DWORD)Info.SendDlgMessage(hDlg,DM_LISTGETCURPOS,0,0);
        if((Param1==0)&&(DlgParams->id)&&(pos<DlgParams->count))
        {
          Info.SendDlgMessage(hDlg,DM_SHOWDIALOG,FALSE,0);
          SuspendThread(DlgParams->CommonData.Thread);
          ShowInfoDialog(DlgParams->id+pos);
          ResumeThread(DlgParams->CommonData.Thread);
          Info.SendDlgMessage(hDlg,DM_SHOWDIALOG,TRUE,0);
          Info.SendDlgMessage(hDlg,DN_ENTERIDLE,0,0);
          return FALSE;
        }
        else
          Redraw_Close(DlgParams->CommonData.Thread);
      }
      break;
  }
  return FastRedrawDefDlgProc(hDlg,Msg,Param1,Param2);
}
예제 #2
0
파일: BNotifier.c 프로젝트: brianhlin/BLAH
void 
CreamConnection(creamConnection_t *connection)
{ 
/*
startnotify 	controls the normal operation in PollDB
startnotifyjob 	is used to send notification of jobs contained in joblist_string 
firstnotify 	controls if NTFDATE/END has to be sent (together with sentendonce)
sentendonce 	controls if NTFDATE/END has to be sent (is used to permit STARTNOTIFYJOBLIST to be used during
            	normal notifier operation without sending NTFDATE/END). It is reset to TRUE only by CREAMFILTER command
            	otherwise it remains FALSE after the first notification (finished with NTFDATE/END).
creamisconn 	starts all the normal usage: without it no notifications are sent to cream

So the initial commands should be:
CREAMFILTER
PARSERVERSION

STARTNOTIFY 
or 
STARTNOTIFYJOBLIST
STARTNOTIFYJOBEND

during the normal usage to have info about a list of job:
STARTNOTIFYJOBLIST
STARTNOTIFYJOBEND

*/

	char *buffer;
	int  conn_c = connection->socket_fd;

	if((buffer=calloc(LISTBUFFER,1)) == 0){
		sysfatal("can't malloc buffer in CreamConnection: %r");
	}

	while (Readline(conn_c, buffer, LISTBUFFER-1) > 0) {
		if(strlen(buffer) > 0)
		{
			do_log(debuglogfile, debug, 1, "Received for Cream:%s\n", buffer);
			if (strstr(buffer,"STARTNOTIFY/") != NULL) {
				NotifyStart(buffer, &(connection->lastnotiftime));
				connection->startnotify=TRUE;
				connection->firstnotify=TRUE;
			} else if (strstr(buffer,"STARTNOTIFYJOBLIST/") != NULL) {
				GetJobList(buffer, &(connection->joblist_string));
				connection->startnotifyjob = TRUE;
				connection->startnotify = FALSE;
			} else if (strstr(buffer,"STARTNETWORKSYNC/") != NULL) {
				GetJobList(buffer, &(connection->joblist_string));
				connection->startnotifyjob = TRUE;
				connection->startnotify = FALSE;
			} else if (strstr(buffer,"STARTNOTIFYJOBEND/") != NULL) {
				connection->firstnotify=TRUE;
				connection->lastnotiftime = time(NULL);
			} else if (strstr(buffer,"CREAMFILTER/") != NULL) {
				GetFilter(buffer, connection->socket_fd, &(connection->creamfilter));
				connection->creamisconn=TRUE;
				connection->sentendonce=TRUE;
			} else if (strstr(buffer,"PARSERVERSION/") != NULL) {
				GetVersion(connection->socket_fd);
			}
		}
	}
	connection->creamisconn=FALSE;
	close(conn_c);
	free(buffer);
	connection->socket_fd = 0;
	if (connection->creamfilter) 
	{
		free(connection->creamfilter);
		connection->creamfilter = NULL;
	}
}