From 129c02fcb4074f400888c3d943e6cf58ee4bd000 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Tue, 16 Oct 2007 11:30:41 +0000 Subject: [PATCH] drag and drop, step two --- .../gLiveSupport/src/ScratchpadWindow.cxx | 115 +++++++++++++++--- .../gLiveSupport/src/ScratchpadWindow.h | 22 ++++ 2 files changed, 120 insertions(+), 17 deletions(-) diff --git a/campcaster/src/products/gLiveSupport/src/ScratchpadWindow.cxx b/campcaster/src/products/gLiveSupport/src/ScratchpadWindow.cxx index 3e9df8c5b..9a199d010 100644 --- a/campcaster/src/products/gLiveSupport/src/ScratchpadWindow.cxx +++ b/campcaster/src/products/gLiveSupport/src/ScratchpadWindow.cxx @@ -35,6 +35,7 @@ #include #include +#include #include "LiveSupport/Widgets/WidgetFactory.h" @@ -687,26 +688,106 @@ ScratchpadWindow :: onTreeViewDragDataReceived( return; } -// Glib::ustring data = selectionData.get_data_as_string(); -Glib::ustring data = "searchWindow 123 456 789 abc"; + Glib::ustring data = selectionData.get_data_as_string(); std::stringstream dataStream(data); Glib::ustring sourceWindow; dataStream >> sourceWindow; - - - Glib::ustring playableId; - while (dataStream >> playableId) { - if (sourceWindow == bundleName) { - //insertRow(destination, x, y, stripped, ROW_MOVE); - std::cerr << "same window; move " << playableId << std::endl; - context->drag_finish(true, true, time); - - } else { - //insertRow(destination, x, y, stripped, ROW_COPY); - std::cerr << "other window: " << sourceWindow - << "; copy " << playableId << std::endl; - context->drag_finish(true, false, time); - } + + Gtk::TreeIter iter = insertRowAtPos(x, y); + Glib::ustring idAsString; + dataStream >> idAsString; // only works for 1 item, for now + Ptr::Ref id(new UniqueId(idAsString)); + addItem(iter, id); + + if (sourceWindow == bundleName) { + context->drag_finish(true, true, time); // delete the original + + } else { + context->drag_finish(true, false, time); // don't delete the original } } + +/*------------------------------------------------------------------------------ + * Insert a row into the tree model at the given tree view position. + *----------------------------------------------------------------------------*/ +Gtk::TreeIter +ScratchpadWindow :: insertRowAtPos (int x, + int y) throw () +{ + Gtk::TreePath destPath; + Gtk::TreeViewDropPosition destPos; + bool pathIsValid = treeView->get_dest_row_at_pos( + x, y, destPath, destPos); + // get_drag_dest_row() does not work here, for some strange reason + Gtk::TreeIter newIter; + + if (pathIsValid) { + assert (!destPath.empty()); + Gtk::TreeIter destination = treeModel->get_iter(destPath); + + if (destPos == Gtk::TREE_VIEW_DROP_BEFORE + || destPos == Gtk::TREE_VIEW_DROP_INTO_OR_BEFORE) { + newIter = treeModel->insert(destination); + + } else if (destPos == Gtk::TREE_VIEW_DROP_AFTER + || destPos == Gtk::TREE_VIEW_DROP_INTO_OR_AFTER) { + newIter = treeModel->insert_after(destination); + + } else { + assert (false); + } + } else { + newIter = treeModel->append(); + } + + return newIter; +} + + +/*------------------------------------------------------------------------------ + * Add an item to the Scratchpad at the given position. + *----------------------------------------------------------------------------*/ +void +ScratchpadWindow :: addItem(Gtk::TreeIter iter, + Ptr::Ref id) + throw () +{ + Ptr::Ref playable; + try { + playable = gLiveSupport->acquirePlayable(id); + } catch (XmlRpcException &e) { + std::cerr << "could not acquire playable in ScratchpadWindow: " + << e.what() << std::endl; + return; + } + + Gtk::TreeModel::Row row = *iter; + + row[modelColumns.playableColumn] = playable; + + Ptr::Ref widgetFactory = WidgetFactory::getInstance(); + + switch (playable->getType()) { + case Playable::AudioClipType: + row[modelColumns.typeColumn] = widgetFactory->getPixbuf( + WidgetConstants::audioClipIconImage); + break; + + case Playable::PlaylistType: + row[modelColumns.typeColumn] = widgetFactory->getPixbuf( + WidgetConstants::playlistIconImage); + break; + } + + Ptr::Ref creator = playable->getMetadata( + "dc:creator"); + if (creator) { + row[modelColumns.creatorColumn] = Glib::Markup::escape_text( + *creator); + } + row[modelColumns.titleColumn] = Glib::Markup::escape_text( + *playable->getTitle()); +} + + diff --git a/campcaster/src/products/gLiveSupport/src/ScratchpadWindow.h b/campcaster/src/products/gLiveSupport/src/ScratchpadWindow.h index 7d879bcf8..e063363b6 100644 --- a/campcaster/src/products/gLiveSupport/src/ScratchpadWindow.h +++ b/campcaster/src/products/gLiveSupport/src/ScratchpadWindow.h @@ -153,6 +153,28 @@ class ScratchpadWindow : public GuiWindow, void setupDndCallbacks (void) throw (); + /** + * Insert a row into the tree model at the given tree view position. + * Creates the new row; the caller should fill it with data. + * + * @param x the x coordinate of the location of the new row. + * @param y the y coordinate of the location of the new row. + * @return an iterator pointing to the newly created row. + */ + Gtk::TreeIter + insertRowAtPos (int x, + int y) throw (); + + /** + * Add an item to the Scratchpad at the given position. + * + * @param iter the iterator pointing to the row to be filled in. + * @param id the ID of the item to add. + */ + void + addItem(Gtk::TreeIter iter, + Ptr::Ref id) throw (); + protected: