From 40ffeb9e0c78b2d809ed172fed455528b7427de6 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 22 Apr 2006 21:18:02 +0000 Subject: [PATCH] Splited GUI sources --- po/POTFILES.in | 22 +- po/cs.po | 136 +-- po/de.po | 136 +-- po/es.po | 136 +-- po/fr.po | 136 +-- po/hu.po | 136 +-- po/weechat.pot | 136 +-- src/common/command.c | 18 +- src/common/completion.c | 2 +- src/common/session.c | 8 +- src/common/weechat.c | 8 +- src/common/weeconfig.c | 32 +- src/gui/Makefile.am | 4 +- src/gui/curses/Makefile.am | 18 +- src/gui/curses/gui-chat.c | 1098 +++++++++++++++++++ src/gui/curses/gui-color.c | 607 +++++++++++ src/gui/curses/gui-curses.h | 57 + src/gui/curses/gui-infobar.c | 137 +++ src/gui/curses/gui-input.c | 793 ++++++-------- src/gui/curses/gui-keyboard.c | 324 ++++++ src/gui/curses/gui-main.c | 355 +++++++ src/gui/curses/gui-nicklist.c | 236 +++++ src/gui/curses/gui-status.c | 402 +++++++ src/gui/curses/gui-window.c | 1175 ++++++++++++++++++++ src/gui/gtk/Makefile.am | 18 +- src/gui/gtk/gui-chat.c | 633 +++++++++++ src/gui/gtk/gui-color.c | 580 ++++++++++ src/gui/gtk/gui-gtk.h | 81 ++ src/gui/gtk/gui-infobar.c | 81 ++ src/gui/gtk/gui-input.c | 265 +++-- src/gui/gtk/gui-keyboard.c | 173 +++ src/gui/gtk/gui-main.c | 218 ++++ src/gui/gtk/gui-nicklist.c | 54 + src/gui/gtk/gui-status.c | 61 ++ src/gui/gtk/gui-window.c | 847 +++++++++++++++ src/gui/gui-action.c | 98 +- src/gui/gui-buffer.c | 932 ++++++++++++++++ src/gui/gui-common.c | 1296 +---------------------- src/gui/gui-keyboard.c | 2 +- src/gui/gui-window.c | 424 ++++++++ src/gui/gui.h | 115 +- src/irc/irc-channel.c | 4 +- src/irc/irc-dcc.c | 8 +- src/irc/irc-nick.c | 2 +- src/irc/irc-recv.c | 72 +- src/irc/irc-send.c | 18 +- src/irc/irc-server.c | 4 +- src/plugins/plugins-interface.c | 6 +- weechat/po/POTFILES.in | 22 +- weechat/po/cs.po | 136 +-- weechat/po/de.po | 136 +-- weechat/po/es.po | 136 +-- weechat/po/fr.po | 136 +-- weechat/po/hu.po | 136 +-- weechat/po/weechat.pot | 136 +-- weechat/src/common/command.c | 18 +- weechat/src/common/completion.c | 2 +- weechat/src/common/session.c | 8 +- weechat/src/common/weechat.c | 8 +- weechat/src/common/weeconfig.c | 32 +- weechat/src/gui/Makefile.am | 4 +- weechat/src/gui/curses/Makefile.am | 18 +- weechat/src/gui/curses/gui-chat.c | 1098 +++++++++++++++++++ weechat/src/gui/curses/gui-color.c | 607 +++++++++++ weechat/src/gui/curses/gui-curses.h | 57 + weechat/src/gui/curses/gui-infobar.c | 137 +++ weechat/src/gui/curses/gui-input.c | 793 ++++++-------- weechat/src/gui/curses/gui-keyboard.c | 324 ++++++ weechat/src/gui/curses/gui-main.c | 355 +++++++ weechat/src/gui/curses/gui-nicklist.c | 236 +++++ weechat/src/gui/curses/gui-status.c | 402 +++++++ weechat/src/gui/curses/gui-window.c | 1175 ++++++++++++++++++++ weechat/src/gui/gtk/Makefile.am | 18 +- weechat/src/gui/gtk/gui-chat.c | 633 +++++++++++ weechat/src/gui/gtk/gui-color.c | 580 ++++++++++ weechat/src/gui/gtk/gui-gtk.h | 81 ++ weechat/src/gui/gtk/gui-infobar.c | 81 ++ weechat/src/gui/gtk/gui-input.c | 265 +++-- weechat/src/gui/gtk/gui-keyboard.c | 173 +++ weechat/src/gui/gtk/gui-main.c | 218 ++++ weechat/src/gui/gtk/gui-nicklist.c | 54 + weechat/src/gui/gtk/gui-status.c | 61 ++ weechat/src/gui/gtk/gui-window.c | 847 +++++++++++++++ weechat/src/gui/gui-action.c | 98 +- weechat/src/gui/gui-buffer.c | 932 ++++++++++++++++ weechat/src/gui/gui-common.c | 1296 +---------------------- weechat/src/gui/gui-keyboard.c | 2 +- weechat/src/gui/gui-window.c | 424 ++++++++ weechat/src/gui/gui.h | 115 +- weechat/src/irc/irc-channel.c | 4 +- weechat/src/irc/irc-dcc.c | 8 +- weechat/src/irc/irc-nick.c | 2 +- weechat/src/irc/irc-recv.c | 72 +- weechat/src/irc/irc-send.c | 18 +- weechat/src/irc/irc-server.c | 4 +- weechat/src/plugins/plugins-interface.c | 6 +- 96 files changed, 19252 insertions(+), 4956 deletions(-) create mode 100644 src/gui/curses/gui-chat.c create mode 100644 src/gui/curses/gui-color.c create mode 100644 src/gui/curses/gui-curses.h create mode 100644 src/gui/curses/gui-infobar.c create mode 100644 src/gui/curses/gui-keyboard.c create mode 100644 src/gui/curses/gui-main.c create mode 100644 src/gui/curses/gui-nicklist.c create mode 100644 src/gui/curses/gui-status.c create mode 100644 src/gui/curses/gui-window.c create mode 100644 src/gui/gtk/gui-chat.c create mode 100644 src/gui/gtk/gui-color.c create mode 100644 src/gui/gtk/gui-gtk.h create mode 100644 src/gui/gtk/gui-infobar.c create mode 100644 src/gui/gtk/gui-keyboard.c create mode 100644 src/gui/gtk/gui-main.c create mode 100644 src/gui/gtk/gui-nicklist.c create mode 100644 src/gui/gtk/gui-status.c create mode 100644 src/gui/gtk/gui-window.c create mode 100644 src/gui/gui-buffer.c create mode 100644 src/gui/gui-window.c create mode 100644 weechat/src/gui/curses/gui-chat.c create mode 100644 weechat/src/gui/curses/gui-color.c create mode 100644 weechat/src/gui/curses/gui-curses.h create mode 100644 weechat/src/gui/curses/gui-infobar.c create mode 100644 weechat/src/gui/curses/gui-keyboard.c create mode 100644 weechat/src/gui/curses/gui-main.c create mode 100644 weechat/src/gui/curses/gui-nicklist.c create mode 100644 weechat/src/gui/curses/gui-status.c create mode 100644 weechat/src/gui/curses/gui-window.c create mode 100644 weechat/src/gui/gtk/gui-chat.c create mode 100644 weechat/src/gui/gtk/gui-color.c create mode 100644 weechat/src/gui/gtk/gui-gtk.h create mode 100644 weechat/src/gui/gtk/gui-infobar.c create mode 100644 weechat/src/gui/gtk/gui-keyboard.c create mode 100644 weechat/src/gui/gtk/gui-main.c create mode 100644 weechat/src/gui/gtk/gui-nicklist.c create mode 100644 weechat/src/gui/gtk/gui-status.c create mode 100644 weechat/src/gui/gtk/gui-window.c create mode 100644 weechat/src/gui/gui-buffer.c create mode 100644 weechat/src/gui/gui-window.c diff --git a/po/POTFILES.in b/po/POTFILES.in index aab77a7ca..3639a29cc 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -14,13 +14,31 @@ ./src/plugins/plugins-config.h ./src/plugins/plugins-interface.c ./src/plugins/weechat-plugin.h +./src/gui/curses/gui-chat.c +./src/gui/curses/gui-color.c +./src/gui/curses/gui-infobar.c ./src/gui/curses/gui-input.c -./src/gui/curses/gui-display.c -./src/gui/gtk/gui-display.c +./src/gui/curses/gui-keyboard.c +./src/gui/curses/gui-main.c +./src/gui/curses/gui-nicklist.c +./src/gui/curses/gui-status.c +./src/gui/curses/gui-window.c +./src/gui/curses/gui-curses.h +./src/gui/gtk/gui-chat.c +./src/gui/gtk/gui-color.c +./src/gui/gtk/gui-infobar.c ./src/gui/gtk/gui-input.c +./src/gui/gtk/gui-keyboard.c +./src/gui/gtk/gui-main.c +./src/gui/gtk/gui-nicklist.c +./src/gui/gtk/gui-status.c +./src/gui/gtk/gui-window.c +./src/gui/gtk/gui-gtk.h ./src/gui/gui-action.c +./src/gui/gui-buffer.c ./src/gui/gui-common.c ./src/gui/gui-keyboard.c +./src/gui/gui-window.c ./src/gui/gui.h ./src/common/command.c ./src/common/command.h diff --git a/po/cs.po b/po/cs.po index 767c41c0c..7352e3c90 100644 --- a/po/cs.po +++ b/po/cs.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:53+0200\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -1351,38 +1351,38 @@ msgstr "nemůžu změnit mód přo ostatní uživatele" msgid "whois (secure connection)" msgstr "whois (zabezpečená část)" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%sServer: %s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "připojen" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "nepřipojen" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "na" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "off" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (dočasný server, nebude uložen)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "sekund" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(skrytý)" @@ -2365,102 +2365,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "%s server/kanál (%s/%s) nenaleyen pro exec příkaz pluginu\n" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "bajtů" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "Kb" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "Mb" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "Gb" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "ETA" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] Akceptovat" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] Storno" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] Odebrat" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] Pročistit staré DCC" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] Zavřít DCC pohled" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr " [Q] Zavřít čistý pohled na data" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "Změnil se den na %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s zpoždění je veliké, odpojuji se od serveru...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "bajtů" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "Kb" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "Mb" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "Gb" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "ETA" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(pryč)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[nepřipojen] " -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr "<ČISTÉ_IRC> " -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Aktivní: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "ČISTÉ_IRC" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Zpoždění: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-VÍCE-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] Akceptovat" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] Storno" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] Odebrat" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] Pročistit staré DCC" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] Zavřít DCC pohled" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr " [Q] Zavřít čistý pohled na data" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "server" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "Nedostatek paměti pro nový řádek\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "Nedostatek paměti pro infobar zprávu\n" diff --git a/po/de.po b/po/de.po index b230b8066..6c31a19aa 100644 --- a/po/de.po +++ b/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:53+0200\n" "Last-Translator: Thomas Schütz \n" "Language-Team: weechat-dev \n" @@ -1348,38 +1348,38 @@ msgstr "Modes anderer User können nicht geändert werden" msgid "whois (secure connection)" msgstr "whois (sichere Verbindung)" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%sServer: %s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "verbunden" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "nicht verbunden" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "an" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "aus" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (temporärer Server, wird nicht gespeichert)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "Sekunden" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(versteckt)" @@ -2356,102 +2356,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "%s Server/Channel (%s/%s) für den Plugin-Exec-Befehl nicht gefunden\n" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "Bytes" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "KB" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "MB" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "GB" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "ETA" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] annehmen" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] abbrechen" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] entfernen" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] alte DCCs entfernen" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] DCC-Ansicht schließen" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr " [Q] Rohdatenansicht schließen" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "Ein neuer Tag bricht hat, heute ist der %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s der Lag ist hoch, die Verbindung wird getrennt...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "Bytes" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "KB" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "MB" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "GB" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "ETA" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(abwesend)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[nicht verbunden]" -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr " " -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Aktiv: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "RAW_IRC" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Lag: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-MEHR-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] annehmen" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] abbrechen" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] entfernen" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] alte DCCs entfernen" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] DCC-Ansicht schließen" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr " [Q] Rohdatenansicht schließen" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "Server" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "Nicht genügend Speicher für neue Zeile\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "Nicht genügend Speicher für Infobar-Nachricht\n" diff --git a/po/es.po b/po/es.po index 1aa744368..3e7719175 100644 --- a/po/es.po +++ b/po/es.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:53+0200\n" "Last-Translator: Roberto Gonzlez Cardenete \n" "Language-Team: weechat-dev \n" @@ -1366,38 +1366,38 @@ msgstr "no es posible cambiar el modo para el resto de usuarios" msgid "whois (secure connection)" msgstr "quin es (conexin segura)" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%sServidor:%s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "conectado" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "no conectado" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "activo" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "inactivo" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (servidor temporal, no ser guardado)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "segundos" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(oculto)" @@ -2400,102 +2400,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "bytes" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "KB" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "MB" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "GB" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "Tiempo estimado de llegada" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] Aceptar" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] Cancelar" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] Eliminar" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] Purgar los viejos DCC" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] Cerrar la vista DCC" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr "" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "Da cambiado a %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s el lag (retraso) es alto, desconectando del servidor...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "bytes" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "KB" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "MB" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "GB" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "Tiempo estimado de llegada" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(ausente)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[no conectado] " -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr "" -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Act: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Lag: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-MS-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] Aceptar" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] Cancelar" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] Eliminar" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] Purgar los viejos DCC" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] Cerrar la vista DCC" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr "" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "servidor" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "No hay suficiente memoria para una nueva lnea\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "No hay suficiente memoria para el mensaje de la barra de informacin\n" diff --git a/po/fr.po b/po/fr.po index 2fb0ace0d..b8f6d6750 100644 --- a/po/fr.po +++ b/po/fr.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:53+0200\n" "Last-Translator: FlashCode \n" "Language-Team: weechat-dev \n" @@ -1357,38 +1357,38 @@ msgstr "impossible de changer le mode pour les autres utilisateurs" msgid "whois (secure connection)" msgstr "qui est (connexion scurise)" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%sServeur: %s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "connect" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "non connect" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "activ" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "dsactiv" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (serveur temporaire, ne sera pas sauv)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "secondes" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(cach)" @@ -2375,102 +2375,102 @@ msgstr "" "%s serveur/canal (%s/%s) non trouv pour l'excution de commande de " "l'extension\n" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "octets" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "Ko" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "Mo" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "Go" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "ETA" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] Accepter" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] Annuler" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] Retirer" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] Purger anciens DCC" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] Fermer la vue DCC" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr " [Q] Fermer la vue IRC brut" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "Jour chang: %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s le lag est lev, dconnexion du serveur...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "octets" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "Ko" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "Mo" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "Go" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "ETA" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(absent)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[non connect] " -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr " " -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Act: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "IRC_BRUT" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Lag: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-PLUS-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] Accepter" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] Annuler" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] Retirer" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] Purger anciens DCC" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] Fermer la vue DCC" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr " [Q] Fermer la vue IRC brut" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "serveur" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "Pas assez de mmoire pour une nouvelle ligne !\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "Pas assez de mmoire pour un message de la barre d'infos\n" diff --git a/po/hu.po b/po/hu.po index 23814d4fa..7ee8d8358 100644 --- a/po/hu.po +++ b/po/hu.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:55+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -1367,38 +1367,38 @@ msgstr "más felhasználók üzemmódját nem módosíthatja" msgid "whois (secure connection)" msgstr "" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%s Szerver: %s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "csatlakozva" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "nincs csatlakozva" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "be" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "ki" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (átmeneti szerver, nem lesz mentve)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "másodperc" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(rejtett)" @@ -2354,102 +2354,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "%s (%s/%s) szerver/szoba nem található a modul futtatása parancshoz\n" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "byte" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "Kb" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "Mb" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "Gb" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] Elfogadás" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] Mégsem" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] Eltávolítás" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] Régi DCC törlése" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] DCC nézet bezárása" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr " [Q] Nyers adat nézet bezárása" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "A mai dátum: %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s túl nagy a késés(lag), lecsatlakozás a szerverről...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "byte" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "Kb" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "Mb" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "Gb" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(távol)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[nincs csatlakozva]" -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr " " -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Akt: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Lag: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-TOVÁBB-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] Elfogadás" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] Mégsem" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] Eltávolítás" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] Régi DCC törlése" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] DCC nézet bezárása" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr " [Q] Nyers adat nézet bezárása" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "szerver" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "Nincs elég memória az új sorhoz\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "Nincs elég memória az információs pult üzenethez\n" diff --git a/po/weechat.pot b/po/weechat.pot index dd8589468..5750c0846 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1247,38 +1247,38 @@ msgstr "" msgid "whois (secure connection)" msgstr "" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr "" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "" @@ -2209,102 +2209,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr "" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr "" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr "" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr "" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr "" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr "" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "" -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr "" -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "" -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr "" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr "" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr "" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr "" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr "" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr "" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "" diff --git a/src/common/command.c b/src/common/command.c index 5d3d47d54..86d729fbe 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -1381,8 +1381,8 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, ptr_channel = CHANNEL(buffer); gui_buffer_free (ptr_channel->buffer, 1); channel_free (SERVER(buffer), ptr_channel); - gui_draw_buffer_status (buffer, 1); - gui_draw_buffer_input (buffer, 1); + gui_status_draw (buffer, 1); + gui_input_draw (buffer, 1); } else { @@ -1414,7 +1414,7 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, gui_buffer_free (buffer, 1); } } - gui_draw_buffer_status (buffer, 1); + gui_status_draw (buffer, 1); } else if (ascii_strcasecmp (argv[0], "notify") == 0) { @@ -1563,8 +1563,8 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, } if (ptr_buffer) { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (ptr_buffer); + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (ptr_buffer); } } } @@ -2093,7 +2093,7 @@ weechat_cmd_disconnect (t_irc_server *server, t_irc_channel *channel, _("Auto-reconnection is cancelled\n")); } server_disconnect (ptr_server, 0); - gui_draw_buffer_status (buffer, 1); + gui_status_draw (buffer, 1); } else { @@ -2879,7 +2879,7 @@ weechat_cmd_server (t_irc_server *server, t_irc_channel *channel, if (server_name) free (server_name); - gui_redraw_buffer (buffer); + gui_window_redraw_buffer (buffer); return 0; } @@ -3088,7 +3088,7 @@ weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *val option->array_values[*((int *)value)]); break; case OPTION_TYPE_COLOR: - color_name = gui_get_color_name (*((int *)value)); + color_name = gui_color_get_name (*((int *)value)); gui_printf (NULL, "%s%s\n", GUI_COLOR(COLOR_WIN_CHAT_HOST), (color_name) ? color_name : _("(unknown)")); @@ -3798,7 +3798,7 @@ weechat_cmd_upgrade (t_irc_server *server, t_irc_channel *channel, plugin_end (); #endif (void) config_write (NULL); - gui_end (); + gui_main_end (); fifo_remove (); if (weechat_log_file) fclose (weechat_log_file); diff --git a/src/common/completion.c b/src/common/completion.c index c0fe8401d..3d25b1e46 100644 --- a/src/common/completion.c +++ b/src/common/completion.c @@ -644,7 +644,7 @@ completion_list_add_option_value (t_completion *completion) weelist_add (&completion->completion_list, &completion->last_completion, (option_value) ? - gui_get_color_name (*((int *)(option_value))) : + gui_color_get_name (*((int *)(option_value))) : option->default_string); break; case OPTION_TYPE_STRING: diff --git a/src/common/session.c b/src/common/session.c index 86ace569f..f73e3c110 100644 --- a/src/common/session.c +++ b/src/common/session.c @@ -472,7 +472,7 @@ session_crash (FILE *file, char *message, ...) va_end (argptr); fclose (file); - gui_end (); + gui_main_end (); fprintf (stderr, "%s %s\n", WEECHAT_ERROR, buffer); fprintf (stderr, @@ -1464,7 +1464,7 @@ session_load_line (FILE *file) } /* allocate line */ - line = gui_line_new (session_current_buffer); + line = gui_buffer_line_new (session_current_buffer); if (!line) { session_crash (file, _("can't create new line")); @@ -1685,8 +1685,8 @@ session_load (char *filename) ptr_server->buffer = gui_buffers; } - gui_switch_to_buffer (gui_windows, gui_buffers); - gui_redraw_buffer (gui_current_window->buffer); + gui_window_switch_to_buffer (gui_windows, gui_buffers); + gui_window_redraw_buffer (gui_current_window->buffer); fclose (file); diff --git a/src/common/weechat.c b/src/common/weechat.c index 6c9392c9e..5963d89bf 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -1062,7 +1062,7 @@ weechat_sigsegv () weechat_dump (1); dcc_end (); server_free_all (); - gui_end (); + gui_main_end (); fprintf (stderr, "\n"); fprintf (stderr, "*** Very bad! WeeChat has crashed (SIGSEGV received)\n"); fprintf (stderr, "*** Full crash dump was saved to %s/weechat.log file\n", weechat_home); @@ -1093,7 +1093,7 @@ main (int argc, char *argv[]) signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal */ signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal */ signal (SIGSEGV, weechat_sigsegv); /* crash dump when SIGSEGV received */ - gui_pre_init (&argc, &argv); /* pre-initiliaze interface */ + gui_main_pre_init (&argc, &argv); /* pre-initiliaze interface */ weechat_init_vars (); /* initialize some variables */ gui_key_init (); /* init keyb. (default key bindings)*/ weechat_parse_args (argc, argv); /* parse command line args */ @@ -1103,7 +1103,7 @@ main (int argc, char *argv[]) weechat_config_read (); /* read configuration */ weechat_create_config_dirs (); /* create config directories */ utf8_init (); /* init UTF-8 in WeeChat */ - gui_init (); /* init WeeChat interface */ + gui_main_init (); /* init WeeChat interface */ fifo_create (); /* FIFO pipe for remote control */ if (weechat_session) session_load (weechat_session); /* load previous session if asked */ @@ -1125,7 +1125,7 @@ main (int argc, char *argv[]) command_index_free (); /* free commands index */ dcc_end (); /* remove all DCC */ server_free_all (); /* free all servers */ - gui_end (); /* shut down WeeChat GUI */ + gui_main_end (); /* shut down WeeChat GUI */ weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */ return EXIT_SUCCESS; /* make gcc happy (never executed) */ diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index d3a119b4b..71b82287a 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -1110,9 +1110,9 @@ void config_change_title () { if (cfg_look_set_title) - gui_set_window_title (); + gui_window_set_title (); else - gui_reset_window_title (); + gui_window_reset_title (); } /* @@ -1122,8 +1122,8 @@ config_change_title () void config_change_buffers () { - gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); - gui_redraw_buffer (gui_current_window->buffer); + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); } /* @@ -1133,7 +1133,7 @@ config_change_buffers () void config_change_buffer_content () { - gui_redraw_buffer (gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); } /* @@ -1146,7 +1146,7 @@ config_change_read_marker () t_gui_window *ptr_win; for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - gui_redraw_buffer (ptr_win->buffer); + gui_window_redraw_buffer (ptr_win->buffer); } /* @@ -1157,7 +1157,7 @@ void config_change_charset () { utf8_init (); - gui_redraw_buffer (gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); } /* @@ -1169,9 +1169,9 @@ void config_change_one_server_buffer () { if (cfg_look_one_server_buffer) - gui_merge_servers (gui_current_window); + gui_buffer_merge_servers (gui_current_window); else - gui_split_server (gui_current_window); + gui_buffer_split_server (gui_current_window); } /* @@ -1181,9 +1181,9 @@ config_change_one_server_buffer () void config_change_color () { - gui_init_color_pairs (); - gui_rebuild_weechat_colors (); - gui_refresh_windows (); + gui_color_init_pairs (); + gui_color_rebuild_weechat (); + gui_window_refresh_windows (); } /* @@ -1338,7 +1338,7 @@ config_option_set_value (t_config_option *option, char *value) *(option->ptr_int) = int_value; break; case OPTION_TYPE_COLOR: - if (!gui_assign_color (option->ptr_int, value)) + if (!gui_color_assign (option->ptr_int, value)) return -1; break; case OPTION_TYPE_STRING: @@ -1574,7 +1574,7 @@ config_set_server_value (t_irc_server *server, char *option_name, *((int *)(ptr_data)) = int_value; break; case OPTION_TYPE_COLOR: - if (!gui_assign_color ((int *)ptr_data, value)) + if (!gui_color_assign ((int *)ptr_data, value)) return -2; break; case OPTION_TYPE_STRING: @@ -1792,7 +1792,7 @@ config_default_values () int_value; break; case OPTION_TYPE_COLOR: - if (!gui_assign_color ( + if (!gui_color_assign ( weechat_options[i][j].ptr_int, weechat_options[i][j].default_string)) gui_printf (NULL, @@ -2377,7 +2377,7 @@ config_write (char *config_name) fprintf (file, "%s = %s\n", weechat_options[i][j].option_name, (weechat_options[i][j].ptr_int) ? - gui_get_color_name (*weechat_options[i][j].ptr_int) : + gui_color_get_name (*weechat_options[i][j].ptr_int) : weechat_options[i][j].default_string); break; case OPTION_TYPE_STRING: diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 268f88621..b202250e2 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -19,9 +19,11 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" noinst_LIBRARIES = lib_weechat_gui_common.a -lib_weechat_gui_common_a_SOURCES = gui-common.c \ +lib_weechat_gui_common_a_SOURCES = gui-buffer.c \ + gui-common.c \ gui-action.c \ gui-keyboard.c \ + gui-window.c \ gui.h if GUI_NCURSES diff --git a/src/gui/curses/Makefile.am b/src/gui/curses/Makefile.am index 0de2b9926..0041d8080 100644 --- a/src/gui/curses/Makefile.am +++ b/src/gui/curses/Makefile.am @@ -20,7 +20,8 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" bin_PROGRAMS = weechat-curses if PLUGINS -weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \ +weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \ + ../gui-window.o ../gui-keyboard.o \ ../gui-action.o \ ../../common/lib_weechat_main.a \ ../../irc/lib_weechat_irc.a \ @@ -29,7 +30,8 @@ weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \ $(NCURSES_LIBS) \ $(GNUTLS_LFLAGS) else -weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \ +weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \ + ../gui-window.o ../gui-keyboard.o \ ../gui-action.o \ ../../common/lib_weechat_main.a \ ../../irc/lib_weechat_irc.a \ @@ -38,5 +40,13 @@ weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \ $(GNUTLS_LFLAGS) endif -weechat_curses_SOURCES = gui-display.c \ - gui-input.c +weechat_curses_SOURCES = gui-chat.c \ + gui-color.c \ + gui-infobar.c \ + gui-input.c \ + gui-keyboard.c \ + gui-main.c \ + gui-nicklist.c \ + gui-status.c \ + gui-window.c \ + gui-curses.h diff --git a/src/gui/curses/gui-chat.c b/src/gui/curses/gui-chat.c new file mode 100644 index 000000000..e7bef1cd2 --- /dev/null +++ b/src/gui/curses/gui-chat.c @@ -0,0 +1,1098 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-chat.c: chat display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/utf8.h" +#include "../../common/weeconfig.h" +#include "../../irc/irc.h" +#include "gui-curses.h" + + +/* + * gui_chat_set_style: set style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_set_style (t_gui_window *window, int style) +{ + wattron (window->win_chat, style); +} + +/* + * gui_chat_remove_style: remove style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_remove_style (t_gui_window *window, int style) +{ + wattroff (window->win_chat, style); +} + +/* + * gui_chat_toggle_style: toggle a style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_toggle_style (t_gui_window *window, int style) +{ + window->current_style_attr ^= style; + if (window->current_style_attr & style) + gui_chat_set_style (window, style); + else + gui_chat_remove_style (window, style); +} + +/* + * gui_chat_reset_style: reset style (color and attr) + * for a chat window + */ + +void +gui_chat_reset_style (t_gui_window *window) +{ + window->current_style_fg = -1; + window->current_style_bg = -1; + window->current_style_attr = 0; + window->current_color_attr = 0; + + gui_window_set_weechat_color (window->win_chat, COLOR_WIN_CHAT); + gui_chat_remove_style (window, + A_BOLD | A_UNDERLINE | A_REVERSE); +} + +/* + * gui_chat_set_color_style: set style for color + */ + +void +gui_chat_set_color_style (t_gui_window *window, int style) +{ + window->current_color_attr |= style; + wattron (window->win_chat, style); +} + +/* + * gui_chat_remove_color_style: remove style for color + */ + +void +gui_chat_remove_color_style (t_gui_window *window, int style) +{ + window->current_color_attr &= !style; + wattroff (window->win_chat, style); +} + +/* + * gui_chat_reset_color_style: reset style for color + */ + +void +gui_chat_reset_color_style (t_gui_window *window) +{ + wattroff (window->win_chat, window->current_color_attr); + window->current_color_attr = 0; +} + +/* + * gui_chat_set_color: set color for a chat window + */ + +void +gui_chat_set_color (t_gui_window *window, int fg, int bg) +{ + if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + wattron (window->win_chat, COLOR_PAIR(63)); + else + { + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + wattron (window->win_chat, COLOR_PAIR((bg * 8) + fg)); + } +} + +/* + * gui_chat_set_weechat_color: set a WeeChat color for a chat window + */ + +void +gui_chat_set_weechat_color (t_gui_window *window, int weechat_color) +{ + gui_chat_reset_style (window); + gui_chat_set_style (window, + gui_color[weechat_color]->attributes); + gui_chat_set_color (window, + gui_color[weechat_color]->foreground, + gui_color[weechat_color]->background); +} + +/* + * gui_chat_draw_title: draw title window for a buffer + */ + +void +gui_chat_draw_title (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + char format[32], *buf, *buf2; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + if (erase) + gui_window_curses_clear (ptr_win->win_title, COLOR_WIN_TITLE); + + gui_window_set_weechat_color (ptr_win->win_title, COLOR_WIN_TITLE); + snprintf (format, 32, "%%-%ds", ptr_win->win_width); + if (CHANNEL(buffer)) + { + if (CHANNEL(buffer)->topic) + { + buf = (char *)gui_color_decode ((unsigned char *)(CHANNEL(buffer)->topic), 0); + buf2 = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + (buf) ? buf : CHANNEL(buffer)->topic); + mvwprintw (ptr_win->win_title, 0, 0, format, (buf2) ? buf2 : CHANNEL(buffer)->topic); + if (buf) + free (buf); + if (buf2) + free (buf2); + } + else + mvwprintw (ptr_win->win_title, 0, 0, format, " "); + } + else + { + if (buffer->type == BUFFER_TYPE_STANDARD) + { + mvwprintw (ptr_win->win_title, 0, 0, + format, + PACKAGE_STRING " " WEECHAT_COPYRIGHT_DATE " - " + WEECHAT_WEBSITE); + } + else + mvwprintw (ptr_win->win_title, 0, 0, format, " "); + } + wnoutrefresh (ptr_win->win_title); + refresh (); + } + } +} + +/* + * gui_chat_display_new_line: display a new line + */ + +void +gui_chat_display_new_line (t_gui_window *window, int num_lines, int count, + int *lines_displayed, int simulate) +{ + if ((count == 0) || (*lines_displayed >= num_lines - count)) + { + if ((!simulate) && (window->win_chat_cursor_x <= window->win_chat_width - 1)) + { + wmove (window->win_chat, + window->win_chat_cursor_y, + window->win_chat_cursor_x); + wclrtoeol (window->win_chat); + } + window->win_chat_cursor_y++; + } + window->win_chat_cursor_x = 0; + (*lines_displayed)++; +} + +/* + * gui_chat_word_get_next_char: returns next char of a word + * special chars like colors, bold, .. are skipped + */ + +char * +gui_chat_word_get_next_char (t_gui_window *window, unsigned char *string, int apply_style) +{ + char str_fg[3], str_bg[3]; + int fg, bg, weechat_color; + + while (string[0]) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_BOLD); + break; + case GUI_ATTR_COLOR_CHAR: + string++; + str_fg[0] = '\0'; + str_bg[0] = '\0'; + fg = 99; + bg = 99; + if (isdigit (string[0])) + { + str_fg[0] = string[0]; + str_fg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_fg[1] = string[0]; + str_fg[2] = '\0'; + string++; + } + } + if (string[0] == ',') + { + string++; + if (isdigit (string[0])) + { + str_bg[0] = string[0]; + str_bg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_bg[1] = string[0]; + str_bg[2] = '\0'; + string++; + } + } + } + if (apply_style) + { + if (str_fg[0] || str_bg[0]) + { + if (str_fg[0]) + sscanf (str_fg, "%d", &fg); + else + fg = window->current_style_fg; + if (str_bg[0]) + sscanf (str_bg, "%d", &bg); + else + bg = window->current_style_bg; + } + if (!str_fg[0] && !str_bg[0]) + gui_chat_reset_color_style (window); + window->current_style_fg = fg; + window->current_style_bg = bg; + gui_chat_set_color (window, fg, bg); + } + break; + case GUI_ATTR_RESET_CHAR: + string++; + if (apply_style) + gui_chat_reset_style (window); + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_REVERSE); + break; + case GUI_ATTR_WEECHAT_COLOR_CHAR: + string++; + if (isdigit (string[0]) && isdigit (string[1])) + { + str_fg[0] = string[0]; + str_fg[1] = string[1]; + str_fg[2] = '\0'; + string += 2; + if (apply_style) + { + sscanf (str_fg, "%d", &weechat_color); + gui_chat_set_weechat_color (window, weechat_color); + } + } + break; + case GUI_ATTR_WEECHAT_SET_CHAR: + string++; + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_BOLD); + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_REVERSE); + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_UNDERLINE); + break; + } + break; + case GUI_ATTR_WEECHAT_REMOVE_CHAR: + string++; + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_BOLD); + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_REVERSE); + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_UNDERLINE); + break; + } + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_UNDERLINE); + break; + default: + if (string[0] < 32) + string++; + else + return utf8_next_char ((char *)string); + } + + } + + /* nothing found except color/attrib codes, so return NULL */ + return NULL; +} + +/* + * gui_chat_display_word_raw: display word on chat buffer, letter by letter + * special chars like color, bold, .. are interpreted + */ + +void +gui_chat_display_word_raw (t_gui_window *window, char *string) +{ + char *prev_char, *next_char, saved_char; + + wmove (window->win_chat, + window->win_chat_cursor_y, + window->win_chat_cursor_x); + + while (string && string[0]) + { + next_char = gui_chat_word_get_next_char (window, (unsigned char *)string, 1); + if (!next_char) + return; + + prev_char = utf8_prev_char (string, next_char); + if (prev_char) + { + saved_char = next_char[0]; + next_char[0] = '\0'; + wprintw (window->win_chat, "%s", prev_char); + next_char[0] = saved_char; + } + + string = next_char; + } +} + +/* + * gui_chat_display_word: display a word on chat buffer + */ + +void +gui_chat_display_word (t_gui_window *window, + t_gui_line *line, + char *data, + char *end_offset, + int num_lines, int count, int *lines_displayed, int simulate) +{ + char *end_line, saved_char_end, saved_char; + int pos_saved_char, chars_to_display, num_displayed; + + if (!data || + ((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height))) + return; + + end_line = data + strlen (data); + + if (end_offset[0]) + { + saved_char_end = end_offset[1]; + end_offset[1] = '\0'; + } + else + { + end_offset = NULL; + saved_char_end = '\0'; + } + + while (data && data[0]) + { + /* insert spaces for align text under time/nick */ + if ((line->length_align > 0) && + (window->win_chat_cursor_x == 0) && + (*lines_displayed > 0) && + /* TODO: modify arbitraty value for non aligning messages on time/nick? */ + (line->length_align < (window->win_chat_width - 5))) + { + if (!simulate) + { + wmove (window->win_chat, + window->win_chat_cursor_y, + window->win_chat_cursor_x); + wclrtoeol (window->win_chat); + } + window->win_chat_cursor_x += line->length_align; + } + + chars_to_display = gui_word_strlen (window, data); + + /* too long for current line */ + if (window->win_chat_cursor_x + chars_to_display > window->win_chat_width) + { + num_displayed = window->win_chat_width - window->win_chat_cursor_x; + pos_saved_char = gui_word_real_pos (window, data, num_displayed); + saved_char = data[pos_saved_char]; + data[pos_saved_char] = '\0'; + if ((!simulate) && + ((count == 0) || (*lines_displayed >= num_lines - count))) + gui_chat_display_word_raw (window, data); + data[pos_saved_char] = saved_char; + data += pos_saved_char; + } + else + { + num_displayed = chars_to_display; + if ((!simulate) && + ((count == 0) || (*lines_displayed >= num_lines - count))) + gui_chat_display_word_raw (window, data); + data += strlen (data); + } + + window->win_chat_cursor_x += num_displayed; + + /* display new line? */ + if ((data >= end_line) || + (((simulate) || + (window->win_chat_cursor_y <= window->win_chat_height - 1)) && + (window->win_chat_cursor_x > (window->win_chat_width - 1)))) + gui_chat_display_new_line (window, num_lines, count, + lines_displayed, simulate); + + if ((data >= end_line) || + ((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height))) + data = NULL; + } + + if (end_offset) + end_offset[1] = saved_char_end; +} + +/* + * gui_chat_get_word_info: returns info about next word: beginning, end, length + */ + +void +gui_chat_get_word_info (t_gui_window *window, + char *data, + int *word_start_offset, int *word_end_offset, + int *word_length_with_spaces, int *word_length) +{ + char *start_data, *prev_char, *next_char; + int leading_spaces, char_size; + + *word_start_offset = 0; + *word_end_offset = 0; + *word_length_with_spaces = 0; + *word_length = 0; + + start_data = data; + + leading_spaces = 1; + while (data && data[0]) + { + next_char = gui_chat_word_get_next_char (window, (unsigned char *)data, 0); + if (next_char) + { + prev_char = utf8_prev_char (data, next_char); + if (prev_char) + { + if (prev_char[0] != ' ') + { + if (leading_spaces) + *word_start_offset = prev_char - start_data; + leading_spaces = 0; + char_size = next_char - prev_char; + *word_end_offset = next_char - start_data - 1; + (*word_length_with_spaces) += char_size; + (*word_length) += char_size; + } + else + { + if (leading_spaces) + (*word_length_with_spaces)++; + else + { + *word_end_offset = prev_char - start_data - 1; + return; + } + } + data = next_char; + } + } + else + { + *word_end_offset = data + strlen (data) - start_data - 1; + return; + } + } +} + +/* + * gui_chat_display_line: display a line in the chat window + * if count == 0, display whole line + * if count > 0, display 'count' lines + * (beginning from the end) + * if simulate == 1, nothing is displayed + * (for counting how many lines would have been + * lines displayed) + * returns: number of lines displayed (or simulated) + */ + +int +gui_chat_display_line (t_gui_window *window, t_gui_line *line, int count, + int simulate) +{ + int num_lines, x, y, lines_displayed; + int read_marker_x, read_marker_y; + int word_start_offset, word_end_offset; + int word_length_with_spaces, word_length; + char *ptr_data, *ptr_end_offset, *next_char, *prev_char; + char *ptr_style, saved_char; + + if (simulate) + { + x = window->win_chat_cursor_x; + y = window->win_chat_cursor_y; + window->win_chat_cursor_x = 0; + window->win_chat_cursor_y = 0; + num_lines = 0; + } + else + { + if (window->win_chat_cursor_y > window->win_chat_height - 1) + return 0; + x = window->win_chat_cursor_x; + y = window->win_chat_cursor_y; + num_lines = gui_chat_display_line (window, line, 0, 1); + window->win_chat_cursor_x = x; + window->win_chat_cursor_y = y; + } + + /* calculate marker position (maybe not used for this line!) */ + if (line->ofs_after_date > 0) + { + saved_char = line->data[line->ofs_after_date - 1]; + line->data[line->ofs_after_date - 1] = '\0'; + read_marker_x = x + gui_word_strlen (NULL, line->data); + line->data[line->ofs_after_date - 1] = saved_char; + } + else + read_marker_x = x; + read_marker_y = y; + + /* reset color & style for a new line */ + gui_chat_reset_style (window); + + lines_displayed = 0; + ptr_data = line->data; + while (ptr_data && ptr_data[0]) + { + gui_chat_get_word_info (window, + ptr_data, + &word_start_offset, + &word_end_offset, + &word_length_with_spaces, &word_length); + + ptr_end_offset = ptr_data + word_end_offset; + + if (word_length > 0) + { + /* spaces + word too long for current line but ok for next line */ + if ((window->win_chat_cursor_x + word_length_with_spaces > window->win_chat_width) + && (word_length <= window->win_chat_width - line->length_align)) + { + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + /* apply styles before jumping to start of word */ + if (!simulate && (word_start_offset > 0)) + { + saved_char = ptr_data[word_start_offset]; + ptr_data[word_start_offset] = '\0'; + ptr_style = ptr_data; + while ((ptr_style = gui_chat_word_get_next_char (window, (unsigned char *)ptr_style, 1)) != NULL) + { + /* loop until no style/char available */ + } + ptr_data[word_start_offset] = saved_char; + } + /* jump to start of word */ + ptr_data += word_start_offset; + } + + /* display word */ + gui_chat_display_word (window, line, ptr_data, + ptr_end_offset, + num_lines, count, &lines_displayed, simulate); + + if ((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height)) + ptr_data = NULL; + else + { + /* move pointer after end of word */ + ptr_data = ptr_end_offset + 1; + if (*(ptr_data - 1) == '\0') + ptr_data = NULL; + + if (window->win_chat_cursor_x == 0) + { + while (ptr_data && (ptr_data[0] == ' ')) + { + next_char = gui_chat_word_get_next_char (window, + (unsigned char *)ptr_data, 0); + if (!next_char) + break; + prev_char = utf8_prev_char (ptr_data, next_char); + if (prev_char && (prev_char[0] == ' ')) + ptr_data = next_char; + else + break; + } + } + } + } + else + { + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + ptr_data = NULL; + } + } + + if (simulate) + { + window->win_chat_cursor_x = x; + window->win_chat_cursor_y = y; + } + else + { + /* display read marker if needed */ + if (cfg_look_read_marker && cfg_look_read_marker[0] && + window->buffer->last_read_line && + (window->buffer->last_read_line == line->prev_line)) + { + gui_chat_set_weechat_color (window, COLOR_WIN_CHAT_READ_MARKER); + mvwprintw (window->win_chat, read_marker_y, read_marker_x, + "%c", cfg_look_read_marker[0]); + } + } + + return lines_displayed; +} + +/* + * gui_chat_calculate_line_diff: returns pointer to line & offset for a difference + * with given line + */ + +void +gui_chat_calculate_line_diff (t_gui_window *window, t_gui_line **line, + int *line_pos, int difference) +{ + int backward, current_size; + + if (!line || !line_pos) + return; + + backward = (difference < 0); + + if (!(*line)) + { + /* if looking backward, start at last line of buffer */ + if (backward) + { + *line = window->buffer->last_line; + if (!(*line)) + return; + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = current_size - 1; + } + /* if looking forward, start at first line of buffer */ + else + { + *line = window->buffer->lines; + if (!(*line)) + return; + *line_pos = 0; + current_size = gui_chat_display_line (window, *line, 0, 1); + } + } + else + current_size = gui_chat_display_line (window, *line, 0, 1); + + while ((*line) && (difference != 0)) + { + /* looking backward */ + if (backward) + { + if (*line_pos > 0) + (*line_pos)--; + else + { + *line = (*line)->prev_line; + if (*line) + { + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = current_size - 1; + } + } + difference++; + } + /* looking forward */ + else + { + if (*line_pos < current_size - 1) + (*line_pos)++; + else + { + *line = (*line)->next_line; + if (*line) + { + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = 0; + } + } + difference--; + } + } + + /* first or last line reached */ + if (!(*line)) + { + if (backward) + { + /* first line reached */ + *line = window->buffer->lines; + *line_pos = 0; + } + else + { + /* last line reached => consider we'll display all until the end */ + *line_pos = 0; + } + } +} + +/* + * gui_chat_draw: draw chat window for a buffer + */ + +void +gui_chat_draw (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + t_gui_line *ptr_line; + t_irc_dcc *dcc_first, *dcc_selected, *ptr_dcc; + char format_empty[32]; + int i, j, line_pos, count, num_bars; + char *unit_name[] = { N_("bytes"), N_("Kb"), N_("Mb"), N_("Gb") }; + char *unit_format[] = { "%.0Lf", "%.1Lf", "%.02Lf", "%.02Lf" }; + long unit_divide[] = { 1, 1024, 1024*1024, 1024*1024,1024 }; + int num_unit; + char format[32], date[128], *buf; + struct tm *date_tmp; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + if (erase) + { + gui_window_set_weechat_color (ptr_win->win_chat, COLOR_WIN_CHAT); + + snprintf (format_empty, 32, "%%-%ds", ptr_win->win_chat_width); + for (i = 0; i < ptr_win->win_chat_height; i++) + { + mvwprintw (ptr_win->win_chat, i, 0, format_empty, " "); + } + } + + gui_window_set_weechat_color (ptr_win->win_chat, COLOR_WIN_CHAT); + + if (buffer->type == BUFFER_TYPE_DCC) + { + i = 0; + dcc_first = (ptr_win->dcc_first) ? (t_irc_dcc *) ptr_win->dcc_first : dcc_list; + dcc_selected = (ptr_win->dcc_selected) ? (t_irc_dcc *) ptr_win->dcc_selected : dcc_list; + for (ptr_dcc = dcc_first; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc) + { + if (i >= ptr_win->win_chat_height - 1) + break; + + /* nickname and filename */ + gui_window_set_weechat_color (ptr_win->win_chat, + (ptr_dcc == dcc_selected) ? + COLOR_DCC_SELECTED : COLOR_WIN_CHAT); + mvwprintw (ptr_win->win_chat, i, 0, "%s %-16s ", + (ptr_dcc == dcc_selected) ? "***" : " ", + ptr_dcc->nick); + buf = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + (DCC_IS_CHAT(ptr_dcc->type)) ? + _(ptr_dcc->filename) : ptr_dcc->filename); + wprintw (ptr_win->win_chat, "%s", buf); + free (buf); + if (DCC_IS_FILE(ptr_dcc->type)) + { + if (ptr_dcc->filename_suffix > 0) + wprintw (ptr_win->win_chat, " (.%d)", + ptr_dcc->filename_suffix); + } + + /* status */ + gui_window_set_weechat_color (ptr_win->win_chat, + (ptr_dcc == dcc_selected) ? + COLOR_DCC_SELECTED : COLOR_WIN_CHAT); + mvwprintw (ptr_win->win_chat, i + 1, 0, "%s %s ", + (ptr_dcc == dcc_selected) ? "***" : " ", + (DCC_IS_RECV(ptr_dcc->type)) ? "-->>" : "<<--"); + gui_window_set_weechat_color (ptr_win->win_chat, + COLOR_DCC_WAITING + ptr_dcc->status); + buf = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + _(dcc_status_string[ptr_dcc->status])); + wprintw (ptr_win->win_chat, "%-10s", buf); + free (buf); + + /* other infos */ + gui_window_set_weechat_color (ptr_win->win_chat, + (ptr_dcc == dcc_selected) ? + COLOR_DCC_SELECTED : COLOR_WIN_CHAT); + if (DCC_IS_FILE(ptr_dcc->type)) + { + wprintw (ptr_win->win_chat, " ["); + if (ptr_dcc->size == 0) + num_bars = 10; + else + num_bars = (int)((((long double)(ptr_dcc->pos)/(long double)(ptr_dcc->size))*100) / 10); + for (j = 0; j < num_bars - 1; j++) + wprintw (ptr_win->win_chat, "="); + if (num_bars > 0) + wprintw (ptr_win->win_chat, ">"); + for (j = 0; j < 10 - num_bars; j++) + wprintw (ptr_win->win_chat, " "); + + if (ptr_dcc->size < 1024*10) + num_unit = 0; + else if (ptr_dcc->size < 1024*1024) + num_unit = 1; + else if (ptr_dcc->size < 1024*1024*1024) + num_unit = 2; + else + num_unit = 3; + wprintw (ptr_win->win_chat, "] %3lu%% ", + (unsigned long)(((long double)(ptr_dcc->pos)/(long double)(ptr_dcc->size))*100)); + sprintf (format, "%s %%s / %s %%s", + unit_format[num_unit], + unit_format[num_unit]); + wprintw (ptr_win->win_chat, format, + ((long double)(ptr_dcc->pos)) / ((long double)(unit_divide[num_unit])), + unit_name[num_unit], + ((long double)(ptr_dcc->size)) / ((long double)(unit_divide[num_unit])), + unit_name[num_unit]); + + if (ptr_dcc->bytes_per_sec < 1024*1024) + num_unit = 1; + else if (ptr_dcc->bytes_per_sec < 1024*1024*1024) + num_unit = 2; + else + num_unit = 3; + wprintw (ptr_win->win_chat, " ("); + if (ptr_dcc->status == DCC_ACTIVE) + { + wprintw (ptr_win->win_chat, _("ETA")); + wprintw (ptr_win->win_chat, ": %.2lu:%.2lu:%.2lu - ", + ptr_dcc->eta / 3600, + (ptr_dcc->eta / 60) % 60, + ptr_dcc->eta % 60); + } + sprintf (format, "%s %%s/s)", unit_format[num_unit]); + buf = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + unit_name[num_unit]); + wprintw (ptr_win->win_chat, format, + ((long double) ptr_dcc->bytes_per_sec) / ((long double)(unit_divide[num_unit])), + buf); + free (buf); + } + else + { + date_tmp = localtime (&(ptr_dcc->start_time)); + strftime (date, sizeof (date) - 1, "%a, %d %b %Y %H:%M:%S", date_tmp); + wprintw (ptr_win->win_chat, " %s", date); + } + + wclrtoeol (ptr_win->win_chat); + + ptr_win->dcc_last_displayed = ptr_dcc; + i += 2; + } + } + else + { + ptr_win->win_chat_cursor_x = 0; + ptr_win->win_chat_cursor_y = 0; + + /* display at position of scrolling */ + if (ptr_win->start_line) + { + ptr_line = ptr_win->start_line; + line_pos = ptr_win->start_line_pos; + } + else + { + /* look for first line to display, starting from last line */ + ptr_line = NULL; + line_pos = 0; + gui_chat_calculate_line_diff (ptr_win, &ptr_line, &line_pos, + (-1) * (ptr_win->win_chat_height - 1)); + } + + if (line_pos > 0) + { + /* display end of first line at top of screen */ + gui_chat_display_line (ptr_win, ptr_line, + gui_chat_display_line (ptr_win, + ptr_line, + 0, 1) - + line_pos, 0); + ptr_line = ptr_line->next_line; + ptr_win->first_line_displayed = 0; + } + else + ptr_win->first_line_displayed = + (ptr_line == ptr_win->buffer->lines); + + /* display lines */ + count = 0; + while (ptr_line && (ptr_win->win_chat_cursor_y <= ptr_win->win_chat_height - 1)) + { + count = gui_chat_display_line (ptr_win, ptr_line, 0, 0); + ptr_line = ptr_line->next_line; + } + + ptr_win->scroll = (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1); + + /* check if last line of buffer is entirely displayed and scrolling */ + /* if so, disable scroll indicator */ + if (!ptr_line && ptr_win->scroll) + { + if (count == gui_chat_display_line (ptr_win, ptr_win->buffer->last_line, 0, 1)) + { + ptr_win->scroll = 0; + ptr_win->start_line = NULL; + ptr_win->start_line_pos = 0; + } + } + + if (!ptr_win->scroll && (ptr_win->start_line == ptr_win->buffer->lines)) + { + ptr_win->start_line = NULL; + ptr_win->start_line_pos = 0; + } + + /* cursor is below end line of chat window? */ + if (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1) + { + ptr_win->win_chat_cursor_x = 0; + ptr_win->win_chat_cursor_y = ptr_win->win_chat_height - 1; + } + } + wnoutrefresh (ptr_win->win_chat); + refresh (); + } + } +} + +/* + * gui_chat_draw_line: add a line to chat window for a buffer + */ + +void +gui_chat_draw_line (t_gui_buffer *buffer, t_gui_line *line) +{ + /* This function does nothing in Curses GUI, + line will be displayed by gui_buffer_draw_chat() */ + (void) buffer; + (void) line; +} diff --git a/src/gui/curses/gui-color.c b/src/gui/curses/gui-color.c new file mode 100644 index 000000000..9fd1d85de --- /dev/null +++ b/src/gui/curses/gui-color.c @@ -0,0 +1,607 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-color.c: color functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + + +t_gui_color gui_weechat_colors[] = +{ { -1, 0, 0, "default" }, + { WEECHAT_COLOR_BLACK, 0, 0, "black" }, + { WEECHAT_COLOR_RED, 0, 0, "red" }, + { WEECHAT_COLOR_RED, 0, A_BOLD, "lightred" }, + { WEECHAT_COLOR_GREEN, 0, 0, "green" }, + { WEECHAT_COLOR_GREEN, 0, A_BOLD, "lightgreen" }, + { WEECHAT_COLOR_YELLOW, 0, 0, "brown" }, + { WEECHAT_COLOR_YELLOW, 0, A_BOLD, "yellow" }, + { WEECHAT_COLOR_BLUE, 0, 0, "blue" }, + { WEECHAT_COLOR_BLUE, 0, A_BOLD, "lightblue" }, + { WEECHAT_COLOR_MAGENTA, 0, 0, "magenta" }, + { WEECHAT_COLOR_MAGENTA, 0, A_BOLD, "lightmagenta" }, + { WEECHAT_COLOR_CYAN, 0, 0, "cyan" }, + { WEECHAT_COLOR_CYAN, 0, A_BOLD, "lightcyan" }, + { WEECHAT_COLOR_WHITE, 0, A_BOLD, "white" }, + { 0, 0, 0, NULL } +}; + +int gui_irc_colors[GUI_NUM_IRC_COLORS][2] = +{ { /* 0 */ WEECHAT_COLOR_WHITE, A_BOLD }, + { /* 1 */ WEECHAT_COLOR_BLACK, 0 }, + { /* 2 */ WEECHAT_COLOR_BLUE, 0 }, + { /* 3 */ WEECHAT_COLOR_GREEN, 0 }, + { /* 4 */ WEECHAT_COLOR_RED, A_BOLD }, + { /* 5 */ WEECHAT_COLOR_RED, 0 }, + { /* 6 */ WEECHAT_COLOR_MAGENTA, 0 }, + { /* 7 */ WEECHAT_COLOR_YELLOW, 0 }, + { /* 8 */ WEECHAT_COLOR_YELLOW, A_BOLD }, + { /* 9 */ WEECHAT_COLOR_GREEN, A_BOLD }, + { /* 10 */ WEECHAT_COLOR_CYAN, 0 }, + { /* 11 */ WEECHAT_COLOR_CYAN, A_BOLD }, + { /* 12 */ WEECHAT_COLOR_BLUE, A_BOLD }, + { /* 13 */ WEECHAT_COLOR_MAGENTA, A_BOLD }, + { /* 14 */ WEECHAT_COLOR_WHITE, 0 }, + { /* 15 */ WEECHAT_COLOR_WHITE, A_BOLD } +}; + +t_gui_color *gui_color[GUI_NUM_COLORS]; + + +/* + * gui_color_assign: assign a WeeChat color (read from config) + */ + +int +gui_color_assign (int *color, char *color_name) +{ + int i; + + /* look for curses colors in table */ + i = 0; + while (gui_weechat_colors[i].string) + { + if (ascii_strcasecmp (gui_weechat_colors[i].string, color_name) == 0) + { + *color = i; + return 1; + } + i++; + } + + /* color not found */ + return 0; +} + +/* + * gui_color_get_name: get color name + */ + +char * +gui_color_get_name (int num_color) +{ + return gui_weechat_colors[num_color].string; +} + +/* + * gui_color_decode: parses a message (coming from IRC server), + * and according: + * - remove any color/style in message + * or: + * - change colors by codes to be compatible with + * other IRC clients + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode (unsigned char *string, int keep_colors) +{ + unsigned char *out; + int out_length, out_pos; + char str_fg[3], str_bg[3]; + int fg, bg, attr; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + case GUI_ATTR_RESET_CHAR: + case GUI_ATTR_FIXED_CHAR: + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + case GUI_ATTR_ITALIC_CHAR: + case GUI_ATTR_UNDERLINE_CHAR: + if (keep_colors) + out[out_pos++] = string[0]; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + string++; + str_fg[0] = '\0'; + str_bg[0] = '\0'; + if (isdigit (string[0])) + { + str_fg[0] = string[0]; + str_fg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_fg[1] = string[0]; + str_fg[2] = '\0'; + string++; + } + } + if (string[0] == ',') + { + string++; + if (isdigit (string[0])) + { + str_bg[0] = string[0]; + str_bg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_bg[1] = string[0]; + str_bg[2] = '\0'; + string++; + } + } + } + if (keep_colors) + { + if (!str_fg[0] && !str_bg[0]) + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + else + { + attr = 0; + if (str_fg[0]) + { + sscanf (str_fg, "%d", &fg); + fg %= GUI_NUM_IRC_COLORS; + attr |= gui_irc_colors[fg][1]; + } + if (str_bg[0]) + { + sscanf (str_bg, "%d", &bg); + bg %= GUI_NUM_IRC_COLORS; + attr |= gui_irc_colors[bg][1]; + } + if (attr & A_BOLD) + { + out[out_pos++] = GUI_ATTR_WEECHAT_SET_CHAR; + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + } + else + { + out[out_pos++] = GUI_ATTR_WEECHAT_REMOVE_CHAR; + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + } + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + if (str_fg[0]) + { + out[out_pos++] = (gui_irc_colors[fg][0] / 10) + '0'; + out[out_pos++] = (gui_irc_colors[fg][0] % 10) + '0'; + } + if (str_bg[0]) + { + out[out_pos++] = ','; + out[out_pos++] = (gui_irc_colors[bg][0] / 10) + '0'; + out[out_pos++] = (gui_irc_colors[bg][0] % 10) + '0'; + } + } + } + break; + case GUI_ATTR_WEECHAT_COLOR_CHAR: + string++; + if (isdigit (string[0]) && isdigit (string[1])) + { + if (keep_colors) + { + out[out_pos++] = string[0]; + out[out_pos++] = string[1]; + } + string += 2; + } + break; + case GUI_ATTR_WEECHAT_SET_CHAR: + case GUI_ATTR_WEECHAT_REMOVE_CHAR: + string++; + if (string[0]) + { + if (keep_colors) + { + out[out_pos++] = *(string - 1); + out[out_pos++] = string[0]; + } + string++; + } + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_decode_for_user_entry: parses a message (coming from IRC server), + * and replaces colors/bold/.. by %C, %B, .. + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode_for_user_entry (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'B'; + string++; + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_RESET_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'O'; + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'C'; + string++; + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_encode: parses a message (entered by user), and + * encode special chars (%B, %C, ..) in IRC colors + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_encode (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case '%': + string++; + switch (string[0]) + { + case '\0': + out[out_pos++] = '%'; + break; + case '%': /* double '%' replaced by single '%' */ + out[out_pos++] = string[0]; + string++; + break; + case 'B': /* bold */ + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + string++; + break; + case 'C': /* color */ + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + } + } + if (string[0] == ',') + { + out[out_pos++] = ','; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + } + } + } + break; + case 'O': /* reset */ + out[out_pos++] = GUI_ATTR_RESET_CHAR; + string++; + break; + case 'R': /* reverse */ + out[out_pos++] = GUI_ATTR_REVERSE_CHAR; + string++; + break; + case 'U': /* underline */ + out[out_pos++] = GUI_ATTR_UNDERLINE_CHAR; + string++; + break; + default: + out[out_pos++] = '%'; + out[out_pos++] = string[0]; + string++; + } + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_build: build a WeeChat color with foreground, + * background and attributes (attributes are + * given with foreground color, with a OR) + */ + +t_gui_color * +gui_color_build (int number, int foreground, int background) +{ + t_gui_color *new_color; + + new_color = (t_gui_color *)malloc (sizeof (t_gui_color)); + if (!new_color) + return NULL; + + new_color->foreground = gui_weechat_colors[foreground].foreground; + new_color->background = gui_weechat_colors[background].foreground; + new_color->attributes = gui_weechat_colors[foreground].attributes; + new_color->string = (char *)malloc (4); + if (new_color->string) + snprintf (new_color->string, 4, + "%s%02d", + GUI_ATTR_WEECHAT_COLOR_STR, number); + + return new_color; +} + +/* + * gui_color_get_pair: get color pair with a WeeChat color number + */ + +int +gui_color_get_pair (int num_color) +{ + int fg, bg; + + if ((num_color < 0) || (num_color > GUI_NUM_COLORS - 1)) + return WEECHAT_COLOR_WHITE; + + fg = gui_color[num_color]->foreground; + bg = gui_color[num_color]->background; + + if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + return 63; + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + + return (bg * 8) + fg; +} + +/* + * gui_color_init_pairs: init color pairs + */ + +void +gui_color_init_pairs () +{ + int i; + char shift_colors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; + + if (has_colors ()) + { + for (i = 1; i < COLOR_PAIRS; i++) + init_pair (i, shift_colors[i % 8], (i < 8) ? -1 : shift_colors[i / 8]); + + /* disable white on white, replaced by black on white */ + init_pair (63, -1, -1); + + /* white on default bg is default (-1) */ + if (!cfg_col_real_white) + init_pair (WEECHAT_COLOR_WHITE, -1, -1); + } +} + +/* + * gui_color_init_weechat: init WeeChat colors + */ + +void +gui_color_init_weechat () +{ + int i; + + gui_color[COLOR_WIN_SEPARATOR] = gui_color_build (COLOR_WIN_SEPARATOR, cfg_col_separator, cfg_col_separator); + gui_color[COLOR_WIN_TITLE] = gui_color_build (COLOR_WIN_TITLE, cfg_col_title, cfg_col_title_bg); + gui_color[COLOR_WIN_CHAT] = gui_color_build (COLOR_WIN_CHAT, cfg_col_chat, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_TIME] = gui_color_build (COLOR_WIN_CHAT_TIME, cfg_col_chat_time, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_TIME_SEP] = gui_color_build (COLOR_WIN_CHAT_TIME_SEP, cfg_col_chat_time_sep, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PREFIX1] = gui_color_build (COLOR_WIN_CHAT_PREFIX1, cfg_col_chat_prefix1, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PREFIX2] = gui_color_build (COLOR_WIN_CHAT_PREFIX2, cfg_col_chat_prefix2, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_SERVER] = gui_color_build (COLOR_WIN_CHAT_SERVER, cfg_col_chat_server, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_JOIN] = gui_color_build (COLOR_WIN_CHAT_JOIN, cfg_col_chat_join, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PART] = gui_color_build (COLOR_WIN_CHAT_PART, cfg_col_chat_part, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_NICK] = gui_color_build (COLOR_WIN_CHAT_NICK, cfg_col_chat_nick, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_HOST] = gui_color_build (COLOR_WIN_CHAT_HOST, cfg_col_chat_host, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_CHANNEL] = gui_color_build (COLOR_WIN_CHAT_CHANNEL, cfg_col_chat_channel, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_DARK] = gui_color_build (COLOR_WIN_CHAT_DARK, cfg_col_chat_dark, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_HIGHLIGHT] = gui_color_build (COLOR_WIN_CHAT_HIGHLIGHT, cfg_col_chat_highlight, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_READ_MARKER] = gui_color_build (COLOR_WIN_CHAT_READ_MARKER, cfg_col_chat_read_marker, cfg_col_chat_read_marker_bg); + gui_color[COLOR_WIN_STATUS] = gui_color_build (COLOR_WIN_STATUS, cfg_col_status, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DELIMITERS] = gui_color_build (COLOR_WIN_STATUS_DELIMITERS, cfg_col_status_delimiters, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_CHANNEL] = gui_color_build (COLOR_WIN_STATUS_CHANNEL, cfg_col_status_channel, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_MSG] = gui_color_build (COLOR_WIN_STATUS_DATA_MSG, cfg_col_status_data_msg, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_PRIVATE] = gui_color_build (COLOR_WIN_STATUS_DATA_PRIVATE, cfg_col_status_data_private, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_HIGHLIGHT] = gui_color_build (COLOR_WIN_STATUS_DATA_HIGHLIGHT, cfg_col_status_data_highlight, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_OTHER] = gui_color_build (COLOR_WIN_STATUS_DATA_OTHER, cfg_col_status_data_other, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_MORE] = gui_color_build (COLOR_WIN_STATUS_MORE, cfg_col_status_more, cfg_col_status_bg); + gui_color[COLOR_WIN_INFOBAR] = gui_color_build (COLOR_WIN_INFOBAR, cfg_col_infobar, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INFOBAR_DELIMITERS] = gui_color_build (COLOR_WIN_INFOBAR_DELIMITERS, cfg_col_infobar_delimiters, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INFOBAR_HIGHLIGHT] = gui_color_build (COLOR_WIN_INFOBAR_HIGHLIGHT, cfg_col_infobar_highlight, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INPUT] = gui_color_build (COLOR_WIN_INPUT, cfg_col_input, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_SERVER] = gui_color_build (COLOR_WIN_INPUT_SERVER, cfg_col_input_server, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_CHANNEL] = gui_color_build (COLOR_WIN_INPUT_CHANNEL, cfg_col_input_channel, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_NICK] = gui_color_build (COLOR_WIN_INPUT_NICK, cfg_col_input_nick, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_DELIMITERS] = gui_color_build (COLOR_WIN_INPUT_DELIMITERS, cfg_col_input_delimiters, cfg_col_input_bg); + gui_color[COLOR_WIN_NICK] = gui_color_build (COLOR_WIN_NICK, cfg_col_nick, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_AWAY] = gui_color_build (COLOR_WIN_NICK_AWAY, cfg_col_nick_away, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_CHANOWNER] = gui_color_build (COLOR_WIN_NICK_CHANOWNER, cfg_col_nick_chanowner, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_CHANADMIN] = gui_color_build (COLOR_WIN_NICK_CHANADMIN, cfg_col_nick_chanadmin, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_OP] = gui_color_build (COLOR_WIN_NICK_OP, cfg_col_nick_op, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_HALFOP] = gui_color_build (COLOR_WIN_NICK_HALFOP, cfg_col_nick_halfop, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_VOICE] = gui_color_build (COLOR_WIN_NICK_VOICE, cfg_col_nick_voice, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_MORE] = gui_color_build (COLOR_WIN_NICK_MORE, cfg_col_nick_more, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_SEP] = gui_color_build (COLOR_WIN_NICK_SEP, cfg_col_nick_sep, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_SELF] = gui_color_build (COLOR_WIN_NICK_SELF, cfg_col_nick_self, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_PRIVATE] = gui_color_build (COLOR_WIN_NICK_PRIVATE, cfg_col_nick_private, cfg_col_nick_bg); + + for (i = 0; i < COLOR_WIN_NICK_NUMBER; i++) + { + gui_color[COLOR_WIN_NICK_1 + i] = gui_color_build (COLOR_WIN_NICK_1 + i, cfg_col_nick_colors[i], cfg_col_chat_bg); + } + + gui_color[COLOR_DCC_SELECTED] = gui_color_build (COLOR_DCC_SELECTED, cfg_col_dcc_selected, cfg_col_chat_bg); + gui_color[COLOR_DCC_WAITING] = gui_color_build (COLOR_DCC_WAITING, cfg_col_dcc_waiting, cfg_col_chat_bg); + gui_color[COLOR_DCC_CONNECTING] = gui_color_build (COLOR_DCC_CONNECTING, cfg_col_dcc_connecting, cfg_col_chat_bg); + gui_color[COLOR_DCC_ACTIVE] = gui_color_build (COLOR_DCC_ACTIVE, cfg_col_dcc_active, cfg_col_chat_bg); + gui_color[COLOR_DCC_DONE] = gui_color_build (COLOR_DCC_DONE, cfg_col_dcc_done, cfg_col_chat_bg); + gui_color[COLOR_DCC_FAILED] = gui_color_build (COLOR_DCC_FAILED, cfg_col_dcc_failed, cfg_col_chat_bg); + gui_color[COLOR_DCC_ABORTED] = gui_color_build (COLOR_DCC_ABORTED, cfg_col_dcc_aborted, cfg_col_chat_bg); +} + +/* + * gui_color_rebuild_weechat: rebuild WeeChat colors + */ + +void +gui_color_rebuild_weechat () +{ + int i; + + if (has_colors ()) + { + for (i = 0; i < GUI_NUM_COLORS; i++) + { + if (gui_color[i]) + { + if (gui_color[i]->string) + free (gui_color[i]->string); + free (gui_color[i]); + gui_color[i] = NULL; + } + } + gui_color_init_weechat (); + } +} + +/* + * gui_color_init: init GUI colors + */ + +void +gui_color_init () +{ + if (has_colors ()) + { + start_color (); + use_default_colors (); + } + gui_color_init_pairs (); + gui_color_init_weechat (); +} diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h new file mode 100644 index 000000000..27dcdd372 --- /dev/null +++ b/src/gui/curses/gui-curses.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef __WEECHAT_GUI_CURSES_H +#define __WEECHAT_GUI_CURSES_H 1 + +/* shift ncurses colors for compatibility with colors + in IRC messages (same as other IRC clients) */ + +#define WEECHAT_COLOR_BLACK COLOR_BLACK +#define WEECHAT_COLOR_RED COLOR_BLUE +#define WEECHAT_COLOR_GREEN COLOR_GREEN +#define WEECHAT_COLOR_YELLOW COLOR_CYAN +#define WEECHAT_COLOR_BLUE COLOR_RED +#define WEECHAT_COLOR_MAGENTA COLOR_MAGENTA +#define WEECHAT_COLOR_CYAN COLOR_YELLOW +#define WEECHAT_COLOR_WHITE COLOR_WHITE + +extern t_gui_color gui_weechat_colors[]; +extern int gui_irc_colors[GUI_NUM_IRC_COLORS][2]; + +/* color functions */ +extern int gui_color_get_pair (int); +extern void gui_color_init (); + +/* chat functions */ +extern void gui_chat_calculate_line_diff (t_gui_window *, t_gui_line **, int *, int); + +/* keyboard functions */ +extern void gui_keyboard_default_bindings (); +extern void gui_keyboard_read (); + +/* window functions */ +extern void gui_window_curses_clear (WINDOW *, int); +extern void gui_window_set_weechat_color (WINDOW *, int); +extern void gui_window_refresh_screen_sigwinch (); +extern void gui_window_set_title (); +extern void gui_window_reset_title (); + +#endif /* gui-curses.h */ diff --git a/src/gui/curses/gui-infobar.c b/src/gui/curses/gui-infobar.c new file mode 100644 index 000000000..73abf75c0 --- /dev/null +++ b/src/gui/curses/gui-infobar.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-infobar.c: infobar display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + + +/* + * gui_infobar_draw_time: draw time in infobar window + */ + +void +gui_infobar_draw_time (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + time_t time_seconds; + struct tm *local_time; + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + time_seconds = time (NULL); + local_time = localtime (&time_seconds); + if (local_time) + { + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + mvwprintw (ptr_win->win_infobar, + 0, 1, + "%02d:%02d", + local_time->tm_hour, local_time->tm_min); + if (cfg_look_infobar_seconds) + wprintw (ptr_win->win_infobar, + ":%02d", + local_time->tm_sec); + } + wnoutrefresh (ptr_win->win_infobar); + } +} + +/* + * gui_infobar_draw: draw infobar window for a buffer + */ + +void +gui_infobar_draw (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + time_t time_seconds; + struct tm *local_time; + char text_time[1024 + 1]; + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (erase) + gui_window_curses_clear (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + + time_seconds = time (NULL); + local_time = localtime (&time_seconds); + if (local_time) + { + strftime (text_time, 1024, cfg_look_infobar_timestamp, local_time); + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR_DELIMITERS); + wprintw (ptr_win->win_infobar, "["); + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + wprintw (ptr_win->win_infobar, + "%02d:%02d", + local_time->tm_hour, local_time->tm_min); + if (cfg_look_infobar_seconds) + wprintw (ptr_win->win_infobar, + ":%02d", + local_time->tm_sec); + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR_DELIMITERS); + wprintw (ptr_win->win_infobar, "]"); + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + wprintw (ptr_win->win_infobar, + " %s", text_time); + } + if (gui_infobar) + { + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR_DELIMITERS); + wprintw (ptr_win->win_infobar, " | "); + gui_window_set_weechat_color (ptr_win->win_infobar, gui_infobar->color); + wprintw (ptr_win->win_infobar, "%s", gui_infobar->text); + } + + wnoutrefresh (ptr_win->win_infobar); + refresh (); + } +} diff --git a/src/gui/curses/gui-input.c b/src/gui/curses/gui-input.c index 450fef559..9e93c9a1a 100644 --- a/src/gui/curses/gui-input.c +++ b/src/gui/curses/gui-input.c @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -/* gui-input: user input functions for Curses GUI */ +/* gui-input: input display functions for Curses GUI */ #ifdef HAVE_CONFIG_H @@ -25,12 +25,6 @@ #endif #include -#include -#include -#include -#include -#include -#include #ifdef HAVE_NCURSESW_CURSES_H #include @@ -40,12 +34,9 @@ #include "../../common/weechat.h" #include "../gui.h" -#include "../../common/weeconfig.h" -#include "../../common/command.h" -#include "../../common/hotlist.h" -#include "../../common/fifo.h" #include "../../common/utf8.h" -#include "../../irc/irc.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" #ifdef PLUGINS #include "../../plugins/plugins.h" @@ -53,483 +44,391 @@ /* - * gui_input_default_key_bindings: create default key bindings + * gui_input_set_color: set color for an input window */ void -gui_input_default_key_bindings () +gui_input_set_color (t_gui_window *window, int irc_color) { - int i; - char key_str[32], command[32]; + int fg, bg; - /* keys binded with internal functions */ - gui_key_bind ( /* RC */ "ctrl-M", "return"); - gui_key_bind ( /* RC */ "ctrl-J", "return"); - gui_key_bind ( /* tab */ "ctrl-I", "tab"); - gui_key_bind ( /* basckp */ "ctrl-H", "backspace"); - gui_key_bind ( /* basckp */ "ctrl-?", "backspace"); - gui_key_bind ( /* del */ "meta2-3~", "delete"); - gui_key_bind ( /* ^K */ "ctrl-K", "delete_end_line"); - gui_key_bind ( /* ^U */ "ctrl-U", "delete_beginning_line"); - gui_key_bind ( /* ^W */ "ctrl-W", "delete_previous_word"); - gui_key_bind ( /* ^Y */ "ctrl-Y", "clipboard_paste"); - gui_key_bind ( /* ^T */ "ctrl-T", "transpose_chars"); - gui_key_bind ( /* home */ "meta2-1~", "home"); - gui_key_bind ( /* home */ "meta2-H", "home"); - gui_key_bind ( /* home */ "meta2-7~", "home"); - gui_key_bind ( /* ^A */ "ctrl-A", "home"); - gui_key_bind ( /* end */ "meta2-4~", "end"); - gui_key_bind ( /* end */ "meta2-F", "end"); - gui_key_bind ( /* end */ "meta2-8~", "end"); - gui_key_bind ( /* ^E */ "ctrl-E", "end"); - gui_key_bind ( /* left */ "meta2-D", "left"); - gui_key_bind ( /* right */ "meta2-C", "right"); - gui_key_bind ( /* up */ "meta2-A", "up"); - gui_key_bind ( /* ^up */ "meta-Oa", "up_global"); - gui_key_bind ( /* down */ "meta2-B", "down"); - gui_key_bind ( /* ^down */ "meta-Ob", "down_global"); - gui_key_bind ( /* pgup */ "meta2-5~", "page_up"); - gui_key_bind ( /* pgdn */ "meta2-6~", "page_down"); - gui_key_bind ( /* m-pgup */ "meta-meta2-5~", "scroll_up"); - gui_key_bind ( /* m-pgdn */ "meta-meta2-6~", "scroll_down"); - gui_key_bind ( /* m-home */ "meta-meta2-1~", "scroll_top"); - gui_key_bind ( /* m-end */ "meta-meta2-4~", "scroll_bottom"); - gui_key_bind ( /* F10 */ "meta2-21~", "infobar_clear"); - gui_key_bind ( /* F11 */ "meta2-23~", "nick_page_up"); - gui_key_bind ( /* F12 */ "meta2-24~", "nick_page_down"); - gui_key_bind ( /* m-F11 */ "meta-meta2-23~", "nick_beginning"); - gui_key_bind ( /* m-F12 */ "meta-meta2-24~", "nick_end"); - gui_key_bind ( /* ^L */ "ctrl-L", "refresh"); - gui_key_bind ( /* m-a */ "meta-a", "jump_smart"); - gui_key_bind ( /* m-b */ "meta-b", "previous_word"); - gui_key_bind ( /* ^left */ "meta-Od", "previous_word"); - gui_key_bind ( /* m-d */ "meta-d", "delete_next_word"); - gui_key_bind ( /* m-f */ "meta-f", "next_word"); - gui_key_bind ( /* ^right */ "meta-Oc", "next_word"); - gui_key_bind ( /* m-h */ "meta-h", "hotlist_clear"); - gui_key_bind ( /* m-j,m-d */ "meta-jmeta-d", "jump_dcc"); - gui_key_bind ( /* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer"); - gui_key_bind ( /* m-j,m-s */ "meta-jmeta-s", "jump_server"); - gui_key_bind ( /* m-j,m-x */ "meta-jmeta-x", "jump_next_server"); - gui_key_bind ( /* m-j,m-r */ "meta-jmeta-r", "jump_raw_data"); - gui_key_bind ( /* m-k */ "meta-k", "grab_key"); - gui_key_bind ( /* m-n */ "meta-n", "scroll_next_highlight"); - gui_key_bind ( /* m-p */ "meta-p", "scroll_previous_highlight"); - gui_key_bind ( /* m-r */ "meta-r", "delete_line"); - gui_key_bind ( /* m-s */ "meta-s", "switch_server"); - gui_key_bind ( /* m-u */ "meta-u", "scroll_unread"); + fg = gui_irc_colors[irc_color][0]; + bg = gui_color[COLOR_WIN_INPUT]->background; - /* keys binded with commands */ - gui_key_bind ( /* m-left */ "meta-meta2-D", "/buffer -1"); - gui_key_bind ( /* F5 */ "meta2-15~", "/buffer -1"); - gui_key_bind ( /* m-right */ "meta-meta2-C", "/buffer +1"); - gui_key_bind ( /* F6 */ "meta2-17~", "/buffer +1"); - gui_key_bind ( /* F7 */ "meta2-18~", "/window -1"); - gui_key_bind ( /* F8 */ "meta2-19~", "/window +1"); - gui_key_bind ( /* m-w,m-up */ "meta-wmeta-meta2-A", "/window up"); - gui_key_bind ( /* m-w,m-down */ "meta-wmeta-meta2-B", "/window down"); - gui_key_bind ( /* m-w,m-left */ "meta-wmeta-meta2-D", "/window left"); - gui_key_bind ( /* m-w,m-right */ "meta-wmeta-meta2-C", "/window right"); - gui_key_bind ( /* m-0 */ "meta-0", "/buffer 10"); - gui_key_bind ( /* m-1 */ "meta-1", "/buffer 1"); - gui_key_bind ( /* m-2 */ "meta-2", "/buffer 2"); - gui_key_bind ( /* m-3 */ "meta-3", "/buffer 3"); - gui_key_bind ( /* m-4 */ "meta-4", "/buffer 4"); - gui_key_bind ( /* m-5 */ "meta-5", "/buffer 5"); - gui_key_bind ( /* m-6 */ "meta-6", "/buffer 6"); - gui_key_bind ( /* m-7 */ "meta-7", "/buffer 7"); - gui_key_bind ( /* m-8 */ "meta-8", "/buffer 8"); - gui_key_bind ( /* m-9 */ "meta-9", "/buffer 9"); + irc_color %= GUI_NUM_IRC_COLORS; + if (gui_irc_colors[irc_color][1] & A_BOLD) + wattron (window->win_input, A_BOLD); - /* bind meta-j + {01..99} to switch to buffers # > 10 */ - for (i = 1; i < 100; i++) + if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + wattron (window->win_input, COLOR_PAIR(63)); + else { - sprintf (key_str, "meta-j%02d", i); - sprintf (command, "/buffer %d", i); - gui_key_bind (key_str, command); + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + wattron (window->win_input, COLOR_PAIR((bg * 8) + fg)); } } /* - * gui_input_grab_end: insert grabbed key in input buffer + * gui_input_get_prompt_length: return input prompt length + */ + +int +gui_input_get_prompt_length (t_gui_window *window, char *nick) +{ + char *pos, *modes; + int length, mode_found; + + length = 0; + pos = cfg_look_input_format; + while (pos && pos[0]) + { + switch (pos[0]) + { + case '%': + pos++; + switch (pos[0]) + { + case 'c': + if (CHANNEL(window->buffer)) + length += utf8_strlen (CHANNEL(window->buffer)->name); + else + { + if (SERVER(window->buffer)) + length += utf8_strlen (SERVER(window->buffer)->name); + } + pos++; + break; + case 'm': + if (SERVER(window->buffer)) + { + mode_found = 0; + for (modes = SERVER(window->buffer)->nick_modes; + modes && modes[0]; modes++) + { + if (modes[0] != ' ') + { + length++; + mode_found = 1; + } + } + if (mode_found) + length++; + } + pos++; + break; + case 'n': + length += utf8_strlen (nick); + pos++; + break; + default: + length++; + if (pos[0]) + { + if (pos[0] == '%') + pos++; + else + { + length++; + pos += utf8_char_size (pos); + } + } + break; + } + break; + default: + length++; + pos += utf8_char_size (pos); + break; + } + } + return length; +} + +/* + * gui_input_draw_prompt: display input prompt */ void -gui_input_grab_end () +gui_input_draw_prompt (t_gui_window *window, char *nick) { - char *expanded_key, *expanded_key2; - int length; - char *buffer_before_key; - - /* get expanded name (for example: ^U => ctrl-u) */ - expanded_key = gui_key_get_expanded_name (gui_key_buffer); + char *pos, saved_char, *modes; + int char_size, mode_found; - if (expanded_key) + wmove (window->win_input, 0, 0); + pos = cfg_look_input_format; + while (pos && pos[0]) { - if (gui_current_window->buffer->has_input) + switch (pos[0]) { - buffer_before_key = - (gui_current_window->buffer->input_buffer) ? - strdup (gui_current_window->buffer->input_buffer) : strdup (""); - gui_insert_string_input (gui_current_window, expanded_key, -1); - gui_current_window->buffer->input_buffer_pos += utf8_strlen (expanded_key); - gui_draw_buffer_input (gui_current_window->buffer, 1); - gui_current_window->buffer->completion.position = -1; -#ifdef PLUGINS - length = strlen (expanded_key) + 1 + 1; - expanded_key2 = (char *) malloc (length); - if (expanded_key2) + case '%': + pos++; + switch (pos[0]) + { + case 'c': + if (CHANNEL(window->buffer)) + { + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_CHANNEL); + wprintw (window->win_input, "%s", + CHANNEL(window->buffer)->name); + } + else + { + if (SERVER(window->buffer)) + { + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_SERVER); + wprintw (window->win_input, "%s", + SERVER(window->buffer)->name); + } + } + pos++; + break; + case 'm': + if (SERVER(window->buffer)) + { + mode_found = 0; + for (modes = SERVER(window->buffer)->nick_modes; + modes && modes[0]; modes++) + { + if (modes[0] != ' ') + mode_found = 1; + } + if (mode_found) + { + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT); + wprintw (window->win_input, "+"); + for (modes = SERVER(window->buffer)->nick_modes; + modes && modes[0]; modes++) + { + if (modes[0] != ' ') + wprintw (window->win_input, "%c", + modes[0]); + } + } + } + pos++; + break; + case 'n': + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_NICK); + wprintw (window->win_input, "%s", nick); + pos++; + break; + default: + if (pos[0]) + { + char_size = utf8_char_size (pos); + saved_char = pos[char_size]; + pos[char_size] = '\0'; + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_DELIMITERS); + wprintw (window->win_input, "%%%s", pos); + pos[char_size] = saved_char; + pos += char_size; + } + else + { + wprintw (window->win_input, "%%"); + pos++; + } + break; + } + break; + default: + char_size = utf8_char_size (pos); + saved_char = pos[char_size]; + pos[char_size] = '\0'; + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_DELIMITERS); + wprintw (window->win_input, "%s", pos); + pos[char_size] = saved_char; + pos += char_size; + break; + } + } +} + +/* + * gui_input_draw_text: display text in input buffer, according to color mask + */ + +void +gui_input_draw_text (t_gui_window *window, int input_width) +{ + char *ptr_start, *ptr_next, saved_char; + int pos_mask, size, last_color, color; + + ptr_start = utf8_add_offset (window->buffer->input_buffer, + window->buffer->input_buffer_1st_display); + pos_mask = ptr_start - window->buffer->input_buffer; + last_color = -1; + while ((input_width > 0) && ptr_start && ptr_start[0]) + { + ptr_next = utf8_next_char (ptr_start); + if (ptr_next) + { + saved_char = ptr_next[0]; + ptr_next[0] = '\0'; + size = ptr_next - ptr_start; + if (window->buffer->input_buffer_color_mask[pos_mask] != ' ') + color = window->buffer->input_buffer_color_mask[pos_mask] - '0'; + else + color = -1; + if (color != last_color) { - snprintf (expanded_key2, length, "*%s", expanded_key); - (void) plugin_keyboard_handler_exec (expanded_key2, - buffer_before_key, - gui_current_window->buffer->input_buffer); - free (expanded_key2); + if (color == -1) + gui_window_set_weechat_color (window->win_input, COLOR_WIN_INPUT); + else + gui_input_set_color (window, color); } -#endif - if (buffer_before_key) - free (buffer_before_key); - } - free (expanded_key); - } - - /* end grab mode */ - gui_key_grab = 0; - gui_key_grab_count = 0; - gui_key_buffer[0] = '\0'; -} - -/* - * gui_input_read: read keyboard chars - */ - -void -gui_input_read () -{ - int key, i, insert_ok; - char key_str[32], key_str2[33]; - char *buffer_before_key; - - i = 0; - /* do not loop too much here (for example when big paste was made), - to read also socket & co */ - while (i < 8) - { - if (gui_key_grab && (gui_key_grab_count > 10)) - gui_input_grab_end (); - - key = getch (); - insert_ok = 1; - - if (key == ERR) - { - if (gui_key_grab && (gui_key_grab_count > 0)) - gui_input_grab_end (); - break; - } - - if (key == KEY_RESIZE) - { - gui_refresh_screen (); - continue; - } - - gui_last_activity_time = time (NULL); - - if (key < 32) - { - insert_ok = 0; - key_str[0] = '^'; - key_str[1] = (char) key + '@'; - key_str[2] = '\0'; - } - else if (key == 127) - { - key_str[0] = '^'; - key_str[1] = '?'; - key_str[2] = '\0'; + last_color = color; + wprintw (window->win_input, "%s", ptr_start); + ptr_next[0] = saved_char; + ptr_start = ptr_next; + pos_mask += size; } else - { - if (local_utf8) - { - /* 1 char: 0vvvvvvv */ - if (key < 0x80) - { - key_str[0] = (char) key; - key_str[1] = '\0'; - } - /* 2 chars: 110vvvvv 10vvvvvv */ - else if ((key & 0xE0) == 0xC0) - { - key_str[0] = (char) key; - key_str[1] = (char) (getch ()); - key_str[2] = '\0'; - } - /* 3 chars: 1110vvvv 10vvvvvv 10vvvvvv */ - else if ((key & 0xF0) == 0xE0) - { - key_str[0] = (char) key; - key_str[1] = (char) (getch ()); - key_str[2] = (char) (getch ()); - key_str[3] = '\0'; - } - /* 4 chars: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */ - else if ((key & 0xF8) == 0xF0) - { - key_str[0] = (char) key; - key_str[1] = (char) (getch ()); - key_str[2] = (char) (getch ()); - key_str[3] = (char) (getch ()); - key_str[4] = '\0'; - } - } - else - { - key_str[0] = (char) key; - key_str[1] = '\0'; - } - } - - if (strcmp (key_str, "^") == 0) - { - key_str[1] = '^'; - key_str[2] = '\0'; - } - - /*gui_printf (gui_current_window->buffer, "gui_input_read: key = %s (%d)\n", key_str, key);*/ - - if ((gui_key_pressed (key_str) != 0) && (insert_ok)) - { - if (strcmp (key_str, "^^") == 0) - key_str[1] = '\0'; - - switch (gui_current_window->buffer->type) - { - case BUFFER_TYPE_STANDARD: - buffer_before_key = - (gui_current_window->buffer->input_buffer) ? - strdup (gui_current_window->buffer->input_buffer) : strdup (""); - gui_insert_string_input (gui_current_window, key_str, -1); - gui_current_window->buffer->input_buffer_pos += utf8_strlen (key_str); - gui_draw_buffer_input (gui_current_window->buffer, 0); - gui_current_window->buffer->completion.position = -1; -#ifdef PLUGINS - snprintf (key_str2, sizeof (key_str2), "*%s", key_str); - (void) plugin_keyboard_handler_exec (key_str2, - buffer_before_key, - gui_current_window->buffer->input_buffer); -#endif - break; - case BUFFER_TYPE_DCC: - gui_exec_action_dcc (gui_current_window, key_str); - break; - case BUFFER_TYPE_RAW_DATA: - gui_exec_action_raw_data (gui_current_window, key_str); - break; - } - } - - i++; + ptr_start = NULL; + input_width--; } } /* - * gui_main_loop: main loop for WeeChat with ncurses GUI + * gui_input_draw: draw input window for a buffer */ void -gui_main_loop () +gui_input_draw (t_gui_buffer *buffer, int erase) { - fd_set read_fd; - static struct timeval timeout, tv; - static struct timezone tz; - t_irc_server *ptr_server; - t_gui_buffer *ptr_buffer; - int old_day, old_min, old_sec, diff; - char text_time[1024]; - time_t new_time; - struct tm *local_time; + t_gui_window *ptr_win; + char format[32]; + char *ptr_nickname; + int prompt_length, display_prompt; + t_irc_dcc *dcc_selected; - quit_weechat = 0; - - new_time = time (NULL); - gui_last_activity_time = new_time; - local_time = localtime (&new_time); - old_day = local_time->tm_mday; + if (!gui_ok) + return; - old_min = -1; - old_sec = -1; - check_away = 0; - while (!quit_weechat) + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { - new_time = time (NULL); - local_time = localtime (&new_time); - - /* minute has changed ? => redraw infobar */ - if (local_time->tm_min != old_min) + if (ptr_win->buffer == buffer) { - old_min = local_time->tm_min; - gui_draw_buffer_infobar (gui_current_window->buffer, 1); + if (erase) + gui_window_curses_clear (ptr_win->win_input, COLOR_WIN_INPUT); - if (cfg_look_day_change - && (local_time->tm_mday != old_day)) + switch (buffer->type) { - strftime (text_time, sizeof (text_time), - cfg_look_day_change_timestamp, local_time); - gui_add_hotlist = 0; - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->type == BUFFER_TYPE_STANDARD) - gui_printf_nolog_notime (ptr_buffer, - _("Day changed to %s\n"), - text_time); - } - gui_add_hotlist = 1; - } - old_day = local_time->tm_mday; - } - - /* second has changed ? */ - if (local_time->tm_sec != old_sec) - { - old_sec = local_time->tm_sec; - - if (cfg_look_infobar_seconds) - { - gui_draw_buffer_infobar_time (gui_current_window->buffer); - wmove (gui_current_window->win_input, - 0, gui_current_window->win_input_x); - wrefresh (gui_current_window->win_input); - } - - /* infobar count down */ - if (gui_infobar && gui_infobar->remaining_time > 0) - { - gui_infobar->remaining_time--; - if (gui_infobar->remaining_time == 0) - { - gui_infobar_remove (); - gui_draw_buffer_infobar (gui_current_window->buffer, 1); - } - } - - /* away check */ - if (cfg_irc_away_check != 0) - { - check_away++; - if (check_away >= (cfg_irc_away_check * 60)) - { - check_away = 0; - server_check_away (); - } - } - -#ifdef PLUGINS - /* call timer handlers */ - plugin_timer_handler_exec (); -#endif - } - - /* read keyboard */ - - FD_ZERO (&read_fd); - timeout.tv_sec = 0; - timeout.tv_usec = 8000; - - FD_SET (STDIN_FILENO, &read_fd); - - if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) - { - if (FD_ISSET (STDIN_FILENO, &read_fd)) - { - gui_input_read (); - } - } - - /* read sockets (servers, child process when connecting, FIFO pipe) */ - - FD_ZERO (&read_fd); - - timeout.tv_sec = 0; - timeout.tv_usec = 2000; - - if (weechat_fifo != -1) - FD_SET (weechat_fifo, &read_fd); - - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - /* check if reconnection is pending */ - if ((!ptr_server->is_connected) - && (ptr_server->reconnect_start > 0) - && (new_time >= (ptr_server->reconnect_start + ptr_server->autoreconnect_delay))) - server_reconnect (ptr_server); - else - { - if (ptr_server->is_connected) - { - /* check for lag */ - if ((ptr_server->lag_check_time.tv_sec == 0) - && (new_time >= ptr_server->lag_next_check)) + case BUFFER_TYPE_STANDARD: + if (buffer->has_input) { - server_sendf (ptr_server, "PING %s\r\n", ptr_server->address); - gettimeofday (&(ptr_server->lag_check_time), &tz); - } - - /* lag timeout => disconnect */ - if ((ptr_server->lag_check_time.tv_sec != 0) - && (cfg_irc_lag_disconnect > 0)) - { - gettimeofday (&tv, &tz); - diff = (int) get_timeval_diff (&(ptr_server->lag_check_time), &tv); - if (diff / 1000 > cfg_irc_lag_disconnect * 60) + if (buffer->input_buffer_length == 0) + buffer->input_buffer[0] = '\0'; + + if (SERVER(buffer)) + ptr_nickname = (SERVER(buffer)->nick) ? + SERVER(buffer)->nick : SERVER(buffer)->nick1; + else + ptr_nickname = cfg_look_no_nickname; + + prompt_length = gui_input_get_prompt_length (ptr_win, ptr_nickname); + + if (ptr_win->win_width - prompt_length < 3) { - irc_display_prefix (ptr_server, ptr_server->buffer, PREFIX_ERROR); - gui_printf (ptr_server->buffer, - _("%s lag is high, disconnecting from server...\n"), - WEECHAT_WARNING); - server_disconnect (ptr_server, 1); - continue; + prompt_length = 0; + display_prompt = 0; + } + else + display_prompt = 1; + + if (buffer->input_buffer_pos - buffer->input_buffer_1st_display + 1 > + ptr_win->win_width - prompt_length) + buffer->input_buffer_1st_display = buffer->input_buffer_pos - + (ptr_win->win_width - prompt_length) + 1; + else + { + if (buffer->input_buffer_pos < buffer->input_buffer_1st_display) + buffer->input_buffer_1st_display = buffer->input_buffer_pos; + else + { + if ((buffer->input_buffer_1st_display > 0) && + (buffer->input_buffer_pos - + buffer->input_buffer_1st_display + 1) + < ptr_win->win_width - prompt_length) + { + buffer->input_buffer_1st_display = + buffer->input_buffer_pos - + (ptr_win->win_width - prompt_length) + 1; + if (buffer->input_buffer_1st_display < 0) + buffer->input_buffer_1st_display = 0; + } + } + } + if (display_prompt) + gui_input_draw_prompt (ptr_win, ptr_nickname); + + gui_window_set_weechat_color (ptr_win->win_input, COLOR_WIN_INPUT); + snprintf (format, 32, "%%-%ds", ptr_win->win_width - prompt_length); + if (ptr_win == gui_current_window) + gui_input_draw_text (ptr_win, ptr_win->win_width - prompt_length); + else + wprintw (ptr_win->win_input, format, ""); + wclrtoeol (ptr_win->win_input); + ptr_win->win_input_x = prompt_length + + (buffer->input_buffer_pos - buffer->input_buffer_1st_display); + if (ptr_win == gui_current_window) + move (ptr_win->win_y + ptr_win->win_height - 1, + ptr_win->win_x + ptr_win->win_input_x); + } + break; + case BUFFER_TYPE_DCC: + dcc_selected = (ptr_win->dcc_selected) ? (t_irc_dcc *) ptr_win->dcc_selected : dcc_list; + wmove (ptr_win->win_input, 0, 0); + if (dcc_selected) + { + switch (dcc_selected->status) + { + case DCC_WAITING: + if (DCC_IS_RECV(dcc_selected->type)) + wprintw (ptr_win->win_input, _(" [A] Accept")); + wprintw (ptr_win->win_input, _(" [C] Cancel")); + break; + case DCC_CONNECTING: + case DCC_ACTIVE: + wprintw (ptr_win->win_input, _(" [C] Cancel")); + break; + case DCC_DONE: + case DCC_FAILED: + case DCC_ABORTED: + wprintw (ptr_win->win_input, _(" [R] Remove")); + break; } } - } - - if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) - FD_SET (ptr_server->child_read, &read_fd); - else - { - if (ptr_server->sock >= 0) - FD_SET (ptr_server->sock, &read_fd); - } + wprintw (ptr_win->win_input, _(" [P] Purge old DCC")); + wprintw (ptr_win->win_input, _(" [Q] Close DCC view")); + wclrtoeol (ptr_win->win_input); + ptr_win->win_input_x = 0; + if (ptr_win == gui_current_window) + move (ptr_win->win_y + ptr_win->win_height - 1, + ptr_win->win_x); + break; + case BUFFER_TYPE_RAW_DATA: + mvwprintw (ptr_win->win_input, 0, 0, _(" [Q] Close raw data view")); + wclrtoeol (ptr_win->win_input); + ptr_win->win_input_x = 0; + if (ptr_win == gui_current_window) + move (ptr_win->win_y + ptr_win->win_height - 1, + ptr_win->win_x); + break; } + doupdate (); + wrefresh (ptr_win->win_input); + refresh (); } - - if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) - { - if ((weechat_fifo != -1) && (FD_ISSET (weechat_fifo, &read_fd))) - { - fifo_read (); - } - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) - { - if (FD_ISSET (ptr_server->child_read, &read_fd)) - server_child_read (ptr_server); - } - else - { - if ((ptr_server->sock >= 0) && - (FD_ISSET (ptr_server->sock, &read_fd))) - server_recv (ptr_server); - } - } - } - - /* manages active DCC */ - dcc_handle (); } } diff --git a/src/gui/curses/gui-keyboard.c b/src/gui/curses/gui-keyboard.c new file mode 100644 index 000000000..25c4bedd6 --- /dev/null +++ b/src/gui/curses/gui-keyboard.c @@ -0,0 +1,324 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-keyboard.c: keyboard functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/utf8.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif + + +/* + * gui_keyboard__default_bindings: create default key bindings + */ + +void +gui_keyboard_default_bindings () +{ + int i; + char key_str[32], command[32]; + + /* keys binded with internal functions */ + gui_key_bind ( /* RC */ "ctrl-M", "return"); + gui_key_bind ( /* RC */ "ctrl-J", "return"); + gui_key_bind ( /* tab */ "ctrl-I", "tab"); + gui_key_bind ( /* basckp */ "ctrl-H", "backspace"); + gui_key_bind ( /* basckp */ "ctrl-?", "backspace"); + gui_key_bind ( /* del */ "meta2-3~", "delete"); + gui_key_bind ( /* ^K */ "ctrl-K", "delete_end_line"); + gui_key_bind ( /* ^U */ "ctrl-U", "delete_beginning_line"); + gui_key_bind ( /* ^W */ "ctrl-W", "delete_previous_word"); + gui_key_bind ( /* ^Y */ "ctrl-Y", "clipboard_paste"); + gui_key_bind ( /* ^T */ "ctrl-T", "transpose_chars"); + gui_key_bind ( /* home */ "meta2-1~", "home"); + gui_key_bind ( /* home */ "meta2-H", "home"); + gui_key_bind ( /* home */ "meta2-7~", "home"); + gui_key_bind ( /* ^A */ "ctrl-A", "home"); + gui_key_bind ( /* end */ "meta2-4~", "end"); + gui_key_bind ( /* end */ "meta2-F", "end"); + gui_key_bind ( /* end */ "meta2-8~", "end"); + gui_key_bind ( /* ^E */ "ctrl-E", "end"); + gui_key_bind ( /* left */ "meta2-D", "left"); + gui_key_bind ( /* right */ "meta2-C", "right"); + gui_key_bind ( /* up */ "meta2-A", "up"); + gui_key_bind ( /* ^up */ "meta-Oa", "up_global"); + gui_key_bind ( /* down */ "meta2-B", "down"); + gui_key_bind ( /* ^down */ "meta-Ob", "down_global"); + gui_key_bind ( /* pgup */ "meta2-5~", "page_up"); + gui_key_bind ( /* pgdn */ "meta2-6~", "page_down"); + gui_key_bind ( /* m-pgup */ "meta-meta2-5~", "scroll_up"); + gui_key_bind ( /* m-pgdn */ "meta-meta2-6~", "scroll_down"); + gui_key_bind ( /* m-home */ "meta-meta2-1~", "scroll_top"); + gui_key_bind ( /* m-end */ "meta-meta2-4~", "scroll_bottom"); + gui_key_bind ( /* F10 */ "meta2-21~", "infobar_clear"); + gui_key_bind ( /* F11 */ "meta2-23~", "nick_page_up"); + gui_key_bind ( /* F12 */ "meta2-24~", "nick_page_down"); + gui_key_bind ( /* m-F11 */ "meta-meta2-23~", "nick_beginning"); + gui_key_bind ( /* m-F12 */ "meta-meta2-24~", "nick_end"); + gui_key_bind ( /* ^L */ "ctrl-L", "refresh"); + gui_key_bind ( /* m-a */ "meta-a", "jump_smart"); + gui_key_bind ( /* m-b */ "meta-b", "previous_word"); + gui_key_bind ( /* ^left */ "meta-Od", "previous_word"); + gui_key_bind ( /* m-d */ "meta-d", "delete_next_word"); + gui_key_bind ( /* m-f */ "meta-f", "next_word"); + gui_key_bind ( /* ^right */ "meta-Oc", "next_word"); + gui_key_bind ( /* m-h */ "meta-h", "hotlist_clear"); + gui_key_bind ( /* m-j,m-d */ "meta-jmeta-d", "jump_dcc"); + gui_key_bind ( /* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer"); + gui_key_bind ( /* m-j,m-s */ "meta-jmeta-s", "jump_server"); + gui_key_bind ( /* m-j,m-x */ "meta-jmeta-x", "jump_next_server"); + gui_key_bind ( /* m-j,m-r */ "meta-jmeta-r", "jump_raw_data"); + gui_key_bind ( /* m-k */ "meta-k", "grab_key"); + gui_key_bind ( /* m-n */ "meta-n", "scroll_next_highlight"); + gui_key_bind ( /* m-p */ "meta-p", "scroll_previous_highlight"); + gui_key_bind ( /* m-r */ "meta-r", "delete_line"); + gui_key_bind ( /* m-s */ "meta-s", "switch_server"); + gui_key_bind ( /* m-u */ "meta-u", "scroll_unread"); + + /* keys binded with commands */ + gui_key_bind ( /* m-left */ "meta-meta2-D", "/buffer -1"); + gui_key_bind ( /* F5 */ "meta2-15~", "/buffer -1"); + gui_key_bind ( /* m-right */ "meta-meta2-C", "/buffer +1"); + gui_key_bind ( /* F6 */ "meta2-17~", "/buffer +1"); + gui_key_bind ( /* F7 */ "meta2-18~", "/window -1"); + gui_key_bind ( /* F8 */ "meta2-19~", "/window +1"); + gui_key_bind ( /* m-w,m-up */ "meta-wmeta-meta2-A", "/window up"); + gui_key_bind ( /* m-w,m-down */ "meta-wmeta-meta2-B", "/window down"); + gui_key_bind ( /* m-w,m-left */ "meta-wmeta-meta2-D", "/window left"); + gui_key_bind ( /* m-w,m-right */ "meta-wmeta-meta2-C", "/window right"); + gui_key_bind ( /* m-0 */ "meta-0", "/buffer 10"); + gui_key_bind ( /* m-1 */ "meta-1", "/buffer 1"); + gui_key_bind ( /* m-2 */ "meta-2", "/buffer 2"); + gui_key_bind ( /* m-3 */ "meta-3", "/buffer 3"); + gui_key_bind ( /* m-4 */ "meta-4", "/buffer 4"); + gui_key_bind ( /* m-5 */ "meta-5", "/buffer 5"); + gui_key_bind ( /* m-6 */ "meta-6", "/buffer 6"); + gui_key_bind ( /* m-7 */ "meta-7", "/buffer 7"); + gui_key_bind ( /* m-8 */ "meta-8", "/buffer 8"); + gui_key_bind ( /* m-9 */ "meta-9", "/buffer 9"); + + /* bind meta-j + {01..99} to switch to buffers # > 10 */ + for (i = 1; i < 100; i++) + { + sprintf (key_str, "meta-j%02d", i); + sprintf (command, "/buffer %d", i); + gui_key_bind (key_str, command); + } +} + +/* + * gui_keyboard_grab_end: insert grabbed key in input buffer + */ + +void +gui_keyboard_grab_end () +{ + char *expanded_key, *expanded_key2; + int length; + char *buffer_before_key; + + /* get expanded name (for example: ^U => ctrl-u) */ + expanded_key = gui_key_get_expanded_name (gui_key_buffer); + + if (expanded_key) + { + if (gui_current_window->buffer->has_input) + { + buffer_before_key = + (gui_current_window->buffer->input_buffer) ? + strdup (gui_current_window->buffer->input_buffer) : strdup (""); + gui_insert_string_input (gui_current_window, expanded_key, -1); + gui_current_window->buffer->input_buffer_pos += utf8_strlen (expanded_key); + gui_input_draw (gui_current_window->buffer, 1); + gui_current_window->buffer->completion.position = -1; +#ifdef PLUGINS + length = strlen (expanded_key) + 1 + 1; + expanded_key2 = (char *) malloc (length); + if (expanded_key2) + { + snprintf (expanded_key2, length, "*%s", expanded_key); + (void) plugin_keyboard_handler_exec (expanded_key2, + buffer_before_key, + gui_current_window->buffer->input_buffer); + free (expanded_key2); + } +#endif + if (buffer_before_key) + free (buffer_before_key); + } + free (expanded_key); + } + + /* end grab mode */ + gui_key_grab = 0; + gui_key_grab_count = 0; + gui_key_buffer[0] = '\0'; +} + +/* + * gui_keyboard_read: read keyboard chars + */ + +void +gui_keyboard_read () +{ + int key, i, insert_ok; + char key_str[32], key_str2[33]; + char *buffer_before_key; + + i = 0; + /* do not loop too much here (for example when big paste was made), + to read also socket & co */ + while (i < 8) + { + if (gui_key_grab && (gui_key_grab_count > 10)) + gui_keyboard_grab_end (); + + key = getch (); + insert_ok = 1; + + if (key == ERR) + { + if (gui_key_grab && (gui_key_grab_count > 0)) + gui_keyboard_grab_end (); + break; + } + + if (key == KEY_RESIZE) + { + gui_window_refresh_screen (); + continue; + } + + gui_last_activity_time = time (NULL); + + if (key < 32) + { + insert_ok = 0; + key_str[0] = '^'; + key_str[1] = (char) key + '@'; + key_str[2] = '\0'; + } + else if (key == 127) + { + key_str[0] = '^'; + key_str[1] = '?'; + key_str[2] = '\0'; + } + else + { + if (local_utf8) + { + /* 1 char: 0vvvvvvv */ + if (key < 0x80) + { + key_str[0] = (char) key; + key_str[1] = '\0'; + } + /* 2 chars: 110vvvvv 10vvvvvv */ + else if ((key & 0xE0) == 0xC0) + { + key_str[0] = (char) key; + key_str[1] = (char) (getch ()); + key_str[2] = '\0'; + } + /* 3 chars: 1110vvvv 10vvvvvv 10vvvvvv */ + else if ((key & 0xF0) == 0xE0) + { + key_str[0] = (char) key; + key_str[1] = (char) (getch ()); + key_str[2] = (char) (getch ()); + key_str[3] = '\0'; + } + /* 4 chars: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */ + else if ((key & 0xF8) == 0xF0) + { + key_str[0] = (char) key; + key_str[1] = (char) (getch ()); + key_str[2] = (char) (getch ()); + key_str[3] = (char) (getch ()); + key_str[4] = '\0'; + } + } + else + { + key_str[0] = (char) key; + key_str[1] = '\0'; + } + } + + if (strcmp (key_str, "^") == 0) + { + key_str[1] = '^'; + key_str[2] = '\0'; + } + + /*gui_printf (gui_current_window->buffer, "gui_input_read: key = %s (%d)\n", key_str, key);*/ + + if ((gui_key_pressed (key_str) != 0) && (insert_ok)) + { + if (strcmp (key_str, "^^") == 0) + key_str[1] = '\0'; + + switch (gui_current_window->buffer->type) + { + case BUFFER_TYPE_STANDARD: + buffer_before_key = + (gui_current_window->buffer->input_buffer) ? + strdup (gui_current_window->buffer->input_buffer) : strdup (""); + gui_insert_string_input (gui_current_window, key_str, -1); + gui_current_window->buffer->input_buffer_pos += utf8_strlen (key_str); + gui_input_draw (gui_current_window->buffer, 0); + gui_current_window->buffer->completion.position = -1; +#ifdef PLUGINS + snprintf (key_str2, sizeof (key_str2), "*%s", key_str); + (void) plugin_keyboard_handler_exec (key_str2, + buffer_before_key, + gui_current_window->buffer->input_buffer); +#endif + break; + case BUFFER_TYPE_DCC: + gui_exec_action_dcc (gui_current_window, key_str); + break; + case BUFFER_TYPE_RAW_DATA: + gui_exec_action_raw_data (gui_current_window, key_str); + break; + } + } + i++; + } +} diff --git a/src/gui/curses/gui-main.c b/src/gui/curses/gui-main.c new file mode 100644 index 000000000..0e8c61fd2 --- /dev/null +++ b/src/gui/curses/gui-main.c @@ -0,0 +1,355 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-main.c: main loop and keyboard management for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/fifo.h" +#include "../../common/utf8.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif + + +/* + * gui_main_loop: main loop for WeeChat with ncurses GUI + */ + +void +gui_main_loop () +{ + fd_set read_fd; + static struct timeval timeout, tv; + static struct timezone tz; + t_irc_server *ptr_server; + t_gui_buffer *ptr_buffer; + int old_day, old_min, old_sec, diff; + char text_time[1024]; + time_t new_time; + struct tm *local_time; + + quit_weechat = 0; + + new_time = time (NULL); + gui_last_activity_time = new_time; + local_time = localtime (&new_time); + old_day = local_time->tm_mday; + + old_min = -1; + old_sec = -1; + check_away = 0; + while (!quit_weechat) + { + new_time = time (NULL); + local_time = localtime (&new_time); + + /* minute has changed ? => redraw infobar */ + if (local_time->tm_min != old_min) + { + old_min = local_time->tm_min; + gui_infobar_draw (gui_current_window->buffer, 1); + + if (cfg_look_day_change + && (local_time->tm_mday != old_day)) + { + strftime (text_time, sizeof (text_time), + cfg_look_day_change_timestamp, local_time); + gui_add_hotlist = 0; + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->type == BUFFER_TYPE_STANDARD) + gui_printf_nolog_notime (ptr_buffer, + _("Day changed to %s\n"), + text_time); + } + gui_add_hotlist = 1; + } + old_day = local_time->tm_mday; + } + + /* second has changed ? */ + if (local_time->tm_sec != old_sec) + { + old_sec = local_time->tm_sec; + + if (cfg_look_infobar_seconds) + { + gui_infobar_draw_time (gui_current_window->buffer); + wmove (gui_current_window->win_input, + 0, gui_current_window->win_input_x); + wrefresh (gui_current_window->win_input); + } + + /* infobar count down */ + if (gui_infobar && gui_infobar->remaining_time > 0) + { + gui_infobar->remaining_time--; + if (gui_infobar->remaining_time == 0) + { + gui_infobar_remove (); + gui_infobar_draw (gui_current_window->buffer, 1); + } + } + + /* away check */ + if (cfg_irc_away_check != 0) + { + check_away++; + if (check_away >= (cfg_irc_away_check * 60)) + { + check_away = 0; + server_check_away (); + } + } + +#ifdef PLUGINS + /* call timer handlers */ + plugin_timer_handler_exec (); +#endif + } + + /* read keyboard */ + + FD_ZERO (&read_fd); + timeout.tv_sec = 0; + timeout.tv_usec = 8000; + + FD_SET (STDIN_FILENO, &read_fd); + + if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) + { + if (FD_ISSET (STDIN_FILENO, &read_fd)) + { + gui_keyboard_read (); + } + } + + /* read sockets (servers, child process when connecting, FIFO pipe) */ + + FD_ZERO (&read_fd); + + timeout.tv_sec = 0; + timeout.tv_usec = 2000; + + if (weechat_fifo != -1) + FD_SET (weechat_fifo, &read_fd); + + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + /* check if reconnection is pending */ + if ((!ptr_server->is_connected) + && (ptr_server->reconnect_start > 0) + && (new_time >= (ptr_server->reconnect_start + ptr_server->autoreconnect_delay))) + server_reconnect (ptr_server); + else + { + if (ptr_server->is_connected) + { + /* check for lag */ + if ((ptr_server->lag_check_time.tv_sec == 0) + && (new_time >= ptr_server->lag_next_check)) + { + server_sendf (ptr_server, "PING %s\r\n", ptr_server->address); + gettimeofday (&(ptr_server->lag_check_time), &tz); + } + + /* lag timeout => disconnect */ + if ((ptr_server->lag_check_time.tv_sec != 0) + && (cfg_irc_lag_disconnect > 0)) + { + gettimeofday (&tv, &tz); + diff = (int) get_timeval_diff (&(ptr_server->lag_check_time), &tv); + if (diff / 1000 > cfg_irc_lag_disconnect * 60) + { + irc_display_prefix (ptr_server, ptr_server->buffer, PREFIX_ERROR); + gui_printf (ptr_server->buffer, + _("%s lag is high, disconnecting from server...\n"), + WEECHAT_WARNING); + server_disconnect (ptr_server, 1); + continue; + } + } + } + + if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) + FD_SET (ptr_server->child_read, &read_fd); + else + { + if (ptr_server->sock >= 0) + FD_SET (ptr_server->sock, &read_fd); + } + } + } + + if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) + { + if ((weechat_fifo != -1) && (FD_ISSET (weechat_fifo, &read_fd))) + { + fifo_read (); + } + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) + { + if (FD_ISSET (ptr_server->child_read, &read_fd)) + server_child_read (ptr_server); + } + else + { + if ((ptr_server->sock >= 0) && + (FD_ISSET (ptr_server->sock, &read_fd))) + server_recv (ptr_server); + } + } + } + + /* manages active DCC */ + dcc_handle (); + } +} + +/* + * gui_main_pre_init: pre-initialize GUI (called before gui_init) + */ + +void +gui_main_pre_init (int *argc, char **argv[]) +{ + /* nothing for Curses interface */ + (void) argc; + (void) argv; +} + +/* + * gui_main_init: init GUI + */ + +void +gui_main_init () +{ + initscr (); + + curs_set (1); + noecho (); + nodelay (stdscr, TRUE); + + gui_color_init (); + + gui_infobar = NULL; + + gui_ok = ((COLS > 5) && (LINES > 5)); + + refresh (); + + /* init clipboard buffer */ + gui_input_clipboard = NULL; + + /* create new window/buffer */ + if (gui_window_new (NULL, 0, 0, COLS, LINES, 100, 100)) + { + gui_current_window = gui_windows; + gui_buffer_new (gui_windows, NULL, NULL, BUFFER_TYPE_STANDARD, 1); + + signal (SIGWINCH, gui_window_refresh_screen_sigwinch); + + if (cfg_look_set_title) + gui_window_set_title (); + + gui_init_ok = 1; + } +} + +/* + * gui_main_end: GUI end + */ + +void +gui_main_end () +{ + t_gui_window *ptr_win; + + /* free clipboard buffer */ + if (gui_input_clipboard) + free(gui_input_clipboard); + + /* delete all windows */ + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->win_title) + delwin (ptr_win->win_title); + if (ptr_win->win_chat) + delwin (ptr_win->win_chat); + if (ptr_win->win_nick) + delwin (ptr_win->win_nick); + if (ptr_win->win_status) + delwin (ptr_win->win_status); + if (ptr_win->win_infobar) + delwin (ptr_win->win_infobar); + if (ptr_win->win_input) + delwin (ptr_win->win_input); + } + + /* delete all buffers */ + while (gui_buffers) + gui_buffer_free (gui_buffers, 0); + + /* delete all windows */ + while (gui_windows) + gui_window_free (gui_windows); + gui_window_tree_free (&gui_windows_tree); + + /* delete global history */ + history_global_free (); + + /* delete infobar messages */ + while (gui_infobar) + gui_infobar_remove (); + + /* reset title */ + if (cfg_look_set_title) + gui_window_reset_title (); + + /* end of curses output */ + refresh (); + endwin (); +} diff --git a/src/gui/curses/gui-nicklist.c b/src/gui/curses/gui-nicklist.c new file mode 100644 index 000000000..2022df25c --- /dev/null +++ b/src/gui/curses/gui-nicklist.c @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-nicklist.c: nicklist display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/weeconfig.h" +#include "../../irc/irc.h" +#include "gui-curses.h" + + +/* + * gui_nicklist_draw: draw nick window for a buffer + */ + +void +gui_nicklist_draw (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + int i, j, x, y, x2, column, max_length, nicks_displayed; + char format[32], format_empty[32]; + t_irc_nick *ptr_nick; + + if (!gui_ok || !BUFFER_HAS_NICKLIST(buffer)) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if ((ptr_win->buffer == buffer) && (buffer->num_displayed > 0)) + { + max_length = nick_get_max_length (CHANNEL(buffer)); + + if (gui_window_calculate_pos_size (ptr_win, 0)) + { + delwin (ptr_win->win_chat); + delwin (ptr_win->win_nick); + ptr_win->win_chat = newwin (ptr_win->win_chat_height, + ptr_win->win_chat_width, + ptr_win->win_chat_y, + ptr_win->win_chat_x); + ptr_win->win_nick = newwin (ptr_win->win_nick_height, + ptr_win->win_nick_width, + ptr_win->win_nick_y, + ptr_win->win_nick_x); + gui_chat_draw (buffer, 1); + erase = 1; + } + + if (erase) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK); + + snprintf (format_empty, 32, "%%-%ds", ptr_win->win_nick_width); + for (i = 0; i < ptr_win->win_nick_height; i++) + { + mvwprintw (ptr_win->win_nick, i, 0, format_empty, " "); + } + } + + if ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_TOP) || + (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM)) + snprintf (format, 32, "%%.%ds", max_length); + else + snprintf (format, 32, "%%.%ds", + ((cfg_look_nicklist_min_size > 0) + && (max_length < cfg_look_nicklist_min_size)) ? + cfg_look_nicklist_min_size : + (((cfg_look_nicklist_max_size > 0) + && (max_length > cfg_look_nicklist_max_size)) ? + cfg_look_nicklist_max_size : max_length)); + + if (has_colors ()) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_SEP); + switch (cfg_look_nicklist_position) + { + case CFG_LOOK_NICKLIST_LEFT: + mvwvline (ptr_win->win_nick, + 0, ptr_win->win_nick_width - 1, ACS_VLINE, + ptr_win->win_chat_height); + break; + case CFG_LOOK_NICKLIST_RIGHT: + mvwvline (ptr_win->win_nick, + 0, 0, ACS_VLINE, + ptr_win->win_chat_height); + break; + case CFG_LOOK_NICKLIST_TOP: + mvwhline (ptr_win->win_nick, + ptr_win->win_nick_height - 1, 0, ACS_HLINE, + ptr_win->win_chat_width); + break; + case CFG_LOOK_NICKLIST_BOTTOM: + mvwhline (ptr_win->win_nick, + 0, 0, ACS_HLINE, + ptr_win->win_chat_width); + break; + } + } + + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK); + x = 0; + y = (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM) ? 1 : 0; + column = 0; + + if ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_TOP) || + (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM)) + nicks_displayed = (ptr_win->win_width / (max_length + 2)) * (ptr_win->win_nick_height - 1); + else + nicks_displayed = ptr_win->win_nick_height; + + ptr_nick = CHANNEL(buffer)->nicks; + for (i = 0; i < ptr_win->win_nick_start; i++) + { + if (!ptr_nick) + break; + ptr_nick = ptr_nick->next_nick; + } + if (ptr_nick) + { + for (i = 0; i < nicks_displayed; i++) + { + switch (cfg_look_nicklist_position) + { + case CFG_LOOK_NICKLIST_LEFT: + x = 0; + break; + case CFG_LOOK_NICKLIST_RIGHT: + x = 1; + break; + case CFG_LOOK_NICKLIST_TOP: + case CFG_LOOK_NICKLIST_BOTTOM: + x = column; + break; + } + if ( ((i == 0) && (ptr_win->win_nick_start > 0)) + || ((i == nicks_displayed - 1) && (ptr_nick->next_nick)) ) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_MORE); + j = (max_length + 1) >= 4 ? 4 : max_length + 1; + for (x2 = 1; x2 <= j; x2++) + mvwprintw (ptr_win->win_nick, y, x + x2, "+"); + } + else + { + if (ptr_nick->flags & NICK_CHANOWNER) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_CHANOWNER); + mvwprintw (ptr_win->win_nick, y, x, "~"); + x++; + } + else if (ptr_nick->flags & NICK_CHANADMIN) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_CHANADMIN); + mvwprintw (ptr_win->win_nick, y, x, "&"); + x++; + } + else if (ptr_nick->flags & NICK_OP) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_OP); + mvwprintw (ptr_win->win_nick, y, x, "@"); + x++; + } + else if (ptr_nick->flags & NICK_HALFOP) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_HALFOP); + mvwprintw (ptr_win->win_nick, y, x, "%%"); + x++; + } + else if (ptr_nick->flags & NICK_VOICE) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_VOICE); + mvwprintw (ptr_win->win_nick, y, x, "+"); + x++; + } + else + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK); + mvwprintw (ptr_win->win_nick, y, x, " "); + x++; + } + gui_window_set_weechat_color (ptr_win->win_nick, + ((cfg_irc_away_check > 0) && (ptr_nick->flags & NICK_AWAY)) ? + COLOR_WIN_NICK_AWAY : COLOR_WIN_NICK); + mvwprintw (ptr_win->win_nick, y, x, format, ptr_nick->nick); + + ptr_nick = ptr_nick->next_nick; + + if (!ptr_nick) + break; + } + y++; + if ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_TOP) || + (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM)) + { + if (y - ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM) ? 1 : 0) >= ptr_win->win_nick_height - 1) + { + column += max_length + 2; + y = (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_TOP) ? + 0 : 1; + } + } + } + } + wnoutrefresh (ptr_win->win_nick); + refresh (); + } + } +} diff --git a/src/gui/curses/gui-status.c b/src/gui/curses/gui-status.c new file mode 100644 index 000000000..5da5bb6ec --- /dev/null +++ b/src/gui/curses/gui-status.c @@ -0,0 +1,402 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-status.c: status display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + + +/* + * gui_status_draw: draw status window for a buffer + */ + +void +gui_status_draw (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + t_weechat_hotlist *ptr_hotlist; + char format[32], str_nicks[32], *more; + int i, first_mode, x, server_pos, server_total; + int display_name, names_count; + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (erase) + gui_window_curses_clear (ptr_win->win_status, COLOR_WIN_STATUS); + + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + + /* display number of buffers */ + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + mvwprintw (ptr_win->win_status, 0, 0, "["); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", + (last_gui_buffer) ? last_gui_buffer->number : 0); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "] "); + + /* display "" or current server */ + if (ptr_win->buffer->all_servers) + { + wprintw (ptr_win->win_status, "["); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, _("")); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "] "); + } + else if (SERVER(ptr_win->buffer) && SERVER(ptr_win->buffer)->name) + { + wprintw (ptr_win->win_status, "["); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%s", SERVER(ptr_win->buffer)->name); + if (SERVER(ptr_win->buffer)->is_away) + wprintw (ptr_win->win_status, _("(away)")); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "] "); + } + + /* infos about current server buffer */ + if (SERVER(ptr_win->buffer) && !CHANNEL(ptr_win->buffer)) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", + ptr_win->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_CHANNEL); + if (SERVER(ptr_win->buffer)->is_connected) + wprintw (ptr_win->win_status, "[%s] ", + SERVER(ptr_win->buffer)->name); + else + wprintw (ptr_win->win_status, "(%s) ", + SERVER(ptr_win->buffer)->name); + if (ptr_win->buffer->all_servers) + { + server_get_number_buffer (SERVER(ptr_win->buffer), + &server_pos, + &server_total); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "("); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", server_pos); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "/"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", server_total); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ") "); + + } + } + + /* infos about current channel/pv buffer */ + if (SERVER(ptr_win->buffer) && CHANNEL(ptr_win->buffer)) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", + ptr_win->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_CHANNEL); + if (((CHANNEL(ptr_win->buffer)->type != CHANNEL_TYPE_PRIVATE) + && (CHANNEL(ptr_win->buffer)->type != CHANNEL_TYPE_DCC_CHAT) + && (!CHANNEL(ptr_win->buffer)->nicks)) + || ((CHANNEL(ptr_win->buffer)->type == CHANNEL_TYPE_DCC_CHAT) + && (CHANNEL(ptr_win->buffer)->dcc_chat) + && (((t_irc_dcc *)(CHANNEL(ptr_win->buffer)->dcc_chat))->sock < 0))) + wprintw (ptr_win->win_status, "(%s)", + CHANNEL(ptr_win->buffer)->name); + else + wprintw (ptr_win->win_status, "%s", + CHANNEL(ptr_win->buffer)->name); + if (ptr_win->buffer == CHANNEL(ptr_win->buffer)->buffer) + { + /* display channel modes */ + if (CHANNEL(ptr_win->buffer)->type == CHANNEL_TYPE_CHANNEL) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "("); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + i = 0; + first_mode = 1; + while (CHANNEL(ptr_win->buffer)->modes[i]) + { + if (CHANNEL(ptr_win->buffer)->modes[i] != ' ') + { + if (first_mode) + { + wprintw (ptr_win->win_status, "+"); + first_mode = 0; + } + wprintw (ptr_win->win_status, "%c", + CHANNEL(ptr_win->buffer)->modes[i]); + } + i++; + } + if (CHANNEL(ptr_win->buffer)->modes[CHANNEL_MODE_KEY] != ' ') + wprintw (ptr_win->win_status, ",%s", + CHANNEL(ptr_win->buffer)->key); + if (CHANNEL(ptr_win->buffer)->modes[CHANNEL_MODE_LIMIT] != ' ') + wprintw (ptr_win->win_status, ",%d", + CHANNEL(ptr_win->buffer)->limit); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ")"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + } + + /* display DCC if private is DCC CHAT */ + if (CHANNEL(ptr_win->buffer)->type == CHANNEL_TYPE_DCC_CHAT) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "("); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_CHANNEL); + wprintw (ptr_win->win_status, "DCC"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ")"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + } + } + wprintw (ptr_win->win_status, " "); + } + if (!SERVER(ptr_win->buffer)) + { + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", + ptr_win->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS_CHANNEL); + switch (ptr_win->buffer->type) + { + case BUFFER_TYPE_STANDARD: + wprintw (ptr_win->win_status, _("[not connected] ")); + break; + case BUFFER_TYPE_DCC: + wprintw (ptr_win->win_status, " "); + break; + case BUFFER_TYPE_RAW_DATA: + wprintw (ptr_win->win_status, _(" ")); + break; + } + } + + /* display list of other active windows (if any) with numbers */ + if (hotlist) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "["); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, _("Act: ")); + + names_count = 0; + for (ptr_hotlist = hotlist; ptr_hotlist; + ptr_hotlist = ptr_hotlist->next_hotlist) + { + switch (ptr_hotlist->priority) + { + case HOTLIST_LOW: + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DATA_OTHER); + display_name = ((cfg_look_hotlist_names_level & 1) != 0); + break; + case HOTLIST_MSG: + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DATA_MSG); + display_name = ((cfg_look_hotlist_names_level & 2) != 0); + break; + case HOTLIST_PRIVATE: + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DATA_PRIVATE); + display_name = ((cfg_look_hotlist_names_level & 4) != 0); + break; + case HOTLIST_HIGHLIGHT: + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DATA_HIGHLIGHT); + display_name = ((cfg_look_hotlist_names_level & 8) != 0); + break; + default: + display_name = 0; + break; + } + switch (ptr_hotlist->buffer->type) + { + case BUFFER_TYPE_STANDARD: + wprintw (ptr_win->win_status, "%d", + ptr_hotlist->buffer->number); + + if (display_name && (cfg_look_hotlist_names_count != 0) + && (names_count < cfg_look_hotlist_names_count)) + { + names_count++; + + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + if (cfg_look_hotlist_names_length == 0) + snprintf (format, sizeof (format) - 1, "%%s"); + else + snprintf (format, sizeof (format) - 1, "%%.%ds", cfg_look_hotlist_names_length); + if (BUFFER_IS_SERVER(ptr_hotlist->buffer)) + wprintw (ptr_win->win_status, format, + (ptr_hotlist->server) ? + ptr_hotlist->server->name : + SERVER(ptr_hotlist->buffer)->name); + else if (BUFFER_IS_CHANNEL(ptr_hotlist->buffer) + || BUFFER_IS_PRIVATE(ptr_hotlist->buffer)) + wprintw (ptr_win->win_status, format, CHANNEL(ptr_hotlist->buffer)->name); + } + break; + case BUFFER_TYPE_DCC: + wprintw (ptr_win->win_status, "%d", + ptr_hotlist->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "DCC"); + break; + case BUFFER_TYPE_RAW_DATA: + wprintw (ptr_win->win_status, "%d", + ptr_hotlist->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, _("RAW_IRC")); + break; + } + + if (ptr_hotlist->next_hotlist) + wprintw (ptr_win->win_status, ","); + } + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "] "); + } + + /* display lag */ + if (SERVER(ptr_win->buffer)) + { + if (SERVER(ptr_win->buffer)->lag / 1000 >= cfg_irc_lag_min_show) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "["); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, _("Lag: %.1f"), + ((float)(SERVER(ptr_win->buffer)->lag)) / 1000); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "]"); + } + } + + /* display "-MORE-" (if last line is not displayed) & nicks count */ + if (BUFFER_HAS_NICKLIST(ptr_win->buffer)) + { + snprintf (str_nicks, sizeof (str_nicks) - 1, "%d", CHANNEL(ptr_win->buffer)->nicks_count); + x = ptr_win->win_width - strlen (str_nicks) - 4; + } + else + x = ptr_win->win_width - 2; + more = strdup (_("-MORE-")); + x -= strlen (more) - 1; + if (x < 0) + x = 0; + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS_MORE); + if (ptr_win->scroll) + mvwprintw (ptr_win->win_status, 0, x, "%s", more); + else + { + snprintf (format, sizeof (format) - 1, "%%-%ds", (int)(strlen (more))); + mvwprintw (ptr_win->win_status, 0, x, format, " "); + } + if (BUFFER_HAS_NICKLIST(ptr_win->buffer)) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, " ["); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%s", str_nicks); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "]"); + } + free (more); + + wnoutrefresh (ptr_win->win_status); + refresh (); + } +} diff --git a/src/gui/curses/gui-window.c b/src/gui/curses/gui-window.c new file mode 100644 index 000000000..8cb067234 --- /dev/null +++ b/src/gui/curses/gui-window.c @@ -0,0 +1,1175 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-window.c: window display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + + +/* + * gui_window_curses_clear: clear a Curses window + */ + +void +gui_window_curses_clear (WINDOW *window, int num_color) +{ + if (!gui_ok) + return; + + wbkgdset(window, ' ' | COLOR_PAIR (gui_color_get_pair (num_color))); + werase (window); + wmove (window, 0, 0); +} + +/* + * gui_window_set_weechat_color: set WeeChat color for window + */ + +void +gui_window_set_weechat_color (WINDOW *window, int num_color) +{ + if ((num_color >= 0) && (num_color <= GUI_NUM_COLORS - 1)) + { + wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE); + wattron (window, COLOR_PAIR(gui_color_get_pair (num_color)) | + gui_color[num_color]->attributes); + } +} + +/* + * gui_window_calculate_pos_size: calculate position and size for a buffer & subwindows + * return 1 if pos/size changed, 0 if no change + */ + +int +gui_window_calculate_pos_size (t_gui_window *window, int force_calculate) +{ + int max_length, max_height, lines; + int num_nicks, num_op, num_halfop, num_voice, num_normal; + + if (!gui_ok) + return 0; + + /* init chat & nicklist settings */ + if (cfg_look_nicklist && BUFFER_IS_CHANNEL(window->buffer)) + { + max_length = nick_get_max_length (CHANNEL(window->buffer)); + + lines = 0; + + if ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_LEFT) || + (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_RIGHT)) + { + if ((cfg_look_nicklist_min_size > 0) + && (max_length < cfg_look_nicklist_min_size)) + max_length = cfg_look_nicklist_min_size; + else if ((cfg_look_nicklist_max_size > 0) + && (max_length > cfg_look_nicklist_max_size)) + max_length = cfg_look_nicklist_max_size; + if (!force_calculate && (window->win_nick_width == max_length + 2)) + return 0; + } + else + { + nick_count (CHANNEL(window->buffer), &num_nicks, &num_op, + &num_halfop, &num_voice, &num_normal); + if (((max_length + 2) * num_nicks) % window->win_width == 0) + lines = ((max_length + 2) * num_nicks) / window->win_width; + else + lines = (((max_length + 2) * num_nicks) / window->win_width) + 1; + if ((cfg_look_nicklist_max_size > 0) && (lines > cfg_look_nicklist_max_size)) + lines = cfg_look_nicklist_max_size; + if ((cfg_look_nicklist_min_size > 0) && (lines < cfg_look_nicklist_min_size)) + lines = cfg_look_nicklist_min_size; + max_height = (cfg_look_infobar) ? + window->win_height - 3 - 4 : window->win_height - 2 - 4; + if (lines > max_height) + lines = max_height; + if (!force_calculate && (window->win_nick_height == lines + 1)) + return 0; + } + + switch (cfg_look_nicklist_position) + { + case CFG_LOOK_NICKLIST_LEFT: + window->win_chat_x = window->win_x + max_length + 2; + window->win_chat_y = window->win_y + 1; + window->win_chat_width = window->win_width - max_length - 2; + window->win_nick_x = window->win_x + 0; + window->win_nick_y = window->win_y + 1; + window->win_nick_width = max_length + 2; + if (cfg_look_infobar) + { + window->win_chat_height = window->win_height - 4; + window->win_nick_height = window->win_height - 4; + } + else + { + window->win_chat_height = window->win_height - 3; + window->win_nick_height = window->win_height - 3; + } + window->win_nick_num_max = window->win_nick_height; + break; + case CFG_LOOK_NICKLIST_RIGHT: + window->win_chat_x = window->win_x; + window->win_chat_y = window->win_y + 1; + window->win_chat_width = window->win_width - max_length - 2; + window->win_nick_x = window->win_x + window->win_width - max_length - 2; + window->win_nick_y = window->win_y + 1; + window->win_nick_width = max_length + 2; + if (cfg_look_infobar) + { + window->win_chat_height = window->win_height - 4; + window->win_nick_height = window->win_height - 4; + } + else + { + window->win_chat_height = window->win_height - 3; + window->win_nick_height = window->win_height - 3; + } + window->win_nick_num_max = window->win_nick_height; + break; + case CFG_LOOK_NICKLIST_TOP: + window->win_chat_x = window->win_x; + window->win_chat_y = window->win_y + 1 + (lines + 1); + window->win_chat_width = window->win_width; + if (cfg_look_infobar) + window->win_chat_height = window->win_height - 3 - (lines + 1) - 1; + else + window->win_chat_height = window->win_height - 3 - (lines + 1); + window->win_nick_x = window->win_x; + window->win_nick_y = window->win_y + 1; + window->win_nick_width = window->win_width; + window->win_nick_height = lines + 1; + window->win_nick_num_max = lines * (window->win_nick_width / (max_length + 2)); + break; + case CFG_LOOK_NICKLIST_BOTTOM: + window->win_chat_x = window->win_x; + window->win_chat_y = window->win_y + 1; + window->win_chat_width = window->win_width; + if (cfg_look_infobar) + window->win_chat_height = window->win_height - 3 - (lines + 1) - 1; + else + window->win_chat_height = window->win_height - 3 - (lines + 1); + window->win_nick_x = window->win_x; + if (cfg_look_infobar) + window->win_nick_y = window->win_y + window->win_height - 2 - (lines + 1) - 1; + else + window->win_nick_y = window->win_y + window->win_height - 2 - (lines + 1); + window->win_nick_width = window->win_width; + window->win_nick_height = lines + 1; + window->win_nick_num_max = lines * (window->win_nick_width / (max_length + 2)); + break; + } + + window->win_chat_cursor_x = window->win_x; + window->win_chat_cursor_y = window->win_y; + } + else + { + window->win_chat_x = window->win_x; + window->win_chat_y = window->win_y + 1; + window->win_chat_width = window->win_width; + if (cfg_look_infobar) + window->win_chat_height = window->win_height - 4; + else + window->win_chat_height = window->win_height - 3; + window->win_chat_cursor_x = window->win_x; + window->win_chat_cursor_y = window->win_y; + window->win_nick_x = -1; + window->win_nick_y = -1; + window->win_nick_width = -1; + window->win_nick_height = -1; + window->win_nick_num_max = -1; + } + + return 1; +} + +/* + * gui_window_draw_separator: draw window separation + */ + +void +gui_window_draw_separator (t_gui_window *window) +{ + if (window->win_separator) + delwin (window->win_separator); + + if (window->win_x > 0) + { + window->win_separator = newwin (window->win_height, + 1, + window->win_y, + window->win_x - 1); + gui_window_set_weechat_color (window->win_separator, COLOR_WIN_SEPARATOR); + wborder (window->win_separator, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + wnoutrefresh (window->win_separator); + refresh (); + } +} + +/* + * gui_window_redraw_buffer: redraw a buffer + */ + +void +gui_window_redraw_buffer (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + gui_chat_draw_title (buffer, 1); + gui_chat_draw (buffer, 1); + if (ptr_win->win_nick) + gui_nicklist_draw (buffer, 1); + gui_status_draw (buffer, 1); + if (cfg_look_infobar) + gui_infobar_draw (buffer, 1); + gui_input_draw (buffer, 1); + } + } +} + +/* + * gui_window_switch_to_buffer: switch to another buffer + */ + +void +gui_window_switch_to_buffer (t_gui_window *window, t_gui_buffer *buffer) +{ + if (!gui_ok) + return; + + if (window->buffer->num_displayed > 0) + window->buffer->num_displayed--; + + if (window->buffer != buffer) + { + window->buffer->last_read_line = window->buffer->last_line; + if (buffer->last_read_line == buffer->last_line) + buffer->last_read_line = NULL; + } + + window->buffer = buffer; + window->win_nick_start = 0; + gui_window_calculate_pos_size (window, 1); + + /* destroy Curses windows */ + if (window->win_title) + { + delwin (window->win_title); + window->win_title = NULL; + } + if (window->win_nick) + { + delwin (window->win_nick); + window->win_nick = NULL; + } + if (window->win_status) + { + delwin (window->win_status); + window->win_status = NULL; + } + if (window->win_infobar) + { + delwin (window->win_infobar); + window->win_infobar = NULL; + } + if (window->win_input) + { + delwin (window->win_input); + window->win_input = NULL; + } + + /* create Curses windows */ + window->win_title = newwin (1, + window->win_width, + window->win_y, + window->win_x); + window->win_input = newwin (1, + window->win_width, + window->win_y + window->win_height - 1, + window->win_x); + if (BUFFER_IS_CHANNEL(buffer)) + { + if (window->win_chat) + delwin (window->win_chat); + window->win_chat = newwin (window->win_chat_height, + window->win_chat_width, + window->win_chat_y, + window->win_chat_x); + if (cfg_look_nicklist) + window->win_nick = newwin (window->win_nick_height, + window->win_nick_width, + window->win_nick_y, + window->win_nick_x); + else + window->win_nick = NULL; + } + if (!(BUFFER_IS_CHANNEL(buffer))) + { + if (window->win_chat) + delwin (window->win_chat); + window->win_chat = newwin (window->win_chat_height, + window->win_chat_width, + window->win_chat_y, + window->win_chat_x); + } + + /* create status/infobar windows */ + if (cfg_look_infobar) + { + window->win_infobar = newwin (1, window->win_width, + window->win_y + window->win_height - 2, + window->win_x); + window->win_status = newwin (1, window->win_width, + window->win_y + window->win_height - 3, + window->win_x); + } + else + window->win_status = newwin (1, window->win_width, + window->win_y + window->win_height - 2, + window->win_x); + + window->start_line = NULL; + window->start_line_pos = 0; + + buffer->num_displayed++; + + hotlist_remove_buffer (buffer); +} + +/* + * gui_window_page_up: display previous page on buffer + */ + +void +gui_window_page_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * (window->win_chat_height - 1) : + (-1) * ((window->win_chat_height - 1) * 2)); + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_page_down: display next page on buffer + */ + +void +gui_window_page_down (t_gui_window *window) +{ + t_gui_line *ptr_line; + int line_pos; + + if (!gui_ok) + return; + + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + window->win_chat_height - 1); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_up: display previous few lines in buffer + */ + +void +gui_window_scroll_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * cfg_look_scroll_amount : + (-1) * ( (window->win_chat_height - 1) + cfg_look_scroll_amount)); + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_down: display next few lines in buffer + */ + +void +gui_window_scroll_down (t_gui_window *window) +{ + t_gui_line *ptr_line; + int line_pos; + + if (!gui_ok) + return; + + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + cfg_look_scroll_amount); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_top: scroll to top of buffer + */ + +void +gui_window_scroll_top (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + window->start_line = window->buffer->lines; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_bottom: scroll to bottom of buffer + */ + +void +gui_window_scroll_bottom (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (window->start_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_nick_beginning: go to beginning of nicklist + */ + +void +gui_window_nick_beginning (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if (window->win_nick_start > 0) + { + window->win_nick_start = 0; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_end: go to the end of nicklist + */ + +void +gui_window_nick_end (t_gui_window *window) +{ + int new_start; + + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + new_start = + CHANNEL(window->buffer)->nicks_count - window->win_nick_num_max; + if (new_start < 0) + new_start = 0; + else if (new_start >= 1) + new_start++; + + if (new_start != window->win_nick_start) + { + window->win_nick_start = new_start; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_page_up: scroll one page up in nicklist + */ + +void +gui_window_nick_page_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if (window->win_nick_start > 0) + { + window->win_nick_start -= (window->win_nick_num_max - 1); + if (window->win_nick_start <= 1) + window->win_nick_start = 0; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_page_down: scroll one page down in nicklist + */ + +void +gui_window_nick_page_down (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if ((CHANNEL(window->buffer)->nicks_count > window->win_nick_num_max) + && (window->win_nick_start + window->win_nick_num_max - 1 + < CHANNEL(window->buffer)->nicks_count)) + { + if (window->win_nick_start == 0) + window->win_nick_start += (window->win_nick_num_max - 1); + else + window->win_nick_start += (window->win_nick_num_max - 2); + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_init_subwindows: init subviews for a WeeChat window + */ + +void +gui_window_init_subwindows (t_gui_window *window) +{ + window->win_title = NULL; + window->win_chat = NULL; + window->win_nick = NULL; + window->win_status = NULL; + window->win_infobar = NULL; + window->win_input = NULL; +} + +/* + * gui_window_auto_resize: auto-resize all windows, according to % of global size + * This function is called after a terminal resize. + * Returns 0 if ok, -1 if all window should be merged + * (not enough space according to windows %) + */ + +int +gui_window_auto_resize (t_gui_window_tree *tree, + int x, int y, int width, int height, + int simulate) +{ + int size1, size2; + + if (tree) + { + if (tree->window) + { + if ((width < WINDOW_MIN_WIDTH) || (height < WINDOW_MIN_HEIGHT)) + return -1; + if (!simulate) + { + tree->window->win_x = x; + tree->window->win_y = y; + tree->window->win_width = width; + tree->window->win_height = height; + } + } + else + { + if (tree->split_horiz) + { + size1 = (height * tree->split_pct) / 100; + size2 = height - size1; + if (gui_window_auto_resize (tree->child1, x, y + size1, + width, size2, simulate) < 0) + return -1; + if (gui_window_auto_resize (tree->child2, x, y, + width, size1, simulate) < 0) + return -1; + } + else + { + size1 = (width * tree->split_pct) / 100; + size2 = width - size1 - 1; + if (gui_window_auto_resize (tree->child1, x, y, + size1, height, simulate) < 0) + return -1; + if (gui_window_auto_resize (tree->child2, x + size1 + 1, y, + size2, height, simulate) < 0) + return -1; + } + } + } + return 0; +} + +/* + * gui_window_refresh_windows: auto resize and refresh all windows + */ + +void +gui_window_refresh_windows () +{ + t_gui_window *ptr_win, *old_current_window; + + if (gui_ok) + { + old_current_window = gui_current_window; + + if (gui_window_auto_resize (gui_windows_tree, 0, 0, COLS, LINES, 0) < 0) + gui_window_merge_all (gui_current_window); + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + gui_window_switch_to_buffer (ptr_win, ptr_win->buffer); + gui_window_redraw_buffer (ptr_win->buffer); + gui_window_draw_separator (ptr_win); + } + + gui_current_window = old_current_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + } +} + +/* + * gui_window_split_horiz: split a window horizontally + */ + +void +gui_window_split_horiz (t_gui_window *window, int pourcentage) +{ + t_gui_window *new_window; + int height1, height2; + + if (!gui_ok) + return; + + height1 = (window->win_height * pourcentage) / 100; + height2 = window->win_height - height1; + + if ((height1 >= WINDOW_MIN_HEIGHT) && (height2 >= WINDOW_MIN_HEIGHT) + && (pourcentage > 0) && (pourcentage <= 100)) + { + if ((new_window = gui_window_new (window, + window->win_x, window->win_y, + window->win_width, height1, + 100, pourcentage))) + { + /* reduce old window height (bottom window) */ + window->win_y = new_window->win_y + new_window->win_height; + window->win_height = height2; + window->win_height_pct = 100 - pourcentage; + + /* assign same buffer for new window (top window) */ + new_window->buffer = window->buffer; + new_window->buffer->num_displayed++; + + gui_window_switch_to_buffer (window, window->buffer); + + gui_current_window = new_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + } + } +} + +/* + * gui_window_split_vertic: split a window vertically + */ + +void +gui_window_split_vertic (t_gui_window *window, int pourcentage) +{ + t_gui_window *new_window; + int width1, width2; + + if (!gui_ok) + return; + + width1 = (window->win_width * pourcentage) / 100; + width2 = window->win_width - width1 - 1; + + if ((width1 >= WINDOW_MIN_WIDTH) && (width2 >= WINDOW_MIN_WIDTH) + && (pourcentage > 0) && (pourcentage <= 100)) + { + if ((new_window = gui_window_new (window, + window->win_x + width1 + 1, window->win_y, + width2, window->win_height, + pourcentage, 100))) + { + /* reduce old window height (left window) */ + window->win_width = width1; + window->win_width_pct = 100 - pourcentage; + + /* assign same buffer for new window (right window) */ + new_window->buffer = window->buffer; + new_window->buffer->num_displayed++; + + gui_window_switch_to_buffer (window, window->buffer); + + gui_current_window = new_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + + /* create & draw separator */ + gui_window_draw_separator (gui_current_window); + } + } +} + +/* + * gui_window_resize: resize window + */ + +void +gui_window_resize (t_gui_window *window, int pourcentage) +{ + t_gui_window_tree *parent; + int old_split_pct; + + parent = window->ptr_tree->parent_node; + if (parent) + { + old_split_pct = parent->split_pct; + if (((parent->split_horiz) && (window->ptr_tree == parent->child2)) + || ((!(parent->split_horiz)) && (window->ptr_tree == parent->child1))) + parent->split_pct = pourcentage; + else + parent->split_pct = 100 - pourcentage; + if (gui_window_auto_resize (gui_windows_tree, 0, 0, COLS, LINES, 1) < 0) + parent->split_pct = old_split_pct; + else + gui_window_refresh_windows (); + } +} + +/* + * gui_window_merge: merge window with its sister + */ + +int +gui_window_merge (t_gui_window *window) +{ + t_gui_window_tree *parent, *sister; + + parent = window->ptr_tree->parent_node; + if (parent) + { + sister = (parent->child1->window == window) ? + parent->child2 : parent->child1; + + if (!(sister->window)) + return 0; + + if (window->win_y == sister->window->win_y) + { + /* horizontal merge */ + window->win_width += sister->window->win_width + 1; + window->win_width_pct += sister->window->win_width_pct; + } + else + { + /* vertical merge */ + window->win_height += sister->window->win_height; + window->win_height_pct += sister->window->win_height_pct; + } + if (sister->window->win_x < window->win_x) + window->win_x = sister->window->win_x; + if (sister->window->win_y < window->win_y) + window->win_y = sister->window->win_y; + + gui_window_free (sister->window); + gui_window_tree_node_to_leaf (parent, window); + + gui_window_switch_to_buffer (window, window->buffer); + gui_window_redraw_buffer (window->buffer); + return 1; + } + return 0; +} + +/* + * gui_window_merge_all: merge all windows into only one + */ + +void +gui_window_merge_all (t_gui_window *window) +{ + while (gui_windows->next_window) + { + gui_window_free ((gui_windows == window) ? gui_windows->next_window : gui_windows); + } + gui_window_tree_free (&gui_windows_tree); + gui_window_tree_init (window); + window->ptr_tree = gui_windows_tree; + window->win_x = 0; + window->win_y = 0; + window->win_width = COLS; + window->win_height = LINES; + window->win_width_pct = 100; + window->win_height_pct = 100; + gui_window_switch_to_buffer (window, window->buffer); + gui_window_redraw_buffer (window->buffer); +} + +/* + * gui_window_side_by_side: return a code about position of 2 windows: + * 0 = they're not side by side + * 1 = side by side (win2 is over the win1) + * 2 = side by side (win2 on the right) + * 3 = side by side (win2 below win1) + * 4 = side by side (win2 on the left) + */ + +int +gui_window_side_by_side (t_gui_window *win1, t_gui_window *win2) +{ + /* win2 over win1 ? */ + if (win2->win_y + win2->win_height == win1->win_y) + { + if (win2->win_x >= win1->win_x + win1->win_width) + return 0; + if (win2->win_x + win2->win_width <= win1->win_x) + return 0; + return 1; + } + + /* win2 on the right ? */ + if (win2->win_x == win1->win_x + win1->win_width + 1) + { + if (win2->win_y >= win1->win_y + win1->win_height) + return 0; + if (win2->win_y + win2->win_height <= win1->win_y) + return 0; + return 2; + } + + /* win2 below win1 ? */ + if (win2->win_y == win1->win_y + win1->win_height) + { + if (win2->win_x >= win1->win_x + win1->win_width) + return 0; + if (win2->win_x + win2->win_width <= win1->win_x) + return 0; + return 3; + } + + /* win2 on the left ? */ + if (win2->win_x + win2->win_width + 1 == win1->win_x) + { + if (win2->win_y >= win1->win_y + win1->win_height) + return 0; + if (win2->win_y + win2->win_height <= win1->win_y) + return 0; + return 4; + } + + return 0; +} + +/* + * gui_window_switch_up: search and switch to a window over current window + */ + +void +gui_window_switch_up (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 1)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_down: search and switch to a window below current window + */ + +void +gui_window_switch_down (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 3)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_left: search and switch to a window on the left of current window + */ + +void +gui_window_switch_left (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 4)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_right: search and switch to a window on the right of current window + */ + +void +gui_window_switch_right (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 2)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_refresh_screen: called when term size is modified + */ + +void +gui_window_refresh_screen () +{ + int new_height, new_width; + + endwin (); + refresh (); + + getmaxyx (stdscr, new_height, new_width); + + gui_ok = ((new_width > WINDOW_MIN_WIDTH) && (new_height > WINDOW_MIN_HEIGHT)); + + if (gui_ok) + gui_window_refresh_windows (); +} + +/* + * gui_window_refresh_screen_sigwinch: called when signal SIGWINCH is received + */ + +void +gui_window_refresh_screen_sigwinch () +{ + gui_window_refresh_screen (); + signal (SIGWINCH, gui_window_refresh_screen_sigwinch); +} + +/* + * gui_window_set_title: set terminal title + */ + +void +gui_window_set_title () +{ + char *envterm = getenv ("TERM"); + + if (envterm) + { + if (strcmp( envterm, "sun-cmd") == 0) + printf ("\033]l%s %s\033\\", PACKAGE_NAME, PACKAGE_VERSION); + else if (strcmp(envterm, "hpterm") == 0) + printf ("\033&f0k%dD%s %s", strlen(PACKAGE_NAME) + + strlen(PACKAGE_VERSION) + 1, + PACKAGE_NAME, PACKAGE_VERSION); + /* the following term supports the xterm excapes */ + else if (strncmp (envterm, "xterm", 5) == 0 + || strncmp (envterm, "rxvt", 4) == 0 + || strcmp (envterm, "Eterm") == 0 + || strcmp (envterm, "aixterm") == 0 + || strcmp (envterm, "iris-ansi") == 0 + || strcmp (envterm, "dtterm") == 0) + printf ("\33]0;%s %s\7", PACKAGE_NAME, PACKAGE_VERSION); + else if (strcmp (envterm, "screen") == 0) + { + printf ("\033k%s %s\033\\", PACKAGE_NAME, PACKAGE_VERSION); + /* tryning to set the title of a backgrounded xterm like terminal */ + printf ("\33]0;%s %s\7", PACKAGE_NAME, PACKAGE_VERSION); + } + } +} + +/* + * gui_window_reset_title: reset terminal title + */ + +void +gui_window_reset_title () +{ + char *envterm = getenv ("TERM"); + char *envshell = getenv ("SHELL"); + + if (envterm) + { + if (strcmp( envterm, "sun-cmd") == 0) + printf ("\033]l%s\033\\", "Terminal"); + else if (strcmp( envterm, "hpterm") == 0) + printf ("\033&f0k%dD%s", strlen("Terminal"), "Terminal"); + /* the following term supports the xterm excapes */ + else if (strncmp (envterm, "xterm", 5) == 0 + || strncmp (envterm, "rxvt", 4) == 0 + || strcmp (envterm, "Eterm") == 0 + || strcmp( envterm, "aixterm") == 0 + || strcmp( envterm, "iris-ansi") == 0 + || strcmp( envterm, "dtterm") == 0) + printf ("\33]0;%s\7", "Terminal"); + else if (strcmp (envterm, "screen") == 0) + { + char *shell, *shellname; + if (envshell) + { + shell = strdup (envterm); + shellname = basename(shell); + if (shell) + { + printf ("\033k%s\033\\", shellname); + free (shell); + } + else + printf ("\033k%s\033\\", envterm); + } + else + printf ("\033k%s\033\\", envterm); + /* tryning to reset the title of a backgrounded xterm like terminal */ + printf ("\33]0;%s\7", "Terminal"); + } + } +} diff --git a/src/gui/gtk/Makefile.am b/src/gui/gtk/Makefile.am index 655a03d40..46b5667dd 100644 --- a/src/gui/gtk/Makefile.am +++ b/src/gui/gtk/Makefile.am @@ -20,7 +20,8 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GTK_CFLAGS) bin_PROGRAMS = weechat-gtk if PLUGINS -weechat_gtk_LDADD = ../gui-common.o ../gui-keyboard.o \ +weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \ + ../gui-window.o ../gui-keyboard.o \ ../gui-action.o \ ../../common/lib_weechat_main.a \ ../../irc/lib_weechat_irc.a \ @@ -29,7 +30,8 @@ weechat_gtk_LDADD = ../gui-common.o ../gui-keyboard.o \ $(GTK_LIBS) \ $(GNUTLS_LFLAGS) else -weechat_gtk_LDADD = ../gui-common.o ../gui-keyboard.o \ +weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \ + ../gui-window.o ../gui-keyboard.o \ ../gui-action.o \ ../../common/lib_weechat_main.a \ ../../irc/lib_weechat_irc.a \ @@ -38,5 +40,13 @@ weechat_gtk_LDADD = ../gui-common.o ../gui-keyboard.o \ $(GNUTLS_LFLAGS) endif -weechat_gtk_SOURCES = gui-display.c \ - gui-input.c +weechat_gtk_SOURCES = gui-chat.c \ + gui-color.c \ + gui-infobar.c \ + gui-input.c \ + gui-keyboard.c \ + gui-main.c \ + gui-nicklist.c \ + gui-status.c \ + gui-window.c \ + gui-gtk.h diff --git a/src/gui/gtk/gui-chat.c b/src/gui/gtk/gui-chat.c new file mode 100644 index 000000000..6773bcd33 --- /dev/null +++ b/src/gui/gtk/gui-chat.c @@ -0,0 +1,633 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-chat.c: chat display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/utf8.h" +#include "../../common/weeconfig.h" +#include "../../irc/irc.h" +#include "gui-gtk.h" + + +/* + * gui_chat_set_style: set style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_set_style (t_gui_window *window, int style) +{ + /* TODO: write this function for Gtk */ + /*wattron (window->win_chat, style);*/ + (void) window; + (void) style; +} + +/* + * gui_chat_remove_style: remove style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_remove_style (t_gui_window *window, int style) +{ + /* TODO: write this function for Gtk */ + /*wattroff (window->win_chat, style);*/ + (void) window; + (void) style; +} + +/* + * gui_chat_toggle_style: toggle a style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_toggle_style (t_gui_window *window, int style) +{ + window->current_style_attr ^= style; + if (window->current_style_attr & style) + gui_chat_set_style (window, style); + else + gui_chat_remove_style (window, style); +} + +/* + * gui_chat_reset_style: reset style (color and attr) + * for a chat window + */ + +void +gui_chat_reset_style (t_gui_window *window) +{ + window->current_style_fg = -1; + window->current_style_bg = -1; + window->current_style_attr = 0; + window->current_color_attr = 0; + + /* TODO: change following function call */ + /*gui_window_set_weechat_color (window->win_chat, COLOR_WIN_CHAT);*/ + gui_chat_remove_style (window, + A_BOLD | A_UNDERLINE | A_REVERSE); +} + +/* + * gui_chat_set_color_style: set style for color + */ + +void +gui_chat_set_color_style (t_gui_window *window, int style) +{ + window->current_color_attr |= style; + /* TODO: change following function call */ + /*wattron (window->win_chat, style);*/ +} + +/* + * gui_chat_remove_color_style: remove style for color + */ + +void +gui_chat_remove_color_style (t_gui_window *window, int style) +{ + window->current_color_attr &= !style; + /* TODO: change following function call */ + /*wattroff (window->win_chat, style);*/ +} + +/* + * gui_chat_reset_color_style: reset style for color + */ + +void +gui_chat_reset_color_style (t_gui_window *window) +{ + /* TODO: change following function call */ + /*wattroff (window->win_chat, window->current_color_attr);*/ + window->current_color_attr = 0; +} + +/* + * gui_chat_set_color: set color for a chat window + */ + +void +gui_chat_set_color (t_gui_window *window, int fg, int bg) +{ + /* TODO: write this function for Gtk */ + /*if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + wattron (window->win_chat, COLOR_PAIR(63)); + else + { + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + wattron (window->win_chat, COLOR_PAIR((bg * 8) + fg)); + }*/ + (void) window; + (void) fg; + (void) bg; +} + +/* + * gui_chat_set_weechat_color: set a WeeChat color for a chat window + */ + +void +gui_chat_set_weechat_color (t_gui_window *window, int weechat_color) +{ + gui_chat_reset_style (window); + gui_chat_set_style (window, + gui_color[weechat_color]->attributes); + gui_chat_set_color (window, + gui_color[weechat_color]->foreground, + gui_color[weechat_color]->background); +} + +/* + * gui_chat_draw_title: draw title window for a buffer + */ + +void +gui_chat_draw_title (t_gui_buffer *buffer, int erase) +{ + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} + +/* + * gui_chat_word_get_next_char: returns next char of a word + * special chars like colors, bold, .. are skipped + */ + +char * +gui_chat_word_get_next_char (t_gui_window *window, unsigned char *string, int apply_style) +{ + char str_fg[3], str_bg[3]; + int fg, bg, weechat_color; + + while (string[0]) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_BOLD); + break; + case GUI_ATTR_COLOR_CHAR: + string++; + str_fg[0] = '\0'; + str_bg[0] = '\0'; + fg = 99; + bg = 99; + if (isdigit (string[0])) + { + str_fg[0] = string[0]; + str_fg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_fg[1] = string[0]; + str_fg[2] = '\0'; + string++; + } + } + if (string[0] == ',') + { + string++; + if (isdigit (string[0])) + { + str_bg[0] = string[0]; + str_bg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_bg[1] = string[0]; + str_bg[2] = '\0'; + string++; + } + } + } + if (apply_style) + { + if (str_fg[0] || str_bg[0]) + { + if (str_fg[0]) + sscanf (str_fg, "%d", &fg); + else + fg = window->current_style_fg; + if (str_bg[0]) + sscanf (str_bg, "%d", &bg); + else + bg = window->current_style_bg; + } + if (!str_fg[0] && !str_bg[0]) + gui_chat_reset_color_style (window); + window->current_style_fg = fg; + window->current_style_bg = bg; + gui_chat_set_color (window, fg, bg); + } + break; + case GUI_ATTR_RESET_CHAR: + string++; + if (apply_style) + gui_chat_reset_style (window); + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_REVERSE); + break; + case GUI_ATTR_WEECHAT_COLOR_CHAR: + string++; + if (isdigit (string[0]) && isdigit (string[1])) + { + str_fg[0] = string[0]; + str_fg[1] = string[1]; + str_fg[2] = '\0'; + string += 2; + if (apply_style) + { + sscanf (str_fg, "%d", &weechat_color); + gui_chat_set_weechat_color (window, weechat_color); + } + } + break; + case GUI_ATTR_WEECHAT_SET_CHAR: + string++; + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_BOLD); + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_REVERSE); + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_UNDERLINE); + break; + } + break; + case GUI_ATTR_WEECHAT_REMOVE_CHAR: + string++; + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_BOLD); + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_REVERSE); + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_UNDERLINE); + break; + } + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_UNDERLINE); + break; + default: + if (string[0] < 32) + string++; + else + return utf8_next_char ((char *)string); + } + + } + + /* nothing found except color/attrib codes, so return NULL */ + return NULL; +} + +/* + * gui_chat_display_word_raw: display word on chat buffer, letter by letter + * special chars like color, bold, .. are interpreted + */ + +void +gui_chat_display_word_raw (t_gui_window *window, char *string) +{ + /*char *prev_char, *next_char, saved_char;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) string; +} + +/* + * gui_chat_display_word: display a word on chat buffer + */ + +void +gui_chat_display_word (t_gui_window *window, + t_gui_line *line, + char *data, + char *end_offset, + int num_lines, int count, int *lines_displayed, int simulate) +{ + /*char *end_line, saved_char_end, saved_char; + int pos_saved_char, chars_to_display, num_displayed;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) line; + (void) data; + (void) end_offset; + (void) num_lines; + (void) count; + (void) lines_displayed; + (void) simulate; +} + +/* + * gui_chat_get_word_info: returns info about next word: beginning, end, length + */ + +void +gui_chat_get_word_info (t_gui_window *window, + char *data, + int *word_start_offset, int *word_end_offset, + int *word_length_with_spaces, int *word_length) +{ + char *start_data, *prev_char, *next_char; + int leading_spaces, char_size; + + *word_start_offset = 0; + *word_end_offset = 0; + *word_length_with_spaces = 0; + *word_length = 0; + + start_data = data; + + leading_spaces = 1; + while (data && data[0]) + { + next_char = gui_chat_word_get_next_char (window, (unsigned char *)data, 0); + if (next_char) + { + prev_char = utf8_prev_char (data, next_char); + if (prev_char) + { + if (prev_char[0] != ' ') + { + if (leading_spaces) + *word_start_offset = prev_char - start_data; + leading_spaces = 0; + char_size = next_char - prev_char; + *word_end_offset = next_char - start_data - 1; + (*word_length_with_spaces) += char_size; + (*word_length) += char_size; + } + else + { + if (leading_spaces) + (*word_length_with_spaces)++; + else + { + *word_end_offset = prev_char - start_data - 1; + return; + } + } + data = next_char; + } + } + else + { + *word_end_offset = data + strlen (data) - start_data - 1; + return; + } + } +} + +/* + * gui_chat_display_line: display a line in the chat window + * if count == 0, display whole line + * if count > 0, display 'count' lines (beginning from the end) + * if simulate == 1, nothing is displayed (for counting how + * many lines would have been lines displayed) + * returns: number of lines displayed (or simulated) + */ + +int +gui_chat_display_line (t_gui_window *window, t_gui_line *line, int count, + int simulate) +{ + /* TODO: write this function for Gtk */ + (void) window; + (void) line; + (void) count; + (void) simulate; + return 1; +} + +/* + * gui_chat_calculate_line_diff: returns pointer to line & offset for a difference + * with given line + */ + +void +gui_chat_calculate_line_diff (t_gui_window *window, t_gui_line **line, + int *line_pos, int difference) +{ + int backward, current_size; + + if (!line || !line_pos) + return; + + backward = (difference < 0); + + if (!(*line)) + { + /* if looking backward, start at last line of buffer */ + if (backward) + { + *line = window->buffer->last_line; + if (!(*line)) + return; + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = current_size - 1; + } + /* if looking forward, start at first line of buffer */ + else + { + *line = window->buffer->lines; + if (!(*line)) + return; + *line_pos = 0; + current_size = gui_chat_display_line (window, *line, 0, 1); + } + } + else + current_size = gui_chat_display_line (window, *line, 0, 1); + + while ((*line) && (difference != 0)) + { + /* looking backward */ + if (backward) + { + if (*line_pos > 0) + (*line_pos)--; + else + { + *line = (*line)->prev_line; + if (*line) + { + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = current_size - 1; + } + } + difference++; + } + /* looking forward */ + else + { + if (*line_pos < current_size - 1) + (*line_pos)++; + else + { + *line = (*line)->next_line; + if (*line) + { + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = 0; + } + } + difference--; + } + } + + /* first or last line reached */ + if (!(*line)) + { + if (backward) + { + /* first line reached */ + *line = window->buffer->lines; + *line_pos = 0; + } + else + { + /* last line reached => consider we'll display all until the end */ + *line_pos = 0; + } + } +} + +/* + * gui_chat_draw: draw chat window for a buffer + */ + +void +gui_chat_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + t_gui_line *ptr_line; + t_irc_dcc *dcc_first, *dcc_selected, *ptr_dcc; + char format_empty[32]; + int i, j, line_pos, count, num_bars; + char *unit_name[] = { N_("bytes"), N_("Kb"), N_("Mb"), N_("Gb") }; + char *unit_format[] = { "%.0Lf", "%.1Lf", "%.02Lf", "%.02Lf" }; + long unit_divide[] = { 1, 1024, 1024*1024, 1024*1024,1024 }; + int num_unit; + char format[32], date[128], *buf; + struct tm *date_tmp;*/ + + if (!gui_ok) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} + +/* + * gui_chat_draw_line: add a line to chat window for a buffer + */ + +void +gui_chat_draw_line (t_gui_buffer *buffer, t_gui_line *line) +{ + t_gui_window *ptr_win; + unsigned char *text_without_color; + GtkTextIter start, end; + + ptr_win = gui_buffer_find_window (buffer); + if (ptr_win) + { + text_without_color = gui_color_decode ((unsigned char *)(line->data), 0); + if (text_without_color) + { + gtk_text_buffer_insert_at_cursor (ptr_win->textbuffer_chat, + (char *)text_without_color, -1); + gtk_text_buffer_insert_at_cursor (ptr_win->textbuffer_chat, + "\n", -1); + gtk_text_buffer_get_bounds (ptr_win->textbuffer_chat, + &start, &end); + /* TODO */ + /*gtk_text_buffer_apply_tag (ptr_win->textbuffer_chat, ptr_win->texttag_chat, &start, &end);*/ + free (text_without_color); + } + } +} diff --git a/src/gui/gtk/gui-color.c b/src/gui/gtk/gui-color.c new file mode 100644 index 000000000..852a2af5b --- /dev/null +++ b/src/gui/gtk/gui-color.c @@ -0,0 +1,580 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-color.c: color functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + + +t_gui_color gui_weechat_colors[] = +{ { -1, 0, 0, "default" }, + { WEECHAT_COLOR_BLACK, 0, 0, "black" }, + { WEECHAT_COLOR_RED, 0, 0, "red" }, + { WEECHAT_COLOR_RED, 0, A_BOLD, "lightred" }, + { WEECHAT_COLOR_GREEN, 0, 0, "green" }, + { WEECHAT_COLOR_GREEN, 0, A_BOLD, "lightgreen" }, + { WEECHAT_COLOR_YELLOW, 0, 0, "brown" }, + { WEECHAT_COLOR_YELLOW, 0, A_BOLD, "yellow" }, + { WEECHAT_COLOR_BLUE, 0, 0, "blue" }, + { WEECHAT_COLOR_BLUE, 0, A_BOLD, "lightblue" }, + { WEECHAT_COLOR_MAGENTA, 0, 0, "magenta" }, + { WEECHAT_COLOR_MAGENTA, 0, A_BOLD, "lightmagenta" }, + { WEECHAT_COLOR_CYAN, 0, 0, "cyan" }, + { WEECHAT_COLOR_CYAN, 0, A_BOLD, "lightcyan" }, + { WEECHAT_COLOR_WHITE, 0, A_BOLD, "white" }, + { 0, 0, 0, NULL } +}; + +int gui_irc_colors[GUI_NUM_IRC_COLORS][2] = +{ { /* 0 */ WEECHAT_COLOR_WHITE, A_BOLD }, + { /* 1 */ WEECHAT_COLOR_BLACK, 0 }, + { /* 2 */ WEECHAT_COLOR_BLUE, 0 }, + { /* 3 */ WEECHAT_COLOR_GREEN, 0 }, + { /* 4 */ WEECHAT_COLOR_RED, A_BOLD }, + { /* 5 */ WEECHAT_COLOR_RED, 0 }, + { /* 6 */ WEECHAT_COLOR_MAGENTA, 0 }, + { /* 7 */ WEECHAT_COLOR_YELLOW, 0 }, + { /* 8 */ WEECHAT_COLOR_YELLOW, A_BOLD }, + { /* 9 */ WEECHAT_COLOR_GREEN, A_BOLD }, + { /* 10 */ WEECHAT_COLOR_CYAN, 0 }, + { /* 11 */ WEECHAT_COLOR_CYAN, A_BOLD }, + { /* 12 */ WEECHAT_COLOR_BLUE, A_BOLD }, + { /* 13 */ WEECHAT_COLOR_MAGENTA, A_BOLD }, + { /* 14 */ WEECHAT_COLOR_WHITE, 0 }, + { /* 15 */ WEECHAT_COLOR_WHITE, A_BOLD } +}; + +t_gui_color *gui_color[GUI_NUM_COLORS]; + + +/* + * gui_color_assign: assign a WeeChat color (read from config) + */ + +int +gui_color_assign (int *color, char *color_name) +{ + int i; + + /* look for curses colors in table */ + i = 0; + while (gui_weechat_colors[i].string) + { + if (ascii_strcasecmp (gui_weechat_colors[i].string, color_name) == 0) + { + *color = i; + return 1; + } + i++; + } + + /* color not found */ + return 0; +} + +/* + * gui_color_get_name: get color name + */ + +char * +gui_color_get_name (int num_color) +{ + return gui_weechat_colors[num_color].string; +} + +/* + * gui_color_decode: parses a message (coming from IRC server), + * and according: + * - remove any color/style in message + * or: + * - change colors by codes to be compatible with + * other IRC clients + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode (unsigned char *string, int keep_colors) +{ + unsigned char *out; + int out_length, out_pos; + char str_fg[3], str_bg[3]; + int fg, bg, attr; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + case GUI_ATTR_RESET_CHAR: + case GUI_ATTR_FIXED_CHAR: + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + case GUI_ATTR_ITALIC_CHAR: + case GUI_ATTR_UNDERLINE_CHAR: + if (keep_colors) + out[out_pos++] = string[0]; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + string++; + str_fg[0] = '\0'; + str_bg[0] = '\0'; + if (isdigit (string[0])) + { + str_fg[0] = string[0]; + str_fg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_fg[1] = string[0]; + str_fg[2] = '\0'; + string++; + } + } + if (string[0] == ',') + { + string++; + if (isdigit (string[0])) + { + str_bg[0] = string[0]; + str_bg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_bg[1] = string[0]; + str_bg[2] = '\0'; + string++; + } + } + } + if (keep_colors) + { + if (!str_fg[0] && !str_bg[0]) + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + else + { + attr = 0; + if (str_fg[0]) + { + sscanf (str_fg, "%d", &fg); + fg %= 16; + attr |= gui_irc_colors[fg][1]; + } + if (str_bg[0]) + { + sscanf (str_bg, "%d", &bg); + bg %= 16; + attr |= gui_irc_colors[bg][1]; + } + if (attr & A_BOLD) + { + out[out_pos++] = GUI_ATTR_WEECHAT_SET_CHAR; + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + } + else + { + out[out_pos++] = GUI_ATTR_WEECHAT_REMOVE_CHAR; + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + } + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + if (str_fg[0]) + { + out[out_pos++] = (gui_irc_colors[fg][0] / 10) + '0'; + out[out_pos++] = (gui_irc_colors[fg][0] % 10) + '0'; + } + if (str_bg[0]) + { + out[out_pos++] = ','; + out[out_pos++] = (gui_irc_colors[bg][0] / 10) + '0'; + out[out_pos++] = (gui_irc_colors[bg][0] % 10) + '0'; + } + } + } + break; + case GUI_ATTR_WEECHAT_COLOR_CHAR: + string++; + if (isdigit (string[0]) && isdigit (string[1])) + { + if (keep_colors) + { + out[out_pos++] = string[0]; + out[out_pos++] = string[1]; + } + string += 2; + } + break; + case GUI_ATTR_WEECHAT_SET_CHAR: + case GUI_ATTR_WEECHAT_REMOVE_CHAR: + string++; + if (string[0]) + { + if (keep_colors) + { + out[out_pos++] = *(string - 1); + out[out_pos++] = string[0]; + } + string++; + } + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_decode_for_user_entry: parses a message (coming from IRC server), + * and replaces colors/bold/.. by %C, %B, .. + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode_for_user_entry (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'B'; + string++; + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_RESET_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'O'; + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'C'; + string++; + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_encode: parses a message (entered by user), and + * encode special chars (%B, %C, ..) in IRC colors + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_encode (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case '%': + string++; + switch (string[0]) + { + case '\0': + out[out_pos++] = '%'; + break; + case '%': /* double '%' replaced by single '%' */ + out[out_pos++] = string[0]; + string++; + break; + case 'B': /* bold */ + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + string++; + break; + case 'C': /* color */ + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + } + } + if (string[0] == ',') + { + out[out_pos++] = ','; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + } + } + } + break; + case 'O': /* reset */ + out[out_pos++] = GUI_ATTR_RESET_CHAR; + string++; + break; + case 'R': /* reverse */ + out[out_pos++] = GUI_ATTR_REVERSE_CHAR; + string++; + break; + case 'U': /* underline */ + out[out_pos++] = GUI_ATTR_UNDERLINE_CHAR; + string++; + break; + default: + out[out_pos++] = '%'; + out[out_pos++] = string[0]; + string++; + } + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_build: build a WeeChat color with foreground, + * background and attributes (attributes are + * given with foreground color, with a OR) + */ + +t_gui_color * +gui_color_build (int number, int foreground, int background) +{ + t_gui_color *new_color; + + new_color = (t_gui_color *)malloc (sizeof (t_gui_color)); + if (!new_color) + return NULL; + + new_color->foreground = gui_weechat_colors[foreground].foreground; + new_color->background = gui_weechat_colors[background].foreground; + new_color->attributes = gui_weechat_colors[foreground].attributes; + new_color->string = (char *)malloc (4); + if (new_color->string) + snprintf (new_color->string, 4, + "%s%02d", + GUI_ATTR_WEECHAT_COLOR_STR, number); + + return new_color; +} + +/* + * gui_color_get_pair: get color pair with a WeeChat color number + */ + +int +gui_color_get_pair (int num_color) +{ + int fg, bg; + + if ((num_color < 0) || (num_color > GUI_NUM_COLORS - 1)) + return WEECHAT_COLOR_WHITE; + + fg = gui_color[num_color]->foreground; + bg = gui_color[num_color]->background; + + if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + return 63; + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + + return (bg * 8) + fg; +} + +/* + * gui_color_init_pairs: init color pairs + */ + +void +gui_color_init_pairs () +{ + /* This function does nothing in Gtk GUI */ +} + +/* + * gui_color_init_weechat: init WeeChat colors + */ + +void +gui_color_init_weechat () +{ + int i; + + gui_color[COLOR_WIN_SEPARATOR] = gui_color_build (COLOR_WIN_SEPARATOR, cfg_col_separator, cfg_col_separator); + gui_color[COLOR_WIN_TITLE] = gui_color_build (COLOR_WIN_TITLE, cfg_col_title, cfg_col_title_bg); + gui_color[COLOR_WIN_CHAT] = gui_color_build (COLOR_WIN_CHAT, cfg_col_chat, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_TIME] = gui_color_build (COLOR_WIN_CHAT_TIME, cfg_col_chat_time, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_TIME_SEP] = gui_color_build (COLOR_WIN_CHAT_TIME_SEP, cfg_col_chat_time_sep, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PREFIX1] = gui_color_build (COLOR_WIN_CHAT_PREFIX1, cfg_col_chat_prefix1, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PREFIX2] = gui_color_build (COLOR_WIN_CHAT_PREFIX2, cfg_col_chat_prefix2, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_SERVER] = gui_color_build (COLOR_WIN_CHAT_SERVER, cfg_col_chat_server, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_JOIN] = gui_color_build (COLOR_WIN_CHAT_JOIN, cfg_col_chat_join, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PART] = gui_color_build (COLOR_WIN_CHAT_PART, cfg_col_chat_part, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_NICK] = gui_color_build (COLOR_WIN_CHAT_NICK, cfg_col_chat_nick, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_HOST] = gui_color_build (COLOR_WIN_CHAT_HOST, cfg_col_chat_host, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_CHANNEL] = gui_color_build (COLOR_WIN_CHAT_CHANNEL, cfg_col_chat_channel, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_DARK] = gui_color_build (COLOR_WIN_CHAT_DARK, cfg_col_chat_dark, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_HIGHLIGHT] = gui_color_build (COLOR_WIN_CHAT_HIGHLIGHT, cfg_col_chat_highlight, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_READ_MARKER] = gui_color_build (COLOR_WIN_CHAT_READ_MARKER, cfg_col_chat_read_marker, cfg_col_chat_read_marker_bg); + gui_color[COLOR_WIN_STATUS] = gui_color_build (COLOR_WIN_STATUS, cfg_col_status, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DELIMITERS] = gui_color_build (COLOR_WIN_STATUS_DELIMITERS, cfg_col_status_delimiters, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_CHANNEL] = gui_color_build (COLOR_WIN_STATUS_CHANNEL, cfg_col_status_channel, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_MSG] = gui_color_build (COLOR_WIN_STATUS_DATA_MSG, cfg_col_status_data_msg, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_PRIVATE] = gui_color_build (COLOR_WIN_STATUS_DATA_PRIVATE, cfg_col_status_data_private, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_HIGHLIGHT] = gui_color_build (COLOR_WIN_STATUS_DATA_HIGHLIGHT, cfg_col_status_data_highlight, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_OTHER] = gui_color_build (COLOR_WIN_STATUS_DATA_OTHER, cfg_col_status_data_other, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_MORE] = gui_color_build (COLOR_WIN_STATUS_MORE, cfg_col_status_more, cfg_col_status_bg); + gui_color[COLOR_WIN_INFOBAR] = gui_color_build (COLOR_WIN_INFOBAR, cfg_col_infobar, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INFOBAR_DELIMITERS] = gui_color_build (COLOR_WIN_INFOBAR_DELIMITERS, cfg_col_infobar_delimiters, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INFOBAR_HIGHLIGHT] = gui_color_build (COLOR_WIN_INFOBAR_HIGHLIGHT, cfg_col_infobar_highlight, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INPUT] = gui_color_build (COLOR_WIN_INPUT, cfg_col_input, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_CHANNEL] = gui_color_build (COLOR_WIN_INPUT_CHANNEL, cfg_col_input_channel, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_NICK] = gui_color_build (COLOR_WIN_INPUT_NICK, cfg_col_input_nick, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_DELIMITERS] = gui_color_build (COLOR_WIN_INPUT_DELIMITERS, cfg_col_input_delimiters, cfg_col_input_bg); + gui_color[COLOR_WIN_NICK] = gui_color_build (COLOR_WIN_NICK, cfg_col_nick, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_AWAY] = gui_color_build (COLOR_WIN_NICK_AWAY, cfg_col_nick_away, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_CHANOWNER] = gui_color_build (COLOR_WIN_NICK_CHANOWNER, cfg_col_nick_chanowner, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_CHANADMIN] = gui_color_build (COLOR_WIN_NICK_CHANADMIN, cfg_col_nick_chanadmin, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_OP] = gui_color_build (COLOR_WIN_NICK_OP, cfg_col_nick_op, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_HALFOP] = gui_color_build (COLOR_WIN_NICK_HALFOP, cfg_col_nick_halfop, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_VOICE] = gui_color_build (COLOR_WIN_NICK_VOICE, cfg_col_nick_voice, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_MORE] = gui_color_build (COLOR_WIN_NICK_MORE, cfg_col_nick_more, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_SEP] = gui_color_build (COLOR_WIN_NICK_SEP, cfg_col_nick_sep, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_SELF] = gui_color_build (COLOR_WIN_NICK_SELF, cfg_col_nick_self, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_PRIVATE] = gui_color_build (COLOR_WIN_NICK_PRIVATE, cfg_col_nick_private, cfg_col_nick_bg); + + for (i = 0; i < COLOR_WIN_NICK_NUMBER; i++) + { + gui_color[COLOR_WIN_NICK_1 + i] = gui_color_build (COLOR_WIN_NICK_1 + i, cfg_col_nick_colors[i], cfg_col_chat_bg); + } + + gui_color[COLOR_DCC_SELECTED] = gui_color_build (COLOR_DCC_SELECTED, cfg_col_dcc_selected, cfg_col_chat_bg); + gui_color[COLOR_DCC_WAITING] = gui_color_build (COLOR_DCC_WAITING, cfg_col_dcc_waiting, cfg_col_chat_bg); + gui_color[COLOR_DCC_CONNECTING] = gui_color_build (COLOR_DCC_CONNECTING, cfg_col_dcc_connecting, cfg_col_chat_bg); + gui_color[COLOR_DCC_ACTIVE] = gui_color_build (COLOR_DCC_ACTIVE, cfg_col_dcc_active, cfg_col_chat_bg); + gui_color[COLOR_DCC_DONE] = gui_color_build (COLOR_DCC_DONE, cfg_col_dcc_done, cfg_col_chat_bg); + gui_color[COLOR_DCC_FAILED] = gui_color_build (COLOR_DCC_FAILED, cfg_col_dcc_failed, cfg_col_chat_bg); + gui_color[COLOR_DCC_ABORTED] = gui_color_build (COLOR_DCC_ABORTED, cfg_col_dcc_aborted, cfg_col_chat_bg); +} + +/* + * gui_color_rebuild_weechat: rebuild WeeChat colors + */ + +void +gui_color_rebuild_weechat () +{ + int i; + + for (i = 0; i < GUI_NUM_COLORS; i++) + { + if (gui_color[i]) + { + if (gui_color[i]->string) + free (gui_color[i]->string); + free (gui_color[i]); + gui_color[i] = NULL; + } + } + gui_color_init_weechat (); +} + +/* + * gui_color_init: init GUI colors + */ + +void +gui_color_init () +{ + gui_color_init_pairs (); + gui_color_init_weechat (); +} diff --git a/src/gui/gtk/gui-gtk.h b/src/gui/gtk/gui-gtk.h new file mode 100644 index 000000000..c8a44108f --- /dev/null +++ b/src/gui/gtk/gui-gtk.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef __WEECHAT_GUI_GTK_H +#define __WEECHAT_GUI_GTK_H 1 + +/* TODO: remove these temporary defines */ + +#define A_BOLD 1 +#define A_UNDERLINE 2 +#define A_REVERSE 4 + +#define COLOR_BLACK 0 +#define COLOR_BLUE 1 +#define COLOR_GREEN 2 +#define COLOR_CYAN 3 +#define COLOR_RED 4 +#define COLOR_MAGENTA 5 +#define COLOR_YELLOW 6 +#define COLOR_WHITE 7 + +/* shift ncurses colors for compatibility with colors + in IRC messages (same as other IRC clients) */ + +#define WEECHAT_COLOR_BLACK COLOR_BLACK +#define WEECHAT_COLOR_RED COLOR_BLUE +#define WEECHAT_COLOR_GREEN COLOR_GREEN +#define WEECHAT_COLOR_YELLOW COLOR_CYAN +#define WEECHAT_COLOR_BLUE COLOR_RED +#define WEECHAT_COLOR_MAGENTA COLOR_MAGENTA +#define WEECHAT_COLOR_CYAN COLOR_YELLOW +#define WEECHAT_COLOR_WHITE COLOR_WHITE + +extern t_gui_color gui_weechat_colors[]; +extern int gui_irc_colors[GUI_NUM_IRC_COLORS][2]; + +extern GtkWidget *gtk_main_window; +extern GtkWidget *vbox1; +extern GtkWidget *entry_topic; +extern GtkWidget *notebook1; +extern GtkWidget *vbox2; +extern GtkWidget *hbox1; +extern GtkWidget *hpaned1; +extern GtkWidget *scrolledwindow_chat; +extern GtkWidget *scrolledwindow_nick; +extern GtkWidget *entry_input; +extern GtkWidget *label1; + +/* color functions */ +extern int gui_color_get_pair (int); +extern void gui_color_init (); + +/* chat functions */ +extern void gui_chat_calculate_line_diff (t_gui_window *, t_gui_line **, int *, int); + +/* keyboard functions */ +extern void gui_keyboard_default_bindings (); +extern void gui_keyboard_read (); + +/* window functions */ +extern void gui_window_set_title (); +extern void gui_window_reset_title (); + +#endif /* gui-gtk.h */ diff --git a/src/gui/gtk/gui-infobar.c b/src/gui/gtk/gui-infobar.c new file mode 100644 index 000000000..f90eb8209 --- /dev/null +++ b/src/gui/gtk/gui-infobar.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-infobar.c: infobar display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + + +/* + * gui_infobar_draw_time: draw time in infobar window + */ + +void +gui_infobar_draw_time (t_gui_buffer *buffer) +{ + /*t_gui_window *ptr_win; + time_t time_seconds; + struct tm *local_time;*/ + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; +} + +/* + * gui_infobar_draw: draw infobar window for a buffer + */ + +void +gui_infobar_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + time_t time_seconds; + struct tm *local_time; + char text_time[1024 + 1];*/ + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} diff --git a/src/gui/gtk/gui-input.c b/src/gui/gtk/gui-input.c index 79555fc4c..e38089c36 100644 --- a/src/gui/gtk/gui-input.c +++ b/src/gui/gtk/gui-input.c @@ -25,166 +25,157 @@ #endif #include -#include -#include -#include -#include -#include -#include + #include #include "../../common/weechat.h" #include "../gui.h" -#include "../../common/weeconfig.h" -#include "../../common/command.h" -#include "../../common/hotlist.h" -#include "../../common/fifo.h" #include "../../common/utf8.h" -#include "../../irc/irc.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif /* - * gui_input_default_key_bindings: create default key bindings + * gui_input_set_color: set color for an input window */ void -gui_input_default_key_bindings () +gui_input_set_color (t_gui_window *window, int irc_color) { - int i; - char key_str[32], command[32]; - - /* keys binded with internal functions */ - gui_key_bind ( /* RC */ "ctrl-M", "return"); - gui_key_bind ( /* RC */ "ctrl-J", "return"); - gui_key_bind ( /* tab */ "ctrl-I", "tab"); - gui_key_bind ( /* basckp */ "ctrl-H", "backspace"); - gui_key_bind ( /* basckp */ "ctrl-?", "backspace"); - gui_key_bind ( /* del */ "meta2-3~", "delete"); - gui_key_bind ( /* ^K */ "ctrl-K", "delete_end_line"); - gui_key_bind ( /* ^U */ "ctrl-U", "delete_beginning_line"); - gui_key_bind ( /* ^W */ "ctrl-W", "delete_previous_word"); - gui_key_bind ( /* ^Y */ "ctrl-Y", "clipboard_paste"); - gui_key_bind ( /* ^T */ "ctrl-T", "transpose_chars"); - gui_key_bind ( /* home */ "meta2-1~", "home"); - gui_key_bind ( /* home */ "meta2-H", "home"); - gui_key_bind ( /* home */ "meta2-7~", "home"); - gui_key_bind ( /* ^A */ "ctrl-A", "home"); - gui_key_bind ( /* end */ "meta2-4~", "end"); - gui_key_bind ( /* end */ "meta2-F", "end"); - gui_key_bind ( /* end */ "meta2-8~", "end"); - gui_key_bind ( /* ^E */ "ctrl-E", "end"); - gui_key_bind ( /* left */ "meta2-D", "left"); - gui_key_bind ( /* right */ "meta2-C", "right"); - gui_key_bind ( /* up */ "meta2-A", "up"); - gui_key_bind ( /* ^up */ "meta-Oa", "up_global"); - gui_key_bind ( /* down */ "meta2-B", "down"); - gui_key_bind ( /* ^down */ "meta-Ob", "down_global"); - gui_key_bind ( /* pgup */ "meta2-5~", "page_up"); - gui_key_bind ( /* pgdn */ "meta2-6~", "page_down"); - gui_key_bind ( /* m-pgup */ "meta-meta2-5~", "scroll_up"); - gui_key_bind ( /* m-pgdn */ "meta-meta2-6~", "scroll_down"); - gui_key_bind ( /* F10 */ "meta2-21~", "infobar_clear"); - gui_key_bind ( /* F11 */ "meta2-23~", "nick_page_up"); - gui_key_bind ( /* F12 */ "meta2-24~", "nick_page_down"); - gui_key_bind ( /* m-F11 */ "meta-meta2-1~", "nick_beginning"); - gui_key_bind ( /* m-F12 */ "meta-meta2-4~", "nick_end"); - gui_key_bind ( /* ^L */ "ctrl-L", "refresh"); - gui_key_bind ( /* m-a */ "meta-a", "jump_smart"); - gui_key_bind ( /* m-b */ "meta-b", "previous_word"); - gui_key_bind ( /* ^left */ "meta-Od", "previous_word"); - gui_key_bind ( /* m-d */ "meta-d", "delete_next_word"); - gui_key_bind ( /* m-f */ "meta-f", "next_word"); - gui_key_bind ( /* ^right */ "meta-Oc", "next_word"); - gui_key_bind ( /* m-h */ "meta-h", "hotlist_clear"); - gui_key_bind ( /* m-j,m-d */ "meta-jmeta-d", "jump_dcc"); - gui_key_bind ( /* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer"); - gui_key_bind ( /* m-j,m-s */ "meta-jmeta-s", "jump_server"); - gui_key_bind ( /* m-j,m-x */ "meta-jmeta-x", "jump_next_server"); - gui_key_bind ( /* m-k */ "meta-k", "grab_key"); - gui_key_bind ( /* m-n */ "meta-n", "scroll_next_highlight"); - gui_key_bind ( /* m-p */ "meta-p", "scroll_previous_highlight"); - gui_key_bind ( /* m-r */ "meta-r", "delete_line"); - gui_key_bind ( /* m-s */ "meta-s", "switch_server"); - gui_key_bind ( /* m-u */ "meta-u", "scroll_unread"); - - /* keys binded with commands */ - gui_key_bind ( /* m-left */ "meta-meta2-D", "/buffer -1"); - gui_key_bind ( /* F5 */ "meta2-15~", "/buffer -1"); - gui_key_bind ( /* m-right */ "meta-meta2-C", "/buffer +1"); - gui_key_bind ( /* F6 */ "meta2-17~", "/buffer +1"); - gui_key_bind ( /* F7 */ "meta2-18~", "/window -1"); - gui_key_bind ( /* F8 */ "meta2-19~", "/window +1"); - gui_key_bind ( /* m-w,m-up */ "meta-wmeta-meta2-A", "/window up"); - gui_key_bind ( /* m-w,m-down */ "meta-wmeta-meta2-B", "/window down"); - gui_key_bind ( /* m-w,m-left */ "meta-wmeta-meta2-D", "/window left"); - gui_key_bind ( /* m-w,m-right */ "meta-wmeta-meta2-C", "/window right"); - gui_key_bind ( /* m-0 */ "meta-0", "/buffer 10"); - gui_key_bind ( /* m-1 */ "meta-1", "/buffer 1"); - gui_key_bind ( /* m-2 */ "meta-2", "/buffer 2"); - gui_key_bind ( /* m-3 */ "meta-3", "/buffer 3"); - gui_key_bind ( /* m-4 */ "meta-4", "/buffer 4"); - gui_key_bind ( /* m-5 */ "meta-5", "/buffer 5"); - gui_key_bind ( /* m-6 */ "meta-6", "/buffer 6"); - gui_key_bind ( /* m-7 */ "meta-7", "/buffer 7"); - gui_key_bind ( /* m-8 */ "meta-8", "/buffer 8"); - gui_key_bind ( /* m-9 */ "meta-9", "/buffer 9"); - - /* bind meta-j + {01..99} to switch to buffers # > 10 */ - for (i = 1; i < 100; i++) - { - sprintf (key_str, "meta-j%02d", i); - sprintf (command, "/buffer %d", i); - gui_key_bind (key_str, command); - } + /*int fg, bg;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) irc_color; } /* - * gui_input_grab_end: insert grabbed key in input buffer + * gui_input_get_prompt_length: return input prompt length */ -void -gui_input_grab_end () +int +gui_input_get_prompt_length (t_gui_window *window, char *nick) { - char *expanded_key; - - /* get expanded name (for example: ^U => ctrl-u) */ - expanded_key = gui_key_get_expanded_name (gui_key_buffer); + char *pos, *modes; + int length, mode_found; - if (expanded_key) + length = 0; + pos = cfg_look_input_format; + while (pos && pos[0]) { - if (gui_current_window->buffer->has_input) + switch (pos[0]) { - gui_insert_string_input (gui_current_window, expanded_key, -1); - gui_current_window->buffer->input_buffer_pos += utf8_strlen (expanded_key); - gui_draw_buffer_input (gui_current_window->buffer, 1); + case '%': + pos++; + switch (pos[0]) + { + case 'c': + if (CHANNEL(window->buffer)) + length += utf8_strlen (CHANNEL(window->buffer)->name); + else + { + if (SERVER(window->buffer)) + length += utf8_strlen (SERVER(window->buffer)->name); + } + pos++; + break; + case 'm': + if (SERVER(window->buffer)) + { + mode_found = 0; + for (modes = SERVER(window->buffer)->nick_modes; + modes && modes[0]; modes++) + { + if (modes[0] != ' ') + { + length++; + mode_found = 1; + } + } + if (mode_found) + length++; + } + pos++; + break; + case 'n': + length += utf8_strlen (nick); + pos++; + break; + default: + length++; + if (pos[0]) + { + if (pos[0] == '%') + pos++; + else + { + length++; + pos += utf8_char_size (pos); + } + } + break; + } + break; + default: + length++; + pos += utf8_char_size (pos); + break; } - free (expanded_key); } + return length; +} + +/* + * gui_input_draw_prompt: display input prompt + */ + +void +gui_input_draw_prompt (t_gui_window *window, char *nick) +{ + /*char *pos, saved_char, *modes; + int char_size, mode_found;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) nick; +} + +/* + * gui_input_draw_text: display text in input buffer, according to color mask + */ + +void +gui_input_draw_text (t_gui_window *window, int input_width) +{ + /*char *ptr_start, *ptr_next, saved_char; + int pos_mask, size, last_color, color;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) input_width; +} + +/* + * gui_input_draw: draw input window for a buffer + */ + +void +gui_input_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + char format[32]; + char *ptr_nickname; + int input_width; + t_irc_dcc *dcc_selected;*/ + + if (!gui_ok) + return; - /* end grab mode */ - gui_key_grab = 0; - gui_key_grab_count = 0; - gui_key_buffer[0] = '\0'; -} - -/* - * gui_input_read: read keyboard chars - */ - -void -gui_input_read () -{ /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; } - -/* - * gui_main_loop: main loop for WeeChat with ncurses GUI - */ - -void -gui_main_loop () -{ - /* TODO: write this function for Gtk */ - gtk_main (); -} - diff --git a/src/gui/gtk/gui-keyboard.c b/src/gui/gtk/gui-keyboard.c new file mode 100644 index 000000000..508a055eb --- /dev/null +++ b/src/gui/gtk/gui-keyboard.c @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-keyboard.c: keyboard functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/utf8.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif + + +/* + * gui_keyboard_default_bindings: create default key bindings + */ + +void +gui_keyboard_default_bindings () +{ + int i; + char key_str[32], command[32]; + + /* keys binded with internal functions */ + gui_key_bind ( /* RC */ "ctrl-M", "return"); + gui_key_bind ( /* RC */ "ctrl-J", "return"); + gui_key_bind ( /* tab */ "ctrl-I", "tab"); + gui_key_bind ( /* basckp */ "ctrl-H", "backspace"); + gui_key_bind ( /* basckp */ "ctrl-?", "backspace"); + gui_key_bind ( /* del */ "meta2-3~", "delete"); + gui_key_bind ( /* ^K */ "ctrl-K", "delete_end_line"); + gui_key_bind ( /* ^U */ "ctrl-U", "delete_beginning_line"); + gui_key_bind ( /* ^W */ "ctrl-W", "delete_previous_word"); + gui_key_bind ( /* ^Y */ "ctrl-Y", "clipboard_paste"); + gui_key_bind ( /* ^T */ "ctrl-T", "transpose_chars"); + gui_key_bind ( /* home */ "meta2-1~", "home"); + gui_key_bind ( /* home */ "meta2-H", "home"); + gui_key_bind ( /* home */ "meta2-7~", "home"); + gui_key_bind ( /* ^A */ "ctrl-A", "home"); + gui_key_bind ( /* end */ "meta2-4~", "end"); + gui_key_bind ( /* end */ "meta2-F", "end"); + gui_key_bind ( /* end */ "meta2-8~", "end"); + gui_key_bind ( /* ^E */ "ctrl-E", "end"); + gui_key_bind ( /* left */ "meta2-D", "left"); + gui_key_bind ( /* right */ "meta2-C", "right"); + gui_key_bind ( /* up */ "meta2-A", "up"); + gui_key_bind ( /* ^up */ "meta-Oa", "up_global"); + gui_key_bind ( /* down */ "meta2-B", "down"); + gui_key_bind ( /* ^down */ "meta-Ob", "down_global"); + gui_key_bind ( /* pgup */ "meta2-5~", "page_up"); + gui_key_bind ( /* pgdn */ "meta2-6~", "page_down"); + gui_key_bind ( /* m-pgup */ "meta-meta2-5~", "scroll_up"); + gui_key_bind ( /* m-pgdn */ "meta-meta2-6~", "scroll_down"); + gui_key_bind ( /* F10 */ "meta2-21~", "infobar_clear"); + gui_key_bind ( /* F11 */ "meta2-23~", "nick_page_up"); + gui_key_bind ( /* F12 */ "meta2-24~", "nick_page_down"); + gui_key_bind ( /* m-F11 */ "meta-meta2-1~", "nick_beginning"); + gui_key_bind ( /* m-F12 */ "meta-meta2-4~", "nick_end"); + gui_key_bind ( /* ^L */ "ctrl-L", "refresh"); + gui_key_bind ( /* m-a */ "meta-a", "jump_smart"); + gui_key_bind ( /* m-b */ "meta-b", "previous_word"); + gui_key_bind ( /* ^left */ "meta-Od", "previous_word"); + gui_key_bind ( /* m-d */ "meta-d", "delete_next_word"); + gui_key_bind ( /* m-f */ "meta-f", "next_word"); + gui_key_bind ( /* ^right */ "meta-Oc", "next_word"); + gui_key_bind ( /* m-h */ "meta-h", "hotlist_clear"); + gui_key_bind ( /* m-j,m-d */ "meta-jmeta-d", "jump_dcc"); + gui_key_bind ( /* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer"); + gui_key_bind ( /* m-j,m-s */ "meta-jmeta-s", "jump_server"); + gui_key_bind ( /* m-j,m-x */ "meta-jmeta-x", "jump_next_server"); + gui_key_bind ( /* m-k */ "meta-k", "grab_key"); + gui_key_bind ( /* m-n */ "meta-n", "scroll_next_highlight"); + gui_key_bind ( /* m-p */ "meta-p", "scroll_previous_highlight"); + gui_key_bind ( /* m-r */ "meta-r", "delete_line"); + gui_key_bind ( /* m-s */ "meta-s", "switch_server"); + gui_key_bind ( /* m-u */ "meta-u", "scroll_unread"); + + /* keys binded with commands */ + gui_key_bind ( /* m-left */ "meta-meta2-D", "/buffer -1"); + gui_key_bind ( /* F5 */ "meta2-15~", "/buffer -1"); + gui_key_bind ( /* m-right */ "meta-meta2-C", "/buffer +1"); + gui_key_bind ( /* F6 */ "meta2-17~", "/buffer +1"); + gui_key_bind ( /* F7 */ "meta2-18~", "/window -1"); + gui_key_bind ( /* F8 */ "meta2-19~", "/window +1"); + gui_key_bind ( /* m-w,m-up */ "meta-wmeta-meta2-A", "/window up"); + gui_key_bind ( /* m-w,m-down */ "meta-wmeta-meta2-B", "/window down"); + gui_key_bind ( /* m-w,m-left */ "meta-wmeta-meta2-D", "/window left"); + gui_key_bind ( /* m-w,m-right */ "meta-wmeta-meta2-C", "/window right"); + gui_key_bind ( /* m-0 */ "meta-0", "/buffer 10"); + gui_key_bind ( /* m-1 */ "meta-1", "/buffer 1"); + gui_key_bind ( /* m-2 */ "meta-2", "/buffer 2"); + gui_key_bind ( /* m-3 */ "meta-3", "/buffer 3"); + gui_key_bind ( /* m-4 */ "meta-4", "/buffer 4"); + gui_key_bind ( /* m-5 */ "meta-5", "/buffer 5"); + gui_key_bind ( /* m-6 */ "meta-6", "/buffer 6"); + gui_key_bind ( /* m-7 */ "meta-7", "/buffer 7"); + gui_key_bind ( /* m-8 */ "meta-8", "/buffer 8"); + gui_key_bind ( /* m-9 */ "meta-9", "/buffer 9"); + + /* bind meta-j + {01..99} to switch to buffers # > 10 */ + for (i = 1; i < 100; i++) + { + sprintf (key_str, "meta-j%02d", i); + sprintf (command, "/buffer %d", i); + gui_key_bind (key_str, command); + } +} + +/* + * gui_keyboard_grab_end: insert grabbed key in input buffer + */ + +void +gui_keyboard_grab_end () +{ + char *expanded_key; + + /* get expanded name (for example: ^U => ctrl-u) */ + expanded_key = gui_key_get_expanded_name (gui_key_buffer); + + if (expanded_key) + { + if (gui_current_window->buffer->has_input) + { + gui_insert_string_input (gui_current_window, expanded_key, -1); + gui_current_window->buffer->input_buffer_pos += utf8_strlen (expanded_key); + gui_input_draw (gui_current_window->buffer, 1); + } + free (expanded_key); + } + + /* end grab mode */ + gui_key_grab = 0; + gui_key_grab_count = 0; + gui_key_buffer[0] = '\0'; +} + +/* + * gui_keyboard_read: read keyboard chars + */ + +void +gui_keyboard_read () +{ + /* TODO: write this function for Gtk */ +} diff --git a/src/gui/gtk/gui-main.c b/src/gui/gtk/gui-main.c new file mode 100644 index 000000000..01dc67d65 --- /dev/null +++ b/src/gui/gtk/gui-main.c @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-main.c: main loop and keyboard management for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/fifo.h" +#include "../../common/utf8.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif + + +GtkWidget *gtk_main_window; +GtkWidget *vbox1; +GtkWidget *entry_topic; +GtkWidget *notebook1; +GtkWidget *vbox2; +GtkWidget *hbox1; +GtkWidget *hpaned1; +GtkWidget *scrolledwindow_chat; +GtkWidget *scrolledwindow_nick; +GtkWidget *entry_input; +GtkWidget *label1; + + +/* + * gui_main_loop: main loop for WeeChat with ncurses GUI + */ + +void +gui_main_loop () +{ + /* TODO: write this function for Gtk */ + gtk_main (); +} + +/* + * gui_main_pre_init: pre-initialize GUI (called before gui_init) + */ + +void +gui_main_pre_init (int *argc, char **argv[]) +{ + /* Initialise Gtk */ + gtk_init (argc, argv); +} + +/* + * gui_main_init: init GUI + */ + +void +gui_main_init () +{ + GdkColor color_fg, color_bg; + + gui_color_init (); + + gui_infobar = NULL; + + gui_ok = 1; + + /* init clipboard buffer */ + gui_input_clipboard = NULL; + + /* create Gtk widgets */ + + gdk_color_parse ("white", &color_fg); + gdk_color_parse ("black", &color_bg); + + gtk_main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (gtk_main_window), PACKAGE_STRING); + + g_signal_connect (G_OBJECT (gtk_main_window), "destroy", gtk_main_quit, NULL); + + vbox1 = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox1); + gtk_container_add (GTK_CONTAINER (gtk_main_window), vbox1); + + entry_topic = gtk_entry_new (); + gtk_widget_show (entry_topic); + gtk_box_pack_start (GTK_BOX (vbox1), entry_topic, FALSE, FALSE, 0); + gtk_widget_modify_text (entry_topic, GTK_STATE_NORMAL, &color_fg); + gtk_widget_modify_base (entry_topic, GTK_STATE_NORMAL, &color_bg); + + notebook1 = gtk_notebook_new (); + gtk_widget_show (notebook1); + gtk_box_pack_start (GTK_BOX (vbox1), notebook1, TRUE, TRUE, 0); + gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook1), GTK_POS_BOTTOM); + + vbox2 = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox2); + gtk_container_add (GTK_CONTAINER (notebook1), vbox2); + + hbox1 = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox1); + gtk_box_pack_start (GTK_BOX (vbox2), hbox1, TRUE, TRUE, 0); + + hpaned1 = gtk_hpaned_new (); + gtk_widget_show (hpaned1); + gtk_box_pack_start (GTK_BOX (hbox1), hpaned1, TRUE, TRUE, 0); + gtk_paned_set_position (GTK_PANED (hpaned1), 0); + + scrolledwindow_chat = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_show (scrolledwindow_chat); + gtk_paned_pack1 (GTK_PANED (hpaned1), scrolledwindow_chat, FALSE, TRUE); + //gtk_box_pack_start (GTK_PANED (hpaned1), scrolledwindow_chat, TRUE, TRUE, 0); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_chat), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + gtk_widget_modify_text (scrolledwindow_chat, GTK_STATE_NORMAL, &color_fg); + gtk_widget_modify_base (scrolledwindow_chat, GTK_STATE_NORMAL, &color_bg); + + scrolledwindow_nick = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_show (scrolledwindow_nick); + gtk_paned_pack2 (GTK_PANED (hpaned1), scrolledwindow_nick, FALSE, TRUE); + //gtk_box_pack_start (GTK_PANED (hpaned1), scrolledwindow_nick, TRUE, TRUE, 0); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_nick), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + gtk_widget_modify_text (scrolledwindow_nick, GTK_STATE_NORMAL, &color_fg); + gtk_widget_modify_base (scrolledwindow_nick, GTK_STATE_NORMAL, &color_bg); + + entry_input = gtk_entry_new (); + gtk_widget_show (entry_input); + gtk_box_pack_start (GTK_BOX (vbox2), entry_input, FALSE, FALSE, 0); + gtk_widget_modify_text (entry_input, GTK_STATE_NORMAL, &color_fg); + gtk_widget_modify_base (entry_input, GTK_STATE_NORMAL, &color_bg); + + label1 = gtk_label_new (_("server")); + gtk_widget_show (label1); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 0), label1); + gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT); + + gtk_widget_show_all (gtk_main_window); + + /* create new window/buffer */ + if (gui_window_new (NULL, 0, 0, 0, 0, 100, 100)) + { + gui_current_window = gui_windows; + gui_buffer_new (gui_windows, NULL, NULL, 0, 1); + + if (cfg_look_set_title) + gui_window_set_title (); + + gui_init_ok = 1; + } +} + +/* + * gui_main_end: GUI end + */ + +void +gui_main_end () +{ + t_gui_window *ptr_win; + + /* free clipboard buffer */ + if (gui_input_clipboard) + free(gui_input_clipboard); + + /* delete all windows */ + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + /* TODO: destroy Gtk widgets */ + } + + /* delete all buffers */ + while (gui_buffers) + gui_buffer_free (gui_buffers, 0); + + /* delete all windows */ + while (gui_windows) + gui_window_free (gui_windows); + gui_window_tree_free (&gui_windows_tree); + + /* delete global history */ + history_global_free (); + + /* delete infobar messages */ + while (gui_infobar) + gui_infobar_remove (); + + /* reset title */ + if (cfg_look_set_title) + gui_window_reset_title (); +} diff --git a/src/gui/gtk/gui-nicklist.c b/src/gui/gtk/gui-nicklist.c new file mode 100644 index 000000000..eebdc5b51 --- /dev/null +++ b/src/gui/gtk/gui-nicklist.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-nicklist.c: nicklist display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/weeconfig.h" +#include "../../irc/irc.h" +#include "gui-gtk.h" + + +/* + * gui_nicklist_draw: draw nick window for a buffer + */ + +void +gui_nicklist_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + int i, j, x, y, column, max_length, nicks_displayed; + char format[32], format_empty[32]; + t_irc_nick *ptr_nick;*/ + + if (!gui_ok || !BUFFER_HAS_NICKLIST(buffer)) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} diff --git a/src/gui/gtk/gui-status.c b/src/gui/gtk/gui-status.c new file mode 100644 index 000000000..436f7b7f9 --- /dev/null +++ b/src/gui/gtk/gui-status.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-status.c: status display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + + +/* + * gui_status_draw: draw status window for a buffer + */ + +void +gui_status_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + t_weechat_hotlist *ptr_hotlist; + char format[32], str_nicks[32], *more; + int i, first_mode, x, server_pos, server_total; + int display_name, names_count;*/ + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} diff --git a/src/gui/gtk/gui-window.c b/src/gui/gtk/gui-window.c new file mode 100644 index 000000000..72791d6c6 --- /dev/null +++ b/src/gui/gtk/gui-window.c @@ -0,0 +1,847 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-window.c: window display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + + +/* + * gui_window_set_weechat_color: set WeeChat color for window + */ + +/* TODO: write this function for Gtk */ +/*void +gui_window_set_weechat_color (WINDOW *window, int num_color) +{ + if ((num_color >= 0) && (num_color <= GUI_NUM_COLORS - 1)) + { + wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE); + wattron (window, COLOR_PAIR(gui_color_get_pair (num_color)) | + gui_color[num_color]->attributes); + } +}*/ + +/* + * gui_window_calculate_pos_size: calculate position and size for a window & sub-win + */ + +int +gui_window_calculate_pos_size (t_gui_window *window, int force_calculate) +{ + /* TODO: write this function for Gtk */ + (void) window; + (void) force_calculate; + + return 0; +} + +/* + * gui_window_draw_separator: draw window separation + */ + +void +gui_window_draw_separator (t_gui_window *window) +{ + /* TODO: write this function for Gtk */ + /*if (window->win_separator) + delwin (window->win_separator); + + if (window->win_x > 0) + { + window->win_separator = newwin (window->win_height, + 1, + window->win_y, + window->win_x - 1); + gui_window_set_weechat_color (window->win_separator, COLOR_WIN_SEPARATOR); + wborder (window->win_separator, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + wnoutrefresh (window->win_separator); + refresh (); + }*/ + (void) window; +} + +/* + * gui_window_redraw_buffer: redraw a buffer + */ + +void +gui_window_redraw_buffer (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + gui_chat_draw_title (buffer, 1); + gui_chat_draw (buffer, 1); + if (ptr_win->win_nick) + gui_nicklist_draw (buffer, 1); + gui_status_draw (buffer, 1); + if (cfg_look_infobar) + gui_infobar_draw (buffer, 1); + gui_input_draw (buffer, 1); + } + } +} + +/* + * gui_window_switch_to_buffer: switch to another buffer + */ + +void +gui_window_switch_to_buffer (t_gui_window *window, t_gui_buffer *buffer) +{ + GtkTextIter start, end; + + if (window->buffer->num_displayed > 0) + window->buffer->num_displayed--; + + if (window->buffer != buffer) + { + window->buffer->last_read_line = window->buffer->last_line; + if (buffer->last_read_line == buffer->last_line) + buffer->last_read_line = NULL; + } + + window->buffer = buffer; + window->win_nick_start = 0; + gui_window_calculate_pos_size (window, 1); + + if (!window->textview_chat) + { + window->textview_chat = gtk_text_view_new (); + gtk_widget_show (window->textview_chat); + gtk_container_add (GTK_CONTAINER (scrolledwindow_chat), window->textview_chat); + gtk_widget_set_size_request (window->textview_chat, 300, -1); + gtk_text_view_set_editable (GTK_TEXT_VIEW (window->textview_chat), FALSE); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (window->textview_chat), FALSE); + + window->textbuffer_chat = gtk_text_buffer_new (NULL); + gtk_text_view_set_buffer (GTK_TEXT_VIEW (window->textview_chat), window->textbuffer_chat); + + /*window->texttag_chat = gtk_text_buffer_create_tag(window->textbuffer_chat, "courier", "font_family", "lucida");*/ + gtk_text_buffer_get_bounds (window->textbuffer_chat, &start, &end); + gtk_text_buffer_apply_tag (window->textbuffer_chat, window->texttag_chat, &start, &end); + } + if (BUFFER_IS_CHANNEL(buffer) && !window->textbuffer_nicklist) + { + window->textview_nicklist = gtk_text_view_new (); + gtk_widget_show (window->textview_nicklist); + gtk_container_add (GTK_CONTAINER (scrolledwindow_nick), window->textview_nicklist); + gtk_text_view_set_editable (GTK_TEXT_VIEW (window->textview_nicklist), FALSE); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (window->textview_nicklist), FALSE); + + window->textbuffer_nicklist = gtk_text_buffer_new (NULL); + gtk_text_view_set_buffer (GTK_TEXT_VIEW (window->textview_nicklist), window->textbuffer_nicklist); + } + + window->start_line = NULL; + window->start_line_pos = 0; + + buffer->num_displayed++; + + hotlist_remove_buffer (buffer); +} + +/* + * gui_window_page_up: display previous page on buffer + */ + +void +gui_window_page_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * (window->win_chat_height - 1) : + (-1) * ((window->win_chat_height - 1) * 2)); + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_page_down: display next page on buffer + */ + +void +gui_window_page_down (t_gui_window *window) +{ + t_gui_line *ptr_line; + int line_pos; + + if (!gui_ok) + return; + + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + window->win_chat_height - 1); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_up: display previous few lines in buffer + */ + +void +gui_window_scroll_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * cfg_look_scroll_amount : + (-1) * ( (window->win_chat_height - 1) + cfg_look_scroll_amount)); + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_down: display next few lines in buffer + */ + +void +gui_window_scroll_down (t_gui_window *window) +{ + t_gui_line *ptr_line; + int line_pos; + + if (!gui_ok) + return; + + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + cfg_look_scroll_amount); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_top: scroll to top of buffer + */ + +void +gui_window_scroll_top (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + window->start_line = window->buffer->lines; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_bottom: scroll to bottom of buffer + */ + +void +gui_window_scroll_bottom (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (window->start_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_nick_beginning: go to beginning of nicklist + */ + +void +gui_window_nick_beginning (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if (window->win_nick_start > 0) + { + window->win_nick_start = 0; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_end: go to the end of nicklist + */ + +void +gui_window_nick_end (t_gui_window *window) +{ + int new_start; + + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + new_start = + CHANNEL(window->buffer)->nicks_count - window->win_nick_height; + if (new_start < 0) + new_start = 0; + else if (new_start >= 1) + new_start++; + + if (new_start != window->win_nick_start) + { + window->win_nick_start = new_start; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_page_up: scroll one page up in nicklist + */ + +void +gui_window_nick_page_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if (window->win_nick_start > 0) + { + window->win_nick_start -= (window->win_nick_height - 1); + if (window->win_nick_start <= 1) + window->win_nick_start = 0; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_page_down: scroll one page down in nicklist + */ + +void +gui_window_nick_page_down (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if ((CHANNEL(window->buffer)->nicks_count > window->win_nick_height) + && (window->win_nick_start + window->win_nick_height - 1 + < CHANNEL(window->buffer)->nicks_count)) + { + if (window->win_nick_start == 0) + window->win_nick_start += (window->win_nick_height - 1); + else + window->win_nick_start += (window->win_nick_height - 2); + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_init_subwindows: init subwindows for a WeeChat window + */ + +void +gui_window_init_subwindows (t_gui_window *window) +{ + window->textview_chat = NULL; + window->textbuffer_chat = NULL; + window->texttag_chat = NULL; + window->textview_nicklist = NULL; + window->textbuffer_nicklist = NULL; +} + +/* + * gui_window_auto_resize: auto-resize all windows, according to % of global size + * This function is called after a terminal resize. + * Returns 0 if ok, -1 if all window should be merged + * (not enough space according to windows %) + */ + +int +gui_window_auto_resize (t_gui_window_tree *tree, + int x, int y, int width, int height, + int simulate) +{ + int size1, size2; + + if (tree) + { + if (tree->window) + { + if ((width < WINDOW_MIN_WIDTH) || (height < WINDOW_MIN_HEIGHT)) + return -1; + if (!simulate) + { + tree->window->win_x = x; + tree->window->win_y = y; + tree->window->win_width = width; + tree->window->win_height = height; + } + } + else + { + if (tree->split_horiz) + { + size1 = (height * tree->split_pct) / 100; + size2 = height - size1; + if (gui_window_auto_resize (tree->child1, x, y + size1, + width, size2, simulate) < 0) + return -1; + if (gui_window_auto_resize (tree->child2, x, y, + width, size1, simulate) < 0) + return -1; + } + else + { + size1 = (width * tree->split_pct) / 100; + size2 = width - size1 - 1; + if (gui_window_auto_resize (tree->child1, x, y, + size1, height, simulate) < 0) + return -1; + if (gui_window_auto_resize (tree->child2, x + size1 + 1, y, + size2, height, simulate) < 0) + return -1; + } + } + } + return 0; +} + +/* + * gui_window_refresh_windows: auto resize and refresh all windows + */ + +void +gui_window_refresh_windows () +{ + /*t_gui_window *ptr_win, *old_current_window;*/ + + if (gui_ok) + { + /* TODO: write this function for Gtk */ + } +} + +/* + * gui_window_split_horiz: split a window horizontally + */ + +void +gui_window_split_horiz (t_gui_window *window, int pourcentage) +{ + t_gui_window *new_window; + int height1, height2; + + if (!gui_ok) + return; + + height1 = (window->win_height * pourcentage) / 100; + height2 = window->win_height - height1; + + if ((height1 >= WINDOW_MIN_HEIGHT) && (height2 >= WINDOW_MIN_HEIGHT) + && (pourcentage > 0) && (pourcentage <= 100)) + { + if ((new_window = gui_window_new (window, + window->win_x, window->win_y, + window->win_width, height1, + 100, pourcentage))) + { + /* reduce old window height (bottom window) */ + window->win_y = new_window->win_y + new_window->win_height; + window->win_height = height2; + window->win_height_pct = 100 - pourcentage; + + /* assign same buffer for new window (top window) */ + new_window->buffer = window->buffer; + new_window->buffer->num_displayed++; + + gui_window_switch_to_buffer (window, window->buffer); + + gui_current_window = new_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + } + } +} + +/* + * gui_window_split_vertic: split a window vertically + */ + +void +gui_window_split_vertic (t_gui_window *window, int pourcentage) +{ + t_gui_window *new_window; + int width1, width2; + + if (!gui_ok) + return; + + width1 = (window->win_width * pourcentage) / 100; + width2 = window->win_width - width1 - 1; + + if ((width1 >= WINDOW_MIN_WIDTH) && (width2 >= WINDOW_MIN_WIDTH) + && (pourcentage > 0) && (pourcentage <= 100)) + { + if ((new_window = gui_window_new (window, + window->win_x + width1 + 1, window->win_y, + width2, window->win_height, + pourcentage, 100))) + { + /* reduce old window height (left window) */ + window->win_width = width1; + window->win_width_pct = 100 - pourcentage; + + /* assign same buffer for new window (right window) */ + new_window->buffer = window->buffer; + new_window->buffer->num_displayed++; + + gui_window_switch_to_buffer (window, window->buffer); + + gui_current_window = new_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + + /* create & draw separator */ + gui_window_draw_separator (gui_current_window); + } + } +} + +/* + * gui_window_resize: resize window + */ + +void +gui_window_resize (t_gui_window *window, int pourcentage) +{ + /* TODO: write this function for Gtk */ + (void) window; + (void) pourcentage; +} + +/* + * gui_window_merge: merge window with its sister + */ + +int +gui_window_merge (t_gui_window *window) +{ + t_gui_window_tree *parent, *sister; + + parent = window->ptr_tree->parent_node; + if (parent) + { + sister = (parent->child1->window == window) ? + parent->child2 : parent->child1; + + if (!(sister->window)) + return 0; + + if (window->win_y == sister->window->win_y) + { + /* horizontal merge */ + window->win_width += sister->window->win_width + 1; + window->win_width_pct += sister->window->win_width_pct; + } + else + { + /* vertical merge */ + window->win_height += sister->window->win_height; + window->win_height_pct += sister->window->win_height_pct; + } + if (sister->window->win_x < window->win_x) + window->win_x = sister->window->win_x; + if (sister->window->win_y < window->win_y) + window->win_y = sister->window->win_y; + + gui_window_free (sister->window); + gui_window_tree_node_to_leaf (parent, window); + + gui_window_switch_to_buffer (window, window->buffer); + gui_window_redraw_buffer (window->buffer); + return 1; + } + return 0; +} + +/* + * gui_window_merge_all: merge all windows into only one + */ + +void +gui_window_merge_all (t_gui_window *window) +{ + /* TODO: write this function for Gtk */ + (void) window; +} + +/* + * gui_window_side_by_side: return a code about position of 2 windows: + * 0 = they're not side by side + * 1 = side by side (win2 is over the win1) + * 2 = side by side (win2 on the right) + * 3 = side by side (win2 below win1) + * 4 = side by side (win2 on the left) + */ + +int +gui_window_side_by_side (t_gui_window *win1, t_gui_window *win2) +{ + /* win2 over win1 ? */ + if (win2->win_y + win2->win_height == win1->win_y) + { + if (win2->win_x >= win1->win_x + win1->win_width) + return 0; + if (win2->win_x + win2->win_width <= win1->win_x) + return 0; + return 1; + } + + /* win2 on the right ? */ + if (win2->win_x == win1->win_x + win1->win_width + 1) + { + if (win2->win_y >= win1->win_y + win1->win_height) + return 0; + if (win2->win_y + win2->win_height <= win1->win_y) + return 0; + return 2; + } + + /* win2 below win1 ? */ + if (win2->win_y == win1->win_y + win1->win_height) + { + if (win2->win_x >= win1->win_x + win1->win_width) + return 0; + if (win2->win_x + win2->win_width <= win1->win_x) + return 0; + return 3; + } + + /* win2 on the left ? */ + if (win2->win_x + win2->win_width + 1 == win1->win_x) + { + if (win2->win_y >= win1->win_y + win1->win_height) + return 0; + if (win2->win_y + win2->win_height <= win1->win_y) + return 0; + return 4; + } + + return 0; +} + +/* + * gui_window_switch_up: search and switch to a window over current window + */ + +void +gui_window_switch_up (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 1)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_down: search and switch to a window below current window + */ + +void +gui_window_switch_down (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 3)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_left: search and switch to a window on the left of current window + */ + +void +gui_window_switch_left (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 4)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_right: search and switch to a window on the right of current window + */ + +void +gui_window_switch_right (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 2)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_refresh_screen: called when term size is modified + */ + +void +gui_window_refresh_screen () +{ + /* TODO: write this function for Gtk */ +} + +/* + * gui_window_set_title: set terminal title + */ + +void +gui_window_set_title () +{ + /* TODO: write this function for Gtk */ +} + +/* + * gui_window_reset_title: reset terminal title + */ + +void +gui_window_reset_title () +{ + /* This function does nothing in Gtk GUI */ +} diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c index 3cedac744..bbdd41cc7 100644 --- a/src/gui/gui-action.c +++ b/src/gui/gui-action.c @@ -76,7 +76,7 @@ gui_action_clipboard_paste (t_gui_window *window) { gui_insert_string_input (window, gui_input_clipboard, -1); window->buffer->input_buffer_pos += utf8_strlen (gui_input_clipboard); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -110,7 +110,7 @@ gui_action_return (t_gui_window *window) window->buffer->completion.position = -1; window->buffer->ptr_history = NULL; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); user_command (SERVER(window->buffer), CHANNEL(window->buffer), command, 0); free (command); @@ -231,7 +231,7 @@ gui_action_tab (t_gui_window *window) window->buffer->input_buffer_pos++; } } - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -262,7 +262,7 @@ gui_action_backspace (t_gui_window *window) window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -294,7 +294,7 @@ gui_action_delete (t_gui_window *window) window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -354,7 +354,7 @@ gui_action_delete_previous_word (t_gui_window *window) window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_pos -= length_deleted; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -394,7 +394,7 @@ gui_action_delete_next_word (t_gui_window *window) window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -429,7 +429,7 @@ gui_action_delete_begin_of_line (t_gui_window *window) window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_pos = 0; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -458,7 +458,7 @@ gui_action_delete_end_of_line (t_gui_window *window) window->buffer->input_buffer_size = strlen (window->buffer->input_buffer); window->buffer->input_buffer_length = utf8_strlen (window->buffer->input_buffer); gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -478,7 +478,7 @@ gui_action_delete_line (t_gui_window *window) window->buffer->input_buffer_length = 0; window->buffer->input_buffer_pos = 0; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -522,7 +522,7 @@ gui_action_transpose_chars (t_gui_window *window) window->buffer->input_buffer_pos++; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -540,7 +540,7 @@ gui_action_home (t_gui_window *window) if (window->buffer->input_buffer_pos > 0) { window->buffer->input_buffer_pos = 0; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -559,7 +559,7 @@ gui_action_end (t_gui_window *window) { window->buffer->input_buffer_pos = window->buffer->input_buffer_length; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -576,7 +576,7 @@ gui_action_left (t_gui_window *window) if (window->buffer->input_buffer_pos > 0) { window->buffer->input_buffer_pos--; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -616,7 +616,7 @@ gui_action_previous_word (t_gui_window *window) else window->buffer->input_buffer_pos = 0; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -634,7 +634,7 @@ gui_action_right (t_gui_window *window) window->buffer->input_buffer_length) { window->buffer->input_buffer_pos++; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -678,7 +678,7 @@ gui_action_next_word (t_gui_window *window) utf8_pos (window->buffer->input_buffer, utf8_prev_char (window->buffer->input_buffer, pos) - window->buffer->input_buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -703,8 +703,8 @@ gui_action_up (t_gui_window *window) ((t_irc_dcc *)(window->dcc_first))->prev_dcc; window->dcc_selected = ((t_irc_dcc *)(window->dcc_selected))->prev_dcc; - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_input (window->buffer, 1); + gui_chat_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); } } } @@ -756,7 +756,7 @@ gui_action_up (t_gui_window *window) strcpy (window->buffer->input_buffer, window->buffer->ptr_history->text); gui_input_init_color_mask (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -791,7 +791,7 @@ gui_action_up_global (t_gui_window *window) strcpy (window->buffer->input_buffer, history_global_ptr->text); gui_input_init_color_mask (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -827,8 +827,8 @@ gui_action_down (t_gui_window *window) else window->dcc_selected = dcc_list->next_dcc; - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_input (window->buffer, 1); + gui_chat_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); } } } @@ -860,7 +860,7 @@ gui_action_down (t_gui_window *window) window->buffer->ptr_history->text); gui_input_init_color_mask (window->buffer); } - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -899,7 +899,7 @@ gui_action_down_global (t_gui_window *window) history_global_ptr->text); gui_input_init_color_mask (window->buffer); } - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -1015,15 +1015,15 @@ gui_action_jump_smart (t_gui_window *window) { if (!hotlist_initial_buffer) hotlist_initial_buffer = window->buffer; - gui_switch_to_buffer (window, hotlist->buffer); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, hotlist->buffer); + gui_window_redraw_buffer (window->buffer); } else { if (hotlist_initial_buffer) { - gui_switch_to_buffer (window, hotlist_initial_buffer); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, hotlist_initial_buffer); + gui_window_redraw_buffer (window->buffer); hotlist_initial_buffer = NULL; } } @@ -1040,9 +1040,9 @@ gui_action_jump_dcc (t_gui_window *window) { if (gui_buffer_before_dcc) { - gui_switch_to_buffer (window, - gui_buffer_before_dcc); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, + gui_buffer_before_dcc); + gui_window_redraw_buffer (window->buffer); } } else @@ -1063,9 +1063,9 @@ gui_action_jump_raw_data (t_gui_window *window) { if (gui_buffer_before_raw_data) { - gui_switch_to_buffer (window, - gui_buffer_before_raw_data); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, + gui_buffer_before_raw_data); + gui_window_redraw_buffer (window->buffer); } } else @@ -1098,9 +1098,9 @@ gui_action_jump_server (t_gui_window *window) if (SERVER(window->buffer)->buffer != window->buffer) { - gui_switch_to_buffer (window, - SERVER(window->buffer)->buffer); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, + SERVER(window->buffer)->buffer); + gui_window_redraw_buffer (window->buffer); } } } @@ -1141,8 +1141,8 @@ gui_action_jump_next_server (t_gui_window *window) if ((ptr_server->buffer == ptr_buffer) && (ptr_buffer->all_servers)) ptr_buffer->server = ptr_server; - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (window->buffer); } } } @@ -1181,8 +1181,8 @@ gui_action_scroll_previous_highlight (t_gui_window *window) window->start_line_pos = 0; window->first_line_displayed = (window->start_line == window->buffer->lines); - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_status (window->buffer, 0); + gui_chat_draw (window->buffer, 1); + gui_status_draw (window->buffer, 0); return; } ptr_line = ptr_line->prev_line; @@ -1214,8 +1214,8 @@ gui_action_scroll_next_highlight (t_gui_window *window) window->start_line_pos = 0; window->first_line_displayed = (window->start_line == window->buffer->lines); - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_status (window->buffer, 0); + gui_chat_draw (window->buffer, 1); + gui_status_draw (window->buffer, 0); return; } ptr_line = ptr_line->next_line; @@ -1241,8 +1241,8 @@ gui_action_scroll_unread (t_gui_window *window) window->start_line_pos = 0; window->first_line_displayed = (window->start_line == window->buffer->lines); - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_status (window->buffer, 0); + gui_chat_draw (window->buffer, 1); + gui_status_draw (window->buffer, 0); } } @@ -1256,7 +1256,7 @@ gui_action_hotlist_clear (t_gui_window *window) if (hotlist) { hotlist_free_all (); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); } hotlist_initial_buffer = window->buffer; } @@ -1269,7 +1269,7 @@ void gui_action_infobar_clear (t_gui_window *window) { gui_infobar_remove (); - gui_draw_buffer_infobar (window->buffer, 1); + gui_infobar_draw (window->buffer, 1); } /* @@ -1282,7 +1282,7 @@ gui_action_refresh_screen (t_gui_window *window) /* make gcc happy */ (void) window; - gui_refresh_screen (); + gui_window_refresh_screen (); } /* diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c new file mode 100644 index 000000000..3f7107bc3 --- /dev/null +++ b/src/gui/gui-buffer.c @@ -0,0 +1,932 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-window.c: window functions, used by all GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../common/weechat.h" +#include "gui.h" +#include "../common/command.h" +#include "../common/weeconfig.h" +#include "../common/history.h" +#include "../common/hotlist.h" +#include "../common/log.h" +#include "../common/utf8.h" +#include "../irc/irc.h" + + +/* + * gui_buffer_servers_search: search servers buffer + * (when same buffer is used for all servers) + */ + +t_gui_buffer * +gui_buffer_servers_search () +{ + t_gui_buffer *ptr_buffer; + + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->all_servers) + return ptr_buffer; + } + + /* buffer not found */ + return NULL; +} + +/* + * gui_buffer_new: create a new buffer in current window + */ + +t_gui_buffer * +gui_buffer_new (t_gui_window *window, void *server, void *channel, int type, + int switch_to_buffer) +{ + t_gui_buffer *new_buffer, *ptr_buffer; + +#ifdef DEBUG + weechat_log_printf ("Creating new buffer\n"); +#endif + + /* use first buffer if no server was assigned to this buffer */ + if ((type == BUFFER_TYPE_STANDARD) && gui_buffers && (!SERVER(gui_buffers))) + { + if (server) + ((t_irc_server *)(server))->buffer = gui_buffers; + if (channel) + ((t_irc_channel *)(channel))->buffer = gui_buffers; + gui_buffers->server = server; + gui_buffers->channel = channel; + if (cfg_look_one_server_buffer && server && !channel) + gui_buffers->all_servers = 1; + if (cfg_log_auto_server) + log_start (gui_buffers); + return gui_buffers; + } + + if (cfg_look_one_server_buffer && (type == BUFFER_TYPE_STANDARD) && + gui_buffers && server && !channel) + { + ptr_buffer = gui_buffer_servers_search (); + if (ptr_buffer) + { + ((t_irc_server *)(server))->buffer = gui_buffers; + gui_buffers->server = server; + if (switch_to_buffer) + gui_window_switch_to_buffer (window, gui_buffers); + gui_window_redraw_buffer (gui_buffers); + return gui_buffers; + } + } + + if ((new_buffer = (t_gui_buffer *)(malloc (sizeof (t_gui_buffer))))) + { + new_buffer->num_displayed = 0; + new_buffer->number = (last_gui_buffer) ? last_gui_buffer->number + 1 : 1; + + /* assign server and channel to buffer */ + new_buffer->server = server; + new_buffer->all_servers = 0; + new_buffer->channel = channel; + new_buffer->type = type; + if (new_buffer->type == BUFFER_TYPE_RAW_DATA) + gui_buffer_raw_data = new_buffer; + /* assign buffer to server and channel */ + if (server && !channel) + { + SERVER(new_buffer)->buffer = new_buffer; + new_buffer->all_servers = (cfg_look_one_server_buffer) ? 1 : 0; + } + if (!gui_buffers && cfg_look_one_server_buffer) + new_buffer->all_servers = 1; + if (channel) + CHANNEL(new_buffer)->buffer = new_buffer; + + if (!window->buffer) + { + window->buffer = new_buffer; + window->first_line_displayed = 1; + window->start_line = NULL; + window->start_line_pos = 0; + gui_window_calculate_pos_size (window, 1); + gui_window_init_subwindows (window); + } + + /* init lines */ + new_buffer->lines = NULL; + new_buffer->last_line = NULL; + new_buffer->last_read_line = NULL; + new_buffer->num_lines = 0; + new_buffer->line_complete = 1; + + /* notify level */ + new_buffer->notify_level = channel_get_notify_level (server, channel); + + /* create/append to log file */ + new_buffer->log_filename = NULL; + new_buffer->log_file = NULL; + if ((cfg_log_auto_server && BUFFER_IS_SERVER(new_buffer)) + || (cfg_log_auto_channel && BUFFER_IS_CHANNEL(new_buffer)) + || (cfg_log_auto_private && BUFFER_IS_PRIVATE(new_buffer))) + log_start (new_buffer); + + /* init input buffer */ + new_buffer->has_input = (new_buffer->type == BUFFER_TYPE_STANDARD) ? 1 : 0; + if (new_buffer->has_input) + { + new_buffer->input_buffer_alloc = INPUT_BUFFER_BLOCK_SIZE; + new_buffer->input_buffer = (char *) malloc (INPUT_BUFFER_BLOCK_SIZE); + new_buffer->input_buffer_color_mask = (char *) malloc (INPUT_BUFFER_BLOCK_SIZE); + new_buffer->input_buffer[0] = '\0'; + new_buffer->input_buffer_color_mask[0] = '\0'; + } + else + { + new_buffer->input_buffer = NULL; + new_buffer->input_buffer_color_mask = NULL; + } + new_buffer->input_buffer_size = 0; + new_buffer->input_buffer_length = 0; + new_buffer->input_buffer_pos = 0; + new_buffer->input_buffer_1st_display = 0; + + /* init completion */ + completion_init (&(new_buffer->completion), server, channel); + + /* init history */ + new_buffer->history = NULL; + new_buffer->last_history = NULL; + new_buffer->ptr_history = NULL; + new_buffer->num_history = 0; + + /* add buffer to buffers queue */ + new_buffer->prev_buffer = last_gui_buffer; + if (gui_buffers) + last_gui_buffer->next_buffer = new_buffer; + else + gui_buffers = new_buffer; + last_gui_buffer = new_buffer; + new_buffer->next_buffer = NULL; + + /* move buffer next to server */ + if (server && cfg_look_open_near_server && (!cfg_look_one_server_buffer)) + { + ptr_buffer = SERVER(new_buffer)->buffer; + while (ptr_buffer && (ptr_buffer->server == server)) + { + ptr_buffer = ptr_buffer->next_buffer; + } + if (ptr_buffer) + gui_buffer_move_to_number (new_buffer, ptr_buffer->number); + } + + /* switch to new buffer */ + if (switch_to_buffer) + gui_window_switch_to_buffer (window, new_buffer); + + /* redraw buffer */ + gui_window_redraw_buffer (new_buffer); + } + else + return NULL; + + return new_buffer; +} + +/* + * gui_buffer_search: search a buffer by server and channel name + */ + +t_gui_buffer * +gui_buffer_search (char *server, char *channel) +{ + t_irc_server *ptr_server; + t_irc_channel *ptr_channel; + t_gui_buffer *ptr_buffer; + + ptr_server = NULL; + ptr_channel = NULL; + ptr_buffer = NULL; + + /* nothing given => print on current buffer */ + if ((!server || !server[0]) && (!channel || !channel[0])) + ptr_buffer = gui_current_window->buffer; + else + { + if (server && server[0]) + { + ptr_server = server_search (server); + if (!ptr_server) + return NULL; + } + else + { + ptr_server = SERVER(gui_current_window->buffer); + if (!ptr_server) + ptr_server = SERVER(gui_buffers); + } + + if (channel && channel[0]) + { + if (ptr_server) + { + ptr_channel = channel_search_any (ptr_server, channel); + if (ptr_channel) + ptr_buffer = ptr_channel->buffer; + } + } + else + { + if (ptr_server) + ptr_buffer = ptr_server->buffer; + else + ptr_buffer = gui_current_window->buffer; + } + } + + if (!ptr_buffer) + return NULL; + + return (ptr_buffer->type != BUFFER_TYPE_STANDARD) ? + gui_buffers : ptr_buffer; +} + +/* + * gui_buffer_find_window: find a window displaying buffer + */ + +t_gui_window * +gui_buffer_find_window (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + + if (gui_current_window->buffer == buffer) + return gui_current_window; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + return ptr_win; + } + + /* no window found */ + return NULL; +} + +/* + * gui_buffer_get_dcc: get pointer to DCC buffer (DCC buffer created if not existing) + */ + +t_gui_buffer * +gui_buffer_get_dcc (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + + /* check if dcc buffer exists */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->type == BUFFER_TYPE_DCC) + break; + } + if (ptr_buffer) + return ptr_buffer; + else + return gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_DCC, 0); +} + +/* + * gui_buffer_clear: clear buffer content + */ + +void +gui_buffer_clear (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + t_gui_line *ptr_line; + + /* remove buffer from hotlist */ + hotlist_remove_buffer (buffer); + + /* remove lines from buffer */ + while (buffer->lines) + { + ptr_line = buffer->lines->next_line; + if (buffer->lines->data) + free (buffer->lines->data); + free (buffer->lines); + buffer->lines = ptr_line; + } + + buffer->lines = NULL; + buffer->last_line = NULL; + buffer->num_lines = 0; + buffer->line_complete = 1; + + /* remove any scroll for buffer */ + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + ptr_win->first_line_displayed = 1; + ptr_win->start_line = NULL; + ptr_win->start_line_pos = 0; + } + } + + gui_chat_draw (buffer, 1); + gui_status_draw (buffer, 1); +} + +/* + * gui_buffer_clear_all: clear all buffers content + */ + +void +gui_buffer_clear_all () +{ + t_gui_buffer *ptr_buffer; + + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + gui_buffer_clear (ptr_buffer); +} + +/* + * gui_buffer_line_free: delete a line from a buffer + */ + +void +gui_buffer_line_free (t_gui_line *line) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->start_line == line) + { + ptr_win->start_line = ptr_win->start_line->next_line; + ptr_win->start_line_pos = 0; + gui_chat_draw (ptr_win->buffer, 0); + gui_status_draw (ptr_win->buffer, 0); + } + } + if (line->nick) + free (line->nick); + if (line->data) + free (line->data); + free (line); +} + +/* + * gui_buffer_free: delete a buffer + */ + +void +gui_buffer_free (t_gui_buffer *buffer, int switch_to_another) +{ + t_gui_window *ptr_win; + t_gui_buffer *ptr_buffer; + t_gui_line *ptr_line; + t_irc_server *ptr_server; + int create_new; + + create_new = (buffer->server || buffer->channel); + + hotlist_remove_buffer (buffer); + if (hotlist_initial_buffer == buffer) + hotlist_initial_buffer = NULL; + + if (gui_buffer_before_dcc == buffer) + gui_buffer_before_dcc = NULL; + + if (gui_buffer_before_raw_data == buffer) + gui_buffer_before_raw_data = NULL; + + if (buffer->type == BUFFER_TYPE_RAW_DATA) + gui_buffer_raw_data = NULL; + + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (ptr_server->saved_buffer == buffer) + ptr_server->saved_buffer = NULL; + } + + if (switch_to_another) + { + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if ((buffer == ptr_win->buffer) && + ((buffer->next_buffer) || (buffer->prev_buffer))) + gui_buffer_switch_previous (ptr_win); + } + } + + /* decrease buffer number for all next buffers */ + for (ptr_buffer = buffer->next_buffer; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + ptr_buffer->number--; + } + + /* free lines and messages */ + while (buffer->lines) + { + ptr_line = buffer->lines->next_line; + gui_buffer_line_free (buffer->lines); + buffer->lines = ptr_line; + } + + /* close log if opened */ + if (buffer->log_file) + log_end (buffer); + + if (buffer->input_buffer) + free (buffer->input_buffer); + if (buffer->input_buffer_color_mask) + free (buffer->input_buffer_color_mask); + + completion_free (&(buffer->completion)); + + history_buffer_free (buffer); + + /* remove buffer from buffers list */ + if (buffer->prev_buffer) + buffer->prev_buffer->next_buffer = buffer->next_buffer; + if (buffer->next_buffer) + buffer->next_buffer->prev_buffer = buffer->prev_buffer; + if (gui_buffers == buffer) + gui_buffers = buffer->next_buffer; + if (last_gui_buffer == buffer) + last_gui_buffer = buffer->prev_buffer; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + ptr_win->buffer = NULL; + } + + free (buffer); + + /* always at least one buffer */ + if (!gui_buffers && create_new && switch_to_another) + (void) gui_buffer_new (gui_windows, NULL, NULL, + BUFFER_TYPE_STANDARD, 1); +} + +/* + * gui_buffer_line_new: create new line for a buffer + */ + +t_gui_line * +gui_buffer_line_new (t_gui_buffer *buffer) +{ + t_gui_line *new_line, *ptr_line; + + if ((new_line = (t_gui_line *) malloc (sizeof (struct t_gui_line)))) + { + new_line->length = 0; + new_line->length_align = 0; + new_line->log_write = 1; + new_line->line_with_message = 0; + new_line->line_with_highlight = 0; + new_line->nick = NULL; + new_line->data = NULL; + new_line->ofs_after_date = -1; + new_line->ofs_start_message = -1; + if (!buffer->lines) + buffer->lines = new_line; + else + buffer->last_line->next_line = new_line; + new_line->prev_line = buffer->last_line; + new_line->next_line = NULL; + buffer->last_line = new_line; + buffer->num_lines++; + } + else + { + weechat_log_printf (_("Not enough memory for new line\n")); + return NULL; + } + + /* remove one line if necessary */ + if ((cfg_history_max_lines > 0) + && (buffer->num_lines > cfg_history_max_lines)) + { + if (buffer->last_line == buffer->lines) + buffer->last_line = NULL; + ptr_line = buffer->lines->next_line; + gui_buffer_line_free (buffer->lines); + buffer->lines = ptr_line; + ptr_line->prev_line = NULL; + buffer->num_lines--; + gui_chat_draw (buffer, 1); + } + + return new_line; +} + +/* + * gui_buffer_merge_servers: merge server buffers in one buffer + */ + +void +gui_buffer_merge_servers (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer_server, *ptr_buffer; + t_irc_server *ptr_server; + + /* new server buffer is the first server buffer found */ + for (ptr_buffer_server = gui_buffers; ptr_buffer_server; + ptr_buffer_server = ptr_buffer_server->next_buffer) + { + if (BUFFER_IS_SERVER(ptr_buffer_server)) + break; + } + + /* no server buffer found */ + if (!ptr_buffer_server) + return; + + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if ((ptr_buffer != ptr_buffer_server) + && (BUFFER_IS_SERVER(ptr_buffer))) + { + ptr_server = SERVER(ptr_buffer); + + /* add (by pointer artefact) lines from buffer found to server buffer */ + if (ptr_buffer->lines) + { + if (ptr_buffer_server->lines) + { + ptr_buffer->lines->prev_line = + ptr_buffer_server->last_line; + ptr_buffer_server->last_line->next_line = + ptr_buffer->lines; + ptr_buffer_server->last_line = + ptr_buffer->last_line; + } + else + { + ptr_buffer_server->lines = ptr_buffer->lines; + ptr_buffer_server->last_line = ptr_buffer->last_line; + } + } + + /* free buffer but not lines, because they're now used by + our unique server buffer */ + ptr_buffer->lines = NULL; + gui_buffer_free (ptr_buffer, 1); + + /* asociate server with new server buffer */ + ptr_server->buffer = ptr_buffer_server; + } + } + + ptr_buffer_server->all_servers = 1; + gui_window_redraw_buffer (window->buffer); +} + +/* + * gui_buffer_split_server: split the server buffer into many buffers (one by server) + */ + +void +gui_buffer_split_server (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + t_irc_server *ptr_server; + + ptr_buffer = gui_buffer_servers_search (); + + if (ptr_buffer) + { + if (SERVER(ptr_buffer)) + { + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (ptr_server->buffer + && (ptr_server != SERVER(ptr_buffer)) + && (ptr_server->buffer == ptr_buffer)) + { + ptr_server->buffer = NULL; + gui_buffer_new (window, ptr_server, NULL, + BUFFER_TYPE_STANDARD, 0); + } + } + } + ptr_buffer->all_servers = 0; + gui_status_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); + } +} + +/* + * gui_buffer_switch_previous: switch to previous buffer + */ + +void +gui_buffer_switch_previous (t_gui_window *window) +{ + if (!gui_ok) + return; + + /* if only one buffer then return */ + if (gui_buffers == last_gui_buffer) + return; + + if (window->buffer->prev_buffer) + gui_window_switch_to_buffer (window, window->buffer->prev_buffer); + else + gui_window_switch_to_buffer (window, last_gui_buffer); + + gui_window_redraw_buffer (window->buffer); +} + +/* + * gui_buffer_switch_next: switch to next buffer + */ + +void +gui_buffer_switch_next (t_gui_window *window) +{ + if (!gui_ok) + return; + + /* if only one buffer then return */ + if (gui_buffers == last_gui_buffer) + return; + + if (window->buffer->next_buffer) + gui_window_switch_to_buffer (window, window->buffer->next_buffer); + else + gui_window_switch_to_buffer (window, gui_buffers); + + gui_window_redraw_buffer (window->buffer); +} + +/* + * gui_buffer_switch_dcc: switch to dcc buffer (create it if it does not exist) + */ + +void +gui_buffer_switch_dcc (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + + /* check if dcc buffer exists */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->type == BUFFER_TYPE_DCC) + break; + } + if (ptr_buffer) + { + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (ptr_buffer); + } + else + gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_DCC, 1); +} + +/* + * gui_buffer_switch_raw_data: switch to rax IRC data buffer (create it if it does not exist) + */ + +void +gui_buffer_switch_raw_data (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + + /* check if raw IRC data buffer exists */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->type == BUFFER_TYPE_RAW_DATA) + break; + } + if (ptr_buffer) + { + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (ptr_buffer); + } + else + gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_RAW_DATA, 1); +} + +/* + * gui_buffer_switch_by_number: switch to another buffer with number + */ + +t_gui_buffer * +gui_buffer_switch_by_number (t_gui_window *window, int number) +{ + t_gui_buffer *ptr_buffer; + + /* invalid buffer */ + if (number < 0) + return NULL; + + /* buffer is currently displayed ? */ + if (number == window->buffer->number) + return window->buffer; + + /* search for buffer in the list */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if ((ptr_buffer != window->buffer) && (number == ptr_buffer->number)) + { + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (window->buffer); + return ptr_buffer; + } + } + + /* buffer not found */ + return NULL; +} + +/* + * gui_buffer_move_to_number: move a buffer to another number + */ + +void +gui_buffer_move_to_number (t_gui_buffer *buffer, int number) +{ + t_gui_buffer *ptr_buffer; + int i; + + /* if only one buffer then return */ + if (gui_buffers == last_gui_buffer) + return; + + /* buffer number is already ok ? */ + if (number == buffer->number) + return; + + if (number < 1) + number = 1; + + /* remove buffer from list */ + if (buffer == gui_buffers) + { + gui_buffers = buffer->next_buffer; + gui_buffers->prev_buffer = NULL; + } + if (buffer == last_gui_buffer) + { + last_gui_buffer = buffer->prev_buffer; + last_gui_buffer->next_buffer = NULL; + } + if (buffer->prev_buffer) + (buffer->prev_buffer)->next_buffer = buffer->next_buffer; + if (buffer->next_buffer) + (buffer->next_buffer)->prev_buffer = buffer->prev_buffer; + + if (number == 1) + { + gui_buffers->prev_buffer = buffer; + buffer->prev_buffer = NULL; + buffer->next_buffer = gui_buffers; + gui_buffers = buffer; + } + else + { + /* assign new number to all buffers */ + i = 1; + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + ptr_buffer->number = i++; + } + + /* search for new position in the list */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->number == number) + break; + } + if (ptr_buffer) + { + /* insert before buffer found */ + buffer->prev_buffer = ptr_buffer->prev_buffer; + buffer->next_buffer = ptr_buffer; + if (ptr_buffer->prev_buffer) + (ptr_buffer->prev_buffer)->next_buffer = buffer; + ptr_buffer->prev_buffer = buffer; + } + else + { + /* number not found (too big)? => add to end */ + buffer->prev_buffer = last_gui_buffer; + buffer->next_buffer = NULL; + last_gui_buffer->next_buffer = buffer; + last_gui_buffer = buffer; + } + + } + + /* assign new number to all buffers */ + i = 1; + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + ptr_buffer->number = i++; + } + + gui_window_redraw_buffer (buffer); +} + +/* + * gui_buffer_print_log: print buffer infos in log (usually for crash dump) + */ + +void +gui_buffer_print_log (t_gui_buffer *buffer) +{ + t_gui_line *ptr_line; + int num; + + weechat_log_printf ("[buffer (addr:0x%X)]\n", buffer); + weechat_log_printf (" num_displayed. . . . . : %d\n", buffer->num_displayed); + weechat_log_printf (" number . . . . . . . . : %d\n", buffer->number); + weechat_log_printf (" server . . . . . . . . : 0x%X\n", buffer->server); + weechat_log_printf (" all_servers. . . . . . : %d\n", buffer->all_servers); + weechat_log_printf (" channel. . . . . . . . : 0x%X\n", buffer->channel); + weechat_log_printf (" type . . . . . . . . . : %d\n", buffer->type); + weechat_log_printf (" lines. . . . . . . . . : 0x%X\n", buffer->lines); + weechat_log_printf (" last_line. . . . . . . : 0x%X\n", buffer->last_line); + weechat_log_printf (" last_read_line . . . . : 0x%X\n", buffer->last_read_line); + weechat_log_printf (" num_lines. . . . . . . : %d\n", buffer->num_lines); + weechat_log_printf (" line_complete. . . . . : %d\n", buffer->line_complete); + weechat_log_printf (" notify_level . . . . . : %d\n", buffer->notify_level); + weechat_log_printf (" log_filename . . . . . : '%s'\n", buffer->log_filename); + weechat_log_printf (" log_file . . . . . . . : 0x%X\n", buffer->log_file); + weechat_log_printf (" has_input. . . . . . . : %d\n", buffer->has_input); + weechat_log_printf (" input_buffer . . . . . : '%s'\n", buffer->input_buffer); + weechat_log_printf (" input_buffer_color_mask: '%s'\n", buffer->input_buffer_color_mask); + weechat_log_printf (" input_buffer_alloc . . : %d\n", buffer->input_buffer_alloc); + weechat_log_printf (" input_buffer_size. . . : %d\n", buffer->input_buffer_size); + weechat_log_printf (" input_buffer_length. . : %d\n", buffer->input_buffer_length); + weechat_log_printf (" input_buffer_pos . . . : %d\n", buffer->input_buffer_pos); + weechat_log_printf (" input_buffer_1st_disp. : %d\n", buffer->input_buffer_1st_display); + weechat_log_printf (" history. . . . . . . . : 0x%X\n", buffer->history); + weechat_log_printf (" last_history . . . . . : 0x%X\n", buffer->last_history); + weechat_log_printf (" ptr_history. . . . . . : 0x%X\n", buffer->ptr_history); + weechat_log_printf (" prev_buffer. . . . . . : 0x%X\n", buffer->prev_buffer); + weechat_log_printf (" next_buffer. . . . . . : 0x%X\n", buffer->next_buffer); + weechat_log_printf ("\n"); + weechat_log_printf (" => last 100 lines:\n"); + + num = 0; + ptr_line = buffer->last_line; + while (ptr_line && (num < 100)) + { + num++; + ptr_line = ptr_line->prev_line; + } + if (!ptr_line) + ptr_line = buffer->lines; + else + ptr_line = ptr_line->next_line; + + while (ptr_line) + { + num--; + weechat_log_printf (" line N-%05d: %s\n", + num, + (ptr_line->data) ? ptr_line->data : "(empty)"); + + ptr_line = ptr_line->next_line; + } +} diff --git a/src/gui/gui-common.c b/src/gui/gui-common.c index 50066f1a3..12fb81d4c 100644 --- a/src/gui/gui-common.c +++ b/src/gui/gui-common.c @@ -69,742 +69,6 @@ time_t gui_last_activity_time = 0; /* last activity time */ /* (key pressed) */ -/* - * gui_window_tree_init: create first entry in windows tree - */ - -int -gui_window_tree_init (t_gui_window *window) -{ - gui_windows_tree = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); - if (!gui_windows_tree) - return 0; - gui_windows_tree->parent_node = NULL; - gui_windows_tree->split_horiz = 0; - gui_windows_tree->split_pct = 0; - gui_windows_tree->child1 = NULL; - gui_windows_tree->child2 = NULL; - gui_windows_tree->window = window; - return 1; -} - -/* - * gui_window_tree_node_to_leaf: convert a node to a leaf (free any leafs) - * Called when 2 windows are merging into one - */ - -void -gui_window_tree_node_to_leaf (t_gui_window_tree *node, t_gui_window *window) -{ - node->split_horiz = 0; - node->split_pct = 0; - if (node->child1) - { - free (node->child1); - node->child1 = NULL; - } - if (node->child2) - { - free (node->child2); - node->child2 = NULL; - } - node->window = window; - window->ptr_tree = node; -} - -/* - * gui_window_tree_free: delete entire windows tree - */ - -void -gui_window_tree_free (t_gui_window_tree **tree) -{ - if (*tree) - { - if ((*tree)->child1) - gui_window_tree_free (&((*tree)->child1)); - if ((*tree)->child2) - gui_window_tree_free (&((*tree)->child2)); - free (*tree); - *tree = NULL; - } -} - -/* - * gui_window_new: create a new window - */ - -t_gui_window * -gui_window_new (t_gui_window *parent, int x, int y, int width, int height, - int width_pct, int height_pct) -{ - t_gui_window *new_window; - t_gui_window_tree *ptr_tree, *child1, *child2, *ptr_leaf; - -#ifdef DEBUG - weechat_log_printf ("Creating new window (x:%d, y:%d, width:%d, height:%d)\n", - x, y, width, height); -#endif - - if (parent) - { - child1 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); - if (!child1) - return NULL; - child2 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); - if (!child2) - { - free (child1); - return NULL; - } - ptr_tree = parent->ptr_tree; - - if (width_pct == 100) - { - ptr_tree->split_horiz = 1; - ptr_tree->split_pct = height_pct; - } - else - { - ptr_tree->split_horiz = 0; - ptr_tree->split_pct = width_pct; - } - - /* parent window leaf becomes node and we add 2 leafs below - (#1 is parent win, #2 is new win) */ - - parent->ptr_tree = child1; - child1->parent_node = ptr_tree; - child1->child1 = NULL; - child1->child2 = NULL; - child1->window = ptr_tree->window; - - child2->parent_node = ptr_tree; - child2->child1 = NULL; - child2->child2 = NULL; - child2->window = NULL; /* will be assigned by new window below */ - - ptr_tree->child1 = child1; - ptr_tree->child2 = child2; - ptr_tree->window = NULL; /* leaf becomes node */ - - ptr_leaf = child2; - } - else - { - if (!gui_window_tree_init (NULL)) - return NULL; - ptr_leaf = gui_windows_tree; - } - - if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window))))) - { - new_window->win_x = x; - new_window->win_y = y; - new_window->win_width = width; - new_window->win_height = height; - new_window->win_width_pct = width_pct; - new_window->win_height_pct = height_pct; - - new_window->new_x = -1; - new_window->new_y = -1; - new_window->new_width = -1; - new_window->new_height = -1; - - new_window->win_chat_x = 0; - new_window->win_chat_y = 0; - new_window->win_chat_width = 0; - new_window->win_chat_height = 0; - new_window->win_chat_cursor_x = 0; - new_window->win_chat_cursor_y = 0; - - new_window->win_nick_x = 0; - new_window->win_nick_y = 0; - new_window->win_nick_width = 0; - new_window->win_nick_height = 0; - new_window->win_nick_num_max = 0; - new_window->win_nick_start = 0; - - new_window->win_input_x = 0; - - new_window->win_title = NULL; - new_window->win_chat = NULL; - new_window->win_nick = NULL; - new_window->win_status = NULL; - new_window->win_infobar = NULL; - new_window->win_input = NULL; - new_window->win_separator = NULL; - - new_window->textview_chat = NULL; - new_window->textbuffer_chat = NULL; - new_window->texttag_chat = NULL; - new_window->textview_nicklist = NULL; - new_window->textbuffer_nicklist = NULL; - - new_window->dcc_first = NULL; - new_window->dcc_selected = NULL; - new_window->dcc_last_displayed = NULL; - - new_window->buffer = NULL; - - new_window->first_line_displayed = 0; - new_window->start_line = NULL; - new_window->start_line_pos = 0; - new_window->scroll = 0; - - new_window->ptr_tree = ptr_leaf; - ptr_leaf->window = new_window; - - /* add window to windows queue */ - new_window->prev_window = last_gui_window; - if (gui_windows) - last_gui_window->next_window = new_window; - else - gui_windows = new_window; - last_gui_window = new_window; - new_window->next_window = NULL; - } - else - return NULL; - - return new_window; -} - -/* - * gui_buffer_servers_search: search servers buffer - * (when same buffer is used for all servers) - */ - -t_gui_buffer * -gui_buffer_servers_search () -{ - t_gui_buffer *ptr_buffer; - - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->all_servers) - return ptr_buffer; - } - - /* buffer not found */ - return NULL; -} - -/* - * gui_buffer_new: create a new buffer in current window - */ - -t_gui_buffer * -gui_buffer_new (t_gui_window *window, void *server, void *channel, int type, - int switch_to_buffer) -{ - t_gui_buffer *new_buffer, *ptr_buffer; - -#ifdef DEBUG - weechat_log_printf ("Creating new buffer\n"); -#endif - - /* use first buffer if no server was assigned to this buffer */ - if ((type == BUFFER_TYPE_STANDARD) && gui_buffers && (!SERVER(gui_buffers))) - { - if (server) - ((t_irc_server *)(server))->buffer = gui_buffers; - if (channel) - ((t_irc_channel *)(channel))->buffer = gui_buffers; - gui_buffers->server = server; - gui_buffers->channel = channel; - if (cfg_look_one_server_buffer && server && !channel) - gui_buffers->all_servers = 1; - if (cfg_log_auto_server) - log_start (gui_buffers); - return gui_buffers; - } - - if (cfg_look_one_server_buffer && (type == BUFFER_TYPE_STANDARD) && - gui_buffers && server && !channel) - { - ptr_buffer = gui_buffer_servers_search (); - if (ptr_buffer) - { - ((t_irc_server *)(server))->buffer = gui_buffers; - gui_buffers->server = server; - if (switch_to_buffer) - gui_switch_to_buffer (window, gui_buffers); - gui_redraw_buffer (gui_buffers); - return gui_buffers; - } - } - - if ((new_buffer = (t_gui_buffer *)(malloc (sizeof (t_gui_buffer))))) - { - new_buffer->num_displayed = 0; - new_buffer->number = (last_gui_buffer) ? last_gui_buffer->number + 1 : 1; - - /* assign server and channel to buffer */ - new_buffer->server = server; - new_buffer->all_servers = 0; - new_buffer->channel = channel; - new_buffer->type = type; - if (new_buffer->type == BUFFER_TYPE_RAW_DATA) - gui_buffer_raw_data = new_buffer; - /* assign buffer to server and channel */ - if (server && !channel) - { - SERVER(new_buffer)->buffer = new_buffer; - new_buffer->all_servers = (cfg_look_one_server_buffer) ? 1 : 0; - } - if (!gui_buffers && cfg_look_one_server_buffer) - new_buffer->all_servers = 1; - if (channel) - CHANNEL(new_buffer)->buffer = new_buffer; - - if (!window->buffer) - { - window->buffer = new_buffer; - window->first_line_displayed = 1; - window->start_line = NULL; - window->start_line_pos = 0; - gui_calculate_pos_size (window, 1); - gui_window_init_subwindows (window); - } - - /* init lines */ - new_buffer->lines = NULL; - new_buffer->last_line = NULL; - new_buffer->last_read_line = NULL; - new_buffer->num_lines = 0; - new_buffer->line_complete = 1; - - /* notify level */ - new_buffer->notify_level = channel_get_notify_level (server, channel); - - /* create/append to log file */ - new_buffer->log_filename = NULL; - new_buffer->log_file = NULL; - if ((cfg_log_auto_server && BUFFER_IS_SERVER(new_buffer)) - || (cfg_log_auto_channel && BUFFER_IS_CHANNEL(new_buffer)) - || (cfg_log_auto_private && BUFFER_IS_PRIVATE(new_buffer))) - log_start (new_buffer); - - /* init input buffer */ - new_buffer->has_input = (new_buffer->type == BUFFER_TYPE_STANDARD) ? 1 : 0; - if (new_buffer->has_input) - { - new_buffer->input_buffer_alloc = INPUT_BUFFER_BLOCK_SIZE; - new_buffer->input_buffer = (char *) malloc (INPUT_BUFFER_BLOCK_SIZE); - new_buffer->input_buffer_color_mask = (char *) malloc (INPUT_BUFFER_BLOCK_SIZE); - new_buffer->input_buffer[0] = '\0'; - new_buffer->input_buffer_color_mask[0] = '\0'; - } - else - { - new_buffer->input_buffer = NULL; - new_buffer->input_buffer_color_mask = NULL; - } - new_buffer->input_buffer_size = 0; - new_buffer->input_buffer_length = 0; - new_buffer->input_buffer_pos = 0; - new_buffer->input_buffer_1st_display = 0; - - /* init completion */ - completion_init (&(new_buffer->completion), server, channel); - - /* init history */ - new_buffer->history = NULL; - new_buffer->last_history = NULL; - new_buffer->ptr_history = NULL; - new_buffer->num_history = 0; - - /* add buffer to buffers queue */ - new_buffer->prev_buffer = last_gui_buffer; - if (gui_buffers) - last_gui_buffer->next_buffer = new_buffer; - else - gui_buffers = new_buffer; - last_gui_buffer = new_buffer; - new_buffer->next_buffer = NULL; - - /* move buffer next to server */ - if (server && cfg_look_open_near_server && (!cfg_look_one_server_buffer)) - { - ptr_buffer = SERVER(new_buffer)->buffer; - while (ptr_buffer && (ptr_buffer->server == server)) - { - ptr_buffer = ptr_buffer->next_buffer; - } - if (ptr_buffer) - gui_buffer_move_to_number (new_buffer, ptr_buffer->number); - } - - /* switch to new buffer */ - if (switch_to_buffer) - gui_switch_to_buffer (window, new_buffer); - - /* redraw buffer */ - gui_redraw_buffer (new_buffer); - } - else - return NULL; - - return new_buffer; -} - -/* - * gui_buffer_search: search a buffer by server and channel name - */ - -t_gui_buffer * -gui_buffer_search (char *server, char *channel) -{ - t_irc_server *ptr_server; - t_irc_channel *ptr_channel; - t_gui_buffer *ptr_buffer; - - ptr_server = NULL; - ptr_channel = NULL; - ptr_buffer = NULL; - - /* nothing given => print on current buffer */ - if ((!server || !server[0]) && (!channel || !channel[0])) - ptr_buffer = gui_current_window->buffer; - else - { - if (server && server[0]) - { - ptr_server = server_search (server); - if (!ptr_server) - return NULL; - } - else - { - ptr_server = SERVER(gui_current_window->buffer); - if (!ptr_server) - ptr_server = SERVER(gui_buffers); - } - - if (channel && channel[0]) - { - if (ptr_server) - { - ptr_channel = channel_search_any (ptr_server, channel); - if (ptr_channel) - ptr_buffer = ptr_channel->buffer; - } - } - else - { - if (ptr_server) - ptr_buffer = ptr_server->buffer; - else - ptr_buffer = gui_current_window->buffer; - } - } - - if (!ptr_buffer) - return NULL; - - return (ptr_buffer->type != BUFFER_TYPE_STANDARD) ? - gui_buffers : ptr_buffer; -} - -/* - * gui_buffer_find_window: find a window displaying buffer - */ - -t_gui_window * -gui_buffer_find_window (t_gui_buffer *buffer) -{ - t_gui_window *ptr_win; - - if (gui_current_window->buffer == buffer) - return gui_current_window; - - for (ptr_win = gui_windows; ptr_win; - ptr_win = ptr_win->next_window) - { - if (ptr_win->buffer == buffer) - return ptr_win; - } - - /* no window found */ - return NULL; -} - -/* - * gui_get_dcc_buffer: get pointer to DCC buffer (DCC buffer created if not existing) - */ - -t_gui_buffer * -gui_get_dcc_buffer (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - - /* check if dcc buffer exists */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->type == BUFFER_TYPE_DCC) - break; - } - if (ptr_buffer) - return ptr_buffer; - else - return gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_DCC, 0); -} - -/* - * gui_buffer_clear: clear buffer content - */ - -void -gui_buffer_clear (t_gui_buffer *buffer) -{ - t_gui_window *ptr_win; - t_gui_line *ptr_line; - - /* remove buffer from hotlist */ - hotlist_remove_buffer (buffer); - - /* remove lines from buffer */ - while (buffer->lines) - { - ptr_line = buffer->lines->next_line; - if (buffer->lines->data) - free (buffer->lines->data); - free (buffer->lines); - buffer->lines = ptr_line; - } - - buffer->lines = NULL; - buffer->last_line = NULL; - buffer->num_lines = 0; - buffer->line_complete = 1; - - /* remove any scroll for buffer */ - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - { - if (ptr_win->buffer == buffer) - { - ptr_win->first_line_displayed = 1; - ptr_win->start_line = NULL; - ptr_win->start_line_pos = 0; - } - } - - gui_draw_buffer_chat (buffer, 1); - gui_draw_buffer_status (buffer, 1); -} - -/* - * gui_buffer_clear_all: clear all buffers content - */ - -void -gui_buffer_clear_all () -{ - t_gui_buffer *ptr_buffer; - - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - gui_buffer_clear (ptr_buffer); -} - -/* - * gui_window_free: delete a window - */ - -void -gui_window_free (t_gui_window *window) -{ - if (window->buffer && (window->buffer->num_displayed > 0)) - window->buffer->num_displayed--; - - /* remove window from windows list */ - if (window->prev_window) - window->prev_window->next_window = window->next_window; - if (window->next_window) - window->next_window->prev_window = window->prev_window; - if (gui_windows == window) - gui_windows = window->next_window; - if (last_gui_window == window) - last_gui_window = window->prev_window; - - free (window); -} - -/* - * gui_line_free: delete a line from a buffer - */ - -void -gui_line_free (t_gui_line *line) -{ - t_gui_window *ptr_win; - - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - { - if (ptr_win->start_line == line) - { - ptr_win->start_line = ptr_win->start_line->next_line; - ptr_win->start_line_pos = 0; - gui_draw_buffer_chat (ptr_win->buffer, 0); - gui_draw_buffer_status (ptr_win->buffer, 0); - } - } - if (line->nick) - free (line->nick); - if (line->data) - free (line->data); - free (line); -} - -/* - * gui_buffer_free: delete a buffer - */ - -void -gui_buffer_free (t_gui_buffer *buffer, int switch_to_another) -{ - t_gui_window *ptr_win; - t_gui_buffer *ptr_buffer; - t_gui_line *ptr_line; - t_irc_server *ptr_server; - int create_new; - - create_new = (buffer->server || buffer->channel); - - hotlist_remove_buffer (buffer); - if (hotlist_initial_buffer == buffer) - hotlist_initial_buffer = NULL; - - if (gui_buffer_before_dcc == buffer) - gui_buffer_before_dcc = NULL; - - if (gui_buffer_before_raw_data == buffer) - gui_buffer_before_raw_data = NULL; - - if (buffer->type == BUFFER_TYPE_RAW_DATA) - gui_buffer_raw_data = NULL; - - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (ptr_server->saved_buffer == buffer) - ptr_server->saved_buffer = NULL; - } - - if (switch_to_another) - { - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - { - if ((buffer == ptr_win->buffer) && - ((buffer->next_buffer) || (buffer->prev_buffer))) - gui_buffer_switch_previous (ptr_win); - } - } - - /* decrease buffer number for all next buffers */ - for (ptr_buffer = buffer->next_buffer; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - ptr_buffer->number--; - } - - /* free lines and messages */ - while (buffer->lines) - { - ptr_line = buffer->lines->next_line; - gui_line_free (buffer->lines); - buffer->lines = ptr_line; - } - - /* close log if opened */ - if (buffer->log_file) - log_end (buffer); - - if (buffer->input_buffer) - free (buffer->input_buffer); - if (buffer->input_buffer_color_mask) - free (buffer->input_buffer_color_mask); - - completion_free (&(buffer->completion)); - - history_buffer_free (buffer); - - /* remove buffer from buffers list */ - if (buffer->prev_buffer) - buffer->prev_buffer->next_buffer = buffer->next_buffer; - if (buffer->next_buffer) - buffer->next_buffer->prev_buffer = buffer->prev_buffer; - if (gui_buffers == buffer) - gui_buffers = buffer->next_buffer; - if (last_gui_buffer == buffer) - last_gui_buffer = buffer->prev_buffer; - - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - { - if (ptr_win->buffer == buffer) - ptr_win->buffer = NULL; - } - - free (buffer); - - /* always at least one buffer */ - if (!gui_buffers && create_new && switch_to_another) - (void) gui_buffer_new (gui_windows, NULL, NULL, - BUFFER_TYPE_STANDARD, 1); -} - -/* - * gui_line_new: create new line for a buffer - */ - -t_gui_line * -gui_line_new (t_gui_buffer *buffer) -{ - t_gui_line *new_line, *ptr_line; - - if ((new_line = (t_gui_line *) malloc (sizeof (struct t_gui_line)))) - { - new_line->length = 0; - new_line->length_align = 0; - new_line->log_write = 1; - new_line->line_with_message = 0; - new_line->line_with_highlight = 0; - new_line->nick = NULL; - new_line->data = NULL; - new_line->ofs_after_date = -1; - new_line->ofs_start_message = -1; - if (!buffer->lines) - buffer->lines = new_line; - else - buffer->last_line->next_line = new_line; - new_line->prev_line = buffer->last_line; - new_line->next_line = NULL; - buffer->last_line = new_line; - buffer->num_lines++; - } - else - { - weechat_log_printf (_("Not enough memory for new line\n")); - return NULL; - } - - /* remove one line if necessary */ - if ((cfg_history_max_lines > 0) - && (buffer->num_lines > cfg_history_max_lines)) - { - if (buffer->last_line == buffer->lines) - buffer->last_line = NULL; - ptr_line = buffer->lines->next_line; - gui_line_free (buffer->lines); - buffer->lines = ptr_line; - ptr_line->prev_line = NULL; - buffer->num_lines--; - gui_draw_buffer_chat (buffer, 1); - } - - return new_line; -} - /* * gui_word_strlen: returns length of a word * special chars like color, bold, .. are ignored @@ -818,7 +82,7 @@ gui_word_strlen (t_gui_window *window, char *string) length = 0; while (string && string[0]) { - string = gui_word_get_next_char (window, (unsigned char *)string, 0); + string = gui_chat_word_get_next_char (window, (unsigned char *)string, 0); if (string) length++; } @@ -842,7 +106,7 @@ gui_word_real_pos (t_gui_window *window, char *string, int pos) while (string && string[0] && (pos > 0)) { saved_pos = string; - string = gui_word_get_next_char (window, (unsigned char *)string, 0); + string = gui_chat_word_get_next_char (window, (unsigned char *)string, 0); pos--; if (string) real_pos += (string - saved_pos); @@ -864,7 +128,7 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message) if (buffer->line_complete) { buffer->line_complete = 0; - if (!gui_line_new (buffer)) + if (!gui_buffer_line_new (buffer)) return; } @@ -917,8 +181,8 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message) pos[0] = '\n'; if (buffer->num_displayed > 0) { - gui_draw_buffer_chat_line (buffer, buffer->last_line); - gui_draw_buffer_chat (buffer, 0); + gui_chat_draw_line (buffer, buffer->last_line); + gui_chat_draw (buffer, 0); } if (gui_add_hotlist && (buffer->num_displayed == 0)) { @@ -934,7 +198,7 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message) hotlist_add (HOTLIST_MSG, SERVER(buffer), buffer); else hotlist_add (HOTLIST_LOW, SERVER(buffer), buffer); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); } } } @@ -1169,7 +433,7 @@ gui_infobar_printf (int time_displayed, int color, char *message, ...) ptr_infobar->remaining_time = (time_displayed <= 0) ? -1 : time_displayed; ptr_infobar->next_infobar = gui_infobar; gui_infobar = ptr_infobar; - gui_draw_buffer_infobar (gui_current_window->buffer, 1); + gui_infobar_draw (gui_current_window->buffer, 1); } else weechat_log_printf (_("Not enough memory for infobar message\n")); @@ -1337,7 +601,7 @@ gui_exec_action_dcc (t_gui_window *window, char *actions) && (!DCC_ENDED(dcc_selected->status))) { dcc_close (dcc_selected, DCC_ABORTED); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); } break; /* purge old DCC */ @@ -1352,7 +616,7 @@ gui_exec_action_dcc (t_gui_window *window, char *actions) dcc_free (ptr_dcc); ptr_dcc = ptr_dcc_next; } - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); break; /* close DCC window */ case 'q': @@ -1360,12 +624,12 @@ gui_exec_action_dcc (t_gui_window *window, char *actions) if (gui_buffer_before_dcc) { ptr_buffer = window->buffer; - gui_switch_to_buffer (window, gui_buffer_before_dcc); + gui_window_switch_to_buffer (window, gui_buffer_before_dcc); gui_buffer_free (ptr_buffer, 0); } else gui_buffer_free (window->buffer, 1); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); return; break; /* remove from DCC list */ @@ -1379,7 +643,7 @@ gui_exec_action_dcc (t_gui_window *window, char *actions) else window->dcc_selected = NULL; dcc_free (dcc_selected); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); } break; } @@ -1411,13 +675,13 @@ gui_exec_action_raw_data (t_gui_window *window, char *actions) if (gui_buffer_before_raw_data) { ptr_buffer = window->buffer; - gui_switch_to_buffer (window, - gui_buffer_before_raw_data); + gui_window_switch_to_buffer (window, + gui_buffer_before_raw_data); gui_buffer_free (ptr_buffer, 0); } else gui_buffer_free (window->buffer, 1); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); return; break; } @@ -1474,533 +738,3 @@ gui_insert_string_input (t_gui_window *window, char *string, int pos) } return 0; } - -/* - * gui_merge_servers: merge server buffers in one buffer - */ - -void -gui_merge_servers (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer_server, *ptr_buffer; - t_irc_server *ptr_server; - - /* new server buffer is the first server buffer found */ - for (ptr_buffer_server = gui_buffers; ptr_buffer_server; - ptr_buffer_server = ptr_buffer_server->next_buffer) - { - if (BUFFER_IS_SERVER(ptr_buffer_server)) - break; - } - - /* no server buffer found */ - if (!ptr_buffer_server) - return; - - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - if ((ptr_buffer != ptr_buffer_server) - && (BUFFER_IS_SERVER(ptr_buffer))) - { - ptr_server = SERVER(ptr_buffer); - - /* add (by pointer artefact) lines from buffer found to server buffer */ - if (ptr_buffer->lines) - { - if (ptr_buffer_server->lines) - { - ptr_buffer->lines->prev_line = - ptr_buffer_server->last_line; - ptr_buffer_server->last_line->next_line = - ptr_buffer->lines; - ptr_buffer_server->last_line = - ptr_buffer->last_line; - } - else - { - ptr_buffer_server->lines = ptr_buffer->lines; - ptr_buffer_server->last_line = ptr_buffer->last_line; - } - } - - /* free buffer but not lines, because they're now used by - our unique server buffer */ - ptr_buffer->lines = NULL; - gui_buffer_free (ptr_buffer, 1); - - /* asociate server with new server buffer */ - ptr_server->buffer = ptr_buffer_server; - } - } - - ptr_buffer_server->all_servers = 1; - gui_redraw_buffer (window->buffer); -} - -/* - * gui_split_server: split the server buffer into many buffers (one by server) - */ - -void -gui_split_server (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - t_irc_server *ptr_server; - - ptr_buffer = gui_buffer_servers_search (); - - if (ptr_buffer) - { - if (SERVER(ptr_buffer)) - { - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (ptr_server->buffer - && (ptr_server != SERVER(ptr_buffer)) - && (ptr_server->buffer == ptr_buffer)) - { - ptr_server->buffer = NULL; - gui_buffer_new (window, ptr_server, NULL, - BUFFER_TYPE_STANDARD, 0); - } - } - } - ptr_buffer->all_servers = 0; - gui_draw_buffer_status (window->buffer, 1); - gui_draw_buffer_input (window->buffer, 1); - } -} - -/* - * gui_window_switch_server: switch server on servers buffer - * (if same buffer is used for all buffers) - */ - -void -gui_window_switch_server (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - t_irc_server *ptr_server; - - ptr_buffer = gui_buffer_servers_search (); - - if (ptr_buffer) - { - ptr_server = (SERVER(ptr_buffer) && SERVER(ptr_buffer)->next_server) ? - SERVER(ptr_buffer)->next_server : irc_servers; - while (ptr_server != SERVER(window->buffer)) - { - if (ptr_server->buffer) - break; - if (ptr_server->next_server) - ptr_server = ptr_server->next_server; - else - { - if (SERVER(ptr_buffer) == NULL) - { - ptr_server = NULL; - break; - } - ptr_server = irc_servers; - } - } - if (ptr_server && (ptr_server != SERVER(ptr_buffer))) - { - ptr_buffer->server = ptr_server; - gui_draw_buffer_status (window->buffer, 1); - gui_draw_buffer_input (window->buffer, 1); - } - } -} - -/* - * gui_buffer_switch_previous: switch to previous buffer - */ - -void -gui_buffer_switch_previous (t_gui_window *window) -{ - if (!gui_ok) - return; - - /* if only one buffer then return */ - if (gui_buffers == last_gui_buffer) - return; - - if (window->buffer->prev_buffer) - gui_switch_to_buffer (window, window->buffer->prev_buffer); - else - gui_switch_to_buffer (window, last_gui_buffer); - - gui_redraw_buffer (window->buffer); -} - -/* - * gui_buffer_switch_next: switch to next buffer - */ - -void -gui_buffer_switch_next (t_gui_window *window) -{ - if (!gui_ok) - return; - - /* if only one buffer then return */ - if (gui_buffers == last_gui_buffer) - return; - - if (window->buffer->next_buffer) - gui_switch_to_buffer (window, window->buffer->next_buffer); - else - gui_switch_to_buffer (window, gui_buffers); - - gui_redraw_buffer (window->buffer); -} - -/* - * gui_window_switch_previous: switch to previous window - */ - -void -gui_window_switch_previous (t_gui_window *window) -{ - if (!gui_ok) - return; - - /* if only one window then return */ - if (gui_windows == last_gui_window) - return; - - gui_current_window = (window->prev_window) ? window->prev_window : last_gui_window; - gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); - gui_redraw_buffer (gui_current_window->buffer); -} - -/* - * gui_window_switch_next: switch to next window - */ - -void -gui_window_switch_next (t_gui_window *window) -{ - if (!gui_ok) - return; - - /* if only one window then return */ - if (gui_windows == last_gui_window) - return; - - gui_current_window = (window->next_window) ? window->next_window : gui_windows; - gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); - gui_redraw_buffer (gui_current_window->buffer); -} - -/* - * gui_window_switch_by_buffer: switch to next window displaying a buffer - */ - -void -gui_window_switch_by_buffer (t_gui_window *window, int buffer_number) -{ - t_gui_window *ptr_win; - - if (!gui_ok) - return; - - ptr_win = (window->next_window) ? window->next_window : gui_windows; - while (ptr_win != window) - { - if (ptr_win->buffer->number == buffer_number) - { - gui_current_window = ptr_win; - gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); - gui_redraw_buffer (gui_current_window->buffer); - return; - } - ptr_win = (ptr_win->next_window) ? ptr_win->next_window : gui_windows; - } -} - -/* - * gui_buffer_switch_dcc: switch to dcc buffer (create it if it does not exist) - */ - -void -gui_buffer_switch_dcc (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - - /* check if dcc buffer exists */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->type == BUFFER_TYPE_DCC) - break; - } - if (ptr_buffer) - { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (ptr_buffer); - } - else - gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_DCC, 1); -} - -/* - * gui_buffer_switch_raw_data: switch to rax IRC data buffer (create it if it does not exist) - */ - -void -gui_buffer_switch_raw_data (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - - /* check if raw IRC data buffer exists */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->type == BUFFER_TYPE_RAW_DATA) - break; - } - if (ptr_buffer) - { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (ptr_buffer); - } - else - gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_RAW_DATA, 1); -} - -/* - * gui_buffer_switch_by_number: switch to another buffer with number - */ - -t_gui_buffer * -gui_buffer_switch_by_number (t_gui_window *window, int number) -{ - t_gui_buffer *ptr_buffer; - - /* invalid buffer */ - if (number < 0) - return NULL; - - /* buffer is currently displayed ? */ - if (number == window->buffer->number) - return window->buffer; - - /* search for buffer in the list */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if ((ptr_buffer != window->buffer) && (number == ptr_buffer->number)) - { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (window->buffer); - return ptr_buffer; - } - } - - /* buffer not found */ - return NULL; -} - -/* - * gui_buffer_move_to_number: move a buffer to another number - */ - -void -gui_buffer_move_to_number (t_gui_buffer *buffer, int number) -{ - t_gui_buffer *ptr_buffer; - int i; - - /* if only one buffer then return */ - if (gui_buffers == last_gui_buffer) - return; - - /* buffer number is already ok ? */ - if (number == buffer->number) - return; - - if (number < 1) - number = 1; - - /* remove buffer from list */ - if (buffer == gui_buffers) - { - gui_buffers = buffer->next_buffer; - gui_buffers->prev_buffer = NULL; - } - if (buffer == last_gui_buffer) - { - last_gui_buffer = buffer->prev_buffer; - last_gui_buffer->next_buffer = NULL; - } - if (buffer->prev_buffer) - (buffer->prev_buffer)->next_buffer = buffer->next_buffer; - if (buffer->next_buffer) - (buffer->next_buffer)->prev_buffer = buffer->prev_buffer; - - if (number == 1) - { - gui_buffers->prev_buffer = buffer; - buffer->prev_buffer = NULL; - buffer->next_buffer = gui_buffers; - gui_buffers = buffer; - } - else - { - /* assign new number to all buffers */ - i = 1; - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - ptr_buffer->number = i++; - } - - /* search for new position in the list */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->number == number) - break; - } - if (ptr_buffer) - { - /* insert before buffer found */ - buffer->prev_buffer = ptr_buffer->prev_buffer; - buffer->next_buffer = ptr_buffer; - if (ptr_buffer->prev_buffer) - (ptr_buffer->prev_buffer)->next_buffer = buffer; - ptr_buffer->prev_buffer = buffer; - } - else - { - /* number not found (too big)? => add to end */ - buffer->prev_buffer = last_gui_buffer; - buffer->next_buffer = NULL; - last_gui_buffer->next_buffer = buffer; - last_gui_buffer = buffer; - } - - } - - /* assign new number to all buffers */ - i = 1; - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - ptr_buffer->number = i++; - } - - gui_redraw_buffer (buffer); -} - -/* - * gui_window_print_log: print window infos in log (usually for crash dump) - */ - -void -gui_window_print_log (t_gui_window *window) -{ - weechat_log_printf ("[window (addr:0x%X)]\n", window); - weechat_log_printf (" win_x . . . . . . . : %d\n", window->win_x); - weechat_log_printf (" win_y . . . . . . . : %d\n", window->win_y); - weechat_log_printf (" win_width . . . . . : %d\n", window->win_width); - weechat_log_printf (" win_height. . . . . : %d\n", window->win_height); - weechat_log_printf (" win_width_pct . . . : %d\n", window->win_width_pct); - weechat_log_printf (" win_height_pct. . . : %d\n", window->win_height_pct); - weechat_log_printf (" win_chat_x. . . . . : %d\n", window->win_chat_x); - weechat_log_printf (" win_chat_y. . . . . : %d\n", window->win_chat_y); - weechat_log_printf (" win_chat_width. . . : %d\n", window->win_chat_width); - weechat_log_printf (" win_chat_height . . : %d\n", window->win_chat_height); - weechat_log_printf (" win_chat_cursor_x . : %d\n", window->win_chat_cursor_x); - weechat_log_printf (" win_chat_cursor_y . : %d\n", window->win_chat_cursor_y); - weechat_log_printf (" win_nick_x. . . . . : %d\n", window->win_nick_x); - weechat_log_printf (" win_nick_y. . . . . : %d\n", window->win_nick_y); - weechat_log_printf (" win_nick_width. . . : %d\n", window->win_nick_width); - weechat_log_printf (" win_nick_height . . : %d\n", window->win_nick_height); - weechat_log_printf (" win_nick_start. . . : %d\n", window->win_nick_start); - weechat_log_printf (" win_title . . . . . : 0x%X\n", window->win_title); - weechat_log_printf (" win_chat. . . . . . : 0x%X\n", window->win_chat); - weechat_log_printf (" win_nick. . . . . . : 0x%X\n", window->win_nick); - weechat_log_printf (" win_status. . . . . : 0x%X\n", window->win_status); - weechat_log_printf (" win_infobar . . . . : 0x%X\n", window->win_infobar); - weechat_log_printf (" win_input . . . . . : 0x%X\n", window->win_input); - weechat_log_printf (" win_separator . . . : 0x%X\n", window->win_separator); - weechat_log_printf (" textview_chat . . . : 0x%X\n", window->textview_chat); - weechat_log_printf (" textbuffer_chat . . : 0x%X\n", window->textbuffer_chat); - weechat_log_printf (" texttag_chat. . . . : 0x%X\n", window->texttag_chat); - weechat_log_printf (" textview_nicklist . : 0x%X\n", window->textview_nicklist); - weechat_log_printf (" textbuffer_nicklist : 0x%X\n", window->textbuffer_nicklist); - weechat_log_printf (" dcc_first . . . . . : 0x%X\n", window->dcc_first); - weechat_log_printf (" dcc_selected. . . . : 0x%X\n", window->dcc_selected); - weechat_log_printf (" dcc_last_displayed. : 0x%X\n", window->dcc_last_displayed); - weechat_log_printf (" buffer. . . . . . . : 0x%X\n", window->buffer); - weechat_log_printf (" first_line_displayed: %d\n", window->first_line_displayed); - weechat_log_printf (" start_line. . . . . : 0x%X\n", window->start_line); - weechat_log_printf (" start_line_pos. . . : %d\n", window->start_line_pos); - weechat_log_printf (" prev_window . . . . : 0x%X\n", window->prev_window); - weechat_log_printf (" next_window . . . . : 0x%X\n", window->next_window); - -} - -/* - * gui_buffer_print_log: print buffer infos in log (usually for crash dump) - */ - -void -gui_buffer_print_log (t_gui_buffer *buffer) -{ - t_gui_line *ptr_line; - int num; - - weechat_log_printf ("[buffer (addr:0x%X)]\n", buffer); - weechat_log_printf (" num_displayed. . . . . : %d\n", buffer->num_displayed); - weechat_log_printf (" number . . . . . . . . : %d\n", buffer->number); - weechat_log_printf (" server . . . . . . . . : 0x%X\n", buffer->server); - weechat_log_printf (" all_servers. . . . . . : %d\n", buffer->all_servers); - weechat_log_printf (" channel. . . . . . . . : 0x%X\n", buffer->channel); - weechat_log_printf (" type . . . . . . . . . : %d\n", buffer->type); - weechat_log_printf (" lines. . . . . . . . . : 0x%X\n", buffer->lines); - weechat_log_printf (" last_line. . . . . . . : 0x%X\n", buffer->last_line); - weechat_log_printf (" last_read_line . . . . : 0x%X\n", buffer->last_read_line); - weechat_log_printf (" num_lines. . . . . . . : %d\n", buffer->num_lines); - weechat_log_printf (" line_complete. . . . . : %d\n", buffer->line_complete); - weechat_log_printf (" notify_level . . . . . : %d\n", buffer->notify_level); - weechat_log_printf (" log_filename . . . . . : '%s'\n", buffer->log_filename); - weechat_log_printf (" log_file . . . . . . . : 0x%X\n", buffer->log_file); - weechat_log_printf (" has_input. . . . . . . : %d\n", buffer->has_input); - weechat_log_printf (" input_buffer . . . . . : '%s'\n", buffer->input_buffer); - weechat_log_printf (" input_buffer_color_mask: '%s'\n", buffer->input_buffer_color_mask); - weechat_log_printf (" input_buffer_alloc . . : %d\n", buffer->input_buffer_alloc); - weechat_log_printf (" input_buffer_size. . . : %d\n", buffer->input_buffer_size); - weechat_log_printf (" input_buffer_length. . : %d\n", buffer->input_buffer_length); - weechat_log_printf (" input_buffer_pos . . . : %d\n", buffer->input_buffer_pos); - weechat_log_printf (" input_buffer_1st_disp. : %d\n", buffer->input_buffer_1st_display); - weechat_log_printf (" history. . . . . . . . : 0x%X\n", buffer->history); - weechat_log_printf (" last_history . . . . . : 0x%X\n", buffer->last_history); - weechat_log_printf (" ptr_history. . . . . . : 0x%X\n", buffer->ptr_history); - weechat_log_printf (" prev_buffer. . . . . . : 0x%X\n", buffer->prev_buffer); - weechat_log_printf (" next_buffer. . . . . . : 0x%X\n", buffer->next_buffer); - weechat_log_printf ("\n"); - weechat_log_printf (" => last 100 lines:\n"); - - num = 0; - ptr_line = buffer->last_line; - while (ptr_line && (num < 100)) - { - num++; - ptr_line = ptr_line->prev_line; - } - if (!ptr_line) - ptr_line = buffer->lines; - else - ptr_line = ptr_line->next_line; - - while (ptr_line) - { - num--; - weechat_log_printf (" line N-%05d: %s\n", - num, - (ptr_line->data) ? ptr_line->data : "(empty)"); - - ptr_line = ptr_line->next_line; - } -} diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c index 47d570891..94662b956 100644 --- a/src/gui/gui-keyboard.c +++ b/src/gui/gui-keyboard.c @@ -150,7 +150,7 @@ gui_key_init () gui_key_grab = 0; gui_key_grab_count = 0; - gui_input_default_key_bindings (); + gui_keyboard_default_bindings (); } /* diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c new file mode 100644 index 000000000..7211e66b3 --- /dev/null +++ b/src/gui/gui-window.c @@ -0,0 +1,424 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-window.c: window functions, used by all GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../common/weechat.h" +#include "gui.h" +#include "../common/command.h" +#include "../common/weeconfig.h" +#include "../common/history.h" +#include "../common/hotlist.h" +#include "../common/log.h" +#include "../common/utf8.h" +#include "../irc/irc.h" + + +/* + * gui_window_tree_init: create first entry in windows tree + */ + +int +gui_window_tree_init (t_gui_window *window) +{ + gui_windows_tree = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); + if (!gui_windows_tree) + return 0; + gui_windows_tree->parent_node = NULL; + gui_windows_tree->split_horiz = 0; + gui_windows_tree->split_pct = 0; + gui_windows_tree->child1 = NULL; + gui_windows_tree->child2 = NULL; + gui_windows_tree->window = window; + return 1; +} + +/* + * gui_window_tree_node_to_leaf: convert a node to a leaf (free any leafs) + * Called when 2 windows are merging into one + */ + +void +gui_window_tree_node_to_leaf (t_gui_window_tree *node, t_gui_window *window) +{ + node->split_horiz = 0; + node->split_pct = 0; + if (node->child1) + { + free (node->child1); + node->child1 = NULL; + } + if (node->child2) + { + free (node->child2); + node->child2 = NULL; + } + node->window = window; + window->ptr_tree = node; +} + +/* + * gui_window_tree_free: delete entire windows tree + */ + +void +gui_window_tree_free (t_gui_window_tree **tree) +{ + if (*tree) + { + if ((*tree)->child1) + gui_window_tree_free (&((*tree)->child1)); + if ((*tree)->child2) + gui_window_tree_free (&((*tree)->child2)); + free (*tree); + *tree = NULL; + } +} + +/* + * gui_window_new: create a new window + */ + +t_gui_window * +gui_window_new (t_gui_window *parent, int x, int y, int width, int height, + int width_pct, int height_pct) +{ + t_gui_window *new_window; + t_gui_window_tree *ptr_tree, *child1, *child2, *ptr_leaf; + +#ifdef DEBUG + weechat_log_printf ("Creating new window (x:%d, y:%d, width:%d, height:%d)\n", + x, y, width, height); +#endif + + if (parent) + { + child1 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); + if (!child1) + return NULL; + child2 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); + if (!child2) + { + free (child1); + return NULL; + } + ptr_tree = parent->ptr_tree; + + if (width_pct == 100) + { + ptr_tree->split_horiz = 1; + ptr_tree->split_pct = height_pct; + } + else + { + ptr_tree->split_horiz = 0; + ptr_tree->split_pct = width_pct; + } + + /* parent window leaf becomes node and we add 2 leafs below + (#1 is parent win, #2 is new win) */ + + parent->ptr_tree = child1; + child1->parent_node = ptr_tree; + child1->child1 = NULL; + child1->child2 = NULL; + child1->window = ptr_tree->window; + + child2->parent_node = ptr_tree; + child2->child1 = NULL; + child2->child2 = NULL; + child2->window = NULL; /* will be assigned by new window below */ + + ptr_tree->child1 = child1; + ptr_tree->child2 = child2; + ptr_tree->window = NULL; /* leaf becomes node */ + + ptr_leaf = child2; + } + else + { + if (!gui_window_tree_init (NULL)) + return NULL; + ptr_leaf = gui_windows_tree; + } + + if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window))))) + { + new_window->win_x = x; + new_window->win_y = y; + new_window->win_width = width; + new_window->win_height = height; + new_window->win_width_pct = width_pct; + new_window->win_height_pct = height_pct; + + new_window->new_x = -1; + new_window->new_y = -1; + new_window->new_width = -1; + new_window->new_height = -1; + + new_window->win_chat_x = 0; + new_window->win_chat_y = 0; + new_window->win_chat_width = 0; + new_window->win_chat_height = 0; + new_window->win_chat_cursor_x = 0; + new_window->win_chat_cursor_y = 0; + + new_window->win_nick_x = 0; + new_window->win_nick_y = 0; + new_window->win_nick_width = 0; + new_window->win_nick_height = 0; + new_window->win_nick_num_max = 0; + new_window->win_nick_start = 0; + + new_window->win_input_x = 0; + + new_window->win_title = NULL; + new_window->win_chat = NULL; + new_window->win_nick = NULL; + new_window->win_status = NULL; + new_window->win_infobar = NULL; + new_window->win_input = NULL; + new_window->win_separator = NULL; + + new_window->textview_chat = NULL; + new_window->textbuffer_chat = NULL; + new_window->texttag_chat = NULL; + new_window->textview_nicklist = NULL; + new_window->textbuffer_nicklist = NULL; + + new_window->dcc_first = NULL; + new_window->dcc_selected = NULL; + new_window->dcc_last_displayed = NULL; + + new_window->buffer = NULL; + + new_window->first_line_displayed = 0; + new_window->start_line = NULL; + new_window->start_line_pos = 0; + new_window->scroll = 0; + + new_window->ptr_tree = ptr_leaf; + ptr_leaf->window = new_window; + + /* add window to windows queue */ + new_window->prev_window = last_gui_window; + if (gui_windows) + last_gui_window->next_window = new_window; + else + gui_windows = new_window; + last_gui_window = new_window; + new_window->next_window = NULL; + } + else + return NULL; + + return new_window; +} + +/* + * gui_window_free: delete a window + */ + +void +gui_window_free (t_gui_window *window) +{ + if (window->buffer && (window->buffer->num_displayed > 0)) + window->buffer->num_displayed--; + + /* remove window from windows list */ + if (window->prev_window) + window->prev_window->next_window = window->next_window; + if (window->next_window) + window->next_window->prev_window = window->prev_window; + if (gui_windows == window) + gui_windows = window->next_window; + if (last_gui_window == window) + last_gui_window = window->prev_window; + + free (window); +} + +/* + * gui_window_switch_server: switch server on servers buffer + * (if same buffer is used for all buffers) + */ + +void +gui_window_switch_server (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + t_irc_server *ptr_server; + + ptr_buffer = gui_buffer_servers_search (); + + if (ptr_buffer) + { + ptr_server = (SERVER(ptr_buffer) && SERVER(ptr_buffer)->next_server) ? + SERVER(ptr_buffer)->next_server : irc_servers; + while (ptr_server != SERVER(window->buffer)) + { + if (ptr_server->buffer) + break; + if (ptr_server->next_server) + ptr_server = ptr_server->next_server; + else + { + if (SERVER(ptr_buffer) == NULL) + { + ptr_server = NULL; + break; + } + ptr_server = irc_servers; + } + } + if (ptr_server && (ptr_server != SERVER(ptr_buffer))) + { + ptr_buffer->server = ptr_server; + gui_status_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_switch_previous: switch to previous window + */ + +void +gui_window_switch_previous (t_gui_window *window) +{ + if (!gui_ok) + return; + + /* if only one window then return */ + if (gui_windows == last_gui_window) + return; + + gui_current_window = (window->prev_window) ? window->prev_window : last_gui_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); +} + +/* + * gui_window_switch_next: switch to next window + */ + +void +gui_window_switch_next (t_gui_window *window) +{ + if (!gui_ok) + return; + + /* if only one window then return */ + if (gui_windows == last_gui_window) + return; + + gui_current_window = (window->next_window) ? window->next_window : gui_windows; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); +} + +/* + * gui_window_switch_by_buffer: switch to next window displaying a buffer + */ + +void +gui_window_switch_by_buffer (t_gui_window *window, int buffer_number) +{ + t_gui_window *ptr_win; + + if (!gui_ok) + return; + + ptr_win = (window->next_window) ? window->next_window : gui_windows; + while (ptr_win != window) + { + if (ptr_win->buffer->number == buffer_number) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + ptr_win = (ptr_win->next_window) ? ptr_win->next_window : gui_windows; + } +} + +/* + * gui_window_print_log: print window infos in log (usually for crash dump) + */ + +void +gui_window_print_log (t_gui_window *window) +{ + weechat_log_printf ("[window (addr:0x%X)]\n", window); + weechat_log_printf (" win_x . . . . . . . : %d\n", window->win_x); + weechat_log_printf (" win_y . . . . . . . : %d\n", window->win_y); + weechat_log_printf (" win_width . . . . . : %d\n", window->win_width); + weechat_log_printf (" win_height. . . . . : %d\n", window->win_height); + weechat_log_printf (" win_width_pct . . . : %d\n", window->win_width_pct); + weechat_log_printf (" win_height_pct. . . : %d\n", window->win_height_pct); + weechat_log_printf (" win_chat_x. . . . . : %d\n", window->win_chat_x); + weechat_log_printf (" win_chat_y. . . . . : %d\n", window->win_chat_y); + weechat_log_printf (" win_chat_width. . . : %d\n", window->win_chat_width); + weechat_log_printf (" win_chat_height . . : %d\n", window->win_chat_height); + weechat_log_printf (" win_chat_cursor_x . : %d\n", window->win_chat_cursor_x); + weechat_log_printf (" win_chat_cursor_y . : %d\n", window->win_chat_cursor_y); + weechat_log_printf (" win_nick_x. . . . . : %d\n", window->win_nick_x); + weechat_log_printf (" win_nick_y. . . . . : %d\n", window->win_nick_y); + weechat_log_printf (" win_nick_width. . . : %d\n", window->win_nick_width); + weechat_log_printf (" win_nick_height . . : %d\n", window->win_nick_height); + weechat_log_printf (" win_nick_start. . . : %d\n", window->win_nick_start); + weechat_log_printf (" win_title . . . . . : 0x%X\n", window->win_title); + weechat_log_printf (" win_chat. . . . . . : 0x%X\n", window->win_chat); + weechat_log_printf (" win_nick. . . . . . : 0x%X\n", window->win_nick); + weechat_log_printf (" win_status. . . . . : 0x%X\n", window->win_status); + weechat_log_printf (" win_infobar . . . . : 0x%X\n", window->win_infobar); + weechat_log_printf (" win_input . . . . . : 0x%X\n", window->win_input); + weechat_log_printf (" win_separator . . . : 0x%X\n", window->win_separator); + weechat_log_printf (" textview_chat . . . : 0x%X\n", window->textview_chat); + weechat_log_printf (" textbuffer_chat . . : 0x%X\n", window->textbuffer_chat); + weechat_log_printf (" texttag_chat. . . . : 0x%X\n", window->texttag_chat); + weechat_log_printf (" textview_nicklist . : 0x%X\n", window->textview_nicklist); + weechat_log_printf (" textbuffer_nicklist : 0x%X\n", window->textbuffer_nicklist); + weechat_log_printf (" dcc_first . . . . . : 0x%X\n", window->dcc_first); + weechat_log_printf (" dcc_selected. . . . : 0x%X\n", window->dcc_selected); + weechat_log_printf (" dcc_last_displayed. : 0x%X\n", window->dcc_last_displayed); + weechat_log_printf (" buffer. . . . . . . : 0x%X\n", window->buffer); + weechat_log_printf (" first_line_displayed: %d\n", window->first_line_displayed); + weechat_log_printf (" start_line. . . . . : 0x%X\n", window->start_line); + weechat_log_printf (" start_line_pos. . . : %d\n", window->start_line_pos); + weechat_log_printf (" prev_window . . . . : 0x%X\n", window->prev_window); + weechat_log_printf (" next_window . . . . : 0x%X\n", window->next_window); + +} diff --git a/src/gui/gui.h b/src/gui/gui.h index a78bf7b6e..bf63fbd9c 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -404,48 +404,38 @@ extern time_t gui_last_activity_time; extern t_gui_color *gui_color[GUI_NUM_COLORS]; -/* GUI independent functions: windows & buffers */ +/* GUI independent functions: windows */ extern int gui_window_tree_init (t_gui_window *); extern void gui_window_tree_node_to_leaf (t_gui_window_tree *, t_gui_window *); extern void gui_window_tree_free (t_gui_window_tree **); extern t_gui_window *gui_window_new (t_gui_window *, int, int, int, int, int, int); -extern t_gui_buffer *gui_buffer_new (t_gui_window *, void *, void *, int, int); -extern t_gui_buffer *gui_buffer_search (char *, char *); -extern t_gui_window *gui_buffer_find_window (t_gui_buffer *); -extern t_gui_buffer *gui_get_dcc_buffer (t_gui_window *); -extern void gui_buffer_clear (t_gui_buffer *); -extern void gui_buffer_clear_all (); extern void gui_window_free (t_gui_window *); -extern void gui_infobar_printf (int, int, char *, ...); -extern void gui_infobar_printf_from_buffer (t_gui_buffer *, int, int, char *, char *, ...); -extern void gui_infobar_remove (); -extern void gui_infobar_remove_all (); -extern void gui_buffer_free (t_gui_buffer *, int); -extern t_gui_line *gui_line_new (t_gui_buffer *); -extern int gui_word_strlen (t_gui_window *, char *); -extern int gui_word_real_pos (t_gui_window *, char *, int); -extern void gui_printf_internal (t_gui_buffer *, int, int, char *, char *, ...); -extern void gui_printf_raw_data (void *, int, char *); -extern void gui_input_optimize_size (t_gui_buffer *); -extern void gui_input_init_color_mask (t_gui_buffer *); -extern void gui_input_move (t_gui_buffer *, char *, char *, int ); -extern void gui_exec_action_dcc (t_gui_window *, char *); -extern void gui_exec_action_raw_data (t_gui_window *, char *); -extern int gui_insert_string_input (t_gui_window *, char *, int); -extern void gui_merge_servers (t_gui_window *); -extern void gui_split_server (t_gui_window *); extern void gui_window_switch_server (t_gui_window *); -extern void gui_buffer_switch_previous (t_gui_window *); -extern void gui_buffer_switch_next (t_gui_window *); extern void gui_window_switch_previous (t_gui_window *); extern void gui_window_switch_next (t_gui_window *); extern void gui_window_switch_by_buffer (t_gui_window *, int); +extern void gui_window_print_log (t_gui_window *); + +/* GUI independent functions: buffers */ + +extern t_gui_buffer *gui_buffer_servers_search (); +extern t_gui_buffer *gui_buffer_new (t_gui_window *, void *, void *, int, int); +extern t_gui_buffer *gui_buffer_search (char *, char *); +extern t_gui_window *gui_buffer_find_window (t_gui_buffer *); +extern t_gui_buffer *gui_buffer_get_dcc (t_gui_window *); +extern void gui_buffer_clear (t_gui_buffer *); +extern void gui_buffer_clear_all (); +extern void gui_buffer_free (t_gui_buffer *, int); +extern t_gui_line *gui_buffer_line_new (t_gui_buffer *); +extern void gui_buffer_merge_servers (t_gui_window *); +extern void gui_buffer_split_server (t_gui_window *); +extern void gui_buffer_switch_previous (t_gui_window *); +extern void gui_buffer_switch_next (t_gui_window *); extern void gui_buffer_switch_dcc (t_gui_window *); extern void gui_buffer_switch_raw_data (t_gui_window *); extern t_gui_buffer *gui_buffer_switch_by_number (t_gui_window *, int); extern void gui_buffer_move_to_number (t_gui_buffer *, int); -extern void gui_window_print_log (t_gui_window *); extern void gui_buffer_print_log (t_gui_buffer *); /* GUI independent functions: actions */ @@ -511,26 +501,48 @@ extern int gui_key_pressed (char *); extern void gui_key_free (t_gui_key *); extern void gui_key_free_all (); +/* other GUI independent functions */ + +extern void gui_infobar_printf (int, int, char *, ...); +extern void gui_infobar_printf_from_buffer (t_gui_buffer *, int, int, char *, char *, ...); +extern void gui_infobar_remove (); +extern void gui_infobar_remove_all (); +extern int gui_word_strlen (t_gui_window *, char *); +extern int gui_word_real_pos (t_gui_window *, char *, int); +extern void gui_printf_internal (t_gui_buffer *, int, int, char *, char *, ...); +extern void gui_printf_raw_data (void *, int, char *); +extern void gui_input_optimize_size (t_gui_buffer *); +extern void gui_input_init_color_mask (t_gui_buffer *); +extern void gui_input_move (t_gui_buffer *, char *, char *, int ); +extern void gui_exec_action_dcc (t_gui_window *, char *); +extern void gui_exec_action_raw_data (t_gui_window *, char *); +extern int gui_insert_string_input (t_gui_window *, char *, int); + +/* GUI dependant functions: keyboard */ + +extern void gui_keyboard_default_bindings (); + /* GUI dependant functions: display */ -extern int gui_assign_color (int *, char *); -extern char *gui_get_color_name (int); +extern void gui_chat_draw_title (t_gui_buffer *, int); +extern char *gui_chat_word_get_next_char (t_gui_window *, unsigned char *, int); +extern void gui_chat_draw (t_gui_buffer *, int); +extern void gui_chat_draw_line (t_gui_buffer *, t_gui_line *); +extern int gui_color_assign (int *, char *); +extern char *gui_color_get_name (int); extern unsigned char *gui_color_decode (unsigned char *, int); extern unsigned char *gui_color_decode_for_user_entry (unsigned char *); extern unsigned char *gui_color_encode (unsigned char *); -extern int gui_buffer_has_nicklist (t_gui_buffer *); -extern int gui_calculate_pos_size (t_gui_window *, int); -extern void gui_draw_buffer_title (t_gui_buffer *, int); -extern char *gui_word_get_next_char (t_gui_window *, unsigned char *, int); -extern void gui_draw_buffer_chat (t_gui_buffer *, int); -extern void gui_draw_buffer_chat_line (t_gui_buffer *, t_gui_line *); -extern void gui_draw_buffer_nick (t_gui_buffer *, int); -extern void gui_draw_buffer_status (t_gui_buffer *, int); -extern void gui_draw_buffer_infobar_time (t_gui_buffer *); -extern void gui_draw_buffer_infobar (t_gui_buffer *, int); -extern void gui_draw_buffer_input (t_gui_buffer *, int); -extern void gui_redraw_buffer (t_gui_buffer *); -extern void gui_switch_to_buffer (t_gui_window *, t_gui_buffer *); +extern void gui_color_init_pairs (); +extern void gui_color_rebuild_weechat(); +extern void gui_infobar_draw_time (t_gui_buffer *); +extern void gui_infobar_draw (t_gui_buffer *, int); +extern void gui_input_draw (t_gui_buffer *, int); +extern void gui_nicklist_draw (t_gui_buffer *, int); +extern void gui_status_draw (t_gui_buffer *, int); +extern int gui_window_calculate_pos_size (t_gui_window *, int); +extern void gui_window_redraw_buffer (t_gui_buffer *); +extern void gui_window_switch_to_buffer (t_gui_window *, t_gui_buffer *); extern void gui_window_page_up (t_gui_window *); extern void gui_window_page_down (t_gui_window *); extern void gui_window_scroll_up (t_gui_window *); @@ -542,7 +554,7 @@ extern void gui_window_nick_end (t_gui_window *); extern void gui_window_nick_page_up (t_gui_window *); extern void gui_window_nick_page_down (t_gui_window *); extern void gui_window_init_subwindows (t_gui_window *); -extern void gui_refresh_windows (); +extern void gui_window_refresh_windows (); extern void gui_window_split_horiz (t_gui_window *, int); extern void gui_window_split_vertic (t_gui_window *, int); extern void gui_window_resize (t_gui_window *, int); @@ -552,15 +564,12 @@ extern void gui_window_switch_up (t_gui_window *); extern void gui_window_switch_down (t_gui_window *); extern void gui_window_switch_left (t_gui_window *); extern void gui_window_switch_right (t_gui_window *); -extern void gui_refresh_screen (); -extern void gui_pre_init (int *, char **[]); -extern void gui_init_color_pairs (); -extern void gui_rebuild_weechat_colors (); -extern void gui_set_window_title (); -extern void gui_reset_window_title (); -extern void gui_init (); -extern void gui_end (); -extern void gui_input_default_key_bindings (); +extern void gui_window_refresh_screen (); +extern void gui_window_set_title (); +extern void gui_window_reset_title (); extern void gui_main_loop (); +extern void gui_main_pre_init (int *, char **[]); +extern void gui_main_init (); +extern void gui_main_end (); #endif /* gui.h */ diff --git a/src/irc/irc-channel.c b/src/irc/irc-channel.c index 900c0eedc..3aeb32538 100644 --- a/src/irc/irc-channel.c +++ b/src/irc/irc-channel.c @@ -376,7 +376,7 @@ channel_remove_away (t_irc_channel *channel) { NICK_SET_FLAG(ptr_nick, 0, NICK_AWAY); } - gui_draw_buffer_nick (channel->buffer, 0); + gui_nicklist_draw (channel->buffer, 0); } } @@ -443,7 +443,7 @@ channel_create_dcc (t_irc_dcc *ptr_dcc) ptr_channel->dcc_chat = ptr_dcc; ptr_dcc->channel = ptr_channel; - gui_redraw_buffer (ptr_channel->buffer); + gui_window_redraw_buffer (ptr_channel->buffer); return 1; } diff --git a/src/irc/irc-dcc.c b/src/irc/irc-dcc.c index 49e03d25b..11d28cf8b 100644 --- a/src/irc/irc-dcc.c +++ b/src/irc/irc-dcc.c @@ -57,11 +57,11 @@ char *dcc_status_string[] = /* strings for DCC status */ void dcc_redraw (int highlight) { - gui_redraw_buffer (gui_get_dcc_buffer (gui_current_window)); + gui_window_redraw_buffer (gui_buffer_get_dcc (gui_current_window)); if (highlight) { - hotlist_add (highlight, NULL, gui_get_dcc_buffer (gui_current_window)); - gui_draw_buffer_status (gui_current_window->buffer, 0); + hotlist_add (highlight, NULL, gui_buffer_get_dcc (gui_current_window)); + gui_status_draw (gui_current_window->buffer, 0); } } @@ -849,7 +849,7 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic dcc_accept (new_dcc); else dcc_redraw (HOTLIST_PRIVATE); - gui_draw_buffer_status (gui_current_window->buffer, 0); + gui_status_draw (gui_current_window->buffer, 0); return new_dcc; } diff --git a/src/irc/irc-nick.c b/src/irc/irc-nick.c index b4f2f63cd..f0542d164 100644 --- a/src/irc/irc-nick.c +++ b/src/irc/irc-nick.c @@ -400,7 +400,7 @@ nick_set_away (t_irc_channel *channel, t_irc_nick *nick, int is_away) ((!is_away) && (nick->flags & NICK_AWAY))) { NICK_SET_FLAG(nick, is_away, NICK_AWAY); - gui_draw_buffer_nick (channel->buffer, 0); + gui_nicklist_draw (channel->buffer, 0); } } } diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c index b1f0181c7..b3b9377b1 100644 --- a/src/irc/irc-recv.c +++ b/src/irc/irc-recv.c @@ -379,7 +379,7 @@ irc_cmd_recv_invite (t_irc_server *server, char *host, char *nick, char *argumen GUI_COLOR(COLOR_WIN_CHAT_NICK), nick); hotlist_add (HOTLIST_HIGHLIGHT, server, server->buffer); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); } } else @@ -442,8 +442,8 @@ irc_cmd_recv_join (t_irc_server *server, char *host, char *nick, char *arguments ptr_nick = nick_new (server, ptr_channel, nick, 0, 0, 0, 0, 0); if (ptr_nick) ptr_nick->host = strdup ((pos) ? pos + 1 : host); - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); return 0; } @@ -523,8 +523,8 @@ irc_cmd_recv_kick (t_irc_server *server, char *host, char *nick, char *arguments { /* my nick was kicked => free all nicks, channel is not active any more */ nick_free_all (ptr_channel); - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); if (server->autorejoin) irc_cmd_send_join (server, NULL, ptr_channel->name); } @@ -534,8 +534,8 @@ irc_cmd_recv_kick (t_irc_server *server, char *host, char *nick, char *arguments if (ptr_nick) { nick_free (ptr_channel, ptr_nick); - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); } } return 0; @@ -761,7 +761,7 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *channel, { NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_HALFOP); nick_resort (channel, ptr_nick); - gui_draw_buffer_nick (channel->buffer, 1); + gui_nicklist_draw (channel->buffer, 1); } } @@ -923,7 +923,7 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *channel, { NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_OP); nick_resort (channel, ptr_nick); - gui_draw_buffer_nick (channel->buffer, 1); + gui_nicklist_draw (channel->buffer, 1); } } @@ -1022,7 +1022,7 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *channel, { NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_VOICE); nick_resort (channel, ptr_nick); - gui_draw_buffer_nick (channel->buffer, 1); + gui_nicklist_draw (channel->buffer, 1); } } @@ -1235,8 +1235,8 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *nick, char *arguments { irc_get_channel_modes (server, ptr_channel, arguments, nick, pos, pos_parm, command_ignored); - gui_draw_buffer_status (ptr_channel->buffer, 1); - gui_draw_buffer_input (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); + gui_input_draw (ptr_channel->buffer, 1); } else { @@ -1250,8 +1250,8 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *nick, char *arguments else { irc_get_nick_modes (server, nick, pos, command_ignored); - gui_draw_buffer_status (gui_current_window->buffer, 1); - gui_draw_buffer_input (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); + gui_input_draw (gui_current_window->buffer, 1); } return 0; } @@ -1320,7 +1320,7 @@ irc_cmd_recv_nick (t_irc_server *server, char *host, char *nick, char *arguments GUI_COLOR(COLOR_WIN_CHAT_NICK), arguments); } - gui_draw_buffer_nick (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); gui_add_hotlist = 1; } } @@ -1329,17 +1329,17 @@ irc_cmd_recv_nick (t_irc_server *server, char *host, char *nick, char *arguments { free (server->nick); server->nick = strdup (arguments); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { if (ptr_win->buffer->server == server) - gui_draw_buffer_input (ptr_win->buffer, 1); + gui_input_draw (ptr_win->buffer, 1); } } else { - gui_draw_buffer_status (gui_current_window->buffer, 1); - gui_draw_buffer_input (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); + gui_input_draw (gui_current_window->buffer, 1); } return 0; @@ -1527,7 +1527,7 @@ irc_cmd_recv_notice (t_irc_server *server, char *host, char *nick, char *argumen (ascii_strcasecmp (nick, "memoserv") != 0)) { hotlist_add (HOTLIST_PRIVATE, server, server->buffer); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); } } } @@ -1641,10 +1641,10 @@ irc_cmd_recv_part (t_irc_server *server, char *host, char *nick, char *arguments if (ptr_channel) { - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); } - gui_draw_buffer_input (gui_current_window->buffer, 1); + gui_input_draw (gui_current_window->buffer, 1); } } else @@ -1701,7 +1701,7 @@ irc_cmd_recv_pong (t_irc_server *server, char *host, char *nick, char *arguments gettimeofday (&tv, &tz); server->lag = (int) get_timeval_diff (&(server->lag_check_time), &tv); if (old_lag != server->lag) - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); /* schedule next lag check */ server->lag_check_time.tv_sec = 0; @@ -2584,8 +2584,8 @@ irc_cmd_recv_quit (t_irc_server *server, char *host, char *nick, char *arguments arguments, GUI_COLOR(COLOR_WIN_CHAT_DARK)); } - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); } } @@ -2756,7 +2756,7 @@ irc_cmd_recv_topic (t_irc_server *server, char *host, char *nick, char *argument ptr_channel->topic = strdup (pos); else ptr_channel->topic = strdup (""); - gui_draw_buffer_title (ptr_channel->buffer, 1); + gui_chat_draw_title (ptr_channel->buffer, 1); } return 0; @@ -2787,8 +2787,8 @@ irc_cmd_recv_004 (t_irc_server *server, char *host, char *nick, char *arguments) /* connection to IRC server is ok! */ server->is_connected = 1; server->lag_next_check = time (NULL) + cfg_irc_lag_check; - gui_draw_buffer_status (server->buffer, 1); - gui_draw_buffer_input (server->buffer, 1); + gui_status_draw (server->buffer, 1); + gui_input_draw (server->buffer, 1); /* execute command once connected */ if (server->command && server->command[0]) @@ -3079,7 +3079,7 @@ irc_cmd_recv_305 (t_irc_server *server, char *host, char *nick, char *arguments) ptr_window = ptr_window->next_window) { if (SERVER(ptr_window->buffer) == server) - gui_draw_buffer_status (ptr_window->buffer, 1); + gui_status_draw (ptr_window->buffer, 1); } return 0; } @@ -3116,7 +3116,7 @@ irc_cmd_recv_306 (t_irc_server *server, char *host, char *nick, char *arguments) ptr_window = ptr_window->next_window) { if (SERVER(ptr_window->buffer) == server) - gui_draw_buffer_status (ptr_window->buffer, 1); + gui_status_draw (ptr_window->buffer, 1); if (SERVER(ptr_window->buffer) == server) ptr_window->buffer->last_read_line = ptr_window->buffer->last_line; @@ -3869,7 +3869,7 @@ irc_cmd_recv_324 (t_irc_server *server, char *host, char *nick, char *arguments) { irc_get_channel_modes (server, ptr_channel, NULL, NULL, pos, pos_parm, command_ignored); - gui_draw_buffer_status (ptr_channel->buffer, 0); + gui_status_draw (ptr_channel->buffer, 0); } } } @@ -4002,7 +4002,7 @@ irc_cmd_recv_332 (t_irc_server *server, char *host, char *nick, char *arguments) } if (ptr_channel) - gui_draw_buffer_title (ptr_buffer, 1); + gui_chat_draw_title (ptr_buffer, 1); } } else @@ -4140,7 +4140,7 @@ irc_cmd_recv_341 (t_irc_server *server, char *host, char *nick, char *arguments) GUI_COLOR(COLOR_WIN_CHAT), GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), pos_channel); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); } else { @@ -4758,8 +4758,8 @@ irc_cmd_recv_353 (t_irc_server *server, char *host, char *nick, char *arguments) } if (ptr_channel) { - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); } else { diff --git a/src/irc/irc-send.c b/src/irc/irc-send.c index a5d829678..9d09b9d58 100644 --- a/src/irc/irc-send.c +++ b/src/irc/irc-send.c @@ -75,7 +75,7 @@ irc_login (t_irc_server *server) "USER %s %s %s :%s\r\n", server->nick, server->username, ptr_hostname, "servername", server->realname); - gui_draw_buffer_input (gui_current_window->buffer, 1); + gui_input_draw (gui_current_window->buffer, 1); } /* @@ -343,7 +343,7 @@ irc_cmd_send_away (t_irc_server *server, t_irc_channel *channel, else irc_send_away (server, arguments); - gui_draw_buffer_status (buffer, 1); + gui_status_draw (buffer, 1); gui_add_hotlist = 1; return 0; } @@ -1368,11 +1368,11 @@ irc_cmd_send_nick_server (t_irc_server *server, char *nickname) if (server->nick) free (server->nick); server->nick = strdup (nickname); - gui_draw_buffer_input (server->buffer, 1); + gui_input_draw (server->buffer, 1); for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { - gui_draw_buffer_input (ptr_channel->buffer, 1); + gui_input_draw (ptr_channel->buffer, 1); } } } @@ -1554,8 +1554,8 @@ irc_cmd_send_part (t_irc_server *server, t_irc_channel *channel, ptr_channel = CHANNEL(buffer); gui_buffer_free (ptr_channel->buffer, 1); channel_free (server, ptr_channel); - gui_draw_buffer_status (buffer, 1); - gui_draw_buffer_input (buffer, 1); + gui_status_draw (buffer, 1); + gui_input_draw (buffer, 1); return 0; } channel_name = CHANNEL(buffer)->name; @@ -1652,7 +1652,7 @@ irc_cmd_send_query (t_irc_server *server, t_irc_channel *channel, } gui_buffer_new (window, server, ptr_channel, BUFFER_TYPE_STANDARD, 1); - gui_draw_buffer_title (ptr_channel->buffer, 1); + gui_chat_draw_title (ptr_channel->buffer, 1); } else { @@ -1660,8 +1660,8 @@ irc_cmd_send_query (t_irc_server *server, t_irc_channel *channel, { if (ptr_buffer->channel == ptr_channel) { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (ptr_buffer); + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (ptr_buffer); break; } } diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index dee0dcd37..a957ef925 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -1655,7 +1655,7 @@ server_auto_connect (int auto_connect, int command_line) { (void) gui_buffer_new (gui_current_window, ptr_server, NULL, BUFFER_TYPE_STANDARD, 1); - gui_redraw_buffer (gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); if (!server_connect (ptr_server)) server_reconnect_schedule (ptr_server); } @@ -1708,7 +1708,7 @@ server_disconnect (t_irc_server *server, int reconnect) else server->reconnect_start = 0; - gui_redraw_buffer (gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); } /* diff --git a/src/plugins/plugins-interface.c b/src/plugins/plugins-interface.c index 24a45e09b..72c2b6a5c 100644 --- a/src/plugins/plugins-interface.c +++ b/src/plugins/plugins-interface.c @@ -234,7 +234,7 @@ weechat_plugin_infobar_remove (t_weechat_plugin *plugin, int how_many) how_many--; } } - gui_draw_buffer_infobar (gui_current_window->buffer, 1); + gui_infobar_draw (gui_current_window->buffer, 1); } /* @@ -621,7 +621,7 @@ weechat_plugin_get_config_str_value (t_config_option *option, void *value) return option->array_values[*((int *)value)]; break; case OPTION_TYPE_COLOR: - color_name = gui_get_color_name (*((int *)value)); + color_name = gui_color_get_name (*((int *)value)); return (color_name) ? strdup (color_name) : strdup (""); break; case OPTION_TYPE_STRING: @@ -1073,7 +1073,7 @@ weechat_plugin_input_color (t_weechat_plugin *plugin, int color, int start, int return; if (color < 0) - gui_draw_buffer_input (gui_current_window->buffer, 0); + gui_input_draw (gui_current_window->buffer, 0); else { if ((start < 0) || (length <= 0)) diff --git a/weechat/po/POTFILES.in b/weechat/po/POTFILES.in index aab77a7ca..3639a29cc 100644 --- a/weechat/po/POTFILES.in +++ b/weechat/po/POTFILES.in @@ -14,13 +14,31 @@ ./src/plugins/plugins-config.h ./src/plugins/plugins-interface.c ./src/plugins/weechat-plugin.h +./src/gui/curses/gui-chat.c +./src/gui/curses/gui-color.c +./src/gui/curses/gui-infobar.c ./src/gui/curses/gui-input.c -./src/gui/curses/gui-display.c -./src/gui/gtk/gui-display.c +./src/gui/curses/gui-keyboard.c +./src/gui/curses/gui-main.c +./src/gui/curses/gui-nicklist.c +./src/gui/curses/gui-status.c +./src/gui/curses/gui-window.c +./src/gui/curses/gui-curses.h +./src/gui/gtk/gui-chat.c +./src/gui/gtk/gui-color.c +./src/gui/gtk/gui-infobar.c ./src/gui/gtk/gui-input.c +./src/gui/gtk/gui-keyboard.c +./src/gui/gtk/gui-main.c +./src/gui/gtk/gui-nicklist.c +./src/gui/gtk/gui-status.c +./src/gui/gtk/gui-window.c +./src/gui/gtk/gui-gtk.h ./src/gui/gui-action.c +./src/gui/gui-buffer.c ./src/gui/gui-common.c ./src/gui/gui-keyboard.c +./src/gui/gui-window.c ./src/gui/gui.h ./src/common/command.c ./src/common/command.h diff --git a/weechat/po/cs.po b/weechat/po/cs.po index 767c41c0c..7352e3c90 100644 --- a/weechat/po/cs.po +++ b/weechat/po/cs.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:53+0200\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -1351,38 +1351,38 @@ msgstr "nemůžu změnit mód přo ostatní uživatele" msgid "whois (secure connection)" msgstr "whois (zabezpečená část)" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%sServer: %s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "připojen" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "nepřipojen" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "na" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "off" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (dočasný server, nebude uložen)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "sekund" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(skrytý)" @@ -2365,102 +2365,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "%s server/kanál (%s/%s) nenaleyen pro exec příkaz pluginu\n" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "bajtů" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "Kb" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "Mb" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "Gb" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "ETA" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] Akceptovat" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] Storno" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] Odebrat" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] Pročistit staré DCC" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] Zavřít DCC pohled" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr " [Q] Zavřít čistý pohled na data" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "Změnil se den na %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s zpoždění je veliké, odpojuji se od serveru...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "bajtů" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "Kb" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "Mb" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "Gb" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "ETA" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(pryč)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[nepřipojen] " -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr "<ČISTÉ_IRC> " -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Aktivní: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "ČISTÉ_IRC" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Zpoždění: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-VÍCE-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] Akceptovat" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] Storno" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] Odebrat" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] Pročistit staré DCC" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] Zavřít DCC pohled" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr " [Q] Zavřít čistý pohled na data" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "server" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "Nedostatek paměti pro nový řádek\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "Nedostatek paměti pro infobar zprávu\n" diff --git a/weechat/po/de.po b/weechat/po/de.po index b230b8066..6c31a19aa 100644 --- a/weechat/po/de.po +++ b/weechat/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:53+0200\n" "Last-Translator: Thomas Schütz \n" "Language-Team: weechat-dev \n" @@ -1348,38 +1348,38 @@ msgstr "Modes anderer User können nicht geändert werden" msgid "whois (secure connection)" msgstr "whois (sichere Verbindung)" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%sServer: %s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "verbunden" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "nicht verbunden" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "an" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "aus" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (temporärer Server, wird nicht gespeichert)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "Sekunden" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(versteckt)" @@ -2356,102 +2356,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "%s Server/Channel (%s/%s) für den Plugin-Exec-Befehl nicht gefunden\n" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "Bytes" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "KB" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "MB" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "GB" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "ETA" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] annehmen" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] abbrechen" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] entfernen" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] alte DCCs entfernen" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] DCC-Ansicht schließen" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr " [Q] Rohdatenansicht schließen" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "Ein neuer Tag bricht hat, heute ist der %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s der Lag ist hoch, die Verbindung wird getrennt...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "Bytes" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "KB" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "MB" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "GB" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "ETA" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(abwesend)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[nicht verbunden]" -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr " " -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Aktiv: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "RAW_IRC" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Lag: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-MEHR-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] annehmen" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] abbrechen" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] entfernen" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] alte DCCs entfernen" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] DCC-Ansicht schließen" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr " [Q] Rohdatenansicht schließen" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "Server" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "Nicht genügend Speicher für neue Zeile\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "Nicht genügend Speicher für Infobar-Nachricht\n" diff --git a/weechat/po/es.po b/weechat/po/es.po index 1aa744368..3e7719175 100644 --- a/weechat/po/es.po +++ b/weechat/po/es.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:53+0200\n" "Last-Translator: Roberto Gonzlez Cardenete \n" "Language-Team: weechat-dev \n" @@ -1366,38 +1366,38 @@ msgstr "no es posible cambiar el modo para el resto de usuarios" msgid "whois (secure connection)" msgstr "quin es (conexin segura)" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%sServidor:%s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "conectado" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "no conectado" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "activo" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "inactivo" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (servidor temporal, no ser guardado)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "segundos" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(oculto)" @@ -2400,102 +2400,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "bytes" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "KB" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "MB" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "GB" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "Tiempo estimado de llegada" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] Aceptar" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] Cancelar" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] Eliminar" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] Purgar los viejos DCC" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] Cerrar la vista DCC" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr "" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "Da cambiado a %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s el lag (retraso) es alto, desconectando del servidor...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "bytes" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "KB" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "MB" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "GB" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "Tiempo estimado de llegada" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(ausente)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[no conectado] " -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr "" -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Act: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Lag: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-MS-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] Aceptar" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] Cancelar" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] Eliminar" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] Purgar los viejos DCC" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] Cerrar la vista DCC" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr "" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "servidor" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "No hay suficiente memoria para una nueva lnea\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "No hay suficiente memoria para el mensaje de la barra de informacin\n" diff --git a/weechat/po/fr.po b/weechat/po/fr.po index 2fb0ace0d..b8f6d6750 100644 --- a/weechat/po/fr.po +++ b/weechat/po/fr.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:53+0200\n" "Last-Translator: FlashCode \n" "Language-Team: weechat-dev \n" @@ -1357,38 +1357,38 @@ msgstr "impossible de changer le mode pour les autres utilisateurs" msgid "whois (secure connection)" msgstr "qui est (connexion scurise)" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%sServeur: %s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "connect" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "non connect" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "activ" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "dsactiv" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (serveur temporaire, ne sera pas sauv)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "secondes" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(cach)" @@ -2375,102 +2375,102 @@ msgstr "" "%s serveur/canal (%s/%s) non trouv pour l'excution de commande de " "l'extension\n" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "octets" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "Ko" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "Mo" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "Go" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "ETA" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] Accepter" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] Annuler" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] Retirer" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] Purger anciens DCC" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] Fermer la vue DCC" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr " [Q] Fermer la vue IRC brut" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "Jour chang: %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s le lag est lev, dconnexion du serveur...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "octets" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "Ko" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "Mo" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "Go" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "ETA" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(absent)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[non connect] " -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr " " -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Act: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "IRC_BRUT" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Lag: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-PLUS-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] Accepter" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] Annuler" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] Retirer" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] Purger anciens DCC" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] Fermer la vue DCC" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr " [Q] Fermer la vue IRC brut" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "serveur" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "Pas assez de mmoire pour une nouvelle ligne !\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "Pas assez de mmoire pour un message de la barre d'infos\n" diff --git a/weechat/po/hu.po b/weechat/po/hu.po index 23814d4fa..7ee8d8358 100644 --- a/weechat/po/hu.po +++ b/weechat/po/hu.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.1.9-cvs\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: 2006-04-16 13:55+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -1367,38 +1367,38 @@ msgstr "más felhasználók üzemmódját nem módosíthatja" msgid "whois (secure connection)" msgstr "" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "%s Szerver: %s%s %s[%s%s%s]\n" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "csatlakozva" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "nincs csatlakozva" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "be" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "ki" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr " (átmeneti szerver, nem lesz mentve)" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "másodperc" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "(rejtett)" @@ -2354,102 +2354,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "%s (%s/%s) szerver/szoba nem található a modul futtatása parancshoz\n" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "byte" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "Kb" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "Mb" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "Gb" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr " [A] Elfogadás" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr " [C] Mégsem" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr " [R] Eltávolítás" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr " [P] Régi DCC törlése" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr " [Q] DCC nézet bezárása" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr " [Q] Nyers adat nézet bezárása" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "A mai dátum: %s\n" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "%s túl nagy a késés(lag), lecsatlakozás a szerverről...\n" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "byte" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "Kb" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "Mb" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "Gb" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "(távol)" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "[nincs csatlakozva]" -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr " " -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "Akt: " -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "Lag: %.1f" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "-TOVÁBB-" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr " [A] Elfogadás" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr " [C] Mégsem" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr " [R] Eltávolítás" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr " [P] Régi DCC törlése" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr " [Q] DCC nézet bezárása" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr " [Q] Nyers adat nézet bezárása" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "szerver" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "Nincs elég memória az új sorhoz\n" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "Nincs elég memória az információs pult üzenethez\n" diff --git a/weechat/po/weechat.pot b/weechat/po/weechat.pot index dd8589468..5750c0846 100644 --- a/weechat/po/weechat.pot +++ b/weechat/po/weechat.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2006-04-16 13:52+0200\n" +"POT-Creation-Date: 2006-04-22 23:03+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1247,38 +1247,38 @@ msgstr "" msgid "whois (secure connection)" msgstr "" -#: src/irc/irc-display.c:367 +#: src/irc/irc-display.c:375 #, c-format msgid "%sServer: %s%s %s[%s%s%s]\n" msgstr "" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "connected" msgstr "" -#: src/irc/irc-display.c:374 +#: src/irc/irc-display.c:382 msgid "not connected" msgstr "" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "on" msgstr "" -#: src/irc/irc-display.c:378 src/irc/irc-display.c:382 -#: src/irc/irc-display.c:391 src/irc/irc-display.c:393 +#: src/irc/irc-display.c:386 src/irc/irc-display.c:390 +#: src/irc/irc-display.c:399 src/irc/irc-display.c:401 msgid "off" msgstr "" -#: src/irc/irc-display.c:380 +#: src/irc/irc-display.c:388 msgid " (temporary server, will not be saved)" msgstr "" -#: src/irc/irc-display.c:385 src/irc/irc-display.c:416 src/irc/irc-recv.c:3543 +#: src/irc/irc-display.c:393 src/irc/irc-display.c:424 src/irc/irc-recv.c:3543 msgid "seconds" msgstr "" -#: src/irc/irc-display.c:396 +#: src/irc/irc-display.c:404 msgid "(hidden)" msgstr "" @@ -2209,102 +2209,102 @@ msgstr "" msgid "%s server/channel (%s/%s) not found for plugin exec command\n" msgstr "" -#: src/gui/curses/gui-input.c:386 +#: src/gui/curses/gui-chat.c:865 +msgid "bytes" +msgstr "" + +#: src/gui/curses/gui-chat.c:865 +msgid "Kb" +msgstr "" + +#: src/gui/curses/gui-chat.c:865 +msgid "Mb" +msgstr "" + +#: src/gui/curses/gui-chat.c:865 +msgid "Gb" +msgstr "" + +#: src/gui/curses/gui-chat.c:983 +msgid "ETA" +msgstr "" + +#: src/gui/curses/gui-input.c:398 +msgid " [A] Accept" +msgstr "" + +#: src/gui/curses/gui-input.c:399 src/gui/curses/gui-input.c:403 +msgid " [C] Cancel" +msgstr "" + +#: src/gui/curses/gui-input.c:408 +msgid " [R] Remove" +msgstr "" + +#: src/gui/curses/gui-input.c:412 +msgid " [P] Purge old DCC" +msgstr "" + +#: src/gui/curses/gui-input.c:413 +msgid " [Q] Close DCC view" +msgstr "" + +#: src/gui/curses/gui-input.c:421 +msgid " [Q] Close raw data view" +msgstr "" + +#: src/gui/curses/gui-main.c:100 #, c-format msgid "Day changed to %s\n" msgstr "" -#: src/gui/curses/gui-input.c:491 +#: src/gui/curses/gui-main.c:205 #, c-format msgid "%s lag is high, disconnecting from server...\n" msgstr "" -#: src/gui/curses/gui-display.c:1549 -msgid "bytes" -msgstr "" - -#: src/gui/curses/gui-display.c:1549 -msgid "Kb" -msgstr "" - -#: src/gui/curses/gui-display.c:1549 -msgid "Mb" -msgstr "" - -#: src/gui/curses/gui-display.c:1549 -msgid "Gb" -msgstr "" - -#: src/gui/curses/gui-display.c:1667 -msgid "ETA" -msgstr "" - -#: src/gui/curses/gui-display.c:2026 +#: src/gui/curses/gui-status.c:87 msgid "" msgstr "" -#: src/gui/curses/gui-display.c:2038 +#: src/gui/curses/gui-status.c:99 msgid "(away)" msgstr "" -#: src/gui/curses/gui-display.c:2177 +#: src/gui/curses/gui-status.c:238 msgid "[not connected] " msgstr "" -#: src/gui/curses/gui-display.c:2183 +#: src/gui/curses/gui-status.c:244 msgid " " msgstr "" -#: src/gui/curses/gui-display.c:2195 +#: src/gui/curses/gui-status.c:256 msgid "Act: " msgstr "" -#: src/gui/curses/gui-display.c:2276 +#: src/gui/curses/gui-status.c:337 msgid "RAW_IRC" msgstr "" -#: src/gui/curses/gui-display.c:2297 +#: src/gui/curses/gui-status.c:358 #, c-format msgid "Lag: %.1f" msgstr "" -#: src/gui/curses/gui-display.c:2313 +#: src/gui/curses/gui-status.c:374 msgid "-MORE-" msgstr "" -#: src/gui/curses/gui-display.c:2762 -msgid " [A] Accept" -msgstr "" - -#: src/gui/curses/gui-display.c:2763 src/gui/curses/gui-display.c:2767 -msgid " [C] Cancel" -msgstr "" - -#: src/gui/curses/gui-display.c:2772 -msgid " [R] Remove" -msgstr "" - -#: src/gui/curses/gui-display.c:2776 -msgid " [P] Purge old DCC" -msgstr "" - -#: src/gui/curses/gui-display.c:2777 -msgid " [Q] Close DCC view" -msgstr "" - -#: src/gui/curses/gui-display.c:2785 -msgid " [Q] Close raw data view" -msgstr "" - -#: src/gui/gtk/gui-display.c:2279 +#: src/gui/gtk/gui-main.c:160 msgid "server" msgstr "" -#: src/gui/gui-common.c:782 +#: src/gui/gui-buffer.c:538 msgid "Not enough memory for new line\n" msgstr "" -#: src/gui/gui-common.c:1170 +#: src/gui/gui-common.c:439 msgid "Not enough memory for infobar message\n" msgstr "" diff --git a/weechat/src/common/command.c b/weechat/src/common/command.c index 5d3d47d54..86d729fbe 100644 --- a/weechat/src/common/command.c +++ b/weechat/src/common/command.c @@ -1381,8 +1381,8 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, ptr_channel = CHANNEL(buffer); gui_buffer_free (ptr_channel->buffer, 1); channel_free (SERVER(buffer), ptr_channel); - gui_draw_buffer_status (buffer, 1); - gui_draw_buffer_input (buffer, 1); + gui_status_draw (buffer, 1); + gui_input_draw (buffer, 1); } else { @@ -1414,7 +1414,7 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, gui_buffer_free (buffer, 1); } } - gui_draw_buffer_status (buffer, 1); + gui_status_draw (buffer, 1); } else if (ascii_strcasecmp (argv[0], "notify") == 0) { @@ -1563,8 +1563,8 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, } if (ptr_buffer) { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (ptr_buffer); + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (ptr_buffer); } } } @@ -2093,7 +2093,7 @@ weechat_cmd_disconnect (t_irc_server *server, t_irc_channel *channel, _("Auto-reconnection is cancelled\n")); } server_disconnect (ptr_server, 0); - gui_draw_buffer_status (buffer, 1); + gui_status_draw (buffer, 1); } else { @@ -2879,7 +2879,7 @@ weechat_cmd_server (t_irc_server *server, t_irc_channel *channel, if (server_name) free (server_name); - gui_redraw_buffer (buffer); + gui_window_redraw_buffer (buffer); return 0; } @@ -3088,7 +3088,7 @@ weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *val option->array_values[*((int *)value)]); break; case OPTION_TYPE_COLOR: - color_name = gui_get_color_name (*((int *)value)); + color_name = gui_color_get_name (*((int *)value)); gui_printf (NULL, "%s%s\n", GUI_COLOR(COLOR_WIN_CHAT_HOST), (color_name) ? color_name : _("(unknown)")); @@ -3798,7 +3798,7 @@ weechat_cmd_upgrade (t_irc_server *server, t_irc_channel *channel, plugin_end (); #endif (void) config_write (NULL); - gui_end (); + gui_main_end (); fifo_remove (); if (weechat_log_file) fclose (weechat_log_file); diff --git a/weechat/src/common/completion.c b/weechat/src/common/completion.c index c0fe8401d..3d25b1e46 100644 --- a/weechat/src/common/completion.c +++ b/weechat/src/common/completion.c @@ -644,7 +644,7 @@ completion_list_add_option_value (t_completion *completion) weelist_add (&completion->completion_list, &completion->last_completion, (option_value) ? - gui_get_color_name (*((int *)(option_value))) : + gui_color_get_name (*((int *)(option_value))) : option->default_string); break; case OPTION_TYPE_STRING: diff --git a/weechat/src/common/session.c b/weechat/src/common/session.c index 86ace569f..f73e3c110 100644 --- a/weechat/src/common/session.c +++ b/weechat/src/common/session.c @@ -472,7 +472,7 @@ session_crash (FILE *file, char *message, ...) va_end (argptr); fclose (file); - gui_end (); + gui_main_end (); fprintf (stderr, "%s %s\n", WEECHAT_ERROR, buffer); fprintf (stderr, @@ -1464,7 +1464,7 @@ session_load_line (FILE *file) } /* allocate line */ - line = gui_line_new (session_current_buffer); + line = gui_buffer_line_new (session_current_buffer); if (!line) { session_crash (file, _("can't create new line")); @@ -1685,8 +1685,8 @@ session_load (char *filename) ptr_server->buffer = gui_buffers; } - gui_switch_to_buffer (gui_windows, gui_buffers); - gui_redraw_buffer (gui_current_window->buffer); + gui_window_switch_to_buffer (gui_windows, gui_buffers); + gui_window_redraw_buffer (gui_current_window->buffer); fclose (file); diff --git a/weechat/src/common/weechat.c b/weechat/src/common/weechat.c index 6c9392c9e..5963d89bf 100644 --- a/weechat/src/common/weechat.c +++ b/weechat/src/common/weechat.c @@ -1062,7 +1062,7 @@ weechat_sigsegv () weechat_dump (1); dcc_end (); server_free_all (); - gui_end (); + gui_main_end (); fprintf (stderr, "\n"); fprintf (stderr, "*** Very bad! WeeChat has crashed (SIGSEGV received)\n"); fprintf (stderr, "*** Full crash dump was saved to %s/weechat.log file\n", weechat_home); @@ -1093,7 +1093,7 @@ main (int argc, char *argv[]) signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal */ signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal */ signal (SIGSEGV, weechat_sigsegv); /* crash dump when SIGSEGV received */ - gui_pre_init (&argc, &argv); /* pre-initiliaze interface */ + gui_main_pre_init (&argc, &argv); /* pre-initiliaze interface */ weechat_init_vars (); /* initialize some variables */ gui_key_init (); /* init keyb. (default key bindings)*/ weechat_parse_args (argc, argv); /* parse command line args */ @@ -1103,7 +1103,7 @@ main (int argc, char *argv[]) weechat_config_read (); /* read configuration */ weechat_create_config_dirs (); /* create config directories */ utf8_init (); /* init UTF-8 in WeeChat */ - gui_init (); /* init WeeChat interface */ + gui_main_init (); /* init WeeChat interface */ fifo_create (); /* FIFO pipe for remote control */ if (weechat_session) session_load (weechat_session); /* load previous session if asked */ @@ -1125,7 +1125,7 @@ main (int argc, char *argv[]) command_index_free (); /* free commands index */ dcc_end (); /* remove all DCC */ server_free_all (); /* free all servers */ - gui_end (); /* shut down WeeChat GUI */ + gui_main_end (); /* shut down WeeChat GUI */ weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */ return EXIT_SUCCESS; /* make gcc happy (never executed) */ diff --git a/weechat/src/common/weeconfig.c b/weechat/src/common/weeconfig.c index d3a119b4b..71b82287a 100644 --- a/weechat/src/common/weeconfig.c +++ b/weechat/src/common/weeconfig.c @@ -1110,9 +1110,9 @@ void config_change_title () { if (cfg_look_set_title) - gui_set_window_title (); + gui_window_set_title (); else - gui_reset_window_title (); + gui_window_reset_title (); } /* @@ -1122,8 +1122,8 @@ config_change_title () void config_change_buffers () { - gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); - gui_redraw_buffer (gui_current_window->buffer); + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); } /* @@ -1133,7 +1133,7 @@ config_change_buffers () void config_change_buffer_content () { - gui_redraw_buffer (gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); } /* @@ -1146,7 +1146,7 @@ config_change_read_marker () t_gui_window *ptr_win; for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - gui_redraw_buffer (ptr_win->buffer); + gui_window_redraw_buffer (ptr_win->buffer); } /* @@ -1157,7 +1157,7 @@ void config_change_charset () { utf8_init (); - gui_redraw_buffer (gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); } /* @@ -1169,9 +1169,9 @@ void config_change_one_server_buffer () { if (cfg_look_one_server_buffer) - gui_merge_servers (gui_current_window); + gui_buffer_merge_servers (gui_current_window); else - gui_split_server (gui_current_window); + gui_buffer_split_server (gui_current_window); } /* @@ -1181,9 +1181,9 @@ config_change_one_server_buffer () void config_change_color () { - gui_init_color_pairs (); - gui_rebuild_weechat_colors (); - gui_refresh_windows (); + gui_color_init_pairs (); + gui_color_rebuild_weechat (); + gui_window_refresh_windows (); } /* @@ -1338,7 +1338,7 @@ config_option_set_value (t_config_option *option, char *value) *(option->ptr_int) = int_value; break; case OPTION_TYPE_COLOR: - if (!gui_assign_color (option->ptr_int, value)) + if (!gui_color_assign (option->ptr_int, value)) return -1; break; case OPTION_TYPE_STRING: @@ -1574,7 +1574,7 @@ config_set_server_value (t_irc_server *server, char *option_name, *((int *)(ptr_data)) = int_value; break; case OPTION_TYPE_COLOR: - if (!gui_assign_color ((int *)ptr_data, value)) + if (!gui_color_assign ((int *)ptr_data, value)) return -2; break; case OPTION_TYPE_STRING: @@ -1792,7 +1792,7 @@ config_default_values () int_value; break; case OPTION_TYPE_COLOR: - if (!gui_assign_color ( + if (!gui_color_assign ( weechat_options[i][j].ptr_int, weechat_options[i][j].default_string)) gui_printf (NULL, @@ -2377,7 +2377,7 @@ config_write (char *config_name) fprintf (file, "%s = %s\n", weechat_options[i][j].option_name, (weechat_options[i][j].ptr_int) ? - gui_get_color_name (*weechat_options[i][j].ptr_int) : + gui_color_get_name (*weechat_options[i][j].ptr_int) : weechat_options[i][j].default_string); break; case OPTION_TYPE_STRING: diff --git a/weechat/src/gui/Makefile.am b/weechat/src/gui/Makefile.am index 268f88621..b202250e2 100644 --- a/weechat/src/gui/Makefile.am +++ b/weechat/src/gui/Makefile.am @@ -19,9 +19,11 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" noinst_LIBRARIES = lib_weechat_gui_common.a -lib_weechat_gui_common_a_SOURCES = gui-common.c \ +lib_weechat_gui_common_a_SOURCES = gui-buffer.c \ + gui-common.c \ gui-action.c \ gui-keyboard.c \ + gui-window.c \ gui.h if GUI_NCURSES diff --git a/weechat/src/gui/curses/Makefile.am b/weechat/src/gui/curses/Makefile.am index 0de2b9926..0041d8080 100644 --- a/weechat/src/gui/curses/Makefile.am +++ b/weechat/src/gui/curses/Makefile.am @@ -20,7 +20,8 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" bin_PROGRAMS = weechat-curses if PLUGINS -weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \ +weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \ + ../gui-window.o ../gui-keyboard.o \ ../gui-action.o \ ../../common/lib_weechat_main.a \ ../../irc/lib_weechat_irc.a \ @@ -29,7 +30,8 @@ weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \ $(NCURSES_LIBS) \ $(GNUTLS_LFLAGS) else -weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \ +weechat_curses_LDADD = ../gui-common.o ../gui-buffer.o \ + ../gui-window.o ../gui-keyboard.o \ ../gui-action.o \ ../../common/lib_weechat_main.a \ ../../irc/lib_weechat_irc.a \ @@ -38,5 +40,13 @@ weechat_curses_LDADD = ../gui-common.o ../gui-keyboard.o \ $(GNUTLS_LFLAGS) endif -weechat_curses_SOURCES = gui-display.c \ - gui-input.c +weechat_curses_SOURCES = gui-chat.c \ + gui-color.c \ + gui-infobar.c \ + gui-input.c \ + gui-keyboard.c \ + gui-main.c \ + gui-nicklist.c \ + gui-status.c \ + gui-window.c \ + gui-curses.h diff --git a/weechat/src/gui/curses/gui-chat.c b/weechat/src/gui/curses/gui-chat.c new file mode 100644 index 000000000..e7bef1cd2 --- /dev/null +++ b/weechat/src/gui/curses/gui-chat.c @@ -0,0 +1,1098 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-chat.c: chat display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/utf8.h" +#include "../../common/weeconfig.h" +#include "../../irc/irc.h" +#include "gui-curses.h" + + +/* + * gui_chat_set_style: set style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_set_style (t_gui_window *window, int style) +{ + wattron (window->win_chat, style); +} + +/* + * gui_chat_remove_style: remove style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_remove_style (t_gui_window *window, int style) +{ + wattroff (window->win_chat, style); +} + +/* + * gui_chat_toggle_style: toggle a style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_toggle_style (t_gui_window *window, int style) +{ + window->current_style_attr ^= style; + if (window->current_style_attr & style) + gui_chat_set_style (window, style); + else + gui_chat_remove_style (window, style); +} + +/* + * gui_chat_reset_style: reset style (color and attr) + * for a chat window + */ + +void +gui_chat_reset_style (t_gui_window *window) +{ + window->current_style_fg = -1; + window->current_style_bg = -1; + window->current_style_attr = 0; + window->current_color_attr = 0; + + gui_window_set_weechat_color (window->win_chat, COLOR_WIN_CHAT); + gui_chat_remove_style (window, + A_BOLD | A_UNDERLINE | A_REVERSE); +} + +/* + * gui_chat_set_color_style: set style for color + */ + +void +gui_chat_set_color_style (t_gui_window *window, int style) +{ + window->current_color_attr |= style; + wattron (window->win_chat, style); +} + +/* + * gui_chat_remove_color_style: remove style for color + */ + +void +gui_chat_remove_color_style (t_gui_window *window, int style) +{ + window->current_color_attr &= !style; + wattroff (window->win_chat, style); +} + +/* + * gui_chat_reset_color_style: reset style for color + */ + +void +gui_chat_reset_color_style (t_gui_window *window) +{ + wattroff (window->win_chat, window->current_color_attr); + window->current_color_attr = 0; +} + +/* + * gui_chat_set_color: set color for a chat window + */ + +void +gui_chat_set_color (t_gui_window *window, int fg, int bg) +{ + if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + wattron (window->win_chat, COLOR_PAIR(63)); + else + { + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + wattron (window->win_chat, COLOR_PAIR((bg * 8) + fg)); + } +} + +/* + * gui_chat_set_weechat_color: set a WeeChat color for a chat window + */ + +void +gui_chat_set_weechat_color (t_gui_window *window, int weechat_color) +{ + gui_chat_reset_style (window); + gui_chat_set_style (window, + gui_color[weechat_color]->attributes); + gui_chat_set_color (window, + gui_color[weechat_color]->foreground, + gui_color[weechat_color]->background); +} + +/* + * gui_chat_draw_title: draw title window for a buffer + */ + +void +gui_chat_draw_title (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + char format[32], *buf, *buf2; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + if (erase) + gui_window_curses_clear (ptr_win->win_title, COLOR_WIN_TITLE); + + gui_window_set_weechat_color (ptr_win->win_title, COLOR_WIN_TITLE); + snprintf (format, 32, "%%-%ds", ptr_win->win_width); + if (CHANNEL(buffer)) + { + if (CHANNEL(buffer)->topic) + { + buf = (char *)gui_color_decode ((unsigned char *)(CHANNEL(buffer)->topic), 0); + buf2 = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + (buf) ? buf : CHANNEL(buffer)->topic); + mvwprintw (ptr_win->win_title, 0, 0, format, (buf2) ? buf2 : CHANNEL(buffer)->topic); + if (buf) + free (buf); + if (buf2) + free (buf2); + } + else + mvwprintw (ptr_win->win_title, 0, 0, format, " "); + } + else + { + if (buffer->type == BUFFER_TYPE_STANDARD) + { + mvwprintw (ptr_win->win_title, 0, 0, + format, + PACKAGE_STRING " " WEECHAT_COPYRIGHT_DATE " - " + WEECHAT_WEBSITE); + } + else + mvwprintw (ptr_win->win_title, 0, 0, format, " "); + } + wnoutrefresh (ptr_win->win_title); + refresh (); + } + } +} + +/* + * gui_chat_display_new_line: display a new line + */ + +void +gui_chat_display_new_line (t_gui_window *window, int num_lines, int count, + int *lines_displayed, int simulate) +{ + if ((count == 0) || (*lines_displayed >= num_lines - count)) + { + if ((!simulate) && (window->win_chat_cursor_x <= window->win_chat_width - 1)) + { + wmove (window->win_chat, + window->win_chat_cursor_y, + window->win_chat_cursor_x); + wclrtoeol (window->win_chat); + } + window->win_chat_cursor_y++; + } + window->win_chat_cursor_x = 0; + (*lines_displayed)++; +} + +/* + * gui_chat_word_get_next_char: returns next char of a word + * special chars like colors, bold, .. are skipped + */ + +char * +gui_chat_word_get_next_char (t_gui_window *window, unsigned char *string, int apply_style) +{ + char str_fg[3], str_bg[3]; + int fg, bg, weechat_color; + + while (string[0]) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_BOLD); + break; + case GUI_ATTR_COLOR_CHAR: + string++; + str_fg[0] = '\0'; + str_bg[0] = '\0'; + fg = 99; + bg = 99; + if (isdigit (string[0])) + { + str_fg[0] = string[0]; + str_fg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_fg[1] = string[0]; + str_fg[2] = '\0'; + string++; + } + } + if (string[0] == ',') + { + string++; + if (isdigit (string[0])) + { + str_bg[0] = string[0]; + str_bg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_bg[1] = string[0]; + str_bg[2] = '\0'; + string++; + } + } + } + if (apply_style) + { + if (str_fg[0] || str_bg[0]) + { + if (str_fg[0]) + sscanf (str_fg, "%d", &fg); + else + fg = window->current_style_fg; + if (str_bg[0]) + sscanf (str_bg, "%d", &bg); + else + bg = window->current_style_bg; + } + if (!str_fg[0] && !str_bg[0]) + gui_chat_reset_color_style (window); + window->current_style_fg = fg; + window->current_style_bg = bg; + gui_chat_set_color (window, fg, bg); + } + break; + case GUI_ATTR_RESET_CHAR: + string++; + if (apply_style) + gui_chat_reset_style (window); + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_REVERSE); + break; + case GUI_ATTR_WEECHAT_COLOR_CHAR: + string++; + if (isdigit (string[0]) && isdigit (string[1])) + { + str_fg[0] = string[0]; + str_fg[1] = string[1]; + str_fg[2] = '\0'; + string += 2; + if (apply_style) + { + sscanf (str_fg, "%d", &weechat_color); + gui_chat_set_weechat_color (window, weechat_color); + } + } + break; + case GUI_ATTR_WEECHAT_SET_CHAR: + string++; + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_BOLD); + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_REVERSE); + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_UNDERLINE); + break; + } + break; + case GUI_ATTR_WEECHAT_REMOVE_CHAR: + string++; + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_BOLD); + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_REVERSE); + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_UNDERLINE); + break; + } + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_UNDERLINE); + break; + default: + if (string[0] < 32) + string++; + else + return utf8_next_char ((char *)string); + } + + } + + /* nothing found except color/attrib codes, so return NULL */ + return NULL; +} + +/* + * gui_chat_display_word_raw: display word on chat buffer, letter by letter + * special chars like color, bold, .. are interpreted + */ + +void +gui_chat_display_word_raw (t_gui_window *window, char *string) +{ + char *prev_char, *next_char, saved_char; + + wmove (window->win_chat, + window->win_chat_cursor_y, + window->win_chat_cursor_x); + + while (string && string[0]) + { + next_char = gui_chat_word_get_next_char (window, (unsigned char *)string, 1); + if (!next_char) + return; + + prev_char = utf8_prev_char (string, next_char); + if (prev_char) + { + saved_char = next_char[0]; + next_char[0] = '\0'; + wprintw (window->win_chat, "%s", prev_char); + next_char[0] = saved_char; + } + + string = next_char; + } +} + +/* + * gui_chat_display_word: display a word on chat buffer + */ + +void +gui_chat_display_word (t_gui_window *window, + t_gui_line *line, + char *data, + char *end_offset, + int num_lines, int count, int *lines_displayed, int simulate) +{ + char *end_line, saved_char_end, saved_char; + int pos_saved_char, chars_to_display, num_displayed; + + if (!data || + ((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height))) + return; + + end_line = data + strlen (data); + + if (end_offset[0]) + { + saved_char_end = end_offset[1]; + end_offset[1] = '\0'; + } + else + { + end_offset = NULL; + saved_char_end = '\0'; + } + + while (data && data[0]) + { + /* insert spaces for align text under time/nick */ + if ((line->length_align > 0) && + (window->win_chat_cursor_x == 0) && + (*lines_displayed > 0) && + /* TODO: modify arbitraty value for non aligning messages on time/nick? */ + (line->length_align < (window->win_chat_width - 5))) + { + if (!simulate) + { + wmove (window->win_chat, + window->win_chat_cursor_y, + window->win_chat_cursor_x); + wclrtoeol (window->win_chat); + } + window->win_chat_cursor_x += line->length_align; + } + + chars_to_display = gui_word_strlen (window, data); + + /* too long for current line */ + if (window->win_chat_cursor_x + chars_to_display > window->win_chat_width) + { + num_displayed = window->win_chat_width - window->win_chat_cursor_x; + pos_saved_char = gui_word_real_pos (window, data, num_displayed); + saved_char = data[pos_saved_char]; + data[pos_saved_char] = '\0'; + if ((!simulate) && + ((count == 0) || (*lines_displayed >= num_lines - count))) + gui_chat_display_word_raw (window, data); + data[pos_saved_char] = saved_char; + data += pos_saved_char; + } + else + { + num_displayed = chars_to_display; + if ((!simulate) && + ((count == 0) || (*lines_displayed >= num_lines - count))) + gui_chat_display_word_raw (window, data); + data += strlen (data); + } + + window->win_chat_cursor_x += num_displayed; + + /* display new line? */ + if ((data >= end_line) || + (((simulate) || + (window->win_chat_cursor_y <= window->win_chat_height - 1)) && + (window->win_chat_cursor_x > (window->win_chat_width - 1)))) + gui_chat_display_new_line (window, num_lines, count, + lines_displayed, simulate); + + if ((data >= end_line) || + ((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height))) + data = NULL; + } + + if (end_offset) + end_offset[1] = saved_char_end; +} + +/* + * gui_chat_get_word_info: returns info about next word: beginning, end, length + */ + +void +gui_chat_get_word_info (t_gui_window *window, + char *data, + int *word_start_offset, int *word_end_offset, + int *word_length_with_spaces, int *word_length) +{ + char *start_data, *prev_char, *next_char; + int leading_spaces, char_size; + + *word_start_offset = 0; + *word_end_offset = 0; + *word_length_with_spaces = 0; + *word_length = 0; + + start_data = data; + + leading_spaces = 1; + while (data && data[0]) + { + next_char = gui_chat_word_get_next_char (window, (unsigned char *)data, 0); + if (next_char) + { + prev_char = utf8_prev_char (data, next_char); + if (prev_char) + { + if (prev_char[0] != ' ') + { + if (leading_spaces) + *word_start_offset = prev_char - start_data; + leading_spaces = 0; + char_size = next_char - prev_char; + *word_end_offset = next_char - start_data - 1; + (*word_length_with_spaces) += char_size; + (*word_length) += char_size; + } + else + { + if (leading_spaces) + (*word_length_with_spaces)++; + else + { + *word_end_offset = prev_char - start_data - 1; + return; + } + } + data = next_char; + } + } + else + { + *word_end_offset = data + strlen (data) - start_data - 1; + return; + } + } +} + +/* + * gui_chat_display_line: display a line in the chat window + * if count == 0, display whole line + * if count > 0, display 'count' lines + * (beginning from the end) + * if simulate == 1, nothing is displayed + * (for counting how many lines would have been + * lines displayed) + * returns: number of lines displayed (or simulated) + */ + +int +gui_chat_display_line (t_gui_window *window, t_gui_line *line, int count, + int simulate) +{ + int num_lines, x, y, lines_displayed; + int read_marker_x, read_marker_y; + int word_start_offset, word_end_offset; + int word_length_with_spaces, word_length; + char *ptr_data, *ptr_end_offset, *next_char, *prev_char; + char *ptr_style, saved_char; + + if (simulate) + { + x = window->win_chat_cursor_x; + y = window->win_chat_cursor_y; + window->win_chat_cursor_x = 0; + window->win_chat_cursor_y = 0; + num_lines = 0; + } + else + { + if (window->win_chat_cursor_y > window->win_chat_height - 1) + return 0; + x = window->win_chat_cursor_x; + y = window->win_chat_cursor_y; + num_lines = gui_chat_display_line (window, line, 0, 1); + window->win_chat_cursor_x = x; + window->win_chat_cursor_y = y; + } + + /* calculate marker position (maybe not used for this line!) */ + if (line->ofs_after_date > 0) + { + saved_char = line->data[line->ofs_after_date - 1]; + line->data[line->ofs_after_date - 1] = '\0'; + read_marker_x = x + gui_word_strlen (NULL, line->data); + line->data[line->ofs_after_date - 1] = saved_char; + } + else + read_marker_x = x; + read_marker_y = y; + + /* reset color & style for a new line */ + gui_chat_reset_style (window); + + lines_displayed = 0; + ptr_data = line->data; + while (ptr_data && ptr_data[0]) + { + gui_chat_get_word_info (window, + ptr_data, + &word_start_offset, + &word_end_offset, + &word_length_with_spaces, &word_length); + + ptr_end_offset = ptr_data + word_end_offset; + + if (word_length > 0) + { + /* spaces + word too long for current line but ok for next line */ + if ((window->win_chat_cursor_x + word_length_with_spaces > window->win_chat_width) + && (word_length <= window->win_chat_width - line->length_align)) + { + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + /* apply styles before jumping to start of word */ + if (!simulate && (word_start_offset > 0)) + { + saved_char = ptr_data[word_start_offset]; + ptr_data[word_start_offset] = '\0'; + ptr_style = ptr_data; + while ((ptr_style = gui_chat_word_get_next_char (window, (unsigned char *)ptr_style, 1)) != NULL) + { + /* loop until no style/char available */ + } + ptr_data[word_start_offset] = saved_char; + } + /* jump to start of word */ + ptr_data += word_start_offset; + } + + /* display word */ + gui_chat_display_word (window, line, ptr_data, + ptr_end_offset, + num_lines, count, &lines_displayed, simulate); + + if ((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height)) + ptr_data = NULL; + else + { + /* move pointer after end of word */ + ptr_data = ptr_end_offset + 1; + if (*(ptr_data - 1) == '\0') + ptr_data = NULL; + + if (window->win_chat_cursor_x == 0) + { + while (ptr_data && (ptr_data[0] == ' ')) + { + next_char = gui_chat_word_get_next_char (window, + (unsigned char *)ptr_data, 0); + if (!next_char) + break; + prev_char = utf8_prev_char (ptr_data, next_char); + if (prev_char && (prev_char[0] == ' ')) + ptr_data = next_char; + else + break; + } + } + } + } + else + { + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + ptr_data = NULL; + } + } + + if (simulate) + { + window->win_chat_cursor_x = x; + window->win_chat_cursor_y = y; + } + else + { + /* display read marker if needed */ + if (cfg_look_read_marker && cfg_look_read_marker[0] && + window->buffer->last_read_line && + (window->buffer->last_read_line == line->prev_line)) + { + gui_chat_set_weechat_color (window, COLOR_WIN_CHAT_READ_MARKER); + mvwprintw (window->win_chat, read_marker_y, read_marker_x, + "%c", cfg_look_read_marker[0]); + } + } + + return lines_displayed; +} + +/* + * gui_chat_calculate_line_diff: returns pointer to line & offset for a difference + * with given line + */ + +void +gui_chat_calculate_line_diff (t_gui_window *window, t_gui_line **line, + int *line_pos, int difference) +{ + int backward, current_size; + + if (!line || !line_pos) + return; + + backward = (difference < 0); + + if (!(*line)) + { + /* if looking backward, start at last line of buffer */ + if (backward) + { + *line = window->buffer->last_line; + if (!(*line)) + return; + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = current_size - 1; + } + /* if looking forward, start at first line of buffer */ + else + { + *line = window->buffer->lines; + if (!(*line)) + return; + *line_pos = 0; + current_size = gui_chat_display_line (window, *line, 0, 1); + } + } + else + current_size = gui_chat_display_line (window, *line, 0, 1); + + while ((*line) && (difference != 0)) + { + /* looking backward */ + if (backward) + { + if (*line_pos > 0) + (*line_pos)--; + else + { + *line = (*line)->prev_line; + if (*line) + { + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = current_size - 1; + } + } + difference++; + } + /* looking forward */ + else + { + if (*line_pos < current_size - 1) + (*line_pos)++; + else + { + *line = (*line)->next_line; + if (*line) + { + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = 0; + } + } + difference--; + } + } + + /* first or last line reached */ + if (!(*line)) + { + if (backward) + { + /* first line reached */ + *line = window->buffer->lines; + *line_pos = 0; + } + else + { + /* last line reached => consider we'll display all until the end */ + *line_pos = 0; + } + } +} + +/* + * gui_chat_draw: draw chat window for a buffer + */ + +void +gui_chat_draw (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + t_gui_line *ptr_line; + t_irc_dcc *dcc_first, *dcc_selected, *ptr_dcc; + char format_empty[32]; + int i, j, line_pos, count, num_bars; + char *unit_name[] = { N_("bytes"), N_("Kb"), N_("Mb"), N_("Gb") }; + char *unit_format[] = { "%.0Lf", "%.1Lf", "%.02Lf", "%.02Lf" }; + long unit_divide[] = { 1, 1024, 1024*1024, 1024*1024,1024 }; + int num_unit; + char format[32], date[128], *buf; + struct tm *date_tmp; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + if (erase) + { + gui_window_set_weechat_color (ptr_win->win_chat, COLOR_WIN_CHAT); + + snprintf (format_empty, 32, "%%-%ds", ptr_win->win_chat_width); + for (i = 0; i < ptr_win->win_chat_height; i++) + { + mvwprintw (ptr_win->win_chat, i, 0, format_empty, " "); + } + } + + gui_window_set_weechat_color (ptr_win->win_chat, COLOR_WIN_CHAT); + + if (buffer->type == BUFFER_TYPE_DCC) + { + i = 0; + dcc_first = (ptr_win->dcc_first) ? (t_irc_dcc *) ptr_win->dcc_first : dcc_list; + dcc_selected = (ptr_win->dcc_selected) ? (t_irc_dcc *) ptr_win->dcc_selected : dcc_list; + for (ptr_dcc = dcc_first; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc) + { + if (i >= ptr_win->win_chat_height - 1) + break; + + /* nickname and filename */ + gui_window_set_weechat_color (ptr_win->win_chat, + (ptr_dcc == dcc_selected) ? + COLOR_DCC_SELECTED : COLOR_WIN_CHAT); + mvwprintw (ptr_win->win_chat, i, 0, "%s %-16s ", + (ptr_dcc == dcc_selected) ? "***" : " ", + ptr_dcc->nick); + buf = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + (DCC_IS_CHAT(ptr_dcc->type)) ? + _(ptr_dcc->filename) : ptr_dcc->filename); + wprintw (ptr_win->win_chat, "%s", buf); + free (buf); + if (DCC_IS_FILE(ptr_dcc->type)) + { + if (ptr_dcc->filename_suffix > 0) + wprintw (ptr_win->win_chat, " (.%d)", + ptr_dcc->filename_suffix); + } + + /* status */ + gui_window_set_weechat_color (ptr_win->win_chat, + (ptr_dcc == dcc_selected) ? + COLOR_DCC_SELECTED : COLOR_WIN_CHAT); + mvwprintw (ptr_win->win_chat, i + 1, 0, "%s %s ", + (ptr_dcc == dcc_selected) ? "***" : " ", + (DCC_IS_RECV(ptr_dcc->type)) ? "-->>" : "<<--"); + gui_window_set_weechat_color (ptr_win->win_chat, + COLOR_DCC_WAITING + ptr_dcc->status); + buf = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + _(dcc_status_string[ptr_dcc->status])); + wprintw (ptr_win->win_chat, "%-10s", buf); + free (buf); + + /* other infos */ + gui_window_set_weechat_color (ptr_win->win_chat, + (ptr_dcc == dcc_selected) ? + COLOR_DCC_SELECTED : COLOR_WIN_CHAT); + if (DCC_IS_FILE(ptr_dcc->type)) + { + wprintw (ptr_win->win_chat, " ["); + if (ptr_dcc->size == 0) + num_bars = 10; + else + num_bars = (int)((((long double)(ptr_dcc->pos)/(long double)(ptr_dcc->size))*100) / 10); + for (j = 0; j < num_bars - 1; j++) + wprintw (ptr_win->win_chat, "="); + if (num_bars > 0) + wprintw (ptr_win->win_chat, ">"); + for (j = 0; j < 10 - num_bars; j++) + wprintw (ptr_win->win_chat, " "); + + if (ptr_dcc->size < 1024*10) + num_unit = 0; + else if (ptr_dcc->size < 1024*1024) + num_unit = 1; + else if (ptr_dcc->size < 1024*1024*1024) + num_unit = 2; + else + num_unit = 3; + wprintw (ptr_win->win_chat, "] %3lu%% ", + (unsigned long)(((long double)(ptr_dcc->pos)/(long double)(ptr_dcc->size))*100)); + sprintf (format, "%s %%s / %s %%s", + unit_format[num_unit], + unit_format[num_unit]); + wprintw (ptr_win->win_chat, format, + ((long double)(ptr_dcc->pos)) / ((long double)(unit_divide[num_unit])), + unit_name[num_unit], + ((long double)(ptr_dcc->size)) / ((long double)(unit_divide[num_unit])), + unit_name[num_unit]); + + if (ptr_dcc->bytes_per_sec < 1024*1024) + num_unit = 1; + else if (ptr_dcc->bytes_per_sec < 1024*1024*1024) + num_unit = 2; + else + num_unit = 3; + wprintw (ptr_win->win_chat, " ("); + if (ptr_dcc->status == DCC_ACTIVE) + { + wprintw (ptr_win->win_chat, _("ETA")); + wprintw (ptr_win->win_chat, ": %.2lu:%.2lu:%.2lu - ", + ptr_dcc->eta / 3600, + (ptr_dcc->eta / 60) % 60, + ptr_dcc->eta % 60); + } + sprintf (format, "%s %%s/s)", unit_format[num_unit]); + buf = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + unit_name[num_unit]); + wprintw (ptr_win->win_chat, format, + ((long double) ptr_dcc->bytes_per_sec) / ((long double)(unit_divide[num_unit])), + buf); + free (buf); + } + else + { + date_tmp = localtime (&(ptr_dcc->start_time)); + strftime (date, sizeof (date) - 1, "%a, %d %b %Y %H:%M:%S", date_tmp); + wprintw (ptr_win->win_chat, " %s", date); + } + + wclrtoeol (ptr_win->win_chat); + + ptr_win->dcc_last_displayed = ptr_dcc; + i += 2; + } + } + else + { + ptr_win->win_chat_cursor_x = 0; + ptr_win->win_chat_cursor_y = 0; + + /* display at position of scrolling */ + if (ptr_win->start_line) + { + ptr_line = ptr_win->start_line; + line_pos = ptr_win->start_line_pos; + } + else + { + /* look for first line to display, starting from last line */ + ptr_line = NULL; + line_pos = 0; + gui_chat_calculate_line_diff (ptr_win, &ptr_line, &line_pos, + (-1) * (ptr_win->win_chat_height - 1)); + } + + if (line_pos > 0) + { + /* display end of first line at top of screen */ + gui_chat_display_line (ptr_win, ptr_line, + gui_chat_display_line (ptr_win, + ptr_line, + 0, 1) - + line_pos, 0); + ptr_line = ptr_line->next_line; + ptr_win->first_line_displayed = 0; + } + else + ptr_win->first_line_displayed = + (ptr_line == ptr_win->buffer->lines); + + /* display lines */ + count = 0; + while (ptr_line && (ptr_win->win_chat_cursor_y <= ptr_win->win_chat_height - 1)) + { + count = gui_chat_display_line (ptr_win, ptr_line, 0, 0); + ptr_line = ptr_line->next_line; + } + + ptr_win->scroll = (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1); + + /* check if last line of buffer is entirely displayed and scrolling */ + /* if so, disable scroll indicator */ + if (!ptr_line && ptr_win->scroll) + { + if (count == gui_chat_display_line (ptr_win, ptr_win->buffer->last_line, 0, 1)) + { + ptr_win->scroll = 0; + ptr_win->start_line = NULL; + ptr_win->start_line_pos = 0; + } + } + + if (!ptr_win->scroll && (ptr_win->start_line == ptr_win->buffer->lines)) + { + ptr_win->start_line = NULL; + ptr_win->start_line_pos = 0; + } + + /* cursor is below end line of chat window? */ + if (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1) + { + ptr_win->win_chat_cursor_x = 0; + ptr_win->win_chat_cursor_y = ptr_win->win_chat_height - 1; + } + } + wnoutrefresh (ptr_win->win_chat); + refresh (); + } + } +} + +/* + * gui_chat_draw_line: add a line to chat window for a buffer + */ + +void +gui_chat_draw_line (t_gui_buffer *buffer, t_gui_line *line) +{ + /* This function does nothing in Curses GUI, + line will be displayed by gui_buffer_draw_chat() */ + (void) buffer; + (void) line; +} diff --git a/weechat/src/gui/curses/gui-color.c b/weechat/src/gui/curses/gui-color.c new file mode 100644 index 000000000..9fd1d85de --- /dev/null +++ b/weechat/src/gui/curses/gui-color.c @@ -0,0 +1,607 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-color.c: color functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + + +t_gui_color gui_weechat_colors[] = +{ { -1, 0, 0, "default" }, + { WEECHAT_COLOR_BLACK, 0, 0, "black" }, + { WEECHAT_COLOR_RED, 0, 0, "red" }, + { WEECHAT_COLOR_RED, 0, A_BOLD, "lightred" }, + { WEECHAT_COLOR_GREEN, 0, 0, "green" }, + { WEECHAT_COLOR_GREEN, 0, A_BOLD, "lightgreen" }, + { WEECHAT_COLOR_YELLOW, 0, 0, "brown" }, + { WEECHAT_COLOR_YELLOW, 0, A_BOLD, "yellow" }, + { WEECHAT_COLOR_BLUE, 0, 0, "blue" }, + { WEECHAT_COLOR_BLUE, 0, A_BOLD, "lightblue" }, + { WEECHAT_COLOR_MAGENTA, 0, 0, "magenta" }, + { WEECHAT_COLOR_MAGENTA, 0, A_BOLD, "lightmagenta" }, + { WEECHAT_COLOR_CYAN, 0, 0, "cyan" }, + { WEECHAT_COLOR_CYAN, 0, A_BOLD, "lightcyan" }, + { WEECHAT_COLOR_WHITE, 0, A_BOLD, "white" }, + { 0, 0, 0, NULL } +}; + +int gui_irc_colors[GUI_NUM_IRC_COLORS][2] = +{ { /* 0 */ WEECHAT_COLOR_WHITE, A_BOLD }, + { /* 1 */ WEECHAT_COLOR_BLACK, 0 }, + { /* 2 */ WEECHAT_COLOR_BLUE, 0 }, + { /* 3 */ WEECHAT_COLOR_GREEN, 0 }, + { /* 4 */ WEECHAT_COLOR_RED, A_BOLD }, + { /* 5 */ WEECHAT_COLOR_RED, 0 }, + { /* 6 */ WEECHAT_COLOR_MAGENTA, 0 }, + { /* 7 */ WEECHAT_COLOR_YELLOW, 0 }, + { /* 8 */ WEECHAT_COLOR_YELLOW, A_BOLD }, + { /* 9 */ WEECHAT_COLOR_GREEN, A_BOLD }, + { /* 10 */ WEECHAT_COLOR_CYAN, 0 }, + { /* 11 */ WEECHAT_COLOR_CYAN, A_BOLD }, + { /* 12 */ WEECHAT_COLOR_BLUE, A_BOLD }, + { /* 13 */ WEECHAT_COLOR_MAGENTA, A_BOLD }, + { /* 14 */ WEECHAT_COLOR_WHITE, 0 }, + { /* 15 */ WEECHAT_COLOR_WHITE, A_BOLD } +}; + +t_gui_color *gui_color[GUI_NUM_COLORS]; + + +/* + * gui_color_assign: assign a WeeChat color (read from config) + */ + +int +gui_color_assign (int *color, char *color_name) +{ + int i; + + /* look for curses colors in table */ + i = 0; + while (gui_weechat_colors[i].string) + { + if (ascii_strcasecmp (gui_weechat_colors[i].string, color_name) == 0) + { + *color = i; + return 1; + } + i++; + } + + /* color not found */ + return 0; +} + +/* + * gui_color_get_name: get color name + */ + +char * +gui_color_get_name (int num_color) +{ + return gui_weechat_colors[num_color].string; +} + +/* + * gui_color_decode: parses a message (coming from IRC server), + * and according: + * - remove any color/style in message + * or: + * - change colors by codes to be compatible with + * other IRC clients + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode (unsigned char *string, int keep_colors) +{ + unsigned char *out; + int out_length, out_pos; + char str_fg[3], str_bg[3]; + int fg, bg, attr; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + case GUI_ATTR_RESET_CHAR: + case GUI_ATTR_FIXED_CHAR: + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + case GUI_ATTR_ITALIC_CHAR: + case GUI_ATTR_UNDERLINE_CHAR: + if (keep_colors) + out[out_pos++] = string[0]; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + string++; + str_fg[0] = '\0'; + str_bg[0] = '\0'; + if (isdigit (string[0])) + { + str_fg[0] = string[0]; + str_fg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_fg[1] = string[0]; + str_fg[2] = '\0'; + string++; + } + } + if (string[0] == ',') + { + string++; + if (isdigit (string[0])) + { + str_bg[0] = string[0]; + str_bg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_bg[1] = string[0]; + str_bg[2] = '\0'; + string++; + } + } + } + if (keep_colors) + { + if (!str_fg[0] && !str_bg[0]) + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + else + { + attr = 0; + if (str_fg[0]) + { + sscanf (str_fg, "%d", &fg); + fg %= GUI_NUM_IRC_COLORS; + attr |= gui_irc_colors[fg][1]; + } + if (str_bg[0]) + { + sscanf (str_bg, "%d", &bg); + bg %= GUI_NUM_IRC_COLORS; + attr |= gui_irc_colors[bg][1]; + } + if (attr & A_BOLD) + { + out[out_pos++] = GUI_ATTR_WEECHAT_SET_CHAR; + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + } + else + { + out[out_pos++] = GUI_ATTR_WEECHAT_REMOVE_CHAR; + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + } + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + if (str_fg[0]) + { + out[out_pos++] = (gui_irc_colors[fg][0] / 10) + '0'; + out[out_pos++] = (gui_irc_colors[fg][0] % 10) + '0'; + } + if (str_bg[0]) + { + out[out_pos++] = ','; + out[out_pos++] = (gui_irc_colors[bg][0] / 10) + '0'; + out[out_pos++] = (gui_irc_colors[bg][0] % 10) + '0'; + } + } + } + break; + case GUI_ATTR_WEECHAT_COLOR_CHAR: + string++; + if (isdigit (string[0]) && isdigit (string[1])) + { + if (keep_colors) + { + out[out_pos++] = string[0]; + out[out_pos++] = string[1]; + } + string += 2; + } + break; + case GUI_ATTR_WEECHAT_SET_CHAR: + case GUI_ATTR_WEECHAT_REMOVE_CHAR: + string++; + if (string[0]) + { + if (keep_colors) + { + out[out_pos++] = *(string - 1); + out[out_pos++] = string[0]; + } + string++; + } + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_decode_for_user_entry: parses a message (coming from IRC server), + * and replaces colors/bold/.. by %C, %B, .. + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode_for_user_entry (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'B'; + string++; + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_RESET_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'O'; + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'C'; + string++; + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_encode: parses a message (entered by user), and + * encode special chars (%B, %C, ..) in IRC colors + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_encode (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case '%': + string++; + switch (string[0]) + { + case '\0': + out[out_pos++] = '%'; + break; + case '%': /* double '%' replaced by single '%' */ + out[out_pos++] = string[0]; + string++; + break; + case 'B': /* bold */ + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + string++; + break; + case 'C': /* color */ + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + } + } + if (string[0] == ',') + { + out[out_pos++] = ','; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + } + } + } + break; + case 'O': /* reset */ + out[out_pos++] = GUI_ATTR_RESET_CHAR; + string++; + break; + case 'R': /* reverse */ + out[out_pos++] = GUI_ATTR_REVERSE_CHAR; + string++; + break; + case 'U': /* underline */ + out[out_pos++] = GUI_ATTR_UNDERLINE_CHAR; + string++; + break; + default: + out[out_pos++] = '%'; + out[out_pos++] = string[0]; + string++; + } + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_build: build a WeeChat color with foreground, + * background and attributes (attributes are + * given with foreground color, with a OR) + */ + +t_gui_color * +gui_color_build (int number, int foreground, int background) +{ + t_gui_color *new_color; + + new_color = (t_gui_color *)malloc (sizeof (t_gui_color)); + if (!new_color) + return NULL; + + new_color->foreground = gui_weechat_colors[foreground].foreground; + new_color->background = gui_weechat_colors[background].foreground; + new_color->attributes = gui_weechat_colors[foreground].attributes; + new_color->string = (char *)malloc (4); + if (new_color->string) + snprintf (new_color->string, 4, + "%s%02d", + GUI_ATTR_WEECHAT_COLOR_STR, number); + + return new_color; +} + +/* + * gui_color_get_pair: get color pair with a WeeChat color number + */ + +int +gui_color_get_pair (int num_color) +{ + int fg, bg; + + if ((num_color < 0) || (num_color > GUI_NUM_COLORS - 1)) + return WEECHAT_COLOR_WHITE; + + fg = gui_color[num_color]->foreground; + bg = gui_color[num_color]->background; + + if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + return 63; + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + + return (bg * 8) + fg; +} + +/* + * gui_color_init_pairs: init color pairs + */ + +void +gui_color_init_pairs () +{ + int i; + char shift_colors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; + + if (has_colors ()) + { + for (i = 1; i < COLOR_PAIRS; i++) + init_pair (i, shift_colors[i % 8], (i < 8) ? -1 : shift_colors[i / 8]); + + /* disable white on white, replaced by black on white */ + init_pair (63, -1, -1); + + /* white on default bg is default (-1) */ + if (!cfg_col_real_white) + init_pair (WEECHAT_COLOR_WHITE, -1, -1); + } +} + +/* + * gui_color_init_weechat: init WeeChat colors + */ + +void +gui_color_init_weechat () +{ + int i; + + gui_color[COLOR_WIN_SEPARATOR] = gui_color_build (COLOR_WIN_SEPARATOR, cfg_col_separator, cfg_col_separator); + gui_color[COLOR_WIN_TITLE] = gui_color_build (COLOR_WIN_TITLE, cfg_col_title, cfg_col_title_bg); + gui_color[COLOR_WIN_CHAT] = gui_color_build (COLOR_WIN_CHAT, cfg_col_chat, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_TIME] = gui_color_build (COLOR_WIN_CHAT_TIME, cfg_col_chat_time, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_TIME_SEP] = gui_color_build (COLOR_WIN_CHAT_TIME_SEP, cfg_col_chat_time_sep, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PREFIX1] = gui_color_build (COLOR_WIN_CHAT_PREFIX1, cfg_col_chat_prefix1, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PREFIX2] = gui_color_build (COLOR_WIN_CHAT_PREFIX2, cfg_col_chat_prefix2, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_SERVER] = gui_color_build (COLOR_WIN_CHAT_SERVER, cfg_col_chat_server, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_JOIN] = gui_color_build (COLOR_WIN_CHAT_JOIN, cfg_col_chat_join, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PART] = gui_color_build (COLOR_WIN_CHAT_PART, cfg_col_chat_part, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_NICK] = gui_color_build (COLOR_WIN_CHAT_NICK, cfg_col_chat_nick, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_HOST] = gui_color_build (COLOR_WIN_CHAT_HOST, cfg_col_chat_host, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_CHANNEL] = gui_color_build (COLOR_WIN_CHAT_CHANNEL, cfg_col_chat_channel, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_DARK] = gui_color_build (COLOR_WIN_CHAT_DARK, cfg_col_chat_dark, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_HIGHLIGHT] = gui_color_build (COLOR_WIN_CHAT_HIGHLIGHT, cfg_col_chat_highlight, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_READ_MARKER] = gui_color_build (COLOR_WIN_CHAT_READ_MARKER, cfg_col_chat_read_marker, cfg_col_chat_read_marker_bg); + gui_color[COLOR_WIN_STATUS] = gui_color_build (COLOR_WIN_STATUS, cfg_col_status, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DELIMITERS] = gui_color_build (COLOR_WIN_STATUS_DELIMITERS, cfg_col_status_delimiters, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_CHANNEL] = gui_color_build (COLOR_WIN_STATUS_CHANNEL, cfg_col_status_channel, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_MSG] = gui_color_build (COLOR_WIN_STATUS_DATA_MSG, cfg_col_status_data_msg, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_PRIVATE] = gui_color_build (COLOR_WIN_STATUS_DATA_PRIVATE, cfg_col_status_data_private, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_HIGHLIGHT] = gui_color_build (COLOR_WIN_STATUS_DATA_HIGHLIGHT, cfg_col_status_data_highlight, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_OTHER] = gui_color_build (COLOR_WIN_STATUS_DATA_OTHER, cfg_col_status_data_other, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_MORE] = gui_color_build (COLOR_WIN_STATUS_MORE, cfg_col_status_more, cfg_col_status_bg); + gui_color[COLOR_WIN_INFOBAR] = gui_color_build (COLOR_WIN_INFOBAR, cfg_col_infobar, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INFOBAR_DELIMITERS] = gui_color_build (COLOR_WIN_INFOBAR_DELIMITERS, cfg_col_infobar_delimiters, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INFOBAR_HIGHLIGHT] = gui_color_build (COLOR_WIN_INFOBAR_HIGHLIGHT, cfg_col_infobar_highlight, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INPUT] = gui_color_build (COLOR_WIN_INPUT, cfg_col_input, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_SERVER] = gui_color_build (COLOR_WIN_INPUT_SERVER, cfg_col_input_server, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_CHANNEL] = gui_color_build (COLOR_WIN_INPUT_CHANNEL, cfg_col_input_channel, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_NICK] = gui_color_build (COLOR_WIN_INPUT_NICK, cfg_col_input_nick, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_DELIMITERS] = gui_color_build (COLOR_WIN_INPUT_DELIMITERS, cfg_col_input_delimiters, cfg_col_input_bg); + gui_color[COLOR_WIN_NICK] = gui_color_build (COLOR_WIN_NICK, cfg_col_nick, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_AWAY] = gui_color_build (COLOR_WIN_NICK_AWAY, cfg_col_nick_away, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_CHANOWNER] = gui_color_build (COLOR_WIN_NICK_CHANOWNER, cfg_col_nick_chanowner, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_CHANADMIN] = gui_color_build (COLOR_WIN_NICK_CHANADMIN, cfg_col_nick_chanadmin, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_OP] = gui_color_build (COLOR_WIN_NICK_OP, cfg_col_nick_op, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_HALFOP] = gui_color_build (COLOR_WIN_NICK_HALFOP, cfg_col_nick_halfop, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_VOICE] = gui_color_build (COLOR_WIN_NICK_VOICE, cfg_col_nick_voice, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_MORE] = gui_color_build (COLOR_WIN_NICK_MORE, cfg_col_nick_more, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_SEP] = gui_color_build (COLOR_WIN_NICK_SEP, cfg_col_nick_sep, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_SELF] = gui_color_build (COLOR_WIN_NICK_SELF, cfg_col_nick_self, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_PRIVATE] = gui_color_build (COLOR_WIN_NICK_PRIVATE, cfg_col_nick_private, cfg_col_nick_bg); + + for (i = 0; i < COLOR_WIN_NICK_NUMBER; i++) + { + gui_color[COLOR_WIN_NICK_1 + i] = gui_color_build (COLOR_WIN_NICK_1 + i, cfg_col_nick_colors[i], cfg_col_chat_bg); + } + + gui_color[COLOR_DCC_SELECTED] = gui_color_build (COLOR_DCC_SELECTED, cfg_col_dcc_selected, cfg_col_chat_bg); + gui_color[COLOR_DCC_WAITING] = gui_color_build (COLOR_DCC_WAITING, cfg_col_dcc_waiting, cfg_col_chat_bg); + gui_color[COLOR_DCC_CONNECTING] = gui_color_build (COLOR_DCC_CONNECTING, cfg_col_dcc_connecting, cfg_col_chat_bg); + gui_color[COLOR_DCC_ACTIVE] = gui_color_build (COLOR_DCC_ACTIVE, cfg_col_dcc_active, cfg_col_chat_bg); + gui_color[COLOR_DCC_DONE] = gui_color_build (COLOR_DCC_DONE, cfg_col_dcc_done, cfg_col_chat_bg); + gui_color[COLOR_DCC_FAILED] = gui_color_build (COLOR_DCC_FAILED, cfg_col_dcc_failed, cfg_col_chat_bg); + gui_color[COLOR_DCC_ABORTED] = gui_color_build (COLOR_DCC_ABORTED, cfg_col_dcc_aborted, cfg_col_chat_bg); +} + +/* + * gui_color_rebuild_weechat: rebuild WeeChat colors + */ + +void +gui_color_rebuild_weechat () +{ + int i; + + if (has_colors ()) + { + for (i = 0; i < GUI_NUM_COLORS; i++) + { + if (gui_color[i]) + { + if (gui_color[i]->string) + free (gui_color[i]->string); + free (gui_color[i]); + gui_color[i] = NULL; + } + } + gui_color_init_weechat (); + } +} + +/* + * gui_color_init: init GUI colors + */ + +void +gui_color_init () +{ + if (has_colors ()) + { + start_color (); + use_default_colors (); + } + gui_color_init_pairs (); + gui_color_init_weechat (); +} diff --git a/weechat/src/gui/curses/gui-curses.h b/weechat/src/gui/curses/gui-curses.h new file mode 100644 index 000000000..27dcdd372 --- /dev/null +++ b/weechat/src/gui/curses/gui-curses.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef __WEECHAT_GUI_CURSES_H +#define __WEECHAT_GUI_CURSES_H 1 + +/* shift ncurses colors for compatibility with colors + in IRC messages (same as other IRC clients) */ + +#define WEECHAT_COLOR_BLACK COLOR_BLACK +#define WEECHAT_COLOR_RED COLOR_BLUE +#define WEECHAT_COLOR_GREEN COLOR_GREEN +#define WEECHAT_COLOR_YELLOW COLOR_CYAN +#define WEECHAT_COLOR_BLUE COLOR_RED +#define WEECHAT_COLOR_MAGENTA COLOR_MAGENTA +#define WEECHAT_COLOR_CYAN COLOR_YELLOW +#define WEECHAT_COLOR_WHITE COLOR_WHITE + +extern t_gui_color gui_weechat_colors[]; +extern int gui_irc_colors[GUI_NUM_IRC_COLORS][2]; + +/* color functions */ +extern int gui_color_get_pair (int); +extern void gui_color_init (); + +/* chat functions */ +extern void gui_chat_calculate_line_diff (t_gui_window *, t_gui_line **, int *, int); + +/* keyboard functions */ +extern void gui_keyboard_default_bindings (); +extern void gui_keyboard_read (); + +/* window functions */ +extern void gui_window_curses_clear (WINDOW *, int); +extern void gui_window_set_weechat_color (WINDOW *, int); +extern void gui_window_refresh_screen_sigwinch (); +extern void gui_window_set_title (); +extern void gui_window_reset_title (); + +#endif /* gui-curses.h */ diff --git a/weechat/src/gui/curses/gui-infobar.c b/weechat/src/gui/curses/gui-infobar.c new file mode 100644 index 000000000..73abf75c0 --- /dev/null +++ b/weechat/src/gui/curses/gui-infobar.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-infobar.c: infobar display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + + +/* + * gui_infobar_draw_time: draw time in infobar window + */ + +void +gui_infobar_draw_time (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + time_t time_seconds; + struct tm *local_time; + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + time_seconds = time (NULL); + local_time = localtime (&time_seconds); + if (local_time) + { + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + mvwprintw (ptr_win->win_infobar, + 0, 1, + "%02d:%02d", + local_time->tm_hour, local_time->tm_min); + if (cfg_look_infobar_seconds) + wprintw (ptr_win->win_infobar, + ":%02d", + local_time->tm_sec); + } + wnoutrefresh (ptr_win->win_infobar); + } +} + +/* + * gui_infobar_draw: draw infobar window for a buffer + */ + +void +gui_infobar_draw (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + time_t time_seconds; + struct tm *local_time; + char text_time[1024 + 1]; + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (erase) + gui_window_curses_clear (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + + time_seconds = time (NULL); + local_time = localtime (&time_seconds); + if (local_time) + { + strftime (text_time, 1024, cfg_look_infobar_timestamp, local_time); + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR_DELIMITERS); + wprintw (ptr_win->win_infobar, "["); + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + wprintw (ptr_win->win_infobar, + "%02d:%02d", + local_time->tm_hour, local_time->tm_min); + if (cfg_look_infobar_seconds) + wprintw (ptr_win->win_infobar, + ":%02d", + local_time->tm_sec); + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR_DELIMITERS); + wprintw (ptr_win->win_infobar, "]"); + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR); + wprintw (ptr_win->win_infobar, + " %s", text_time); + } + if (gui_infobar) + { + gui_window_set_weechat_color (ptr_win->win_infobar, COLOR_WIN_INFOBAR_DELIMITERS); + wprintw (ptr_win->win_infobar, " | "); + gui_window_set_weechat_color (ptr_win->win_infobar, gui_infobar->color); + wprintw (ptr_win->win_infobar, "%s", gui_infobar->text); + } + + wnoutrefresh (ptr_win->win_infobar); + refresh (); + } +} diff --git a/weechat/src/gui/curses/gui-input.c b/weechat/src/gui/curses/gui-input.c index 450fef559..9e93c9a1a 100644 --- a/weechat/src/gui/curses/gui-input.c +++ b/weechat/src/gui/curses/gui-input.c @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -/* gui-input: user input functions for Curses GUI */ +/* gui-input: input display functions for Curses GUI */ #ifdef HAVE_CONFIG_H @@ -25,12 +25,6 @@ #endif #include -#include -#include -#include -#include -#include -#include #ifdef HAVE_NCURSESW_CURSES_H #include @@ -40,12 +34,9 @@ #include "../../common/weechat.h" #include "../gui.h" -#include "../../common/weeconfig.h" -#include "../../common/command.h" -#include "../../common/hotlist.h" -#include "../../common/fifo.h" #include "../../common/utf8.h" -#include "../../irc/irc.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" #ifdef PLUGINS #include "../../plugins/plugins.h" @@ -53,483 +44,391 @@ /* - * gui_input_default_key_bindings: create default key bindings + * gui_input_set_color: set color for an input window */ void -gui_input_default_key_bindings () +gui_input_set_color (t_gui_window *window, int irc_color) { - int i; - char key_str[32], command[32]; + int fg, bg; - /* keys binded with internal functions */ - gui_key_bind ( /* RC */ "ctrl-M", "return"); - gui_key_bind ( /* RC */ "ctrl-J", "return"); - gui_key_bind ( /* tab */ "ctrl-I", "tab"); - gui_key_bind ( /* basckp */ "ctrl-H", "backspace"); - gui_key_bind ( /* basckp */ "ctrl-?", "backspace"); - gui_key_bind ( /* del */ "meta2-3~", "delete"); - gui_key_bind ( /* ^K */ "ctrl-K", "delete_end_line"); - gui_key_bind ( /* ^U */ "ctrl-U", "delete_beginning_line"); - gui_key_bind ( /* ^W */ "ctrl-W", "delete_previous_word"); - gui_key_bind ( /* ^Y */ "ctrl-Y", "clipboard_paste"); - gui_key_bind ( /* ^T */ "ctrl-T", "transpose_chars"); - gui_key_bind ( /* home */ "meta2-1~", "home"); - gui_key_bind ( /* home */ "meta2-H", "home"); - gui_key_bind ( /* home */ "meta2-7~", "home"); - gui_key_bind ( /* ^A */ "ctrl-A", "home"); - gui_key_bind ( /* end */ "meta2-4~", "end"); - gui_key_bind ( /* end */ "meta2-F", "end"); - gui_key_bind ( /* end */ "meta2-8~", "end"); - gui_key_bind ( /* ^E */ "ctrl-E", "end"); - gui_key_bind ( /* left */ "meta2-D", "left"); - gui_key_bind ( /* right */ "meta2-C", "right"); - gui_key_bind ( /* up */ "meta2-A", "up"); - gui_key_bind ( /* ^up */ "meta-Oa", "up_global"); - gui_key_bind ( /* down */ "meta2-B", "down"); - gui_key_bind ( /* ^down */ "meta-Ob", "down_global"); - gui_key_bind ( /* pgup */ "meta2-5~", "page_up"); - gui_key_bind ( /* pgdn */ "meta2-6~", "page_down"); - gui_key_bind ( /* m-pgup */ "meta-meta2-5~", "scroll_up"); - gui_key_bind ( /* m-pgdn */ "meta-meta2-6~", "scroll_down"); - gui_key_bind ( /* m-home */ "meta-meta2-1~", "scroll_top"); - gui_key_bind ( /* m-end */ "meta-meta2-4~", "scroll_bottom"); - gui_key_bind ( /* F10 */ "meta2-21~", "infobar_clear"); - gui_key_bind ( /* F11 */ "meta2-23~", "nick_page_up"); - gui_key_bind ( /* F12 */ "meta2-24~", "nick_page_down"); - gui_key_bind ( /* m-F11 */ "meta-meta2-23~", "nick_beginning"); - gui_key_bind ( /* m-F12 */ "meta-meta2-24~", "nick_end"); - gui_key_bind ( /* ^L */ "ctrl-L", "refresh"); - gui_key_bind ( /* m-a */ "meta-a", "jump_smart"); - gui_key_bind ( /* m-b */ "meta-b", "previous_word"); - gui_key_bind ( /* ^left */ "meta-Od", "previous_word"); - gui_key_bind ( /* m-d */ "meta-d", "delete_next_word"); - gui_key_bind ( /* m-f */ "meta-f", "next_word"); - gui_key_bind ( /* ^right */ "meta-Oc", "next_word"); - gui_key_bind ( /* m-h */ "meta-h", "hotlist_clear"); - gui_key_bind ( /* m-j,m-d */ "meta-jmeta-d", "jump_dcc"); - gui_key_bind ( /* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer"); - gui_key_bind ( /* m-j,m-s */ "meta-jmeta-s", "jump_server"); - gui_key_bind ( /* m-j,m-x */ "meta-jmeta-x", "jump_next_server"); - gui_key_bind ( /* m-j,m-r */ "meta-jmeta-r", "jump_raw_data"); - gui_key_bind ( /* m-k */ "meta-k", "grab_key"); - gui_key_bind ( /* m-n */ "meta-n", "scroll_next_highlight"); - gui_key_bind ( /* m-p */ "meta-p", "scroll_previous_highlight"); - gui_key_bind ( /* m-r */ "meta-r", "delete_line"); - gui_key_bind ( /* m-s */ "meta-s", "switch_server"); - gui_key_bind ( /* m-u */ "meta-u", "scroll_unread"); + fg = gui_irc_colors[irc_color][0]; + bg = gui_color[COLOR_WIN_INPUT]->background; - /* keys binded with commands */ - gui_key_bind ( /* m-left */ "meta-meta2-D", "/buffer -1"); - gui_key_bind ( /* F5 */ "meta2-15~", "/buffer -1"); - gui_key_bind ( /* m-right */ "meta-meta2-C", "/buffer +1"); - gui_key_bind ( /* F6 */ "meta2-17~", "/buffer +1"); - gui_key_bind ( /* F7 */ "meta2-18~", "/window -1"); - gui_key_bind ( /* F8 */ "meta2-19~", "/window +1"); - gui_key_bind ( /* m-w,m-up */ "meta-wmeta-meta2-A", "/window up"); - gui_key_bind ( /* m-w,m-down */ "meta-wmeta-meta2-B", "/window down"); - gui_key_bind ( /* m-w,m-left */ "meta-wmeta-meta2-D", "/window left"); - gui_key_bind ( /* m-w,m-right */ "meta-wmeta-meta2-C", "/window right"); - gui_key_bind ( /* m-0 */ "meta-0", "/buffer 10"); - gui_key_bind ( /* m-1 */ "meta-1", "/buffer 1"); - gui_key_bind ( /* m-2 */ "meta-2", "/buffer 2"); - gui_key_bind ( /* m-3 */ "meta-3", "/buffer 3"); - gui_key_bind ( /* m-4 */ "meta-4", "/buffer 4"); - gui_key_bind ( /* m-5 */ "meta-5", "/buffer 5"); - gui_key_bind ( /* m-6 */ "meta-6", "/buffer 6"); - gui_key_bind ( /* m-7 */ "meta-7", "/buffer 7"); - gui_key_bind ( /* m-8 */ "meta-8", "/buffer 8"); - gui_key_bind ( /* m-9 */ "meta-9", "/buffer 9"); + irc_color %= GUI_NUM_IRC_COLORS; + if (gui_irc_colors[irc_color][1] & A_BOLD) + wattron (window->win_input, A_BOLD); - /* bind meta-j + {01..99} to switch to buffers # > 10 */ - for (i = 1; i < 100; i++) + if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + wattron (window->win_input, COLOR_PAIR(63)); + else { - sprintf (key_str, "meta-j%02d", i); - sprintf (command, "/buffer %d", i); - gui_key_bind (key_str, command); + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + wattron (window->win_input, COLOR_PAIR((bg * 8) + fg)); } } /* - * gui_input_grab_end: insert grabbed key in input buffer + * gui_input_get_prompt_length: return input prompt length + */ + +int +gui_input_get_prompt_length (t_gui_window *window, char *nick) +{ + char *pos, *modes; + int length, mode_found; + + length = 0; + pos = cfg_look_input_format; + while (pos && pos[0]) + { + switch (pos[0]) + { + case '%': + pos++; + switch (pos[0]) + { + case 'c': + if (CHANNEL(window->buffer)) + length += utf8_strlen (CHANNEL(window->buffer)->name); + else + { + if (SERVER(window->buffer)) + length += utf8_strlen (SERVER(window->buffer)->name); + } + pos++; + break; + case 'm': + if (SERVER(window->buffer)) + { + mode_found = 0; + for (modes = SERVER(window->buffer)->nick_modes; + modes && modes[0]; modes++) + { + if (modes[0] != ' ') + { + length++; + mode_found = 1; + } + } + if (mode_found) + length++; + } + pos++; + break; + case 'n': + length += utf8_strlen (nick); + pos++; + break; + default: + length++; + if (pos[0]) + { + if (pos[0] == '%') + pos++; + else + { + length++; + pos += utf8_char_size (pos); + } + } + break; + } + break; + default: + length++; + pos += utf8_char_size (pos); + break; + } + } + return length; +} + +/* + * gui_input_draw_prompt: display input prompt */ void -gui_input_grab_end () +gui_input_draw_prompt (t_gui_window *window, char *nick) { - char *expanded_key, *expanded_key2; - int length; - char *buffer_before_key; - - /* get expanded name (for example: ^U => ctrl-u) */ - expanded_key = gui_key_get_expanded_name (gui_key_buffer); + char *pos, saved_char, *modes; + int char_size, mode_found; - if (expanded_key) + wmove (window->win_input, 0, 0); + pos = cfg_look_input_format; + while (pos && pos[0]) { - if (gui_current_window->buffer->has_input) + switch (pos[0]) { - buffer_before_key = - (gui_current_window->buffer->input_buffer) ? - strdup (gui_current_window->buffer->input_buffer) : strdup (""); - gui_insert_string_input (gui_current_window, expanded_key, -1); - gui_current_window->buffer->input_buffer_pos += utf8_strlen (expanded_key); - gui_draw_buffer_input (gui_current_window->buffer, 1); - gui_current_window->buffer->completion.position = -1; -#ifdef PLUGINS - length = strlen (expanded_key) + 1 + 1; - expanded_key2 = (char *) malloc (length); - if (expanded_key2) + case '%': + pos++; + switch (pos[0]) + { + case 'c': + if (CHANNEL(window->buffer)) + { + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_CHANNEL); + wprintw (window->win_input, "%s", + CHANNEL(window->buffer)->name); + } + else + { + if (SERVER(window->buffer)) + { + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_SERVER); + wprintw (window->win_input, "%s", + SERVER(window->buffer)->name); + } + } + pos++; + break; + case 'm': + if (SERVER(window->buffer)) + { + mode_found = 0; + for (modes = SERVER(window->buffer)->nick_modes; + modes && modes[0]; modes++) + { + if (modes[0] != ' ') + mode_found = 1; + } + if (mode_found) + { + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT); + wprintw (window->win_input, "+"); + for (modes = SERVER(window->buffer)->nick_modes; + modes && modes[0]; modes++) + { + if (modes[0] != ' ') + wprintw (window->win_input, "%c", + modes[0]); + } + } + } + pos++; + break; + case 'n': + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_NICK); + wprintw (window->win_input, "%s", nick); + pos++; + break; + default: + if (pos[0]) + { + char_size = utf8_char_size (pos); + saved_char = pos[char_size]; + pos[char_size] = '\0'; + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_DELIMITERS); + wprintw (window->win_input, "%%%s", pos); + pos[char_size] = saved_char; + pos += char_size; + } + else + { + wprintw (window->win_input, "%%"); + pos++; + } + break; + } + break; + default: + char_size = utf8_char_size (pos); + saved_char = pos[char_size]; + pos[char_size] = '\0'; + gui_window_set_weechat_color (window->win_input, + COLOR_WIN_INPUT_DELIMITERS); + wprintw (window->win_input, "%s", pos); + pos[char_size] = saved_char; + pos += char_size; + break; + } + } +} + +/* + * gui_input_draw_text: display text in input buffer, according to color mask + */ + +void +gui_input_draw_text (t_gui_window *window, int input_width) +{ + char *ptr_start, *ptr_next, saved_char; + int pos_mask, size, last_color, color; + + ptr_start = utf8_add_offset (window->buffer->input_buffer, + window->buffer->input_buffer_1st_display); + pos_mask = ptr_start - window->buffer->input_buffer; + last_color = -1; + while ((input_width > 0) && ptr_start && ptr_start[0]) + { + ptr_next = utf8_next_char (ptr_start); + if (ptr_next) + { + saved_char = ptr_next[0]; + ptr_next[0] = '\0'; + size = ptr_next - ptr_start; + if (window->buffer->input_buffer_color_mask[pos_mask] != ' ') + color = window->buffer->input_buffer_color_mask[pos_mask] - '0'; + else + color = -1; + if (color != last_color) { - snprintf (expanded_key2, length, "*%s", expanded_key); - (void) plugin_keyboard_handler_exec (expanded_key2, - buffer_before_key, - gui_current_window->buffer->input_buffer); - free (expanded_key2); + if (color == -1) + gui_window_set_weechat_color (window->win_input, COLOR_WIN_INPUT); + else + gui_input_set_color (window, color); } -#endif - if (buffer_before_key) - free (buffer_before_key); - } - free (expanded_key); - } - - /* end grab mode */ - gui_key_grab = 0; - gui_key_grab_count = 0; - gui_key_buffer[0] = '\0'; -} - -/* - * gui_input_read: read keyboard chars - */ - -void -gui_input_read () -{ - int key, i, insert_ok; - char key_str[32], key_str2[33]; - char *buffer_before_key; - - i = 0; - /* do not loop too much here (for example when big paste was made), - to read also socket & co */ - while (i < 8) - { - if (gui_key_grab && (gui_key_grab_count > 10)) - gui_input_grab_end (); - - key = getch (); - insert_ok = 1; - - if (key == ERR) - { - if (gui_key_grab && (gui_key_grab_count > 0)) - gui_input_grab_end (); - break; - } - - if (key == KEY_RESIZE) - { - gui_refresh_screen (); - continue; - } - - gui_last_activity_time = time (NULL); - - if (key < 32) - { - insert_ok = 0; - key_str[0] = '^'; - key_str[1] = (char) key + '@'; - key_str[2] = '\0'; - } - else if (key == 127) - { - key_str[0] = '^'; - key_str[1] = '?'; - key_str[2] = '\0'; + last_color = color; + wprintw (window->win_input, "%s", ptr_start); + ptr_next[0] = saved_char; + ptr_start = ptr_next; + pos_mask += size; } else - { - if (local_utf8) - { - /* 1 char: 0vvvvvvv */ - if (key < 0x80) - { - key_str[0] = (char) key; - key_str[1] = '\0'; - } - /* 2 chars: 110vvvvv 10vvvvvv */ - else if ((key & 0xE0) == 0xC0) - { - key_str[0] = (char) key; - key_str[1] = (char) (getch ()); - key_str[2] = '\0'; - } - /* 3 chars: 1110vvvv 10vvvvvv 10vvvvvv */ - else if ((key & 0xF0) == 0xE0) - { - key_str[0] = (char) key; - key_str[1] = (char) (getch ()); - key_str[2] = (char) (getch ()); - key_str[3] = '\0'; - } - /* 4 chars: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */ - else if ((key & 0xF8) == 0xF0) - { - key_str[0] = (char) key; - key_str[1] = (char) (getch ()); - key_str[2] = (char) (getch ()); - key_str[3] = (char) (getch ()); - key_str[4] = '\0'; - } - } - else - { - key_str[0] = (char) key; - key_str[1] = '\0'; - } - } - - if (strcmp (key_str, "^") == 0) - { - key_str[1] = '^'; - key_str[2] = '\0'; - } - - /*gui_printf (gui_current_window->buffer, "gui_input_read: key = %s (%d)\n", key_str, key);*/ - - if ((gui_key_pressed (key_str) != 0) && (insert_ok)) - { - if (strcmp (key_str, "^^") == 0) - key_str[1] = '\0'; - - switch (gui_current_window->buffer->type) - { - case BUFFER_TYPE_STANDARD: - buffer_before_key = - (gui_current_window->buffer->input_buffer) ? - strdup (gui_current_window->buffer->input_buffer) : strdup (""); - gui_insert_string_input (gui_current_window, key_str, -1); - gui_current_window->buffer->input_buffer_pos += utf8_strlen (key_str); - gui_draw_buffer_input (gui_current_window->buffer, 0); - gui_current_window->buffer->completion.position = -1; -#ifdef PLUGINS - snprintf (key_str2, sizeof (key_str2), "*%s", key_str); - (void) plugin_keyboard_handler_exec (key_str2, - buffer_before_key, - gui_current_window->buffer->input_buffer); -#endif - break; - case BUFFER_TYPE_DCC: - gui_exec_action_dcc (gui_current_window, key_str); - break; - case BUFFER_TYPE_RAW_DATA: - gui_exec_action_raw_data (gui_current_window, key_str); - break; - } - } - - i++; + ptr_start = NULL; + input_width--; } } /* - * gui_main_loop: main loop for WeeChat with ncurses GUI + * gui_input_draw: draw input window for a buffer */ void -gui_main_loop () +gui_input_draw (t_gui_buffer *buffer, int erase) { - fd_set read_fd; - static struct timeval timeout, tv; - static struct timezone tz; - t_irc_server *ptr_server; - t_gui_buffer *ptr_buffer; - int old_day, old_min, old_sec, diff; - char text_time[1024]; - time_t new_time; - struct tm *local_time; + t_gui_window *ptr_win; + char format[32]; + char *ptr_nickname; + int prompt_length, display_prompt; + t_irc_dcc *dcc_selected; - quit_weechat = 0; - - new_time = time (NULL); - gui_last_activity_time = new_time; - local_time = localtime (&new_time); - old_day = local_time->tm_mday; + if (!gui_ok) + return; - old_min = -1; - old_sec = -1; - check_away = 0; - while (!quit_weechat) + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { - new_time = time (NULL); - local_time = localtime (&new_time); - - /* minute has changed ? => redraw infobar */ - if (local_time->tm_min != old_min) + if (ptr_win->buffer == buffer) { - old_min = local_time->tm_min; - gui_draw_buffer_infobar (gui_current_window->buffer, 1); + if (erase) + gui_window_curses_clear (ptr_win->win_input, COLOR_WIN_INPUT); - if (cfg_look_day_change - && (local_time->tm_mday != old_day)) + switch (buffer->type) { - strftime (text_time, sizeof (text_time), - cfg_look_day_change_timestamp, local_time); - gui_add_hotlist = 0; - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->type == BUFFER_TYPE_STANDARD) - gui_printf_nolog_notime (ptr_buffer, - _("Day changed to %s\n"), - text_time); - } - gui_add_hotlist = 1; - } - old_day = local_time->tm_mday; - } - - /* second has changed ? */ - if (local_time->tm_sec != old_sec) - { - old_sec = local_time->tm_sec; - - if (cfg_look_infobar_seconds) - { - gui_draw_buffer_infobar_time (gui_current_window->buffer); - wmove (gui_current_window->win_input, - 0, gui_current_window->win_input_x); - wrefresh (gui_current_window->win_input); - } - - /* infobar count down */ - if (gui_infobar && gui_infobar->remaining_time > 0) - { - gui_infobar->remaining_time--; - if (gui_infobar->remaining_time == 0) - { - gui_infobar_remove (); - gui_draw_buffer_infobar (gui_current_window->buffer, 1); - } - } - - /* away check */ - if (cfg_irc_away_check != 0) - { - check_away++; - if (check_away >= (cfg_irc_away_check * 60)) - { - check_away = 0; - server_check_away (); - } - } - -#ifdef PLUGINS - /* call timer handlers */ - plugin_timer_handler_exec (); -#endif - } - - /* read keyboard */ - - FD_ZERO (&read_fd); - timeout.tv_sec = 0; - timeout.tv_usec = 8000; - - FD_SET (STDIN_FILENO, &read_fd); - - if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) - { - if (FD_ISSET (STDIN_FILENO, &read_fd)) - { - gui_input_read (); - } - } - - /* read sockets (servers, child process when connecting, FIFO pipe) */ - - FD_ZERO (&read_fd); - - timeout.tv_sec = 0; - timeout.tv_usec = 2000; - - if (weechat_fifo != -1) - FD_SET (weechat_fifo, &read_fd); - - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - /* check if reconnection is pending */ - if ((!ptr_server->is_connected) - && (ptr_server->reconnect_start > 0) - && (new_time >= (ptr_server->reconnect_start + ptr_server->autoreconnect_delay))) - server_reconnect (ptr_server); - else - { - if (ptr_server->is_connected) - { - /* check for lag */ - if ((ptr_server->lag_check_time.tv_sec == 0) - && (new_time >= ptr_server->lag_next_check)) + case BUFFER_TYPE_STANDARD: + if (buffer->has_input) { - server_sendf (ptr_server, "PING %s\r\n", ptr_server->address); - gettimeofday (&(ptr_server->lag_check_time), &tz); - } - - /* lag timeout => disconnect */ - if ((ptr_server->lag_check_time.tv_sec != 0) - && (cfg_irc_lag_disconnect > 0)) - { - gettimeofday (&tv, &tz); - diff = (int) get_timeval_diff (&(ptr_server->lag_check_time), &tv); - if (diff / 1000 > cfg_irc_lag_disconnect * 60) + if (buffer->input_buffer_length == 0) + buffer->input_buffer[0] = '\0'; + + if (SERVER(buffer)) + ptr_nickname = (SERVER(buffer)->nick) ? + SERVER(buffer)->nick : SERVER(buffer)->nick1; + else + ptr_nickname = cfg_look_no_nickname; + + prompt_length = gui_input_get_prompt_length (ptr_win, ptr_nickname); + + if (ptr_win->win_width - prompt_length < 3) { - irc_display_prefix (ptr_server, ptr_server->buffer, PREFIX_ERROR); - gui_printf (ptr_server->buffer, - _("%s lag is high, disconnecting from server...\n"), - WEECHAT_WARNING); - server_disconnect (ptr_server, 1); - continue; + prompt_length = 0; + display_prompt = 0; + } + else + display_prompt = 1; + + if (buffer->input_buffer_pos - buffer->input_buffer_1st_display + 1 > + ptr_win->win_width - prompt_length) + buffer->input_buffer_1st_display = buffer->input_buffer_pos - + (ptr_win->win_width - prompt_length) + 1; + else + { + if (buffer->input_buffer_pos < buffer->input_buffer_1st_display) + buffer->input_buffer_1st_display = buffer->input_buffer_pos; + else + { + if ((buffer->input_buffer_1st_display > 0) && + (buffer->input_buffer_pos - + buffer->input_buffer_1st_display + 1) + < ptr_win->win_width - prompt_length) + { + buffer->input_buffer_1st_display = + buffer->input_buffer_pos - + (ptr_win->win_width - prompt_length) + 1; + if (buffer->input_buffer_1st_display < 0) + buffer->input_buffer_1st_display = 0; + } + } + } + if (display_prompt) + gui_input_draw_prompt (ptr_win, ptr_nickname); + + gui_window_set_weechat_color (ptr_win->win_input, COLOR_WIN_INPUT); + snprintf (format, 32, "%%-%ds", ptr_win->win_width - prompt_length); + if (ptr_win == gui_current_window) + gui_input_draw_text (ptr_win, ptr_win->win_width - prompt_length); + else + wprintw (ptr_win->win_input, format, ""); + wclrtoeol (ptr_win->win_input); + ptr_win->win_input_x = prompt_length + + (buffer->input_buffer_pos - buffer->input_buffer_1st_display); + if (ptr_win == gui_current_window) + move (ptr_win->win_y + ptr_win->win_height - 1, + ptr_win->win_x + ptr_win->win_input_x); + } + break; + case BUFFER_TYPE_DCC: + dcc_selected = (ptr_win->dcc_selected) ? (t_irc_dcc *) ptr_win->dcc_selected : dcc_list; + wmove (ptr_win->win_input, 0, 0); + if (dcc_selected) + { + switch (dcc_selected->status) + { + case DCC_WAITING: + if (DCC_IS_RECV(dcc_selected->type)) + wprintw (ptr_win->win_input, _(" [A] Accept")); + wprintw (ptr_win->win_input, _(" [C] Cancel")); + break; + case DCC_CONNECTING: + case DCC_ACTIVE: + wprintw (ptr_win->win_input, _(" [C] Cancel")); + break; + case DCC_DONE: + case DCC_FAILED: + case DCC_ABORTED: + wprintw (ptr_win->win_input, _(" [R] Remove")); + break; } } - } - - if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) - FD_SET (ptr_server->child_read, &read_fd); - else - { - if (ptr_server->sock >= 0) - FD_SET (ptr_server->sock, &read_fd); - } + wprintw (ptr_win->win_input, _(" [P] Purge old DCC")); + wprintw (ptr_win->win_input, _(" [Q] Close DCC view")); + wclrtoeol (ptr_win->win_input); + ptr_win->win_input_x = 0; + if (ptr_win == gui_current_window) + move (ptr_win->win_y + ptr_win->win_height - 1, + ptr_win->win_x); + break; + case BUFFER_TYPE_RAW_DATA: + mvwprintw (ptr_win->win_input, 0, 0, _(" [Q] Close raw data view")); + wclrtoeol (ptr_win->win_input); + ptr_win->win_input_x = 0; + if (ptr_win == gui_current_window) + move (ptr_win->win_y + ptr_win->win_height - 1, + ptr_win->win_x); + break; } + doupdate (); + wrefresh (ptr_win->win_input); + refresh (); } - - if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) - { - if ((weechat_fifo != -1) && (FD_ISSET (weechat_fifo, &read_fd))) - { - fifo_read (); - } - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) - { - if (FD_ISSET (ptr_server->child_read, &read_fd)) - server_child_read (ptr_server); - } - else - { - if ((ptr_server->sock >= 0) && - (FD_ISSET (ptr_server->sock, &read_fd))) - server_recv (ptr_server); - } - } - } - - /* manages active DCC */ - dcc_handle (); } } diff --git a/weechat/src/gui/curses/gui-keyboard.c b/weechat/src/gui/curses/gui-keyboard.c new file mode 100644 index 000000000..25c4bedd6 --- /dev/null +++ b/weechat/src/gui/curses/gui-keyboard.c @@ -0,0 +1,324 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-keyboard.c: keyboard functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/utf8.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif + + +/* + * gui_keyboard__default_bindings: create default key bindings + */ + +void +gui_keyboard_default_bindings () +{ + int i; + char key_str[32], command[32]; + + /* keys binded with internal functions */ + gui_key_bind ( /* RC */ "ctrl-M", "return"); + gui_key_bind ( /* RC */ "ctrl-J", "return"); + gui_key_bind ( /* tab */ "ctrl-I", "tab"); + gui_key_bind ( /* basckp */ "ctrl-H", "backspace"); + gui_key_bind ( /* basckp */ "ctrl-?", "backspace"); + gui_key_bind ( /* del */ "meta2-3~", "delete"); + gui_key_bind ( /* ^K */ "ctrl-K", "delete_end_line"); + gui_key_bind ( /* ^U */ "ctrl-U", "delete_beginning_line"); + gui_key_bind ( /* ^W */ "ctrl-W", "delete_previous_word"); + gui_key_bind ( /* ^Y */ "ctrl-Y", "clipboard_paste"); + gui_key_bind ( /* ^T */ "ctrl-T", "transpose_chars"); + gui_key_bind ( /* home */ "meta2-1~", "home"); + gui_key_bind ( /* home */ "meta2-H", "home"); + gui_key_bind ( /* home */ "meta2-7~", "home"); + gui_key_bind ( /* ^A */ "ctrl-A", "home"); + gui_key_bind ( /* end */ "meta2-4~", "end"); + gui_key_bind ( /* end */ "meta2-F", "end"); + gui_key_bind ( /* end */ "meta2-8~", "end"); + gui_key_bind ( /* ^E */ "ctrl-E", "end"); + gui_key_bind ( /* left */ "meta2-D", "left"); + gui_key_bind ( /* right */ "meta2-C", "right"); + gui_key_bind ( /* up */ "meta2-A", "up"); + gui_key_bind ( /* ^up */ "meta-Oa", "up_global"); + gui_key_bind ( /* down */ "meta2-B", "down"); + gui_key_bind ( /* ^down */ "meta-Ob", "down_global"); + gui_key_bind ( /* pgup */ "meta2-5~", "page_up"); + gui_key_bind ( /* pgdn */ "meta2-6~", "page_down"); + gui_key_bind ( /* m-pgup */ "meta-meta2-5~", "scroll_up"); + gui_key_bind ( /* m-pgdn */ "meta-meta2-6~", "scroll_down"); + gui_key_bind ( /* m-home */ "meta-meta2-1~", "scroll_top"); + gui_key_bind ( /* m-end */ "meta-meta2-4~", "scroll_bottom"); + gui_key_bind ( /* F10 */ "meta2-21~", "infobar_clear"); + gui_key_bind ( /* F11 */ "meta2-23~", "nick_page_up"); + gui_key_bind ( /* F12 */ "meta2-24~", "nick_page_down"); + gui_key_bind ( /* m-F11 */ "meta-meta2-23~", "nick_beginning"); + gui_key_bind ( /* m-F12 */ "meta-meta2-24~", "nick_end"); + gui_key_bind ( /* ^L */ "ctrl-L", "refresh"); + gui_key_bind ( /* m-a */ "meta-a", "jump_smart"); + gui_key_bind ( /* m-b */ "meta-b", "previous_word"); + gui_key_bind ( /* ^left */ "meta-Od", "previous_word"); + gui_key_bind ( /* m-d */ "meta-d", "delete_next_word"); + gui_key_bind ( /* m-f */ "meta-f", "next_word"); + gui_key_bind ( /* ^right */ "meta-Oc", "next_word"); + gui_key_bind ( /* m-h */ "meta-h", "hotlist_clear"); + gui_key_bind ( /* m-j,m-d */ "meta-jmeta-d", "jump_dcc"); + gui_key_bind ( /* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer"); + gui_key_bind ( /* m-j,m-s */ "meta-jmeta-s", "jump_server"); + gui_key_bind ( /* m-j,m-x */ "meta-jmeta-x", "jump_next_server"); + gui_key_bind ( /* m-j,m-r */ "meta-jmeta-r", "jump_raw_data"); + gui_key_bind ( /* m-k */ "meta-k", "grab_key"); + gui_key_bind ( /* m-n */ "meta-n", "scroll_next_highlight"); + gui_key_bind ( /* m-p */ "meta-p", "scroll_previous_highlight"); + gui_key_bind ( /* m-r */ "meta-r", "delete_line"); + gui_key_bind ( /* m-s */ "meta-s", "switch_server"); + gui_key_bind ( /* m-u */ "meta-u", "scroll_unread"); + + /* keys binded with commands */ + gui_key_bind ( /* m-left */ "meta-meta2-D", "/buffer -1"); + gui_key_bind ( /* F5 */ "meta2-15~", "/buffer -1"); + gui_key_bind ( /* m-right */ "meta-meta2-C", "/buffer +1"); + gui_key_bind ( /* F6 */ "meta2-17~", "/buffer +1"); + gui_key_bind ( /* F7 */ "meta2-18~", "/window -1"); + gui_key_bind ( /* F8 */ "meta2-19~", "/window +1"); + gui_key_bind ( /* m-w,m-up */ "meta-wmeta-meta2-A", "/window up"); + gui_key_bind ( /* m-w,m-down */ "meta-wmeta-meta2-B", "/window down"); + gui_key_bind ( /* m-w,m-left */ "meta-wmeta-meta2-D", "/window left"); + gui_key_bind ( /* m-w,m-right */ "meta-wmeta-meta2-C", "/window right"); + gui_key_bind ( /* m-0 */ "meta-0", "/buffer 10"); + gui_key_bind ( /* m-1 */ "meta-1", "/buffer 1"); + gui_key_bind ( /* m-2 */ "meta-2", "/buffer 2"); + gui_key_bind ( /* m-3 */ "meta-3", "/buffer 3"); + gui_key_bind ( /* m-4 */ "meta-4", "/buffer 4"); + gui_key_bind ( /* m-5 */ "meta-5", "/buffer 5"); + gui_key_bind ( /* m-6 */ "meta-6", "/buffer 6"); + gui_key_bind ( /* m-7 */ "meta-7", "/buffer 7"); + gui_key_bind ( /* m-8 */ "meta-8", "/buffer 8"); + gui_key_bind ( /* m-9 */ "meta-9", "/buffer 9"); + + /* bind meta-j + {01..99} to switch to buffers # > 10 */ + for (i = 1; i < 100; i++) + { + sprintf (key_str, "meta-j%02d", i); + sprintf (command, "/buffer %d", i); + gui_key_bind (key_str, command); + } +} + +/* + * gui_keyboard_grab_end: insert grabbed key in input buffer + */ + +void +gui_keyboard_grab_end () +{ + char *expanded_key, *expanded_key2; + int length; + char *buffer_before_key; + + /* get expanded name (for example: ^U => ctrl-u) */ + expanded_key = gui_key_get_expanded_name (gui_key_buffer); + + if (expanded_key) + { + if (gui_current_window->buffer->has_input) + { + buffer_before_key = + (gui_current_window->buffer->input_buffer) ? + strdup (gui_current_window->buffer->input_buffer) : strdup (""); + gui_insert_string_input (gui_current_window, expanded_key, -1); + gui_current_window->buffer->input_buffer_pos += utf8_strlen (expanded_key); + gui_input_draw (gui_current_window->buffer, 1); + gui_current_window->buffer->completion.position = -1; +#ifdef PLUGINS + length = strlen (expanded_key) + 1 + 1; + expanded_key2 = (char *) malloc (length); + if (expanded_key2) + { + snprintf (expanded_key2, length, "*%s", expanded_key); + (void) plugin_keyboard_handler_exec (expanded_key2, + buffer_before_key, + gui_current_window->buffer->input_buffer); + free (expanded_key2); + } +#endif + if (buffer_before_key) + free (buffer_before_key); + } + free (expanded_key); + } + + /* end grab mode */ + gui_key_grab = 0; + gui_key_grab_count = 0; + gui_key_buffer[0] = '\0'; +} + +/* + * gui_keyboard_read: read keyboard chars + */ + +void +gui_keyboard_read () +{ + int key, i, insert_ok; + char key_str[32], key_str2[33]; + char *buffer_before_key; + + i = 0; + /* do not loop too much here (for example when big paste was made), + to read also socket & co */ + while (i < 8) + { + if (gui_key_grab && (gui_key_grab_count > 10)) + gui_keyboard_grab_end (); + + key = getch (); + insert_ok = 1; + + if (key == ERR) + { + if (gui_key_grab && (gui_key_grab_count > 0)) + gui_keyboard_grab_end (); + break; + } + + if (key == KEY_RESIZE) + { + gui_window_refresh_screen (); + continue; + } + + gui_last_activity_time = time (NULL); + + if (key < 32) + { + insert_ok = 0; + key_str[0] = '^'; + key_str[1] = (char) key + '@'; + key_str[2] = '\0'; + } + else if (key == 127) + { + key_str[0] = '^'; + key_str[1] = '?'; + key_str[2] = '\0'; + } + else + { + if (local_utf8) + { + /* 1 char: 0vvvvvvv */ + if (key < 0x80) + { + key_str[0] = (char) key; + key_str[1] = '\0'; + } + /* 2 chars: 110vvvvv 10vvvvvv */ + else if ((key & 0xE0) == 0xC0) + { + key_str[0] = (char) key; + key_str[1] = (char) (getch ()); + key_str[2] = '\0'; + } + /* 3 chars: 1110vvvv 10vvvvvv 10vvvvvv */ + else if ((key & 0xF0) == 0xE0) + { + key_str[0] = (char) key; + key_str[1] = (char) (getch ()); + key_str[2] = (char) (getch ()); + key_str[3] = '\0'; + } + /* 4 chars: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */ + else if ((key & 0xF8) == 0xF0) + { + key_str[0] = (char) key; + key_str[1] = (char) (getch ()); + key_str[2] = (char) (getch ()); + key_str[3] = (char) (getch ()); + key_str[4] = '\0'; + } + } + else + { + key_str[0] = (char) key; + key_str[1] = '\0'; + } + } + + if (strcmp (key_str, "^") == 0) + { + key_str[1] = '^'; + key_str[2] = '\0'; + } + + /*gui_printf (gui_current_window->buffer, "gui_input_read: key = %s (%d)\n", key_str, key);*/ + + if ((gui_key_pressed (key_str) != 0) && (insert_ok)) + { + if (strcmp (key_str, "^^") == 0) + key_str[1] = '\0'; + + switch (gui_current_window->buffer->type) + { + case BUFFER_TYPE_STANDARD: + buffer_before_key = + (gui_current_window->buffer->input_buffer) ? + strdup (gui_current_window->buffer->input_buffer) : strdup (""); + gui_insert_string_input (gui_current_window, key_str, -1); + gui_current_window->buffer->input_buffer_pos += utf8_strlen (key_str); + gui_input_draw (gui_current_window->buffer, 0); + gui_current_window->buffer->completion.position = -1; +#ifdef PLUGINS + snprintf (key_str2, sizeof (key_str2), "*%s", key_str); + (void) plugin_keyboard_handler_exec (key_str2, + buffer_before_key, + gui_current_window->buffer->input_buffer); +#endif + break; + case BUFFER_TYPE_DCC: + gui_exec_action_dcc (gui_current_window, key_str); + break; + case BUFFER_TYPE_RAW_DATA: + gui_exec_action_raw_data (gui_current_window, key_str); + break; + } + } + i++; + } +} diff --git a/weechat/src/gui/curses/gui-main.c b/weechat/src/gui/curses/gui-main.c new file mode 100644 index 000000000..0e8c61fd2 --- /dev/null +++ b/weechat/src/gui/curses/gui-main.c @@ -0,0 +1,355 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-main.c: main loop and keyboard management for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/fifo.h" +#include "../../common/utf8.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif + + +/* + * gui_main_loop: main loop for WeeChat with ncurses GUI + */ + +void +gui_main_loop () +{ + fd_set read_fd; + static struct timeval timeout, tv; + static struct timezone tz; + t_irc_server *ptr_server; + t_gui_buffer *ptr_buffer; + int old_day, old_min, old_sec, diff; + char text_time[1024]; + time_t new_time; + struct tm *local_time; + + quit_weechat = 0; + + new_time = time (NULL); + gui_last_activity_time = new_time; + local_time = localtime (&new_time); + old_day = local_time->tm_mday; + + old_min = -1; + old_sec = -1; + check_away = 0; + while (!quit_weechat) + { + new_time = time (NULL); + local_time = localtime (&new_time); + + /* minute has changed ? => redraw infobar */ + if (local_time->tm_min != old_min) + { + old_min = local_time->tm_min; + gui_infobar_draw (gui_current_window->buffer, 1); + + if (cfg_look_day_change + && (local_time->tm_mday != old_day)) + { + strftime (text_time, sizeof (text_time), + cfg_look_day_change_timestamp, local_time); + gui_add_hotlist = 0; + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->type == BUFFER_TYPE_STANDARD) + gui_printf_nolog_notime (ptr_buffer, + _("Day changed to %s\n"), + text_time); + } + gui_add_hotlist = 1; + } + old_day = local_time->tm_mday; + } + + /* second has changed ? */ + if (local_time->tm_sec != old_sec) + { + old_sec = local_time->tm_sec; + + if (cfg_look_infobar_seconds) + { + gui_infobar_draw_time (gui_current_window->buffer); + wmove (gui_current_window->win_input, + 0, gui_current_window->win_input_x); + wrefresh (gui_current_window->win_input); + } + + /* infobar count down */ + if (gui_infobar && gui_infobar->remaining_time > 0) + { + gui_infobar->remaining_time--; + if (gui_infobar->remaining_time == 0) + { + gui_infobar_remove (); + gui_infobar_draw (gui_current_window->buffer, 1); + } + } + + /* away check */ + if (cfg_irc_away_check != 0) + { + check_away++; + if (check_away >= (cfg_irc_away_check * 60)) + { + check_away = 0; + server_check_away (); + } + } + +#ifdef PLUGINS + /* call timer handlers */ + plugin_timer_handler_exec (); +#endif + } + + /* read keyboard */ + + FD_ZERO (&read_fd); + timeout.tv_sec = 0; + timeout.tv_usec = 8000; + + FD_SET (STDIN_FILENO, &read_fd); + + if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) + { + if (FD_ISSET (STDIN_FILENO, &read_fd)) + { + gui_keyboard_read (); + } + } + + /* read sockets (servers, child process when connecting, FIFO pipe) */ + + FD_ZERO (&read_fd); + + timeout.tv_sec = 0; + timeout.tv_usec = 2000; + + if (weechat_fifo != -1) + FD_SET (weechat_fifo, &read_fd); + + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + /* check if reconnection is pending */ + if ((!ptr_server->is_connected) + && (ptr_server->reconnect_start > 0) + && (new_time >= (ptr_server->reconnect_start + ptr_server->autoreconnect_delay))) + server_reconnect (ptr_server); + else + { + if (ptr_server->is_connected) + { + /* check for lag */ + if ((ptr_server->lag_check_time.tv_sec == 0) + && (new_time >= ptr_server->lag_next_check)) + { + server_sendf (ptr_server, "PING %s\r\n", ptr_server->address); + gettimeofday (&(ptr_server->lag_check_time), &tz); + } + + /* lag timeout => disconnect */ + if ((ptr_server->lag_check_time.tv_sec != 0) + && (cfg_irc_lag_disconnect > 0)) + { + gettimeofday (&tv, &tz); + diff = (int) get_timeval_diff (&(ptr_server->lag_check_time), &tv); + if (diff / 1000 > cfg_irc_lag_disconnect * 60) + { + irc_display_prefix (ptr_server, ptr_server->buffer, PREFIX_ERROR); + gui_printf (ptr_server->buffer, + _("%s lag is high, disconnecting from server...\n"), + WEECHAT_WARNING); + server_disconnect (ptr_server, 1); + continue; + } + } + } + + if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) + FD_SET (ptr_server->child_read, &read_fd); + else + { + if (ptr_server->sock >= 0) + FD_SET (ptr_server->sock, &read_fd); + } + } + } + + if (select (FD_SETSIZE, &read_fd, NULL, NULL, &timeout) > 0) + { + if ((weechat_fifo != -1) && (FD_ISSET (weechat_fifo, &read_fd))) + { + fifo_read (); + } + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (!ptr_server->is_connected && (ptr_server->child_pid > 0)) + { + if (FD_ISSET (ptr_server->child_read, &read_fd)) + server_child_read (ptr_server); + } + else + { + if ((ptr_server->sock >= 0) && + (FD_ISSET (ptr_server->sock, &read_fd))) + server_recv (ptr_server); + } + } + } + + /* manages active DCC */ + dcc_handle (); + } +} + +/* + * gui_main_pre_init: pre-initialize GUI (called before gui_init) + */ + +void +gui_main_pre_init (int *argc, char **argv[]) +{ + /* nothing for Curses interface */ + (void) argc; + (void) argv; +} + +/* + * gui_main_init: init GUI + */ + +void +gui_main_init () +{ + initscr (); + + curs_set (1); + noecho (); + nodelay (stdscr, TRUE); + + gui_color_init (); + + gui_infobar = NULL; + + gui_ok = ((COLS > 5) && (LINES > 5)); + + refresh (); + + /* init clipboard buffer */ + gui_input_clipboard = NULL; + + /* create new window/buffer */ + if (gui_window_new (NULL, 0, 0, COLS, LINES, 100, 100)) + { + gui_current_window = gui_windows; + gui_buffer_new (gui_windows, NULL, NULL, BUFFER_TYPE_STANDARD, 1); + + signal (SIGWINCH, gui_window_refresh_screen_sigwinch); + + if (cfg_look_set_title) + gui_window_set_title (); + + gui_init_ok = 1; + } +} + +/* + * gui_main_end: GUI end + */ + +void +gui_main_end () +{ + t_gui_window *ptr_win; + + /* free clipboard buffer */ + if (gui_input_clipboard) + free(gui_input_clipboard); + + /* delete all windows */ + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->win_title) + delwin (ptr_win->win_title); + if (ptr_win->win_chat) + delwin (ptr_win->win_chat); + if (ptr_win->win_nick) + delwin (ptr_win->win_nick); + if (ptr_win->win_status) + delwin (ptr_win->win_status); + if (ptr_win->win_infobar) + delwin (ptr_win->win_infobar); + if (ptr_win->win_input) + delwin (ptr_win->win_input); + } + + /* delete all buffers */ + while (gui_buffers) + gui_buffer_free (gui_buffers, 0); + + /* delete all windows */ + while (gui_windows) + gui_window_free (gui_windows); + gui_window_tree_free (&gui_windows_tree); + + /* delete global history */ + history_global_free (); + + /* delete infobar messages */ + while (gui_infobar) + gui_infobar_remove (); + + /* reset title */ + if (cfg_look_set_title) + gui_window_reset_title (); + + /* end of curses output */ + refresh (); + endwin (); +} diff --git a/weechat/src/gui/curses/gui-nicklist.c b/weechat/src/gui/curses/gui-nicklist.c new file mode 100644 index 000000000..2022df25c --- /dev/null +++ b/weechat/src/gui/curses/gui-nicklist.c @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-nicklist.c: nicklist display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/weeconfig.h" +#include "../../irc/irc.h" +#include "gui-curses.h" + + +/* + * gui_nicklist_draw: draw nick window for a buffer + */ + +void +gui_nicklist_draw (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + int i, j, x, y, x2, column, max_length, nicks_displayed; + char format[32], format_empty[32]; + t_irc_nick *ptr_nick; + + if (!gui_ok || !BUFFER_HAS_NICKLIST(buffer)) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if ((ptr_win->buffer == buffer) && (buffer->num_displayed > 0)) + { + max_length = nick_get_max_length (CHANNEL(buffer)); + + if (gui_window_calculate_pos_size (ptr_win, 0)) + { + delwin (ptr_win->win_chat); + delwin (ptr_win->win_nick); + ptr_win->win_chat = newwin (ptr_win->win_chat_height, + ptr_win->win_chat_width, + ptr_win->win_chat_y, + ptr_win->win_chat_x); + ptr_win->win_nick = newwin (ptr_win->win_nick_height, + ptr_win->win_nick_width, + ptr_win->win_nick_y, + ptr_win->win_nick_x); + gui_chat_draw (buffer, 1); + erase = 1; + } + + if (erase) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK); + + snprintf (format_empty, 32, "%%-%ds", ptr_win->win_nick_width); + for (i = 0; i < ptr_win->win_nick_height; i++) + { + mvwprintw (ptr_win->win_nick, i, 0, format_empty, " "); + } + } + + if ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_TOP) || + (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM)) + snprintf (format, 32, "%%.%ds", max_length); + else + snprintf (format, 32, "%%.%ds", + ((cfg_look_nicklist_min_size > 0) + && (max_length < cfg_look_nicklist_min_size)) ? + cfg_look_nicklist_min_size : + (((cfg_look_nicklist_max_size > 0) + && (max_length > cfg_look_nicklist_max_size)) ? + cfg_look_nicklist_max_size : max_length)); + + if (has_colors ()) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_SEP); + switch (cfg_look_nicklist_position) + { + case CFG_LOOK_NICKLIST_LEFT: + mvwvline (ptr_win->win_nick, + 0, ptr_win->win_nick_width - 1, ACS_VLINE, + ptr_win->win_chat_height); + break; + case CFG_LOOK_NICKLIST_RIGHT: + mvwvline (ptr_win->win_nick, + 0, 0, ACS_VLINE, + ptr_win->win_chat_height); + break; + case CFG_LOOK_NICKLIST_TOP: + mvwhline (ptr_win->win_nick, + ptr_win->win_nick_height - 1, 0, ACS_HLINE, + ptr_win->win_chat_width); + break; + case CFG_LOOK_NICKLIST_BOTTOM: + mvwhline (ptr_win->win_nick, + 0, 0, ACS_HLINE, + ptr_win->win_chat_width); + break; + } + } + + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK); + x = 0; + y = (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM) ? 1 : 0; + column = 0; + + if ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_TOP) || + (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM)) + nicks_displayed = (ptr_win->win_width / (max_length + 2)) * (ptr_win->win_nick_height - 1); + else + nicks_displayed = ptr_win->win_nick_height; + + ptr_nick = CHANNEL(buffer)->nicks; + for (i = 0; i < ptr_win->win_nick_start; i++) + { + if (!ptr_nick) + break; + ptr_nick = ptr_nick->next_nick; + } + if (ptr_nick) + { + for (i = 0; i < nicks_displayed; i++) + { + switch (cfg_look_nicklist_position) + { + case CFG_LOOK_NICKLIST_LEFT: + x = 0; + break; + case CFG_LOOK_NICKLIST_RIGHT: + x = 1; + break; + case CFG_LOOK_NICKLIST_TOP: + case CFG_LOOK_NICKLIST_BOTTOM: + x = column; + break; + } + if ( ((i == 0) && (ptr_win->win_nick_start > 0)) + || ((i == nicks_displayed - 1) && (ptr_nick->next_nick)) ) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_MORE); + j = (max_length + 1) >= 4 ? 4 : max_length + 1; + for (x2 = 1; x2 <= j; x2++) + mvwprintw (ptr_win->win_nick, y, x + x2, "+"); + } + else + { + if (ptr_nick->flags & NICK_CHANOWNER) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_CHANOWNER); + mvwprintw (ptr_win->win_nick, y, x, "~"); + x++; + } + else if (ptr_nick->flags & NICK_CHANADMIN) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_CHANADMIN); + mvwprintw (ptr_win->win_nick, y, x, "&"); + x++; + } + else if (ptr_nick->flags & NICK_OP) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_OP); + mvwprintw (ptr_win->win_nick, y, x, "@"); + x++; + } + else if (ptr_nick->flags & NICK_HALFOP) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_HALFOP); + mvwprintw (ptr_win->win_nick, y, x, "%%"); + x++; + } + else if (ptr_nick->flags & NICK_VOICE) + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK_VOICE); + mvwprintw (ptr_win->win_nick, y, x, "+"); + x++; + } + else + { + gui_window_set_weechat_color (ptr_win->win_nick, COLOR_WIN_NICK); + mvwprintw (ptr_win->win_nick, y, x, " "); + x++; + } + gui_window_set_weechat_color (ptr_win->win_nick, + ((cfg_irc_away_check > 0) && (ptr_nick->flags & NICK_AWAY)) ? + COLOR_WIN_NICK_AWAY : COLOR_WIN_NICK); + mvwprintw (ptr_win->win_nick, y, x, format, ptr_nick->nick); + + ptr_nick = ptr_nick->next_nick; + + if (!ptr_nick) + break; + } + y++; + if ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_TOP) || + (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM)) + { + if (y - ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_BOTTOM) ? 1 : 0) >= ptr_win->win_nick_height - 1) + { + column += max_length + 2; + y = (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_TOP) ? + 0 : 1; + } + } + } + } + wnoutrefresh (ptr_win->win_nick); + refresh (); + } + } +} diff --git a/weechat/src/gui/curses/gui-status.c b/weechat/src/gui/curses/gui-status.c new file mode 100644 index 000000000..5da5bb6ec --- /dev/null +++ b/weechat/src/gui/curses/gui-status.c @@ -0,0 +1,402 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-status.c: status display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + + +/* + * gui_status_draw: draw status window for a buffer + */ + +void +gui_status_draw (t_gui_buffer *buffer, int erase) +{ + t_gui_window *ptr_win; + t_weechat_hotlist *ptr_hotlist; + char format[32], str_nicks[32], *more; + int i, first_mode, x, server_pos, server_total; + int display_name, names_count; + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (erase) + gui_window_curses_clear (ptr_win->win_status, COLOR_WIN_STATUS); + + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + + /* display number of buffers */ + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + mvwprintw (ptr_win->win_status, 0, 0, "["); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", + (last_gui_buffer) ? last_gui_buffer->number : 0); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "] "); + + /* display "" or current server */ + if (ptr_win->buffer->all_servers) + { + wprintw (ptr_win->win_status, "["); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, _("")); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "] "); + } + else if (SERVER(ptr_win->buffer) && SERVER(ptr_win->buffer)->name) + { + wprintw (ptr_win->win_status, "["); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%s", SERVER(ptr_win->buffer)->name); + if (SERVER(ptr_win->buffer)->is_away) + wprintw (ptr_win->win_status, _("(away)")); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "] "); + } + + /* infos about current server buffer */ + if (SERVER(ptr_win->buffer) && !CHANNEL(ptr_win->buffer)) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", + ptr_win->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_CHANNEL); + if (SERVER(ptr_win->buffer)->is_connected) + wprintw (ptr_win->win_status, "[%s] ", + SERVER(ptr_win->buffer)->name); + else + wprintw (ptr_win->win_status, "(%s) ", + SERVER(ptr_win->buffer)->name); + if (ptr_win->buffer->all_servers) + { + server_get_number_buffer (SERVER(ptr_win->buffer), + &server_pos, + &server_total); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "("); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", server_pos); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "/"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", server_total); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ") "); + + } + } + + /* infos about current channel/pv buffer */ + if (SERVER(ptr_win->buffer) && CHANNEL(ptr_win->buffer)) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", + ptr_win->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_CHANNEL); + if (((CHANNEL(ptr_win->buffer)->type != CHANNEL_TYPE_PRIVATE) + && (CHANNEL(ptr_win->buffer)->type != CHANNEL_TYPE_DCC_CHAT) + && (!CHANNEL(ptr_win->buffer)->nicks)) + || ((CHANNEL(ptr_win->buffer)->type == CHANNEL_TYPE_DCC_CHAT) + && (CHANNEL(ptr_win->buffer)->dcc_chat) + && (((t_irc_dcc *)(CHANNEL(ptr_win->buffer)->dcc_chat))->sock < 0))) + wprintw (ptr_win->win_status, "(%s)", + CHANNEL(ptr_win->buffer)->name); + else + wprintw (ptr_win->win_status, "%s", + CHANNEL(ptr_win->buffer)->name); + if (ptr_win->buffer == CHANNEL(ptr_win->buffer)->buffer) + { + /* display channel modes */ + if (CHANNEL(ptr_win->buffer)->type == CHANNEL_TYPE_CHANNEL) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "("); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + i = 0; + first_mode = 1; + while (CHANNEL(ptr_win->buffer)->modes[i]) + { + if (CHANNEL(ptr_win->buffer)->modes[i] != ' ') + { + if (first_mode) + { + wprintw (ptr_win->win_status, "+"); + first_mode = 0; + } + wprintw (ptr_win->win_status, "%c", + CHANNEL(ptr_win->buffer)->modes[i]); + } + i++; + } + if (CHANNEL(ptr_win->buffer)->modes[CHANNEL_MODE_KEY] != ' ') + wprintw (ptr_win->win_status, ",%s", + CHANNEL(ptr_win->buffer)->key); + if (CHANNEL(ptr_win->buffer)->modes[CHANNEL_MODE_LIMIT] != ' ') + wprintw (ptr_win->win_status, ",%d", + CHANNEL(ptr_win->buffer)->limit); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ")"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + } + + /* display DCC if private is DCC CHAT */ + if (CHANNEL(ptr_win->buffer)->type == CHANNEL_TYPE_DCC_CHAT) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "("); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_CHANNEL); + wprintw (ptr_win->win_status, "DCC"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ")"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + } + } + wprintw (ptr_win->win_status, " "); + } + if (!SERVER(ptr_win->buffer)) + { + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%d", + ptr_win->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS_CHANNEL); + switch (ptr_win->buffer->type) + { + case BUFFER_TYPE_STANDARD: + wprintw (ptr_win->win_status, _("[not connected] ")); + break; + case BUFFER_TYPE_DCC: + wprintw (ptr_win->win_status, " "); + break; + case BUFFER_TYPE_RAW_DATA: + wprintw (ptr_win->win_status, _(" ")); + break; + } + } + + /* display list of other active windows (if any) with numbers */ + if (hotlist) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "["); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, _("Act: ")); + + names_count = 0; + for (ptr_hotlist = hotlist; ptr_hotlist; + ptr_hotlist = ptr_hotlist->next_hotlist) + { + switch (ptr_hotlist->priority) + { + case HOTLIST_LOW: + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DATA_OTHER); + display_name = ((cfg_look_hotlist_names_level & 1) != 0); + break; + case HOTLIST_MSG: + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DATA_MSG); + display_name = ((cfg_look_hotlist_names_level & 2) != 0); + break; + case HOTLIST_PRIVATE: + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DATA_PRIVATE); + display_name = ((cfg_look_hotlist_names_level & 4) != 0); + break; + case HOTLIST_HIGHLIGHT: + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DATA_HIGHLIGHT); + display_name = ((cfg_look_hotlist_names_level & 8) != 0); + break; + default: + display_name = 0; + break; + } + switch (ptr_hotlist->buffer->type) + { + case BUFFER_TYPE_STANDARD: + wprintw (ptr_win->win_status, "%d", + ptr_hotlist->buffer->number); + + if (display_name && (cfg_look_hotlist_names_count != 0) + && (names_count < cfg_look_hotlist_names_count)) + { + names_count++; + + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + if (cfg_look_hotlist_names_length == 0) + snprintf (format, sizeof (format) - 1, "%%s"); + else + snprintf (format, sizeof (format) - 1, "%%.%ds", cfg_look_hotlist_names_length); + if (BUFFER_IS_SERVER(ptr_hotlist->buffer)) + wprintw (ptr_win->win_status, format, + (ptr_hotlist->server) ? + ptr_hotlist->server->name : + SERVER(ptr_hotlist->buffer)->name); + else if (BUFFER_IS_CHANNEL(ptr_hotlist->buffer) + || BUFFER_IS_PRIVATE(ptr_hotlist->buffer)) + wprintw (ptr_win->win_status, format, CHANNEL(ptr_hotlist->buffer)->name); + } + break; + case BUFFER_TYPE_DCC: + wprintw (ptr_win->win_status, "%d", + ptr_hotlist->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "DCC"); + break; + case BUFFER_TYPE_RAW_DATA: + wprintw (ptr_win->win_status, "%d", + ptr_hotlist->buffer->number); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, ":"); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, _("RAW_IRC")); + break; + } + + if (ptr_hotlist->next_hotlist) + wprintw (ptr_win->win_status, ","); + } + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "] "); + } + + /* display lag */ + if (SERVER(ptr_win->buffer)) + { + if (SERVER(ptr_win->buffer)->lag / 1000 >= cfg_irc_lag_min_show) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "["); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, _("Lag: %.1f"), + ((float)(SERVER(ptr_win->buffer)->lag)) / 1000); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "]"); + } + } + + /* display "-MORE-" (if last line is not displayed) & nicks count */ + if (BUFFER_HAS_NICKLIST(ptr_win->buffer)) + { + snprintf (str_nicks, sizeof (str_nicks) - 1, "%d", CHANNEL(ptr_win->buffer)->nicks_count); + x = ptr_win->win_width - strlen (str_nicks) - 4; + } + else + x = ptr_win->win_width - 2; + more = strdup (_("-MORE-")); + x -= strlen (more) - 1; + if (x < 0) + x = 0; + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS_MORE); + if (ptr_win->scroll) + mvwprintw (ptr_win->win_status, 0, x, "%s", more); + else + { + snprintf (format, sizeof (format) - 1, "%%-%ds", (int)(strlen (more))); + mvwprintw (ptr_win->win_status, 0, x, format, " "); + } + if (BUFFER_HAS_NICKLIST(ptr_win->buffer)) + { + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, " ["); + gui_window_set_weechat_color (ptr_win->win_status, COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "%s", str_nicks); + gui_window_set_weechat_color (ptr_win->win_status, + COLOR_WIN_STATUS_DELIMITERS); + wprintw (ptr_win->win_status, "]"); + } + free (more); + + wnoutrefresh (ptr_win->win_status); + refresh (); + } +} diff --git a/weechat/src/gui/curses/gui-window.c b/weechat/src/gui/curses/gui-window.c new file mode 100644 index 000000000..8cb067234 --- /dev/null +++ b/weechat/src/gui/curses/gui-window.c @@ -0,0 +1,1175 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-window.c: window display functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#ifdef HAVE_NCURSESW_CURSES_H +#include +#else +#include +#endif + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-curses.h" + + +/* + * gui_window_curses_clear: clear a Curses window + */ + +void +gui_window_curses_clear (WINDOW *window, int num_color) +{ + if (!gui_ok) + return; + + wbkgdset(window, ' ' | COLOR_PAIR (gui_color_get_pair (num_color))); + werase (window); + wmove (window, 0, 0); +} + +/* + * gui_window_set_weechat_color: set WeeChat color for window + */ + +void +gui_window_set_weechat_color (WINDOW *window, int num_color) +{ + if ((num_color >= 0) && (num_color <= GUI_NUM_COLORS - 1)) + { + wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE); + wattron (window, COLOR_PAIR(gui_color_get_pair (num_color)) | + gui_color[num_color]->attributes); + } +} + +/* + * gui_window_calculate_pos_size: calculate position and size for a buffer & subwindows + * return 1 if pos/size changed, 0 if no change + */ + +int +gui_window_calculate_pos_size (t_gui_window *window, int force_calculate) +{ + int max_length, max_height, lines; + int num_nicks, num_op, num_halfop, num_voice, num_normal; + + if (!gui_ok) + return 0; + + /* init chat & nicklist settings */ + if (cfg_look_nicklist && BUFFER_IS_CHANNEL(window->buffer)) + { + max_length = nick_get_max_length (CHANNEL(window->buffer)); + + lines = 0; + + if ((cfg_look_nicklist_position == CFG_LOOK_NICKLIST_LEFT) || + (cfg_look_nicklist_position == CFG_LOOK_NICKLIST_RIGHT)) + { + if ((cfg_look_nicklist_min_size > 0) + && (max_length < cfg_look_nicklist_min_size)) + max_length = cfg_look_nicklist_min_size; + else if ((cfg_look_nicklist_max_size > 0) + && (max_length > cfg_look_nicklist_max_size)) + max_length = cfg_look_nicklist_max_size; + if (!force_calculate && (window->win_nick_width == max_length + 2)) + return 0; + } + else + { + nick_count (CHANNEL(window->buffer), &num_nicks, &num_op, + &num_halfop, &num_voice, &num_normal); + if (((max_length + 2) * num_nicks) % window->win_width == 0) + lines = ((max_length + 2) * num_nicks) / window->win_width; + else + lines = (((max_length + 2) * num_nicks) / window->win_width) + 1; + if ((cfg_look_nicklist_max_size > 0) && (lines > cfg_look_nicklist_max_size)) + lines = cfg_look_nicklist_max_size; + if ((cfg_look_nicklist_min_size > 0) && (lines < cfg_look_nicklist_min_size)) + lines = cfg_look_nicklist_min_size; + max_height = (cfg_look_infobar) ? + window->win_height - 3 - 4 : window->win_height - 2 - 4; + if (lines > max_height) + lines = max_height; + if (!force_calculate && (window->win_nick_height == lines + 1)) + return 0; + } + + switch (cfg_look_nicklist_position) + { + case CFG_LOOK_NICKLIST_LEFT: + window->win_chat_x = window->win_x + max_length + 2; + window->win_chat_y = window->win_y + 1; + window->win_chat_width = window->win_width - max_length - 2; + window->win_nick_x = window->win_x + 0; + window->win_nick_y = window->win_y + 1; + window->win_nick_width = max_length + 2; + if (cfg_look_infobar) + { + window->win_chat_height = window->win_height - 4; + window->win_nick_height = window->win_height - 4; + } + else + { + window->win_chat_height = window->win_height - 3; + window->win_nick_height = window->win_height - 3; + } + window->win_nick_num_max = window->win_nick_height; + break; + case CFG_LOOK_NICKLIST_RIGHT: + window->win_chat_x = window->win_x; + window->win_chat_y = window->win_y + 1; + window->win_chat_width = window->win_width - max_length - 2; + window->win_nick_x = window->win_x + window->win_width - max_length - 2; + window->win_nick_y = window->win_y + 1; + window->win_nick_width = max_length + 2; + if (cfg_look_infobar) + { + window->win_chat_height = window->win_height - 4; + window->win_nick_height = window->win_height - 4; + } + else + { + window->win_chat_height = window->win_height - 3; + window->win_nick_height = window->win_height - 3; + } + window->win_nick_num_max = window->win_nick_height; + break; + case CFG_LOOK_NICKLIST_TOP: + window->win_chat_x = window->win_x; + window->win_chat_y = window->win_y + 1 + (lines + 1); + window->win_chat_width = window->win_width; + if (cfg_look_infobar) + window->win_chat_height = window->win_height - 3 - (lines + 1) - 1; + else + window->win_chat_height = window->win_height - 3 - (lines + 1); + window->win_nick_x = window->win_x; + window->win_nick_y = window->win_y + 1; + window->win_nick_width = window->win_width; + window->win_nick_height = lines + 1; + window->win_nick_num_max = lines * (window->win_nick_width / (max_length + 2)); + break; + case CFG_LOOK_NICKLIST_BOTTOM: + window->win_chat_x = window->win_x; + window->win_chat_y = window->win_y + 1; + window->win_chat_width = window->win_width; + if (cfg_look_infobar) + window->win_chat_height = window->win_height - 3 - (lines + 1) - 1; + else + window->win_chat_height = window->win_height - 3 - (lines + 1); + window->win_nick_x = window->win_x; + if (cfg_look_infobar) + window->win_nick_y = window->win_y + window->win_height - 2 - (lines + 1) - 1; + else + window->win_nick_y = window->win_y + window->win_height - 2 - (lines + 1); + window->win_nick_width = window->win_width; + window->win_nick_height = lines + 1; + window->win_nick_num_max = lines * (window->win_nick_width / (max_length + 2)); + break; + } + + window->win_chat_cursor_x = window->win_x; + window->win_chat_cursor_y = window->win_y; + } + else + { + window->win_chat_x = window->win_x; + window->win_chat_y = window->win_y + 1; + window->win_chat_width = window->win_width; + if (cfg_look_infobar) + window->win_chat_height = window->win_height - 4; + else + window->win_chat_height = window->win_height - 3; + window->win_chat_cursor_x = window->win_x; + window->win_chat_cursor_y = window->win_y; + window->win_nick_x = -1; + window->win_nick_y = -1; + window->win_nick_width = -1; + window->win_nick_height = -1; + window->win_nick_num_max = -1; + } + + return 1; +} + +/* + * gui_window_draw_separator: draw window separation + */ + +void +gui_window_draw_separator (t_gui_window *window) +{ + if (window->win_separator) + delwin (window->win_separator); + + if (window->win_x > 0) + { + window->win_separator = newwin (window->win_height, + 1, + window->win_y, + window->win_x - 1); + gui_window_set_weechat_color (window->win_separator, COLOR_WIN_SEPARATOR); + wborder (window->win_separator, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + wnoutrefresh (window->win_separator); + refresh (); + } +} + +/* + * gui_window_redraw_buffer: redraw a buffer + */ + +void +gui_window_redraw_buffer (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + gui_chat_draw_title (buffer, 1); + gui_chat_draw (buffer, 1); + if (ptr_win->win_nick) + gui_nicklist_draw (buffer, 1); + gui_status_draw (buffer, 1); + if (cfg_look_infobar) + gui_infobar_draw (buffer, 1); + gui_input_draw (buffer, 1); + } + } +} + +/* + * gui_window_switch_to_buffer: switch to another buffer + */ + +void +gui_window_switch_to_buffer (t_gui_window *window, t_gui_buffer *buffer) +{ + if (!gui_ok) + return; + + if (window->buffer->num_displayed > 0) + window->buffer->num_displayed--; + + if (window->buffer != buffer) + { + window->buffer->last_read_line = window->buffer->last_line; + if (buffer->last_read_line == buffer->last_line) + buffer->last_read_line = NULL; + } + + window->buffer = buffer; + window->win_nick_start = 0; + gui_window_calculate_pos_size (window, 1); + + /* destroy Curses windows */ + if (window->win_title) + { + delwin (window->win_title); + window->win_title = NULL; + } + if (window->win_nick) + { + delwin (window->win_nick); + window->win_nick = NULL; + } + if (window->win_status) + { + delwin (window->win_status); + window->win_status = NULL; + } + if (window->win_infobar) + { + delwin (window->win_infobar); + window->win_infobar = NULL; + } + if (window->win_input) + { + delwin (window->win_input); + window->win_input = NULL; + } + + /* create Curses windows */ + window->win_title = newwin (1, + window->win_width, + window->win_y, + window->win_x); + window->win_input = newwin (1, + window->win_width, + window->win_y + window->win_height - 1, + window->win_x); + if (BUFFER_IS_CHANNEL(buffer)) + { + if (window->win_chat) + delwin (window->win_chat); + window->win_chat = newwin (window->win_chat_height, + window->win_chat_width, + window->win_chat_y, + window->win_chat_x); + if (cfg_look_nicklist) + window->win_nick = newwin (window->win_nick_height, + window->win_nick_width, + window->win_nick_y, + window->win_nick_x); + else + window->win_nick = NULL; + } + if (!(BUFFER_IS_CHANNEL(buffer))) + { + if (window->win_chat) + delwin (window->win_chat); + window->win_chat = newwin (window->win_chat_height, + window->win_chat_width, + window->win_chat_y, + window->win_chat_x); + } + + /* create status/infobar windows */ + if (cfg_look_infobar) + { + window->win_infobar = newwin (1, window->win_width, + window->win_y + window->win_height - 2, + window->win_x); + window->win_status = newwin (1, window->win_width, + window->win_y + window->win_height - 3, + window->win_x); + } + else + window->win_status = newwin (1, window->win_width, + window->win_y + window->win_height - 2, + window->win_x); + + window->start_line = NULL; + window->start_line_pos = 0; + + buffer->num_displayed++; + + hotlist_remove_buffer (buffer); +} + +/* + * gui_window_page_up: display previous page on buffer + */ + +void +gui_window_page_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * (window->win_chat_height - 1) : + (-1) * ((window->win_chat_height - 1) * 2)); + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_page_down: display next page on buffer + */ + +void +gui_window_page_down (t_gui_window *window) +{ + t_gui_line *ptr_line; + int line_pos; + + if (!gui_ok) + return; + + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + window->win_chat_height - 1); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_up: display previous few lines in buffer + */ + +void +gui_window_scroll_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * cfg_look_scroll_amount : + (-1) * ( (window->win_chat_height - 1) + cfg_look_scroll_amount)); + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_down: display next few lines in buffer + */ + +void +gui_window_scroll_down (t_gui_window *window) +{ + t_gui_line *ptr_line; + int line_pos; + + if (!gui_ok) + return; + + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + cfg_look_scroll_amount); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_top: scroll to top of buffer + */ + +void +gui_window_scroll_top (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + window->start_line = window->buffer->lines; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_bottom: scroll to bottom of buffer + */ + +void +gui_window_scroll_bottom (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (window->start_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_nick_beginning: go to beginning of nicklist + */ + +void +gui_window_nick_beginning (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if (window->win_nick_start > 0) + { + window->win_nick_start = 0; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_end: go to the end of nicklist + */ + +void +gui_window_nick_end (t_gui_window *window) +{ + int new_start; + + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + new_start = + CHANNEL(window->buffer)->nicks_count - window->win_nick_num_max; + if (new_start < 0) + new_start = 0; + else if (new_start >= 1) + new_start++; + + if (new_start != window->win_nick_start) + { + window->win_nick_start = new_start; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_page_up: scroll one page up in nicklist + */ + +void +gui_window_nick_page_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if (window->win_nick_start > 0) + { + window->win_nick_start -= (window->win_nick_num_max - 1); + if (window->win_nick_start <= 1) + window->win_nick_start = 0; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_page_down: scroll one page down in nicklist + */ + +void +gui_window_nick_page_down (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if ((CHANNEL(window->buffer)->nicks_count > window->win_nick_num_max) + && (window->win_nick_start + window->win_nick_num_max - 1 + < CHANNEL(window->buffer)->nicks_count)) + { + if (window->win_nick_start == 0) + window->win_nick_start += (window->win_nick_num_max - 1); + else + window->win_nick_start += (window->win_nick_num_max - 2); + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_init_subwindows: init subviews for a WeeChat window + */ + +void +gui_window_init_subwindows (t_gui_window *window) +{ + window->win_title = NULL; + window->win_chat = NULL; + window->win_nick = NULL; + window->win_status = NULL; + window->win_infobar = NULL; + window->win_input = NULL; +} + +/* + * gui_window_auto_resize: auto-resize all windows, according to % of global size + * This function is called after a terminal resize. + * Returns 0 if ok, -1 if all window should be merged + * (not enough space according to windows %) + */ + +int +gui_window_auto_resize (t_gui_window_tree *tree, + int x, int y, int width, int height, + int simulate) +{ + int size1, size2; + + if (tree) + { + if (tree->window) + { + if ((width < WINDOW_MIN_WIDTH) || (height < WINDOW_MIN_HEIGHT)) + return -1; + if (!simulate) + { + tree->window->win_x = x; + tree->window->win_y = y; + tree->window->win_width = width; + tree->window->win_height = height; + } + } + else + { + if (tree->split_horiz) + { + size1 = (height * tree->split_pct) / 100; + size2 = height - size1; + if (gui_window_auto_resize (tree->child1, x, y + size1, + width, size2, simulate) < 0) + return -1; + if (gui_window_auto_resize (tree->child2, x, y, + width, size1, simulate) < 0) + return -1; + } + else + { + size1 = (width * tree->split_pct) / 100; + size2 = width - size1 - 1; + if (gui_window_auto_resize (tree->child1, x, y, + size1, height, simulate) < 0) + return -1; + if (gui_window_auto_resize (tree->child2, x + size1 + 1, y, + size2, height, simulate) < 0) + return -1; + } + } + } + return 0; +} + +/* + * gui_window_refresh_windows: auto resize and refresh all windows + */ + +void +gui_window_refresh_windows () +{ + t_gui_window *ptr_win, *old_current_window; + + if (gui_ok) + { + old_current_window = gui_current_window; + + if (gui_window_auto_resize (gui_windows_tree, 0, 0, COLS, LINES, 0) < 0) + gui_window_merge_all (gui_current_window); + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + gui_window_switch_to_buffer (ptr_win, ptr_win->buffer); + gui_window_redraw_buffer (ptr_win->buffer); + gui_window_draw_separator (ptr_win); + } + + gui_current_window = old_current_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + } +} + +/* + * gui_window_split_horiz: split a window horizontally + */ + +void +gui_window_split_horiz (t_gui_window *window, int pourcentage) +{ + t_gui_window *new_window; + int height1, height2; + + if (!gui_ok) + return; + + height1 = (window->win_height * pourcentage) / 100; + height2 = window->win_height - height1; + + if ((height1 >= WINDOW_MIN_HEIGHT) && (height2 >= WINDOW_MIN_HEIGHT) + && (pourcentage > 0) && (pourcentage <= 100)) + { + if ((new_window = gui_window_new (window, + window->win_x, window->win_y, + window->win_width, height1, + 100, pourcentage))) + { + /* reduce old window height (bottom window) */ + window->win_y = new_window->win_y + new_window->win_height; + window->win_height = height2; + window->win_height_pct = 100 - pourcentage; + + /* assign same buffer for new window (top window) */ + new_window->buffer = window->buffer; + new_window->buffer->num_displayed++; + + gui_window_switch_to_buffer (window, window->buffer); + + gui_current_window = new_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + } + } +} + +/* + * gui_window_split_vertic: split a window vertically + */ + +void +gui_window_split_vertic (t_gui_window *window, int pourcentage) +{ + t_gui_window *new_window; + int width1, width2; + + if (!gui_ok) + return; + + width1 = (window->win_width * pourcentage) / 100; + width2 = window->win_width - width1 - 1; + + if ((width1 >= WINDOW_MIN_WIDTH) && (width2 >= WINDOW_MIN_WIDTH) + && (pourcentage > 0) && (pourcentage <= 100)) + { + if ((new_window = gui_window_new (window, + window->win_x + width1 + 1, window->win_y, + width2, window->win_height, + pourcentage, 100))) + { + /* reduce old window height (left window) */ + window->win_width = width1; + window->win_width_pct = 100 - pourcentage; + + /* assign same buffer for new window (right window) */ + new_window->buffer = window->buffer; + new_window->buffer->num_displayed++; + + gui_window_switch_to_buffer (window, window->buffer); + + gui_current_window = new_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + + /* create & draw separator */ + gui_window_draw_separator (gui_current_window); + } + } +} + +/* + * gui_window_resize: resize window + */ + +void +gui_window_resize (t_gui_window *window, int pourcentage) +{ + t_gui_window_tree *parent; + int old_split_pct; + + parent = window->ptr_tree->parent_node; + if (parent) + { + old_split_pct = parent->split_pct; + if (((parent->split_horiz) && (window->ptr_tree == parent->child2)) + || ((!(parent->split_horiz)) && (window->ptr_tree == parent->child1))) + parent->split_pct = pourcentage; + else + parent->split_pct = 100 - pourcentage; + if (gui_window_auto_resize (gui_windows_tree, 0, 0, COLS, LINES, 1) < 0) + parent->split_pct = old_split_pct; + else + gui_window_refresh_windows (); + } +} + +/* + * gui_window_merge: merge window with its sister + */ + +int +gui_window_merge (t_gui_window *window) +{ + t_gui_window_tree *parent, *sister; + + parent = window->ptr_tree->parent_node; + if (parent) + { + sister = (parent->child1->window == window) ? + parent->child2 : parent->child1; + + if (!(sister->window)) + return 0; + + if (window->win_y == sister->window->win_y) + { + /* horizontal merge */ + window->win_width += sister->window->win_width + 1; + window->win_width_pct += sister->window->win_width_pct; + } + else + { + /* vertical merge */ + window->win_height += sister->window->win_height; + window->win_height_pct += sister->window->win_height_pct; + } + if (sister->window->win_x < window->win_x) + window->win_x = sister->window->win_x; + if (sister->window->win_y < window->win_y) + window->win_y = sister->window->win_y; + + gui_window_free (sister->window); + gui_window_tree_node_to_leaf (parent, window); + + gui_window_switch_to_buffer (window, window->buffer); + gui_window_redraw_buffer (window->buffer); + return 1; + } + return 0; +} + +/* + * gui_window_merge_all: merge all windows into only one + */ + +void +gui_window_merge_all (t_gui_window *window) +{ + while (gui_windows->next_window) + { + gui_window_free ((gui_windows == window) ? gui_windows->next_window : gui_windows); + } + gui_window_tree_free (&gui_windows_tree); + gui_window_tree_init (window); + window->ptr_tree = gui_windows_tree; + window->win_x = 0; + window->win_y = 0; + window->win_width = COLS; + window->win_height = LINES; + window->win_width_pct = 100; + window->win_height_pct = 100; + gui_window_switch_to_buffer (window, window->buffer); + gui_window_redraw_buffer (window->buffer); +} + +/* + * gui_window_side_by_side: return a code about position of 2 windows: + * 0 = they're not side by side + * 1 = side by side (win2 is over the win1) + * 2 = side by side (win2 on the right) + * 3 = side by side (win2 below win1) + * 4 = side by side (win2 on the left) + */ + +int +gui_window_side_by_side (t_gui_window *win1, t_gui_window *win2) +{ + /* win2 over win1 ? */ + if (win2->win_y + win2->win_height == win1->win_y) + { + if (win2->win_x >= win1->win_x + win1->win_width) + return 0; + if (win2->win_x + win2->win_width <= win1->win_x) + return 0; + return 1; + } + + /* win2 on the right ? */ + if (win2->win_x == win1->win_x + win1->win_width + 1) + { + if (win2->win_y >= win1->win_y + win1->win_height) + return 0; + if (win2->win_y + win2->win_height <= win1->win_y) + return 0; + return 2; + } + + /* win2 below win1 ? */ + if (win2->win_y == win1->win_y + win1->win_height) + { + if (win2->win_x >= win1->win_x + win1->win_width) + return 0; + if (win2->win_x + win2->win_width <= win1->win_x) + return 0; + return 3; + } + + /* win2 on the left ? */ + if (win2->win_x + win2->win_width + 1 == win1->win_x) + { + if (win2->win_y >= win1->win_y + win1->win_height) + return 0; + if (win2->win_y + win2->win_height <= win1->win_y) + return 0; + return 4; + } + + return 0; +} + +/* + * gui_window_switch_up: search and switch to a window over current window + */ + +void +gui_window_switch_up (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 1)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_down: search and switch to a window below current window + */ + +void +gui_window_switch_down (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 3)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_left: search and switch to a window on the left of current window + */ + +void +gui_window_switch_left (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 4)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_right: search and switch to a window on the right of current window + */ + +void +gui_window_switch_right (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 2)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_refresh_screen: called when term size is modified + */ + +void +gui_window_refresh_screen () +{ + int new_height, new_width; + + endwin (); + refresh (); + + getmaxyx (stdscr, new_height, new_width); + + gui_ok = ((new_width > WINDOW_MIN_WIDTH) && (new_height > WINDOW_MIN_HEIGHT)); + + if (gui_ok) + gui_window_refresh_windows (); +} + +/* + * gui_window_refresh_screen_sigwinch: called when signal SIGWINCH is received + */ + +void +gui_window_refresh_screen_sigwinch () +{ + gui_window_refresh_screen (); + signal (SIGWINCH, gui_window_refresh_screen_sigwinch); +} + +/* + * gui_window_set_title: set terminal title + */ + +void +gui_window_set_title () +{ + char *envterm = getenv ("TERM"); + + if (envterm) + { + if (strcmp( envterm, "sun-cmd") == 0) + printf ("\033]l%s %s\033\\", PACKAGE_NAME, PACKAGE_VERSION); + else if (strcmp(envterm, "hpterm") == 0) + printf ("\033&f0k%dD%s %s", strlen(PACKAGE_NAME) + + strlen(PACKAGE_VERSION) + 1, + PACKAGE_NAME, PACKAGE_VERSION); + /* the following term supports the xterm excapes */ + else if (strncmp (envterm, "xterm", 5) == 0 + || strncmp (envterm, "rxvt", 4) == 0 + || strcmp (envterm, "Eterm") == 0 + || strcmp (envterm, "aixterm") == 0 + || strcmp (envterm, "iris-ansi") == 0 + || strcmp (envterm, "dtterm") == 0) + printf ("\33]0;%s %s\7", PACKAGE_NAME, PACKAGE_VERSION); + else if (strcmp (envterm, "screen") == 0) + { + printf ("\033k%s %s\033\\", PACKAGE_NAME, PACKAGE_VERSION); + /* tryning to set the title of a backgrounded xterm like terminal */ + printf ("\33]0;%s %s\7", PACKAGE_NAME, PACKAGE_VERSION); + } + } +} + +/* + * gui_window_reset_title: reset terminal title + */ + +void +gui_window_reset_title () +{ + char *envterm = getenv ("TERM"); + char *envshell = getenv ("SHELL"); + + if (envterm) + { + if (strcmp( envterm, "sun-cmd") == 0) + printf ("\033]l%s\033\\", "Terminal"); + else if (strcmp( envterm, "hpterm") == 0) + printf ("\033&f0k%dD%s", strlen("Terminal"), "Terminal"); + /* the following term supports the xterm excapes */ + else if (strncmp (envterm, "xterm", 5) == 0 + || strncmp (envterm, "rxvt", 4) == 0 + || strcmp (envterm, "Eterm") == 0 + || strcmp( envterm, "aixterm") == 0 + || strcmp( envterm, "iris-ansi") == 0 + || strcmp( envterm, "dtterm") == 0) + printf ("\33]0;%s\7", "Terminal"); + else if (strcmp (envterm, "screen") == 0) + { + char *shell, *shellname; + if (envshell) + { + shell = strdup (envterm); + shellname = basename(shell); + if (shell) + { + printf ("\033k%s\033\\", shellname); + free (shell); + } + else + printf ("\033k%s\033\\", envterm); + } + else + printf ("\033k%s\033\\", envterm); + /* tryning to reset the title of a backgrounded xterm like terminal */ + printf ("\33]0;%s\7", "Terminal"); + } + } +} diff --git a/weechat/src/gui/gtk/Makefile.am b/weechat/src/gui/gtk/Makefile.am index 655a03d40..46b5667dd 100644 --- a/weechat/src/gui/gtk/Makefile.am +++ b/weechat/src/gui/gtk/Makefile.am @@ -20,7 +20,8 @@ INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GTK_CFLAGS) bin_PROGRAMS = weechat-gtk if PLUGINS -weechat_gtk_LDADD = ../gui-common.o ../gui-keyboard.o \ +weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \ + ../gui-window.o ../gui-keyboard.o \ ../gui-action.o \ ../../common/lib_weechat_main.a \ ../../irc/lib_weechat_irc.a \ @@ -29,7 +30,8 @@ weechat_gtk_LDADD = ../gui-common.o ../gui-keyboard.o \ $(GTK_LIBS) \ $(GNUTLS_LFLAGS) else -weechat_gtk_LDADD = ../gui-common.o ../gui-keyboard.o \ +weechat_gtk_LDADD = ../gui-common.o ../gui-buffer.o \ + ../gui-window.o ../gui-keyboard.o \ ../gui-action.o \ ../../common/lib_weechat_main.a \ ../../irc/lib_weechat_irc.a \ @@ -38,5 +40,13 @@ weechat_gtk_LDADD = ../gui-common.o ../gui-keyboard.o \ $(GNUTLS_LFLAGS) endif -weechat_gtk_SOURCES = gui-display.c \ - gui-input.c +weechat_gtk_SOURCES = gui-chat.c \ + gui-color.c \ + gui-infobar.c \ + gui-input.c \ + gui-keyboard.c \ + gui-main.c \ + gui-nicklist.c \ + gui-status.c \ + gui-window.c \ + gui-gtk.h diff --git a/weechat/src/gui/gtk/gui-chat.c b/weechat/src/gui/gtk/gui-chat.c new file mode 100644 index 000000000..6773bcd33 --- /dev/null +++ b/weechat/src/gui/gtk/gui-chat.c @@ -0,0 +1,633 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-chat.c: chat display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/utf8.h" +#include "../../common/weeconfig.h" +#include "../../irc/irc.h" +#include "gui-gtk.h" + + +/* + * gui_chat_set_style: set style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_set_style (t_gui_window *window, int style) +{ + /* TODO: write this function for Gtk */ + /*wattron (window->win_chat, style);*/ + (void) window; + (void) style; +} + +/* + * gui_chat_remove_style: remove style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_remove_style (t_gui_window *window, int style) +{ + /* TODO: write this function for Gtk */ + /*wattroff (window->win_chat, style);*/ + (void) window; + (void) style; +} + +/* + * gui_chat_toggle_style: toggle a style (bold, underline, ..) + * for a chat window + */ + +void +gui_chat_toggle_style (t_gui_window *window, int style) +{ + window->current_style_attr ^= style; + if (window->current_style_attr & style) + gui_chat_set_style (window, style); + else + gui_chat_remove_style (window, style); +} + +/* + * gui_chat_reset_style: reset style (color and attr) + * for a chat window + */ + +void +gui_chat_reset_style (t_gui_window *window) +{ + window->current_style_fg = -1; + window->current_style_bg = -1; + window->current_style_attr = 0; + window->current_color_attr = 0; + + /* TODO: change following function call */ + /*gui_window_set_weechat_color (window->win_chat, COLOR_WIN_CHAT);*/ + gui_chat_remove_style (window, + A_BOLD | A_UNDERLINE | A_REVERSE); +} + +/* + * gui_chat_set_color_style: set style for color + */ + +void +gui_chat_set_color_style (t_gui_window *window, int style) +{ + window->current_color_attr |= style; + /* TODO: change following function call */ + /*wattron (window->win_chat, style);*/ +} + +/* + * gui_chat_remove_color_style: remove style for color + */ + +void +gui_chat_remove_color_style (t_gui_window *window, int style) +{ + window->current_color_attr &= !style; + /* TODO: change following function call */ + /*wattroff (window->win_chat, style);*/ +} + +/* + * gui_chat_reset_color_style: reset style for color + */ + +void +gui_chat_reset_color_style (t_gui_window *window) +{ + /* TODO: change following function call */ + /*wattroff (window->win_chat, window->current_color_attr);*/ + window->current_color_attr = 0; +} + +/* + * gui_chat_set_color: set color for a chat window + */ + +void +gui_chat_set_color (t_gui_window *window, int fg, int bg) +{ + /* TODO: write this function for Gtk */ + /*if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + wattron (window->win_chat, COLOR_PAIR(63)); + else + { + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + wattron (window->win_chat, COLOR_PAIR((bg * 8) + fg)); + }*/ + (void) window; + (void) fg; + (void) bg; +} + +/* + * gui_chat_set_weechat_color: set a WeeChat color for a chat window + */ + +void +gui_chat_set_weechat_color (t_gui_window *window, int weechat_color) +{ + gui_chat_reset_style (window); + gui_chat_set_style (window, + gui_color[weechat_color]->attributes); + gui_chat_set_color (window, + gui_color[weechat_color]->foreground, + gui_color[weechat_color]->background); +} + +/* + * gui_chat_draw_title: draw title window for a buffer + */ + +void +gui_chat_draw_title (t_gui_buffer *buffer, int erase) +{ + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} + +/* + * gui_chat_word_get_next_char: returns next char of a word + * special chars like colors, bold, .. are skipped + */ + +char * +gui_chat_word_get_next_char (t_gui_window *window, unsigned char *string, int apply_style) +{ + char str_fg[3], str_bg[3]; + int fg, bg, weechat_color; + + while (string[0]) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_BOLD); + break; + case GUI_ATTR_COLOR_CHAR: + string++; + str_fg[0] = '\0'; + str_bg[0] = '\0'; + fg = 99; + bg = 99; + if (isdigit (string[0])) + { + str_fg[0] = string[0]; + str_fg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_fg[1] = string[0]; + str_fg[2] = '\0'; + string++; + } + } + if (string[0] == ',') + { + string++; + if (isdigit (string[0])) + { + str_bg[0] = string[0]; + str_bg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_bg[1] = string[0]; + str_bg[2] = '\0'; + string++; + } + } + } + if (apply_style) + { + if (str_fg[0] || str_bg[0]) + { + if (str_fg[0]) + sscanf (str_fg, "%d", &fg); + else + fg = window->current_style_fg; + if (str_bg[0]) + sscanf (str_bg, "%d", &bg); + else + bg = window->current_style_bg; + } + if (!str_fg[0] && !str_bg[0]) + gui_chat_reset_color_style (window); + window->current_style_fg = fg; + window->current_style_bg = bg; + gui_chat_set_color (window, fg, bg); + } + break; + case GUI_ATTR_RESET_CHAR: + string++; + if (apply_style) + gui_chat_reset_style (window); + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_REVERSE); + break; + case GUI_ATTR_WEECHAT_COLOR_CHAR: + string++; + if (isdigit (string[0]) && isdigit (string[1])) + { + str_fg[0] = string[0]; + str_fg[1] = string[1]; + str_fg[2] = '\0'; + string += 2; + if (apply_style) + { + sscanf (str_fg, "%d", &weechat_color); + gui_chat_set_weechat_color (window, weechat_color); + } + } + break; + case GUI_ATTR_WEECHAT_SET_CHAR: + string++; + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_BOLD); + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_REVERSE); + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_set_color_style (window, A_UNDERLINE); + break; + } + break; + case GUI_ATTR_WEECHAT_REMOVE_CHAR: + string++; + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_BOLD); + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_REVERSE); + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_remove_color_style (window, A_UNDERLINE); + break; + } + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + string++; + if (apply_style) + gui_chat_toggle_style (window, A_UNDERLINE); + break; + default: + if (string[0] < 32) + string++; + else + return utf8_next_char ((char *)string); + } + + } + + /* nothing found except color/attrib codes, so return NULL */ + return NULL; +} + +/* + * gui_chat_display_word_raw: display word on chat buffer, letter by letter + * special chars like color, bold, .. are interpreted + */ + +void +gui_chat_display_word_raw (t_gui_window *window, char *string) +{ + /*char *prev_char, *next_char, saved_char;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) string; +} + +/* + * gui_chat_display_word: display a word on chat buffer + */ + +void +gui_chat_display_word (t_gui_window *window, + t_gui_line *line, + char *data, + char *end_offset, + int num_lines, int count, int *lines_displayed, int simulate) +{ + /*char *end_line, saved_char_end, saved_char; + int pos_saved_char, chars_to_display, num_displayed;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) line; + (void) data; + (void) end_offset; + (void) num_lines; + (void) count; + (void) lines_displayed; + (void) simulate; +} + +/* + * gui_chat_get_word_info: returns info about next word: beginning, end, length + */ + +void +gui_chat_get_word_info (t_gui_window *window, + char *data, + int *word_start_offset, int *word_end_offset, + int *word_length_with_spaces, int *word_length) +{ + char *start_data, *prev_char, *next_char; + int leading_spaces, char_size; + + *word_start_offset = 0; + *word_end_offset = 0; + *word_length_with_spaces = 0; + *word_length = 0; + + start_data = data; + + leading_spaces = 1; + while (data && data[0]) + { + next_char = gui_chat_word_get_next_char (window, (unsigned char *)data, 0); + if (next_char) + { + prev_char = utf8_prev_char (data, next_char); + if (prev_char) + { + if (prev_char[0] != ' ') + { + if (leading_spaces) + *word_start_offset = prev_char - start_data; + leading_spaces = 0; + char_size = next_char - prev_char; + *word_end_offset = next_char - start_data - 1; + (*word_length_with_spaces) += char_size; + (*word_length) += char_size; + } + else + { + if (leading_spaces) + (*word_length_with_spaces)++; + else + { + *word_end_offset = prev_char - start_data - 1; + return; + } + } + data = next_char; + } + } + else + { + *word_end_offset = data + strlen (data) - start_data - 1; + return; + } + } +} + +/* + * gui_chat_display_line: display a line in the chat window + * if count == 0, display whole line + * if count > 0, display 'count' lines (beginning from the end) + * if simulate == 1, nothing is displayed (for counting how + * many lines would have been lines displayed) + * returns: number of lines displayed (or simulated) + */ + +int +gui_chat_display_line (t_gui_window *window, t_gui_line *line, int count, + int simulate) +{ + /* TODO: write this function for Gtk */ + (void) window; + (void) line; + (void) count; + (void) simulate; + return 1; +} + +/* + * gui_chat_calculate_line_diff: returns pointer to line & offset for a difference + * with given line + */ + +void +gui_chat_calculate_line_diff (t_gui_window *window, t_gui_line **line, + int *line_pos, int difference) +{ + int backward, current_size; + + if (!line || !line_pos) + return; + + backward = (difference < 0); + + if (!(*line)) + { + /* if looking backward, start at last line of buffer */ + if (backward) + { + *line = window->buffer->last_line; + if (!(*line)) + return; + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = current_size - 1; + } + /* if looking forward, start at first line of buffer */ + else + { + *line = window->buffer->lines; + if (!(*line)) + return; + *line_pos = 0; + current_size = gui_chat_display_line (window, *line, 0, 1); + } + } + else + current_size = gui_chat_display_line (window, *line, 0, 1); + + while ((*line) && (difference != 0)) + { + /* looking backward */ + if (backward) + { + if (*line_pos > 0) + (*line_pos)--; + else + { + *line = (*line)->prev_line; + if (*line) + { + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = current_size - 1; + } + } + difference++; + } + /* looking forward */ + else + { + if (*line_pos < current_size - 1) + (*line_pos)++; + else + { + *line = (*line)->next_line; + if (*line) + { + current_size = gui_chat_display_line (window, *line, 0, 1); + if (current_size == 0) + current_size = 1; + *line_pos = 0; + } + } + difference--; + } + } + + /* first or last line reached */ + if (!(*line)) + { + if (backward) + { + /* first line reached */ + *line = window->buffer->lines; + *line_pos = 0; + } + else + { + /* last line reached => consider we'll display all until the end */ + *line_pos = 0; + } + } +} + +/* + * gui_chat_draw: draw chat window for a buffer + */ + +void +gui_chat_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + t_gui_line *ptr_line; + t_irc_dcc *dcc_first, *dcc_selected, *ptr_dcc; + char format_empty[32]; + int i, j, line_pos, count, num_bars; + char *unit_name[] = { N_("bytes"), N_("Kb"), N_("Mb"), N_("Gb") }; + char *unit_format[] = { "%.0Lf", "%.1Lf", "%.02Lf", "%.02Lf" }; + long unit_divide[] = { 1, 1024, 1024*1024, 1024*1024,1024 }; + int num_unit; + char format[32], date[128], *buf; + struct tm *date_tmp;*/ + + if (!gui_ok) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} + +/* + * gui_chat_draw_line: add a line to chat window for a buffer + */ + +void +gui_chat_draw_line (t_gui_buffer *buffer, t_gui_line *line) +{ + t_gui_window *ptr_win; + unsigned char *text_without_color; + GtkTextIter start, end; + + ptr_win = gui_buffer_find_window (buffer); + if (ptr_win) + { + text_without_color = gui_color_decode ((unsigned char *)(line->data), 0); + if (text_without_color) + { + gtk_text_buffer_insert_at_cursor (ptr_win->textbuffer_chat, + (char *)text_without_color, -1); + gtk_text_buffer_insert_at_cursor (ptr_win->textbuffer_chat, + "\n", -1); + gtk_text_buffer_get_bounds (ptr_win->textbuffer_chat, + &start, &end); + /* TODO */ + /*gtk_text_buffer_apply_tag (ptr_win->textbuffer_chat, ptr_win->texttag_chat, &start, &end);*/ + free (text_without_color); + } + } +} diff --git a/weechat/src/gui/gtk/gui-color.c b/weechat/src/gui/gtk/gui-color.c new file mode 100644 index 000000000..852a2af5b --- /dev/null +++ b/weechat/src/gui/gtk/gui-color.c @@ -0,0 +1,580 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-color.c: color functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + + +t_gui_color gui_weechat_colors[] = +{ { -1, 0, 0, "default" }, + { WEECHAT_COLOR_BLACK, 0, 0, "black" }, + { WEECHAT_COLOR_RED, 0, 0, "red" }, + { WEECHAT_COLOR_RED, 0, A_BOLD, "lightred" }, + { WEECHAT_COLOR_GREEN, 0, 0, "green" }, + { WEECHAT_COLOR_GREEN, 0, A_BOLD, "lightgreen" }, + { WEECHAT_COLOR_YELLOW, 0, 0, "brown" }, + { WEECHAT_COLOR_YELLOW, 0, A_BOLD, "yellow" }, + { WEECHAT_COLOR_BLUE, 0, 0, "blue" }, + { WEECHAT_COLOR_BLUE, 0, A_BOLD, "lightblue" }, + { WEECHAT_COLOR_MAGENTA, 0, 0, "magenta" }, + { WEECHAT_COLOR_MAGENTA, 0, A_BOLD, "lightmagenta" }, + { WEECHAT_COLOR_CYAN, 0, 0, "cyan" }, + { WEECHAT_COLOR_CYAN, 0, A_BOLD, "lightcyan" }, + { WEECHAT_COLOR_WHITE, 0, A_BOLD, "white" }, + { 0, 0, 0, NULL } +}; + +int gui_irc_colors[GUI_NUM_IRC_COLORS][2] = +{ { /* 0 */ WEECHAT_COLOR_WHITE, A_BOLD }, + { /* 1 */ WEECHAT_COLOR_BLACK, 0 }, + { /* 2 */ WEECHAT_COLOR_BLUE, 0 }, + { /* 3 */ WEECHAT_COLOR_GREEN, 0 }, + { /* 4 */ WEECHAT_COLOR_RED, A_BOLD }, + { /* 5 */ WEECHAT_COLOR_RED, 0 }, + { /* 6 */ WEECHAT_COLOR_MAGENTA, 0 }, + { /* 7 */ WEECHAT_COLOR_YELLOW, 0 }, + { /* 8 */ WEECHAT_COLOR_YELLOW, A_BOLD }, + { /* 9 */ WEECHAT_COLOR_GREEN, A_BOLD }, + { /* 10 */ WEECHAT_COLOR_CYAN, 0 }, + { /* 11 */ WEECHAT_COLOR_CYAN, A_BOLD }, + { /* 12 */ WEECHAT_COLOR_BLUE, A_BOLD }, + { /* 13 */ WEECHAT_COLOR_MAGENTA, A_BOLD }, + { /* 14 */ WEECHAT_COLOR_WHITE, 0 }, + { /* 15 */ WEECHAT_COLOR_WHITE, A_BOLD } +}; + +t_gui_color *gui_color[GUI_NUM_COLORS]; + + +/* + * gui_color_assign: assign a WeeChat color (read from config) + */ + +int +gui_color_assign (int *color, char *color_name) +{ + int i; + + /* look for curses colors in table */ + i = 0; + while (gui_weechat_colors[i].string) + { + if (ascii_strcasecmp (gui_weechat_colors[i].string, color_name) == 0) + { + *color = i; + return 1; + } + i++; + } + + /* color not found */ + return 0; +} + +/* + * gui_color_get_name: get color name + */ + +char * +gui_color_get_name (int num_color) +{ + return gui_weechat_colors[num_color].string; +} + +/* + * gui_color_decode: parses a message (coming from IRC server), + * and according: + * - remove any color/style in message + * or: + * - change colors by codes to be compatible with + * other IRC clients + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode (unsigned char *string, int keep_colors) +{ + unsigned char *out; + int out_length, out_pos; + char str_fg[3], str_bg[3]; + int fg, bg, attr; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + case GUI_ATTR_RESET_CHAR: + case GUI_ATTR_FIXED_CHAR: + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + case GUI_ATTR_ITALIC_CHAR: + case GUI_ATTR_UNDERLINE_CHAR: + if (keep_colors) + out[out_pos++] = string[0]; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + string++; + str_fg[0] = '\0'; + str_bg[0] = '\0'; + if (isdigit (string[0])) + { + str_fg[0] = string[0]; + str_fg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_fg[1] = string[0]; + str_fg[2] = '\0'; + string++; + } + } + if (string[0] == ',') + { + string++; + if (isdigit (string[0])) + { + str_bg[0] = string[0]; + str_bg[1] = '\0'; + string++; + if (isdigit (string[0])) + { + str_bg[1] = string[0]; + str_bg[2] = '\0'; + string++; + } + } + } + if (keep_colors) + { + if (!str_fg[0] && !str_bg[0]) + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + else + { + attr = 0; + if (str_fg[0]) + { + sscanf (str_fg, "%d", &fg); + fg %= 16; + attr |= gui_irc_colors[fg][1]; + } + if (str_bg[0]) + { + sscanf (str_bg, "%d", &bg); + bg %= 16; + attr |= gui_irc_colors[bg][1]; + } + if (attr & A_BOLD) + { + out[out_pos++] = GUI_ATTR_WEECHAT_SET_CHAR; + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + } + else + { + out[out_pos++] = GUI_ATTR_WEECHAT_REMOVE_CHAR; + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + } + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + if (str_fg[0]) + { + out[out_pos++] = (gui_irc_colors[fg][0] / 10) + '0'; + out[out_pos++] = (gui_irc_colors[fg][0] % 10) + '0'; + } + if (str_bg[0]) + { + out[out_pos++] = ','; + out[out_pos++] = (gui_irc_colors[bg][0] / 10) + '0'; + out[out_pos++] = (gui_irc_colors[bg][0] % 10) + '0'; + } + } + } + break; + case GUI_ATTR_WEECHAT_COLOR_CHAR: + string++; + if (isdigit (string[0]) && isdigit (string[1])) + { + if (keep_colors) + { + out[out_pos++] = string[0]; + out[out_pos++] = string[1]; + } + string += 2; + } + break; + case GUI_ATTR_WEECHAT_SET_CHAR: + case GUI_ATTR_WEECHAT_REMOVE_CHAR: + string++; + if (string[0]) + { + if (keep_colors) + { + out[out_pos++] = *(string - 1); + out[out_pos++] = string[0]; + } + string++; + } + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_decode_for_user_entry: parses a message (coming from IRC server), + * and replaces colors/bold/.. by %C, %B, .. + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode_for_user_entry (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'B'; + string++; + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_RESET_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'O'; + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + case GUI_ATTR_REVERSE2_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'C'; + string++; + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_encode: parses a message (entered by user), and + * encode special chars (%B, %C, ..) in IRC colors + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_encode (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case '%': + string++; + switch (string[0]) + { + case '\0': + out[out_pos++] = '%'; + break; + case '%': /* double '%' replaced by single '%' */ + out[out_pos++] = string[0]; + string++; + break; + case 'B': /* bold */ + out[out_pos++] = GUI_ATTR_BOLD_CHAR; + string++; + break; + case 'C': /* color */ + out[out_pos++] = GUI_ATTR_COLOR_CHAR; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + } + } + if (string[0] == ',') + { + out[out_pos++] = ','; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + if (isdigit (string[0])) + { + out[out_pos++] = string[0]; + string++; + } + } + } + break; + case 'O': /* reset */ + out[out_pos++] = GUI_ATTR_RESET_CHAR; + string++; + break; + case 'R': /* reverse */ + out[out_pos++] = GUI_ATTR_REVERSE_CHAR; + string++; + break; + case 'U': /* underline */ + out[out_pos++] = GUI_ATTR_UNDERLINE_CHAR; + string++; + break; + default: + out[out_pos++] = '%'; + out[out_pos++] = string[0]; + string++; + } + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* + * gui_color_build: build a WeeChat color with foreground, + * background and attributes (attributes are + * given with foreground color, with a OR) + */ + +t_gui_color * +gui_color_build (int number, int foreground, int background) +{ + t_gui_color *new_color; + + new_color = (t_gui_color *)malloc (sizeof (t_gui_color)); + if (!new_color) + return NULL; + + new_color->foreground = gui_weechat_colors[foreground].foreground; + new_color->background = gui_weechat_colors[background].foreground; + new_color->attributes = gui_weechat_colors[foreground].attributes; + new_color->string = (char *)malloc (4); + if (new_color->string) + snprintf (new_color->string, 4, + "%s%02d", + GUI_ATTR_WEECHAT_COLOR_STR, number); + + return new_color; +} + +/* + * gui_color_get_pair: get color pair with a WeeChat color number + */ + +int +gui_color_get_pair (int num_color) +{ + int fg, bg; + + if ((num_color < 0) || (num_color > GUI_NUM_COLORS - 1)) + return WEECHAT_COLOR_WHITE; + + fg = gui_color[num_color]->foreground; + bg = gui_color[num_color]->background; + + if (((fg == -1) || (fg == 99)) + && ((bg == -1) || (bg == 99))) + return 63; + if ((fg == -1) || (fg == 99)) + fg = WEECHAT_COLOR_WHITE; + if ((bg == -1) || (bg == 99)) + bg = 0; + + return (bg * 8) + fg; +} + +/* + * gui_color_init_pairs: init color pairs + */ + +void +gui_color_init_pairs () +{ + /* This function does nothing in Gtk GUI */ +} + +/* + * gui_color_init_weechat: init WeeChat colors + */ + +void +gui_color_init_weechat () +{ + int i; + + gui_color[COLOR_WIN_SEPARATOR] = gui_color_build (COLOR_WIN_SEPARATOR, cfg_col_separator, cfg_col_separator); + gui_color[COLOR_WIN_TITLE] = gui_color_build (COLOR_WIN_TITLE, cfg_col_title, cfg_col_title_bg); + gui_color[COLOR_WIN_CHAT] = gui_color_build (COLOR_WIN_CHAT, cfg_col_chat, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_TIME] = gui_color_build (COLOR_WIN_CHAT_TIME, cfg_col_chat_time, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_TIME_SEP] = gui_color_build (COLOR_WIN_CHAT_TIME_SEP, cfg_col_chat_time_sep, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PREFIX1] = gui_color_build (COLOR_WIN_CHAT_PREFIX1, cfg_col_chat_prefix1, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PREFIX2] = gui_color_build (COLOR_WIN_CHAT_PREFIX2, cfg_col_chat_prefix2, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_SERVER] = gui_color_build (COLOR_WIN_CHAT_SERVER, cfg_col_chat_server, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_JOIN] = gui_color_build (COLOR_WIN_CHAT_JOIN, cfg_col_chat_join, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_PART] = gui_color_build (COLOR_WIN_CHAT_PART, cfg_col_chat_part, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_NICK] = gui_color_build (COLOR_WIN_CHAT_NICK, cfg_col_chat_nick, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_HOST] = gui_color_build (COLOR_WIN_CHAT_HOST, cfg_col_chat_host, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_CHANNEL] = gui_color_build (COLOR_WIN_CHAT_CHANNEL, cfg_col_chat_channel, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_DARK] = gui_color_build (COLOR_WIN_CHAT_DARK, cfg_col_chat_dark, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_HIGHLIGHT] = gui_color_build (COLOR_WIN_CHAT_HIGHLIGHT, cfg_col_chat_highlight, cfg_col_chat_bg); + gui_color[COLOR_WIN_CHAT_READ_MARKER] = gui_color_build (COLOR_WIN_CHAT_READ_MARKER, cfg_col_chat_read_marker, cfg_col_chat_read_marker_bg); + gui_color[COLOR_WIN_STATUS] = gui_color_build (COLOR_WIN_STATUS, cfg_col_status, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DELIMITERS] = gui_color_build (COLOR_WIN_STATUS_DELIMITERS, cfg_col_status_delimiters, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_CHANNEL] = gui_color_build (COLOR_WIN_STATUS_CHANNEL, cfg_col_status_channel, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_MSG] = gui_color_build (COLOR_WIN_STATUS_DATA_MSG, cfg_col_status_data_msg, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_PRIVATE] = gui_color_build (COLOR_WIN_STATUS_DATA_PRIVATE, cfg_col_status_data_private, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_HIGHLIGHT] = gui_color_build (COLOR_WIN_STATUS_DATA_HIGHLIGHT, cfg_col_status_data_highlight, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_DATA_OTHER] = gui_color_build (COLOR_WIN_STATUS_DATA_OTHER, cfg_col_status_data_other, cfg_col_status_bg); + gui_color[COLOR_WIN_STATUS_MORE] = gui_color_build (COLOR_WIN_STATUS_MORE, cfg_col_status_more, cfg_col_status_bg); + gui_color[COLOR_WIN_INFOBAR] = gui_color_build (COLOR_WIN_INFOBAR, cfg_col_infobar, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INFOBAR_DELIMITERS] = gui_color_build (COLOR_WIN_INFOBAR_DELIMITERS, cfg_col_infobar_delimiters, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INFOBAR_HIGHLIGHT] = gui_color_build (COLOR_WIN_INFOBAR_HIGHLIGHT, cfg_col_infobar_highlight, cfg_col_infobar_bg); + gui_color[COLOR_WIN_INPUT] = gui_color_build (COLOR_WIN_INPUT, cfg_col_input, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_CHANNEL] = gui_color_build (COLOR_WIN_INPUT_CHANNEL, cfg_col_input_channel, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_NICK] = gui_color_build (COLOR_WIN_INPUT_NICK, cfg_col_input_nick, cfg_col_input_bg); + gui_color[COLOR_WIN_INPUT_DELIMITERS] = gui_color_build (COLOR_WIN_INPUT_DELIMITERS, cfg_col_input_delimiters, cfg_col_input_bg); + gui_color[COLOR_WIN_NICK] = gui_color_build (COLOR_WIN_NICK, cfg_col_nick, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_AWAY] = gui_color_build (COLOR_WIN_NICK_AWAY, cfg_col_nick_away, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_CHANOWNER] = gui_color_build (COLOR_WIN_NICK_CHANOWNER, cfg_col_nick_chanowner, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_CHANADMIN] = gui_color_build (COLOR_WIN_NICK_CHANADMIN, cfg_col_nick_chanadmin, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_OP] = gui_color_build (COLOR_WIN_NICK_OP, cfg_col_nick_op, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_HALFOP] = gui_color_build (COLOR_WIN_NICK_HALFOP, cfg_col_nick_halfop, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_VOICE] = gui_color_build (COLOR_WIN_NICK_VOICE, cfg_col_nick_voice, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_MORE] = gui_color_build (COLOR_WIN_NICK_MORE, cfg_col_nick_more, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_SEP] = gui_color_build (COLOR_WIN_NICK_SEP, cfg_col_nick_sep, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_SELF] = gui_color_build (COLOR_WIN_NICK_SELF, cfg_col_nick_self, cfg_col_nick_bg); + gui_color[COLOR_WIN_NICK_PRIVATE] = gui_color_build (COLOR_WIN_NICK_PRIVATE, cfg_col_nick_private, cfg_col_nick_bg); + + for (i = 0; i < COLOR_WIN_NICK_NUMBER; i++) + { + gui_color[COLOR_WIN_NICK_1 + i] = gui_color_build (COLOR_WIN_NICK_1 + i, cfg_col_nick_colors[i], cfg_col_chat_bg); + } + + gui_color[COLOR_DCC_SELECTED] = gui_color_build (COLOR_DCC_SELECTED, cfg_col_dcc_selected, cfg_col_chat_bg); + gui_color[COLOR_DCC_WAITING] = gui_color_build (COLOR_DCC_WAITING, cfg_col_dcc_waiting, cfg_col_chat_bg); + gui_color[COLOR_DCC_CONNECTING] = gui_color_build (COLOR_DCC_CONNECTING, cfg_col_dcc_connecting, cfg_col_chat_bg); + gui_color[COLOR_DCC_ACTIVE] = gui_color_build (COLOR_DCC_ACTIVE, cfg_col_dcc_active, cfg_col_chat_bg); + gui_color[COLOR_DCC_DONE] = gui_color_build (COLOR_DCC_DONE, cfg_col_dcc_done, cfg_col_chat_bg); + gui_color[COLOR_DCC_FAILED] = gui_color_build (COLOR_DCC_FAILED, cfg_col_dcc_failed, cfg_col_chat_bg); + gui_color[COLOR_DCC_ABORTED] = gui_color_build (COLOR_DCC_ABORTED, cfg_col_dcc_aborted, cfg_col_chat_bg); +} + +/* + * gui_color_rebuild_weechat: rebuild WeeChat colors + */ + +void +gui_color_rebuild_weechat () +{ + int i; + + for (i = 0; i < GUI_NUM_COLORS; i++) + { + if (gui_color[i]) + { + if (gui_color[i]->string) + free (gui_color[i]->string); + free (gui_color[i]); + gui_color[i] = NULL; + } + } + gui_color_init_weechat (); +} + +/* + * gui_color_init: init GUI colors + */ + +void +gui_color_init () +{ + gui_color_init_pairs (); + gui_color_init_weechat (); +} diff --git a/weechat/src/gui/gtk/gui-gtk.h b/weechat/src/gui/gtk/gui-gtk.h new file mode 100644 index 000000000..c8a44108f --- /dev/null +++ b/weechat/src/gui/gtk/gui-gtk.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef __WEECHAT_GUI_GTK_H +#define __WEECHAT_GUI_GTK_H 1 + +/* TODO: remove these temporary defines */ + +#define A_BOLD 1 +#define A_UNDERLINE 2 +#define A_REVERSE 4 + +#define COLOR_BLACK 0 +#define COLOR_BLUE 1 +#define COLOR_GREEN 2 +#define COLOR_CYAN 3 +#define COLOR_RED 4 +#define COLOR_MAGENTA 5 +#define COLOR_YELLOW 6 +#define COLOR_WHITE 7 + +/* shift ncurses colors for compatibility with colors + in IRC messages (same as other IRC clients) */ + +#define WEECHAT_COLOR_BLACK COLOR_BLACK +#define WEECHAT_COLOR_RED COLOR_BLUE +#define WEECHAT_COLOR_GREEN COLOR_GREEN +#define WEECHAT_COLOR_YELLOW COLOR_CYAN +#define WEECHAT_COLOR_BLUE COLOR_RED +#define WEECHAT_COLOR_MAGENTA COLOR_MAGENTA +#define WEECHAT_COLOR_CYAN COLOR_YELLOW +#define WEECHAT_COLOR_WHITE COLOR_WHITE + +extern t_gui_color gui_weechat_colors[]; +extern int gui_irc_colors[GUI_NUM_IRC_COLORS][2]; + +extern GtkWidget *gtk_main_window; +extern GtkWidget *vbox1; +extern GtkWidget *entry_topic; +extern GtkWidget *notebook1; +extern GtkWidget *vbox2; +extern GtkWidget *hbox1; +extern GtkWidget *hpaned1; +extern GtkWidget *scrolledwindow_chat; +extern GtkWidget *scrolledwindow_nick; +extern GtkWidget *entry_input; +extern GtkWidget *label1; + +/* color functions */ +extern int gui_color_get_pair (int); +extern void gui_color_init (); + +/* chat functions */ +extern void gui_chat_calculate_line_diff (t_gui_window *, t_gui_line **, int *, int); + +/* keyboard functions */ +extern void gui_keyboard_default_bindings (); +extern void gui_keyboard_read (); + +/* window functions */ +extern void gui_window_set_title (); +extern void gui_window_reset_title (); + +#endif /* gui-gtk.h */ diff --git a/weechat/src/gui/gtk/gui-infobar.c b/weechat/src/gui/gtk/gui-infobar.c new file mode 100644 index 000000000..f90eb8209 --- /dev/null +++ b/weechat/src/gui/gtk/gui-infobar.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-infobar.c: infobar display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + + +/* + * gui_infobar_draw_time: draw time in infobar window + */ + +void +gui_infobar_draw_time (t_gui_buffer *buffer) +{ + /*t_gui_window *ptr_win; + time_t time_seconds; + struct tm *local_time;*/ + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; +} + +/* + * gui_infobar_draw: draw infobar window for a buffer + */ + +void +gui_infobar_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + time_t time_seconds; + struct tm *local_time; + char text_time[1024 + 1];*/ + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} diff --git a/weechat/src/gui/gtk/gui-input.c b/weechat/src/gui/gtk/gui-input.c index 79555fc4c..e38089c36 100644 --- a/weechat/src/gui/gtk/gui-input.c +++ b/weechat/src/gui/gtk/gui-input.c @@ -25,166 +25,157 @@ #endif #include -#include -#include -#include -#include -#include -#include + #include #include "../../common/weechat.h" #include "../gui.h" -#include "../../common/weeconfig.h" -#include "../../common/command.h" -#include "../../common/hotlist.h" -#include "../../common/fifo.h" #include "../../common/utf8.h" -#include "../../irc/irc.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif /* - * gui_input_default_key_bindings: create default key bindings + * gui_input_set_color: set color for an input window */ void -gui_input_default_key_bindings () +gui_input_set_color (t_gui_window *window, int irc_color) { - int i; - char key_str[32], command[32]; - - /* keys binded with internal functions */ - gui_key_bind ( /* RC */ "ctrl-M", "return"); - gui_key_bind ( /* RC */ "ctrl-J", "return"); - gui_key_bind ( /* tab */ "ctrl-I", "tab"); - gui_key_bind ( /* basckp */ "ctrl-H", "backspace"); - gui_key_bind ( /* basckp */ "ctrl-?", "backspace"); - gui_key_bind ( /* del */ "meta2-3~", "delete"); - gui_key_bind ( /* ^K */ "ctrl-K", "delete_end_line"); - gui_key_bind ( /* ^U */ "ctrl-U", "delete_beginning_line"); - gui_key_bind ( /* ^W */ "ctrl-W", "delete_previous_word"); - gui_key_bind ( /* ^Y */ "ctrl-Y", "clipboard_paste"); - gui_key_bind ( /* ^T */ "ctrl-T", "transpose_chars"); - gui_key_bind ( /* home */ "meta2-1~", "home"); - gui_key_bind ( /* home */ "meta2-H", "home"); - gui_key_bind ( /* home */ "meta2-7~", "home"); - gui_key_bind ( /* ^A */ "ctrl-A", "home"); - gui_key_bind ( /* end */ "meta2-4~", "end"); - gui_key_bind ( /* end */ "meta2-F", "end"); - gui_key_bind ( /* end */ "meta2-8~", "end"); - gui_key_bind ( /* ^E */ "ctrl-E", "end"); - gui_key_bind ( /* left */ "meta2-D", "left"); - gui_key_bind ( /* right */ "meta2-C", "right"); - gui_key_bind ( /* up */ "meta2-A", "up"); - gui_key_bind ( /* ^up */ "meta-Oa", "up_global"); - gui_key_bind ( /* down */ "meta2-B", "down"); - gui_key_bind ( /* ^down */ "meta-Ob", "down_global"); - gui_key_bind ( /* pgup */ "meta2-5~", "page_up"); - gui_key_bind ( /* pgdn */ "meta2-6~", "page_down"); - gui_key_bind ( /* m-pgup */ "meta-meta2-5~", "scroll_up"); - gui_key_bind ( /* m-pgdn */ "meta-meta2-6~", "scroll_down"); - gui_key_bind ( /* F10 */ "meta2-21~", "infobar_clear"); - gui_key_bind ( /* F11 */ "meta2-23~", "nick_page_up"); - gui_key_bind ( /* F12 */ "meta2-24~", "nick_page_down"); - gui_key_bind ( /* m-F11 */ "meta-meta2-1~", "nick_beginning"); - gui_key_bind ( /* m-F12 */ "meta-meta2-4~", "nick_end"); - gui_key_bind ( /* ^L */ "ctrl-L", "refresh"); - gui_key_bind ( /* m-a */ "meta-a", "jump_smart"); - gui_key_bind ( /* m-b */ "meta-b", "previous_word"); - gui_key_bind ( /* ^left */ "meta-Od", "previous_word"); - gui_key_bind ( /* m-d */ "meta-d", "delete_next_word"); - gui_key_bind ( /* m-f */ "meta-f", "next_word"); - gui_key_bind ( /* ^right */ "meta-Oc", "next_word"); - gui_key_bind ( /* m-h */ "meta-h", "hotlist_clear"); - gui_key_bind ( /* m-j,m-d */ "meta-jmeta-d", "jump_dcc"); - gui_key_bind ( /* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer"); - gui_key_bind ( /* m-j,m-s */ "meta-jmeta-s", "jump_server"); - gui_key_bind ( /* m-j,m-x */ "meta-jmeta-x", "jump_next_server"); - gui_key_bind ( /* m-k */ "meta-k", "grab_key"); - gui_key_bind ( /* m-n */ "meta-n", "scroll_next_highlight"); - gui_key_bind ( /* m-p */ "meta-p", "scroll_previous_highlight"); - gui_key_bind ( /* m-r */ "meta-r", "delete_line"); - gui_key_bind ( /* m-s */ "meta-s", "switch_server"); - gui_key_bind ( /* m-u */ "meta-u", "scroll_unread"); - - /* keys binded with commands */ - gui_key_bind ( /* m-left */ "meta-meta2-D", "/buffer -1"); - gui_key_bind ( /* F5 */ "meta2-15~", "/buffer -1"); - gui_key_bind ( /* m-right */ "meta-meta2-C", "/buffer +1"); - gui_key_bind ( /* F6 */ "meta2-17~", "/buffer +1"); - gui_key_bind ( /* F7 */ "meta2-18~", "/window -1"); - gui_key_bind ( /* F8 */ "meta2-19~", "/window +1"); - gui_key_bind ( /* m-w,m-up */ "meta-wmeta-meta2-A", "/window up"); - gui_key_bind ( /* m-w,m-down */ "meta-wmeta-meta2-B", "/window down"); - gui_key_bind ( /* m-w,m-left */ "meta-wmeta-meta2-D", "/window left"); - gui_key_bind ( /* m-w,m-right */ "meta-wmeta-meta2-C", "/window right"); - gui_key_bind ( /* m-0 */ "meta-0", "/buffer 10"); - gui_key_bind ( /* m-1 */ "meta-1", "/buffer 1"); - gui_key_bind ( /* m-2 */ "meta-2", "/buffer 2"); - gui_key_bind ( /* m-3 */ "meta-3", "/buffer 3"); - gui_key_bind ( /* m-4 */ "meta-4", "/buffer 4"); - gui_key_bind ( /* m-5 */ "meta-5", "/buffer 5"); - gui_key_bind ( /* m-6 */ "meta-6", "/buffer 6"); - gui_key_bind ( /* m-7 */ "meta-7", "/buffer 7"); - gui_key_bind ( /* m-8 */ "meta-8", "/buffer 8"); - gui_key_bind ( /* m-9 */ "meta-9", "/buffer 9"); - - /* bind meta-j + {01..99} to switch to buffers # > 10 */ - for (i = 1; i < 100; i++) - { - sprintf (key_str, "meta-j%02d", i); - sprintf (command, "/buffer %d", i); - gui_key_bind (key_str, command); - } + /*int fg, bg;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) irc_color; } /* - * gui_input_grab_end: insert grabbed key in input buffer + * gui_input_get_prompt_length: return input prompt length */ -void -gui_input_grab_end () +int +gui_input_get_prompt_length (t_gui_window *window, char *nick) { - char *expanded_key; - - /* get expanded name (for example: ^U => ctrl-u) */ - expanded_key = gui_key_get_expanded_name (gui_key_buffer); + char *pos, *modes; + int length, mode_found; - if (expanded_key) + length = 0; + pos = cfg_look_input_format; + while (pos && pos[0]) { - if (gui_current_window->buffer->has_input) + switch (pos[0]) { - gui_insert_string_input (gui_current_window, expanded_key, -1); - gui_current_window->buffer->input_buffer_pos += utf8_strlen (expanded_key); - gui_draw_buffer_input (gui_current_window->buffer, 1); + case '%': + pos++; + switch (pos[0]) + { + case 'c': + if (CHANNEL(window->buffer)) + length += utf8_strlen (CHANNEL(window->buffer)->name); + else + { + if (SERVER(window->buffer)) + length += utf8_strlen (SERVER(window->buffer)->name); + } + pos++; + break; + case 'm': + if (SERVER(window->buffer)) + { + mode_found = 0; + for (modes = SERVER(window->buffer)->nick_modes; + modes && modes[0]; modes++) + { + if (modes[0] != ' ') + { + length++; + mode_found = 1; + } + } + if (mode_found) + length++; + } + pos++; + break; + case 'n': + length += utf8_strlen (nick); + pos++; + break; + default: + length++; + if (pos[0]) + { + if (pos[0] == '%') + pos++; + else + { + length++; + pos += utf8_char_size (pos); + } + } + break; + } + break; + default: + length++; + pos += utf8_char_size (pos); + break; } - free (expanded_key); } + return length; +} + +/* + * gui_input_draw_prompt: display input prompt + */ + +void +gui_input_draw_prompt (t_gui_window *window, char *nick) +{ + /*char *pos, saved_char, *modes; + int char_size, mode_found;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) nick; +} + +/* + * gui_input_draw_text: display text in input buffer, according to color mask + */ + +void +gui_input_draw_text (t_gui_window *window, int input_width) +{ + /*char *ptr_start, *ptr_next, saved_char; + int pos_mask, size, last_color, color;*/ + + /* TODO: write this function for Gtk */ + (void) window; + (void) input_width; +} + +/* + * gui_input_draw: draw input window for a buffer + */ + +void +gui_input_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + char format[32]; + char *ptr_nickname; + int input_width; + t_irc_dcc *dcc_selected;*/ + + if (!gui_ok) + return; - /* end grab mode */ - gui_key_grab = 0; - gui_key_grab_count = 0; - gui_key_buffer[0] = '\0'; -} - -/* - * gui_input_read: read keyboard chars - */ - -void -gui_input_read () -{ /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; } - -/* - * gui_main_loop: main loop for WeeChat with ncurses GUI - */ - -void -gui_main_loop () -{ - /* TODO: write this function for Gtk */ - gtk_main (); -} - diff --git a/weechat/src/gui/gtk/gui-keyboard.c b/weechat/src/gui/gtk/gui-keyboard.c new file mode 100644 index 000000000..508a055eb --- /dev/null +++ b/weechat/src/gui/gtk/gui-keyboard.c @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-keyboard.c: keyboard functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/utf8.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif + + +/* + * gui_keyboard_default_bindings: create default key bindings + */ + +void +gui_keyboard_default_bindings () +{ + int i; + char key_str[32], command[32]; + + /* keys binded with internal functions */ + gui_key_bind ( /* RC */ "ctrl-M", "return"); + gui_key_bind ( /* RC */ "ctrl-J", "return"); + gui_key_bind ( /* tab */ "ctrl-I", "tab"); + gui_key_bind ( /* basckp */ "ctrl-H", "backspace"); + gui_key_bind ( /* basckp */ "ctrl-?", "backspace"); + gui_key_bind ( /* del */ "meta2-3~", "delete"); + gui_key_bind ( /* ^K */ "ctrl-K", "delete_end_line"); + gui_key_bind ( /* ^U */ "ctrl-U", "delete_beginning_line"); + gui_key_bind ( /* ^W */ "ctrl-W", "delete_previous_word"); + gui_key_bind ( /* ^Y */ "ctrl-Y", "clipboard_paste"); + gui_key_bind ( /* ^T */ "ctrl-T", "transpose_chars"); + gui_key_bind ( /* home */ "meta2-1~", "home"); + gui_key_bind ( /* home */ "meta2-H", "home"); + gui_key_bind ( /* home */ "meta2-7~", "home"); + gui_key_bind ( /* ^A */ "ctrl-A", "home"); + gui_key_bind ( /* end */ "meta2-4~", "end"); + gui_key_bind ( /* end */ "meta2-F", "end"); + gui_key_bind ( /* end */ "meta2-8~", "end"); + gui_key_bind ( /* ^E */ "ctrl-E", "end"); + gui_key_bind ( /* left */ "meta2-D", "left"); + gui_key_bind ( /* right */ "meta2-C", "right"); + gui_key_bind ( /* up */ "meta2-A", "up"); + gui_key_bind ( /* ^up */ "meta-Oa", "up_global"); + gui_key_bind ( /* down */ "meta2-B", "down"); + gui_key_bind ( /* ^down */ "meta-Ob", "down_global"); + gui_key_bind ( /* pgup */ "meta2-5~", "page_up"); + gui_key_bind ( /* pgdn */ "meta2-6~", "page_down"); + gui_key_bind ( /* m-pgup */ "meta-meta2-5~", "scroll_up"); + gui_key_bind ( /* m-pgdn */ "meta-meta2-6~", "scroll_down"); + gui_key_bind ( /* F10 */ "meta2-21~", "infobar_clear"); + gui_key_bind ( /* F11 */ "meta2-23~", "nick_page_up"); + gui_key_bind ( /* F12 */ "meta2-24~", "nick_page_down"); + gui_key_bind ( /* m-F11 */ "meta-meta2-1~", "nick_beginning"); + gui_key_bind ( /* m-F12 */ "meta-meta2-4~", "nick_end"); + gui_key_bind ( /* ^L */ "ctrl-L", "refresh"); + gui_key_bind ( /* m-a */ "meta-a", "jump_smart"); + gui_key_bind ( /* m-b */ "meta-b", "previous_word"); + gui_key_bind ( /* ^left */ "meta-Od", "previous_word"); + gui_key_bind ( /* m-d */ "meta-d", "delete_next_word"); + gui_key_bind ( /* m-f */ "meta-f", "next_word"); + gui_key_bind ( /* ^right */ "meta-Oc", "next_word"); + gui_key_bind ( /* m-h */ "meta-h", "hotlist_clear"); + gui_key_bind ( /* m-j,m-d */ "meta-jmeta-d", "jump_dcc"); + gui_key_bind ( /* m-j,m-l */ "meta-jmeta-l", "jump_last_buffer"); + gui_key_bind ( /* m-j,m-s */ "meta-jmeta-s", "jump_server"); + gui_key_bind ( /* m-j,m-x */ "meta-jmeta-x", "jump_next_server"); + gui_key_bind ( /* m-k */ "meta-k", "grab_key"); + gui_key_bind ( /* m-n */ "meta-n", "scroll_next_highlight"); + gui_key_bind ( /* m-p */ "meta-p", "scroll_previous_highlight"); + gui_key_bind ( /* m-r */ "meta-r", "delete_line"); + gui_key_bind ( /* m-s */ "meta-s", "switch_server"); + gui_key_bind ( /* m-u */ "meta-u", "scroll_unread"); + + /* keys binded with commands */ + gui_key_bind ( /* m-left */ "meta-meta2-D", "/buffer -1"); + gui_key_bind ( /* F5 */ "meta2-15~", "/buffer -1"); + gui_key_bind ( /* m-right */ "meta-meta2-C", "/buffer +1"); + gui_key_bind ( /* F6 */ "meta2-17~", "/buffer +1"); + gui_key_bind ( /* F7 */ "meta2-18~", "/window -1"); + gui_key_bind ( /* F8 */ "meta2-19~", "/window +1"); + gui_key_bind ( /* m-w,m-up */ "meta-wmeta-meta2-A", "/window up"); + gui_key_bind ( /* m-w,m-down */ "meta-wmeta-meta2-B", "/window down"); + gui_key_bind ( /* m-w,m-left */ "meta-wmeta-meta2-D", "/window left"); + gui_key_bind ( /* m-w,m-right */ "meta-wmeta-meta2-C", "/window right"); + gui_key_bind ( /* m-0 */ "meta-0", "/buffer 10"); + gui_key_bind ( /* m-1 */ "meta-1", "/buffer 1"); + gui_key_bind ( /* m-2 */ "meta-2", "/buffer 2"); + gui_key_bind ( /* m-3 */ "meta-3", "/buffer 3"); + gui_key_bind ( /* m-4 */ "meta-4", "/buffer 4"); + gui_key_bind ( /* m-5 */ "meta-5", "/buffer 5"); + gui_key_bind ( /* m-6 */ "meta-6", "/buffer 6"); + gui_key_bind ( /* m-7 */ "meta-7", "/buffer 7"); + gui_key_bind ( /* m-8 */ "meta-8", "/buffer 8"); + gui_key_bind ( /* m-9 */ "meta-9", "/buffer 9"); + + /* bind meta-j + {01..99} to switch to buffers # > 10 */ + for (i = 1; i < 100; i++) + { + sprintf (key_str, "meta-j%02d", i); + sprintf (command, "/buffer %d", i); + gui_key_bind (key_str, command); + } +} + +/* + * gui_keyboard_grab_end: insert grabbed key in input buffer + */ + +void +gui_keyboard_grab_end () +{ + char *expanded_key; + + /* get expanded name (for example: ^U => ctrl-u) */ + expanded_key = gui_key_get_expanded_name (gui_key_buffer); + + if (expanded_key) + { + if (gui_current_window->buffer->has_input) + { + gui_insert_string_input (gui_current_window, expanded_key, -1); + gui_current_window->buffer->input_buffer_pos += utf8_strlen (expanded_key); + gui_input_draw (gui_current_window->buffer, 1); + } + free (expanded_key); + } + + /* end grab mode */ + gui_key_grab = 0; + gui_key_grab_count = 0; + gui_key_buffer[0] = '\0'; +} + +/* + * gui_keyboard_read: read keyboard chars + */ + +void +gui_keyboard_read () +{ + /* TODO: write this function for Gtk */ +} diff --git a/weechat/src/gui/gtk/gui-main.c b/weechat/src/gui/gtk/gui-main.c new file mode 100644 index 000000000..01dc67d65 --- /dev/null +++ b/weechat/src/gui/gtk/gui-main.c @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-main.c: main loop and keyboard management for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/fifo.h" +#include "../../common/utf8.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + +#ifdef PLUGINS +#include "../../plugins/plugins.h" +#endif + + +GtkWidget *gtk_main_window; +GtkWidget *vbox1; +GtkWidget *entry_topic; +GtkWidget *notebook1; +GtkWidget *vbox2; +GtkWidget *hbox1; +GtkWidget *hpaned1; +GtkWidget *scrolledwindow_chat; +GtkWidget *scrolledwindow_nick; +GtkWidget *entry_input; +GtkWidget *label1; + + +/* + * gui_main_loop: main loop for WeeChat with ncurses GUI + */ + +void +gui_main_loop () +{ + /* TODO: write this function for Gtk */ + gtk_main (); +} + +/* + * gui_main_pre_init: pre-initialize GUI (called before gui_init) + */ + +void +gui_main_pre_init (int *argc, char **argv[]) +{ + /* Initialise Gtk */ + gtk_init (argc, argv); +} + +/* + * gui_main_init: init GUI + */ + +void +gui_main_init () +{ + GdkColor color_fg, color_bg; + + gui_color_init (); + + gui_infobar = NULL; + + gui_ok = 1; + + /* init clipboard buffer */ + gui_input_clipboard = NULL; + + /* create Gtk widgets */ + + gdk_color_parse ("white", &color_fg); + gdk_color_parse ("black", &color_bg); + + gtk_main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (gtk_main_window), PACKAGE_STRING); + + g_signal_connect (G_OBJECT (gtk_main_window), "destroy", gtk_main_quit, NULL); + + vbox1 = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox1); + gtk_container_add (GTK_CONTAINER (gtk_main_window), vbox1); + + entry_topic = gtk_entry_new (); + gtk_widget_show (entry_topic); + gtk_box_pack_start (GTK_BOX (vbox1), entry_topic, FALSE, FALSE, 0); + gtk_widget_modify_text (entry_topic, GTK_STATE_NORMAL, &color_fg); + gtk_widget_modify_base (entry_topic, GTK_STATE_NORMAL, &color_bg); + + notebook1 = gtk_notebook_new (); + gtk_widget_show (notebook1); + gtk_box_pack_start (GTK_BOX (vbox1), notebook1, TRUE, TRUE, 0); + gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook1), GTK_POS_BOTTOM); + + vbox2 = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox2); + gtk_container_add (GTK_CONTAINER (notebook1), vbox2); + + hbox1 = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox1); + gtk_box_pack_start (GTK_BOX (vbox2), hbox1, TRUE, TRUE, 0); + + hpaned1 = gtk_hpaned_new (); + gtk_widget_show (hpaned1); + gtk_box_pack_start (GTK_BOX (hbox1), hpaned1, TRUE, TRUE, 0); + gtk_paned_set_position (GTK_PANED (hpaned1), 0); + + scrolledwindow_chat = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_show (scrolledwindow_chat); + gtk_paned_pack1 (GTK_PANED (hpaned1), scrolledwindow_chat, FALSE, TRUE); + //gtk_box_pack_start (GTK_PANED (hpaned1), scrolledwindow_chat, TRUE, TRUE, 0); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_chat), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + gtk_widget_modify_text (scrolledwindow_chat, GTK_STATE_NORMAL, &color_fg); + gtk_widget_modify_base (scrolledwindow_chat, GTK_STATE_NORMAL, &color_bg); + + scrolledwindow_nick = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_show (scrolledwindow_nick); + gtk_paned_pack2 (GTK_PANED (hpaned1), scrolledwindow_nick, FALSE, TRUE); + //gtk_box_pack_start (GTK_PANED (hpaned1), scrolledwindow_nick, TRUE, TRUE, 0); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_nick), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + gtk_widget_modify_text (scrolledwindow_nick, GTK_STATE_NORMAL, &color_fg); + gtk_widget_modify_base (scrolledwindow_nick, GTK_STATE_NORMAL, &color_bg); + + entry_input = gtk_entry_new (); + gtk_widget_show (entry_input); + gtk_box_pack_start (GTK_BOX (vbox2), entry_input, FALSE, FALSE, 0); + gtk_widget_modify_text (entry_input, GTK_STATE_NORMAL, &color_fg); + gtk_widget_modify_base (entry_input, GTK_STATE_NORMAL, &color_bg); + + label1 = gtk_label_new (_("server")); + gtk_widget_show (label1); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 0), label1); + gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT); + + gtk_widget_show_all (gtk_main_window); + + /* create new window/buffer */ + if (gui_window_new (NULL, 0, 0, 0, 0, 100, 100)) + { + gui_current_window = gui_windows; + gui_buffer_new (gui_windows, NULL, NULL, 0, 1); + + if (cfg_look_set_title) + gui_window_set_title (); + + gui_init_ok = 1; + } +} + +/* + * gui_main_end: GUI end + */ + +void +gui_main_end () +{ + t_gui_window *ptr_win; + + /* free clipboard buffer */ + if (gui_input_clipboard) + free(gui_input_clipboard); + + /* delete all windows */ + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + /* TODO: destroy Gtk widgets */ + } + + /* delete all buffers */ + while (gui_buffers) + gui_buffer_free (gui_buffers, 0); + + /* delete all windows */ + while (gui_windows) + gui_window_free (gui_windows); + gui_window_tree_free (&gui_windows_tree); + + /* delete global history */ + history_global_free (); + + /* delete infobar messages */ + while (gui_infobar) + gui_infobar_remove (); + + /* reset title */ + if (cfg_look_set_title) + gui_window_reset_title (); +} diff --git a/weechat/src/gui/gtk/gui-nicklist.c b/weechat/src/gui/gtk/gui-nicklist.c new file mode 100644 index 000000000..eebdc5b51 --- /dev/null +++ b/weechat/src/gui/gtk/gui-nicklist.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-nicklist.c: nicklist display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/weeconfig.h" +#include "../../irc/irc.h" +#include "gui-gtk.h" + + +/* + * gui_nicklist_draw: draw nick window for a buffer + */ + +void +gui_nicklist_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + int i, j, x, y, column, max_length, nicks_displayed; + char format[32], format_empty[32]; + t_irc_nick *ptr_nick;*/ + + if (!gui_ok || !BUFFER_HAS_NICKLIST(buffer)) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} diff --git a/weechat/src/gui/gtk/gui-status.c b/weechat/src/gui/gtk/gui-status.c new file mode 100644 index 000000000..436f7b7f9 --- /dev/null +++ b/weechat/src/gui/gtk/gui-status.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-status.c: status display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + + +/* + * gui_status_draw: draw status window for a buffer + */ + +void +gui_status_draw (t_gui_buffer *buffer, int erase) +{ + /*t_gui_window *ptr_win; + t_weechat_hotlist *ptr_hotlist; + char format[32], str_nicks[32], *more; + int i, first_mode, x, server_pos, server_total; + int display_name, names_count;*/ + + /* make gcc happy */ + (void) buffer; + + if (!gui_ok) + return; + + /* TODO: write this function for Gtk */ + (void) buffer; + (void) erase; +} diff --git a/weechat/src/gui/gtk/gui-window.c b/weechat/src/gui/gtk/gui-window.c new file mode 100644 index 000000000..72791d6c6 --- /dev/null +++ b/weechat/src/gui/gtk/gui-window.c @@ -0,0 +1,847 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-window.c: window display functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include "../../common/weechat.h" +#include "../gui.h" +#include "../../common/hotlist.h" +#include "../../common/weeconfig.h" +#include "gui-gtk.h" + + +/* + * gui_window_set_weechat_color: set WeeChat color for window + */ + +/* TODO: write this function for Gtk */ +/*void +gui_window_set_weechat_color (WINDOW *window, int num_color) +{ + if ((num_color >= 0) && (num_color <= GUI_NUM_COLORS - 1)) + { + wattroff (window, A_BOLD | A_UNDERLINE | A_REVERSE); + wattron (window, COLOR_PAIR(gui_color_get_pair (num_color)) | + gui_color[num_color]->attributes); + } +}*/ + +/* + * gui_window_calculate_pos_size: calculate position and size for a window & sub-win + */ + +int +gui_window_calculate_pos_size (t_gui_window *window, int force_calculate) +{ + /* TODO: write this function for Gtk */ + (void) window; + (void) force_calculate; + + return 0; +} + +/* + * gui_window_draw_separator: draw window separation + */ + +void +gui_window_draw_separator (t_gui_window *window) +{ + /* TODO: write this function for Gtk */ + /*if (window->win_separator) + delwin (window->win_separator); + + if (window->win_x > 0) + { + window->win_separator = newwin (window->win_height, + 1, + window->win_y, + window->win_x - 1); + gui_window_set_weechat_color (window->win_separator, COLOR_WIN_SEPARATOR); + wborder (window->win_separator, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + wnoutrefresh (window->win_separator); + refresh (); + }*/ + (void) window; +} + +/* + * gui_window_redraw_buffer: redraw a buffer + */ + +void +gui_window_redraw_buffer (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + + if (!gui_ok) + return; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + gui_chat_draw_title (buffer, 1); + gui_chat_draw (buffer, 1); + if (ptr_win->win_nick) + gui_nicklist_draw (buffer, 1); + gui_status_draw (buffer, 1); + if (cfg_look_infobar) + gui_infobar_draw (buffer, 1); + gui_input_draw (buffer, 1); + } + } +} + +/* + * gui_window_switch_to_buffer: switch to another buffer + */ + +void +gui_window_switch_to_buffer (t_gui_window *window, t_gui_buffer *buffer) +{ + GtkTextIter start, end; + + if (window->buffer->num_displayed > 0) + window->buffer->num_displayed--; + + if (window->buffer != buffer) + { + window->buffer->last_read_line = window->buffer->last_line; + if (buffer->last_read_line == buffer->last_line) + buffer->last_read_line = NULL; + } + + window->buffer = buffer; + window->win_nick_start = 0; + gui_window_calculate_pos_size (window, 1); + + if (!window->textview_chat) + { + window->textview_chat = gtk_text_view_new (); + gtk_widget_show (window->textview_chat); + gtk_container_add (GTK_CONTAINER (scrolledwindow_chat), window->textview_chat); + gtk_widget_set_size_request (window->textview_chat, 300, -1); + gtk_text_view_set_editable (GTK_TEXT_VIEW (window->textview_chat), FALSE); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (window->textview_chat), FALSE); + + window->textbuffer_chat = gtk_text_buffer_new (NULL); + gtk_text_view_set_buffer (GTK_TEXT_VIEW (window->textview_chat), window->textbuffer_chat); + + /*window->texttag_chat = gtk_text_buffer_create_tag(window->textbuffer_chat, "courier", "font_family", "lucida");*/ + gtk_text_buffer_get_bounds (window->textbuffer_chat, &start, &end); + gtk_text_buffer_apply_tag (window->textbuffer_chat, window->texttag_chat, &start, &end); + } + if (BUFFER_IS_CHANNEL(buffer) && !window->textbuffer_nicklist) + { + window->textview_nicklist = gtk_text_view_new (); + gtk_widget_show (window->textview_nicklist); + gtk_container_add (GTK_CONTAINER (scrolledwindow_nick), window->textview_nicklist); + gtk_text_view_set_editable (GTK_TEXT_VIEW (window->textview_nicklist), FALSE); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (window->textview_nicklist), FALSE); + + window->textbuffer_nicklist = gtk_text_buffer_new (NULL); + gtk_text_view_set_buffer (GTK_TEXT_VIEW (window->textview_nicklist), window->textbuffer_nicklist); + } + + window->start_line = NULL; + window->start_line_pos = 0; + + buffer->num_displayed++; + + hotlist_remove_buffer (buffer); +} + +/* + * gui_window_page_up: display previous page on buffer + */ + +void +gui_window_page_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * (window->win_chat_height - 1) : + (-1) * ((window->win_chat_height - 1) * 2)); + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_page_down: display next page on buffer + */ + +void +gui_window_page_down (t_gui_window *window) +{ + t_gui_line *ptr_line; + int line_pos; + + if (!gui_ok) + return; + + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + window->win_chat_height - 1); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_up: display previous few lines in buffer + */ + +void +gui_window_scroll_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + (window->start_line) ? + (-1) * cfg_look_scroll_amount : + (-1) * ( (window->win_chat_height - 1) + cfg_look_scroll_amount)); + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_down: display next few lines in buffer + */ + +void +gui_window_scroll_down (t_gui_window *window) +{ + t_gui_line *ptr_line; + int line_pos; + + if (!gui_ok) + return; + + if (window->start_line) + { + gui_chat_calculate_line_diff (window, &window->start_line, + &window->start_line_pos, + cfg_look_scroll_amount); + + /* check if we can display all */ + ptr_line = window->start_line; + line_pos = window->start_line_pos; + gui_chat_calculate_line_diff (window, &ptr_line, + &line_pos, + window->win_chat_height - 1); + + if (!ptr_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + } + + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_top: scroll to top of buffer + */ + +void +gui_window_scroll_top (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (!window->first_line_displayed) + { + window->start_line = window->buffer->lines; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_scroll_bottom: scroll to bottom of buffer + */ + +void +gui_window_scroll_bottom (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (window->start_line) + { + window->start_line = NULL; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 0); + } +} + +/* + * gui_window_nick_beginning: go to beginning of nicklist + */ + +void +gui_window_nick_beginning (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if (window->win_nick_start > 0) + { + window->win_nick_start = 0; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_end: go to the end of nicklist + */ + +void +gui_window_nick_end (t_gui_window *window) +{ + int new_start; + + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + new_start = + CHANNEL(window->buffer)->nicks_count - window->win_nick_height; + if (new_start < 0) + new_start = 0; + else if (new_start >= 1) + new_start++; + + if (new_start != window->win_nick_start) + { + window->win_nick_start = new_start; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_page_up: scroll one page up in nicklist + */ + +void +gui_window_nick_page_up (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if (window->win_nick_start > 0) + { + window->win_nick_start -= (window->win_nick_height - 1); + if (window->win_nick_start <= 1) + window->win_nick_start = 0; + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_nick_page_down: scroll one page down in nicklist + */ + +void +gui_window_nick_page_down (t_gui_window *window) +{ + if (!gui_ok) + return; + + if (BUFFER_HAS_NICKLIST(window->buffer)) + { + if ((CHANNEL(window->buffer)->nicks_count > window->win_nick_height) + && (window->win_nick_start + window->win_nick_height - 1 + < CHANNEL(window->buffer)->nicks_count)) + { + if (window->win_nick_start == 0) + window->win_nick_start += (window->win_nick_height - 1); + else + window->win_nick_start += (window->win_nick_height - 2); + gui_nicklist_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_init_subwindows: init subwindows for a WeeChat window + */ + +void +gui_window_init_subwindows (t_gui_window *window) +{ + window->textview_chat = NULL; + window->textbuffer_chat = NULL; + window->texttag_chat = NULL; + window->textview_nicklist = NULL; + window->textbuffer_nicklist = NULL; +} + +/* + * gui_window_auto_resize: auto-resize all windows, according to % of global size + * This function is called after a terminal resize. + * Returns 0 if ok, -1 if all window should be merged + * (not enough space according to windows %) + */ + +int +gui_window_auto_resize (t_gui_window_tree *tree, + int x, int y, int width, int height, + int simulate) +{ + int size1, size2; + + if (tree) + { + if (tree->window) + { + if ((width < WINDOW_MIN_WIDTH) || (height < WINDOW_MIN_HEIGHT)) + return -1; + if (!simulate) + { + tree->window->win_x = x; + tree->window->win_y = y; + tree->window->win_width = width; + tree->window->win_height = height; + } + } + else + { + if (tree->split_horiz) + { + size1 = (height * tree->split_pct) / 100; + size2 = height - size1; + if (gui_window_auto_resize (tree->child1, x, y + size1, + width, size2, simulate) < 0) + return -1; + if (gui_window_auto_resize (tree->child2, x, y, + width, size1, simulate) < 0) + return -1; + } + else + { + size1 = (width * tree->split_pct) / 100; + size2 = width - size1 - 1; + if (gui_window_auto_resize (tree->child1, x, y, + size1, height, simulate) < 0) + return -1; + if (gui_window_auto_resize (tree->child2, x + size1 + 1, y, + size2, height, simulate) < 0) + return -1; + } + } + } + return 0; +} + +/* + * gui_window_refresh_windows: auto resize and refresh all windows + */ + +void +gui_window_refresh_windows () +{ + /*t_gui_window *ptr_win, *old_current_window;*/ + + if (gui_ok) + { + /* TODO: write this function for Gtk */ + } +} + +/* + * gui_window_split_horiz: split a window horizontally + */ + +void +gui_window_split_horiz (t_gui_window *window, int pourcentage) +{ + t_gui_window *new_window; + int height1, height2; + + if (!gui_ok) + return; + + height1 = (window->win_height * pourcentage) / 100; + height2 = window->win_height - height1; + + if ((height1 >= WINDOW_MIN_HEIGHT) && (height2 >= WINDOW_MIN_HEIGHT) + && (pourcentage > 0) && (pourcentage <= 100)) + { + if ((new_window = gui_window_new (window, + window->win_x, window->win_y, + window->win_width, height1, + 100, pourcentage))) + { + /* reduce old window height (bottom window) */ + window->win_y = new_window->win_y + new_window->win_height; + window->win_height = height2; + window->win_height_pct = 100 - pourcentage; + + /* assign same buffer for new window (top window) */ + new_window->buffer = window->buffer; + new_window->buffer->num_displayed++; + + gui_window_switch_to_buffer (window, window->buffer); + + gui_current_window = new_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + } + } +} + +/* + * gui_window_split_vertic: split a window vertically + */ + +void +gui_window_split_vertic (t_gui_window *window, int pourcentage) +{ + t_gui_window *new_window; + int width1, width2; + + if (!gui_ok) + return; + + width1 = (window->win_width * pourcentage) / 100; + width2 = window->win_width - width1 - 1; + + if ((width1 >= WINDOW_MIN_WIDTH) && (width2 >= WINDOW_MIN_WIDTH) + && (pourcentage > 0) && (pourcentage <= 100)) + { + if ((new_window = gui_window_new (window, + window->win_x + width1 + 1, window->win_y, + width2, window->win_height, + pourcentage, 100))) + { + /* reduce old window height (left window) */ + window->win_width = width1; + window->win_width_pct = 100 - pourcentage; + + /* assign same buffer for new window (right window) */ + new_window->buffer = window->buffer; + new_window->buffer->num_displayed++; + + gui_window_switch_to_buffer (window, window->buffer); + + gui_current_window = new_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + + /* create & draw separator */ + gui_window_draw_separator (gui_current_window); + } + } +} + +/* + * gui_window_resize: resize window + */ + +void +gui_window_resize (t_gui_window *window, int pourcentage) +{ + /* TODO: write this function for Gtk */ + (void) window; + (void) pourcentage; +} + +/* + * gui_window_merge: merge window with its sister + */ + +int +gui_window_merge (t_gui_window *window) +{ + t_gui_window_tree *parent, *sister; + + parent = window->ptr_tree->parent_node; + if (parent) + { + sister = (parent->child1->window == window) ? + parent->child2 : parent->child1; + + if (!(sister->window)) + return 0; + + if (window->win_y == sister->window->win_y) + { + /* horizontal merge */ + window->win_width += sister->window->win_width + 1; + window->win_width_pct += sister->window->win_width_pct; + } + else + { + /* vertical merge */ + window->win_height += sister->window->win_height; + window->win_height_pct += sister->window->win_height_pct; + } + if (sister->window->win_x < window->win_x) + window->win_x = sister->window->win_x; + if (sister->window->win_y < window->win_y) + window->win_y = sister->window->win_y; + + gui_window_free (sister->window); + gui_window_tree_node_to_leaf (parent, window); + + gui_window_switch_to_buffer (window, window->buffer); + gui_window_redraw_buffer (window->buffer); + return 1; + } + return 0; +} + +/* + * gui_window_merge_all: merge all windows into only one + */ + +void +gui_window_merge_all (t_gui_window *window) +{ + /* TODO: write this function for Gtk */ + (void) window; +} + +/* + * gui_window_side_by_side: return a code about position of 2 windows: + * 0 = they're not side by side + * 1 = side by side (win2 is over the win1) + * 2 = side by side (win2 on the right) + * 3 = side by side (win2 below win1) + * 4 = side by side (win2 on the left) + */ + +int +gui_window_side_by_side (t_gui_window *win1, t_gui_window *win2) +{ + /* win2 over win1 ? */ + if (win2->win_y + win2->win_height == win1->win_y) + { + if (win2->win_x >= win1->win_x + win1->win_width) + return 0; + if (win2->win_x + win2->win_width <= win1->win_x) + return 0; + return 1; + } + + /* win2 on the right ? */ + if (win2->win_x == win1->win_x + win1->win_width + 1) + { + if (win2->win_y >= win1->win_y + win1->win_height) + return 0; + if (win2->win_y + win2->win_height <= win1->win_y) + return 0; + return 2; + } + + /* win2 below win1 ? */ + if (win2->win_y == win1->win_y + win1->win_height) + { + if (win2->win_x >= win1->win_x + win1->win_width) + return 0; + if (win2->win_x + win2->win_width <= win1->win_x) + return 0; + return 3; + } + + /* win2 on the left ? */ + if (win2->win_x + win2->win_width + 1 == win1->win_x) + { + if (win2->win_y >= win1->win_y + win1->win_height) + return 0; + if (win2->win_y + win2->win_height <= win1->win_y) + return 0; + return 4; + } + + return 0; +} + +/* + * gui_window_switch_up: search and switch to a window over current window + */ + +void +gui_window_switch_up (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 1)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_down: search and switch to a window below current window + */ + +void +gui_window_switch_down (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 3)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_left: search and switch to a window on the left of current window + */ + +void +gui_window_switch_left (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 4)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_switch_right: search and switch to a window on the right of current window + */ + +void +gui_window_switch_right (t_gui_window *window) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if ((ptr_win != window) && + (gui_window_side_by_side (window, ptr_win) == 2)) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + } +} + +/* + * gui_window_refresh_screen: called when term size is modified + */ + +void +gui_window_refresh_screen () +{ + /* TODO: write this function for Gtk */ +} + +/* + * gui_window_set_title: set terminal title + */ + +void +gui_window_set_title () +{ + /* TODO: write this function for Gtk */ +} + +/* + * gui_window_reset_title: reset terminal title + */ + +void +gui_window_reset_title () +{ + /* This function does nothing in Gtk GUI */ +} diff --git a/weechat/src/gui/gui-action.c b/weechat/src/gui/gui-action.c index 3cedac744..bbdd41cc7 100644 --- a/weechat/src/gui/gui-action.c +++ b/weechat/src/gui/gui-action.c @@ -76,7 +76,7 @@ gui_action_clipboard_paste (t_gui_window *window) { gui_insert_string_input (window, gui_input_clipboard, -1); window->buffer->input_buffer_pos += utf8_strlen (gui_input_clipboard); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -110,7 +110,7 @@ gui_action_return (t_gui_window *window) window->buffer->completion.position = -1; window->buffer->ptr_history = NULL; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); user_command (SERVER(window->buffer), CHANNEL(window->buffer), command, 0); free (command); @@ -231,7 +231,7 @@ gui_action_tab (t_gui_window *window) window->buffer->input_buffer_pos++; } } - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -262,7 +262,7 @@ gui_action_backspace (t_gui_window *window) window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -294,7 +294,7 @@ gui_action_delete (t_gui_window *window) window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -354,7 +354,7 @@ gui_action_delete_previous_word (t_gui_window *window) window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_pos -= length_deleted; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -394,7 +394,7 @@ gui_action_delete_next_word (t_gui_window *window) window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -429,7 +429,7 @@ gui_action_delete_begin_of_line (t_gui_window *window) window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_pos = 0; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -458,7 +458,7 @@ gui_action_delete_end_of_line (t_gui_window *window) window->buffer->input_buffer_size = strlen (window->buffer->input_buffer); window->buffer->input_buffer_length = utf8_strlen (window->buffer->input_buffer); gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -478,7 +478,7 @@ gui_action_delete_line (t_gui_window *window) window->buffer->input_buffer_length = 0; window->buffer->input_buffer_pos = 0; gui_input_optimize_size (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -522,7 +522,7 @@ gui_action_transpose_chars (t_gui_window *window) window->buffer->input_buffer_pos++; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); window->buffer->completion.position = -1; } } @@ -540,7 +540,7 @@ gui_action_home (t_gui_window *window) if (window->buffer->input_buffer_pos > 0) { window->buffer->input_buffer_pos = 0; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -559,7 +559,7 @@ gui_action_end (t_gui_window *window) { window->buffer->input_buffer_pos = window->buffer->input_buffer_length; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -576,7 +576,7 @@ gui_action_left (t_gui_window *window) if (window->buffer->input_buffer_pos > 0) { window->buffer->input_buffer_pos--; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -616,7 +616,7 @@ gui_action_previous_word (t_gui_window *window) else window->buffer->input_buffer_pos = 0; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -634,7 +634,7 @@ gui_action_right (t_gui_window *window) window->buffer->input_buffer_length) { window->buffer->input_buffer_pos++; - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -678,7 +678,7 @@ gui_action_next_word (t_gui_window *window) utf8_pos (window->buffer->input_buffer, utf8_prev_char (window->buffer->input_buffer, pos) - window->buffer->input_buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -703,8 +703,8 @@ gui_action_up (t_gui_window *window) ((t_irc_dcc *)(window->dcc_first))->prev_dcc; window->dcc_selected = ((t_irc_dcc *)(window->dcc_selected))->prev_dcc; - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_input (window->buffer, 1); + gui_chat_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); } } } @@ -756,7 +756,7 @@ gui_action_up (t_gui_window *window) strcpy (window->buffer->input_buffer, window->buffer->ptr_history->text); gui_input_init_color_mask (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -791,7 +791,7 @@ gui_action_up_global (t_gui_window *window) strcpy (window->buffer->input_buffer, history_global_ptr->text); gui_input_init_color_mask (window->buffer); - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -827,8 +827,8 @@ gui_action_down (t_gui_window *window) else window->dcc_selected = dcc_list->next_dcc; - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_input (window->buffer, 1); + gui_chat_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); } } } @@ -860,7 +860,7 @@ gui_action_down (t_gui_window *window) window->buffer->ptr_history->text); gui_input_init_color_mask (window->buffer); } - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -899,7 +899,7 @@ gui_action_down_global (t_gui_window *window) history_global_ptr->text); gui_input_init_color_mask (window->buffer); } - gui_draw_buffer_input (window->buffer, 0); + gui_input_draw (window->buffer, 0); } } } @@ -1015,15 +1015,15 @@ gui_action_jump_smart (t_gui_window *window) { if (!hotlist_initial_buffer) hotlist_initial_buffer = window->buffer; - gui_switch_to_buffer (window, hotlist->buffer); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, hotlist->buffer); + gui_window_redraw_buffer (window->buffer); } else { if (hotlist_initial_buffer) { - gui_switch_to_buffer (window, hotlist_initial_buffer); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, hotlist_initial_buffer); + gui_window_redraw_buffer (window->buffer); hotlist_initial_buffer = NULL; } } @@ -1040,9 +1040,9 @@ gui_action_jump_dcc (t_gui_window *window) { if (gui_buffer_before_dcc) { - gui_switch_to_buffer (window, - gui_buffer_before_dcc); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, + gui_buffer_before_dcc); + gui_window_redraw_buffer (window->buffer); } } else @@ -1063,9 +1063,9 @@ gui_action_jump_raw_data (t_gui_window *window) { if (gui_buffer_before_raw_data) { - gui_switch_to_buffer (window, - gui_buffer_before_raw_data); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, + gui_buffer_before_raw_data); + gui_window_redraw_buffer (window->buffer); } } else @@ -1098,9 +1098,9 @@ gui_action_jump_server (t_gui_window *window) if (SERVER(window->buffer)->buffer != window->buffer) { - gui_switch_to_buffer (window, - SERVER(window->buffer)->buffer); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, + SERVER(window->buffer)->buffer); + gui_window_redraw_buffer (window->buffer); } } } @@ -1141,8 +1141,8 @@ gui_action_jump_next_server (t_gui_window *window) if ((ptr_server->buffer == ptr_buffer) && (ptr_buffer->all_servers)) ptr_buffer->server = ptr_server; - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (window->buffer); + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (window->buffer); } } } @@ -1181,8 +1181,8 @@ gui_action_scroll_previous_highlight (t_gui_window *window) window->start_line_pos = 0; window->first_line_displayed = (window->start_line == window->buffer->lines); - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_status (window->buffer, 0); + gui_chat_draw (window->buffer, 1); + gui_status_draw (window->buffer, 0); return; } ptr_line = ptr_line->prev_line; @@ -1214,8 +1214,8 @@ gui_action_scroll_next_highlight (t_gui_window *window) window->start_line_pos = 0; window->first_line_displayed = (window->start_line == window->buffer->lines); - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_status (window->buffer, 0); + gui_chat_draw (window->buffer, 1); + gui_status_draw (window->buffer, 0); return; } ptr_line = ptr_line->next_line; @@ -1241,8 +1241,8 @@ gui_action_scroll_unread (t_gui_window *window) window->start_line_pos = 0; window->first_line_displayed = (window->start_line == window->buffer->lines); - gui_draw_buffer_chat (window->buffer, 1); - gui_draw_buffer_status (window->buffer, 0); + gui_chat_draw (window->buffer, 1); + gui_status_draw (window->buffer, 0); } } @@ -1256,7 +1256,7 @@ gui_action_hotlist_clear (t_gui_window *window) if (hotlist) { hotlist_free_all (); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); } hotlist_initial_buffer = window->buffer; } @@ -1269,7 +1269,7 @@ void gui_action_infobar_clear (t_gui_window *window) { gui_infobar_remove (); - gui_draw_buffer_infobar (window->buffer, 1); + gui_infobar_draw (window->buffer, 1); } /* @@ -1282,7 +1282,7 @@ gui_action_refresh_screen (t_gui_window *window) /* make gcc happy */ (void) window; - gui_refresh_screen (); + gui_window_refresh_screen (); } /* diff --git a/weechat/src/gui/gui-buffer.c b/weechat/src/gui/gui-buffer.c new file mode 100644 index 000000000..3f7107bc3 --- /dev/null +++ b/weechat/src/gui/gui-buffer.c @@ -0,0 +1,932 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-window.c: window functions, used by all GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../common/weechat.h" +#include "gui.h" +#include "../common/command.h" +#include "../common/weeconfig.h" +#include "../common/history.h" +#include "../common/hotlist.h" +#include "../common/log.h" +#include "../common/utf8.h" +#include "../irc/irc.h" + + +/* + * gui_buffer_servers_search: search servers buffer + * (when same buffer is used for all servers) + */ + +t_gui_buffer * +gui_buffer_servers_search () +{ + t_gui_buffer *ptr_buffer; + + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->all_servers) + return ptr_buffer; + } + + /* buffer not found */ + return NULL; +} + +/* + * gui_buffer_new: create a new buffer in current window + */ + +t_gui_buffer * +gui_buffer_new (t_gui_window *window, void *server, void *channel, int type, + int switch_to_buffer) +{ + t_gui_buffer *new_buffer, *ptr_buffer; + +#ifdef DEBUG + weechat_log_printf ("Creating new buffer\n"); +#endif + + /* use first buffer if no server was assigned to this buffer */ + if ((type == BUFFER_TYPE_STANDARD) && gui_buffers && (!SERVER(gui_buffers))) + { + if (server) + ((t_irc_server *)(server))->buffer = gui_buffers; + if (channel) + ((t_irc_channel *)(channel))->buffer = gui_buffers; + gui_buffers->server = server; + gui_buffers->channel = channel; + if (cfg_look_one_server_buffer && server && !channel) + gui_buffers->all_servers = 1; + if (cfg_log_auto_server) + log_start (gui_buffers); + return gui_buffers; + } + + if (cfg_look_one_server_buffer && (type == BUFFER_TYPE_STANDARD) && + gui_buffers && server && !channel) + { + ptr_buffer = gui_buffer_servers_search (); + if (ptr_buffer) + { + ((t_irc_server *)(server))->buffer = gui_buffers; + gui_buffers->server = server; + if (switch_to_buffer) + gui_window_switch_to_buffer (window, gui_buffers); + gui_window_redraw_buffer (gui_buffers); + return gui_buffers; + } + } + + if ((new_buffer = (t_gui_buffer *)(malloc (sizeof (t_gui_buffer))))) + { + new_buffer->num_displayed = 0; + new_buffer->number = (last_gui_buffer) ? last_gui_buffer->number + 1 : 1; + + /* assign server and channel to buffer */ + new_buffer->server = server; + new_buffer->all_servers = 0; + new_buffer->channel = channel; + new_buffer->type = type; + if (new_buffer->type == BUFFER_TYPE_RAW_DATA) + gui_buffer_raw_data = new_buffer; + /* assign buffer to server and channel */ + if (server && !channel) + { + SERVER(new_buffer)->buffer = new_buffer; + new_buffer->all_servers = (cfg_look_one_server_buffer) ? 1 : 0; + } + if (!gui_buffers && cfg_look_one_server_buffer) + new_buffer->all_servers = 1; + if (channel) + CHANNEL(new_buffer)->buffer = new_buffer; + + if (!window->buffer) + { + window->buffer = new_buffer; + window->first_line_displayed = 1; + window->start_line = NULL; + window->start_line_pos = 0; + gui_window_calculate_pos_size (window, 1); + gui_window_init_subwindows (window); + } + + /* init lines */ + new_buffer->lines = NULL; + new_buffer->last_line = NULL; + new_buffer->last_read_line = NULL; + new_buffer->num_lines = 0; + new_buffer->line_complete = 1; + + /* notify level */ + new_buffer->notify_level = channel_get_notify_level (server, channel); + + /* create/append to log file */ + new_buffer->log_filename = NULL; + new_buffer->log_file = NULL; + if ((cfg_log_auto_server && BUFFER_IS_SERVER(new_buffer)) + || (cfg_log_auto_channel && BUFFER_IS_CHANNEL(new_buffer)) + || (cfg_log_auto_private && BUFFER_IS_PRIVATE(new_buffer))) + log_start (new_buffer); + + /* init input buffer */ + new_buffer->has_input = (new_buffer->type == BUFFER_TYPE_STANDARD) ? 1 : 0; + if (new_buffer->has_input) + { + new_buffer->input_buffer_alloc = INPUT_BUFFER_BLOCK_SIZE; + new_buffer->input_buffer = (char *) malloc (INPUT_BUFFER_BLOCK_SIZE); + new_buffer->input_buffer_color_mask = (char *) malloc (INPUT_BUFFER_BLOCK_SIZE); + new_buffer->input_buffer[0] = '\0'; + new_buffer->input_buffer_color_mask[0] = '\0'; + } + else + { + new_buffer->input_buffer = NULL; + new_buffer->input_buffer_color_mask = NULL; + } + new_buffer->input_buffer_size = 0; + new_buffer->input_buffer_length = 0; + new_buffer->input_buffer_pos = 0; + new_buffer->input_buffer_1st_display = 0; + + /* init completion */ + completion_init (&(new_buffer->completion), server, channel); + + /* init history */ + new_buffer->history = NULL; + new_buffer->last_history = NULL; + new_buffer->ptr_history = NULL; + new_buffer->num_history = 0; + + /* add buffer to buffers queue */ + new_buffer->prev_buffer = last_gui_buffer; + if (gui_buffers) + last_gui_buffer->next_buffer = new_buffer; + else + gui_buffers = new_buffer; + last_gui_buffer = new_buffer; + new_buffer->next_buffer = NULL; + + /* move buffer next to server */ + if (server && cfg_look_open_near_server && (!cfg_look_one_server_buffer)) + { + ptr_buffer = SERVER(new_buffer)->buffer; + while (ptr_buffer && (ptr_buffer->server == server)) + { + ptr_buffer = ptr_buffer->next_buffer; + } + if (ptr_buffer) + gui_buffer_move_to_number (new_buffer, ptr_buffer->number); + } + + /* switch to new buffer */ + if (switch_to_buffer) + gui_window_switch_to_buffer (window, new_buffer); + + /* redraw buffer */ + gui_window_redraw_buffer (new_buffer); + } + else + return NULL; + + return new_buffer; +} + +/* + * gui_buffer_search: search a buffer by server and channel name + */ + +t_gui_buffer * +gui_buffer_search (char *server, char *channel) +{ + t_irc_server *ptr_server; + t_irc_channel *ptr_channel; + t_gui_buffer *ptr_buffer; + + ptr_server = NULL; + ptr_channel = NULL; + ptr_buffer = NULL; + + /* nothing given => print on current buffer */ + if ((!server || !server[0]) && (!channel || !channel[0])) + ptr_buffer = gui_current_window->buffer; + else + { + if (server && server[0]) + { + ptr_server = server_search (server); + if (!ptr_server) + return NULL; + } + else + { + ptr_server = SERVER(gui_current_window->buffer); + if (!ptr_server) + ptr_server = SERVER(gui_buffers); + } + + if (channel && channel[0]) + { + if (ptr_server) + { + ptr_channel = channel_search_any (ptr_server, channel); + if (ptr_channel) + ptr_buffer = ptr_channel->buffer; + } + } + else + { + if (ptr_server) + ptr_buffer = ptr_server->buffer; + else + ptr_buffer = gui_current_window->buffer; + } + } + + if (!ptr_buffer) + return NULL; + + return (ptr_buffer->type != BUFFER_TYPE_STANDARD) ? + gui_buffers : ptr_buffer; +} + +/* + * gui_buffer_find_window: find a window displaying buffer + */ + +t_gui_window * +gui_buffer_find_window (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + + if (gui_current_window->buffer == buffer) + return gui_current_window; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + return ptr_win; + } + + /* no window found */ + return NULL; +} + +/* + * gui_buffer_get_dcc: get pointer to DCC buffer (DCC buffer created if not existing) + */ + +t_gui_buffer * +gui_buffer_get_dcc (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + + /* check if dcc buffer exists */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->type == BUFFER_TYPE_DCC) + break; + } + if (ptr_buffer) + return ptr_buffer; + else + return gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_DCC, 0); +} + +/* + * gui_buffer_clear: clear buffer content + */ + +void +gui_buffer_clear (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + t_gui_line *ptr_line; + + /* remove buffer from hotlist */ + hotlist_remove_buffer (buffer); + + /* remove lines from buffer */ + while (buffer->lines) + { + ptr_line = buffer->lines->next_line; + if (buffer->lines->data) + free (buffer->lines->data); + free (buffer->lines); + buffer->lines = ptr_line; + } + + buffer->lines = NULL; + buffer->last_line = NULL; + buffer->num_lines = 0; + buffer->line_complete = 1; + + /* remove any scroll for buffer */ + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + { + ptr_win->first_line_displayed = 1; + ptr_win->start_line = NULL; + ptr_win->start_line_pos = 0; + } + } + + gui_chat_draw (buffer, 1); + gui_status_draw (buffer, 1); +} + +/* + * gui_buffer_clear_all: clear all buffers content + */ + +void +gui_buffer_clear_all () +{ + t_gui_buffer *ptr_buffer; + + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + gui_buffer_clear (ptr_buffer); +} + +/* + * gui_buffer_line_free: delete a line from a buffer + */ + +void +gui_buffer_line_free (t_gui_line *line) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->start_line == line) + { + ptr_win->start_line = ptr_win->start_line->next_line; + ptr_win->start_line_pos = 0; + gui_chat_draw (ptr_win->buffer, 0); + gui_status_draw (ptr_win->buffer, 0); + } + } + if (line->nick) + free (line->nick); + if (line->data) + free (line->data); + free (line); +} + +/* + * gui_buffer_free: delete a buffer + */ + +void +gui_buffer_free (t_gui_buffer *buffer, int switch_to_another) +{ + t_gui_window *ptr_win; + t_gui_buffer *ptr_buffer; + t_gui_line *ptr_line; + t_irc_server *ptr_server; + int create_new; + + create_new = (buffer->server || buffer->channel); + + hotlist_remove_buffer (buffer); + if (hotlist_initial_buffer == buffer) + hotlist_initial_buffer = NULL; + + if (gui_buffer_before_dcc == buffer) + gui_buffer_before_dcc = NULL; + + if (gui_buffer_before_raw_data == buffer) + gui_buffer_before_raw_data = NULL; + + if (buffer->type == BUFFER_TYPE_RAW_DATA) + gui_buffer_raw_data = NULL; + + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (ptr_server->saved_buffer == buffer) + ptr_server->saved_buffer = NULL; + } + + if (switch_to_another) + { + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if ((buffer == ptr_win->buffer) && + ((buffer->next_buffer) || (buffer->prev_buffer))) + gui_buffer_switch_previous (ptr_win); + } + } + + /* decrease buffer number for all next buffers */ + for (ptr_buffer = buffer->next_buffer; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + ptr_buffer->number--; + } + + /* free lines and messages */ + while (buffer->lines) + { + ptr_line = buffer->lines->next_line; + gui_buffer_line_free (buffer->lines); + buffer->lines = ptr_line; + } + + /* close log if opened */ + if (buffer->log_file) + log_end (buffer); + + if (buffer->input_buffer) + free (buffer->input_buffer); + if (buffer->input_buffer_color_mask) + free (buffer->input_buffer_color_mask); + + completion_free (&(buffer->completion)); + + history_buffer_free (buffer); + + /* remove buffer from buffers list */ + if (buffer->prev_buffer) + buffer->prev_buffer->next_buffer = buffer->next_buffer; + if (buffer->next_buffer) + buffer->next_buffer->prev_buffer = buffer->prev_buffer; + if (gui_buffers == buffer) + gui_buffers = buffer->next_buffer; + if (last_gui_buffer == buffer) + last_gui_buffer = buffer->prev_buffer; + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + ptr_win->buffer = NULL; + } + + free (buffer); + + /* always at least one buffer */ + if (!gui_buffers && create_new && switch_to_another) + (void) gui_buffer_new (gui_windows, NULL, NULL, + BUFFER_TYPE_STANDARD, 1); +} + +/* + * gui_buffer_line_new: create new line for a buffer + */ + +t_gui_line * +gui_buffer_line_new (t_gui_buffer *buffer) +{ + t_gui_line *new_line, *ptr_line; + + if ((new_line = (t_gui_line *) malloc (sizeof (struct t_gui_line)))) + { + new_line->length = 0; + new_line->length_align = 0; + new_line->log_write = 1; + new_line->line_with_message = 0; + new_line->line_with_highlight = 0; + new_line->nick = NULL; + new_line->data = NULL; + new_line->ofs_after_date = -1; + new_line->ofs_start_message = -1; + if (!buffer->lines) + buffer->lines = new_line; + else + buffer->last_line->next_line = new_line; + new_line->prev_line = buffer->last_line; + new_line->next_line = NULL; + buffer->last_line = new_line; + buffer->num_lines++; + } + else + { + weechat_log_printf (_("Not enough memory for new line\n")); + return NULL; + } + + /* remove one line if necessary */ + if ((cfg_history_max_lines > 0) + && (buffer->num_lines > cfg_history_max_lines)) + { + if (buffer->last_line == buffer->lines) + buffer->last_line = NULL; + ptr_line = buffer->lines->next_line; + gui_buffer_line_free (buffer->lines); + buffer->lines = ptr_line; + ptr_line->prev_line = NULL; + buffer->num_lines--; + gui_chat_draw (buffer, 1); + } + + return new_line; +} + +/* + * gui_buffer_merge_servers: merge server buffers in one buffer + */ + +void +gui_buffer_merge_servers (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer_server, *ptr_buffer; + t_irc_server *ptr_server; + + /* new server buffer is the first server buffer found */ + for (ptr_buffer_server = gui_buffers; ptr_buffer_server; + ptr_buffer_server = ptr_buffer_server->next_buffer) + { + if (BUFFER_IS_SERVER(ptr_buffer_server)) + break; + } + + /* no server buffer found */ + if (!ptr_buffer_server) + return; + + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if ((ptr_buffer != ptr_buffer_server) + && (BUFFER_IS_SERVER(ptr_buffer))) + { + ptr_server = SERVER(ptr_buffer); + + /* add (by pointer artefact) lines from buffer found to server buffer */ + if (ptr_buffer->lines) + { + if (ptr_buffer_server->lines) + { + ptr_buffer->lines->prev_line = + ptr_buffer_server->last_line; + ptr_buffer_server->last_line->next_line = + ptr_buffer->lines; + ptr_buffer_server->last_line = + ptr_buffer->last_line; + } + else + { + ptr_buffer_server->lines = ptr_buffer->lines; + ptr_buffer_server->last_line = ptr_buffer->last_line; + } + } + + /* free buffer but not lines, because they're now used by + our unique server buffer */ + ptr_buffer->lines = NULL; + gui_buffer_free (ptr_buffer, 1); + + /* asociate server with new server buffer */ + ptr_server->buffer = ptr_buffer_server; + } + } + + ptr_buffer_server->all_servers = 1; + gui_window_redraw_buffer (window->buffer); +} + +/* + * gui_buffer_split_server: split the server buffer into many buffers (one by server) + */ + +void +gui_buffer_split_server (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + t_irc_server *ptr_server; + + ptr_buffer = gui_buffer_servers_search (); + + if (ptr_buffer) + { + if (SERVER(ptr_buffer)) + { + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (ptr_server->buffer + && (ptr_server != SERVER(ptr_buffer)) + && (ptr_server->buffer == ptr_buffer)) + { + ptr_server->buffer = NULL; + gui_buffer_new (window, ptr_server, NULL, + BUFFER_TYPE_STANDARD, 0); + } + } + } + ptr_buffer->all_servers = 0; + gui_status_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); + } +} + +/* + * gui_buffer_switch_previous: switch to previous buffer + */ + +void +gui_buffer_switch_previous (t_gui_window *window) +{ + if (!gui_ok) + return; + + /* if only one buffer then return */ + if (gui_buffers == last_gui_buffer) + return; + + if (window->buffer->prev_buffer) + gui_window_switch_to_buffer (window, window->buffer->prev_buffer); + else + gui_window_switch_to_buffer (window, last_gui_buffer); + + gui_window_redraw_buffer (window->buffer); +} + +/* + * gui_buffer_switch_next: switch to next buffer + */ + +void +gui_buffer_switch_next (t_gui_window *window) +{ + if (!gui_ok) + return; + + /* if only one buffer then return */ + if (gui_buffers == last_gui_buffer) + return; + + if (window->buffer->next_buffer) + gui_window_switch_to_buffer (window, window->buffer->next_buffer); + else + gui_window_switch_to_buffer (window, gui_buffers); + + gui_window_redraw_buffer (window->buffer); +} + +/* + * gui_buffer_switch_dcc: switch to dcc buffer (create it if it does not exist) + */ + +void +gui_buffer_switch_dcc (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + + /* check if dcc buffer exists */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->type == BUFFER_TYPE_DCC) + break; + } + if (ptr_buffer) + { + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (ptr_buffer); + } + else + gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_DCC, 1); +} + +/* + * gui_buffer_switch_raw_data: switch to rax IRC data buffer (create it if it does not exist) + */ + +void +gui_buffer_switch_raw_data (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + + /* check if raw IRC data buffer exists */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->type == BUFFER_TYPE_RAW_DATA) + break; + } + if (ptr_buffer) + { + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (ptr_buffer); + } + else + gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_RAW_DATA, 1); +} + +/* + * gui_buffer_switch_by_number: switch to another buffer with number + */ + +t_gui_buffer * +gui_buffer_switch_by_number (t_gui_window *window, int number) +{ + t_gui_buffer *ptr_buffer; + + /* invalid buffer */ + if (number < 0) + return NULL; + + /* buffer is currently displayed ? */ + if (number == window->buffer->number) + return window->buffer; + + /* search for buffer in the list */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if ((ptr_buffer != window->buffer) && (number == ptr_buffer->number)) + { + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (window->buffer); + return ptr_buffer; + } + } + + /* buffer not found */ + return NULL; +} + +/* + * gui_buffer_move_to_number: move a buffer to another number + */ + +void +gui_buffer_move_to_number (t_gui_buffer *buffer, int number) +{ + t_gui_buffer *ptr_buffer; + int i; + + /* if only one buffer then return */ + if (gui_buffers == last_gui_buffer) + return; + + /* buffer number is already ok ? */ + if (number == buffer->number) + return; + + if (number < 1) + number = 1; + + /* remove buffer from list */ + if (buffer == gui_buffers) + { + gui_buffers = buffer->next_buffer; + gui_buffers->prev_buffer = NULL; + } + if (buffer == last_gui_buffer) + { + last_gui_buffer = buffer->prev_buffer; + last_gui_buffer->next_buffer = NULL; + } + if (buffer->prev_buffer) + (buffer->prev_buffer)->next_buffer = buffer->next_buffer; + if (buffer->next_buffer) + (buffer->next_buffer)->prev_buffer = buffer->prev_buffer; + + if (number == 1) + { + gui_buffers->prev_buffer = buffer; + buffer->prev_buffer = NULL; + buffer->next_buffer = gui_buffers; + gui_buffers = buffer; + } + else + { + /* assign new number to all buffers */ + i = 1; + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + ptr_buffer->number = i++; + } + + /* search for new position in the list */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->number == number) + break; + } + if (ptr_buffer) + { + /* insert before buffer found */ + buffer->prev_buffer = ptr_buffer->prev_buffer; + buffer->next_buffer = ptr_buffer; + if (ptr_buffer->prev_buffer) + (ptr_buffer->prev_buffer)->next_buffer = buffer; + ptr_buffer->prev_buffer = buffer; + } + else + { + /* number not found (too big)? => add to end */ + buffer->prev_buffer = last_gui_buffer; + buffer->next_buffer = NULL; + last_gui_buffer->next_buffer = buffer; + last_gui_buffer = buffer; + } + + } + + /* assign new number to all buffers */ + i = 1; + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + ptr_buffer->number = i++; + } + + gui_window_redraw_buffer (buffer); +} + +/* + * gui_buffer_print_log: print buffer infos in log (usually for crash dump) + */ + +void +gui_buffer_print_log (t_gui_buffer *buffer) +{ + t_gui_line *ptr_line; + int num; + + weechat_log_printf ("[buffer (addr:0x%X)]\n", buffer); + weechat_log_printf (" num_displayed. . . . . : %d\n", buffer->num_displayed); + weechat_log_printf (" number . . . . . . . . : %d\n", buffer->number); + weechat_log_printf (" server . . . . . . . . : 0x%X\n", buffer->server); + weechat_log_printf (" all_servers. . . . . . : %d\n", buffer->all_servers); + weechat_log_printf (" channel. . . . . . . . : 0x%X\n", buffer->channel); + weechat_log_printf (" type . . . . . . . . . : %d\n", buffer->type); + weechat_log_printf (" lines. . . . . . . . . : 0x%X\n", buffer->lines); + weechat_log_printf (" last_line. . . . . . . : 0x%X\n", buffer->last_line); + weechat_log_printf (" last_read_line . . . . : 0x%X\n", buffer->last_read_line); + weechat_log_printf (" num_lines. . . . . . . : %d\n", buffer->num_lines); + weechat_log_printf (" line_complete. . . . . : %d\n", buffer->line_complete); + weechat_log_printf (" notify_level . . . . . : %d\n", buffer->notify_level); + weechat_log_printf (" log_filename . . . . . : '%s'\n", buffer->log_filename); + weechat_log_printf (" log_file . . . . . . . : 0x%X\n", buffer->log_file); + weechat_log_printf (" has_input. . . . . . . : %d\n", buffer->has_input); + weechat_log_printf (" input_buffer . . . . . : '%s'\n", buffer->input_buffer); + weechat_log_printf (" input_buffer_color_mask: '%s'\n", buffer->input_buffer_color_mask); + weechat_log_printf (" input_buffer_alloc . . : %d\n", buffer->input_buffer_alloc); + weechat_log_printf (" input_buffer_size. . . : %d\n", buffer->input_buffer_size); + weechat_log_printf (" input_buffer_length. . : %d\n", buffer->input_buffer_length); + weechat_log_printf (" input_buffer_pos . . . : %d\n", buffer->input_buffer_pos); + weechat_log_printf (" input_buffer_1st_disp. : %d\n", buffer->input_buffer_1st_display); + weechat_log_printf (" history. . . . . . . . : 0x%X\n", buffer->history); + weechat_log_printf (" last_history . . . . . : 0x%X\n", buffer->last_history); + weechat_log_printf (" ptr_history. . . . . . : 0x%X\n", buffer->ptr_history); + weechat_log_printf (" prev_buffer. . . . . . : 0x%X\n", buffer->prev_buffer); + weechat_log_printf (" next_buffer. . . . . . : 0x%X\n", buffer->next_buffer); + weechat_log_printf ("\n"); + weechat_log_printf (" => last 100 lines:\n"); + + num = 0; + ptr_line = buffer->last_line; + while (ptr_line && (num < 100)) + { + num++; + ptr_line = ptr_line->prev_line; + } + if (!ptr_line) + ptr_line = buffer->lines; + else + ptr_line = ptr_line->next_line; + + while (ptr_line) + { + num--; + weechat_log_printf (" line N-%05d: %s\n", + num, + (ptr_line->data) ? ptr_line->data : "(empty)"); + + ptr_line = ptr_line->next_line; + } +} diff --git a/weechat/src/gui/gui-common.c b/weechat/src/gui/gui-common.c index 50066f1a3..12fb81d4c 100644 --- a/weechat/src/gui/gui-common.c +++ b/weechat/src/gui/gui-common.c @@ -69,742 +69,6 @@ time_t gui_last_activity_time = 0; /* last activity time */ /* (key pressed) */ -/* - * gui_window_tree_init: create first entry in windows tree - */ - -int -gui_window_tree_init (t_gui_window *window) -{ - gui_windows_tree = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); - if (!gui_windows_tree) - return 0; - gui_windows_tree->parent_node = NULL; - gui_windows_tree->split_horiz = 0; - gui_windows_tree->split_pct = 0; - gui_windows_tree->child1 = NULL; - gui_windows_tree->child2 = NULL; - gui_windows_tree->window = window; - return 1; -} - -/* - * gui_window_tree_node_to_leaf: convert a node to a leaf (free any leafs) - * Called when 2 windows are merging into one - */ - -void -gui_window_tree_node_to_leaf (t_gui_window_tree *node, t_gui_window *window) -{ - node->split_horiz = 0; - node->split_pct = 0; - if (node->child1) - { - free (node->child1); - node->child1 = NULL; - } - if (node->child2) - { - free (node->child2); - node->child2 = NULL; - } - node->window = window; - window->ptr_tree = node; -} - -/* - * gui_window_tree_free: delete entire windows tree - */ - -void -gui_window_tree_free (t_gui_window_tree **tree) -{ - if (*tree) - { - if ((*tree)->child1) - gui_window_tree_free (&((*tree)->child1)); - if ((*tree)->child2) - gui_window_tree_free (&((*tree)->child2)); - free (*tree); - *tree = NULL; - } -} - -/* - * gui_window_new: create a new window - */ - -t_gui_window * -gui_window_new (t_gui_window *parent, int x, int y, int width, int height, - int width_pct, int height_pct) -{ - t_gui_window *new_window; - t_gui_window_tree *ptr_tree, *child1, *child2, *ptr_leaf; - -#ifdef DEBUG - weechat_log_printf ("Creating new window (x:%d, y:%d, width:%d, height:%d)\n", - x, y, width, height); -#endif - - if (parent) - { - child1 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); - if (!child1) - return NULL; - child2 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); - if (!child2) - { - free (child1); - return NULL; - } - ptr_tree = parent->ptr_tree; - - if (width_pct == 100) - { - ptr_tree->split_horiz = 1; - ptr_tree->split_pct = height_pct; - } - else - { - ptr_tree->split_horiz = 0; - ptr_tree->split_pct = width_pct; - } - - /* parent window leaf becomes node and we add 2 leafs below - (#1 is parent win, #2 is new win) */ - - parent->ptr_tree = child1; - child1->parent_node = ptr_tree; - child1->child1 = NULL; - child1->child2 = NULL; - child1->window = ptr_tree->window; - - child2->parent_node = ptr_tree; - child2->child1 = NULL; - child2->child2 = NULL; - child2->window = NULL; /* will be assigned by new window below */ - - ptr_tree->child1 = child1; - ptr_tree->child2 = child2; - ptr_tree->window = NULL; /* leaf becomes node */ - - ptr_leaf = child2; - } - else - { - if (!gui_window_tree_init (NULL)) - return NULL; - ptr_leaf = gui_windows_tree; - } - - if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window))))) - { - new_window->win_x = x; - new_window->win_y = y; - new_window->win_width = width; - new_window->win_height = height; - new_window->win_width_pct = width_pct; - new_window->win_height_pct = height_pct; - - new_window->new_x = -1; - new_window->new_y = -1; - new_window->new_width = -1; - new_window->new_height = -1; - - new_window->win_chat_x = 0; - new_window->win_chat_y = 0; - new_window->win_chat_width = 0; - new_window->win_chat_height = 0; - new_window->win_chat_cursor_x = 0; - new_window->win_chat_cursor_y = 0; - - new_window->win_nick_x = 0; - new_window->win_nick_y = 0; - new_window->win_nick_width = 0; - new_window->win_nick_height = 0; - new_window->win_nick_num_max = 0; - new_window->win_nick_start = 0; - - new_window->win_input_x = 0; - - new_window->win_title = NULL; - new_window->win_chat = NULL; - new_window->win_nick = NULL; - new_window->win_status = NULL; - new_window->win_infobar = NULL; - new_window->win_input = NULL; - new_window->win_separator = NULL; - - new_window->textview_chat = NULL; - new_window->textbuffer_chat = NULL; - new_window->texttag_chat = NULL; - new_window->textview_nicklist = NULL; - new_window->textbuffer_nicklist = NULL; - - new_window->dcc_first = NULL; - new_window->dcc_selected = NULL; - new_window->dcc_last_displayed = NULL; - - new_window->buffer = NULL; - - new_window->first_line_displayed = 0; - new_window->start_line = NULL; - new_window->start_line_pos = 0; - new_window->scroll = 0; - - new_window->ptr_tree = ptr_leaf; - ptr_leaf->window = new_window; - - /* add window to windows queue */ - new_window->prev_window = last_gui_window; - if (gui_windows) - last_gui_window->next_window = new_window; - else - gui_windows = new_window; - last_gui_window = new_window; - new_window->next_window = NULL; - } - else - return NULL; - - return new_window; -} - -/* - * gui_buffer_servers_search: search servers buffer - * (when same buffer is used for all servers) - */ - -t_gui_buffer * -gui_buffer_servers_search () -{ - t_gui_buffer *ptr_buffer; - - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->all_servers) - return ptr_buffer; - } - - /* buffer not found */ - return NULL; -} - -/* - * gui_buffer_new: create a new buffer in current window - */ - -t_gui_buffer * -gui_buffer_new (t_gui_window *window, void *server, void *channel, int type, - int switch_to_buffer) -{ - t_gui_buffer *new_buffer, *ptr_buffer; - -#ifdef DEBUG - weechat_log_printf ("Creating new buffer\n"); -#endif - - /* use first buffer if no server was assigned to this buffer */ - if ((type == BUFFER_TYPE_STANDARD) && gui_buffers && (!SERVER(gui_buffers))) - { - if (server) - ((t_irc_server *)(server))->buffer = gui_buffers; - if (channel) - ((t_irc_channel *)(channel))->buffer = gui_buffers; - gui_buffers->server = server; - gui_buffers->channel = channel; - if (cfg_look_one_server_buffer && server && !channel) - gui_buffers->all_servers = 1; - if (cfg_log_auto_server) - log_start (gui_buffers); - return gui_buffers; - } - - if (cfg_look_one_server_buffer && (type == BUFFER_TYPE_STANDARD) && - gui_buffers && server && !channel) - { - ptr_buffer = gui_buffer_servers_search (); - if (ptr_buffer) - { - ((t_irc_server *)(server))->buffer = gui_buffers; - gui_buffers->server = server; - if (switch_to_buffer) - gui_switch_to_buffer (window, gui_buffers); - gui_redraw_buffer (gui_buffers); - return gui_buffers; - } - } - - if ((new_buffer = (t_gui_buffer *)(malloc (sizeof (t_gui_buffer))))) - { - new_buffer->num_displayed = 0; - new_buffer->number = (last_gui_buffer) ? last_gui_buffer->number + 1 : 1; - - /* assign server and channel to buffer */ - new_buffer->server = server; - new_buffer->all_servers = 0; - new_buffer->channel = channel; - new_buffer->type = type; - if (new_buffer->type == BUFFER_TYPE_RAW_DATA) - gui_buffer_raw_data = new_buffer; - /* assign buffer to server and channel */ - if (server && !channel) - { - SERVER(new_buffer)->buffer = new_buffer; - new_buffer->all_servers = (cfg_look_one_server_buffer) ? 1 : 0; - } - if (!gui_buffers && cfg_look_one_server_buffer) - new_buffer->all_servers = 1; - if (channel) - CHANNEL(new_buffer)->buffer = new_buffer; - - if (!window->buffer) - { - window->buffer = new_buffer; - window->first_line_displayed = 1; - window->start_line = NULL; - window->start_line_pos = 0; - gui_calculate_pos_size (window, 1); - gui_window_init_subwindows (window); - } - - /* init lines */ - new_buffer->lines = NULL; - new_buffer->last_line = NULL; - new_buffer->last_read_line = NULL; - new_buffer->num_lines = 0; - new_buffer->line_complete = 1; - - /* notify level */ - new_buffer->notify_level = channel_get_notify_level (server, channel); - - /* create/append to log file */ - new_buffer->log_filename = NULL; - new_buffer->log_file = NULL; - if ((cfg_log_auto_server && BUFFER_IS_SERVER(new_buffer)) - || (cfg_log_auto_channel && BUFFER_IS_CHANNEL(new_buffer)) - || (cfg_log_auto_private && BUFFER_IS_PRIVATE(new_buffer))) - log_start (new_buffer); - - /* init input buffer */ - new_buffer->has_input = (new_buffer->type == BUFFER_TYPE_STANDARD) ? 1 : 0; - if (new_buffer->has_input) - { - new_buffer->input_buffer_alloc = INPUT_BUFFER_BLOCK_SIZE; - new_buffer->input_buffer = (char *) malloc (INPUT_BUFFER_BLOCK_SIZE); - new_buffer->input_buffer_color_mask = (char *) malloc (INPUT_BUFFER_BLOCK_SIZE); - new_buffer->input_buffer[0] = '\0'; - new_buffer->input_buffer_color_mask[0] = '\0'; - } - else - { - new_buffer->input_buffer = NULL; - new_buffer->input_buffer_color_mask = NULL; - } - new_buffer->input_buffer_size = 0; - new_buffer->input_buffer_length = 0; - new_buffer->input_buffer_pos = 0; - new_buffer->input_buffer_1st_display = 0; - - /* init completion */ - completion_init (&(new_buffer->completion), server, channel); - - /* init history */ - new_buffer->history = NULL; - new_buffer->last_history = NULL; - new_buffer->ptr_history = NULL; - new_buffer->num_history = 0; - - /* add buffer to buffers queue */ - new_buffer->prev_buffer = last_gui_buffer; - if (gui_buffers) - last_gui_buffer->next_buffer = new_buffer; - else - gui_buffers = new_buffer; - last_gui_buffer = new_buffer; - new_buffer->next_buffer = NULL; - - /* move buffer next to server */ - if (server && cfg_look_open_near_server && (!cfg_look_one_server_buffer)) - { - ptr_buffer = SERVER(new_buffer)->buffer; - while (ptr_buffer && (ptr_buffer->server == server)) - { - ptr_buffer = ptr_buffer->next_buffer; - } - if (ptr_buffer) - gui_buffer_move_to_number (new_buffer, ptr_buffer->number); - } - - /* switch to new buffer */ - if (switch_to_buffer) - gui_switch_to_buffer (window, new_buffer); - - /* redraw buffer */ - gui_redraw_buffer (new_buffer); - } - else - return NULL; - - return new_buffer; -} - -/* - * gui_buffer_search: search a buffer by server and channel name - */ - -t_gui_buffer * -gui_buffer_search (char *server, char *channel) -{ - t_irc_server *ptr_server; - t_irc_channel *ptr_channel; - t_gui_buffer *ptr_buffer; - - ptr_server = NULL; - ptr_channel = NULL; - ptr_buffer = NULL; - - /* nothing given => print on current buffer */ - if ((!server || !server[0]) && (!channel || !channel[0])) - ptr_buffer = gui_current_window->buffer; - else - { - if (server && server[0]) - { - ptr_server = server_search (server); - if (!ptr_server) - return NULL; - } - else - { - ptr_server = SERVER(gui_current_window->buffer); - if (!ptr_server) - ptr_server = SERVER(gui_buffers); - } - - if (channel && channel[0]) - { - if (ptr_server) - { - ptr_channel = channel_search_any (ptr_server, channel); - if (ptr_channel) - ptr_buffer = ptr_channel->buffer; - } - } - else - { - if (ptr_server) - ptr_buffer = ptr_server->buffer; - else - ptr_buffer = gui_current_window->buffer; - } - } - - if (!ptr_buffer) - return NULL; - - return (ptr_buffer->type != BUFFER_TYPE_STANDARD) ? - gui_buffers : ptr_buffer; -} - -/* - * gui_buffer_find_window: find a window displaying buffer - */ - -t_gui_window * -gui_buffer_find_window (t_gui_buffer *buffer) -{ - t_gui_window *ptr_win; - - if (gui_current_window->buffer == buffer) - return gui_current_window; - - for (ptr_win = gui_windows; ptr_win; - ptr_win = ptr_win->next_window) - { - if (ptr_win->buffer == buffer) - return ptr_win; - } - - /* no window found */ - return NULL; -} - -/* - * gui_get_dcc_buffer: get pointer to DCC buffer (DCC buffer created if not existing) - */ - -t_gui_buffer * -gui_get_dcc_buffer (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - - /* check if dcc buffer exists */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->type == BUFFER_TYPE_DCC) - break; - } - if (ptr_buffer) - return ptr_buffer; - else - return gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_DCC, 0); -} - -/* - * gui_buffer_clear: clear buffer content - */ - -void -gui_buffer_clear (t_gui_buffer *buffer) -{ - t_gui_window *ptr_win; - t_gui_line *ptr_line; - - /* remove buffer from hotlist */ - hotlist_remove_buffer (buffer); - - /* remove lines from buffer */ - while (buffer->lines) - { - ptr_line = buffer->lines->next_line; - if (buffer->lines->data) - free (buffer->lines->data); - free (buffer->lines); - buffer->lines = ptr_line; - } - - buffer->lines = NULL; - buffer->last_line = NULL; - buffer->num_lines = 0; - buffer->line_complete = 1; - - /* remove any scroll for buffer */ - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - { - if (ptr_win->buffer == buffer) - { - ptr_win->first_line_displayed = 1; - ptr_win->start_line = NULL; - ptr_win->start_line_pos = 0; - } - } - - gui_draw_buffer_chat (buffer, 1); - gui_draw_buffer_status (buffer, 1); -} - -/* - * gui_buffer_clear_all: clear all buffers content - */ - -void -gui_buffer_clear_all () -{ - t_gui_buffer *ptr_buffer; - - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - gui_buffer_clear (ptr_buffer); -} - -/* - * gui_window_free: delete a window - */ - -void -gui_window_free (t_gui_window *window) -{ - if (window->buffer && (window->buffer->num_displayed > 0)) - window->buffer->num_displayed--; - - /* remove window from windows list */ - if (window->prev_window) - window->prev_window->next_window = window->next_window; - if (window->next_window) - window->next_window->prev_window = window->prev_window; - if (gui_windows == window) - gui_windows = window->next_window; - if (last_gui_window == window) - last_gui_window = window->prev_window; - - free (window); -} - -/* - * gui_line_free: delete a line from a buffer - */ - -void -gui_line_free (t_gui_line *line) -{ - t_gui_window *ptr_win; - - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - { - if (ptr_win->start_line == line) - { - ptr_win->start_line = ptr_win->start_line->next_line; - ptr_win->start_line_pos = 0; - gui_draw_buffer_chat (ptr_win->buffer, 0); - gui_draw_buffer_status (ptr_win->buffer, 0); - } - } - if (line->nick) - free (line->nick); - if (line->data) - free (line->data); - free (line); -} - -/* - * gui_buffer_free: delete a buffer - */ - -void -gui_buffer_free (t_gui_buffer *buffer, int switch_to_another) -{ - t_gui_window *ptr_win; - t_gui_buffer *ptr_buffer; - t_gui_line *ptr_line; - t_irc_server *ptr_server; - int create_new; - - create_new = (buffer->server || buffer->channel); - - hotlist_remove_buffer (buffer); - if (hotlist_initial_buffer == buffer) - hotlist_initial_buffer = NULL; - - if (gui_buffer_before_dcc == buffer) - gui_buffer_before_dcc = NULL; - - if (gui_buffer_before_raw_data == buffer) - gui_buffer_before_raw_data = NULL; - - if (buffer->type == BUFFER_TYPE_RAW_DATA) - gui_buffer_raw_data = NULL; - - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (ptr_server->saved_buffer == buffer) - ptr_server->saved_buffer = NULL; - } - - if (switch_to_another) - { - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - { - if ((buffer == ptr_win->buffer) && - ((buffer->next_buffer) || (buffer->prev_buffer))) - gui_buffer_switch_previous (ptr_win); - } - } - - /* decrease buffer number for all next buffers */ - for (ptr_buffer = buffer->next_buffer; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - ptr_buffer->number--; - } - - /* free lines and messages */ - while (buffer->lines) - { - ptr_line = buffer->lines->next_line; - gui_line_free (buffer->lines); - buffer->lines = ptr_line; - } - - /* close log if opened */ - if (buffer->log_file) - log_end (buffer); - - if (buffer->input_buffer) - free (buffer->input_buffer); - if (buffer->input_buffer_color_mask) - free (buffer->input_buffer_color_mask); - - completion_free (&(buffer->completion)); - - history_buffer_free (buffer); - - /* remove buffer from buffers list */ - if (buffer->prev_buffer) - buffer->prev_buffer->next_buffer = buffer->next_buffer; - if (buffer->next_buffer) - buffer->next_buffer->prev_buffer = buffer->prev_buffer; - if (gui_buffers == buffer) - gui_buffers = buffer->next_buffer; - if (last_gui_buffer == buffer) - last_gui_buffer = buffer->prev_buffer; - - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - { - if (ptr_win->buffer == buffer) - ptr_win->buffer = NULL; - } - - free (buffer); - - /* always at least one buffer */ - if (!gui_buffers && create_new && switch_to_another) - (void) gui_buffer_new (gui_windows, NULL, NULL, - BUFFER_TYPE_STANDARD, 1); -} - -/* - * gui_line_new: create new line for a buffer - */ - -t_gui_line * -gui_line_new (t_gui_buffer *buffer) -{ - t_gui_line *new_line, *ptr_line; - - if ((new_line = (t_gui_line *) malloc (sizeof (struct t_gui_line)))) - { - new_line->length = 0; - new_line->length_align = 0; - new_line->log_write = 1; - new_line->line_with_message = 0; - new_line->line_with_highlight = 0; - new_line->nick = NULL; - new_line->data = NULL; - new_line->ofs_after_date = -1; - new_line->ofs_start_message = -1; - if (!buffer->lines) - buffer->lines = new_line; - else - buffer->last_line->next_line = new_line; - new_line->prev_line = buffer->last_line; - new_line->next_line = NULL; - buffer->last_line = new_line; - buffer->num_lines++; - } - else - { - weechat_log_printf (_("Not enough memory for new line\n")); - return NULL; - } - - /* remove one line if necessary */ - if ((cfg_history_max_lines > 0) - && (buffer->num_lines > cfg_history_max_lines)) - { - if (buffer->last_line == buffer->lines) - buffer->last_line = NULL; - ptr_line = buffer->lines->next_line; - gui_line_free (buffer->lines); - buffer->lines = ptr_line; - ptr_line->prev_line = NULL; - buffer->num_lines--; - gui_draw_buffer_chat (buffer, 1); - } - - return new_line; -} - /* * gui_word_strlen: returns length of a word * special chars like color, bold, .. are ignored @@ -818,7 +82,7 @@ gui_word_strlen (t_gui_window *window, char *string) length = 0; while (string && string[0]) { - string = gui_word_get_next_char (window, (unsigned char *)string, 0); + string = gui_chat_word_get_next_char (window, (unsigned char *)string, 0); if (string) length++; } @@ -842,7 +106,7 @@ gui_word_real_pos (t_gui_window *window, char *string, int pos) while (string && string[0] && (pos > 0)) { saved_pos = string; - string = gui_word_get_next_char (window, (unsigned char *)string, 0); + string = gui_chat_word_get_next_char (window, (unsigned char *)string, 0); pos--; if (string) real_pos += (string - saved_pos); @@ -864,7 +128,7 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message) if (buffer->line_complete) { buffer->line_complete = 0; - if (!gui_line_new (buffer)) + if (!gui_buffer_line_new (buffer)) return; } @@ -917,8 +181,8 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message) pos[0] = '\n'; if (buffer->num_displayed > 0) { - gui_draw_buffer_chat_line (buffer, buffer->last_line); - gui_draw_buffer_chat (buffer, 0); + gui_chat_draw_line (buffer, buffer->last_line); + gui_chat_draw (buffer, 0); } if (gui_add_hotlist && (buffer->num_displayed == 0)) { @@ -934,7 +198,7 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message) hotlist_add (HOTLIST_MSG, SERVER(buffer), buffer); else hotlist_add (HOTLIST_LOW, SERVER(buffer), buffer); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); } } } @@ -1169,7 +433,7 @@ gui_infobar_printf (int time_displayed, int color, char *message, ...) ptr_infobar->remaining_time = (time_displayed <= 0) ? -1 : time_displayed; ptr_infobar->next_infobar = gui_infobar; gui_infobar = ptr_infobar; - gui_draw_buffer_infobar (gui_current_window->buffer, 1); + gui_infobar_draw (gui_current_window->buffer, 1); } else weechat_log_printf (_("Not enough memory for infobar message\n")); @@ -1337,7 +601,7 @@ gui_exec_action_dcc (t_gui_window *window, char *actions) && (!DCC_ENDED(dcc_selected->status))) { dcc_close (dcc_selected, DCC_ABORTED); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); } break; /* purge old DCC */ @@ -1352,7 +616,7 @@ gui_exec_action_dcc (t_gui_window *window, char *actions) dcc_free (ptr_dcc); ptr_dcc = ptr_dcc_next; } - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); break; /* close DCC window */ case 'q': @@ -1360,12 +624,12 @@ gui_exec_action_dcc (t_gui_window *window, char *actions) if (gui_buffer_before_dcc) { ptr_buffer = window->buffer; - gui_switch_to_buffer (window, gui_buffer_before_dcc); + gui_window_switch_to_buffer (window, gui_buffer_before_dcc); gui_buffer_free (ptr_buffer, 0); } else gui_buffer_free (window->buffer, 1); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); return; break; /* remove from DCC list */ @@ -1379,7 +643,7 @@ gui_exec_action_dcc (t_gui_window *window, char *actions) else window->dcc_selected = NULL; dcc_free (dcc_selected); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); } break; } @@ -1411,13 +675,13 @@ gui_exec_action_raw_data (t_gui_window *window, char *actions) if (gui_buffer_before_raw_data) { ptr_buffer = window->buffer; - gui_switch_to_buffer (window, - gui_buffer_before_raw_data); + gui_window_switch_to_buffer (window, + gui_buffer_before_raw_data); gui_buffer_free (ptr_buffer, 0); } else gui_buffer_free (window->buffer, 1); - gui_redraw_buffer (window->buffer); + gui_window_redraw_buffer (window->buffer); return; break; } @@ -1474,533 +738,3 @@ gui_insert_string_input (t_gui_window *window, char *string, int pos) } return 0; } - -/* - * gui_merge_servers: merge server buffers in one buffer - */ - -void -gui_merge_servers (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer_server, *ptr_buffer; - t_irc_server *ptr_server; - - /* new server buffer is the first server buffer found */ - for (ptr_buffer_server = gui_buffers; ptr_buffer_server; - ptr_buffer_server = ptr_buffer_server->next_buffer) - { - if (BUFFER_IS_SERVER(ptr_buffer_server)) - break; - } - - /* no server buffer found */ - if (!ptr_buffer_server) - return; - - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - if ((ptr_buffer != ptr_buffer_server) - && (BUFFER_IS_SERVER(ptr_buffer))) - { - ptr_server = SERVER(ptr_buffer); - - /* add (by pointer artefact) lines from buffer found to server buffer */ - if (ptr_buffer->lines) - { - if (ptr_buffer_server->lines) - { - ptr_buffer->lines->prev_line = - ptr_buffer_server->last_line; - ptr_buffer_server->last_line->next_line = - ptr_buffer->lines; - ptr_buffer_server->last_line = - ptr_buffer->last_line; - } - else - { - ptr_buffer_server->lines = ptr_buffer->lines; - ptr_buffer_server->last_line = ptr_buffer->last_line; - } - } - - /* free buffer but not lines, because they're now used by - our unique server buffer */ - ptr_buffer->lines = NULL; - gui_buffer_free (ptr_buffer, 1); - - /* asociate server with new server buffer */ - ptr_server->buffer = ptr_buffer_server; - } - } - - ptr_buffer_server->all_servers = 1; - gui_redraw_buffer (window->buffer); -} - -/* - * gui_split_server: split the server buffer into many buffers (one by server) - */ - -void -gui_split_server (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - t_irc_server *ptr_server; - - ptr_buffer = gui_buffer_servers_search (); - - if (ptr_buffer) - { - if (SERVER(ptr_buffer)) - { - for (ptr_server = irc_servers; ptr_server; - ptr_server = ptr_server->next_server) - { - if (ptr_server->buffer - && (ptr_server != SERVER(ptr_buffer)) - && (ptr_server->buffer == ptr_buffer)) - { - ptr_server->buffer = NULL; - gui_buffer_new (window, ptr_server, NULL, - BUFFER_TYPE_STANDARD, 0); - } - } - } - ptr_buffer->all_servers = 0; - gui_draw_buffer_status (window->buffer, 1); - gui_draw_buffer_input (window->buffer, 1); - } -} - -/* - * gui_window_switch_server: switch server on servers buffer - * (if same buffer is used for all buffers) - */ - -void -gui_window_switch_server (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - t_irc_server *ptr_server; - - ptr_buffer = gui_buffer_servers_search (); - - if (ptr_buffer) - { - ptr_server = (SERVER(ptr_buffer) && SERVER(ptr_buffer)->next_server) ? - SERVER(ptr_buffer)->next_server : irc_servers; - while (ptr_server != SERVER(window->buffer)) - { - if (ptr_server->buffer) - break; - if (ptr_server->next_server) - ptr_server = ptr_server->next_server; - else - { - if (SERVER(ptr_buffer) == NULL) - { - ptr_server = NULL; - break; - } - ptr_server = irc_servers; - } - } - if (ptr_server && (ptr_server != SERVER(ptr_buffer))) - { - ptr_buffer->server = ptr_server; - gui_draw_buffer_status (window->buffer, 1); - gui_draw_buffer_input (window->buffer, 1); - } - } -} - -/* - * gui_buffer_switch_previous: switch to previous buffer - */ - -void -gui_buffer_switch_previous (t_gui_window *window) -{ - if (!gui_ok) - return; - - /* if only one buffer then return */ - if (gui_buffers == last_gui_buffer) - return; - - if (window->buffer->prev_buffer) - gui_switch_to_buffer (window, window->buffer->prev_buffer); - else - gui_switch_to_buffer (window, last_gui_buffer); - - gui_redraw_buffer (window->buffer); -} - -/* - * gui_buffer_switch_next: switch to next buffer - */ - -void -gui_buffer_switch_next (t_gui_window *window) -{ - if (!gui_ok) - return; - - /* if only one buffer then return */ - if (gui_buffers == last_gui_buffer) - return; - - if (window->buffer->next_buffer) - gui_switch_to_buffer (window, window->buffer->next_buffer); - else - gui_switch_to_buffer (window, gui_buffers); - - gui_redraw_buffer (window->buffer); -} - -/* - * gui_window_switch_previous: switch to previous window - */ - -void -gui_window_switch_previous (t_gui_window *window) -{ - if (!gui_ok) - return; - - /* if only one window then return */ - if (gui_windows == last_gui_window) - return; - - gui_current_window = (window->prev_window) ? window->prev_window : last_gui_window; - gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); - gui_redraw_buffer (gui_current_window->buffer); -} - -/* - * gui_window_switch_next: switch to next window - */ - -void -gui_window_switch_next (t_gui_window *window) -{ - if (!gui_ok) - return; - - /* if only one window then return */ - if (gui_windows == last_gui_window) - return; - - gui_current_window = (window->next_window) ? window->next_window : gui_windows; - gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); - gui_redraw_buffer (gui_current_window->buffer); -} - -/* - * gui_window_switch_by_buffer: switch to next window displaying a buffer - */ - -void -gui_window_switch_by_buffer (t_gui_window *window, int buffer_number) -{ - t_gui_window *ptr_win; - - if (!gui_ok) - return; - - ptr_win = (window->next_window) ? window->next_window : gui_windows; - while (ptr_win != window) - { - if (ptr_win->buffer->number == buffer_number) - { - gui_current_window = ptr_win; - gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); - gui_redraw_buffer (gui_current_window->buffer); - return; - } - ptr_win = (ptr_win->next_window) ? ptr_win->next_window : gui_windows; - } -} - -/* - * gui_buffer_switch_dcc: switch to dcc buffer (create it if it does not exist) - */ - -void -gui_buffer_switch_dcc (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - - /* check if dcc buffer exists */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->type == BUFFER_TYPE_DCC) - break; - } - if (ptr_buffer) - { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (ptr_buffer); - } - else - gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_DCC, 1); -} - -/* - * gui_buffer_switch_raw_data: switch to rax IRC data buffer (create it if it does not exist) - */ - -void -gui_buffer_switch_raw_data (t_gui_window *window) -{ - t_gui_buffer *ptr_buffer; - - /* check if raw IRC data buffer exists */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->type == BUFFER_TYPE_RAW_DATA) - break; - } - if (ptr_buffer) - { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (ptr_buffer); - } - else - gui_buffer_new (window, NULL, NULL, BUFFER_TYPE_RAW_DATA, 1); -} - -/* - * gui_buffer_switch_by_number: switch to another buffer with number - */ - -t_gui_buffer * -gui_buffer_switch_by_number (t_gui_window *window, int number) -{ - t_gui_buffer *ptr_buffer; - - /* invalid buffer */ - if (number < 0) - return NULL; - - /* buffer is currently displayed ? */ - if (number == window->buffer->number) - return window->buffer; - - /* search for buffer in the list */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if ((ptr_buffer != window->buffer) && (number == ptr_buffer->number)) - { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (window->buffer); - return ptr_buffer; - } - } - - /* buffer not found */ - return NULL; -} - -/* - * gui_buffer_move_to_number: move a buffer to another number - */ - -void -gui_buffer_move_to_number (t_gui_buffer *buffer, int number) -{ - t_gui_buffer *ptr_buffer; - int i; - - /* if only one buffer then return */ - if (gui_buffers == last_gui_buffer) - return; - - /* buffer number is already ok ? */ - if (number == buffer->number) - return; - - if (number < 1) - number = 1; - - /* remove buffer from list */ - if (buffer == gui_buffers) - { - gui_buffers = buffer->next_buffer; - gui_buffers->prev_buffer = NULL; - } - if (buffer == last_gui_buffer) - { - last_gui_buffer = buffer->prev_buffer; - last_gui_buffer->next_buffer = NULL; - } - if (buffer->prev_buffer) - (buffer->prev_buffer)->next_buffer = buffer->next_buffer; - if (buffer->next_buffer) - (buffer->next_buffer)->prev_buffer = buffer->prev_buffer; - - if (number == 1) - { - gui_buffers->prev_buffer = buffer; - buffer->prev_buffer = NULL; - buffer->next_buffer = gui_buffers; - gui_buffers = buffer; - } - else - { - /* assign new number to all buffers */ - i = 1; - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - ptr_buffer->number = i++; - } - - /* search for new position in the list */ - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->number == number) - break; - } - if (ptr_buffer) - { - /* insert before buffer found */ - buffer->prev_buffer = ptr_buffer->prev_buffer; - buffer->next_buffer = ptr_buffer; - if (ptr_buffer->prev_buffer) - (ptr_buffer->prev_buffer)->next_buffer = buffer; - ptr_buffer->prev_buffer = buffer; - } - else - { - /* number not found (too big)? => add to end */ - buffer->prev_buffer = last_gui_buffer; - buffer->next_buffer = NULL; - last_gui_buffer->next_buffer = buffer; - last_gui_buffer = buffer; - } - - } - - /* assign new number to all buffers */ - i = 1; - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) - { - ptr_buffer->number = i++; - } - - gui_redraw_buffer (buffer); -} - -/* - * gui_window_print_log: print window infos in log (usually for crash dump) - */ - -void -gui_window_print_log (t_gui_window *window) -{ - weechat_log_printf ("[window (addr:0x%X)]\n", window); - weechat_log_printf (" win_x . . . . . . . : %d\n", window->win_x); - weechat_log_printf (" win_y . . . . . . . : %d\n", window->win_y); - weechat_log_printf (" win_width . . . . . : %d\n", window->win_width); - weechat_log_printf (" win_height. . . . . : %d\n", window->win_height); - weechat_log_printf (" win_width_pct . . . : %d\n", window->win_width_pct); - weechat_log_printf (" win_height_pct. . . : %d\n", window->win_height_pct); - weechat_log_printf (" win_chat_x. . . . . : %d\n", window->win_chat_x); - weechat_log_printf (" win_chat_y. . . . . : %d\n", window->win_chat_y); - weechat_log_printf (" win_chat_width. . . : %d\n", window->win_chat_width); - weechat_log_printf (" win_chat_height . . : %d\n", window->win_chat_height); - weechat_log_printf (" win_chat_cursor_x . : %d\n", window->win_chat_cursor_x); - weechat_log_printf (" win_chat_cursor_y . : %d\n", window->win_chat_cursor_y); - weechat_log_printf (" win_nick_x. . . . . : %d\n", window->win_nick_x); - weechat_log_printf (" win_nick_y. . . . . : %d\n", window->win_nick_y); - weechat_log_printf (" win_nick_width. . . : %d\n", window->win_nick_width); - weechat_log_printf (" win_nick_height . . : %d\n", window->win_nick_height); - weechat_log_printf (" win_nick_start. . . : %d\n", window->win_nick_start); - weechat_log_printf (" win_title . . . . . : 0x%X\n", window->win_title); - weechat_log_printf (" win_chat. . . . . . : 0x%X\n", window->win_chat); - weechat_log_printf (" win_nick. . . . . . : 0x%X\n", window->win_nick); - weechat_log_printf (" win_status. . . . . : 0x%X\n", window->win_status); - weechat_log_printf (" win_infobar . . . . : 0x%X\n", window->win_infobar); - weechat_log_printf (" win_input . . . . . : 0x%X\n", window->win_input); - weechat_log_printf (" win_separator . . . : 0x%X\n", window->win_separator); - weechat_log_printf (" textview_chat . . . : 0x%X\n", window->textview_chat); - weechat_log_printf (" textbuffer_chat . . : 0x%X\n", window->textbuffer_chat); - weechat_log_printf (" texttag_chat. . . . : 0x%X\n", window->texttag_chat); - weechat_log_printf (" textview_nicklist . : 0x%X\n", window->textview_nicklist); - weechat_log_printf (" textbuffer_nicklist : 0x%X\n", window->textbuffer_nicklist); - weechat_log_printf (" dcc_first . . . . . : 0x%X\n", window->dcc_first); - weechat_log_printf (" dcc_selected. . . . : 0x%X\n", window->dcc_selected); - weechat_log_printf (" dcc_last_displayed. : 0x%X\n", window->dcc_last_displayed); - weechat_log_printf (" buffer. . . . . . . : 0x%X\n", window->buffer); - weechat_log_printf (" first_line_displayed: %d\n", window->first_line_displayed); - weechat_log_printf (" start_line. . . . . : 0x%X\n", window->start_line); - weechat_log_printf (" start_line_pos. . . : %d\n", window->start_line_pos); - weechat_log_printf (" prev_window . . . . : 0x%X\n", window->prev_window); - weechat_log_printf (" next_window . . . . : 0x%X\n", window->next_window); - -} - -/* - * gui_buffer_print_log: print buffer infos in log (usually for crash dump) - */ - -void -gui_buffer_print_log (t_gui_buffer *buffer) -{ - t_gui_line *ptr_line; - int num; - - weechat_log_printf ("[buffer (addr:0x%X)]\n", buffer); - weechat_log_printf (" num_displayed. . . . . : %d\n", buffer->num_displayed); - weechat_log_printf (" number . . . . . . . . : %d\n", buffer->number); - weechat_log_printf (" server . . . . . . . . : 0x%X\n", buffer->server); - weechat_log_printf (" all_servers. . . . . . : %d\n", buffer->all_servers); - weechat_log_printf (" channel. . . . . . . . : 0x%X\n", buffer->channel); - weechat_log_printf (" type . . . . . . . . . : %d\n", buffer->type); - weechat_log_printf (" lines. . . . . . . . . : 0x%X\n", buffer->lines); - weechat_log_printf (" last_line. . . . . . . : 0x%X\n", buffer->last_line); - weechat_log_printf (" last_read_line . . . . : 0x%X\n", buffer->last_read_line); - weechat_log_printf (" num_lines. . . . . . . : %d\n", buffer->num_lines); - weechat_log_printf (" line_complete. . . . . : %d\n", buffer->line_complete); - weechat_log_printf (" notify_level . . . . . : %d\n", buffer->notify_level); - weechat_log_printf (" log_filename . . . . . : '%s'\n", buffer->log_filename); - weechat_log_printf (" log_file . . . . . . . : 0x%X\n", buffer->log_file); - weechat_log_printf (" has_input. . . . . . . : %d\n", buffer->has_input); - weechat_log_printf (" input_buffer . . . . . : '%s'\n", buffer->input_buffer); - weechat_log_printf (" input_buffer_color_mask: '%s'\n", buffer->input_buffer_color_mask); - weechat_log_printf (" input_buffer_alloc . . : %d\n", buffer->input_buffer_alloc); - weechat_log_printf (" input_buffer_size. . . : %d\n", buffer->input_buffer_size); - weechat_log_printf (" input_buffer_length. . : %d\n", buffer->input_buffer_length); - weechat_log_printf (" input_buffer_pos . . . : %d\n", buffer->input_buffer_pos); - weechat_log_printf (" input_buffer_1st_disp. : %d\n", buffer->input_buffer_1st_display); - weechat_log_printf (" history. . . . . . . . : 0x%X\n", buffer->history); - weechat_log_printf (" last_history . . . . . : 0x%X\n", buffer->last_history); - weechat_log_printf (" ptr_history. . . . . . : 0x%X\n", buffer->ptr_history); - weechat_log_printf (" prev_buffer. . . . . . : 0x%X\n", buffer->prev_buffer); - weechat_log_printf (" next_buffer. . . . . . : 0x%X\n", buffer->next_buffer); - weechat_log_printf ("\n"); - weechat_log_printf (" => last 100 lines:\n"); - - num = 0; - ptr_line = buffer->last_line; - while (ptr_line && (num < 100)) - { - num++; - ptr_line = ptr_line->prev_line; - } - if (!ptr_line) - ptr_line = buffer->lines; - else - ptr_line = ptr_line->next_line; - - while (ptr_line) - { - num--; - weechat_log_printf (" line N-%05d: %s\n", - num, - (ptr_line->data) ? ptr_line->data : "(empty)"); - - ptr_line = ptr_line->next_line; - } -} diff --git a/weechat/src/gui/gui-keyboard.c b/weechat/src/gui/gui-keyboard.c index 47d570891..94662b956 100644 --- a/weechat/src/gui/gui-keyboard.c +++ b/weechat/src/gui/gui-keyboard.c @@ -150,7 +150,7 @@ gui_key_init () gui_key_grab = 0; gui_key_grab_count = 0; - gui_input_default_key_bindings (); + gui_keyboard_default_bindings (); } /* diff --git a/weechat/src/gui/gui-window.c b/weechat/src/gui/gui-window.c new file mode 100644 index 000000000..7211e66b3 --- /dev/null +++ b/weechat/src/gui/gui-window.c @@ -0,0 +1,424 @@ +/* + * Copyright (c) 2003-2006 by FlashCode + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* gui-window.c: window functions, used by all GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../common/weechat.h" +#include "gui.h" +#include "../common/command.h" +#include "../common/weeconfig.h" +#include "../common/history.h" +#include "../common/hotlist.h" +#include "../common/log.h" +#include "../common/utf8.h" +#include "../irc/irc.h" + + +/* + * gui_window_tree_init: create first entry in windows tree + */ + +int +gui_window_tree_init (t_gui_window *window) +{ + gui_windows_tree = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); + if (!gui_windows_tree) + return 0; + gui_windows_tree->parent_node = NULL; + gui_windows_tree->split_horiz = 0; + gui_windows_tree->split_pct = 0; + gui_windows_tree->child1 = NULL; + gui_windows_tree->child2 = NULL; + gui_windows_tree->window = window; + return 1; +} + +/* + * gui_window_tree_node_to_leaf: convert a node to a leaf (free any leafs) + * Called when 2 windows are merging into one + */ + +void +gui_window_tree_node_to_leaf (t_gui_window_tree *node, t_gui_window *window) +{ + node->split_horiz = 0; + node->split_pct = 0; + if (node->child1) + { + free (node->child1); + node->child1 = NULL; + } + if (node->child2) + { + free (node->child2); + node->child2 = NULL; + } + node->window = window; + window->ptr_tree = node; +} + +/* + * gui_window_tree_free: delete entire windows tree + */ + +void +gui_window_tree_free (t_gui_window_tree **tree) +{ + if (*tree) + { + if ((*tree)->child1) + gui_window_tree_free (&((*tree)->child1)); + if ((*tree)->child2) + gui_window_tree_free (&((*tree)->child2)); + free (*tree); + *tree = NULL; + } +} + +/* + * gui_window_new: create a new window + */ + +t_gui_window * +gui_window_new (t_gui_window *parent, int x, int y, int width, int height, + int width_pct, int height_pct) +{ + t_gui_window *new_window; + t_gui_window_tree *ptr_tree, *child1, *child2, *ptr_leaf; + +#ifdef DEBUG + weechat_log_printf ("Creating new window (x:%d, y:%d, width:%d, height:%d)\n", + x, y, width, height); +#endif + + if (parent) + { + child1 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); + if (!child1) + return NULL; + child2 = (t_gui_window_tree *)malloc (sizeof (t_gui_window_tree)); + if (!child2) + { + free (child1); + return NULL; + } + ptr_tree = parent->ptr_tree; + + if (width_pct == 100) + { + ptr_tree->split_horiz = 1; + ptr_tree->split_pct = height_pct; + } + else + { + ptr_tree->split_horiz = 0; + ptr_tree->split_pct = width_pct; + } + + /* parent window leaf becomes node and we add 2 leafs below + (#1 is parent win, #2 is new win) */ + + parent->ptr_tree = child1; + child1->parent_node = ptr_tree; + child1->child1 = NULL; + child1->child2 = NULL; + child1->window = ptr_tree->window; + + child2->parent_node = ptr_tree; + child2->child1 = NULL; + child2->child2 = NULL; + child2->window = NULL; /* will be assigned by new window below */ + + ptr_tree->child1 = child1; + ptr_tree->child2 = child2; + ptr_tree->window = NULL; /* leaf becomes node */ + + ptr_leaf = child2; + } + else + { + if (!gui_window_tree_init (NULL)) + return NULL; + ptr_leaf = gui_windows_tree; + } + + if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window))))) + { + new_window->win_x = x; + new_window->win_y = y; + new_window->win_width = width; + new_window->win_height = height; + new_window->win_width_pct = width_pct; + new_window->win_height_pct = height_pct; + + new_window->new_x = -1; + new_window->new_y = -1; + new_window->new_width = -1; + new_window->new_height = -1; + + new_window->win_chat_x = 0; + new_window->win_chat_y = 0; + new_window->win_chat_width = 0; + new_window->win_chat_height = 0; + new_window->win_chat_cursor_x = 0; + new_window->win_chat_cursor_y = 0; + + new_window->win_nick_x = 0; + new_window->win_nick_y = 0; + new_window->win_nick_width = 0; + new_window->win_nick_height = 0; + new_window->win_nick_num_max = 0; + new_window->win_nick_start = 0; + + new_window->win_input_x = 0; + + new_window->win_title = NULL; + new_window->win_chat = NULL; + new_window->win_nick = NULL; + new_window->win_status = NULL; + new_window->win_infobar = NULL; + new_window->win_input = NULL; + new_window->win_separator = NULL; + + new_window->textview_chat = NULL; + new_window->textbuffer_chat = NULL; + new_window->texttag_chat = NULL; + new_window->textview_nicklist = NULL; + new_window->textbuffer_nicklist = NULL; + + new_window->dcc_first = NULL; + new_window->dcc_selected = NULL; + new_window->dcc_last_displayed = NULL; + + new_window->buffer = NULL; + + new_window->first_line_displayed = 0; + new_window->start_line = NULL; + new_window->start_line_pos = 0; + new_window->scroll = 0; + + new_window->ptr_tree = ptr_leaf; + ptr_leaf->window = new_window; + + /* add window to windows queue */ + new_window->prev_window = last_gui_window; + if (gui_windows) + last_gui_window->next_window = new_window; + else + gui_windows = new_window; + last_gui_window = new_window; + new_window->next_window = NULL; + } + else + return NULL; + + return new_window; +} + +/* + * gui_window_free: delete a window + */ + +void +gui_window_free (t_gui_window *window) +{ + if (window->buffer && (window->buffer->num_displayed > 0)) + window->buffer->num_displayed--; + + /* remove window from windows list */ + if (window->prev_window) + window->prev_window->next_window = window->next_window; + if (window->next_window) + window->next_window->prev_window = window->prev_window; + if (gui_windows == window) + gui_windows = window->next_window; + if (last_gui_window == window) + last_gui_window = window->prev_window; + + free (window); +} + +/* + * gui_window_switch_server: switch server on servers buffer + * (if same buffer is used for all buffers) + */ + +void +gui_window_switch_server (t_gui_window *window) +{ + t_gui_buffer *ptr_buffer; + t_irc_server *ptr_server; + + ptr_buffer = gui_buffer_servers_search (); + + if (ptr_buffer) + { + ptr_server = (SERVER(ptr_buffer) && SERVER(ptr_buffer)->next_server) ? + SERVER(ptr_buffer)->next_server : irc_servers; + while (ptr_server != SERVER(window->buffer)) + { + if (ptr_server->buffer) + break; + if (ptr_server->next_server) + ptr_server = ptr_server->next_server; + else + { + if (SERVER(ptr_buffer) == NULL) + { + ptr_server = NULL; + break; + } + ptr_server = irc_servers; + } + } + if (ptr_server && (ptr_server != SERVER(ptr_buffer))) + { + ptr_buffer->server = ptr_server; + gui_status_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); + } + } +} + +/* + * gui_window_switch_previous: switch to previous window + */ + +void +gui_window_switch_previous (t_gui_window *window) +{ + if (!gui_ok) + return; + + /* if only one window then return */ + if (gui_windows == last_gui_window) + return; + + gui_current_window = (window->prev_window) ? window->prev_window : last_gui_window; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); +} + +/* + * gui_window_switch_next: switch to next window + */ + +void +gui_window_switch_next (t_gui_window *window) +{ + if (!gui_ok) + return; + + /* if only one window then return */ + if (gui_windows == last_gui_window) + return; + + gui_current_window = (window->next_window) ? window->next_window : gui_windows; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); +} + +/* + * gui_window_switch_by_buffer: switch to next window displaying a buffer + */ + +void +gui_window_switch_by_buffer (t_gui_window *window, int buffer_number) +{ + t_gui_window *ptr_win; + + if (!gui_ok) + return; + + ptr_win = (window->next_window) ? window->next_window : gui_windows; + while (ptr_win != window) + { + if (ptr_win->buffer->number == buffer_number) + { + gui_current_window = ptr_win; + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); + return; + } + ptr_win = (ptr_win->next_window) ? ptr_win->next_window : gui_windows; + } +} + +/* + * gui_window_print_log: print window infos in log (usually for crash dump) + */ + +void +gui_window_print_log (t_gui_window *window) +{ + weechat_log_printf ("[window (addr:0x%X)]\n", window); + weechat_log_printf (" win_x . . . . . . . : %d\n", window->win_x); + weechat_log_printf (" win_y . . . . . . . : %d\n", window->win_y); + weechat_log_printf (" win_width . . . . . : %d\n", window->win_width); + weechat_log_printf (" win_height. . . . . : %d\n", window->win_height); + weechat_log_printf (" win_width_pct . . . : %d\n", window->win_width_pct); + weechat_log_printf (" win_height_pct. . . : %d\n", window->win_height_pct); + weechat_log_printf (" win_chat_x. . . . . : %d\n", window->win_chat_x); + weechat_log_printf (" win_chat_y. . . . . : %d\n", window->win_chat_y); + weechat_log_printf (" win_chat_width. . . : %d\n", window->win_chat_width); + weechat_log_printf (" win_chat_height . . : %d\n", window->win_chat_height); + weechat_log_printf (" win_chat_cursor_x . : %d\n", window->win_chat_cursor_x); + weechat_log_printf (" win_chat_cursor_y . : %d\n", window->win_chat_cursor_y); + weechat_log_printf (" win_nick_x. . . . . : %d\n", window->win_nick_x); + weechat_log_printf (" win_nick_y. . . . . : %d\n", window->win_nick_y); + weechat_log_printf (" win_nick_width. . . : %d\n", window->win_nick_width); + weechat_log_printf (" win_nick_height . . : %d\n", window->win_nick_height); + weechat_log_printf (" win_nick_start. . . : %d\n", window->win_nick_start); + weechat_log_printf (" win_title . . . . . : 0x%X\n", window->win_title); + weechat_log_printf (" win_chat. . . . . . : 0x%X\n", window->win_chat); + weechat_log_printf (" win_nick. . . . . . : 0x%X\n", window->win_nick); + weechat_log_printf (" win_status. . . . . : 0x%X\n", window->win_status); + weechat_log_printf (" win_infobar . . . . : 0x%X\n", window->win_infobar); + weechat_log_printf (" win_input . . . . . : 0x%X\n", window->win_input); + weechat_log_printf (" win_separator . . . : 0x%X\n", window->win_separator); + weechat_log_printf (" textview_chat . . . : 0x%X\n", window->textview_chat); + weechat_log_printf (" textbuffer_chat . . : 0x%X\n", window->textbuffer_chat); + weechat_log_printf (" texttag_chat. . . . : 0x%X\n", window->texttag_chat); + weechat_log_printf (" textview_nicklist . : 0x%X\n", window->textview_nicklist); + weechat_log_printf (" textbuffer_nicklist : 0x%X\n", window->textbuffer_nicklist); + weechat_log_printf (" dcc_first . . . . . : 0x%X\n", window->dcc_first); + weechat_log_printf (" dcc_selected. . . . : 0x%X\n", window->dcc_selected); + weechat_log_printf (" dcc_last_displayed. : 0x%X\n", window->dcc_last_displayed); + weechat_log_printf (" buffer. . . . . . . : 0x%X\n", window->buffer); + weechat_log_printf (" first_line_displayed: %d\n", window->first_line_displayed); + weechat_log_printf (" start_line. . . . . : 0x%X\n", window->start_line); + weechat_log_printf (" start_line_pos. . . : %d\n", window->start_line_pos); + weechat_log_printf (" prev_window . . . . : 0x%X\n", window->prev_window); + weechat_log_printf (" next_window . . . . : 0x%X\n", window->next_window); + +} diff --git a/weechat/src/gui/gui.h b/weechat/src/gui/gui.h index a78bf7b6e..bf63fbd9c 100644 --- a/weechat/src/gui/gui.h +++ b/weechat/src/gui/gui.h @@ -404,48 +404,38 @@ extern time_t gui_last_activity_time; extern t_gui_color *gui_color[GUI_NUM_COLORS]; -/* GUI independent functions: windows & buffers */ +/* GUI independent functions: windows */ extern int gui_window_tree_init (t_gui_window *); extern void gui_window_tree_node_to_leaf (t_gui_window_tree *, t_gui_window *); extern void gui_window_tree_free (t_gui_window_tree **); extern t_gui_window *gui_window_new (t_gui_window *, int, int, int, int, int, int); -extern t_gui_buffer *gui_buffer_new (t_gui_window *, void *, void *, int, int); -extern t_gui_buffer *gui_buffer_search (char *, char *); -extern t_gui_window *gui_buffer_find_window (t_gui_buffer *); -extern t_gui_buffer *gui_get_dcc_buffer (t_gui_window *); -extern void gui_buffer_clear (t_gui_buffer *); -extern void gui_buffer_clear_all (); extern void gui_window_free (t_gui_window *); -extern void gui_infobar_printf (int, int, char *, ...); -extern void gui_infobar_printf_from_buffer (t_gui_buffer *, int, int, char *, char *, ...); -extern void gui_infobar_remove (); -extern void gui_infobar_remove_all (); -extern void gui_buffer_free (t_gui_buffer *, int); -extern t_gui_line *gui_line_new (t_gui_buffer *); -extern int gui_word_strlen (t_gui_window *, char *); -extern int gui_word_real_pos (t_gui_window *, char *, int); -extern void gui_printf_internal (t_gui_buffer *, int, int, char *, char *, ...); -extern void gui_printf_raw_data (void *, int, char *); -extern void gui_input_optimize_size (t_gui_buffer *); -extern void gui_input_init_color_mask (t_gui_buffer *); -extern void gui_input_move (t_gui_buffer *, char *, char *, int ); -extern void gui_exec_action_dcc (t_gui_window *, char *); -extern void gui_exec_action_raw_data (t_gui_window *, char *); -extern int gui_insert_string_input (t_gui_window *, char *, int); -extern void gui_merge_servers (t_gui_window *); -extern void gui_split_server (t_gui_window *); extern void gui_window_switch_server (t_gui_window *); -extern void gui_buffer_switch_previous (t_gui_window *); -extern void gui_buffer_switch_next (t_gui_window *); extern void gui_window_switch_previous (t_gui_window *); extern void gui_window_switch_next (t_gui_window *); extern void gui_window_switch_by_buffer (t_gui_window *, int); +extern void gui_window_print_log (t_gui_window *); + +/* GUI independent functions: buffers */ + +extern t_gui_buffer *gui_buffer_servers_search (); +extern t_gui_buffer *gui_buffer_new (t_gui_window *, void *, void *, int, int); +extern t_gui_buffer *gui_buffer_search (char *, char *); +extern t_gui_window *gui_buffer_find_window (t_gui_buffer *); +extern t_gui_buffer *gui_buffer_get_dcc (t_gui_window *); +extern void gui_buffer_clear (t_gui_buffer *); +extern void gui_buffer_clear_all (); +extern void gui_buffer_free (t_gui_buffer *, int); +extern t_gui_line *gui_buffer_line_new (t_gui_buffer *); +extern void gui_buffer_merge_servers (t_gui_window *); +extern void gui_buffer_split_server (t_gui_window *); +extern void gui_buffer_switch_previous (t_gui_window *); +extern void gui_buffer_switch_next (t_gui_window *); extern void gui_buffer_switch_dcc (t_gui_window *); extern void gui_buffer_switch_raw_data (t_gui_window *); extern t_gui_buffer *gui_buffer_switch_by_number (t_gui_window *, int); extern void gui_buffer_move_to_number (t_gui_buffer *, int); -extern void gui_window_print_log (t_gui_window *); extern void gui_buffer_print_log (t_gui_buffer *); /* GUI independent functions: actions */ @@ -511,26 +501,48 @@ extern int gui_key_pressed (char *); extern void gui_key_free (t_gui_key *); extern void gui_key_free_all (); +/* other GUI independent functions */ + +extern void gui_infobar_printf (int, int, char *, ...); +extern void gui_infobar_printf_from_buffer (t_gui_buffer *, int, int, char *, char *, ...); +extern void gui_infobar_remove (); +extern void gui_infobar_remove_all (); +extern int gui_word_strlen (t_gui_window *, char *); +extern int gui_word_real_pos (t_gui_window *, char *, int); +extern void gui_printf_internal (t_gui_buffer *, int, int, char *, char *, ...); +extern void gui_printf_raw_data (void *, int, char *); +extern void gui_input_optimize_size (t_gui_buffer *); +extern void gui_input_init_color_mask (t_gui_buffer *); +extern void gui_input_move (t_gui_buffer *, char *, char *, int ); +extern void gui_exec_action_dcc (t_gui_window *, char *); +extern void gui_exec_action_raw_data (t_gui_window *, char *); +extern int gui_insert_string_input (t_gui_window *, char *, int); + +/* GUI dependant functions: keyboard */ + +extern void gui_keyboard_default_bindings (); + /* GUI dependant functions: display */ -extern int gui_assign_color (int *, char *); -extern char *gui_get_color_name (int); +extern void gui_chat_draw_title (t_gui_buffer *, int); +extern char *gui_chat_word_get_next_char (t_gui_window *, unsigned char *, int); +extern void gui_chat_draw (t_gui_buffer *, int); +extern void gui_chat_draw_line (t_gui_buffer *, t_gui_line *); +extern int gui_color_assign (int *, char *); +extern char *gui_color_get_name (int); extern unsigned char *gui_color_decode (unsigned char *, int); extern unsigned char *gui_color_decode_for_user_entry (unsigned char *); extern unsigned char *gui_color_encode (unsigned char *); -extern int gui_buffer_has_nicklist (t_gui_buffer *); -extern int gui_calculate_pos_size (t_gui_window *, int); -extern void gui_draw_buffer_title (t_gui_buffer *, int); -extern char *gui_word_get_next_char (t_gui_window *, unsigned char *, int); -extern void gui_draw_buffer_chat (t_gui_buffer *, int); -extern void gui_draw_buffer_chat_line (t_gui_buffer *, t_gui_line *); -extern void gui_draw_buffer_nick (t_gui_buffer *, int); -extern void gui_draw_buffer_status (t_gui_buffer *, int); -extern void gui_draw_buffer_infobar_time (t_gui_buffer *); -extern void gui_draw_buffer_infobar (t_gui_buffer *, int); -extern void gui_draw_buffer_input (t_gui_buffer *, int); -extern void gui_redraw_buffer (t_gui_buffer *); -extern void gui_switch_to_buffer (t_gui_window *, t_gui_buffer *); +extern void gui_color_init_pairs (); +extern void gui_color_rebuild_weechat(); +extern void gui_infobar_draw_time (t_gui_buffer *); +extern void gui_infobar_draw (t_gui_buffer *, int); +extern void gui_input_draw (t_gui_buffer *, int); +extern void gui_nicklist_draw (t_gui_buffer *, int); +extern void gui_status_draw (t_gui_buffer *, int); +extern int gui_window_calculate_pos_size (t_gui_window *, int); +extern void gui_window_redraw_buffer (t_gui_buffer *); +extern void gui_window_switch_to_buffer (t_gui_window *, t_gui_buffer *); extern void gui_window_page_up (t_gui_window *); extern void gui_window_page_down (t_gui_window *); extern void gui_window_scroll_up (t_gui_window *); @@ -542,7 +554,7 @@ extern void gui_window_nick_end (t_gui_window *); extern void gui_window_nick_page_up (t_gui_window *); extern void gui_window_nick_page_down (t_gui_window *); extern void gui_window_init_subwindows (t_gui_window *); -extern void gui_refresh_windows (); +extern void gui_window_refresh_windows (); extern void gui_window_split_horiz (t_gui_window *, int); extern void gui_window_split_vertic (t_gui_window *, int); extern void gui_window_resize (t_gui_window *, int); @@ -552,15 +564,12 @@ extern void gui_window_switch_up (t_gui_window *); extern void gui_window_switch_down (t_gui_window *); extern void gui_window_switch_left (t_gui_window *); extern void gui_window_switch_right (t_gui_window *); -extern void gui_refresh_screen (); -extern void gui_pre_init (int *, char **[]); -extern void gui_init_color_pairs (); -extern void gui_rebuild_weechat_colors (); -extern void gui_set_window_title (); -extern void gui_reset_window_title (); -extern void gui_init (); -extern void gui_end (); -extern void gui_input_default_key_bindings (); +extern void gui_window_refresh_screen (); +extern void gui_window_set_title (); +extern void gui_window_reset_title (); extern void gui_main_loop (); +extern void gui_main_pre_init (int *, char **[]); +extern void gui_main_init (); +extern void gui_main_end (); #endif /* gui.h */ diff --git a/weechat/src/irc/irc-channel.c b/weechat/src/irc/irc-channel.c index 900c0eedc..3aeb32538 100644 --- a/weechat/src/irc/irc-channel.c +++ b/weechat/src/irc/irc-channel.c @@ -376,7 +376,7 @@ channel_remove_away (t_irc_channel *channel) { NICK_SET_FLAG(ptr_nick, 0, NICK_AWAY); } - gui_draw_buffer_nick (channel->buffer, 0); + gui_nicklist_draw (channel->buffer, 0); } } @@ -443,7 +443,7 @@ channel_create_dcc (t_irc_dcc *ptr_dcc) ptr_channel->dcc_chat = ptr_dcc; ptr_dcc->channel = ptr_channel; - gui_redraw_buffer (ptr_channel->buffer); + gui_window_redraw_buffer (ptr_channel->buffer); return 1; } diff --git a/weechat/src/irc/irc-dcc.c b/weechat/src/irc/irc-dcc.c index 49e03d25b..11d28cf8b 100644 --- a/weechat/src/irc/irc-dcc.c +++ b/weechat/src/irc/irc-dcc.c @@ -57,11 +57,11 @@ char *dcc_status_string[] = /* strings for DCC status */ void dcc_redraw (int highlight) { - gui_redraw_buffer (gui_get_dcc_buffer (gui_current_window)); + gui_window_redraw_buffer (gui_buffer_get_dcc (gui_current_window)); if (highlight) { - hotlist_add (highlight, NULL, gui_get_dcc_buffer (gui_current_window)); - gui_draw_buffer_status (gui_current_window->buffer, 0); + hotlist_add (highlight, NULL, gui_buffer_get_dcc (gui_current_window)); + gui_status_draw (gui_current_window->buffer, 0); } } @@ -849,7 +849,7 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic dcc_accept (new_dcc); else dcc_redraw (HOTLIST_PRIVATE); - gui_draw_buffer_status (gui_current_window->buffer, 0); + gui_status_draw (gui_current_window->buffer, 0); return new_dcc; } diff --git a/weechat/src/irc/irc-nick.c b/weechat/src/irc/irc-nick.c index b4f2f63cd..f0542d164 100644 --- a/weechat/src/irc/irc-nick.c +++ b/weechat/src/irc/irc-nick.c @@ -400,7 +400,7 @@ nick_set_away (t_irc_channel *channel, t_irc_nick *nick, int is_away) ((!is_away) && (nick->flags & NICK_AWAY))) { NICK_SET_FLAG(nick, is_away, NICK_AWAY); - gui_draw_buffer_nick (channel->buffer, 0); + gui_nicklist_draw (channel->buffer, 0); } } } diff --git a/weechat/src/irc/irc-recv.c b/weechat/src/irc/irc-recv.c index b1f0181c7..b3b9377b1 100644 --- a/weechat/src/irc/irc-recv.c +++ b/weechat/src/irc/irc-recv.c @@ -379,7 +379,7 @@ irc_cmd_recv_invite (t_irc_server *server, char *host, char *nick, char *argumen GUI_COLOR(COLOR_WIN_CHAT_NICK), nick); hotlist_add (HOTLIST_HIGHLIGHT, server, server->buffer); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); } } else @@ -442,8 +442,8 @@ irc_cmd_recv_join (t_irc_server *server, char *host, char *nick, char *arguments ptr_nick = nick_new (server, ptr_channel, nick, 0, 0, 0, 0, 0); if (ptr_nick) ptr_nick->host = strdup ((pos) ? pos + 1 : host); - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); return 0; } @@ -523,8 +523,8 @@ irc_cmd_recv_kick (t_irc_server *server, char *host, char *nick, char *arguments { /* my nick was kicked => free all nicks, channel is not active any more */ nick_free_all (ptr_channel); - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); if (server->autorejoin) irc_cmd_send_join (server, NULL, ptr_channel->name); } @@ -534,8 +534,8 @@ irc_cmd_recv_kick (t_irc_server *server, char *host, char *nick, char *arguments if (ptr_nick) { nick_free (ptr_channel, ptr_nick); - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); } } return 0; @@ -761,7 +761,7 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *channel, { NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_HALFOP); nick_resort (channel, ptr_nick); - gui_draw_buffer_nick (channel->buffer, 1); + gui_nicklist_draw (channel->buffer, 1); } } @@ -923,7 +923,7 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *channel, { NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_OP); nick_resort (channel, ptr_nick); - gui_draw_buffer_nick (channel->buffer, 1); + gui_nicklist_draw (channel->buffer, 1); } } @@ -1022,7 +1022,7 @@ void irc_get_channel_modes (t_irc_server *server, t_irc_channel *channel, { NICK_SET_FLAG(ptr_nick, (set_flag == '+'), NICK_VOICE); nick_resort (channel, ptr_nick); - gui_draw_buffer_nick (channel->buffer, 1); + gui_nicklist_draw (channel->buffer, 1); } } @@ -1235,8 +1235,8 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *nick, char *arguments { irc_get_channel_modes (server, ptr_channel, arguments, nick, pos, pos_parm, command_ignored); - gui_draw_buffer_status (ptr_channel->buffer, 1); - gui_draw_buffer_input (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); + gui_input_draw (ptr_channel->buffer, 1); } else { @@ -1250,8 +1250,8 @@ irc_cmd_recv_mode (t_irc_server *server, char *host, char *nick, char *arguments else { irc_get_nick_modes (server, nick, pos, command_ignored); - gui_draw_buffer_status (gui_current_window->buffer, 1); - gui_draw_buffer_input (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); + gui_input_draw (gui_current_window->buffer, 1); } return 0; } @@ -1320,7 +1320,7 @@ irc_cmd_recv_nick (t_irc_server *server, char *host, char *nick, char *arguments GUI_COLOR(COLOR_WIN_CHAT_NICK), arguments); } - gui_draw_buffer_nick (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); gui_add_hotlist = 1; } } @@ -1329,17 +1329,17 @@ irc_cmd_recv_nick (t_irc_server *server, char *host, char *nick, char *arguments { free (server->nick); server->nick = strdup (arguments); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { if (ptr_win->buffer->server == server) - gui_draw_buffer_input (ptr_win->buffer, 1); + gui_input_draw (ptr_win->buffer, 1); } } else { - gui_draw_buffer_status (gui_current_window->buffer, 1); - gui_draw_buffer_input (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); + gui_input_draw (gui_current_window->buffer, 1); } return 0; @@ -1527,7 +1527,7 @@ irc_cmd_recv_notice (t_irc_server *server, char *host, char *nick, char *argumen (ascii_strcasecmp (nick, "memoserv") != 0)) { hotlist_add (HOTLIST_PRIVATE, server, server->buffer); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); } } } @@ -1641,10 +1641,10 @@ irc_cmd_recv_part (t_irc_server *server, char *host, char *nick, char *arguments if (ptr_channel) { - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); } - gui_draw_buffer_input (gui_current_window->buffer, 1); + gui_input_draw (gui_current_window->buffer, 1); } } else @@ -1701,7 +1701,7 @@ irc_cmd_recv_pong (t_irc_server *server, char *host, char *nick, char *arguments gettimeofday (&tv, &tz); server->lag = (int) get_timeval_diff (&(server->lag_check_time), &tv); if (old_lag != server->lag) - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); /* schedule next lag check */ server->lag_check_time.tv_sec = 0; @@ -2584,8 +2584,8 @@ irc_cmd_recv_quit (t_irc_server *server, char *host, char *nick, char *arguments arguments, GUI_COLOR(COLOR_WIN_CHAT_DARK)); } - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); } } @@ -2756,7 +2756,7 @@ irc_cmd_recv_topic (t_irc_server *server, char *host, char *nick, char *argument ptr_channel->topic = strdup (pos); else ptr_channel->topic = strdup (""); - gui_draw_buffer_title (ptr_channel->buffer, 1); + gui_chat_draw_title (ptr_channel->buffer, 1); } return 0; @@ -2787,8 +2787,8 @@ irc_cmd_recv_004 (t_irc_server *server, char *host, char *nick, char *arguments) /* connection to IRC server is ok! */ server->is_connected = 1; server->lag_next_check = time (NULL) + cfg_irc_lag_check; - gui_draw_buffer_status (server->buffer, 1); - gui_draw_buffer_input (server->buffer, 1); + gui_status_draw (server->buffer, 1); + gui_input_draw (server->buffer, 1); /* execute command once connected */ if (server->command && server->command[0]) @@ -3079,7 +3079,7 @@ irc_cmd_recv_305 (t_irc_server *server, char *host, char *nick, char *arguments) ptr_window = ptr_window->next_window) { if (SERVER(ptr_window->buffer) == server) - gui_draw_buffer_status (ptr_window->buffer, 1); + gui_status_draw (ptr_window->buffer, 1); } return 0; } @@ -3116,7 +3116,7 @@ irc_cmd_recv_306 (t_irc_server *server, char *host, char *nick, char *arguments) ptr_window = ptr_window->next_window) { if (SERVER(ptr_window->buffer) == server) - gui_draw_buffer_status (ptr_window->buffer, 1); + gui_status_draw (ptr_window->buffer, 1); if (SERVER(ptr_window->buffer) == server) ptr_window->buffer->last_read_line = ptr_window->buffer->last_line; @@ -3869,7 +3869,7 @@ irc_cmd_recv_324 (t_irc_server *server, char *host, char *nick, char *arguments) { irc_get_channel_modes (server, ptr_channel, NULL, NULL, pos, pos_parm, command_ignored); - gui_draw_buffer_status (ptr_channel->buffer, 0); + gui_status_draw (ptr_channel->buffer, 0); } } } @@ -4002,7 +4002,7 @@ irc_cmd_recv_332 (t_irc_server *server, char *host, char *nick, char *arguments) } if (ptr_channel) - gui_draw_buffer_title (ptr_buffer, 1); + gui_chat_draw_title (ptr_buffer, 1); } } else @@ -4140,7 +4140,7 @@ irc_cmd_recv_341 (t_irc_server *server, char *host, char *nick, char *arguments) GUI_COLOR(COLOR_WIN_CHAT), GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), pos_channel); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); } else { @@ -4758,8 +4758,8 @@ irc_cmd_recv_353 (t_irc_server *server, char *host, char *nick, char *arguments) } if (ptr_channel) { - gui_draw_buffer_nick (ptr_channel->buffer, 1); - gui_draw_buffer_status (ptr_channel->buffer, 1); + gui_nicklist_draw (ptr_channel->buffer, 1); + gui_status_draw (ptr_channel->buffer, 1); } else { diff --git a/weechat/src/irc/irc-send.c b/weechat/src/irc/irc-send.c index a5d829678..9d09b9d58 100644 --- a/weechat/src/irc/irc-send.c +++ b/weechat/src/irc/irc-send.c @@ -75,7 +75,7 @@ irc_login (t_irc_server *server) "USER %s %s %s :%s\r\n", server->nick, server->username, ptr_hostname, "servername", server->realname); - gui_draw_buffer_input (gui_current_window->buffer, 1); + gui_input_draw (gui_current_window->buffer, 1); } /* @@ -343,7 +343,7 @@ irc_cmd_send_away (t_irc_server *server, t_irc_channel *channel, else irc_send_away (server, arguments); - gui_draw_buffer_status (buffer, 1); + gui_status_draw (buffer, 1); gui_add_hotlist = 1; return 0; } @@ -1368,11 +1368,11 @@ irc_cmd_send_nick_server (t_irc_server *server, char *nickname) if (server->nick) free (server->nick); server->nick = strdup (nickname); - gui_draw_buffer_input (server->buffer, 1); + gui_input_draw (server->buffer, 1); for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { - gui_draw_buffer_input (ptr_channel->buffer, 1); + gui_input_draw (ptr_channel->buffer, 1); } } } @@ -1554,8 +1554,8 @@ irc_cmd_send_part (t_irc_server *server, t_irc_channel *channel, ptr_channel = CHANNEL(buffer); gui_buffer_free (ptr_channel->buffer, 1); channel_free (server, ptr_channel); - gui_draw_buffer_status (buffer, 1); - gui_draw_buffer_input (buffer, 1); + gui_status_draw (buffer, 1); + gui_input_draw (buffer, 1); return 0; } channel_name = CHANNEL(buffer)->name; @@ -1652,7 +1652,7 @@ irc_cmd_send_query (t_irc_server *server, t_irc_channel *channel, } gui_buffer_new (window, server, ptr_channel, BUFFER_TYPE_STANDARD, 1); - gui_draw_buffer_title (ptr_channel->buffer, 1); + gui_chat_draw_title (ptr_channel->buffer, 1); } else { @@ -1660,8 +1660,8 @@ irc_cmd_send_query (t_irc_server *server, t_irc_channel *channel, { if (ptr_buffer->channel == ptr_channel) { - gui_switch_to_buffer (window, ptr_buffer); - gui_redraw_buffer (ptr_buffer); + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (ptr_buffer); break; } } diff --git a/weechat/src/irc/irc-server.c b/weechat/src/irc/irc-server.c index dee0dcd37..a957ef925 100644 --- a/weechat/src/irc/irc-server.c +++ b/weechat/src/irc/irc-server.c @@ -1655,7 +1655,7 @@ server_auto_connect (int auto_connect, int command_line) { (void) gui_buffer_new (gui_current_window, ptr_server, NULL, BUFFER_TYPE_STANDARD, 1); - gui_redraw_buffer (gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); if (!server_connect (ptr_server)) server_reconnect_schedule (ptr_server); } @@ -1708,7 +1708,7 @@ server_disconnect (t_irc_server *server, int reconnect) else server->reconnect_start = 0; - gui_redraw_buffer (gui_current_window->buffer); + gui_window_redraw_buffer (gui_current_window->buffer); } /* diff --git a/weechat/src/plugins/plugins-interface.c b/weechat/src/plugins/plugins-interface.c index 24a45e09b..72c2b6a5c 100644 --- a/weechat/src/plugins/plugins-interface.c +++ b/weechat/src/plugins/plugins-interface.c @@ -234,7 +234,7 @@ weechat_plugin_infobar_remove (t_weechat_plugin *plugin, int how_many) how_many--; } } - gui_draw_buffer_infobar (gui_current_window->buffer, 1); + gui_infobar_draw (gui_current_window->buffer, 1); } /* @@ -621,7 +621,7 @@ weechat_plugin_get_config_str_value (t_config_option *option, void *value) return option->array_values[*((int *)value)]; break; case OPTION_TYPE_COLOR: - color_name = gui_get_color_name (*((int *)value)); + color_name = gui_color_get_name (*((int *)value)); return (color_name) ? strdup (color_name) : strdup (""); break; case OPTION_TYPE_STRING: @@ -1073,7 +1073,7 @@ weechat_plugin_input_color (t_weechat_plugin *plugin, int color, int start, int return; if (color < 0) - gui_draw_buffer_input (gui_current_window->buffer, 0); + gui_input_draw (gui_current_window->buffer, 0); else { if ((start < 0) || (length <= 0))