int exportCALLS(QTextStream *outputStream) { CallModel callModel; callModel.enableContactChanges(false); callModel.setQueryMode(EventModel::SyncQuery); callModel.setTreeMode(false); callModel.setFilter(CallModel::SortByTime); if(!callModel.getEvents()) { qCritical() << "Error fetching calls"; return 0; } int i; qDebug() << "# calls: " << callModel.rowCount(); for(i = callModel.rowCount() - 1; i >= 0; i--) //we iterate backwards, because the jolla does not like to import the last call first { Event e = callModel.event(callModel.index(i, 0)); if(e.type() != Event::CallEvent) { qDebug() << "Not a call"; } else { QString direction = e.direction() == Event::Inbound ? "IN" : "OUT"; QString missed = e.isMissedCall() ? "MISSED" : "OK"; *outputStream << e.remoteUid() << ";" << direction << ";" << missed << ";" << e.startTime().toString(Qt::ISODate) << ";" << e.endTime().toString(Qt::ISODate) << endl; } } return 1; }
void CallModelTest::testGetEventsTimeTypeFilter() { QFETCH(bool, useThread); deleteAll(); QThread modelThread; //initTestCase ==> 3 dialled calls, 2 Received calls, 3 Missed Calls already added CallModel model; watcher.setModel(&model); if (useThread) { modelThread.start(); model.setBackgroundThread(&modelThread); } QDateTime when = QDateTime::currentDateTime(); //3 dialled addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when ); addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs(5) ); addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs(10) ); QVERIFY(watcher.waitForAdded(3)); //2 received addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when ); addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs(5) ); QVERIFY(watcher.waitForAdded(2)); //3 missed addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when ); addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(5) ); addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(10) ); QVERIFY(watcher.waitForAdded(3)); QDateTime time = when; //model.setQueryMode(EventModel::SyncQuery); model.setTreeMode(false); QVERIFY(model.setFilter(CallModel::SortByTime, CallEvent::DialedCallType, time)); QVERIFY(model.getEvents()); QVERIFY(watcher.waitForModelReady()); int numEventsRet = model.rowCount(); QCOMPARE(numEventsRet, 3); Event e1 = model.event(model.index(0,0)); Event e2 = model.event(model.index(1,0)); Event e3 = model.event(model.index(2,0)); QVERIFY(e1.isValid()); QVERIFY(e2.isValid()); QVERIFY(e3.isValid()); QVERIFY(e1.direction() == Event::Outbound); QVERIFY(e2.direction() == Event::Outbound); QVERIFY(e3.direction() == Event::Outbound); QVERIFY(model.setFilter(CallModel::SortByTime, CallEvent::MissedCallType, time)); QVERIFY(watcher.waitForModelReady()); QVERIFY(model.rowCount() == 3); QVERIFY(model.setFilter(CallModel::SortByTime, CallEvent::ReceivedCallType, time)); qDebug() << time; QVERIFY(watcher.waitForModelReady()); for (int i = 0; i < model.rowCount(); i++) { qDebug() << model.event(model.index(i, 0)).toString(); } QVERIFY(model.rowCount() == 2); /** * testing to check for adding events with wrong filters */ time = when.addSecs(-60*5); int numEventsGot = 0; //adding one more received but 5 minutes before the set time filter addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, time ); QVERIFY(watcher.waitForAdded()); QVERIFY(model.rowCount() == 2); //event should not be added to model, so rowCount should remain same for received calls //filter is set for received call, try to add missed and dialled calls with correct time filter addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when ); QVERIFY(watcher.waitForAdded()); numEventsGot = model.rowCount(); QVERIFY(numEventsGot == 2); //event should not be added to model, so rowCount should remain same which was for received calls addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when ); QVERIFY(watcher.waitForAdded()); numEventsGot = model.rowCount(); QVERIFY(numEventsGot == 2); //event should not be added to model, so rowCount should remain same which was for received calls /** ** testing to check for getting events after he time when all events addition was complete */ //Trying to get events after 5 minutes after the first event was added time = when.addSecs(60*5); QVERIFY(model.setFilter(CallModel::SortByTime, CallEvent::ReceivedCallType, time)); QVERIFY(watcher.waitForModelReady()); QVERIFY(model.rowCount() == 0); qDebug() << "wait thread"; modelThread.quit(); modelThread.wait(3000); qDebug() << "done"; }
void CallModelTest::testDeleteEvent() { CallModel model; watcher.setModel(&model); model.setTreeMode(false); QVERIFY(model.getEvents()); QVERIFY(watcher.waitForModelReady()); // delete first event from hidden number Event e = model.event(model.index(0, 0)); QVERIFY(e.isValid()); QCOMPARE(e.remoteUid(), QLatin1String("<hidden>")); QVERIFY(model.deleteEvent(e.id())); QVERIFY(watcher.waitForDeleted()); // correct test helper lists to match current situation QMutableListIterator<TestCallItem> i(testCalls); while (i.hasNext()) { i.next(); if (i.value().remoteUid == QLatin1String("<hidden>")) i.remove(); } // force change of sorting to SortByContact model.setTreeMode(true); QVERIFY( model.setFilter( CallModel::SortByContact ) ); QVERIFY( model.getEvents() ); QVERIFY(watcher.waitForModelReady()); /* by contact: * ----------- * user2, received (0) * user1, received (0) */ // delete first group from user2 e = model.event( model.index( 0, 0 ) ); QVERIFY( e.isValid() ); QCOMPARE( e.type(), Event::CallEvent ); qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount(); QCOMPARE( e.direction(), Event::Inbound ); QCOMPARE( e.isMissedCall(), false ); QCOMPARE( e.remoteUid(), REMOTEUID2 ); // delete it QVERIFY( model.deleteEvent( e.id() ) ); QVERIFY( watcher.waitForDeleted(2) ); // correct test helper lists to match current situation i = QMutableListIterator<TestCallItem>(testCalls); while (i.hasNext()) { i.next(); if (i.value().remoteUid == REMOTEUID2) i.remove(); } // test if model contains what we want it does testGetEvents( CallModel::SortByContact, 1, testCalls ); // force change of sorting to SortByTime QVERIFY( model.setFilter( CallModel::SortByTime ) ); QVERIFY(watcher.waitForModelReady()); /* by time: * -------- * user1, received (6)*** * user1, dialed (1) * user1, missed (2) * user1, dialed (1) * user1, received (2) * user1, missed (1) * user1, dialed (2) * * || * \/ * * user1, dialed (1) * user1, missed (2) * user1, dialed (1) * user1, received (2) * user1, missed (1) * user1, dialed (2) */ // take the event e = model.event( model.index( 0, 0 ) ); QVERIFY( e.isValid() ); QCOMPARE( e.type(), Event::CallEvent ); qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount(); QCOMPARE( e.direction(), Event::Inbound ); QCOMPARE( e.isMissedCall(), false ); // delete it QVERIFY( model.deleteEvent( e.id() ) ); QVERIFY( watcher.waitForDeleted(6) ); // correct test helper lists to match current situation foreach (TestCallItem item, testCalls) { qDebug() << item.remoteUid << item.callType << item.eventCount; } testCalls.takeFirst(); testCalls.takeFirst(); foreach (TestCallItem item, testCalls) { qDebug() << item.remoteUid << item.callType << item.eventCount; } // test if model contains what we want it does testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls ); /* by time: * -------- * user1, dialed (1) <---\ * user1, missed (2)*** regrouping * user1, dialed (1) <---/ * user1, received (2) * user1, missed (1) * user1, dialed (2) * * || * \/ * * user1, dialed (2) * user1, received (2) * user1, missed (1) * user1, dialed (2) */ // take the event e = model.event( model.index( 1, 0 ) ); QVERIFY( e.isValid() ); QCOMPARE( e.type(), Event::CallEvent ); qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount(); QCOMPARE( e.direction(), Event::Inbound ); QCOMPARE( e.isMissedCall(), true ); // delete it QVERIFY( model.deleteEvent( e.id() ) ); QVERIFY( watcher.waitForDeleted(2) ); // correct test helper lists to match current situation testCalls.takeFirst(); testCalls.takeFirst(); testCalls.first().eventCount = 2; // test if model contains what we want it does testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls ); // force change of sorting to SortByContact QVERIFY( model.setFilter( CallModel::SortByContact ) ); QVERIFY(watcher.waitForModelReady()); /* by contact: * ----------- * user1, dialed (0)*** * * || * \/ * * (empty) */ // take the event e = model.event( model.index( 0, 0 ) ); QVERIFY( e.isValid() ); QCOMPARE( e.type(), Event::CallEvent ); qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount(); QCOMPARE( e.direction(), Event::Outbound ); QCOMPARE( e.isMissedCall(), false ); // delete it QVERIFY( model.deleteEvent( e.id() ) ); QVERIFY( watcher.waitForDeleted(7) ); // correct test helper lists to match current situation testCalls.clear(); // test if model contains what we want it does testGetEvents( CallModel::SortByContact, 0, testCalls ); }