コード例 #1
0
ファイル: find-files.c プロジェクト: alfbar0/spacefm
void fm_find_files( const char** search_dirs )
{
    FindFile* data = g_slice_new0(FindFile);
    GtkTreeIter it;
    GtkTreeViewColumn* col;
    GtkWidget *add_folder_btn, *remove_folder_btn, *img;

    GtkBuilder* builder = _gtk_builder_new_from_file( PACKAGE_UI_DIR "/find-files.ui", NULL );
    data->win = (GtkWidget*)gtk_builder_get_object( builder, "win" );
    g_object_set_data_full( G_OBJECT( data->win ), "find-files", data, (GDestroyNotify)free_data );

    GdkPixbuf* icon = NULL;
    GtkIconTheme* theme = gtk_icon_theme_get_default();
    if ( theme )
        icon = gtk_icon_theme_load_icon( theme, "spacefm-find", 48, 0, NULL );
    if ( icon )
    {
        gtk_window_set_icon( GTK_WINDOW( data->win ), icon );
        g_object_unref( icon );
    }
    else
        gtk_window_set_icon_name( GTK_WINDOW( data->win ), GTK_STOCK_FIND );

    /* search criteria pane */
    data->search_criteria = (GtkWidget*)gtk_builder_get_object( builder, "search_criteria" );

    data->fn_pattern = (GtkWidget*)gtk_builder_get_object( builder, "fn_pattern" );
    data->fn_pattern_entry = gtk_bin_get_child( GTK_BIN( data->fn_pattern ) );
    data->fn_case_sensitive = (GtkWidget*)gtk_builder_get_object( builder, "fn_case_sensitive" );
    gtk_entry_set_activates_default( (GtkEntry*)data->fn_pattern_entry, TRUE );

    /* file content */
    data->fc_pattern = (GtkWidget*)gtk_builder_get_object( builder, "fc_pattern" );
    data->fc_case_sensitive = (GtkWidget*)gtk_builder_get_object( builder, "fc_case_sensitive" );
    data->fc_use_regexp = (GtkWidget*)gtk_builder_get_object( builder, "fc_use_regexp" );

    /* advanced options */
    data->search_hidden = (GtkWidget*)gtk_builder_get_object( builder, "search_hidden" );

    /* size & date */
    data->use_size_lower = (GtkWidget*)gtk_builder_get_object( builder, "use_size_lower" );
    data->use_size_upper = (GtkWidget*)gtk_builder_get_object( builder, "use_size_upper" );
    data->size_lower = (GtkWidget*)gtk_builder_get_object( builder, "size_lower" );
    data->size_upper = (GtkWidget*)gtk_builder_get_object( builder, "size_upper" );
    data->size_lower_unit = (GtkWidget*)gtk_builder_get_object( builder, "size_lower_unit" );
    data->size_upper_unit = (GtkWidget*)gtk_builder_get_object( builder, "size_upper_unit" );
    g_signal_connect( data->use_size_lower, "toggled",
                            G_CALLBACK( on_use_size_lower_toggled ), data );
    g_signal_connect( data->use_size_upper, "toggled",
                            G_CALLBACK( on_use_size_upper_toggled ), data );
    on_use_size_lower_toggled( data->use_size_lower, data );
    on_use_size_upper_toggled( data->use_size_upper, data );

    data->date_limit = (GtkWidget*)gtk_builder_get_object( builder, "date_limit" );
    data->date1 = (GtkWidget*)gtk_builder_get_object( builder, "date1" );
    data->date2 = (GtkWidget*)gtk_builder_get_object( builder, "date2" );
    g_signal_connect( data->date_limit, "changed", G_CALLBACK( on_date_limit_changed ), data );

    /* file types */
    data->all_files = (GtkWidget*)gtk_builder_get_object( builder, "all_files" );
    data->text_files = (GtkWidget*)gtk_builder_get_object( builder, "text_files" );
    data->img_files = (GtkWidget*)gtk_builder_get_object( builder, "img_files" );
    data->audio_files = (GtkWidget*)gtk_builder_get_object( builder, "audio_files" );
    data->video_files = (GtkWidget*)gtk_builder_get_object( builder, "video_files" );

    /* places */
    data->places_list = gtk_list_store_new( 1, G_TYPE_STRING );
    data->places_view = (GtkWidget*)gtk_builder_get_object( builder, "places_view" );
    add_folder_btn = (GtkWidget*)gtk_builder_get_object( builder, "add_folder_btn" );
    remove_folder_btn = (GtkWidget*)gtk_builder_get_object( builder, "remove_folder_btn" );
    data->include_sub = (GtkWidget*)gtk_builder_get_object( builder, "include_sub" );

    if( search_dirs )
    {
        const char** dir;
        for( dir = search_dirs; *dir; ++dir )
        {
            if( g_file_test( *dir, G_FILE_TEST_IS_DIR ) )
                gtk_list_store_insert_with_values( data->places_list, &it, 0, 0, *dir, -1 );
        }
    }

    gtk_tree_view_set_model( (GtkTreeView*)data->places_view, (GtkTreeModel*)data->places_list );
    g_object_unref( data->places_list );
    col = gtk_tree_view_column_new_with_attributes(NULL, gtk_cell_renderer_text_new(), "text", 0, NULL );
    gtk_tree_view_append_column( (GtkTreeView*)data->places_view, col );

    g_signal_connect(add_folder_btn, "clicked", G_CALLBACK( on_add_search_folder ), data );
    g_signal_connect(remove_folder_btn, "clicked", G_CALLBACK( on_remove_search_folder ), data );

    /* search result pane */
    data->search_result = (GtkWidget*)gtk_builder_get_object( builder, "search_result" );
    /* replace the problematic GtkTreeView with ExoTreeView */
    data->result_view = exo_tree_view_new();
    if( app_settings.single_click )
    {
        exo_tree_view_set_single_click( EXO_TREE_VIEW( data->result_view ), TRUE );
        exo_tree_view_set_single_click_timeout( EXO_TREE_VIEW( data->result_view ),
                                                        SINGLE_CLICK_TIMEOUT );
    }
    gtk_widget_show( data->result_view );
    gtk_container_add( (GtkContainer*)gtk_builder_get_object(builder, "result_scroll"), data->result_view );
    init_search_result( data );
    g_signal_connect(data->result_view, "button-press-event", G_CALLBACK( on_view_button_press ), data );

    /* buttons */
    data->start_btn = (GtkWidget*)gtk_builder_get_object( builder, "start_btn" );
    data->stop_btn = (GtkWidget*)gtk_builder_get_object( builder, "stop_btn" );
    data->again_btn = (GtkWidget*)gtk_builder_get_object( builder, "again_btn" );
    img = gtk_image_new_from_icon_name( GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON );
    gtk_button_set_image( (GtkButton*)data->again_btn, img );

    g_signal_connect(data->start_btn, "clicked", G_CALLBACK( on_start_search ), data );
    g_signal_connect(data->stop_btn, "clicked", G_CALLBACK( on_stop_search ), data );
    g_signal_connect(data->again_btn, "clicked", G_CALLBACK( on_search_again ), data );


    gtk_entry_set_text( (GtkEntry*)data->fn_pattern_entry, "*" );
    gtk_editable_select_region( (GtkEditable*)data->fn_pattern_entry, 0, -1 );

    gtk_combo_box_set_active( (GtkComboBox*)data->size_lower_unit, 1 );
    gtk_spin_button_set_range( (GtkSpinButton*)data->size_lower, 0, G_MAXINT );
    gtk_combo_box_set_active( (GtkComboBox*)data->size_upper_unit, 2 );
    gtk_spin_button_set_range( (GtkSpinButton*)data->size_upper, 0, G_MAXINT );

    gtk_combo_box_set_active( (GtkComboBox*)data->date_limit, 0 );

    g_signal_connect( data->win, "delete-event", G_CALLBACK(gtk_widget_destroy), NULL );

    pcmanfm_ref();
    g_signal_connect( data->win, "destroy", G_CALLBACK(pcmanfm_unref), NULL );

    int width = xset_get_int( "main_search", "x" );
    int height = xset_get_int( "main_search", "y" );
    if ( width && height )
        gtk_window_set_default_size( GTK_WINDOW( data->win ), width, height );
    
    gtk_widget_show( data->win );

}
コード例 #2
0
ファイル: prefs_actions.c プロジェクト: SpOOnman/claws
static void prefs_actions_create(MainWindow *mainwin)
{
	GtkWidget *window;
	GtkWidget *vbox;
	GtkWidget *filter_hbox;
	GtkWidget *help_btn;
	GtkWidget *ok_btn;
	GtkWidget *cancel_btn;
	GtkWidget *confirm_area;

	GtkWidget *vbox1;
	GtkWidget *table;

	GtkWidget *shell_radiobtn;
	GtkWidget *filter_radiobtn;

	GtkWidget *name_label;
	GtkWidget *name_entry;
	GtkWidget *cmd_label;
	GtkWidget *cmd_entry;
	GtkWidget *filter_btn;

	GtkWidget *reg_hbox;
	GtkWidget *btn_hbox;
	GtkWidget *arrow;
	GtkWidget *reg_btn;
	GtkWidget *subst_btn;
	GtkWidget *del_btn;
	GtkWidget *clear_btn;

	GtkWidget *cond_hbox;
	GtkWidget *cond_scrolledwin;
	GtkWidget *cond_list_view;

	GtkWidget *info_btn;

	GtkWidget *btn_vbox;
	GtkWidget *up_btn;
	GtkWidget *down_btn;
	static GdkGeometry geometry;

	debug_print("Creating actions configuration window...\n");

	window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_actions");

	gtk_container_set_border_width(GTK_CONTAINER (window), 8);
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
	gtk_window_set_resizable(GTK_WINDOW(window), TRUE);

	vbox = gtk_vbox_new(FALSE, 6);
	gtk_widget_show(vbox);
	gtk_container_add(GTK_CONTAINER(window), vbox);

	gtkut_stock_button_set_create_with_help(&confirm_area, &help_btn,
			&cancel_btn, GTK_STOCK_CANCEL,
			&ok_btn, GTK_STOCK_OK,
			NULL, NULL);
	gtk_widget_show(confirm_area);
	gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
	gtk_widget_grab_default(ok_btn);

	gtk_window_set_title(GTK_WINDOW(window), _("Actions configuration"));
	g_signal_connect(G_OBJECT(window), "delete_event",
			 G_CALLBACK(prefs_actions_deleted), NULL);
	g_signal_connect(G_OBJECT(window), "size_allocate",
			 G_CALLBACK(prefs_actions_size_allocate_cb), NULL);
	g_signal_connect(G_OBJECT(window), "key_press_event",
			 G_CALLBACK(prefs_actions_key_pressed), NULL);
	MANAGE_WINDOW_SIGNALS_CONNECT(window);
	g_signal_connect(G_OBJECT(ok_btn), "clicked",
			 G_CALLBACK(prefs_actions_ok), mainwin);
	g_signal_connect(G_OBJECT(cancel_btn), "clicked",
			 G_CALLBACK(prefs_actions_cancel), NULL);
	g_signal_connect(G_OBJECT(help_btn), "clicked",
			 G_CALLBACK(manual_open_with_anchor_cb),
			 MANUAL_ANCHOR_ACTIONS);

	vbox1 = gtk_vbox_new(FALSE, VSPACING);
	gtk_widget_show(vbox1);
	gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
	gtk_container_set_border_width(GTK_CONTAINER(vbox1), 2);	

	table = gtk_table_new(3, 2, FALSE);
	gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
	gtk_table_set_col_spacings (GTK_TABLE (table), 4);
	gtk_widget_show(table);
	gtk_box_pack_start (GTK_BOX (vbox1), table, FALSE, FALSE, 0);

	name_label = gtk_label_new (_("Menu name"));
	gtk_widget_show (name_label);
	gtk_misc_set_alignment (GTK_MISC (name_label), 1, 0.5);
  	gtk_table_attach (GTK_TABLE (table), name_label, 0, 1, 0, 1,
                    	  (GtkAttachOptions) (GTK_FILL),
                    	  (GtkAttachOptions) (0), 0, 0);

	name_entry = gtk_entry_new ();
	gtk_widget_show (name_entry);
  	gtk_table_attach (GTK_TABLE (table), name_entry, 1, 2, 0, 1,
                    	  (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
			  (GtkAttachOptions) (0), 0, 0);

	cmd_label = gtk_label_new (_("Command"));
	gtk_widget_show (cmd_label);
	gtk_misc_set_alignment (GTK_MISC (cmd_label), 1, 0.5);
  	gtk_table_attach (GTK_TABLE (table), cmd_label, 0, 1, 2, 3,
                    	  (GtkAttachOptions) (GTK_FILL),
                    	  (GtkAttachOptions) (0), 0, 0);

	cmd_entry = gtk_entry_new ();
	gtk_widget_show (cmd_entry);
  	gtk_table_attach (GTK_TABLE (table), cmd_entry, 1, 2, 2, 3,
                    	  (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
                    	  (GtkAttachOptions) (0), 0, 0);

	/* radio buttons for filter actions or shell */
	filter_hbox = gtk_hbox_new(FALSE,4);
	gtk_table_attach(GTK_TABLE(table), filter_hbox, 1, 2, 3, 4,
                    	  (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
			  (GtkAttachOptions) (0), 0, 0);
	gtk_widget_show(filter_hbox);

	shell_radiobtn = gtk_radio_button_new_with_label(NULL, _("Shell command"));
	gtk_box_pack_start(GTK_BOX(filter_hbox), shell_radiobtn, FALSE, FALSE, 0);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(shell_radiobtn), TRUE);
	gtk_widget_show(shell_radiobtn);
	
	g_signal_connect(G_OBJECT(shell_radiobtn), "clicked",
			 G_CALLBACK(prefs_action_shell_radiobtn_cb), NULL);

	filter_radiobtn =
		gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(shell_radiobtn), 
							    _("Filter action"));
	gtk_box_pack_start(GTK_BOX(filter_hbox), filter_radiobtn, FALSE, FALSE, 0);
	gtk_widget_show(filter_radiobtn);
	g_signal_connect(G_OBJECT(filter_radiobtn), "clicked",
			 G_CALLBACK(prefs_action_filter_radiobtn_cb), NULL);

	filter_btn = gtk_button_new_with_label(_("Edit filter action"));
	gtk_box_pack_start(GTK_BOX(filter_hbox), filter_btn, FALSE, FALSE, 0);
	gtk_widget_set_sensitive(filter_btn, FALSE);
	g_signal_connect(G_OBJECT(filter_btn), "clicked",
			 G_CALLBACK(prefs_action_filterbtn_cb), NULL);
	gtk_widget_show(filter_btn);

	/* register / substitute / delete */

	reg_hbox = gtk_hbox_new(FALSE, 4);
	gtk_widget_show(reg_hbox);
	gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);

	arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
	gtk_widget_show(arrow);
	gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
	gtk_widget_set_size_request(arrow, -1, 16);

	btn_hbox = gtk_hbox_new(TRUE, 4);
	gtk_widget_show(btn_hbox);
	gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);

	reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
	gtk_widget_show(reg_btn);
	gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
	g_signal_connect(G_OBJECT(reg_btn), "clicked",
			 G_CALLBACK(prefs_actions_register_cb), NULL);
	CLAWS_SET_TIP(reg_btn,
			_("Append the new action above to the list"));

	subst_btn = gtkut_get_replace_btn(_("_Replace"));
	gtk_widget_show(subst_btn);
	gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
	g_signal_connect(G_OBJECT(subst_btn), "clicked",
			 G_CALLBACK(prefs_actions_substitute_cb), NULL);
	CLAWS_SET_TIP(subst_btn,
			_("Replace the selected action in list with the action above"));

	del_btn = gtk_button_new_with_mnemonic (_("Re_move"));
	gtk_button_set_image(GTK_BUTTON(del_btn),
			gtk_image_new_from_stock(GTK_STOCK_REMOVE,GTK_ICON_SIZE_BUTTON));
	gtk_widget_show(del_btn);
	gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
	g_signal_connect(G_OBJECT(del_btn), "clicked",
			 G_CALLBACK(prefs_actions_delete_cb), NULL);
	CLAWS_SET_TIP(del_btn,
			_("Delete the selected action from the list"));

	clear_btn = gtk_button_new_with_mnemonic (_("C_lear"));
	gtk_button_set_image(GTK_BUTTON(clear_btn),
			gtk_image_new_from_stock(GTK_STOCK_CLEAR,GTK_ICON_SIZE_BUTTON));
	gtk_widget_show (clear_btn);
	gtk_box_pack_start (GTK_BOX (btn_hbox), clear_btn, FALSE, TRUE, 0);
	g_signal_connect(G_OBJECT (clear_btn), "clicked",
			G_CALLBACK(prefs_actions_clear_cb), NULL);
	CLAWS_SET_TIP(clear_btn,
			_("Clear all the input fields in the dialog"));

	info_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
	gtk_widget_show(info_btn);
	gtk_box_pack_end(GTK_BOX(reg_hbox), info_btn, FALSE, FALSE, 0);
	g_signal_connect(G_OBJECT(info_btn), "clicked",
			 G_CALLBACK(prefs_actions_info_cb), GTK_WINDOW(window));
	CLAWS_SET_TIP(info_btn,
			_("Show information on configuring actions"));

	cond_hbox = gtk_hbox_new(FALSE, 8);
	gtk_widget_show(cond_hbox);
	gtk_box_pack_start(GTK_BOX(vbox1), cond_hbox, TRUE, TRUE, 0);

	cond_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
	gtk_widget_show(cond_scrolledwin);
	gtk_widget_set_size_request(cond_scrolledwin, -1, 150);
	gtk_box_pack_start(GTK_BOX(cond_hbox), cond_scrolledwin,
			   TRUE, TRUE, 0);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (cond_scrolledwin),
				       GTK_POLICY_AUTOMATIC,
				       GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(cond_scrolledwin),
					    GTK_SHADOW_ETCHED_IN);

	cond_list_view = prefs_actions_list_view_create();				       
	gtk_widget_show(cond_list_view);
	gtk_container_add(GTK_CONTAINER (cond_scrolledwin), cond_list_view);

	btn_vbox = gtk_vbox_new(FALSE, 8);
	gtk_widget_show(btn_vbox);
	gtk_box_pack_start(GTK_BOX(cond_hbox), btn_vbox, FALSE, FALSE, 0);

	up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
	gtk_widget_show(up_btn);
	gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
	g_signal_connect(G_OBJECT(up_btn), "clicked",
			 G_CALLBACK(prefs_actions_up), NULL);
	CLAWS_SET_TIP(up_btn,
			_("Move the selected action up"));

	down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
	gtk_widget_show(down_btn);
	gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
	g_signal_connect(G_OBJECT(down_btn), "clicked",
			 G_CALLBACK(prefs_actions_down), NULL);
	CLAWS_SET_TIP(down_btn,
			_("Move selected action down"));

	if (!geometry.min_height) {
		geometry.min_width = 486;
		geometry.min_height = 322;
	}

	gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
				      GDK_HINT_MIN_SIZE);
	gtk_widget_set_size_request(window, prefs_common.actionswin_width,
				    prefs_common.actionswin_height);

	gtk_widget_show(window);

	actions.window = window;
	actions.ok_btn = ok_btn;
	actions.info_btn = info_btn;

	actions.name_entry = name_entry;
	actions.cmd_entry  = cmd_entry;
	actions.filter_btn = filter_btn;
	actions.shell_radiobtn = shell_radiobtn;
	actions.filter_radiobtn = filter_radiobtn;
	
	actions.actions_list_view = cond_list_view;
}
コード例 #3
0
ファイル: gui_gtk3.c プロジェクト: avafinger/guvcview_2.0.4
/*
 * GUI initialization
 * args:
 *   width - window width
 *   height - window height
 *
 * asserts:
 *   none
 *
 * returns: error code (0 -OK)
 */
int gui_attach_gtk3(int width, int height)
{
	if(!gtk_init_called)
	{
		if(!gtk_init_check(NULL, NULL))
		{
			fprintf(stderr, "GUVCVIEW: (GUI) Gtk3 can't open display\n");
			return -1;
		}

		gtk_init_called = 1;
	}


	/*check for device errors*/
	//if(!device)
	//{
	//	gui_error("Guvcview error", "no video device found", 1);
	//	return -1;
	//}

	g_set_application_name(_("Guvcview Video Capture"));

#if !GTK_VER_AT_LEAST(3,12)
	/* make sure the type is realized so that we can change the properties*/
	g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON));
	/* make sure gtk-button-images property is set to true (defaults to false in karmic)*/
	g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL);
#endif

	/* Create a main window */
	main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (main_window), _("Guvcview"));
	gtk_widget_show (main_window);

	/* get screen resolution */
	GdkScreen* screen = NULL;
	screen = gtk_window_get_screen(GTK_WINDOW(main_window));
	int desktop_width = gdk_screen_get_width(screen);
	int desktop_height = gdk_screen_get_height(screen);

	if(debug_level > 0)
		printf("GUVCVIEW: (GUI) Screen resolution is (%d x %d)\n", desktop_width, desktop_height);

	if((width > desktop_width) && (desktop_width > 0))
		width = desktop_width;
	if((height > desktop_height) && (desktop_height > 0))
		height = desktop_height;

	gtk_window_resize(GTK_WINDOW(main_window), width, height);

	/* Add delete event handler */
	g_signal_connect(GTK_WINDOW(main_window), "delete_event", G_CALLBACK(delete_event), NULL);

	/*window icon*/
	char* icon1path = g_strconcat (PACKAGE_DATA_DIR, "/pixmaps/guvcview/guvcview.png", NULL);
	if (g_file_test(icon1path, G_FILE_TEST_EXISTS))
		gtk_window_set_icon_from_file(GTK_WINDOW (main_window), icon1path, NULL);
	g_free(icon1path);

	/*---------------------------- Main table ---------------------------------*/
	GtkWidget *maintable = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
	gtk_widget_show (maintable);

	/*----------------------------- Top Menu ----------------------------------*/
	gui_attach_gtk3_menu(maintable);

	/*----------------------------- Buttons -----------------------------------*/
	GtkWidget *HButtonBox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
	gtk_widget_set_halign (HButtonBox, GTK_ALIGN_FILL);
	gtk_widget_set_hexpand (HButtonBox, TRUE);
	gtk_button_box_set_layout(GTK_BUTTON_BOX(HButtonBox),GTK_BUTTONBOX_SPREAD);
	gtk_box_set_homogeneous(GTK_BOX(HButtonBox),TRUE);
	gtk_widget_show(HButtonBox);

	/*photo button*/
	if(check_photo_timer())
	{
		CapImageButt = gtk_button_new_with_mnemonic (_("Stop Cap. (I)"));
		g_object_set_data (G_OBJECT (CapImageButt), "control_info",
							GINT_TO_POINTER(1));
	}
	else
	{
		CapImageButt = gtk_button_new_with_mnemonic (_("Cap. Image (I)"));
		g_object_set_data (G_OBJECT (CapImageButt), "control_info",
							GINT_TO_POINTER(0));
	}

	char *pix2path = g_strconcat (PACKAGE_DATA_DIR, "/pixmaps/guvcview/camera.png",NULL);
	if (g_file_test(pix2path, G_FILE_TEST_EXISTS))
	{
		GtkWidget *ImgButton_Img = gtk_image_new_from_file (pix2path);
#if GTK_VER_AT_LEAST(3,12)		
		gtk_button_set_always_show_image(GTK_BUTTON(CapImageButt), TRUE);
#endif
		gtk_button_set_image(GTK_BUTTON(CapImageButt), ImgButton_Img);
		gtk_button_set_image_position(GTK_BUTTON(CapImageButt), GTK_POS_TOP);
	}
	g_free(pix2path);
	
	gtk_box_pack_start(GTK_BOX(HButtonBox), CapImageButt, TRUE, TRUE, 2);
	gtk_widget_show (CapImageButt);

	g_signal_connect (GTK_BUTTON(CapImageButt), "clicked",
		G_CALLBACK (capture_image_clicked), NULL);

	/*video button*/
	CapVideoButt = gtk_toggle_button_new_with_mnemonic (_("Cap. Video (V)"));
	gui_set_video_capture_button_status_gtk3(get_encoder_status());

	char *pix3path = g_strconcat (PACKAGE_DATA_DIR, "/pixmaps/guvcview/movie.png",NULL);
	if (g_file_test(pix3path, G_FILE_TEST_EXISTS))
	{
		GtkWidget *VideoButton_Img = gtk_image_new_from_file (pix3path);
#if GTK_VER_AT_LEAST(3,12)
		gtk_button_set_always_show_image(GTK_BUTTON(CapVideoButt), TRUE);
#endif
		gtk_button_set_image(GTK_BUTTON(CapVideoButt), VideoButton_Img);
		gtk_button_set_image_position(GTK_BUTTON(CapVideoButt), GTK_POS_TOP);
	}
	g_free(pix3path);

	gtk_box_pack_start(GTK_BOX(HButtonBox), CapVideoButt, TRUE, TRUE, 2);
	gtk_widget_show (CapVideoButt);

	g_signal_connect (GTK_BUTTON(CapVideoButt), "clicked",
		G_CALLBACK (capture_video_clicked), NULL);

	/*quit button*/
	//GtkWidget *quitButton = gtk_button_new_from_stock(GTK_STOCK_QUIT);
	GtkWidget *quitButton = gtk_button_new_with_mnemonic (_("Quit"));

	char* pix4path = g_strconcat (PACKAGE_DATA_DIR, "/pixmaps/guvcview/close.png", NULL);
	if (g_file_test(pix4path,G_FILE_TEST_EXISTS))
	{
		GtkWidget *QButton_Img = gtk_image_new_from_file (pix4path);
#if GTK_VER_AT_LEAST(3,12)		
		gtk_button_set_always_show_image(GTK_BUTTON(quitButton), TRUE);
#endif
		gtk_button_set_image(GTK_BUTTON(quitButton), QButton_Img);
		gtk_button_set_image_position(GTK_BUTTON(quitButton), GTK_POS_TOP);

	}
	/*must free path strings*/
	g_free(pix4path);
	gtk_box_pack_start(GTK_BOX(HButtonBox), quitButton, TRUE, TRUE, 2);
	gtk_widget_show_all (quitButton);

	g_signal_connect (GTK_BUTTON(quitButton), "clicked",
		G_CALLBACK (quit_button_clicked), NULL);

	gtk_box_pack_start(GTK_BOX(maintable), HButtonBox, FALSE, TRUE, 2);

	/*--------------------------- Tab container -------------------------------*/
	GtkWidget *tab_box = gtk_notebook_new();
	gtk_widget_show (tab_box);

	/*------------------------ Image controls Tab -----------------------------*/

	GtkWidget *scroll_1 = gtk_scrolled_window_new(NULL,NULL);
	gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(scroll_1), GTK_CORNER_TOP_LEFT);
	gtk_widget_show(scroll_1);

	/*
	 * viewport is only needed for gtk < 3.8
	 * for 3.8 and above controls tab can be directly added to scroll1
	 */
	GtkWidget* viewport = gtk_viewport_new(NULL,NULL);
	gtk_widget_show(viewport);

	gtk_container_add(GTK_CONTAINER(scroll_1), viewport);

	gui_attach_gtk3_v4l2ctrls(viewport);

	GtkWidget *tab_1 = gtk_grid_new();
	gtk_widget_show (tab_1);

    GtkWidget *tab_1_label = gtk_label_new(_("Image Controls"));
	gtk_widget_show (tab_1_label);
	/** check for files */
	gchar *tab_1_icon_path = g_strconcat (PACKAGE_DATA_DIR,"/pixmaps/guvcview/image_controls.png",NULL);
	/** don't test for file - use default empty image if load fails */
	/** get icon image*/
	GtkWidget *tab_1_icon = gtk_image_new_from_file(tab_1_icon_path);
	gtk_widget_show (tab_1_icon);

	g_free(tab_1_icon_path);
	gtk_grid_attach (GTK_GRID(tab_1), tab_1_icon, 0, 0, 1, 1);
	gtk_grid_attach (GTK_GRID(tab_1), tab_1_label, 1, 0, 1, 1);

	gtk_notebook_append_page(GTK_NOTEBOOK(tab_box), scroll_1, tab_1);

	/*----------------------------H264 Controls Tab --------------------------*/
	if(v4l2core_get_h264_unit_id(get_v4l2_device_handler()) > 0)
	{
		GtkWidget *scroll_2 = gtk_scrolled_window_new(NULL,NULL);
		gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(scroll_2), GTK_CORNER_TOP_LEFT);
		gtk_widget_show(scroll_2);

		/*
		 * viewport is only needed for gtk < 3.8
		 * for 3.8 and above controls tab can be directly added to scroll1
		 */
		GtkWidget* viewport2 = gtk_viewport_new(NULL,NULL);
		gtk_widget_show(viewport2);

		gtk_container_add(GTK_CONTAINER(scroll_2), viewport2);

		gui_attach_gtk3_h264ctrls(viewport2);

		GtkWidget *tab_2 = gtk_grid_new();
		gtk_widget_show (tab_2);

		GtkWidget *tab_2_label = gtk_label_new(_("H264 Controls"));
		gtk_widget_show (tab_2_label);
		/** check for files */
		gchar *tab_2_icon_path = g_strconcat (PACKAGE_DATA_DIR,"/pixmaps/guvcview/image_controls.png",NULL);
		/** don't test for file - use default empty image if load fails */
		/** get icon image*/
		GtkWidget *tab_2_icon = gtk_image_new_from_file(tab_2_icon_path);
		gtk_widget_show (tab_2_icon);

		g_free(tab_2_icon_path);
		gtk_grid_attach (GTK_GRID(tab_2), tab_2_icon, 0, 0, 1, 1);
		gtk_grid_attach (GTK_GRID(tab_2), tab_2_label, 1, 0, 1, 1);

		gtk_notebook_append_page(GTK_NOTEBOOK(tab_box), scroll_2, tab_2);
	}

	/*exclude video and audio tabs if we are in control panel mode*/
	if(!is_control_panel)
	{
		/*----------------------- Video controls Tab ------------------------------*/

		GtkWidget *scroll_3 = gtk_scrolled_window_new(NULL,NULL);
		gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(scroll_3), GTK_CORNER_TOP_LEFT);
		gtk_widget_show(scroll_3);

		/*
		 * viewport is only needed for gtk < 3.8
		 * for 3.8 and above controls tab can be directly added to scroll1
		 */
		GtkWidget* viewport3 = gtk_viewport_new(NULL,NULL);
		gtk_widget_show(viewport3);

		gtk_container_add(GTK_CONTAINER(scroll_3), viewport3);

		gui_attach_gtk3_videoctrls(viewport3);

		GtkWidget *tab_3 = gtk_grid_new();
		gtk_widget_show (tab_3);

		GtkWidget *tab_3_label = gtk_label_new(_("Video Controls"));
		gtk_widget_show (tab_3_label);
		/** check for files */
		gchar *tab_3_icon_path = g_strconcat (PACKAGE_DATA_DIR,"/pixmaps/guvcview/video_controls.png",NULL);
		/** don't test for file - use default empty image if load fails */
		/** get icon image*/
		GtkWidget *tab_3_icon = gtk_image_new_from_file(tab_3_icon_path);
		gtk_widget_show (tab_3_icon);

		g_free(tab_3_icon_path);
		gtk_grid_attach (GTK_GRID(tab_3), tab_3_icon, 0, 0, 1, 1);
		gtk_grid_attach (GTK_GRID(tab_3), tab_3_label, 1, 0, 1, 1);

		gtk_notebook_append_page(GTK_NOTEBOOK(tab_box), scroll_3, tab_3);

		/*----------------------- Audio controls Tab ------------------------------*/

		GtkWidget *scroll_4 = gtk_scrolled_window_new(NULL,NULL);
		gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(scroll_4), GTK_CORNER_TOP_LEFT);
		gtk_widget_show(scroll_4);

		/*
		 * viewport is only needed for gtk < 3.8
		 * for 3.8 and above controls tab can be directly added to scroll1
		 */
		GtkWidget* viewport4 = gtk_viewport_new(NULL,NULL);
		gtk_widget_show(viewport4);

		gtk_container_add(GTK_CONTAINER(scroll_4), viewport4);

		gui_attach_gtk3_audioctrls(viewport4);

		GtkWidget *tab_4 = gtk_grid_new();
		gtk_widget_show (tab_4);

		GtkWidget *tab_4_label = gtk_label_new(_("Audio Controls"));
		gtk_widget_show (tab_4_label);
		/** check for files */
		gchar *tab_4_icon_path = g_strconcat (PACKAGE_DATA_DIR,"/pixmaps/guvcview/audio_controls.png",NULL);
		/** don't test for file - use default empty image if load fails */
		/** get icon image*/
		GtkWidget *tab_4_icon = gtk_image_new_from_file(tab_4_icon_path);
		gtk_widget_show (tab_4_icon);

		g_free(tab_4_icon_path);
		gtk_grid_attach (GTK_GRID(tab_4), tab_4_icon, 0, 0, 1, 1);
		gtk_grid_attach (GTK_GRID(tab_4), tab_4_label, 1, 0, 1, 1);

		gtk_notebook_append_page(GTK_NOTEBOOK(tab_box), scroll_4, tab_4);
	}

	/* Attach the notebook (tabs) */
	gtk_box_pack_start(GTK_BOX(maintable), tab_box, TRUE, TRUE, 2);

	/*-------------------------- Status bar ------------------------------------*/
	status_bar = gtk_statusbar_new();
	status_warning_id = gtk_statusbar_get_context_id (GTK_STATUSBAR(status_bar), "warning");

    gtk_widget_show(status_bar);
	/* add the status bar*/
	gtk_box_pack_start(GTK_BOX(maintable), status_bar, FALSE, FALSE, 2);


	/* attach to main window container */
	gtk_container_add (GTK_CONTAINER (main_window), maintable);

	/* add key events*/
	gtk_widget_add_events (GTK_WIDGET (main_window), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
	g_signal_connect (GTK_WINDOW(main_window), "key_press_event", G_CALLBACK(window_key_pressed), NULL);

	/* add update timers:
	 *  devices
	 */
	gtk_devices_timer_id = g_timeout_add( 1000, check_device_events, NULL);
	/*controls*/
	gtk_control_events_timer_id = g_timeout_add(1000, check_control_events, NULL);

	return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: xdien/my_cproject
int main(int argc, char *argv[])
{
	printf("%s \nPlease report any bug to %s\n", PACKAGE_STRING, PACKAGE_BUGREPORT);	
	//printf("number of arg = %d, argv = %s\n", argc, argv[1]);
	/*printf("argc = %d\n", argc);
	if (argv[1] != NULL) {
		if (strstr (argv[1],"debug") != NULL) {
		debug = TRUE;
		printf("debug = TRUE\n");
			}  
		}
	DEBUG("debug is true\n");*/
	gchar *filename;
	int i = 0;
	gint initialWindowHeight = 170;
	guint timeoutEvent, intervalDisplaySpectro;
	GtkWidget *pVBox[4], *pHBox[13], *menuBar, *menu, *submenu, *menuItem, *submenuItem, *button, *frame, *image, *label, *widget;
	GdkColor color;
	Spectrum3dGui spectrum3dGui;
	GSList *radio_menu_group;
	GError **error;

#if defined (GTKGLEXT3) || defined (GTKGLEXT1)
	GdkGLConfig *glconfig;
#endif 
	
	gst_init (NULL, NULL);
	gtk_init (&argc, &argv);

	get_saved_values();
	intervalDisplaySpectro = (guint)spectrum3d.interval_display;

#if defined (GTKGLEXT3) || defined (GTKGLEXT1)
	gtk_gl_init(NULL, NULL);
	glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB    |
					GDK_GL_MODE_DEPTH  |
					GDK_GL_MODE_DOUBLE);
	  if (glconfig == NULL)
	    {
	      g_print ("\n*** Cannot find the double-buffered visual.\n");
	      g_print ("\n*** Trying single-buffered visual.\n");

	      /* Try single-buffered visual */
	      glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB   |
						    GDK_GL_MODE_DEPTH);
	      if (glconfig == NULL)
		{
		  g_print ("*** No appropriate OpenGL-capable visual found.\n");
		  exit (1);
		}
	    }
#endif

	initGstreamer();
	init_audio_values();
	init_display_values(&spectrum3dGui);
	
	spectrum3dGui.mainWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_size_request (spectrum3dGui.mainWindow, 700, initialWindowHeight);
	gtk_widget_realize(spectrum3dGui.mainWindow);
	gtk_window_set_title(GTK_WINDOW(spectrum3dGui.mainWindow), PACKAGE_NAME);
	filename = g_build_filename (G_DIR_SEPARATOR_S, DATADIR, "icons", "spectrum3d.png", NULL);
	gtk_window_set_icon(GTK_WINDOW(spectrum3dGui.mainWindow), gdk_pixbuf_new_from_file (filename, error));
	g_signal_connect (G_OBJECT (spectrum3dGui.mainWindow), "destroy", G_CALLBACK (quit_spectrum3d), NULL);

#ifdef GTK3
	gtk_container_set_reallocate_redraws (GTK_CONTAINER (spectrum3dGui.mainWindow), TRUE);
#endif

#ifdef GTK3
	for (i = 0; i < 4; i++) {
		pVBox[i] = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
		}
	pHBox[0] = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
	for (i = 1; i < 12; i++) {
		pHBox[i] = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
		}
	pHBox[12] = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#elif defined GTK2
	for (i = 0; i < 4; i++) {
		pVBox[i] = gtk_vbox_new(FALSE, 0);
		}
	pHBox[0] = gtk_hbox_new(TRUE, 0);
	for (i = 1; i < 12; i++) {
		pHBox[i] = gtk_hbox_new(FALSE, 0);
		}
	pHBox[12] = gtk_hbox_new(TRUE, 0);
#endif
	
	gtk_container_add(GTK_CONTAINER(spectrum3dGui.mainWindow), pVBox[1]); 
	gtk_box_pack_start(GTK_BOX(pVBox[1]), pHBox[0], FALSE, FALSE, 0);
		
/* Menu */
	menuBar = gtk_menu_bar_new();

	menu = gtk_menu_new(); // 'Quit' submenu
	menuItem = gtk_menu_item_new_with_label("Quit");
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItem);    
	g_signal_connect(G_OBJECT(menuItem), "activate", G_CALLBACK(gtk_main_quit), NULL); 
	menuItem = gtk_menu_item_new_with_label("Quit");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItem), menu);
	gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), menuItem);

	menu = gtk_menu_new(); // 'Edit' submenu
        menuItem = gtk_menu_item_new_with_label("Preferences");
	g_signal_connect(G_OBJECT(menuItem), "activate", G_CALLBACK(onPreferences), &spectrum3dGui);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItem);
	menuItem = gtk_menu_item_new_with_label("Edit");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItem), menu);
	gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), menuItem);

	menu = gtk_menu_new(); // 'Sound' submenu
	menuItem = gtk_menu_item_new_with_label("Sound");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItem), menu);
	gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), menuItem);

		submenu = gtk_menu_new();// 'Play test sound' sub-submenu
		spectrum3dGui.checkMenuTestSound = gtk_check_menu_item_new_with_label("Test Sound");
		gtk_menu_shell_append(GTK_MENU_SHELL(menu), spectrum3dGui.checkMenuTestSound);
		g_signal_connect(G_OBJECT(spectrum3dGui.checkMenuTestSound), "activate", G_CALLBACK(menu_check_test_sound), &spectrum3dGui);

	menu = gtk_menu_new(); // 'View' submenu
	menuItem = gtk_menu_item_new_with_label("View");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItem), menu);
	gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), menuItem);
	
		submenu = gtk_menu_new();// 'viewType' sub-submenu
		menuItem = gtk_menu_item_new_with_label("Perspective");
		gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuItem), submenu);
		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItem);	
			
			spectrum3dGui.radio3D = gtk_radio_menu_item_new_with_label(NULL, "3D (D)");
			radio_menu_group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(spectrum3dGui.radio3D));
			g_signal_connect(G_OBJECT(spectrum3dGui.radio3D), "toggled", G_CALLBACK(change_perspective), spectrum3dGui.radio3D);
			gtk_menu_shell_append(GTK_MENU_SHELL(submenu), spectrum3dGui.radio3D);

			spectrum3dGui.radio3Dflat = gtk_radio_menu_item_new_with_label(radio_menu_group, "3D flat (F)");
			radio_menu_group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(spectrum3dGui.radio3Dflat));
			g_signal_connect(G_OBJECT(spectrum3dGui.radio3Dflat), "toggled", G_CALLBACK(change_perspective), spectrum3dGui.radio3Dflat);
			gtk_menu_shell_append(GTK_MENU_SHELL(submenu), spectrum3dGui.radio3Dflat);

			spectrum3dGui.radio2D = gtk_radio_menu_item_new_with_label(radio_menu_group, "2D (D)");
			radio_menu_group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(spectrum3dGui.radio2D));
			g_signal_connect(G_OBJECT(spectrum3dGui.radio2D), "toggled", G_CALLBACK(change_perspective), spectrum3dGui.radio2D);
			gtk_menu_shell_append(GTK_MENU_SHELL(submenu), spectrum3dGui.radio2D);

		submenu = gtk_menu_new();// 'Scale' sub-submenu
		menuItem = gtk_menu_item_new_with_label("Scale");
		gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuItem), submenu);
		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItem);	
	
			spectrum3dGui.checkMenuText = gtk_check_menu_item_new_with_label("Text (T)");
			gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(spectrum3dGui.checkMenuText), TRUE);
			g_signal_connect(G_OBJECT(spectrum3dGui.checkMenuText), "activate", G_CALLBACK(check_menu_text), &spectrum3dGui);
			gtk_menu_shell_append(GTK_MENU_SHELL(submenu), spectrum3dGui.checkMenuText);
	
			spectrum3dGui.checkMenuLines = gtk_check_menu_item_new_with_label("Lines (L)");
			gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(spectrum3dGui.checkMenuLines), TRUE);
			g_signal_connect(G_OBJECT(spectrum3dGui.checkMenuLines), "activate", G_CALLBACK(check_menu_lines), &spectrum3dGui);
			gtk_menu_shell_append(GTK_MENU_SHELL(submenu), spectrum3dGui.checkMenuLines);

			spectrum3dGui.checkMenuPointer = gtk_check_menu_item_new_with_label("Pointer (P)");
			g_signal_connect(G_OBJECT(spectrum3dGui.checkMenuPointer), "activate", G_CALLBACK(check_menu_pointer), &spectrum3dGui);
			gtk_menu_shell_append(GTK_MENU_SHELL(submenu), spectrum3dGui.checkMenuPointer);

		submenu = gtk_menu_new();// 'Change/reset view' sub-submenu
		menuItem = gtk_menu_item_new_with_label("Change/reset view");
		gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuItem), submenu);
		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItem);	
			
			spectrum3dGui.reset = gtk_menu_item_new_with_label("Reset view (R)");
			gtk_widget_set_tooltip_text (spectrum3dGui.reset, "Reset the view as if Spectrum3d was just started");
			g_signal_connect(G_OBJECT(spectrum3dGui.reset), "activate", G_CALLBACK(reset_view), spectrum3dGui.reset);
			gtk_menu_shell_append(GTK_MENU_SHELL(submenu), spectrum3dGui.reset);

			spectrum3dGui.front = gtk_menu_item_new_with_label("Front view (O)");
			gtk_widget_set_tooltip_text (spectrum3dGui.front, "2D view showing frequency versus intensity of the sound; shows a snapshot of the harmonics at a given time");
			g_signal_connect(G_OBJECT(spectrum3dGui.front), "activate", G_CALLBACK(front_view), spectrum3dGui.front);
			gtk_menu_shell_append(GTK_MENU_SHELL(submenu), spectrum3dGui.front);

			submenuItem = gtk_menu_item_new_with_label("Preset view");
			gtk_widget_set_tooltip_text (submenuItem, "Set the view with the chosen preset values");
			g_signal_connect(G_OBJECT(submenuItem), "activate", G_CALLBACK(set_view_from_preset), submenuItem);
			gtk_menu_shell_append(GTK_MENU_SHELL(submenu), submenuItem);

	menu = gtk_menu_new(); // 'Help...' submenu
	menuItem = gtk_menu_item_new_with_label("Shortcuts"); 
	g_signal_connect(G_OBJECT(menuItem), "activate", G_CALLBACK(onShortcuts), (GtkWidget*) spectrum3dGui.mainWindow);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItem);
#ifdef HAVE_LIBGEIS
	menuItem = gtk_menu_item_new_with_label("Gestures Shortcuts");
	g_signal_connect(G_OBJECT(menuItem), "activate", G_CALLBACK(onGesturesShortcuts), (GtkWidget*) spectrum3dGui.mainWindow);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItem);
#endif 
	menuItem = gtk_menu_item_new_with_label("About...");
	g_signal_connect(G_OBJECT(menuItem), "activate", G_CALLBACK(onAbout), (GtkWidget*) spectrum3dGui.mainWindow);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItem);
	menuItem = gtk_menu_item_new_with_label("Quick start");
	g_signal_connect(G_OBJECT(menuItem), "activate", G_CALLBACK(onQuickStart), (GtkWidget*) spectrum3dGui.mainWindow);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItem);
	menuItem = gtk_menu_item_new_with_label("Help");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItem), menu);
	gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), menuItem);
	gtk_box_pack_start(GTK_BOX(pHBox[0]), menuBar, FALSE, TRUE, 0);

/* SourceButtons to set type of source (none, audio file, microphone) */
	spectrum3dGui.stop = gtk_button_new();
	filename = g_build_filename (G_DIR_SEPARATOR_S, DATADIR, "icons", "stop.png", NULL);
	image = gtk_image_new_from_file(filename);
	gtk_button_set_image(GTK_BUTTON(spectrum3dGui.stop),image);
	gdk_color_parse ("gold",&color);
	gtk_widget_set_name(spectrum3dGui.stop, "stop");
	gtk_widget_modify_bg(GTK_WIDGET(spectrum3dGui.stop), GTK_STATE_NORMAL, &color);
	gtk_widget_modify_bg(GTK_WIDGET(spectrum3dGui.stop), GTK_STATE_PRELIGHT, &color);
	gtk_widget_set_tooltip_text (spectrum3dGui.stop, "Stop playing everything; no source of playing");
	gtk_box_pack_start(GTK_BOX(pVBox[1]), pHBox[1], FALSE, TRUE, 2);
	gtk_box_pack_start(GTK_BOX(pHBox[1]), spectrum3dGui.stop, FALSE, TRUE, 2);
	g_signal_connect(G_OBJECT(spectrum3dGui.stop), "clicked", G_CALLBACK(change_source_button), &spectrum3dGui);

	filename = g_build_filename (G_DIR_SEPARATOR_S, DATADIR, "icons", "microphone_grey.png", NULL);
	image = gtk_image_new_from_file(filename);
	spectrum3dGui.mic = gtk_button_new();
	gtk_button_set_image (GTK_BUTTON(spectrum3dGui.mic), image);
	gtk_widget_set_name(spectrum3dGui.mic, "mic");
	gtk_widget_set_tooltip_text (spectrum3dGui.mic, "Source is microphone; select this to record something and then load it");
	gtk_box_pack_start(GTK_BOX(pHBox[1]), spectrum3dGui.mic, FALSE, TRUE, 2);
	g_signal_connect(G_OBJECT(spectrum3dGui.mic), "clicked", G_CALLBACK(change_source_button), &spectrum3dGui);

	spectrum3dGui.file = gtk_button_new();
	filename = g_build_filename (G_DIR_SEPARATOR_S, DATADIR, "icons", "file_grey.png", NULL);
	image = gtk_image_new_from_file(filename);
	gtk_button_set_image(GTK_BUTTON(spectrum3dGui.file),image);
	gtk_widget_set_name(spectrum3dGui.file, "file");
	gtk_widget_set_tooltip_text (spectrum3dGui.file, "Source is an audio file");
	gtk_box_pack_start(GTK_BOX(pHBox[1]), spectrum3dGui.file, FALSE, FALSE, 2);
	g_signal_connect(G_OBJECT(spectrum3dGui.file), "clicked", G_CALLBACK(change_source_button), &spectrum3dGui);

	spectrum3dGui.reload = gtk_button_new();
	image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_LARGE_TOOLBAR);
	gtk_button_set_image(GTK_BUTTON(spectrum3dGui.reload),image);
	gtk_widget_set_sensitive (spectrum3dGui.reload, FALSE);
	gtk_widget_set_tooltip_text (spectrum3dGui.reload, "Reload audio file (usefull if some audio parameters like equalizer or filters have been changed)");
	gtk_box_pack_start(GTK_BOX(pHBox[1]), spectrum3dGui.reload, FALSE, FALSE, 2);
	g_signal_connect(G_OBJECT(spectrum3dGui.reload), "clicked", G_CALLBACK(load_audio_file), NULL);

	widget = gtk_check_button_new_with_label("Analyse in\nrealtime");
	gtk_widget_set_tooltip_text (GTK_WIDGET(widget), "If checked, harmonics will be analysed and displayed at the same time; if unchecked, harmonics will be analysed first, then displayed for the whole audio file, then it can be played afterwards");
	gtk_box_pack_start(GTK_BOX(pHBox[1]), widget, FALSE, FALSE, 0);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), TRUE);
	g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(set_analyse_in_rt), &spectrum3dGui);

/* separator */
#ifdef GTK3
	widget = gtk_separator_new(GTK_ORIENTATION_VERTICAL);
#elif defined GTK2
	widget = gtk_vseparator_new();
#endif
	gtk_box_pack_start(GTK_BOX(pHBox[1]), widget, FALSE, FALSE, 5);
	
/* "Play/Pause" button */
	playButton = gtk_button_new();
	gtk_widget_set_tooltip_text (playButton, "Play/Pause the audio stream");
	setPlayButtonIcon();
	gtk_widget_set_size_request (playButton, 50, 20);
	gtk_box_pack_start(GTK_BOX(pHBox[1]), playButton, FALSE, FALSE, 2);
	g_signal_connect(G_OBJECT(playButton), "clicked", G_CALLBACK(playFromSource), "NO_MESSAGE");
	
/* "Stop" button */
	button = gtk_button_new();
	gtk_widget_set_tooltip_text (button, "Stop playing audio stream");
	image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_STOP, GTK_ICON_SIZE_SMALL_TOOLBAR);
	gtk_button_set_image(GTK_BUTTON(button),image);
	gtk_box_pack_start(GTK_BOX(pHBox[1]), button, FALSE, FALSE, 2);
	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_stop), NULL);

/* "Record" button */
	spectrum3dGui.record = gtk_button_new();
	gtk_widget_set_tooltip_text (spectrum3dGui.record, "Record from microphone");
	image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_RECORD, GTK_ICON_SIZE_SMALL_TOOLBAR);
	gtk_button_set_image(GTK_BUTTON(spectrum3dGui.record),image);
	gtk_widget_set_sensitive (spectrum3dGui.record, FALSE);
	gtk_box_pack_start(GTK_BOX(pHBox[1]), spectrum3dGui.record, FALSE, FALSE, 2);
	g_signal_connect(G_OBJECT(spectrum3dGui.record), "clicked", G_CALLBACK(record_window), NULL);

/* separator */
#ifdef GTK3
	widget = gtk_separator_new(GTK_ORIENTATION_VERTICAL);
#elif defined GTK2
	widget = gtk_vseparator_new();
#endif	
	gtk_box_pack_start(GTK_BOX(pHBox[1]), widget, FALSE, FALSE, 5);

/* JACK check button */
	filename = g_build_filename (G_DIR_SEPARATOR_S, DATADIR, "icons", "qjackctl.png", NULL);
	image = gtk_image_new_from_file(filename);
	widget = gtk_check_button_new ();
	gtk_button_set_image (GTK_BUTTON(widget), image);
	gtk_widget_set_tooltip_text (widget, "Use Jack-Audio-Connection-Kit (JACK)");
	gtk_box_pack_start(GTK_BOX(pHBox[1]), widget, FALSE, FALSE, 2);
	g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(use_jack), &spectrum3dGui);

/* separator */
#ifdef GTK3
	widget = gtk_separator_new(GTK_ORIENTATION_VERTICAL);
#elif defined GTK2
	widget = gtk_vseparator_new();
#endif	
	gtk_box_pack_start(GTK_BOX(pHBox[1]), widget, FALSE, FALSE, 5);

/* Button to open the Filter and Equalizer window */
	// create effectsWindow first without showing it
	effects_window(&spectrum3dGui);
	// then create a button that will call its display when clicked
	filename = g_build_filename (G_DIR_SEPARATOR_S, DATADIR, "icons", "equalizer.png", NULL);
	image = gtk_image_new_from_file(filename);
	widget = gtk_button_new();  
	gtk_button_set_image (GTK_BUTTON(widget), image);
	gtk_widget_set_tooltip_text (widget, "Show/Hide the filter and equalizer window");
	gtk_box_pack_start(GTK_BOX(pHBox[1]), widget, FALSE, FALSE, 0);
	g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(show_effects_window), &spectrum3dGui);

/* Time label */
	label=gtk_label_new("Time : ");
	gtk_box_pack_start(GTK_BOX(pHBox[5]), label, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(pVBox[1]), pHBox[5], FALSE, FALSE, 2);

/* Progress & seek scale */
#ifdef GTK3
	scaleSeek = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0.0, 100.0, 1);
#elif defined GTK2
	scaleSeek = gtk_hscale_new_with_range (0.0, 100.0, 1);
#endif
	gtk_scale_set_draw_value (GTK_SCALE (scaleSeek), FALSE);
	//gtk_scale_set_value_pos (GTK_SCALE (pScaleSeek), GTK_POS_TOP);
	gtk_range_set_value (GTK_RANGE (scaleSeek), 0);
	gtk_widget_set_size_request (scaleSeek, 500, 20);
	gtk_box_pack_start(GTK_BOX(pHBox[5]), scaleSeek, FALSE, FALSE, 0);
	g_signal_connect(G_OBJECT(scaleSeek), "value-changed", G_CALLBACK(on_seek), NULL);
	
	timeLabel=gtk_label_new("           0:00 / 0:00           ");
	gtk_box_pack_start(GTK_BOX(pHBox[5]), timeLabel, FALSE, FALSE, 0);

/* Create drawing area */
	if (externalWindow == FALSE){
		/* Resize spectrum3dGui.mainWindow to contain drawing_area; using gtk_window_set_defaut() allows to shrink the window (gtk_widget_set_size_request() does not allow to shrink the window below the requested size); */
		gtk_window_set_default_size (GTK_WINDOW(spectrum3dGui.mainWindow), (gint)spectrum3d.width, initialWindowHeight + (gint)spectrum3d.height);
		
		//gtk_widget_realize(spectrum3dGui.mainWindow);

		spectrum3dGui.drawing_area = gtk_drawing_area_new ();
		
#if defined (GTKGLEXT3) || defined (GTKGLEXT1)
		/* Set OpenGL-capability to the widget */
	  	gtk_widget_set_gl_capability (spectrum3dGui.drawing_area,
					glconfig,
					NULL,
					TRUE,
					GDK_GL_RGBA_TYPE);		
#endif	
		
		/* drawing_area has to be put in vBox AFTER the call to gtk_widget_set_gl_capability() (if GtkGlExt is used) and BEFORE the call to the sdl-gtk hack (if sdl is used)*/ 
		gtk_box_pack_start (GTK_BOX (pVBox[1]), spectrum3dGui.drawing_area, TRUE, TRUE, 0);	
		
#ifdef HAVE_LIBSDL 
		/* Hack to get SDL to use GTK window */
		{ char SDL_windowhack[32];
			sprintf(SDL_windowhack,"SDL_WINDOWID=%ld",
				GDK_WINDOW_XID(gtk_widget_get_window(spectrum3dGui.drawing_area)));
				// GDK_WINDOW_XID( spectrum3dGui.drawing_area->window))); pour GTK2??
			putenv(SDL_windowhack);
		printf("%s\n", SDL_windowhack);
		}

		if (SDL_Init(SDL_INIT_VIDEO) < 0) {
			fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
			exit(1);
			}
#endif

		g_signal_connect (spectrum3dGui.mainWindow, "key-press-event", G_CALLBACK (on_key_press), &spectrum3dGui);
		g_signal_connect (spectrum3dGui.mainWindow, "key-release-event", G_CALLBACK (on_key_release), &spectrum3dGui);
		g_signal_connect (spectrum3dGui.mainWindow, "motion-notify-event", G_CALLBACK (on_mouse_motion), NULL);
		g_signal_connect (spectrum3dGui.mainWindow, "scroll-event", G_CALLBACK (on_mouse_scroll), NULL);
		g_signal_connect (G_OBJECT (spectrum3dGui.drawing_area), "configure_event", G_CALLBACK (configure_event), NULL);
		gtk_widget_add_events (spectrum3dGui.mainWindow, gtk_widget_get_events (spectrum3dGui.mainWindow) | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK);
	}
	else {
		create_external_window_drawing_area(&spectrum3dGui);
		}	

/* Starting value of the display */
	frame = gtk_frame_new("Start value of display (in Hz)");
	gtk_widget_set_tooltip_text (frame, "The lower displayed frequency (in herz)");
	spectrum3dGui.adjustStart = gtk_adjustment_new(0, 0, 9000, ((gdouble)hzStep * (gdouble)zoomFactor), (((gdouble)hzStep * (gdouble)zoomFactor) * 10), 0);
#ifdef GTK3
	pScaleStart = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT(spectrum3dGui.adjustStart));
#elif defined GTK2
	pScaleStart = gtk_hscale_new(GTK_ADJUSTMENT(spectrum3dGui.adjustStart));
#endif
	gtk_scale_set_digits (GTK_SCALE(pScaleStart), 0);
	gtk_scale_set_value_pos(GTK_SCALE(pScaleStart), GTK_POS_RIGHT);
	gtk_box_pack_start(GTK_BOX(pVBox[1]), pHBox[11], FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(pHBox[11]), frame, FALSE, FALSE, 0);
	gtk_container_add(GTK_CONTAINER(frame), pScaleStart);
	g_signal_connect(G_OBJECT(pScaleStart), "value-changed", G_CALLBACK(change_start), &spectrum3dGui);
	g_signal_connect(G_OBJECT(pScaleStart), "format-value", G_CALLBACK(format_value_start), NULL);
	g_signal_connect(G_OBJECT(pScaleStart), "value-changed", G_CALLBACK(getTextDisplayLabel), &spectrum3dGui);

/* Range of display */
	frame = gtk_frame_new("Range of display (in Hz)");
	gtk_widget_set_tooltip_text (frame, "The range of the displayed frequency (in herz)");
	spectrum3dGui.adjustBands = gtk_adjustment_new(1000, 20, 1000, 10, 50, 0);
#ifdef GTK3
	spectrum3dGui.scaleBands = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT(spectrum3dGui.adjustBands));
#elif defined GTK2
	spectrum3dGui.scaleBands = gtk_hscale_new(GTK_ADJUSTMENT(spectrum3dGui.adjustBands));
#endif
	gtk_scale_set_digits (GTK_SCALE(spectrum3dGui.scaleBands), 0);
	gtk_scale_set_value_pos(GTK_SCALE(spectrum3dGui.scaleBands), GTK_POS_RIGHT);
	gtk_container_add(GTK_CONTAINER(frame), spectrum3dGui.scaleBands);
	gtk_box_pack_start(GTK_BOX(pHBox[11]), frame, FALSE, FALSE, 0);
	g_signal_connect(G_OBJECT(spectrum3dGui.scaleBands), "value-changed", G_CALLBACK(change_bands), &spectrum3dGui);
	g_signal_connect(G_OBJECT(spectrum3dGui.scaleBands), "format-value", G_CALLBACK(format_value_bands), NULL);
	g_signal_connect(G_OBJECT(spectrum3dGui.scaleBands), "value-changed", G_CALLBACK(getTextDisplayLabel), &spectrum3dGui);
	
/* "x" label */
	label=gtk_label_new("x");
	gtk_container_add(GTK_CONTAINER(pHBox[11]), label);

/* Factor that multiplies the range of display */
	frame = gtk_frame_new("");
	gtk_widget_set_tooltip_text (frame, "Factor that multiplies the frequency range, to make it larger");
	spectrum3dGui.cbRange = gtk_combo_box_text_new();
	gtk_container_add(GTK_CONTAINER(frame), spectrum3dGui.cbRange);
	gtk_box_pack_start(GTK_BOX(pHBox[11]), frame, FALSE, FALSE, 0);
	for (i = 1; i <= 20; i++){
		gchar text[4];
		sprintf(text, "%d", i);
		gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(spectrum3dGui.cbRange), text);
		}
	gtk_combo_box_set_active(GTK_COMBO_BOX(spectrum3dGui.cbRange), 0);
	g_signal_connect( G_OBJECT(spectrum3dGui.cbRange), "changed", G_CALLBACK( cb_range_changed ), &spectrum3dGui );
	g_signal_connect( G_OBJECT(spectrum3dGui.cbRange), "changed", G_CALLBACK(getTextDisplayLabel), &spectrum3dGui );
	
/* Label that shows starting value, ending value and range of display */
	frame = gtk_frame_new("Values displayed");
	gtk_widget_set_tooltip_text (frame, "The lower and the highest displayed value (in herz), and their range");
	displayLabel=gtk_label_new(""); 
	gtk_container_add(GTK_CONTAINER(frame), displayLabel);
	getTextDisplayLabel(NULL, &spectrum3dGui);
	gtk_box_pack_start(GTK_BOX(pHBox[11]), frame, FALSE, FALSE, 0);

