Esempio n. 1
0
void MorseConnection::doConnect(Tp::DBusError *error)
{
    Q_UNUSED(error);

    CAppInformation appInfo;
    appInfo.setAppId(14617);
    appInfo.setAppHash(QLatin1String("e17ac360fd072f83d5d08db45ce9a121"));
    appInfo.setAppVersion(QLatin1String("0.1"));
    appInfo.setDeviceInfo(QLatin1String("pc"));
    appInfo.setOsInfo(QLatin1String("GNU/Linux"));
    appInfo.setLanguageCode(QLatin1String("en"));

    m_authReconnectionsCount = 0;
    m_core = new CTelegramCore(0);
    m_core->setPingInterval(m_keepaliveInterval * 1000);
    m_core->setAppInformation(&appInfo);
    m_core->setMessageReceivingFilterFlags(TelegramNamespace::MessageFlagOut|TelegramNamespace::MessageFlagRead);
    m_core->setAcceptableMessageTypes(TelegramNamespace::MessageTypeText);

    setStatus(Tp::ConnectionStatusConnecting, Tp::ConnectionStatusReasonNoneSpecified);

    connect(m_core, SIGNAL(connectionStateChanged(TelegramNamespace::ConnectionState)),
            this, SLOT(whenConnectionStateChanged(TelegramNamespace::ConnectionState)));
    connect(m_core, SIGNAL(authorizationErrorReceived()),
            this, SLOT(whenAuthErrorReceived()));
    connect(m_core, SIGNAL(phoneCodeRequired()),
            this, SLOT(whenPhoneCodeRequired()));
    connect(m_core, SIGNAL(authSignErrorReceived(TelegramNamespace::AuthSignError,QString)),
            this, SLOT(whenAuthSignErrorReceived(TelegramNamespace::AuthSignError,QString)));
    connect(m_core, SIGNAL(avatarReceived(QString,QByteArray,QString,QString)),
            this, SLOT(whenAvatarReceived(QString,QByteArray,QString,QString)));
    connect(m_core, SIGNAL(contactListChanged()),
            this, SLOT(whenContactListChanged()));
    connect(m_core, SIGNAL(messageReceived(QString,QString,TelegramNamespace::MessageType,quint32,quint32,quint32)),
            this, SLOT(whenMessageReceived(QString,QString,TelegramNamespace::MessageType,quint32,quint32,quint32)));
    connect(m_core, SIGNAL(chatMessageReceived(quint32,QString,QString,TelegramNamespace::MessageType,quint32,quint32,quint32)),
            this, SLOT(whenChatMessageReceived(quint32,QString,QString,TelegramNamespace::MessageType,quint32,quint32,quint32)));
    connect(m_core, SIGNAL(chatChanged(quint32)),
            this, SLOT(whenChatChanged(quint32)));
    connect(m_core, SIGNAL(contactStatusChanged(QString,TelegramNamespace::ContactStatus)),
            this, SLOT(updateContactPresence(QString)));

    const QByteArray sessionData = getSessionData(m_selfPhone);

    if (sessionData.isEmpty()) {
        qDebug() << "init connection...";
        m_core->initConnection(QLatin1String("149.154.175.50"), 443);
    } else {
        qDebug() << "restore connection...";
        m_core->restoreConnection(sessionData);
    }
}
Esempio n. 2
0
MsgEdit::MsgEdit(QWidget *p, unsigned long uin)
        : QFrame(p),
        Uin(this, "Uin")
{
    Uin = uin;
    msg = NULL;
    tabId = -1;
    tab = NULL;
    sendEvent = NULL;
    mHistory = NULL;
    bMultiply = false;
    setWFlags(WDestructiveClose);
    QVBoxLayout *lay = new QVBoxLayout(this);
    boxSend = new QVGroupBox(this);
    lay->addWidget(boxSend);
    QFrame *frmHead = new QFrame(boxSend);
    QHBoxLayout *hLay = new QHBoxLayout(frmHead);
    btnBgColor = new CPushButton(frmHead);
    btnBgColor->setTip(i18n("Background color"));
    btnBgColor->setPixmap(Pict("bgcolor"));
    connect(btnBgColor, SIGNAL(clicked()), this, SLOT(setMsgBackgroundColor()));
    btnBgColor->hide();
    hLay->addWidget(btnBgColor);
    btnReply = new QPushButton(i18n("&Reply"), frmHead);
    btnReply->hide();
    hLay->addWidget(btnReply);
    connect(btnReply, SIGNAL(clicked()), this, SLOT(replyClick()));
    btnGrant = new QPushButton(i18n("&Grant"), frmHead);
    btnGrant->hide();
    hLay->addWidget(btnGrant);
    connect(btnGrant, SIGNAL(clicked()), this, SLOT(grantClick()));
    btnAccept = new QPushButton(i18n("&Accept"), frmHead);
    btnAccept->hide();
    hLay->addWidget(btnAccept);
    connect(btnAccept, SIGNAL(clicked()), this, SLOT(acceptMessage()));
    btnFgColor = new CPushButton(frmHead);
    btnFgColor->setTip(i18n("Text color"));
    btnFgColor->setPixmap(Pict("fgcolor"));
    connect(btnFgColor, SIGNAL(clicked()), this, SLOT(setMsgForegroundColor()));
    hLay->addSpacing(2);
    btnFgColor->hide();
    hLay->addWidget(btnFgColor);
    btnQuote = new QPushButton(i18n("&Quote"), frmHead);
    btnQuote->hide();
    hLay->addWidget(btnQuote);
    connect(btnQuote, SIGNAL(clicked()), this, SLOT(quoteClick()));
    btnRefuse = new QPushButton(i18n("&Refuse"), frmHead);
    btnRefuse->hide();
    hLay->addWidget(btnRefuse);
    declineMenu = new QPopupMenu(this);
    connect(btnRefuse, SIGNAL(clicked()), this, SLOT(refuseClick()));
    connect(declineMenu, SIGNAL(activated(int)), this, SLOT(declineMessage(int)));
    declineMenu->insertItem(reason_string(DECLINE_WITHOUT_REASON), DECLINE_WITHOUT_REASON);
    declineMenu->insertItem(reason_string(DECLINE_REASON_BUSY), DECLINE_REASON_BUSY);
    declineMenu->insertItem(reason_string(DECLINE_REASON_LATER), DECLINE_REASON_LATER);
    declineMenu->insertItem(reason_string(DECLINE_REASON_INPUT), DECLINE_REASON_INPUT);
    btnDecline = new QPushButton(i18n("&Decline"), frmHead);
    btnDecline->hide();
    btnDecline->setPopup(declineMenu);
    hLay->addWidget(btnDecline);
    btnBold = new CPushButton(frmHead);
    btnBold->setTip(i18n("Bold"));
    btnBold->setPixmap(Pict("text_bold"));
    btnBold->setToggleButton(true);
    connect(btnBold, SIGNAL(toggled(bool)), this, SLOT(setBold(bool)));
    hLay->addSpacing(2);
    btnBold->hide();
    hLay->addWidget(btnBold);
    btnForward = new QPushButton(i18n("&Forward"), frmHead);
    connect(btnForward, SIGNAL(clicked()), this, SLOT(forwardClick()));
    btnForward->hide();
    hLay->addWidget(btnForward);
    btnItalic = new CPushButton(frmHead);
    btnItalic->setTip(i18n("Italic"));
    btnItalic->setPixmap(Pict("text_italic"));
    btnItalic->setToggleButton(true);
    connect(btnItalic, SIGNAL(toggled(bool)), this, SLOT(setItalic(bool)));
    hLay->addSpacing(2);
    btnItalic->hide();
    hLay->addWidget(btnItalic);
    btnUnder = new CPushButton(frmHead);
    btnUnder->setTip(i18n("Underline"));
    btnUnder->setPixmap(Pict("text_under"));
    btnUnder->setToggleButton(true);
    connect(btnUnder, SIGNAL(toggled(bool)), this, SLOT(setUnder(bool)));
    hLay->addSpacing(2);
    btnUnder->hide();
    hLay->addWidget(btnUnder);
    btnFont = new CPushButton(frmHead);
    btnFont->setTip(i18n("Text font"));
    btnFont->setPixmap(Pict("text"));
    connect(btnFont, SIGNAL(clicked()), this, SLOT(setFont()));
    hLay->addSpacing(2);
    btnFont->hide();
    hLay->addWidget(btnFont);
#ifdef USE_SPELL
    btnSpell = new CPushButton(frmHead);
    btnSpell->setTip(i18n("Spell check"));
    btnSpell->setPixmap(Pict("spellcheck"));
    connect(btnSpell, SIGNAL(clicked()), this, SLOT(spell()));
    hLay->addSpacing(2);
    btnSpell->hide();
    hLay->addWidget(btnSpell);
#endif
    hLay->addSpacing(2);
    hLay->addStretch();
    chkClose = new QCheckBox(i18n("C&lose after send"), frmHead);
    chkClose->setChecked(pMain->CloseAfterSend());
    connect(chkClose, SIGNAL(toggled(bool)), this, SLOT(closeToggle(bool)));
    hLay->addWidget(chkClose);
    btnSend = new QPushButton(frmHead);
    connect(btnSend, SIGNAL(clicked()), this, SLOT(sendClick()));
    hLay->addWidget(btnSend);
    btnNext = new PictPushButton(frmHead);
    connect(btnNext, SIGNAL(clicked()), this, SLOT(nextClick()));
    btnNext->hide();
    hLay->addWidget(btnNext);
    phone = new QFrame(boxSend);
    phone->hide();
    QHBoxLayout *hlay = new QHBoxLayout(phone);
    QLabel *title = new QLabel(i18n("Phone:"), phone);
    hlay->addWidget(title);
    phoneEdit = new QComboBox(phone);
    phoneEdit->setEditable(true);
    phoneEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
    hlay->addWidget(phoneEdit);
    connect(phoneEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&)));
    url   = new QFrame(boxSend);
    url->hide();
    hlay = new QHBoxLayout(url);
    title = new QLabel(i18n("URL:"), url);
    hlay->addWidget(title);
    urlEdit = new QLineEdit(url);
    hlay->addWidget(urlEdit);
    connect(urlEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&)));
    file = new QFrame(boxSend);
    file->hide();
    hlay = new QHBoxLayout(file);
    title = new QLabel(i18n("File:"), file);
    hlay->addWidget(title);
    fileEdit = new EditFile(file);
    hlay->addWidget(fileEdit);
    connect(fileEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&)));
    btnMultiply = new CPushButton(frmHead);
    btnMultiply->setTip(i18n("Multiply send"));
    btnMultiply->setPixmap(Pict("1rightarrow"));
    connect(btnMultiply, SIGNAL(clicked()), this, SLOT(toggleMultiply()));
    hLay->addSpacing(2);
    hLay->addWidget(btnMultiply);
    lblUsers = new QLabel(i18n("Drag users here"), boxSend);
    edit  = new EditSpell(this);
    edit->hide();
    lay->addWidget(edit);
    users = new UserTbl(this);
    users->hide();
    lay->addWidget(users);
    view  = new TextShow(this);
    view->hide();
    lay->addWidget(view);
    connect(edit, SIGNAL(textChanged()), this, SLOT(editTextChanged()));
    connect(edit, SIGNAL(currentFontChanged(const QFont&)), this, SLOT(editFontChanged(const QFont&)));
    connect(edit, SIGNAL(ctrlEnterPressed()), this, SLOT(sendClick()));
    connect(users, SIGNAL(changed()), this, SLOT(textChanged()));
    connect(pClient, SIGNAL(messageReceived(ICQMessage*)), this, SLOT(messageReceived(ICQMessage*)));
    connect(pClient, SIGNAL(event(ICQEvent*)), this, SLOT(processEvent(ICQEvent*)));
    connect(pMain, SIGNAL(chatChanged()), this, SLOT(chatChanged()));
    connect(pMain, SIGNAL(ftChanged()), this, SLOT(ftChanged()));
    setState();
    setUin(uin);
}
Esempio n. 3
0
void MsgEdit::setMessage(ICQMessage *_msg, bool bMark, bool bInTop, bool bSaveEdit)
{
    msgTail = "";
    setUpdatesEnabled(false);
    if (msg != _msg){
        if (msg && (msg->Id < MSG_PROCESS_ID)) delete msg;
        msg = _msg;
    }
    if (bMultiply) toggleMultiply();
    if (msg == NULL){
        edit->setText("");
        edit->resetColors(false);
        urlEdit->setText("");
        users->clear();
        url->hide();
        edit->hide();
        file->hide();
        lblUsers->hide();
        btnBgColor->hide();
        btnFgColor->hide();
        btnBold->hide();
        btnItalic->hide();
        btnUnder->hide();
        btnFont->hide();
#ifdef USE_SPELL
        btnSpell->hide();
#endif
        btnSend->hide();
        chkClose->hide();
        btnAccept->hide();
        btnDecline->hide();
        btnNext->show();
        btnReply->hide();
        btnQuote->hide();
        btnGrant->hide();
        btnRefuse->hide();
        btnMultiply->hide();
        btnForward->hide();
        users->hide();
        view->hide();
        setupNext();
        setUpdatesEnabled(true);
        repaint();
        return;
    }
    emit showMessage(Uin, msg->Id);
    if (msg->Received()){
        if (bMark) pClient->markAsRead(msg);
        phone->hide();
        url->hide();
        edit->hide();
        file->hide();
        lblUsers->hide();
        btnBgColor->hide();
        btnFgColor->hide();
        btnBold->hide();
        btnItalic->hide();
        btnUnder->hide();
        btnFont->hide();
#ifdef USE_SPELL
        btnSpell->hide();
#endif
        btnSend->hide();
        chkClose->hide();
        btnAccept->hide();
        btnDecline->hide();
        btnNext->show();
        btnMultiply->hide();
        setupNext();
        if (msg->Type() == ICQ_MSGxCONTACTxLIST){
            btnReply->hide();
            btnQuote->hide();
            btnGrant->hide();
            btnRefuse->hide();
            users->show();
            view->hide();
            btnForward->show();
            ICQContacts *m = static_cast<ICQContacts*>(msg);
            for (ContactList::iterator it = m->Contacts.begin(); it != m->Contacts.end(); it++){
                Contact *contact = static_cast<Contact*>(*it);
                users->addUser(contact->Uin, contact->Alias);
            }
            users->sender = false;
        }else{
            switch (msg->Type()){
            case ICQ_MSGxFILE:{
                    ICQFile *f = static_cast<ICQFile*>(msg);
                    btnReply->hide();
                    btnQuote->hide();
                    btnGrant->hide();
                    btnRefuse->hide();
                    if (f->Id >= MSG_PROCESS_ID){
                        btnAccept->show();
                        btnDecline->show();
                        file->show();
                        ICQUser *u = pClient->getUser(f->getUin());
                        if ((u == NULL) || !u->AcceptFileOverride()) u = pClient;
                        string path = u->AcceptFilePath.c_str();
                        if (*path.c_str() == 0)
                            pMain->buildFileName(path, "IncommingFiles/");
                        QString name = QString::fromLocal8Bit(path.c_str());
#ifdef WIN32
                        name.replace(QRegExp("/"), "\\");
                        if ((name.length() == 0) || (name[(int)(name.length() - 1)] != '\\'))
                            name += "\\";
#else
                        if ((name.length() == 0) || (name[(int)(name.length() - 1)] != '/'))
                            name += "/";
#endif
                        name += QString::fromLocal8Bit(f->Name.c_str());
                        fileEdit->setText(name);
                        fileEdit->setSaveMode(true);
                        ftChanged();
                    }else{
                        btnAccept->hide();
                        btnDecline->hide();
                    }
                    break;
                }
            case ICQ_MSGxAUTHxREQUEST:
                btnReply->hide();
                btnQuote->hide();
                btnGrant->show();
                btnRefuse->show();
                btnAccept->hide();
                btnDecline->hide();
                btnForward->hide();
                break;
            case ICQ_MSGxMSG:
            case ICQ_MSGxURL:
                if (bInTop && !pMain->SimpleMode()){
                    btnReply->hide();
                    btnQuote->show();
                    btnForward->show();
                    btnGrant->hide();
                    btnRefuse->hide();
                    btnAccept->hide();
                    btnDecline->hide();
                    users->hide();
                    view->hide();
                    edit->setTextFormat(RichText);
                    edit->setText("");
                    edit->show();
                    edit->resetColors(true);
                    textChanged();
                    setUpdatesEnabled(true);
                    edit->setFocus();
                    repaint();
                    return;
                }
                btnReply->show();
                btnQuote->show();
                btnGrant->hide();
                btnRefuse->hide();
                btnAccept->hide();
                btnDecline->hide();
                btnForward->show();
                break;
            case ICQ_MSGxCHAT:
                btnReply->hide();
                btnQuote->hide();
                btnGrant->hide();
                btnRefuse->hide();
                btnAccept->hide();
                btnDecline->hide();
                btnForward->hide();
                if (msg->Id >= MSG_PROCESS_ID){
                    btnAccept->show();
                    btnDecline->show();
                    chatChanged();
                }
                break;
            default:
                btnReply->hide();
                btnQuote->hide();
                btnGrant->hide();
                btnRefuse->hide();
                btnAccept->hide();
                btnDecline->hide();
                btnForward->hide();
            }
            users->hide();
            view->show();
            view->setText(view->makeMessageText(msg, false));
            if (msg->Type() == ICQ_MSGxMSG){
                ICQMsg *m = static_cast<ICQMsg*>(msg);
                if (m->BackColor() != m->ForeColor()){
                    view->setForeground(QColor(m->ForeColor));
                    view->setBackground(QColor(m->BackColor));
                }else{
                    view->resetColors();
                }
            }else{
                view->resetColors();
            }
        }
    }else{
        btnReply->hide();
        btnForward->hide();
        btnQuote->hide();
        btnGrant->hide();
        btnRefuse->hide();
        btnNext->hide();
        btnAccept->hide();
        btnDecline->hide();
        chkClose->show();
        btnSend->show();
        switch (msg->Type()){
        case ICQ_MSGxMSG:{
                phone->hide();
                url->hide();
                edit->show();
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->show();
                btnFgColor->show();
                btnBold->show();
                btnItalic->show();
                btnUnder->show();
                btnFont->show();
                btnMultiply->show();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                if (!bSaveEdit){
                    edit->setTextFormat(RichText);
                    ICQMsg *m = static_cast<ICQMsg*>(msg);
                    edit->setText(QString::fromLocal8Bit(m->Message.c_str()));
                    if (m->BackColor() != m->ForeColor()){
                        edit->setBackground(QColor(m->BackColor));
                        edit->setForeground(QColor(m->ForeColor));
                    }else{
                        edit->resetColors(true);
                    }
                    edit->setFocus();
                }
                break;
            }
        case ICQ_MSGxURL:{
                phone->hide();
                url->show();
                edit->show();
                edit->setTextFormat(PlainText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->show();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                ICQUrl *m = static_cast<ICQUrl*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Message.c_str()));
                urlEdit->setText(QString::fromLocal8Bit(m->URL.c_str()));
                urlEdit->setFocus();
                break;
            }
        case ICQ_MSGxFILE:{
                phone->hide();
                url->hide();
                edit->show();
                edit->setTextFormat(PlainText);
                users->hide();
                view->hide();
                file->show();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                ICQFile *m = static_cast<ICQFile*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Description.c_str()));
                fileEdit->setSaveMode(false);
                fileEdit->setText(QString::fromLocal8Bit(m->Name.c_str()));
                fileEdit->setFocus();
                break;
            }
        case ICQ_MSGxCHAT:{
                phone->hide();
                url->hide();
                edit->show();
                edit->setTextFormat(PlainText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                ICQChat *m = static_cast<ICQChat*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Reason.c_str()));
                break;
            }
        case ICQ_MSGxSMS:{
                phone->show();
                url->hide();
                edit->show();
                edit->setTextFormat(RichText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->show();
#endif
                ICQSMS *m = static_cast<ICQSMS*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(pClient->clearHTML(m->Message.c_str()).c_str()));
                if (*m->Phone.c_str())
                    phoneEdit->lineEdit()->setText(QString::fromLocal8Bit(m->Phone.c_str()));
                phoneEdit->setFocus();
                break;
            }
        case ICQ_MSGxCONTACTxLIST:{
                phone->hide();
                url->hide();
                edit->hide();
                users->show();
                view->hide();
                file->hide();
                lblUsers->show();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->show();
#ifdef USE_SPELL
                btnSpell->hide();
#endif
                ICQContacts *m = static_cast<ICQContacts*>(msg);
                for (ContactList::iterator it = m->Contacts.begin(); it != m->Contacts.end(); it++){
                    Contact *contact = static_cast<Contact*>(*it);
                    users->addUser(contact->Uin, contact->Alias);
                }
                users->sender = true;
                break;
            }
        case ICQ_MSGxAUTHxREQUEST:{
                phone->hide();
                url->hide();
                edit->show();
                edit->setTextFormat(RichText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->hide();
#endif
                ICQAuthRequest *m = static_cast<ICQAuthRequest*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Message.c_str()));
                edit->setFocus();
                break;
            }
        case ICQ_MSGxAUTHxREFUSED:{
                phone->hide();
                url->hide();
                edit->show();
                edit->setTextFormat(RichText);
                users->hide();
                view->hide();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->hide();
#endif
                ICQAuthRefused *m = static_cast<ICQAuthRefused*>(msg);
                edit->resetColors(false);
                edit->setText(QString::fromLocal8Bit(m->Message.c_str()));
                edit->setFocus();
                break;
            }
        case ICQ_MSGxAUTHxGRANTED:{
                phone->hide();
                url->hide();
                edit->hide();
                users->hide();
                view->show();
                file->hide();
                lblUsers->hide();
                btnBgColor->hide();
                btnFgColor->hide();
                btnBold->hide();
                btnItalic->hide();
                btnUnder->hide();
                btnFont->hide();
                btnMultiply->hide();
#ifdef USE_SPELL
                btnSpell->hide();
#endif
                break;
            }
        default:
            log(L_WARN, "Unknown message type %u", msg->Type());
        }
    }
    textChanged();
    setUpdatesEnabled(true);
    repaint();
}
Esempio n. 4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_contactsModel(new CContactsModel(this)),
    m_messagingModel(new CMessagingModel(this)),
    m_chatContactsModel(new CContactsModel(this)),
    m_chatMessagingModel(new CMessagingModel(this)),
    m_chatInfoModel(new CChatInfoModel(this)),
    m_activeChatId(0),
    m_chatCreationMode(false),
    m_core(new CTelegramCore(this)),
    m_registered(false),
    m_appState(AppStateNone)
{
    ui->setupUi(this);
    ui->contactListTable->setModel(m_contactsModel);
    ui->messagingView->setModel(m_messagingModel);
    ui->groupChatContacts->setModel(m_chatContactsModel);
    ui->groupChatChatsList->setModel(m_chatInfoModel);
    ui->groupChatMessagingView->setModel(m_chatMessagingModel);

    QCompleter *comp = new QCompleter(m_contactsModel, this);
    ui->messagingContactPhone->setCompleter(comp);
    ui->groupChatContactPhone->setCompleter(comp);

    connect(ui->secretOpenFile, SIGNAL(clicked()), SLOT(loadSecretFromBrowsedFile()));

    // Telepathy Morse app info
    CAppInformation appInfo;
    appInfo.setAppId(14617);
    appInfo.setAppHash(QLatin1String("e17ac360fd072f83d5d08db45ce9a121"));
    appInfo.setAppVersion(QLatin1String("0.1"));
    appInfo.setDeviceInfo(QLatin1String("pc"));
    appInfo.setOsInfo(QLatin1String("GNU/Linux"));
    appInfo.setLanguageCode(QLatin1String("en"));

    m_core->setAppInformation(&appInfo);
    m_core->setAutoReconnection(true);

    connect(m_core, SIGNAL(connectionStateChanged(TelegramNamespace::ConnectionState)),
            SLOT(whenConnectionStateChanged(TelegramNamespace::ConnectionState)));
    connect(m_core, SIGNAL(phoneStatusReceived(QString,bool,bool)),
            SLOT(whenPhoneStatusReceived(QString,bool,bool)));
    connect(m_core, SIGNAL(phoneCodeRequired()),
            SLOT(whenPhoneCodeRequested()));
    connect(m_core, SIGNAL(authSignErrorReceived(TelegramNamespace::AuthSignError,QString)),
            SLOT(whenAuthSignErrorReceived(TelegramNamespace::AuthSignError,QString)));
    connect(m_core, SIGNAL(contactListChanged()),
            SLOT(whenContactListChanged()));
    connect(m_core, SIGNAL(contactProfileChanged(QString)),
            SLOT(whenContactProfileChanged(QString)));
    connect(m_core, SIGNAL(avatarReceived(QString,QByteArray,QString,QString)),
            SLOT(whenAvatarReceived(QString,QByteArray,QString)));
    connect(m_core, SIGNAL(messageMediaDataReceived(QString,quint32,QByteArray,QString,TelegramNamespace::MessageType,quint32,quint32)),
            SLOT(whenMessageMediaDataReceived(QString,quint32,QByteArray,QString,TelegramNamespace::MessageType,quint32,quint32)));
    connect(m_core, SIGNAL(messageReceived(TelegramNamespace::Message)),
            SLOT(whenMessageReceived(TelegramNamespace::Message)));
    connect(m_core, SIGNAL(contactChatTypingStatusChanged(quint32,QString,bool)),
            SLOT(whenContactChatTypingStatusChanged(quint32,QString,bool)));
    connect(m_core, SIGNAL(contactTypingStatusChanged(QString,bool)),
            SLOT(whenContactTypingStatusChanged(QString,bool)));
    connect(m_core, SIGNAL(contactStatusChanged(QString,TelegramNamespace::ContactStatus)),
            SLOT(whenContactStatusChanged(QString)));
    connect(m_core, SIGNAL(sentMessageStatusChanged(QString,quint64,TelegramNamespace::MessageDeliveryStatus)),
            m_messagingModel, SLOT(setMessageDeliveryStatus(QString,quint64,TelegramNamespace::MessageDeliveryStatus)));
    connect(m_core, SIGNAL(uploadingStatusUpdated(quint32,quint32,quint32)),
            SLOT(whenUploadingStatusUpdated(quint32,quint32,quint32)));

    connect(m_core, SIGNAL(chatAdded(quint32)), SLOT(whenChatAdded(quint32)));
    connect(m_core, SIGNAL(chatChanged(quint32)), SLOT(whenChatChanged(quint32)));

    ui->groupChatContacts->hideColumn(CContactsModel::Blocked);

    ui->mainSplitter->setSizes(QList<int>() << 0 << 100);
    ui->groupChatSplitter->setSizes(QList<int>() << 550 << 450 << 300);

    ui->groupChatChatsList->setColumnWidth(CChatInfoModel::Id, 30);

    ui->blockContact->hide();
    ui->unblockContact->hide();

    ui->groupChatLeaveChat->hide();

    QFile helpFile(QLatin1String(":/USAGE"));
    helpFile.open(QIODevice::ReadOnly);
    ui->helpView->setPlainText(helpFile.readAll());

    setAppState(AppStateNone);
    updateGroupChatAddContactButtonText();

    connect(ui->groupChatContactPhone, SIGNAL(textChanged(QString)), SLOT(updateGroupChatAddContactButtonText()));

#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
    connect(ui->messagingView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(whenCustomMenuRequested(QPoint)));
#endif

    ui->groupChatAddContactForwardMessages->hide();

    ui->messagingAttachButton->hide();
}