本文整理汇总了C++中gtk::SelectionData::get_data_as_string方法的典型用法代码示例。如果您正苦于以下问题:C++ SelectionData::get_data_as_string方法的具体用法?C++ SelectionData::get_data_as_string怎么用?C++ SelectionData::get_data_as_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gtk::SelectionData
的用法示例。
在下文中一共展示了SelectionData::get_data_as_string方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_drag_data_received
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: onFileDropped
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);
}
}
示例3: on_routine_drop
//------------------------------------------------------------------------------
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);
}
示例4: onFileDropped
/**
* 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
}
}
}
示例5: dropFunction
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);
}
示例6: on_label_drop_drag_data_received
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);
}
示例7: box
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);
}
示例8: on_drag_data_received
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);
}
示例9: file_drag_data_received
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);
}
示例10: onFileDropped
/**
* 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
}
}
}