Skip to content

Commit

Permalink
Add possibility to insert link by nickname
Browse files Browse the repository at this point in the history
Originally patch was found here:
	http://people.freebsd.org/~novel/patches/non-freebsd/logjam452_userlink.diff

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  • Loading branch information
andy-shev committed May 9, 2009
1 parent 51ab126 commit 43ff911
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/link-journal.c
Expand Up @@ -44,11 +44,12 @@ make_usertype_omenu() {
void
link_journal_dialog_run(GtkWindow *win, JamDoc *doc) {
GtkWidget *dlg;
GtkWidget *vbox, *hbox, *entry, *omenu;
GtkWidget *vbox, *hbox, *entry, *entry_name, *omenu;
GtkSizeGroup *sizegroup;
GtkTextBuffer *buffer;
GtkTextIter start, end;
char *username = NULL;
char *usernick = NULL;
int usertype;
gboolean selection = FALSE;

Expand Down Expand Up @@ -78,6 +79,11 @@ link_journal_dialog_run(GtkWindow *win, JamDoc *doc) {
hbox = labelled_box_new_sg(_("_Username:"), entry, sizegroup);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

entry_name = gtk_entry_new();
gtk_entry_set_activates_default(GTK_ENTRY(entry_name), TRUE);
hbox = labelled_box_new_sg(_("_Nickname:"), entry_name, sizegroup);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

omenu = make_usertype_omenu();
hbox = labelled_box_new_sg(_("User _Type:"), omenu, sizegroup);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
Expand All @@ -89,6 +95,7 @@ link_journal_dialog_run(GtkWindow *win, JamDoc *doc) {
return;
}
username = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
usernick = gtk_editable_get_chars(GTK_EDITABLE(entry_name), 0, -1);
usertype = gtk_option_menu_get_history(GTK_OPTION_MENU(omenu));
gtk_widget_destroy(dlg);
if (username[0] == 0) {
Expand All @@ -102,6 +109,41 @@ link_journal_dialog_run(GtkWindow *win, JamDoc *doc) {
gtk_text_buffer_get_iter_at_mark(buffer, &start,
gtk_text_buffer_get_insert(buffer));

if (usernick && *usernick) {
gchar *link;
gchar *img;
JamAccount *acc = jam_doc_get_account(doc);

xml_escape(&username);
xml_escape(&usernick);

if (usertype == 0)
img = g_strdup("userinfo.gif");
else
img = g_strdup("community.gif");

link = g_strdup_printf(
"<a href='%s/userinfo.bml?user=%s'>"
"<img src='%s/img/%s' alt='[info]' align='absmiddle' width='17' height='17' border='0' />"
"</a>"
"<a style='FONT-WEIGHT: 800' href='%s/users/%s'>%s</a>",
jam_account_lj_get_server(JAM_ACCOUNT_LJ(acc))->url,
username,
jam_account_lj_get_server(JAM_ACCOUNT_LJ(acc))->url,
img,
jam_account_lj_get_server(JAM_ACCOUNT_LJ(acc))->url,
username,
usernick);

gtk_text_buffer_insert(buffer, &start, link, -1);

g_free(link);
g_free(img);
free(username);
free(usernick);
return;
}

gtk_text_buffer_insert(buffer, &start, "<lj ", -1);
if (usertype == 0)
gtk_text_buffer_insert(buffer, &start, "user=\"", -1);
Expand Down

0 comments on commit 43ff911

Please sign in to comment.