marking.c
author Mikael Berthe <mikael@lilotux.net>
Sat, 04 Aug 2012 14:17:36 +0200
changeset 26 24ed43268d29
parent 25 39d261f589d0
child 27 b51de2faa028
permissions -rw-r--r--
Display a message when marking/unmarking a contact
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     1
1
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
     2
/*
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
     3
 * marking.c            -- Actions on multiple buddies
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
     4
 *
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
     5
 * Copyrigth (C) 2009      Myhailo Danylenko <isbear@ukrpost.net>
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
     6
 *
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
     7
 * This program is free software; you can redistribute it and/or modify
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
     8
 * it under the terms of the GNU General Public License as published by
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
     9
 * the Free Software Foundation; either version 2 of the License, or (at
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    10
 * your option) any later version.
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    11
 *
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    12
 * This program is distributed in the hope that it will be useful, but
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    15
 * General Public License for more details.
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    16
 *
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    17
 * You should have received a copy of the GNU General Public License
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    18
 * along with this program; if not, write to the Free Software
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    20
 * USA
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    21
 */
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    23
#include <glib.h>
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    24
#include <string.h>
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
2
30b66610f86a Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    26
#include <mcabber/hbuf.h>
30b66610f86a Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    27
#include <mcabber/screen.h>
30b66610f86a Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    28
#include <mcabber/commands.h>
30b66610f86a Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    29
#include <mcabber/compl.h>
30b66610f86a Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    30
#include <mcabber/utils.h>
30b66610f86a Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    31
#include <mcabber/logprint.h>
10
b84d72957c06 New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 2
diff changeset
    32
#include <mcabber/modules.h>
b84d72957c06 New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 2
diff changeset
    33
11
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    34
#include "config.h"
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    35
19
c7e7218be611 Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
    36
void marking_init   (void);
c7e7218be611 Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
    37
void marking_uninit (void);
10
b84d72957c06 New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 2
diff changeset
    38
11
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    39
#define DESCRIPTION ( "Actions on multiple marked buddies\nProvides commands /mark and /marked" )
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    40
22
cbae62eecb1d Use build-time api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 21
diff changeset
    41
module_info_t info_marking = {
cbae62eecb1d Use build-time api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 21
diff changeset
    42
	.branch      = MCABBER_BRANCH,
cbae62eecb1d Use build-time api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 21
diff changeset
    43
	.api         = MCABBER_API_VERSION,
11
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    44
	.version     = PROJECT_VERSION,
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    45
	.description = DESCRIPTION,
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    46
	.requires    = NULL,
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    47
	.init        = marking_init,
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    48
	.uninit      = marking_uninit,
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    49
	.next        = NULL,
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    50
};
f7c76b2c9900 Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    51
19
c7e7218be611 Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
    52
#ifdef MCABBER_API_HAVE_CMD_ID
15
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
    53
static gpointer mark_cmid   = NULL;
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
    54
static gpointer marked_cmid = NULL;
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
    55
#endif
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
    56
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    57
static GSList *marked_jids = NULL;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    58
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    59
// mark set jid
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    60
// mark clear jid
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    61
// mark toggle jid
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    62
static void do_mark (char *arg)
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    63
{
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
	char     **args   = split_arg (arg, 2, 1);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    65
	char      *cmd    = NULL;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    66
	char      *jid    = NULL;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    67
	gboolean   jfree  = FALSE;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    68
	int        marked = -1;
26
24ed43268d29 Display a message when marking/unmarking a contact
Mikael Berthe <mikael@lilotux.net>
parents: 25
diff changeset
    69
	guint	   len;
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    70
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    71
	if (args[0]) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    72
		cmd = args[0];
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    73
23
66455f258c64 Check user-supplied JID, change memory allocation tracking logic
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
    74
		if (args[1]) {
24
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    75
			const char *j = args[1];
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    76
			if (check_jid_syntax(j)) {
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    77
				scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    78
					     "<%s> is not a valid Jabber ID.", j);
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    79
				return;
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    80
			}
23
66455f258c64 Check user-supplied JID, change memory allocation tracking logic
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
    81
			jid = jidtodisp(j);
24
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    82
			if (!jid) {
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    83
				scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    84
					     "Unexpected error.");
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    85
				return;
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    86
			}
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    87
			jfree = TRUE;
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    88
		}
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    89
	} else
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    90
		cmd = "set";
23
66455f258c64 Check user-supplied JID, change memory allocation tracking logic
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
    91
24
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    92
	if (!jid) {
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    93
		// JID was not provided
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    94
		const char *j = NULL;
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    95
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    96
		if (current_buddy)
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    97
			j = CURRENT_JID;
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    98
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    99
		if (!j) {
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   100
			scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   101
			return;
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   102
		}
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   103
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   104
		jid = g_strdup(j);
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   105
		jfree = TRUE;
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   106
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   107
		// TODO: handle group marking :)
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   108
	}
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   109
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   110
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   111
	if (!strcmp (cmd, "set")) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   112
24
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   113
		if (!g_slist_find_custom (marked_jids, jid, (GCompareFunc) g_strcmp0)) {
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   114
			marked_jids = g_slist_append (marked_jids, jid);
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   115
			marked = 1;
23
66455f258c64 Check user-supplied JID, change memory allocation tracking logic
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   116
			jfree = FALSE;
66455f258c64 Check user-supplied JID, change memory allocation tracking logic
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   117
		}
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   118
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   119
	} else if (!strcmp (cmd, "clear")) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   120
24
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   121
		GSList *mel = g_slist_find_custom (marked_jids, jid, (GCompareFunc) g_strcmp0);
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   122
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   123
		if (mel) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   124
			g_free (mel->data);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   125
			marked_jids = g_slist_delete_link (marked_jids, mel);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   126
			marked = 0;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   127
		}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   128
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   129
	} else if (!strcmp (cmd, "toggle")) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   130
24
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   131
		GSList *mel = g_slist_find_custom (marked_jids, jid, (GCompareFunc) g_strcmp0);
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   132
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   133
		if (mel) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   134
			g_free (mel->data);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   135
			marked_jids = g_slist_delete_link (marked_jids, mel);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   136
			marked = 0;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   137
		} else {
24
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   138
			marked_jids = g_slist_append (marked_jids, jid);
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   139
			marked = 1;
23
66455f258c64 Check user-supplied JID, change memory allocation tracking logic
Mikael Berthe <mikael@lilotux.net>
parents: 22
diff changeset
   140
			jfree  = FALSE;
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   141
		}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   142
	}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   143
26
24ed43268d29 Display a message when marking/unmarking a contact
Mikael Berthe <mikael@lilotux.net>
parents: 25
diff changeset
   144
	len = g_slist_length(marked_jids);
24
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   145
	if (marked == 1) {
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   146
		scr_write_incoming_message (jid, "Marked", 0,
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   147
					    HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   148
	} else if (marked == 0) {
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   149
		scr_write_incoming_message (jid, "Mark cleared", 0,
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   150
					    HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
5254ab4a5f24 Do more checks when JID isn't explicitly specified
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
   151
	}
26
24ed43268d29 Display a message when marking/unmarking a contact
Mikael Berthe <mikael@lilotux.net>
parents: 25
diff changeset
   152
	if (marked >= 0) {
24ed43268d29 Display a message when marking/unmarking a contact
Mikael Berthe <mikael@lilotux.net>
parents: 25
diff changeset
   153
		scr_LogPrint(LPRINT_NORMAL, "<%s> is now %s (%u mark%s).", jid,
24ed43268d29 Display a message when marking/unmarking a contact
Mikael Berthe <mikael@lilotux.net>
parents: 25
diff changeset
   154
					 marked == 1 ? "marked" : "unmarked",
24ed43268d29 Display a message when marking/unmarking a contact
Mikael Berthe <mikael@lilotux.net>
parents: 25
diff changeset
   155
					 len, len > 1 ? "s" : "");
24ed43268d29 Display a message when marking/unmarking a contact
Mikael Berthe <mikael@lilotux.net>
parents: 25
diff changeset
   156
	}
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   157
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   158
	if (jfree && jid)
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   159
		g_free (jid);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   160
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   161
	free_arg_lst (args);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   162
}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   163
1
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   164
// marked clear
c8473c43ce72 Cosmetics, install help
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
   165
// marked do cmd
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   166
void do_marked (char *arg)
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   167
{
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   168
	char **args = split_arg (arg, 2, 1);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   169
	char  *cmd = args[0];
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   170
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   171
	if (!cmd)
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   172
		cmd = "list";
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   173
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   174
	if (!strcmp (cmd, "list")) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   175
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   176
		GSList *mel;
25
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   177
		guint len = g_slist_length(marked_jids);
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   178
25
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   179
		if (!marked_jids) {
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   180
			scr_log_print (LPRINT_NORMAL, "No marked JIDs.");
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   181
		} else {
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   182
			scr_log_print (LPRINT_NORMAL, "%d marked JIDs:", len);
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   183
			for (mel = marked_jids; mel; mel = mel->next) {
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   184
				char *jid = (char *) mel->data;
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   185
				scr_log_print (LPRINT_NORMAL, " * %s", jid);
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   186
			}
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   187
			// Smartly set the status flag if we have more marks than the log
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   188
			// window height.
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   189
			if (len + 1 > scr_getlogwinheight()) {
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   190
				scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE);
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   191
				scr_setattentionflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE,
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   192
							       ROSTER_UI_PRIO_STATUS_WIN_MESSAGE, prio_max);
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   193
			}
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   194
		}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   195
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   196
	} else if (!strcmp (cmd, "clear")) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   197
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   198
		GSList *mel;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   199
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   200
		for (mel = marked_jids; mel; mel = mel->next)
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   201
			g_free (mel->data);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   202
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   203
		g_slist_free (marked_jids);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   204
		marked_jids = NULL;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   205
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   206
	} else if (!strcmp (cmd, "do")) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   207
		char *format = args[1];
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   208
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   209
		if (!format)
