void KDirModelV2Private::newItemsFromLister(const KFileItemList& items) { qDebug() << "newItemsFromLister delay:" << m_time.elapsed(); m_time.restart(); const int itemCount = items.count(); const int newItemListLength = m_itemList.count() + itemCount; // We can already determine the number of items in this list. Reserve them manyally. m_itemList.reserve(newItemListLength); m_model->beginInsertRows(m_currentIndex, rowCount, itemCount); QTime time; time.start(); /* #pragma omp parallel for schedule(dynamic, 100) for(int i = 0; i < itemCount; i++) { ItemData newData; newData.item = new KFileItem(items.at(i)); // newData.collationSequence = new CNaturalString(newData.item->name().toAscii().constData()); newData.modelIndex = m_model->createIndex(i, 0); #pragma omp critical m_itemList.append(newData); } #pragma omp parallel for schedule(dynamic, 100) for(int i = 0; i < itemCount; i++) { ItemData * newData = &m_itemList[iBase + i]; newData->collationSequence = new CNaturalString(newData->item->name().toAscii().constData()); } */ for(int i = 0; i < itemCount; i++) { ItemData newData; newData.item = new KFileItem(items.at(i)); newData.collationSequence = new CNaturalString(newData.item->name().toAscii().constData()); newData.modelIndex = m_model->createIndex(i, 0); m_itemList.append(newData); } qDebug() << "Time elapsed:" << time.elapsed() << "ms"; rowCount = m_itemList.count(); // std::sort(m_itemList.begin(), m_itemList.end(), lessThan); // qSort(m_itemList.begin(), m_itemList.end(), lessThan); m_model->endInsertRows(); emit m_model->layoutChanged(); // Move the current index to the last inserted item. ItemData lastItem = m_itemList.last(); m_currentIndex = lastItem.modelIndex; qDebug() << "KDirModelV2Private::newItemsFromLister rowCount:" << rowCount; }
void PopupView::showContextMenu(QWidget *widget, const QPoint &screenPos, const QList<QModelIndex> &indexes) { Q_UNUSED(widget) // contextMenuRequest is only called from the icon view, which is created in init() // which mean m_model should always be initialized Q_ASSERT(m_model); if (indexes.isEmpty()) { return; } if (m_actionCollection.isEmpty()) { createActions(); } KFileItemList items; bool hasRemoteFiles = false; bool isTrashLink = false; foreach (const QModelIndex &index, m_selectionModel->selectedIndexes()) { KFileItem item = m_model->itemForIndex(index); if (!item.isNull()) { hasRemoteFiles |= item.localPath().isEmpty(); items.append(item); } } // Check if we're showing the menu for the trash link if (items.count() == 1 && items.at(0).isDesktopFile()) { KDesktopFile file(items.at(0).localPath()); if (file.readType() == "Link" && file.readUrl() == "trash:/") { isTrashLink = true; } } QAction *pasteTo = m_actionCollection.action("pasteto"); if (pasteTo) { if (QAction *paste = m_actionCollection.action("paste")) { pasteTo->setEnabled(paste->isEnabled()); pasteTo->setText(paste->text()); } } QList<QAction*> editActions; editActions.append(m_actionCollection.action("rename")); KConfigGroup configGroup(KGlobal::config(), "KDE"); bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false); // Don't add the "Move to Trash" action if we're showing the menu for the trash link if (!isTrashLink) { if (!hasRemoteFiles) { editActions.append(m_actionCollection.action("trash")); } else { showDeleteCommand = true; } } if (showDeleteCommand) { editActions.append(m_actionCollection.action("del")); } KParts::BrowserExtension::ActionGroupMap actionGroups; actionGroups.insert("editactions", editActions); KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::ShowProperties; flags |= KParts::BrowserExtension::ShowUrlOperations; // m_newMenu can be NULL here but KonqPopupMenu does handle this. KonqPopupMenu *contextMenu = new KonqPopupMenu(items, m_url, m_actionCollection, m_newMenu, KonqPopupMenu::ShowNewWindow, flags, QApplication::desktop(), KBookmarkManager::userBookmarksManager(), actionGroups); connect(contextMenu->fileItemActions(), SIGNAL(openWithDialogAboutToBeShown()), this, SLOT(openWithDialogAboutToShow())); m_showingMenu = true; contextMenu->exec(screenPos); delete contextMenu; m_showingMenu = false; if (pasteTo) { pasteTo->setEnabled(false); } if (m_delayedClose) { m_delayedClose = false; closeThisAndParentPopup(); } }