mcabber/src/commands.c
author Mikael Berthe <mikael@lilotux.net>
Wed, 06 Jul 2005 22:29:17 +0100
changeset 283 00b2377539ac
parent 277 4d7040cff8ee
child 285 edc263a5d350
permissions -rw-r--r--
Add /set command (to get/set/unset options values)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     1
/*
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     2
 * commands.c     -- user commands handling
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     3
 * 
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     4
 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     5
 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     8
 * the Free Software Foundation; either version 2 of the License, or (at
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     9
 * your option) any later version.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    10
 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    14
 * General Public License for more details.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    15
 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    17
 * along with this program; if not, write to the Free Software
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    19
 * USA
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    20
 */
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    21
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    22
#include <string.h>
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    23
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    24
#include "commands.h"
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    25
#include "jabglue.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
    26
#include "roster.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    27
#include "screen.h"
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    28
#include "compl.h"
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 108
diff changeset
    29
#include "hooks.h"
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
    30
#include "hbuf.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
    31
#include "utf8.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    32
#include "utils.h"
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
    33
#include "settings.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    34
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    35
// Commands callbacks
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    36
void do_roster(char *arg);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
    37
void do_status(char *arg);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
    38
void do_add(char *arg);
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 191
diff changeset
    39
void do_del(char *arg);
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
    40
void do_group(char *arg);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
    41
void do_say(char *arg);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
    42
void do_msay(char *arg);
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
    43
void do_buffer(char *arg);
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
    44
void do_clear(char *arg);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
    45
void do_info(char *arg);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
    46
void do_rename(char *arg);
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
    47
void do_move(char *arg);
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
    48
void do_set(char *arg);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    49
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    50
// Global variable for the commands list
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    51
static GSList *Commands;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    52
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    53
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    54
//  cmd_add()
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    55
// Adds a command to the commands list and to the CMD completion list
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    56
void cmd_add(const char *name, const char *help,
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    57
        guint flags_row1, guint flags_row2, void (*f)())
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    58
{
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    59
  cmd *n_cmd = g_new0(cmd, 1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    60
  strncpy(n_cmd->name, name, 32-1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    61
  n_cmd->help = help;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    62
  n_cmd->completion_flags[0] = flags_row1;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    63
  n_cmd->completion_flags[1] = flags_row2;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    64
  n_cmd->func = f;
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
    65
  Commands = g_slist_append(Commands, n_cmd);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    66
  // Add to completion CMD category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    67
  compl_add_category_word(COMPL_CMD, name);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    68
}
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    69
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    70
//  cmd_init()
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    71
// ...
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    72
void cmd_init(void)
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    73
{
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
    74
  cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add);
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
    75
  cmd_add("buffer", "Manipulate current buddy's buffer (chat window)",
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
    76
          COMPL_BUFFER, 0, &do_buffer);
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
    77
  cmd_add("clear", "Clear the dialog window", 0, 0, &do_clear);
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 191
diff changeset
    78
  cmd_add("del", "Delete the current buddy", 0, 0, &do_del);
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
    79
  cmd_add("group", "Change group display settings", COMPL_GROUP, 0, &do_group);
262
ab6f83a82811 Do not add /help to command completion, as it isn't implemented yet.
mikael@frmp8452
parents: 260
diff changeset
    80
  //cmd_add("help", "Display some help", COMPL_CMD, 0, NULL);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
    81
  cmd_add("info", "Show basic infos on current buddy", 0, 0, &do_info);
225
d5ae42cbe1fa [/trunk] Changeset 237 by mikael
mikael
parents: 221
diff changeset
    82
  cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME,
d5ae42cbe1fa [/trunk] Changeset 237 by mikael
mikael
parents: 221
diff changeset
    83
          0, &do_move);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
    84
  cmd_add("msay", "Send a multi-lines message to the selected buddy",
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
    85
          COMPL_MULTILINE, 0, &do_msay);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    86
  //cmd_add("nick");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    87
  cmd_add("quit", "Exit the software", 0, 0, NULL);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
    88
  cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    89
  //cmd_add("request_auth");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
    90
  cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0,
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
    91
          &do_roster);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
    92
  cmd_add("say", "Say something to the selected buddy", 0, 0, &do_say);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    93
  //cmd_add("search");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    94
  //cmd_add("send_auth");
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
    95
  cmd_add("set", "Set/query an option value", 0, 0, &do_set);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
    96
  cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    97
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    98
  // Status category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    99
  compl_add_category_word(COMPL_STATUS, "online");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
   100
  compl_add_category_word(COMPL_STATUS, "avail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
   101
  compl_add_category_word(COMPL_STATUS, "invisible");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
   102
  compl_add_category_word(COMPL_STATUS, "free");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
   103
  compl_add_category_word(COMPL_STATUS, "dnd");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
   104
  compl_add_category_word(COMPL_STATUS, "notavail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
   105
  compl_add_category_word(COMPL_STATUS, "away");
103
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
   106
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
   107
  // Roster category
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
   108
  compl_add_category_word(COMPL_ROSTER, "bottom");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   109
  compl_add_category_word(COMPL_ROSTER, "top");
103
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
   110
  compl_add_category_word(COMPL_ROSTER, "hide_offline");
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
   111
  compl_add_category_word(COMPL_ROSTER, "show_offline");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   112
  compl_add_category_word(COMPL_ROSTER, "search");
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
   113
  compl_add_category_word(COMPL_ROSTER, "unread_first");
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
   114
  compl_add_category_word(COMPL_ROSTER, "unread_next");
127
0f7ec11efd06 [/trunk] Changeset 140 by mikael
mikael
parents: 124
diff changeset
   115
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   116
  // Roster category
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   117
  compl_add_category_word(COMPL_BUFFER, "bottom");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   118
  compl_add_category_word(COMPL_BUFFER, "clear");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   119
  compl_add_category_word(COMPL_BUFFER, "top");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   120
127
0f7ec11efd06 [/trunk] Changeset 140 by mikael
mikael
parents: 124
diff changeset
   121
  // Group category
240
723433a677f0 [/trunk] Changeset 253 by mikael
mikael
parents: 238
diff changeset
   122
  compl_add_category_word(COMPL_GROUP, "fold");
723433a677f0 [/trunk] Changeset 253 by mikael
mikael
parents: 238
diff changeset
   123
  compl_add_category_word(COMPL_GROUP, "unfold");
130
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   124
  compl_add_category_word(COMPL_GROUP, "toggle");
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   125
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   126
  // Multi-line (msay) category
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   127
  compl_add_category_word(COMPL_MULTILINE, "abort");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   128
  compl_add_category_word(COMPL_MULTILINE, "begin");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   129
  compl_add_category_word(COMPL_MULTILINE, "send");
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   130
  compl_add_category_word(COMPL_MULTILINE, "verbatim");
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
   131
}
94
9a4aa2797f02 [/trunk] Changeset 108 by mikael
mikael
parents: 81
diff changeset
   132
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   133
//  cmd_get
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   134
// Finds command in the command list structure.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   135
// Returns a pointer to the cmd entry, or NULL if command not found.
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   136
cmd *cmd_get(const char *command)
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   137
{
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   138
  const char *p1, *p2;
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   139
  char *com;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   140
  GSList *sl_com;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   141
  // Ignore leading '/'
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   142
  for (p1 = command ; *p1 == '/' ; p1++)
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   143
    ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   144
  // Locate the end of the command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   145
  for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   146
    ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   147
  // Copy the clean command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   148
  com = g_strndup(p1, p2-p1);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   149
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   150
  // Look for command in the list
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   151
  for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) {
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   152
    if (!strcasecmp(com, ((cmd*)sl_com->data)->name))
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   153
      break;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   154
  }
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   155
  g_free(com);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   156
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   157
  if (sl_com)       // Command has been found.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   158
    return (cmd*)sl_com->data;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   159
  return NULL;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   160
}
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   161
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   162
//  send_message(msg)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   163
// Write the message in the buddy's window and send the message on
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   164
// the network.
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   165
void send_message(const char *msg)
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   166
{
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   167
  const char *jid;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   168
      
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   169
  if (!current_buddy) {
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   170
    scr_LogPrint("No buddy currently selected.");
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   171
    return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   172
  }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   173
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   174
  jid = CURRENT_JID;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   175
  if (!jid) {
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   176
    scr_LogPrint("No buddy currently selected.");
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   177
    return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   178
  }
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   179
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 108
diff changeset
   180
  // local part (UI, logging, etc.)
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 108
diff changeset
   181
  hk_message_out(jid, 0, msg);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   182
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   183
  // Network part
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 212
diff changeset
   184
  jb_send_msg(jid, msg);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   185
}
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   186
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   187
//  process_line(line)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   188
// Process a command/message line.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   189
// If this isn't a command, this is a message and it is sent to the
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   190
// currently selected buddy.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   191
int process_line(char *line)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   192
{
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   193
  char *p;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   194
  cmd *curcmd;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   195
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   196
  if (!*line) { // User only pressed enter
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   197
    if (scr_get_multimode()) {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   198
      scr_append_multiline("");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   199
      return 0;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   200
    }
129
03be1cc94560 [/trunk] Changeset 142 by mikael
mikael
parents: 128
diff changeset
   201
    if (current_buddy) {
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   202
      scr_set_chatmode(TRUE);
129
03be1cc94560 [/trunk] Changeset 142 by mikael
mikael
parents: 128
diff changeset
   203
      buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   204
      scr_ShowBuddyWindow();
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   205
    }
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   206
    return 0;
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   207
  }
129
03be1cc94560 [/trunk] Changeset 142 by mikael
mikael
parents: 128
diff changeset
   208
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   209
  if (*line != '/') {
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   210
    // This isn't a command
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   211
    if (scr_get_multimode())
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   212
      scr_append_multiline(line);
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   213
    else
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   214
      do_say(line);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   215
    return 0;
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   216
  }
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   217
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   218
  /* It is a command */
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   219
  // Remove trailing spaces:
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   220
  for (p=line ; *p ; p++)
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   221
    ;
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   222
  for (p-- ; p>line && (*p == ' ') ; p--)
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   223
    *p = 0;
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   224
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   225
  // Command "quit"?
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   226
  if ((!strncasecmp(line, "/quit", 5)) && (scr_get_multimode() != 2) )
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   227
    if (!line[5] || line[5] == ' ')
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   228
      return 255;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   229
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   230
  // If verbatim multi-line mode, we check if another /msay command is typed
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   231
  if ((scr_get_multimode() == 2) && (strncasecmp(line, "/msay ", 6))) {
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   232
    // It isn't an /msay command
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   233
    scr_append_multiline(line);
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   234
    return 0;
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   235
  }
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   236
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   237
  // Commands handling
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   238
  curcmd = cmd_get(line);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   239
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   240
  if (!curcmd) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   241
    scr_LogPrint("Unrecognized command, sorry.");
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   242
    return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   243
  }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   244
  if (!curcmd->func) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   245
    scr_LogPrint("Not yet implemented, sorry.");
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   246
    return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   247
  }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   248
  // Lets go to the command parameters
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   249
  for (line++; *line && (*line != ' ') ; line++)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   250
    ;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   251
  // Skip spaces
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   252
  while (*line && (*line == ' '))
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   253
    line++;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   254
  // Call command-specific function
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   255
  (*curcmd->func)(line);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   256
  return 0;
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   257
}
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   258
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   259
/* Commands callback functions */
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   260
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   261
void do_roster(char *arg)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   262
{
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   263
  if (!strcasecmp(arg, "top")) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   264
    scr_RosterTop();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   265
    update_roster = TRUE;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   266
  } else if (!strcasecmp(arg, "bottom")) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   267
    scr_RosterBottom();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   268
    update_roster = TRUE;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   269
  } else if (!strcasecmp(arg, "hide_offline")) {
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 118
diff changeset
   270
    buddylist_set_hide_offline_buddies(TRUE);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   271
    if (current_buddy)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   272
      buddylist_build();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   273
    update_roster = TRUE;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   274
  } else if (!strcasecmp(arg, "show_offline")) {
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 118
diff changeset
   275
    buddylist_set_hide_offline_buddies(FALSE);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
   276
    buddylist_build();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   277
    update_roster = TRUE;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
   278
  } else if (!strcasecmp(arg, "unread_first")) {
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
   279
    scr_RosterUnreadMessage(0);
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
   280
  } else if (!strcasecmp(arg, "unread_next")) {
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
   281
    scr_RosterUnreadMessage(1);
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   282
  } else if (!strncasecmp(arg, "search", 6)) {
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   283
    char *string = arg+6;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   284
    if (*string && (*string != ' ')) {
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   285
      scr_LogPrint("Unrecognized parameter!");
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   286
      return;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   287
    }
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   288
    while (*string == ' ')
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   289
      string++;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   290
    if (!*string) {
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   291
      scr_LogPrint("What name or jid are you looking for?");
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   292
      return;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   293
    }
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   294
    scr_RosterSearch(string);
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
   295
    update_roster = TRUE;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   296
  } else
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   297
    scr_LogPrint("Unrecognized parameter!");
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   298
}
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
   299
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   300
void do_status(char *arg)
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   301
{
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   302
  enum imstatus st;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   303
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   304
  if (!arg || (*arg == 0)) {
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   305
    scr_LogPrint("Your status is: %c", imstatus2char[jb_getstatus()]);
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   306
    return;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   307
  }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   308
130
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   309
  if (!strcasecmp(arg, "offline"))        st = offline;
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   310
  else if (!strcasecmp(arg, "online"))    st = available;
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   311
  else if (!strcasecmp(arg, "avail"))     st = available;
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   312
  else if (!strcasecmp(arg, "away"))      st = away;
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   313
  else if (!strcasecmp(arg, "invisible")) st = invisible;
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   314
  else if (!strcasecmp(arg, "dnd"))       st = dontdisturb;
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   315
  else if (!strcasecmp(arg, "notavail"))  st = notavail;
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   316
  else if (!strcasecmp(arg, "free"))      st = freeforchat;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   317
  else {
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   318
    scr_LogPrint("Unrecognized parameter!");
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   319
    return;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   320
  }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   321
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   322
  // XXX special case if offline??
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   323
  jb_setstatus(st, NULL);  // TODO handle message (instead of NULL)
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   324
}
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
   325
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
   326
void do_add(char *arg)
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
   327
{
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   328
  char *id, *nick;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
   329
  if (!arg || (*arg == 0)) {
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
   330
    scr_LogPrint("Wrong usage");
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
   331
    return;
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
   332
  }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
   333
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   334
  id = g_strdup(arg);
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   335
  nick = strchr(id, ' ');
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   336
  if (nick) {
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   337
    *nick++ = 0;
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   338
    while (*nick && *nick == ' ')
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   339
      nick++;
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   340
  }
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   341
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   342
  // FIXME check id =~ jabber id
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   343
  // 2nd parameter = optional nickname
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   344
  jb_addbuddy(id, nick, NULL);
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   345
  scr_LogPrint("Sent presence notfication request to <%s>", id);
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
   346
  g_free(id);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
   347
}
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   348
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   349
void do_del(char *arg)
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   350
{
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   351
  const char *jid;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   352
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   353
  if (arg && (*arg)) {
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   354
    scr_LogPrint("Wrong usage");
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   355
    return;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   356
  }
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   357
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   358
  if (!current_buddy) return;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   359
  jid = buddy_getjid(BUDDATA(current_buddy));
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   360
  if (!jid) return;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   361
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   362
  scr_LogPrint("Removing <%s>...", jid);
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   363
  jb_delbuddy(jid);
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   364
}
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
   365
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   366
void do_group(char *arg)
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   367
{
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   368
  gpointer group;
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   369
  guint leave_windowbuddy;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   370
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   371
  if (!arg || (*arg == 0)) {
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   372
    scr_LogPrint("Missing parameter");
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   373
    return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   374
  }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   375
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   376
  if (!current_buddy) return;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   377
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   378
  group = buddy_getgroup(BUDDATA(current_buddy));
212
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
   379
  // We'll have to redraw the chat window if we're not currently on the group
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
   380
  // entry itself, because it means we'll have to leave the current buddy
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
   381
  // chat window.
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   382
  leave_windowbuddy = (group != BUDDATA(current_buddy));
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   383
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   384
  if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) {
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   385
    scr_LogPrint("You need to select a group");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   386
    return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   387
  }
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   388
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   389
  if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) {
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   390
    buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE);
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   391
  } else if (!strcasecmp(arg, "shrink") || !strcasecmp(arg, "fold")) {
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   392
    buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE);
130
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   393
  } else if (!strcasecmp(arg, "toggle")) {
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   394
    buddy_setflags(group, ROSTER_FLAG_HIDE,
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
   395
            !(buddy_getflags(group) & ROSTER_FLAG_HIDE));
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   396
  } else {
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   397
    scr_LogPrint("Unrecognized parameter!");
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   398
    return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   399
  }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   400
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   401
  buddylist_build();
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   402
  update_roster = TRUE;
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
   403
  if (leave_windowbuddy) scr_ShowBuddyWindow();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   404
}
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
   405
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   406
void do_say(char *arg)
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   407
{
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   408
  gpointer bud;
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   409
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   410
  scr_set_chatmode(TRUE);
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   411
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   412
  if (!current_buddy) {
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   413
    scr_LogPrint("Who are you talking to??");
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   414
    return;
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   415
  }
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   416
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   417
  bud = BUDDATA(current_buddy);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   418
  if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) {
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   419
    scr_LogPrint("This is not a user");
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   420
    return;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   421
  }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   422
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   423
  buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
   424
  send_message(arg);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   425
}
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
   426
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   427
void do_msay(char *arg)
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   428
{
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   429
  /* Parameters: begin verbatim abort send */
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   430
  gpointer bud;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   431
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   432
  if (!strcasecmp(arg, "abort")) {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   433
    scr_set_multimode(FALSE);
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   434
    return;
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   435
  } else if ((!strcasecmp(arg, "begin")) || (!strcasecmp(arg, "verbatim"))) {
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   436
    if (!strcasecmp(arg, "verbatim"))
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   437
      scr_set_multimode(2);
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   438
    else
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   439
      scr_set_multimode(1);
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
   440
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   441
    scr_LogPrint("Entered multi-line message mode.");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   442
    scr_LogPrint("Select a buddy and use \"/msay send\" "
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   443
                 "when your message is ready.");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   444
    return;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   445
  } else if (*arg == 0) {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   446
    scr_LogPrint("Please read the manual before using the /msay command.");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   447
    scr_LogPrint("(Use /msay begin to enter multi-line mode...)");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   448
    return;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   449
  } else if (strcasecmp(arg, "send")) {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   450
    scr_LogPrint("Unrecognized parameter!");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   451
    return;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   452
  }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   453
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   454
  // send command
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   455
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   456
  if (!scr_get_multimode()) {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   457
    scr_LogPrint("No message to send.  Use \"/msay begin\" first.");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   458
    return;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   459
  }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   460
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   461
  scr_set_chatmode(TRUE);
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   462
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   463
  if (!current_buddy) {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   464
    scr_LogPrint("Who are you talking to??");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   465
    return;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   466
  }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   467
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   468
  bud = BUDDATA(current_buddy);
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   469
  if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   470
    scr_LogPrint("This is not a user");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   471
    return;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   472
  }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   473
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   474
  buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   475
  send_message(scr_get_multiline());
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   476
  scr_set_multimode(FALSE);
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   477
}
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
   478
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   479
void do_buffer(char *arg)
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   480
{
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   481
  if (!strcasecmp(arg, "top")) {
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   482
    scr_BufferTop();
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   483
  } else if (!strcasecmp(arg, "bottom")) {
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   484
    scr_BufferBottom();
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   485
  } else if (!strcasecmp(arg, "clear")) {
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   486
    scr_Clear();
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   487
  } else
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   488
    scr_LogPrint("Unrecognized parameter!");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   489
}
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   490
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   491
void do_clear(char *arg)    // Alias for "/buffer clear"
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   492
{
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   493
  do_buffer("clear");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   494
}
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
   495
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   496
void do_info(char *arg)
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   497
{
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   498
  gpointer bud;
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
   499
  const char *jid, *name, *st_msg;
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   500
  guint type;
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   501
  enum imstatus status;
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   502
  char *buffer;
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   503
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   504
  if (!current_buddy) return;
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   505
  bud = BUDDATA(current_buddy);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   506
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   507
  jid    = buddy_getjid(bud);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   508
  name   = buddy_getname(bud);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   509
  type   = buddy_gettype(bud);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   510
  status = buddy_getstatus(bud);
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
   511
  st_msg = buddy_getstatusmsg(bud);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   512
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   513
  buffer = g_new(char, 128);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   514
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   515
  if (jid) {
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   516
    char *typestr = "unknown";
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   517
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   518
    snprintf(buffer, 127, "jid:  <%s>", jid);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   519
    scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   520
    if (name) {
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   521
      snprintf(buffer, 127, "Name: %s", name);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   522
      scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   523
    }
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
   524
    if (st_msg) {
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
   525
      snprintf(buffer, 127, "Status message: %s", st_msg);
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
   526
      scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
   527
    }
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   528
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   529
    if (type == ROSTER_TYPE_USER) typestr = "user";
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   530
    else if (type == ROSTER_TYPE_AGENT) typestr = "agent";
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   531
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   532
    snprintf(buffer, 127, "Type: %s", typestr);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   533
    scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   534
  } else {
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   535
    if (name) scr_LogPrint("Name: %s", name);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   536
    scr_LogPrint("Type: %s",
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   537
            ((type == ROSTER_TYPE_GROUP) ? "group" : "unknown"));
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   538
  }
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   539
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   540
  g_free(buffer);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   541
}
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
   542
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   543
void do_rename(char *arg)
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   544
{
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   545
  gpointer bud;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   546
  const char *jid, *group;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   547
  guint type;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   548
  char *newname, *p;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   549
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   550
  if (!arg || (*arg == 0)) {
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   551
    scr_LogPrint("Missing parameter");
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   552
    return;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   553
  }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   554
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   555
  if (!current_buddy) return;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   556
  bud = BUDDATA(current_buddy);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   557
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   558
  jid   = buddy_getjid(bud);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   559
  group = buddy_getgroupname(bud);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   560
  type  = buddy_gettype(bud);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   561
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   562
  if (type & ROSTER_TYPE_GROUP) {
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   563
    scr_LogPrint("You can't rename groups");
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   564
    return;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   565
  }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   566
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   567
  newname = g_strdup(arg);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   568
  // Remove trailing space
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   569
  for (p = newname; *p; p++) ;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   570
  while (p > newname && *p == ' ') *p = 0;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   571
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   572
  buddy_setname(bud, newname);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   573
  jb_updatebuddy(jid, newname, group);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   574
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   575
  g_free(newname);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   576
  update_roster = TRUE;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   577
}
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
   578
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   579
void do_move(char *arg)
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   580
{
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   581
  gpointer bud;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   582
  const char *jid, *name;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   583
  guint type;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   584
  char *newgroupname, *p;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   585
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   586
  if (!current_buddy) return;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   587
  bud = BUDDATA(current_buddy);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   588
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   589
  jid  = buddy_getjid(bud);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   590
  name = buddy_getname(bud);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   591
  type = buddy_gettype(bud);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   592
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   593
  if (type & ROSTER_TYPE_GROUP) {
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   594
    scr_LogPrint("You can't move groups!");
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   595
    return;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   596
  }
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   597
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   598
  newgroupname = g_strdup(arg);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   599
  // Remove trailing space
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   600
  for (p = newgroupname; *p; p++) ;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   601
  while (p > newgroupname && *p == ' ') *p = 0;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   602
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   603
  // Call to buddy_setgroup() should be at the end, as current implementation
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   604
  // clones the buddy and deletes the old one (and thus, jid and name are
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   605
  // freed)
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   606
  jb_updatebuddy(jid, name, newgroupname);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   607
  buddy_setgroup(bud, newgroupname);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   608
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   609
  g_free(newgroupname);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   610
  update_roster = TRUE;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   611
}
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
   612
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   613
void do_set(char *arg)
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   614
{
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   615
  guint assign;
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   616
  const gchar *option, *value;
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   617
  
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   618
  assign = parse_assigment(arg, &option, &value);
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   619
  if (!option) {
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   620
    scr_LogPrint("Huh?");
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   621
    return;
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   622
  }
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   623
  if (!assign) {
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   624
    // This is a query
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   625
    value = settings_opt_get(option);
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   626
    if (value) {
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   627
      scr_LogPrint("%s = [%s]", option, value);
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   628
    } else
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   629
      scr_LogPrint("Option %s is not set", option);
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   630
    return;
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   631
  }
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   632
  // Update the option
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   633
  // XXX Maybe some options should be protected when user is connected
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   634
  // (server, username, etc.).  And we should catch some options here, too
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   635
  // (hide_offline_buddies for ex.)
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   636
  if (!value) {
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   637
    settings_del(SETTINGS_TYPE_OPTION, option);
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   638
  } else {
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   639
    settings_set(SETTINGS_TYPE_OPTION, option, value);
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   640
  }
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   641
}
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
   642