Ejemplo n.º 1
0
bool DockApplet::init()
{
	updateClientList();
	updateActiveWindow();

	for(int i = 0; i < m_dockItems.size(); i++)
		m_dockItems[i]->moveInstantly();

	return true;
}
Ejemplo n.º 2
0
void DockApplet::draggingStopped()
{
	m_dragging = false;
	// Since we don't update it when dragging, we should do it now.
	updateClientList();
}
int main(int argc,char** argv){

  int yes = 1;
  int i,j,rv;
  char *commands ;
  int length = 0 ;
  char array[100];
  char *cmdargs;
  char *res ;
  cmdargs = array;
  head = NULL ;
  headRef = &head; 
  int ln1;
  int obytes ;
  int retSel; 
  char ipremote[INET_ADDRSTRLEN];

  /* Bufferrs for read and write */

  char buf[350] ;
  char opbuff[350];
 
  
  

  if(argc != 3){

   printf("Invalid call ..exiting............\n");
   exit(0);
  }
  
  if(strcasecmp(argv[1],"s") != 0 &&  strcasecmp(argv[1],"c") != 0 ){

    printf("Invalid arguments ..exiting............\n");
    exit(0);

  }


  int iport ;
  iport = atoi(argv[2]);

  if(iport <= 1024 || iport > 45355){
 
     printf("Invalid port ..exiting............\n");
    exit(0);   

  }

 /* Setting the client or server flag */

  if(strcasecmp(argv[1],"S")== 0 ){
      serverclientflag = 1;
  }else{

    serverclientflag = 2 ;
  }

  portnum = argv[2]; // setting the portnum to global variable
  
  //Method to initialise the system

  initialize();
 
  
  for(;;){
 

  read_fds = master ;

  if(select(fdmax + 1,&read_fds,NULL,NULL,NULL) == -1){
    perror("select");
    exit(4);
  }

        //run through the existing connections looking for data
  
  for(i=0 ; i<= fdmax ; i++){

         if(FD_ISSET(i,&read_fds)){ // we got one conncetion

            if(i == 0){
             //read the command from the terminal
             //printf("[PA1]$");
             if((res=fgets(cmd,sizeof cmd,stdin) )!= NULL){
               length = strlen(cmd);
               cmd[length-1] = '\0';   
                //fflush(stdin);
                commands = cmd ;
                 returnfd = processCommand(commands,serverclientflag,portnum); //get the file descriptor for server connection 
                 fflush(stdout);

                 if(returnfd == -1){
                  
                   printf("Invalid arguments to command.");
                   fflush(stdout); 
                   printf("\n[PA1]$:");
                   fflush(stdout); 
                 }
               }
                 
             }else{
              
              if(i == listener){
                //handle new connection accept the connection and add it to the read set
                addrlen = sizeof remoteaddr ;
                newfd = accept(listener,(struct sockaddr *)&remoteaddr,&addrlen);
                
                if(newfd == -1){
                 perror("accept");
                 } else{

                    /* Getting the ip address of the remote connection */
                    /*And adding the  connection to list*/

                         struct sockaddr_in *s = (struct sockaddr_in *)&remoteaddr;
                         struct hostent *hnet; 
                         inet_ntop(AF_INET, &s->sin_addr, ipremote, sizeof ipremote);
                         int port = s->sin_port;
                         char tempport[33]; 
                         sprintf(tempport,"%d",port);
                         //hnet = gethostbyaddr(&ipremote,sizeof ipremote,AF_INET);
                         if(serverclientflag == 1){

                           getConnectDetails(newfd,tempport,&head,ipremote);
                         }else{

                           getConnectDetails(newfd,tempport,&headConnectdNode,ipremote);
                         }
                         
                         //adding the connection details in the memory  
                         //addClientstoList(&headConnectdNode,ipremote,portnum,hnet->h_name,iconnid,i); 
                         //portnum;
                    printf("----------A new connection requested from :%s",inet_ntop(remoteaddr.ss_family,get_in_addr((struct sockaddr*)&remoteaddr),remoteIP,INET6_ADDRSTRLEN));
                    printf ("\n---------------------Connected to :%s-----------\n",inet_ntop(remoteaddr.ss_family,get_in_addr((struct sockaddr*)&remoteaddr),remoteIP,INET6_ADDRSTRLEN));
                    
                    FD_SET(newfd,&master);
                    
                    //End Send the updated list of clients
                    if(newfd > fdmax){
                      fdmax = newfd ;
                   }
                    // process register command
                  }

                }else{

                     /*handle data from the client
                     clear the data from the buffer
                     */

                     if((nbytes = recv(i,buf,sizeof buf,0)) <= 0 ){
                       fflush(stdout);
                       if(nbytes == 0 ){
                         //connection closed
                          if(serverclientflag == 1){                       
                          //Reset the client list and push data to other clients
                           updateClientList(i,serverclientflag) ;   
                           buildclist(head);
                           sendupdate(i,listener);  
                          }else{
                         
                          updateClientList(i,serverclientflag);  
                          iconnid = iconnid - 1 ; 
                          }                              
                          printf("\n[PA1]$:");
                          fflush(stdout);
                        }else{
                         perror("recv");
                         printf("\n wrog connection");
                        } 
                      //close(i);
                      FD_CLR(i,&master);
                      printf("\n[PA1]$:"); 
                      }else{

                            //printf("\n Bytes received is %d",nbytes); 
                            
                             //we have data from the client
                            //buf[nbytes] ='\0';
                            //printf("\nBytes %d",nbytes) ;
                            //Get the data about the server
                            if(serverclientflag == 1){
                            
                                //Adding the server details first
                                //getClientDetails(i,buf,&head);
                                char ips[INET6_ADDRSTRLEN] ;
                                char *rip = ips ;
                                updateConnctdPort(i,buf,&head,rip);
                                //addClientstoList(&head,ipaddress,portnum,"dokken.cse.buffalo.edu",1);
                                ln1 =buildclist(head);
                                strcpy(opbuff,sbcheckdata);
                                obytes = send(i,opbuff,sizeof opbuff,0);
                                if(obytes < 0){
                                perror("senddata");
                            }
                               //obytes = send(i,"HEllo",6,0);
                              fflush(stdout);
                              //printf("\n Bytes transferred %d",obytes);
                           }else{

                            processCmd(buf,i,nbytes);
                            memset(buf,0,sizeof buf);
                            
                           }
                         
                           if(serverclientflag == 1 ){

                          //Send the updated data to all the clients
                          for(j=0;j<=fdmax;j++){
                             if(FD_ISSET(j,&master)){
                              //need not send the data to listener && this machine
                              if(j!=listener && j!=i){

                                if(send(j,opbuff,sizeof opbuff,0)== -1){
                                //perror("Sending the list data");
                              }
                              }
                            }
                          }
                        }
                        
                        //Send the updated data to all the clients
                       fflush(stdout);
                       printf("\n[PA1]$:");
                       fflush(stdout);
                       
                 }
               }

             }

           }
        } //end of the readset polling loop
    } //end of the running loop 
  
    return 0 ;
  }     
Ejemplo n.º 4
0
ClientEdit::ClientEdit(QWidget *parent) : QWidget(parent)
{
    // Set up the client list view.
    m_clientListView = new QListWidget;
    m_clientListView->setMovement(QListWidget::Static);
    connect(m_clientListView, SIGNAL(currentTextChanged(QString)), this, SLOT(changeClient(QString)));

    QPushButton * addClient = new QPushButton(tr("Add"));
    connect(addClient, SIGNAL(clicked()), this, SLOT(addClient()));

    QHBoxLayout * clientButtonLayout = new QHBoxLayout;
    clientButtonLayout->addWidget(addClient);
    clientButtonLayout->addStretch(-1);

    QVBoxLayout * clientLayout = new QVBoxLayout;
    clientLayout->setAlignment(Qt::AlignLeft);
    clientLayout->addWidget(new QLabel(tr("Clients:")));
    clientLayout->addWidget(m_clientListView, 1);
    clientLayout->addLayout(clientButtonLayout);

    // Set up the property view.
    m_nameLabel = new QLabel;
    m_billTypeLabel = new QLabel;
    m_billTypeLabel->setMinimumWidth(64);

    QPushButton * editBillType = new QPushButton(tr("Edit"));


    QGridLayout * gLayout = new QGridLayout;
    gLayout->addWidget(new QLabel(tr("Name:")), 0, 0, Qt::AlignRight);
    gLayout->addWidget(m_nameLabel, 0, 1);
    gLayout->addWidget(new QLabel(tr("Bill Type:")), 1, 0, Qt::AlignRight);
    gLayout->addWidget(m_billTypeLabel, 1, 1);
    gLayout->addWidget(editBillType, 1, 2);

    QHBoxLayout * propertyLayout = new QHBoxLayout;
    propertyLayout->addLayout(gLayout);
    propertyLayout->addStretch(-1);

    // Set up the bill view.
    m_billListView = new QListWidget;
    m_billListView->setMovement(QListWidget::Static);

    QVBoxLayout * billButtonLayout = new QVBoxLayout;
    billButtonLayout->addWidget(new QLabel(tr("Bills:")));
    billButtonLayout->addStretch(-1);

    QHBoxLayout * billUpLayout = new QHBoxLayout;
    billUpLayout->setAlignment(Qt::AlignRight);
    billUpLayout->addLayout(billButtonLayout);
    billUpLayout->addWidget(m_billListView, 1);

    QPushButton * print = new QPushButton(tr("Print"));

    QPushButton * printPreview = new QPushButton(tr("Print Preview"));

    QHBoxLayout * billDownLayout = new QHBoxLayout;
    billDownLayout->addWidget(print);
    billDownLayout->addWidget(printPreview);
    billDownLayout->addStretch(-1);

    // Set up the main layout.
    QFrame * verticalSeperator = new QFrame;
    verticalSeperator->setFrameShape(QFrame::HLine);

    QVBoxLayout * rightLayout = new QVBoxLayout;
    rightLayout->addLayout(propertyLayout);
    rightLayout->addWidget(verticalSeperator);
    rightLayout->addLayout(billUpLayout, 1);
    rightLayout->addLayout(billDownLayout);

    QHBoxLayout * mainLayout = new QHBoxLayout;
    mainLayout->addLayout(clientLayout, 1);
    mainLayout->addSpacing(12);
    mainLayout->addLayout(rightLayout, 2);

    updateClientList();
    setLayout(mainLayout);
}