~ubuntu-branches/ubuntu/natty/pidgin-otr/natty-updates

« back to all changes in this revision

Viewing changes to ui.c

  • Committer: Bazaar Package Importer
  • Author(s): Thibaut VARENE
  • Date: 2007-05-08 17:21:54 UTC
  • Revision ID: james.westby@ubuntu.com-20070508172154-rl73hykhkfbbvhzm
Tags: upstream-3.0.0+cvs20070508
ImportĀ upstreamĀ versionĀ 3.0.0+cvs20070508

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Off-the-Record Messaging plugin for pidgin
 
3
 *  Copyright (C) 2004-2005  Nikita Borisov and Ian Goldberg
 
4
 *                           <otr@cypherpunks.ca>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of version 2 of the GNU General Public License as
 
8
 *  published by the Free Software Foundation.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 */
 
19
 
 
20
/* system headers */
 
21
#include <stdlib.h>
 
22
 
 
23
/* purple headers */
 
24
#include "util.h"
 
25
#include "account.h"
 
26
 
 
27
/* libotr headers */
 
28
#include <libotr/privkey.h>
 
29
#include <libotr/proto.h>
 
30
#include <libotr/message.h>
 
31
 
 
32
/* purple-otr headers */
 
33
#include "ui.h"
 
34
#include "dialogs.h"
 
35
#include "otr-plugin.h"
 
36
 
 
37
static const OtrgUiUiOps *ui_ops = NULL;
 
38
 
 
39
/* Set the UI ops */
 
40
void otrg_ui_set_ui_ops(const OtrgUiUiOps *ops)
 
41
{
 
42
    ui_ops = ops;
 
43
}
 
44
 
 
45
/* Get the UI ops */
 
46
const OtrgUiUiOps *otrg_ui_get_ui_ops(void)
 
47
{
 
48
    return ui_ops;
 
49
}
 
50
 
 
51
/* Call this function when the DSA key is updated; it will redraw the
 
52
 * UI, if visible. */
 
53
void otrg_ui_update_fingerprint(void)
 
54
{
 
55
    if (ui_ops != NULL) {
 
56
        ui_ops->update_fingerprint();
 
57
    }
 
58
}
 
59
 
 
60
/* Update the keylist, if it's visible */
 
61
void otrg_ui_update_keylist(void)
 
62
{
 
63
    if (ui_ops != NULL) {
 
64
        ui_ops->update_keylist();
 
65
    }
 
66
}
 
67
 
 
68
/* Send an OTR Query Message to attempt to start a connection */
 
69
void otrg_ui_connect_connection(ConnContext *context)
 
70
{
 
71
    /* Send an OTR Query to the other side. */
 
72
    PurpleAccount *account;
 
73
    char *msg;
 
74
        
 
75
    /* Don't do this if we're already ENCRYPTED */
 
76
    if (context == NULL || context->msgstate == OTRL_MSGSTATE_ENCRYPTED)
 
77
        return;
 
78
        
 
79
    account = purple_accounts_find(context->accountname, context->protocol);
 
80
    if (!account) {
 
81
        PurplePlugin *p = purple_find_prpl(context->protocol);
 
82
        msg = g_strdup_printf("Account %s (%s) could not be found",
 
83
                  context->accountname,
 
84
                  (p && p->info->name) ? p->info->name : "Unknown");
 
85
        otrg_dialog_notify_error(context->accountname, context->protocol,
 
86
                context->username, "Account not found", msg, NULL);
 
87
        g_free(msg);
 
88
        return;
 
89
    }
 
90
    otrg_plugin_send_default_query(context, account);   
 
91
}
 
92
 
 
93
/* Drop a context to PLAINTEXT state */
 
94
void otrg_ui_disconnect_connection(ConnContext *context)
 
95
{
 
96
    /* Don't do anything with PLAINTEXT fingerprints */
 
97
    if (context == NULL || context->msgstate == OTRL_MSGSTATE_PLAINTEXT)
 
98
        return;
 
99
                
 
100
    otrg_plugin_disconnect(context);
 
101
    otrg_dialog_disconnected(context);  
 
102
}
 
103
 
 
104
/* Forget a fingerprint */
 
105
void otrg_ui_forget_fingerprint(Fingerprint *fingerprint)
 
106
{
 
107
    ConnContext *context;
 
108
        
 
109
    if (fingerprint == NULL) return;
 
110
 
 
111
    /* Don't do anything with the active fingerprint if we're in the
 
112
     * ENCRYPTED state. */
 
113
    context = fingerprint->context;
 
114
    if (context->msgstate == OTRL_MSGSTATE_ENCRYPTED &&
 
115
            context->active_fingerprint == fingerprint) return;
 
116
        
 
117
    otrl_context_forget_fingerprint(fingerprint, 1);
 
118
    otrg_plugin_write_fingerprints();
 
119
        
 
120
    otrg_ui_update_keylist();
 
121
}
 
122
 
 
123
/* Configure OTR for a particular buddy */
 
124
void otrg_ui_config_buddy(PurpleBuddy *buddy)
 
125
{
 
126
    if (ui_ops != NULL) {
 
127
        ui_ops->config_buddy(buddy);
 
128
    }
 
129
}
 
130
 
 
131
/* Calculate the policy for a particular account / username */
 
132
OtrlPolicy otrg_ui_find_policy(PurpleAccount *account, const char *name)
 
133
{
 
134
    /* Check to see if the protocol for this account supports OTR at all. */
 
135
    const char *proto = purple_account_get_protocol_id(account);
 
136
    if (!otrg_plugin_proto_supports_otr(proto)) {
 
137
        return OTRL_POLICY_NEVER;
 
138
    }
 
139
 
 
140
    if (ui_ops != NULL) {
 
141
        return ui_ops->find_policy(account, name);
 
142
    }
 
143
    return OTRL_POLICY_DEFAULT;
 
144
}