void ClipSelector::dropFunction( const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
                       const Gtk::SelectionData& selection_data, guint info, guint time)
{
  // drop target is of string type, load that sample
  
  int block = y / 18;
  cout << "DROP on block " << block << endl;
  
  const int length = selection_data.get_length();
  if( (length >= 0) ) // && (selection_data.get_format() == 8)
  {
    std::string filename = selection_data.get_data_as_string();
    std::cout << "Received " << filename << " in ClipSelector, loading now! " << std::endl;
    
    // audioFileLoader informs engine & updates StateStore
    int ret = top->offlineWorker->loadAudioBuffer( ID, block, filename );
    
    if ( ret == 0 ) // successful load, so store filename in vector
    {
      stateStore->addAudioBufferName(ID, Glib::path_get_basename(filename) );
    }
  }

  context->drag_finish(false, false, time);
}
//------------------------------------------------------------------------------
void DbMySQLRoutineGroupEditor::on_routine_drop(const Glib::RefPtr<Gdk::DragContext>& context
                                               ,int x, int y
                                               , const Gtk::SelectionData& selection_data
                                               , guint info, guint time)
{
  bool dnd_status = false;
  
  if ( selection_data.get_target() == WB_DBOBJECT_DRAG_TYPE)
  {
    std::list<db_DatabaseObjectRef> objects;

    const std::string selection = selection_data.get_data_as_string();

    objects= bec::CatalogHelper::dragdata_to_dbobject_list(_be->get_catalog(), selection);
    
    for (std::list<db_DatabaseObjectRef>::const_iterator obj= objects.begin(); 
         obj != objects.end(); ++obj)
    {
      if (obj->is_instance<db_mysql_Routine>())
      {
        db_mysql_RoutineRef routine = db_mysql_RoutineRef::cast_from(*obj);
        if ( routine.is_valid() )
          _be->append_routine_with_id(routine.id());
      }
    }

    recreate_model_from_string_list(_routines_model, _be->get_routines_names());

    dnd_status = true;
  }
  context->drag_finish(dnd_status, false, time);
}
Esempio n. 3
0
void
Dockable::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
{
	if (selection_data.get_length() >= 0
	 && selection_data.get_format() == 8
	 && selection_data.get_data_type() == "SYNFIG_DOCK")
	{
		Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));

		DockBook *parent = dynamic_cast<DockBook*>(get_parent());
		DockBook *dockable_parent = dynamic_cast<DockBook*>(dockable.get_parent());

		if (parent)
		{
			if (dockable_parent != parent)
				 parent->add(dockable,parent->page_num(*this));
			else
				parent->reorder_child(dockable,parent->page_num(*this));
			dockable.present();
			context->drag_finish(true, false, time);
			App::dock_manager->update_window_titles();
			return;
		}
	}

	context->drag_finish(false, false, time);
}
Esempio n. 4
0
void DnDWindow::on_button_drag_data_get(
        const Glib::RefPtr<Gdk::DragContext>&,
        Gtk::SelectionData& selection_data, guint, guint)
{
  selection_data.set(selection_data.get_target(), 8 /* 8 bits format */,
          (const guchar*)"I'm Data!",
          9 /* the length of I'm Data! in bytes */);
}
Esempio n. 5
0
void TestDnDWindow::on_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
{ 
  if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
  {
    std::cout << "Received \"" << selection_data.get_data_as_string() << "\" in label " << std::endl;
  }

  context->drag_finish(false, false, time);
}
Esempio n. 6
0
void GtkMainWindow::onFileDropped(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time)
{
	string str = selection_data.get_data_as_string();
	string str2 = Glib::filename_from_uri(str);
	string str3 = rtrim(str2);
	bool want_uncertain = true;
	string content_type = Gio::content_type_guess(str3, selection_data.get_data_as_string(), want_uncertain);
	if(content_type == "application/x-bittorrent")
	{
		shared_ptr<Torrent> t = m_core->addTorrent(str3);
		m_treeview->addCell(t);
	}
}
Esempio n. 7
0
void
DockDialog::drop_on_append(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
{
	if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
	{
		Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
		append_dock_book()->add(dockable);
		context->drag_finish(true, false, time);
		return;
	}

	context->drag_finish(false, false, time);
}
Esempio n. 8
0
void
Toolbox::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int /*x*/, int /*y*/, const Gtk::SelectionData& selection_data_, guint /*info*/, guint time)
{
	// We will make this true once we have a solid drop
	bool success(false);

	if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
	{
		synfig::String selection_data((gchar *)(selection_data_.get_data()));

		// For some reason, GTK hands us a list of URLs separated
		// by not only Carriage-Returns, but also Line-Feeds.
		// Line-Feeds will mess us up. Remove all the line-feeds.
		while(selection_data.find_first_of('\r')!=synfig::String::npos)
			selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));

		std::stringstream stream(selection_data);

		while(stream)
		{
			synfig::String filename,URI;
			getline(stream,filename);

			// If we don't have a filename, move on.
			if(filename.empty())
				continue;

			// Make sure this URL is of the "file://" type.
			URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
			if(URI!="file://")
			{
				synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
				continue;
			}

			// Strip the "file://" part from the filename
			filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());

			synfig::info("Attempting to open "+filename);
			if(App::open(filename))
				success=true;
			else
				synfig::error("Drop failed: Unable to open "+filename);
		}
	}
	else
		synfig::error("Drop failed: bad selection data");

	// Finish the drag
	context->drag_finish(success, false, time);
}
Esempio n. 9
0
void ImportClassesBox::ClassesTreeView::on_drag_data_get(
    const Glib::RefPtr<Gdk::DragContext>& ,
    Gtk::SelectionData& selection_data, guint, guint)
{
    Glib::RefPtr<Gtk::TreeSelection> srcSelect(get_selection());
    if (srcSelect) {
	Gtk::TreeModel::iterator iter = srcSelect->get_selected();
	if (iter) {
	    Gtk::TreeModel::Row row = *iter;
	    std::string className = row.get_value(mColumns.m_col_name);
	    selection_data.set(selection_data.get_target(), className);
	}
    }
}
Esempio n. 10
0
void
DockBook::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
{
	if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
	{
		Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
		if(dockable.get_parent()!=this)
			add(dockable);
		dockable.present();
		context->drag_finish(true, false, time);
		return;
	}

	context->drag_finish(false, false, time);
}
Esempio n. 11
0
void CIconView::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, 
	Gtk::SelectionData& selection_data, guint info, guint time)
	{
	std::list<Gtk::TreeModel::Path> selected_items = ThumbsIconView.get_selected_items();
	
	std::list<Gtk::TreeModel::Path>::iterator path_list_iter = selected_items.begin();
	std::list<Gtk::TreeModel::Path>::iterator path_list_end = selected_items.end();
	
	
	//std::list<Glib::ustring>* filenames = new std::list<Glib::ustring>;
	
	std::list<Glib::ustring> filenames;
	while( path_list_iter != path_list_end )
		{
		Gtk::TreeModel::iterator model_iter = refImageList->get_iter( *path_list_iter );
		Gtk::TreeModel::Row row = *model_iter;
		
		std::cout << row[ ImageListColumns.filenames_column ] << std::endl;
		
		filenames.push_back( row[ ImageListColumns.filenames_column] );

		path_list_iter++;
		}
	
	selection_data.set_uris( filenames );
	}
Esempio n. 12
0
/**
* Does something when a file is dropped onto the window.
*/
void GtkMainWindow::onFileDropped(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time)
{
	std::string sel_data = selection_data.get_data_as_string();
	if(m_core->isLink(sel_data))
	{
		std::shared_ptr<gt::Torrent> t = m_core->addTorrent(sel_data);
		if (t)//Checks if t is not null
			m_treeview->addCell(t);
	}
	else
	{
		std::string fn = Glib::filename_from_uri(sel_data);
		boost::algorithm::trim(fn); //d-don't worry guys! w-we only need boo-boost for libtorrent! th-that's all!
		bool want_uncertain = true;
		std::string content_type = Gio::content_type_guess(fn, sel_data, want_uncertain);
		if(content_type == "application/x-bittorrent" || content_type == ".torrent")
		{
			std::shared_ptr<gt::Torrent> t = m_core->addTorrent(fn);
			if (t)//Checks if t is not null
			{
				t->onStateChanged = std::bind(&GtkMainWindow::torrentStateChangedCallback, this, std::placeholders::_1, std::placeholders::_2);
				m_treeview->addCell(t);
			}
			//TODO Add error dialogue if torrent add is unsuccessful
		}
	}
}
Esempio n. 13
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);

}
Esempio n. 14
0
void ScriptSlots::onScriptDragNDropDataReceived(
    const Glib::RefPtr<Gdk::DragContext>& context, int, int,
    const Gtk::SelectionData& selection_data, guint, guint time)
{
    gig::Script* script = *((gig::Script**) selection_data.get_data());
    if (script && selection_data.get_length() == sizeof(gig::Script*)) {
        std::cout << "Drop received script \"" << script->Name << "\"" << std::endl;
        m_instrument->AddScriptSlot(script);
        appendNewSlot(script);
        // drop success
        context->drop_reply(true, time);
    } else {
        // drop failed
        context->drop_reply(false, time);
    }
}
Esempio n. 15
0
void
Dockable::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, Gtk::SelectionData& selection_data, guint /*info*/, guint /*time*/)
{
	Dockable* tmp(this);
	dnd_success_=true;

	selection_data.set(8, reinterpret_cast<const guchar*>(&tmp), sizeof(Dockable**));
}
Esempio n. 16
0
bool NatnTreeMdl::drag_data_get_vfunc(const TreeModel::Path& path, Gtk::SelectionData& selection_data) const
{
    bool res = false;
    // Set selection. This will evolve DnD process 
    int row_index = path[0];
    string data = iNodesInfo.at(row_index);
    selection_data.set_text(data);
    res = true;
    return res;
}
//------------------------------------------------------------------------------
bool ListModelWrapper::drag_data_received_vfunc(const Gtk::TreeModel::Path& dest,
                                                const Gtk::SelectionData& selection_data) {
  bool ret = false;
  // Currently this works for linear lists
  try {
    (*_tm)->reorder(bec::NodeId((const char*)selection_data.get_data()), dest.front());
    ret = true;
  } catch (const std::logic_error& e) {
  }
  return ret;
}
Esempio n. 18
0
//
// D&Dで受信側がデータ送信を要求してきた
//
void TabLabel::on_drag_data_get( const Glib::RefPtr<Gdk::DragContext>& context,
                                 Gtk::SelectionData& selection_data, guint info, guint time )
{
#ifdef _DEBUG
    std::cout << "TabLabel::on_drag_data_get target = " << selection_data.get_target()
              << " " << m_fulltext << std::endl;;
#endif

    Gtk::EventBox::on_drag_data_get( context, selection_data, info, time );

    m_sig_tab_drag_data_get( selection_data );
}
Esempio n. 19
0
void ApplicationList::onDragDataGet(const Glib::RefPtr<Gdk::DragContext>& context, 
                             Gtk::SelectionData& data, guint info, guint time)
{
    Glib::RefPtr<Gtk::TreeSelection> refTreeSelection = m_TreeView.get_selection();
    Gtk::TreeModel::iterator iter = refTreeSelection->get_selected();

    if(iter && ((*iter)[m_appColumns.m_col_type] == MODULE))
    {
        Glib::ustring name = (*iter)[m_appColumns.m_col_name];
        data.set(data.get_target(), MODULE,
                (const guchar*)name.c_str(), name.size()+1);  
    }
    else if(iter && ((*iter)[m_appColumns.m_col_type] == RESOURCE))
    {
        Glib::ustring name = (*iter)[m_appColumns.m_col_name];
        data.set(data.get_target(), RESOURCE,
                (const guchar*)name.c_str(), name.size()+1);  
    }
    else if(iter && ((*iter)[m_appColumns.m_col_type] == APPLICATION))
    {
        Glib::ustring name = (*iter)[m_appColumns.m_col_name];
        data.set(data.get_target(), APPLICATION,
                (const guchar*)name.c_str(), name.size()+1);  
    }
}
Esempio n. 20
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);
	}