/* 'Gain' Gtk Scale */
	frame = gtk_frame_new("Display Gain");
	gtk_box_pack_start(GTK_BOX(pHBox[11]), frame, FALSE, FALSE, 10);
	filename = g_build_filename (G_DIR_SEPARATOR_S, DATADIR, "icons", "gain.png", NULL);
	image = gtk_image_new_from_file(filename);

	spectrum3dGui.scaleGain = gtk_scale_button_new (GTK_ICON_SIZE_LARGE_TOOLBAR, 0, 1, 0.01, NULL);
	gtk_button_set_image(GTK_BUTTON(spectrum3dGui.scaleGain),image);
	//gtk_button_set_label (GTK_BUTTON(spectrum3dGui.scaleGain), "GAIN");
	gtk_container_add(GTK_CONTAINER(frame), spectrum3dGui.scaleGain);
	//gtk_box_pack_start(GTK_BOX(pHBox[11]), pScaleGain, FALSE, FALSE, 0);
	//gtk_widget_set_size_request (pScaleGain, 200, 20);
	//gtk_scale_set_value_pos(GTK_SCALE(pScaleGain), GTK_POS_RIGHT);
	gtk_widget_set_tooltip_text (spectrum3dGui.scaleGain, "Adjust the displayed level of the intensity of the sound");
	gtk_scale_button_set_value(GTK_SCALE_BUTTON(spectrum3dGui.scaleGain), 0.2);
	// FIXME error message here with the previous line : gtk_image_set_from_stock: assertion `GTK_IS_IMAGE (image)' failed; it could be a bug in Gtk
	//g_object_set (pScaleGain, "update-policy", GTK_UPDATE_DISCONTINUOUS, NULL);
	g_signal_connect(G_OBJECT(spectrum3dGui.scaleGain), "value-changed", G_CALLBACK(change_gain), NULL);

#ifdef HAVE_LIBGEIS
	setupGeis();
#endif

	gtk_widget_show_all (spectrum3dGui.mainWindow);

	//timeoutEvent = g_timeout_add (100, (GSourceFunc)sdl_event, &spectrum3dGui);
	spectrum3d.timeoutExpose = g_timeout_add (intervalDisplaySpectro, (GSourceFunc)display_spectro, &spectrum3dGui);

	printf("Showing Gtk GUI\n");
	gtk_main ();

/* Quit everything */

#ifdef HAVE_LIBGEIS
	geisQuit();
#endif
	on_stop();
	g_source_remove(spectrum3d.timeoutExpose);
#ifdef HAVE_LIBSDL
	//g_source_remove(timeoutEvent);
	SDL_Quit();
#endif

	print_rc_file();

	printf("Quit everything\nGood Bye!\n");
	
	return 0;
}
コード例 #5
0
/**
 * @fn int main (int argc, char **argv)
 * @brief Main program & Gtk thread.
 *
 * Create window and all widgets, then set there parameters to be the <br>
 * ROS params.
 */
int main (int argc, char **argv)
{
    GtkBuilder *builder;
    GdkColor black = { 0, 0, 0, 0 };
    GError *error = NULL;
    char glade_gui_file[FILENAME_MAX];
    int start_zoom = 15;
    char *mapcachedir;
    OsmGpsMapPoint ccny_coord = { 40.818551, -73.948674 };

    struct arg param;
    param.argc = argc;
    param.argv = argv;

    pthread_t rosThread;

    // **** init threads
    g_thread_init (NULL);
    gdk_threads_init ();
    gdk_threads_enter ();

    // **** init gtk
    gtk_init (&argc, &argv);

    // **** allocate data structure
    data = g_slice_new (AppData);

    // **** set the glade gui file & set icon directory
    std::string package_path = ros::package::getPath (ROS_PACKAGE_NAME);
    sprintf (glade_gui_file, "%s/gui/%s", package_path.c_str (), "gui.glade");
    sprintf (data->icon_directory, "%s/gui/icon", package_path.c_str ());

    std::string rosbag_path = ros::package::getPath("rosbag");
    sprintf (data->rosbag_rec_path, "%s/bin/record", rosbag_path.c_str ());

    data->current_page = 0;
    data->telemetry_opt_popup_state = false;
    data->gps_opt_popup_state = false;
    data->fullscreen = false;
    load_icon ();

    // **** Create new GtkBuilder object
    builder = gtk_builder_new ();
    // **** Load UI from file
    if (!gtk_builder_add_from_file (builder, glade_gui_file, &error))
    {
        g_warning ("%s", error->message);
        g_free (error);
        exit (-1);
    }

    // **** Get main window pointer from UI
    data->window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
    gtk_window_set_title (GTK_WINDOW (data->window), "CityFlyer Ground Station");
    gtk_window_set_position (GTK_WINDOW (data->window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size (GTK_WINDOW (data->window), 1024, 576);

    // **** create ROS thread
    pthread_create (&rosThread, NULL, startROS, &param);

    // **** wait ros finish read params
    while (!data->ros_param_read)
    {
        ROS_DEBUG ("Waiting ROS params");
    }

    // **** Get GtkNotebook objsect
    data->notebook = GTK_WIDGET (gtk_builder_get_object (builder, "notebook1"));

    // #####################################################################
    // #####################################################################
    // **** Tab 1: Telemetry

    // **** create altimeter widgets
    data->alt = gtk_altimeter_new ();
    g_object_set (GTK_ALTIMETER (data->alt),
                  "grayscale-color", data->grayscale_color,
                  "unit-is-feet", data->altimeter_unit_is_feet,
                  "unit-step-value", data->altimeter_step_value, "radial-color", data->radial_color, NULL);

    // **** create compass widgets
    data->comp = gtk_compass_new ();
    g_object_set (GTK_COMPASS (data->comp),
                  "grayscale-color", data->grayscale_color, "radial-color", data->radial_color, NULL);

    data->comp2 = gtk_compass_new ();
    g_object_set (GTK_COMPASS (data->comp2),
                  "grayscale-color", data->grayscale_color, "radial-color", data->radial_color, NULL);

    data->gauge1 = gtk_gauge_new ();
    g_object_set (GTK_GAUGE (data->gauge1), "name", data->gauge1_name_f, NULL);
    g_object_set (GTK_GAUGE (data->gauge1),
                  "grayscale-color", data->grayscale_color,
                  "radial-color", data->radial_color,
                  "start-value", data->gauge1_start_value,
                  "end-value", data->gauge1_end_value,
                  "initial-step", data->gauge1_initial_step,
                  "sub-step", (gdouble) data->gauge1_sub_step,
                  "drawing-step", data->gauge1_drawing_step,
                  "color-strip-order", data->gauge1_color_strip_order,
                  "green-strip-start", data->gauge1_green_strip_start,
                  "yellow-strip-start", data->gauge1_yellow_strip_start,
                  "red-strip-start", data->gauge1_red_strip_start, NULL);

    // **** create artificial horizon widgets
    data->arh = gtk_artificial_horizon_new ();
    g_object_set (GTK_ARTIFICIAL_HORIZON (data->arh),
                  "grayscale-color", data->grayscale_color, "radial-color", data->radial_color, NULL);

    // **** create variometer widgets
    data->vario = gtk_variometer_new ();
    g_object_set (GTK_VARIOMETER (data->vario),
                  "grayscale-color", data->grayscale_color,
                  "unit-is-feet", data->variometer_unit_is_feet,
                  "unit-step-value", data->variometer_step_value, "radial-color", data->radial_color, NULL);

    data->widget_table = GTK_WIDGET (gtk_builder_get_object (builder, "table_Widgets"));
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->alt, 0, 1, 0, 1);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->arh, 1, 2, 0, 1);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->comp, 2, 3, 0, 1);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->vario, 0, 1, 1, 2);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->comp2, 1, 2, 1, 2);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->gauge1, 2, 3, 1, 2);

    gtk_widget_modify_bg (data->alt, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->comp, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->comp2, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->arh, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->gauge1, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->vario, GTK_STATE_NORMAL, &black);

    data->telemetry_option_popup = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_TelemetryOption"));
    data->btn_open_telemetry_option_popup =
        GTK_WIDGET (gtk_builder_get_object (builder, "button_OpenTelemetryOptionPopup"));
    data->btn_close_telemetry_option_popup =
        GTK_WIDGET (gtk_builder_get_object (builder, "button_CloseTelemetryOptionPopup"));
    gtk_button_set_image (GTK_BUTTON (data->btn_open_telemetry_option_popup),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->leftarrow_icon_64, 24, 50, GDK_INTERP_HYPER)));
    gtk_button_set_image (GTK_BUTTON (data->btn_close_telemetry_option_popup),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->rightarrow_icon_64, 24, 50, GDK_INTERP_HYPER)));

    // #####################################################################
    // #####################################################################
    // **** Tab 2: Gps

    // Some GpsdViewer initialisation
    data->draw_path = false;
    data->map_provider = OSM_GPS_MAP_SOURCE_OPENSTREETMAP;
    data->map_zoom_max = 18;
    data->map_current_zoom = start_zoom;
    data->repo_uri = osm_gps_map_source_get_repo_uri (data->map_provider);
    data->friendly_name = osm_gps_map_source_get_friendly_name (data->map_provider);
    data->uav_track = osm_gps_map_track_new ();
    mapcachedir = osm_gps_map_get_default_cache_directory ();
    data->cachedir = g_build_filename (mapcachedir, data->friendly_name, NULL);
    g_free (mapcachedir);

    // Create the OsmGpsMap object
    data->map = (OsmGpsMap *) g_object_new (OSM_TYPE_GPS_MAP,
                                            "map-source", data->map_provider,
                                            "tile-cache", data->cachedir, "proxy-uri", g_getenv ("http_proxy"), NULL);

    //Set the starting coordinates and zoom level for the map
    osm_gps_map_set_zoom (data->map, start_zoom);
    osm_gps_map_set_center (data->map, ccny_coord.rlat, ccny_coord.rlon);

    data->osd = gpsd_viewer_osd_new ();
    g_object_set (GPSD_VIEWER_OSD (data->osd),
                  "show-scale", true,
                  "show-coordinates", true,
                  "show-dpad", true,
                  "show-zoom", true, "show-gps-in-dpad", true, "show-gps-in-zoom", false, "dpad-radius", 30, NULL);
    osm_gps_map_layer_add (OSM_GPS_MAP (data->map), OSM_GPS_MAP_LAYER (data->osd));

    data->map_box = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_map_box"));
    data->map_container = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_map_container"));
    gtk_box_pack_start (GTK_BOX (data->map_box), GTK_WIDGET (data->map), TRUE, TRUE, 0);

    data->gpsd_option_popup = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_GpsdOptionPopup"));
    data->btn_open_gpsd_option_popup = GTK_WIDGET (gtk_builder_get_object (builder, "button_OpenGpsdOptionPopup"));
    data->btn_close_gpsd_option_popup = GTK_WIDGET (gtk_builder_get_object (builder, "button_CloseGpsdOptionPopup"));
    gtk_button_set_image (GTK_BUTTON (data->btn_open_gpsd_option_popup),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->leftarrow_icon_64, 24, 50, GDK_INTERP_HYPER)));
    gtk_button_set_image (GTK_BUTTON (data->btn_close_gpsd_option_popup),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->rightarrow_icon_64, 24, 50, GDK_INTERP_HYPER)));

    // #####################################################################
    // #####################################################################
    // **** Tab 3: Rec

    data->recording = 0;
    data->rosbag_record_cmd = "rosbag record";
    data->topicsList = GTK_LIST_STORE (gtk_builder_get_object (builder, "liststore_TopicList"));
    data->cmd_line_entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry_CommandLine"));
    data->prefix_entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry_Prefix"));
    data->info_textview = GTK_WIDGET (gtk_builder_get_object (builder, "textview_BagInfo"));
    data->update_btn = GTK_WIDGET (gtk_builder_get_object (builder, "button_UpdateTopicList"));
    data->box_MotorStatus = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_MotorStatus"));
    data->box_Flying = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_Flying"));
    data->box_Gps = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_Gps"));
    data->flightMode_label = GTK_WIDGET (gtk_builder_get_object (builder, "label_FlightModeValue"));
    data->upTime_label = GTK_WIDGET (gtk_builder_get_object (builder, "label_UpTimeValue"));
    data->cpuLoad_label = GTK_WIDGET (gtk_builder_get_object (builder, "label_CpuLoadValue"));
    data->box_RecordStatus = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_RecordStatus"));
    data->record_stop_btn = GTK_WIDGET (gtk_builder_get_object (builder, "button_RecordStop"));

    gtk_box_pack_end (GTK_BOX (data->box_MotorStatus), data->status_ok_icon_motor, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_MotorStatus), data->status_fail_icon_motor, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_Flying), data->status_ok_icon_flying, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_Flying), data->status_fail_icon_flying, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_Gps), data->status_ok_icon_gps, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_Gps), data->status_fail_icon_gps, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_RecordStatus), data->record_icon, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_RecordStatus), data->record_g_icon, TRUE, TRUE, 0);

    gtk_button_set_image (GTK_BUTTON (data->update_btn),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->refresh_icon_64, 24, 24, GDK_INTERP_HYPER)));
    gtk_button_set_image (GTK_BUTTON (data->record_stop_btn),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->record_icon_64, 40, 40, GDK_INTERP_HYPER)));

    // Connect signals
    gtk_builder_connect_signals (builder, data);

    // Destroy builder, since we don't need it anymore
    g_object_unref (G_OBJECT (builder));

    // Show window. All other widgets are automatically shown by GtkBuilder
    gtk_widget_show_all (data->window);
    gtk_widget_hide(data->record_icon);
    gtk_widget_hide(data->status_ok_icon_motor);
    gtk_widget_hide(data->status_ok_icon_flying);
    gtk_widget_hide(data->status_ok_icon_gps);
    gtk_widget_hide_all(data->telemetry_option_popup);
    gtk_widget_hide_all(data->gpsd_option_popup);

    // **** allow ROS spinning
    data->widget_created = true;

    // **** udpate all widgets
    g_timeout_add (data->telemetry_refresh_rate, widgets_update, NULL);

    gtk_main ();
    gdk_threads_leave ();
    return 0;
}
コード例 #6
0
static void atlas_template_dialog_init(AtlasTemplateDialog *atlas_template_dialog)
{
	AtlasTemplateDialog * atd = atlas_template_dialog;
	gtk_dialog_set_has_separator(GTK_DIALOG(atd), FALSE);

	gtk_dialog_add_button(GTK_DIALOG(atd), "Apply", 0);
	gtk_dialog_add_button(GTK_DIALOG(atd), "Cancel", -1);

	atd -> combo_pagesize = gtk_combo_box_new_text();
	int i; char text[8];
	for (i = 0; i < PAPERSIZE_LAST; i++){
		gtk_combo_box_append_text(GTK_COMBO_BOX(atd -> combo_pagesize), page_format_names[i]);
	}

	atd -> entry_width = gtk_entry_new();
	atd -> entry_height = gtk_entry_new();

	atd -> radio_orientation_landscape	= gtk_radio_button_new(NULL);
	atd -> radio_orientation_portrait	= gtk_radio_button_new(gtk_radio_button_get_group(GTK_RADIO_BUTTON(atd -> radio_orientation_landscape)));
	GtkWidget * image_landscape 	= gtk_image_new_from_stock("gtk-orientation-landscape", GTK_ICON_SIZE_BUTTON);
	GtkWidget * image_portrait	= gtk_image_new_from_stock("gtk-orientation-portrait", GTK_ICON_SIZE_BUTTON);
	gtk_button_set_image(GTK_BUTTON(atd -> radio_orientation_landscape), image_landscape);
	gtk_button_set_image(GTK_BUTTON(atd -> radio_orientation_portrait), image_portrait);
	GtkWidget * box_orientation = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(box_orientation), atd -> radio_orientation_portrait, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(box_orientation), atd -> radio_orientation_landscape, FALSE, FALSE, 0);

        atd -> entry_border_top    = gtk_entry_new();
        atd -> entry_border_left   = gtk_entry_new();
        atd -> entry_border_right  = gtk_entry_new();
        atd -> entry_border_bottom = gtk_entry_new();

        atd -> entry_resolution = gtk_entry_new();

	GtkWidget * label_paper_format	= gtk_label_new("Paper format");
	GtkWidget * label_format	= gtk_label_new("Format");
	GtkWidget * label_width		= gtk_label_new("Width");
	GtkWidget * label_height	= gtk_label_new("Height");
	GtkWidget * label_orientation	= gtk_label_new("Orientation");
	GtkWidget * label_margins	= gtk_label_new("Margins");
	GtkWidget * label_left		= gtk_label_new("Left");
	GtkWidget * label_right		= gtk_label_new("Right");
	GtkWidget * label_top		= gtk_label_new("Top");
	GtkWidget * label_bottom	= gtk_label_new("Bottom");
	GtkWidget * label_quality	= gtk_label_new("Quality");
	GtkWidget * label_resolution	= gtk_label_new("Resolution");

	GtkWidget * table = gtk_table_new(10, 2, FALSE);
        gtk_table_attach(GTK_TABLE(table), label_paper_format,		0, 1, 0,  1,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_format,		0, 1, 1,  2,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), atd -> combo_pagesize,	1, 2, 1,  2,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_width,			0, 1, 2,  3,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), atd -> entry_width,		1, 2, 2,  3,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_height,		0, 1, 3,  4,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), atd -> entry_height,		1, 2, 3,  4,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_orientation,		0, 1, 4,  5,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), box_orientation,		1, 2, 4,  5,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_margins,		0, 1, 5,  6,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_left,			0, 1, 6,  7,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), atd -> entry_border_left,	1, 2, 6,  7,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_right,			0, 1, 7,  8,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), atd -> entry_border_right,	1, 2, 7,  8,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_top,			0, 1, 8,  9,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), atd -> entry_border_top,	1, 2, 8,  9,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_bottom,		0, 1, 9,  10, GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), atd -> entry_border_bottom,	1, 2, 9,  10, GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_quality,		0, 1, 10, 11,  GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), label_resolution,		0, 1, 11, 12, GTK_EXPAND | GTK_FILL, 0, 0, 0);
        gtk_table_attach(GTK_TABLE(table), atd -> entry_resolution,	1, 2, 11, 12, GTK_EXPAND | GTK_FILL, 0, 0, 0);

	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(atd) -> vbox), table, FALSE, FALSE, 0);

	//gtk_widget_set_size_request(GTK_WIDGET(atd -> entry_height), 40, -1);
	gtk_widget_show_all(GTK_WIDGET(atd));

        g_signal_connect(G_OBJECT(atd -> combo_pagesize), "changed", G_CALLBACK(papertype_changed_cb), (gpointer)atd);
        g_signal_connect(G_OBJECT(atd -> radio_orientation_portrait), "toggled", G_CALLBACK(orientation_changed_cb), (gpointer)atd);
	g_signal_connect(G_OBJECT(atd -> entry_width), "changed", G_CALLBACK(size_changed_cb), (gpointer)atd);
	g_signal_connect(G_OBJECT(atd -> entry_height), "changed", G_CALLBACK(size_changed_cb), (gpointer)atd);
	g_signal_connect(G_OBJECT(atd -> entry_border_top), "changed", G_CALLBACK(border_changed_cb), (gpointer)atd);
	g_signal_connect(G_OBJECT(atd -> entry_border_bottom), "changed", G_CALLBACK(border_changed_cb), (gpointer)atd);
	g_signal_connect(G_OBJECT(atd -> entry_border_left), "changed", G_CALLBACK(border_changed_cb), (gpointer)atd);
	g_signal_connect(G_OBJECT(atd -> entry_border_right), "changed", G_CALLBACK(border_changed_cb), (gpointer)atd);
	//g_signal_connect(G_OBJECT(atd -> entry_resolution), "changed", G_CALLBACK(resolution_changed_cb), (gpointer)atd);
}
コード例 #7
0
void _fcitx_main_window_add_addon_page(FcitxMainWindow* self)
{
    FcitxAddon* addon;
    utarray_new(self->addons, &addonicd);
    FcitxAddonsLoad(self->addons);

    GtkWidget* vbox = gtk_vbox_new(FALSE, 0);

    GtkListStore *store;
    store = gtk_list_store_new(N_COLUMNS, G_TYPE_POINTER);

    GtkWidget* swin = gtk_scrolled_window_new(NULL, NULL);
    gtk_box_pack_start(GTK_BOX(vbox), swin, TRUE, TRUE, 0);
    g_object_set(swin, "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
    self->addonview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
    g_object_set(self->addonview, "headers-visible", FALSE, NULL);
    gtk_container_add(GTK_CONTAINER(swin), self->addonview);
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;

    renderer = gtk_cell_renderer_toggle_new();
    column = gtk_tree_view_column_new_with_attributes("Enable", renderer, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(self->addonview), column);
    gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(column),
                                       renderer,
                                       _fcitx_main_window_enabled_data_func,
                                       self->addonview,
                                       NULL);
    g_signal_connect(G_OBJECT(renderer), "toggled",
                     G_CALLBACK(_fcitx_main_window_toggled_cb), GTK_TREE_MODEL(store));

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Name", renderer, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(self->addonview), column);
    gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(column),
                                       renderer,
                                       _fcitx_main_window_name_data_func,
                                       self->addonview,
                                       NULL);

    gtk_tree_view_set_model(GTK_TREE_VIEW(self->addonview),
                            GTK_TREE_MODEL(store));

    g_object_unref(store);

    for (addon = (FcitxAddon *) utarray_front(self->addons);
            addon != NULL;
            addon = (FcitxAddon *) utarray_next(self->addons, addon)) {
        GtkTreeIter iter;
        store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(self->addonview)));
        gtk_list_store_append(store, &iter);
        gtk_list_store_set(store, &iter, LIST_ADDON, addon, -1);
    }

    GtkWidget* hbuttonbox = gtk_hbutton_box_new();
    gtk_box_pack_start(GTK_BOX(vbox), hbuttonbox, FALSE, TRUE, 0);

    self->button = gtk_button_new_with_label(_("Configure"));
    gtk_widget_set_sensitive(self->button, FALSE);
    gtk_button_set_image(GTK_BUTTON(self->button), gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_BUTTON));
    gtk_box_pack_start(GTK_BOX(hbuttonbox), self->button, TRUE, TRUE, 0);
    g_signal_connect(G_OBJECT(self->button), "clicked", G_CALLBACK(_fcitx_main_window_configure_button_clicked), self);

    GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self->addonview));
    gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
    g_signal_connect(G_OBJECT(selection), "changed",
                     G_CALLBACK(_fcitx_main_window_addon_selection_changed), self);

    self->addonpage = _fcitx_main_window_add_page(self, _("Addon"), vbox, GTK_STOCK_ADD);
}
コード例 #8
0
static GObject *
gdict_source_chooser_constructor (GType                  gtype,
                                  guint                  n_params,
                                  GObjectConstructParam *params)
{
  GdictSourceChooser *chooser;
  GdictSourceChooserPrivate *priv;
  GObjectClass *parent_class;
  GObject *retval;
  GtkWidget *sw;
  GtkCellRenderer *renderer;
  GtkTreeViewColumn *column;
  GtkWidget *hbox;

  parent_class = G_OBJECT_CLASS (gdict_source_chooser_parent_class);
  retval = parent_class->constructor (gtype, n_params, params);

  chooser = GDICT_SOURCE_CHOOSER (retval);
  priv = chooser->priv;

  gtk_widget_push_composite_child ();

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_set_composite_name (sw, "gdict-source-chooser-scrolled-window");
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
                                       GTK_SHADOW_IN);
  gtk_box_pack_start (GTK_BOX (chooser), sw, TRUE, TRUE, 0);
  gtk_widget_show (sw);

  renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes ("sources",
                                                     renderer,
                                                     "text", SOURCE_DESCRIPTION,
                                                     "weight", SOURCE_CURRENT,
                                                     NULL);
  priv->treeview = gtk_tree_view_new ();
  gtk_widget_set_composite_name (priv->treeview, "gdict-source-chooser-treeview");
  gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
                           GTK_TREE_MODEL (priv->store));
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->treeview), FALSE);
  gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview), column);
  g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)),
                    "changed", G_CALLBACK (selection_changed_cb),
                    chooser);
  g_signal_connect (priv->treeview,
                    "row-activated", G_CALLBACK (row_activated_cb),
                    chooser);
  gtk_container_add (GTK_CONTAINER (sw), priv->treeview);
  gtk_widget_show (priv->treeview);

  hbox = gtk_hbox_new (FALSE, 6);
  priv->buttons_box = hbox;

  priv->refresh_button = gtk_button_new ();
  gtk_button_set_image (GTK_BUTTON (priv->refresh_button),
                        gtk_image_new_from_stock (GTK_STOCK_REFRESH,
                                                  GTK_ICON_SIZE_BUTTON));
  g_signal_connect (priv->refresh_button,
                    "clicked", G_CALLBACK (refresh_button_clicked_cb),
                    chooser);
  gtk_box_pack_start (GTK_BOX (hbox), priv->refresh_button, FALSE, FALSE, 0);
  gtk_widget_show (priv->refresh_button);
  gtk_widget_set_tooltip_text (priv->refresh_button,
                               _("Reload the list of available sources"));

  gtk_box_pack_end (GTK_BOX (chooser), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  gtk_widget_pop_composite_child ();

  return retval;
}
コード例 #9
0
void
nautilus_x_content_bar_set_x_content_type (NautilusXContentBar *bar, const char *x_content_type)
{					  
	char *message;
	char *description;
	GAppInfo *default_app;

	g_free (bar->priv->x_content_type);
	bar->priv->x_content_type = g_strdup (x_content_type);

	description = g_content_type_get_description (x_content_type);

	/* Customize greeting for well-known x-content types */
	if (strcmp (x_content_type, "x-content/audio-cdda") == 0) {
		message = g_strdup (_("These files are on an Audio CD."));
	} else if (strcmp (x_content_type, "x-content/audio-dvd") == 0) {
		message = g_strdup (_("These files are on an Audio DVD."));
	} else if (strcmp (x_content_type, "x-content/video-dvd") == 0) {
		message = g_strdup (_("These files are on a Video DVD."));
	} else if (strcmp (x_content_type, "x-content/video-vcd") == 0) {
		message = g_strdup (_("These files are on a Video CD."));
	} else if (strcmp (x_content_type, "x-content/video-svcd") == 0) {
		message = g_strdup (_("These files are on a Super Video CD."));
	} else if (strcmp (x_content_type, "x-content/image-photocd") == 0) {
		message = g_strdup (_("These files are on a Photo CD."));
	} else if (strcmp (x_content_type, "x-content/image-picturecd") == 0) {
		message = g_strdup (_("These files are on a Picture CD."));
	} else if (strcmp (x_content_type, "x-content/image-dcf") == 0) {
		message = g_strdup (_("The media contains digital photos."));
	} else if (strcmp (x_content_type, "x-content/audio-player") == 0) {
		message = g_strdup (_("These files are on a digital audio player."));
	} else if (strcmp (x_content_type, "x-content/software") == 0) {
		message = g_strdup (_("The media contains software."));
	} else {
		/* fallback to generic greeting */
		message = g_strdup_printf (_("The media has been detected as \"%s\"."), description);
	}


	gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
	gtk_widget_show (bar->priv->label);

	/* TODO: We really need a GtkBrowserBackButton-ish widget here.. until then, we only
	 *       show the default application. */

 	default_app = g_app_info_get_default_for_type (x_content_type, FALSE);
	if (default_app != NULL) {
		char *button_text;
		const char *name;
		GIcon *icon;
		GtkWidget *image;

		icon = g_app_info_get_icon (default_app);
		if (icon != NULL) {
			GdkPixbuf *pixbuf;
			int icon_size;
			NautilusIconInfo *icon_info;
			icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON);
			icon_info = nautilus_icon_info_lookup (icon, icon_size);
			pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);
			image = gtk_image_new_from_pixbuf (pixbuf);
			g_object_unref (pixbuf);
			g_object_unref (icon_info);
		} else {
			image = NULL;
		}

		name = g_app_info_get_name (default_app);
		button_text = g_strdup_printf (_("Open %s"), name);

		gtk_button_set_image (GTK_BUTTON (bar->priv->button), image);
		gtk_button_set_label (GTK_BUTTON (bar->priv->button), button_text);
		gtk_widget_show (bar->priv->button);
		g_free (button_text);
		g_object_unref (default_app);
	} else {
		gtk_widget_hide (bar->priv->button);
	}

	g_free (message);
	g_free (description);
}
コード例 #10
0
GtkWidget *
reader_window_new(GtkApplication *application,
                  CainteoirSettings *settings,
                  CainteoirSpeechSynthesizers *synthesizers,
                  const gchar *filename)
{
	ReaderWindow *reader = READER_WINDOW(g_object_new(READER_TYPE_WINDOW,
		"application", application,
		nullptr));
	ReaderWindowPrivate *priv = READER_WINDOW_PRIVATE(reader);
	priv->self = GTK_WIDGET(reader);
	priv->settings = CAINTEOIR_SETTINGS(g_object_ref(G_OBJECT(settings)));
	priv->tts = CAINTEOIR_SPEECH_SYNTHESIZERS(g_object_ref(G_OBJECT(synthesizers)));
	priv->application = READER_APPLICATION(application);

	gtk_window_set_default_size(GTK_WINDOW(reader), INDEX_PANE_WIDTH + DOCUMENT_PANE_WIDTH + 5, 300);
	gtk_window_set_title(GTK_WINDOW(reader), i18n("Cainteoir Text-to-Speech"));

	GtkWidget *layout = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
	gtk_container_add(GTK_CONTAINER(reader), layout);

	priv->header = gtk_header_bar_new();
	gtk_header_bar_set_title(GTK_HEADER_BAR(priv->header), i18n("Cainteoir Text-to-Speech"));
	if (cainteoir_settings_get_boolean(priv->settings, "window", "have-csd", TRUE))
	{
		// Use client-side decorations (e.g. on Gnome Shell and Unity) ...
		gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(priv->header), TRUE);
		gtk_window_set_titlebar(GTK_WINDOW(reader), priv->header);
	}
	else
	{
		// Don't use client-side decorations (e.g. on KDE) ...
		gtk_box_pack_start(GTK_BOX(layout), priv->header, FALSE, FALSE, 0);
	}

	priv->actions = create_action_group(priv);
	gtk_widget_insert_action_group(GTK_WIDGET(reader), "cainteoir", G_ACTION_GROUP(priv->actions));

	priv->view = reader_document_view_new(priv->settings);
	gtk_box_pack_start(GTK_BOX(layout), priv->view, TRUE, TRUE, 0);
	reader_document_view_set_index_pane_close_action_name(READER_DOCUMENT_VIEW(priv->view), "cainteoir.side-pane");

	GtkWidget *bottombar = gtk_toolbar_new();
	gtk_widget_set_size_request(bottombar, -1, 45);
	gtk_style_context_add_class(gtk_widget_get_style_context(bottombar), "bottombar");
	gtk_box_pack_start(GTK_BOX(layout), bottombar, FALSE, FALSE, 0);

	GtkToolItem *record = gtk_tool_button_new(gtk_image_new_from_icon_name("media-record-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR), nullptr);
	gtk_toolbar_insert(GTK_TOOLBAR(bottombar), record, -1);
	gtk_actionable_set_action_name(GTK_ACTIONABLE(record), "cainteoir.record");

	priv->play_stop = gtk_tool_button_new(nullptr, nullptr);
	gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(priv->play_stop), "media-playback-start-symbolic");
	gtk_toolbar_insert(GTK_TOOLBAR(bottombar), priv->play_stop, -1);
	gtk_actionable_set_action_name(GTK_ACTIONABLE(priv->play_stop), "cainteoir.play-stop");

	GtkToolItem *open = gtk_tool_button_new(gtk_image_new_from_icon_name("document-open-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR), nullptr);
	gtk_toolbar_insert(GTK_TOOLBAR(bottombar), open, -1);
	gtk_actionable_set_action_name(GTK_ACTIONABLE(open), "cainteoir.open");

	GtkToolItem *timebar = gtk_tool_item_new();
	gtk_tool_item_set_expand(GTK_TOOL_ITEM(timebar), TRUE);
	gtk_toolbar_insert(GTK_TOOLBAR(bottombar), timebar, -1);

	priv->timebar = cainteoir_timebar_new();
	gtk_style_context_add_class(gtk_widget_get_style_context(priv->timebar), "timebar");
	gtk_container_add(GTK_CONTAINER(timebar), priv->timebar);

	priv->previous = gtk_button_new();
	gtk_button_set_image(GTK_BUTTON(priv->previous), gtk_image_new_from_icon_name("go-previous-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR));
	gtk_header_bar_pack_start(GTK_HEADER_BAR(priv->header), priv->previous);
	gtk_actionable_set_action_name(GTK_ACTIONABLE(priv->previous), "cainteoir.view-previous");

	GtkWidget *menu_button = gtk_menu_button_new();
	gtk_button_set_image(GTK_BUTTON(menu_button), gtk_image_new_from_icon_name(HAMBURGER_MENU_ICON, GTK_ICON_SIZE_SMALL_TOOLBAR));
	gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(menu_button), create_main_menu());
	gtk_header_bar_pack_end(GTK_HEADER_BAR(priv->header), menu_button);

	g_signal_connect(reader, "window-state-event", G_CALLBACK(on_window_state_changed), priv->settings);
	g_signal_connect(reader, "delete_event", G_CALLBACK(on_window_delete), priv);
	g_signal_connect(reader, "show", G_CALLBACK(on_window_show), priv);
	g_signal_connect(priv->tts, "speaking", G_CALLBACK(on_speaking), priv);
	g_signal_connect(priv->tts, "text-range-changed", G_CALLBACK(on_text_range_changed), priv);

	gtk_window_resize(GTK_WINDOW(reader),
	                  cainteoir_settings_get_integer(priv->settings, "window", "width",  700),
	                  cainteoir_settings_get_integer(priv->settings, "window", "height", 445));
	gtk_window_move(GTK_WINDOW(reader),
	                cainteoir_settings_get_integer(priv->settings, "window", "left", 0),
	                cainteoir_settings_get_integer(priv->settings, "window", "top",  0));
	if (cainteoir_settings_get_boolean(priv->settings, "window", "maximized", FALSE))
		gtk_window_maximize(GTK_WINDOW(reader));

	if (filename)
		reader_window_load_document(reader, filename);
	else
	{
		gchar *prev_filename = cainteoir_settings_get_string(priv->settings, "document", "filename", nullptr);
		if (prev_filename)
		{
			reader_window_load_document(reader, prev_filename);
			g_free(prev_filename);
		}
	}

	gchar *anchor = cainteoir_settings_get_string(priv->settings, "highlight", "anchor", "none");
	if (anchor)
	{
		if (!strcmp(anchor, "top"))
			reader_window_set_highlight_anchor(reader, GTK_ALIGN_START);
		else if (!strcmp(anchor, "middle"))
			reader_window_set_highlight_anchor(reader, GTK_ALIGN_CENTER);
		else if (!strcmp(anchor, "bottom"))
			reader_window_set_highlight_anchor(reader, GTK_ALIGN_END);
		g_free(anchor);
	}

	return GTK_WIDGET(reader);
}
コード例 #11
0
static PropertyPage *
create_property_page (NemoFileInfo *fileinfo)
{
  PropertyPage *page;
  GError *error;
  ShareInfo *share_info;
  char *share_name;
  gboolean free_share_name;
  const char *comment;
  char *apply_button_label;

  page = g_new0 (PropertyPage, 1);

  page->path = get_fullpath_from_fileinfo(fileinfo);
  page->fileinfo = g_object_ref (fileinfo);

  error = NULL;
  if (!shares_get_share_info_for_path (page->path, &share_info, &error))
    {
      /* We'll assume that there is no share for that path, but we'll still
       * bring up an error dialog.
       */
      GtkWidget *message;

      message = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
					_("There was an error while getting the sharing information"));
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s", error->message);
      gtk_widget_show (message);

      share_info = NULL;
      g_error_free (error);
      error = NULL;
    }


  page->xml = gtk_builder_new ();
  gtk_builder_set_translation_domain (page->xml, "nemo-share");
  g_assert (gtk_builder_add_from_file (page->xml,
              INTERFACES_DIR"/share-dialog.ui", &error));

  page->main = GTK_WIDGET (gtk_builder_get_object (page->xml, "vbox1"));
  g_assert (page->main != NULL);

  g_object_set_data_full (G_OBJECT (page->main),
			  "PropertyPage",
			  page,
			  free_property_page_cb);

  page->checkbutton_share_folder = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_folder"));
  page->hbox_share_comment = GTK_WIDGET (gtk_builder_get_object (page->xml,"hbox_share_comment"));
  page->hbox_share_name = GTK_WIDGET (gtk_builder_get_object (page->xml,"hbox_share_name"));
  page->checkbutton_share_rw_ro = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_rw_ro"));
  page->checkbutton_share_guest_ok = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_guest_ok"));
  page->entry_share_name = GTK_WIDGET (gtk_builder_get_object (page->xml,"entry_share_name"));
  page->entry_share_comment = GTK_WIDGET (gtk_builder_get_object (page->xml,"entry_share_comment"));
  page->label_status = GTK_WIDGET (gtk_builder_get_object (page->xml,"label_status"));
  page->button_cancel = GTK_WIDGET (gtk_builder_get_object (page->xml,"button_cancel"));
  page->button_apply = GTK_WIDGET (gtk_builder_get_object (page->xml,"button_apply"));

  /* Sanity check so that we don't screw up the Glade file */
  g_assert (page->checkbutton_share_folder != NULL
	    && page->hbox_share_comment != NULL
	    && page->hbox_share_name != NULL
	    && page->checkbutton_share_rw_ro != NULL
	    && page->checkbutton_share_guest_ok != NULL
	    && page->entry_share_name != NULL
	    && page->entry_share_comment != NULL
	    && page->label_status != NULL
	    && page->button_cancel != NULL
	    && page->button_apply != NULL);

  if (share_info)
    {
      page->was_initially_shared = TRUE;
      page->was_writable = share_info->is_writable;
    }

  /* Share name */

  if (share_info)
    {
      share_name = share_info->share_name;
      free_share_name = FALSE;
    }
  else
    {
      share_name = g_filename_display_basename (page->path);
      free_share_name = TRUE;
    }

  gtk_entry_set_text (GTK_ENTRY (page->entry_share_name), share_name);

  if (free_share_name)
    g_free (share_name);

  /* Comment */

  if (share_info == NULL || share_info->comment == NULL)
    comment = "";
  else
    comment = share_info->comment;

  gtk_entry_set_text (GTK_ENTRY (page->entry_share_comment), comment);

  /* Share toggle */

  if (share_info)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_folder), TRUE);
  else
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_folder), FALSE);
    }

  /* Share name */

  if (g_utf8_strlen(gtk_entry_get_text (GTK_ENTRY (page->entry_share_name)), -1) > 12)
    property_page_set_warning (page);

  /* Permissions */
  if (share_info != NULL && share_info->is_writable)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_rw_ro), TRUE);
  else
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_rw_ro), FALSE);

  /* Guest access */
  if (share_info != NULL && share_info->guest_ok)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_guest_ok), TRUE);
  else
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_guest_ok), FALSE);

  /* Apply button */

  if (share_info)
    apply_button_label = _("Modify _Share");
  else
    apply_button_label = _("Create _Share");

  gtk_button_set_label (GTK_BUTTON (page->button_apply), apply_button_label);
  gtk_button_set_use_underline (GTK_BUTTON (page->button_apply), TRUE);
  gtk_button_set_image (GTK_BUTTON (page->button_apply), gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_BUTTON));

  gtk_widget_set_sensitive (page->button_apply, FALSE);

  /* Sensitivity */

  property_page_check_sensitivity (page);

  /* Signal handlers */

  g_signal_connect (page->checkbutton_share_folder, "toggled",
                    G_CALLBACK (on_checkbutton_share_folder_toggled),
                    page);

  g_signal_connect (page->checkbutton_share_rw_ro, "toggled",
                    G_CALLBACK (on_checkbutton_rw_ro_toggled),
                    page);

  g_signal_connect (page->checkbutton_share_guest_ok, "toggled",
                    G_CALLBACK (on_checkbutton_guest_ok_toggled),
                    page);

  g_signal_connect (page->entry_share_name, "changed",
                    G_CALLBACK (modify_share_name_text_entry),
                    page);

  g_signal_connect (page->entry_share_comment, "changed",
		    G_CALLBACK (modify_share_comment_text_entry),
		    page);

  g_signal_connect (page->button_apply, "clicked",
		    G_CALLBACK (button_apply_clicked_cb), page);

  if (share_info != NULL)
    shares_free_share_info (share_info);

  return page;
}
コード例 #12
0
static GConfValue *
application_font_to_gconf (GConfPropertyEditor *peditor,
			   GConfValue          *value)
{
  GConfValue *new_value;
  const char *new_font;
  GtkWidget *font_button;
  gint danger_level;

  font_button = GTK_WIDGET (gconf_property_editor_get_ui_control (peditor));
  g_return_val_if_fail (font_button != NULL, NULL);

  new_value = gconf_value_new (GCONF_VALUE_STRING);
  new_font = gconf_value_get_string (value);
  if (font_dangerous (old_font)) {
    /* If we're already too large, we don't warn again. */
    gconf_value_set_string (new_value, new_font);
    return new_value;
  }

  danger_level = font_dangerous (new_font);
  if (danger_level) {
    GtkWidget *warning_dialog, *apply_button;
    const gchar *warning_label;
    gchar *warning_label2;

    warning_label = _("Font may be too large");

    if (danger_level > MAX_FONT_POINT_WITHOUT_WARNING) {
      warning_label2 = g_strdup_printf (ngettext (
			"The font selected is %d point large, "
			"and may make it difficult to effectively "
			"use the computer.  It is recommended that "
			"you select a size smaller than %d.",
			"The font selected is %d points large, "
			"and may make it difficult to effectively "
			"use the computer. It is recommended that "
			"you select a size smaller than %d.",
			danger_level),
			danger_level,
			MAX_FONT_POINT_WITHOUT_WARNING);
    } else {
      warning_label2 = g_strdup_printf (ngettext (
			"The font selected is %d point large, "
			"and may make it difficult to effectively "
			"use the computer.  It is recommended that "
			"you select a smaller sized font.",
			"The font selected is %d points large, "
			"and may make it difficult to effectively "
			"use the computer. It is recommended that "
			"you select a smaller sized font.",
			danger_level),
			danger_level);
    }

    warning_dialog = gtk_message_dialog_new (NULL,
					     GTK_DIALOG_MODAL,
					     GTK_MESSAGE_WARNING,
					     GTK_BUTTONS_NONE,
					     warning_label);

    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (warning_dialog),
					      warning_label2);

    gtk_dialog_add_button (GTK_DIALOG (warning_dialog),
			   _("Use previous font"), GTK_RESPONSE_CLOSE);

    apply_button = gtk_button_new_with_label (_("Use selected font"));

    gtk_button_set_image (GTK_BUTTON (apply_button), gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON));
    gtk_dialog_add_action_widget (GTK_DIALOG (warning_dialog), apply_button, GTK_RESPONSE_APPLY);
    GTK_WIDGET_SET_FLAGS (apply_button, GTK_CAN_DEFAULT);
    gtk_widget_show (apply_button);

    gtk_dialog_set_default_response (GTK_DIALOG (warning_dialog), GTK_RESPONSE_CLOSE);

    g_free (warning_label2);

    if (gtk_dialog_run (GTK_DIALOG (warning_dialog)) == GTK_RESPONSE_APPLY) {
      gconf_value_set_string (new_value, new_font);
    } else {
      gconf_value_set_string (new_value, old_font);
      gtk_font_button_set_font_name (GTK_FONT_BUTTON (font_button), old_font);
    }

    gtk_widget_destroy (warning_dialog);
  } else {
    gconf_value_set_string (new_value, new_font);
  }

  return new_value;
}
コード例 #13
0
/*********************************************************************** Menu */
void
bmd_construct_menu (GtkApplication *app, gpointer data)
{
	GtkWidget *headerbar;
	// the application menu displayed in the GNOME panel
	GMenu *appmenu;
	GMenu *editmenu;

	GtkWidget *openbutton;
	GtkWidget *savebutton;

	// the menu displayed as a popover below the gears button
	GMenu *gearmenu;
	GtkWidget *gearmenubutton;
	GtkWidget *gearicon;

	bmd_widgets *a = (bmd_widgets *) data;

	// define keyboard accelerators
	const gchar *open_accels[2] = { "<Ctrl>O", NULL };
	const gchar *save_accels[2] = { "<Ctrl>S", NULL };
	const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
	const gchar *add_accels[2] = { "<Ctrl>A", NULL };
	const gchar *del_accels[2] = { "<Ctrl>D", NULL };
	const gchar *find_accels[2] = { "<Ctrl>F", NULL };
	const gchar *help_accels[2] = { "F1", NULL };

	// create and fill in the application menu in the GNOME panel
	appmenu = g_menu_new();
	g_menu_append (appmenu, "About", "app.about");
	g_menu_append (appmenu, "Help", "app.help");
	g_menu_append (appmenu, "_Quit", "app.quit");
	gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (appmenu));
	g_object_unref (appmenu);

	// create a headerbar
	headerbar = gtk_header_bar_new ();
	gtk_widget_show (headerbar);
	gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar), "Book Management");
	gtk_header_bar_set_subtitle (GTK_HEADER_BAR (headerbar), "Simple Demo Application");
	gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (headerbar), TRUE);
	gtk_window_set_titlebar (GTK_WINDOW (a->window), headerbar);

	// create an OPEN button, add it to the headerbar and connect the callbacks
	openbutton = gtk_button_new_with_label ("Open");
	gtk_header_bar_pack_start (GTK_HEADER_BAR (headerbar), openbutton);
	gtk_actionable_set_action_name (GTK_ACTIONABLE (openbutton), "app.open");

	// create the gear menu button
	gearmenubutton = gtk_menu_button_new();
	gearicon = gtk_image_new_from_icon_name ("emblem-system-symbolic",
						 GTK_ICON_SIZE_SMALL_TOOLBAR);
	gtk_button_set_image (GTK_BUTTON (gearmenubutton), gearicon);
	gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), gearmenubutton);
	// create a menu for the gear button
	gearmenu = g_menu_new();
	g_menu_append (gearmenu, "Save As ...", "app.saveAs");
	editmenu = g_menu_new();
	g_menu_append (editmenu, "_Find", "app.find");
	g_menu_append (editmenu, "_Add", "app.add");
	g_menu_append (editmenu, "_Delete", "app.delete");
	g_menu_append_section (gearmenu, NULL, G_MENU_MODEL (editmenu));
	gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (gearmenubutton),
					G_MENU_MODEL (gearmenu));
	g_object_unref (editmenu);
	g_object_unref (gearmenu);

	// create an SAVE button, add it to the headerbar and connect the callbacks
	savebutton = gtk_button_new_with_label ("Save");
	gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), savebutton);
	gtk_actionable_set_action_name (GTK_ACTIONABLE (savebutton), "app.save");

	// connect keyboard accelerators
	gtk_application_set_accels_for_action (GTK_APPLICATION (app),
					       "app.open", open_accels);
	gtk_application_set_accels_for_action (GTK_APPLICATION (app),
					       "app.save", save_accels);
	gtk_application_set_accels_for_action (GTK_APPLICATION (app),
					       "app.quit", quit_accels);
	gtk_application_set_accels_for_action (GTK_APPLICATION (app),
					       "app.add", add_accels);
	gtk_application_set_accels_for_action (GTK_APPLICATION (app),
					       "app.delete", del_accels);
	gtk_application_set_accels_for_action (GTK_APPLICATION (app),
					       "app.find", find_accels);
	gtk_application_set_accels_for_action (GTK_APPLICATION (app),
					       "app.help", help_accels);
}
コード例 #14
0
ファイル: viktrwlayer_tpwin.c プロジェクト: guyou/viking
/**
 * vik_trw_layer_tpwin_set_tp:
 * @tpwin:      The Trackpoint Edit Window
 * @tpl:        The #Glist of trackpoints pointing at the current trackpoint
 * @track_name: The name of the track in which the trackpoint belongs
 * @is_route:   Is the track of the trackpoint actually a route?
 *
 * Sets the Trackpoint Edit Window to the values of the current trackpoint given in @tpl.
 *
 */
