Removing entries from call history programmatically

Hi guys, is someone aware of, and could please point me to, some documentation or example code about how to programmatically (C++) remove entries from the call history?

So… not possible, or no one knows? :roll_eyes:

Quickly checking think it’s libcommhistory → callmodel/eventmodel → deleteEvent() etc. There’s commhistory-tool on the libcommhistory repository too with c++ implementation.

3 Likes

OK, thanks a lot @pvuorela for your suggestion! It seems to work fine. The following does the job for me:

CommHistory::CallModel::Sorting sorting = CommHistory::CallModel::SortByContact;
    CommHistory::CallModel::ContactResolveType resolve = CommHistory::CallModel::DoNotResolve;
    CommHistory::CallModel model;
        model.setFilter(sorting, CommHistory::CallEvent::CallType::ReceivedCallType);
        model.setResolveContacts(resolve);
        model.setQueryMode(resolve == CommHistory::CallModel::ResolveImmediately ? CommHistory::EventModel::AsyncQuery : CommHistory::EventModel::SyncQuery);

QVector<QStringList> array;
        for ( int i = 0; i < model.rowCount(); i++ )
            {
                CommHistory::Event e = model.event(model.index(i, 0));
                QString text = e.toString();
                array.append(text.split("|"));
            }

        for (int c = 0; c < model.rowCount(); c++)
                {
            if (array[c][9].contains(callingNumber))
            {
                 model.deleteEvent(array[c][0].toInt());
            }
        }

Note that I had to manually split event string to a list / array for easier processing, i.e. something like

QString text = e.toString();
                array.append(text.split("|"));

because I couldn’t make CommHistory::Event::toList() work (the result is always empty). Only CommHistory::Event::toString() works for me, and then I manually split it by the “|” character to e.g. a QStringList.

Note 2: after deleting a call event from commhistory, it doesn’t seem to disappear right away from the list in the History tab of the Voicecall-ui. Sometimes it takes closing and reopening, or even restarting voicecall-ui for it to notice it. Should it be signalled somehow for voicecall-ui to automatically refresh the history?