File indexing completed on 2024-11-10 04:40:08
0001 /* 0002 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "collection.h" 0008 #include "qtest_akonadi.h" 0009 0010 #include "../src/widgets/actionstatemanager_p.h" 0011 #include "../src/widgets/standardactionmanager.h" 0012 0013 #define QT_NO_CLIPBOARD // allow running without GUI 0014 #include "../src/widgets/actionstatemanager.cpp" 0015 #undef QT_NO_CLIPBOARD 0016 0017 using StateMap = QHash<Akonadi::StandardActionManager::Type, bool>; 0018 Q_DECLARE_METATYPE(StateMap) 0019 0020 using namespace Akonadi; 0021 0022 class ActionStateManagerTest; 0023 0024 class UnitActionStateManager : public ActionStateManager 0025 { 0026 public: 0027 explicit UnitActionStateManager(ActionStateManagerTest *receiver); 0028 0029 protected: 0030 bool hasResourceCapability(const Collection &collection, const QString &capability) const override; 0031 0032 private: 0033 ActionStateManagerTest *mReceiver = nullptr; 0034 }; 0035 0036 class ActionStateManagerTest : public QObject 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 ActionStateManagerTest() 0042 : rootCollection(Collection::root()) 0043 { 0044 const QString dummyMimeType(QStringLiteral("text/dummy")); 0045 0046 resourceCollectionOne.setId(1); 0047 resourceCollectionOne.setName(QStringLiteral("resourceCollectionOne")); 0048 resourceCollectionOne.setRights(Collection::ReadOnly); 0049 resourceCollectionOne.setParentCollection(rootCollection); 0050 resourceCollectionOne.setContentMimeTypes(QStringList() << Collection::mimeType() << dummyMimeType); 0051 0052 folderCollectionOne.setId(10); 0053 folderCollectionOne.setName(QStringLiteral("folderCollectionOne")); 0054 folderCollectionOne.setRights(Collection::ReadOnly); 0055 folderCollectionOne.setParentCollection(resourceCollectionOne); 0056 folderCollectionOne.setContentMimeTypes(QStringList() << Collection::mimeType() << dummyMimeType); 0057 0058 resourceCollectionTwo.setId(2); 0059 resourceCollectionTwo.setName(QStringLiteral("resourceCollectionTwo")); 0060 resourceCollectionTwo.setRights(Collection::AllRights); 0061 resourceCollectionTwo.setParentCollection(rootCollection); 0062 resourceCollectionTwo.setContentMimeTypes(QStringList() << Collection::mimeType() << dummyMimeType); 0063 0064 folderCollectionTwo.setId(20); 0065 folderCollectionTwo.setName(QStringLiteral("folderCollectionTwo")); 0066 folderCollectionTwo.setRights(Collection::AllRights); 0067 folderCollectionTwo.setParentCollection(resourceCollectionTwo); 0068 folderCollectionTwo.setContentMimeTypes(QStringList() << Collection::mimeType() << dummyMimeType); 0069 0070 resourceCollectionThree.setId(3); 0071 resourceCollectionThree.setName(QStringLiteral("resourceCollectionThree")); 0072 resourceCollectionThree.setRights(Collection::AllRights); 0073 resourceCollectionThree.setParentCollection(rootCollection); 0074 resourceCollectionThree.setContentMimeTypes(QStringList() << Collection::mimeType() << dummyMimeType); 0075 0076 folderCollectionThree.setId(30); 0077 folderCollectionThree.setName(QStringLiteral("folderCollectionThree")); 0078 folderCollectionThree.setRights(Collection::AllRights); 0079 folderCollectionThree.setParentCollection(resourceCollectionThree); 0080 folderCollectionThree.setContentMimeTypes(QStringList() << Collection::mimeType() << dummyMimeType); 0081 0082 folderCollectionThree.setId(31); 0083 folderCollectionThree.setName(QStringLiteral("folderCollectionThreeOne")); 0084 folderCollectionThree.setRights(Collection::AllRights); 0085 folderCollectionThree.setParentCollection(resourceCollectionThree); 0086 0087 mCapabilityMap.insert(QStringLiteral("NoConfig"), Collection::List() << resourceCollectionThree); 0088 mFavoriteCollectionMap.insert(folderCollectionThree.id()); 0089 } 0090 0091 bool hasResourceCapability(const Collection &collection, const QString &capability) const 0092 { 0093 return mCapabilityMap.value(capability).contains(collection); 0094 } 0095 0096 public Q_SLOTS: 0097 void enableAction(int type, bool enable) 0098 { 0099 mStateMap.insert(static_cast<StandardActionManager::Type>(type), enable); 0100 } 0101 0102 void updatePluralLabel(int type, int count) 0103 { 0104 Q_UNUSED(type) 0105 Q_UNUSED(count) 0106 } 0107 0108 bool isFavoriteCollection(const Akonadi::Collection &collection) 0109 { 0110 return mFavoriteCollectionMap.contains(collection.id()); 0111 } 0112 0113 void updateAlternatingAction(int action) 0114 { 0115 Q_UNUSED(action) 0116 } 0117 0118 private Q_SLOTS: 0119 0120 void init() 0121 { 0122 mStateMap.clear(); 0123 } 0124 0125 void testCollectionSelected_data() 0126 { 0127 QTest::addColumn<Collection::List>("collections"); 0128 QTest::addColumn<StateMap>("stateMap"); 0129 0130 { 0131 Collection::List collectionList; 0132 0133 StateMap map; 0134 map.insert(StandardActionManager::CreateCollection, false); 0135 map.insert(StandardActionManager::CopyCollections, false); 0136 map.insert(StandardActionManager::DeleteCollections, false); 0137 map.insert(StandardActionManager::SynchronizeCollections, false); 0138 map.insert(StandardActionManager::CollectionProperties, false); 0139 map.insert(StandardActionManager::CopyItems, false); 0140 map.insert(StandardActionManager::Paste, false); 0141 map.insert(StandardActionManager::DeleteItems, false); 0142 map.insert(StandardActionManager::AddToFavoriteCollections, false); 0143 map.insert(StandardActionManager::RemoveFromFavoriteCollections, false); 0144 map.insert(StandardActionManager::RenameFavoriteCollection, false); 0145 map.insert(StandardActionManager::CopyCollectionToMenu, false); 0146 map.insert(StandardActionManager::CopyItemToMenu, false); 0147 map.insert(StandardActionManager::MoveItemToMenu, false); 0148 map.insert(StandardActionManager::MoveCollectionToMenu, false); 0149 map.insert(StandardActionManager::CutItems, false); 0150 map.insert(StandardActionManager::CutCollections, false); 0151 map.insert(StandardActionManager::CreateResource, true); 0152 map.insert(StandardActionManager::DeleteResources, false); 0153 map.insert(StandardActionManager::ResourceProperties, false); 0154 map.insert(StandardActionManager::SynchronizeResources, false); 0155 map.insert(StandardActionManager::MoveItemToDialog, false); 0156 map.insert(StandardActionManager::CopyItemToDialog, false); 0157 map.insert(StandardActionManager::CopyCollectionToDialog, false); 0158 map.insert(StandardActionManager::MoveCollectionToDialog, false); 0159 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, false); 0160 map.insert(StandardActionManager::MoveCollectionsToTrash, false); 0161 map.insert(StandardActionManager::MoveItemsToTrash, false); 0162 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0163 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0164 map.insert(StandardActionManager::MoveToTrashRestoreCollection, false); 0165 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0166 map.insert(StandardActionManager::SynchronizeCollectionTree, false); 0167 0168 QTest::newRow("nothing selected") << collectionList << map; 0169 } 0170 0171 { 0172 Collection::List collectionList; 0173 collectionList << rootCollection; 0174 0175 StateMap map; 0176 map.insert(StandardActionManager::CreateCollection, false); 0177 map.insert(StandardActionManager::CopyCollections, false); 0178 map.insert(StandardActionManager::DeleteCollections, false); 0179 map.insert(StandardActionManager::SynchronizeCollections, false); 0180 map.insert(StandardActionManager::CollectionProperties, false); 0181 map.insert(StandardActionManager::CopyItems, false); 0182 map.insert(StandardActionManager::Paste, false); 0183 map.insert(StandardActionManager::DeleteItems, false); 0184 map.insert(StandardActionManager::AddToFavoriteCollections, false); 0185 map.insert(StandardActionManager::RemoveFromFavoriteCollections, false); 0186 map.insert(StandardActionManager::RenameFavoriteCollection, false); 0187 map.insert(StandardActionManager::CopyCollectionToMenu, false); 0188 map.insert(StandardActionManager::CopyItemToMenu, false); 0189 map.insert(StandardActionManager::MoveItemToMenu, false); 0190 map.insert(StandardActionManager::MoveCollectionToMenu, false); 0191 map.insert(StandardActionManager::CutItems, false); 0192 map.insert(StandardActionManager::CutCollections, false); 0193 map.insert(StandardActionManager::CreateResource, true); 0194 map.insert(StandardActionManager::DeleteResources, false); 0195 map.insert(StandardActionManager::ResourceProperties, false); 0196 map.insert(StandardActionManager::SynchronizeResources, false); 0197 map.insert(StandardActionManager::MoveItemToDialog, false); 0198 map.insert(StandardActionManager::CopyItemToDialog, false); 0199 map.insert(StandardActionManager::CopyCollectionToDialog, false); 0200 map.insert(StandardActionManager::MoveCollectionToDialog, false); 0201 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, false); 0202 map.insert(StandardActionManager::MoveCollectionsToTrash, false); 0203 map.insert(StandardActionManager::MoveItemsToTrash, false); 0204 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0205 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0206 map.insert(StandardActionManager::MoveToTrashRestoreCollection, false); 0207 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0208 map.insert(StandardActionManager::SynchronizeCollectionTree, false); 0209 0210 QTest::newRow("root collection selected") << collectionList << map; 0211 } 0212 0213 { 0214 Collection::List collectionList; 0215 collectionList << resourceCollectionOne; 0216 0217 StateMap map; 0218 map.insert(StandardActionManager::CreateCollection, false); 0219 map.insert(StandardActionManager::CopyCollections, true); 0220 map.insert(StandardActionManager::DeleteCollections, false); 0221 map.insert(StandardActionManager::SynchronizeCollections, true); 0222 map.insert(StandardActionManager::CollectionProperties, true); 0223 map.insert(StandardActionManager::CopyItems, false); 0224 map.insert(StandardActionManager::Paste, false); 0225 map.insert(StandardActionManager::DeleteItems, false); 0226 map.insert(StandardActionManager::AddToFavoriteCollections, true); 0227 map.insert(StandardActionManager::RemoveFromFavoriteCollections, false); 0228 map.insert(StandardActionManager::RenameFavoriteCollection, false); 0229 map.insert(StandardActionManager::CopyCollectionToMenu, true); 0230 map.insert(StandardActionManager::CopyItemToMenu, false); 0231 map.insert(StandardActionManager::MoveItemToMenu, false); 0232 map.insert(StandardActionManager::MoveCollectionToMenu, false); 0233 map.insert(StandardActionManager::CutItems, false); 0234 map.insert(StandardActionManager::CutCollections, false); 0235 map.insert(StandardActionManager::CreateResource, true); 0236 map.insert(StandardActionManager::DeleteResources, true); 0237 map.insert(StandardActionManager::ResourceProperties, true); 0238 map.insert(StandardActionManager::SynchronizeResources, true); 0239 map.insert(StandardActionManager::MoveItemToDialog, false); 0240 map.insert(StandardActionManager::CopyItemToDialog, false); 0241 map.insert(StandardActionManager::CopyCollectionToDialog, true); 0242 map.insert(StandardActionManager::MoveCollectionToDialog, false); 0243 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, true); 0244 map.insert(StandardActionManager::MoveCollectionsToTrash, false); 0245 map.insert(StandardActionManager::MoveItemsToTrash, false); 0246 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0247 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0248 map.insert(StandardActionManager::MoveToTrashRestoreCollection, false); 0249 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0250 map.insert(StandardActionManager::SynchronizeCollectionTree, true); 0251 0252 QTest::newRow("read-only resource collection selected") << collectionList << map; 0253 } 0254 0255 { 0256 Collection::List collectionList; 0257 collectionList << resourceCollectionTwo; 0258 0259 StateMap map; 0260 map.insert(StandardActionManager::CreateCollection, true); 0261 map.insert(StandardActionManager::CopyCollections, true); 0262 map.insert(StandardActionManager::DeleteCollections, false); 0263 map.insert(StandardActionManager::SynchronizeCollections, true); 0264 map.insert(StandardActionManager::CollectionProperties, true); 0265 map.insert(StandardActionManager::CopyItems, false); 0266 map.insert(StandardActionManager::Paste, false); 0267 map.insert(StandardActionManager::DeleteItems, false); 0268 map.insert(StandardActionManager::AddToFavoriteCollections, true); 0269 map.insert(StandardActionManager::RemoveFromFavoriteCollections, false); 0270 map.insert(StandardActionManager::RenameFavoriteCollection, false); 0271 map.insert(StandardActionManager::CopyCollectionToMenu, true); 0272 map.insert(StandardActionManager::CopyItemToMenu, false); 0273 map.insert(StandardActionManager::MoveItemToMenu, false); 0274 map.insert(StandardActionManager::MoveCollectionToMenu, false); 0275 map.insert(StandardActionManager::CutItems, false); 0276 map.insert(StandardActionManager::CutCollections, false); 0277 map.insert(StandardActionManager::CreateResource, true); 0278 map.insert(StandardActionManager::DeleteResources, true); 0279 map.insert(StandardActionManager::ResourceProperties, true); 0280 map.insert(StandardActionManager::SynchronizeResources, true); 0281 map.insert(StandardActionManager::MoveItemToDialog, false); 0282 map.insert(StandardActionManager::CopyItemToDialog, false); 0283 map.insert(StandardActionManager::CopyCollectionToDialog, true); 0284 map.insert(StandardActionManager::MoveCollectionToDialog, false); 0285 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, true); 0286 map.insert(StandardActionManager::MoveCollectionsToTrash, false); 0287 map.insert(StandardActionManager::MoveItemsToTrash, false); 0288 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0289 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0290 map.insert(StandardActionManager::MoveToTrashRestoreCollection, false); 0291 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0292 map.insert(StandardActionManager::SynchronizeCollectionTree, true); 0293 0294 QTest::newRow("writable resource collection selected") << collectionList << map; 0295 } 0296 0297 { 0298 Collection::List collectionList; 0299 collectionList << resourceCollectionThree; 0300 0301 StateMap map; 0302 map.insert(StandardActionManager::CreateCollection, true); 0303 map.insert(StandardActionManager::CopyCollections, true); 0304 map.insert(StandardActionManager::DeleteCollections, false); 0305 map.insert(StandardActionManager::SynchronizeCollections, true); 0306 map.insert(StandardActionManager::CollectionProperties, true); 0307 map.insert(StandardActionManager::CopyItems, false); 0308 map.insert(StandardActionManager::Paste, false); 0309 map.insert(StandardActionManager::DeleteItems, false); 0310 map.insert(StandardActionManager::AddToFavoriteCollections, true); 0311 map.insert(StandardActionManager::RemoveFromFavoriteCollections, false); 0312 map.insert(StandardActionManager::RenameFavoriteCollection, false); 0313 map.insert(StandardActionManager::CopyCollectionToMenu, true); 0314 map.insert(StandardActionManager::CopyItemToMenu, false); 0315 map.insert(StandardActionManager::MoveItemToMenu, false); 0316 map.insert(StandardActionManager::MoveCollectionToMenu, false); 0317 map.insert(StandardActionManager::CutItems, false); 0318 map.insert(StandardActionManager::CutCollections, false); 0319 map.insert(StandardActionManager::CreateResource, true); 0320 map.insert(StandardActionManager::DeleteResources, true); 0321 map.insert(StandardActionManager::ResourceProperties, false); 0322 map.insert(StandardActionManager::SynchronizeResources, true); 0323 map.insert(StandardActionManager::MoveItemToDialog, false); 0324 map.insert(StandardActionManager::CopyItemToDialog, false); 0325 map.insert(StandardActionManager::CopyCollectionToDialog, true); 0326 map.insert(StandardActionManager::MoveCollectionToDialog, false); 0327 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, true); 0328 map.insert(StandardActionManager::MoveCollectionsToTrash, false); 0329 map.insert(StandardActionManager::MoveItemsToTrash, false); 0330 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0331 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0332 map.insert(StandardActionManager::MoveToTrashRestoreCollection, false); 0333 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0334 map.insert(StandardActionManager::SynchronizeCollectionTree, true); 0335 0336 QTest::newRow("non-configurable resource collection selected") << collectionList << map; 0337 } 0338 0339 { 0340 Collection::List collectionList; 0341 collectionList << folderCollectionOne; 0342 0343 StateMap map; 0344 map.insert(StandardActionManager::CreateCollection, false); 0345 map.insert(StandardActionManager::CopyCollections, true); 0346 map.insert(StandardActionManager::DeleteCollections, false); 0347 map.insert(StandardActionManager::SynchronizeCollections, true); 0348 map.insert(StandardActionManager::CollectionProperties, true); 0349 map.insert(StandardActionManager::CopyItems, false); 0350 map.insert(StandardActionManager::Paste, false); 0351 map.insert(StandardActionManager::DeleteItems, false); 0352 map.insert(StandardActionManager::AddToFavoriteCollections, true); 0353 map.insert(StandardActionManager::RemoveFromFavoriteCollections, false); 0354 map.insert(StandardActionManager::RenameFavoriteCollection, false); 0355 map.insert(StandardActionManager::CopyCollectionToMenu, true); 0356 map.insert(StandardActionManager::CopyItemToMenu, false); 0357 map.insert(StandardActionManager::MoveItemToMenu, false); 0358 map.insert(StandardActionManager::MoveCollectionToMenu, false); 0359 map.insert(StandardActionManager::CutItems, false); 0360 map.insert(StandardActionManager::CutCollections, false); 0361 map.insert(StandardActionManager::CreateResource, true); 0362 map.insert(StandardActionManager::DeleteResources, false); 0363 map.insert(StandardActionManager::ResourceProperties, false); 0364 map.insert(StandardActionManager::SynchronizeResources, false); 0365 map.insert(StandardActionManager::MoveItemToDialog, false); 0366 map.insert(StandardActionManager::CopyItemToDialog, false); 0367 map.insert(StandardActionManager::CopyCollectionToDialog, true); 0368 map.insert(StandardActionManager::MoveCollectionToDialog, false); 0369 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, true); 0370 map.insert(StandardActionManager::MoveCollectionsToTrash, false); 0371 map.insert(StandardActionManager::MoveItemsToTrash, false); 0372 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0373 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0374 map.insert(StandardActionManager::MoveToTrashRestoreCollection, false); 0375 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0376 map.insert(StandardActionManager::SynchronizeCollectionTree, false); 0377 0378 QTest::newRow("read-only folder collection selected") << collectionList << map; 0379 } 0380 0381 { 0382 Collection::List collectionList; 0383 collectionList << folderCollectionTwo; 0384 0385 StateMap map; 0386 map.insert(StandardActionManager::CreateCollection, true); 0387 map.insert(StandardActionManager::CopyCollections, true); 0388 map.insert(StandardActionManager::DeleteCollections, true); 0389 map.insert(StandardActionManager::SynchronizeCollections, true); 0390 map.insert(StandardActionManager::CollectionProperties, true); 0391 map.insert(StandardActionManager::CopyItems, false); 0392 map.insert(StandardActionManager::Paste, false); 0393 map.insert(StandardActionManager::DeleteItems, false); 0394 map.insert(StandardActionManager::AddToFavoriteCollections, true); 0395 map.insert(StandardActionManager::RemoveFromFavoriteCollections, false); 0396 map.insert(StandardActionManager::RenameFavoriteCollection, false); 0397 map.insert(StandardActionManager::CopyCollectionToMenu, true); 0398 map.insert(StandardActionManager::CopyItemToMenu, false); 0399 map.insert(StandardActionManager::MoveItemToMenu, false); 0400 map.insert(StandardActionManager::MoveCollectionToMenu, true); 0401 map.insert(StandardActionManager::CutItems, false); 0402 map.insert(StandardActionManager::CutCollections, true); 0403 map.insert(StandardActionManager::CreateResource, true); 0404 map.insert(StandardActionManager::DeleteResources, false); 0405 map.insert(StandardActionManager::ResourceProperties, false); 0406 map.insert(StandardActionManager::SynchronizeResources, false); 0407 map.insert(StandardActionManager::MoveItemToDialog, false); 0408 map.insert(StandardActionManager::CopyItemToDialog, false); 0409 map.insert(StandardActionManager::CopyCollectionToDialog, true); 0410 map.insert(StandardActionManager::MoveCollectionToDialog, true); 0411 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, true); 0412 map.insert(StandardActionManager::MoveCollectionsToTrash, true); 0413 map.insert(StandardActionManager::MoveItemsToTrash, false); 0414 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0415 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0416 map.insert(StandardActionManager::MoveToTrashRestoreCollection, true); 0417 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0418 map.insert(StandardActionManager::SynchronizeCollectionTree, false); 0419 0420 QTest::newRow("writable folder collection selected") << collectionList << map; 0421 } 0422 0423 { 0424 Collection::List collectionList; 0425 collectionList << folderCollectionThree; 0426 0427 StateMap map; 0428 map.insert(StandardActionManager::CreateCollection, true); 0429 map.insert(StandardActionManager::CopyCollections, true); 0430 map.insert(StandardActionManager::DeleteCollections, true); 0431 map.insert(StandardActionManager::SynchronizeCollections, true); 0432 map.insert(StandardActionManager::CollectionProperties, true); 0433 map.insert(StandardActionManager::CopyItems, false); 0434 map.insert(StandardActionManager::Paste, false); 0435 map.insert(StandardActionManager::DeleteItems, false); 0436 map.insert(StandardActionManager::AddToFavoriteCollections, false); 0437 map.insert(StandardActionManager::RemoveFromFavoriteCollections, true); 0438 map.insert(StandardActionManager::RenameFavoriteCollection, true); 0439 map.insert(StandardActionManager::CopyCollectionToMenu, true); 0440 map.insert(StandardActionManager::CopyItemToMenu, false); 0441 map.insert(StandardActionManager::MoveItemToMenu, false); 0442 map.insert(StandardActionManager::MoveCollectionToMenu, true); 0443 map.insert(StandardActionManager::CutItems, false); 0444 map.insert(StandardActionManager::CutCollections, true); 0445 map.insert(StandardActionManager::CreateResource, true); 0446 map.insert(StandardActionManager::DeleteResources, false); 0447 map.insert(StandardActionManager::ResourceProperties, false); 0448 map.insert(StandardActionManager::SynchronizeResources, false); 0449 map.insert(StandardActionManager::MoveItemToDialog, false); 0450 map.insert(StandardActionManager::CopyItemToDialog, false); 0451 map.insert(StandardActionManager::CopyCollectionToDialog, true); 0452 map.insert(StandardActionManager::MoveCollectionToDialog, true); 0453 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, true); 0454 map.insert(StandardActionManager::MoveCollectionsToTrash, true); 0455 map.insert(StandardActionManager::MoveItemsToTrash, false); 0456 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0457 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0458 map.insert(StandardActionManager::MoveToTrashRestoreCollection, true); 0459 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0460 map.insert(StandardActionManager::SynchronizeCollectionTree, false); 0461 0462 QTest::newRow("favorite writable folder collection selected") << collectionList << map; 0463 } 0464 0465 { 0466 Collection::List collectionList; 0467 collectionList << folderCollectionThreeOne; 0468 0469 StateMap map; 0470 map.insert(StandardActionManager::CreateCollection, false); // content mimetype is missing 0471 map.insert(StandardActionManager::CopyCollections, true); 0472 map.insert(StandardActionManager::DeleteCollections, true); 0473 map.insert(StandardActionManager::SynchronizeCollections, false); 0474 map.insert(StandardActionManager::CollectionProperties, true); 0475 map.insert(StandardActionManager::CopyItems, false); 0476 map.insert(StandardActionManager::Paste, false); 0477 map.insert(StandardActionManager::DeleteItems, false); 0478 map.insert(StandardActionManager::AddToFavoriteCollections, false); // content mimetype is missing 0479 map.insert(StandardActionManager::RemoveFromFavoriteCollections, false); 0480 map.insert(StandardActionManager::RenameFavoriteCollection, false); 0481 map.insert(StandardActionManager::CopyCollectionToMenu, true); 0482 map.insert(StandardActionManager::CopyItemToMenu, false); 0483 map.insert(StandardActionManager::MoveItemToMenu, false); 0484 map.insert(StandardActionManager::MoveCollectionToMenu, true); 0485 map.insert(StandardActionManager::CutItems, false); 0486 map.insert(StandardActionManager::CutCollections, true); 0487 map.insert(StandardActionManager::CreateResource, true); 0488 map.insert(StandardActionManager::DeleteResources, false); 0489 map.insert(StandardActionManager::ResourceProperties, false); 0490 map.insert(StandardActionManager::SynchronizeResources, false); 0491 map.insert(StandardActionManager::MoveItemToDialog, false); 0492 map.insert(StandardActionManager::CopyItemToDialog, false); 0493 map.insert(StandardActionManager::CopyCollectionToDialog, true); 0494 map.insert(StandardActionManager::MoveCollectionToDialog, true); 0495 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, true); 0496 map.insert(StandardActionManager::MoveCollectionsToTrash, true); 0497 map.insert(StandardActionManager::MoveItemsToTrash, false); 0498 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0499 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0500 map.insert(StandardActionManager::MoveToTrashRestoreCollection, true); 0501 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0502 map.insert(StandardActionManager::SynchronizeCollectionTree, false); 0503 0504 QTest::newRow("structural folder collection selected") << collectionList << map; 0505 } 0506 0507 // multiple collections 0508 { 0509 Collection::List collectionList; 0510 collectionList << rootCollection << resourceCollectionTwo; 0511 0512 StateMap map; 0513 map.insert(StandardActionManager::CreateCollection, false); 0514 map.insert(StandardActionManager::CopyCollections, false); 0515 map.insert(StandardActionManager::DeleteCollections, false); 0516 map.insert(StandardActionManager::SynchronizeCollections, true); 0517 map.insert(StandardActionManager::CollectionProperties, false); 0518 map.insert(StandardActionManager::CopyItems, false); 0519 map.insert(StandardActionManager::Paste, false); 0520 map.insert(StandardActionManager::DeleteItems, false); 0521 map.insert(StandardActionManager::AddToFavoriteCollections, false); 0522 map.insert(StandardActionManager::RemoveFromFavoriteCollections, false); 0523 map.insert(StandardActionManager::RenameFavoriteCollection, false); 0524 map.insert(StandardActionManager::CopyCollectionToMenu, false); 0525 map.insert(StandardActionManager::CopyItemToMenu, false); 0526 map.insert(StandardActionManager::MoveItemToMenu, false); 0527 map.insert(StandardActionManager::MoveCollectionToMenu, false); 0528 map.insert(StandardActionManager::CutItems, false); 0529 map.insert(StandardActionManager::CutCollections, false); 0530 map.insert(StandardActionManager::CreateResource, true); 0531 map.insert(StandardActionManager::DeleteResources, false); 0532 map.insert(StandardActionManager::ResourceProperties, false); 0533 map.insert(StandardActionManager::SynchronizeResources, false); 0534 map.insert(StandardActionManager::MoveItemToDialog, false); 0535 map.insert(StandardActionManager::CopyItemToDialog, false); 0536 map.insert(StandardActionManager::CopyCollectionToDialog, false); 0537 map.insert(StandardActionManager::MoveCollectionToDialog, false); 0538 map.insert(StandardActionManager::SynchronizeCollectionsRecursive, false); 0539 map.insert(StandardActionManager::MoveCollectionsToTrash, false); 0540 map.insert(StandardActionManager::MoveItemsToTrash, false); 0541 map.insert(StandardActionManager::RestoreCollectionsFromTrash, false); 0542 map.insert(StandardActionManager::RestoreItemsFromTrash, false); 0543 map.insert(StandardActionManager::MoveToTrashRestoreCollection, false); 0544 map.insert(StandardActionManager::MoveToTrashRestoreItem, false); 0545 map.insert(StandardActionManager::SynchronizeCollectionTree, false); 0546 0547 QTest::newRow("root collection and writable resource collection selected") << collectionList << map; 0548 } 0549 } 0550 0551 void testCollectionSelected() 0552 { 0553 QFETCH(Collection::List, collections); 0554 QFETCH(StateMap, stateMap); 0555 0556 UnitActionStateManager manager(this); 0557 Collection::List favoriteCollections; 0558 if (collections.contains(folderCollectionThree)) { 0559 favoriteCollections << folderCollectionThree; 0560 } 0561 0562 manager.updateState(collections, favoriteCollections, Item::List()); 0563 0564 QCOMPARE(stateMap.count(), mStateMap.count()); 0565 0566 QHashIterator<StandardActionManager::Type, bool> it(stateMap); 0567 while (it.hasNext()) { 0568 it.next(); 0569 // qDebug() << it.key(); 0570 QVERIFY(mStateMap.contains(it.key())); 0571 const bool expected = mStateMap.value(it.key()); 0572 if (it.value() != expected) { 0573 qWarning() << "Wrong state for" << it.key(); 0574 } 0575 QCOMPARE(it.value(), expected); 0576 } 0577 } 0578 0579 private: 0580 /** 0581 * The structure of our fake collections: 0582 * 0583 * rootCollection 0584 * | 0585 * +- resourceCollectionOne 0586 * | | 0587 * | `folderCollectionOne 0588 * | 0589 * +- resourceCollectionTwo 0590 * | | 0591 * | `folderCollectionTwo 0592 * | 0593 * `- resourceCollectionThree 0594 * | 0595 * +-folderCollectionThree 0596 * | 0597 * `-folderCollectionThreeOne 0598 */ 0599 Collection rootCollection; 0600 Collection resourceCollectionOne; 0601 Collection resourceCollectionTwo; 0602 Collection resourceCollectionThree; 0603 Collection folderCollectionOne; 0604 Collection folderCollectionTwo; 0605 Collection folderCollectionThree; 0606 Collection folderCollectionThreeOne; 0607 0608 StateMap mStateMap; 0609 QHash<QString, Collection::List> mCapabilityMap; 0610 QSet<qlonglong> mFavoriteCollectionMap; 0611 }; 0612 0613 UnitActionStateManager::UnitActionStateManager(ActionStateManagerTest *receiver) 0614 : mReceiver(receiver) 0615 { 0616 setReceiver(receiver); 0617 } 0618 0619 bool UnitActionStateManager::hasResourceCapability(const Collection &collection, const QString &capability) const 0620 { 0621 return mReceiver->hasResourceCapability(collection, capability); 0622 } 0623 0624 QTEST_AKONADIMAIN(ActionStateManagerTest) 0625 0626 #include "actionstatemanagertest.moc"