예제 #1
0
void AppWindow::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, 
	int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time)
	{
	
#ifdef DEBUG	
	std::cout << "ON_DRAG_DATA_RECEIVED: type: " << selection_data.get_data_type() << std::endl;
	std::cout << "ON_DRAG_DATA_RECEIVED: data: " << selection_data.get_data_as_string() << std::endl;
#endif // DEBUG

	if (selection_data.get_data_type() == "text/uri-list")
		{
		std::list<Glib::ustring> new_filenames = selection_data.get_uris();
			
		const std::list<Glib::ustring>::iterator begin = new_filenames.begin();
		const std::list<Glib::ustring>::iterator end = new_filenames.end();
		std::list<Glib::ustring>::iterator iter = new_filenames.begin();
		int counter = 0;
		
		while( iter != end )
			{
			// we erase the protocol in front of the filename
			if( (*iter).find(':') != std::string::npos )
				(*iter).erase(0, (*iter).find(':')+3);
			
			// unescape the URI
			char * tempfilename = curl_unescape( iter->c_str(), 0);
			(*iter) = tempfilename;
			// curl requires this to be freed like this
			curl_free( tempfilename );

#ifdef DEBUG			
	std::cout << "ON_DRAG_DATA_RECEIVED: URI: " << *iter << std::endl;
#endif // DEBUG

			iter++;
			counter++;
			}
		open_list( new_filenames, counter );
		}
	
	// if we're given plain text, maybe it's still an uri or a filename, we should better check
	// ImageManager.OpenFiles is safe anyway	
	else if( selection_data.get_data_type() == "text/plain" )
		{
			std::string data = selection_data.get_data_as_string();
			data.erase( data.find('\n') ); // erase any newlines, all we can do is one file
			// we erase the protocol in front of the filename
			if( data.find(':') != std::string::npos )
				data.erase(0, data.find(':')+3);
			
			// unescape the URI
			char * tempfilename = curl_unescape( data.c_str(), 0);
			data = tempfilename;
			// curl requires this to be freed like this
			curl_free( tempfilename );
			
			open_new_file( data );
		} 	
	context->drag_finish(true, false, time);
	}
예제 #2
0
void Gui_MyWindow::on_dropped_file(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time){
    std::vector<std::string> paths;
    DEV_INFOS("D");
    if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8)){
        std::vector<Glib::ustring> file_list;
        file_list = selection_data.get_uris();
        for (auto &str: file_list){
            paths.push_back(str);
        }
        context->drag_finish(true, false, time);
    }
    else
        context->drag_finish(false, false, time);
    m_signal_drag_and_drop.emit(paths);

}