]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.cpp
Fix regression that caused "(I18N_EMPTY_MESSAGE)" sub menus in menus
[dolphin.git] / src / kitemviews / kfileitemmodel.cpp
index 9f92d8a81fdc832ac45751031728efaa101a1a72..6936af4311da9bd657d78aeab658de721307dcb1 100644 (file)
@@ -72,13 +72,16 @@ KFileItemModel::KFileItemModel(QObject* parent) :
     connect(m_dirLister, SIGNAL(infoMessage(QString)), this, SIGNAL(infoMessage(QString)));
     connect(m_dirLister, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString)));
     connect(m_dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SIGNAL(directoryRedirection(KUrl,KUrl)));
+    connect(m_dirLister, SIGNAL(urlIsFileError(KUrl)), this, SIGNAL(urlIsFileError(KUrl)));
 
     // Apply default roles that should be determined
     resetRoles();
     m_requestRole[NameRole] = true;
     m_requestRole[IsDirRole] = true;
+    m_requestRole[IsLinkRole] = true;
     m_roles.insert("text");
     m_roles.insert("isDir");
+    m_roles.insert("isLink");
 
     // For slow KIO-slaves like used for searching it makes sense to show results periodically even
     // before the completed() or canceled() signal has been emitted.
@@ -165,6 +168,12 @@ bool KFileItemModel::setData(int index, const QHash<QByteArray, QVariant>& value
     }
 
     m_itemData[index]->values = currentValues;
+    if (changedRoles.contains("text")) {
+        KUrl url = m_itemData[index]->item.url();
+        url.setFileName(currentValues["text"].toString());
+        m_itemData[index]->item.setUrl(url);
+    }
+
     emit itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
 
     if (changedRoles.contains(sortRole())) {
@@ -278,7 +287,7 @@ QString KFileItemModel::roleDescription(const QByteArray& role) const
         int count = 0;
         const RoleInfoMap* map = rolesInfoMap(count);
         for (int i = 0; i < count; ++i) {
-            description.insert(map[i].role, map[i].roleTranslation);
+            description.insert(map[i].role, i18nc(map[i].roleTranslationContext, map[i].roleTranslation));
         }
     }
 
@@ -528,7 +537,7 @@ void KFileItemModel::setNameFilter(const QString& nameFilter)
             const KFileItem item = it.next();
             if (m_filter.matches(item)) {
                 newVisibleItems.append(item);
-                m_filteredItems.remove(item);
+                it.remove();
             }
         }
 
@@ -551,8 +560,15 @@ QList<KFileItemModel::RoleInfo> KFileItemModel::rolesInformation()
             if (map[i].roleType != NoRole) {
                 RoleInfo info;
                 info.role = map[i].role;
-                info.translation = map[i].roleTranslation;
-                info.group = map[i].groupTranslation;
+                info.translation = i18nc(map[i].roleTranslationContext, map[i].roleTranslation);
+                if (map[i].groupTranslation) {
+                    info.group = i18nc(map[i].groupTranslationContext, map[i].groupTranslation);
+                } else {
+                    // For top level roles, groupTranslation is 0. We must make sure that
+                    // info.group is an empty string then because the code that generates
+                    // menus tries to put the actions into sub menus otherwise.
+                    info.group = QString();
+                }
                 info.requiresNepomuk = map[i].requiresNepomuk;
                 info.requiresIndexer = map[i].requiresIndexer;
                 rolesInfo.append(info);
@@ -653,7 +669,7 @@ void KFileItemModel::slotCompleted()
         // Note that the parent folder must be expanded before any of its subfolders become visible.
         // Therefore, some URLs in m_restoredExpandedUrls might not be visible yet
         // -> we expand the first visible URL we find in m_restoredExpandedUrls.
-        foreach(const KUrl& url, m_urlsToExpand) {
+        foreach (const KUrl& url, m_urlsToExpand) {
             const int index = m_items.value(url, -1);
             if (index >= 0) {
                 m_urlsToExpand.remove(url);
@@ -930,7 +946,7 @@ void KFileItemModel::insertItems(const KFileItemList& items)
             insertedCount = 0;
         }
 
-        // Insert item at the position targetIndex by transfering
+        // Insert item at the position targetIndex by transferring
         // the ownership of the item-data from sortedItems to m_itemData.
         // m_items will be inserted after the loop (see comment below)
         m_itemData.insert(targetIndex, sortedItems.at(sourceIndex));
@@ -1116,6 +1132,7 @@ KFileItemModel::RoleType KFileItemModel::typeForRole(const QByteArray& role) con
         // Insert internal roles (take care to synchronize the implementation
         // with KFileItemModel::roleForType() in case if a change is done).
         roles.insert("isDir", IsDirRole);
+        roles.insert("isLink", IsLinkRole);
         roles.insert("isExpanded", IsExpandedRole);
         roles.insert("isExpandable", IsExpandableRole);
         roles.insert("expandedParentsCount", ExpandedParentsCountRole);
@@ -1141,6 +1158,7 @@ QByteArray KFileItemModel::roleForType(RoleType roleType) const
         // Insert internal roles (take care to synchronize the implementation
         // with KFileItemModel::typeForRole() in case if a change is done).
         roles.insert(IsDirRole, "isDir");
+        roles.insert(IsLinkRole, "isLink");
         roles.insert(IsExpandedRole, "isExpanded");
         roles.insert(IsExpandableRole, "isExpandable");
         roles.insert(ExpandedParentsCountRole, "expandedParentsCount");
@@ -1164,6 +1182,11 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item)
         data.insert("isDir", isDir);
     }
 
+    if (m_requestRole[IsLinkRole]) {
+        const bool isLink = item.isLink();
+        data.insert("isLink", isLink);
+    }
+
     if (m_requestRole[NameRole]) {
         data.insert("text", item.text());
     }
@@ -1905,7 +1928,7 @@ void KFileItemModel::determineMimeTypes(const KFileItemList& items, int timeout)
 {
     QElapsedTimer timer;
     timer.start();
-    foreach (KFileItem item, items) {
+    foreach (KFileItem item, items) { // krazy:exclude=foreach
         item.determineMimeType();
         if (timer.elapsed() > timeout) {
             // Don't block the user interface, let the remaining items