Exemple #1
0
Telegram::Telegram(int argc, char **argv, QObject *parent) :
    QObject(parent)
{
    p = new TelegramPrivate;
    p->update_dialog_again = false;
    p->update_dialog_timer_id = 0;
    p->update_contact_again = false;
    p->update_contact_timer_id = 0;
    p->authenticating = false;
    p->started = false;
    p->msg_send_timer = 0;
    p->last_wait_and_get = Enums::NoWaitAndGet;

    p->tg_thread = new TelegramThread(argc,argv);

    connect( p->tg_thread, SIGNAL(contactsChanged())                   , SIGNAL(meChanged())                          );
    connect( p->tg_thread, SIGNAL(contactsChanged())                   , SLOT(_loadOwnInfo())                         );
    connect( p->tg_thread, SIGNAL(unreadChanged())                     , SIGNAL(unreadChanged())                      );
    connect( p->tg_thread, SIGNAL(contactsChanged())                   , SIGNAL(contactsChanged())                    );
    connect( p->tg_thread, SIGNAL(dialogsChanged())                    , SIGNAL(dialogsChanged())                     );
    connect( p->tg_thread, SIGNAL(incomingMsg(qint64))                 , SIGNAL(incomingMsg(qint64))                  );
    connect( p->tg_thread, SIGNAL(incomingNewMsg(qint64))              , SLOT(_incomingNewMsg(qint64))                );
    connect( p->tg_thread, SIGNAL(userIsTyping(int,int))               , SIGNAL(userIsTyping(int,int))                );
    connect( p->tg_thread, SIGNAL(userStatusChanged(int,int,QDateTime)), SIGNAL(userStatusChanged(int,int,QDateTime)) );
    connect( p->tg_thread, SIGNAL(msgChanged(qint64))                  , SIGNAL(msgChanged(qint64))                   );
    connect( p->tg_thread, SIGNAL(msgSent(qint64,qint64))              , SIGNAL(msgSent(qint64,qint64))               );
    connect( p->tg_thread, SIGNAL(userPhotoChanged(int))               , SIGNAL(userPhotoChanged(int))                );
    connect( p->tg_thread, SIGNAL(chatPhotoChanged(int))               , SIGNAL(chatPhotoChanged(int))                );
    connect( p->tg_thread, SIGNAL(fileUploaded(int,QString))           , SIGNAL(fileUploaded(int,QString))            );
    connect( p->tg_thread, SIGNAL(fileUploading(int,QString,qreal))    , SIGNAL(fileUploading(int,QString,qreal))     );
    connect( p->tg_thread, SIGNAL(fileUserUploaded(int))               , SIGNAL(fileUserUploaded(int))                );
    connect( p->tg_thread, SIGNAL(fileUserUploading(int,qreal))        , SIGNAL(fileUserUploading(int,qreal))         );
    connect( p->tg_thread, SIGNAL(msgFileDownloaded(qint64))           , SIGNAL(msgFileDownloaded(qint64))            );
    connect( p->tg_thread, SIGNAL(msgFileDownloading(qint64,qreal))    , SIGNAL(msgFileDownloading(qint64,qreal))     );
    connect( p->tg_thread, SIGNAL(messageDeleted(qint64))              , SIGNAL(messageDeleted(qint64))               );
    connect( p->tg_thread, SIGNAL(messageRestored(qint64))             , SIGNAL(messageRestored(qint64))              );
    connect( p->tg_thread, SIGNAL(registeringStarted())                , SLOT(registeringStarted())                   );
    connect( p->tg_thread, SIGNAL(registeringFinished())               , SLOT(registeringFinished())                  );
    connect( p->tg_thread, SIGNAL(registeringInvalidCode())            , SIGNAL(registeringInvalidCode())             );
    connect( p->tg_thread, SIGNAL(myStatusUpdated())                   , SIGNAL(myStatusUpdated())                    );
    connect( p->tg_thread, SIGNAL(waitAndGet(int))                     , SLOT(_waitAndGet(int))                       );
    connect( p->tg_thread, SIGNAL(tgStarted())                         , SLOT(_startedChanged())                      );

    p->tg_thread->start();
}
Exemple #2
0
void connection::chatData()
{
    QByteArray receive_datagram;
    quint16 serverPort;
    qDebug() << UDPsocket->pendingDatagramSize();
    receive_datagram.resize(UDPsocket->pendingDatagramSize());
    UDPsocket->readDatagram(receive_datagram.data(),receive_datagram.size(),&opponent,&serverPort);
    qDebug() << receive_datagram.data();
    QString input = QString::fromUtf8(receive_datagram.data());
    qDebug() << "input: " + input;
    QStringList list = input.split("@@");
    if(list.at(1)!=QString::number(speler))
    {
        qDebug("recieve6");
        QString info = "Openent: " + list.at(0) + "\n";
        emit msgChanged(info);
    }
}
Exemple #3
0
DockWnd::DockWnd(QWidget *main)
        : QWidget(NULL, "dock",  WType_TopLevel | WStyle_Customize | WStyle_NoBorder | WStyle_StaysOnTop)
{
    setMouseTracking(true);
    connect(this, SIGNAL(toggleWin()), main, SLOT(toggleShow()));
    connect(this, SIGNAL(showPopup(QPoint)), main, SLOT(showDockPopup(QPoint)));
    connect(this, SIGNAL(doubleClicked()), main, SLOT(dockDblClicked()));
    connect(pClient, SIGNAL(event(ICQEvent*)), this, SLOT(processEvent(ICQEvent*)));
    connect(pMain, SIGNAL(iconChanged()), this, SLOT(reset()));
    connect(pMain, SIGNAL(msgChanged()), this, SLOT(reset()));
    m_state = 0;
    showIcon = State;
    QTimer *t = new QTimer(this);
    connect(t, SIGNAL(timeout()), this, SLOT(timer()));
    t->start(800);
    bNoToggle = false;
#ifdef WIN32
    QWidget::hide();
    QWidget::setIcon(Pict(pClient->getStatusIcon()));
    gDock = this;
    oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    if (oldDockProc == 0)
        oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    NOTIFYICONDATAA notifyIconData;
    notifyIconData.cbSize = sizeof(notifyIconData);
    notifyIconData.hIcon = topData()->winIcon;
    notifyIconData.hWnd = winId();
    notifyIconData.szTip[0] = 0;
    notifyIconData.uCallbackMessage = WM_DOCK;
    notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    notifyIconData.uID = 0;
    Shell_NotifyIconA(NIM_ADD, &notifyIconData);
#else
    setMinimumSize(22, 22);
    resize(22, 22);
    bInit = false;
    inTray = false;
    inNetTray = false;

    Display *dsp = x11Display();
    WId win = winId();

    if (bEnlightenment){
        wharfIcon = NULL;
        bInit = true;
        resize(48, 48);
        setFocusPolicy(NoFocus);
        move(pMain->getDockX(), pMain->getDockY());
        reset();
        MWMHints mwm;
        mwm.flags = MWM_HINTS_DECORATIONS;
        mwm.functions = 0;
        mwm.decorations = 0;
        mwm.inputMode = 0;
        mwm.status = 0;
        Atom a = XInternAtom(dsp, "_MOTIF_WM_HINTS", False);
        XChangeProperty(dsp, win, a, a, 32, PropModeReplace,
                        (unsigned char *)&mwm, sizeof(MWMHints) / 4);
        XStoreName(dsp, win, "SIM");
        XClassHint *xch = XAllocClassHint();
        xch->res_name  = (char*)"SIM";
        xch->res_class = (char*)"Epplet";
        XSetClassHint(dsp, win, xch);
        XFree(xch);
        XSetIconName(dsp, win, "SIM");
        unsigned long val = (1 << 0) /* | (1 << 9) */ ;
        a = XInternAtom(dsp, "_WIN_STATE", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = 2;
        a = XInternAtom(dsp, "_WIN_LAYER", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 5);
        a = XInternAtom(dsp, "_WIN_HINTS", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        win_name = "SIM";
        win_version = VERSION;
        win_info = "";
        while (!comms_win)
        {
            ECommsSetup(dsp);
            sleep(1);
        }
        char s[256];
        snprintf(s, sizeof(s), "set clientname %s", win_name);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set version %s", win_version);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set info %s", win_info);
        ECommsSend(s);
        ESYNC;

        set_background_properties(this);

        show();
        return;
    }

    wharfIcon = new WharfIcon(this);

    setBackgroundMode(X11ParentRelative);
    const QPixmap &pict = Pict(pClient->getStatusIcon());
    setIcon(pict);

    XClassHint classhint;
    classhint.res_name  = (char*)"sim";
    classhint.res_class = (char*)"Wharf";
    XSetClassHint(dsp, win, &classhint);

    Screen *screen = XDefaultScreenOfDisplay(dsp);
    int screen_id = XScreenNumberOfScreen(screen);
    char buf[32];
    snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id);
    Atom selection_atom = XInternAtom(dsp, buf, false);
    XGrabServer(dsp);
    Window manager_window = XGetSelectionOwner(dsp, selection_atom);
    if (manager_window != None)
        XSelectInput(dsp, manager_window, StructureNotifyMask);
    XUngrabServer(dsp);
    XFlush(dsp);
    if (manager_window != None){
        inNetTray = true;
        if (!send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, win, 0, 0)){
            inNetTray = false;
        }
    }

    Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);

    long data[1];
    data[0] = 0;
    XChangeProperty(dsp, win, kde_net_system_tray_window_for_atom, XA_WINDOW,
                    32, PropModeReplace,
                    (unsigned char*)data, 1);

    XWMHints *hints;
    hints = XGetWMHints(dsp, win);
    hints->initial_state = WithdrawnState;
    hints->icon_x = 0;
    hints->icon_y = 0;
    hints->icon_window = wharfIcon->winId();
    hints->window_group = win;
    hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint;
    XSetWMHints(dsp, win, hints);
    XFree( hints );
    XSetCommand(dsp, win, _argv, _argc);

    if (!inNetTray){
        move(-21, -21);
        resize(22, 22);
    }
    show();
#endif
    reset();
}
Exemple #4
0
bool CanProtcl::bCheckErrorRply(CanProtcl::tRevFrame *frame)
{
    static int len = 0;
    static int lencount = 0;
    if((frame->uiCanID & M_ID_CMD) == S_FIRST_RPLY) {    //收到从机第一条回复
 //       printf("S_FIRST_RPLY\n");
        lencount = 0;
        memset(&RevData,0,sizeof(RevData));  //清除接收缓存
        if(frame_rp != frame->ucFrameBuf[0]) {
            printf("Frame type error: not a reply frame !\n");
            lencount = 0;
            return false;
        }
        else if(SRC_ADDR != frame->ucFrameBuf[1]){
            printf("Frame Address error: not a host address !\n");
            lencount = 0;
            return false;
        }
    /*    else if((SendData.ucBuf[2] | 0x80)!= frame->ucFrameBuf[2]){
            printf("first Cmd error !\n");
            lencount = 0;
            return false;
        }*/

        lencount += frame->uiFrameLen; //此次CAN数据长度
        RevData.ucLen = lencount;
        memcpy(RevData.ucBuf,frame->ucFrameBuf,frame->uiFrameLen); //
        len = frame->ucFrameBuf[3]; //保存帧长度
        vSendPacket(NEXT_RPLY_ID,SendData.ucBuf[2]);
        return true;
    }
    else if((frame->uiCanID & M_ID_CMD) == S_LAST_RPLY) { //收到从机最后一条回复
         if(lencount == 0){
            if(frame_rp != frame->ucFrameBuf[0]) {
                printf("Frame type error: not a reply frame !\n");
                return false;
            }
            else if(SRC_ADDR != frame->ucFrameBuf[1]){
                printf("Frame Address error: not a host address !\n");
                return false;
            }
      /*      else if((SendData.ucBuf[2] | 0x80)!= frame->ucFrameBuf[2]){
                printf("last Cmd error !\n");
                return false;
            }*/
            else if(frame->uiFrameLen  != frame->ucFrameBuf[3]) {     //检查长度
                 printf("Frame length error !\n");
                 return false;
             }
            else if(frame->ucFrameBuf[frame->uiFrameLen-1] !=
                    ucXOR(frame->ucFrameBuf,frame->uiFrameLen-1)) {  //检查CRC
                 printf("Frame CRC error !\n");
                 return false;
             }
            RevData.ucLen = frame->uiFrameLen; //此次CAN数据长度
            memcpy(RevData.ucBuf,frame->ucFrameBuf,frame->uiFrameLen); //
         }
         else {     //检查长度
            memcpy(RevData.ucBuf+RevData.ucLen,frame->ucFrameBuf,frame->uiFrameLen); //
            lencount += frame->uiFrameLen; //此次CAN数据长度
            RevData.ucLen = lencount;
            if(lencount != len) {
                printf("Frame length error ! lencount =%d len =%d\n",lencount,len);
                memset(&RevData,0,sizeof(RevData));  //清除接收缓存
                lencount = 0;
                return false;
            }
            else if(frame->ucFrameBuf[frame->uiFrameLen-1] !=
                    ucXOR(RevData.ucBuf,RevData.ucLen-1)) {  //检查CRC
                printf("Frame CRC error !\n");
                memset(&RevData,0,sizeof(RevData));  //清除接收缓存
                lencount = 0;
                return false;
            }
        }
         lencount = 0;
         emit msgChanged();
         return true;
    }
    else if((frame->uiCanID & M_ID_CMD) == S_NEXT_RPLY) {  //收到从机继续回复
        memcpy(RevData.ucBuf+RevData.ucLen,frame->ucFrameBuf,frame->uiFrameLen); //
        lencount += frame->uiFrameLen; //此次CAN数据长度 += frame->uiFrameLen; //此次CAN数据长度
        RevData.ucLen = lencount;
        vSendPacket(NEXT_RPLY_ID,SendData.ucBuf[2]);
        return true;
    }
    else return true;
}