mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 10:22:49 +00:00
generic: prepare for KFileItem changes
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
64c5eb0884
commit
692edb429a
16 changed files with 21 additions and 77 deletions
|
@ -438,9 +438,7 @@ void DolphinViewContainer::slotUrlIsFileError(const KUrl& url)
|
|||
{
|
||||
const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
|
||||
|
||||
// Find out if the file can be opened in the view. The mime type must be
|
||||
// known for that.
|
||||
item.determineMimeType();
|
||||
// Find out if the file can be opened in the view. The mime type must be known for that.
|
||||
const KUrl& folderUrl = DolphinView::openItemAsFolderUrl(item);
|
||||
if (!folderUrl.isEmpty()) {
|
||||
m_view->setUrl(folderUrl);
|
||||
|
|
|
@ -61,7 +61,6 @@ KFileItemModel::KFileItemModel(QObject* parent) :
|
|||
m_groups()
|
||||
{
|
||||
m_dirLister = new KFileItemModelDirLister(this);
|
||||
m_dirLister->setDelayedMimeTypes(true);
|
||||
|
||||
const QWidget* parentWidget = qobject_cast<QWidget*>(parent);
|
||||
if (parentWidget) {
|
||||
|
@ -983,13 +982,6 @@ void KFileItemModel::removeItems(const KItemRangeList& itemRanges, RemoveItemsBe
|
|||
|
||||
QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const KUrl& parentUrl, const KFileItemList& items) const
|
||||
{
|
||||
if (m_sortRole == TypeRole) {
|
||||
// Try to resolve the MIME-types synchronously to prevent a reordering of
|
||||
// the items when sorting by type (per default MIME-types are resolved
|
||||
// asynchronously by KFileItemModelRolesUpdater).
|
||||
determineMimeTypes(items, 200);
|
||||
}
|
||||
|
||||
const int parentIndex = index(parentUrl);
|
||||
ItemData* parentItem = parentIndex < 0 ? 0 : m_itemData.at(parentIndex);
|
||||
|
||||
|
@ -1028,7 +1020,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList)
|
|||
foreach (ItemData* itemData, itemDataList) {
|
||||
if (itemData->values.isEmpty()) {
|
||||
const KFileItem item = itemData->item;
|
||||
if (item.isDir() || item.isMimeTypeKnown()) {
|
||||
if (item.isDir() || !item.mimeTypePtr().isNull()) {
|
||||
itemData->values = retrieveData(itemData->item, itemData->parent);
|
||||
}
|
||||
}
|
||||
|
@ -1220,7 +1212,7 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item,
|
|||
data.insert(sharedValue("path"), path);
|
||||
}
|
||||
|
||||
if (item.isMimeTypeKnown()) {
|
||||
if (!item.mimeTypePtr().isNull()) {
|
||||
data.insert(sharedValue("iconName"), item.iconName());
|
||||
|
||||
if (m_requestRole[TypeRole]) {
|
||||
|
@ -1684,28 +1676,6 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
|
|||
return rolesInfoMap;
|
||||
}
|
||||
|
||||
void KFileItemModel::determineMimeTypes(const KFileItemList& items, int timeout)
|
||||
{
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
foreach (const KFileItem& item, items) { // krazy:exclude=foreach
|
||||
// Only determine mime types for files here. For directories,
|
||||
// KFileItem::determineMimeType() reads the .directory file inside to
|
||||
// load the icon, but this is not necessary at all if we just need the
|
||||
// type. Some special code for setting the correct mime type for
|
||||
// directories is in retrieveData().
|
||||
if (!item.isDir()) {
|
||||
item.determineMimeType();
|
||||
}
|
||||
|
||||
if (timer.elapsed() > timeout) {
|
||||
// Don't block the user interface, let the remaining items
|
||||
// be resolved asynchronously.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray KFileItemModel::sharedValue(const QByteArray& value)
|
||||
{
|
||||
static QSet<QByteArray> pool;
|
||||
|
|
|
@ -392,12 +392,6 @@ private:
|
|||
*/
|
||||
static const RoleInfoMap* rolesInfoMap(int& count);
|
||||
|
||||
/**
|
||||
* Determines the MIME-types of all items that can be done within
|
||||
* the given timeout.
|
||||
*/
|
||||
static void determineMimeTypes(const KFileItemList& items, int timeout);
|
||||
|
||||
/**
|
||||
* @return Returns a copy of \a value that is implicitly shared
|
||||
* with other users to save memory.
|
||||
|
|
|
@ -714,14 +714,14 @@ void KFileItemModelRolesUpdater::startPreviewJob()
|
|||
KFileItemList itemSubSet;
|
||||
itemSubSet.reserve(count);
|
||||
|
||||
if (m_pendingPreviewItems.first().isMimeTypeKnown()) {
|
||||
if (!m_pendingPreviewItems.first().mimeTypePtr().isNull()) {
|
||||
// Some mime types are known already, probably because they were
|
||||
// determined when loading the icons for the visible items. Start
|
||||
// a preview job for all items at the beginning of the list which
|
||||
// have a known mime type.
|
||||
do {
|
||||
itemSubSet.append(m_pendingPreviewItems.takeFirst());
|
||||
} while (!m_pendingPreviewItems.isEmpty() && m_pendingPreviewItems.first().isMimeTypeKnown());
|
||||
} while (!m_pendingPreviewItems.isEmpty() && !m_pendingPreviewItems.first().mimeTypePtr().isNull());
|
||||
} else {
|
||||
// Determine mime types for MaxBlockTimeout ms, and start a preview
|
||||
// job for the corresponding items.
|
||||
|
@ -730,7 +730,6 @@ void KFileItemModelRolesUpdater::startPreviewJob()
|
|||
|
||||
do {
|
||||
const KFileItem item = m_pendingPreviewItems.takeFirst();
|
||||
item.determineMimeType();
|
||||
itemSubSet.append(item);
|
||||
} while (!m_pendingPreviewItems.isEmpty() && timer.elapsed() < MaxBlockTimeout);
|
||||
}
|
||||
|
@ -829,10 +828,6 @@ void KFileItemModelRolesUpdater::applySortRole(int index)
|
|||
const KFileItem item = m_model->fileItem(index);
|
||||
|
||||
if (m_model->sortRole() == "type") {
|
||||
if (!item.isMimeTypeKnown()) {
|
||||
item.determineMimeType();
|
||||
}
|
||||
|
||||
data.insert("type", item.mimeComment());
|
||||
} else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) {
|
||||
const QString path = item.localPath();
|
||||
|
@ -863,8 +858,7 @@ bool KFileItemModelRolesUpdater::applyResolvedRoles(int index, ResolveHint hint)
|
|||
const bool resolveAll = (hint == ResolveAll);
|
||||
|
||||
bool iconChanged = false;
|
||||
if (!item.isMimeTypeKnown() || !item.isFinalIconKnown()) {
|
||||
item.determineMimeType();
|
||||
if (item.mimeTypePtr().isNull()) {
|
||||
iconChanged = true;
|
||||
} else if (!m_model->data(index).contains("iconName")) {
|
||||
iconChanged = true;
|
||||
|
|
|
@ -84,7 +84,6 @@ void FileNameSearchProtocol::searchDirectory(const KUrl& directory)
|
|||
|
||||
// Get all items of the directory
|
||||
KDirLister *dirLister = new KDirLister();
|
||||
dirLister->setDelayedMimeTypes(false);
|
||||
dirLister->setAutoUpdate(false);
|
||||
dirLister->setAutoErrorHandlingEnabled(false, 0);
|
||||
|
||||
|
@ -104,14 +103,14 @@ void FileNameSearchProtocol::searchDirectory(const KUrl& directory)
|
|||
if (!m_checkType.isEmpty()) {
|
||||
addItem = false;
|
||||
const QStringList types = m_checkType.split(";");
|
||||
const KSharedPtr<KMimeType> mime = item.determineMimeType();
|
||||
const KSharedPtr<KMimeType> mime = item.mimeTypePtr();
|
||||
foreach (const QString& t, types) {
|
||||
if (mime->is(t)) {
|
||||
addItem = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!m_checkContent.isEmpty() && item.determineMimeType()->is(QLatin1String("text/plain"))) {
|
||||
} else if (!m_checkContent.isEmpty() && item.mimeTypePtr()->is(QLatin1String("text/plain"))) {
|
||||
addItem = contentContainsPattern(item.url());
|
||||
}
|
||||
|
||||
|
|
|
@ -257,13 +257,6 @@ void KFileItemModelTest::testChangeSortRole()
|
|||
QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
|
||||
QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.jpg" << "c.txt");
|
||||
|
||||
// Simulate that KFileItemModelRolesUpdater determines the mime type.
|
||||
// Resorting the files by 'type' will only work immediately if their
|
||||
// mime types are known.
|
||||
for (int index = 0; index < m_model->count(); ++index) {
|
||||
m_model->fileItem(index).determineMimeType();
|
||||
}
|
||||
|
||||
// Now: sort by type.
|
||||
QSignalSpy spyItemsMoved(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)));
|
||||
m_model->setSortRole("type");
|
||||
|
@ -690,15 +683,15 @@ void KFileItemModelTest::testChangeSortRoleWhileFiltering()
|
|||
|
||||
entry.insert(KIO::UDSEntry::UDS_NAME, "a.txt");
|
||||
entry.insert(KIO::UDSEntry::UDS_USER, "user-b");
|
||||
items.append(KFileItem(entry, m_testDir->url(), false, true));
|
||||
items.append(KFileItem(entry, m_testDir->url()));
|
||||
|
||||
entry.insert(KIO::UDSEntry::UDS_NAME, "b.txt");
|
||||
entry.insert(KIO::UDSEntry::UDS_USER, "user-c");
|
||||
items.append(KFileItem(entry, m_testDir->url(), false, true));
|
||||
items.append(KFileItem(entry, m_testDir->url()));
|
||||
|
||||
entry.insert(KIO::UDSEntry::UDS_NAME, "c.txt");
|
||||
entry.insert(KIO::UDSEntry::UDS_USER, "user-a");
|
||||
items.append(KFileItem(entry, m_testDir->url(), false, true));
|
||||
items.append(KFileItem(entry, m_testDir->url()));
|
||||
|
||||
m_model->slotItemsAdded(items);
|
||||
m_model->slotCompleted();
|
||||
|
|
|
@ -1183,7 +1183,7 @@ KUrl DolphinView::openItemAsFolderUrl(const KFileItem& item)
|
|||
return url;
|
||||
}
|
||||
|
||||
if (item.isMimeTypeKnown()) {
|
||||
if (!item.mimeTypePtr().isNull()) {
|
||||
if (item.mimetype() == QLatin1String("application/x-desktop")) {
|
||||
// Redirect to the URL in Type=Link desktop files, unless it is a http(s) URL.
|
||||
KDesktopFile desktopFile(url.toLocalFile());
|
||||
|
@ -1607,7 +1607,7 @@ void DolphinView::updateWritableState()
|
|||
if (item.isNull()) {
|
||||
// Try to find out if the URL is writable even if the "root item" is
|
||||
// null, see https://bugs.kde.org/show_bug.cgi?id=330001
|
||||
item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, url(), true);
|
||||
item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, url());
|
||||
}
|
||||
|
||||
KFileItemListProperties capabilities(KFileItemList() << item);
|
||||
|
|
|
@ -660,7 +660,7 @@ void KateMainWindow::slotDropEvent( QDropEvent * event )
|
|||
for (KUrl::List::Iterator i = textlist.begin(); i != textlist.end(); ++i)
|
||||
{
|
||||
// if url has no file component, try and recursively scan dir
|
||||
KFileItem kitem( KFileItem::Unknown, KFileItem::Unknown, *i, true );
|
||||
KFileItem kitem( KFileItem::Unknown, KFileItem::Unknown, *i );
|
||||
if( kitem.isDir() ) {
|
||||
KIO::ListJob *list_job = KIO::listRecursive(*i, KIO::DefaultFlags, false);
|
||||
connect(list_job, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)),
|
||||
|
|
|
@ -280,7 +280,7 @@ void Autostart::slotEditCMD(QTreeWidgetItem* ent)
|
|||
if (!ent) return;
|
||||
AutoStartItem *entry = dynamic_cast<AutoStartItem*>( ent );
|
||||
if (entry) {
|
||||
const KFileItem kfi = KFileItem( KFileItem::Unknown, KFileItem::Unknown, KUrl(entry->fileName()), true);
|
||||
const KFileItem kfi = KFileItem( KFileItem::Unknown, KFileItem::Unknown, KUrl(entry->fileName()));
|
||||
if (!slotEditCMD(kfi)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ void DesktopPathConfig::slotEntries(KIO::Job*, const KIO::UDSEntryList& list)
|
|||
{
|
||||
QListIterator<KIO::UDSEntry> it(list);
|
||||
while (it.hasNext()) {
|
||||
KFileItem file(it.next(), m_copyFromSrc, true, true);
|
||||
KFileItem file(it.next(), m_copyFromSrc);
|
||||
kDebug() << file.url();
|
||||
if (file.url() == m_copyFromSrc || file.url().fileName() == "..") {
|
||||
continue;
|
||||
|
|
|
@ -113,7 +113,7 @@ void KQuery::slotListEntries(KIO::Job*, const KIO::UDSEntryList& list)
|
|||
const KIO::UDSEntryList::ConstIterator end = list.constEnd();
|
||||
|
||||
for (KIO::UDSEntryList::ConstIterator it = list.constBegin(); it != end; ++it)
|
||||
m_fileItems.enqueue(KFileItem(*it, m_url, true, true));
|
||||
m_fileItems.enqueue(KFileItem(*it, m_url));
|
||||
|
||||
checkEntries();
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ void KQuery::checkEntries()
|
|||
{
|
||||
if (m_insideCheckEntries) return;
|
||||
|
||||
m_insideCheckEntries=true;
|
||||
m_insideCheckEntries = true;
|
||||
|
||||
metaKeyRx = QRegExp(m_metainfokey);
|
||||
metaKeyRx.setPatternSyntax( QRegExp::Wildcard );
|
||||
|
|
|
@ -963,7 +963,7 @@ QPair<bool, QString> KonqOperations::pasteInfo(const KUrl& targetUrl)
|
|||
ret.first = KFileItemListProperties(KFileItemList() << item).supportsWriting();
|
||||
|
||||
if (urls.count() == 1) {
|
||||
const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, urls.first(), true);
|
||||
const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, urls.first());
|
||||
ret.second = item.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
|
||||
i18nc("@action:inmenu", "Paste One File");
|
||||
|
||||
|
|
|
@ -418,7 +418,6 @@ void FolderView::init()
|
|||
m_model->sort(m_sortColumn != int(FolderView::Unsorted) ? m_sortColumn : KDirModel::Name, m_sortOrder);
|
||||
|
||||
m_dirLister = new DirLister(this);
|
||||
m_dirLister->setDelayedMimeTypes(true);
|
||||
m_dirLister->setAutoErrorHandlingEnabled(false, 0);
|
||||
|
||||
m_dirModel->setDirLister(m_dirLister);
|
||||
|
|
|
@ -181,7 +181,6 @@ void PopupView::init()
|
|||
m_view->show();
|
||||
|
||||
DirLister *lister = new DirLister(this);
|
||||
lister->setDelayedMimeTypes(true);
|
||||
lister->setAutoErrorHandlingEnabled(false, 0);
|
||||
lister->openUrl(m_url);
|
||||
|
||||
|
|
|
@ -229,9 +229,7 @@ inline bool ProxyModel::matchMimeType(const KFileItem &item) const
|
|||
if (m_mimeSet.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString mimeType = item.determineMimeType()->name();
|
||||
return m_mimeSet.contains(mimeType);
|
||||
return m_mimeSet.contains(item.mimetype());
|
||||
}
|
||||
|
||||
inline bool ProxyModel::matchPattern(const KFileItem &item) const
|
||||
|
|
|
@ -121,7 +121,7 @@ void ToolTipWidget::setContent()
|
|||
KDesktopFile file(m_item.localPath());
|
||||
subText = file.readComment();
|
||||
} else {
|
||||
if (m_item.isMimeTypeKnown()) {
|
||||
if (!m_item.mimeTypePtr().isNull()) {
|
||||
subText = m_item.mimeComment();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue