5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 #include "silcerapp.hh"
21 #include "silcerchatview.hh"
22 #include "SilcerMainDlg.hh"
25 #include <libgnomeui/gnome-window-icon.h>
26 #include <libgnome/gnome-help.h>
27 #include <gtk--/style.h>
28 #include <gnome--/href.h>
29 #include <gtk--/text.h>
30 #include <gtk--/toolbar.h>
31 #include <gtk--/notebook.h>
33 static char *parse_command(const char *buffer)
36 char *cp = (char *)buffer;
39 len = strcspn((const char *)cp, " ");
40 ret = silc_to_upper(cp + 1);
45 SilcerMainDlg::SilcerMainDlg(void) : SilcerBaseDialog("SilcerMainDlg")
47 _thisWindow->realize();
49 // Get intput box and set it for input
50 _InputBox = getWidget<Gtk::Text>("SilcerMainDlgInputBox");
51 _InputBox->key_press_event.connect(slot(this,
52 &SilcerMainDlg::InputBoxKeyPress));
53 _Completer = g_completion_new(NULL);
55 // Get output box and create new chat view box
56 _OutputBox = getWidget<Gtk::HBox>("SilcerMainDlgOutputBox");
57 _ChatView = new SilcerChatView(_thisWindow, _OutputBox, false);
59 // Show only icons on toolbar
60 getWidget<Gtk::Toolbar>("SilcerMainDlgToolbar")->
61 set_style(GTK_TOOLBAR_ICONS);
63 // Hide tabs, since they are not used currently!
64 getWidget<Gtk::Notebook>("SilcerMainDlgTab")->set_show_tabs(false);
69 SilcerMainDlg::~SilcerMainDlg(void)
74 void SilcerMainDlg::print(const string message)
76 _ChatView->render(message, "", "", BLUE);
79 void SilcerMainDlg::print(const string message, const string nickname)
81 _ChatView->render(message, nickname, "", BLUE2);
84 gint SilcerMainDlg::InputBoxKeyPress(GdkEventKey *key)
88 switch (key->keyval) {
90 if (gtkspell_running())
91 gtkspell_check_all(_InputBox->gtkobj());
96 if (key->state & GDK_SHIFT_MASK) {
97 key->state ^= GDK_SHIFT_MASK;
101 // Parse message to see whether it is command
102 msg = _InputBox->get_chars(0, -1);
104 _InputBox->delete_text(0, -1);
105 gtk_signal_emit_stop_by_name(GTK_OBJECT(_InputBox->gtkobj()),
110 if (msg.at(0) == '/') {
112 SilcClientCommand cmd;
113 SilcClientCommandContext ctx;
116 unsigned char **argv;
117 uint32 *argv_lens, *argv_types;
120 tmpcmd = parse_command(msg.c_str());
121 cmd = silc_client_command_find(silc_client, (const char *)tmpcmd);
126 silc_parse_command_line((unsigned char *)msg.c_str(), &argv, &argv_lens,
127 &argv_types, &argc, cmd->max_args);
129 ctx = silc_client_command_alloc();
130 ctx->client = silc_client;
131 ctx->conn = silc_client_conn;
135 ctx->argv_lens = argv_lens;
136 ctx->argv_types = argv_types;
138 // Execute the command
139 silc_client_command_call(cmd, ctx);
142 if (silc_client_conn->current_channel) {
144 silc_client_send_channel_message(silc_client,
146 silc_client_conn->current_channel,
148 0, (unsigned char *)msg.c_str(),
153 _InputBox->delete_text(0, -1);
154 gtk_signal_emit_stop_by_name(GTK_OBJECT(_InputBox->gtkobj()),
161 msg = _InputBox->get_chars(0, -1);
166 // Search for the last whitespace
167 string::size_type n = msg.find_last_of(" ");
168 if (n != string::npos)
169 lastword = msg.substr(n+1);
173 // Try and autocomplete
175 g_completion_complete(_Completer, (char*)lastword.c_str(), &prefix);
177 // Replace the last word in the message and update
178 if (n != string::npos)
179 msg.replace(msg.find_last_of(" ")+1, msg.length(), prefix);
181 msg = string(prefix);
185 _InputBox->delete_text(0, -1);
186 _InputBox->insert(msg);
189 gtk_signal_emit_stop_by_name(GTK_OBJECT(_InputBox->gtkobj()),