QMimeData *InventoryItemModel::mimeData(const QModelIndexList &indexes) const { QMimeData *mimeData = new QMimeData(); QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); foreach(QModelIndex index, indexes) { if (index.isValid()) { QString info, asset_type, asset_ref; AbstractInventoryItem *item = GetItem(index); InventoryAsset *asset = dynamic_cast<InventoryAsset *>(item); if (asset) { asset_type.append(QString("%1").arg(asset->GetAssetType())); asset_ref = asset->GetAssetReference(); } else { asset_type.append(QString("%1").arg(RexTypes::RexAT_None)); asset_ref = RexUUID().ToString().c_str(); } info.append(asset_type + ";" + item->GetID() + ";" + item->GetName() + ";" + asset_ref); stream << info; } } mimeData->setData("application/vnd.inventory.item", encodedData); return mimeData; }
void InventoryItemModel::CopyAssetReferenceToClipboard(const QModelIndex &index) { if (!index.isValid()) return; InventoryAsset *asset = dynamic_cast<InventoryAsset *>(GetItem(index)); if (!asset) return; QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(asset->GetAssetReference(), QClipboard::Clipboard); }
void InventoryModule::OpenItemPropertiesWindow(const QString &inventory_id) { boost::shared_ptr<UiServices::UiModule> ui_module = GetFramework()->GetModuleManager()->GetModule<UiServices::UiModule>(Foundation::Module::MT_UiServices).lock(); if (!ui_module.get()) return; // Check that item properties window for this item doesn't already exists. // If it does, bring it to front and set focus to it. QMap<QString, ItemPropertiesWindow *>::iterator it = itemPropertiesWindows_.find(inventory_id); if (it != itemPropertiesWindows_.end()) { ui_module->GetInworldSceneController()->BringProxyToFront(it.value()); return; } InventoryAsset *asset = dynamic_cast<InventoryAsset *>(inventory_->GetChildById(inventory_id)); if (!asset) return; ItemPropertiesWindow *wnd = new ItemPropertiesWindow(this); connect(wnd, SIGNAL(Closed(const QString &, bool)), this, SLOT(CloseItemPropertiesWindow(const QString &, bool))); wnd->SetItem(asset); itemPropertiesWindows_[inventory_id] = wnd; if (inventoryType_ == IDMT_OpenSim) { static_cast<OpenSimInventoryDataModel *>(inventory_.get())->SendNameUuidRequest(asset); // Get asset service interface and check if the asset is in cache. // If it is, show file size to item properties UI. SLUDP protocol doesn't support querying asset size // and we don't want download asset only just to know its size. ///\todo If WebDAV supports this, utilize it. Foundation::ServiceManagerPtr service_manager = framework_->GetServiceManager(); if (!service_manager->IsRegistered(Foundation::Service::ST_Asset)) return; boost::shared_ptr<Foundation::AssetServiceInterface> asset_service = service_manager->GetService<Foundation::AssetServiceInterface>(Foundation::Service::ST_Asset).lock(); Foundation::AssetPtr assetPtr = asset_service->GetAsset(asset->GetAssetReference().toStdString(), GetTypeNameFromAssetType(asset->GetAssetType())); if (assetPtr && assetPtr->GetSize() > 0) wnd->SetFileSize(assetPtr->GetSize()); } }
void WebDavInventoryDataModel::DownloadFile(const QString &store_folder, AbstractInventoryItem *selected_item) { InventoryAsset *item = dynamic_cast<InventoryAsset *>(selected_item); if (!item) return; QString storePath = store_folder; QString parentPath = ValidateFolderPath(item->GetParent()->GetID()); QString filename = item->GetName(); //emit DownloadStarted(id); QStringList result = webdavclient_.call("downloadFile", QVariantList() << storePath << parentPath << filename).toStringList(); if (result.count() >= 1) { if (result[0] == "True") { InventoryModule::LogInfo(QString("Webdav | Downloaded file %1%2 to path %3\n").arg(parentPath, filename, storePath).toStdString()); //emit DownloadCompleted(id); } else InventoryModule::LogInfo(QString("Webdav | Downloaded of file %1%2 to path %3 failed\n").arg(parentPath, filename, storePath).toStdString()); } }
void InventoryModule::CloseItemPropertiesWindow(const QString &inventory_id, bool save_changes) { // Note: We only remove the pointer from the map here. The window deletes itself. ItemPropertiesWindow *wnd = itemPropertiesWindows_.take(inventory_id); if (!wnd) return; boost::shared_ptr<UiServices::UiModule> ui_module = GetFramework()->GetModuleManager()->GetModule<UiServices::UiModule>(Foundation::Module::MT_UiServices).lock(); if (ui_module) ui_module->GetInworldSceneController()->RemoveProxyWidgetFromScene(wnd); // If inventory item is modified notify server. if (save_changes) { InventoryAsset *asset = dynamic_cast<InventoryAsset *>(inventory_->GetChildById(inventory_id)); if (asset) ///\todo WebDAV needs the old name and we don't have it here. inventory_->NotifyServerAboutItemUpdate(asset, asset->GetName()); } wnd->deleteLater(); }
bool InventoryItemModel::InsertExistingItem(int position, AbstractInventoryItem *new_parent, AbstractInventoryItem *item, const QModelIndex &parent_index) { if (new_parent == item->GetParent()) return false; InventoryFolder *newParentFolder = dynamic_cast<InventoryFolder *>(new_parent); if (!newParentFolder) return false; if (parent_index.isValid()) beginInsertRows(parent_index, parent_index.row(), parent_index.row()); if (item->GetItemType() == AbstractInventoryItem::Type_Folder) { dataModel_->GetOrCreateNewFolder(item->GetID(), *newParentFolder, item->GetName(), false); InventoryFolder *newFolder = static_cast<InventoryFolder *>(dataModel_->GetOrCreateNewFolder( item->GetID(), *newParentFolder, item->GetName(), false)); //newFolder->SetDirty(true); // When moving folders with descendents, we don't need to notify server about every descendent, // just the root item we're moving i.e. when the current parent is different from the new parent. InventoryFolder *currentParent = static_cast<InventoryFolder *>(item->GetParent()); if (currentParent != newParentFolder) dataModel_->NotifyServerAboutItemMove(newFolder); /* if (newFolder->HasChildren()) { AbstractInventoryItem childItem = newFolder->Child(0); InsertExistingItem(0, newFolder, item); } */ } if (item->GetItemType()== AbstractInventoryItem::Type_Asset) { InventoryAsset *oldAsset= static_cast<InventoryAsset *>(item); if (oldAsset->IsLibraryItem()) { // Library asset can only be copied, moving not possible. // Server is authorative for copy operation so we don't create the new asset right here. // If the copy as legal, server sends us packet and we create the asset after that. InventoryAsset newTempAsset(oldAsset->GetID(), oldAsset->GetAssetReference(), oldAsset->GetName(), newParentFolder); dataModel_->NotifyServerAboutItemCopy(&newTempAsset); } else { InventoryAsset *newAsset = static_cast<InventoryAsset *>(dataModel_->GetOrCreateNewAsset( oldAsset->GetID(), oldAsset->GetAssetReference(), *newParentFolder, oldAsset->GetName())); newAsset->SetDescription(oldAsset->GetDescription()); newAsset->SetInventoryType(oldAsset->GetInventoryType()); newAsset->SetAssetType(oldAsset->GetAssetType()); newAsset->SetCreatorId(oldAsset->GetCreatorId()); newAsset->SetOwnerId(oldAsset->GetOwnerId()); newAsset->SetGroupId(oldAsset->GetGroupId()); newAsset->SetCreationTime(oldAsset->GetCreationTime()); // When moving folders with descendents, we don't need to notify server about every descendent, // just the root item we're moving i.e. when the current parent is different from the new parent. InventoryFolder *currentParent = static_cast<InventoryFolder *>(item->GetParent()); if (currentParent != newParentFolder) dataModel_->NotifyServerAboutItemMove(newAsset); } } if (parent_index.isValid()) { endInsertRows(); fetchMore(parent_index); } return true; }