Skip to content

Commit

Permalink
Implementing a configuration property to evaluate if the user want to…
Browse files Browse the repository at this point in the history
… show the SSID on conversation screen
  • Loading branch information
MauroVelasco committed Aug 7, 2019
1 parent 42b9be5 commit 5f14624
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
3 changes: 2 additions & 1 deletion gtk-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,8 @@ otrng_gtk_dialog_connected_real(const otrng_plugin_conversation *context) {
otrng_conversation_s *otr_conv =
purple_conversation_to_otrng_conversation(conv);

if (memcmp(otr_conv->conn->keys->ssid, emptySSID, 8) != 0) {
if (memcmp(otr_conv->conn->keys->ssid, emptySSID, 8) != 0 &&
purple_prefs_get_bool("/OTR/showssidbutton") ){
if (otr_conv->conn->keys->ssid_half_first) {
ssid = _("The <a href=\"ssid\">SSID</a> for this conversation is: "
"<b>%02X%02X%02X%02X</b> %02X%02X%02X%02X");
Expand Down
56 changes: 47 additions & 9 deletions gtk-ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct otrsettingsdata {

struct otroptionsdata {
GtkWidget *showotrbutton;
GtkWidget *showssidbutton;
};

static struct {
Expand Down Expand Up @@ -615,24 +616,36 @@ static void create_otrsettings_buttons(struct otrsettingsdata *os,
G_CALLBACK(otrsettings_clicked_cb), os);
g_signal_connect(G_OBJECT(os->avoidloggingotrbox), "clicked",
G_CALLBACK(otrsettings_clicked_cb), os);

}

static void otroptions_clicked_cb(GtkButton *button,
struct otroptionsdata *oo) {
/* This doesn't really do anything useful right now, but is here for
* future expansion purposes. */
gtk_widget_set_sensitive(oo->showotrbutton, TRUE);

gtk_widget_set_sensitive(oo->showssidbutton, TRUE);
}

static void create_otroptions_buttons(struct otroptionsdata *oo,
GtkWidget *vbox) {
oo->showotrbutton =
gtk_check_button_new_with_label(_("Show OTR button in toolbar"));

oo->showssidbutton =
gtk_check_button_new_with_label(_("Show Secure Session ID (SSID)"));


gtk_box_pack_start(GTK_BOX(vbox), oo->showotrbutton, FALSE, FALSE, 0);

gtk_box_pack_start(GTK_BOX(vbox), oo->showssidbutton, FALSE, FALSE, 0);

g_signal_connect(G_OBJECT(oo->showotrbutton), "clicked",
G_CALLBACK(otroptions_clicked_cb), oo);

g_signal_connect(G_OBJECT(oo->showssidbutton), "clicked",
G_CALLBACK(otroptions_clicked_cb), oo);
}

/* Load the global OTR prefs */
Expand Down Expand Up @@ -721,34 +734,53 @@ static void load_otrsettings(struct otrsettingsdata *os) {
}

/* Load the global OTR UI options */
static void otrng_gtk_ui_global_options_load(gboolean *showotrbuttonp) {
static void otrng_gtk_ui_global_options_load(gboolean *showotrbuttonp , gboolean *showssidbuttonp) {
if (purple_prefs_exists("/OTR/showotrbutton")) {
*showotrbuttonp = purple_prefs_get_bool("/OTR/showotrbutton");
} else {
*showotrbuttonp = TRUE;
}

if (purple_prefs_exists("/OTR/showssidbutton")) {
*showssidbuttonp = purple_prefs_get_bool("/OTR/showssidbutton");
} else {
*showssidbuttonp = FALSE;
}
}

/* Save the global OTR UI options */
static void otrng_gtk_ui_global_options_save(gboolean showotrbutton) {
static void otrng_gtk_ui_global_options_save(gboolean showotrbutton , gboolean showssidbutton) {
if (!purple_prefs_exists("/OTR")) {
purple_prefs_add_none("/OTR");
}

if (!purple_prefs_exists("/OTR/showotrbutton")) {
purple_prefs_add_bool("/OTR/showotrbutton", showotrbutton);
}else{
purple_prefs_set_bool("/OTR/showotrbutton", showotrbutton);
}

if (!purple_prefs_exists("/OTR/showssidbutton")) {
purple_prefs_add_bool("/OTR/showssidbutton", showssidbutton);
}else{
purple_prefs_set_bool("/OTR/showssidbutton", showssidbutton);
}
purple_prefs_set_bool("/OTR/showotrbutton", showotrbutton);
}

static void load_otroptions(struct otroptionsdata *oo) {
gboolean showotrbutton;
gboolean showssidbutton;

otrng_gtk_ui_global_options_load(&showotrbutton);
otrng_gtk_ui_global_options_load(&showotrbutton,&showssidbutton);

gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(oo->showotrbutton),
showotrbutton);

gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(oo->showssidbutton),
showssidbutton);

otroptions_clicked_cb(GTK_BUTTON(oo->showotrbutton), oo);
otroptions_clicked_cb(GTK_BUTTON(oo->showssidbutton), oo);
}

/* Create the privkeys UI, and pack it into the vbox */
Expand Down Expand Up @@ -813,7 +845,8 @@ static void otrsettings_save_cb(GtkButton *button, struct otrsettingsdata *os) {
/* Save the global OTR UI options whenever they're clicked */
static void otroptions_save_cb(GtkButton *button, struct otroptionsdata *oo) {
otrng_gtk_ui_global_options_save(
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oo->showotrbutton)));
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oo->showotrbutton)),
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oo->showssidbutton)));

otrng_dialog_resensitize_all();
}
Expand Down Expand Up @@ -863,6 +896,9 @@ static void make_options_ui(GtkWidget *vbox) {

g_signal_connect(G_OBJECT(ui_layout.oo.showotrbutton), "clicked",
G_CALLBACK(otroptions_save_cb), &(ui_layout.oo));

g_signal_connect(G_OBJECT(ui_layout.oo.showssidbutton), "clicked",
G_CALLBACK(otroptions_save_cb), &(ui_layout.oo));
}

/* Create the fingerprint UI, and pack it into the vbox */
Expand Down Expand Up @@ -1038,6 +1074,7 @@ static void load_buddyprefs(struct cbdata *data) {
onlyprivate);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->os.avoidloggingotrbox),
avoidloggingotr);

}

default_clicked_cb(GTK_BUTTON(data->defaultbox), data);
Expand All @@ -1058,8 +1095,7 @@ static void config_buddy_clicked_cb(GtkButton *button, struct cbdata *data) {
enabled,
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->os.automaticbox)),
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->os.onlyprivatebox)),
gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(data->os.avoidloggingotrbox)));
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->os.avoidloggingotrbox)));

otrng_dialog_resensitize_all();
}
Expand Down Expand Up @@ -1160,11 +1196,12 @@ static void otrng_gtk_ui_get_prefs(OtrgUiPrefs *prefsp, PurpleAccount *account,
prefsp->policy = OTRL_POLICY_DEFAULT;
prefsp->avoid_logging_otr = FALSE;
prefsp->show_otr_button = FALSE;
prefsp->show_ssid_button = FALSE;

/* Get the default policy */
otrng_gtk_ui_global_prefs_load(&otrenabled, &otrautomatic, &otronlyprivate,
&otravoidloggingotr);
otrng_gtk_ui_global_options_load(&(prefsp->show_otr_button));
otrng_gtk_ui_global_options_load(&(prefsp->show_otr_button),&(prefsp->show_ssid_button));

if (otrenabled) {
if (otrautomatic) {
Expand Down Expand Up @@ -1225,11 +1262,12 @@ static void otrng_gtk_ui_get_prefs_v4(otrng_ui_prefs *prefs,
prefs->policy.type = OTRNG_POLICY_DEFAULT;
prefs->avoid_logging_otr = FALSE;
prefs->show_otr_button = FALSE;
prefs->show_ssid_button = FALSE;

/* Get the default policy */
otrng_gtk_ui_global_prefs_load(&otrng_enabled, &otrng_automatic,
&otrng_only_private, &otrng_avoid_logging_otr);
otrng_gtk_ui_global_options_load(&(prefs->show_otr_button));
otrng_gtk_ui_global_options_load(&(prefs->show_otr_button),&(prefs->show_ssid_button));

if (otrng_enabled) {
prefs->policy.allows = OTRNG_ALLOW_V34;
Expand Down
2 changes: 2 additions & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ typedef struct {
OtrlPolicy policy;
gboolean avoid_logging_otr;
gboolean show_otr_button;
gboolean show_ssid_button;
} OtrgUiPrefs;

typedef struct {
otrng_policy_s policy;
gboolean avoid_logging_otr;
gboolean show_otr_button;
gboolean show_ssid_button;
} otrng_ui_prefs;

typedef struct {
Expand Down

0 comments on commit 5f14624

Please sign in to comment.