File: securedlg.cpp

package info (click to toggle)
sim 0.9.5~svn20080806-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 18,108 kB
  • ctags: 11,570
  • sloc: cpp: 119,605; sh: 9,986; ansic: 3,312; perl: 2,752; lex: 1,533; makefile: 839; xml: 206; python: 56
file content (110 lines) | stat: -rw-r--r-- 3,147 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/***************************************************************************
                          securedlg.cpp  -  description
                             -------------------
    begin                : Sun Mar 17 2002
    copyright            : (C) 2002 by Vladimir Shutoff
    email                : vovan@shutoff.ru
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "icons.h"
#include "securedlg.h"
#include "icqclient.h"
#include "icqmessage.h"

#include <qpixmap.h>
#include <qtimer.h>
#include <qpushbutton.h>
#include <qtimer.h>
#include <qlabel.h>

using namespace SIM;

SecureDlg::SecureDlg(ICQClient *client, unsigned contact, ICQUserData *data)
        : SecureDlgBase(NULL, "securedlg", false, WDestructiveClose)
{
    SET_WNDPROC("secure")
    setIcon(Pict("encrypted"));
    setButtonsPict(this);
    setCaption(caption());
    m_client  = client;
    m_contact = contact;
    m_data    = data;
    m_msg	  = NULL;
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(close()));
    QTimer::singleShot(0, this, SLOT(start()));
}

SecureDlg::~SecureDlg()
{
    if (m_msg)
        EventMessageCancel(m_msg).process();
}

void SecureDlg::start()
{
    m_msg = new Message(MessageOpenSecure);
    m_msg->setContact(m_contact);
    m_msg->setClient(m_client->dataName(m_data));
    m_msg->setFlags(MESSAGE_NOHISTORY);
    if (!static_cast<Client*>(m_client)->send(m_msg, m_data)){
        delete m_msg;
        error(I18N_NOOP("Request secure channel fail"));
    }
}

bool SecureDlg::processEvent(Event *e)
{
    switch(e->type()) {
    case eEventContact: {
        EventContact *ec = static_cast<EventContact*>(e);
        switch(ec->action()) {
            case EventContact::eDeleted: {
                close();
                break;
            }
            default:
                break;
        }
        break;
    }
    case eEventMessageSent: {
        EventMessage *em = static_cast<EventMessage*>(e);
        Message *msg = em->msg();
        if (msg != m_msg)
            return false;
        QString err = msg->getError();
        if (!err.isEmpty()){
            error(err);
        }else{
            m_msg = NULL;
            close();
        }
        return true;
    }
    default:
        break;
    }
    return false;
}

void SecureDlg::error(const QString &err)
{
    QString errText = i18n(err);
    m_msg = NULL;
    lblError->setText(errText);
    btnCancel->setText(i18n("&Close"));
}

#ifndef NO_MOC_INCLUDES
#include "securedlg.moc"
#endif