Ejemplo n.º 1
0
static void
adc_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
{
    MsnSession *session;
    PurpleAccount *account;
    PurpleConnection *gc;
    const char *list, *passport;
    const char *reason;
    char *msg = NULL;
    char **params;

    session = cmdproc->session;
    account = session->account;
    gc = purple_account_get_connection(account);
    params = g_strsplit(trans->params, " ", 0);

    list     = params[0];
    passport = params[1];

    if (!strcmp(list, "FL"))
        msg = pecan_strdup_printf(_("Unable to add user on %s (%s)"),
                                  purple_account_get_username(account),
                                  purple_account_get_protocol_name(account));
    else if (!strcmp(list, "BL"))
        msg = pecan_strdup_printf(_("Unable to block user on %s (%s)"),
                                  purple_account_get_username(account),
                                  purple_account_get_protocol_name(account));
    else if (!strcmp(list, "AL"))
        msg = pecan_strdup_printf(_("Unable to permit user on %s (%s)"),
                                  purple_account_get_username(account),
                                  purple_account_get_protocol_name(account));

    reason = pecan_error_to_string (error);

    if (msg != NULL)
    {
        purple_notify_error(gc, NULL, msg, reason);
        g_free(msg);
    }

    if (!strcmp(list, "FL"))
    {
        PurpleBuddy *buddy;

        buddy = purple_find_buddy(account, passport);

        if (buddy != NULL)
            purple_blist_remove_buddy(buddy);
    }

    g_strfreev(params);
}
Ejemplo n.º 2
0
static void *
finch_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
		const char **subjects, const char **froms, const char **tos,
		const char **urls)
{
	PurpleAccount *account = purple_connection_get_account(gc);
	GString *message = g_string_new(NULL);
	void *ret;
	static int key = 0;

	if (count == 0)
		return NULL;

	if (!detailed)
	{
		g_string_append_printf(message,
				ngettext("%s (%s) has %d new message.",
					     "%s (%s) has %d new messages.",
						 (int)count),
				tos ? *tos : purple_account_get_username(account),
				purple_account_get_protocol_name(account), (int)count);
	}
	else
	{
		char *to;
		gboolean newwin = (emaildialog.window == NULL);

		if (newwin)
			setup_email_dialog();

		to = g_strdup_printf("%s (%s)", tos ? *tos : purple_account_get_username(account),
					purple_account_get_protocol_name(account));
		gnt_tree_add_row_after(GNT_TREE(emaildialog.tree), GINT_TO_POINTER(++key),
				gnt_tree_create_row(GNT_TREE(emaildialog.tree), to,
					froms ? *froms : "[Unknown sender]",
					*subjects),
				NULL, NULL);
		g_free(to);
		if (newwin)
			gnt_widget_show(emaildialog.window);
		else
			gnt_window_present(emaildialog.window);
		return NULL;
	}

	ret = finch_notify_common(PURPLE_NOTIFY_EMAIL, PURPLE_NOTIFY_MSG_INFO,
		_("New Mail"), _("You have mail!"), message->str);
	g_string_free(message, TRUE);
	return ret;
}
Ejemplo n.º 3
0
static void
add_substatus(EditStatus *edit, PurpleAccount *account)
{
	char *name;
	const char *type = NULL, *message = NULL;
	PurpleSavedStatusSub *sub = NULL;
	RowInfo *key;

	if (!edit || !edit->tree)
		return;

	if (edit->saved)
		sub = purple_savedstatus_get_substatus(edit->saved, account);

	key = g_new0(RowInfo, 1);
	key->account = account;

	if (sub)
	{
		key->type = purple_savedstatus_substatus_get_type(sub);
		type = purple_status_type_get_name(key->type);
		message = purple_savedstatus_substatus_get_message(sub);
		key->message = g_strdup(message);
	}

	name = g_strdup_printf("%s (%s)", purple_account_get_username(account),
			purple_account_get_protocol_name(account));
	gnt_tree_add_choice(GNT_TREE(edit->tree), key,
			gnt_tree_create_row(GNT_TREE(edit->tree),
				name, type ? type : "", message ? message : ""), NULL, NULL);

	if (sub)
		gnt_tree_set_choice(GNT_TREE(edit->tree), key, TRUE);
	g_free(name);
}
Ejemplo n.º 4
0
static
void cb_custom_toggled(GtkCellRendererToggle *cell, char *path, gpointer data)
{
	GtkTreeIter iter;
	GtkTreeModel *model = (GtkTreeModel*) data;
	if (gtk_tree_model_get_iter_from_string(model, &iter, path)) {
                PurpleAccount *account;
                GValue value;
                memset(&value, 0, sizeof(value));
                gtk_tree_model_get_value(model, &iter, 5, &value);
                assert(G_VALUE_HOLDS_POINTER(&value));
                account = g_value_get_pointer(&value);
                g_value_unset(&value);

		gboolean flag;
		char pref[STRLEN];

		build_pref(pref, PREF_CUSTOM_DISABLED, purple_account_get_username(account), purple_account_get_protocol_name(account));

		memset(&value, 0, sizeof(value));
		gtk_tree_model_get_value(model, &iter, 3, &value);
		assert(G_VALUE_HOLDS_BOOLEAN(&value));
		flag = !g_value_get_boolean(&value);
		g_value_unset(&value);

		gtk_list_store_set(GTK_LIST_STORE(model), &iter, 3, flag, -1);
		purple_prefs_set_bool(pref, flag);
		if (flag) {
			set_status(account, "", 0);
		}
	}
}
Ejemplo n.º 5
0
static void
set_account(GtkListStore *store, GtkTreeIter *iter, PurpleAccount *account)
{
  GdkPixbuf *pixbuf;
  GdkPixbuf *scale;

  scale = NULL;

  pixbuf = pidgin_create_prpl_icon(account, 0.5);

  if (pixbuf != NULL)
  {
    scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR);

    if (purple_account_is_disconnected(account))
      gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
  }

  gtk_list_store_set(store, iter,
    COLUMN_ICON, scale,
    COLUMN_SCREENNAME, purple_account_get_username(account),
    COLUMN_ENABLED, ap_account_has_profile_enabled(account),
    COLUMN_PROTOCOL, purple_account_get_protocol_name(account),
    COLUMN_DATA, account,
    -1);

  if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf));
  if (scale  != NULL) g_object_unref(G_OBJECT(scale));
}
Ejemplo n.º 6
0
void GeneralMenu::fields_ok_cb(PurpleRequestFields *fields)
{
  LOG->debug(
      "fields_ok_cb: text0=%s, text1=%s, int0=%d, bool0=%d, choice0=%d\n",
      purple_request_fields_get_string(fields, "text0"),
      purple_request_fields_get_string(fields, "text1"),
      purple_request_fields_get_integer(fields, "int0"),
      purple_request_fields_get_bool(fields, "bool0"),
      purple_request_fields_get_choice(fields, "choice0"));

  for (GList *list = purple_request_field_list_get_selected(
        purple_request_fields_get_field(fields, "list0")); list;
      list = list->next)
    LOG->debug("fields_ok_cb: list0=%s",
        reinterpret_cast<const char*>(list->data));

  for (GList *list = purple_request_field_list_get_selected(
        purple_request_fields_get_field(fields, "list1")); list;
      list = list->next)
    LOG->debug("fields_ok_cb: list1=%s",
        reinterpret_cast<const char*>(list->data));

  PurpleAccount *account = purple_request_fields_get_account(fields,
      "account0");
  LOG->debug("fields_ok_cb: account0=[%s] %s",
      purple_account_get_protocol_name(account),
      purple_account_get_username(account));
}
Ejemplo n.º 7
0
static void
group_error_helper(MsnSession *session, const char *msg, const gchar *group_guid, int error)
{
    PurpleAccount *account;
    PurpleConnection *gc;
    char *reason = NULL;
    char *title = NULL;

    account = session->account;
    gc = purple_account_get_connection(account);

    if (error == 224)
    {
        const char *group_name;
        group_name = pecan_contactlist_find_group_name(session->contactlist, group_guid);
        reason = pecan_strdup_printf(_("%s is not a valid group."),
                                     group_name);
    }
    else
    {
        reason = g_strdup(_("Unknown error."));
    }

    title = pecan_strdup_printf(_("%s on %s (%s)"), msg,
                                purple_account_get_username(account),
                                purple_account_get_protocol_name(account));
    purple_notify_error(gc, NULL, title, reason);
    g_free(title);
    g_free(reason);
}
Ejemplo n.º 8
0
Request::FieldsDialog::AccountField::AccountField(PurpleRequestField *field)
    : field(field)
{
    g_assert(field);

    // TODO filter (purple_request_field_account_get_filter())
    // TODO signals (signed-on, signed-off, account-added, account-removed)

    char *text = g_strdup_printf("%s%s",
                                 purple_request_field_is_required(field) ? "*" : "",
                                 purple_request_field_get_label(field));
    SetText(text);
    g_free(text);

    gboolean show_all = purple_request_field_account_get_show_all(field);
    for (GList *list = purple_accounts_get_all(); list; list = list->next) {
        PurpleAccount *account = reinterpret_cast<PurpleAccount*>(list->data);
        if (!show_all && !purple_account_is_connected(account))
            continue;

        char *label = g_strdup_printf("[%s] %s",
                                      purple_account_get_protocol_name(account),
                                      purple_account_get_username(account));
        AddOptionPtr(label, account);
        g_free(label);
    }
    SetSelectedByDataPtr(purple_request_field_account_get_default_value(field));

    signal_selection_changed.connect(sigc::mem_fun(this,
                                     &AccountField::OnAccountChanged));
}
Ejemplo n.º 9
0
void Accounts::status_changed(PurpleAccount *account, PurpleStatus *status)
{
  if (!purple_account_get_enabled(account, PACKAGE_NAME))
    return;

  LOG->Message(_("+ [%s] %s: Status changed to: %s"),
      purple_account_get_protocol_name(account),
      purple_account_get_username(account),
      purple_status_get_name(status));
}
Ejemplo n.º 10
0
static void log_select_cb(GtkTreeSelection *sel, PidginLogViewer *viewer) {
	GtkTreeIter iter;
	GValue val;
	GtkTreeModel *model = GTK_TREE_MODEL(viewer->treestore);
	PurpleLog *log = NULL;
	PurpleLogReadFlags flags;
	char *read = NULL;

	if (!gtk_tree_selection_get_selected(sel, &model, &iter))
		return;

	val.g_type = 0;
	gtk_tree_model_get_value (model, &iter, 1, &val);
	log = g_value_get_pointer(&val);
	g_value_unset(&val);

	if (log == NULL)
		return;

	pidgin_set_cursor(viewer->window, GDK_WATCH);

	if (log->type != PURPLE_LOG_SYSTEM) {
		char *title;
		if (log->type == PURPLE_LOG_CHAT)
			title = g_strdup_printf(_("<span size='larger' weight='bold'>Conversation in %s on %s</span>"),
									log->name, log_get_date(log));
		else
			title = g_strdup_printf(_("<span size='larger' weight='bold'>Conversation with %s on %s</span>"),
									log->name, log_get_date(log));

		gtk_label_set_markup(GTK_LABEL(viewer->label), title);
		g_free(title);
	}

	read = purple_log_read(log, &flags);
	viewer->flags = flags;

	gtk_imhtml_clear(GTK_IMHTML(viewer->imhtml));
	gtk_imhtml_set_protocol_name(GTK_IMHTML(viewer->imhtml),
	                            purple_account_get_protocol_name(log->account));

	purple_signal_emit(pidgin_log_get_handle(), "log-displaying", viewer, log);

	gtk_imhtml_append_text(GTK_IMHTML(viewer->imhtml), read,
			       GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_TITLE | GTK_IMHTML_NO_SCROLL |
			       ((flags & PURPLE_LOG_READ_NO_NEWLINE) ? GTK_IMHTML_NO_NEWLINE : 0));
	g_free(read);

	if (viewer->search != NULL) {
		gtk_imhtml_search_clear(GTK_IMHTML(viewer->imhtml));
		g_idle_add(search_find_cb, viewer);
	}

	pidgin_clear_cursor(viewer->window);
}
/*******************
 * Signal Handlers *
 *******************/
static void rc_at_conversation_event(PurpleConversation *conv)
{
  PurpleAccount *acct = purple_conversation_get_account(conv);
  const char * proto = purple_account_get_protocol_name(acct);
  const char * proto_id = purple_account_get_protocol_id(acct);
  const char * my_acct = purple_account_get_username(acct);
  const char * recv_acct = purple_conversation_get_name(conv);

  trace("Conversation event.. [%s: %s] account: %s to %s", proto_id,
      proto, my_acct, recv_acct); 

  rc_push_contact(acct, recv_acct);

}
Ejemplo n.º 12
0
void
msn_show_sync_issue(MsnSession *session, const char *passport,
					const char *group_name)
{
	PurpleConnection *gc;
	PurpleAccount *account;
	MsnAddRemData *data;
	char *msg, *reason;

	account = session->account;
	gc = purple_account_get_connection(account);

	data        = g_new0(MsnAddRemData, 1);
	data->who   = g_strdup(passport);
	data->group = g_strdup(group_name);
	data->gc    = gc;

	msg = g_strdup_printf(_("Buddy list synchronization issue in %s (%s)"),
						  purple_account_get_username(account),
						  purple_account_get_protocol_name(account));

	if (group_name != NULL)
	{
		reason = g_strdup_printf(_("%s on the local list is "
								   "inside the group \"%s\" but not on "
								   "the server list. "
								   "Do you want this buddy to be added?"),
								 passport, group_name);
	}
	else
	{
		reason = g_strdup_printf(_("%s is on the local list but "
								   "not on the server list. "
								   "Do you want this buddy to be added?"),
								 passport);
	}

	purple_request_action(gc, NULL, msg, reason, PURPLE_DEFAULT_ACTION_NONE, 
						purple_connection_get_account(gc), data->who, NULL,
						data, 2,
						_("Yes"), G_CALLBACK(msn_add_cb),
						_("No"), G_CALLBACK(msn_rem_cb));

	g_free(reason);
	g_free(msg);
}
Ejemplo n.º 13
0
PurpleSmileyList *
pidgin_smiley_theme_for_conv(PurpleConversation *conv)
{
	PurpleAccount *acc = NULL;
	PurpleSmileyTheme *theme;
	const gchar *proto_name = NULL;

	theme = purple_smiley_theme_get_current();
	if (theme == NULL)
		return NULL;

	if (conv)
		acc = purple_conversation_get_account(conv);
	if (acc)
		proto_name = purple_account_get_protocol_name(acc);

	return purple_smiley_theme_get_smileys(theme, (gpointer)proto_name);
}
Ejemplo n.º 14
0
static
void cb_custom_edited(GtkCellRendererText *renderer, char *path, char *str, gpointer data)
{
	GtkTreeIter iter;
	GtkTreeModel *model = (GtkTreeModel*) data;
	if (gtk_tree_model_get_iter_from_string(model, &iter, path)) {
                PurpleAccount *account;
                GValue value;
                memset(&value, 0, sizeof(value));
                gtk_tree_model_get_value(model, &iter, 5, &value);
                assert(G_VALUE_HOLDS_POINTER(&value));
                account = g_value_get_pointer(&value);
                g_value_unset(&value);

		char pref[STRLEN];
		build_pref(pref, PREF_CUSTOM_FORMAT, purple_account_get_username(account), purple_account_get_protocol_name(account));

		gtk_list_store_set(GTK_LIST_STORE(model), &iter, 2, str, -1);
		purple_prefs_set_string(pref, str);
	}
}
Ejemplo n.º 15
0
static void
reset_account_list(PurpleAccount *account)
{
	GList *list;
	GntComboBox *accounts = GNT_COMBO_BOX(froomlist.accounts);
	gnt_combo_box_remove_all(accounts);
	for (list = purple_connections_get_all(); list; list = list->next) {
		PurplePluginProtocolInfo *prpl_info = NULL;
		PurpleConnection *gc = list->data;

		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
		if (PURPLE_CONNECTION_IS_CONNECTED(gc) &&
		        prpl_info->roomlist_get_list != NULL) {
			PurpleAccount *account = purple_connection_get_account(gc);
			char *text = g_strdup_printf("%s (%s)",
					purple_account_get_username(account),
					purple_account_get_protocol_name(account));
			gnt_combo_box_add_data(accounts, account, text);
			g_free(text);
		}
	}
}
Ejemplo n.º 16
0
static GntWidget*
create_account_field(PurpleRequestField *field)
{
	gboolean all;
	PurpleAccount *def;
	GList *list;
	GntWidget *combo = gnt_combo_box_new();

	all = purple_request_field_account_get_show_all(field);
	def = purple_request_field_account_get_value(field);
	if (!def)
		def = purple_request_field_account_get_default_value(field);

	if (all)
		list = purple_accounts_get_all();
	else
		list = purple_connections_get_all();

	for (; list; list = list->next)
	{
		PurpleAccount *account;
		char *text;

		if (all)
			account = list->data;
		else
			account = purple_connection_get_account(list->data);

		text = g_strdup_printf("%s (%s)",
				purple_account_get_username(account),
				purple_account_get_protocol_name(account));
		gnt_combo_box_add_data(GNT_COMBO_BOX(combo), account, text);
		g_free(text);
		if (account == def)
			gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), account);
	}
	gnt_widget_set_size(combo, 20, 3); /* ew */
	return combo;
}
Ejemplo n.º 17
0
static void historize(PurpleConversation *c)
{
	PurpleAccount *account = NULL;
	PurpleConversationType convtype;
	PidginConversation *gtkconv = NULL;
	GtkTextIter start;
	GtkIMHtmlOptions options;
	GList *logs = NULL, *logs_head = NULL;
	struct tm *log_tm = NULL, *local_tm = NULL;
	time_t t, log_time;
	double limit_time = 0.0;
	const char *name = NULL, *alias = NULL, *LOG_MODE = NULL;
	char *header = NULL, *protocol = NULL, *history = NULL;
	int conv_counter = 0;
	int limit_offset = 0;
	int byte_counter = 0;
	int check_time = 0;
	int log_size, overshoot;

	account = purple_conversation_get_account(c);
	name = purple_conversation_get_name(c);
	alias = name;
	LOG_MODE = purple_prefs_get_string("/purple/logging/format");

	/* If logging isn't enabled, don't show any history */
	if(!purple_prefs_get_bool("/purple/logging/log_ims") &&
			!purple_prefs_get_bool("/purple/logging/log_chats"))
		return;
	
	/* If the user wants to show 0 logs, stop now */
	if(PREF_NUMBER_VAL == 0) {
		return;
	}
	
	/* If the logging mode is html, set the output options to include no newline.
	 * Otherwise, it's normal text, so we don't need extra lines */
	if(strcasecmp(LOG_MODE, "html")==0) {
		options = GTK_IMHTML_NO_NEWLINE;
	} else {
		options = GTK_IMHTML_NO_COLOURS;
	}
	
	/* Determine whether this is an IM or a chat. In either case, if the user has that
	 * particular log type disabled, the logs file doesnt not get specified */
	convtype = purple_conversation_get_type(c);
	if (convtype == PURPLE_CONV_TYPE_IM && PREF_IM_VAL) {
		GSList *cur;
		GSList *buddies = NULL;

		/* Find buddies for this conversation. */
		buddies = purple_find_buddies(account, name);

		/* If we found at least one buddy, save the first buddy's alias. */
		if (buddies != NULL)
			alias = purple_buddy_get_contact_alias((PurpleBuddy *)buddies->data);

		for(cur = buddies; cur; cur = cur->next) {
			PurpleBlistNode *node = cur->data;

			if(node && (node->prev || node->next)) {
				PurpleBlistNode *node2;

				for(node2 = node->parent->child; node2; node2 = node2->next) {
					logs = g_list_concat(purple_log_get_logs(PURPLE_LOG_IM,
								purple_buddy_get_name((PurpleBuddy *)node2),
								purple_buddy_get_account((PurpleBuddy *)node2)), logs);
				}

				break;
			}
		}

		g_slist_free(buddies);

		if (logs)
			logs = g_list_sort(logs, purple_log_compare);
		else
			logs = purple_log_get_logs(PURPLE_LOG_IM, name, account);
	} else if (convtype == PURPLE_CONV_TYPE_CHAT && PREF_CHAT_VAL) {
		logs = purple_log_get_logs(PURPLE_LOG_CHAT,
			purple_conversation_get_name(c), purple_conversation_get_account(c));
	}

	gtkconv = PIDGIN_CONVERSATION(c);

	/* The logs are non-existant or the user has disabled this type for log displaying. */
	if (!logs) {
		return;
	}

	/* Keep a pointer to the head of the logs for freeing later */
	logs_head = logs;

	/* If all time prefs are not 0, prepare to check times */
	if (!(PREF_MINS_VAL == 0 && PREF_HOURS_VAL == 0 && PREF_DAYS_VAL == 0)) {
		check_time = 1;

		/* Grab current time and normalize it to UTC */
		t = time(NULL);
		local_tm = gmtime(&t);
		t = mktime(local_tm);

		limit_time = (PREF_MINS_VAL * 60.0) + (PREF_HOURS_VAL * 60.0 * 60.0) +
				(PREF_DAYS_VAL * 60.0 * 60.0 * 24.0);
	}

	/* The protocol will need to be adjusted for each log for correct display,
	   so save the current imhtml protocol_name to restore it later */
	protocol = g_strdup(gtk_imhtml_get_protocol_name(GTK_IMHTML(gtkconv->imhtml)));

	/* Calculate time for the first log */
	log_tm = gmtime(&((PurpleLog*)logs->data)->time);
	log_time = mktime(log_tm);

	/* Continue to add older logs until they run out or the conditions are no
	   longer met */
	while (logs && conv_counter < PREF_NUMBER_VAL
			&& byte_counter < PREF_BYTES_VAL
			&& (!check_time || difftime(t, log_time) < limit_time)) {
		guint flags;

		/* Get the current log's contents as a char* */
		history = purple_log_read((PurpleLog*)logs->data, &flags);
		log_size = strlen(history);

		if (flags & PURPLE_LOG_READ_NO_NEWLINE)
			options |= GTK_IMHTML_NO_NEWLINE;
		else
			options &= ~GTK_IMHTML_NO_NEWLINE;

		/* Update the overall byte count and determine if this log exceeds the limit */
		byte_counter += log_size;
		overshoot = byte_counter - PREF_BYTES_VAL;
		if (overshoot > 0) {
			/* Start looking at the maximum log size for a newline to break at */
			limit_offset = overshoot;
			/* Find the next \n, or stop if the end of the log is reached */
			while (history[limit_offset] && history[limit_offset] != '\n') {
				limit_offset++;
			}
			/* If we're at or very close to the end of the log, forget this log */
			if (!history[limit_offset] || (log_size - limit_offset < 3)) {
				limit_offset = -1;
			}
			else {
				/* Start at the first character after the newline */
				limit_offset++;
			}
		}

		conv_counter++;

		/* If this log won't fit at all, don't display it in the conversation */
		if (limit_offset != -1) {
			/* Set the correct protocol_name for this log */
			gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml),
					purple_account_get_protocol_name(((PurpleLog*)logs->data)->account));

			/* Prepend the contents of the log starting at the calculated offset */
			gtk_text_buffer_get_iter_at_offset(GTK_IMHTML(gtkconv->imhtml)->text_buffer,
					&start, 0);
			gtk_imhtml_insert_html_at_iter(GTK_IMHTML(gtkconv->imhtml),
						history + limit_offset, options, &start);

			/* Prepend the conversation header */
			if (PREF_DATES_VAL) {
				header = g_strdup_printf(_("<b>Conversation with %s on %s:</b><br>"), alias,
					purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time)));
				gtk_text_buffer_get_iter_at_offset(GTK_IMHTML(gtkconv->imhtml)->text_buffer,
						&start, 0);
				gtk_imhtml_insert_html_at_iter(GTK_IMHTML(gtkconv->imhtml),
						header, options, &start);
				g_free(header);
			}
		}

		g_free(history);

		if (limit_offset > 0) {
			/* This log had to be chopped to fit, so stop after this one */
			break;
		}

		logs = logs->next;

		/* Recalculate log time if we haven't run out of logs */
		if (logs) {
			log_tm = gmtime(&((PurpleLog*)logs->data)->time);
			log_time = mktime(log_tm);
		}
	}

	gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<hr>", options);

	/* Restore the original protocol_name */
	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol);
	g_free(protocol);
	
	g_object_ref(G_OBJECT(gtkconv->imhtml));
	g_idle_add(_scroll_imhtml_to_end, gtkconv->imhtml);
	
	/* Clear the allocated memory that the logs are using */
	g_list_foreach(logs_head, (GFunc)purple_log_free, NULL);
	g_list_free(logs_head);
	
}
Ejemplo n.º 18
0
static void
update_detailed_info(PidginXferDialog *dialog, PurpleXfer *xfer)
{
	PidginXferUiData *data;
	char *kbsec, *time_elapsed, *time_remaining;
	char *status, *utf8;

	if (dialog == NULL || xfer == NULL)
		return;

	data = PIDGINXFER(xfer);

	get_xfer_info_strings(xfer, &kbsec, &time_elapsed, &time_remaining);

	status = g_strdup_printf("%d%% (%" G_GSIZE_FORMAT " of %" G_GSIZE_FORMAT " bytes)",
							 (int)(purple_xfer_get_progress(xfer)*100),
							 purple_xfer_get_bytes_sent(xfer),
							 purple_xfer_get_size(xfer));

	if (purple_xfer_is_completed(xfer)) {

		GdkPixbuf *pixbuf = NULL;

		pixbuf = gtk_widget_render_icon(xfer_dialog->window,
										PIDGIN_STOCK_FILE_DONE,
										GTK_ICON_SIZE_MENU, NULL);

		gtk_list_store_set(GTK_LIST_STORE(xfer_dialog->model), &data->iter,
						   COLUMN_STATUS, pixbuf,
						   -1);

		g_object_unref(pixbuf);
	}

	if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) {
		gtk_label_set_markup(GTK_LABEL(dialog->local_user_desc_label),
							 _("<b>Receiving As:</b>"));
		gtk_label_set_markup(GTK_LABEL(dialog->remote_user_desc_label),
							 _("<b>Receiving From:</b>"));
	}
	else {
		gtk_label_set_markup(GTK_LABEL(dialog->remote_user_desc_label),
							 _("<b>Sending To:</b>"));
		gtk_label_set_markup(GTK_LABEL(dialog->local_user_desc_label),
							 _("<b>Sending As:</b>"));
	}

	gtk_label_set_text(GTK_LABEL(dialog->local_user_label),
								 purple_account_get_username(xfer->account));
	gtk_label_set_text(GTK_LABEL(dialog->remote_user_label), xfer->who);
	gtk_label_set_text(GTK_LABEL(dialog->protocol_label),
								 purple_account_get_protocol_name(xfer->account));

	if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) {
		gtk_label_set_text(GTK_LABEL(dialog->filename_label),
					   purple_xfer_get_filename(xfer));
	} else {
		char *tmp;

		tmp = g_path_get_basename(purple_xfer_get_local_filename(xfer));
		utf8 = g_filename_to_utf8(tmp, -1, NULL, NULL, NULL);
		g_free(tmp);

		gtk_label_set_text(GTK_LABEL(dialog->filename_label), utf8);
		g_free(utf8);
	}

	utf8 = g_filename_to_utf8((purple_xfer_get_local_filename(xfer)), -1, NULL, NULL, NULL);
	gtk_label_set_text(GTK_LABEL(dialog->localfile_label), utf8);
	g_free(utf8);

	gtk_label_set_text(GTK_LABEL(dialog->status_label), status);

	gtk_label_set_text(GTK_LABEL(dialog->speed_label), kbsec);
	gtk_label_set_text(GTK_LABEL(dialog->time_elapsed_label), time_elapsed);
	gtk_label_set_text(GTK_LABEL(dialog->time_remaining_label),
					   time_remaining);

	gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dialog->progress),
								  purple_xfer_get_progress(xfer));

	g_free(kbsec);
	g_free(time_elapsed);
	g_free(time_remaining);
	g_free(status);
}
Ejemplo n.º 19
0
void AccountWindow::populateAccount(PurpleAccount *account)
{
  if (account_entries.find(account) == account_entries.end()) {
    // no entry for this account, so add one
    AccountEntry entry;
    entry.parent = NULL;
    account_entries[account] = entry;
  }
  else {
    // the account exists, so clear all data
    clearAccount(account, false);
  }

  AccountEntry *account_entry = &account_entries[account];

  if (!account_entry->parent) {
    CppConsUI::TreeView::ToggleCollapseButton *button
      = new CppConsUI::TreeView::ToggleCollapseButton;
    CppConsUI::TreeView::NodeReference parent_reference
      = treeview->appendNode(treeview->getRootNode(), *button);
    treeview->setCollapsed(parent_reference, true);
    account_entry->parent = button;
    account_entry->parent_reference = parent_reference;
  }

  char *label = g_strdup_printf("[%s] %s",
      purple_account_get_protocol_name(account),
      purple_account_get_username(account));
  account_entry->parent->setText(label);
  g_free(label);

  const char *protocol_id = purple_account_get_protocol_id(account);
  PurplePlugin *prpl = purple_find_prpl(protocol_id);

  if (!prpl) {
    // we cannot change the settings of an unknown account
    CppConsUI::Label *label = new CppConsUI::Label(
        _("Invalid account or protocol plugin not loaded."));
    treeview->appendNode(account_entry->parent_reference, *label);
  }
  else {
    PurplePluginProtocolInfo *prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

    // protocols combobox
    ProtocolOption *combobox = new ProtocolOption(account, *this);
    CppConsUI::TreeView::NodeReference protocol_node
      = treeview->appendNode(account_entry->parent_reference, *combobox);
    combobox->grabFocus();

    /* The username must be treated in a special way because it can contain
     * multiple values (e.g. user@server:port/resource). */
    char *username = g_strdup(purple_account_get_username(account));

    for (GList *iter = g_list_last(prplinfo->user_splits); iter;
        iter = iter->prev) {
      PurpleAccountUserSplit *split
        = reinterpret_cast<PurpleAccountUserSplit*>(iter->data);

      char *s;
      if (purple_account_user_split_get_reverse(split))
        s = strrchr(username, purple_account_user_split_get_separator(split));
      else
        s = strchr(username, purple_account_user_split_get_separator(split));

      const char *value;
      if (s) {
        *s = '\0';
        value = s + 1;
      }
      else
        value = purple_account_user_split_get_default_value(split);

      // create widget for the username split and remember
      SplitOption *widget_split = new SplitOption(account, split,
          account_entry);
      widget_split->setValue(value);
      account_entry->split_widgets.push_front(widget_split);

      treeview->appendNode(account_entry->parent_reference, *widget_split);
    }

    SplitOption *widget_split = new SplitOption(account, NULL, account_entry);
    widget_split->setValue(username);
    account_entry->split_widgets.push_front(widget_split);
    treeview->insertNodeAfter(protocol_node, *widget_split);
    g_free(username);

    // password
    Widget *widget = new StringOption(account, StringOption::TYPE_PASSWORD);
    treeview->appendNode(account_entry->parent_reference, *widget);

    // remember password
    widget = new BoolOption(account, BoolOption::TYPE_REMEMBER_PASSWORD);
    treeview->appendNode(account_entry->parent_reference, *widget);

    // alias
    widget = new StringOption(account, StringOption::TYPE_ALIAS);
    treeview->appendNode(account_entry->parent_reference, *widget);

    for (GList *pref = prplinfo->protocol_options; pref; pref = pref->next) {
      PurpleAccountOption *option
        = reinterpret_cast<PurpleAccountOption*>(pref->data);
      PurplePrefType type = purple_account_option_get_type(option);

      switch (type) {
        case PURPLE_PREF_STRING:
          widget = new StringOption(account, option);
          treeview->appendNode(account_entry->parent_reference, *widget);
          break;
        case PURPLE_PREF_INT:
          widget = new IntegerOption(account, option);
          treeview->appendNode(account_entry->parent_reference, *widget);
          break;
        case PURPLE_PREF_BOOLEAN:
          widget = new BoolOption(account, option);
          treeview->appendNode(account_entry->parent_reference, *widget);
          break;
        case PURPLE_PREF_STRING_LIST:
          widget = new StringListOption(account, option);
          treeview->appendNode(account_entry->parent_reference, *widget);
          break;
        default:
          LOG->error(_("Unhandled account option type '%d'."), type);
          break;
      }
    }

    // enable/disable account
    widget = new BoolOption(account, BoolOption::TYPE_ENABLE_ACCOUNT);
    treeview->appendNode(account_entry->parent_reference, *widget);

    // coloring
    widget = new ColorOption(account);
    treeview->appendNode(account_entry->parent_reference, *widget);
  }

  // drop account
  CppConsUI::Button *drop_button = new CppConsUI::Button(_("Drop account"));
  drop_button->signal_activate.connect(sigc::bind(sigc::mem_fun(this,
          &AccountWindow::dropAccount), account));
  treeview->appendNode(account_entry->parent_reference, *drop_button);
}
Ejemplo n.º 20
0
static void historize(PurpleConversation *c)
{
	PurpleAccount *account = purple_conversation_get_account(c);
	const char *name = purple_conversation_get_name(c);
	PurpleConversationType convtype;
	GList *logs = NULL;
	const char *alias = name;
	guint flags;
	char *history;
	PidginConversation *gtkconv;
	GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS;
	char *header;
	char *protocol;
	char *escaped_alias;
	const char *header_date;

	convtype = purple_conversation_get_type(c);
	gtkconv = PIDGIN_CONVERSATION(c);
	g_return_if_fail(gtkconv != NULL);

	/* An IM which is the first active conversation. */
	g_return_if_fail(gtkconv->convs != NULL);
	if (convtype == PURPLE_CONV_TYPE_IM && !gtkconv->convs->next)
	{
		GSList *buddies;
		GSList *cur;

		/* If we're not logging, don't show anything.
		 * Otherwise, we might show a very old log. */
		if (!purple_prefs_get_bool("/purple/logging/log_ims"))
			return;

		/* Find buddies for this conversation. */
	        buddies = purple_find_buddies(account, name);

		/* If we found at least one buddy, save the first buddy's alias. */
		if (buddies != NULL)
			alias = purple_buddy_get_contact_alias((PurpleBuddy *)buddies->data);

	        for (cur = buddies; cur != NULL; cur = cur->next)
	        {
	                PurpleBlistNode *node = cur->data;
	                if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL)))
	                {
				PurpleBlistNode *node2;

				alias = purple_buddy_get_contact_alias((PurpleBuddy *)node);

				/* We've found a buddy that matches this conversation.  It's part of a
				 * PurpleContact with more than one PurpleBuddy.  Loop through the PurpleBuddies
				 * in the contact and get all the logs. */
				for (node2 = node->parent->child ; node2 != NULL ; node2 = node2->next)
				{
					logs = g_list_concat(
						purple_log_get_logs(PURPLE_LOG_IM,
							purple_buddy_get_name((PurpleBuddy *)node2),
							purple_buddy_get_account((PurpleBuddy *)node2)),
						logs);
				}
				break;
	                }
	        }
	        g_slist_free(buddies);

		if (logs == NULL)
			logs = purple_log_get_logs(PURPLE_LOG_IM, name, account);
		else
			logs = g_list_sort(logs, purple_log_compare);
	}
	else if (convtype == PURPLE_CONV_TYPE_CHAT)
	{
		/* If we're not logging, don't show anything.
		 * Otherwise, we might show a very old log. */
		if (!purple_prefs_get_bool("/purple/logging/log_chats"))
			return;

		logs = purple_log_get_logs(PURPLE_LOG_CHAT, name, account);
	}

	if (logs == NULL)
		return;

	history = purple_log_read((PurpleLog*)logs->data, &flags);
	gtkconv = PIDGIN_CONVERSATION(c);
	if (flags & PURPLE_LOG_READ_NO_NEWLINE)
		options |= GTK_IMHTML_NO_NEWLINE;

	protocol = g_strdup(gtk_imhtml_get_protocol_name(GTK_IMHTML(gtkconv->imhtml)));
	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml),
							      purple_account_get_protocol_name(((PurpleLog*)logs->data)->account));

	if (gtk_text_buffer_get_char_count(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml))))
		gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", options);

	escaped_alias = g_markup_escape_text(alias, -1);

	if (((PurpleLog *)logs->data)->tm)
		header_date = purple_date_format_full(((PurpleLog *)logs->data)->tm);
	else
		header_date = purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time));

	header = g_strdup_printf(_("<b>Conversation with %s on %s:</b><br>"), escaped_alias, header_date);
	gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), header, options);
	g_free(header);
	g_free(escaped_alias);

	g_strchomp(history);
	gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), history, options);
	g_free(history);

	gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<hr>", options);

	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol);
	g_free(protocol);

	g_object_ref(G_OBJECT(gtkconv->imhtml));
	g_idle_add(_scroll_imhtml_to_end, gtkconv->imhtml);

	g_list_foreach(logs, (GFunc)purple_log_free, NULL);
	g_list_free(logs);
}
Ejemplo n.º 21
0
static void historize(PurpleConversation *c)
{
	PurpleAccount *account = purple_conversation_get_account(c);
	const char *name = purple_conversation_get_name(c);
	GList *logs = NULL;
	const char *alias = name;
	guint flags;
	char *history;
	PidginConversation *gtkconv;
#if 0
	/* FIXME: WebView has no options */
	GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS;
#endif
	char *header;
#if 0
	/* FIXME: WebView has no protocol setting */
	char *protocol;
#endif
	char *escaped_alias;
	const char *header_date;

	gtkconv = PIDGIN_CONVERSATION(c);
	g_return_if_fail(gtkconv != NULL);

	/* An IM which is the first active conversation. */
	g_return_if_fail(gtkconv->convs != NULL);
	if (PURPLE_IS_IM_CONVERSATION(c) && !gtkconv->convs->next)
	{
		GSList *buddies;
		GSList *cur;

		/* If we're not logging, don't show anything.
		 * Otherwise, we might show a very old log. */
		if (!purple_prefs_get_bool("/purple/logging/log_ims"))
			return;

		/* Find buddies for this conversation. */
		buddies = purple_blist_find_buddies(account, name);

		/* If we found at least one buddy, save the first buddy's alias. */
		if (buddies != NULL)
			alias = purple_buddy_get_contact_alias(PURPLE_BUDDY(buddies->data));

		for (cur = buddies; cur != NULL; cur = cur->next)
		{
			PurpleBlistNode *node = cur->data;
			PurpleBlistNode *prev = purple_blist_node_get_sibling_prev(node);
			PurpleBlistNode *next = purple_blist_node_get_sibling_next(node);
			if ((node != NULL) && ((prev != NULL) || (next != NULL)))
			{
				PurpleBlistNode *node2;
				PurpleBlistNode *parent = purple_blist_node_get_parent(node);
				PurpleBlistNode *child = purple_blist_node_get_first_child(parent);

				alias = purple_buddy_get_contact_alias(PURPLE_BUDDY(node));

				/* We've found a buddy that matches this conversation.  It's part of a
				 * PurpleContact with more than one PurpleBuddy.  Loop through the PurpleBuddies
				 * in the contact and get all the logs. */
				for (node2 = child ; node2 != NULL ; node2 = purple_blist_node_get_sibling_next(node2))
				{
					logs = g_list_concat(purple_log_get_logs(PURPLE_LOG_IM,
							purple_buddy_get_name(PURPLE_BUDDY(node2)),
							purple_buddy_get_account(PURPLE_BUDDY(node2))),
							logs);
				}
				break;
			}
		}
		g_slist_free(buddies);

		if (logs == NULL)
			logs = purple_log_get_logs(PURPLE_LOG_IM, name, account);
		else
			logs = g_list_sort(logs, purple_log_compare);
	}
	else if (PURPLE_IS_CHAT_CONVERSATION(c))
	{
		/* If we're not logging, don't show anything.
		 * Otherwise, we might show a very old log. */
		if (!purple_prefs_get_bool("/purple/logging/log_chats"))
			return;

		logs = purple_log_get_logs(PURPLE_LOG_CHAT, name, account);
	}

	if (logs == NULL)
		return;

	history = purple_log_read((PurpleLog*)logs->data, &flags);
	gtkconv = PIDGIN_CONVERSATION(c);
#if 0
	/* FIXME: WebView has no options */
	if (flags & PURPLE_LOG_READ_NO_NEWLINE)
		options |= GTK_IMHTML_NO_NEWLINE;
#endif

#if 0
	/* FIXME: WebView has no protocol setting */
	protocol = g_strdup(gtk_imhtml_get_protocol_name(GTK_IMHTML(gtkconv->imhtml)));
	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml),
			purple_account_get_protocol_name(((PurpleLog*)logs->data)->account));
#endif

#if 0
	/* TODO WebKit: Do this properly... */
	if (!pidgin_webview_is_empty(PIDGIN_WEBVIEW(gtkconv->webview)))
		pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), "<BR>");
#endif

	escaped_alias = g_markup_escape_text(alias, -1);

	if (((PurpleLog *)logs->data)->tm)
		header_date = purple_date_format_full(((PurpleLog *)logs->data)->tm);
	else
		header_date = purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time));

	header = g_strdup_printf(_("<b>Conversation with %s on %s:</b><br>"), escaped_alias, header_date);
	pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), header);
	g_free(header);
	g_free(escaped_alias);

	g_strchomp(history);
	pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), history);
	g_free(history);

	pidgin_webview_append_html(PIDGIN_WEBVIEW(gtkconv->webview), "<hr>");

#if 0
	/* FIXME: WebView has no protocol setting */
	gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol);
	g_free(protocol);
#endif

	g_object_ref(G_OBJECT(gtkconv->webview));
	g_idle_add(_scroll_webview_to_end, gtkconv->webview);

	g_list_foreach(logs, (GFunc)purple_log_free, NULL);
	g_list_free(logs);
}
Ejemplo n.º 22
0
void init_acct_features_dialog(struct acct_features_dialog *f_diag)
{
  GList *a = purple_accounts_get_all_active();
  /* TODO: should be freed ? */
  GdkPixbuf *yes = gtk_widget_render_icon(f_diag->window, GTK_STOCK_YES,
                                          GTK_ICON_SIZE_MENU, NULL);
  GdkPixbuf *no  = gtk_widget_render_icon(f_diag->window, GTK_STOCK_NO,
                                          GTK_ICON_SIZE_MENU, NULL);

  /* last line summarize all available features */
  GtkTreeIter e_iter;
  GdkPixbuf *e_icon     = gtk_widget_render_icon(f_diag->window,
                                                 PIDGIN_STOCK_INFO,
                                                 GTK_ICON_SIZE_MENU,
                                                 NULL);
  GdkPixbuf *e_pm        = no;
  GdkPixbuf *e_buddyicon = no;
  GdkPixbuf *e_nickname  = no;
  GdkPixbuf *e_mood      = no;
  GdkPixbuf *e_moodmsg   = no;
  GdkPixbuf *e_game      = no;
  GdkPixbuf *e_app       = no;
  GdkPixbuf *e_tune      = no;

  for(; a ; a = a->next) {
    PurpleAccount *acct  = (PurpleAccount *)a->data;
    PurplePlugin *plugin = purple_find_prpl(acct->protocol_id);
    PurplePluginProtocolInfo *protocol = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);

    GtkTreeIter iter;
    gchar *username = g_strdup_printf("%s (%s)",
                                           purple_account_get_username(acct),
                                           purple_account_get_protocol_name(acct));
    GdkPixbuf *a_icon = pidgin_create_prpl_icon(acct, PIDGIN_PRPL_ICON_MEDIUM);
    GHashTable *attrs  = get_account_attrs(acct);

    GdkPixbuf *nickname, *mood, *moodmsg, *game, *app, *tune, *pm, *buddyicon;

    if(g_hash_table_lookup(attrs, "mood"))
      e_mood = mood = yes;
    else
      mood = no;
    if(g_hash_table_lookup(attrs, "moodtext"))
      e_moodmsg = moodmsg = yes;
    else
      moodmsg = no;
    if(g_hash_table_lookup(attrs, "game"))
      e_game = game = yes;
    else
      game = no;
    if(g_hash_table_lookup(attrs, "office"))
      e_app = app = yes;
    else
      app = no;
    if((g_hash_table_lookup(attrs, "tune_title") &&
        g_hash_table_lookup(attrs, "tune_artist") &&
        g_hash_table_lookup(attrs, "tune_album")))
      e_tune = tune = yes;
    else
      tune = no;
    g_hash_table_destroy(attrs);

    if(protocol->set_status)
      e_pm = pm = yes;
    else
      pm = no;
    if(protocol->set_buddy_icon)
      e_buddyicon = buddyicon = yes;
    else
      buddyicon = no;
    /* exception for XMPP
       nickname supported
       manually
       FIXME: however some XMPP account don't support nickname extension */
    if(!strcmp(acct->protocol_id, "prpl-jabber") || protocol->set_public_alias)
      e_nickname = nickname = yes;
    else
      nickname = no;

    gtk_list_store_append(f_diag->list_store, &iter);
    gtk_list_store_set(f_diag->list_store, &iter,
                       ACCT_COLUMN, username,
                       ACCTICON_COLUMN, a_icon,
                       NICKNAME_COLUMN, nickname,
                       PM_COLUMN, pm,
                       ICON_COLUMN, buddyicon,
                       MOOD_COLUMN, mood,
                       MOODMSG_COLUMN, moodmsg,
                       TUNE_COLUMN, tune,
                       GAME_COLUMN, game,
                       APP_COLUMN, app,
                       -1);
    g_free(username);
  }

  /* last line summarize all available features */
  gtk_list_store_append(f_diag->list_store, &e_iter);
  gtk_list_store_set(f_diag->list_store, &e_iter,
                     ACCT_COLUMN, "Available features",
                     ACCTICON_COLUMN, e_icon,
                     NICKNAME_COLUMN, e_nickname,
                     PM_COLUMN, e_pm,
                     ICON_COLUMN, e_buddyicon,
                     MOOD_COLUMN, e_mood,
                     MOODMSG_COLUMN, e_moodmsg,
                     TUNE_COLUMN, e_tune,
                     GAME_COLUMN, e_game,
                     APP_COLUMN, e_app,
                     -1);
}
Ejemplo n.º 23
0
static void
pounce_cb(PurplePounce *pounce, PurplePounceEvent events, void *data)
{
	PurpleConversation *conv;
	PurpleAccount *account;
	PurpleBuddy *buddy;
	const char *pouncee;
	const char *alias;

	pouncee = purple_pounce_get_pouncee(pounce);
	account = purple_pounce_get_pouncer(pounce);

	buddy = purple_find_buddy(account, pouncee);
	if (buddy != NULL)
	{
		alias = purple_buddy_get_alias(buddy);
		if (alias == NULL)
			alias = pouncee;
	}
	else
		alias = pouncee;

	if (purple_pounce_action_is_enabled(pounce, "open-window"))
	{
		if (!purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pouncee, account))
			purple_conversation_new(PURPLE_CONV_TYPE_IM, account, pouncee);
	}

	if (purple_pounce_action_is_enabled(pounce, "popup-notify"))
	{
		char *tmp = NULL;
		const char *name_shown;
		const char *reason;
		struct {
			PurplePounceEvent event;
			const char *format;
		} messages[] = {
			{PURPLE_POUNCE_TYPING, _("%s has started typing to you (%s)")},
			{PURPLE_POUNCE_TYPED, _("%s has paused while typing to you (%s)")},
			{PURPLE_POUNCE_SIGNON, _("%s has signed on (%s)")},
			{PURPLE_POUNCE_IDLE_RETURN, _("%s has returned from being idle (%s)")},
			{PURPLE_POUNCE_AWAY_RETURN, _("%s has returned from being away (%s)")},
			{PURPLE_POUNCE_TYPING_STOPPED, _("%s has stopped typing to you (%s)")},
			{PURPLE_POUNCE_SIGNOFF, _("%s has signed off (%s)")},
			{PURPLE_POUNCE_IDLE, _("%s has become idle (%s)")},
			{PURPLE_POUNCE_AWAY, _("%s has gone away. (%s)")},
			{PURPLE_POUNCE_MESSAGE_RECEIVED, _("%s has sent you a message. (%s)")},
			{0, NULL}
		};
		int i;
		reason = purple_pounce_action_get_attribute(pounce, "popup-notify",
				"reason");

		/*
		 * Here we place the protocol name in the pounce dialog to lessen
		 * confusion about what protocol a pounce is for.
		 */
		for (i = 0; messages[i].format != NULL; i++) {
			if (messages[i].event & events) {
				tmp = g_strdup_printf(messages[i].format, alias,
						purple_account_get_protocol_name(account));
				break;
			}
		}
		if (tmp == NULL)
			tmp = g_strdup(_("Unknown pounce event. Please report this!"));

		/*
		 * Ok here is where I change the second argument, title, from
		 * NULL to the account alias if we have it or the account
		 * name if that's all we have
		 */
		if ((name_shown = purple_account_get_alias(account)) == NULL)
			name_shown = purple_account_get_username(account);

		if (reason == NULL)
		{
			purple_notify_info(NULL, name_shown, tmp, purple_date_format_full(NULL));
		}
		else
		{
			char *tmp2 = g_strdup_printf("%s\n\n%s", reason, purple_date_format_full(NULL));
			purple_notify_info(NULL, name_shown, tmp, tmp2);
			g_free(tmp2);
		}
		g_free(tmp);
	}

	if (purple_pounce_action_is_enabled(pounce, "send-message"))
	{
		const char *message;

		message = purple_pounce_action_get_attribute(pounce, "send-message",
												   "message");

		if (message != NULL)
		{
			conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pouncee, account);

			if (conv == NULL)
				conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, pouncee);

			purple_conversation_write(conv, NULL, message,
									PURPLE_MESSAGE_SEND, time(NULL));

			serv_send_im(purple_account_get_connection(account), (char *)pouncee, (char *)message, 0);
		}
	}

	if (purple_pounce_action_is_enabled(pounce, "execute-command"))
	{
		const char *command;

		command = purple_pounce_action_get_attribute(pounce,
				"execute-command", "command");

		if (command != NULL)
		{
			char *localecmd = g_locale_from_utf8(command, -1, NULL,
					NULL, NULL);

			if (localecmd != NULL)
			{
				int pid = fork();

				if (pid == 0) {
					char *args[4];

					args[0] = "sh";
					args[1] = "-c";
					args[2] = (char *)localecmd;
					args[3] = NULL;

					execvp(args[0], args);

					_exit(0);
				}
				g_free(localecmd);
			}
		}
	}

	if (purple_pounce_action_is_enabled(pounce, "play-beep"))
	{
		beep();
	}
}
Ejemplo n.º 24
0
GtkWidget* pref_frame(PurplePlugin *plugin)
{
	GtkWidget *align, *frame, *align2, *vbox2;
	GtkWidget *vbox, *hbox;
	GtkWidget *widget, *widget2;
	GtkWidget *expand;
	GtkWidget *treeview;
	GtkListStore *liststore;
	GtkCellRenderer *renderer;
	int i;

	// Root container
	vbox = gtk_vbox_new(FALSE, 10);
	align = gtk_alignment_new(0, 0, 1, 1);
	gtk_alignment_set_padding(GTK_ALIGNMENT(align), 10, 10, 10, 10);
	gtk_container_add(GTK_CONTAINER(align), vbox);

	// Player selection
	hbox = gtk_hbox_new(FALSE, 5);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(_("Player:")), FALSE, FALSE, 0);
	widget = gtk_combo_box_new_text();
	gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
	widget2 = gtk_button_new_from_stock(GTK_STOCK_PROPERTIES);
	gtk_box_pack_start(GTK_BOX(hbox), widget2, FALSE, FALSE, 0);

	gtk_combo_box_append_text(GTK_COMBO_BOX(widget), _("Auto-detect"));
	for (i=0; *g_players[i].name; ++i)
		gtk_combo_box_append_text(GTK_COMBO_BOX(widget), g_players[i].name);
	g_signal_connect(G_OBJECT(widget), "changed", G_CALLBACK(cb_player_changed), (gpointer) widget2);
	g_signal_connect(G_OBJECT(widget2), "clicked", G_CALLBACK(cb_player_properties), 0);
	gtk_combo_box_set_active(GTK_COMBO_BOX(widget), purple_prefs_get_int(PREF_PLAYER) + 1);

	// Popup menu for format
	format_menu = gtk_menu_new();
	char buf[100];
	APPEND_FORMAT_MENU(_("Artist"), "%p");
	APPEND_FORMAT_MENU(_("Album"), "%a");
	APPEND_FORMAT_MENU(_("Title"), "%t");
	APPEND_FORMAT_MENU(_("Track Duration"), "%d");
	APPEND_FORMAT_MENU(_("Elapsed Track Time"), "%c");
	APPEND_FORMAT_MENU(_("Progress Bar"), "%b");
	APPEND_FORMAT_MENU(_("Player"), "%r");
	APPEND_FORMAT_MENU(_("Music Symbol (may not display on some networks)"), "%m");
	gtk_widget_show_all(format_menu);

	// Format selection
	frame = gtk_frame_new(_("Status Format"));
	gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
	align2 = gtk_alignment_new(0, 0, 1, 1);
	gtk_alignment_set_padding(GTK_ALIGNMENT(align2), 5, 5, 5, 5);
	gtk_container_add(GTK_CONTAINER(frame), align2);
	vbox2 = gtk_vbox_new(FALSE, 5);
	gtk_container_add(GTK_CONTAINER(align2), vbox2);
	ADD_FORMAT_ENTRY(vbox2, _("Playing:"), PREF_FORMAT);
	ADD_FORMAT_ENTRY(vbox2, _("Paused:"), PREF_PAUSED);
	ADD_FORMAT_ENTRY(vbox2, _("Stopped/Off:"), PREF_OFF);

	// Protocol-specific formats
	liststore = gtk_list_store_new(6, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_POINTER);
	GList *accounts = purple_accounts_get_all();
	while (accounts) {
		PurpleAccount *account = (PurpleAccount*) accounts->data;
		GtkTreeIter iter;
		const char *username = purple_account_get_username(account);
                const char *protocolname = purple_account_get_protocol_name(account);

		char buf1[100], buf2[100], buf3[100];
		build_pref(buf1, PREF_CUSTOM_FORMAT, username, protocolname);
		build_pref(buf2, PREF_CUSTOM_DISABLED, username, protocolname);
		build_pref(buf3, PREF_BROKEN_NOWLISTENING, username, protocolname);
		trace("%s %s", buf1, purple_prefs_get_string(buf1));

		gtk_list_store_append(liststore, &iter);
		gtk_list_store_set(liststore, &iter, 0, username, 1, purple_account_get_protocol_name(account),
				2, purple_prefs_get_string(buf1), 3, purple_prefs_get_bool(buf2),
				4, purple_prefs_get_bool(buf3), 5, account, -1);
		accounts = accounts->next;
	}
	treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore));
	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, _("Screen Name"),
			gtk_cell_renderer_text_new(), "text", 0, NULL);
	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, _("Protocol"),
			gtk_cell_renderer_text_new(), "text", 1, NULL);

	renderer = gtk_cell_renderer_text_new();
	g_signal_connect(G_OBJECT(renderer), "edited", G_CALLBACK(cb_custom_edited), (gpointer) GTK_TREE_MODEL(liststore));
	g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL);
	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, _("Playing Status Format"),
			renderer, "text", 2, NULL);

	renderer = gtk_cell_renderer_toggle_new();
	g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(cb_custom_toggled), (gpointer) GTK_TREE_MODEL(liststore));
	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, _("Disable"),
			renderer, "active", 3, NULL);


	renderer = gtk_cell_renderer_toggle_new();
	g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(cb_broken_nowlistening_toggled), (gpointer) GTK_TREE_MODEL(liststore));
	gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, _("Broken 'now listening'"),
			renderer, "active", 4, NULL);


	expand = gtk_expander_new(_("Customize playing status format, or disable status changing altogether for specific accounts"));
	gtk_expander_set_spacing(GTK_EXPANDER(expand), 5);
	gtk_box_pack_start(GTK_BOX(vbox), expand, TRUE, TRUE, 0);
	widget = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(widget), GTK_SHADOW_ETCHED_IN);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_container_add(GTK_CONTAINER(expand), widget);
	gtk_container_add(GTK_CONTAINER(widget), treeview);

        // Misc settings
	frame = gtk_frame_new(_("Other settings"));
	gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
	align2 = gtk_alignment_new(0, 0, 1, 1);
	gtk_alignment_set_padding(GTK_ALIGNMENT(align2), 5, 5, 5, 5);
	gtk_container_add(GTK_CONTAINER(frame), align2);
	vbox2 = gtk_vbox_new(FALSE, 5);
	gtk_container_add(GTK_CONTAINER(align2), vbox2);

	hbox = gtk_hbox_new(FALSE, 5);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
	widget = gtk_check_button_new_with_label(_("Don't change status message when away"));
	gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), purple_prefs_get_bool(PREF_DISABLE_WHEN_AWAY));
	g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(cb_misc_toggled), (gpointer) PREF_DISABLE_WHEN_AWAY);

	hbox = gtk_hbox_new(FALSE, 5);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
	widget = gtk_check_button_new_with_label(_("Don't change status message if protocol has working 'now listening'"));
	gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), purple_prefs_get_bool(PREF_NOW_LISTENING_ONLY));
	g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(cb_misc_toggled), (gpointer) PREF_NOW_LISTENING_ONLY);

	// Filter
	frame = gtk_frame_new(_("Status Filter"));
	gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
	align2 = gtk_alignment_new(0, 0, 1, 1);
	gtk_alignment_set_padding(GTK_ALIGNMENT(align2), 5, 5, 5, 5);
	gtk_container_add(GTK_CONTAINER(frame), align2);
	vbox2 = gtk_vbox_new(FALSE, 5);
	gtk_container_add(GTK_CONTAINER(align2), vbox2);

	hbox = gtk_hbox_new(FALSE, 5);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
	widget = gtk_check_button_new_with_label(_("Enable status filter"));
	gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), purple_prefs_get_bool(PREF_FILTER_ENABLE));
	g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(cb_filter_toggled), 0);

	hbox = gtk_hbox_new(FALSE, 5);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(_("Blacklist (comma-delimited):")), FALSE, FALSE, 0);
	widget = gtk_entry_new();
	gtk_entry_set_text(GTK_ENTRY(widget), purple_prefs_get_string(PREF_FILTER));
	gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
	g_signal_connect(G_OBJECT(widget), "changed", G_CALLBACK(cb_filter_changed), 0);
	filter_list = widget;

	hbox = gtk_hbox_new(FALSE, 5);
	gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(_("Mask character:")), FALSE, FALSE, 0);
	widget = gtk_entry_new_with_max_length(1);
	gtk_entry_set_text(GTK_ENTRY(widget), purple_prefs_get_string(PREF_MASK));
	gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
	g_signal_connect(G_OBJECT(widget), "changed", G_CALLBACK(cb_filter_mask_changed), 0);
	filter_mask = widget;

	gboolean state = purple_prefs_get_bool(PREF_FILTER_ENABLE);
	gtk_widget_set_sensitive(filter_list, state);
	gtk_widget_set_sensitive(filter_mask, state);

	gtk_widget_show_all(align);
	return align;
}
Ejemplo n.º 25
0
static void on_new_message(PurpleAccount *account, const char *remote,
    const char *message)
{
  const char *command = purple_prefs_get_path(PLUGIN_PREF_COMMAND);

  // the command should be never NULL
  g_return_if_fail(command);

  if (!command[0]) {
    // no command is set
    return;
  }

  const char *protocol = purple_account_get_protocol_name(account);
  char *local = g_strdup(purple_normalize(account,
        purple_account_get_username(account)));
  char *nohtml = purple_markup_strip_html(message);
  PurpleBuddy *buddy = purple_find_buddy(account, remote);
  char *icon_encoded = NULL;
  if (buddy) {
    // get buddy alias and icon
    remote = purple_buddy_get_alias(buddy);
    PurpleBuddyIcon *icon = purple_buddy_get_icon(buddy);
    if (icon) {
      size_t len;
      gconstpointer data = purple_buddy_icon_get_data(icon, &len);
      icon_encoded = g_base64_encode(data, len);
    }
  }

  char *argv[2];
  argv[0] = g_strdup(command);
  argv[1] = NULL;

  // prepare child's environment variables
  char **envp = g_get_environ();
  envp = g_environ_setenv(envp, "EVENT_TYPE", "msg", TRUE);
  envp = g_environ_setenv(envp, "EVENT_NETWORK", protocol, TRUE);
  envp = g_environ_setenv(envp, "EVENT_LOCAL_USER", local, TRUE);
  envp = g_environ_setenv(envp, "EVENT_REMOTE_USER", remote, TRUE);
  if (icon_encoded)
    envp = g_environ_setenv(envp, "EVENT_REMOTE_USER_ICON", icon_encoded, TRUE);
  envp = g_environ_setenv(envp, "EVENT_MESSAGE", nohtml, TRUE);
  envp = g_environ_setenv(envp, "EVENT_MESSAGE_HTML", message, TRUE);

  // spawn the command
  GError *err = NULL;
  if (!g_spawn_async(NULL, argv, envp, G_SPAWN_SEARCH_PATH
        | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL,
        NULL, &err)) {
    purple_debug_error("extaction", "%s", err->message);
    g_clear_error(&err);
  }

  // free all resources
  g_free(argv[0]);
  g_strfreev(envp);

  g_free(local);
  g_free(nohtml);
  g_free(icon_encoded);
}
Ejemplo n.º 26
0
static VALUE protocol_name(VALUE self)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  return rb_str_new2(purple_account_get_protocol_name(account));
}
Ejemplo n.º 27
0
void
finch_pounce_editor_show(PurpleAccount *account, const char *name,
							PurplePounce *cur_pounce)
{
	PurpleGntPounceDialog *dialog;
	GntWidget *window;
	GntWidget *bbox;
	GntWidget *hbox, *vbox;
	GntWidget *button;
	GntWidget *combo;
	GList *list;

	g_return_if_fail((cur_pounce != NULL) ||
	                 (account != NULL) ||
	                 (purple_accounts_get_all() != NULL));

	dialog = g_new0(PurpleGntPounceDialog, 1);

	if (cur_pounce != NULL) {
		dialog->pounce  = cur_pounce;
		dialog->account = purple_pounce_get_pouncer(cur_pounce);
	} else if (account != NULL) {
		dialog->pounce  = NULL;
		dialog->account = account;
	} else {
		GList *connections = purple_connections_get_all();
		PurpleConnection *gc;

		if (connections != NULL) {
			gc = (PurpleConnection *)connections->data;
			dialog->account = purple_connection_get_account(gc);
		} else
			dialog->account = purple_accounts_get_all()->data;

		dialog->pounce  = NULL;
	}

	/* Create the window. */
	dialog->window = window = gnt_vbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(window), 0);
	gnt_box_set_toplevel(GNT_BOX(window), TRUE);
	gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_LEFT);
	gnt_box_set_title(GNT_BOX(window),
						 (cur_pounce == NULL
						  ? _("New Buddy Pounce") : _("Edit Buddy Pounce")));

	g_signal_connect(G_OBJECT(window), "destroy",
					 G_CALLBACK(delete_win_cb), dialog);

	gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Pounce on Whom"), GNT_TEXT_FLAG_BOLD));

	/* Account: */
	gnt_box_add_widget(GNT_BOX(window), gnt_label_new(_("Account:")));
	dialog->account_menu = combo = gnt_combo_box_new();
	list = purple_accounts_get_all();
	for (; list; list = list->next)
	{
		PurpleAccount *account;
		char *text;

		account = list->data;
		text = g_strdup_printf("%s (%s)",
				purple_account_get_username(account),
				purple_account_get_protocol_name(account));
		gnt_combo_box_add_data(GNT_COMBO_BOX(combo), account, text);
		g_free(text);
	}
	if (dialog->account)
		gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), dialog->account);

	gnt_box_add_widget(GNT_BOX(window), combo);

	/* Buddy: */
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Buddy name:")));

	dialog->buddy_entry = gnt_entry_new(NULL);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->buddy_entry);

	setup_buddy_list_suggestion(GNT_ENTRY(dialog->buddy_entry), TRUE);

	gnt_box_add_widget(GNT_BOX(window), hbox);

	if (cur_pounce != NULL) {
		gnt_entry_set_text(GNT_ENTRY(dialog->buddy_entry),
						   purple_pounce_get_pouncee(cur_pounce));
	} else if (name != NULL) {
		gnt_entry_set_text(GNT_ENTRY(dialog->buddy_entry), name);
	}

	/* Create the event frame */
	gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE));
	gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Pounce When Buddy..."), GNT_TEXT_FLAG_BOLD));

	dialog->signon = gnt_check_box_new(_("Signs on"));
	dialog->signoff = gnt_check_box_new(_("Signs off"));
	dialog->away = gnt_check_box_new(_("Goes away"));
	dialog->away_return = gnt_check_box_new(_("Returns from away"));
	dialog->idle = gnt_check_box_new(_("Becomes idle"));
	dialog->idle_return = gnt_check_box_new(_("Is no longer idle"));
	dialog->typing = gnt_check_box_new(_("Starts typing"));
	dialog->typed = gnt_check_box_new(_("Pauses while typing"));
	dialog->stop_typing = gnt_check_box_new(_("Stops typing"));
	dialog->message_recv = gnt_check_box_new(_("Sends a message"));

	hbox = gnt_hbox_new(TRUE);
	gnt_box_set_pad(GNT_BOX(hbox), 2);

	vbox = gnt_vbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(vbox), 0);
	gnt_box_add_widget(GNT_BOX(hbox), vbox);

	gnt_box_add_widget(GNT_BOX(vbox), dialog->signon);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->away);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->idle);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->typing);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->stop_typing);

	vbox = gnt_vbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(vbox), 0);
	gnt_box_add_widget(GNT_BOX(hbox), vbox);

	gnt_box_add_widget(GNT_BOX(vbox), dialog->signoff);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->away_return);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->idle_return);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->typed);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->message_recv);

	gnt_box_add_widget(GNT_BOX(window), hbox);

	/* Create the "Action" frame. */
	gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE));
	gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Action"), GNT_TEXT_FLAG_BOLD));

	dialog->open_win = gnt_check_box_new(_("Open an IM window"));
	dialog->popup = gnt_check_box_new(_("Pop up a notification"));
	dialog->send_msg = gnt_check_box_new(_("Send a message"));
	dialog->exec_cmd = gnt_check_box_new(_("Execute a command"));
	dialog->play_sound = gnt_check_box_new(_("Play a sound"));

	dialog->send_msg_entry    = gnt_entry_new(NULL);
	dialog->exec_cmd_entry    = gnt_entry_new(NULL);
	dialog->popup_entry       = gnt_entry_new(NULL);
	dialog->exec_cmd_entry   = gnt_entry_new(NULL);

	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->open_win);
	gnt_box_add_widget(GNT_BOX(window), hbox);
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->popup);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->popup_entry);
	gnt_box_add_widget(GNT_BOX(window), hbox);
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->send_msg);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->send_msg_entry);
	gnt_box_add_widget(GNT_BOX(window), hbox);
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->exec_cmd);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->exec_cmd_entry);
	gnt_box_add_widget(GNT_BOX(window), hbox);
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->play_sound);
	gnt_box_add_widget(GNT_BOX(window), hbox);

	gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE));
	gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Options"), GNT_TEXT_FLAG_BOLD));
	dialog->on_away = gnt_check_box_new(_("Pounce only when my status is not Available"));
	gnt_box_add_widget(GNT_BOX(window), dialog->on_away);
	dialog->save_pounce = gnt_check_box_new(_("Recurring"));
	gnt_box_add_widget(GNT_BOX(window), dialog->save_pounce);


	gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE));
	/* Now the button box! */
	bbox = gnt_hbox_new(FALSE);

	/* Cancel button */
	button = gnt_button_new(_("Cancel"));
	gnt_box_add_widget(GNT_BOX(bbox), button);
	g_signal_connect(G_OBJECT(button), "activate",
					 G_CALLBACK(cancel_cb), dialog);

	/* Save button */
	dialog->save_button = button = gnt_button_new(_("Save"));
	gnt_box_add_widget(GNT_BOX(bbox), button);
	g_signal_connect(G_OBJECT(button), "activate",
					 G_CALLBACK(save_pounce_cb), dialog);

	gnt_box_add_widget(GNT_BOX(window), bbox);


	/* Set the values of stuff. */
	if (cur_pounce != NULL)
	{
		PurplePounceEvent events   = purple_pounce_get_events(cur_pounce);
		PurplePounceOption options = purple_pounce_get_options(cur_pounce);
		const char *value;

		/* Options */
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->on_away),
									(options & PURPLE_POUNCE_OPTION_AWAY));

		/* Events */
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->signon),
									(events & PURPLE_POUNCE_SIGNON));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->signoff),
									(events & PURPLE_POUNCE_SIGNOFF));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->away),
									(events & PURPLE_POUNCE_AWAY));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->away_return),
									(events & PURPLE_POUNCE_AWAY_RETURN));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->idle),
									(events & PURPLE_POUNCE_IDLE));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->idle_return),
									(events & PURPLE_POUNCE_IDLE_RETURN));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->typing),
									(events & PURPLE_POUNCE_TYPING));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->typed),
									(events & PURPLE_POUNCE_TYPED));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->stop_typing),
									(events & PURPLE_POUNCE_TYPING_STOPPED));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->message_recv),
									(events & PURPLE_POUNCE_MESSAGE_RECEIVED));

		/* Actions */
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->open_win),
			purple_pounce_action_is_enabled(cur_pounce, "open-window"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->popup),
			purple_pounce_action_is_enabled(cur_pounce, "popup-notify"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->send_msg),
			purple_pounce_action_is_enabled(cur_pounce, "send-message"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->exec_cmd),
			purple_pounce_action_is_enabled(cur_pounce, "execute-command"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->play_sound),
			purple_pounce_action_is_enabled(cur_pounce, "play-beep"));

		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->save_pounce),
			purple_pounce_get_save(cur_pounce));

		if ((value = purple_pounce_action_get_attribute(cur_pounce,
		                                              "send-message",
		                                              "message")) != NULL)
		{
			gnt_entry_set_text(GNT_ENTRY(dialog->send_msg_entry), value);
		}

		if ((value = purple_pounce_action_get_attribute(cur_pounce,
		                                              "popup-notify",
		                                              "reason")) != NULL)
		{
			gnt_entry_set_text(GNT_ENTRY(dialog->popup_entry), value);
		}

		if ((value = purple_pounce_action_get_attribute(cur_pounce,
		                                              "execute-command",
		                                              "command")) != NULL)
		{
			gnt_entry_set_text(GNT_ENTRY(dialog->exec_cmd_entry), value);
		}
	}
	else
	{
		PurpleBuddy *buddy = NULL;

		if (name != NULL)
			buddy = purple_find_buddy(account, name);

		/* Set some defaults */
		if (buddy == NULL) {
			gnt_check_box_set_checked(
				GNT_CHECK_BOX(dialog->signon), TRUE);
		} else {
			if (!PURPLE_BUDDY_IS_ONLINE(buddy)) {
				gnt_check_box_set_checked(
					GNT_CHECK_BOX(dialog->signon), TRUE);
			} else {
				gboolean default_set = FALSE;
				PurplePresence *presence = purple_buddy_get_presence(buddy);

				if (purple_presence_is_idle(presence))
				{
					gnt_check_box_set_checked(
						GNT_CHECK_BOX(dialog->idle_return), TRUE);

					default_set = TRUE;
				}

				if (!purple_presence_is_available(presence))
				{
					gnt_check_box_set_checked(
						GNT_CHECK_BOX(dialog->away_return), TRUE);

					default_set = TRUE;
				}

				if (!default_set)
				{
					gnt_check_box_set_checked(
						GNT_CHECK_BOX(dialog->signon), TRUE);
				}
			}
		}

		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->open_win),
			purple_prefs_get_bool("/finch/pounces/default_actions/open-window"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->popup),
			purple_prefs_get_bool("/finch/pounces/default_actions/popup-notify"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->send_msg),
			purple_prefs_get_bool("/finch/pounces/default_actions/send-message"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->exec_cmd),
			purple_prefs_get_bool("/finch/pounces/default_actions/execute-command"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->play_sound),
			purple_prefs_get_bool("/finch/pounces/default_actions/play-beep"));
	}

	gnt_widget_show(window);
}
Ejemplo n.º 28
0
static gboolean
popup_substatus(GntTree *tree, const char *key, EditStatus *edit)
{
	if (key[0] == ' ' && key[1] == 0)
	{
		EditSubStatus *sub;
		GntWidget *window, *combo, *entry, *box, *button, *l;
		PurpleSavedStatusSub *substatus = NULL;
		GList *iter;
		char *name;
		RowInfo *selected = gnt_tree_get_selection_data(tree);
		PurpleAccount *account = selected->account;

		if (gnt_tree_get_choice(tree, selected))
		{
			/* There was a savedstatus for this account. Now remove it. */
			g_free(selected->message);
			selected->type = NULL;
			selected->message = NULL;
			/* XXX: should we really be saving it right now? */
			purple_savedstatus_unset_substatus(edit->saved, account);
			gnt_tree_change_text(tree, account, 1, NULL);
			gnt_tree_change_text(tree, account, 2, NULL);
			return FALSE;
		}

		if (g_hash_table_lookup(edit->hash, account))
			return TRUE;

		if (edit->saved)
			substatus = purple_savedstatus_get_substatus(edit->saved, account);

		sub = g_new0(EditSubStatus, 1);
		sub->parent = edit;
		sub->key = selected;

		sub->window = window = gnt_vbox_new(FALSE);
		gnt_box_set_toplevel(GNT_BOX(window), TRUE);
		gnt_box_set_title(GNT_BOX(window), _("Substatus"));  /* XXX: a better title */
		gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);

		box = gnt_hbox_new(FALSE);
		gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Account:")));
		name = g_strdup_printf("%s (%s)", purple_account_get_username(account),
				purple_account_get_protocol_name(account));
		gnt_box_add_widget(GNT_BOX(box), gnt_label_new(name));
		g_free(name);
		gnt_box_add_widget(GNT_BOX(window), box);

		box = gnt_hbox_new(FALSE);
		gnt_box_add_widget(GNT_BOX(box), (l = gnt_label_new(_("Status:"))));
		gnt_widget_set_size(l, 0, 1);   /* I don't like having to do this */
		sub->type = combo = gnt_combo_box_new();
		gnt_box_add_widget(GNT_BOX(box), combo);
		gnt_box_add_widget(GNT_BOX(window), box);

		for (iter = purple_account_get_status_types(account); iter; iter = iter->next)
		{
			PurpleStatusType *type = iter->data;
			if (!purple_status_type_is_user_settable(type))
				continue;
			gnt_combo_box_add_data(GNT_COMBO_BOX(combo), type, purple_status_type_get_name(type));
		}

		box = gnt_hbox_new(FALSE);
		gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message:")));
		sub->message = entry = gnt_entry_new(substatus ? purple_savedstatus_substatus_get_message(substatus) : NULL);
		gnt_box_add_widget(GNT_BOX(box), entry);
		gnt_box_add_widget(GNT_BOX(window), box);

		box  = gnt_hbox_new(FALSE);
		button = gnt_button_new(_("Cancel"));
		g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window);
		gnt_box_add_widget(GNT_BOX(box), button);
		button = gnt_button_new(_("Save"));
		g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_substatus_cb), sub);
		gnt_box_add_widget(GNT_BOX(box), button);
		gnt_box_add_widget(GNT_BOX(window), box);

		gnt_widget_show(window);

		g_hash_table_insert(edit->hash, account, sub);

		g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(substatus_window_destroy_cb), sub);

		return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 29
0
static PurplePluginPrefFrame *
get_plugin_pref_frame(PurplePlugin *plugin)
{
	PurplePluginPrefFrame *frame;
	PurplePluginPref *ppref;

	PurpleAccount *account;
	char *name, *id, *path;
	int len;
	GList *l, *listed_protocols;
	
	DEBUG_MSG("get_plugin_pref_frame");
	
	frame = purple_plugin_pref_frame_new();

	ppref = purple_plugin_pref_new_with_name_and_label(
	"/plugins/core/pidgin-gntp/on_focus", "show message when window is focused");
	purple_plugin_pref_frame_add(frame, ppref);
	
	ppref = purple_plugin_pref_new_with_label("Send notifications when status is:");
	purple_plugin_pref_frame_add(frame, ppref);	
	
	ppref = purple_plugin_pref_new_with_name_and_label(
	"/plugins/core/pidgin-gntp/on_available", "available");
	purple_plugin_pref_frame_add(frame, ppref);
	
	ppref = purple_plugin_pref_new_with_name_and_label(
	"/plugins/core/pidgin-gntp/on_unavailable", "unavailable");
	purple_plugin_pref_frame_add(frame, ppref);
	
	ppref = purple_plugin_pref_new_with_name_and_label(
	"/plugins/core/pidgin-gntp/on_invisible", "invisible");
	purple_plugin_pref_frame_add(frame, ppref);
	
	ppref = purple_plugin_pref_new_with_name_and_label(
	"/plugins/core/pidgin-gntp/on_away", "away");
	purple_plugin_pref_frame_add(frame, ppref);
	
	
	ppref = purple_plugin_pref_new_with_label("Starting delay (to prevent spam while connecting):");
	purple_plugin_pref_frame_add(frame, ppref);
	
	ppref = purple_plugin_pref_new_with_name_and_label(
	"/plugins/core/pidgin-gntp/hack_ms", "value in milliseconds (1000ms = 1 sec)");
	purple_plugin_pref_set_bounds(ppref, 0, 30000);
	purple_plugin_pref_frame_add(frame, ppref);
	
	
	ppref = purple_plugin_pref_new_with_label("Following protocols sends notifications:");
	purple_plugin_pref_frame_add(frame, ppref);
		
	listed_protocols = NULL;
	for (l = purple_accounts_get_all(); l != NULL; l = l->next)
	{
		account = (PurpleAccount *)l->data;
		
		name = (char*)purple_account_get_protocol_name (account);
		id = (char*)purple_account_get_protocol_id (account);		
		
		if( !g_list_find_custom(listed_protocols, id, (GCompareFunc)strcmp) )
		{
			listed_protocols = g_list_prepend (listed_protocols, id);
			
			len = s_strlen("/plugins/core/pidgin-gntp/") + s_strlen(id) + 1;
			path = malloc( len ); 
			g_snprintf(path, len, "%s%s", "/plugins/core/pidgin-gntp/", id );
				
			if(!purple_prefs_exists(path))
				purple_prefs_add_bool(path, TRUE);
			
			ppref = purple_plugin_pref_new_with_name_and_label(path, name);
			purple_plugin_pref_frame_add(frame, ppref);
			free(path);
		}
	}
	g_list_free(listed_protocols);
			
	ppref = purple_plugin_pref_new_with_label(REV);
	purple_plugin_pref_frame_add(frame, ppref);

	return frame;
}