compact test case for weird filechooser behaviour



A couple of days ago i reported that the filechooserwidget behaves
rather unpredictably when in a GNOME session. Here's a little testcase
that reproduces the behaviour as in gimmage.

compile and launch "./testfilechooser *" in a directory with a couple of
files

-click apply a couple of times to trigger set_filename(), note the
output and what happens in the window, note that get_filename() does NOT
return anything!

-click remove to hide the filechooser widget from the window
-click remove again to make it reappear
-click apply a couple of times and note that the what happens in the
window does not match what is sent to set_filename(), get_filename()
still does not return anything

again, the weird behaviour happens only in a gnome session, but
get_filename() returns an empty string even in a non-gnome session

I use: gentoo ~x86
GTK 2.10.13, GLib 2.12.12, gtkmm 2.10.9, libgnome 2.18.0

-Bartek
// testfilechooser.cpp

#include <iostream>

#include <gtkmm.h>

extern "C"
{
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
}

class TestChooser : public Gtk::VBox
{
public:
	TestChooser(int argc, char **argv) :
		TestButton( Gtk::Stock::APPLY ),
		HideButton( Gtk::Stock::REMOVE )
		{
		_argc = argc;
		_argv = argv;
		
		TestButton.signal_clicked().connect(sigc::mem_fun(*this,&TestChooser::on_test_button));
		HideButton.signal_clicked().connect(sigc::mem_fun(*this,&TestChooser::on_hide_button));
		
		pack_start(FileChooser);
		Buttons.pack_start(TestButton);
		Buttons.pack_start(HideButton);
		pack_start(Buttons);
		}
	
	
		
	void on_hide_button(void)
		{
		FileChooser.is_visible() ? FileChooser.hide() : FileChooser.show();
		}
	
	void on_test_button(void)
		{
		test( _argc, _argv );
		}
	
	
	void test( int argc, char **argv )
		{
		static int i = 1;
		if( argc > 1 && i < argc && FileChooser.is_visible() )
			{
			i++;
			if( stat(argv[i], &filemode) != 0 )
				{
				std::cout << "Stat Error!  " << argv[i] << std::endl;
				return;
				}		
						
			Glib::ustring filename;
			// Resolve any ".." in the filename and make the filename absolute
			if( Glib::path_is_absolute( argv[i] ) )
				filename = argv[i] ;
			else
				filename = (Glib::ustring)get_current_dir_name() + "/" + (Glib::ustring)argv[i];
			
			while( filename.find("..") != Glib::ustring::npos )
				{
				filename.erase( 
					filename.rfind( '/', filename.find("..")-2), 
					filename.find("..")+2 - filename.rfind( '/', filename.find("..")-2) );
				}
				
			if(filemode.st_mode & S_IFREG)
				{
				std::cout << "\nSetting Filechooser to: " << filename << std::endl;
				FileChooser.set_filename( filename );
				std::cout << "FileChooser resports: " << FileChooser.get_filename() << std::endl;
				}
			if( i == argc-1 )
			  i = 1;	
			}
		
		}	

private:
	int _argc;
	char **_argv;

	struct stat filemode;

	Gtk::FileChooserWidget FileChooser;
	Gtk::HButtonBox Buttons;
	Gtk::Button	TestButton;	
	Gtk::Button HideButton;	
};

int main(int argc,char **argv)
	{	
	Glib::init();
	Glib::set_prgname("testfilechooser");
	Glib::set_application_name("testfilechooser");
	Gtk::Main kit(argc,argv);

	Gtk::Window testwindow;
	TestChooser widget(argc,argv);

	testwindow.add(widget);
	testwindow.show_all_children();
	
	testwindow.set_size_request(512,384);
	
	Gtk::Main::run(testwindow);
	
	return 0;
	}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]