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

📄 app4.4.c

📁 code about gtk++ for MID intel develop in Linux moblin. code interface write as language c in linu
💻 C
📖 第 1 页 / 共 5 页
字号:
         * Parameter  :  2
		 "widget" (I) :  object handle event
		 "data" (I):  data send to handle
         * Return       :  gint
        ***************************************************************************/	
void end_program (GtkWidget *widget, gpointer data)
{
  /* function exit */
  gtk_main_quit();
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	show notation with message 
         * Parameter  :  1
		 "message" (I) :  message in form alert 
         * Return       :  none
        ***************************************************************************/	
void message_form (gchar* message)           
{
	/* variables*/
	GtkWidget *dialog_mess, *label, *image, *hbox;

	/* Create a new dialog form with one OK button. */
	dialog_mess = gtk_dialog_new_with_buttons ("Alert", NULL,
										GTK_DIALOG_MODAL,
										GTK_STOCK_OK, GTK_RESPONSE_OK,
										NULL);
	/* hide separator in dialog */
	gtk_dialog_set_has_separator (GTK_DIALOG (dialog_mess), FALSE);
	/*init label with message */
	label = gtk_label_new (message);
	/* init image infomation*/
	image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, 
									GTK_ICON_SIZE_DIALOG);
	/* init container and add label and image to container */
	hbox = gtk_hbox_new (FALSE, 3);
	gtk_container_set_border_width (GTK_CONTAINER (hbox), 1);
	gtk_box_pack_start_defaults (GTK_BOX (hbox), image);
	gtk_box_pack_start_defaults (GTK_BOX (hbox), label);
	
	/* Pack the content  alert into the dialog's GtkVBox. */
	gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (dialog_mess)->vbox), hbox);
	/* show all dialog form alert */
	gtk_widget_show_all (dialog_mess);
	/* Create the dialog as modal and destroy it when a button is pressed. */
	gtk_dialog_run (GTK_DIALOG (dialog_mess));
	/* destroy dialog form */
	gtk_widget_destroy (dialog_mess);
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	function process for signal from apply button in alarm form.
         * Parameter  :  2
		 "button" (I) :  object send signal to function	
		 "data" (I) :   data recive after event has been send
         * Return       :  none
        ***************************************************************************/	
void apply_click (GtkWidget* button, gint8 data)
{
	
    int err = 0;
	int spin_day,spin_month, spin_year,spin_hour,spin_minute;
	char* string;
	/* string in combo_box active or unactive*/
	 string = (char*) gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (combo)->entry));
	/* init variable time */
	int hr,min,day,month,year;
	time_t now;
	
	gchar *str_time = g_new(gchar, 25);
	gchar *str_date = g_new(gchar, 25);
	 struct tm *nowbase;   
	 time (&now);
     nowbase = localtime(&now);
	 if (nowbase)
	{
		hr = nowbase->tm_hour;
		min = nowbase->tm_min ;
		day = nowbase->tm_mday;
		month = nowbase->tm_mon+1;
		year = nowbase->tm_year+1900;
	}
	/* check if  device is active or unactive*/	
	switch (state_arr[data] )
	{
		case 1:
			/* check string if  active device then send message device is acting*/	
			if (strcmp (string, "Active Device") == 0)
			{
				message_form ("Device Actived");
			}
			else
			{
				/* else get infomation day, month, year, hour, minute and compare with date time at now*/
				spin_day = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_day));
				spin_month = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_month));
				spin_year = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_year)) -2000;
				spin_hour = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_hour));
				spin_minute = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_minute));
				
				if ( (spin_year < (year -2000)) )
				{
					message_form ("Set the Alarm time must larger than current time!");
					err =1;
				}
				else
				{
					if (spin_year == (year -2000))
						if (spin_month < month)
						{
							message_form ("Set the Alarm time must larger than current time!");
							err =1;
						}
						else
						{
							if (spin_month == month)
							{
								if (spin_day < day)
								{
									message_form ("Set the Alarm time must larger than current time!");
									err =1;
								}
								else
								{
									if (spin_day == day)
									{
										if (spin_hour < hr)
										{
											message_form ("Set the Alarm time must larger than current time!");
											err =1;
										}
										else
										{
											if (spin_hour == hr)
											{
												if (spin_minute <= min)
												{
													message_form ("Set the Alarm time must larger than current time!");
													err =1;
												}
											}
										}
									}
								}
							}
						}
					}
				if (err == 0)
				/* if check successful then send infomation date time for alarm to server*/
				{
					send_buffer [0] = 10;
					send_buffer [1] = data;
					send_buffer [2]= gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_day));
					 send_buffer [3]= gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_month));
					send_buffer [4]= (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_year))) -2000;
					send_buffer [5]= gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_hour));
					send_buffer [6]= gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_minute)); 
					
					if ( write(sockfd,send_buffer,2) < 0 )
						perror("ERROR writing to socket");
						
					// set label time
					nowbase->tm_min  = send_buffer [6];
					nowbase->tm_hour = send_buffer [5];
					
					nowbase->tm_mday = send_buffer [2];
					nowbase->tm_mon = send_buffer [3];
					nowbase->tm_year = send_buffer [4] - 1900;
					
					strftime(str_time, 25, "%X", nowbase);
					strftime(str_date, 25, "%x", nowbase);	
					
					gchar* str = g_strconcat (str_time ," ",NULL);
					gchar* str_date_time = g_strconcat (str , str_date ,NULL);
					gchar* text = g_strconcat ("Device has been set time at ",str_date_time,NULL);
					message_form (text);
				}
			}
			break;
		/* same for case 0 */
		case 0:	
			if (strcmp (string, "Unactive Device") == 0)
			{
				message_form ("Device Unactived");
			}
			else
			{
				spin_day = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_day));
				spin_month = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_month));
				spin_year = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_year)) -2000;
				spin_hour = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_hour));
				spin_minute = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_minute));
				if ( (spin_year < (year -2000)) )
				{
					message_form ( "Set the Alarm time must larger than current time!");
					err =1;
				}
				else
				{
					if (spin_year == (year -2000))
					{
						if (spin_month < month)
						{
							message_form ("Set the Alarm time must larger than current time!");
							err =1;
						}
						else
						{
							if (spin_month == month )
							{
								if (spin_day < day)
								{
									message_form ("Set the Alarm time must larger than current time!");
									err =1;
								}
								else
								{
									if (spin_day == day)
									{
										if (spin_hour < hr)
										{
											message_form ("Set the Alarm time must larger than current time!");
											err =1;
										}
										else
										{
											if (spin_hour == hr)
											{
												if (spin_minute <= min)
												{
													message_form ("Set the Alarm time must larger than current time!");
													err =1;
												}
											}
										}
									}
								}
							}
						}
					}
				}
				if (err == 0)
				{
				
					send_buffer [0] = 10;
					send_buffer [1] = data;
					send_buffer [2]= gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_day));
					send_buffer [3]= gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_month));
					send_buffer [4]= (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_year))) -2000;
					send_buffer [5]= gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_hour));
					send_buffer [6]= gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spinner_minute)); 
					
					if ( write(sockfd,send_buffer,2) < 0 )
						perror("ERROR writing to socket");
						
					// set label time
					nowbase->tm_min  = send_buffer [6];
					nowbase->tm_hour = send_buffer [5];
					
					nowbase->tm_mday = send_buffer [2];
					nowbase->tm_mon = (send_buffer [3]) - 1;
					nowbase->tm_year = send_buffer [4] - 1900;
					
				
					strftime(str_time, 25, "%X", nowbase);
					strftime(str_date, 25, "%x", nowbase);	
	
					gchar* str = g_strconcat (str_time ," , ",NULL);
					gchar* str_date_time = g_strconcat (str , str_date ,NULL);
					gchar* text = g_strconcat ("Device has been set time at ",str_date_time,NULL);
					message_form (text);
				}
			}
			break;
		default:
			break;
	}
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	function process for signal from cancel button in alarm form.
         * Parameter  :  2
		 "button" (I) :  object send signal to function	
		 "data" (I) :   data recive after event has been send
         * Return       :  none
        ***************************************************************************/	