Esempio n. 21
0
void ClipSelector::dragFunction( const Glib::RefPtr<Gdk::DragContext>& context,
                       Gtk::SelectionData& selection_data, guint info, guint time)
{
  cout << "ClipSelector::dragFunction() called!" << endl;
  
  // drag target is of string type, send
  cout << "DRAG from block " << block << endl;
  
  // get state of clip selector
  ClipSelectorState* state = &stateStore->clipSelectorState.at(ID);
  
  // get block info, to retrieve its bufferID
  std::list<ClipInfo>::iterator iter = state->clipInfo.begin();
  std::advance(iter, block);
  
  stringstream s;
  s << (*iter).bufferID;
  
  // send data to drop
  selection_data.set( selection_data.get_target(), 8, (guchar*) s.str().c_str(), s.str().size() );
  
}
Esempio n. 22
0
void NaviModules::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection_data, guint info, guint time)
{
    // Combining full path to module
    GtkTreeRowReference* grr = (GtkTreeRowReference*) context->get_data(Glib::Quark("gtk-tree-view-source-row"));
    Gtk::TreeRowReference rr = Glib::wrap(grr);
    Gtk::TreePath path = rr.get_path();
    Glib::RefPtr<Gtk::TreeModel> mdl = get_model();
    Gtk::TreeIter it = mdl->get_iter(path);
    string modname = (*it).get_value(iColRec.name);
    string modpath = iDesEnv->Provider()->ModulesPath();
    string data = "file:" + modpath + modname + "#";
    selection_data.set_text(data);
}
Esempio n. 23
0
void window_main::file_drag_data_received(
	const Glib::RefPtr<Gdk::DragContext> & context, //info about drag (available on source and dest)
	const int x,                                    //x-coord of drop
	const int y,                                    //y-coord of drop
	const Gtk::SelectionData & selection_data,      //data dropped
	const guint info,                               //type of info dropped
	const guint time)                               //time stamp of when drop happened
{
//DEBUG, dragging file on to window does not work on windows, not sure why

	if(selection_data.get_length() >= 0 && selection_data.get_format() == 8){
		//this will look like file:///home/foo/bar.txt
		std::string URI = selection_data.get_data_as_string();
		if(URI.size() > 7){
			std::string path = URI.substr(7);
			//get rid of newline on the end
			boost::trim(path);
			p2p::load_file(path);
		}
	}

	//tell other end we're done with drag and drop so it can free resources
	context->drag_finish(true, true, time);
}
Esempio n. 24
0
void ImportClassesBox::ClassesTreeView::on_drag_data_received(
    const Glib::RefPtr<Gdk::DragContext>& context, int, int,
    const Gtk::SelectionData& selection_data, guint, guint time)
{
    std::string className = selection_data.get_data_as_string();

    if (mClasses->exist(className)) {
	const std::string title(_("Choose a new class name"));
	InteractiveTypeBox box(title, mClasses, className);
	std::string newClassName = box.run();
	if (not newClassName.empty())
	    mParent->importClass(className, newClassName);
    } else {
	mParent->importClass(className);
    }
    build(mClasses);

    if ((context->get_actions () & Gdk::ACTION_MOVE) != 0)
	context->drag_finish(true, false, time);
}
Esempio n. 25
0
bool HierTreeMdl::drag_data_get_vfunc(const TreeModel::Path& path, Gtk::SelectionData& selection_data) const
{
    bool res = false;
    // Set selection. This will evolve DnD process 
    iterator iter((TreeModel*)this);
    bool ires = get_iter_vfunc(path, iter);
    Elem* node = (Elem*) (*iter).get_value(ColRec().elem);
    GUri uri;
    node->GetUri(uri);
    //selection_data.set_text(uri.GetUri());
    selection_data.set(KDnDTarg_Comp, uri.GetUri());

    //
    /*
    int row_index = path[0];
    Elem* node = iRoot->Comps().at(row_index);
    string data = node->Name();
    selection_data.set_text(data);
    */
    res = true;
    return res;
}
Esempio n. 26
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)
	{  
    // this is totally ridiculous, but so be it!
	// we erase the protocol in front of the filename
	// using std::string because Glib::ustring throws a conversion error for some reason
	std::string string_filename = selection_data.get_data_as_string();
	string_filename.erase(0, string_filename.find(':')+3); 

	//convert to char* and unescape
	char * temp_filename = curl_unescape( string_filename.c_str(), 0);
	string_filename = temp_filename;
	// curl requires this to be freed
	curl_free( temp_filename );
	
	//let's remove any \n and \r that are typical of URI's
	if ( string_filename.find('\n') != Glib::ustring::npos )
		string_filename.erase( string_filename.find('\n'), 1 );
	if ( string_filename.find('\r') != Glib::ustring::npos )
		string_filename.erase( string_filename.find('\r'), 1 );

	open_new_file( string_filename );
	context->drag_finish(false, false, time);
	}
Esempio n. 27
0
/**
* Does something when a file is dropped onto the window.
*/
void GtkMainWindow::onFileDropped(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time)
{
	string sel_data = selection_data.get_data_as_string();
	if(m_core->isMagnetLink(sel_data))
	{
		shared_ptr<gt::Torrent> t = m_core->addTorrent(sel_data);
		if (t)//Checks if t is not null
			m_treeview->addCell(t);
	}
	else
	{
		string fn = Glib::filename_from_uri(sel_data);
		boost::algorithm::trim(fn);
		bool want_uncertain = true;
		string content_type = Gio::content_type_guess(fn, sel_data, want_uncertain);
		if(content_type == "application/x-bittorrent" || content_type == ".torrent")
		{
			shared_ptr<gt::Torrent> t = m_core->addTorrent(fn);
			if (t)//Checks if t is not null
				m_treeview->addCell(t);
			//TODO Add error dialogue if torrent add is unsuccessful
		}
	}
}
Esempio n. 28
0
  void BugzillaNoteAddin::drop_uri_list(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, 
                                        const Gtk::SelectionData & selection_data, guint time)
  {
    std::string uriString = selection_data.get_text();
    if(uriString.empty()) {
      return;
    }

    const char * regexString = "\\bhttps?://.*/show_bug\\.cgi\\?(\\S+\\&){0,1}id=(\\d{1,})";

    pcrecpp::RE re(regexString, pcrecpp::RE_Options(PCRE_CASELESS|PCRE_UTF8));
    int m;

    if(re.FullMatch(uriString, (void*)NULL, &m)) {

      int bugId = m;

      if (insert_bug (x, y, uriString, bugId)) {
        context->drag_finish(true, false, time);
        g_signal_stop_emission_by_name(get_window()->editor()->gobj(),
                                       "drag_data_received");
      }
    }
  }
Esempio n. 29
0
void PrintSelectionData(const Gtk::SelectionData& selection_data, const std::string& location_str)
{
    io::cout << "\nFrom " << location_str << ":" << io::endl;
    io::cout << "Target: " << selection_data.get_target() << io::endl;
    io::cout << "Selection: " << gdk_atom_name(selection_data.get_selection()) << io::endl;
}
Esempio n. 30
0
void SetData(Gtk::SelectionData& selection_data, void* dat, int dat_sz)
{
    selection_data.set(selection_data.get_target(), 8 /* 8 bits format */,
                       (const guchar*)dat, dat_sz /* the length of data in bytes */);
}