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

📄 app4.4.c

📁 code about gtk++ for MID intel develop in Linux moblin. code interface write as language c in linu
💻 C
📖 第 1 页 / 共 5 页
字号:
	/*init the renderer and column for treeview*/
	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes
						 ("Devices", renderer, "text", DEVICE_NAME, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes
						 ("Users", renderer, "text", USER_NAME, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes
						 ("Control", renderer, "text", EVENT, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes
						 ("Minute", renderer, "text", MINUTE, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes
						 ("Hour", renderer, "text",HOUR, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes
						 ("Day", renderer, "text",DAY, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes
						 ("Month", renderer, "text",MONTH, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes
						 ("Year", renderer, "text",YEAR, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	update report when button  update was clicked
         * Parameter  :  none
         * Return       :  none
        ***************************************************************************/	
void update_report ()
{
	/*send signal to server for update */
	send_buffer [0] = 40;
	send_buffer [1] = 0;
	if ( write(sockfd,send_buffer,2) < 0 )
		perror("ERROR writing to socket");
}
/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	create form login and check acount login and send signal id_acount to server
         * Parameter  :  none
         * Return       :  none
        ***************************************************************************/	
void create_form_login ()
{
  //variable
  GtkWidget *usr_hbox,*pass_hbox,*label_usr, *label_pass, *entry_usr, *entry_pass, *buttonBox_ok_cancel, *button_ok, *button_cancel, *dialog, *table;
  gint result;
  const char* password;
  const char* username;
  char usr[RECORD_LEN_USER];
  char pass[RECORD_LEN_USER];
  int f, t, j ;
  /* create dialog form login */
  dialog = gtk_dialog_new_with_buttons ("Login",NULL,GTK_DIALOG_MODAL,GTK_STOCK_OK, GTK_RESPONSE_OK,
  GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,NULL);

   /*set properties for form*/
  gtk_widget_set_size_request(dialog,LOGIN_WIDTH, LOGIN_HEIGHT);
  gtk_dialog_set_has_separator(GTK_DIALOG(dialog),FALSE);
  gtk_dialog_set_default_response (GTK_DIALOG (dialog),GTK_RESPONSE_OK);

  /*create label_usr and entry_usr*/
  label_usr = gtk_label_new ("User Name");
  entry_usr = gtk_entry_new_with_max_length (50);

  /*create label_pass and entry_pass */
  label_pass = gtk_label_new ("Pass Word");
  entry_pass = gtk_entry_new_with_max_length (50);

  /* hiden password */
  gtk_entry_set_visibility(GTK_ENTRY(entry_pass),FALSE);
  gtk_entry_set_invisible_char(GTK_ENTRY(entry_pass),'*');

  /*create table*/
   table = gtk_table_new (2,2,FALSE);

  /*attach widget label,entry about user /pass  into table*/
   gtk_table_attach_defaults (GTK_TABLE(table),label_usr,0,1,0,1);
   gtk_table_attach_defaults (GTK_TABLE(table),label_pass,0,1,1,2);
   gtk_table_attach_defaults (GTK_TABLE(table),entry_usr,1,2,0,1);
   gtk_table_attach_defaults (GTK_TABLE(table),entry_pass,1,2,1,2);

   /*set property for table*/
   gtk_table_set_row_spacings (GTK_TABLE(table),5);
   gtk_table_set_col_spacings (GTK_TABLE(table),5);
   gtk_container_set_border_width(GTK_CONTAINER (table),2);

  /*add usr_hbox and pass_hbox into content_area of dialog */
  gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (dialog)->vbox), table);

  /*show dialog*/
  gtk_widget_show_all ( dialog );
  
  /*process response*/
	int id_user;
	t = f =0;
	do
	{   
		/*get result*/
	   result = gtk_dialog_run (GTK_DIALOG (dialog));
	   switch (result)
	   {
	   // case button Ok was clicked
			case GTK_RESPONSE_OK:
			/* get user/ password*/
			username = gtk_entry_get_text ( GTK_ENTRY (entry_usr) ); 
			password = gtk_entry_get_text ( GTK_ENTRY (entry_pass) );
		  
			j =0;
			do 
			{
			// check user/ password 
				if ( (strcmp ( all_user[j].usr , username ) == 0 ) && ( strcmp ( all_user[j].pass , password ) == 0 ) )
				{
					id_user = j;
					t =1;
					break;
				}
				j = j + 1;
			} while ( j < NUMBER_USER );
			// if fail then send message note
			if  ( t  == 0)
			{  
				message_form ("The User Name or Password is incorrect !");
				
				gtk_entry_set_text (  GTK_ENTRY (entry_pass), "" );
				f = 1;
			}	
			else
			{
				f=0;
			}
		   break;
		   //case Cancel button was clicked
	      case GTK_RESPONSE_CANCEL:
		   exit(1);
		   break;
	      default:
		   break;
	   }
	   //if acount true then exit loop
	} while (f);
	/* send signal to check id user */
	send_buffer[0] =  30;
	send_buffer[1] = id_user;
	if ( write(sockfd,send_buffer,256) < 0 )
	perror("ERROR writing to socket");
/*hide dialog form login*/
  gtk_widget_hide (dialog);

}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	create all device buttons visible in main form. 
         * Parameter  :  2
		 "arr_button_device" (I) : array contain object button devices
		 "devices" (I) : array contain name and id of devices
         * Return       :  none
        ***************************************************************************/	
void create_devices (GtkWidget* arr_button_device[], Device devices [])
{
/*variables*/
  GtkWidget* arr_vbox [NUMBER_DEVICE];
  GdkPixbuf* arr_pixbuf [NUMBER_DEVICE];
  GtkWidget* arr_image [NUMBER_DEVICE];
  GtkWidget* arr_label [NUMBER_DEVICE];
  
  GError *err =NULL;

  int i,fkey;

  /* init font*/

  for(i=0; i<NUMBER_DEVICE; i++)
  {
    gchar* text;
    gchar* name;
    text = g_strconcat (devices[i].name,".jpg",NULL);
    //concat path string of image
    name = g_strconcat ("/usr/src/code/images/",text,NULL);
    //create and set size device
    arr_button_device[i]= gtk_button_new ();
    gtk_widget_set_size_request (arr_button_device[i],SIZE_DEVICE,SIZE_DEVICE);

    fkey =devices[i].key;

    // add signal for device
     g_signal_connect (G_OBJECT (arr_button_device[i]), "clicked",G_CALLBACK (button_clicked), (gpointer)fkey );

    //create vbox for add image and name device
    arr_vbox[i] = gtk_vbox_new (FALSE,0);
    gtk_container_set_border_width (GTK_CONTAINER(arr_vbox[i]),1);
    //image of device
    arr_pixbuf[i] = gdk_pixbuf_new_from_file_at_size(name,X_IMAGE_SIZE,Y_IMAGE_SIZE, &err);
    arr_image[i] = gtk_image_new_from_pixbuf (arr_pixbuf[i]);
    //name of device
    arr_label[i] = gtk_label_new ( devices[i].name);
    gtk_widget_modify_font (arr_label[i], init_font);
    //gtk_label_set_max_width_chars (GTK_LABEL(arr_label[i]),2);

    // add image and label into vbox
    gtk_box_pack_start_defaults (GTK_BOX (arr_vbox[i]), arr_image[i]);
    gtk_box_pack_start_defaults (GTK_BOX (arr_vbox[i]), arr_label[i]);

    //add vbox into device
    gtk_container_add (GTK_CONTAINER (arr_button_device[i]),arr_vbox[i]);
    //show device
    gtk_widget_show_all (arr_button_device[i]);
  }
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   :  create form all device which is visible on main window
         * Parameter  :  none
         * Return       :  none
        ***************************************************************************/	
void create_form_devices ()
{
	/* variables*/
	int data =1;
	int i;
	char* arr_char[4] = {"All Device","Active Device","Unactive Device","Reports"};
	GtkWidget *hbuttonbox;
	GtkWidget* arr_label[4];
	GtkWidget *fix_box;
	GtkWidget *notebook;
	GtkWidget *btnRefresh;
	GtkWidget *new_device, *open_all, *close_all;
	GtkWidget* label;

	/* create fix container */
	fix_box = gtk_fixed_new ();
	/* Add vbox to main window */
	gtk_container_add (GTK_CONTAINER ( window),fix_box);

	/*create notebook and place position of tabs */
	notebook = gtk_notebook_new ();
	gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
	/* set properties for notebook */
	gtk_widget_set_size_request (notebook,NOTEBOOK_WIDTH,NOTEBOOK_HEIGHT);
	gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), 5);
	gtk_notebook_set_tab_border (GTK_NOTEBOOK (notebook), 5);
	gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(notebook),TRUE);
	// init 3 button New Device, Open All, Close All and set size of buttons 
	hbuttonbox  = gtk_hbox_new (FALSE,10);
	new_device = create_button (GTK_STOCK_NEW, "New Device");
	gtk_widget_set_size_request (new_device,-1,40);
	open_all = create_button (GTK_STOCK_OPEN,"Open All");
	gtk_widget_set_size_request (new_device,-1,40);
	close_all = create_button (GTK_STOCK_CLOSE,"Close All");
	gtk_widget_set_size_request (new_device,-1,40);
	/* add buttons to container hbuttonbox*/
	gtk_box_pack_start (GTK_BOX ( hbuttonbox) , new_device ,TRUE, TRUE ,0);
	gtk_box_pack_start (GTK_BOX ( hbuttonbox) , open_all ,TRUE, TRUE ,0);
	gtk_box_pack_start (GTK_BOX ( hbuttonbox) , close_all ,TRUE, TRUE ,0);

	/*add callback function into buttons*/
	g_signal_connect (G_OBJECT (open_all), "clicked",G_CALLBACK (function_open_all), (gpointer) data );
	g_signal_connect (G_OBJECT (close_all), "clicked",G_CALLBACK (function_close_all), (gpointer) data );
	
	/*add container hbuttonbox to fix container*/
	gtk_fixed_put (GTK_FIXED (fix_box), hbuttonbox, 100,380);
	/* add notebook to fix container*/
	gtk_fixed_put (GTK_FIXED (fix_box), notebook, 100,20);

	/*init taps */

	for (i =0;i<4;i++)
	{
	 arr_label [i] = gtk_label_new (arr_char [i]);
	 gtk_widget_modify_font (arr_label[i], init_font);
	//init fixbox
	arr_fix_box[i] = gtk_fixed_new ();
	 // add fixbox into notebook
	 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), arr_fix_box[i], arr_label[i]);
	}

	for (i =0;i<3 ;i++)
	{
		//init container (hbox) for devices
		arr_hbutton_box [i] = gtk_hbox_new (FALSE,10);
		// add hbox into fixbox
		gtk_fixed_put (GTK_FIXED (arr_fix_box[i]),arr_hbutton_box[i],10,10);
	}
	/*create report and add to container*/
	create_report (treeview);
	gtk_fixed_put ( GTK_FIXED (arr_fix_box[3]), treeview, 3, 3 );

	/*button Refesh report */
	btnRefresh = create_button ( GTK_STOCK_REFRESH, "Refresh");
	gtk_fixed_put ( GTK_FIXED (arr_fix_box[3]), btnRefresh, 3,280  );
	g_signal_connect (G_OBJECT (btnRefresh), "clicked",G_CALLBACK (update_report), (gpointer) data );

	/* init device buttons in array arr_all_device */
	create_devices (arr_all_devices, all_device);
	/* init device buttons in array arr_active_unactive */
	create_devices (arr_active_unactive, all_device);
	
	/*add device buttons to notebook*/
	for (i =0 ; i<NUMBER_DEVICE; i++)
	{
	 // add to frame all_device
	gtk_box_pack_start (GTK_BOX ( arr_hbutton_box[0]) , arr_all_devices[i] ,TRUE, TRUE ,0);

	}
	/*add button device in active_unactive to container in 2 tab Active and Unactice on notebook*/
	 for (i =0 ; i<NUMBER_DEVICE; i++)
	{
		if (state_arr[i] == 1)
		{
			// add to frame active_device
			gtk_box_pack_start (GTK_BOX ( arr_hbutton_box[1]) , arr_active_unactive[i] ,TRUE, TRUE ,0);
		}
		else
		{
			// add to frame unactive_device
			gtk_box_pack_start (GTK_BOX ( arr_hbutton_box[2]) , arr_active_unactive[i] ,TRUE, TRUE ,0);
		}
	} 
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	create form login and check acount login and send signal id_acount to server
         * Parameter  :  none
         * Return       :  none
        ***************************************************************************/	
GtkWidget *create_main_window( const gchar*title )
{
  GtkWidget *window;
  /* Create toplevel widget */
    window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    gtk_window_set_title( GTK_WINDOW( window ), title );
    gtk_window_set_default_size(GTK_WINDOW(window), 250, -1);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

    gtk_signal_connect( GTK_OBJECT( window ), "delete-event",
                        GTK_SIGNAL_FUNC(delete_event_handler), NULL );
    gtk_signal_connect( GTK_OBJECT( window ), "destroy",
                        GTK_SIGNAL_FUNC(end_program), NULL );
	// create font for application
	display = gdk_display_get_default ();
	init_font = pango_font_description_from_string ("Sans 14");
	/* send signal for update database */
	send_buffer[0] = 40;
	if ( write(sockfd,send_buffer,256) < 0 )
	perror("ERROR writing to socket");
	
    return window;
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia

⌨️ 快捷键说明

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