void cancel_click (GtkWidget* button, gint8 data)
{
	/*send signal to server*/
	
	/* notation message cancel alarm */
	message_form ("Device has been cancel alarm!");
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	create button with icon and name of button
         * Parameter  :  3
		 "style" (I) :  style of icon on button
		 "title" (I) :  name in button
         * Return       :  GtkWidget
        ***************************************************************************/	
GtkWidget *create_button ( gchar* style, gchar* title)
{
	/*variables*/
	GtkWidget *button;
	GtkWidget* hbox_button, *label_button, *image_button;
	/*init button*/
	button = gtk_button_new  ();
	/*init label contain name of button*/
	label_button= gtk_label_new (title);
	gtk_widget_modify_font (label_button, init_font);
	/*init stock icon*/
	image_button = gtk_image_new_from_stock ( style, GTK_ICON_SIZE_BUTTON );
    
    //create hbox for add image and name device
    hbox_button = gtk_hbox_new (FALSE,0);
    gtk_container_set_border_width (GTK_CONTAINER(hbox_button),1);
    
    // add image and label into vbox
    gtk_box_pack_start_defaults (GTK_BOX (hbox_button), image_button);
    gtk_box_pack_start_defaults (GTK_BOX (hbox_button), label_button);

	//add hbox into device
    gtk_container_add (GTK_CONTAINER (button), hbox_button);
	return button;
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	create report with treeview object
         * Parameter  :  none
         * Return       :  none
        ***************************************************************************/	
void create_report ()
{
	GtkListStore *store;
	GtkTreeIter iter;
	int i ;
	PangoFontDescription *font = pango_font_description_from_string ("Sans 12");
	/* create treeview object (global variable)*/
	treeview = gtk_tree_view_new ();
	/*modify font in treeview*/
	gtk_widget_modify_font (treeview, font);
	/*call funtion setup_tree_view*/
	setup_tree_view (treeview);
	/*create model for treeview*/
	store = gtk_list_store_new (COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
	i =0;
	while (i<10)
	{
		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter, DEVICE_NAME, list[i].device_name, USER_NAME, list[i].user_name, EVENT, list[i].event, MINUTE , list[i].minute, HOUR , list[i].hour, DAY, list[i].day, MONTH, list[i].month, YEAR, list[i].year, -1);
	  i++;
	}
	/* set kind of view of treeview with model*/
	gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
	/*release store*/
	g_object_unref (store);
}

/**************************************************************************
         * Create Date  : 02/11/2009
         * Creator Name : Tran Chi Nghia
         * Decription   : 	setup columns and renderer for treeview
         * Parameter  :  1
		 "treeview" (I) : treeview variable will be set columns
         * Return       :  none
        ***************************************************************************/	
void setup_tree_view (GtkWidget *treeview)
{
  GtkCellRenderer *renderer;
  GtkTreeViewColumn *column;

⌨️ 快捷键说明

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