SailorgramContactsModel::SailorgramContactsModel(QObject *parent) : QIdentityProxyModel(parent)
{
    this->_telegramcontactsmodel = new TelegramContactsModel(this);
    this->setSourceModel(this->_telegramcontactsmodel);

    connect(this->_telegramcontactsmodel, SIGNAL(telegramChanged()), this, SIGNAL(telegramChanged()));
    connect(this->_telegramcontactsmodel, SIGNAL(countChanged()), this, SIGNAL(countChanged()));
    connect(this->_telegramcontactsmodel, SIGNAL(initializingChanged()), this, SIGNAL(initializingChanged()));
}
void TelegramContactsModel::setTelegram(TelegramQml *tgo)
{
    TelegramQml *tg = static_cast<TelegramQml*>(tgo);
    if( p->telegram == tg )
        return;

    p->telegram = tg;
    emit telegramChanged();
    if( !p->telegram )
        return;

    connect( p->telegram, SIGNAL(contactsChanged()), SLOT(contactsChanged()) );
    refresh();
}
void TelegramMessagesModel::setTelegram(TelegramQml *tgo)
{
    TelegramQml *tg = static_cast<TelegramQml*>(tgo);
    if( p->telegram == tg )
        return;

    p->telegram = tg;
    p->initializing = tg;
    emit telegramChanged();
    emit initializingChanged();
    if( !p->telegram )
        return;

    connect( p->telegram, SIGNAL(messagesChanged(bool)), SLOT(messagesChanged(bool)) );

    init();
}