25
39d261f589d0 Improve listing of marked JIDs
Mikael Berthe <mikael@lilotux.net>
parents: 24
diff changeset
   210
			scr_log_print (LPRINT_NORMAL, "You must specify action to do with marked JIDs");
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   211
		else {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   212
			char     *pos   = format;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   213
			gboolean  found = FALSE;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   214
			gboolean  error = FALSE;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   215
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   216
			for (pos = strchr (pos, '%'); pos; pos = strchr (pos, '%')) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   217
				if (*(pos + 1) == 's')
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   218
					found = TRUE;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   219
				else if (*(pos + 1) == '%')
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   220
					++pos;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   221
				else {
12
5ae14bc061b2 Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   222
					scr_log_print (LPRINT_NORMAL, "Action string must not contain any other %%-sequesnces!");
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   223
					error = TRUE;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   224
					break;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   225
				}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   226
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   227
				++pos;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   228
			}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   229
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   230
			if (!found)
12
5ae14bc061b2 Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   231
				scr_log_print (LPRINT_NORMAL, "Action string must contain one %%s!");
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   232
			else if (!error) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   233
				GSList *mel;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   234
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   235
				for (mel = marked_jids; mel; mel = mel->next) {
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   236
					char *jid     = (char *) mel->data;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   237
					char *command = g_strdup_printf (format, jid);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   238
					process_command (command, TRUE);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   239
					g_free (command);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   240
				}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   241
			}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   242
		}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   243
	}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   244
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   245
	free_arg_lst (args);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   246
}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   247
19
c7e7218be611 Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   248
void marking_init (void)
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   249
{
19
c7e7218be611 Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   250
#ifndef MCABBER_API_HAVE_CMD_ID
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   251
	cmd_add ("mark", "", 0, COMPL_JID, do_mark, NULL);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   252
	cmd_add ("marked", "", 0, COMPL_CMD, do_marked, NULL);
15
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   253
#else
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   254
	mark_cmid   = cmd_add ("mark", "", 0, COMPL_JID, do_mark, NULL);
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   255
	marked_cmid = cmd_add ("marked", "", 0, COMPL_CMD, do_marked, NULL);
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   256
#endif
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   257
}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   258
19
c7e7218be611 Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   259
void marking_uninit (void)
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   260
{
19
c7e7218be611 Update versions and add AVV description
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   261
#ifndef MCABBER_API_HAVE_CMD_ID
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   262
	cmd_del ("mark");
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   263
	cmd_del ("marked");
15
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   264
#else
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   265
	if (mark_cmid)
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   266
		cmd_del (mark_cmid);
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   267
	if (marked_cmid)
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   268
		cmd_del (marked_cmid);
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   269
#endif
0
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   270
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   271
	{
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   272
		GSList *mel;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   273
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   274
		for (mel = marked_jids; mel; mel = mel->next)
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   275
			g_free (mel->data);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   276
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   277
		g_slist_free (marked_jids);
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   278
		marked_jids = NULL;
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   279
	}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   280
}
aad5201e3413 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   281
15
522a4193ef2f Use id to delete commands
Myhailo Danylenko <isbear@ukrpost.net>
parents: 14
diff changeset
   282
/* vim: se ts=4 sw=4: */