Changeset View
Changeset View
Standalone View
Standalone View
autotests/kfileplacesmodeltest.cpp
Show All 22 Lines | |||||
23 | 23 | | |||
24 | #include <kbookmarkmanager.h> | 24 | #include <kbookmarkmanager.h> | ||
25 | #include <kbookmark.h> | 25 | #include <kbookmark.h> | ||
26 | #include <QDebug> | 26 | #include <QDebug> | ||
27 | #include <kfileplacesmodel.h> | 27 | #include <kfileplacesmodel.h> | ||
28 | #include <solid/device.h> | 28 | #include <solid/device.h> | ||
29 | #include <kconfig.h> | 29 | #include <kconfig.h> | ||
30 | #include <kconfiggroup.h> | 30 | #include <kconfiggroup.h> | ||
31 | #include <KProtocolInfo> | ||||
31 | 32 | | |||
32 | #include <QtTest> | 33 | #include <QtTest> | ||
33 | 34 | | |||
34 | #include <stdlib.h> | 35 | #include <stdlib.h> | ||
35 | #include <qstandardpaths.h> | 36 | #include <qstandardpaths.h> | ||
36 | 37 | | |||
37 | Q_DECLARE_METATYPE(KFilePlacesModel::GroupType) | 38 | Q_DECLARE_METATYPE(KFilePlacesModel::GroupType) | ||
38 | 39 | | |||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 88 | private: | |||
91 | 92 | | |||
92 | KFilePlacesModel *m_places; | 93 | KFilePlacesModel *m_places; | ||
93 | KFilePlacesModel *m_places2; // To check that they always stay in sync | 94 | KFilePlacesModel *m_places2; // To check that they always stay in sync | ||
94 | // actually supposed to work across processes, | 95 | // actually supposed to work across processes, | ||
95 | // but much harder to test | 96 | // but much harder to test | ||
96 | 97 | | |||
97 | QMap<QString, QDBusInterface *> m_interfacesMap; | 98 | QMap<QString, QDBusInterface *> m_interfacesMap; | ||
98 | QTemporaryDir m_tmpHome; | 99 | QTemporaryDir m_tmpHome; | ||
100 | bool m_hasRecentlyUsedKio; | ||||
99 | }; | 101 | }; | ||
100 | 102 | | |||
101 | static QString bookmarksFile() | 103 | static QString bookmarksFile() | ||
102 | { | 104 | { | ||
103 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/user-places.xbel"); | 105 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/user-places.xbel"); | ||
104 | } | 106 | } | ||
105 | 107 | | |||
106 | void KFilePlacesModelTest::initTestCase() | 108 | void KFilePlacesModelTest::initTestCase() | ||
Show All 16 Lines | 109 | { | |||
123 | qRegisterMetaType<QModelIndex>(); | 125 | qRegisterMetaType<QModelIndex>(); | ||
124 | qRegisterMetaType<KFilePlacesModel::GroupType>(); | 126 | qRegisterMetaType<KFilePlacesModel::GroupType>(); | ||
125 | 127 | | |||
126 | const QString fakeHw = QFINDTESTDATA("fakecomputer.xml"); | 128 | const QString fakeHw = QFINDTESTDATA("fakecomputer.xml"); | ||
127 | QVERIFY(!fakeHw.isEmpty()); | 129 | QVERIFY(!fakeHw.isEmpty()); | ||
128 | qputenv("SOLID_FAKEHW", QFile::encodeName(fakeHw)); | 130 | qputenv("SOLID_FAKEHW", QFile::encodeName(fakeHw)); | ||
129 | m_places = new KFilePlacesModel(); | 131 | m_places = new KFilePlacesModel(); | ||
130 | m_places2 = new KFilePlacesModel(); | 132 | m_places2 = new KFilePlacesModel(); | ||
133 | | ||||
134 | m_hasRecentlyUsedKio = qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")); | ||||
131 | } | 135 | } | ||
132 | 136 | | |||
133 | void KFilePlacesModelTest::cleanupTestCase() | 137 | void KFilePlacesModelTest::cleanupTestCase() | ||
134 | { | 138 | { | ||
135 | delete m_places; | 139 | delete m_places; | ||
136 | delete m_places2; | 140 | delete m_places2; | ||
137 | qDeleteAll(m_interfacesMap); | 141 | qDeleteAll(m_interfacesMap); | ||
138 | QFile::remove(bookmarksFile()); | 142 | QFile::remove(bookmarksFile()); | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 188 | { | |||
190 | QDBusInterface *iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), udi); | 194 | QDBusInterface *iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), udi); | ||
191 | m_interfacesMap[udi] = iface; | 195 | m_interfacesMap[udi] = iface; | ||
192 | 196 | | |||
193 | return iface; | 197 | return iface; | ||
194 | } | 198 | } | ||
195 | 199 | | |||
196 | void KFilePlacesModelTest::testInitialState() | 200 | void KFilePlacesModelTest::testInitialState() | ||
197 | { | 201 | { | ||
198 | QCOMPARE(m_places->rowCount(), 3); // when the xbel file is empty, KFilePlacesModel fills it with 3 default items | 202 | QCOMPARE(m_places->rowCount(), m_hasRecentlyUsedKio ? 5 : 3); // when the xbel file is empty, KFilePlacesModel fills it with 3 default items | ||
203 | // 4 when ioslave recentlyused:/ is installed | ||||
199 | QCoreApplication::processEvents(); // Devices have a delayed loading | 204 | QCoreApplication::processEvents(); // Devices have a delayed loading | ||
200 | QCOMPARE(m_places->rowCount(), 8); | 205 | QCOMPARE(m_places->rowCount(), m_hasRecentlyUsedKio ? 10 : 8); | ||
201 | } | 206 | } | ||
202 | 207 | | |||
203 | static const QStringList initialListOfPlaces() | 208 | static const QStringList initialListOfPlaces() | ||
204 | { | 209 | { | ||
205 | return QStringList() << QDir::homePath() << QStringLiteral("trash:/"); | 210 | return QStringList() << QDir::homePath() << QStringLiteral("trash:/"); | ||
206 | } | 211 | } | ||
207 | 212 | | |||
208 | static const QStringList initialListOfShared() | 213 | static const QStringList initialListOfShared() | ||
209 | { | 214 | { | ||
210 | return QStringList() << QStringLiteral("remote:/") << QStringLiteral("/media/nfs"); | 215 | return QStringList() << QStringLiteral("remote:/") << QStringLiteral("/media/nfs"); | ||
211 | } | 216 | } | ||
212 | 217 | | |||
218 | static const QStringList initialListOfRecent() | ||||
219 | { | ||||
220 | auto list = QStringList(); | ||||
221 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused"))) { | ||||
222 | list << QStringLiteral("recentlyused:/files"); | ||||
223 | list << QStringLiteral("recentlyused:/locations"); | ||||
224 | } | ||||
225 | return list; | ||||
226 | } | ||||
227 | | ||||
213 | static const QStringList initialListOfDevices() | 228 | static const QStringList initialListOfDevices() | ||
214 | { | 229 | { | ||
215 | return QStringList() << QStringLiteral("/foreign"); | 230 | return QStringList() << QStringLiteral("/foreign"); | ||
216 | } | 231 | } | ||
217 | 232 | | |||
218 | static const QStringList initialListOfRemovableDevices() | 233 | static const QStringList initialListOfRemovableDevices() | ||
219 | { | 234 | { | ||
220 | return QStringList() << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | 235 | return QStringList() << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | ||
221 | } | 236 | } | ||
222 | 237 | | |||
223 | static const QStringList initialListOfUrls() | 238 | static const QStringList initialListOfUrls() | ||
224 | { | 239 | { | ||
225 | return QStringList() << initialListOfPlaces() | 240 | return QStringList() << initialListOfPlaces() | ||
226 | << initialListOfShared() | 241 | << initialListOfShared() | ||
242 | << initialListOfRecent() | ||||
227 | << initialListOfDevices() | 243 | << initialListOfDevices() | ||
228 | << initialListOfRemovableDevices(); | 244 | << initialListOfRemovableDevices(); | ||
229 | } | 245 | } | ||
230 | 246 | | |||
231 | void KFilePlacesModelTest::testInitialList() | 247 | void KFilePlacesModelTest::testInitialList() | ||
232 | { | 248 | { | ||
233 | const QStringList urls = initialListOfUrls(); | 249 | const QStringList urls = initialListOfUrls(); | ||
234 | CHECK_PLACES_URLS(urls); | 250 | CHECK_PLACES_URLS(urls); | ||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Line(s) | 405 | while (!root.next(last).isNull()) { | |||
390 | last = root.next(last); | 406 | last = root.next(last); | ||
391 | } | 407 | } | ||
392 | root.moveBookmark(system_home, last); | 408 | root.moveBookmark(system_home, last); | ||
393 | bookmarkManager->emitChanged(root); | 409 | bookmarkManager->emitChanged(root); | ||
394 | 410 | | |||
395 | QStringList urls; | 411 | QStringList urls; | ||
396 | urls << QStringLiteral("trash:/") << QDir::homePath() | 412 | urls << QStringLiteral("trash:/") << QDir::homePath() | ||
397 | << initialListOfShared() | 413 | << initialListOfShared() | ||
414 | << initialListOfRecent() | ||||
398 | << initialListOfDevices() | 415 | << initialListOfDevices() | ||
399 | << initialListOfRemovableDevices(); | 416 | << initialListOfRemovableDevices(); | ||
400 | 417 | | |||
401 | CHECK_PLACES_URLS(urls); | 418 | CHECK_PLACES_URLS(urls); | ||
402 | QCOMPARE(spy_inserted.count(), 1); | 419 | QCOMPARE(spy_inserted.count(), 1); | ||
403 | args = spy_inserted.takeFirst(); | 420 | args = spy_inserted.takeFirst(); | ||
404 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 421 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
405 | QCOMPARE(args.at(1).toInt(), 1); | 422 | QCOMPARE(args.at(1).toInt(), 1); | ||
406 | QCOMPARE(args.at(2).toInt(), 1); | 423 | QCOMPARE(args.at(2).toInt(), 1); | ||
407 | QCOMPARE(spy_removed.count(), 1); | 424 | QCOMPARE(spy_removed.count(), 1); | ||
408 | args = spy_removed.takeFirst(); | 425 | args = spy_removed.takeFirst(); | ||
409 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 426 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
410 | QCOMPARE(args.at(1).toInt(), 0); | 427 | QCOMPARE(args.at(1).toInt(), 0); | ||
411 | QCOMPARE(args.at(2).toInt(), 0); | 428 | QCOMPARE(args.at(2).toInt(), 0); | ||
412 | 429 | | |||
413 | // Move home at the beginning of the list (at its original place) | 430 | // Move home at the beginning of the list (at its original place) | ||
414 | root.moveBookmark(system_home, KBookmark()); | 431 | root.moveBookmark(system_home, KBookmark()); | ||
415 | bookmarkManager->emitChanged(root); | 432 | bookmarkManager->emitChanged(root); | ||
416 | urls.clear(); | 433 | urls.clear(); | ||
417 | urls << initialListOfPlaces() | 434 | urls << initialListOfPlaces() | ||
418 | << initialListOfShared() | 435 | << initialListOfShared() | ||
436 | << initialListOfRecent() | ||||
419 | << initialListOfDevices() | 437 | << initialListOfDevices() | ||
420 | << initialListOfRemovableDevices(); | 438 | << initialListOfRemovableDevices(); | ||
421 | CHECK_PLACES_URLS(urls); | 439 | CHECK_PLACES_URLS(urls); | ||
422 | QCOMPARE(spy_inserted.count(), 1); | 440 | QCOMPARE(spy_inserted.count(), 1); | ||
423 | args = spy_inserted.takeFirst(); | 441 | args = spy_inserted.takeFirst(); | ||
424 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 442 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
425 | QCOMPARE(args.at(1).toInt(), 1); | 443 | QCOMPARE(args.at(1).toInt(), 1); | ||
426 | QCOMPARE(args.at(2).toInt(), 1); | 444 | QCOMPARE(args.at(2).toInt(), 1); | ||
Show All 20 Lines | 454 | { | |||
447 | QModelIndexList indexes; | 465 | QModelIndexList indexes; | ||
448 | indexes << m_places->index(0, 0); | 466 | indexes << m_places->index(0, 0); | ||
449 | QMimeData *mimeData = m_places->mimeData(indexes); | 467 | QMimeData *mimeData = m_places->mimeData(indexes); | ||
450 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 2, 0, QModelIndex())); | 468 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 2, 0, QModelIndex())); | ||
451 | 469 | | |||
452 | QStringList urls; | 470 | QStringList urls; | ||
453 | urls << QStringLiteral("trash:/") << QDir::homePath() | 471 | urls << QStringLiteral("trash:/") << QDir::homePath() | ||
454 | << initialListOfShared() | 472 | << initialListOfShared() | ||
473 | << initialListOfRecent() | ||||
455 | << initialListOfDevices() | 474 | << initialListOfDevices() | ||
456 | << initialListOfRemovableDevices(); | 475 | << initialListOfRemovableDevices(); | ||
457 | CHECK_PLACES_URLS(urls); | 476 | CHECK_PLACES_URLS(urls); | ||
458 | QCOMPARE(spy_inserted.count(), 0); | 477 | QCOMPARE(spy_inserted.count(), 0); | ||
459 | QCOMPARE(spy_removed.count(), 0); | 478 | QCOMPARE(spy_removed.count(), 0); | ||
460 | QCOMPARE(spy_moved.count(), 1); | 479 | QCOMPARE(spy_moved.count(), 1); | ||
461 | args = spy_moved.takeFirst(); | 480 | args = spy_moved.takeFirst(); | ||
462 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 481 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
463 | QCOMPARE(args.at(1).toInt(), 0); | 482 | QCOMPARE(args.at(1).toInt(), 0); | ||
464 | QCOMPARE(args.at(2).toInt(), 0); | 483 | QCOMPARE(args.at(2).toInt(), 0); | ||
465 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | 484 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | ||
466 | QCOMPARE(args.at(4).toInt(), 2); | 485 | QCOMPARE(args.at(4).toInt(), 2); | ||
467 | 486 | | |||
468 | // Move home back at the beginning of the list | 487 | // Move home back at the beginning of the list | ||
469 | indexes.clear(); | 488 | indexes.clear(); | ||
470 | indexes << m_places->index(1, 0); | 489 | indexes << m_places->index(1, 0); | ||
471 | mimeData = m_places->mimeData(indexes); | 490 | mimeData = m_places->mimeData(indexes); | ||
472 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 0, 0, QModelIndex())); | 491 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 0, 0, QModelIndex())); | ||
473 | 492 | | |||
474 | urls.clear(); | 493 | urls.clear(); | ||
475 | urls << QDir::homePath() << QStringLiteral("trash:/") | 494 | urls << QDir::homePath() << QStringLiteral("trash:/") | ||
476 | << initialListOfShared() | 495 | << initialListOfShared() | ||
496 | << initialListOfRecent() | ||||
477 | << initialListOfDevices() | 497 | << initialListOfDevices() | ||
478 | << initialListOfRemovableDevices(); | 498 | << initialListOfRemovableDevices(); | ||
479 | CHECK_PLACES_URLS(urls); | 499 | CHECK_PLACES_URLS(urls); | ||
480 | QCOMPARE(spy_inserted.count(), 0); | 500 | QCOMPARE(spy_inserted.count(), 0); | ||
481 | QCOMPARE(spy_removed.count(), 0); | 501 | QCOMPARE(spy_removed.count(), 0); | ||
482 | QCOMPARE(spy_moved.count(), 1); | 502 | QCOMPARE(spy_moved.count(), 1); | ||
483 | args = spy_moved.takeFirst(); | 503 | args = spy_moved.takeFirst(); | ||
484 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 504 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
Show All 20 Lines | 522 | { | |||
505 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | 525 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | ||
506 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | 526 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | ||
507 | 527 | | |||
508 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo"))); | 528 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo"))); | ||
509 | 529 | | |||
510 | QStringList urls; | 530 | QStringList urls; | ||
511 | urls << initialListOfPlaces() << QStringLiteral("/home/foo") | 531 | urls << initialListOfPlaces() << QStringLiteral("/home/foo") | ||
512 | << initialListOfShared() | 532 | << initialListOfShared() | ||
533 | << initialListOfRecent() | ||||
513 | << initialListOfDevices() | 534 | << initialListOfDevices() | ||
514 | << initialListOfRemovableDevices(); | 535 | << initialListOfRemovableDevices(); | ||
515 | CHECK_PLACES_URLS(urls); | 536 | CHECK_PLACES_URLS(urls); | ||
516 | QCOMPARE(spy_inserted.count(), 1); | 537 | QCOMPARE(spy_inserted.count(), 1); | ||
517 | args = spy_inserted.takeFirst(); | 538 | args = spy_inserted.takeFirst(); | ||
518 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 539 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
519 | QCOMPARE(args.at(1).toInt(), 2); | 540 | QCOMPARE(args.at(1).toInt(), 2); | ||
520 | QCOMPARE(args.at(2).toInt(), 2); | 541 | QCOMPARE(args.at(2).toInt(), 2); | ||
521 | QCOMPARE(spy_removed.count(), 0); | 542 | QCOMPARE(spy_removed.count(), 0); | ||
522 | 543 | | |||
523 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | 544 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | ||
524 | KBookmarkGroup root = bookmarkManager->root(); | 545 | KBookmarkGroup root = bookmarkManager->root(); | ||
525 | KBookmark before_trash = m_places->bookmarkForIndex(m_places->index(0, 0)); | 546 | KBookmark before_trash = m_places->bookmarkForIndex(m_places->index(0, 0)); | ||
526 | KBookmark foo = m_places->bookmarkForIndex(m_places->index(2, 0)); | 547 | KBookmark foo = m_places->bookmarkForIndex(m_places->index(2, 0)); | ||
527 | 548 | | |||
528 | root.moveBookmark(foo, before_trash); | 549 | root.moveBookmark(foo, before_trash); | ||
529 | bookmarkManager->emitChanged(root); | 550 | bookmarkManager->emitChanged(root); | ||
530 | 551 | | |||
531 | urls.clear(); | 552 | urls.clear(); | ||
532 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | 553 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | ||
533 | << initialListOfShared() | 554 | << initialListOfShared() | ||
555 | << initialListOfRecent() | ||||
534 | << initialListOfDevices() | 556 | << initialListOfDevices() | ||
535 | << initialListOfRemovableDevices(); | 557 | << initialListOfRemovableDevices(); | ||
536 | CHECK_PLACES_URLS(urls); | 558 | CHECK_PLACES_URLS(urls); | ||
537 | QCOMPARE(spy_inserted.count(), 1); | 559 | QCOMPARE(spy_inserted.count(), 1); | ||
538 | args = spy_inserted.takeFirst(); | 560 | args = spy_inserted.takeFirst(); | ||
539 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 561 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
540 | QCOMPARE(args.at(1).toInt(), 2); | 562 | QCOMPARE(args.at(1).toInt(), 2); | ||
541 | QCOMPARE(args.at(2).toInt(), 2); | 563 | QCOMPARE(args.at(2).toInt(), 2); | ||
542 | QCOMPARE(spy_removed.count(), 1); | 564 | QCOMPARE(spy_removed.count(), 1); | ||
543 | args = spy_removed.takeFirst(); | 565 | args = spy_removed.takeFirst(); | ||
544 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 566 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
545 | QCOMPARE(args.at(1).toInt(), 1); | 567 | QCOMPARE(args.at(1).toInt(), 1); | ||
546 | QCOMPARE(args.at(2).toInt(), 1); | 568 | QCOMPARE(args.at(2).toInt(), 1); | ||
547 | 569 | | |||
548 | m_places->editPlace(m_places->index(1, 0), QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/mnt/foo"))); | 570 | m_places->editPlace(m_places->index(1, 0), QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/mnt/foo"))); | ||
549 | 571 | | |||
550 | urls.clear(); | 572 | urls.clear(); | ||
551 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | 573 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | ||
552 | << initialListOfShared() | 574 | << initialListOfShared() | ||
575 | << initialListOfRecent() | ||||
553 | << initialListOfDevices() | 576 | << initialListOfDevices() | ||
554 | << initialListOfRemovableDevices(); | 577 | << initialListOfRemovableDevices(); | ||
555 | CHECK_PLACES_URLS(urls); | 578 | CHECK_PLACES_URLS(urls); | ||
556 | QCOMPARE(spy_inserted.count(), 0); | 579 | QCOMPARE(spy_inserted.count(), 0); | ||
557 | QCOMPARE(spy_removed.count(), 0); | 580 | QCOMPARE(spy_removed.count(), 0); | ||
558 | QCOMPARE(spy_changed.count(), 1); | 581 | QCOMPARE(spy_changed.count(), 1); | ||
559 | args = spy_changed.takeFirst(); | 582 | args = spy_changed.takeFirst(); | ||
560 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(1, 0)); | 583 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(1, 0)); | ||
561 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(1, 0)); | 584 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(1, 0)); | ||
562 | 585 | | |||
563 | foo = m_places->bookmarkForIndex(m_places->index(1, 0)); | 586 | foo = m_places->bookmarkForIndex(m_places->index(1, 0)); | ||
564 | foo.setFullText(QStringLiteral("Bar")); | 587 | foo.setFullText(QStringLiteral("Bar")); | ||
565 | bookmarkManager->notifyCompleteChange(QString()); | 588 | bookmarkManager->notifyCompleteChange(QString()); | ||
566 | 589 | | |||
567 | urls.clear(); | 590 | urls.clear(); | ||
568 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | 591 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | ||
569 | << initialListOfShared() | 592 | << initialListOfShared() | ||
593 | << initialListOfRecent() | ||||
570 | << initialListOfDevices() | 594 | << initialListOfDevices() | ||
571 | << initialListOfRemovableDevices(); | 595 | << initialListOfRemovableDevices(); | ||
572 | 596 | | |||
573 | CHECK_PLACES_URLS(urls); | 597 | CHECK_PLACES_URLS(urls); | ||
574 | QCOMPARE(spy_inserted.count(), 0); | 598 | QCOMPARE(spy_inserted.count(), 0); | ||
575 | QCOMPARE(spy_removed.count(), 0); | 599 | QCOMPARE(spy_removed.count(), 0); | ||
576 | QCOMPARE(spy_changed.count(), 9); | 600 | QCOMPARE(spy_changed.count(), m_hasRecentlyUsedKio ? 11 : 9); | ||
577 | args = spy_changed[2]; | 601 | args = spy_changed[2]; | ||
578 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(2, 0)); | 602 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(2, 0)); | ||
579 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(2, 0)); | 603 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(2, 0)); | ||
580 | spy_changed.clear(); | 604 | spy_changed.clear(); | ||
581 | 605 | | |||
582 | m_places->removePlace(m_places->index(1, 0)); | 606 | m_places->removePlace(m_places->index(1, 0)); | ||
583 | 607 | | |||
584 | urls.clear(); | 608 | urls.clear(); | ||
585 | urls << initialListOfPlaces() | 609 | urls << initialListOfPlaces() | ||
586 | << initialListOfShared() | 610 | << initialListOfShared() | ||
611 | << initialListOfRecent() | ||||
587 | << initialListOfDevices() | 612 | << initialListOfDevices() | ||
588 | << initialListOfRemovableDevices(); | 613 | << initialListOfRemovableDevices(); | ||
589 | CHECK_PLACES_URLS(urls); | 614 | CHECK_PLACES_URLS(urls); | ||
590 | QCOMPARE(spy_inserted.count(), 0); | 615 | QCOMPARE(spy_inserted.count(), 0); | ||
591 | QCOMPARE(spy_removed.count(), 1); | 616 | QCOMPARE(spy_removed.count(), 1); | ||
592 | args = spy_removed.takeFirst(); | 617 | args = spy_removed.takeFirst(); | ||
593 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 618 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
594 | QCOMPARE(args.at(1).toInt(), 1); | 619 | QCOMPARE(args.at(1).toInt(), 1); | ||
595 | QCOMPARE(args.at(2).toInt(), 1); | 620 | QCOMPARE(args.at(2).toInt(), 1); | ||
596 | 621 | | |||
597 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo")), QString(), QString(), m_places->index(0, 0)); | 622 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo")), QString(), QString(), m_places->index(0, 0)); | ||
598 | 623 | | |||
599 | urls.clear(); | 624 | urls.clear(); | ||
600 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | 625 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | ||
601 | << initialListOfShared() | 626 | << initialListOfShared() | ||
627 | << initialListOfRecent() | ||||
602 | << initialListOfDevices() | 628 | << initialListOfDevices() | ||
603 | << initialListOfRemovableDevices(); | 629 | << initialListOfRemovableDevices(); | ||
604 | CHECK_PLACES_URLS(urls); | 630 | CHECK_PLACES_URLS(urls); | ||
605 | QCOMPARE(spy_inserted.count(), 1); | 631 | QCOMPARE(spy_inserted.count(), 1); | ||
606 | args = spy_inserted.takeFirst(); | 632 | args = spy_inserted.takeFirst(); | ||
607 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 633 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
608 | QCOMPARE(args.at(1).toInt(), 1); | 634 | QCOMPARE(args.at(1).toInt(), 1); | ||
609 | QCOMPARE(args.at(2).toInt(), 1); | 635 | QCOMPARE(args.at(2).toInt(), 1); | ||
610 | QCOMPARE(spy_removed.count(), 0); | 636 | QCOMPARE(spy_removed.count(), 0); | ||
611 | 637 | | |||
612 | m_places->removePlace(m_places->index(1, 0)); | 638 | m_places->removePlace(m_places->index(1, 0)); | ||
613 | } | 639 | } | ||
614 | 640 | | |||
615 | void KFilePlacesModelTest::testDevicePlugging() | 641 | void KFilePlacesModelTest::testDevicePlugging() | ||
616 | { | 642 | { | ||
617 | QList<QVariant> args; | 643 | QList<QVariant> args; | ||
618 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | 644 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | ||
619 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | 645 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | ||
620 | 646 | | |||
621 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 647 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
622 | 648 | | |||
623 | QStringList urls; | 649 | QStringList urls; | ||
624 | urls << initialListOfPlaces() | 650 | urls << initialListOfPlaces() | ||
625 | << initialListOfShared() | 651 | << initialListOfShared() | ||
652 | << initialListOfRecent() | ||||
626 | << initialListOfDevices() | 653 | << initialListOfDevices() | ||
627 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 654 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
628 | CHECK_PLACES_URLS(urls); | 655 | CHECK_PLACES_URLS(urls); | ||
629 | QCOMPARE(spy_inserted.count(), 0); | 656 | QCOMPARE(spy_inserted.count(), 0); | ||
630 | QCOMPARE(spy_removed.count(), 1); | 657 | QCOMPARE(spy_removed.count(), 1); | ||
631 | args = spy_removed.takeFirst(); | 658 | args = spy_removed.takeFirst(); | ||
632 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 659 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
633 | QCOMPARE(args.at(1).toInt(), 6); | 660 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8 : 6); | ||
634 | QCOMPARE(args.at(2).toInt(), 6); | 661 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8 : 6); | ||
635 | 662 | | |||
636 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 663 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
637 | 664 | | |||
638 | urls.clear(); | 665 | urls.clear(); | ||
639 | urls << initialListOfPlaces() | 666 | urls << initialListOfPlaces() | ||
640 | << initialListOfShared() | 667 | << initialListOfShared() | ||
668 | << initialListOfRecent() | ||||
641 | << initialListOfDevices() | 669 | << initialListOfDevices() | ||
642 | << initialListOfRemovableDevices(); | 670 | << initialListOfRemovableDevices(); | ||
643 | CHECK_PLACES_URLS(urls); | 671 | CHECK_PLACES_URLS(urls); | ||
644 | QCOMPARE(spy_inserted.count(), 1); | 672 | QCOMPARE(spy_inserted.count(), 1); | ||
645 | args = spy_inserted.takeFirst(); | 673 | args = spy_inserted.takeFirst(); | ||
646 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 674 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
647 | QCOMPARE(args.at(1).toInt(), 6); | 675 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8 : 6); | ||
648 | QCOMPARE(args.at(2).toInt(), 6); | 676 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8 : 6); | ||
649 | QCOMPARE(spy_removed.count(), 0); | 677 | QCOMPARE(spy_removed.count(), 0); | ||
650 | 678 | | |||
651 | // Move the device in the list, and check that it memorizes the position across plug/unplug | 679 | // Move the device in the list, and check that it memorizes the position across plug/unplug | ||
652 | 680 | | |||
653 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | 681 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | ||
654 | KBookmarkGroup root = bookmarkManager->root(); | 682 | KBookmarkGroup root = bookmarkManager->root(); | ||
655 | KBookmark before_floppy; | 683 | KBookmark before_floppy; | ||
656 | 684 | | |||
657 | KBookmark device = root.first(); // The device we'll move is the 6th bookmark | 685 | KBookmark device = root.first(); // The device we'll move is the 6th bookmark | ||
658 | for (int i = 0; i < 5; i++) { | 686 | const int count = m_hasRecentlyUsedKio ? 7 : 5; | ||
687 | for (int i = 0; i < count; i++) { | ||||
elvisangelaccio: `const`, and maybe a more descriptive name (`count` or similar?) | |||||
659 | if (i == 2) { | 688 | if (i == 2) { | ||
660 | // store item before to be able to move it back to original position | 689 | // store item before to be able to move it back to original position | ||
661 | device = before_floppy = root.next(device); | 690 | device = before_floppy = root.next(device); | ||
662 | } else { | 691 | } else { | ||
663 | device = root.next(device); | 692 | device = root.next(device); | ||
664 | } | 693 | } | ||
665 | } | 694 | } | ||
666 | 695 | | |||
667 | root.moveBookmark(device, before_floppy); | 696 | root.moveBookmark(device, before_floppy); | ||
668 | bookmarkManager->emitChanged(root); | 697 | bookmarkManager->emitChanged(root); | ||
669 | 698 | | |||
670 | urls.clear(); | 699 | urls.clear(); | ||
671 | urls << initialListOfPlaces() | 700 | urls << initialListOfPlaces() | ||
672 | << initialListOfShared() | 701 | << initialListOfShared() | ||
702 | << initialListOfRecent() | ||||
673 | << initialListOfDevices() | 703 | << initialListOfDevices() | ||
674 | << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 704 | << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
675 | CHECK_PLACES_URLS(urls); | 705 | CHECK_PLACES_URLS(urls); | ||
676 | QCOMPARE(spy_inserted.count(), 1); | 706 | QCOMPARE(spy_inserted.count(), 1); | ||
677 | args = spy_inserted.takeFirst(); | 707 | args = spy_inserted.takeFirst(); | ||
678 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 708 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
679 | QCOMPARE(args.at(1).toInt(), 6); | 709 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8 : 6); | ||
680 | QCOMPARE(args.at(2).toInt(), 6); | 710 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8 : 6); | ||
681 | QCOMPARE(spy_removed.count(), 1); | 711 | QCOMPARE(spy_removed.count(), 1); | ||
682 | args = spy_removed.takeFirst(); | 712 | args = spy_removed.takeFirst(); | ||
683 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 713 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
684 | QCOMPARE(args.at(1).toInt(), 5); | 714 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 5); | ||
685 | QCOMPARE(args.at(2).toInt(), 5); | 715 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 5); | ||
686 | 716 | | |||
687 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 717 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
688 | 718 | | |||
689 | urls.clear(); | 719 | urls.clear(); | ||
690 | urls << initialListOfPlaces() | 720 | urls << initialListOfPlaces() | ||
691 | << initialListOfShared() | 721 | << initialListOfShared() | ||
722 | << initialListOfRecent() | ||||
692 | << initialListOfDevices() | 723 | << initialListOfDevices() | ||
693 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 724 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
694 | CHECK_PLACES_URLS(urls); | 725 | CHECK_PLACES_URLS(urls); | ||
695 | QCOMPARE(spy_inserted.count(), 0); | 726 | QCOMPARE(spy_inserted.count(), 0); | ||
696 | QCOMPARE(spy_removed.count(), 1); | 727 | QCOMPARE(spy_removed.count(), 1); | ||
697 | args = spy_removed.takeFirst(); | 728 | args = spy_removed.takeFirst(); | ||
698 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 729 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
699 | QCOMPARE(args.at(1).toInt(), 5); | 730 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 5); | ||
700 | QCOMPARE(args.at(2).toInt(), 5); | 731 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 5); | ||
701 | 732 | | |||
702 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 733 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
703 | 734 | | |||
704 | urls.clear(); | 735 | urls.clear(); | ||
705 | urls << initialListOfPlaces() | 736 | urls << initialListOfPlaces() | ||
706 | << initialListOfShared() | 737 | << initialListOfShared() | ||
738 | << initialListOfRecent() | ||||
707 | << initialListOfDevices() << QStringLiteral("/media/XO-Y4") | 739 | << initialListOfDevices() << QStringLiteral("/media/XO-Y4") | ||
708 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 740 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
709 | CHECK_PLACES_URLS(urls); | 741 | CHECK_PLACES_URLS(urls); | ||
710 | QCOMPARE(spy_inserted.count(), 1); | 742 | QCOMPARE(spy_inserted.count(), 1); | ||
711 | args = spy_inserted.takeFirst(); | 743 | args = spy_inserted.takeFirst(); | ||
712 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 744 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
713 | QCOMPARE(args.at(1).toInt(), 5); | 745 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 5); | ||
714 | QCOMPARE(args.at(2).toInt(), 5); | 746 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 5); | ||
715 | QCOMPARE(spy_removed.count(), 0); | 747 | QCOMPARE(spy_removed.count(), 0); | ||
716 | 748 | | |||
717 | KBookmark sixth = root.first(); | 749 | KBookmark seventh = root.first(); | ||
718 | for (int i = 0; i < 5; i++) { | 750 | for (int i = 0; i < count; i++) { | ||
719 | sixth = root.next(sixth); | 751 | seventh = root.next(seventh); | ||
720 | } | 752 | } | ||
721 | root.moveBookmark(device, sixth); | 753 | root.moveBookmark(device, seventh); | ||
722 | bookmarkManager->emitChanged(root); | 754 | bookmarkManager->emitChanged(root); | ||
723 | 755 | | |||
724 | urls.clear(); | 756 | urls.clear(); | ||
725 | urls << initialListOfPlaces() | 757 | urls << initialListOfPlaces() | ||
726 | << initialListOfShared() | 758 | << initialListOfShared() | ||
759 | << initialListOfRecent() | ||||
727 | << initialListOfDevices() | 760 | << initialListOfDevices() | ||
728 | << initialListOfRemovableDevices(); | 761 | << initialListOfRemovableDevices(); | ||
729 | CHECK_PLACES_URLS(urls); | 762 | CHECK_PLACES_URLS(urls); | ||
730 | QCOMPARE(spy_inserted.count(), 1); | 763 | QCOMPARE(spy_inserted.count(), 1); | ||
731 | args = spy_inserted.takeFirst(); | 764 | args = spy_inserted.takeFirst(); | ||
732 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 765 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
733 | QCOMPARE(args.at(1).toInt(), 6); | 766 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8 : 6); | ||
734 | QCOMPARE(args.at(2).toInt(), 6); | 767 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8 : 6); | ||
735 | QCOMPARE(spy_removed.count(), 1); | 768 | QCOMPARE(spy_removed.count(), 1); | ||
736 | args = spy_removed.takeFirst(); | 769 | args = spy_removed.takeFirst(); | ||
737 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 770 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
738 | QCOMPARE(args.at(1).toInt(), 5); | 771 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 5); | ||
739 | QCOMPARE(args.at(2).toInt(), 5); | 772 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 5); | ||
740 | } | 773 | } | ||
741 | 774 | | |||
742 | void KFilePlacesModelTest::testDeviceSetupTeardown() | 775 | void KFilePlacesModelTest::testDeviceSetupTeardown() | ||
743 | { | 776 | { | ||
744 | QList<QVariant> args; | 777 | QList<QVariant> args; | ||
745 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | 778 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | ||
746 | 779 | | |||
747 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("teardown")); | 780 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("teardown")); | ||
748 | 781 | | |||
749 | QCOMPARE(spy_changed.count(), 1); | 782 | QCOMPARE(spy_changed.count(), 1); | ||
750 | args = spy_changed.takeFirst(); | 783 | args = spy_changed.takeFirst(); | ||
751 | QCOMPARE(args.at(0).toModelIndex().row(), 6); | 784 | QCOMPARE(args.at(0).toModelIndex().row(), m_hasRecentlyUsedKio ? 8 : 6); | ||
752 | QCOMPARE(args.at(1).toModelIndex().row(), 6); | 785 | QCOMPARE(args.at(1).toModelIndex().row(), m_hasRecentlyUsedKio ? 8 : 6); | ||
753 | 786 | | |||
754 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("setup")); | 787 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("setup")); | ||
755 | 788 | | |||
756 | QCOMPARE(spy_changed.count(), 1); | 789 | QCOMPARE(spy_changed.count(), 1); | ||
757 | args = spy_changed.takeFirst(); | 790 | args = spy_changed.takeFirst(); | ||
758 | QCOMPARE(args.at(0).toModelIndex().row(), 6); | 791 | QCOMPARE(args.at(0).toModelIndex().row(), m_hasRecentlyUsedKio ? 8 : 6); | ||
759 | QCOMPARE(args.at(1).toModelIndex().row(), 6); | 792 | QCOMPARE(args.at(1).toModelIndex().row(), m_hasRecentlyUsedKio ? 8 : 6); | ||
760 | } | 793 | } | ||
761 | 794 | | |||
762 | void KFilePlacesModelTest::testEnableBaloo() | 795 | void KFilePlacesModelTest::testEnableBaloo() | ||
763 | { | 796 | { | ||
764 | KConfig config(QStringLiteral("baloofilerc")); | 797 | KConfig config(QStringLiteral("baloofilerc")); | ||
765 | KConfigGroup basicSettings = config.group("Basic Settings"); | 798 | KConfigGroup basicSettings = config.group("Basic Settings"); | ||
766 | basicSettings.writeEntry("Indexing-Enabled", true); | 799 | basicSettings.writeEntry("Indexing-Enabled", true); | ||
767 | config.sync(); | 800 | config.sync(); | ||
Show All 38 Lines | 832 | { | |||
806 | 839 | | |||
807 | // insert a new network url | 840 | // insert a new network url | ||
808 | m_places->addPlace(QStringLiteral("My Shared"), url, QString(), QString(), QModelIndex()); | 841 | m_places->addPlace(QStringLiteral("My Shared"), url, QString(), QString(), QModelIndex()); | ||
809 | 842 | | |||
810 | // check if url list is correct after insertion | 843 | // check if url list is correct after insertion | ||
811 | QStringList urls; | 844 | QStringList urls; | ||
812 | urls << QDir::homePath() << QStringLiteral("trash:/") // places | 845 | urls << QDir::homePath() << QStringLiteral("trash:/") // places | ||
813 | << QStringLiteral("remote:/") << QStringLiteral("/media/nfs") | 846 | << QStringLiteral("remote:/") << QStringLiteral("/media/nfs") | ||
814 | << url.toString() << QStringLiteral("/foreign") | 847 | << url.toString() | ||
848 | << initialListOfRecent() | ||||
849 | << QStringLiteral("/foreign") | ||||
815 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | 850 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | ||
816 | CHECK_PLACES_URLS(urls); | 851 | CHECK_PLACES_URLS(urls); | ||
817 | 852 | | |||
818 | // check if the new url was inserted in the right position (end of "Remote" section) | 853 | // check if the new url was inserted in the right position (end of "Remote" section) | ||
819 | QTRY_COMPARE(spy_inserted.count(), 1); | 854 | QTRY_COMPARE(spy_inserted.count(), 1); | ||
820 | args = spy_inserted.takeFirst(); | 855 | args = spy_inserted.takeFirst(); | ||
821 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 856 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
822 | QCOMPARE(args.at(1).toInt(), expectedRow); | 857 | QCOMPARE(args.at(1).toInt(), expectedRow); | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | |||||
924 | } | 959 | } | ||
925 | 960 | | |||
926 | void KFilePlacesModelTest::testIconRole_data() | 961 | void KFilePlacesModelTest::testIconRole_data() | ||
927 | { | 962 | { | ||
928 | QTest::addColumn<QModelIndex>("index"); | 963 | QTest::addColumn<QModelIndex>("index"); | ||
929 | QTest::addColumn<QString>("expectedIconName"); | 964 | QTest::addColumn<QString>("expectedIconName"); | ||
930 | 965 | | |||
931 | // places | 966 | // places | ||
932 | QTest::newRow("Places - Home") << m_places->index(0, 0) | 967 | int index = 0; | ||
968 | QTest::newRow("Places - Home") << m_places->index(index++, 0) | ||||
elvisangelaccio: I'd avoid cryptic names. If we can't use `index`, maybe just `i`? | |||||
933 | << QStringLiteral("user-home"); | 969 | << QStringLiteral("user-home"); | ||
934 | QTest::newRow("Places - Trash") << m_places->index(1, 0) | 970 | QTest::newRow("Places - Trash") << m_places->index(index++, 0) | ||
935 | << QStringLiteral("user-trash"); | 971 | << QStringLiteral("user-trash"); | ||
936 | QTest::newRow("Remote - Network") << m_places->index(2, 0) | 972 | | ||
973 | QTest::newRow("Remote - Network") << m_places->index(index++, 0) | ||||
937 | << QStringLiteral("folder-network"); | 974 | << QStringLiteral("folder-network"); | ||
938 | QTest::newRow("Devices - Nfs") << m_places->index(3, 0) | 975 | QTest::newRow("Devices - Nfs") << m_places->index(index++, 0) | ||
939 | << QStringLiteral("hwinfo"); | 976 | << QStringLiteral("hwinfo"); | ||
940 | QTest::newRow("Devices - foreign") << m_places->index(4, 0) | 977 | if (m_hasRecentlyUsedKio) { | ||
978 | QTest::newRow("Recent Files") << m_places->index(index++, 0) | ||||
979 | << QStringLiteral("document-open-recent"); | ||||
980 | QTest::newRow("Recent Locations") << m_places->index(index++, 0) | ||||
981 | << QStringLiteral("folder-open-recent"); | ||||
982 | } | ||||
983 | QTest::newRow("Devices - foreign") << m_places->index(index++, 0) | ||||
941 | << QStringLiteral("blockdevice"); | 984 | << QStringLiteral("blockdevice"); | ||
942 | QTest::newRow("Devices - Floppy") << m_places->index(5, 0) | 985 | QTest::newRow("Devices - Floppy") << m_places->index(index++, 0) | ||
943 | << QStringLiteral("blockdevice"); | 986 | << QStringLiteral("blockdevice"); | ||
944 | QTest::newRow("Devices - cdrom") << m_places->index(6, 0) | 987 | QTest::newRow("Devices - cdrom") << m_places->index(index++, 0) | ||
945 | << QStringLiteral("blockdevice"); | 988 | << QStringLiteral("blockdevice"); | ||
946 | } | 989 | } | ||
947 | 990 | | |||
948 | void KFilePlacesModelTest::testIconRole() | 991 | void KFilePlacesModelTest::testIconRole() | ||
949 | { | 992 | { | ||
950 | QFETCH(QModelIndex, index); | 993 | QFETCH(QModelIndex, index); | ||
951 | QFETCH(QString, expectedIconName); | 994 | QFETCH(QString, expectedIconName); | ||
952 | 995 | | |||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 1000 | { | |||
999 | QTRY_COMPARE(rowsMoved.count(), 1); | 1042 | QTRY_COMPARE(rowsMoved.count(), 1); | ||
1000 | args = rowsMoved.takeFirst(); | 1043 | args = rowsMoved.takeFirst(); | ||
1001 | QCOMPARE(args.at(1).toInt(), 1); // start | 1044 | QCOMPARE(args.at(1).toInt(), 1); // start | ||
1002 | QCOMPARE(args.at(2).toInt(), 1); // end | 1045 | QCOMPARE(args.at(2).toInt(), 1); // end | ||
1003 | QCOMPARE(args.at(4).toInt(), 0); // row (destination) | 1046 | QCOMPARE(args.at(4).toInt(), 0); // row (destination) | ||
1004 | QCOMPARE(placesUrls(), urls); | 1047 | QCOMPARE(placesUrls(), urls); | ||
1005 | rowsMoved.clear(); | 1048 | rowsMoved.clear(); | ||
1006 | 1049 | | |||
1007 | QVERIFY(m_places->movePlace(7, 5)); | 1050 | QVERIFY(m_places->movePlace(m_hasRecentlyUsedKio ? 8: 7, m_hasRecentlyUsedKio ? 6 : 5)); | ||
1008 | urls.move(7, 5); | 1051 | urls.move(m_hasRecentlyUsedKio ? 8: 7, m_hasRecentlyUsedKio ? 6 : 5); | ||
1009 | QTRY_COMPARE(rowsMoved.count(), 1); | 1052 | QTRY_COMPARE(rowsMoved.count(), 1); | ||
1010 | args = rowsMoved.takeFirst(); | 1053 | args = rowsMoved.takeFirst(); | ||
1011 | QCOMPARE(args.at(1).toInt(), 7); // start | 1054 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8: 7); // start | ||
1012 | QCOMPARE(args.at(2).toInt(), 7); // end | 1055 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8: 7); // end | ||
1013 | QCOMPARE(args.at(4).toInt(), 5); // row (destination) | 1056 | QCOMPARE(args.at(4).toInt(), m_hasRecentlyUsedKio ? 6: 4); // row (destination) | ||
1014 | QCOMPARE(placesUrls(), urls); | 1057 | QCOMPARE(placesUrls(), urls); | ||
1015 | rowsMoved.clear(); | 1058 | rowsMoved.clear(); | ||
1016 | 1059 | | |||
1017 | // move it back | 1060 | // move it back | ||
1018 | QVERIFY(m_places->movePlace(5, 8)); | 1061 | QVERIFY(m_places->movePlace(m_hasRecentlyUsedKio ? 6 : 5, m_hasRecentlyUsedKio ? 9 : 8)); | ||
1019 | urls.move(5, 7); | 1062 | urls.move(m_hasRecentlyUsedKio ? 6 : 5, m_hasRecentlyUsedKio ? 8 : 7); | ||
1020 | QTRY_COMPARE(rowsMoved.count(), 1); | 1063 | QTRY_COMPARE(rowsMoved.count(), 1); | ||
1021 | args = rowsMoved.takeFirst(); | 1064 | args = rowsMoved.takeFirst(); | ||
1022 | QCOMPARE(args.at(1).toInt(), 5); // start | 1065 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 6 : 5); // start | ||
1023 | QCOMPARE(args.at(2).toInt(), 5); // end | 1066 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 6 : 5); // end | ||
1024 | QCOMPARE(args.at(4).toInt(), 8); // row (destination) | 1067 | QCOMPARE(args.at(4).toInt(), m_hasRecentlyUsedKio ? 9 : 8); // row (destination) | ||
1025 | QCOMPARE(placesUrls(), urls); | 1068 | QCOMPARE(placesUrls(), urls); | ||
1026 | rowsMoved.clear(); | 1069 | rowsMoved.clear(); | ||
1027 | 1070 | | |||
1028 | //use a invalid start position | 1071 | //use a invalid start position | ||
1029 | QVERIFY(!m_places->movePlace(100, 20)); | 1072 | QVERIFY(!m_places->movePlace(100, 20)); | ||
1030 | QCOMPARE(rowsMoved.count(), 0); | 1073 | QCOMPARE(rowsMoved.count(), 0); | ||
1031 | 1074 | | |||
1032 | //use same start and target position | 1075 | //use same start and target position | ||
1033 | QVERIFY(!m_places->movePlace(1, 1)); | 1076 | QVERIFY(!m_places->movePlace(1, 1)); | ||
1034 | QCOMPARE(rowsMoved.count(), 0); | 1077 | QCOMPARE(rowsMoved.count(), 0); | ||
1035 | } | 1078 | } | ||
1036 | 1079 | | |||
1037 | void KFilePlacesModelTest::testPlaceGroupHidden() | 1080 | void KFilePlacesModelTest::testPlaceGroupHidden() | ||
1038 | { | 1081 | { | ||
1039 | // GIVEN | 1082 | // GIVEN | ||
1040 | QCOMPARE(m_places->hiddenCount(), 0); | 1083 | QCOMPARE(m_places->hiddenCount(), 0); | ||
1041 | 1084 | | |||
1042 | QStringList urls; | 1085 | QStringList urls; | ||
1043 | urls << initialListOfPlaces() << initialListOfShared() << initialListOfDevices() << initialListOfRemovableDevices(); | 1086 | urls << initialListOfPlaces() | ||
1087 | << initialListOfShared() | ||||
1088 | << initialListOfRecent() | ||||
1089 | << initialListOfDevices() | ||||
1090 | << initialListOfRemovableDevices(); | ||||
1044 | CHECK_PLACES_URLS(urls); | 1091 | CHECK_PLACES_URLS(urls); | ||
1045 | QVector<QModelIndex> indexesHidden; | 1092 | QVector<QModelIndex> indexesHidden; | ||
1046 | 1093 | | |||
1047 | // WHEN | 1094 | // WHEN | ||
1048 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | 1095 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | ||
1049 | 1096 | | |||
1050 | // THEN | 1097 | // THEN | ||
1051 | for (int row = 0; row < m_places->rowCount(); ++row) { | 1098 | for (int row = 0; row < m_places->rowCount(); ++row) { | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
1102 | } | 1149 | } | ||
1103 | 1150 | | |||
1104 | void KFilePlacesModelTest::testPlaceGroupHiddenAndShownWithHiddenChild() | 1151 | void KFilePlacesModelTest::testPlaceGroupHiddenAndShownWithHiddenChild() | ||
1105 | { | 1152 | { | ||
1106 | // GIVEN | 1153 | // GIVEN | ||
1107 | QCOMPARE(m_places->hiddenCount(), 0); | 1154 | QCOMPARE(m_places->hiddenCount(), 0); | ||
1108 | 1155 | | |||
1109 | QStringList urls; | 1156 | QStringList urls; | ||
1110 | urls << initialListOfPlaces() << initialListOfShared() << initialListOfDevices() << initialListOfRemovableDevices(); | 1157 | urls << initialListOfPlaces() | ||
1158 | << initialListOfShared() | ||||
1159 | << initialListOfRecent() | ||||
1160 | << initialListOfDevices() | ||||
1161 | << initialListOfRemovableDevices(); | ||||
1111 | CHECK_PLACES_URLS(urls); | 1162 | CHECK_PLACES_URLS(urls); | ||
1112 | 1163 | | |||
1113 | QModelIndex firstIndexHidden = m_places->index(0,0); | 1164 | QModelIndex firstIndexHidden = m_places->index(0,0); | ||
1114 | m_places->setPlaceHidden(firstIndexHidden, true); // first place index is hidden within an hidden parent | 1165 | m_places->setPlaceHidden(firstIndexHidden, true); // first place index is hidden within an hidden parent | ||
1115 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | 1166 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | ||
1116 | QCOMPARE(m_places->hiddenCount(), initialListOfPlaces().size()); | 1167 | QCOMPARE(m_places->hiddenCount(), initialListOfPlaces().size()); | ||
1117 | 1168 | | |||
1118 | // WHEN | 1169 | // WHEN | ||
Show All 21 Lines | |||||
1140 | 1191 | | |||
1141 | void KFilePlacesModelTest::testPlaceGroupHiddenGroupIndexesIntegrity() | 1192 | void KFilePlacesModelTest::testPlaceGroupHiddenGroupIndexesIntegrity() | ||
1142 | { | 1193 | { | ||
1143 | // GIVEN | 1194 | // GIVEN | ||
1144 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | 1195 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | ||
1145 | QVERIFY(m_places->groupIndexes(KFilePlacesModel::UnknownType).isEmpty()); | 1196 | QVERIFY(m_places->groupIndexes(KFilePlacesModel::UnknownType).isEmpty()); | ||
1146 | QVERIFY(m_places->isGroupHidden(KFilePlacesModel::PlacesType)); | 1197 | QVERIFY(m_places->isGroupHidden(KFilePlacesModel::PlacesType)); | ||
1147 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); | 1198 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); | ||
1148 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), 0); | 1199 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), m_hasRecentlyUsedKio ? 2 : 0); | ||
1149 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); | 1200 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); | ||
1150 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); | 1201 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); | ||
1151 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); | 1202 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); | ||
1152 | 1203 | | |||
1153 | //WHEN | 1204 | //WHEN | ||
1154 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, false); | 1205 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, false); | ||
1155 | 1206 | | |||
1156 | // THEN | 1207 | // THEN | ||
1157 | // Make sure that hidden place group doesn't change model | 1208 | // Make sure that hidden place group doesn't change model | ||
1158 | QVERIFY(!m_places->isGroupHidden(KFilePlacesModel::PlacesType)); | 1209 | QVERIFY(!m_places->isGroupHidden(KFilePlacesModel::PlacesType)); | ||
1159 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); | 1210 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); | ||
1160 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), 0); | 1211 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), m_hasRecentlyUsedKio ? 2 : 0); | ||
1161 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); | 1212 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); | ||
1162 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); | 1213 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); | ||
1163 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); | 1214 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); | ||
1164 | } | 1215 | } | ||
1165 | 1216 | | |||
1166 | void KFilePlacesModelTest::testPlaceGroupHiddenSignal() | 1217 | void KFilePlacesModelTest::testPlaceGroupHiddenSignal() | ||
1167 | { | 1218 | { | ||
1168 | QSignalSpy groupHiddenSignal(m_places, &KFilePlacesModel::groupHiddenChanged); | 1219 | QSignalSpy groupHiddenSignal(m_places, &KFilePlacesModel::groupHiddenChanged); | ||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |
const, and maybe a more descriptive name (count or similar?)