void vik_trw_layer_tpwin_set_tp ( VikTrwLayerTpwin *tpwin, GList *tpl, const gchar *track_name, gboolean is_route )
{
  static char tmp_str[64];
  static struct LatLon ll;
  VikTrackpoint *tp = VIK_TRACKPOINT(tpl->data);

  if ( tp->name )
    gtk_entry_set_text ( GTK_ENTRY(tpwin->trkpt_name), tp->name );
  else
    gtk_editable_delete_text ( GTK_EDITABLE(tpwin->trkpt_name), 0, -1 );
  gtk_widget_set_sensitive ( tpwin->trkpt_name, TRUE );

  /* Only can insert if not at the end (otherwise use extend track) */
  gtk_widget_set_sensitive ( tpwin->button_insert, (gboolean) GPOINTER_TO_INT (tpl->next) );
  gtk_widget_set_sensitive ( tpwin->button_delete, TRUE );

  /* We can only split up a track if it's not an endpoint. Makes sense to me. */
  gtk_widget_set_sensitive ( tpwin->button_split, tpl->next && tpl->prev );

  gtk_widget_set_sensitive ( tpwin->button_forward, (gboolean) GPOINTER_TO_INT (tpl->next) );
  gtk_widget_set_sensitive ( tpwin->button_back, (gboolean) GPOINTER_TO_INT (tpl->prev) );

  gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->lat), TRUE );
  gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->lon), TRUE );
  gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->alt), TRUE );
  gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->ts), tp->has_timestamp );
  gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->time), tp->has_timestamp );
  // Enable adding timestamps - but not on routepoints
  if ( !tp->has_timestamp && !is_route ) {
    gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->time), TRUE );
    GtkWidget *img = gtk_image_new_from_stock ( GTK_STOCK_ADD, GTK_ICON_SIZE_MENU );
    gtk_button_set_image ( GTK_BUTTON(tpwin->time), img );
  }
  else

  vik_trw_layer_tpwin_set_track_name ( tpwin, track_name );

  tpwin->sync_to_tp_block = TRUE; /* don't update while setting data. */

  vik_coord_to_latlon ( &(tp->coord), &ll );
  gtk_spin_button_set_value ( tpwin->lat, ll.lat );
  gtk_spin_button_set_value ( tpwin->lon, ll.lon );
  vik_units_height_t height_units = a_vik_get_units_height ();
  switch (height_units) {
  case VIK_UNITS_HEIGHT_METRES:
    gtk_spin_button_set_value ( tpwin->alt, tp->altitude );
    break;
  case VIK_UNITS_HEIGHT_FEET:
    gtk_spin_button_set_value ( tpwin->alt, VIK_METERS_TO_FEET(tp->altitude) );
    break;
  default:
    gtk_spin_button_set_value ( tpwin->alt, tp->altitude );
    g_critical("Houston, we've had a problem. height=%d", height_units);
  }

  tpwin_update_times ( tpwin, tp );

  tpwin->sync_to_tp_block = FALSE; // don't update while setting data.

  vik_units_speed_t speed_units = a_vik_get_units_speed ();
  vik_units_distance_t dist_units = a_vik_get_units_distance ();
  if ( tpwin->cur_tp )
  {
    switch (dist_units) {
    case VIK_UNITS_DISTANCE_KILOMETRES:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f m", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)));
      break;
    case VIK_UNITS_DISTANCE_MILES:
    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f yards", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord))*1.0936133);
      break;
    default:
      g_critical("Houston, we've had a problem. distance=%d", dist_units);
    }

    gtk_label_set_text ( tpwin->diff_dist, tmp_str );
    if ( tp->has_timestamp && tpwin->cur_tp->has_timestamp )
    {
      g_snprintf ( tmp_str, sizeof(tmp_str), "%ld s", tp->timestamp - tpwin->cur_tp->timestamp);
      gtk_label_set_text ( tpwin->diff_time, tmp_str );
      if ( tp->timestamp == tpwin->cur_tp->timestamp )
        gtk_label_set_text ( tpwin->diff_speed, "--" );
      else
      {
	switch (speed_units) {
	case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
	  g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f km/h", VIK_MPS_TO_KPH(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) );
	  break;
	case VIK_UNITS_SPEED_MILES_PER_HOUR:
	  g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f mph", VIK_MPS_TO_MPH(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) );
	  break;
	case VIK_UNITS_SPEED_METRES_PER_SECOND:
	  g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f m/s", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / ABS(tp->timestamp - tpwin->cur_tp->timestamp) );
	  break;
	case VIK_UNITS_SPEED_KNOTS:
	  g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f knots", VIK_MPS_TO_KNOTS(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) );
	  break;
	case VIK_UNITS_SPEED_SECONDS_PER_KM:
	  g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f s/km", VIK_MPS_TO_PACE_SPK(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) );
	  break;
	case VIK_UNITS_SPEED_MINUTES_PER_KM:
	  g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f min/km", VIK_MPS_TO_PACE_MPK(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) );
	  break;
	case VIK_UNITS_SPEED_SECONDS_PER_MILE:
	  g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f sec/mi", VIK_MPS_TO_PACE_SPM(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) );
	  break;
	case VIK_UNITS_SPEED_MINUTES_PER_MILE:
	  g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f min/mi", VIK_MPS_TO_PACE_MPM(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) );
	  break;
	default:
	  g_snprintf ( tmp_str, sizeof(tmp_str), "--" );
	  g_critical("Houston, we've had a problem. speed=%d", speed_units);
	}
        gtk_label_set_text ( tpwin->diff_speed, tmp_str );
      }
    }
    else
    {
      gtk_label_set_text ( tpwin->diff_time, NULL );
      gtk_label_set_text ( tpwin->diff_speed, NULL );
    }
  }

  if ( isnan(tp->course) )
    g_snprintf ( tmp_str, sizeof(tmp_str), "--" );
  else
    g_snprintf ( tmp_str, sizeof(tmp_str), "%05.1f\302\260", tp->course );
  gtk_label_set_text ( tpwin->course, tmp_str );

  if ( isnan(tp->speed) )
    g_snprintf ( tmp_str, sizeof(tmp_str), "--" );
  else {
    switch (speed_units) {
    case VIK_UNITS_SPEED_MILES_PER_HOUR:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f mph", VIK_MPS_TO_MPH(tp->speed) );
      break;
    case VIK_UNITS_SPEED_METRES_PER_SECOND:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f m/s", tp->speed );
      break;
    case VIK_UNITS_SPEED_KNOTS:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f knots", VIK_MPS_TO_KNOTS(tp->speed) );
      break;
    case VIK_UNITS_SPEED_SECONDS_PER_KM:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f s/km", VIK_MPS_TO_PACE_SPK(tp->speed) );
      break;
    case VIK_UNITS_SPEED_MINUTES_PER_KM:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f min/km", VIK_MPS_TO_PACE_MPK(tp->speed) );
      break;
    case VIK_UNITS_SPEED_SECONDS_PER_MILE:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f s/mi", VIK_MPS_TO_PACE_SPM(tp->speed) );
      break;
    case VIK_UNITS_SPEED_MINUTES_PER_MILE:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f min/mi", VIK_MPS_TO_PACE_MPM(tp->speed) );
      break;
    default:
      // VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
      g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f km/h", VIK_MPS_TO_KPH(tp->speed) );
      break;
    }
  }
  gtk_label_set_text ( tpwin->speed, tmp_str );

  switch (dist_units) {
  case VIK_UNITS_DISTANCE_KILOMETRES:
    g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f m", tp->hdop );
    gtk_label_set_text ( tpwin->hdop, tmp_str );
    g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f m", tp->pdop );
    gtk_label_set_text ( tpwin->pdop, tmp_str );
    break;
  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
  case VIK_UNITS_DISTANCE_MILES:
    g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f yards", tp->hdop*1.0936133 );
    gtk_label_set_text ( tpwin->hdop, tmp_str );
    g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f yards", tp->pdop*1.0936133 );
    gtk_label_set_text ( tpwin->pdop, tmp_str );
    break;
  default:
    g_critical("Houston, we've had a problem. distance=%d", dist_units);
  }

  switch (height_units) {
  case VIK_UNITS_HEIGHT_METRES:
    g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f m", tp->vdop );
    break;
  case VIK_UNITS_HEIGHT_FEET:
    g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f feet", VIK_METERS_TO_FEET(tp->vdop) );
    break;
  default:
    g_snprintf ( tmp_str, sizeof(tmp_str), "--" );
    g_critical("Houston, we've had a problem. height=%d", height_units);
  }
  gtk_label_set_text ( tpwin->vdop, tmp_str );

  g_snprintf ( tmp_str, sizeof(tmp_str), "%d / %d", tp->nsats, tp->fix_mode );
  gtk_label_set_text ( tpwin->sat, tmp_str );

  tpwin->cur_tp = tp;
}
コード例 #15
0
static void
do_constructed (GObject *obj)
{
  EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
  EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
  TpAccount *account;
  const gchar *protocol, *cm_name;
  guint i = 0;
  struct {
    const gchar *cm_name;
    const gchar *protocol;
    const char *file;
    void (*func)(EmpathyAccountWidget *self, const gchar *filename);
  } widgets [] = {
    { "salut", "local-xmpp", "empathy-account-widget-local-xmpp.ui",
        account_widget_build_salut },
    WIDGET (gabble, jabber),
    WIDGET (butterfly, msn),
    WIDGET (haze, icq),
    WIDGET (haze, aim),
    WIDGET (haze, yahoo),
    WIDGET (haze, groupwise),
    WIDGET (idle, irc),
    WIDGET (sofiasip, sip),
  };

  cm_name = empathy_account_settings_get_cm (priv->settings);
  protocol = empathy_account_settings_get_protocol (priv->settings);

  for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
    {
      if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
          !tp_strdiff (widgets[i].protocol, protocol))
        {
          gchar *filename;

          filename = empathy_file_lookup (widgets[i].file,
              "libempathy-gtk");
          widgets[i].func (self, filename);
          g_free (filename);

          break;
        }
    }

  if (i == G_N_ELEMENTS (widgets))
    {
      gchar *filename = empathy_file_lookup (
          "empathy-account-widget-generic.ui", "libempathy-gtk");
      account_widget_build_generic (self, filename);
      g_free (filename);
    }

  /* handle default focus */
  if (self->ui_details->default_focus != NULL)
    {
      GObject *default_focus_entry;

      default_focus_entry = gtk_builder_get_object
        (self->ui_details->gui, self->ui_details->default_focus);
      g_signal_connect (default_focus_entry, "realize",
          G_CALLBACK (gtk_widget_grab_focus),
          NULL);
    }

  /* handle forget button */
  if (self->ui_details->add_forget)
    {
      const gchar *password = NULL;

      priv->button_forget = GTK_WIDGET (gtk_builder_get_object
          (self->ui_details->gui, "button_forget"));
      priv->entry_password = GTK_WIDGET (gtk_builder_get_object
          (self->ui_details->gui, "entry_password"));

      password = empathy_account_settings_get_string (priv->settings,
          "password");
      gtk_widget_set_sensitive (priv->button_forget,
          !EMP_STR_EMPTY (password));

      g_signal_connect (priv->button_forget, "clicked",
          G_CALLBACK (account_widget_forget_clicked_cb),
          self);
      g_signal_connect (priv->entry_password, "changed",
          G_CALLBACK (account_widget_password_changed_cb),
          self);
    }

  /* handle apply and cancel button */
  if (!priv->simple)
    {
      GtkWidget *hbox = gtk_hbox_new (TRUE, 3);

      priv->cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);

      if (priv->creating_account)
        {
          TpConnectionPresenceType state;
          priv->idle = empathy_idle_dup_singleton ();

          empathy_signal_connect_weak (priv->idle, "notify::state",
              G_CALLBACK (idle_state_change_cb), obj);

          state = empathy_idle_get_state (priv->idle);

          if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
            {
              /* We are online, display a Login button */
              GtkWidget *image;

              priv->apply_button = gtk_button_new_with_mnemonic (_("L_og in"));
              image = gtk_image_new_from_stock (GTK_STOCK_CONNECT,
                  GTK_ICON_SIZE_BUTTON);
              gtk_button_set_image (GTK_BUTTON (priv->apply_button), image);
            }
          else
            {
              /* We are offline, display a Save button */
              priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
            }
        }
      else
        {
          /* We are editing an existing account, display an Apply button */
          priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
        }

      gtk_box_pack_end (GTK_BOX (hbox), priv->apply_button, TRUE,
          TRUE, 3);
      gtk_box_pack_end (GTK_BOX (hbox), priv->cancel_button, TRUE,
          TRUE, 3);

      gtk_box_pack_end (GTK_BOX (self->ui_details->widget), hbox, FALSE,
          FALSE, 3);

      g_signal_connect (priv->cancel_button, "clicked",
          G_CALLBACK (account_widget_cancel_clicked_cb),
          self);
      g_signal_connect (priv->apply_button, "clicked",
          G_CALLBACK (account_widget_apply_clicked_cb),
          self);
      gtk_widget_show_all (hbox);

      if (priv->creating_account)
        /* When creating an account, the user might have nothing to enter.
         * That means that no control interaction might occur,
         * so we update the control button sensitivity manually.
         */
        account_widget_handle_control_buttons_sensitivity (self);
      else
        account_widget_set_control_buttons_sensitivity (self, FALSE);
    }

  account = empathy_account_settings_get_account (priv->settings);

  if (account != NULL)
    {
      g_signal_connect (account, "notify::enabled",
          G_CALLBACK (empathy_account_widget_enabled_cb), self);
    }

  /* handle the "Enabled" checkbox. We only add it when modifying an account */
  if (!priv->creating_account && priv->table_common_settings != NULL)
    {
#ifdef HAVE_MOBLIN
      GtkWidget *w;
#endif
      guint nb_rows, nb_columns;
      gboolean is_enabled;

      is_enabled = tp_account_is_enabled (account);

#ifndef HAVE_MOBLIN
      priv->enabled_checkbox =
          gtk_check_button_new_with_label (_("Enabled"));

      gtk_toggle_button_set_active (
          GTK_TOGGLE_BUTTON (priv->enabled_checkbox), is_enabled);
#else
      /* Translators: this is used only when built on a moblin platform */
      w = gtk_label_new (_("Account:"));
      gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);

      priv->enabled_checkbox = nbtk_gtk_light_switch_new ();

      nbtk_gtk_light_switch_set_active (
          NBTK_GTK_LIGHT_SWITCH (priv->enabled_checkbox), is_enabled);

      gtk_widget_show (w);
#endif /* HAVE_MOBLIN */

      g_object_get (priv->table_common_settings, "n-rows", &nb_rows,
          "n-columns", &nb_columns, NULL);

      gtk_table_resize (GTK_TABLE (priv->table_common_settings), ++nb_rows,
          nb_columns);

#ifndef HAVE_MOBLIN
      gtk_table_attach (GTK_TABLE (priv->table_common_settings),
          priv->enabled_checkbox,
          0, nb_columns, nb_rows - 1, nb_rows,
          GTK_EXPAND | GTK_FILL, 0, 0, 0);
#else
      gtk_table_attach (GTK_TABLE (priv->table_common_settings),
          w,
          0, 1, nb_rows - 1, nb_rows,
          GTK_FILL, 0, 0, 0);
      gtk_table_attach (GTK_TABLE (priv->table_common_settings),
          priv->enabled_checkbox,
          1, nb_columns, nb_rows - 1, nb_rows,
          GTK_EXPAND | GTK_FILL, 0, 0, 0);
#endif /* HAVE_MOBLIN */

      gtk_widget_show (priv->enabled_checkbox);

#ifndef HAVE_MOBLIN
      g_signal_connect (G_OBJECT (priv->enabled_checkbox), "released",
          G_CALLBACK (account_widget_enabled_released_cb), self);
#else
      g_signal_connect (G_OBJECT (priv->enabled_checkbox), "switch-flipped",
          G_CALLBACK (account_widget_switch_flipped_cb), self);
#endif /* HAVE_MOBLIN */
    }

  /* hook up to widget destruction to unref ourselves */
  g_signal_connect (self->ui_details->widget, "destroy",
      G_CALLBACK (account_widget_destroy_cb), self);

  empathy_builder_unref_and_keep_widget (self->ui_details->gui,
      self->ui_details->widget);
  self->ui_details->gui = NULL;
}
コード例 #16
0
ファイル: lxsession-logout.c プロジェクト: magist3r/lxsession
/* Main program. */
int main(int argc, char * argv[])
{
#ifdef ENABLE_NLS
    setlocale(LC_ALL, "");
    bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);
#endif

    /* Initialize GTK (via g_option_context_parse) and parse command line arguments. */
    GOptionContext * context = g_option_context_new("");
    g_option_context_add_main_entries(context, opt_entries, GETTEXT_PACKAGE);
    g_option_context_add_group(context, gtk_get_option_group(TRUE));
    GError * err = NULL;
    if ( ! g_option_context_parse(context, &argc, &argv, &err))
    {
        g_print(_("Error: %s\n"), err->message);
        g_error_free(err);
        return 1;
    }
    g_option_context_free(context);

    HandlerContext handler_context;
    memset(&handler_context, 0, sizeof(handler_context));

    /* Get the lxsession PID. */
    const char * p = g_getenv("_LXSESSION_PID");
    if (p != NULL) handler_context.lxsession_pid = atoi(p);

    /* Initialize capabilities of the systemd mechanism. */
    if (dbus_systemd_CanPowerOff())
    {
        handler_context.shutdown_available = TRUE;
        handler_context.shutdown_systemd = TRUE;
    }
    if (dbus_systemd_CanReboot())
    {
        handler_context.reboot_available = TRUE;
        handler_context.reboot_systemd = TRUE;
    }
    if (dbus_systemd_CanSuspend())
    {
        handler_context.suspend_available = TRUE;
        handler_context.suspend_systemd = TRUE;
    }
    if (dbus_systemd_CanHibernate())
    {
        handler_context.hibernate_available = TRUE;
        handler_context.hibernate_systemd = TRUE;
    }

    /* Initialize capabilities of the ConsoleKit mechanism. */
    if (!handler_context.shutdown_available && dbus_ConsoleKit_CanStop())
    {
        handler_context.shutdown_available = TRUE;
        handler_context.shutdown_ConsoleKit = TRUE;
    }
    if (!handler_context.reboot_available && dbus_ConsoleKit_CanRestart())
    {
        handler_context.reboot_available = TRUE;
        handler_context.reboot_ConsoleKit = TRUE;
    }

    /* Initialize capabilities of the UPower mechanism. */
    if (!handler_context.suspend_available && dbus_UPower_CanSuspend())
    {
        handler_context.suspend_available = TRUE;
        handler_context.suspend_UPower = TRUE;
    }
    if (!handler_context.hibernate_available && dbus_UPower_CanHibernate())
    {
        handler_context.hibernate_available = TRUE;
        handler_context.hibernate_UPower = TRUE;
    }

    /* If we are under GDM, its "Switch User" is available. */
    if (verify_running("gdm", "gdmflexiserver"))
    {
        handler_context.switch_user_available = TRUE;
        handler_context.switch_user_GDM = TRUE;
    }

    /* If we are under GDM3, its "Switch User" is available. */
    if (verify_running("gdm3", "gdmflexiserver"))
    {
        handler_context.switch_user_available = TRUE;
        handler_context.switch_user_GDM = TRUE;
    }

    /* lightdm also use gdmflexiserver */
    if (verify_running("lightdm", "gdmflexiserver"))
    {
        handler_context.switch_user_available = TRUE;
        handler_context.switch_user_GDM = TRUE;
    }

    /* lightdm also use gdmflexiserver */
    if (verify_running("lightdm", "gdmflexiserver"))
    {
        handler_context.switch_user_available = TRUE;
        handler_context.switch_user_GDM = TRUE;
    }

    /* lightdm can also be find by the env */
    if (g_getenv("XDG_SEAT_PATH"))
    {
        handler_context.switch_user_available = TRUE;
        handler_context.switch_user_LIGHTDM = TRUE;
    }

    /* If we are under KDM, its "Switch User" is available. */
    if (verify_running("kdm", "kdmctl"))
    {
        handler_context.switch_user_available = TRUE;
        handler_context.switch_user_KDM = TRUE;
    }

    if (verify_running("lxdm", "lxdm-binary"))
    {
        handler_context.switch_user_available = TRUE;
        handler_context.switch_user_LXDM = TRUE;
    }

    /* LTSP support */
    if (g_getenv("LTSP_CLIENT"))
    {
        handler_context.ltsp = TRUE;
        handler_context.shutdown_available = TRUE;
        handler_context.reboot_available = TRUE;
    }

    /* Lock screen */
    const gchar* very_lock_screen = determine_lock_screen();
    if (very_lock_screen)
    {
        handler_context.lock_screen = TRUE;
    }

    /* Make the button images accessible. */
    gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), PACKAGE_DATA_DIR "/lxsession/images");

    /* Get the background pixbuf. */
    GdkPixbuf * pixbuf = get_background_pixbuf();

    /* Create the toplevel window. */
    GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
    gtk_window_fullscreen(GTK_WINDOW(window));
    GdkScreen* screen = gtk_widget_get_screen(window);
    gtk_window_set_default_size(GTK_WINDOW(window), gdk_screen_get_width(screen), gdk_screen_get_height(screen));
    gtk_widget_set_app_paintable(window, TRUE);
    g_signal_connect(G_OBJECT(window), "expose_event", G_CALLBACK(expose_event), pixbuf);

    /* Toplevel container */
    GtkWidget* alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
    gtk_container_add(GTK_CONTAINER(window), alignment);

    GtkWidget* center_area = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(alignment), center_area);

    GtkWidget* center_vbox = gtk_vbox_new(FALSE, 6);
    gtk_container_set_border_width(GTK_CONTAINER(center_vbox), 12);
    gtk_container_add(GTK_CONTAINER(center_area), center_vbox);

    GtkWidget* controls = gtk_vbox_new(FALSE, 6);

    /* If specified, apply a user-specified banner image. */
    if (banner_path != NULL)
    {
        GtkWidget * banner_image = gtk_image_new_from_file(banner_path);
        GtkPositionType banner_position = get_banner_position();

        switch (banner_position)
        {
            case GTK_POS_LEFT:
            case GTK_POS_RIGHT:
                {
                /* Create a horizontal box to contain the image and the controls. */
                GtkWidget * box = gtk_hbox_new(FALSE, 2);
                gtk_box_pack_start(GTK_BOX(center_vbox), box, FALSE, FALSE, 0);

                /* Pack the image and a separator. */
                gtk_misc_set_alignment(GTK_MISC(banner_image), 0.5, 0.0);
                if (banner_position == GTK_POS_LEFT)
                {
                    gtk_box_pack_start(GTK_BOX(box), banner_image, FALSE, FALSE, 2);
                    gtk_box_pack_start(GTK_BOX(box), gtk_vseparator_new(), FALSE, FALSE, 2);
                    gtk_box_pack_start(GTK_BOX(box), controls, FALSE, FALSE, 2);
                }
                else
                {
                    gtk_box_pack_start(GTK_BOX(box), controls, FALSE, FALSE, 2);
                    gtk_box_pack_end(GTK_BOX(box), gtk_vseparator_new(), FALSE, FALSE, 2);
                    gtk_box_pack_end(GTK_BOX(box), banner_image, FALSE, FALSE, 2);
                }
                }
                break;

            case GTK_POS_TOP:
                gtk_box_pack_start(GTK_BOX(controls), banner_image, FALSE, FALSE, 2);
                gtk_box_pack_start(GTK_BOX(controls), gtk_hseparator_new(), FALSE, FALSE, 2);
                gtk_box_pack_start(GTK_BOX(center_vbox), controls, FALSE, FALSE, 0);
                break;

            case GTK_POS_BOTTOM:
                gtk_box_pack_end(GTK_BOX(controls), banner_image, FALSE, FALSE, 2);
                gtk_box_pack_end(GTK_BOX(controls), gtk_hseparator_new(), FALSE, FALSE, 2);
                gtk_box_pack_start(GTK_BOX(center_vbox), controls, FALSE, FALSE, 0);
                break;
        }
    }
    else
        gtk_box_pack_start(GTK_BOX(center_vbox), controls, FALSE, FALSE, 0);

    /* Create the label. */
    GtkWidget * label = gtk_label_new("");
    if (prompt == NULL)
    {
        const char * session_name = g_getenv("DESKTOP_SESSION");
        if (session_name == NULL)
            session_name = "LXDE";

        const gchar *command_line = "lsb_release -r -s";
        gchar *output = NULL;
        GError *error;

        if (!g_spawn_command_line_sync( command_line,
                                        &output,
                                        NULL,
                                        NULL,
                                        &error))
        {

            fprintf (stderr, "Error: %s\n", error->message);
            g_error_free (error);

        }

        if (output == NULL)
        {
            output = "";
        }
        else
        {
            output[strlen ( output ) - 1] = '\0';
        }

        prompt = g_strdup_printf(_("<b><big>Logout %s %s session ?</big></b>"), session_name, output);
    }
    gtk_label_set_markup(GTK_LABEL(label), prompt);
    gtk_box_pack_start(GTK_BOX(controls), label, FALSE, FALSE, 4);

    /* Create the Shutdown button. */
    if (handler_context.shutdown_available)
    {
        GtkWidget * shutdown_button = gtk_button_new_with_mnemonic(_("Sh_utdown"));
        GtkWidget * image = gtk_image_new_from_icon_name("system-shutdown", GTK_ICON_SIZE_BUTTON);
        gtk_button_set_image(GTK_BUTTON(shutdown_button), image);
        gtk_button_set_alignment(GTK_BUTTON(shutdown_button), 0.0, 0.5);
        g_signal_connect(G_OBJECT(shutdown_button), "clicked", G_CALLBACK(shutdown_clicked), &handler_context);
        gtk_box_pack_start(GTK_BOX(controls), shutdown_button, FALSE, FALSE, 4);
    }

    /* Create the Reboot button. */
    if (handler_context.reboot_available)
    {
        GtkWidget * reboot_button = gtk_button_new_with_mnemonic(_("_Reboot"));
        GtkWidget * image = gtk_image_new_from_icon_name("gnome-session-reboot", GTK_ICON_SIZE_BUTTON);
        gtk_button_set_image(GTK_BUTTON(reboot_button), image);
        gtk_button_set_alignment(GTK_BUTTON(reboot_button), 0.0, 0.5);
        g_signal_connect(G_OBJECT(reboot_button), "clicked", G_CALLBACK(reboot_clicked), &handler_context);
        gtk_box_pack_start(GTK_BOX(controls), reboot_button, FALSE, FALSE, 4);
    }

    /* Create the Suspend button. */
    if (handler_context.suspend_available && !handler_context.ltsp)
    {
        GtkWidget * suspend_button = gtk_button_new_with_mnemonic(_("_Suspend"));
        GtkWidget * image = gtk_image_new_from_icon_name("gnome-session-suspend", GTK_ICON_SIZE_BUTTON);
        gtk_button_set_image(GTK_BUTTON(suspend_button), image);
        gtk_button_set_alignment(GTK_BUTTON(suspend_button), 0.0, 0.5);
        g_signal_connect(G_OBJECT(suspend_button), "clicked", G_CALLBACK(suspend_clicked), &handler_context);
        gtk_box_pack_start(GTK_BOX(controls), suspend_button, FALSE, FALSE, 4);
    }

    /* Create the Hibernate button. */
    if (handler_context.hibernate_available && !handler_context.ltsp)
    {
        GtkWidget * hibernate_button = gtk_button_new_with_mnemonic(_("_Hibernate"));
        GtkWidget * image = gtk_image_new_from_icon_name("gnome-session-hibernate", GTK_ICON_SIZE_BUTTON);
        gtk_button_set_image(GTK_BUTTON(hibernate_button), image);
        gtk_button_set_alignment(GTK_BUTTON(hibernate_button), 0.0, 0.5);
        g_signal_connect(G_OBJECT(hibernate_button), "clicked", G_CALLBACK(hibernate_clicked), &handler_context);
        gtk_box_pack_start(GTK_BOX(controls), hibernate_button, FALSE, FALSE, 4);
    }

    /* Create the Switch User button. */
    if (handler_context.switch_user_available && !handler_context.ltsp)
    {
        GtkWidget * switch_user_button = gtk_button_new_with_mnemonic(_("S_witch User"));
        GtkWidget * image = gtk_image_new_from_icon_name("gnome-session-switch", GTK_ICON_SIZE_BUTTON);
        gtk_button_set_image(GTK_BUTTON(switch_user_button), image);
        gtk_button_set_alignment(GTK_BUTTON(switch_user_button), 0.0, 0.5);
        g_signal_connect(G_OBJECT(switch_user_button), "clicked", G_CALLBACK(switch_user_clicked), &handler_context);
        gtk_box_pack_start(GTK_BOX(controls), switch_user_button, FALSE, FALSE, 4);
    }

    /* Create the Lock Screen button. */
    if (handler_context.lock_screen && !handler_context.ltsp)
    {
        GtkWidget * lock_screen_button = gtk_button_new_with_mnemonic(_("L_ock Screen"));
        GtkWidget * image = gtk_image_new_from_icon_name("system-lock-screen", GTK_ICON_SIZE_BUTTON);
        gtk_button_set_image(GTK_BUTTON(lock_screen_button), image);
        gtk_button_set_alignment(GTK_BUTTON(lock_screen_button), 0.0, 0.5);
        g_signal_connect(G_OBJECT(lock_screen_button), "clicked", G_CALLBACK(lock_screen_clicked), &handler_context);
        gtk_box_pack_start(GTK_BOX(controls), lock_screen_button, FALSE, FALSE, 4);
    }

    /* Create the Logout button. */
    GtkWidget * logout_button = gtk_button_new_with_mnemonic(_("_Logout"));
    GtkWidget * image = gtk_image_new_from_icon_name("system-log-out", GTK_ICON_SIZE_BUTTON);
    gtk_button_set_image(GTK_BUTTON(logout_button), image);
    gtk_button_set_alignment(GTK_BUTTON(logout_button), 0.0, 0.5);
    g_signal_connect(G_OBJECT(logout_button), "clicked", G_CALLBACK(logout_clicked), &handler_context);
    gtk_box_pack_start(GTK_BOX(controls), logout_button, FALSE, FALSE, 4);

    /* Create the Cancel button. */
    GtkWidget * cancel_button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
    gtk_button_set_alignment(GTK_BUTTON(cancel_button), 0.0, 0.5);
    g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(cancel_clicked), NULL);
    gtk_box_pack_start(GTK_BOX(controls), cancel_button, FALSE, FALSE, 4);

    /* Create the error text. */
    handler_context.error_label = gtk_label_new("");
    gtk_label_set_justify(GTK_LABEL(handler_context.error_label), GTK_JUSTIFY_CENTER);
    gtk_box_pack_start(GTK_BOX(controls), handler_context.error_label, FALSE, FALSE, 4);

    /* Show everything. */
    gtk_widget_show_all(window);

    /* Run the main event loop. */
    gtk_main();

    /* Return. */
    return 0;
}
コード例 #17
0
ファイル: preferences.c プロジェクト: ZaWertun/ClipIt
/* Shows the preferences dialog on the given tab */
void show_preferences(gint tab) {
  if(gtk_grab_get_current()) {
    /* A window is already open, so we present it to the user */
    GtkWidget *toplevel = gtk_widget_get_toplevel(gtk_grab_get_current());
    gtk_window_present((GtkWindow*)toplevel);
    return;
  }
  /* Declare some variables */
  GtkWidget *frame,     *label,
            *alignment, *hbox,
            *vbox;
  
  GtkObject *adjustment, *adjustment_small, *adjustment_statics;
  GtkTreeViewColumn *tree_column;
  
  /* Create the dialog */
  GtkWidget* dialog = gtk_dialog_new_with_buttons(_("Preferences"),     NULL,
                                                   (GTK_DIALOG_MODAL  + GTK_DIALOG_NO_SEPARATOR),
                                                    GTK_STOCK_CANCEL,   GTK_RESPONSE_REJECT,
                                                    GTK_STOCK_OK,       GTK_RESPONSE_ACCEPT, NULL);
  
  gtk_window_set_icon((GtkWindow*)dialog, gtk_widget_render_icon(dialog, GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU, NULL));
  gtk_window_set_resizable((GtkWindow*)dialog, FALSE);
  
  /* Create notebook */
  GtkWidget* notebook = gtk_notebook_new();
#if GTK_CHECK_VERSION (2,14,0)
  gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dialog))), notebook, TRUE, TRUE, 2);
#else
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), notebook, TRUE, TRUE, 2);
#endif
  
  /* Build the settings page */  
  GtkWidget* page_settings = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_settings, 12, 6, 12, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_settings, gtk_label_new(_("Settings")));
  GtkWidget* vbox_settings = gtk_vbox_new(FALSE, 12);
  gtk_container_add((GtkContainer*)page_settings, vbox_settings);
  
  /* Build the clipboards frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Clipboards</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  copy_check = gtk_check_button_new_with_mnemonic(_("Use _Copy (Ctrl-C)"));
  g_signal_connect((GObject*)copy_check, "toggled", (GCallback)check_toggled, NULL);
  gtk_box_pack_start((GtkBox*)vbox, copy_check, FALSE, FALSE, 0);
  primary_check = gtk_check_button_new_with_mnemonic(_("Use _Primary (Selection)"));
  g_signal_connect((GObject*)primary_check, "toggled", (GCallback)check_toggled, NULL);
  gtk_box_pack_start((GtkBox*)vbox, primary_check, FALSE, FALSE, 0);
  synchronize_check = gtk_check_button_new_with_mnemonic(_("S_ynchronize clipboards"));
  gtk_box_pack_start((GtkBox*)vbox, synchronize_check, FALSE, FALSE, 0);
  paste_check = gtk_check_button_new_with_mnemonic(_("_Automatically paste selected item"));
  g_signal_connect((GObject*)paste_check, "toggled", (GCallback)check_toggled, NULL);
  gtk_box_pack_start((GtkBox*)vbox, paste_check, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_settings, frame, FALSE, FALSE, 0);

  /* Build the miscellaneous frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Miscellaneous</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  show_indexes_check = gtk_check_button_new_with_mnemonic(_("Show _indexes in history menu"));
  gtk_box_pack_start((GtkBox*)vbox, show_indexes_check, FALSE, FALSE, 0);
  save_uris_check = gtk_check_button_new_with_mnemonic(_("S_ave URIs"));
  gtk_box_pack_start((GtkBox*)vbox, save_uris_check, FALSE, FALSE, 0);
  hyperlinks_check = gtk_check_button_new_with_mnemonic(_("Capture _hyperlinks only"));
  gtk_box_pack_start((GtkBox*)vbox, hyperlinks_check, FALSE, FALSE, 0);
  confirm_check = gtk_check_button_new_with_mnemonic(_("C_onfirm before clearing history"));
  gtk_box_pack_start((GtkBox*)vbox, confirm_check, FALSE, FALSE, 0);
  use_rmb_menu_check = gtk_check_button_new_with_mnemonic(_("_Use right-click menu"));
  gtk_box_pack_start((GtkBox*)vbox, use_rmb_menu_check, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_settings, frame, FALSE, FALSE, 0);

  /* Build the history page */
  GtkWidget* page_history = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_history, 12, 6, 12, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_history, gtk_label_new(_("History")));
  GtkWidget* vbox_history = gtk_vbox_new(FALSE, 12);
  gtk_container_add((GtkContainer*)page_history, vbox_history);

  /* Build the history frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>History</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  save_check = gtk_check_button_new_with_mnemonic(_("Save _history"));
  gtk_widget_set_tooltip_text(save_check, _("Save and restore history between sessions"));
  gtk_box_pack_start((GtkBox*)vbox, save_check, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Items in history:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  adjustment = gtk_adjustment_new(25, 5, 1000, 1, 10, 0);
  history_spin = gtk_spin_button_new((GtkAdjustment*)adjustment, 0.0, 0);
  gtk_spin_button_set_update_policy((GtkSpinButton*)history_spin, GTK_UPDATE_IF_VALID);
  gtk_box_pack_start((GtkBox*)hbox, history_spin, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Items in menu:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  adjustment_small = gtk_adjustment_new(25, 5, 100, 1, 10, 0);
  items_menu = gtk_spin_button_new((GtkAdjustment*)adjustment_small, 0.0, 0);
  gtk_spin_button_set_update_policy((GtkSpinButton*)items_menu, GTK_UPDATE_IF_VALID);
  gtk_box_pack_start((GtkBox*)hbox, items_menu, FALSE, FALSE, 0);
  statics_show_check = gtk_check_button_new_with_mnemonic(_("Show _static items in menu"));
  g_signal_connect((GObject*)statics_show_check, "toggled", (GCallback)check_toggled, NULL);
  gtk_box_pack_start((GtkBox*)vbox, statics_show_check, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Static items in menu:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  adjustment_statics = gtk_adjustment_new(10, 1, 100, 1, 10, 0);
  statics_items_spin = gtk_spin_button_new((GtkAdjustment*)adjustment_statics, 0.0, 0);
  gtk_spin_button_set_update_policy((GtkSpinButton*)statics_items_spin, GTK_UPDATE_IF_VALID);
  gtk_box_pack_start((GtkBox*)hbox, statics_items_spin, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_history, frame, FALSE, FALSE, 0);

  /* Build the items frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Items</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  linemode_check = gtk_check_button_new_with_mnemonic(_("Show in a single _line"));
  gtk_box_pack_start((GtkBox*)vbox, linemode_check, FALSE, FALSE, 0);
  reverse_check = gtk_check_button_new_with_mnemonic(_("Show in _reverse order"));
  gtk_box_pack_start((GtkBox*)vbox, reverse_check, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Character length of items:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  adjustment = gtk_adjustment_new(50, 25, 75, 1, 5, 0);
  charlength_spin = gtk_spin_button_new((GtkAdjustment*)adjustment, 0.0, 0);
  gtk_spin_button_set_update_policy((GtkSpinButton*)charlength_spin, GTK_UPDATE_IF_VALID);
  gtk_box_pack_start((GtkBox*)hbox, charlength_spin, FALSE, FALSE, 0);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Omit items in the:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  ellipsize_combo = gtk_combo_box_new_text();
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("Beginning"));
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("Middle"));
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("End"));
  gtk_box_pack_start((GtkBox*)hbox, ellipsize_combo, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_history, frame, FALSE, FALSE, 0);
  
  /* Build the omitting frame 
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Omitting</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  hbox = gtk_hbox_new(FALSE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Omit items in the:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
  ellipsize_combo = gtk_combo_box_new_text();
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("Beginning"));
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("Middle"));
  gtk_combo_box_append_text((GtkComboBox*)ellipsize_combo, _("End"));
  gtk_box_pack_start((GtkBox*)hbox, ellipsize_combo, FALSE, FALSE, 0);
  gtk_box_pack_start((GtkBox*)vbox_history, frame, FALSE, FALSE, 0); */
  
  /* Build the actions page */
  GtkWidget* page_actions = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_actions, 6, 6, 6, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_actions, gtk_label_new(_("Actions")));
  GtkWidget* vbox_actions = gtk_vbox_new(FALSE, 6);
  gtk_container_add((GtkContainer*)page_actions, vbox_actions);
  
  /* Build the actions label */
  label = gtk_label_new(_("Control-click ClipIt\'s tray icon to use actions"));
  gtk_label_set_line_wrap((GtkLabel*)label, TRUE);
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)vbox_actions, label, FALSE, FALSE, 0);
  
  /* Build the actions treeview */
  GtkWidget* scrolled_window = gtk_scrolled_window_new(
                               (GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0),
                               (GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0));
  
  gtk_scrolled_window_set_policy((GtkScrolledWindow*)scrolled_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type((GtkScrolledWindow*)scrolled_window, GTK_SHADOW_ETCHED_OUT);
  GtkWidget* treeview = gtk_tree_view_new();
  gtk_tree_view_set_reorderable((GtkTreeView*)treeview, TRUE);
  gtk_tree_view_set_rules_hint((GtkTreeView*)treeview, TRUE);
  actions_list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING, -1);
  gtk_tree_view_set_model((GtkTreeView*)treeview, (GtkTreeModel*)actions_list);
  GtkCellRenderer* name_renderer = gtk_cell_renderer_text_new();
  g_object_set(name_renderer, "editable", TRUE, NULL);
  g_signal_connect((GObject*)name_renderer, "edited", (GCallback)edit_action, (gpointer)0);
  tree_column = gtk_tree_view_column_new_with_attributes(_("Action"), name_renderer, "text", 0, NULL);
  gtk_tree_view_column_set_resizable(tree_column, TRUE);
  gtk_tree_view_append_column((GtkTreeView*)treeview, tree_column);
  GtkCellRenderer* command_renderer = gtk_cell_renderer_text_new();
  g_object_set(command_renderer, "editable", TRUE, NULL);
  g_object_set(command_renderer, "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
  g_signal_connect((GObject*)command_renderer, "edited", (GCallback)edit_action, (gpointer)1);
  tree_column = gtk_tree_view_column_new_with_attributes(_("Command"), command_renderer, "text", 1, NULL);
  gtk_tree_view_column_set_expand(tree_column, TRUE);
  gtk_tree_view_append_column((GtkTreeView*)treeview, tree_column);
  gtk_container_add((GtkContainer*)scrolled_window, treeview);
  gtk_box_pack_start((GtkBox*)vbox_actions, scrolled_window, TRUE, TRUE, 0);
  
  /* Edit selection and connect treeview related signals */
  actions_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview);
  gtk_tree_selection_set_mode(actions_selection, GTK_SELECTION_BROWSE);
  g_signal_connect((GObject*)treeview, "key-press-event", (GCallback)delete_key_pressed, NULL);
  
  /* Build the buttons */
  GtkWidget* hbbox = gtk_hbutton_box_new();
  gtk_box_set_spacing((GtkBox*)hbbox, 6);
  gtk_button_box_set_layout((GtkButtonBox*)hbbox, GTK_BUTTONBOX_START);
  GtkWidget* add_button = gtk_button_new_with_label(_("Add..."));
  gtk_button_set_image((GtkButton*)add_button, gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)add_button, "clicked", (GCallback)add_action, NULL);
  gtk_box_pack_start((GtkBox*)hbbox, add_button, FALSE, TRUE, 0);
  GtkWidget* remove_button = gtk_button_new_with_label(_("Remove"));
  gtk_button_set_image((GtkButton*)remove_button, gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)remove_button, "clicked", (GCallback)remove_action, NULL);
  gtk_box_pack_start((GtkBox*)hbbox, remove_button, FALSE, TRUE, 0);
  GtkWidget* up_button = gtk_button_new();
  gtk_button_set_image((GtkButton*)up_button, gtk_image_new_from_stock(GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)up_button, "clicked", (GCallback)move_action_up, NULL);
  gtk_box_pack_start((GtkBox*)hbbox, up_button, FALSE, TRUE, 0);
  GtkWidget* down_button = gtk_button_new();
  gtk_button_set_image((GtkButton*)down_button, gtk_image_new_from_stock(GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)down_button, "clicked", (GCallback)move_action_down, NULL);
  gtk_box_pack_start((GtkBox*)hbbox, down_button, FALSE, TRUE, 0);
  gtk_box_pack_start((GtkBox*)vbox_actions, hbbox, FALSE, FALSE, 0);

  /* Build the exclude page */
  GtkWidget* page_exclude = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_exclude, 6, 6, 6, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_exclude, gtk_label_new(_("Exclude")));
  GtkWidget* vbox_exclude = gtk_vbox_new(FALSE, 6);
  gtk_container_add((GtkContainer*)page_exclude, vbox_exclude);
  
  /* Build the exclude label */
  label = gtk_label_new(_("Regex list of items that should not be inserted into the history (passwords/sites that you don't need in history, etc)."));
  gtk_label_set_line_wrap((GtkLabel*)label, TRUE);
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)vbox_exclude, label, FALSE, FALSE, 0);
  
  /* Build the exclude treeview */
  GtkWidget* scrolled_window_exclude = gtk_scrolled_window_new(
                               (GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0),
                               (GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0));
  
  gtk_scrolled_window_set_policy((GtkScrolledWindow*)scrolled_window_exclude, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type((GtkScrolledWindow*)scrolled_window_exclude, GTK_SHADOW_ETCHED_OUT);
  GtkWidget* treeview_exclude = gtk_tree_view_new();
  gtk_tree_view_set_reorderable((GtkTreeView*)treeview_exclude, TRUE);
  gtk_tree_view_set_rules_hint((GtkTreeView*)treeview_exclude, TRUE);
  exclude_list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING, -1);
  gtk_tree_view_set_model((GtkTreeView*)treeview_exclude, (GtkTreeModel*)exclude_list);
  GtkCellRenderer* name_renderer_exclude = gtk_cell_renderer_text_new();
  g_object_set(name_renderer_exclude, "editable", TRUE, NULL);
  g_signal_connect((GObject*)name_renderer_exclude, "edited", (GCallback)edit_exclude, (gpointer)0);
  tree_column = gtk_tree_view_column_new_with_attributes(_("Regex"), name_renderer_exclude, "text", 0, NULL);
  gtk_tree_view_column_set_resizable(tree_column, TRUE);
  gtk_tree_view_append_column((GtkTreeView*)treeview_exclude, tree_column);
  gtk_container_add((GtkContainer*)scrolled_window_exclude, treeview_exclude);
  gtk_box_pack_start((GtkBox*)vbox_exclude, scrolled_window_exclude, TRUE, TRUE, 0);
  
  /* Edit selection and connect treeview related signals */
  exclude_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_exclude);
  gtk_tree_selection_set_mode(exclude_selection, GTK_SELECTION_BROWSE);
  g_signal_connect((GObject*)treeview_exclude, "key-press-event", (GCallback)delete_key_pressed, NULL);
  
  /* Build the buttons */
  GtkWidget* hbbox_exclude = gtk_hbutton_box_new();
  gtk_box_set_spacing((GtkBox*)hbbox_exclude, 6);
  gtk_button_box_set_layout((GtkButtonBox*)hbbox_exclude, GTK_BUTTONBOX_START);
  GtkWidget* add_button_exclude = gtk_button_new_with_label(_("Add..."));
  gtk_button_set_image((GtkButton*)add_button_exclude, gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)add_button_exclude, "clicked", (GCallback)add_exclude, NULL);
  gtk_box_pack_start((GtkBox*)hbbox_exclude, add_button_exclude, FALSE, TRUE, 0);
  GtkWidget* remove_button_exclude = gtk_button_new_with_label(_("Remove"));
  gtk_button_set_image((GtkButton*)remove_button_exclude, gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
  g_signal_connect((GObject*)remove_button_exclude, "clicked", (GCallback)remove_exclude, NULL);
  gtk_box_pack_start((GtkBox*)hbbox_exclude, remove_button_exclude, FALSE, TRUE, 0);
  gtk_box_pack_start((GtkBox*)vbox_exclude, hbbox_exclude, FALSE, FALSE, 0);
  
  /* Build the hotkeys page */
  GtkWidget* page_extras = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)page_extras, 12, 6, 12, 6);
  gtk_notebook_append_page((GtkNotebook*)notebook, page_extras, gtk_label_new(_("Hotkeys")));
  GtkWidget* vbox_extras = gtk_vbox_new(FALSE, 12);
  gtk_container_add((GtkContainer*)page_extras, vbox_extras);
  
  /* Build the hotkeys frame */
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type((GtkFrame*)frame, GTK_SHADOW_NONE);
  label = gtk_label_new(NULL);
  gtk_label_set_markup((GtkLabel*)label, _("<b>Hotkeys</b>"));
  gtk_frame_set_label_widget((GtkFrame*)frame, label);
  alignment = gtk_alignment_new(0.50, 0.50, 1.0, 1.0);
  gtk_alignment_set_padding((GtkAlignment*)alignment, 12, 0, 12, 0);
  gtk_container_add((GtkContainer*)frame, alignment);
  vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_add((GtkContainer*)alignment, vbox);
  /* History key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("History hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  history_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)history_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, history_key_entry, TRUE, TRUE, 0);
  /* Actions key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Actions hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  actions_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)actions_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, actions_key_entry, TRUE, TRUE, 0);
  /* Menu key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Menu hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  menu_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)menu_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, menu_key_entry, TRUE, TRUE, 0);
  /* Search key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Manage hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  search_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)search_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, search_key_entry, TRUE, TRUE, 0);
  /* Offline mode key combination */
  hbox = gtk_hbox_new(TRUE, 4);
  gtk_box_pack_start((GtkBox*)vbox, hbox, FALSE, FALSE, 0);
  label = gtk_label_new(_("Offline mode hotkey:"));
  gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
  gtk_box_pack_start((GtkBox*)hbox, label, TRUE, TRUE, 0);
  offline_key_entry = gtk_entry_new();
  gtk_entry_set_width_chars((GtkEntry*)offline_key_entry, 10);
  gtk_box_pack_end((GtkBox*)hbox, offline_key_entry, TRUE, TRUE, 0);
  gtk_box_pack_start((GtkBox*)vbox_extras, frame, FALSE, FALSE, 0);
  
  /* Make widgets reflect current preferences */
  gtk_toggle_button_set_active((GtkToggleButton*)copy_check, prefs.use_copy);
  gtk_toggle_button_set_active((GtkToggleButton*)primary_check, prefs.use_primary);
  gtk_toggle_button_set_active((GtkToggleButton*)synchronize_check, prefs.synchronize);
  gtk_toggle_button_set_active((GtkToggleButton*)paste_check, prefs.automatic_paste);
  gtk_toggle_button_set_active((GtkToggleButton*)show_indexes_check, prefs.show_indexes);
  gtk_toggle_button_set_active((GtkToggleButton*)save_uris_check, prefs.save_uris);
  gtk_toggle_button_set_active((GtkToggleButton*)use_rmb_menu_check, prefs.use_rmb_menu);
  gtk_toggle_button_set_active((GtkToggleButton*)save_check, prefs.save_history);
  gtk_spin_button_set_value((GtkSpinButton*)history_spin, (gdouble)prefs.history_limit);
  gtk_spin_button_set_value((GtkSpinButton*)items_menu, (gdouble)prefs.items_menu);
  gtk_toggle_button_set_active((GtkToggleButton*)statics_show_check, prefs.statics_show);
  gtk_spin_button_set_value((GtkSpinButton*)statics_items_spin, (gdouble)prefs.statics_items);
  gtk_toggle_button_set_active((GtkToggleButton*)hyperlinks_check, prefs.hyperlinks_only);
  gtk_toggle_button_set_active((GtkToggleButton*)confirm_check, prefs.confirm_clear);
  gtk_toggle_button_set_active((GtkToggleButton*)linemode_check, prefs.single_line);
  gtk_toggle_button_set_active((GtkToggleButton*)reverse_check, prefs.reverse_history);
  gtk_spin_button_set_value((GtkSpinButton*)charlength_spin, (gdouble)prefs.item_length);
  gtk_combo_box_set_active((GtkComboBox*)ellipsize_combo, prefs.ellipsize - 1);
  gtk_entry_set_text((GtkEntry*)history_key_entry, prefs.history_key);
  gtk_entry_set_text((GtkEntry*)actions_key_entry, prefs.actions_key);
  gtk_entry_set_text((GtkEntry*)menu_key_entry, prefs.menu_key);
  gtk_entry_set_text((GtkEntry*)search_key_entry, prefs.search_key);
  gtk_entry_set_text((GtkEntry*)offline_key_entry, prefs.offline_key);
  
  /* Read actions */
  read_actions();
  read_excludes();
  
  /* Run the dialog */
  gtk_widget_show_all(dialog);
#ifdef HAVE_APPINDICATOR
  gtk_widget_hide(use_rmb_menu_check);
#endif
  gtk_notebook_set_current_page((GtkNotebook*)notebook, tab);
  if (gtk_dialog_run((GtkDialog*)dialog) == GTK_RESPONSE_ACCEPT)
  {
    /* If the user disabled history saving, we ask him if he wants to delete the history file */
    if(prefs.save_history && !gtk_toggle_button_get_active((GtkToggleButton*)save_check))
      check_saved_hist_file();
    /* Apply and save preferences */
    apply_preferences();
    save_preferences();
    save_actions();
    save_excludes();
  }
  gtk_widget_destroy(dialog);
}
コード例 #18
0
ファイル: dialog.c プロジェクト: MichaelMure/Gimp-Cage-Tool
static GtkWidget *
build_searchbar (void)
{
  GtkWidget *button;
  GtkWidget *image;
  GtkWidget *entry;
  GtkWidget *hbox;
  GtkWidget *label;

  hbox = gtk_hbox_new (FALSE, 6);

  label = gtk_label_new (_("Find:"));
  gtk_widget_show (label);
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);

  entry = gtk_entry_new ();
  gtk_widget_show (entry);
  gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
  g_object_set_data (G_OBJECT (hbox), "entry", entry);

  g_signal_connect (entry, "changed",
                    G_CALLBACK (search_entry_changed),
                    NULL);

  g_signal_connect (entry, "key-press-event",
                    G_CALLBACK (search_entry_key_press),
                    NULL);

  button = gtk_button_new_with_mnemonic (C_("search", "_Previous"));
  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
  gtk_button_set_image (GTK_BUTTON (button),
                        gtk_image_new_from_stock (GTK_STOCK_GO_BACK,
                                                  GTK_ICON_SIZE_BUTTON));
  gtk_widget_show (button);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);

  g_signal_connect (button, "clicked",
                    G_CALLBACK (search_prev_clicked),
                    entry);

  button = gtk_button_new_with_mnemonic (C_("search", "_Next"));
  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
  gtk_button_set_image (GTK_BUTTON (button),
                        gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD,
                                                  GTK_ICON_SIZE_BUTTON));
  gtk_widget_show (button);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);

  g_signal_connect (button, "clicked",
                    G_CALLBACK (search_next_clicked),
                    entry);

  button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);

  g_object_get (button, "image", &image, NULL);
  g_object_set (image, "icon-size", GTK_ICON_SIZE_MENU, NULL);
  g_object_unref (image);

  gtk_widget_show (button);
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);

  g_signal_connect (button, "clicked",
                    G_CALLBACK (search_close_clicked),
                    NULL);

  return hbox;
}
コード例 #19
0
static int _progress(Prefs * prefs, char * argv[])
{
	Progress p;
	struct stat st;
	GtkWidget * vbox;
	GtkWidget * hbox;
	GtkSizeGroup * left;
	GtkSizeGroup * right;
	GtkWidget * widget;
	PangoFontDescription * bold;
	char const * q;
	unsigned long id;
  
	memset(&p, 0, sizeof(p));
	p.prefs = prefs;
	if(prefs->bufsiz == 0)
		errno = EINVAL;
	if(prefs->bufsiz == 0 || (p.buf = malloc(prefs->bufsiz)) == NULL)
		return _progress_error(&p, "malloc", 1);
	p.bufsiz = prefs->bufsiz;
	if(pipe(p.fds) != 0)
		return _progress_error(&p, "pipe", 1);
	if((p.pid = fork()) == -1)
	{
		close(p.fds[0]);
		close(p.fds[1]);
		return _progress_error(&p, "fork", 1);
	}
	if(p.pid != 0)
		return _progress_exec(&p, argv);
	close(p.fds[0]);
	if(gettimeofday(&p.tv, NULL) != 0)
		return _progress_error(&p, "gettimeofday", 1);
	if(prefs->filename == NULL)
		prefs->filename = _("Standard input");
	else if((p.fd = open(prefs->filename, O_RDONLY)) < 0)
		return _progress_error(&p, prefs->filename, 1);
	else if(fstat(p.fd, &st) == 0 && S_ISREG(st.st_mode))
		prefs->length = st.st_size;
	p.in_channel = g_io_channel_unix_new(p.fd);
	g_io_channel_set_encoding(p.in_channel, NULL, NULL);
	p.in_id = 0;
	g_idle_add(_progress_idle_in, &p);
	p.out_channel = g_io_channel_unix_new(p.fds[1]);
	g_io_channel_set_encoding(p.out_channel, NULL, NULL);
	p.out_id = 0;
	/* graphical interface */
	if((prefs->flags & PREFS_x) == 0)
	{
		p.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
#if GTK_CHECK_VERSION(3, 0, 0) && !GTK_CHECK_VERSION(3, 14, 0)
		gtk_window_set_has_resize_grip(GTK_WINDOW(p.window), FALSE);
#endif
		gtk_window_set_title(GTK_WINDOW(p.window), prefs->title != NULL
				? prefs->title : _("Progress"));
		g_signal_connect_swapped(p.window, "delete-event", G_CALLBACK(
					_progress_closex), p.window);
	}
	else
	{
		p.window = gtk_plug_new(0);
		g_signal_connect_swapped(p.window, "embedded", G_CALLBACK(
					_progress_embedded), &p);
	}
#if GTK_CHECK_VERSION(3, 0, 0)
	vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
	hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#else
	vbox = gtk_vbox_new(FALSE, 0);
	hbox = gtk_hbox_new(FALSE, 0);
#endif
	left = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
	right = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
	/* file */
	widget = gtk_label_new(_("File: "));
	bold = pango_font_description_new();
	pango_font_description_set_weight(bold, PANGO_WEIGHT_BOLD);
#if GTK_CHECK_VERSION(3, 0, 0)
	gtk_widget_override_font(widget, bold);
	g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
#else
	gtk_widget_modify_font(widget, bold);
	gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
#endif
	gtk_size_group_add_widget(left, widget);
	gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
	if((q = g_filename_to_utf8(prefs->filename, -1, NULL, NULL, NULL))
			== NULL)
		q = prefs->filename;
	widget = gtk_label_new(q);
	gtk_label_set_ellipsize(GTK_LABEL(widget), PANGO_ELLIPSIZE_MIDDLE);
#if GTK_CHECK_VERSION(3, 0, 0)
	g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
#else
	gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
#endif
	gtk_size_group_add_widget(right, widget);
	gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
	/* done */
#if GTK_CHECK_VERSION(3, 0, 0)
	hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#else
	hbox = gtk_hbox_new(FALSE, 0);
#endif
	widget = gtk_label_new(_("Done: "));
#if GTK_CHECK_VERSION(3, 0, 0)
	gtk_widget_override_font(widget, bold);
	g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
#else
	gtk_widget_modify_font(widget, bold);
	gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
#endif
	gtk_size_group_add_widget(left, widget);
	gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
	p.done = gtk_label_new(_("0.0 kB"));
#if GTK_CHECK_VERSION(3, 0, 0)
	g_object_set(p.done, "halign", GTK_ALIGN_START, NULL);
#else
	gtk_misc_set_alignment(GTK_MISC(p.done), 0.0, 0.5);
#endif
	gtk_size_group_add_widget(right, p.done);
	gtk_box_pack_start(GTK_BOX(hbox), p.done, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 4);
	/* remaining */
#if GTK_CHECK_VERSION(3, 0, 0)
	hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#else
	hbox = gtk_hbox_new(FALSE, 0);
#endif
	widget = gtk_label_new(_("Remaining: "));
#if GTK_CHECK_VERSION(3, 0, 0)
	gtk_widget_override_font(widget, bold);
	g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
#else
	gtk_widget_modify_font(widget, bold);
	gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
#endif
	gtk_size_group_add_widget(left, widget);
	gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
	p.remaining = gtk_label_new("");
	g_timeout_add(250, _progress_timeout, &p);
#if GTK_CHECK_VERSION(3, 0, 0)
	g_object_set(p.remaining, "halign", GTK_ALIGN_START, NULL);
#else
	gtk_misc_set_alignment(GTK_MISC(p.remaining), 0.0, 0.5);
#endif
	gtk_size_group_add_widget(right, p.remaining);
	gtk_box_pack_start(GTK_BOX(hbox), p.remaining, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 4);
	/* progress */
	p.progress = gtk_progress_bar_new();
	p.pulse = 0;
	if(prefs->prefix != NULL)
	{
#if GTK_CHECK_VERSION(3, 0, 0)
		hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#else
		hbox = gtk_hbox_new(FALSE, 0);
#endif
		widget = gtk_label_new(prefs->prefix);
#if GTK_CHECK_VERSION(3, 0, 0)
		g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
#else
		gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
#endif
		gtk_size_group_add_widget(left, widget);
		gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
		gtk_size_group_add_widget(right, p.progress);
		gtk_box_pack_start(GTK_BOX(hbox), p.progress, TRUE, TRUE, 0);
		gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 4);
	}
	else
		gtk_box_pack_start(GTK_BOX(vbox), p.progress, TRUE, TRUE, 4);
	/* cancel */
#if GTK_CHECK_VERSION(3, 0, 0)
	hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#else
	hbox = gtk_hbox_new(FALSE, 0);
#endif
#if GTK_CHECK_VERSION(3, 10, 0)
	widget = gtk_button_new_with_label(_("Cancel"));
	gtk_button_set_image(GTK_BUTTON(widget),
			gtk_image_new_from_icon_name(GTK_STOCK_CANCEL,
				GTK_ICON_SIZE_BUTTON));
#else
	widget = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
#endif
	g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(
				_progress_cancel), NULL);
	gtk_box_pack_end(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
	gtk_container_add(GTK_CONTAINER(p.window), vbox);
	gtk_container_set_border_width(GTK_CONTAINER(p.window), 4);
	gtk_widget_show_all(vbox);
	if((prefs->flags & PREFS_x) == 0)
		/* show the window */
		gtk_widget_show(p.window);
	else
	{
		/* print the window ID and force a flush */
		id = gtk_plug_get_id(GTK_PLUG(p.window));
		printf("%lu\n", id);
		fclose(stdout);
	}
	gtk_main();
	close(p.fd);
	close(p.fds[1]);
	return p.ret;
}
コード例 #20
0
static void
nautilus_file_conflict_dialog_init (NautilusFileConflictDialog *fcd)
{
    GtkWidget *hbox, *vbox, *vbox2, *alignment;
    GtkWidget *widget, *dialog_area;
    NautilusFileConflictDialogDetails *details;
    GtkDialog *dialog;

    details = fcd->details = NAUTILUS_FILE_CONFLICT_DIALOG_GET_PRIVATE (fcd);
    dialog = GTK_DIALOG (fcd);

    /* Setup the main hbox */
    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
    dialog_area = gtk_dialog_get_content_area (dialog);
    gtk_box_pack_start (GTK_BOX (dialog_area), hbox, FALSE, FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);

    /* Setup the dialog image */
    widget = gtk_image_new_from_icon_name ("dialog-warning",
                                           GTK_ICON_SIZE_DIALOG);
    gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
    gtk_misc_set_alignment (GTK_MISC (widget), 0.5, 0.0);

    /* Setup the vbox containing the dialog body */
    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
    gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);

    /* Setup the vbox for the dialog labels */
    widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
    gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
    details->titles_vbox = widget;

    /* Setup the hboxes to pack file infos into */
    alignment = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
    g_object_set (alignment, "left-padding", 12, NULL);
    vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
    gtk_container_add (GTK_CONTAINER (alignment), vbox2);
    gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);

    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
    gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
    details->first_hbox = hbox;

    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
    gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
    details->second_hbox = hbox;

    /* Setup the expander for the rename action */
    details->expander = gtk_expander_new_with_mnemonic (_("_Select a new name for the destination"));
    gtk_box_pack_start (GTK_BOX (vbox2), details->expander, FALSE, FALSE, 0);
    g_signal_connect (details->expander, "activate",
                      G_CALLBACK (expander_activated_cb), dialog);

    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
    gtk_container_add (GTK_CONTAINER (details->expander), hbox);

    widget = gtk_entry_new ();
    gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 6);
    details->entry = widget;
    g_signal_connect (widget, "changed",
                      G_CALLBACK (entry_text_changed_cb), dialog);

    widget = gtk_button_new_with_label (_("Reset"));
    gtk_button_set_image (GTK_BUTTON (widget),
                          gtk_image_new_from_icon_name ("edit-undo",
                                  GTK_ICON_SIZE_MENU));
    gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 6);
    g_signal_connect (widget, "clicked",
                      G_CALLBACK (reset_button_clicked_cb), dialog);

    gtk_widget_show_all (alignment);


    /* Setup the checkbox to apply the action to all files */
    widget = gtk_check_button_new_with_mnemonic (_("Apply this action to all files"));
    gtk_box_pack_start (GTK_BOX (vbox),
                        widget, FALSE, FALSE, 0);
    details->checkbox = widget;
    g_signal_connect (widget, "toggled",
                      G_CALLBACK (checkbox_toggled_cb), dialog);

    /* Add buttons */
    gtk_dialog_add_buttons (dialog,
                            _("_Cancel"),
                            GTK_RESPONSE_CANCEL,
                            _("_Skip"),
                            CONFLICT_RESPONSE_SKIP,
                            NULL);
    details->rename_button =
        gtk_dialog_add_button (dialog,
                               _("Re_name"),
                               CONFLICT_RESPONSE_RENAME);
    gtk_widget_hide (details->rename_button);

    details->replace_button =
        gtk_dialog_add_button (dialog,
                               _("Replace"),
                               CONFLICT_RESPONSE_REPLACE);
    gtk_widget_grab_focus (details->replace_button);

    /* Setup HIG properties */
    gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
    gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (dialog)), 14);
    gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);

    gtk_widget_show_all (dialog_area);
}
コード例 #21
0
/* returns TRUE if a folder window should be opened */
static gboolean
do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAutorunOpenWindow open_window_func, gpointer user_data)
{
    AutorunDialogData *data;
    GtkWidget *dialog;
    GtkWidget *hbox;
    GtkWidget *vbox;
    GtkWidget *label;
    GtkWidget *combo_box;
    GtkWidget *always_check_button;
    GtkWidget *eject_button;
    GtkWidget *image;
    char *markup;
    char *content_description;
    char *mount_name;
    GIcon *icon;
    GdkPixbuf *pixbuf;
    CajaIconInfo *icon_info;
    int icon_size;
    gboolean user_forced_dialog;
    gboolean pref_ask;
    gboolean pref_start_app;
    gboolean pref_ignore;
    gboolean pref_open_folder;
    char *media_greeting;
    gboolean ret;

    ret = FALSE;
    mount_name = NULL;

    if (g_content_type_is_a (x_content_type, "x-content/win32-software"))
    {
        /* don't pop up the dialog anyway if the content type says
         * windows software.
         */
        goto out;
    }

    user_forced_dialog = is_shift_pressed ();

    caja_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder);
    pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;

    if (user_forced_dialog)
    {
        goto show_dialog;
    }

    if (!pref_ask && !pref_ignore && !pref_open_folder)
    {
        GAppInfo *app_info;
        app_info = g_app_info_get_default_for_type (x_content_type, FALSE);
        if (app_info != NULL)
        {
            caja_autorun_launch_for_mount (mount, app_info);
        }
        goto out;
    }

    if (pref_open_folder)
    {
        ret = TRUE;
        goto out;
    }

    if (pref_ignore)
    {
        goto out;
    }

show_dialog:

    mount_name = g_mount_get_name (mount);

    dialog = gtk_dialog_new ();

    hbox = gtk_hbox_new (FALSE, 12);
    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);

    icon = g_mount_get_icon (mount);
    icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG);
    icon_info = caja_icon_info_lookup (icon, icon_size);
    pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
    g_object_unref (icon_info);
    g_object_unref (icon);
    image = gtk_image_new_from_pixbuf (pixbuf);
    gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
    gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0);
    /* also use the icon on the dialog */
    gtk_window_set_title (GTK_WINDOW (dialog), mount_name);
    gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf);
    gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
    g_object_unref (pixbuf);

    vbox = gtk_vbox_new (FALSE, 12);
    gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);

    label = gtk_label_new (NULL);


    /* Customize greeting for well-known x-content types */
    if (strcmp (x_content_type, "x-content/audio-cdda") == 0)
    {
        media_greeting = _("You have just inserted an Audio CD.");
    }
    else if (strcmp (x_content_type, "x-content/audio-dvd") == 0)
    {
        media_greeting = _("You have just inserted an Audio DVD.");
    }
    else if (strcmp (x_content_type, "x-content/video-dvd") == 0)
    {
        media_greeting = _("You have just inserted a Video DVD.");
    }
    else if (strcmp (x_content_type, "x-content/video-vcd") == 0)
    {
        media_greeting = _("You have just inserted a Video CD.");
    }
    else if (strcmp (x_content_type, "x-content/video-svcd") == 0)
    {
        media_greeting = _("You have just inserted a Super Video CD.");
    }
    else if (strcmp (x_content_type, "x-content/blank-cd") == 0)
    {
        media_greeting = _("You have just inserted a blank CD.");
    }
    else if (strcmp (x_content_type, "x-content/blank-dvd") == 0)
    {
        media_greeting = _("You have just inserted a blank DVD.");
    }
    else if (strcmp (x_content_type, "x-content/blank-cd") == 0)
    {
        media_greeting = _("You have just inserted a blank Blu-Ray disc.");
    }
    else if (strcmp (x_content_type, "x-content/blank-cd") == 0)
    {
        media_greeting = _("You have just inserted a blank HD DVD.");
    }
    else if (strcmp (x_content_type, "x-content/image-photocd") == 0)
    {
        media_greeting = _("You have just inserted a Photo CD.");
    }
    else if (strcmp (x_content_type, "x-content/image-picturecd") == 0)
    {
        media_greeting = _("You have just inserted a Picture CD.");
    }
    else if (strcmp (x_content_type, "x-content/image-dcf") == 0)
    {
        media_greeting = _("You have just inserted a medium with digital photos.");
    }
    else if (strcmp (x_content_type, "x-content/audio-player") == 0)
    {
        media_greeting = _("You have just inserted a digital audio player.");
    }
    else if (g_content_type_is_a (x_content_type, "x-content/software"))
    {
        media_greeting = _("You have just inserted a medium with software intended to be automatically started.");
    }
    else
    {
        /* fallback to generic greeting */
        media_greeting = _("You have just inserted a medium.");
    }
    markup = g_strdup_printf ("<big><b>%s %s</b></big>", media_greeting, _("Choose what application to launch."));
    gtk_label_set_markup (GTK_LABEL (label), markup);
    g_free (markup);
    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);

    label = gtk_label_new (NULL);
    content_description = g_content_type_get_description (x_content_type);
    markup = g_strdup_printf (_("Select how to open \"%s\" and whether to perform this action in the future for other media of type \"%s\"."), mount_name, content_description);
    g_free (content_description);
    gtk_label_set_markup (GTK_LABEL (label), markup);
    g_free (markup);
    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);

    data = g_new0 (AutorunDialogData, 1);
    data->dialog = dialog;
    data->mount = g_object_ref (mount);
    data->remember = !pref_ask;
    data->selected_ignore = pref_ignore;
    data->x_content_type = g_strdup (x_content_type);
    data->selected_app = g_app_info_get_default_for_type (x_content_type, FALSE);
    data->open_window_func = open_window_func;
    data->user_data = user_data;

    combo_box = gtk_combo_box_new ();
    caja_autorun_prepare_combo_box (combo_box, x_content_type, FALSE, TRUE, FALSE, autorun_combo_changed, data);
    g_signal_connect (G_OBJECT (combo_box),
                      "key-press-event",
                      G_CALLBACK (combo_box_enter_ok),
                      dialog);

    gtk_box_pack_start (GTK_BOX (vbox), combo_box, TRUE, TRUE, 0);

    always_check_button = gtk_check_button_new_with_mnemonic (_("_Always perform this action"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (always_check_button), data->remember);
    g_signal_connect (G_OBJECT (always_check_button),
                      "toggled",
                      G_CALLBACK (autorun_always_toggled),
                      data);
    gtk_box_pack_start (GTK_BOX (vbox), always_check_button, TRUE, TRUE, 0);

    gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_OK, GTK_RESPONSE_OK,
                            NULL);
    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

    if (g_mount_can_eject (mount))
    {
        GtkWidget *eject_image;
        eject_button = gtk_button_new_with_mnemonic (_("_Eject"));
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           "media-eject",
                                           caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON),
                                           0,
                                           NULL);
        eject_image = gtk_image_new_from_pixbuf (pixbuf);
        g_object_unref (pixbuf);
        gtk_button_set_image (GTK_BUTTON (eject_button), eject_image);
        data->should_eject = TRUE;
    }
    else
    {
        eject_button = gtk_button_new_with_mnemonic (_("_Unmount"));
        data->should_eject = FALSE;
    }
    gtk_dialog_add_action_widget (GTK_DIALOG (dialog), eject_button, AUTORUN_DIALOG_RESPONSE_EJECT);
    gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), eject_button, TRUE);

    /* show the dialog */
    gtk_widget_show_all (dialog);

    g_signal_connect (G_OBJECT (dialog),
                      "response",
                      G_CALLBACK (autorun_dialog_response),
                      data);

    g_signal_connect (G_OBJECT (data->mount),
                      "unmounted",
                      G_CALLBACK (autorun_dialog_mount_unmounted),
                      data);

out:
    g_free (mount_name);
    return ret;
}
コード例 #22
0
ファイル: testwindows.c プロジェクト: nacho/gtk-
int
main (int argc, char **argv)
{
    GtkWidget *window, *vbox, *hbox, *frame;
    GtkWidget *button, *scrolled, *table;
    GtkTreeViewColumn *column;
    GtkCellRenderer *renderer;
    GdkRGBA black = {0,0,0,1};
    GFile *file;

    gtk_init (&argc, &argv);

    main_window = window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 0);

    g_signal_connect (G_OBJECT (window), "delete-event", gtk_main_quit, NULL);

    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
    gtk_container_add (GTK_CONTAINER (window), hbox);
    gtk_widget_show (hbox);

    frame = gtk_frame_new ("GdkWindows");
    gtk_box_pack_start (GTK_BOX (hbox),
                        frame,
                        FALSE, FALSE,
                        5);
    gtk_widget_show (frame);

    darea =  gtk_drawing_area_new ();
    /*gtk_widget_set_double_buffered (darea, FALSE);*/
    gtk_widget_add_events (darea, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
    gtk_widget_set_size_request (darea, 500, 500);
    g_signal_connect (darea, "button_release_event",
                      G_CALLBACK (darea_button_release_event),
                      NULL);


    gtk_container_add (GTK_CONTAINER (frame), darea);
    gtk_widget_realize (darea);
    gtk_widget_show (darea);
    gtk_widget_override_background_color (darea, 0, &black);


    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
    gtk_box_pack_start (GTK_BOX (hbox),
                        vbox,
                        FALSE, FALSE,
                        5);
    gtk_widget_show (vbox);

    window_store = gtk_tree_store_new (1, GDK_TYPE_WINDOW);

    treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (window_store));
    gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
                                 GTK_SELECTION_MULTIPLE);
    column = gtk_tree_view_column_new ();
    gtk_tree_view_column_set_title (column, "Window");
    renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_column_pack_start (column, renderer, TRUE);
    gtk_tree_view_column_set_cell_data_func (column,
            renderer,
            render_window_cell,
            NULL, NULL);

    gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);


    scrolled = gtk_scrolled_window_new (NULL, NULL);
    gtk_widget_set_size_request (scrolled, 200, 400);
    gtk_container_add (GTK_CONTAINER (scrolled), treeview);
    gtk_box_pack_start (GTK_BOX (vbox),
                        scrolled,
                        FALSE, FALSE,
                        5);
    gtk_widget_show (scrolled);
    gtk_widget_show (treeview);

    table = gtk_table_new (5, 4, TRUE);
    gtk_box_pack_start (GTK_BOX (vbox),
                        table,
                        FALSE, FALSE,
                        2);
    gtk_widget_show (table);

    button = gtk_button_new ();
    gtk_button_set_image (GTK_BUTTON (button),
                          gtk_image_new_from_stock (GTK_STOCK_GO_BACK,
                                  GTK_ICON_SIZE_BUTTON));
    g_signal_connect (button, "clicked",
                      G_CALLBACK (move_window_clicked),
                      GINT_TO_POINTER (GTK_DIR_LEFT));
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               0, 1,
                               1, 2);
    gtk_widget_show (button);

    button = gtk_button_new ();
    gtk_button_set_image (GTK_BUTTON (button),
                          gtk_image_new_from_stock (GTK_STOCK_GO_UP,
                                  GTK_ICON_SIZE_BUTTON));
    g_signal_connect (button, "clicked",
                      G_CALLBACK (move_window_clicked),
                      GINT_TO_POINTER (GTK_DIR_UP));
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               1, 2,
                               0, 1);
    gtk_widget_show (button);

    button = gtk_button_new ();
    gtk_button_set_image (GTK_BUTTON (button),
                          gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD,
                                  GTK_ICON_SIZE_BUTTON));
    g_signal_connect (button, "clicked",
                      G_CALLBACK (move_window_clicked),
                      GINT_TO_POINTER (GTK_DIR_RIGHT));
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               2, 3,
                               1, 2);
    gtk_widget_show (button);

    button = gtk_button_new ();
    gtk_button_set_image (GTK_BUTTON (button),
                          gtk_image_new_from_stock (GTK_STOCK_GO_DOWN,
                                  GTK_ICON_SIZE_BUTTON));
    g_signal_connect (button, "clicked",
                      G_CALLBACK (move_window_clicked),
                      GINT_TO_POINTER (GTK_DIR_DOWN));
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               1, 2,
                               2, 3);
    gtk_widget_show (button);


    button = gtk_button_new_with_label ("Raise");
    g_signal_connect (button, "clicked",
                      G_CALLBACK (raise_window_clicked),
                      NULL);
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               0, 1,
                               0, 1);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Lower");
    g_signal_connect (button, "clicked",
                      G_CALLBACK (lower_window_clicked),
                      NULL);
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               0, 1,
                               2, 3);
    gtk_widget_show (button);


    button = gtk_button_new_with_label ("Smaller");
    g_signal_connect (button, "clicked",
                      G_CALLBACK (smaller_window_clicked),
                      NULL);
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               2, 3,
                               0, 1);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Larger");
    g_signal_connect (button, "clicked",
                      G_CALLBACK (larger_window_clicked),
                      NULL);
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               2, 3,
                               2, 3);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Native");
    g_signal_connect (button, "clicked",
                      G_CALLBACK (native_window_clicked),
                      NULL);
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               1, 2,
                               1, 2);
    gtk_widget_show (button);


    button = gtk_button_new_with_label ("scroll");
    gtk_button_set_image (GTK_BUTTON (button),
                          gtk_image_new_from_stock (GTK_STOCK_GO_UP,
                                  GTK_ICON_SIZE_BUTTON));
    g_signal_connect (button, "clicked",
                      G_CALLBACK (scroll_window_clicked),
                      GINT_TO_POINTER (GTK_DIR_UP));
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               3, 4,
                               0, 1);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("scroll");
    gtk_button_set_image (GTK_BUTTON (button),
                          gtk_image_new_from_stock (GTK_STOCK_GO_DOWN,
                                  GTK_ICON_SIZE_BUTTON));
    g_signal_connect (button, "clicked",
                      G_CALLBACK (scroll_window_clicked),
                      GINT_TO_POINTER (GTK_DIR_DOWN));
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               3, 4,
                               1, 2);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Manual");
    g_signal_connect (button, "clicked",
                      G_CALLBACK (manual_clicked),
                      NULL);
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               3, 4,
                               2, 3);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Restack above");
    g_signal_connect (button, "clicked",
                      G_CALLBACK (restack_clicked),
                      GINT_TO_POINTER (1));
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               2, 3,
                               3, 4);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Restack below");
    g_signal_connect (button, "clicked",
                      G_CALLBACK (restack_clicked),
                      0);
    gtk_table_attach_defaults (GTK_TABLE (table),
                               button,
                               3, 4,
                               3, 4);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Add window");
    gtk_box_pack_start (GTK_BOX (vbox),
                        button,
                        FALSE, FALSE,
                        2);
    gtk_widget_show (button);
    g_signal_connect (button, "clicked",
                      G_CALLBACK (add_window_clicked),
                      NULL);

    button = gtk_button_new_with_label ("Remove window");
    gtk_box_pack_start (GTK_BOX (vbox),
                        button,
                        FALSE, FALSE,
                        2);
    gtk_widget_show (button);
    g_signal_connect (button, "clicked",
                      G_CALLBACK (remove_window_clicked),
                      NULL);

    button = gtk_button_new_with_label ("Save");
    gtk_box_pack_start (GTK_BOX (vbox),
                        button,
                        FALSE, FALSE,
                        2);
    gtk_widget_show (button);
    g_signal_connect (button, "clicked",
                      G_CALLBACK (save_clicked),
                      NULL);

    gtk_widget_show (window);

    if (argc == 2)
    {
        file = g_file_new_for_commandline_arg (argv[1]);
        load_file (file);
        g_object_unref (file);
    }

    gtk_main ();

    return 0;
}
コード例 #23
0
static GObject *
gdict_database_chooser_constructor (GType                  type,
				    guint                  n_params,
				    GObjectConstructParam *params)
{
  GObjectClass *parent_class;
  GObject *object;
  GdictDatabaseChooser *chooser;
  GdictDatabaseChooserPrivate *priv;
  GtkWidget *sw;
  GtkCellRenderer *renderer;
  GtkTreeViewColumn *column;
  GtkWidget *hbox;

  parent_class = G_OBJECT_CLASS (gdict_database_chooser_parent_class);
  object = parent_class->constructor (type, n_params, params);

  chooser = GDICT_DATABASE_CHOOSER (object);
  priv = chooser->priv;

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_set_vexpand (sw, TRUE);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
		  		  GTK_POLICY_AUTOMATIC,
				  GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
		  		       GTK_SHADOW_IN);
  gtk_box_pack_start (GTK_BOX (chooser), sw, TRUE, TRUE, 0);
  gtk_widget_show (sw);

  renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes ("databases",
		  				     renderer,
						     "text", DB_COLUMN_DESCRIPTION,
                                                     "weight", DB_COLUMN_CURRENT,
						     NULL);
  priv->treeview = gtk_tree_view_new ();
  gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
		  	   GTK_TREE_MODEL (priv->store));
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->treeview), FALSE);
  gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview), column);
  g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)),
                    "changed", G_CALLBACK (selection_changed_cb),
                    chooser);
  g_signal_connect (priv->treeview, "row-activated",
		    G_CALLBACK (row_activated_cb), chooser);
  gtk_container_add (GTK_CONTAINER (sw), priv->treeview);
  gtk_widget_show (priv->treeview);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  priv->buttons_box = hbox;

  priv->refresh_button = gtk_button_new ();
  gtk_button_set_image (GTK_BUTTON (priv->refresh_button),
                        gtk_image_new_from_icon_name ("view-refresh",
                                                      GTK_ICON_SIZE_SMALL_TOOLBAR));
  g_signal_connect (priv->refresh_button, "clicked",
		    G_CALLBACK (refresh_button_clicked_cb),
		    chooser);
  gtk_box_pack_start (GTK_BOX (hbox), priv->refresh_button, FALSE, FALSE, 0);
  gtk_widget_show (priv->refresh_button);
  gtk_widget_set_tooltip_text (priv->refresh_button,
                               _("Reload the list of available databases"));

  priv->clear_button = gtk_button_new ();
  gtk_button_set_image (GTK_BUTTON (priv->clear_button),
                        gtk_image_new_from_icon_name ("edit-clear",
                                                      GTK_ICON_SIZE_SMALL_TOOLBAR));
  g_signal_connect (priv->clear_button, "clicked",
		    G_CALLBACK (clear_button_clicked_cb),
		    chooser);
  gtk_box_pack_start (GTK_BOX (hbox), priv->clear_button, FALSE, FALSE, 0);
  gtk_widget_show (priv->clear_button);
  gtk_widget_set_tooltip_text (priv->clear_button,
                               _("Clear the list of available databases"));

  gtk_box_pack_end (GTK_BOX (chooser), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  return object;
}
コード例 #24
0
ファイル: new_person.c プロジェクト: mthli/COIMS
void new_person(GtkWidget *widget, Item *parents)
{
    /* 仅仅是把当前person_notebook界面的内容清空,
     * 并且把“在院病人列表”设置为没有选项被选择即可,
     * 不需要对数据库进行更改。
     */

    FILE *fp;
    /* 移除照片 */
    gtk_button_set_image(
            GTK_BUTTON((*parents).photo_button),
            NULL
            );
    remove("photo_path.txt");
    fp = fopen("photo_path.txt", "w+");
    fclose(fp);
    gtk_widget_show((*parents).photo_button);
    /* 移除姓名 */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).name_entry),
            ""
            );
    gtk_widget_show((*parents).name_entry);
    /* 设置“性别”下拉菜单为空 */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).sex_combo),
            -1
            );
    gtk_widget_show((*parents).sex_combo);
    /* “生日”按钮 */
    gtk_button_set_label(
            GTK_BUTTON((*parents).birthday_button),
            "选择日期"
            );
    gtk_widget_show((*parents).birthday_button);
    /* “年龄”输入框 */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).age_entry),
            ""
            );
    gtk_widget_show((*parents).age_entry);
    /* “婚姻” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).marriage_combo),
            -1
            );
    gtk_widget_show((*parents).marriage_combo);
    /* “教育” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).edu_combo),
            -1
            );
    gtk_widget_show((*parents).edu_combo);
    /* “身份证” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).id_entry),
            ""
            );
    gtk_widget_show((*parents).id_entry);
    /* “户籍” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).census_entry),
            ""
            );
    gtk_widget_show((*parents).census_entry);
    /* “发生时间” */
    gtk_button_set_label(
            GTK_BUTTON((*parents).happened_button),
            "选择日期"
            );
    gtk_widget_show((*parents).happened_button);
    /* “发生地点” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).place_combo),
            -1
            );
    gtk_widget_show((*parents).place_combo);
    /* “三联单” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).bill_entry),
            ""
            );
    gtk_widget_show((*parents).bill_entry);
    /* “住院号” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).num_entry),
            ""
            );
    gtk_widget_show((*parents).num_entry);
    /* “入院时间” */
    gtk_button_set_label(
            GTK_BUTTON((*parents).into_button),
            "选择日期"
            );
    gtk_widget_show((*parents).into_button);
    /* “入院评分” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).inps_entry),
            ""
            );
    gtk_widget_show((*parents).inps_entry);
    /* “出院时间” */
    gtk_button_set_label(
            GTK_BUTTON((*parents).out_button),
            "选择日期"
            );
    gtk_widget_show((*parents).out_button);
    /* “出院评分” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).outps_entry),
            ""
            );
    gtk_widget_show((*parents).outps_entry);
    /* “住院天数” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).days_entry),
            ""
            );
    gtk_widget_show((*parents).days_entry);
    /* “减分率” */
    gtk_button_set_label(
            GTK_BUTTON((*parents).persent_button),
            "计算"
            );
    gtk_widget_show((*parents).persent_button);
    /* “花费” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).cost_entry),
            ""
            );
    gtk_widget_show((*parents).cost_entry);
    /* “患者去向” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).goto_combo),
            -1
            );
    gtk_widget_show((*parents).goto_combo);
    /* “行为分级” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).level_combo),
            -1
            );
    gtk_widget_show((*parents).level_combo);
    /* “患者症状” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).symptom_combo),
            -1
            );
    gtk_widget_show((*parents).symptom_combo);
    /* “患者状态” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).status_combo),
            -1
            );
    gtk_widget_show((*parents).status_combo);
    /* “抗精神病药物” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).psy_combo),
            -1
            );
    gtk_widget_show((*parents).psy_combo);
    /* “抗抑郁药物” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).dep_combo),
            -1
            );
    gtk_widget_show((*parents).dep_combo);
    /* “抗焦虑药物” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).anxiety_combo),
            -1
            );
    gtk_widget_show((*parents).anxiety_combo);
    /* “心境稳定剂” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).heart_combo),
            -1
            );
    gtk_widget_show((*parents).heart_combo);
    /* “物质依赖” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).addicted_combo),
            -1
            );
    gtk_widget_show((*parents).addicted_combo);
    /* “是否吸毒” */
    gtk_combo_box_set_active(
            GTK_COMBO_BOX((*parents).drug_combo),
            -1
            );
    gtk_widget_show((*parents).drug_combo);
    /* “躯体疾病” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).body_entry),
            ""
            );
    gtk_widget_show((*parents).body_entry);
    /* “传染病” */
    gtk_entry_set_text(
            GTK_ENTRY((*parents).infect_entry),
            ""
            );
    gtk_widget_show((*parents).infect_entry);
    /* “确认出院” */
    gtk_toggle_button_set_active(
            GTK_TOGGLE_BUTTON((*parents).out_check),
            FALSE
            );

    /* 对于clist的处理 */
    (*parents).get_row = -1;
    (*parents).get_column = -1;
    gtk_clist_unselect_all(GTK_CLIST((*parents).hospital_list));
}
コード例 #25
0
static void
inf_gtk_certificate_manager_certificate_func(InfXmppConnection* connection,
                                             gnutls_session_t session,
                                             InfCertificateChain* chain,
                                             gpointer user_data)
{
  InfGtkCertificateManager* manager;
  InfGtkCertificateManagerPrivate* priv;

  InfGtkCertificateDialogFlags flags;
  gnutls_x509_crt_t presented_cert;
  gnutls_x509_crt_t known_cert;
  gchar* hostname;

  gboolean match_hostname;
  gboolean issuer_known;
  gnutls_x509_crt_t root_cert;

  int ret;
  unsigned int verify;
  GHashTable* table;
  gboolean cert_equal;
  time_t expiration_time;

  InfGtkCertificateManagerQuery* query;
  gchar* text;
  GtkWidget* vbox;
  GtkWidget* button;
  GtkWidget* image;
  GtkWidget* label;

  GError* error;

  manager = INF_GTK_CERTIFICATE_MANAGER(user_data);
  priv = INF_GTK_CERTIFICATE_MANAGER_PRIVATE(manager);

  g_object_get(G_OBJECT(connection), "remote-hostname", &hostname, NULL);
  presented_cert = inf_certificate_chain_get_own_certificate(chain);

  match_hostname = gnutls_x509_crt_check_hostname(presented_cert, hostname);

  /* First, validate the certificate */
  ret = gnutls_certificate_verify_peers2(session, &verify);
  error = NULL;

  if(ret != GNUTLS_E_SUCCESS)
    inf_gnutls_set_error(&error, ret);

  /* Remove the GNUTLS_CERT_ISSUER_NOT_KNOWN flag from the verification
   * result, and if the certificate is still invalid, then set an error. */
  if(error == NULL)
  {
    issuer_known = TRUE;
    if(verify & GNUTLS_CERT_SIGNER_NOT_FOUND)
    {
      issuer_known = FALSE;

      /* Re-validate the certificate for other failure reasons --
       * unfortunately the gnutls_certificate_verify_peers2() call
       * does not tell us whether the certificate is otherwise invalid
       * if a signer is not found already. */
      /* TODO: Here it would be good to use the verify flags from the
       * certificate credentials, but GnuTLS does not have API to
       * retrieve them. */
      root_cert = inf_certificate_chain_get_root_certificate(chain);

      ret = gnutls_x509_crt_list_verify(
        inf_certificate_chain_get_raw(chain),
        inf_certificate_chain_get_n_certificates(chain),
        &root_cert,
        1,
        NULL,
        0,
        GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT,
        &verify
      );

      if(ret != GNUTLS_E_SUCCESS)
        inf_gnutls_set_error(&error, ret);
      else if(verify & GNUTLS_CERT_INVALID)
        inf_gnutls_certificate_verification_set_error(&error, verify);
    }
  }

  /* Look up the host in our database of pinned certificates if we could not
   * fully verify the certificate, i.e. if either the issuer is not known or
   * the hostname of the connection does not match the certificate. */
  table = NULL;
  if(error == NULL)
  {
    known_cert = NULL;
    if(!match_hostname || !issuer_known)
    {
      /* If we cannot load the known host file, then cancel the connection.
       * Otherwise it might happen that someone shows us a certificate that we
       * tell the user we don't know, if though actually for that host we expect
       * a different certificate. */
      table = inf_gtk_certificate_manager_ref_known_hosts(manager, &error);
      if(table != NULL)
        known_cert = g_hash_table_lookup(table, hostname);
    }
  }

  /* Next, configure the flags for the dialog to be shown based on the
   * verification result, and on whether the pinned certificate matches
   * the one presented by the host or not. */
  flags = 0;
  if(error == NULL)
  {
    if(known_cert != NULL)
    {
      cert_equal = inf_gtk_certificate_manager_compare_fingerprint(
        known_cert,
        presented_cert,
        &error
      );

      if(error == NULL && cert_equal == FALSE)
      {
        if(!match_hostname)
          flags |= INF_GTK_CERTIFICATE_DIALOG_CERT_HOSTNAME_MISMATCH;
        if(!issuer_known)
          flags |= INF_GTK_CERTIFICATE_DIALOG_CERT_ISSUER_NOT_KNOWN;

        flags |= INF_GTK_CERTIFICATE_DIALOG_CERT_UNEXPECTED;
        expiration_time = gnutls_x509_crt_get_expiration_time(known_cert);
        if(expiration_time != (time_t)(-1))
        {
          expiration_time -= INF_GTK_CERTIFICATE_MANAGER_EXPIRATION_TOLERANCE;
          if(time(NULL) > expiration_time)
          {
            flags |= INF_GTK_CERTIFICATE_DIALOG_CERT_OLD_EXPIRED;
          }
        }
      }
    }
    else
    {
      if(!match_hostname)
        flags |= INF_GTK_CERTIFICATE_DIALOG_CERT_HOSTNAME_MISMATCH;
      if(!issuer_known)
        flags |= INF_GTK_CERTIFICATE_DIALOG_CERT_ISSUER_NOT_KNOWN;
    }
  }

  /* Now proceed either by accepting the connection, rejecting it, or
   * bothering the user with an annoying dialog. */
  if(error == NULL)
  {
    if(flags == 0)
    {
      if(match_hostname && issuer_known)
      {
        /* Remove the pinned entry if we now have a valid certificate for
         * this host. */
        if(table != NULL && g_hash_table_remove(table, hostname) == TRUE)
        {
          inf_gtk_certificate_manager_write_known_hosts_with_warning(
            manager,
            table
          );
        }
      }

      inf_xmpp_connection_certificate_verify_continue(connection);
    }
    else
    {
      query = g_slice_new(InfGtkCertificateManagerQuery);
      query->manager = manager;
      query->known_hosts = table;
      query->connection = connection;
      query->dialog = inf_gtk_certificate_dialog_new(
        priv->parent_window,
        0,
        flags,
        hostname,
        chain
      );
      query->certificate_chain = chain;

      table = NULL;

      g_object_ref(query->connection);
      inf_certificate_chain_ref(chain);

      g_signal_connect(
        G_OBJECT(connection),
        "notify::status",
        G_CALLBACK(inf_gtk_certificate_manager_notify_status_cb),
        query
      );

      g_signal_connect(
        G_OBJECT(query->dialog),
        "response",
        G_CALLBACK(inf_gtk_certificate_manager_response_cb),
        query
      );

      image = gtk_image_new_from_stock(GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
      gtk_widget_show(image);

      button = gtk_dialog_add_button(
        GTK_DIALOG(query->dialog),
        _("_Cancel connection"),
        GTK_RESPONSE_REJECT
      );

      gtk_button_set_image(GTK_BUTTON(button), image);

      image = gtk_image_new_from_stock(GTK_STOCK_CONNECT, GTK_ICON_SIZE_BUTTON);
      gtk_widget_show(image);

      button = gtk_dialog_add_button(
        GTK_DIALOG(query->dialog),
        _("C_ontinue connection"),
        GTK_RESPONSE_ACCEPT
      );

      gtk_button_set_image(GTK_BUTTON(button), image);

      text = g_strdup_printf(
        _("Do you want to continue the connection to host \"%s\"? If you "
          "choose to continue, this certificate will be trusted in the "
          "future when connecting to this host."),
        hostname
      );

      label = gtk_label_new(text);
      gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
      gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
      gtk_label_set_width_chars(GTK_LABEL(label), 60);
      gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
      gtk_widget_show(label);
      g_free(text);

      vbox = gtk_dialog_get_content_area(GTK_DIALOG(query->dialog));
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);

      priv->queries = g_slist_prepend(priv->queries, query);
      gtk_window_present(GTK_WINDOW(query->dialog));
    }
  }
  else
  {
    inf_xmpp_connection_certificate_verify_cancel(connection, error);
    g_error_free(error);
  }

  if(table != NULL) g_hash_table_unref(table);
  g_free(hostname);
}
コード例 #26
0
static void mateweather_pref_create(MateWeatherPref* pref)
{
	GtkWidget* pref_vbox;
	GtkWidget* pref_notebook;
	#ifdef RADARMAP
		GtkWidget* radar_toggle_hbox;
	#endif /* RADARMAP */
	GtkWidget* pref_basic_update_alignment;
	GtkWidget* pref_basic_update_lbl;
	GtkWidget* pref_basic_update_hbox;
	GtkObject* pref_basic_update_spin_adj;
	GtkWidget* pref_basic_update_sec_lbl;
	GtkWidget* pref_basic_note_lbl;
	GtkWidget* pref_loc_hbox;
	GtkWidget* pref_loc_note_lbl;
	GtkWidget* scrolled_window;
	GtkWidget* label;
	GtkWidget* value_hbox;
	GtkWidget* tree_label;
	GtkTreeSelection *selection;
	GtkWidget* pref_basic_vbox;
	GtkWidget* vbox;
	GtkWidget* frame;
	GtkWidget* temp_label;
	GtkWidget* temp_combo;
	GtkWidget* speed_label;
	GtkWidget* speed_combo;
	GtkWidget* pres_label;
	GtkWidget* pres_combo;
	GtkWidget* dist_label;
	GtkWidget* dist_combo;
	GtkWidget* unit_table;
	GtkWidget* pref_find_label;
	GtkWidget* pref_find_hbox;
	GtkWidget* image;


	g_object_set (pref, "destroy-with-parent", TRUE, NULL);
	gtk_window_set_title (GTK_WINDOW (pref), _("Weather Preferences"));
	gtk_dialog_add_buttons (GTK_DIALOG (pref), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, GTK_STOCK_HELP, GTK_RESPONSE_HELP, NULL);
	gtk_dialog_set_default_response (GTK_DIALOG (pref), GTK_RESPONSE_CLOSE);
	gtk_dialog_set_has_separator (GTK_DIALOG (pref), FALSE);
	gtk_container_set_border_width (GTK_CONTAINER (pref), 5);
	gtk_window_set_resizable (GTK_WINDOW (pref), TRUE);
	gtk_window_set_screen (GTK_WINDOW (pref), gtk_widget_get_screen (GTK_WIDGET (pref->priv->applet->applet)));

	pref_vbox = gtk_dialog_get_content_area (GTK_DIALOG (pref));
	gtk_box_set_spacing (GTK_BOX (pref_vbox), 2);
	gtk_widget_show (pref_vbox);

	pref_notebook = gtk_notebook_new ();
	gtk_container_set_border_width (GTK_CONTAINER (pref_notebook), 5);
	gtk_widget_show (pref_notebook);
	gtk_box_pack_start (GTK_BOX (pref_vbox), pref_notebook, TRUE, TRUE, 0);

  /*
   * General settings page.
   */

	pref_basic_vbox = gtk_vbox_new (FALSE, 18);
	gtk_container_set_border_width (GTK_CONTAINER (pref_basic_vbox), 12);
	gtk_container_add (GTK_CONTAINER (pref_notebook), pref_basic_vbox);

	pref_basic_update_alignment = gtk_alignment_new (0, 0.5, 0, 1);
	gtk_widget_show (pref_basic_update_alignment);

	pref->priv->basic_update_btn = gtk_check_button_new_with_mnemonic (_("_Automatically update every:"));
	gtk_widget_show (pref->priv->basic_update_btn);
	gtk_container_add (GTK_CONTAINER (pref_basic_update_alignment), pref->priv->basic_update_btn);
	g_signal_connect (G_OBJECT (pref->priv->basic_update_btn), "toggled", G_CALLBACK (auto_update_toggled), pref);

	if (!g_settings_is_writable (pref->priv->applet->settings, "auto-update"))
	{
		hard_set_sensitive (pref->priv->basic_update_btn, FALSE);
	}

	/*
	 * Units settings page.
	 */

	/* Temperature Unit */
	temp_label = gtk_label_new_with_mnemonic (_("_Temperature unit:"));
	gtk_label_set_use_markup (GTK_LABEL (temp_label), TRUE);
	gtk_label_set_justify (GTK_LABEL (temp_label), GTK_JUSTIFY_LEFT);
	gtk_misc_set_alignment (GTK_MISC (temp_label), 0, 0.5);
	gtk_widget_show (temp_label);

	temp_combo = gtk_combo_box_new_text ();
	pref->priv->basic_temp_combo = temp_combo;
	gtk_label_set_mnemonic_widget (GTK_LABEL (temp_label), temp_combo);
	//gtk_combo_box_append_text (GTK_COMBO_BOX (temp_combo), _("Default"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (temp_combo), _("Kelvin"));
	/* TRANSLATORS: Celsius is sometimes referred Centigrade */
	gtk_combo_box_append_text (GTK_COMBO_BOX (temp_combo), _("Celsius"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (temp_combo), _("Fahrenheit"));
	gtk_widget_show (temp_combo);

	if ( ! g_settings_is_writable (pref->priv->applet->settings, "temperature-unit"))
	{
		hard_set_sensitive (pref->priv->basic_temp_combo, FALSE);
	}

	/* Speed Unit */
	speed_label = gtk_label_new_with_mnemonic (_("_Wind speed unit:"));
	gtk_label_set_use_markup (GTK_LABEL (speed_label), TRUE);
	gtk_label_set_justify (GTK_LABEL (speed_label), GTK_JUSTIFY_LEFT);
	gtk_misc_set_alignment (GTK_MISC (speed_label), 0, 0.5);
	gtk_widget_show (speed_label);

	speed_combo = gtk_combo_box_new_text ();
	pref->priv->basic_speed_combo = speed_combo;
	gtk_label_set_mnemonic_widget (GTK_LABEL (speed_label), speed_combo);
	//gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("Default"));
	/* TRANSLATOR: The wind speed unit "meters per second" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("m/s"));
	/* TRANSLATOR: The wind speed unit "kilometers per hour" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("km/h"));
	/* TRANSLATOR: The wind speed unit "miles per hour" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("mph"));
	/* TRANSLATOR: The wind speed unit "knots" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("knots"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("Beaufort scale"));
	gtk_widget_show (speed_combo);

	if (!g_settings_is_writable (pref->priv->applet->settings, "speed-unit"))
	{
		hard_set_sensitive (pref->priv->basic_speed_combo, FALSE);
	}

	/* Pressure Unit */
	pres_label = gtk_label_new_with_mnemonic (_("_Pressure unit:"));
	gtk_label_set_use_markup (GTK_LABEL (pres_label), TRUE);
	gtk_label_set_justify (GTK_LABEL (pres_label), GTK_JUSTIFY_LEFT);
	gtk_misc_set_alignment (GTK_MISC (pres_label), 0, 0.5);
	gtk_widget_show (pres_label);

	pres_combo = gtk_combo_box_new_text ();
	pref->priv->basic_pres_combo = pres_combo;
	gtk_label_set_mnemonic_widget (GTK_LABEL (pres_label), pres_combo);
	//gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("Default"));
	/* TRANSLATOR: The pressure unit "kiloPascals" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("kPa"));
	/* TRANSLATOR: The pressure unit "hectoPascals" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("hPa"));
	/* TRANSLATOR: The pressure unit "millibars" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("mb"));
	/* TRANSLATOR: The pressure unit "millibars of mercury" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("mmHg"));
	/* TRANSLATOR: The pressure unit "inches of mercury" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("inHg"));
	/* TRANSLATOR: The pressure unit "atmospheres" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("atm"));
	gtk_widget_show (pres_combo);

	if (!g_settings_is_writable(pref->priv->applet->settings, "pressure-unit"))
	{
		hard_set_sensitive(pref->priv->basic_pres_combo, FALSE);
	}

	/* Distance Unit */
	dist_label = gtk_label_new_with_mnemonic (_("_Visibility unit:"));
	gtk_label_set_use_markup (GTK_LABEL (dist_label), TRUE);
	gtk_label_set_justify (GTK_LABEL (dist_label), GTK_JUSTIFY_LEFT);
	gtk_misc_set_alignment (GTK_MISC (dist_label), 0, 0.5);
	gtk_widget_show (dist_label);

	dist_combo = gtk_combo_box_new_text ();
	pref->priv->basic_dist_combo = dist_combo;
	gtk_label_set_mnemonic_widget (GTK_LABEL (dist_label), dist_combo);
	//gtk_combo_box_append_text (GTK_COMBO_BOX (dist_combo), _("Default"));
	/* TRANSLATOR: The distance unit "meters" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (dist_combo), _("meters"));
	/* TRANSLATOR: The distance unit "kilometers" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (dist_combo), _("km"));
	/* TRANSLATOR: The distance unit "miles" */
	gtk_combo_box_append_text (GTK_COMBO_BOX (dist_combo), _("miles"));
	gtk_widget_show (dist_combo);

	if ( ! g_settings_is_writable (pref->priv->applet->settings, "distance-unit"))
		hard_set_sensitive (pref->priv->basic_dist_combo, FALSE);

	unit_table = gtk_table_new(5, 2, FALSE);
	gtk_table_set_row_spacings(GTK_TABLE(unit_table), 6);
	gtk_table_set_col_spacings(GTK_TABLE(unit_table), 12);
	gtk_table_attach(GTK_TABLE(unit_table), temp_label, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
	gtk_table_attach_defaults(GTK_TABLE(unit_table), temp_combo,  1, 2, 0, 1);
	gtk_table_attach(GTK_TABLE(unit_table), speed_label, 0, 1, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
	gtk_table_attach_defaults(GTK_TABLE(unit_table), speed_combo, 1, 2, 1, 2);
	gtk_table_attach(GTK_TABLE(unit_table), pres_label, 0, 1, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
	gtk_table_attach_defaults(GTK_TABLE(unit_table), pres_combo,  1, 2, 2, 3);
	gtk_table_attach(GTK_TABLE(unit_table), dist_label, 0, 1, 3, 4, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
	gtk_table_attach_defaults(GTK_TABLE(unit_table), dist_combo,  1, 2, 3, 4);
	gtk_widget_show(unit_table);

	g_signal_connect (temp_combo, "changed", G_CALLBACK (temp_combo_changed_cb), pref);
	g_signal_connect (speed_combo, "changed", G_CALLBACK (speed_combo_changed_cb), pref);
	g_signal_connect (dist_combo, "changed", G_CALLBACK (dist_combo_changed_cb), pref);
	g_signal_connect (pres_combo, "changed", G_CALLBACK (pres_combo_changed_cb), pref);


	#ifdef RADARMAP
		pref->priv->basic_radar_btn = gtk_check_button_new_with_mnemonic (_("Enable _radar map"));
		gtk_widget_show (pref->priv->basic_radar_btn);
		g_signal_connect (G_OBJECT (pref->priv->basic_radar_btn), "toggled", G_CALLBACK (radar_toggled), pref);

		if (!g_settings_is_writable (pref->priv->applet->settings, "enable-radar-map"))
		{
			hard_set_sensitive(pref->priv->basic_radar_btn, FALSE);
		}

		radar_toggle_hbox = gtk_hbox_new(FALSE, 12);
		gtk_widget_show(radar_toggle_hbox);

		label = gtk_label_new ("    ");
		gtk_widget_show (label);
		gtk_box_pack_start (GTK_BOX (radar_toggle_hbox), label, FALSE, FALSE, 0);

		pref->priv->basic_radar_url_btn = gtk_check_button_new_with_mnemonic (_("Use _custom address for radar map"));
		gtk_widget_show (pref->priv->basic_radar_url_btn);
		gtk_box_pack_start (GTK_BOX (radar_toggle_hbox), pref->priv->basic_radar_url_btn, FALSE, FALSE, 0);

		g_signal_connect (G_OBJECT (pref->priv->basic_radar_url_btn), "toggled", G_CALLBACK (use_radar_url_toggled), pref);

		if ( ! g_settings_is_writable (pref->priv->applet->settings, "use-custom-radar-url"))
		{
			hard_set_sensitive (pref->priv->basic_radar_url_btn, FALSE);
		}

		pref->priv->basic_radar_url_hbox = gtk_hbox_new (FALSE, 12);
		gtk_widget_show (pref->priv->basic_radar_url_hbox);

		label = gtk_label_new ("    ");
		gtk_widget_show (label);
		gtk_box_pack_start (GTK_BOX (pref->priv->basic_radar_url_hbox), label, FALSE, FALSE, 0);

		label = gtk_label_new_with_mnemonic (_("A_ddress:"));
		gtk_widget_show (label);
		gtk_box_pack_start (GTK_BOX (pref->priv->basic_radar_url_hbox), label, FALSE, FALSE, 0);
		pref->priv->basic_radar_url_entry = gtk_entry_new ();
		gtk_widget_show (pref->priv->basic_radar_url_entry);
		gtk_box_pack_start (GTK_BOX (pref->priv->basic_radar_url_hbox), pref->priv->basic_radar_url_entry, TRUE, TRUE, 0);
		g_signal_connect (G_OBJECT (pref->priv->basic_radar_url_entry), "focus_out_event", G_CALLBACK (radar_url_changed), pref);
		if ( ! g_settings_is_writable (pref->priv->applet->settings, "radar"))
		{
			hard_set_sensitive (pref->priv->basic_radar_url_entry, FALSE);
		}
	#endif /* RADARMAP */

    #ifdef HAVE_LIBNOTIFY
		/* setup show-notifications button */
		pref->priv->basic_show_notifications_btn = gtk_check_button_new_with_mnemonic (_("Show _notifications"));

		if (!g_settings_is_writable (pref->priv->applet->settings, "show-notifications"))
		{
			hard_set_sensitive (pref->priv->basic_show_notifications_btn, FALSE);
		}

		g_signal_connect (G_OBJECT (pref->priv->basic_show_notifications_btn), "toggled", G_CALLBACK (show_notifications_toggled), pref);
    #endif

	frame = create_hig_catagory (pref_basic_vbox, _("Update"));

	pref_basic_update_hbox = gtk_hbox_new (FALSE, 12);

	pref_basic_update_lbl = gtk_label_new_with_mnemonic (_("_Automatically update every:"));
	gtk_widget_show (pref_basic_update_lbl);


/*
	gtk_label_set_justify (GTK_LABEL (pref_basic_update_lbl), GTK_JUSTIFY_RIGHT);
	gtk_misc_set_alignment (GTK_MISC (pref_basic_update_lbl), 1, 0.5);
*/

	gtk_widget_show (pref_basic_update_hbox);

	pref_basic_update_spin_adj = gtk_adjustment_new (30, 1, 3600, 5, 25, 1);
	pref->priv->basic_update_spin = gtk_spin_button_new (GTK_ADJUSTMENT (pref_basic_update_spin_adj), 1, 0);
	gtk_widget_show (pref->priv->basic_update_spin);

	gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (pref->priv->basic_update_spin), TRUE);
	gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (pref->priv->basic_update_spin), GTK_UPDATE_IF_VALID);
	g_signal_connect (G_OBJECT (pref->priv->basic_update_spin), "value_changed", G_CALLBACK (update_interval_changed), pref);

	pref_basic_update_sec_lbl = gtk_label_new (_("minutes"));
	gtk_widget_show (pref_basic_update_sec_lbl);

	if ( ! g_settings_is_writable (pref->priv->applet->settings, "auto-update-interval"))
	{
		hard_set_sensitive (pref->priv->basic_update_spin, FALSE);
		hard_set_sensitive (pref_basic_update_sec_lbl, FALSE);
	}

	value_hbox = gtk_hbox_new (FALSE, 6);

	gtk_box_pack_start (GTK_BOX (pref_basic_update_hbox), pref_basic_update_alignment, FALSE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (pref_basic_update_hbox), value_hbox, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (value_hbox), pref->priv->basic_update_spin, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (value_hbox), pref_basic_update_sec_lbl, FALSE, FALSE, 0);

	gtk_container_add (GTK_CONTAINER (frame), pref_basic_update_hbox);

	frame = create_hig_catagory (pref_basic_vbox, _("Display"));

	vbox = gtk_vbox_new (FALSE, 6);

	gtk_box_pack_start (GTK_BOX (vbox), unit_table, TRUE, TRUE, 0);

	#ifdef RADARMAP
		gtk_box_pack_start (GTK_BOX (vbox), pref->priv->basic_radar_btn, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (vbox), radar_toggle_hbox, TRUE, TRUE, 0);
		gtk_box_pack_start (GTK_BOX (vbox), pref->priv->basic_radar_url_hbox, TRUE, TRUE, 0);
	#endif /* RADARMAP */
	
	#ifdef HAVE_LIBNOTIFY
		/* add the show-notification toggle button to the vbox of the display section */
		gtk_box_pack_start (GTK_BOX (vbox), pref->priv->basic_show_notifications_btn, TRUE, TRUE, 0);
	#endif

	gtk_container_add (GTK_CONTAINER (frame), vbox);

	pref_basic_note_lbl = gtk_label_new (_("General"));
	gtk_widget_show (pref_basic_note_lbl);
	gtk_notebook_set_tab_label (GTK_NOTEBOOK (pref_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (pref_notebook), 0), pref_basic_note_lbl);

  /*
   * Location page.
   */
	pref_loc_hbox = gtk_vbox_new (FALSE, 6);
	gtk_container_set_border_width (GTK_CONTAINER (pref_loc_hbox), 12);
	gtk_container_add (GTK_CONTAINER (pref_notebook), pref_loc_hbox);

	tree_label = gtk_label_new_with_mnemonic (_("_Select a location:"));
	gtk_misc_set_alignment (GTK_MISC (tree_label), 0.0, 0.5);
	gtk_box_pack_start (GTK_BOX (pref_loc_hbox), tree_label, FALSE, FALSE, 0);

	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	pref->priv->tree = gtk_tree_view_new ();
	gtk_label_set_mnemonic_widget (GTK_LABEL (tree_label), GTK_WIDGET (pref->priv->tree));
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (pref->priv->tree), FALSE);

	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pref->priv->tree));
	g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (row_selected_cb), pref);

	gtk_container_add (GTK_CONTAINER (scrolled_window), pref->priv->tree);
	gtk_widget_show (pref->priv->tree);
	gtk_widget_show (scrolled_window);
	gtk_box_pack_start (GTK_BOX (pref_loc_hbox), scrolled_window, TRUE, TRUE, 0);
	load_locations(pref);

	pref_find_hbox = gtk_hbox_new (FALSE, 6);
	pref_find_label = gtk_label_new (_("_Find:"));
	gtk_label_set_use_underline (GTK_LABEL (pref_find_label), TRUE);

	pref->priv->find_entry = gtk_entry_new ();
	gtk_label_set_mnemonic_widget (GTK_LABEL (pref_find_label), pref->priv->find_entry);

	pref->priv->find_next_btn = gtk_button_new_with_mnemonic (_("Find _Next"));
	gtk_widget_set_sensitive (pref->priv->find_next_btn, FALSE);

	image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_BUTTON);
	gtk_button_set_image (GTK_BUTTON (pref->priv->find_next_btn), image);

	g_signal_connect (G_OBJECT (pref->priv->find_next_btn), "clicked", G_CALLBACK (find_next_clicked), pref);
	g_signal_connect (G_OBJECT (pref->priv->find_entry), "changed", G_CALLBACK (find_entry_changed), pref);

	gtk_container_set_border_width (GTK_CONTAINER (pref_find_hbox), 0);
	gtk_box_pack_start (GTK_BOX (pref_find_hbox), pref_find_label, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (pref_find_hbox), pref->priv->find_entry, TRUE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (pref_find_hbox), pref->priv->find_next_btn, FALSE, FALSE, 0);

	gtk_box_pack_start (GTK_BOX (pref_loc_hbox), pref_find_hbox, FALSE, FALSE, 0);

	if ( ! g_settings_is_writable (pref->priv->applet->settings, "location0"))
	{
		hard_set_sensitive (scrolled_window, FALSE);
	}

	pref_loc_note_lbl = gtk_label_new (_("Location"));
	gtk_widget_show (pref_loc_note_lbl);
	gtk_notebook_set_tab_label (GTK_NOTEBOOK (pref_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (pref_notebook), 1), pref_loc_note_lbl);


	g_signal_connect (G_OBJECT (pref), "response", G_CALLBACK (response_cb), pref);

	mateweather_pref_set_accessibility (pref);
	gtk_label_set_mnemonic_widget (GTK_LABEL (pref_basic_update_sec_lbl), pref->priv->basic_update_spin);
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), pref->priv->basic_radar_url_entry);
}
コード例 #27
0
static GtkWidget *
gimp_prop_kelvin_presets_new (GObject     *config,
                              const gchar *property_name)
{
  GtkWidget *button;
  GtkWidget *menu;
  gint       i;

  const struct
  {
    gdouble      kelvin;
    const gchar *label;
  }
  kelvin_presets[] =
  {
    { 1700, N_("1,700 K – Match flame") },
    { 1850, N_("1,850 K – Candle flame, sunset/sunrise") },
    { 3000, N_("3,000 K – Soft (or warm) white compact fluorescent lamps") },
    { 3000, N_("3,300 K – Incandescent lamps") },
    { 3200, N_("3,200 K – Studio lamps, photofloods, etc.") },
    { 3350, N_("3,350 K – Studio \"CP\" light") },
    { 4100, N_("4,100 K – Moonlight") },
    { 5000, N_("5,000 K – D50") },
    { 5000, N_("5,000 K – Cool white/daylight compact fluorescent lamps") },
    { 5000, N_("5,000 K – Horizon daylight") },
    { 5500, N_("5,500 K – D55") },
    { 5500, N_("5,500 K – Vertical daylight, electronic flash") },
    { 6200, N_("6,200 K – Xenon short-arc lamp") },
    { 6500, N_("6,500 K – D65") },
    { 6500, N_("6,500 K – Daylight, overcast") },
    { 7500, N_("7,500 K – D75") },
    { 9300, N_("9,300 K") }
  };

  button = gtk_button_new ();
  gtk_widget_set_can_focus (button, FALSE);
  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);

  gtk_button_set_image (GTK_BUTTON (button),
                        gtk_image_new_from_icon_name (GIMP_STOCK_MENU_LEFT,
                                                      GTK_ICON_SIZE_MENU));

  menu = gtk_menu_new ();
  gtk_menu_attach_to_widget (GTK_MENU (menu), button, NULL);

  g_signal_connect (button, "button-press-event",
                    G_CALLBACK (gimp_prop_kelvin_presets_button_press),
                    menu);

  for (i = 0; i < G_N_ELEMENTS (kelvin_presets); i++)
    {
      GtkWidget *item;
      gdouble   *kelvin;

      item = gtk_menu_item_new_with_label (gettext (kelvin_presets[i].label));
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
      gtk_widget_show (item);

      g_object_set_data_full (G_OBJECT (item), "property-name",
                              g_strdup (property_name), (GDestroyNotify) g_free);

      kelvin = g_new (gdouble, 1);
      *kelvin = kelvin_presets[i].kelvin;

      g_object_set_data_full (G_OBJECT (item), "kelvin",
                              kelvin, (GDestroyNotify) g_free);

      g_signal_connect (item, "activate",
                        G_CALLBACK (gimp_prop_kelvin_presets_activate),
                        config);

    }

  return button;
}
コード例 #28
0
static struct _send_data *
build_dialog (EAccountList *accounts, CamelFolder *outbox, const char *destination)
{
	GtkDialog *gd;
	GtkWidget *table;
	int row, num_sources;
	GList *list = NULL;
	struct _send_data *data;
        GtkWidget *send_icon;
	GtkWidget *recv_icon;
	GtkWidget *scrolled_window;
	GtkWidget *label;
	GtkWidget *status_label;
	GtkWidget *progress_bar;
	GtkWidget *cancel_button;
	struct _send_info *info;
	char *pretty_url;
	EAccount *account;
	EIterator *iter;
	GList *icon_list;
	EMEventTargetSendReceive *target;

	gd = (GtkDialog *)(send_recv_dialog = gtk_dialog_new_with_buttons(_("Send & Receive Mail"), NULL, GTK_DIALOG_NO_SEPARATOR, NULL));
	gtk_window_set_modal ((GtkWindow *) gd, FALSE);

	gconf_bridge_bind_window_size (
		gconf_bridge_get (), GCONF_KEY_PREFIX,
		GTK_WINDOW (send_recv_dialog));

	gtk_widget_ensure_style ((GtkWidget *)gd);
	gtk_container_set_border_width ((GtkContainer *)gd->vbox, 0);
	gtk_container_set_border_width ((GtkContainer *)gd->action_area, 6);

	cancel_button = gtk_button_new_with_mnemonic (_("Cancel _All"));
	gtk_button_set_image (
		GTK_BUTTON (cancel_button),
		gtk_image_new_from_stock (
			GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
	gtk_widget_show (cancel_button);
	gtk_dialog_add_action_widget (gd, cancel_button, GTK_RESPONSE_CANCEL);

	icon_list = e_icon_factory_get_icon_list ("mail-send-receive");
	if (icon_list) {
		gtk_window_set_icon_list (GTK_WINDOW (gd), icon_list);
		g_list_foreach (icon_list, (GFunc) g_object_unref, NULL);
		g_list_free (icon_list);
	}

	num_sources = 0;

	iter = e_list_get_iterator ((EList *) accounts);
	while (e_iterator_is_valid (iter)) {
		account = (EAccount *) e_iterator_get (iter);

		if (account->source->url)
			num_sources++;

		e_iterator_next (iter);
	}

	g_object_unref (iter);

	table = gtk_table_new (num_sources, 4, FALSE);
	gtk_container_set_border_width (GTK_CONTAINER (table), 6);
	gtk_table_set_row_spacings (GTK_TABLE (table), 6);
	gtk_table_set_col_spacings (GTK_TABLE (table), 6);

	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
	gtk_container_set_border_width (
		GTK_CONTAINER (scrolled_window), 6);
	gtk_scrolled_window_set_policy (
		GTK_SCROLLED_WINDOW (scrolled_window),
		GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

	gtk_scrolled_window_add_with_viewport (
		GTK_SCROLLED_WINDOW (scrolled_window), table);
	gtk_box_pack_start (
		GTK_BOX (gd->vbox), scrolled_window, TRUE, TRUE, 0);
	gtk_widget_show (scrolled_window);

	/* must bet setup after send_recv_dialog as it may re-trigger send-recv button */
	data = setup_send_data ();

	row = 0;
	iter = e_list_get_iterator ((EList *) accounts);
	while (e_iterator_is_valid (iter)) {
		EAccountService *source;

		account = (EAccount *) e_iterator_get (iter);

		source = account->source;
		if (!account->enabled || !source->url) {
			e_iterator_next (iter);
			continue;
		}

		/* see if we have an outstanding download active */
		info = g_hash_table_lookup (data->active, source->url);
		if (info == NULL) {
			send_info_t type;

			type = get_receive_type (source->url);
			if (type == SEND_INVALID || type == SEND_SEND) {
				e_iterator_next (iter);
				continue;
			}

			info = g_malloc0 (sizeof (*info));
			info->type = type;

			d(printf("adding source %s\n", source->url));

			info->uri = g_strdup (source->url);
			info->keep = source->keep_on_server;
			info->cancel = camel_operation_new (operation_status, info);
			info->state = SEND_ACTIVE;
			info->timeout_id = g_timeout_add (STATUS_TIMEOUT, operation_status_timeout, info);

			g_hash_table_insert (data->active, info->uri, info);
			list = g_list_prepend (list, info);
		} else if (info->progress_bar != NULL) {
			/* incase we get the same source pop up again */
			e_iterator_next (iter);
			continue;
		} else if (info->timeout_id == 0)
			info->timeout_id = g_timeout_add (STATUS_TIMEOUT, operation_status_timeout, info);

		recv_icon = e_icon_factory_get_image (
			"mail-inbox", E_ICON_SIZE_LARGE_TOOLBAR);
	       	pretty_url = format_url (source->url, account->name);
		label = gtk_label_new (NULL);
		gtk_label_set_ellipsize (
			GTK_LABEL (label), PANGO_ELLIPSIZE_END);
		gtk_label_set_markup (GTK_LABEL (label), pretty_url);
		g_free (pretty_url);

		progress_bar = gtk_progress_bar_new ();

		cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);

		status_label = gtk_label_new (
			(info->type == SEND_UPDATE) ?
			_("Updating...") : _("Waiting..."));
		gtk_label_set_ellipsize (
			GTK_LABEL (status_label), PANGO_ELLIPSIZE_END);

		/* g_object_set(data->label, "bold", TRUE, NULL); */
		gtk_misc_set_alignment (GTK_MISC (label), 0, .5);
		gtk_misc_set_alignment (GTK_MISC (status_label), 0, .5);

	        gtk_table_attach (
			GTK_TABLE (table), recv_icon,
			0, 1, row, row+2, 0, 0, 0, 0);
		gtk_table_attach (
			GTK_TABLE (table), label,
			1, 2, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
		gtk_table_attach (
			GTK_TABLE (table), progress_bar,
			2, 3, row, row+2, 0, 0, 0, 0);
		gtk_table_attach (
			GTK_TABLE (table), cancel_button,
			3, 4, row, row+2, 0, 0, 0, 0);
		gtk_table_attach (
			GTK_TABLE (table), status_label,
			1, 2, row+1, row+2, GTK_EXPAND | GTK_FILL, 0, 0, 0);

		info->progress_bar = progress_bar;
		info->status_label = status_label;
		info->cancel_button = cancel_button;
		info->data = data;

		g_signal_connect (
			cancel_button, "clicked",
			G_CALLBACK (receive_cancel), info);
		e_iterator_next (iter);
		row = row + 2;
	}

	g_object_unref (iter);

	/* Hook: If some one wants to hook on to the sendreceive dialog, this is the way to go. */
	target = em_event_target_new_send_receive (em_event_peek(), table, data, row, EM_EVENT_SEND_RECEIVE);
	e_event_emit ((EEvent *)em_event_peek (), "mail.sendreceive", (EEventTarget *) target);

	if (outbox && destination) {
		info = g_hash_table_lookup (data->active, SEND_URI_KEY);
		if (info == NULL) {
			info = g_malloc0 (sizeof (*info));
			info->type = SEND_SEND;
			d(printf("adding dest %s\n", destination));

			info->uri = g_strdup (destination);
			info->keep = FALSE;
			info->cancel = camel_operation_new (operation_status, info);
			info->state = SEND_ACTIVE;
			info->timeout_id = g_timeout_add (STATUS_TIMEOUT, operation_status_timeout, info);

			g_hash_table_insert (data->active, SEND_URI_KEY, info);
			list = g_list_prepend (list, info);
		} else if (info->timeout_id == 0)
			info->timeout_id = g_timeout_add (STATUS_TIMEOUT, operation_status_timeout, info);

		send_icon = e_icon_factory_get_image (
			"mail-outbox", E_ICON_SIZE_LARGE_TOOLBAR);
		pretty_url = format_url (destination, NULL);
		label = gtk_label_new (NULL);
		gtk_label_set_ellipsize (
			GTK_LABEL (label), PANGO_ELLIPSIZE_END);
		gtk_label_set_markup (GTK_LABEL (label), pretty_url);

		g_free (pretty_url);

		progress_bar = gtk_progress_bar_new ();
		cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);

		status_label = gtk_label_new (_("Waiting..."));
		gtk_label_set_ellipsize (
			GTK_LABEL (status_label), PANGO_ELLIPSIZE_END);

		gtk_misc_set_alignment (GTK_MISC (label), 0, .5);
		gtk_misc_set_alignment (GTK_MISC (status_label), 0, .5);

		gtk_table_attach (
			GTK_TABLE (table), send_icon,
			0, 1, row, row+2, 0, 0, 0, 0);
		gtk_table_attach (
			GTK_TABLE (table), label,
			1, 2, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
		gtk_table_attach (
			GTK_TABLE (table), progress_bar,
			2, 3, row, row+2, 0, 0, 0, 0);
		gtk_table_attach (
			GTK_TABLE (table), cancel_button,
			3, 4, row, row+2, 0, 0, 0, 0);
		gtk_table_attach (
			GTK_TABLE (table), status_label,
			1, 2, row+1, row+2, GTK_EXPAND | GTK_FILL, 0, 0, 0);

		info->progress_bar = progress_bar;
		info->cancel_button = cancel_button;
		info->data = data;
		info->status_label = status_label;

		g_signal_connect (
			cancel_button, "clicked",
			G_CALLBACK (receive_cancel), info);
		gtk_widget_show_all (table);
	}

	gtk_widget_show (GTK_WIDGET (gd));

	g_signal_connect (gd, "response", G_CALLBACK (dialog_response), data);

	g_object_weak_ref ((GObject *) gd, (GWeakNotify) dialog_destroy_cb, data);

	data->infos = list;
	data->gd = gd;

	return data;
}
コード例 #29
0
ファイル: lcms.c プロジェクト: DevMaggio/gimp
static gboolean
lcms_icc_apply_dialog (gint32       image,
                       cmsHPROFILE  src_profile,
                       cmsHPROFILE  dest_profile,
                       gboolean    *dont_ask)
{
  GtkWidget *dialog;
  GtkWidget *vbox;
  GtkWidget *label;
  GtkWidget *button;
  GtkWidget *toggle = NULL;
  gboolean   run;

  gimp_ui_init (PLUG_IN_BINARY, FALSE);

  dialog = gimp_dialog_new (_("Convert to RGB working space?"),
                            PLUG_IN_ROLE,
                            NULL, 0,
                            gimp_standard_help_func, PLUG_IN_PROC_APPLY,

                            _("_Keep"),    GTK_RESPONSE_CANCEL,

                            NULL);

  button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                                  _("_Convert"), GTK_RESPONSE_OK);
  gtk_button_set_image (GTK_BUTTON (button),
                        gtk_image_new_from_stock (GTK_STOCK_CONVERT,
                                                  GTK_ICON_SIZE_BUTTON));

  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);

  gimp_window_set_transient (GTK_WINDOW (dialog));

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                      vbox, TRUE, TRUE, 0);
  gtk_widget_show (vbox);

  label = lcms_icc_profile_src_label_new (image, src_profile);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  label = lcms_icc_profile_dest_label_new (dest_profile);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  if (dont_ask)
    {
      toggle = gtk_check_button_new_with_mnemonic (_("_Don't ask me again"));
      gtk_box_pack_end (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), FALSE);
      gtk_widget_show (toggle);
    }

  run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);

  *dont_ask = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle));

  gtk_widget_destroy (dialog);

  return run;
}
コード例 #30
0
int project_edit_dialog_open(GtkWidget *parent, int project_id) {
    project_edit_dialog_project_id = project_id;

    window_project_edit = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    gtk_window_set_transient_for(GTK_WINDOW(window_project_edit), GTK_WINDOW(parent));

    gtk_window_set_position(GTK_WINDOW(window_project_edit), GTK_WIN_POS_CENTER_ON_PARENT);

    gtk_window_set_modal(GTK_WINDOW(window_project_edit), TRUE);

    gtk_window_set_default_size(GTK_WINDOW(window_project_edit), 600, 200);

    gtk_window_set_title(GTK_WINDOW(window_project_edit), "Project information");

    gtk_container_set_border_width(GTK_CONTAINER(window_project_edit), 5);


    GtkWidget *sizer_top;

    sizer_top = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window_project_edit), sizer_top);

    // Grid sizer

    GtkWidget *table_fields = gtk_table_new(2, 2, FALSE);

    gtk_box_pack_start(GTK_BOX(sizer_top), table_fields, TRUE, TRUE, 3);

    gtk_table_set_row_spacings(GTK_TABLE(table_fields), 3);
    gtk_table_set_col_spacings(GTK_TABLE(table_fields), 3);


    // Project name

    GtkWidget *alignment_label = gtk_alignment_new(1, 0, 0, 0);
    gtk_table_attach(GTK_TABLE(table_fields), alignment_label, 0, 1, 1, 2, GTK_FILL, GTK_SHRINK, 0, 0);

    GtkWidget *label = gtk_label_new("Project name: ");
    gtk_container_add(GTK_CONTAINER(alignment_label), label);

    project_edit_entry_name = gtk_entry_new();
    gtk_table_attach(GTK_TABLE(table_fields), project_edit_entry_name, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);

    gtk_entry_set_width_chars(GTK_ENTRY(project_edit_entry_name), 30);


    // Status

    alignment_label = gtk_alignment_new(1, 0, 0, 0);
    gtk_table_attach(GTK_TABLE(table_fields), alignment_label, 0, 1, 5, 6, GTK_FILL, GTK_SHRINK, 0, 0);

    label = gtk_label_new("Status: ");
    gtk_container_add(GTK_CONTAINER(alignment_label), label);

    GtkWidget *alignment_status = gtk_alignment_new(0, 0, 0, 0);
    gtk_table_attach(GTK_TABLE(table_fields), alignment_status, 1, 2, 5, 6, GTK_FILL, GTK_SHRINK, 0, 0);

    project_edit_combo_status = gtk_combo_box_new();
    gtk_container_add(GTK_CONTAINER(alignment_status), project_edit_combo_status);

    // Data model
    GtkListStore *list_store_status = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
    GtkTreeIter iter_status;

    gtk_list_store_append(list_store_status, &iter_status);
    gtk_list_store_set(list_store_status, &iter_status, 0, "Active", 1, "A", -1);

    gtk_list_store_append(list_store_status, &iter_status);
    gtk_list_store_set(list_store_status, &iter_status, 0, "Inactive", 1, "I", -1);

    gtk_combo_box_set_model(GTK_COMBO_BOX(project_edit_combo_status), GTK_TREE_MODEL(list_store_status));

    GtkCellRenderer *status_name_renderer;

    status_name_renderer = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(project_edit_combo_status), status_name_renderer, TRUE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(project_edit_combo_status), status_name_renderer, "text", 0, NULL);

    g_object_unref(G_OBJECT(list_store_status));

    gtk_combo_box_set_active(GTK_COMBO_BOX(project_edit_combo_status), 0);


    // Buttons

    GtkWidget *sizer_buttons = gtk_hbox_new(FALSE, 3);

    gtk_box_pack_end(GTK_BOX(sizer_top), sizer_buttons, FALSE, FALSE, 3);

    // Close button

    GtkWidget *button_close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);

    GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) close_16x16_xpm);
    GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf);

    gtk_button_set_image(GTK_BUTTON(button_close), image);

    gtk_box_pack_end(GTK_BOX(sizer_buttons), button_close, FALSE, FALSE, 3);

    // Save button

    GtkWidget *button_save = gtk_button_new();

    gtk_button_set_label(GTK_BUTTON(button_save), "Save");

    pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) save_16x16_xpm);
    image = gtk_image_new_from_pixbuf(pixbuf);

    gtk_button_set_image(GTK_BUTTON(button_save), image);

    gtk_box_pack_end(GTK_BOX(sizer_buttons), button_save, FALSE, FALSE, 3);

    // Delete button

    GtkWidget *button_delete = gtk_button_new_from_stock(GTK_STOCK_DELETE);

    pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) delete_16x16_xpm);
    image = gtk_image_new_from_pixbuf(pixbuf);

    gtk_button_set_image(GTK_BUTTON(button_delete), image);

    gtk_box_pack_end(GTK_BOX(sizer_buttons), button_delete, FALSE, FALSE, 3);


    // Close window using button

    g_signal_connect(G_OBJECT(button_close), "clicked",
                     G_CALLBACK(on_project_edit_button_close_clicked), G_OBJECT(window_project_edit));

    // Save issue information

    g_signal_connect(G_OBJECT(button_save), "clicked",
                     G_CALLBACK(on_project_edit_button_save_clicked), G_OBJECT(window_project_edit));

    // Delete issue information

    g_signal_connect(G_OBJECT(button_delete), "clicked",
                     G_CALLBACK(on_project_edit_button_delete_clicked), G_OBJECT(window_project_edit));


    gtk_widget_show_all(window_project_edit);


    project_edit_dialog_load_data();


    gtk_widget_grab_focus(GTK_WIDGET(project_edit_combo_status));


    return 0;
}