#include "securitywindow.h"
securityWindow::securityWindow()
{
wType = UE_ENCRYPTION;
}
securityWindow::~securityWindow()
{
delete manager;
}
GtkWidget* securityWindow::createWindowContent()
{
GString *toShow;
gchar *res,
*titleText;
GtkWidget *vbox1,
*vbox2,
*hbox,
*frame,
*label,
*img;
// create the symbol
img = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG);
gtk_misc_set_alignment(GTK_MISC(img), 0.0f, 0.0f);
// create the description
toShow = g_string_new(tr("Secure channel is established using SSL "
"with Diffie-Hellman key exchange and"
"the TLS version 1 protocol\n\n"));
if (((IMSecurityManager*)manager)->hasSecureChannelOnThisClient())
{
if (!((IMSecurityManager*)manager)->secureChannelActivated())
{
switch( ((IMSecurityManager*)manager)->secureChannelSupport())
{
case SECURE_CHANNEL_NOTSUPPORTED:
g_string_append_printf(toShow, tr("The remote user is using a version of Licq "
"that doesn't support encrypted connections. "
"The process will fail!\n\n"
"Would you like to still try it?") );
break;
case SECURE_CHANNEL_SUPPORTED:
g_string_append_printf(toShow, "%s", tr("Establish a secure channel?"));
break;
default:
g_string_append_printf(toShow, tr("It is possible that the remote user's client "
"is not able to establish a secure connection\n\n"
"Would you like to try it?"));
break;
}
} else
g_string_append_printf(toShow, "%s", tr("Disconnect the secure channel?"));
} else
g_string_append_printf(toShow, "%s", tr("Establishing a secure connection is not compiled into this client. Please recompile Licq with the appropriate options set."));
res = g_string_free(toShow, FALSE);
label = gtk_label_new(res);
gtk_widget_set_size_request(label, 250, -1);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
g_free(res);
// create the status line
statusInfo = gtk_label_new(tr("Ready ..."));
gtk_misc_set_alignment(GTK_MISC(statusInfo), 0.0f, 0.5f);
frame = gtk_frame_new(0);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(frame), statusInfo);
// add everything into the box
vbox1 = gtk_vbox_new(FALSE, 4);
gtk_box_pack_start(GTK_BOX(vbox1), label, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox1), frame, FALSE, TRUE, 0);
// add the image and the vbox1 into a hbox
hbox = gtk_hbox_new(FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), vbox1, TRUE, TRUE, 0);
// and add everything into a vbox to include the button bar
vbox2 = gtk_vbox_new(FALSE, 15);
gtk_box_pack_start(GTK_BOX(vbox2), hbox, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox2), createButtonbar(), FALSE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(vbox2), 10);
titleText = g_strdup_printf(tr("Establish a secure connection with %s"), manager->info->alias);
setWindowTitle(titleText);
g_free(titleText);
return vbox2;
}
GtkWidget* securityWindow::createButtonbar()
{
GtkWidget *hbox;
waitAni = new processingAni();
waitAni->setupAnimation(i_getIcons()->images.searchingAni, 22, 22);
// create the send button
if (!((IMSecurityManager*)manager)->secureChannelActivated())
sendButton = u_createTextStockImageButton(tr("Open channel"), GTK_STOCK_OK);
else
sendButton = u_createTextStockImageButton(tr("Close channel"), GTK_STOCK_OK);
if (!((IMSecurityManager*)manager)->hasSecureChannelOnThisClient())
gtk_widget_set_sensitive(sendButton, FALSE);
g_signal_connect_swapped(sendButton, "clicked", G_CALLBACK(this->cb_sendButtonClicked), this);
// create the close button
closeButton = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
g_signal_connect_swapped(closeButton, "clicked", G_CALLBACK(this->cb_closeButtonClicked), this);
hbox = gtk_hbox_new(FALSE, 3);
gtk_box_pack_start(GTK_BOX(hbox), waitAni->widget, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(hbox), closeButton, FALSE, TRUE, 0);
gtk_box_pack_end(GTK_BOX(hbox), sendButton, FALSE, TRUE, 0);
return hbox;
}
void securityWindow::destroyWindowContent()
{
stopOpenChannel();
delete waitAni;
}
void securityWindow::startOpenChannel()
{
gtk_button_set_label(GTK_BUTTON(closeButton), GTK_STOCK_CANCEL);
gtk_button_set_use_stock(GTK_BUTTON(closeButton), TRUE);
gtk_widget_set_sensitive(sendButton, FALSE);
waitAni->play();
if (!((IMSecurityManager*)manager)->secureChannelActivated())
((IMSecurityManager*)manager)->connectSecureChannel();
else
((IMSecurityManager*)manager)->disconnectSecureChannel();
gtk_label_set_text(GTK_LABEL(statusInfo), tr("Requesting channel ..."));
}
void securityWindow::stopOpenChannel()
{
gtk_button_set_label(GTK_BUTTON(closeButton), GTK_STOCK_CLOSE);
gtk_button_set_use_stock(GTK_BUTTON(closeButton), TRUE);
gtk_widget_set_sensitive(sendButton, TRUE);
waitAni->stop();
if (manager->isProcessing)
{
manager->cancelInitatedEvent();
gtk_label_set_text(GTK_LABEL(statusInfo), tr("Canceled"));
}
}
gboolean securityWindow::eventCallback(gint command, gint lastResult, gpointer info)
{
if (command == UC_EVENT_FINISHED)
{
switch(lastResult)
{
case EVENT_RESULT_SUCCESS:
destroyWindow();
delete this;
break;
case EVENT_RESULT_ERROR:
gtk_label_set_text(GTK_LABEL(statusInfo), tr("Unknown error"));
stopOpenChannel();
break;
case EVENT_RESULT_TIMEOUT:
gtk_label_set_text(GTK_LABEL(statusInfo), tr("No answer from remote client!"));
stopOpenChannel();
break;
}
}
return TRUE;
}
void securityWindow::cb_sendButtonClicked(securityWindow* self)
{
self->startOpenChannel();
}
void securityWindow::cb_closeButtonClicked(securityWindow* self)
{
if (self->manager->isProcessing)
self->stopOpenChannel();
else
{
self->destroyWindow();
delete self;
}
}