static void
notify_buddy_signoff_cb (PurpleBuddy *buddy,
						 gpointer data)
{
	gchar *tr_name, *title;
	gboolean blocked;

	g_return_if_fail (buddy);

	if (!purple_prefs_get_bool ("/plugins/gtk/libnotify/signoff"))
		return;

	if (g_list_find (just_signed_on_accounts, buddy->account))
		return;

	blocked = purple_prefs_get_bool ("/plugins/gtk/libnotify/blocked");
	if (!purple_privacy_check (buddy->account, buddy->name) && blocked)
		return;

	if (!should_notify_unavailable (purple_buddy_get_account (buddy)))
		return;

	tr_name = truncate_escape_string (best_name (buddy), 25);

	title = g_strdup_printf (_("%s signed off"), tr_name);

	notify (title, NULL, buddy, NULL);

	g_free (tr_name);
	g_free (title);
}
static void
notify_msg_sent (PurpleAccount *account,
				 PurpleConversation *conv,
				 const gchar *sender,
				 const gchar *message)
{
	PurpleBuddy *buddy;
	gchar *title, *body, *tr_name;
	gboolean blocked;

	blocked = purple_prefs_get_bool ("/plugins/gtk/libnotify/blocked");
	if (blocked && !purple_privacy_check(account, sender))
		return;

	buddy = purple_find_buddy (account, sender);
	if (buddy)
		tr_name = truncate_escape_string (best_name (buddy), 25);
	else if (conv) {
		char *name = g_strdup_printf (_("%s (%s)"), sender, purple_conversation_get_name (conv));
		tr_name = truncate_escape_string (name, 25);
		g_free (name);
	} else
		tr_name = truncate_escape_string (sender, 25);

	if (purple_prefs_get_bool("/plugins/gtk/libnotify/newmsgtxt")) {
		title = g_strdup_printf (_("%s says:"), tr_name);
		body = purple_markup_strip_html (message);

		notify (title, body, buddy, conv);

		g_free (title);
	} else {
		title = _("new message received");
		body = g_strdup_printf (_("from %s"), tr_name);

		notify (title, body, buddy, conv);
	}
	g_free (tr_name);
	g_free (body);
}
示例#3
0
static int
intuit_diff_type(void)
{
	long	this_line = 0, previous_line;
	long	first_command_line = -1;
	LINENUM	fcl_line = -1;
	bool	last_line_was_command = false, this_is_a_command = false;
	bool	stars_last_line = false, stars_this_line = false;
	char	*s, *t;
	int	indent, retval;
	struct file_name names[MAX_FILE];

	memset(names, 0, sizeof(names));
	ok_to_create_file = false;
	fseek(pfp, p_base, SEEK_SET);
	p_input_line = p_bline - 1;
	for (;;) {
		previous_line = this_line;
		last_line_was_command = this_is_a_command;
		stars_last_line = stars_this_line;
		this_line = ftell(pfp);
		indent = 0;
		p_input_line++;
		if (pgets(false) == 0) {
			if (first_command_line >= 0L) {
				/* nothing but deletes!? */
				p_start = first_command_line;
				p_sline = fcl_line;
				retval = ED_DIFF;
				goto scan_exit;
			} else {
				p_start = this_line;
				p_sline = p_input_line;
				retval = 0;
				goto scan_exit;
			}
		}
		for (s = buf; *s == ' ' || *s == '\t' || *s == 'X'; s++) {
			if (*s == '\t')
				indent += 8 - (indent % 8);
			else
				indent++;
		}
		for (t = s; isdigit((unsigned char)*t) || *t == ','; t++)
			;
		this_is_a_command = (isdigit((unsigned char)*s) &&
		    (*t == 'd' || *t == 'c' || *t == 'a'));
		if (first_command_line < 0L && this_is_a_command) {
			first_command_line = this_line;
			fcl_line = p_input_line;
			p_indent = indent;	/* assume this for now */
		}
		if (!stars_last_line && strnEQ(s, "*** ", 4))
			names[OLD_FILE].path = fetchname(s + 4,
			    &names[OLD_FILE].exists, strippath);
		else if (strnEQ(s, "--- ", 4))
			names[NEW_FILE].path = fetchname(s + 4,
			    &names[NEW_FILE].exists, strippath);
		else if (strnEQ(s, "+++ ", 4))
			/* pretend it is the old name */
			names[OLD_FILE].path = fetchname(s + 4,
			    &names[OLD_FILE].exists, strippath);
		else if (strnEQ(s, "Index:", 6))
			names[INDEX_FILE].path = fetchname(s + 6,
			    &names[INDEX_FILE].exists, strippath);
		else if (strnEQ(s, "Prereq:", 7)) {
			for (t = s + 7; isspace((unsigned char)*t); t++)
				;
			revision = savestr(t);
			for (t = revision; *t && !isspace((unsigned char)*t); t++)
				;
			*t = '\0';
			if (*revision == '\0') {
				free(revision);
				revision = NULL;
			}
		} else if (strnEQ(s, "==== ", 5)) {
			/* Perforce-style diffs. */
			if ((t = strstr(s + 5, " - ")) != NULL)
				p4_fetchname(&names[NEW_FILE], t + 3);
			p4_fetchname(&names[OLD_FILE], s + 5);
		}
		if ((!diff_type || diff_type == ED_DIFF) &&
		    first_command_line >= 0L &&
		    strEQ(s, ".\n")) {
			p_indent = indent;
			p_start = first_command_line;
			p_sline = fcl_line;
			retval = ED_DIFF;
			goto scan_exit;
		}
		if ((!diff_type || diff_type == UNI_DIFF) && strnEQ(s, "@@ -", 4)) {
			if (strnEQ(s + 4, "0,0", 3))
				ok_to_create_file = true;
			p_indent = indent;
			p_start = this_line;
			p_sline = p_input_line;
			retval = UNI_DIFF;
			goto scan_exit;
		}
		stars_this_line = strnEQ(s, "********", 8);
		if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line &&
		    strnEQ(s, "*** ", 4)) {
			if (atol(s + 4) == 0)
				ok_to_create_file = true;
			/*
			 * If this is a new context diff the character just
			 * before the newline is a '*'.
			 */
			while (*s != '\n')
				s++;
			p_indent = indent;
			p_start = previous_line;
			p_sline = p_input_line - 1;
			retval = (*(s - 1) == '*' ? NEW_CONTEXT_DIFF : CONTEXT_DIFF);
			goto scan_exit;
		}
		if ((!diff_type || diff_type == NORMAL_DIFF) &&
		    last_line_was_command &&
		    (strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2))) {
			p_start = previous_line;
			p_sline = p_input_line - 1;
			p_indent = indent;
			retval = NORMAL_DIFF;
			goto scan_exit;
		}
	}
scan_exit:
	if (retval == UNI_DIFF) {
		/* unswap old and new */
		struct file_name tmp = names[OLD_FILE];
		names[OLD_FILE] = names[NEW_FILE];
		names[NEW_FILE] = tmp;
	}
	if (filearg[0] == NULL) {
		if (posix)
			filearg[0] = posix_name(names, ok_to_create_file);
		else {
			/* Ignore the Index: name for context diffs, like GNU */
			if (names[OLD_FILE].path != NULL ||
			    names[NEW_FILE].path != NULL) {
				free(names[INDEX_FILE].path);
				names[INDEX_FILE].path = NULL;
			}
			filearg[0] = best_name(names, ok_to_create_file);
		}
	}

	free(bestguess);
	bestguess = NULL;
	if (filearg[0] != NULL)
		bestguess = savestr(filearg[0]);
	else if (!ok_to_create_file) {
		/*
		 * We don't want to create a new file but we need a
		 * filename to set bestguess.  Avoid setting filearg[0]
		 * so the file is not created automatically.
		 */
		if (posix)
			bestguess = posix_name(names, true);
		else
			bestguess = best_name(names, true);
	}
	free(names[OLD_FILE].path);
	free(names[NEW_FILE].path);
	free(names[INDEX_FILE].path);
	return retval;
}
static void
notify (const gchar *title,
		const gchar *body,
		PurpleBuddy *buddy,
		PurpleConversation *conv)
{
	NotifyNotification *notification = NULL;
	GdkPixbuf *icon;
	PurpleBuddyIcon *buddy_icon;
	gchar *tr_body;
	PurpleContact *contact;

	if (buddy)
		contact = purple_buddy_get_contact (buddy);
	else
		contact = NULL;

	if (body)
		tr_body = truncate_escape_string (body, 60);
	else
		tr_body = NULL;

	if (!conv && buddy)
		conv = purple_find_conversation_with_account (PURPLE_CONV_TYPE_ANY, buddy->name, buddy->account);

	if (conv && conv->ui_ops && conv->ui_ops->has_focus) {
	    if (conv->ui_ops->has_focus(conv) == TRUE) {
		/* do not notify if the conversation is currently in focus */
		return;
	    }
	}

	if (contact)
		notification = g_hash_table_lookup (buddy_hash, contact);
	else if (conv)
		notification = g_hash_table_lookup (buddy_hash, conv);
	else
		notification = NULL;

	if (notification != NULL) {
		notify_notification_update (notification, title, tr_body, NULL);
		notify_notification_set_timeout(notification, purple_prefs_get_int("/plugins/gtk/libnotify/timeout"));
		/* this shouldn't be necessary, file a bug */
		notify_notification_show (notification, NULL);

		purple_debug_info (PLUGIN_ID, "notify(), update: "
						 "title: '%s', body: '%s', buddy: '%s'\n",
						 title, tr_body, buddy ? best_name (buddy) : "");

		g_free (tr_body);
		return;
	}
#ifdef LIBNOTIFY_07
	notification = notify_notification_new (title, tr_body, NULL);
#else
	notification = notify_notification_new (title, tr_body, NULL, NULL);
#endif
	purple_debug_info (PLUGIN_ID, "notify(), new: "
					 "title: '%s', body: '%s', buddy: '%s'\n",
					 title, tr_body, buddy ? best_name (buddy) : "");

	g_free (tr_body);

	if (buddy)
		buddy_icon = purple_buddy_get_icon (buddy);
	else
		buddy_icon = NULL;

	if (buddy_icon) {
		icon = pixbuf_from_buddy_icon (buddy_icon);
		purple_debug_info (PLUGIN_ID, "notify(), has a buddy icon.\n");
	} else if (buddy) {
		icon = pidgin_create_prpl_icon (buddy->account, 1);
		purple_debug_info (PLUGIN_ID, "notify(), has a prpl icon.\n");
	} else if (conv) {
		icon = pidgin_create_prpl_icon (conv->account, 1);
		purple_debug_info (PLUGIN_ID, "notify(), has a prpl icon.\n");
	} else {
		icon = NULL;
		purple_debug_info (PLUGIN_ID, "notify(), has no icon.\n");
	}

	if (icon) {
		notify_notification_set_icon_from_pixbuf (notification, icon);
		g_object_unref (icon);
	} else {
		purple_debug_warning (PLUGIN_ID, "notify(), couldn't find any icon!\n");
	}

	if (contact)
		g_hash_table_insert (buddy_hash, contact, notification);
	else if (conv)
		g_hash_table_insert (buddy_hash, conv, notification);

	g_object_set_data (G_OBJECT(notification), "contact", contact);
	g_object_set_data (G_OBJECT(notification), "conv", conv);
	g_object_set_data (G_OBJECT(notification), "buddy", buddy);

	g_signal_connect (notification, "closed", G_CALLBACK(closed_cb), NULL);

	notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);

	notify_notification_add_action (notification, "show", _("Show"), action_cb, NULL, NULL);

	notify_notification_set_timeout(notification, purple_prefs_get_int("/plugins/gtk/libnotify/timeout"));
	if (!notify_notification_show (notification, NULL)) {
		purple_debug_error (PLUGIN_ID, "notify(), failed to send notification\n");
	}

}
示例#5
0
static int filterdiff (FILE *f, const char *patchname)
{
	static unsigned long linenum = 1;
	char *names[2];
	char *header[MAX_HEADERS] = { NULL, NULL };
        unsigned int num_headers = 0;
	char *line = NULL;
	size_t linelen = 0;
	char *p;
	const char *p_stripped;
	int match;
	int i;

	if (getline (&line, &linelen, f) == -1)
		return 0;

	for (;;) {
		char status = '!';
		unsigned long start_linenum;
		int orig_file_exists, new_file_exists;
		int is_context = -1;
		int result;
		int (*do_diff) (FILE *, char **, unsigned int,
                                int, char **, size_t *,
				unsigned long *, unsigned long,
				char, const char *, const char *,
				int *, int *);

		orig_file_exists = 0; // shut gcc up

		// Search for start of patch ("diff ", or "--- " for
		// unified diff, "*** " for context).
		for (;;) {
                        if (!strncmp (line, "diff ", 5))
                                break;

			if (!strncmp (line, "--- ", 4)) {
				is_context = 0;
				break;
			}

			if (!strncmp (line, "*** ", 4)) {
				is_context = 1;
				break;
			}

			/* Show non-diff lines if excluding, or if
			 * in verbose mode, and if --clean isn't specified. */
			if (mode == mode_filter && (pat_exclude || verbose)
				&& !clean_comments)
				fputs (line, stdout);

			if (getline (&line, &linelen, f) == -1)
				goto eof;
			linenum++;
		}

		start_linenum = linenum;
		header[0] = xstrdup (line);
                num_headers = 1;

                if (is_context == -1) {
                        int valid_extended = 1;
                        for (;;) {
                                if (getline (&line, &linelen, f) == -1)
                                        goto eof;
                                linenum++;

                                if (!strncmp (line, "diff ", 5)) {
                                        header[num_headers++] = xstrdup (line);
                                        break;
                                }

                                if (!strncmp (line, "--- ", 4))
                                        is_context = 0;
                                else if (!strncmp (line, "*** ", 4))
                                        is_context = 1;
                                else if (strncmp (line, "old mode ", 9) &&
                                    strncmp (line, "new mode ", 9) &&
                                    strncmp (line, "deleted file mode ", 18) &&
                                    strncmp (line, "new file mode ", 15) &&
                                    strncmp (line, "copy from ", 10) &&
                                    strncmp (line, "copy to ", 8) &&
                                    strncmp (line, "rename from ", 12) &&
                                    strncmp (line, "rename to ", 10) &&
                                    strncmp (line, "similarity index ", 17) &&
                                    strncmp (line, "dissimilarity index ", 20) &&
                                    strncmp (line, "index ", 6))
                                        valid_extended = 0;

                                if (!valid_extended)
                                        break;

                                /* Drop excess header lines */
                                if (num_headers >= MAX_HEADERS - 2)
                                        free (header[--num_headers]);

                                header[num_headers++] = xstrdup (line);

                                if (is_context != -1)
                                        break;
                        }

                        if (!valid_extended)
                                goto flush_continue;
                }

                if (is_context == -1) {
                        /* We don't yet do anything with diffs with
                         * zero hunks. */
                        unsigned int i = 0;
                flush_continue:
                        if (mode == mode_filter && (pat_exclude || verbose)
                            && !clean_comments) {
                                for (i = 0; i < num_headers; i++)
                                        fputs (header[i], stdout);
                        }
                        for (i = 0; i < num_headers; i++) {
                                free (header[i]);
                                header[i] = NULL;
                        }
                        num_headers = 0;
                        continue;
                }

		names[0] = filename_from_header (line + 4);
		if (mode != mode_filter && show_status)
			orig_file_exists = file_exists (names[0], line + 4 +
							strlen (names[0]));

		if (getline (&line, &linelen, f) == -1) {
			/* Show non-diff lines if excluding, or if
			 * in verbose mode, and if --clean isn't specified. */
			if (mode == mode_filter && (pat_exclude || verbose)
				&& !clean_comments)
				fputs (header[0], stdout);
			free (names[0]);
			goto eof;
		}
		linenum++;

		if (strncmp (line, is_context ? "--- " : "+++ ", 4)) {
			/* Show non-diff lines if excluding, or if
			 * in verbose mode, and if --clean isn't specified. */
			free (names[0]);
                        goto flush_continue;
		}

		filecount++;
		header[num_headers++] = xstrdup (line);
		names[1] = filename_from_header (line + 4);

		if (mode != mode_filter && show_status)
			new_file_exists = file_exists (names[1], line + 4 +
						       strlen (names[1]));

		// Decide whether this matches this pattern.
		p = best_name (2, names);
		p_stripped = stripped (p, ignore_components);

		match = !patlist_match(pat_exclude, p_stripped);
		if (match && pat_include != NULL)
			match = patlist_match(pat_include, p_stripped);

		// print if it matches.
		if (match && !show_status && mode == mode_list)
			display_filename (start_linenum, status,
					  p, patchname);

		if (is_context)
			do_diff = do_context;
		else
			do_diff = do_unified;

		result = do_diff (f, header, num_headers,
                                  match, &line,
				  &linelen, &linenum,
				  start_linenum, status, p, patchname,
				  &orig_file_exists, &new_file_exists);

		// print if it matches.
		if (match && show_status && mode == mode_list) {
			if (!orig_file_exists)
				status = '+';
			else if (!new_file_exists)
				status = '-';

			display_filename (start_linenum, status,
					  p, patchname);
		}

		switch (result) {
		case EOF:
			free (names[0]);
			free (names[1]);
			goto eof;
		case 1:
			goto next_diff;
		}

	next_diff:
		for (i = 0; i < 2; i++)
			free (names[i]);
                for (i = 0; i < num_headers; i++) {
			free (header[i]);
			header[i] = NULL;
		}
                num_headers = 0;
	}

 eof:
	for (i = 0; i < num_headers; i++)
		if (header[i])
			free (header[i]);

	if (line)
		free (line);

	return 0;
}