Verified Commit cf4c23be authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Fix restoring default favorite name

The algorithm for default name is more complex than just
collection.displayName()...
parent ace70fca
......@@ -55,22 +55,7 @@ public:
return labelMap[collectionId];
}
const QModelIndex collectionIdx = EntityTreeModel::modelIndexForCollection(q->sourceModel(), Collection(collectionId));
QString accountName;
const QString nameOfCollection = collectionIdx.data().toString();
QModelIndex idx = collectionIdx.parent();
while (idx != QModelIndex()) {
accountName = idx.data(EntityTreeModel::OriginalCollectionNameRole).toString();
idx = idx.parent();
}
if (accountName.isEmpty()) {
return nameOfCollection;
} else {
return nameOfCollection + QStringLiteral(" (") + accountName + QLatin1Char(')');
}
return q->defaultFavoriteLabel(Collection{collectionId});
}
void insertIfAvailable(Collection::Id col)
......@@ -403,6 +388,28 @@ QString Akonadi::FavoriteCollectionsModel::favoriteLabel(const Akonadi::Collecti
return d->labelForCollection(collection.id());
}
QString Akonadi::FavoriteCollectionsModel::defaultFavoriteLabel(const Akonadi::Collection &collection)
{
if (!collection.isValid()) {
return QString();
}
const auto colIdx = EntityTreeModel::modelIndexForCollection(sourceModel(), Collection(collection.id()));
const QString nameOfCollection = colIdx.data().toString();
QModelIndex idx = colIdx.parent();
QString accountName;
while (idx != QModelIndex()) {
accountName = idx.data(EntityTreeModel::OriginalCollectionNameRole).toString();
idx = idx.parent();
}
if (accountName.isEmpty()) {
return nameOfCollection;
} else {
return nameOfCollection + QStringLiteral(" (") + accountName + QLatin1Char(')');
}
}
QVariant FavoriteCollectionsModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (section == 0 &&
......
......@@ -116,6 +116,7 @@ public:
* Return associate label for collection
*/
Q_REQUIRED_RESULT QString favoriteLabel(const Akonadi::Collection &col);
Q_REQUIRED_RESULT QString defaultFavoriteLabel(const Akonadi::Collection &col);
Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Q_REQUIRED_RESULT bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
......
......@@ -1043,7 +1043,7 @@ public:
QPointer<RenameFavoriteDialog> dlg(new RenameFavoriteDialog(
favoritesModel->favoriteLabel(collection),
collection.displayName(),
favoritesModel->defaultFavoriteLabel(collection),
parentWidget));
if (dlg->exec() == QDialog::Accepted) {
favoritesModel->setFavoriteLabel(collection, dlg->newName());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment