lastmsg/lastmsg.c
author Mikael Berthe <mikael@lilotux.net>
Sun, 11 Apr 2010 15:27:59 +0200
changeset 37 a05815df848c
parent 26 a15aa7a218ec
child 40 5cd4b42ada91
permissions -rw-r--r--
Update headers
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
/*
37
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     2
 *  Module "lastmsg"    -- adds a /lastmsg command
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     3
 *                         Displays last personal messages
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     4
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     5
 *  This modules stores messages received in a MUC room while
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     6
 *  you are away (or not available) if they contain your nickname.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     7
 *  When you're back, you can display them in the status window with
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     8
 *  the /lastmsg command.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
     9
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    10
 * Copyright (C) 2010 Mikael Berthe <mikael@lilotux.net>
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    11
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    12
 * This module is free software; you can redistribute it and/or modify
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    13
 * it under the terms of the GNU General Public License as published by
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    14
 * the Free Software Foundation; either version 2 of the License, or (at
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    15
 * your option) any later version.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    16
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    17
 * This program is distributed in the hope that it will be useful, but
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    18
 * WITHOUT ANY WARRANTY; without even the implied warranty of
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    20
 * General Public License for more details.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    21
 *
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    22
 * You should have received a copy of the GNU General Public License
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
a05815df848c Update headers
Mikael Berthe <mikael@lilotux.net>
parents: 26
diff changeset
    24
 */
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
#include <mcabber/modules.h>
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    27
#include <mcabber/commands.h>
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    28
#include <mcabber/hooks.h>
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    29
#include <mcabber/screen.h>
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    30
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    31
static void lastmsg_init(void);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    32
static void lastmsg_uninit(void);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    33
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    34
/* Module description */
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    35
module_info_t info_lastmsg = {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    36
        .branch         = MCABBER_BRANCH,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    37
        .api            = MCABBER_API_VERSION,
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
    38
        .version        = "0.02",
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    39
        .description    = "Add a command /lastmsg",
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    40
        .requires       = NULL,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    41
        .init           = lastmsg_init,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    42
        .uninit         = lastmsg_uninit,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    43
        .next           = NULL,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    44
};
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    45
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    46
static GSList *lastmsg_list;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    47
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
    48
static guint last_message_hid, last_status_hid;
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
    49
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    50
struct lastm_T {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    51
    gchar *mucname;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    52
    gchar *nickname;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    53
    gchar *msg;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    54
};
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    55
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    56
static void do_lastmsg(char *args)
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    57
{
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    58
  GSList *li;
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    59
  guint count = 0;
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    60
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    61
  if (!lastmsg_list) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    62
    scr_log_print(LPRINT_NORMAL, "You have no new message.");
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    63
    return;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    64
  }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    65
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
    66
  for (li = lastmsg_list; li ; li = g_slist_next(li)) {
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    67
    struct lastm_T *lastm_item = li->data;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    68
    scr_LogPrint(LPRINT_NORMAL, "In <#%s>, \"%s\" said:\n%s",
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    69
                 lastm_item->mucname, lastm_item->nickname,
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    70
                 lastm_item->msg);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    71
    g_free(lastm_item->mucname);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    72
    g_free(lastm_item->nickname);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    73
    g_free(lastm_item->msg);
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    74
    count++;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    75
  }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    76
  g_slist_free(lastmsg_list);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    77
  lastmsg_list = NULL;
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    78
  if (count*2 > scr_getlogwinheight()) {
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    79
    scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE);
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    80
    scr_setattentionflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE,
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    81
                                   ROSTER_UI_PRIO_STATUS_WIN_MESSAGE, prio_max);
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
    82
  }
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    83
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    84
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
    85
static guint last_message_hh(const gchar *hookname, hk_arg_t *args,
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
    86
                             gpointer userdata)
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    87
{
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    88
  enum imstatus status;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    89
  const gchar *bjid, *res, *msg;
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
    90
  gboolean muc = FALSE, urgent = FALSE;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    91
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    92
  status = xmpp_getstatus();
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    93
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    94
  if (status != notavail && status != away)
13
efe544108ca1 Update lastmsg module to API dev:11
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
    95
    return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    96
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    97
  bjid = res = NULL;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    98
  msg = NULL;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    99
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   100
  for ( ; args->name; args++) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   101
    if (!g_strcmp0(args->name, "jid"))
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   102
      bjid = args->value;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   103
    else if (!g_strcmp0(args->name, "resource"))
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   104
      res = args->value;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   105
    else if (!g_strcmp0(args->name, "message"))
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   106
      msg = args->value;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   107
    else if (!g_strcmp0(args->name, "groupchat")) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   108
      if (!g_strcmp0(args->value, "true"))
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   109
        muc = TRUE;
18
fb84350decc5 [lastmsg] Fix usage of hook-post-message-in parameters
Mikael Berthe <mikael@lilotux.net>
parents: 15
diff changeset
   110
    } else if (!g_strcmp0(args->name, "attention")) {
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
   111
      if (!g_strcmp0(args->value, "true"))
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
   112
        urgent = TRUE;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   113
    }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   114
  }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   115
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
   116
  if (muc && urgent && bjid && res && msg) {
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   117
    struct lastm_T *lastm_item;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   118
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   119
    lastm_item = g_new(struct lastm_T, 1);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   120
    lastm_item->mucname  = g_strdup(bjid);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   121
    lastm_item->nickname = g_strdup(res);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   122
    lastm_item->msg      = g_strdup(msg);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   123
    lastmsg_list = g_slist_append(lastmsg_list, lastm_item);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   124
  }
13
efe544108ca1 Update lastmsg module to API dev:11
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   125
  return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   126
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   127
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   128
static guint last_status_hh(const gchar *hookname, hk_arg_t *args,
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   129
                            gpointer userdata)
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   130
{
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   131
  gboolean not_away = FALSE;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   132
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   133
  for ( ; args->name; args++) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   134
    if (!g_strcmp0(args->name, "new_status")) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   135
      if (args->value &&
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   136
          (args->value[0] != imstatus2char[away]) &&
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   137
          (args->value[0] != imstatus2char[notavail])) {
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   138
        not_away = TRUE;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   139
        break;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   140
      }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   141
    }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   142
  }
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   143
  if (!not_away || !lastmsg_list)
13
efe544108ca1 Update lastmsg module to API dev:11
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   144
    return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   145
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   146
  scr_log_print(LPRINT_NORMAL, "Looks like you're back...");
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   147
  scr_log_print(LPRINT_NORMAL, "I've got news for you, use /lastmsg to "
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   148
                "read your messages!");
13
efe544108ca1 Update lastmsg module to API dev:11
Mikael Berthe <mikael@lilotux.net>
parents: 12
diff changeset
   149
  return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   150
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   151
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   152
/* Initialization */
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   153
static void lastmsg_init(void)
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   154
{
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   155
  /* Add command */
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   156
  cmd_add("lastmsg", "Display last missed messages", 0, 0, do_lastmsg, NULL);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   157
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
   158
  /* Add hook handlers */
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   159
  last_message_hid = hk_add_handler(last_message_hh, HOOK_POST_MESSAGE_IN,
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   160
                                    G_PRIORITY_DEFAULT_IDLE, NULL);
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   161
  last_status_hid  = hk_add_handler(last_status_hh, HOOK_MY_STATUS_CHANGE,
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   162
                                    G_PRIORITY_DEFAULT_IDLE, NULL);
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   163
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   164
11
573a48de8ee1 Update lastmsg module to API dev:6
Mikael Berthe <mikael@lilotux.net>
parents: 10
diff changeset
   165
/* Uninitialization */
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   166
static void lastmsg_uninit(void)
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   167
{
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   168
  GSList *li;
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   169
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   170
  /* Unregister command */
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   171
  cmd_del("lastmsg");
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
   172
  /* Unregister handlers */
12
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   173
  hk_del_handler(HOOK_POST_MESSAGE_IN, last_message_hid);
3b30c879c8cc Update lastmsg module to API dev:8
Mikael Berthe <mikael@lilotux.net>
parents: 11
diff changeset
   174
  hk_del_handler(HOOK_MY_STATUS_CHANGE, last_status_hid);
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   175
26
a15aa7a218ec [lastmsg] Add the status window message flag when /lastmsg output is long
Mikael Berthe <mikael@lilotux.net>
parents: 18
diff changeset
   176
  /* Clean up data */
15
d7cced6660a7 [lastmsg] Do not use ‘for’ loop initial declarations (C99)
Mikael Berthe <mikael@lilotux.net>
parents: 13
diff changeset
   177
  for (li = lastmsg_list; li ; li = g_slist_next(li)) {
10
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   178
    struct lastm_T *lastm_item = li->data;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   179
    g_free(lastm_item->mucname);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   180
    g_free(lastm_item->nickname);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   181
    g_free(lastm_item->msg);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   182
  }
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   183
  g_slist_free(lastmsg_list);
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   184
  lastmsg_list = NULL;
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   185
}
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   186
14f4f6dcc75a Add lastmsg module
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   187
/* vim: set expandtab cindent cinoptions=>2\:2(0:  For Vim users... */