diff --git a/ChangeLog b/ChangeLog index ce2e1c0da..252b81951 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2008-02-24 +ChangeLog - 2008-03-05 Version 0.2.7 (under dev!): + * added custom bars, with custom items * command /whois is now authorized in private without argument (task #7482) * removed kernel info in CTCP VERSION reply (IRC plugin) (task #7494) * use of many addresses for one IRC server (auto-switch when a connexion @@ -18,7 +19,7 @@ Version 0.2.7 (under dev!): * new plugins: IRC, alias, demo, fifo, logger, trigger * added hooks: command, timer, file descriptor, print, signal, config, completion, modifier - * new plugin API with many new functions: hooks, buffer management, + * new plugin API with many new functions: hooks, buffer management, bars, config files, lists * new display engine, with prefix and message for each line * fixed nick completion bug (missing space after nick) diff --git a/po/POTFILES.in b/po/POTFILES.in index 0379eb893..a432640f4 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -26,6 +26,7 @@ ./src/core/wee-utf8.h ./src/core/wee-util.c ./src/core/wee-util.h +./src/gui/curses/gui-curses-bar.c ./src/gui/curses/gui-curses-chat.c ./src/gui/curses/gui-curses-color.c ./src/gui/curses/gui-curses.h @@ -36,6 +37,7 @@ ./src/gui/curses/gui-curses-nicklist.c ./src/gui/curses/gui-curses-status.c ./src/gui/curses/gui-curses-window.c +./src/gui/gtk/gui-gtk-bar.c ./src/gui/gtk/gui-gtk-chat.c ./src/gui/gtk/gui-gtk-color.c ./src/gui/gtk/gui-gtk.h @@ -48,6 +50,10 @@ ./src/gui/gtk/gui-gtk-window.c ./src/gui/gui-action.c ./src/gui/gui-action.h +./src/gui/gui-bar.c +./src/gui/gui-bar.h +./src/gui/gui-bar-item.c +./src/gui/gui-bar-item.h ./src/gui/gui-buffer.c ./src/gui/gui-buffer.h ./src/gui/gui-chat.c diff --git a/po/cs.po b/po/cs.po index 4269ae107..84e0fe5e7 100644 --- a/po/cs.po +++ b/po/cs.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-02-22 14:17+0100\n" +"POT-Creation-Date: 2008-03-05 14:04+0100\n" "PO-Revision-Date: 2007-09-06 12:44+0200\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -109,13 +109,68 @@ msgstr "%sVítejte do %s%s%s, %s\n" msgid "compiled on" msgstr "kompilováno" -msgid "Buffers list:" +#, fuzzy +msgid "List of bars:" +msgstr "Seznam pro aliasy:\n" + +#, c-format +msgid " %d. %s: %s, %s, %s: %d, items: %s%s (plugin: %s)" msgstr "" +#, fuzzy +msgid "height" +msgstr "vpravo" + +msgid "width" +msgstr "" + +#, fuzzy +msgid ", with separator" +msgstr "barva pro dělič času" + +#, fuzzy +msgid "No bar defined" +msgstr "Žádné aliasy nejsou definovány.\n" + +#, fuzzy +msgid "List of bar items:" +msgstr "Seznam pro aliasy:\n" + +#, fuzzy, c-format +msgid " %s (plugin: %s)" +msgstr " (není plugin)\n" + +#, fuzzy +msgid "No bar item defined" +msgstr "Žádné aliasy nejsou definovány.\n" + #, fuzzy, c-format msgid "%sError: missing arguments for \"%s\" command" msgstr "%s chybí argumenty pro příkaz \"%s\"\n" +#, fuzzy, c-format +msgid "%sError: wrong type \"%s\" for bar \"%s\"" +msgstr "%s špatný počet parametrů pro příkaz \"%s\"\n" + +#, fuzzy, c-format +msgid "%sError: wrong position \"%s\" for bar \"%s\"" +msgstr "%s neznámá volba pro příkaz \"%s\"\n" + +#, fuzzy, c-format +msgid "%sBar \"%s\" created" +msgstr "Alias \"%s\" => \"%s\" vytvořen\n" + +#, fuzzy, c-format +msgid "%sError: failed to create bar \"%s\"" +msgstr "%s selhalo uložení nastavení pluginů\n" + +#, fuzzy, c-format +msgid "%sError: wrong size \"%s\" for bar \"%s\"" +msgstr "%s špatný počet parametrů pro příkaz \"%s\"\n" + +msgid "Buffers list:" +msgstr "" + #, fuzzy, c-format msgid "%sError: incorrect buffer number" msgstr "%s nekorektní číslo bufferu\n" @@ -436,6 +491,24 @@ msgstr "" "%s nemohu spojit okna, není zde další okno se stejnou velikostí poblíž " "aktuálního okna.\n" +#, fuzzy +msgid "manage bars" +msgstr "řídit buffery" + +msgid "[add name type position size [separator]] | [list]" +msgstr "" + +msgid "" +" add: add a new bar\n" +" name: name of bar (must be unique)\n" +" type: \"root\" (outside windows), \"window_active\" (inside active " +"window), or \"window_inactive\" (inside each inactive window)\n" +" position: bottom, top, left or right\n" +" size: size of bar (in chars)\n" +"separator: 1 for using separator (line), 0 or nothing means no separator\n" +" list: list all bars" +msgstr "" + msgid "manage buffers" msgstr "řídit buffery" @@ -1482,6 +1555,10 @@ msgstr "-VÍCE-" msgid "server" msgstr "server" +#, fuzzy +msgid "(MORE)" +msgstr "-VÍCE-" + #, fuzzy, c-format msgid "%sError: a buffer with same name already exists (%s / %s)" msgstr "" @@ -1820,6 +1897,14 @@ msgstr "" " buffer: vypíše obsah bufferu s hexadecimálními hodnotami do log souboru\n" "windows: zobrazit strom oken" +#, fuzzy, c-format +msgid "%s: debug enabled" +msgstr "FIFO roura je otevřena\n" + +#, c-format +msgid "%s: debug disabled" +msgstr "" + msgid "demo message without prefix" msgstr "" @@ -3278,14 +3363,6 @@ msgstr "Ruším aktivní DCC: \"%s\" od %s\n" msgid "IRC debug messages" msgstr "vypsat debug zprávy" -#, fuzzy, c-format -msgid "%s: debug enabled" -msgstr "FIFO roura je otevřena\n" - -#, c-format -msgid "%s: debug disabled" -msgstr "" - #, fuzzy, c-format msgid "%sServer: %s%s %s[%s%s%s]" msgstr "%sServer: %s%s %s[%s%s%s]\n" @@ -5503,9 +5580,6 @@ msgstr "%s špatné parametry pro příkaz \"%s\"\n" #~ msgid "left" #~ msgstr "vlevo" -#~ msgid "right" -#~ msgstr "vpravo" - #~ msgid "Open panels:\n" #~ msgstr "Otevřené panely:\n" @@ -5655,9 +5729,6 @@ msgstr "%s špatné parametry pro příkaz \"%s\"\n" #~ msgid "if set, uses real white color" #~ msgstr "pokud je nastaveno, použije se skutečná bílá barva" -#~ msgid "color for time separator" -#~ msgstr "barva pro dělič času" - #~ msgid "color for time separator (chat window)" #~ msgstr "barva pro dělič času (okno rozhovoru)" diff --git a/po/de.po b/po/de.po index 80dd52b10..6f7777ae7 100644 --- a/po/de.po +++ b/po/de.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-02-22 14:17+0100\n" +"POT-Creation-Date: 2008-03-05 14:04+0100\n" "PO-Revision-Date: 2007-09-06 12:44+0200\n" "Last-Translator: Thomas Schuetz \n" "Language-Team: weechat-dev \n" @@ -114,13 +114,68 @@ msgstr "%sWillkommen in %s%s%s, %s\n" msgid "compiled on" msgstr "kompiliert am" -msgid "Buffers list:" +#, fuzzy +msgid "List of bars:" +msgstr "Liste der Aliases:\n" + +#, c-format +msgid " %d. %s: %s, %s, %s: %d, items: %s%s (plugin: %s)" msgstr "" +#, fuzzy +msgid "height" +msgstr "right" + +msgid "width" +msgstr "" + +#, fuzzy +msgid ", with separator" +msgstr "Farbe für den Zeit-Separator" + +#, fuzzy +msgid "No bar defined" +msgstr "Keine Aliases definiert.\n" + +#, fuzzy +msgid "List of bar items:" +msgstr "Liste der Aliases:\n" + +#, fuzzy, c-format +msgid " %s (plugin: %s)" +msgstr " (kein Plugin)\n" + +#, fuzzy +msgid "No bar item defined" +msgstr "Keine Aliases definiert.\n" + #, fuzzy, c-format msgid "%sError: missing arguments for \"%s\" command" msgstr "%s fehlende Argumente für den \"%s\"-Befehl\n" +#, fuzzy, c-format +msgid "%sError: wrong type \"%s\" for bar \"%s\"" +msgstr "%s fehlerhafte Anzahl von Argumenten für der \"%s\"-Befehl\n" + +#, fuzzy, c-format +msgid "%sError: wrong position \"%s\" for bar \"%s\"" +msgstr "%s unbekannte Option für den \"%s\"-Befehl\n" + +#, fuzzy, c-format +msgid "%sBar \"%s\" created" +msgstr "Alias \"%s\" => \"%s\" angelegt\n" + +#, fuzzy, c-format +msgid "%sError: failed to create bar \"%s\"" +msgstr "%s konnte die Plugin-Konfigurationsdatei nicht sichern\n" + +#, fuzzy, c-format +msgid "%sError: wrong size \"%s\" for bar \"%s\"" +msgstr "%s fehlerhafte Anzahl von Argumenten für der \"%s\"-Befehl\n" + +msgid "Buffers list:" +msgstr "" + #, fuzzy, c-format msgid "%sError: incorrect buffer number" msgstr "%s falsche Puffernummer\n" @@ -444,6 +499,24 @@ msgstr "" "%s kann Fenster nicht vereinigen, es ist kein Fenster mit der gleichen Größe " "in der Nähe des aktuellen Fensters.\n" +#, fuzzy +msgid "manage bars" +msgstr "Puffer verwalten" + +msgid "[add name type position size [separator]] | [list]" +msgstr "" + +msgid "" +" add: add a new bar\n" +" name: name of bar (must be unique)\n" +" type: \"root\" (outside windows), \"window_active\" (inside active " +"window), or \"window_inactive\" (inside each inactive window)\n" +" position: bottom, top, left or right\n" +" size: size of bar (in chars)\n" +"separator: 1 for using separator (line), 0 or nothing means no separator\n" +" list: list all bars" +msgstr "" + msgid "manage buffers" msgstr "Puffer verwalten" @@ -1482,6 +1555,10 @@ msgstr "-MEHR-" msgid "server" msgstr "Server" +#, fuzzy +msgid "(MORE)" +msgstr "-MEHR-" + #, fuzzy, c-format msgid "%sError: a buffer with same name already exists (%s / %s)" msgstr "" @@ -1823,6 +1900,14 @@ msgstr "" "Programmabsturz)\n" "windows: zeigt Fensterdaten an" +#, fuzzy, c-format +msgid "%s: debug enabled" +msgstr "FIFO ist offen\n" + +#, c-format +msgid "%s: debug disabled" +msgstr "" + msgid "demo message without prefix" msgstr "" @@ -3266,14 +3351,6 @@ msgstr "Aktiver DCC wird abgebrochen: \"%s\" von %s\n" msgid "IRC debug messages" msgstr "Debugging-Nachricht ausgeben" -#, fuzzy, c-format -msgid "%s: debug enabled" -msgstr "FIFO ist offen\n" - -#, c-format -msgid "%s: debug disabled" -msgstr "" - #, fuzzy, c-format msgid "%sServer: %s%s %s[%s%s%s]" msgstr "%sServer: %s%s %s[%s%s%s]\n" @@ -5509,9 +5586,6 @@ msgstr "%s fehlerhafte Argumente für der \"%s\"-Befehl\n" #~ msgid "left" #~ msgstr "left" -#~ msgid "right" -#~ msgstr "right" - #~ msgid "Open panels:\n" #~ msgstr "Offene Panel:\n" @@ -5665,9 +5739,6 @@ msgstr "%s fehlerhafte Argumente für der \"%s\"-Befehl\n" #~ msgid "if set, uses real white color" #~ msgstr "wenn gesetzt, benutze echtes Weiß" -#~ msgid "color for time separator" -#~ msgstr "Farbe für den Zeit-Separator" - #~ msgid "color for time separator (chat window)" #~ msgstr "Farbe für den Zeit-Separator im Chatfenster" diff --git a/po/es.po b/po/es.po index 2890a2c53..ed9b9f940 100644 --- a/po/es.po +++ b/po/es.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-02-22 14:17+0100\n" +"POT-Creation-Date: 2008-03-05 14:04+0100\n" "PO-Revision-Date: 2007-09-19 12:09+0200\n" "Last-Translator: Roberto González Cardenete \n" "Language-Team: weechat-dev \n" @@ -111,13 +111,67 @@ msgstr "%sBienvenido a %s%s%s, %s\n" msgid "compiled on" msgstr "compilado en" -msgid "Buffers list:" +#, fuzzy +msgid "List of bars:" +msgstr "Lista de alias:\n" + +#, c-format +msgid " %d. %s: %s, %s, %s: %d, items: %s%s (plugin: %s)" msgstr "" +msgid "height" +msgstr "" + +msgid "width" +msgstr "" + +#, fuzzy +msgid ", with separator" +msgstr "color para el separador de la hora" + +#, fuzzy +msgid "No bar defined" +msgstr "Ningún alias definido.\n" + +#, fuzzy +msgid "List of bar items:" +msgstr "Lista de alias:\n" + +#, fuzzy, c-format +msgid " %s (plugin: %s)" +msgstr " (sin plugins)\n" + +#, fuzzy +msgid "No bar item defined" +msgstr "Ningún alias definido.\n" + #, fuzzy, c-format msgid "%sError: missing arguments for \"%s\" command" msgstr "%s faltan argumentos para el comando \"%s\"\n" +#, fuzzy, c-format +msgid "%sError: wrong type \"%s\" for bar \"%s\"" +msgstr "%s número de argumentos incorrecto para el comando \"%s\"\n" + +#, fuzzy, c-format +msgid "%sError: wrong position \"%s\" for bar \"%s\"" +msgstr "%s opción desconocida para el comando \"%s\"\n" + +#, fuzzy, c-format +msgid "%sBar \"%s\" created" +msgstr "Alias \"%s\" => \"%s\" creado\n" + +#, fuzzy, c-format +msgid "%sError: failed to create bar \"%s\"" +msgstr "%s falló al salvar el archivo de configuración\n" + +#, fuzzy, c-format +msgid "%sError: wrong size \"%s\" for bar \"%s\"" +msgstr "%s número de argumentos incorrecto para el comando \"%s\"\n" + +msgid "Buffers list:" +msgstr "" + #, fuzzy, c-format msgid "%sError: incorrect buffer number" msgstr "%s número de búfer incorrecto\n" @@ -441,6 +495,24 @@ msgstr "" "%s no puede fusionar ventanas, no hay ninguna otra ventana con el mismo tamaÃ" "±o que la actual.\n" +#, fuzzy +msgid "manage bars" +msgstr "gestionar los búfers" + +msgid "[add name type position size [separator]] | [list]" +msgstr "" + +msgid "" +" add: add a new bar\n" +" name: name of bar (must be unique)\n" +" type: \"root\" (outside windows), \"window_active\" (inside active " +"window), or \"window_inactive\" (inside each inactive window)\n" +" position: bottom, top, left or right\n" +" size: size of bar (in chars)\n" +"separator: 1 for using separator (line), 0 or nothing means no separator\n" +" list: list all bars" +msgstr "" + msgid "manage buffers" msgstr "gestionar los búfers" @@ -1470,6 +1542,10 @@ msgstr "-MÁS-" msgid "server" msgstr "servidor" +#, fuzzy +msgid "(MORE)" +msgstr "-MÁS-" + #, fuzzy, c-format msgid "%sError: a buffer with same name already exists (%s / %s)" msgstr "" @@ -1810,6 +1886,14 @@ msgstr "" "(el mismo volcado se escribe cuando Weechat se cuelga)\n" "ventanas: mostrar árbol de ventanas" +#, fuzzy, c-format +msgid "%s: debug enabled" +msgstr "La tubería FIFO está abierta\n" + +#, c-format +msgid "%s: debug disabled" +msgstr "" + msgid "demo message without prefix" msgstr "" @@ -3271,14 +3355,6 @@ msgstr "Abandonar el DCC activo: \"%s\" de %s\n" msgid "IRC debug messages" msgstr "imprime mensajes de depuración" -#, fuzzy, c-format -msgid "%s: debug enabled" -msgstr "La tubería FIFO está abierta\n" - -#, c-format -msgid "%s: debug disabled" -msgstr "" - #, fuzzy, c-format msgid "%sServer: %s%s %s[%s%s%s]" msgstr "%sServidor:%s%s %s[%s%s%s]\n" @@ -5677,9 +5753,6 @@ msgstr "%s argumentos incorrectos para el comando \"%s\"\n" #~ msgid "if set, uses real white color" #~ msgstr "si se establece, usa el color blanco verdadero" -#~ msgid "color for time separator" -#~ msgstr "color para el separador de la hora" - #~ msgid "color for time separator (chat window)" #~ msgstr "color para el separador de la hora (ventana de conversación)" diff --git a/po/fr.po b/po/fr.po index 9abab7fc6..d66f0dc89 100644 --- a/po/fr.po +++ b/po/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-02-22 14:17+0100\n" -"PO-Revision-Date: 2008-02-22 14:18+0100\n" +"POT-Creation-Date: 2008-03-05 14:04+0100\n" +"PO-Revision-Date: 2008-03-05 14:04+0100\n" "Last-Translator: FlashCode \n" "Language-Team: weechat-dev \n" "MIME-Version: 1.0\n" @@ -107,13 +107,62 @@ msgstr "%sBienvenue dans %s%s%s, %s" msgid "compiled on" msgstr "compilé le" -msgid "Buffers list:" -msgstr "Liste des tampons:" +msgid "List of bars:" +msgstr "Liste des barres:" + +#, c-format +msgid " %d. %s: %s, %s, %s: %d, items: %s%s (plugin: %s)" +msgstr " %d. %s: %s, %s, %s: %d, objets: %s%s (extension: %s)" + +msgid "height" +msgstr "hauteur" + +msgid "width" +msgstr "largeur" + +msgid ", with separator" +msgstr ", avec séparateur" + +msgid "No bar defined" +msgstr "Pas de barre définie" + +msgid "List of bar items:" +msgstr "Liste des objets de barres:" + +#, c-format +msgid " %s (plugin: %s)" +msgstr " %s (extension: %s)" + +msgid "No bar item defined" +msgstr "Pas d'objet de barre défini" #, c-format msgid "%sError: missing arguments for \"%s\" command" msgstr "%sErreur: paramètres manquants pour la commande \"%s\"" +#, c-format +msgid "%sError: wrong type \"%s\" for bar \"%s\"" +msgstr "%sErreur: type erroné \"%s\" pour la barre \"%s\"" + +#, c-format +msgid "%sError: wrong position \"%s\" for bar \"%s\"" +msgstr "%sErreur: position erronée \"%s\" pour la barre \"%s\"" + +#, c-format +msgid "%sBar \"%s\" created" +msgstr "%sBarre \"%s\" créée" + +#, c-format +msgid "%sError: failed to create bar \"%s\"" +msgstr "%sErreur: impossible de créer la barre \"%s\"" + +#, c-format +msgid "%sError: wrong size \"%s\" for bar \"%s\"" +msgstr "%sErreur: taille erronée \"%s\" pour la barre \"%s\"" + +msgid "Buffers list:" +msgstr "Liste des tampons:" + #, c-format msgid "%sError: incorrect buffer number" msgstr "%sErreur: numéro de tampon incorrect" @@ -404,6 +453,32 @@ msgstr "" "%sErreur: impossible de fusionner les fenêtres, aucun autre fenêtre avec la " "même taille à coté de la fenêtre actuelle" +msgid "manage bars" +msgstr "gestion des barres" + +msgid "[add name type position size [separator]] | [list]" +msgstr "[add nom type position taille [separateur]] | [list]" + +msgid "" +" add: add a new bar\n" +" name: name of bar (must be unique)\n" +" type: \"root\" (outside windows), \"window_active\" (inside active " +"window), or \"window_inactive\" (inside each inactive window)\n" +" position: bottom, top, left or right\n" +" size: size of bar (in chars)\n" +"separator: 1 for using separator (line), 0 or nothing means no separator\n" +" list: list all bars" +msgstr "" +" add: ajoute une nouvelle barre\n" +" nom: nom de la barre (doit être unique)\n" +" type: \"root\" (en dehors des fenêtres), \"window_active\" (dans la " +"fenêtre active), \"window_inactive\" (dans chaque fenêtre inactive)\n" +" position: bottom (bas), top (haut), left (gauche) ou right (droite)\n" +" taille: taille de la barre (en caractères)\n" +"separateur: 1 pour utiliser un séparateur (ligne), 0 ou rien signifie sans " +"séparateur\n" +" list: liste toutes les barres" + msgid "manage buffers" msgstr "gestion des tampons" @@ -1390,6 +1465,9 @@ msgstr "-PLUS-" msgid "server" msgstr "serveur" +msgid "(MORE)" +msgstr "(PLUS)" + #, c-format msgid "%sError: a buffer with same name already exists (%s / %s)" msgstr "%sErreur: un tampon avec le même nom existe déjà (%s / %s)" @@ -1734,6 +1812,14 @@ msgstr "" "windows: affiche l'arbre des fenêtres<\n" " texte: envoie le signal \"debug\" avec \"texte\" comme paramètre" +#, c-format +msgid "%s: debug enabled" +msgstr "%s: debug activé" + +#, c-format +msgid "%s: debug disabled" +msgstr "%s: debug désactivé" + msgid "demo message without prefix" msgstr "message de démonstration sans préfixe" @@ -3197,14 +3283,6 @@ msgstr "Abandon du DCC actif: \"%s\" de %s" msgid "IRC debug messages" msgstr "Messages de debug IRC" -#, c-format -msgid "%s: debug enabled" -msgstr "%s: debug activé" - -#, c-format -msgid "%s: debug disabled" -msgstr "%s: debug désactivé" - #, c-format msgid "%sServer: %s%s %s[%s%s%s]" msgstr "%sServeur: %s%s %s[%s%s%s]" diff --git a/po/hu.po b/po/hu.po index 570e04677..7851e3c78 100644 --- a/po/hu.po +++ b/po/hu.po @@ -12,7 +12,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-02-22 14:17+0100\n" +"POT-Creation-Date: 2008-03-05 14:04+0100\n" "PO-Revision-Date: 2007-10-10 18:07+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -115,13 +115,68 @@ msgstr "%sÜdvözöli a %s%s%s, %s\n" msgid "compiled on" msgstr "lefordítva:" -msgid "Buffers list:" +#, fuzzy +msgid "List of bars:" +msgstr "Aliaszok listája:\n" + +#, c-format +msgid " %d. %s: %s, %s, %s: %d, items: %s%s (plugin: %s)" msgstr "" +#, fuzzy +msgid "height" +msgstr "jobb" + +msgid "width" +msgstr "" + +#, fuzzy +msgid ", with separator" +msgstr "időelválasztó színe" + +#, fuzzy +msgid "No bar defined" +msgstr "Nincs aliasz definiálva.\n" + +#, fuzzy +msgid "List of bar items:" +msgstr "Aliaszok listája:\n" + +#, fuzzy, c-format +msgid " %s (plugin: %s)" +msgstr " (nem található bővítőmodul)\n" + +#, fuzzy +msgid "No bar item defined" +msgstr "Nincs aliasz definiálva.\n" + #, fuzzy, c-format msgid "%sError: missing arguments for \"%s\" command" msgstr "%s hiányzó argumentum a \"%s\" parancsnak\n" +#, fuzzy, c-format +msgid "%sError: wrong type \"%s\" for bar \"%s\"" +msgstr "%s rossz argumentum szám a \"%s\" parancsnak\n" + +#, fuzzy, c-format +msgid "%sError: wrong position \"%s\" for bar \"%s\"" +msgstr "%s ismeretlen opció a \"%s\" parancsnak\n" + +#, fuzzy, c-format +msgid "%sBar \"%s\" created" +msgstr "A \"%s\" => \"%s\" aliasz elkészült\n" + +#, fuzzy, c-format +msgid "%sError: failed to create bar \"%s\"" +msgstr "%s nem sikerült a modul opciókat elmenteni\n" + +#, fuzzy, c-format +msgid "%sError: wrong size \"%s\" for bar \"%s\"" +msgstr "%s rossz argumentum szám a \"%s\" parancsnak\n" + +msgid "Buffers list:" +msgstr "" + #, fuzzy, c-format msgid "%sError: incorrect buffer number" msgstr "%s helytelen pufferszám\n" @@ -442,6 +497,24 @@ msgstr "" "%s nem sikerült az ablakokat összefésülni: nincs a közelben azonos méretű " "ablak.\n" +#, fuzzy +msgid "manage bars" +msgstr "pufferek kezelése" + +msgid "[add name type position size [separator]] | [list]" +msgstr "" + +msgid "" +" add: add a new bar\n" +" name: name of bar (must be unique)\n" +" type: \"root\" (outside windows), \"window_active\" (inside active " +"window), or \"window_inactive\" (inside each inactive window)\n" +" position: bottom, top, left or right\n" +" size: size of bar (in chars)\n" +"separator: 1 for using separator (line), 0 or nothing means no separator\n" +" list: list all bars" +msgstr "" + msgid "manage buffers" msgstr "pufferek kezelése" @@ -1487,6 +1560,10 @@ msgstr "-TOVÁBB-" msgid "server" msgstr "szerver" +#, fuzzy +msgid "(MORE)" +msgstr "-TOVÁBB-" + #, fuzzy, c-format msgid "%sError: a buffer with same name already exists (%s / %s)" msgstr "%s nem sikerült a \"%s\" modult betölteni: már van ilyen nevű modul\n" @@ -1827,6 +1904,14 @@ msgstr "" " buffer: hexadecimális puffertartalom logba írása\n" "windows: ablakfa megjelenítése" +#, fuzzy, c-format +msgid "%s: debug enabled" +msgstr "FIFO cső nyitva\n" + +#, c-format +msgid "%s: debug disabled" +msgstr "" + msgid "demo message without prefix" msgstr "" @@ -3284,14 +3369,6 @@ msgstr "\"%s\" aktív DCC megszakítása a következővel: %s\n" msgid "IRC debug messages" msgstr "hibakereső üzenetek megjelenítése" -#, fuzzy, c-format -msgid "%s: debug enabled" -msgstr "FIFO cső nyitva\n" - -#, c-format -msgid "%s: debug disabled" -msgstr "" - #, fuzzy, c-format msgid "%sServer: %s%s %s[%s%s%s]" msgstr "%s Szerver: %s%s %s[%s%s%s]\n" @@ -5505,9 +5582,6 @@ msgstr "%s rossz argumentum a \"%s\" parancsnak\n" #~ msgid "left" #~ msgstr "bal" -#~ msgid "right" -#~ msgstr "jobb" - #~ msgid "Open panels:\n" #~ msgstr "Nyitott panelek:\n" @@ -5642,9 +5716,6 @@ msgstr "%s rossz argumentum a \"%s\" parancsnak\n" #~ msgid "if set, uses real white color" #~ msgstr "ha be van állítva, akkor valódi fehér színt használ" -#~ msgid "color for time separator" -#~ msgstr "időelválasztó színe" - #~ msgid "color for time separator (chat window)" #~ msgstr "időelválasztó színe (beszédablak)" diff --git a/po/ru.po b/po/ru.po index 186373337..3ecb581bf 100644 --- a/po/ru.po +++ b/po/ru.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.2.7-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2008-02-22 14:17+0100\n" +"POT-Creation-Date: 2008-03-05 14:04+0100\n" "PO-Revision-Date: 2007-09-06 12:44+0200\n" "Last-Translator: Pavel Shevchuk \n" "Language-Team: weechat-dev \n" @@ -111,13 +111,68 @@ msgstr "%sДобро пожаловать в %s%s%s, %s\n" msgid "compiled on" msgstr "собран:" -msgid "Buffers list:" +#, fuzzy +msgid "List of bars:" +msgstr "Список сокращений:\n" + +#, c-format +msgid " %d. %s: %s, %s, %s: %d, items: %s%s (plugin: %s)" msgstr "" +#, fuzzy +msgid "height" +msgstr "справа" + +msgid "width" +msgstr "" + +#, fuzzy +msgid ", with separator" +msgstr "цвет разделителя времени" + +#, fuzzy +msgid "No bar defined" +msgstr "Сокращения не заданы.\n" + +#, fuzzy +msgid "List of bar items:" +msgstr "Список сокращений:\n" + +#, fuzzy, c-format +msgid " %s (plugin: %s)" +msgstr " (нет pluginа)\n" + +#, fuzzy +msgid "No bar item defined" +msgstr "Сокращения не заданы.\n" + #, fuzzy, c-format msgid "%sError: missing arguments for \"%s\" command" msgstr "%s нет аргументов для \"%s\" команды\n" +#, fuzzy, c-format +msgid "%sError: wrong type \"%s\" for bar \"%s\"" +msgstr "%s некорректное количество аргументов команды \"%s\"\n" + +#, fuzzy, c-format +msgid "%sError: wrong position \"%s\" for bar \"%s\"" +msgstr "%s неизвестный параметр для команды \"%s\"\n" + +#, fuzzy, c-format +msgid "%sBar \"%s\" created" +msgstr "Сокращение \"%s\" => \"%s\" создано\n" + +#, fuzzy, c-format +msgid "%sError: failed to create bar \"%s\"" +msgstr "%s не могу сохранить конфигурационный файл pluginов\n" + +#, fuzzy, c-format +msgid "%sError: wrong size \"%s\" for bar \"%s\"" +msgstr "%s некорректное количество аргументов команды \"%s\"\n" + +msgid "Buffers list:" +msgstr "" + #, fuzzy, c-format msgid "%sError: incorrect buffer number" msgstr "%s неправильный номер буфера\n" @@ -438,6 +493,24 @@ msgstr "" "%s не могу объединить окна, есть другое окно такого-же размера рядом с " "текущим.\n" +#, fuzzy +msgid "manage bars" +msgstr "управление буферами" + +msgid "[add name type position size [separator]] | [list]" +msgstr "" + +msgid "" +" add: add a new bar\n" +" name: name of bar (must be unique)\n" +" type: \"root\" (outside windows), \"window_active\" (inside active " +"window), or \"window_inactive\" (inside each inactive window)\n" +" position: bottom, top, left or right\n" +" size: size of bar (in chars)\n" +"separator: 1 for using separator (line), 0 or nothing means no separator\n" +" list: list all bars" +msgstr "" + msgid "manage buffers" msgstr "управление буферами" @@ -1488,6 +1561,10 @@ msgstr "-ДАЛЬШЕ-" msgid "server" msgstr "сервер" +#, fuzzy +msgid "(MORE)" +msgstr "-ДАЛЬШЕ-" + #, fuzzy, c-format msgid "%sError: a buffer with same name already exists (%s / %s)" msgstr "" @@ -1829,6 +1906,14 @@ msgstr "" "файл\n" "windows: отобразить дерево окон" +#, fuzzy, c-format +msgid "%s: debug enabled" +msgstr "FIFO pipe открыт\n" + +#, c-format +msgid "%s: debug disabled" +msgstr "" + msgid "demo message without prefix" msgstr "" @@ -3272,14 +3357,6 @@ msgstr "Отменяю активное DCC-сединение: \"%s\" от %s\n msgid "IRC debug messages" msgstr "выводить отладочные сообщения" -#, fuzzy, c-format -msgid "%s: debug enabled" -msgstr "FIFO pipe открыт\n" - -#, c-format -msgid "%s: debug disabled" -msgstr "" - #, fuzzy, c-format msgid "%sServer: %s%s %s[%s%s%s]" msgstr "%sСервер: %s%s %s[%s%s%s]\n" @@ -5505,9 +5582,6 @@ msgstr "%s некорректные аргументы команды \"%s\"\n" #~ msgid "left" #~ msgstr "слева" -#~ msgid "right" -#~ msgstr "справа" - #~ msgid "Open panels:\n" #~ msgstr "Открытые панели:\n" @@ -5657,9 +5731,6 @@ msgstr "%s некорректные аргументы команды \"%s\"\n" #~ msgid "if set, uses real white color" #~ msgstr "если установлено - использовать настоящий белый цвет" -#~ msgid "color for time separator" -#~ msgstr "цвет разделителя времени" - #~ msgid "color for time separator (chat window)" #~ msgstr "цвет разделителя времени в окне чата" diff --git a/po/srcfiles.cmake b/po/srcfiles.cmake index a534961bb..9acafbf79 100644 --- a/po/srcfiles.cmake +++ b/po/srcfiles.cmake @@ -27,6 +27,7 @@ SET(WEECHAT_SOURCES ./src/core/wee-utf8.h ./src/core/wee-util.c ./src/core/wee-util.h +./src/gui/curses/gui-curses-bar.c ./src/gui/curses/gui-curses-chat.c ./src/gui/curses/gui-curses-color.c ./src/gui/curses/gui-curses.h @@ -37,6 +38,7 @@ SET(WEECHAT_SOURCES ./src/gui/curses/gui-curses-nicklist.c ./src/gui/curses/gui-curses-status.c ./src/gui/curses/gui-curses-window.c +./src/gui/gtk/gui-gtk-bar.c ./src/gui/gtk/gui-gtk-chat.c ./src/gui/gtk/gui-gtk-color.c ./src/gui/gtk/gui-gtk.h @@ -49,6 +51,10 @@ SET(WEECHAT_SOURCES ./src/gui/gtk/gui-gtk-window.c ./src/gui/gui-action.c ./src/gui/gui-action.h +./src/gui/gui-bar.c +./src/gui/gui-bar.h +./src/gui/gui-bar-item.c +./src/gui/gui-bar-item.h ./src/gui/gui-buffer.c ./src/gui/gui-buffer.h ./src/gui/gui-chat.c diff --git a/po/weechat.pot b/po/weechat.pot index 39948397e..92b1a20ac 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: 2008-02-22 14:17+0100\n" +"POT-Creation-Date: 2008-03-05 14:04+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -90,13 +90,62 @@ msgstr "" msgid "compiled on" msgstr "" -msgid "Buffers list:" +msgid "List of bars:" +msgstr "" + +#, c-format +msgid " %d. %s: %s, %s, %s: %d, items: %s%s (plugin: %s)" +msgstr "" + +msgid "height" +msgstr "" + +msgid "width" +msgstr "" + +msgid ", with separator" +msgstr "" + +msgid "No bar defined" +msgstr "" + +msgid "List of bar items:" +msgstr "" + +#, c-format +msgid " %s (plugin: %s)" +msgstr "" + +msgid "No bar item defined" msgstr "" #, c-format msgid "%sError: missing arguments for \"%s\" command" msgstr "" +#, c-format +msgid "%sError: wrong type \"%s\" for bar \"%s\"" +msgstr "" + +#, c-format +msgid "%sError: wrong position \"%s\" for bar \"%s\"" +msgstr "" + +#, c-format +msgid "%sBar \"%s\" created" +msgstr "" + +#, c-format +msgid "%sError: failed to create bar \"%s\"" +msgstr "" + +#, c-format +msgid "%sError: wrong size \"%s\" for bar \"%s\"" +msgstr "" + +msgid "Buffers list:" +msgstr "" + #, c-format msgid "%sError: incorrect buffer number" msgstr "" @@ -383,6 +432,23 @@ msgid "" "current one" msgstr "" +msgid "manage bars" +msgstr "" + +msgid "[add name type position size [separator]] | [list]" +msgstr "" + +msgid "" +" add: add a new bar\n" +" name: name of bar (must be unique)\n" +" type: \"root\" (outside windows), \"window_active\" (inside active " +"window), or \"window_inactive\" (inside each inactive window)\n" +" position: bottom, top, left or right\n" +" size: size of bar (in chars)\n" +"separator: 1 for using separator (line), 0 or nothing means no separator\n" +" list: list all bars" +msgstr "" + msgid "manage buffers" msgstr "" @@ -1198,6 +1264,9 @@ msgstr "" msgid "server" msgstr "" +msgid "(MORE)" +msgstr "" + #, c-format msgid "%sError: a buffer with same name already exists (%s / %s)" msgstr "" @@ -1508,6 +1577,14 @@ msgid "" " text: send \"debug\" signal with \"text\" as argument" msgstr "" +#, c-format +msgid "%s: debug enabled" +msgstr "" + +#, c-format +msgid "%s: debug disabled" +msgstr "" + msgid "demo message without prefix" msgstr "" @@ -2749,14 +2826,6 @@ msgstr "" msgid "IRC debug messages" msgstr "" -#, c-format -msgid "%s: debug enabled" -msgstr "" - -#, c-format -msgid "%s: debug disabled" -msgstr "" - #, c-format msgid "%sServer: %s%s %s[%s%s%s]" msgstr "" diff --git a/src/core/wee-command.c b/src/core/wee-command.c index cad279d1f..5c6f62cd0 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -40,6 +40,8 @@ #include "wee-string.h" #include "wee-utf8.h" #include "wee-list.h" +#include "../gui/gui-bar.h" +#include "../gui/gui-bar-item.h" #include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" #include "../gui/gui-color.h" @@ -52,6 +54,162 @@ #include "../plugins/plugin-config.h" +/* + * command_bar: manage bars + */ + +int +command_bar (void *data, struct t_gui_buffer *buffer, + int argc, char **argv, char **argv_eol) +{ + int i, type, position, size, separator; + long number; + char *error; + struct t_gui_bar *ptr_bar; + struct t_gui_bar_item *ptr_item; + + /* make C compiler happy */ + (void) data; + (void) buffer; + (void) argc; + (void) argv; + (void) argv_eol; + + if ((argc == 1) + || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) + { + /* list of bars */ + if (gui_bars) + { + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("List of bars:")); + for (ptr_bar = gui_bars; ptr_bar; + ptr_bar = ptr_bar->next_bar) + { + gui_chat_printf (NULL, + _(" %d. %s: %s, %s, %s: %d, items: %s%s (plugin: %s)"), + ptr_bar->number, + ptr_bar->name, + gui_bar_type_str[ptr_bar->type], + gui_bar_position_str[ptr_bar->position], + ((ptr_bar->position == GUI_BAR_POSITION_BOTTOM) + || (ptr_bar->position == GUI_BAR_POSITION_TOP)) ? + _("height") : _("width"), + ptr_bar->size, + (ptr_bar->items) ? ptr_bar->items : "-", + (ptr_bar->separator) ? + _(", with separator") : "", + (ptr_bar->plugin) ? ptr_bar->plugin->name : "-"); + } + } + else + gui_chat_printf (NULL, _("No bar defined")); + + /* list of bar items */ + if (gui_bar_items) + { + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("List of bar items:")); + for (ptr_item = gui_bar_items; ptr_item; + ptr_item = ptr_item->next_item) + { + gui_chat_printf (NULL, + _(" %s (plugin: %s)"), + ptr_item->name, + (ptr_item->plugin) ? ptr_item->plugin->name : "-"); + } + } + else + gui_chat_printf (NULL, _("No bar item defined")); + } + else + { + if (string_strcasecmp (argv[1], "add") == 0) + { + if (argc < 8) + { + gui_chat_printf (NULL, + _("%sError: missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "bar"); + return WEECHAT_RC_ERROR; + } + type = -1; + for (i = 0; i < GUI_BAR_NUM_TYPES; i++) + { + if (string_strcasecmp (argv[3], gui_bar_type_str[i]) == 0) + { + type = i; + break; + } + } + if (type < 0) + { + gui_chat_printf (NULL, + _("%sError: wrong type \"%s\" for bar " + "\"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[3], argv[2]); + return WEECHAT_RC_ERROR; + } + position = -1; + for (i = 0; i < GUI_BAR_NUM_POSITIONS; i++) + { + if (string_strcasecmp (argv[4], gui_bar_position_str[i]) == 0) + { + position = i; + break; + } + } + if (position < 0) + { + gui_chat_printf (NULL, + _("%sError: wrong position \"%s\" for bar " + "\"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[4], argv[2]); + return WEECHAT_RC_ERROR; + } + error = NULL; + number = strtol (argv[5], &error, 10); + if (error && (error[0] == '\0')) + { + size = number; + separator = 0; + if (strcmp (argv[6], "0") != 0) + separator = 1; + + /* create bar */ + if (gui_bar_new (NULL, argv[2], argv[3], argv[4], size, + separator, argv[7])) + gui_chat_printf (NULL, _("%sBar \"%s\" created"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO], + argv[2]); + else + gui_chat_printf (NULL, _("%sError: failed to create bar " + "\"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[2]); + } + else + { + gui_chat_printf (NULL, + _("%sError: wrong size \"%s\" for bar " + "\"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[5], argv[2]); + return WEECHAT_RC_ERROR; + } + } + else + { + } + } + + return WEECHAT_RC_OK; +} + /* * command_buffer: manage buffers */ @@ -1870,6 +2028,21 @@ command_window (void *data, struct t_gui_buffer *buffer, void command_init () { + hook_command (NULL, "bar", + N_("manage bars"), + N_("[add name type position size [separator]] | [list]"), + N_(" add: add a new bar\n" + " name: name of bar (must be unique)\n" + " type: \"root\" (outside windows), \"window_active\" " + "(inside active window), or \"window_inactive\" (inside " + "each inactive window)\n" + " position: bottom, top, left or right\n" + " size: size of bar (in chars)\n" + "separator: 1 for using separator (line), 0 or nothing " + "means no separator\n" + " list: list all bars"), + "list", + &command_bar, NULL); hook_command (NULL, "buffer", N_("manage buffers"), N_("[action [args] | number | [[server] [channel]]]"), diff --git a/src/core/wee-config.c b/src/core/wee-config.c index f2270fe02..9e4484f85 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -1015,7 +1015,7 @@ config_weechat_init () weechat_config_file, ptr_section, "color_status_more", "color", N_("text color for buffer with new data (status bar)"), - NULL, GUI_COLOR_STATUS_MORE, 0, "white", &config_change_color, NULL); + NULL, GUI_COLOR_STATUS_MORE, 0, "yellow", &config_change_color, NULL); /* infobar window */ config_color_infobar = config_file_new_option ( weechat_config_file, ptr_section, diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c index 2682e4e16..e886021a3 100644 --- a/src/core/wee-debug.c +++ b/src/core/wee-debug.c @@ -31,6 +31,8 @@ #include "wee-log.h" #include "wee-hook.h" #include "wee-string.h" +#include "../gui/gui-bar.h" +#include "../gui/gui-bar-item.h" #include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" #include "../gui/gui-hotlist.h" @@ -73,6 +75,8 @@ debug_dump (int crash) gui_window_print_log (); gui_buffer_print_log (); + gui_bar_print_log (); + gui_bar_item_print_log (); gui_hotlist_print_log (); hook_print_log (); diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h index 26f684b06..8cdb7946e 100644 --- a/src/core/wee-hook.h +++ b/src/core/wee-hook.h @@ -34,7 +34,7 @@ enum t_hook_type HOOK_TYPE_SIGNAL, /* signal */ HOOK_TYPE_CONFIG, /* config option */ HOOK_TYPE_COMPLETION, /* custom completions */ - HOOK_TYPE_MODIFIER, /* stirng modifier */ + HOOK_TYPE_MODIFIER, /* string modifier */ /* number of hook types */ HOOK_NUM_TYPES, }; diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 75c971aba..962147e55 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -18,10 +18,11 @@ IF(NOT DISABLE_NCURSES) SUBDIRS( curses ) ENDIF(NOT DISABLE_NCURSES) -SET(LIB_GUI_COMMON_SRC gui-action.c gui-action.h gui-buffer.c gui-buffer.h -gui-chat.c gui-chat.h gui-color.c gui-color.h gui-completion.c gui-completion.h -gui-history.c gui-history.h gui-hotlist.c gui-hotlist.h gui-infobar.c -gui-infobar.h gui-input.c gui-input.h gui-keyboard.c gui-keyboard.h gui-main.h +SET(LIB_GUI_COMMON_SRC gui-action.c gui-action.h gui-bar.c gui-bar.h +gui-bar-item.c gui-bar-item.h gui-buffer.c gui-buffer.h gui-chat.c gui-chat.h +gui-color.c gui-color.h gui-completion.c gui-completion.h gui-history.c +gui-history.h gui-hotlist.c gui-hotlist.h gui-infobar.c gui-infobar.h +gui-input.c gui-input.h gui-keyboard.c gui-keyboard.h gui-main.h gui-nicklist.c gui-nicklist.h gui-status.h gui-window.c gui-window.h) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 49d963709..12c4575fa 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -20,6 +20,10 @@ noinst_LIBRARIES = lib_weechat_gui_common.a lib_weechat_gui_common_a_SOURCES = gui-action.c \ gui-action.h \ + gui-bar.c \ + gui-bar.h \ + gui-bar-item.c \ + gui-bar-item.h \ gui-buffer.c \ gui-buffer.h \ gui-chat.c \ diff --git a/src/gui/curses/CMakeLists.txt b/src/gui/curses/CMakeLists.txt index e9694172f..4d2b8cca9 100644 --- a/src/gui/curses/CMakeLists.txt +++ b/src/gui/curses/CMakeLists.txt @@ -14,9 +14,9 @@ # along with this program. If not, see . # -SET(WEECHAT_CURSES_SRC gui-curses-chat.c gui-curses-color.c gui-curses-infobar.c -gui-curses-input.c gui-curses-keyboard.c gui-curses-main.c gui-curses-nicklist.c -gui-curses-status.c gui-curses-window.c gui-curses.h) +SET(WEECHAT_CURSES_SRC gui-curses-bar.c gui-curses-chat.c gui-curses-color.c +gui-curses-infobar.c gui-curses-input.c gui-curses-keyboard.c gui-curses-main.c +gui-curses-nicklist.c gui-curses-status.c gui-curses-window.c gui-curses.h) SET(EXECUTABLE weechat-curses) diff --git a/src/gui/curses/Makefile.am b/src/gui/curses/Makefile.am index 614295899..b936c6c07 100644 --- a/src/gui/curses/Makefile.am +++ b/src/gui/curses/Makefile.am @@ -37,7 +37,8 @@ weechat_curses_LDADD = ../../core/weechat.o \ $(PLUGINS_LFLAGS) \ $(NCURSES_LFLAGS) -weechat_curses_SOURCES = gui-curses-chat.c \ +weechat_curses_SOURCES = gui-curses-bar.c \ + gui-curses-chat.c \ gui-curses-color.c \ gui-curses-infobar.c \ gui-curses-input.c \ diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c new file mode 100644 index 000000000..24b350804 --- /dev/null +++ b/src/gui/curses/gui-curses-bar.c @@ -0,0 +1,399 @@ +/* + * Copyright (c) 2003-2008 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 3 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, see . + */ + +/* gui-curses-bar.c: bar functions for Curses GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "../../core/weechat.h" +#include "../../core/wee-log.h" +#include "../gui-bar.h" +#include "../gui-bar-item.h" +#include "../gui-chat.h" +#include "../gui-color.h" +#include "../gui-window.h" +#include "gui-curses.h" + + +/* + * gui_bar_window_get_size: get total bar size (window bars) for a position + * bar is optional, if not NULL, size is computed + * from bar 1 to bar # - 1 + */ + +int +gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window, + int position) +{ + struct t_gui_bar_window *ptr_bar_window; + int total_size; + + total_size = 0; + for (ptr_bar_window = GUI_CURSES(window)->bar_windows; ptr_bar_window; + ptr_bar_window = ptr_bar_window->next_bar_window) + { + /* stop before bar */ + if (bar && (ptr_bar_window->bar == bar)) + return total_size; + + if ((ptr_bar_window->bar->type != GUI_BAR_TYPE_ROOT) + && (ptr_bar_window->bar->position == position)) + { + switch (position) + { + case GUI_BAR_POSITION_BOTTOM: + case GUI_BAR_POSITION_TOP: + total_size += ptr_bar_window->height; + break; + case GUI_BAR_POSITION_LEFT: + case GUI_BAR_POSITION_RIGHT: + total_size += ptr_bar_window->width; + break; + } + if (ptr_bar_window->bar->separator) + total_size++; + } + } + return total_size; +} + +/* + * gui_bar_window_calculate_pos_size: calculate position and size of a bar + */ + +void +gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window, + struct t_gui_window *window) +{ + int x1, y1, x2, y2; + int add_bottom, add_top, add_left, add_right; + + if (window) + { + x1 = window->win_x; + y1 = window->win_y + 1; + x2 = x1 + window->win_width - 1; + y2 = y1 + window->win_height - 1; + add_left = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_LEFT); + add_right = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_RIGHT); + add_top = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_TOP); + add_bottom = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_BOTTOM); + } + else + { + x1 = 0; + y1 = 0; + x2 = gui_window_get_width () - 1; + y2 = gui_window_get_height () - 1; + add_bottom = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_BOTTOM); + add_top = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_TOP); + add_left = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_LEFT); + add_right = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_RIGHT); + } + + switch (bar_window->bar->position) + { + case GUI_BAR_POSITION_BOTTOM: + bar_window->x = x1 + add_left; + bar_window->y = y2 - add_bottom - bar_window->bar->size + 1; + bar_window->width = x2 - add_right - x1 + 1; + bar_window->height = bar_window->bar->size - add_top - add_bottom; + break; + case GUI_BAR_POSITION_TOP: + bar_window->x = x1 + add_left; + bar_window->y = y1 + add_top; + bar_window->width = x2 - x1 + 1; + bar_window->height = bar_window->bar->size - add_left - add_right; + break; + case GUI_BAR_POSITION_LEFT: + bar_window->x = x1 + add_left; + bar_window->y = y1 + add_top; + bar_window->width = bar_window->bar->size - add_left - add_right; + bar_window->height = y2 - add_top - add_bottom - y1 + 1; + break; + case GUI_BAR_POSITION_RIGHT: + bar_window->x = x2 - add_right - bar_window->bar->size + 1; + bar_window->y = y1 + add_top; + bar_window->width = bar_window->bar->size - add_left - add_right; + bar_window->height = y2 - y1 + 1; + break; + } +} + +/* + * gui_bar_window_new: create a new "window bar" for a bar, in screen or a window + * if window is not NULL, bar window will be in this window + */ + +int +gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window) +{ + struct t_gui_bar_window *new_bar_window; + + new_bar_window = (struct t_gui_bar_window *) malloc (sizeof (struct t_gui_bar_window)); + if (new_bar_window) + { + new_bar_window->bar = bar; + if (window) + { + bar->bar_window = NULL; + new_bar_window->next_bar_window = GUI_CURSES(window)->bar_windows; + GUI_CURSES(window)->bar_windows = new_bar_window; + } + else + { + bar->bar_window = new_bar_window; + new_bar_window->next_bar_window = NULL; + } + + gui_bar_window_calculate_pos_size (new_bar_window, window); + + new_bar_window->win_bar = newwin (new_bar_window->height, + new_bar_window->width, + new_bar_window->y, + new_bar_window->x); + new_bar_window->win_separator = NULL; + if (new_bar_window->bar->separator) + { + switch (bar->position) + { + case GUI_BAR_POSITION_BOTTOM: + new_bar_window->win_separator = newwin (1, + new_bar_window->width, + new_bar_window->y - 1, + new_bar_window->x); + break; + case GUI_BAR_POSITION_TOP: + new_bar_window->win_separator = newwin (1, + new_bar_window->width, + new_bar_window->y + new_bar_window->height, + new_bar_window->x); + break; + case GUI_BAR_POSITION_LEFT: + new_bar_window->win_separator = newwin (new_bar_window->height, + 1, + new_bar_window->y, + new_bar_window->x + new_bar_window->width); + break; + case GUI_BAR_POSITION_RIGHT: + new_bar_window->win_separator = newwin (new_bar_window->height, + 1, + new_bar_window->y, + new_bar_window->x - 1); + break; + } + } + return 1; + } + + /* failed to create bar window */ + return 0; +} + +/* + * gui_bar_window_print: print text on a bar window + */ + +void +gui_bar_window_print (struct t_gui_bar_window *bar_win, char *text, + int *max_width) +{ + int weechat_color; + char str_color[3]; + + if ((bar_win->bar->position == GUI_BAR_POSITION_LEFT) + || (bar_win->bar->position == GUI_BAR_POSITION_RIGHT)) + gui_window_set_weechat_color (bar_win->win_bar, GUI_COLOR_CHAT); + else + gui_window_set_weechat_color (bar_win->win_bar, GUI_COLOR_STATUS); + + while (text && text[0]) + { + if (text[0] == GUI_COLOR_COLOR_CHAR) + { + text++; + if (isdigit (text[0]) && isdigit (text[1])) + { + str_color[0] = text[0]; + str_color[1] = text[1]; + str_color[2] = '\0'; + text += 2; + sscanf (str_color, "%d", &weechat_color); + gui_window_set_weechat_color (bar_win->win_bar, weechat_color); + } + } + else + { + wprintw (bar_win->win_bar, "%c", text[0]); + (*max_width)--; + text++; + } + } +} + +/* + * gui_bar_window_draw: draw a bar for a window + */ + +void +gui_bar_window_draw (struct t_gui_window *window, + struct t_gui_bar_window *bar_win) +{ + int i, max_width; + char *item_value; + struct t_gui_bar_item *ptr_item; + + if ((bar_win->bar->position == GUI_BAR_POSITION_LEFT) + || (bar_win->bar->position == GUI_BAR_POSITION_RIGHT)) + gui_window_curses_clear (bar_win->win_bar, GUI_COLOR_CHAT); + else + gui_window_curses_clear (bar_win->win_bar, GUI_COLOR_STATUS); + + max_width = bar_win->width; + + for (i = 0; i < bar_win->bar->items_count; i++) + { + ptr_item = gui_bar_item_search (bar_win->bar->items_array[i]); + if (ptr_item && ptr_item->build_callback) + { + item_value = (ptr_item->build_callback) (ptr_item->build_callback_data, + ptr_item, window, + max_width); + if (item_value) + { + if (item_value[0]) + { + gui_bar_window_print (bar_win, item_value, &max_width); + if (max_width < 0) + max_width = 0; + } + free (item_value); + } + } + } + + wnoutrefresh (bar_win->win_bar); + + if (bar_win->bar->separator) + { + switch (bar_win->bar->position) + { + case GUI_BAR_POSITION_BOTTOM: + gui_window_set_weechat_color (bar_win->win_separator, + GUI_COLOR_SEPARATOR); + mvwhline (bar_win->win_separator, 0, 0, ACS_HLINE, + bar_win->width); + break; + case GUI_BAR_POSITION_TOP: + gui_window_set_weechat_color (bar_win->win_separator, + GUI_COLOR_SEPARATOR); + mvwhline (bar_win->win_separator, 0, 0, ACS_HLINE, + bar_win->width); + break; + case GUI_BAR_POSITION_LEFT: + gui_window_set_weechat_color (bar_win->win_separator, + GUI_COLOR_SEPARATOR); + mvwvline (bar_win->win_separator, 0, 0, ACS_VLINE, + bar_win->height); + break; + case GUI_BAR_POSITION_RIGHT: + gui_window_set_weechat_color (bar_win->win_separator, + GUI_COLOR_SEPARATOR); + mvwvline (bar_win->win_separator, 0, 0, ACS_VLINE, + bar_win->height); + break; + } + wnoutrefresh (bar_win->win_separator); + } + + refresh (); +} + +/* + * gui_bar_draw: draw a bar + */ + +void +gui_bar_draw (struct t_gui_bar *bar) +{ + struct t_gui_window *ptr_win; + struct t_gui_bar_window *ptr_bar_win; + + if (bar->bar_window) + { + /* root bar */ + gui_bar_window_draw (NULL, bar->bar_window); + } + else + { + /* bar on each window */ + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + for (ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows; ptr_bar_win; + ptr_bar_win = ptr_bar_win->next_bar_window) + { + if (ptr_bar_win->bar == bar) + { + gui_bar_window_draw (ptr_win, ptr_bar_win); + } + } + } + } +} + +/* + * gui_bar_window_free: delete a bar window + */ + +void +gui_bar_window_free (struct t_gui_bar_window *bar_window) +{ + /* delete Curses windows */ + if (bar_window->win_bar) + delwin (bar_window->win_bar); + if (bar_window->win_separator) + delwin (bar_window->win_separator); + + /* free bar window */ + free (bar_window); +} + +/* + * gui_bar_window_print_log: print bar window infos in log (usually for crash dump) + */ + +void +gui_bar_window_print_log (struct t_gui_bar_window *bar_window) +{ + log_printf (""); + log_printf (" [window bar (addr:0x%x)]", bar_window); + log_printf (" bar . . . . . . . : 0x%x", bar_window->bar); + log_printf (" x . . . . . . . . : %d", bar_window->x); + log_printf (" y . . . . . . . . : %d", bar_window->y); + log_printf (" width . . . . . . : %d", bar_window->width); + log_printf (" height. . . . . . : %d", bar_window->height); + log_printf (" win_bar . . . . . : 0x%x", bar_window->win_bar); + log_printf (" win_separator . . : 0x%x", bar_window->win_separator); +} diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index 2aafcb706..081bb7ffa 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -29,8 +29,10 @@ #include "../../core/weechat.h" #include "../../core/wee-config.h" +#include "../../core/wee-hook.h" #include "../../core/wee-string.h" #include "../../core/wee-utf8.h" +#include "../../plugins/plugin.h" #include "../gui-buffer.h" #include "../gui-chat.h" #include "../gui-color.h" @@ -963,7 +965,7 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase) struct t_gui_line *ptr_line; /*t_irc_dcc *dcc_first, *dcc_selected, *ptr_dcc;*/ char format_empty[32]; - int i, line_pos, count; + int i, line_pos, count, old_scroll; /*int j, num_bars; unsigned long pct_complete; char *unit_name[] = { N_("bytes"), N_("KB"), N_("MB"), N_("GB") }; @@ -1173,6 +1175,8 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase) ptr_line = ptr_line->next_line; } + old_scroll = ptr_win->scroll; + 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 */ @@ -1183,6 +1187,12 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase) ptr_win->scroll = 0; } + if (ptr_win->scroll != old_scroll) + { + hook_signal_send ("window_scrolled", + WEECHAT_HOOK_SIGNAL_POINTER, ptr_win); + } + if (!ptr_win->scroll && (ptr_win->start_line == ptr_win->buffer->lines)) { ptr_win->start_line = NULL; diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index 325255c67..a642cfebf 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -345,7 +345,7 @@ gui_color_init_weechat () { int i; - gui_color[GUI_COLOR_SEPARATOR] = gui_color_build (GUI_COLOR_SEPARATOR, CONFIG_COLOR(config_color_separator), CONFIG_COLOR(config_color_separator)); + gui_color[GUI_COLOR_SEPARATOR] = gui_color_build (GUI_COLOR_SEPARATOR, CONFIG_COLOR(config_color_separator), CONFIG_COLOR(config_color_chat_bg)); gui_color[GUI_COLOR_TITLE] = gui_color_build (GUI_COLOR_TITLE, CONFIG_COLOR(config_color_title), CONFIG_COLOR(config_color_title_bg)); gui_color[GUI_COLOR_TITLE_MORE] = gui_color_build (GUI_COLOR_TITLE_MORE, CONFIG_COLOR(config_color_title_more), CONFIG_COLOR(config_color_title_bg)); @@ -378,8 +378,8 @@ gui_color_init_weechat () gui_color[GUI_COLOR_STATUS] = gui_color_build (GUI_COLOR_STATUS, CONFIG_COLOR(config_color_status), CONFIG_COLOR(config_color_status_bg)); gui_color[GUI_COLOR_STATUS_DELIMITERS] = gui_color_build (GUI_COLOR_STATUS_DELIMITERS, CONFIG_COLOR(config_color_status_delimiters), CONFIG_COLOR(config_color_status_bg)); - gui_color[GUI_COLOR_STATUS_NUMBER] = gui_color_build (GUI_COLOR_STATUS_NAME, CONFIG_COLOR(config_color_status_number), CONFIG_COLOR(config_color_status_bg)); - gui_color[GUI_COLOR_STATUS_CATEGORY] = gui_color_build (GUI_COLOR_STATUS_NAME, CONFIG_COLOR(config_color_status_category), CONFIG_COLOR(config_color_status_bg)); + gui_color[GUI_COLOR_STATUS_NUMBER] = gui_color_build (GUI_COLOR_STATUS_NUMBER, CONFIG_COLOR(config_color_status_number), CONFIG_COLOR(config_color_status_bg)); + gui_color[GUI_COLOR_STATUS_CATEGORY] = gui_color_build (GUI_COLOR_STATUS_CATEGORY, CONFIG_COLOR(config_color_status_category), CONFIG_COLOR(config_color_status_bg)); gui_color[GUI_COLOR_STATUS_NAME] = gui_color_build (GUI_COLOR_STATUS_NAME, CONFIG_COLOR(config_color_status_name), CONFIG_COLOR(config_color_status_bg)); gui_color[GUI_COLOR_STATUS_DATA_MSG] = gui_color_build (GUI_COLOR_STATUS_DATA_MSG, CONFIG_COLOR(config_color_status_data_msg), CONFIG_COLOR(config_color_status_bg)); gui_color[GUI_COLOR_STATUS_DATA_PRIVATE] = gui_color_build (GUI_COLOR_STATUS_DATA_PRIVATE, CONFIG_COLOR(config_color_status_data_private), CONFIG_COLOR(config_color_status_bg)); diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index d2230e3dd..62ca654fa 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -38,6 +38,7 @@ #include "../../core/wee-util.h" #include "../../plugins/plugin.h" #include "../gui-main.h" +#include "../gui-bar-item.h" #include "../gui-buffer.h" #include "../gui-chat.h" #include "../gui-color.h" @@ -97,7 +98,10 @@ gui_main_init () /* get time length */ gui_chat_time_length = util_get_time_length (CONFIG_STRING(config_look_buffer_time_format)); - + + /* init bar items */ + gui_bar_item_init (); + /* create new window/buffer */ if (gui_window_new (NULL, 0, 0, COLS, LINES, 100, 100)) { @@ -243,6 +247,9 @@ gui_main_loop () void gui_main_end () { + /* remove bar items */ + gui_bar_item_end (); + /* free clipboard buffer */ if (gui_input_clipboard) free (gui_input_clipboard); diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 2fe2036ec..89f6a3087 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -31,6 +31,7 @@ #include "../../core/wee-log.h" #include "../../core/wee-string.h" #include "../gui-window.h" +#include "../gui-bar.h" #include "../gui-buffer.h" #include "../gui-chat.h" #include "../gui-color.h" @@ -82,6 +83,7 @@ gui_window_objects_init (struct t_gui_window *window) GUI_CURSES(window)->win_infobar = NULL; GUI_CURSES(window)->win_input = NULL; GUI_CURSES(window)->win_separator = NULL; + GUI_CURSES(window)->bar_windows = NULL; return 1; } else @@ -192,10 +194,16 @@ int gui_window_calculate_pos_size (struct t_gui_window *window, int force_calculate) { int max_length, max_height, lines, width_used; + int add_top, add_bottom, add_left, add_right; if (!gui_ok) return 0; + add_bottom = gui_bar_window_get_size (NULL, window, GUI_BAR_POSITION_BOTTOM); + add_top = gui_bar_window_get_size (NULL, window, GUI_BAR_POSITION_TOP); + add_left = gui_bar_window_get_size (NULL, window, GUI_BAR_POSITION_LEFT); + add_right = gui_bar_window_get_size (NULL, window, GUI_BAR_POSITION_RIGHT); + /* init chat & nicklist settings */ if (window->buffer->nicklist) { @@ -219,7 +227,8 @@ gui_window_calculate_pos_size (struct t_gui_window *window, int force_calculate) } else { - width_used = window->win_width - (window->win_width % (max_length + 2)); + width_used = (window->win_width - add_left - add_right) + - ((window->win_width - add_left - add_right) % (max_length + 2)); if (((max_length + 2) * window->buffer->nicklist_visible_count) % width_used == 0) lines = ((max_length + 2) * window->buffer->nicklist_visible_count) / width_used; else @@ -231,8 +240,8 @@ gui_window_calculate_pos_size (struct t_gui_window *window, int force_calculate) && (lines < CONFIG_INTEGER(config_look_nicklist_min_size))) lines = CONFIG_INTEGER(config_look_nicklist_min_size); max_height = (CONFIG_BOOLEAN(config_look_infobar)) ? - window->win_height - 3 - 4 : - window->win_height - 2 - 4; + window->win_height - add_top - add_bottom - 3 - 4 : + window->win_height - add_top - add_bottom - 2 - 4; if (lines > max_height) lines = max_height; if (!force_calculate @@ -244,85 +253,84 @@ gui_window_calculate_pos_size (struct t_gui_window *window, int force_calculate) switch (CONFIG_INTEGER(config_look_nicklist_position)) { case CONFIG_LOOK_NICKLIST_LEFT: - window->win_chat_x = window->win_x + max_length + + window->win_chat_x = window->win_x + add_left + max_length + ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); - window->win_chat_y = window->win_y + 1; + window->win_chat_y = window->win_y + add_top + 1; window->win_chat_width = window->win_width - max_length - ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); - window->win_nick_x = window->win_x + 0; - window->win_nick_y = window->win_y + 1; + window->win_nick_x = window->win_x + add_left + 0; + window->win_nick_y = window->win_y + add_top + 1; window->win_nick_width = max_length + ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); if (CONFIG_BOOLEAN(config_look_infobar)) { - window->win_chat_height = window->win_height - 4; - window->win_nick_height = window->win_height - 4; + window->win_chat_height = window->win_height - add_top - add_bottom - 4; + window->win_nick_height = window->win_height - add_top - add_bottom - 4; } else { - window->win_chat_height = window->win_height - 3; - window->win_nick_height = window->win_height - 3; + window->win_chat_height = window->win_height - add_top - add_bottom - 3; + window->win_nick_height = window->win_height - add_top - add_bottom - 3; } window->win_nick_num_max = window->win_nick_height; break; case CONFIG_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 - + window->win_chat_x = window->win_x + add_left; + window->win_chat_y = window->win_y + add_top + 1; + window->win_chat_width = window->win_width - add_left - add_right - max_length - ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); - window->win_nick_x = window->win_x + window->win_width - - max_length - + window->win_nick_x = window->win_x + window->win_width - add_right - max_length - ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); - window->win_nick_y = window->win_y + 1; + window->win_nick_y = window->win_y + add_top + 1; window->win_nick_width = max_length + ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); if (CONFIG_BOOLEAN(config_look_infobar)) { - window->win_chat_height = window->win_height - 4; - window->win_nick_height = window->win_height - 4; + window->win_chat_height = window->win_height - add_top - add_bottom - 4; + window->win_nick_height = window->win_height - add_top - add_bottom - 4; } else { - window->win_chat_height = window->win_height - 3; - window->win_nick_height = window->win_height - 3; + window->win_chat_height = window->win_height - add_top - add_bottom - 3; + window->win_nick_height = window->win_height - add_top - add_bottom - 3; } window->win_nick_num_max = window->win_nick_height; break; case CONFIG_LOOK_NICKLIST_TOP: - window->win_chat_x = window->win_x; - window->win_chat_y = window->win_y + 1 + lines + + window->win_chat_x = window->win_x + add_left; + window->win_chat_y = window->win_y + add_top + 1 + lines + ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); - window->win_chat_width = window->win_width; + window->win_chat_width = window->win_width - add_left - add_right; if (CONFIG_BOOLEAN(config_look_infobar)) - window->win_chat_height = window->win_height - 3 - lines - + window->win_chat_height = window->win_height - add_top - add_bottom - 3 - lines - ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0) - 1; else - window->win_chat_height = window->win_height - 3 - lines - + window->win_chat_height = window->win_height - add_top - add_bottom - 3 - lines - ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); - 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_x = window->win_x + add_left; + window->win_nick_y = window->win_y + add_top + 1; + window->win_nick_width = window->win_width - add_left - add_right; window->win_nick_height = lines + ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); window->win_nick_num_max = lines * (window->win_nick_width / (max_length + 1)); break; case CONFIG_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; + window->win_chat_x = window->win_x + add_left; + window->win_chat_y = window->win_y + add_top + 1; + window->win_chat_width = window->win_width - add_left - add_right; if (CONFIG_BOOLEAN(config_look_infobar)) - window->win_chat_height = window->win_height - 3 - lines - + window->win_chat_height = window->win_height - add_top - add_bottom - 3 - lines - ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0) - 1; else - window->win_chat_height = window->win_height - 3 - lines - + window->win_chat_height = window->win_height - add_top - add_bottom - 3 - lines - ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); window->win_nick_x = window->win_x; if (CONFIG_BOOLEAN(config_look_infobar)) - window->win_nick_y = window->win_y + window->win_height - + window->win_nick_y = window->win_y + window->win_height - add_bottom - 2 - lines - ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0) - 1; else - window->win_nick_y = window->win_y + window->win_height - + window->win_nick_y = window->win_y + window->win_height - add_bottom - 2 - lines - ((CONFIG_BOOLEAN(config_look_nicklist_separator)) ? 1 : 0); window->win_nick_width = window->win_width; @@ -332,20 +340,20 @@ gui_window_calculate_pos_size (struct t_gui_window *window, int force_calculate) break; } - window->win_chat_cursor_x = window->win_x; - window->win_chat_cursor_y = window->win_y; + window->win_chat_cursor_x = window->win_x + add_left; + window->win_chat_cursor_y = window->win_y + add_top; } else { - window->win_chat_x = window->win_x; - window->win_chat_y = window->win_y + 1; - window->win_chat_width = window->win_width; + window->win_chat_x = window->win_x + add_left; + window->win_chat_y = window->win_y + add_top + 1; + window->win_chat_width = window->win_width - add_left - add_right; if (CONFIG_BOOLEAN(config_look_infobar)) - window->win_chat_height = window->win_height - 4; + window->win_chat_height = window->win_height - add_top - add_bottom - 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_chat_height = window->win_height - add_top - add_bottom - 3; + window->win_chat_cursor_x = window->win_x + add_left; + window->win_chat_cursor_y = window->win_y + add_top; window->win_nick_x = -1; window->win_nick_y = -1; window->win_nick_width = -1; @@ -354,26 +362,26 @@ gui_window_calculate_pos_size (struct t_gui_window *window, int force_calculate) } /* title window */ - window->win_title_x = window->win_x; - window->win_title_y = window->win_y; - window->win_title_width = window->win_width; + window->win_title_x = window->win_x + add_left; + window->win_title_y = window->win_y + add_top; + window->win_title_width = window->win_width - add_left - add_right; window->win_title_height = 1; /* status window */ - window->win_status_x = window->win_x; + window->win_status_x = window->win_x + add_left; if (CONFIG_BOOLEAN(config_look_infobar)) - window->win_status_y = window->win_y + window->win_height - 3; + window->win_status_y = window->win_y + window->win_height - add_bottom - 3; else - window->win_status_y = window->win_y + window->win_height - 2; - window->win_status_width = window->win_width; + window->win_status_y = window->win_y + window->win_height - add_bottom - 2; + window->win_status_width = window->win_width - add_left - add_right; window->win_status_height = 1; /* infobar window */ if (CONFIG_BOOLEAN(config_look_infobar)) { - window->win_infobar_x = window->win_x; - window->win_infobar_y = window->win_y + window->win_height - 2; - window->win_infobar_width = window->win_width; + window->win_infobar_x = window->win_x + add_left; + window->win_infobar_y = window->win_y + window->win_height - add_bottom - 2; + window->win_infobar_width = window->win_width - add_left - add_right; window->win_infobar_height = 1; } else @@ -385,9 +393,9 @@ gui_window_calculate_pos_size (struct t_gui_window *window, int force_calculate) } /* input window */ - window->win_input_x = window->win_x; - window->win_input_y = window->win_y + window->win_height - 1; - window->win_input_width = window->win_width; + window->win_input_x = window->win_x + add_left; + window->win_input_y = window->win_y + window->win_height - add_bottom - 1; + window->win_input_width = window->win_width - add_left - add_right; window->win_input_height = 1; return 1; @@ -403,7 +411,7 @@ gui_window_draw_separator (struct t_gui_window *window) if (GUI_CURSES(window)->win_separator) delwin (GUI_CURSES(window)->win_separator); - if (window->win_x > 0) + if (window->win_x > gui_bar_root_get_size (NULL, GUI_BAR_POSITION_LEFT)) { GUI_CURSES(window)->win_separator = newwin (window->win_height, 1, @@ -411,8 +419,8 @@ gui_window_draw_separator (struct t_gui_window *window) window->win_x - 1); gui_window_set_weechat_color (GUI_CURSES(window)->win_separator, GUI_COLOR_SEPARATOR); - wborder (GUI_CURSES(window)->win_separator, - ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + mvwvline (GUI_CURSES(window)->win_separator, 0, 0, ACS_VLINE, + window->win_height); wnoutrefresh (GUI_CURSES(window)->win_separator); refresh (); } @@ -928,15 +936,32 @@ gui_window_refresh_windows () { struct t_gui_window *ptr_win, *old_current_window; struct t_gui_buffer *ptr_buffer; + struct t_gui_bar *ptr_bar; + int add_bottom, add_top, add_left, add_right; if (!gui_ok) return; old_current_window = gui_current_window; + + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + if (ptr_bar->type == GUI_BAR_TYPE_ROOT) + { + gui_bar_window_calculate_pos_size (ptr_bar->bar_window, NULL); + gui_bar_draw (ptr_bar); + } + } - if (gui_window_auto_resize (gui_windows_tree, 0, 0, - gui_window_get_width (), - gui_window_get_height (), 0) < 0) + add_bottom = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_BOTTOM); + add_top = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_TOP); + add_left = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_LEFT); + add_right = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_RIGHT); + + if (gui_window_auto_resize (gui_windows_tree, add_left, add_top, + gui_window_get_width () - add_left - add_right, + gui_window_get_height () - add_top - add_bottom, + 0) < 0) gui_window_merge_all (gui_current_window); for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) @@ -1048,7 +1073,7 @@ void gui_window_resize (struct t_gui_window *window, int pourcentage) { struct t_gui_window_tree *parent; - int old_split_pct; + int old_split_pct, add_bottom, add_top, add_left, add_right; if (!gui_ok) return; @@ -1062,9 +1087,16 @@ gui_window_resize (struct t_gui_window *window, int pourcentage) parent->split_pct = pourcentage; else parent->split_pct = 100 - pourcentage; - if (gui_window_auto_resize (gui_windows_tree, 0, 0, - gui_window_get_width (), - gui_window_get_height (), 1) < 0) + + add_bottom = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_BOTTOM); + add_top = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_TOP); + add_left = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_LEFT); + add_right = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_RIGHT); + + if (gui_window_auto_resize (gui_windows_tree, add_left, add_top, + gui_window_get_width () - add_left - add_right, + gui_window_get_height () - add_top - add_bottom, + 1) < 0) parent->split_pct = old_split_pct; else gui_window_refresh_windows (); @@ -1126,7 +1158,7 @@ gui_window_merge (struct t_gui_window *window) void gui_window_merge_all (struct t_gui_window *window) { - int num_deleted; + int num_deleted, add_bottom, add_top, add_left, add_right; if (!gui_ok) return; @@ -1143,12 +1175,19 @@ gui_window_merge_all (struct t_gui_window *window) 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 = gui_window_get_width (); - window->win_height = gui_window_get_height (); + + add_bottom = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_BOTTOM); + add_top = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_TOP); + add_left = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_LEFT); + add_right = gui_bar_root_get_size (NULL, GUI_BAR_POSITION_RIGHT); + window->win_x = add_left; + window->win_y = add_top; + window->win_width = gui_window_get_width () - add_left - add_right; + window->win_height = gui_window_get_height () - add_top - add_bottom; + window->win_width_pct = 100; window->win_height_pct = 100; + gui_current_window = window; gui_window_switch_to_buffer (window, window->buffer); gui_window_redraw_buffer (window->buffer); @@ -1450,6 +1489,9 @@ gui_window_title_reset () void gui_window_objects_print_log (struct t_gui_window *window) { + struct t_gui_bar_window *ptr_bar_win; + + log_printf (""); log_printf (" win_title . . . . . : 0x%x", GUI_CURSES(window)->win_title); log_printf (" win_chat. . . . . . : 0x%x", GUI_CURSES(window)->win_chat); log_printf (" win_nick. . . . . . : 0x%x", GUI_CURSES(window)->win_nick); @@ -1457,4 +1499,10 @@ gui_window_objects_print_log (struct t_gui_window *window) log_printf (" win_infobar . . . . : 0x%x", GUI_CURSES(window)->win_infobar); log_printf (" win_input . . . . . : 0x%x", GUI_CURSES(window)->win_input); log_printf (" win_separator . . . : 0x%x", GUI_CURSES(window)->win_separator); + + for (ptr_bar_win = GUI_CURSES(window)->bar_windows; ptr_bar_win; + ptr_bar_win = ptr_bar_win->next_bar_window) + { + gui_bar_window_print_log (ptr_bar_win); + } } diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h index 2dc52e34c..5a194f88a 100644 --- a/src/gui/curses/gui-curses.h +++ b/src/gui/curses/gui-curses.h @@ -33,6 +33,18 @@ #define GUI_CURSES(window) ((t_gui_curses_objects *)(window->gui_objects)) +struct t_gui_bar_window +{ + struct t_gui_bar *bar; /* pointer to bar */ + int x, y; /* position of window */ + int width, height; /* window size */ + WINDOW *win_bar; /* bar Curses window */ + WINDOW *win_separator; /* separator (optional) */ + struct t_gui_bar_window *next_bar_window; + /* link to next bar window */ + /* (only used if bar is in windows) */ +}; + typedef struct t_gui_curses_objects t_gui_curses_objects; struct t_gui_curses_objects @@ -44,6 +56,7 @@ struct t_gui_curses_objects WINDOW *win_infobar; /* info bar window */ WINDOW *win_input; /* input window */ WINDOW *win_separator; /* separation between 2 splited (V) win */ + struct t_gui_bar_window *bar_windows; /* bar windows */ }; extern struct t_gui_color gui_weechat_colors[]; @@ -52,6 +65,10 @@ extern struct t_gui_color gui_weechat_colors[]; extern int gui_color_get_pair (int num_color); extern void gui_color_init (); +/* bar functions */ +extern void gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window, + struct t_gui_window *window); + /* chat functions */ extern void gui_chat_calculate_line_diff (struct t_gui_window *window, struct t_gui_line **line, diff --git a/src/gui/gtk/CMakeLists.txt b/src/gui/gtk/CMakeLists.txt index 9bb081098..5d5ec2315 100644 --- a/src/gui/gtk/CMakeLists.txt +++ b/src/gui/gtk/CMakeLists.txt @@ -14,9 +14,9 @@ # along with this program. If not, see . # -SET(WEECHAT_GTK_SRC gui-gtk-chat.c gui-gtk-color.c gui-gtk-infobar.c -gui-gtk-input.c gui-gtk-keyboard.c gui-gtk-main.c gui-gtk-nicklist.c -gui-gtk-status.c gui-gtk-window.c gui-gtk.h) +SET(WEECHAT_GTK_SRC gui-gtk-bar.c gui-gtk-chat.c gui-gtk-color.c +gui-gtk-infobar.c gui-gtk-input.c gui-gtk-keyboard.c gui-gtk-main.c +gui-gtk-nicklist.c gui-gtk-status.c gui-gtk-window.c gui-gtk.h) SET(EXECUTABLE weechat-gtk) diff --git a/src/gui/gtk/Makefile.am b/src/gui/gtk/Makefile.am index 6d58071c3..4fcc6424c 100644 --- a/src/gui/gtk/Makefile.am +++ b/src/gui/gtk/Makefile.am @@ -37,7 +37,8 @@ weechat_gtk_LDADD = ../../core/weechat.o \ $(PLUGINS_LFLAGS) \ $(GTK_LFLAGS) -weechat_gtk_SOURCES = gui-gtk-chat.c \ +weechat_gtk_SOURCES = gui-gtk-bar.c \ + gui-gtk-chat.c \ gui-gtk-color.c \ gui-gtk-infobar.c \ gui-gtk-input.c \ diff --git a/src/gui/gtk/gui-gtk-bar.c b/src/gui/gtk/gui-gtk-bar.c new file mode 100644 index 000000000..6c726bc8a --- /dev/null +++ b/src/gui/gtk/gui-gtk-bar.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2003-2008 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 3 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, see . + */ + +/* gui-gtk-bar.c: bar functions for Gtk GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "../../core/weechat.h" +#include "../../core/wee-log.h" +#include "../gui-bar.h" +#include "../gui-chat.h" +#include "../gui-color.h" +#include "../gui-window.h" +#include "gui-gtk.h" + + +/* + * gui_bar_windows_get_size: get total bar size (window bars) for a position + * bar is optional, if not NULL, size is computed + * from bar 1 to bar # - 1 + */ + +int +gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window, + int position) +{ + (void) bar; + (void) window; + (void) position; + + /* TODO: write this function for Gtk */ + return 0; +} + +/* + * gui_bar_window_new: create a new "window bar" for a bar, in screen or a window + * if window is not NULL, bar window will be in this window + */ + +int +gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window) +{ + (void) bar; + (void) window; + + /* TODO: write this function for Gtk */ + return 0; +} + +/* + * gui_bar_draw: draw a bar + */ + +void +gui_bar_draw (struct t_gui_bar *bar) +{ + (void) bar; + + /* TODO: write this function for Gtk */ +} + +/* + * gui_bar_window_free: delete an bar window + */ + +void +gui_bar_window_free (struct t_gui_bar_window *bar_window) +{ + /* TODO: complete this function for Gtk */ + + /* free bar window */ + free (bar_window); +} + +/* + * gui_bar_window_print_log: print bar window infos in log (usually for crash dump) + */ + +void +gui_bar_window_print_log (struct t_gui_bar_window *bar_window) +{ + log_printf (""); + log_printf (" [window bar (addr:0x%x)]", bar_window); + log_printf (" bar . . . . . . . : 0x%x", bar_window->bar); + log_printf (" x . . . . . . . . : %d", bar_window->x); + log_printf (" y . . . . . . . . : %d", bar_window->y); + log_printf (" width . . . . . . : %d", bar_window->width); + log_printf (" height. . . . . . : %d", bar_window->height); +} diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c index 12526333c..8f22655a8 100644 --- a/src/gui/gtk/gui-gtk-window.c +++ b/src/gui/gtk/gui-gtk-window.c @@ -76,6 +76,7 @@ gui_window_objects_init (struct t_gui_window *window) GUI_GTK(window)->texttag_chat = NULL; GUI_GTK(window)->textview_nicklist = NULL; GUI_GTK(window)->textbuffer_nicklist = NULL; + GUI_GTK(window)->bar_windows = NULL; return 1; } else @@ -919,9 +920,23 @@ gui_window_title_reset () void gui_window_objects_print_log (struct t_gui_window *window) { + struct t_gui_bar_window *ptr_bar_win; + log_printf (" textview_chat . . . : 0x%x", GUI_GTK(window)->textview_chat); log_printf (" textbuffer_chat . . : 0x%x", GUI_GTK(window)->textbuffer_chat); log_printf (" texttag_chat. . . . : 0x%x", GUI_GTK(window)->texttag_chat); log_printf (" textview_nicklist . : 0x%x", GUI_GTK(window)->textview_nicklist); log_printf (" textbuffer_nicklist : 0x%x", GUI_GTK(window)->textbuffer_nicklist); + + for (ptr_bar_win = GUI_GTK(window)->bar_windows; ptr_bar_win; + ptr_bar_win = ptr_bar_win->next_bar_window) + { + log_printf (""); + log_printf (" [window bar (addr:0x%x)]", ptr_bar_win); + log_printf (" bar . . . . . . . : 0x%x", ptr_bar_win->bar); + log_printf (" x . . . . . . . . : %d", ptr_bar_win->x); + log_printf (" y . . . . . . . . : %d", ptr_bar_win->y); + log_printf (" width . . . . . . : %d", ptr_bar_win->width); + log_printf (" height. . . . . . : %d", ptr_bar_win->height); + } } diff --git a/src/gui/gtk/gui-gtk.h b/src/gui/gtk/gui-gtk.h index 6b6189ba0..8bedd73cf 100644 --- a/src/gui/gtk/gui-gtk.h +++ b/src/gui/gtk/gui-gtk.h @@ -54,6 +54,16 @@ struct t_gui_line; #define GUI_GTK(window) ((t_gui_gtk_objects *)(window->gui_objects)) +struct t_gui_bar_window +{ + struct t_gui_bar *bar; /* pointer to bar */ + int x, y; /* position of window */ + int width, height; /* window size */ + struct t_gui_bar_window *next_bar_window; + /* link to next bar window */ + /* (only used if bar is in windows) */ +}; + typedef struct t_gui_gtk_objects t_gui_gtk_objects; struct t_gui_gtk_objects @@ -63,6 +73,7 @@ struct t_gui_gtk_objects GtkTextTag *texttag_chat; /* texttag widget for chat */ GtkWidget *textview_nicklist; /* textview widget for nicklist */ GtkTextBuffer *textbuffer_nicklist; /* textbuffer widget for nicklist */ + struct t_gui_bar_window *bar_windows; /* bar windows */ }; //extern t_gui_color gui_weechat_colors[]; diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c new file mode 100644 index 000000000..2239486ed --- /dev/null +++ b/src/gui/gui-bar-item.c @@ -0,0 +1,592 @@ +/* + * Copyright (c) 2003-2008 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 3 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, see . + */ + +/* gui-bar-item.c: bar item functions, used by all GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "../core/weechat.h" +#include "../core/wee-config.h" +#include "../core/wee-hook.h" +#include "../core/wee-log.h" +#include "../core/wee-string.h" +#include "../plugins/plugin.h" +#include "gui-bar-item.h" +#include "gui-bar.h" +#include "gui-buffer.h" +#include "gui-color.h" +#include "gui-hotlist.h" +#include "gui-window.h" + + +struct t_gui_bar_item *gui_bar_items = NULL; /* first bar item */ +struct t_gui_bar_item *last_gui_bar_item = NULL; /* last bar item */ +char *gui_bar_item_names[GUI_BAR_NUM_ITEMS] = +{ "buffer_count", "buffer_plugin", "buffer_name", "nicklist_count", "scroll", + "hotlist" +}; +struct t_hook *gui_bar_item_hook1 = NULL; +struct t_hook *gui_bar_item_hook2 = NULL; +struct t_hook *gui_bar_item_hook3 = NULL; +struct t_hook *gui_bar_item_hook4 = NULL; +struct t_hook *gui_bar_item_hook5 = NULL; +struct t_hook *gui_bar_item_hook6 = NULL; +struct t_hook *gui_bar_item_hook7 = NULL; + + +/* + * gui_bar_item_search: search a bar item + */ + +struct t_gui_bar_item * +gui_bar_item_search (char *name) +{ + struct t_gui_bar_item *ptr_item; + + if (!name || !name[0]) + return NULL; + + for (ptr_item = gui_bar_items; ptr_item; ptr_item = ptr_item->next_item) + { + if (strcmp (ptr_item->name, name) == 0) + return ptr_item; + } + + /* bar item not found */ + return NULL; +} + +/* + * gui_bar_item_search_with_plugin: search a bar item for a plugin + */ + +struct t_gui_bar_item * +gui_bar_item_search_with_plugin (struct t_weechat_plugin *plugin, char *name) +{ + struct t_gui_bar_item *ptr_item; + + if (!name || !name[0]) + return NULL; + + for (ptr_item = gui_bar_items; ptr_item; ptr_item = ptr_item->next_item) + { + if ((ptr_item->plugin == plugin) + && (strcmp (ptr_item->name, name) == 0)) + return ptr_item; + } + + /* bar item not found */ + return NULL; +} + +/* + * gui_bar_item_new: create a new bar item + */ + +struct t_gui_bar_item * +gui_bar_item_new (struct t_weechat_plugin *plugin, char *name, + char *(*build_callback)(void *data, + struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width), + void *build_callback_data) +{ + struct t_gui_bar_item *new_bar_item; + + if (!name || !name[0]) + return NULL; + + /* it's not possible to create 2 bar items with same name for same plugin*/ + if (gui_bar_item_search_with_plugin (plugin, name)) + return NULL; + + /* create bar item */ + new_bar_item = (struct t_gui_bar_item *) malloc (sizeof (struct t_gui_bar_item)); + if (new_bar_item) + { + new_bar_item->plugin = plugin; + new_bar_item->name = strdup (name); + new_bar_item->build_callback = build_callback; + new_bar_item->build_callback_data = build_callback_data; + + /* add bar item to bar items queue */ + new_bar_item->prev_item = last_gui_bar_item; + if (gui_bar_items) + last_gui_bar_item->next_item = new_bar_item; + else + gui_bar_items = new_bar_item; + last_gui_bar_item = new_bar_item; + new_bar_item->next_item = NULL; + + return new_bar_item; + } + + /* failed to create bar item */ + return NULL; +} + +/* + * gui_bar_contains_item: return 1 if a bar contains item, O otherwise + */ + +int +gui_bar_contains_item (struct t_gui_bar *bar, char *name) +{ + int i; + + if (!bar || !name || !name[0]) + return 0; + + for (i = 0; i < bar->items_count; i++) + { + if (strcmp (bar->items_array[i], name) == 0) + return 1; + } + + /* item is not in bar */ + return 0; +} + +/* + * gui_bar_item_update: update an item on all bars displayed on screen + */ + +void +gui_bar_item_update (char *name) +{ + struct t_gui_bar *ptr_bar; + + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + if (gui_bar_contains_item (ptr_bar, name)) + gui_bar_draw (ptr_bar); + } +} + +/* + * gui_bar_item_free: delete a bar item + */ + +void +gui_bar_item_free (struct t_gui_bar_item *item) +{ + /* remove bar item from bar items list */ + if (item->prev_item) + item->prev_item->next_item = item->next_item; + if (item->next_item) + item->next_item->prev_item = item->prev_item; + if (gui_bar_items == item) + gui_bar_items = item->next_item; + if (last_gui_bar_item == item) + last_gui_bar_item = item->prev_item; + + /* free data */ + if (item->name) + free (item->name); + + free (item); +} + +/* + * gui_bar_item_free_all: delete all bar items + */ + +void +gui_bar_item_free_all () +{ + while (gui_bar_items) + { + gui_bar_item_free (gui_bar_items); + } +} + +/* + * gui_bar_item_free_all_plugin: delete all bar items for a plugin + */ + +void +gui_bar_item_free_all_plugin (struct t_weechat_plugin *plugin) +{ + struct t_gui_bar_item *ptr_item, *next_item; + + ptr_item = gui_bar_items; + while (ptr_item) + { + next_item = ptr_item->next_item; + + if (ptr_item->plugin == plugin) + gui_bar_item_free (ptr_item); + + ptr_item = next_item; + } +} + +/* + * gui_bar_item_default_buffer_count: default item for number of buffers + */ + +char * +gui_bar_item_default_buffer_count (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + char buf[64]; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) window; + (void) max_width; + + snprintf (buf, sizeof (buf), "%s[%s%d%s] ", + GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS), + GUI_COLOR(GUI_COLOR_STATUS), + (last_gui_buffer) ? last_gui_buffer->number : 0, + GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS)); + + return strdup (buf); +} + +/* + * gui_bar_item_default_buffer_plugin: default item for name of buffer plugin + */ + +char * +gui_bar_item_default_buffer_plugin (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + char buf[64]; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) max_width; + + if (!window) + return NULL; + + snprintf (buf, sizeof (buf), "%s[%s%s%s] ", + GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS), + GUI_COLOR(GUI_COLOR_STATUS), + (window->buffer->plugin) ? window->buffer->plugin->name : "core", + GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS)); + + return strdup (buf); +} + +/* + * gui_bar_item_default_buffer_name: default item for name of buffer + */ + +char * +gui_bar_item_default_buffer_name (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + char buf[256]; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) max_width; + + if (!window) + return NULL; + + snprintf (buf, sizeof (buf), "%s%d%s:%s%s%s/%s%s ", + GUI_COLOR(GUI_COLOR_STATUS_NUMBER), + window->buffer->number, + GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS), + GUI_COLOR(GUI_COLOR_STATUS_CATEGORY), + window->buffer->category, + GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS), + GUI_COLOR(GUI_COLOR_STATUS_NAME), + window->buffer->name); + + return strdup (buf); +} + +/* + * gui_bar_item_default_nicklist_count: default item for number of nicks in + * buffer nicklist + */ + +char * +gui_bar_item_default_nicklist_count (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + char buf[64]; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) max_width; + + if (!window || !window->buffer->nicklist) + return NULL; + + snprintf (buf, sizeof (buf), "%s[%s%d%s] ", + GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS), + GUI_COLOR(GUI_COLOR_STATUS), + window->buffer->nicklist_visible_count, + GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS)); + + return strdup (buf); +} + +/* + * gui_bar_item_default_scroll: default item for scrolling indicator + */ + +char * +gui_bar_item_default_scroll (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + char buf[64]; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) max_width; + + if (!window || !window->scroll) + return NULL; + + snprintf (buf, sizeof (buf), "%s%s ", + GUI_COLOR(GUI_COLOR_STATUS_MORE), + _("(MORE)")); + + return strdup (buf); +} + +/* + * gui_bar_item_default_hotlist: default item for hotlist + */ + +char * +gui_bar_item_default_hotlist (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + char buf[1024], format[32]; + struct t_gui_hotlist *ptr_hotlist; + int names_count, display_name; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) window; + (void) max_width; + + if (!gui_hotlist) + return NULL; + + buf[0] = '\0'; + + strcat (buf, GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS)); + strcat (buf, "["); + strcat (buf, GUI_COLOR(GUI_COLOR_STATUS)); + strcat (buf, _("Act: ")); + + names_count = 0; + for (ptr_hotlist = gui_hotlist; ptr_hotlist; + ptr_hotlist = ptr_hotlist->next_hotlist) + { + switch (ptr_hotlist->priority) + { + case GUI_HOTLIST_LOW: + strcat (buf, GUI_COLOR(GUI_COLOR_STATUS_DATA_OTHER)); + display_name = ((CONFIG_INTEGER(config_look_hotlist_names_level) & 1) != 0); + break; + case GUI_HOTLIST_MESSAGE: + strcat (buf, GUI_COLOR(GUI_COLOR_STATUS_DATA_MSG)); + display_name = ((CONFIG_INTEGER(config_look_hotlist_names_level) & 2) != 0); + break; + case GUI_HOTLIST_PRIVATE: + strcat (buf, GUI_COLOR(GUI_COLOR_STATUS_DATA_PRIVATE)); + display_name = ((CONFIG_INTEGER(config_look_hotlist_names_level) & 4) != 0); + break; + case GUI_HOTLIST_HIGHLIGHT: + strcat (buf, GUI_COLOR(GUI_COLOR_STATUS_DATA_HIGHLIGHT)); + display_name = ((CONFIG_INTEGER(config_look_hotlist_names_level) & 8) != 0); + break; + default: + display_name = 0; + break; + } + + sprintf (buf + strlen (buf), "%d", ptr_hotlist->buffer->number); + + if (display_name + && (CONFIG_INTEGER(config_look_hotlist_names_count) != 0) + && (names_count < CONFIG_INTEGER(config_look_hotlist_names_count))) + { + names_count++; + + strcat (buf, GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS)); + strcat (buf, ":"); + strcat (buf, GUI_COLOR(GUI_COLOR_STATUS)); + if (CONFIG_INTEGER(config_look_hotlist_names_length) == 0) + snprintf (format, sizeof (format) - 1, "%%s"); + else + snprintf (format, sizeof (format) - 1, + "%%.%ds", + CONFIG_INTEGER(config_look_hotlist_names_length)); + sprintf (buf + strlen (buf), format, ptr_hotlist->buffer->name); + } + + if (ptr_hotlist->next_hotlist) + strcat (buf, ","); + + if (strlen (buf) > sizeof (buf) - 32) + break; + } + strcat (buf, GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS)); + strcat (buf, "] "); + + return strdup (buf); +} + +/* + * gui_bar_item_signal_cb: callback when a signal is received, for rebuilding + * an item + */ + +int +gui_bar_item_signal_cb (void *data, char *signal, + char *type_data, void *signal_data) +{ + /* make C compiler happy */ + (void) signal; + (void) type_data; + (void) signal_data; + + gui_bar_item_update ((char *)data); + + return WEECHAT_RC_OK; +} + +/* + * gui_bar_item_init: init default items in WeeChat + */ + +void +gui_bar_item_init () +{ + /* buffer count */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT], + &gui_bar_item_default_buffer_count, NULL); + gui_bar_item_hook1 = hook_signal (NULL, "buffer_open", + &gui_bar_item_signal_cb, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT]); + gui_bar_item_hook2 = hook_signal (NULL, "buffer_closed", + &gui_bar_item_signal_cb, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT]); + + /* buffer plugin */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_PLUGIN], + &gui_bar_item_default_buffer_plugin, NULL); + + /* buffer name */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME], + &gui_bar_item_default_buffer_name, NULL); + gui_bar_item_hook3 = hook_signal (NULL, "buffer_renamed", + &gui_bar_item_signal_cb, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]); + gui_bar_item_hook4 = hook_signal (NULL, "buffer_moved", + &gui_bar_item_signal_cb, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]); + + /* nicklist count */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT], + &gui_bar_item_default_nicklist_count, NULL); + gui_bar_item_hook5 = hook_signal (NULL, "nicklist_changed", + &gui_bar_item_signal_cb, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT]); + + /* scroll indicator */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_SCROLL], + &gui_bar_item_default_scroll, NULL); + gui_bar_item_hook6 = hook_signal (NULL, "window_scrolled", + &gui_bar_item_signal_cb, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_SCROLL]); + + /* hotlist */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_HOTLIST], + &gui_bar_item_default_hotlist, NULL); + gui_bar_item_hook7 = hook_signal (NULL, "hotlist_changed", + &gui_bar_item_signal_cb, + gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_HOTLIST]); +} + +/* + * gui_bar_item_end: remove bar items and hooks + */ + +void +gui_bar_item_end () +{ + /* remove hooks */ + unhook (gui_bar_item_hook1); + unhook (gui_bar_item_hook2); + unhook (gui_bar_item_hook3); + unhook (gui_bar_item_hook4); + unhook (gui_bar_item_hook5); + unhook (gui_bar_item_hook6); + unhook (gui_bar_item_hook7); + + /* remove bar items */ + gui_bar_item_free_all (); +} + +/* + * gui_bar_item_print_log: print bar items infos in log (usually for crash dump) + */ + +void +gui_bar_item_print_log () +{ + struct t_gui_bar_item *ptr_item; + + for (ptr_item = gui_bar_items; ptr_item; ptr_item = ptr_item->next_item) + { + log_printf (""); + log_printf ("[bar item (addr:0x%x)]", ptr_item); + log_printf (" plugin . . . . . . . . : 0x%x", ptr_item->plugin); + log_printf (" name . . . . . . . . . : '%s'", ptr_item->name); + log_printf (" build_callback . . . . : 0x%x", ptr_item->build_callback); + log_printf (" build_callback_data. . : 0x%x", ptr_item->build_callback_data); + log_printf (" prev_item. . . . . . . : 0x%x", ptr_item->prev_item); + log_printf (" next_item. . . . . . . : 0x%x", ptr_item->next_item); + } +} diff --git a/src/gui/gui-bar-item.h b/src/gui/gui-bar-item.h new file mode 100644 index 000000000..5f5dfec7c --- /dev/null +++ b/src/gui/gui-bar-item.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003-2008 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 3 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, see . + */ + + +#ifndef __WEECHAT_GUI_BAR_ITEM_H +#define __WEECHAT_GUI_BAR_ITEM_H 1 + +enum t_gui_bar_item_weechat +{ + GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT = 0, + GUI_BAR_ITEM_WEECHAT_BUFFER_PLUGIN, + GUI_BAR_ITEM_WEECHAT_BUFFER_NAME, + GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT, + GUI_BAR_ITEM_WEECHAT_SCROLL, + GUI_BAR_ITEM_WEECHAT_HOTLIST, + /* number of bar items */ + GUI_BAR_NUM_ITEMS, +}; + +struct t_gui_window; + +struct t_gui_bar_item +{ + struct t_weechat_plugin *plugin; /* plugin */ + char *name; /* bar item name */ + char *(*build_callback)(void *data, + struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width); + /* callback called for building item */ + void *build_callback_data; /* data for callback */ + struct t_gui_bar_item *prev_item; /* link to previous bar item */ + struct t_gui_bar_item *next_item; /* link to next bar item */ +}; + +/* variables */ + +extern struct t_gui_bar_item *gui_bar_items; +extern struct t_gui_bar_item *last_gui_bar_item; + +/* functions */ + +extern struct t_gui_bar_item *gui_bar_item_search (char *name); +extern struct t_gui_bar_item *gui_bar_item_new (struct t_weechat_plugin *plugin, + char *name, + char *(*build_callback)(void *data, + struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width), + void *build_callback_data); +extern void gui_bar_item_update (char *name); +extern void gui_bar_item_free (struct t_gui_bar_item *item); +extern void gui_bar_item_free_all (); +extern void gui_bar_item_free_all_plugin (struct t_weechat_plugin *plugin); +extern void gui_bar_item_init (); +extern void gui_bar_item_end (); +extern void gui_bar_item_print_log (); + +#endif /* gui-bar-item.h */ diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c new file mode 100644 index 000000000..0cfa99798 --- /dev/null +++ b/src/gui/gui-bar.c @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2003-2008 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 3 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, see . + */ + +/* gui-bar.c: bar functions, used by all GUI */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "../core/weechat.h" +#include "../core/wee-log.h" +#include "../core/wee-string.h" +#include "gui-bar.h" +#include "gui-window.h" + + +char *gui_bar_type_str[GUI_BAR_NUM_TYPES] = +{ "root", "window_active", "window_inactive" }; +char *gui_bar_position_str[GUI_BAR_NUM_POSITIONS] = +{ "bottom", "top", "left", "right" }; + +struct t_gui_bar *gui_bars = NULL; /* first bar */ +struct t_gui_bar *last_gui_bar = NULL; /* last bar */ + + +/* + * gui_bar_root_get_size: get total bar size ("root" type) for a position + */ + +int +gui_bar_root_get_size (struct t_gui_bar *bar, int position) +{ + struct t_gui_bar *ptr_bar; + int total_size; + + total_size = 0; + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + if (bar && (ptr_bar == bar)) + return total_size; + + if ((ptr_bar->type == GUI_BAR_TYPE_ROOT) + && (ptr_bar->position == position)) + { + total_size += ptr_bar->size; + if (ptr_bar->separator) + total_size++; + } + } + return total_size; +} + +/* + * gui_bar_search: search a bar by name + */ + +struct t_gui_bar * +gui_bar_search (char *name) +{ + struct t_gui_bar *ptr_bar; + + if (!name || !name[0]) + return NULL; + + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + if (strcmp (ptr_bar->name, name) == 0) + return ptr_bar; + } + + /* bar not found */ + return NULL; +} + +/* + * gui_bar_new: create a new bar + */ + +struct t_gui_bar * +gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type, + char *position, int size, int separator, char *items) +{ + struct t_gui_bar *new_bar; + struct t_gui_window *ptr_win; + int i, type_value, position_value; + + if (!name || !name[0]) + return NULL; + + /* it's not possible to create 2 bars with same name */ + if (gui_bar_search (name)) + return NULL; + + /* look for type */ + type_value = -1; + for (i = 0; i < GUI_BAR_NUM_TYPES; i++) + { + if (string_strcasecmp (type, gui_bar_type_str[i]) == 0) + { + type_value = i; + break; + } + } + if (type_value < 0) + return NULL; + + /* look for position */ + position_value = -1; + for (i = 0; i < GUI_BAR_NUM_POSITIONS; i++) + { + if (string_strcasecmp (position, gui_bar_position_str[i]) == 0) + { + position_value = i; + break; + } + } + if (position_value < 0) + return NULL; + + /* create bar */ + new_bar = (struct t_gui_bar *) malloc (sizeof (struct t_gui_bar)); + if (new_bar) + { + new_bar->plugin = plugin; + new_bar->number = (last_gui_bar) ? last_gui_bar->number + 1 : 1; + new_bar->name = strdup (name); + new_bar->type = type_value; + new_bar->position = position_value; + new_bar->size = size; + new_bar->separator = separator; + if (items && items[0]) + { + new_bar->items = strdup (items); + new_bar->items_array = string_explode (items, ",", 0, 0, + &new_bar->items_count); + } + else + { + new_bar->items = NULL; + new_bar->items_count = 0; + new_bar->items_array = NULL; + } + + if (type_value == GUI_BAR_TYPE_ROOT) + { + /* create only one window for bar */ + gui_bar_window_new (new_bar, NULL); + } + else + { + /* create bar window for all opened windows */ + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + gui_bar_window_new (new_bar, ptr_win); + } + } + + /* add bar to bars queue */ + new_bar->prev_bar = last_gui_bar; + if (gui_bars) + last_gui_bar->next_bar = new_bar; + else + gui_bars = new_bar; + last_gui_bar = new_bar; + new_bar->next_bar = NULL; + + gui_window_refresh_needed = 1; + + return new_bar; + } + + /* failed to create bar */ + return NULL; +} + +/* + * gui_bar_update: update a bar on screen + */ + +void +gui_bar_update (char *name) +{ + struct t_gui_bar *ptr_bar; + + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + if (strcmp (ptr_bar->name, name) == 0) + gui_bar_draw (ptr_bar); + } +} + +/* + * gui_bar_free: delete a bar + */ + +void +gui_bar_free (struct t_gui_bar *bar) +{ + /* remove bar from bars list */ + if (bar->prev_bar) + bar->prev_bar->next_bar = bar->next_bar; + if (bar->next_bar) + bar->next_bar->prev_bar = bar->prev_bar; + if (gui_bars == bar) + gui_bars = bar->next_bar; + if (last_gui_bar == bar) + last_gui_bar = bar->prev_bar; + + /* free data */ + if (bar->name) + free (bar->name); + if (bar->bar_window) + gui_bar_window_free (bar->bar_window); + if (bar->items) + free (bar->items); + if (bar->items_array) + string_free_exploded (bar->items_array); + + free (bar); + + gui_window_refresh_needed = 1; +} + +/* + * gui_bar_free_all: delete all bars + */ + +void +gui_bar_free_all () +{ + while (gui_bars) + { + gui_bar_free (gui_bars); + } +} + +/* + * gui_bar_free_all_plugin: delete all bars for a plugin + */ + +void +gui_bar_free_all_plugin (struct t_weechat_plugin *plugin) +{ + struct t_gui_bar *ptr_bar, *next_bar; + + ptr_bar = gui_bars; + while (ptr_bar) + { + next_bar = ptr_bar->next_bar; + + if (ptr_bar->plugin == plugin) + gui_bar_free (ptr_bar); + + ptr_bar = next_bar; + } +} + +/* + * gui_bar_print_log: print bar infos in log (usually for crash dump) + */ + +void +gui_bar_print_log () +{ + struct t_gui_bar *ptr_bar; + + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + log_printf (""); + log_printf ("[bar (addr:0x%x)]", ptr_bar); + log_printf (" plugin . . . . . . . . : 0x%x", ptr_bar->plugin); + log_printf (" number . . . . . . . . : %d", ptr_bar->number); + log_printf (" name . . . . . . . . . : '%s'", ptr_bar->name); + log_printf (" type . . . . . . . . . : %d (%s)", + ptr_bar->type, + gui_bar_type_str[ptr_bar->type]); + log_printf (" position . . . . . . . : %d (%s)", + ptr_bar->position, + gui_bar_position_str[ptr_bar->position]); + log_printf (" size . . . . . . . . . : %d", ptr_bar->size); + log_printf (" separator. . . . . . . : %d", ptr_bar->separator); + log_printf (" items. . . . . . . . . : '%s'", ptr_bar->items); + log_printf (" items_count. . . . . . : %d", ptr_bar->items_count); + log_printf (" items_array. . . . . . : 0x%x", ptr_bar->items_array); + log_printf (" bar_window . . . . . . : 0x%x", ptr_bar->bar_window); + log_printf (" prev_bar . . . . . . . : 0x%x", ptr_bar->prev_bar); + log_printf (" next_bar . . . . . . . : 0x%x", ptr_bar->next_bar); + + if (ptr_bar->bar_window) + gui_bar_window_print_log (ptr_bar->bar_window); + } +} diff --git a/src/gui/gui-bar.h b/src/gui/gui-bar.h new file mode 100644 index 000000000..3844bd184 --- /dev/null +++ b/src/gui/gui-bar.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2003-2008 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 3 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, see . + */ + + +#ifndef __WEECHAT_GUI_BAR_H +#define __WEECHAT_GUI_BAR_H 1 + +struct t_weechat_plugin; +struct t_gui_window; + +enum t_gui_bar_type +{ + GUI_BAR_TYPE_ROOT = 0, + GUI_BAR_TYPE_WINDOW_ACTIVE, + GUI_BAR_TYPE_WINDOW_INACTIVE, + /* number of bar types */ + GUI_BAR_NUM_TYPES, +}; + +enum t_gui_bar_position +{ + GUI_BAR_POSITION_BOTTOM = 0, + GUI_BAR_POSITION_TOP, + GUI_BAR_POSITION_LEFT, + GUI_BAR_POSITION_RIGHT, + /* number of bar positions */ + GUI_BAR_NUM_POSITIONS, +}; + +struct t_gui_bar +{ + /* user choices */ + struct t_weechat_plugin *plugin; /* plugin */ + int number; /* bar number */ + char *name; /* bar name */ + int type; /* type (root or window) */ + int position; /* position (bottom, top, left, right) */ + int size; /* size of bar (in chars) */ + int separator; /* 1 if separator (line) displayed */ + char *items; /* bar items */ + + /* internal vars */ + int items_count; /* number of bar items */ + char **items_array; /* exploded bar items */ + struct t_gui_bar_window *bar_window; /* pointer to bar window */ + /* (for type root only) */ + struct t_gui_bar *prev_bar; /* link to previous bar */ + struct t_gui_bar *next_bar; /* link to next bar */ +}; + +/* variables */ + +extern char *gui_bar_type_str[]; +extern char *gui_bar_position_str[]; +extern struct t_gui_bar *gui_bars; +extern struct t_gui_bar *last_gui_bar; + +/* functions */ + +extern int gui_bar_root_get_size (struct t_gui_bar *bar, int position); +extern struct t_gui_bar *gui_bar_search (char *name); +extern struct t_gui_bar *gui_bar_new (struct t_weechat_plugin *plugin, + char *name, char *type, char *position, + int size, int separator, char *items); +extern void gui_bar_update (char *name); +extern void gui_bar_free (struct t_gui_bar *bar); +extern void gui_bar_free_all (); +extern void gui_bar_free_all_plugin (struct t_weechat_plugin *plugin); +extern void gui_bar_print_log (); + +/* functions (GUI dependent) */ + +extern int gui_bar_window_get_size (struct t_gui_bar *bar, + struct t_gui_window *window, int position); +extern int gui_bar_window_new (struct t_gui_bar *bar, + struct t_gui_window *window); +extern void gui_bar_window_free (struct t_gui_bar_window *bar_window); +extern void gui_bar_draw (struct t_gui_bar *bar); +extern void gui_bar_window_print_log (struct t_gui_bar_window *bar_window); + +#endif /* gui-bar.h */ diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 732d13f4d..0948439bd 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -253,6 +253,9 @@ gui_buffer_set_category (struct t_gui_buffer *buffer, char *category) buffer->category = strdup (category); } gui_status_refresh_needed = 1; + + hook_signal_send ("buffer_renamed", + WEECHAT_HOOK_SIGNAL_POINTER, buffer); } /* @@ -269,6 +272,9 @@ gui_buffer_set_name (struct t_gui_buffer *buffer, char *name) buffer->name = strdup (name); } gui_status_refresh_needed = 1; + + hook_signal_send ("buffer_renamed", + WEECHAT_HOOK_SIGNAL_POINTER, buffer); } /* @@ -625,7 +631,7 @@ gui_buffer_close (struct t_gui_buffer *buffer, int switch_to_another) struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; - hook_signal_send ("buffer_close", + hook_signal_send ("buffer_closing", WEECHAT_HOOK_SIGNAL_POINTER, buffer); if (buffer->close_callback) @@ -708,6 +714,8 @@ gui_buffer_close (struct t_gui_buffer *buffer, int switch_to_another) if (gui_windows && gui_current_window && gui_current_window->buffer) gui_status_refresh_needed = 1; + + hook_signal_send ("buffer_closed", WEECHAT_HOOK_SIGNAL_STRING, NULL); } /* @@ -903,8 +911,9 @@ gui_buffer_move_to_number (struct t_gui_buffer *buffer, int number) snprintf (buf1_str, sizeof (buf1_str) - 1, "%d", buffer->number); argv[0] = buf1_str; argv[1] = buf2_str; - /* TODO: send buffer_move event */ - /*plugin_event_handler_exec ("buffer_move", 2, argv);*/ + + hook_signal_send ("buffer_moved", + WEECHAT_HOOK_SIGNAL_POINTER, buffer); } /* diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c index a24adec88..122652e35 100644 --- a/src/gui/gui-hotlist.c +++ b/src/gui/gui-hotlist.c @@ -28,8 +28,10 @@ #include "../core/weechat.h" #include "../core/wee-config.h" +#include "../core/wee-hook.h" #include "../core/wee-log.h" #include "../core/wee-util.h" +#include "../plugins/plugin.h" #include "gui-hotlist.h" #include "gui-buffer.h" #include "gui-status.h" @@ -178,6 +180,8 @@ gui_hotlist_add_hotlist (struct t_gui_hotlist **hotlist, *hotlist = new_hotlist; *last_hotlist = new_hotlist; } + + hook_signal_send ("hotlist_changed", WEECHAT_HOOK_SIGNAL_STRING, NULL); } /* @@ -312,6 +316,8 @@ gui_hotlist_free (struct t_gui_hotlist **hotlist, free (ptr_hotlist); *hotlist = new_hotlist; + + hook_signal_send ("hotlist_changed", WEECHAT_HOOK_SIGNAL_STRING, NULL); } /* diff --git a/src/plugins/demo/demo.c b/src/plugins/demo/demo.c index 4865ecb05..342d0bc68 100644 --- a/src/plugins/demo/demo.c +++ b/src/plugins/demo/demo.c @@ -44,6 +44,35 @@ WEECHAT_PLUGIN_LICENSE("GPL"); struct t_weechat_plugin *weechat_demo_plugin = NULL; #define weechat_plugin weechat_demo_plugin +int demo_debug = 0; + + +/* + * demo_debug_signal_debug_cb: callback for "debug" signal + */ + +int +demo_debug_signal_debug_cb (void *data, char *signal, char *type_data, + void *signal_data) +{ + /* make C compiler happy */ + (void) data; + (void) signal; + + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + if (weechat_strcasecmp ((char *)signal_data, "demo") == 0) + { + demo_debug ^= 1; + if (demo_debug) + weechat_printf (NULL, _("%s: debug enabled"), "demo"); + else + weechat_printf (NULL, _("%s: debug disabled"), "demo"); + } + } + + return WEECHAT_RC_OK; +} /* * demo_printf_command_cb: demo command for printf @@ -134,12 +163,15 @@ demo_buffer_close_cb (void *data, struct t_gui_buffer *buffer) { /* make C compiler happy */ (void) data; - - weechat_printf (NULL, - "buffer_close_cb: buffer = %x (%s / %s)", - buffer, - weechat_buffer_get (buffer, "category"), - weechat_buffer_get (buffer, "name")); + + if (demo_debug) + { + weechat_printf (NULL, + "buffer_close_cb: buffer = %x (%s / %s)", + buffer, + weechat_buffer_get (buffer, "category"), + weechat_buffer_get (buffer, "name")); + } return WEECHAT_RC_OK; } @@ -243,7 +275,6 @@ demo_infolist_print (struct t_plugin_infolist *infolist, char *item_name) break; } } - } if (argv) weechat_string_free_exploded (argv); @@ -337,34 +368,37 @@ demo_signal_cb (void *data, char *signal, char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + + if (demo_debug) { - weechat_printf (NULL, - _("demo_signal: signal: %s, type_data: %s, " - "signal_data: '%s'"), - signal, type_data, (char *)signal_data); - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) - { - weechat_printf (NULL, - _("demo_signal: signal: %s, type_data: %s, " - "signal_data: %d"), - signal, type_data, *((int *)signal_data)); - } - else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) - { - weechat_printf (NULL, - _("demo_signal: signal: %s, type_data: %s, " - "signal_data: 0x%x"), - signal, type_data, signal_data); - } - else - { - weechat_printf (NULL, - _("demo_signal: signal: %s, type_data: %s, " - "signal_data: 0x%x (unknown type)"), - signal, type_data, signal_data); + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + weechat_printf (NULL, + _("demo_signal: signal: %s, type_data: %s, " + "signal_data: '%s'"), + signal, type_data, (char *)signal_data); + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0) + { + weechat_printf (NULL, + _("demo_signal: signal: %s, type_data: %s, " + "signal_data: %d"), + signal, type_data, *((int *)signal_data)); + } + else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0) + { + weechat_printf (NULL, + _("demo_signal: signal: %s, type_data: %s, " + "signal_data: 0x%x"), + signal, type_data, signal_data); + } + else + { + weechat_printf (NULL, + _("demo_signal: signal: %s, type_data: %s, " + "signal_data: 0x%x (unknown type)"), + signal, type_data, signal_data); + } } return WEECHAT_RC_OK; @@ -426,7 +460,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) "weechat_sharedir|charset_terminal|charset_internal|" "inactivity|input|input_mask|input_pos", &demo_info_command_cb, NULL); - + + weechat_hook_signal ("debug", &demo_debug_signal_debug_cb, NULL); weechat_hook_signal ("*", &demo_signal_cb, NULL); return WEECHAT_RC_OK; diff --git a/src/plugins/irc/irc-debug.c b/src/plugins/irc/irc-debug.c index 67b4bbfb9..8384f87ae 100644 --- a/src/plugins/irc/irc-debug.c +++ b/src/plugins/irc/irc-debug.c @@ -116,14 +116,15 @@ irc_debug_signal_debug_cb (void *data, char *signal, char *type_data, if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { if (weechat_strcasecmp ((char *)signal_data, "irc") == 0) + { irc_debug ^= 1; + if (irc_debug) + weechat_printf (NULL, _("%s: debug enabled"), "irc"); + else + weechat_printf (NULL, _("%s: debug disabled"), "irc"); + } } - if (irc_debug) - weechat_printf (NULL, _("%s: debug enabled"), "irc"); - else - weechat_printf (NULL, _("%s: debug disabled"), "irc"); - return WEECHAT_RC_OK; } diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index bc30a7d9e..0bba28722 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -440,12 +440,12 @@ logger_buffer_open_signal_cb (void *data, char *signal, char *type_data, } /* - * logger_buffer_close_signal_cb: callback for "buffer_close" signal + * logger_buffer_closing_signal_cb: callback for "buffer_closing" signal */ int -logger_buffer_close_signal_cb (void *data, char *signal, char *type_data, - void *signal_data) +logger_buffer_closing_signal_cb (void *data, char *signal, char *type_data, + void *signal_data) { /* make C compiler happy */ (void) data; @@ -652,7 +652,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) logger_start_buffer_all (); weechat_hook_signal ("buffer_open", &logger_buffer_open_signal_cb, NULL); - weechat_hook_signal ("buffer_close", &logger_buffer_close_signal_cb, NULL); + weechat_hook_signal ("buffer_closing", &logger_buffer_closing_signal_cb, NULL); weechat_hook_signal ("logger_backlog", &logger_backlog_signal_cb, NULL); weechat_hook_signal ("logger_start", &logger_start_signal_cb, NULL); weechat_hook_signal ("logger_stop", &logger_stop_signal_cb, NULL); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 9e2e5b357..44d09bfcb 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -41,6 +41,8 @@ #include "../core/wee-string.h" #include "../core/wee-utf8.h" #include "../core/wee-util.h" +#include "../gui/gui-bar.h" +#include "../gui/gui-bar-item.h" #include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" #include "../gui/gui-nicklist.h" @@ -337,6 +339,15 @@ plugin_load (char *filename) new_plugin->nicklist_remove_nick = &gui_nicklist_remove_nick; new_plugin->nicklist_remove_all = &gui_nicklist_remove_all; + new_plugin->bar_item_search = &gui_bar_item_search; + new_plugin->bar_item_new = &gui_bar_item_new; + new_plugin->bar_item_update = &gui_bar_item_update; + new_plugin->bar_item_remove = &gui_bar_item_free; + new_plugin->bar_search = &gui_bar_search; + new_plugin->bar_new = &gui_bar_new; + new_plugin->bar_update = &gui_bar_update; + new_plugin->bar_remove = &gui_bar_free; + new_plugin->command = &plugin_api_command; new_plugin->info_get = &plugin_api_info_get; @@ -523,6 +534,9 @@ plugin_remove (struct t_weechat_plugin *plugin) /* remove all hooks */ unhook_all_plugin (plugin); + /* remove all bar items */ + gui_bar_item_free_all_plugin (plugin); + /* remove pointer to this plugin on buffers */ for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 9c79fdfe0..58d390092 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "../../weechat-plugin.h" #include "../script.h" @@ -203,6 +204,7 @@ weechat_lua_api_iconv_to_internal (lua_State *L) string = lua_tostring (lua_current_interpreter, -1); result = weechat_iconv_to_internal ((char *)charset, (char *)string); + LUA_RETURN_STRING_FREE(result); } @@ -242,6 +244,7 @@ weechat_lua_api_iconv_from_internal (lua_State *L) string = lua_tostring (lua_current_interpreter, -1); result = weechat_iconv_from_internal ((char *)charset, (char *)string); + LUA_RETURN_STRING_FREE(result); } @@ -278,6 +281,7 @@ weechat_lua_api_gettext (lua_State *L) string = lua_tostring (lua_current_interpreter, -1); result = weechat_gettext ((char *)string); + LUA_RETURN_STRING(result); } @@ -318,6 +322,7 @@ weechat_lua_api_ngettext (lua_State *L) count = lua_tonumber (lua_current_interpreter, -1); result = weechat_ngettext ((char *)single, (char *)plural, count); + LUA_RETURN_STRING(result); } @@ -418,6 +423,7 @@ weechat_lua_api_list_new (lua_State *L) } result = script_ptr2str (weechat_list_new ()); + LUA_RETURN_STRING_FREE(result); } @@ -460,6 +466,7 @@ weechat_lua_api_list_add (lua_State *L) result = script_ptr2str (weechat_list_add (script_str2ptr ((char *)weelist), (char *)data, (char *)where)); + LUA_RETURN_STRING_FREE(result); } @@ -499,6 +506,7 @@ weechat_lua_api_list_search (lua_State *L) result = script_ptr2str (weechat_list_search (script_str2ptr ((char *)weelist), (char *)data)); + LUA_RETURN_STRING_FREE(result); } @@ -538,6 +546,7 @@ weechat_lua_api_list_casesearch (lua_State *L) result = script_ptr2str (weechat_list_casesearch (script_str2ptr ((char *)weelist), (char *)data)); + LUA_RETURN_STRING_FREE(result); } @@ -577,6 +586,7 @@ weechat_lua_api_list_get (lua_State *L) result = script_ptr2str (weechat_list_get (script_str2ptr ((char *)weelist), position)); + LUA_RETURN_STRING_FREE(result); } @@ -652,6 +662,7 @@ weechat_lua_api_list_next (lua_State *L) item = lua_tostring (lua_current_interpreter, -1); result = script_ptr2str (weechat_list_next (script_str2ptr ((char *)item))); + LUA_RETURN_STRING_FREE(result); } @@ -688,6 +699,7 @@ weechat_lua_api_list_prev (lua_State *L) item = lua_tostring (lua_current_interpreter, -1); result = script_ptr2str (weechat_list_prev (script_str2ptr ((char *)item))); + LUA_RETURN_STRING_FREE(result); } @@ -724,6 +736,7 @@ weechat_lua_api_list_string (lua_State *L) item = lua_tostring (lua_current_interpreter, -1); result = weechat_list_string (script_str2ptr ((char *)item)); + LUA_RETURN_STRING(result); } @@ -759,6 +772,7 @@ weechat_lua_api_list_size (lua_State *L) weelist = lua_tostring (lua_current_interpreter, -1); size = weechat_list_size (script_str2ptr ((char *)weelist)); + LUA_RETURN_INT(size); } @@ -952,6 +966,7 @@ weechat_lua_api_config_new (lua_State *L) (char *)filename, &weechat_lua_api_config_reload_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -1107,6 +1122,7 @@ weechat_lua_api_config_new_section (lua_State *L) (char *)function_write, &weechat_lua_api_config_section_write_cb, (char *)function_write_default)); + LUA_RETURN_STRING_FREE(result); } @@ -1146,6 +1162,7 @@ weechat_lua_api_config_search_section (lua_State *L) result = script_ptr2str (weechat_config_search_section (script_str2ptr ((char *)config_file), (char *)section_name)); + LUA_RETURN_STRING_FREE(result); } @@ -1240,6 +1257,7 @@ weechat_lua_api_config_new_option (lua_State *L) (char *)default_value, &weechat_lua_api_config_option_change_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -1282,6 +1300,7 @@ weechat_lua_api_config_search_option (lua_State *L) result = script_ptr2str (weechat_config_search_option (script_str2ptr ((char *)config_file), script_str2ptr ((char *)section), (char *)option_name)); + LUA_RETURN_STRING_FREE(result); } @@ -1317,6 +1336,7 @@ weechat_lua_api_config_string_to_boolean (lua_State *L) text = lua_tostring (lua_current_interpreter, -1); value = weechat_config_string_to_boolean ((char *)text); + LUA_RETURN_INT(value); } @@ -1358,6 +1378,7 @@ weechat_lua_api_config_option_set (lua_State *L) rc = weechat_config_option_set (script_str2ptr ((char *)option), (char *)new_value, run_callback); + LUA_RETURN_INT(rc); } @@ -1393,6 +1414,7 @@ weechat_lua_api_config_boolean (lua_State *L) option = lua_tostring (lua_current_interpreter, -1); value = weechat_config_boolean (script_str2ptr ((char *)option)); + LUA_RETURN_INT(value); } @@ -1428,6 +1450,7 @@ weechat_lua_api_config_integer (lua_State *L) option = lua_tostring (lua_current_interpreter, -1); value = weechat_config_integer (script_str2ptr ((char *)option)); + LUA_RETURN_INT(value); } @@ -1464,6 +1487,7 @@ weechat_lua_api_config_string (lua_State *L) option = lua_tostring (lua_current_interpreter, -1); value = weechat_config_string (script_str2ptr ((char *)option)); + LUA_RETURN_STRING(value); } @@ -1499,6 +1523,7 @@ weechat_lua_api_config_color (lua_State *L) option = lua_tostring (lua_current_interpreter, -1); value = weechat_config_color (script_str2ptr ((char *)option)); + LUA_RETURN_INT(value); } @@ -1577,6 +1602,7 @@ weechat_lua_api_config_write (lua_State *L) config_file = lua_tostring (lua_current_interpreter, -1); rc = weechat_config_write (script_str2ptr ((char *)config_file)); + LUA_RETURN_INT(rc); } @@ -1612,6 +1638,7 @@ weechat_lua_api_config_read (lua_State *L) config_file = lua_tostring (lua_current_interpreter, -1); rc = weechat_config_read (script_str2ptr ((char *)config_file)); + LUA_RETURN_INT(rc); } @@ -1647,6 +1674,7 @@ weechat_lua_api_config_reload (lua_State *L) config_file = lua_tostring (lua_current_interpreter, -1); rc = weechat_config_reload (script_str2ptr ((char *)config_file)); + LUA_RETURN_INT(rc); } @@ -1721,6 +1749,7 @@ weechat_lua_api_prefix (lua_State *L) prefix = lua_tostring (lua_current_interpreter, -1); result = weechat_prefix ((char *)prefix); + LUA_RETURN_STRING(result); } @@ -1757,6 +1786,7 @@ weechat_lua_api_color (lua_State *L) color = lua_tostring (lua_current_interpreter, -1); result = weechat_prefix ((char *)color); + LUA_RETURN_STRING(result); } @@ -2005,6 +2035,7 @@ weechat_lua_api_hook_command (lua_State *L) (char *)completion, &weechat_lua_api_hook_command_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -2084,6 +2115,7 @@ weechat_lua_api_hook_timer (lua_State *L) max_calls, &weechat_lua_api_hook_timer_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -2166,6 +2198,7 @@ weechat_lua_api_hook_fd (lua_State *L) exception, &weechat_lua_api_hook_fd_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -2253,6 +2286,7 @@ weechat_lua_api_hook_print (lua_State *L) strip_colors, &weechat_lua_api_hook_print_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -2347,6 +2381,7 @@ weechat_lua_api_hook_signal (lua_State *L) (char *)signal, &weechat_lua_api_hook_signal_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -2486,6 +2521,7 @@ weechat_lua_api_hook_config (lua_State *L) (char *)option, &weechat_lua_api_hook_config_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -2568,6 +2604,7 @@ weechat_lua_api_hook_completion (lua_State *L) (char *)completion, &weechat_lua_api_hook_completion_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -2634,6 +2671,7 @@ weechat_lua_api_hook_modifier (lua_State *L) (char *)modifier, &weechat_lua_api_hook_modifier_cb, (char *)function)); + LUA_RETURN_STRING_FREE(result); } @@ -2676,6 +2714,7 @@ weechat_lua_api_hook_modifier_exec (lua_State *L) result = weechat_hook_modifier_exec ((char *)modifier, (char *)modifier_data, (char *)string); + LUA_RETURN_STRING_FREE(result); } @@ -2854,6 +2893,7 @@ weechat_lua_api_buffer_new (lua_State *L) (char *)function_input, &weechat_lua_api_close_cb, (char *)function_close)); + LUA_RETURN_STRING_FREE(result); } @@ -2893,6 +2933,7 @@ weechat_lua_api_buffer_search (lua_State *L) result = script_ptr2str (weechat_buffer_search ((char *)category, (char *)name)); + LUA_RETURN_STRING_FREE(result); } @@ -2973,6 +3014,7 @@ weechat_lua_api_buffer_get (lua_State *L) value = weechat_buffer_get (script_str2ptr ((char *)buffer), (char *)property); + LUA_RETURN_STRING(value); } @@ -3062,6 +3104,7 @@ weechat_lua_api_nicklist_add_group (lua_State *L) (char *)name, (char *)color, visible)); + LUA_RETURN_STRING_FREE(result); } @@ -3104,6 +3147,7 @@ weechat_lua_api_nicklist_search_group (lua_State *L) result = script_ptr2str (weechat_nicklist_search_group (script_str2ptr ((char *)buffer), script_str2ptr ((char *)from_group), (char *)name)); + LUA_RETURN_STRING_FREE(result); } @@ -3163,6 +3207,7 @@ weechat_lua_api_nicklist_add_nick (lua_State *L) char_prefix, (char *)prefix_color, visible)); + LUA_RETURN_STRING_FREE(result); } @@ -3205,6 +3250,7 @@ weechat_lua_api_nicklist_search_nick (lua_State *L) result = script_ptr2str (weechat_nicklist_search_nick (script_str2ptr ((char *)buffer), script_str2ptr ((char *)from_group), (char *)name)); + LUA_RETURN_STRING_FREE(result); } @@ -3322,6 +3368,356 @@ weechat_lua_api_nicklist_remove_all (lua_State *L) LUA_RETURN_OK; } +/* + * weechat_lua_api_bar_item_search: search a bar item + */ + +static int +weechat_lua_api_bar_item_search (lua_State *L) +{ + const char *name; + char *result; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_search"); + LUA_RETURN_EMPTY; + } + + name = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_search"); + LUA_RETURN_EMPTY; + } + + name = lua_tostring (lua_current_interpreter, -1); + + result = script_ptr2str (weechat_bar_item_search ((char *)name)); + + LUA_RETURN_STRING_FREE(result); +} + +/* + * weechat_lua_api_bar_item_build_cb: callback for building bar item + */ + +char * +weechat_lua_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + struct t_script_callback *script_callback; + char *lua_argv[4], *ret; + static char buf[32]; + + script_callback = (struct t_script_callback *)data; + + snprintf (buf, sizeof (buf) - 1, "%d", max_width); + + lua_argv[0] = script_ptr2str (item); + lua_argv[1] = script_ptr2str (window); + lua_argv[2] = buf; + lua_argv[3] = NULL; + + ret = (char *)weechat_lua_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + lua_argv); + + if (lua_argv[0]) + free (lua_argv[0]); + if (lua_argv[1]) + free (lua_argv[1]); + + return ret; +} + +/* + * weechat_lua_api_bar_item_new: add a new bar item + */ + +static int +weechat_lua_api_bar_item_new (lua_State *L) +{ + const char *name, *function; + char *result; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_new"); + LUA_RETURN_EMPTY; + } + + name = NULL; + function = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_new"); + LUA_RETURN_EMPTY; + } + + name = lua_tostring (lua_current_interpreter, -2); + function = lua_tostring (lua_current_interpreter, -1); + + result = script_ptr2str (script_api_bar_item_new (weechat_lua_plugin, + lua_current_script, + (char *)name, + &weechat_lua_api_bar_item_build_cb, + (char *)function)); + + LUA_RETURN_STRING_FREE(result); +} + +/* + * weechat_lua_api_bar_item_update: update a bar item on screen + */ + +static int +weechat_lua_api_bar_item_update (lua_State *L) +{ + const char *name; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_update"); + LUA_RETURN_ERROR; + } + + name = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_update"); + LUA_RETURN_ERROR; + } + + name = lua_tostring (lua_current_interpreter, -1); + + weechat_bar_item_update ((char *)name); + + LUA_RETURN_OK; +} + +/* + * weechat_lua_api_bar_item_remove: remove a bar item + */ + +static int +weechat_lua_api_bar_item_remove (lua_State *L) +{ + const char *item; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_remove"); + LUA_RETURN_ERROR; + } + + item = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_remove"); + LUA_RETURN_ERROR; + } + + item = lua_tostring (lua_current_interpreter, -1); + + script_api_bar_item_remove (weechat_lua_plugin, + lua_current_script, + script_str2ptr ((char *)item)); + + LUA_RETURN_OK; +} + +/* + * weechat_lua_api_bar_search: search a bar + */ + +static int +weechat_lua_api_bar_search (lua_State *L) +{ + const char *name; + char *result; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_search"); + LUA_RETURN_EMPTY; + } + + name = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_search"); + LUA_RETURN_EMPTY; + } + + name = lua_tostring (lua_current_interpreter, -1); + + result = script_ptr2str (weechat_bar_search ((char *)name)); + + LUA_RETURN_STRING_FREE(result); +} + +/* + * weechat_lua_api_bar_new: add a new bar + */ + +static int +weechat_lua_api_bar_new (lua_State *L) +{ + const char *name, *type, *position, *items; + char *result; + int n, size, separator; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_new"); + LUA_RETURN_EMPTY; + } + + name = NULL; + type = NULL; + position = NULL; + size = 0; + separator = 0; + items = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 6) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new"); + LUA_RETURN_EMPTY; + } + + name = lua_tostring (lua_current_interpreter, -6); + type = lua_tostring (lua_current_interpreter, -5); + position = lua_tostring (lua_current_interpreter, -4); + size = lua_tonumber (lua_current_interpreter, -3); + separator = lua_tonumber (lua_current_interpreter, -2); + items = lua_tostring (lua_current_interpreter, -1); + + result = script_ptr2str (weechat_bar_new ((char *)name, + (char *)type, + (char *)position, + size, + separator, + (char *)items)); + + LUA_RETURN_STRING_FREE(result); +} + +/* + * weechat_lua_api_bar_update: update a bar on screen + */ + +static int +weechat_lua_api_bar_update (lua_State *L) +{ + const char *name; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_update"); + LUA_RETURN_ERROR; + } + + name = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_update"); + LUA_RETURN_ERROR; + } + + name = lua_tostring (lua_current_interpreter, -1); + + weechat_bar_update ((char *)name); + + LUA_RETURN_OK; +} + +/* + * weechat_lua_api_bar_remove: remove a bar + */ + +static int +weechat_lua_api_bar_remove (lua_State *L) +{ + const char *bar; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_remove"); + LUA_RETURN_ERROR; + } + + bar = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_remove"); + LUA_RETURN_ERROR; + } + + bar = lua_tostring (lua_current_interpreter, -1); + + weechat_bar_remove (script_str2ptr ((char *)bar)); + + LUA_RETURN_OK; +} + /* * weechat_lua_api_command: send command to server */ @@ -3341,6 +3737,7 @@ weechat_lua_api_command (lua_State *L) LUA_RETURN_ERROR; } + buffer = NULL; command = NULL; n = lua_gettop (lua_current_interpreter); @@ -3395,9 +3792,357 @@ weechat_lua_api_info_get (lua_State *L) info = lua_tostring (lua_current_interpreter, -1); value = weechat_info_get ((char *)info); + LUA_RETURN_STRING(value); } +/* + * weechat_lua_api_infolist_get: get list with infos + */ + +static int +weechat_lua_api_infolist_get (lua_State *L) +{ + const char *name, *pointer; + char *value; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_get"); + LUA_RETURN_EMPTY; + } + + name = NULL; + pointer = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_get"); + LUA_RETURN_EMPTY; + } + + name = lua_tostring (lua_current_interpreter, -2); + pointer = lua_tostring (lua_current_interpreter, -1); + + value = script_ptr2str (weechat_infolist_get ((char *)name, + script_str2ptr ((char *)pointer))); + + LUA_RETURN_STRING_FREE(value); +} + +/* + * weechat_lua_api_infolist_next: move item pointer to next item in infolist + */ + +static int +weechat_lua_api_infolist_next (lua_State *L) +{ + const char *infolist; + int n, value; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_next"); + LUA_RETURN_INT(0); + } + + infolist = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_next"); + LUA_RETURN_INT(0); + } + + infolist = lua_tostring (lua_current_interpreter, -1); + + value = weechat_infolist_next (script_str2ptr ((char *)infolist)); + + LUA_RETURN_INT(value); +} + +/* + * weechat_lua_api_infolist_prev: move item pointer to previous item in infolist + */ + +static int +weechat_lua_api_infolist_prev (lua_State *L) +{ + const char *infolist; + int n, value; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_prev"); + LUA_RETURN_INT(0); + } + + infolist = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_prev"); + LUA_RETURN_INT(0); + } + + infolist = lua_tostring (lua_current_interpreter, -1); + + value = weechat_infolist_prev (script_str2ptr ((char *)infolist)); + + LUA_RETURN_INT(value); +} + +/* + * weechat_lua_api_infolist_fields: get list of fields for current item of infolist + */ + +static int +weechat_lua_api_infolist_fields (lua_State *L) +{ + const char *infolist; + char *value; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_fields"); + LUA_RETURN_EMPTY; + } + + infolist = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_fields"); + LUA_RETURN_EMPTY; + } + + infolist = lua_tostring (lua_current_interpreter, -1); + + value = weechat_infolist_fields (script_str2ptr ((char *)infolist)); + + LUA_RETURN_STRING(value); +} + +/* + * weechat_lua_api_infolist_integer: get integer value of a variable in infolist + */ + +static int +weechat_lua_api_infolist_integer (lua_State *L) +{ + const char *infolist, *variable; + int n, value; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_integer"); + LUA_RETURN_INT(0); + } + + infolist = NULL; + variable = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_integer"); + LUA_RETURN_INT(0); + } + + infolist = lua_tostring (lua_current_interpreter, -2); + variable = lua_tostring (lua_current_interpreter, -1); + + value = weechat_infolist_integer (script_str2ptr ((char *)infolist), + (char *)variable); + + LUA_RETURN_INT(value); +} + +/* + * weechat_lua_api_infolist_string: get string value of a variable in infolist + */ + +static int +weechat_lua_api_infolist_string (lua_State *L) +{ + const char *infolist, *variable; + char *value; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_string"); + LUA_RETURN_EMPTY; + } + + infolist = NULL; + variable = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_string"); + LUA_RETURN_EMPTY; + } + + infolist = lua_tostring (lua_current_interpreter, -2); + variable = lua_tostring (lua_current_interpreter, -1); + + value = weechat_infolist_string (script_str2ptr ((char *)infolist), + (char *)variable); + + LUA_RETURN_STRING(value); +} + +/* + * weechat_lua_api_infolist_pointer: get pointer value of a variable in infolist + */ + +static int +weechat_lua_api_infolist_pointer (lua_State *L) +{ + const char *infolist, *variable; + char *value; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_pointer"); + LUA_RETURN_EMPTY; + } + + infolist = NULL; + variable = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_pointer"); + LUA_RETURN_EMPTY; + } + + infolist = lua_tostring (lua_current_interpreter, -2); + variable = lua_tostring (lua_current_interpreter, -1); + + value = script_ptr2str (weechat_infolist_pointer (script_str2ptr ((char *)infolist), + (char *)variable)); + + LUA_RETURN_STRING_FREE(value); +} + +/* + * weechat_lua_api_infolist_time: get time value of a variable in infolist + */ + +static int +weechat_lua_api_infolist_time (lua_State *L) +{ + const char *infolist, *variable; + time_t time; + char timebuffer[64], *value; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_time"); + LUA_RETURN_EMPTY; + } + + infolist = NULL; + variable = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_time"); + LUA_RETURN_EMPTY; + } + + infolist = lua_tostring (lua_current_interpreter, -2); + variable = lua_tostring (lua_current_interpreter, -1); + + time = weechat_infolist_time (script_str2ptr ((char *)infolist), + (char *)variable); + strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time)); + value = strdup (timebuffer); + + LUA_RETURN_STRING_FREE(value); +} + +/* + * weechat_lua_api_infolist_free: free infolist + */ + +static int +weechat_lua_api_infolist_free (lua_State *L) +{ + const char *infolist; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_free"); + LUA_RETURN_ERROR; + } + + infolist = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_free"); + LUA_RETURN_ERROR; + } + + infolist = lua_tostring (lua_current_interpreter, -1); + + weechat_infolist_free (script_str2ptr ((char *)infolist)); + + LUA_RETURN_OK; +} + /* * Lua constant as functions */ @@ -3634,8 +4379,25 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "nicklist_remove_group", &weechat_lua_api_nicklist_remove_group }, { "nicklist_remove_nick", &weechat_lua_api_nicklist_remove_nick }, { "nicklist_remove_all", &weechat_lua_api_nicklist_remove_all }, + { "bar_item_search", &weechat_lua_api_bar_item_search }, + { "bar_item_new", &weechat_lua_api_bar_item_new }, + { "bar_item_update", &weechat_lua_api_bar_item_update }, + { "bar_item_remove", &weechat_lua_api_bar_item_remove }, + { "bar_search", &weechat_lua_api_bar_search }, + { "bar_new", &weechat_lua_api_bar_new }, + { "bar_update", &weechat_lua_api_bar_update }, + { "bar_remove", &weechat_lua_api_bar_remove }, { "command", &weechat_lua_api_command }, { "info_get", &weechat_lua_api_info_get }, + { "infolist_get", &weechat_lua_api_infolist_get }, + { "infolist_next", &weechat_lua_api_infolist_next }, + { "infolist_prev", &weechat_lua_api_infolist_prev }, + { "infolist_fields", &weechat_lua_api_infolist_fields }, + { "infolist_integer", &weechat_lua_api_infolist_integer }, + { "infolist_string", &weechat_lua_api_infolist_string }, + { "infolist_pointer", &weechat_lua_api_infolist_pointer }, + { "infolist_time", &weechat_lua_api_infolist_time }, + { "infolist_free", &weechat_lua_api_infolist_free }, /* define constants as function which returns values */ { "WEECHAT_RC_OK", &weechat_lua_api_constant_weechat_rc_ok }, { "WEECHAT_RC_ERROR", &weechat_lua_api_constant_weechat_rc_error }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index b689ba6d9..4136490c5 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -178,6 +178,7 @@ static XS (XS_weechat_iconv_to_internal) result = weechat_iconv_to_internal (SvPV (ST (0), PL_na), /* charset */ SvPV (ST (1), PL_na)); /* string */ + PERL_RETURN_STRING_FREE(result); } @@ -208,6 +209,7 @@ static XS (XS_weechat_iconv_from_internal) result = weechat_iconv_from_internal (SvPV (ST (0), PL_na), /* charset */ SvPV (ST (1), PL_na)); /* string */ + PERL_RETURN_STRING_FREE(result); } @@ -236,6 +238,7 @@ static XS (XS_weechat_gettext) } result = weechat_gettext (SvPV (ST (0), PL_na)); /* string */ + PERL_RETURN_STRING(result); } @@ -266,6 +269,7 @@ static XS (XS_weechat_ngettext) result = weechat_ngettext (SvPV (ST (0), PL_na), /* single */ SvPV (ST (1), PL_na), /* plural */ SvIV (ST (2))); /* count */ + PERL_RETURN_STRING(result); } @@ -349,6 +353,7 @@ static XS (XS_weechat_list_new) } result = script_ptr2str (weechat_list_new ()); + PERL_RETURN_STRING_FREE(result); } @@ -379,6 +384,7 @@ static XS (XS_weechat_list_add) result = script_ptr2str (weechat_list_add (script_str2ptr (SvPV (ST (0), PL_na)), /* weelist */ SvPV (ST (1), PL_na), /* data */ SvPV (ST (2), PL_na))); /* where */ + PERL_RETURN_STRING_FREE(result); } @@ -408,6 +414,7 @@ static XS (XS_weechat_list_search) result = script_ptr2str (weechat_list_search (script_str2ptr (SvPV (ST (0), PL_na)), /* weelist */ SvPV (ST (1), PL_na))); /* data */ + PERL_RETURN_STRING_FREE(result); } @@ -437,6 +444,7 @@ static XS (XS_weechat_list_casesearch) result = script_ptr2str (weechat_list_casesearch (script_str2ptr (SvPV (ST (0), PL_na)), /* weelist */ SvPV (ST (1), PL_na))); /* data */ + PERL_RETURN_STRING_FREE(result); } @@ -466,6 +474,7 @@ static XS (XS_weechat_list_get) result = script_ptr2str (weechat_list_get (script_str2ptr (SvPV (ST (0), PL_na)), /* weelist */ SvIV (ST (1)))); /* position */ + PERL_RETURN_STRING_FREE(result); } @@ -523,6 +532,7 @@ static XS (XS_weechat_list_next) } result = script_ptr2str (weechat_list_next (script_str2ptr (SvPV (ST (0), PL_na)))); /* item */ + PERL_RETURN_STRING_FREE(result); } @@ -551,6 +561,7 @@ static XS (XS_weechat_list_prev) } result = script_ptr2str (weechat_list_prev (script_str2ptr (SvPV (ST (0), PL_na)))); /* item */ + PERL_RETURN_STRING_FREE(result); } @@ -579,6 +590,7 @@ static XS (XS_weechat_list_string) } result = weechat_list_string (script_str2ptr (SvPV (ST (0), PL_na))); /* item */ + PERL_RETURN_STRING(result); } @@ -607,6 +619,7 @@ static XS (XS_weechat_list_size) } size = weechat_list_size (script_str2ptr (SvPV (ST (0), PL_na))); /* weelist */ + PERL_RETURN_INT(size); } @@ -764,6 +777,7 @@ static XS (XS_weechat_config_new) SvPV (ST (0), PL_na), /* filename */ &weechat_perl_api_config_reload_cb, SvPV (ST (1), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -902,6 +916,7 @@ static XS (XS_weechat_config_new_section) SvPV (ST (3), PL_na), /* perl function (write cb) */ &weechat_perl_api_config_section_write_default_cb, SvPV (ST (4), PL_na))); /* perl function (write default cb) */ + PERL_RETURN_STRING_FREE(result); } @@ -931,6 +946,7 @@ static XS (XS_weechat_config_search_section) result = script_ptr2str (weechat_config_search_section (script_str2ptr (SvPV (ST (0), PL_na)), /* config_file */ SvPV (ST (1), PL_na))); /* section_name */ + PERL_RETURN_STRING_FREE(result); } @@ -998,6 +1014,7 @@ static XS (XS_weechat_config_new_option) SvPV (ST (8), PL_na), /* default_value */ &weechat_perl_api_config_option_change_cb, SvPV (ST (9), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -1028,6 +1045,7 @@ static XS (XS_weechat_config_search_option) result = script_ptr2str (weechat_config_search_option (script_str2ptr (SvPV (ST (0), PL_na)), /* config_file */ script_str2ptr (SvPV (ST (1), PL_na)), /* section */ SvPV (ST (2), PL_na))); /* option_name */ + PERL_RETURN_STRING_FREE(result); } @@ -1056,6 +1074,7 @@ static XS (XS_weechat_config_string_to_boolean) } value = weechat_config_string_to_boolean (SvPV (ST (0), PL_na)); /* text */ + PERL_RETURN_INT(value); } @@ -1086,6 +1105,7 @@ static XS (XS_weechat_config_option_set) rc = weechat_config_option_set (script_str2ptr (SvPV (ST (0), PL_na)), /* option */ SvPV (ST (1), PL_na), /* new_value */ SvIV (ST (2))); /* run_callback */ + PERL_RETURN_INT(rc); } @@ -1114,6 +1134,7 @@ static XS (XS_weechat_config_boolean) } value = weechat_config_boolean (script_str2ptr (SvPV (ST (0), PL_na))); /* option */ + PERL_RETURN_INT(value); } @@ -1142,6 +1163,7 @@ static XS (XS_weechat_config_integer) } value = weechat_config_integer (script_str2ptr (SvPV (ST (0), PL_na))); /* option */ + PERL_RETURN_INT(value); } @@ -1170,6 +1192,7 @@ static XS (XS_weechat_config_string) } value = weechat_config_string (script_str2ptr (SvPV (ST (0), PL_na))); /* option */ + PERL_RETURN_STRING(value); } @@ -1198,6 +1221,7 @@ static XS (XS_weechat_config_color) } value = weechat_config_color (script_str2ptr (SvPV (ST (0), PL_na))); /* option */ + PERL_RETURN_INT(value); } @@ -1257,6 +1281,7 @@ static XS (XS_weechat_config_write) } rc = weechat_config_write (script_str2ptr (SvPV (ST (0), PL_na))); /* config_file */ + PERL_RETURN_INT(rc); } @@ -1285,6 +1310,7 @@ static XS (XS_weechat_config_read) } rc = weechat_config_read (script_str2ptr (SvPV (ST (0), PL_na))); /* config_file */ + PERL_RETURN_INT(rc); } @@ -1313,6 +1339,7 @@ static XS (XS_weechat_config_reload) } rc = weechat_config_reload (script_str2ptr (SvPV (ST (0), PL_na))); /* config_file */ + PERL_RETURN_INT(rc); } @@ -1371,6 +1398,7 @@ static XS (XS_weechat_prefix) } result = weechat_prefix (SvPV (ST (0), PL_na)); + PERL_RETURN_STRING(result); } @@ -1399,6 +1427,7 @@ static XS (XS_weechat_color) } result = weechat_color (SvPV (ST (0), PL_na)); + PERL_RETURN_STRING(result); } @@ -1590,6 +1619,7 @@ static XS (XS_weechat_hook_command) SvPV (ST (4), PL_na), /* completion */ &weechat_perl_api_hook_command_cb, SvPV (ST (5), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -1655,6 +1685,7 @@ static XS (XS_weechat_hook_timer) SvIV (ST (2)), /* max_calls */ &weechat_perl_api_hook_timer_cb, SvPV (ST (3), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -1721,6 +1752,7 @@ static XS (XS_weechat_hook_fd) SvIV (ST (3)), /* exception */ &weechat_perl_api_hook_fd_cb, SvPV (ST (4), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -1796,6 +1828,7 @@ static XS (XS_weechat_hook_print) SvIV (ST (2)), /* strip_colors */ &weechat_perl_api_hook_print_cb, SvPV (ST (3), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -1882,6 +1915,7 @@ static XS (XS_weechat_hook_signal) SvPV (ST (0), PL_na), /* signal */ &weechat_perl_api_hook_signal_cb, SvPV (ST (1), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -2002,6 +2036,7 @@ static XS (XS_weechat_hook_config) SvPV (ST (1), PL_na), /* option */ &weechat_perl_api_hook_config_cb, SvPV (ST (2), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -2074,6 +2109,7 @@ static XS (XS_weechat_hook_completion) SvPV (ST (0), PL_na), /* completion */ &weechat_perl_api_hook_completion_cb, SvPV (ST (1), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -2130,6 +2166,7 @@ static XS (XS_weechat_hook_modifier) SvPV (ST (0), PL_na), /* modifier */ &weechat_perl_api_hook_modifier_cb, SvPV (ST (1), PL_na))); /* perl function */ + PERL_RETURN_STRING_FREE(result); } @@ -2160,6 +2197,7 @@ static XS (XS_weechat_hook_modifier_exec) result = weechat_hook_modifier_exec (SvPV (ST (0), PL_na), /* modifier */ SvPV (ST (1), PL_na), /* modifier_data */ SvPV (ST (2), PL_na)); /* string */ + PERL_RETURN_STRING_FREE(result); } @@ -2316,6 +2354,7 @@ static XS (XS_weechat_buffer_new) SvPV (ST (2), PL_na), /* function input */ &weechat_perl_api_close_cb, SvPV (ST (3), PL_na))); /* function close */ + PERL_RETURN_STRING_FREE(result); } @@ -2345,6 +2384,7 @@ static XS (XS_weechat_buffer_search) result = script_ptr2str (weechat_buffer_search (SvPV (ST (0), PL_na), /* category */ SvPV (ST (1), PL_na))); /* name */ + PERL_RETURN_STRING_FREE(result); } @@ -2405,6 +2445,7 @@ static XS (XS_weechat_buffer_get) value = weechat_buffer_get (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */ SvPV (ST (1), PL_na)); /* property */ + PERL_RETURN_STRING(value); } @@ -2467,6 +2508,7 @@ static XS (XS_weechat_nicklist_add_group) SvPV (ST (2), PL_na), /* name */ SvPV (ST (3), PL_na), /* color */ SvIV (ST (4)))); /* visible */ + PERL_RETURN_STRING_FREE(result); } @@ -2497,6 +2539,7 @@ static XS (XS_weechat_nicklist_search_group) result = script_ptr2str (weechat_nicklist_search_group (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */ script_str2ptr (SvPV (ST (1), PL_na)), /* from_group */ SvPV (ST (2), PL_na))); /* name */ + PERL_RETURN_STRING_FREE(result); } @@ -2537,6 +2580,7 @@ static XS (XS_weechat_nicklist_add_nick) char_prefix, SvPV (ST (5), PL_na), /* prefix_color */ SvIV (ST (6)))); /* visible */ + PERL_RETURN_STRING_FREE(result); } @@ -2567,6 +2611,7 @@ static XS (XS_weechat_nicklist_search_nick) result = script_ptr2str (weechat_nicklist_search_nick (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */ script_str2ptr (SvPV (ST (1), PL_na)), /* from_group */ SvPV (ST (2), PL_na))); /* name */ + PERL_RETURN_STRING_FREE(result); } @@ -2656,6 +2701,280 @@ static XS (XS_weechat_nicklist_remove_all) PERL_RETURN_OK; } +/* + * weechat::bar_item_search: search a bar item + */ + +static XS (XS_weechat_bar_item_search) +{ + char *result; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_search"); + PERL_RETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_search"); + PERL_RETURN_EMPTY; + } + + result = script_ptr2str (weechat_bar_item_search (SvPV (ST (0), PL_na))); /* name */ + + PERL_RETURN_STRING_FREE(result); +} + +/* + * weechat_perl_api_bar_item_build_cb: callback for building bar item + */ + +char * +weechat_perl_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + struct t_script_callback *script_callback; + char *perl_argv[4], *ret; + static char buf[32]; + + script_callback = (struct t_script_callback *)data; + + snprintf (buf, sizeof (buf) - 1, "%d", max_width); + + perl_argv[0] = script_ptr2str (item); + perl_argv[1] = script_ptr2str (window); + perl_argv[2] = buf; + perl_argv[3] = NULL; + + ret = (char *)weechat_perl_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + perl_argv); + + if (perl_argv[0]) + free (perl_argv[0]); + if (perl_argv[1]) + free (perl_argv[1]); + + return ret; +} + +/* + * weechat::bar_item_new: add a new bar item + */ + +static XS (XS_weechat_bar_item_new) +{ + char *result; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_new"); + PERL_RETURN_EMPTY; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_new"); + PERL_RETURN_EMPTY; + } + + result = script_ptr2str (script_api_bar_item_new (weechat_perl_plugin, + perl_current_script, + SvPV (ST (0), PL_na), /* name */ + &weechat_perl_api_bar_item_build_cb, + SvPV (ST (1), PL_na))); /* function build */ + + PERL_RETURN_STRING_FREE(result); +} + +/* + * weechat::bar_item_update: update a bar item on screen + */ + +static XS (XS_weechat_bar_item_update) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_update"); + PERL_RETURN_ERROR; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_update"); + PERL_RETURN_ERROR; + } + + weechat_bar_item_update (SvPV (ST (0), PL_na)); /* name */ + + PERL_RETURN_OK; +} + +/* + * weechat::bar_item_remove: remove a bar item + */ + +static XS (XS_weechat_bar_item_remove) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_remove"); + PERL_RETURN_ERROR; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_remove"); + PERL_RETURN_ERROR; + } + + script_api_bar_item_remove (weechat_perl_plugin, + perl_current_script, + script_str2ptr (SvPV (ST (0), PL_na))); /* item */ + + PERL_RETURN_OK; +} + +/* + * weechat::bar_search: search a bar + */ + +static XS (XS_weechat_bar_search) +{ + char *result; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_search"); + PERL_RETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_search"); + PERL_RETURN_EMPTY; + } + + result = script_ptr2str (weechat_bar_search (SvPV (ST (0), PL_na))); /* name */ + + PERL_RETURN_STRING_FREE(result); +} + +/* + * weechat::bar_new: add a new bar + */ + +static XS (XS_weechat_bar_new) +{ + char *result; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_new"); + PERL_RETURN_EMPTY; + } + + if (items < 6) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new"); + PERL_RETURN_EMPTY; + } + + result = script_ptr2str (weechat_bar_new (SvPV (ST (0), PL_na), /* name */ + SvPV (ST (1), PL_na), /* type */ + SvPV (ST (2), PL_na), /* position */ + SvIV (ST (3)), /* size */ + SvIV (ST (4)), /* separator */ + SvPV (ST (5), PL_na))); /* items */ + + PERL_RETURN_STRING_FREE(result); +} + +/* + * weechat::bar_update: update a bar on screen + */ + +static XS (XS_weechat_bar_update) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_update"); + PERL_RETURN_ERROR; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_update"); + PERL_RETURN_ERROR; + } + + weechat_bar_update (SvPV (ST (0), PL_na)); /* name */ + + PERL_RETURN_OK; +} + +/* + * weechat::bar_remove: remove a bar + */ + +static XS (XS_weechat_bar_remove) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_remove"); + PERL_RETURN_ERROR; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_remove"); + PERL_RETURN_ERROR; + } + + weechat_bar_remove (script_str2ptr (SvPV (ST (0), PL_na))); /* bar */ + + PERL_RETURN_OK; +} + /* * weechat::command: execute a command on a buffer */ @@ -2712,9 +3031,278 @@ static XS (XS_weechat_info_get) } value = weechat_info_get (SvPV (ST (0), PL_na)); + PERL_RETURN_STRING(value); } +/* + * weechat::infolist_get: get list with infos + */ + +static XS (XS_weechat_infolist_get) +{ + char *value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_get"); + PERL_RETURN_EMPTY; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_get"); + PERL_RETURN_EMPTY; + } + + value = script_ptr2str (weechat_infolist_get (SvPV (ST (0), PL_na), /* name */ + script_str2ptr (SvPV (ST (1), PL_na)))); /* pointer */ + + PERL_RETURN_STRING_FREE(value); +} + +/* + * weechat::infolist_next: move item pointer to next item in infolist + */ + +static XS (XS_weechat_infolist_next) +{ + int value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_next"); + PERL_RETURN_INT(0); + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_next"); + PERL_RETURN_INT(0); + } + + value = weechat_infolist_next (script_str2ptr (SvPV (ST (0), PL_na))); /* infolist */ + + PERL_RETURN_INT(value); +} + +/* + * weechat::infolist_prev: move item pointer to previous item in infolist + */ + +static XS (XS_weechat_infolist_prev) +{ + int value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_prev"); + PERL_RETURN_INT(0); + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_prev"); + PERL_RETURN_INT(0); + } + + value = weechat_infolist_prev (script_str2ptr (SvPV (ST (0), PL_na))); /* infolist */ + + PERL_RETURN_INT(value); +} + +/* + * weechat::infolist_fields: get list of fields for current item of infolist + */ + +static XS (XS_weechat_infolist_fields) +{ + char *value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_fields"); + PERL_RETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_fields"); + PERL_RETURN_EMPTY; + } + + value = weechat_infolist_fields (script_str2ptr (SvPV (ST (0), PL_na))); /* infolist */ + + PERL_RETURN_STRING(value); +} + +/* + * weechat::infolist_integer: get integer value of a variable in infolist + */ + +static XS (XS_weechat_infolist_integer) +{ + int value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_integer"); + PERL_RETURN_INT(0); + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_integer"); + PERL_RETURN_INT(0); + } + + value = weechat_infolist_integer (script_str2ptr (SvPV (ST (0), PL_na)), /* infolist */ + SvPV (ST (1), PL_na)); /* variable */ + + PERL_RETURN_INT(value); +} + +/* + * weechat::infolist_string: get string value of a variable in infolist + */ + +static XS (XS_weechat_infolist_string) +{ + char *value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_string"); + PERL_RETURN_EMPTY; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_string"); + PERL_RETURN_EMPTY; + } + + value = weechat_infolist_string (script_str2ptr (SvPV (ST (0), PL_na)), /* infolist */ + SvPV (ST (1), PL_na)); /* variable */ + + PERL_RETURN_STRING(value); +} + +/* + * weechat::infolist_pointer: get pointer value of a variable in infolist + */ + +static XS (XS_weechat_infolist_pointer) +{ + char *value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_pointer"); + PERL_RETURN_EMPTY; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_pointer"); + PERL_RETURN_EMPTY; + } + + value = script_ptr2str (weechat_infolist_pointer (script_str2ptr (SvPV (ST (0), PL_na)), /* infolist */ + SvPV (ST (1), PL_na))); /* variable */ + + PERL_RETURN_STRING_FREE(value); +} + +/* + * weechat::infolist_time: get time value of a variable in infolist + */ + +static XS (XS_weechat_infolist_time) +{ + time_t time; + char timebuffer[64], *value; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_time"); + PERL_RETURN_EMPTY; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_time"); + PERL_RETURN_EMPTY; + } + + time = weechat_infolist_time (script_str2ptr (SvPV (ST (0), PL_na)), /* infolist */ + SvPV (ST (1), PL_na)); /* variable */ + strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time)); + value = strdup (timebuffer); + + PERL_RETURN_STRING_FREE(value); +} + +/* + * weechat::infolist_free: free infolist + */ + +static XS (XS_weechat_infolist_free) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_free"); + PERL_RETURN_ERROR; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_free"); + PERL_RETURN_ERROR; + } + + weechat_infolist_free (script_str2ptr (SvPV (ST (0), PL_na))); /* infolist */ + + PERL_RETURN_OK; +} + /* * weechat_perl_api_init: initialize subroutines */ @@ -2794,8 +3382,25 @@ weechat_perl_api_init (pTHX) newXS ("weechat::nicklist_remove_group", XS_weechat_nicklist_remove_group, "weechat"); newXS ("weechat::nicklist_remove_nick", XS_weechat_nicklist_remove_nick, "weechat"); newXS ("weechat::nicklist_remove_all", XS_weechat_nicklist_remove_all, "weechat"); + newXS ("weechat::bar_item_search", XS_weechat_bar_item_search, "weechat"); + newXS ("weechat::bar_item_new", XS_weechat_bar_item_new, "weechat"); + newXS ("weechat::bar_item_update", XS_weechat_bar_item_update, "weechat"); + newXS ("weechat::bar_item_remove", XS_weechat_bar_item_remove, "weechat"); + newXS ("weechat::bar_search", XS_weechat_bar_search, "weechat"); + newXS ("weechat::bar_new", XS_weechat_bar_new, "weechat"); + newXS ("weechat::bar_update", XS_weechat_bar_update, "weechat"); + newXS ("weechat::bar_remove", XS_weechat_bar_remove, "weechat"); newXS ("weechat::command", XS_weechat_command, "weechat"); newXS ("weechat::info_get", XS_weechat_info_get, "weechat"); + newXS ("weechat::infolist_get", XS_weechat_infolist_get, "weechat"); + newXS ("weechat::infolist_next", XS_weechat_infolist_next, "weechat"); + newXS ("weechat::infolist_prev", XS_weechat_infolist_prev, "weechat"); + newXS ("weechat::infolist_fields", XS_weechat_infolist_fields, "weechat"); + newXS ("weechat::infolist_integer", XS_weechat_infolist_integer, "weechat"); + newXS ("weechat::infolist_string", XS_weechat_infolist_string, "weechat"); + newXS ("weechat::infolist_pointer", XS_weechat_infolist_pointer, "weechat"); + newXS ("weechat::infolist_time", XS_weechat_infolist_time, "weechat"); + newXS ("weechat::infolist_free", XS_weechat_infolist_free, "weechat"); /* interface constants */ stash = gv_stashpv ("weechat", TRUE); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index f9893ff59..e4a1dd232 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -175,6 +175,7 @@ weechat_python_api_iconv_to_internal (PyObject *self, PyObject *args) } result = weechat_iconv_to_internal (charset, string); + PYTHON_RETURN_STRING_FREE(result); } @@ -208,6 +209,7 @@ weechat_python_api_iconv_from_internal (PyObject *self, PyObject *args) } result = weechat_iconv_from_internal (charset, string); + PYTHON_RETURN_STRING_FREE(result); } @@ -238,6 +240,7 @@ weechat_python_api_gettext (PyObject *self, PyObject *args) } result = weechat_gettext (string); + PYTHON_RETURN_STRING(result); } @@ -271,6 +274,7 @@ weechat_python_api_ngettext (PyObject *self, PyObject *args) } result = weechat_ngettext (single, plural, count); + PYTHON_RETURN_STRING(result); } @@ -363,6 +367,7 @@ weechat_python_api_list_new (PyObject *self, PyObject *args) } result = script_ptr2str (weechat_list_new ()); + PYTHON_RETURN_STRING_FREE(result); } @@ -398,6 +403,7 @@ weechat_python_api_list_add (PyObject *self, PyObject *args) result = script_ptr2str (weechat_list_add (script_str2ptr (weelist), data, where)); + PYTHON_RETURN_STRING_FREE(result); } @@ -431,6 +437,7 @@ weechat_python_api_list_search (PyObject *self, PyObject *args) result = script_ptr2str (weechat_list_search (script_str2ptr (weelist), data)); + PYTHON_RETURN_STRING_FREE(result); } @@ -464,6 +471,7 @@ weechat_python_api_list_casesearch (PyObject *self, PyObject *args) result = script_ptr2str (weechat_list_casesearch (script_str2ptr (weelist), data)); + PYTHON_RETURN_STRING_FREE(result); } @@ -562,6 +570,7 @@ weechat_python_api_list_next (PyObject *self, PyObject *args) } result = script_ptr2str (weechat_list_next (script_str2ptr (item))); + PYTHON_RETURN_STRING_FREE(result); } @@ -593,6 +602,7 @@ weechat_python_api_list_prev (PyObject *self, PyObject *args) } result = script_ptr2str (weechat_list_prev (script_str2ptr (item))); + PYTHON_RETURN_STRING_FREE(result); } @@ -623,6 +633,7 @@ weechat_python_api_list_string (PyObject *self, PyObject *args) } result = weechat_list_string (script_str2ptr (item)); + PYTHON_RETURN_STRING(result); } @@ -654,6 +665,7 @@ weechat_python_api_list_size (PyObject *self, PyObject *args) } size = weechat_list_size (script_str2ptr (weelist)); + PYTHON_RETURN_INT(size); } @@ -825,6 +837,7 @@ weechat_python_api_config_new (PyObject *self, PyObject *args) filename, &weechat_python_api_config_reload_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -972,6 +985,7 @@ weechat_python_api_config_new_section (PyObject *self, PyObject *args) function_write, &weechat_python_api_config_section_write_default_cb, function_write_default)); + PYTHON_RETURN_STRING_FREE(result); } @@ -1005,6 +1019,7 @@ weechat_python_api_config_search_section (PyObject *self, PyObject *args) result = script_ptr2str (weechat_config_search_section (script_str2ptr (config_file), section_name)); + PYTHON_RETURN_STRING_FREE(result); } @@ -1086,6 +1101,7 @@ weechat_python_api_config_new_option (PyObject *self, PyObject *args) default_value, &weechat_python_api_config_option_change_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -1121,6 +1137,7 @@ weechat_python_api_config_search_option (PyObject *self, PyObject *args) result = script_ptr2str (weechat_config_search_option (script_str2ptr (config_file), script_str2ptr (section), option_name)); + PYTHON_RETURN_STRING_FREE(result); } @@ -1152,6 +1169,7 @@ weechat_python_api_config_string_to_boolean (PyObject *self, PyObject *args) } value = weechat_config_string_to_boolean (text); + PYTHON_RETURN_INT(value); } @@ -1187,6 +1205,7 @@ weechat_python_api_config_option_set (PyObject *self, PyObject *args) rc = weechat_config_option_set (script_str2ptr (option), new_value, run_callback); + PYTHON_RETURN_INT(rc); } @@ -1218,6 +1237,7 @@ weechat_python_api_config_boolean (PyObject *self, PyObject *args) } value = weechat_config_boolean (script_str2ptr (option)); + PYTHON_RETURN_INT(value); } @@ -1249,6 +1269,7 @@ weechat_python_api_config_integer (PyObject *self, PyObject *args) } value = weechat_config_integer (script_str2ptr (option)); + PYTHON_RETURN_INT(value); } @@ -1279,6 +1300,7 @@ weechat_python_api_config_string (PyObject *self, PyObject *args) } value = weechat_config_string (script_str2ptr (option)); + PYTHON_RETURN_STRING(value); } @@ -1310,6 +1332,7 @@ weechat_python_api_config_color (PyObject *self, PyObject *args) } value = weechat_config_color (script_str2ptr (option)); + PYTHON_RETURN_INT(value); } @@ -1377,6 +1400,7 @@ weechat_python_api_config_write (PyObject *self, PyObject *args) } rc = weechat_config_write (script_str2ptr (config_file)); + PYTHON_RETURN_INT(rc); } @@ -1408,6 +1432,7 @@ weechat_python_api_config_read (PyObject *self, PyObject *args) } rc = weechat_config_read (script_str2ptr (config_file)); + PYTHON_RETURN_INT(rc); } @@ -1439,6 +1464,7 @@ weechat_python_api_config_reload (PyObject *self, PyObject *args) } rc = weechat_config_reload (script_str2ptr (config_file)); + PYTHON_RETURN_INT(rc); } @@ -1502,6 +1528,7 @@ weechat_python_api_prefix (PyObject *self, PyObject *args) } result = weechat_prefix (prefix); + PYTHON_RETURN_STRING(result); } @@ -1532,6 +1559,7 @@ weechat_python_api_color (PyObject *self, PyObject *args) } result = weechat_color (color); + PYTHON_RETURN_STRING(result); } @@ -1751,6 +1779,7 @@ weechat_python_api_hook_command (PyObject *self, PyObject *args) completion, &weechat_python_api_hook_command_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -1824,6 +1853,7 @@ weechat_python_api_hook_timer (PyObject *self, PyObject *args) max_calls, &weechat_python_api_hook_timer_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -1899,6 +1929,7 @@ weechat_python_api_hook_fd (PyObject *self, PyObject *args) exception, &weechat_python_api_hook_fd_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -1982,6 +2013,7 @@ weechat_python_api_hook_print (PyObject *self, PyObject *args) strip_colors, &weechat_python_api_hook_print_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2072,6 +2104,7 @@ weechat_python_api_hook_signal (PyObject *self, PyObject *args) signal, &weechat_python_api_hook_signal_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2199,6 +2232,7 @@ weechat_python_api_hook_config (PyObject *self, PyObject *args) option, &weechat_python_api_hook_config_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2275,6 +2309,7 @@ weechat_python_api_hook_completion (PyObject *self, PyObject *args) completion, &weechat_python_api_hook_completion_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2335,6 +2370,7 @@ weechat_python_api_hook_modifier (PyObject *self, PyObject *args) modifier, &weechat_python_api_hook_modifier_cb, function)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2368,6 +2404,7 @@ weechat_python_api_hook_modifier_exec (PyObject *self, PyObject *args) } result = weechat_hook_modifier_exec (modifier, modifier_data, string); + PYTHON_RETURN_STRING_FREE(result); } @@ -2533,6 +2570,7 @@ weechat_python_api_buffer_new (PyObject *self, PyObject *args) function_input, &weechat_python_api_close_cb, function_close)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2566,6 +2604,7 @@ weechat_python_api_buffer_search (PyObject *self, PyObject *args) } result = script_ptr2str (weechat_buffer_search (category, name)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2633,6 +2672,7 @@ weechat_python_api_buffer_get (PyObject *self, PyObject *args) } value = weechat_buffer_get (script_str2ptr (buffer), property); + PYTHON_RETURN_STRING(value); } @@ -2709,6 +2749,7 @@ weechat_python_api_nicklist_add_group (PyObject *self, PyObject *args) name, color, visible)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2744,6 +2785,7 @@ weechat_python_api_nicklist_search_group (PyObject *self, PyObject *args) result = script_ptr2str (weechat_nicklist_search_group (script_str2ptr (buffer), script_str2ptr (from_group), name)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2795,6 +2837,7 @@ weechat_python_api_nicklist_add_nick (PyObject *self, PyObject *args) char_prefix, prefix_color, visible)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2830,6 +2873,7 @@ weechat_python_api_nicklist_search_nick (PyObject *self, PyObject *args) result = script_ptr2str (weechat_nicklist_search_nick (script_str2ptr (buffer), script_str2ptr (from_group), name)); + PYTHON_RETURN_STRING_FREE(result); } @@ -2930,6 +2974,312 @@ weechat_python_api_nicklist_remove_all (PyObject *self, PyObject *args) PYTHON_RETURN_OK; } +/* + * weechat_python_api_bar_item_search: search a bar item + */ + +static PyObject * +weechat_python_api_bar_item_search (PyObject *self, PyObject *args) +{ + char *name, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_search"); + PYTHON_RETURN_EMPTY; + } + + name = NULL; + + if (!PyArg_ParseTuple (args, "s", &name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_search"); + PYTHON_RETURN_EMPTY; + } + + result = script_ptr2str (weechat_bar_item_search (name)); + + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_bar_item_build_cb: callback for building bar item + */ + +char * +weechat_python_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + struct t_script_callback *script_callback; + char *python_argv[4], *ret; + static char buf[32]; + + script_callback = (struct t_script_callback *)data; + + snprintf (buf, sizeof (buf) - 1, "%d", max_width); + + python_argv[0] = script_ptr2str (item); + python_argv[1] = script_ptr2str (window); + python_argv[2] = buf; + python_argv[3] = NULL; + + ret = (char *)weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + python_argv); + + if (python_argv[0]) + free (python_argv[0]); + if (python_argv[1]) + free (python_argv[1]); + + return ret; +} + +/* + * weechat_python_api_bar_item_new: add a new bar item + */ + +static PyObject * +weechat_python_api_bar_item_new (PyObject *self, PyObject *args) +{ + char *name, *function, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_new"); + PYTHON_RETURN_EMPTY; + } + + name = NULL; + function = NULL; + + if (!PyArg_ParseTuple (args, "ss", &name, &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_new"); + PYTHON_RETURN_EMPTY; + } + + result = script_ptr2str (script_api_bar_item_new (weechat_python_plugin, + python_current_script, + name, + &weechat_python_api_bar_item_build_cb, + function)); + + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_bar_item_update: update a bar item on screen + */ + +static PyObject * +weechat_python_api_bar_item_update (PyObject *self, PyObject *args) +{ + char *name; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_update"); + PYTHON_RETURN_ERROR; + } + + name = NULL; + + if (!PyArg_ParseTuple (args, "s", &name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_update"); + PYTHON_RETURN_ERROR; + } + + weechat_bar_item_update (name); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_bar_item_remove: remove a bar item + */ + +static PyObject * +weechat_python_api_bar_item_remove (PyObject *self, PyObject *args) +{ + char *item; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_remove"); + PYTHON_RETURN_ERROR; + } + + item = NULL; + + if (!PyArg_ParseTuple (args, "s", &item)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_remove"); + PYTHON_RETURN_ERROR; + } + + script_api_bar_item_remove (weechat_python_plugin, + python_current_script, + script_str2ptr (item)); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_bar_search: search a bar + */ + +static PyObject * +weechat_python_api_bar_search (PyObject *self, PyObject *args) +{ + char *name, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_search"); + PYTHON_RETURN_EMPTY; + } + + name = NULL; + + if (!PyArg_ParseTuple (args, "s", &name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_search"); + PYTHON_RETURN_EMPTY; + } + + result = script_ptr2str (weechat_bar_search (name)); + + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_bar_new: add a new bar + */ + +static PyObject * +weechat_python_api_bar_new (PyObject *self, PyObject *args) +{ + char *name, *type, *position, *items, *result; + int size, separator; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_new"); + PYTHON_RETURN_EMPTY; + } + + name = NULL; + type = NULL; + position = NULL; + size = 0; + separator = 0; + items = NULL; + + if (!PyArg_ParseTuple (args, "sssiis", &name, &type, &position, &size, + &separator, &items)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new"); + PYTHON_RETURN_EMPTY; + } + + result = script_ptr2str (weechat_bar_new (name, + type, + position, + size, + separator, + items)); + + PYTHON_RETURN_STRING_FREE(result); +} + +/* + * weechat_python_api_bar_update: update a bar on screen + */ + +static PyObject * +weechat_python_api_bar_update (PyObject *self, PyObject *args) +{ + char *name; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item"); + PYTHON_RETURN_ERROR; + } + + name = NULL; + + if (!PyArg_ParseTuple (args, "s", &name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item"); + PYTHON_RETURN_ERROR; + } + + weechat_bar_update (name); + + PYTHON_RETURN_OK; +} + +/* + * weechat_python_api_bar_remove: remove a bar + */ + +static PyObject * +weechat_python_api_bar_remove (PyObject *self, PyObject *args) +{ + char *bar; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_remove"); + PYTHON_RETURN_ERROR; + } + + bar = NULL; + + if (!PyArg_ParseTuple (args, "s", &bar)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_remove"); + PYTHON_RETURN_ERROR; + } + + weechat_bar_remove (script_str2ptr (bar)); + + PYTHON_RETURN_OK; +} + /* * weechat_python_api_command: send command to server */ @@ -2992,9 +3342,308 @@ weechat_python_api_info_get (PyObject *self, PyObject *args) } value = weechat_info_get (info); + PYTHON_RETURN_STRING(value); } +/* + * weechat_python_api_infolist_get: get list with infos + */ + +static PyObject * +weechat_python_api_infolist_get (PyObject *self, PyObject *args) +{ + char *name, *pointer, *value; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_get"); + PYTHON_RETURN_EMPTY; + } + + name = NULL; + pointer = NULL; + + if (!PyArg_ParseTuple (args, "ss", &name, &pointer)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_get"); + PYTHON_RETURN_EMPTY; + } + + value = script_ptr2str (weechat_infolist_get (name, + script_str2ptr (pointer))); + + PYTHON_RETURN_STRING_FREE(value); +} + +/* + * weechat_python_api_infolist_next: move item pointer to next item in infolist + */ + +static PyObject * +weechat_python_api_infolist_next (PyObject *self, PyObject *args) +{ + char *infolist; + int value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_next"); + PYTHON_RETURN_INT(0); + } + + infolist = NULL; + + if (!PyArg_ParseTuple (args, "s", &infolist)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_next"); + PYTHON_RETURN_INT(0); + } + + value = weechat_infolist_next (script_str2ptr (infolist)); + + PYTHON_RETURN_INT(value); +} + +/* + * weechat_python_api_infolist_prev: move item pointer to previous item in infolist + */ + +static PyObject * +weechat_python_api_infolist_prev (PyObject *self, PyObject *args) +{ + char *infolist; + int value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_prev"); + PYTHON_RETURN_INT(0); + } + + infolist = NULL; + + if (!PyArg_ParseTuple (args, "s", &infolist)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_prev"); + PYTHON_RETURN_INT(0); + } + + value = weechat_infolist_prev (script_str2ptr (infolist)); + + PYTHON_RETURN_INT(value); +} + +/* + * weechat_python_api_infolist_fields: get list of fields for current item of infolist + */ + +static PyObject * +weechat_python_api_infolist_fields (PyObject *self, PyObject *args) +{ + char *infolist, *value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_fields"); + PYTHON_RETURN_EMPTY; + } + + infolist = NULL; + + if (!PyArg_ParseTuple (args, "s", &infolist)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_fields"); + PYTHON_RETURN_EMPTY; + } + + value = weechat_infolist_fields (script_str2ptr (infolist)); + + PYTHON_RETURN_STRING(value); +} + +/* + * weechat_python_api_infolist_integer: get integer value of a variable in infolist + */ + +static PyObject * +weechat_python_api_infolist_integer (PyObject *self, PyObject *args) +{ + char *infolist, *variable; + int value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_integer"); + PYTHON_RETURN_INT(0); + } + + infolist = NULL; + variable = NULL; + + if (!PyArg_ParseTuple (args, "s&", &infolist, &variable)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_integer"); + PYTHON_RETURN_INT(0); + } + + value = weechat_infolist_integer (script_str2ptr (infolist), + variable); + + PYTHON_RETURN_INT(value); +} + +/* + * weechat_python_api_infolist_string: get string value of a variable in infolist + */ + +static PyObject * +weechat_python_api_infolist_string (PyObject *self, PyObject *args) +{ + char *infolist, *variable, *value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_string"); + PYTHON_RETURN_EMPTY; + } + + infolist = NULL; + variable = NULL; + + if (!PyArg_ParseTuple (args, "ss", &infolist, &variable)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_string"); + PYTHON_RETURN_EMPTY; + } + + value = weechat_infolist_string (script_str2ptr (infolist), + variable); + + PYTHON_RETURN_STRING(value); +} + +/* + * weechat_python_api_infolist_pointer: get pointer value of a variable in infolist + */ + +static PyObject * +weechat_python_api_infolist_pointer (PyObject *self, PyObject *args) +{ + char *infolist, *variable, *value; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_pointer"); + PYTHON_RETURN_EMPTY; + } + + infolist = NULL; + variable = NULL; + + if (!PyArg_ParseTuple (args, "ss", &infolist, &variable)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_pointer"); + PYTHON_RETURN_EMPTY; + } + + value = script_ptr2str (weechat_infolist_string (script_str2ptr (infolist), + variable)); + + PYTHON_RETURN_STRING_FREE(value); +} + +/* + * weechat_python_api_infolist_time: get time value of a variable in infolist + */ + +static PyObject * +weechat_python_api_infolist_time (PyObject *self, PyObject *args) +{ + char *infolist, *variable, timebuffer[64], *value; + time_t time; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_time"); + PYTHON_RETURN_EMPTY; + } + + infolist = NULL; + variable = NULL; + + if (!PyArg_ParseTuple (args, "ss", &infolist, &variable)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_time"); + PYTHON_RETURN_EMPTY; + } + + time = weechat_infolist_time (script_str2ptr (infolist), + variable); + strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time)); + value = strdup (timebuffer); + + PYTHON_RETURN_STRING_FREE(value); +} + +/* + * weechat_python_api_infolist_free: free infolist + */ + +static PyObject * +weechat_python_api_infolist_free (PyObject *self, PyObject *args) +{ + char *infolist; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_free"); + PYTHON_RETURN_ERROR; + } + + infolist = NULL; + + if (!PyArg_ParseTuple (args, "s", &infolist)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_free"); + PYTHON_RETURN_ERROR; + } + + weechat_infolist_free (script_str2ptr (infolist)); + + PYTHON_RETURN_OK; +} + /* * Python subroutines */ @@ -3068,7 +3717,24 @@ PyMethodDef weechat_python_funcs[] = { "nicklist_remove_group", &weechat_python_api_nicklist_remove_group, METH_VARARGS, "" }, { "nicklist_remove_nick", &weechat_python_api_nicklist_remove_nick, METH_VARARGS, "" }, { "nicklist_remove_all", &weechat_python_api_nicklist_remove_all, METH_VARARGS, "" }, + { "bar_item_search", &weechat_python_api_bar_item_search, METH_VARARGS, "" }, + { "bar_item_new", &weechat_python_api_bar_item_new, METH_VARARGS, "" }, + { "bar_item_update", &weechat_python_api_bar_item_update, METH_VARARGS, "" }, + { "bar_item_remove", &weechat_python_api_bar_item_remove, METH_VARARGS, "" }, + { "bar_search", &weechat_python_api_bar_search, METH_VARARGS, "" }, + { "bar_new", &weechat_python_api_bar_new, METH_VARARGS, "" }, + { "bar_update", &weechat_python_api_bar_update, METH_VARARGS, "" }, + { "bar_remove", &weechat_python_api_bar_remove, METH_VARARGS, "" }, { "command", &weechat_python_api_command, METH_VARARGS, "" }, { "info_get", &weechat_python_api_info_get, METH_VARARGS, "" }, + { "infolist_get", &weechat_python_api_infolist_get, METH_VARARGS, "" }, + { "infolist_next", &weechat_python_api_infolist_next, METH_VARARGS, "" }, + { "infolist_prev", &weechat_python_api_infolist_prev, METH_VARARGS, "" }, + { "infolist_fields", &weechat_python_api_infolist_fields, METH_VARARGS, "" }, + { "infolist_integer", &weechat_python_api_infolist_integer, METH_VARARGS, "" }, + { "infolist_string", &weechat_python_api_infolist_string, METH_VARARGS, "" }, + { "infolist_pointer", &weechat_python_api_infolist_pointer, METH_VARARGS, "" }, + { "infolist_time", &weechat_python_api_infolist_time, METH_VARARGS, "" }, + { "infolist_free", &weechat_python_api_infolist_free, METH_VARARGS, "" }, { NULL, NULL, 0, NULL } }; diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 8dc1d388f..152e3d5f6 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -202,6 +202,7 @@ weechat_ruby_api_iconv_to_internal (VALUE class, VALUE charset, VALUE string) c_string = STR2CSTR (string); result = weechat_iconv_to_internal (c_charset, c_string); + RUBY_RETURN_STRING_FREE(result); } @@ -241,6 +242,7 @@ weechat_ruby_api_iconv_from_internal (VALUE class, VALUE charset, VALUE string) c_string = STR2CSTR (string); result = weechat_iconv_from_internal (c_charset, c_string); + RUBY_RETURN_STRING_FREE(result); } @@ -275,6 +277,7 @@ weechat_ruby_api_gettext (VALUE class, VALUE string) c_string = STR2CSTR (string); result = weechat_gettext (c_string); + RUBY_RETURN_STRING(result); } @@ -317,6 +320,7 @@ weechat_ruby_api_ngettext (VALUE class, VALUE single, VALUE plural, c_count = FIX2INT (count); result = weechat_ngettext (c_single, c_plural, c_count); + RUBY_RETURN_STRING(result); } @@ -419,6 +423,7 @@ weechat_ruby_api_list_new (VALUE class) } result = script_ptr2str (weechat_list_new ()); + RUBY_RETURN_STRING(result); } @@ -461,6 +466,7 @@ weechat_ruby_api_list_add (VALUE class, VALUE weelist, VALUE data, VALUE where) result = script_ptr2str (weechat_list_add (script_str2ptr(c_weelist), c_data, c_where)); + RUBY_RETURN_STRING(result); } @@ -499,6 +505,7 @@ weechat_ruby_api_list_search (VALUE class, VALUE weelist, VALUE data) result = script_ptr2str (weechat_list_search (script_str2ptr(c_weelist), c_data)); + RUBY_RETURN_STRING(result); } @@ -537,6 +544,7 @@ weechat_ruby_api_list_casesearch (VALUE class, VALUE weelist, VALUE data) result = script_ptr2str (weechat_list_casesearch (script_str2ptr(c_weelist), c_data)); + RUBY_RETURN_STRING(result); } @@ -576,6 +584,7 @@ weechat_ruby_api_list_get (VALUE class, VALUE weelist, VALUE position) result = script_ptr2str (weechat_list_get (script_str2ptr(c_weelist), c_position)); + RUBY_RETURN_STRING(result); } @@ -649,6 +658,7 @@ weechat_ruby_api_list_next (VALUE class, VALUE item) c_item = STR2CSTR (item); result = script_ptr2str (weechat_list_next (script_str2ptr(c_item))); + RUBY_RETURN_STRING(result); } @@ -683,6 +693,7 @@ weechat_ruby_api_list_prev (VALUE class, VALUE item) c_item = STR2CSTR (item); result = script_ptr2str (weechat_list_prev (script_str2ptr(c_item))); + RUBY_RETURN_STRING(result); } @@ -717,6 +728,7 @@ weechat_ruby_api_list_string (VALUE class, VALUE item) c_item = STR2CSTR (item); result = weechat_list_string (script_str2ptr(c_item)); + RUBY_RETURN_STRING(result); } @@ -752,6 +764,7 @@ weechat_ruby_api_list_size (VALUE class, VALUE weelist) c_weelist = STR2CSTR (weelist); size = weechat_list_size (script_str2ptr(c_weelist)); + RUBY_RETURN_INT(size); } @@ -943,6 +956,7 @@ weechat_ruby_api_config_new (VALUE class, VALUE filename, VALUE function) c_filename, &weechat_ruby_api_config_reload_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -1105,6 +1119,7 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file, c_function_write, &weechat_ruby_api_config_section_write_default_cb, c_function_write_default)); + RUBY_RETURN_STRING_FREE(result); } @@ -1145,6 +1160,7 @@ weechat_ruby_api_config_search_section (VALUE class, VALUE config_file, result = script_ptr2str (weechat_config_search_section (script_str2ptr (c_config_file), c_section_name)); + RUBY_RETURN_STRING_FREE(result); } @@ -1254,6 +1270,7 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, c_default_value, &weechat_ruby_api_config_option_change_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -1298,6 +1315,7 @@ weechat_ruby_api_config_search_option (VALUE class, VALUE config_file, result = script_ptr2str (weechat_config_search_option (script_str2ptr (c_config_file), script_str2ptr (c_section), c_option_name)); + RUBY_RETURN_STRING_FREE(result); } @@ -1333,6 +1351,7 @@ weechat_ruby_api_config_string_to_boolean (VALUE class, VALUE text) c_text = STR2CSTR (text); value = weechat_config_string_to_boolean (c_text); + RUBY_RETURN_INT(value); } @@ -1377,6 +1396,7 @@ weechat_ruby_api_config_option_set (VALUE class, VALUE option, VALUE new_value, rc = weechat_config_option_set (script_str2ptr (c_option), c_new_value, c_run_callback); + RUBY_RETURN_INT(rc); } @@ -1412,6 +1432,7 @@ weechat_ruby_api_config_boolean (VALUE class, VALUE option) c_option = STR2CSTR (option); value = weechat_config_boolean (script_str2ptr (c_option)); + RUBY_RETURN_INT(value); } @@ -1447,6 +1468,7 @@ weechat_ruby_api_config_integer (VALUE class, VALUE option) c_option = STR2CSTR (option); value = weechat_config_integer (script_str2ptr (c_option)); + RUBY_RETURN_INT(value); } @@ -1481,6 +1503,7 @@ weechat_ruby_api_config_string (VALUE class, VALUE option) c_option = STR2CSTR (option); value = weechat_config_string (script_str2ptr (c_option)); + RUBY_RETURN_STRING(value); } @@ -1516,6 +1539,7 @@ weechat_ruby_api_config_color (VALUE class, VALUE option) c_option = STR2CSTR (option); value = weechat_config_color (script_str2ptr (c_option)); + RUBY_RETURN_INT(value); } @@ -1596,6 +1620,7 @@ weechat_ruby_api_config_write (VALUE class, VALUE config_file) c_config_file = STR2CSTR (config_file); rc = weechat_config_write (script_str2ptr (c_config_file)); + RUBY_RETURN_INT(rc); } @@ -1631,6 +1656,7 @@ weechat_ruby_api_config_read (VALUE class, VALUE config_file) c_config_file = STR2CSTR (config_file); rc = weechat_config_read (script_str2ptr (c_config_file)); + RUBY_RETURN_INT(rc); } @@ -1666,6 +1692,7 @@ weechat_ruby_api_config_reload (VALUE class, VALUE config_file) c_config_file = STR2CSTR (config_file); rc = weechat_config_reload (script_str2ptr (c_config_file)); + RUBY_RETURN_INT(rc); } @@ -1737,6 +1764,7 @@ weechat_ruby_api_prefix (VALUE class, VALUE prefix) c_prefix = STR2CSTR (prefix); result = weechat_prefix (c_prefix); + RUBY_RETURN_STRING(result); } @@ -1771,6 +1799,7 @@ weechat_ruby_api_color (VALUE class, VALUE color) c_color = STR2CSTR (color); result = weechat_color (c_color); + RUBY_RETURN_STRING(result); } @@ -2031,6 +2060,7 @@ weechat_ruby_api_hook_command (VALUE class, VALUE command, VALUE description, c_completion, &weechat_ruby_api_hook_command_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -2115,6 +2145,7 @@ weechat_ruby_api_hook_timer (VALUE class, VALUE interval, VALUE align_second, c_max_calls, &weechat_ruby_api_hook_timer_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -2203,6 +2234,7 @@ weechat_ruby_api_hook_fd (VALUE class, VALUE fd, VALUE read, VALUE write, c_exception, &weechat_ruby_api_hook_fd_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -2297,6 +2329,7 @@ weechat_ruby_api_hook_print (VALUE class, VALUE buffer, VALUE message, c_strip_colors, &weechat_ruby_api_hook_print_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -2393,6 +2426,7 @@ weechat_ruby_api_hook_signal (VALUE class, VALUE signal, VALUE function) c_signal, &weechat_ruby_api_hook_signal_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -2537,6 +2571,7 @@ weechat_ruby_api_hook_config (VALUE class, VALUE type, VALUE option, c_option, &weechat_ruby_api_hook_config_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -2620,6 +2655,7 @@ weechat_ruby_api_hook_completion (VALUE class, VALUE completion, c_completion, &weechat_ruby_api_hook_completion_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -2686,6 +2722,7 @@ weechat_ruby_api_hook_modifier (VALUE class, VALUE modifier, VALUE function) c_modifier, &weechat_ruby_api_hook_modifier_cb, c_function)); + RUBY_RETURN_STRING_FREE(result); } @@ -2728,6 +2765,7 @@ weechat_ruby_api_hook_modifier_exec (VALUE class, VALUE modifier, c_string = STR2CSTR (string); result = weechat_hook_modifier_exec (c_modifier, c_modifier_data, c_string); + RUBY_RETURN_STRING_FREE(result); } @@ -2909,6 +2947,7 @@ weechat_ruby_api_buffer_new (VALUE class, VALUE category, VALUE name, c_function_input, &weechat_ruby_api_close_cb, c_function_close)); + RUBY_RETURN_STRING_FREE(result); } @@ -2947,6 +2986,7 @@ weechat_ruby_api_buffer_search (VALUE class, VALUE category, VALUE name) c_name = STR2CSTR (name); result = script_ptr2str (weechat_buffer_search (c_category, c_name)); + RUBY_RETURN_STRING_FREE(result); } @@ -3025,6 +3065,7 @@ weechat_ruby_api_buffer_get (VALUE class, VALUE buffer, VALUE property) value = weechat_buffer_get (script_str2ptr (c_buffer), c_property); + RUBY_RETURN_STRING(value); } @@ -3120,6 +3161,7 @@ weechat_ruby_api_nicklist_add_group (VALUE class, VALUE buffer, c_name, c_color, c_visible)); + RUBY_RETURN_STRING_FREE(result); } @@ -3164,6 +3206,7 @@ weechat_ruby_api_nicklist_search_group (VALUE class, VALUE buffer, result = script_ptr2str (weechat_nicklist_search_group (script_str2ptr (c_buffer), script_str2ptr (c_from_group), c_name)); + RUBY_RETURN_STRING_FREE(result); } @@ -3233,6 +3276,7 @@ weechat_ruby_api_nicklist_add_nick (VALUE class, VALUE buffer, VALUE group, char_prefix, c_prefix_color, c_visible)); + RUBY_RETURN_STRING_FREE(result); } @@ -3277,6 +3321,7 @@ weechat_ruby_api_nicklist_search_nick (VALUE class, VALUE buffer, result = script_ptr2str (weechat_nicklist_search_nick (script_str2ptr (c_buffer), script_str2ptr (c_from_group), c_name)); + RUBY_RETURN_STRING_FREE(result); } @@ -3385,6 +3430,349 @@ weechat_ruby_api_nicklist_remove_all (VALUE class, VALUE buffer) RUBY_RETURN_OK; } +/* + * weechat_ruby_api_bar_item_search: search a bar item + */ + +static VALUE +weechat_ruby_api_bar_item_search (VALUE class, VALUE name) +{ + char *c_name, *result; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_search"); + RUBY_RETURN_EMPTY; + } + + c_name = NULL; + + if (NIL_P (name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_search"); + RUBY_RETURN_EMPTY; + } + + Check_Type (name, T_STRING); + + c_name = STR2CSTR (name); + + result = script_ptr2str (weechat_bar_item_search (c_name)); + + RUBY_RETURN_STRING_FREE(result); +} + +/* + * weechat_ruby_api_bar_item_build_cb: callback for building bar item + */ + +char * +weechat_ruby_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width) +{ + struct t_script_callback *script_callback; + char *ruby_argv[4], *ret; + static char buf[32]; + + script_callback = (struct t_script_callback *)data; + + snprintf (buf, sizeof (buf) - 1, "%d", max_width); + + ruby_argv[0] = script_ptr2str (item); + ruby_argv[1] = script_ptr2str (window); + ruby_argv[2] = buf; + ruby_argv[3] = NULL; + + ret = (char *)weechat_ruby_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_STRING, + script_callback->function, + ruby_argv); + + if (ruby_argv[0]) + free (ruby_argv[0]); + if (ruby_argv[1]) + free (ruby_argv[1]); + + return ret; +} + +/* + * weechat_ruby_api_bar_item_new: add a new bar item + */ + +static VALUE +weechat_ruby_api_bar_item_new (VALUE class, VALUE name, VALUE function) +{ + char *c_name, *c_function, *result; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_new"); + RUBY_RETURN_EMPTY; + } + + c_name = NULL; + c_function = NULL; + + if (NIL_P (name) || NIL_P (function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_new"); + RUBY_RETURN_EMPTY; + } + + Check_Type (name, T_STRING); + Check_Type (function, T_STRING); + + c_name = STR2CSTR (name); + c_function = STR2CSTR (function); + + result = script_ptr2str (script_api_bar_item_new (weechat_ruby_plugin, + ruby_current_script, + c_name, + &weechat_ruby_api_bar_item_build_cb, + c_function)); + + RUBY_RETURN_STRING_FREE(result); +} + +/* + * weechat_ruby_api_bar_item_update: update a bar item on screen + */ + +static VALUE +weechat_ruby_api_bar_item_update (VALUE class, VALUE name) +{ + char *c_name; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_update"); + RUBY_RETURN_ERROR; + } + + if (NIL_P (name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_update"); + RUBY_RETURN_ERROR; + } + + Check_Type (name, T_STRING); + + c_name = STR2CSTR (name); + + weechat_bar_item_update (c_name); + + RUBY_RETURN_OK; +} + +/* + * weechat_ruby_api_bar_item_remove: remove a bar item + */ + +static VALUE +weechat_ruby_api_bar_item_remove (VALUE class, VALUE item) +{ + char *c_item; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_item_remove"); + RUBY_RETURN_ERROR; + } + + if (NIL_P (item)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_item_remove"); + RUBY_RETURN_ERROR; + } + + Check_Type (item, T_STRING); + + c_item = STR2CSTR (item); + + script_api_bar_item_remove (weechat_ruby_plugin, + ruby_current_script, + script_str2ptr (c_item)); + + RUBY_RETURN_OK; +} + +/* + * weechat_ruby_api_bar_search: search a bar + */ + +static VALUE +weechat_ruby_api_bar_search (VALUE class, VALUE name) +{ + char *c_name, *result; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_search"); + RUBY_RETURN_EMPTY; + } + + c_name = NULL; + + if (NIL_P (name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_search"); + RUBY_RETURN_EMPTY; + } + + Check_Type (name, T_STRING); + + c_name = STR2CSTR (name); + + result = script_ptr2str (weechat_bar_search (c_name)); + + RUBY_RETURN_STRING_FREE(result); +} + +/* + * weechat_ruby_api_bar_new: add a new bar + */ + +static VALUE +weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE type, VALUE position, + VALUE size, VALUE separator, VALUE items) +{ + char *c_name, *c_type, *c_position, *c_items, *result; + int c_size, c_separator; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_new"); + RUBY_RETURN_EMPTY; + } + + c_name = NULL; + c_type = NULL; + c_position = NULL; + c_size = 0; + c_separator = 0; + c_items = NULL; + + if (NIL_P (name) || NIL_P (type) || NIL_P (position) || NIL_P (size) + || NIL_P (separator) || NIL_P (items)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new"); + RUBY_RETURN_EMPTY; + } + + Check_Type (name, T_STRING); + Check_Type (type, T_STRING); + Check_Type (position, T_STRING); + Check_Type (size, T_FIXNUM); + Check_Type (separator, T_FIXNUM); + Check_Type (items, T_STRING); + + c_name = STR2CSTR (name); + c_type = STR2CSTR (type); + c_position = STR2CSTR (position); + c_size = FIX2INT (size); + c_separator = FIX2INT (separator); + c_items = STR2CSTR (items); + + result = script_ptr2str (weechat_bar_new (c_name, + c_type, + c_position, + c_size, + c_separator, + c_items)); + + RUBY_RETURN_STRING_FREE(result); +} + +/* + * weechat_ruby_api_bar_update: update a bar on screen + */ + +static VALUE +weechat_ruby_api_bar_update (VALUE class, VALUE name) +{ + char *c_name; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_update"); + RUBY_RETURN_ERROR; + } + + if (NIL_P (name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_update"); + RUBY_RETURN_ERROR; + } + + Check_Type (name, T_STRING); + + c_name = STR2CSTR (name); + + weechat_bar_update (c_name); + + RUBY_RETURN_OK; +} + +/* + * weechat_ruby_api_bar_remove: remove a bar + */ + +static VALUE +weechat_ruby_api_bar_remove (VALUE class, VALUE bar) +{ + char *c_bar; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("bar_remove"); + RUBY_RETURN_ERROR; + } + + if (NIL_P (bar)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_remove"); + RUBY_RETURN_ERROR; + } + + Check_Type (bar, T_STRING); + + c_bar = STR2CSTR (bar); + + weechat_bar_remove (script_str2ptr (c_bar)); + + RUBY_RETURN_OK; +} + /* * weechat_ruby_api_command: send command to server */ @@ -3452,9 +3840,326 @@ weechat_ruby_api_info_get (VALUE class, VALUE info) c_info = STR2CSTR (info); value = weechat_info_get (c_info); + RUBY_RETURN_STRING(value); } +/* + * weechat_ruby_api_infolist_get: get list with infos + */ + +static VALUE +weechat_ruby_api_infolist_get (VALUE class, VALUE name, VALUE pointer) +{ + char *c_name, *c_pointer, *value; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_get"); + RUBY_RETURN_EMPTY; + } + + if (NIL_P (name) || NIL_P (pointer)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_get"); + RUBY_RETURN_EMPTY; + } + + Check_Type (name, T_STRING); + Check_Type (pointer, T_STRING); + + c_name = STR2CSTR (name); + c_pointer = STR2CSTR (pointer); + + value = script_ptr2str (weechat_infolist_get (c_name, script_str2ptr (c_pointer))); + + RUBY_RETURN_STRING_FREE(value); +} + +/* + * weechat_ruby_api_infolist_next: move item pointer to next item in infolist + */ + +static VALUE +weechat_ruby_api_infolist_next (VALUE class, VALUE infolist) +{ + char *c_infolist; + int value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_next"); + RUBY_RETURN_INT(0); + } + + if (NIL_P (infolist)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_next"); + RUBY_RETURN_INT(0); + } + + Check_Type (infolist, T_STRING); + + c_infolist = STR2CSTR (infolist); + + value = weechat_infolist_next (script_str2ptr (c_infolist)); + + RUBY_RETURN_INT(value); +} + +/* + * weechat_ruby_api_infolist_prev: move item pointer to previous item in infolist + */ + +static VALUE +weechat_ruby_api_infolist_prev (VALUE class, VALUE infolist) +{ + char *c_infolist; + int value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_prev"); + RUBY_RETURN_INT(0); + } + + if (NIL_P (infolist)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_prev"); + RUBY_RETURN_INT(0); + } + + Check_Type (infolist, T_STRING); + + c_infolist = STR2CSTR (infolist); + + value = weechat_infolist_prev (script_str2ptr (c_infolist)); + + RUBY_RETURN_INT(value); +} + +/* + * weechat_ruby_api_infolist_fields: get list of fields for current item of infolist + */ + +static VALUE +weechat_ruby_api_infolist_fields (VALUE class, VALUE infolist) +{ + char *c_infolist, *value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_fields"); + RUBY_RETURN_EMPTY; + } + + if (NIL_P (infolist)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_fields"); + RUBY_RETURN_EMPTY; + } + + Check_Type (infolist, T_STRING); + + c_infolist = STR2CSTR (infolist); + + value = weechat_infolist_fields (script_str2ptr (c_infolist)); + + RUBY_RETURN_STRING(value); +} + +/* + * weechat_ruby_api_infolist_integer: get integer value of a variable in infolist + */ + +static VALUE +weechat_ruby_api_infolist_integer (VALUE class, VALUE infolist, VALUE variable) +{ + char *c_infolist, *c_variable; + int value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_integer"); + RUBY_RETURN_INT(0); + } + + if (NIL_P (infolist) || NIL_P (variable)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_integer"); + RUBY_RETURN_INT(0); + } + + Check_Type (infolist, T_STRING); + Check_Type (variable, T_STRING); + + c_infolist = STR2CSTR (infolist); + c_variable = STR2CSTR (variable); + + value = weechat_infolist_integer (script_str2ptr (c_infolist), c_variable); + + RUBY_RETURN_INT(value); +} + +/* + * weechat_ruby_api_infolist_string: get string value of a variable in infolist + */ + +static VALUE +weechat_ruby_api_infolist_string (VALUE class, VALUE infolist, VALUE variable) +{ + char *c_infolist, *c_variable, *value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_string"); + RUBY_RETURN_EMPTY; + } + + if (NIL_P (infolist) || NIL_P (variable)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_string"); + RUBY_RETURN_EMPTY; + } + + Check_Type (infolist, T_STRING); + Check_Type (variable, T_STRING); + + c_infolist = STR2CSTR (infolist); + c_variable = STR2CSTR (variable); + + value = weechat_infolist_string (script_str2ptr (c_infolist), c_variable); + + RUBY_RETURN_STRING(value); +} + +/* + * weechat_ruby_api_infolist_pointer: get pointer value of a variable in infolist + */ + +static VALUE +weechat_ruby_api_infolist_pointer (VALUE class, VALUE infolist, VALUE variable) +{ + char *c_infolist, *c_variable, *value; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_pointer"); + RUBY_RETURN_EMPTY; + } + + if (NIL_P (infolist) || NIL_P (variable)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_pointer"); + RUBY_RETURN_EMPTY; + } + + Check_Type (infolist, T_STRING); + Check_Type (variable, T_STRING); + + c_infolist = STR2CSTR (infolist); + c_variable = STR2CSTR (variable); + + value = script_ptr2str (weechat_infolist_pointer (script_str2ptr (c_infolist), c_variable)); + + RUBY_RETURN_STRING_FREE(value); +} + +/* + * weechat_ruby_api_infolist_time: get time value of a variable in infolist + */ + +static VALUE +weechat_ruby_api_infolist_time (VALUE class, VALUE infolist, VALUE variable) +{ + char *c_infolist, *c_variable, timebuffer[64], *value; + time_t time; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_time"); + RUBY_RETURN_EMPTY; + } + + if (NIL_P (infolist) || NIL_P (variable)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_time"); + RUBY_RETURN_EMPTY; + } + + Check_Type (infolist, T_STRING); + Check_Type (variable, T_STRING); + + c_infolist = STR2CSTR (infolist); + c_variable = STR2CSTR (variable); + + time = weechat_infolist_time (script_str2ptr (c_infolist), c_variable); + strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time)); + value = strdup (timebuffer); + + RUBY_RETURN_STRING_FREE(value); +} + +/* + * weechat_ruby_api_infolist_free: free infolist + */ + +static VALUE +weechat_ruby_api_infolist_free (VALUE class, VALUE infolist) +{ + char *c_infolist; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infolist_free"); + RUBY_RETURN_ERROR; + } + + if (NIL_P (infolist)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_free"); + RUBY_RETURN_ERROR; + } + + Check_Type (infolist, T_STRING); + + c_infolist = STR2CSTR (infolist); + + weechat_infolist_free (script_str2ptr (c_infolist)); + + RUBY_RETURN_OK; +} + /* * weechat_ruby_api_init: init Ruby API: add variables and functions */ @@ -3545,6 +4250,23 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "nicklist_remove_group", &weechat_ruby_api_nicklist_remove_group, 2); rb_define_module_function (ruby_mWeechat, "nicklist_remove_nick", &weechat_ruby_api_nicklist_remove_nick, 2); rb_define_module_function (ruby_mWeechat, "nicklist_remove_all", &weechat_ruby_api_nicklist_remove_all, 1); + rb_define_module_function (ruby_mWeechat, "bar_item_search", &weechat_ruby_api_bar_item_search, 1); + rb_define_module_function (ruby_mWeechat, "bar_item_new", &weechat_ruby_api_bar_item_new, 2); + rb_define_module_function (ruby_mWeechat, "bar_item_update", &weechat_ruby_api_bar_item_update, 1); + rb_define_module_function (ruby_mWeechat, "bar_item_remove", &weechat_ruby_api_bar_item_remove, 1); + rb_define_module_function (ruby_mWeechat, "bar_search", &weechat_ruby_api_bar_search, 1); + rb_define_module_function (ruby_mWeechat, "bar_new", &weechat_ruby_api_bar_new, 6); + rb_define_module_function (ruby_mWeechat, "bar_update", &weechat_ruby_api_bar_update, 1); + rb_define_module_function (ruby_mWeechat, "bar_remove", &weechat_ruby_api_bar_remove, 1); rb_define_module_function (ruby_mWeechat, "command", &weechat_ruby_api_command, 2); rb_define_module_function (ruby_mWeechat, "info_get", &weechat_ruby_api_info_get, 1); + rb_define_module_function (ruby_mWeechat, "infolist_get", &weechat_ruby_api_infolist_get, 2); + rb_define_module_function (ruby_mWeechat, "infolist_next", &weechat_ruby_api_infolist_next, 1); + rb_define_module_function (ruby_mWeechat, "infolist_prev", &weechat_ruby_api_infolist_prev, 1); + rb_define_module_function (ruby_mWeechat, "infolist_fields", &weechat_ruby_api_infolist_fields, 1); + rb_define_module_function (ruby_mWeechat, "infolist_integer", &weechat_ruby_api_infolist_integer, 2); + rb_define_module_function (ruby_mWeechat, "infolist_string", &weechat_ruby_api_infolist_string, 2); + rb_define_module_function (ruby_mWeechat, "infolist_pointer", &weechat_ruby_api_infolist_pointer, 2); + rb_define_module_function (ruby_mWeechat, "infolist_time", &weechat_ruby_api_infolist_time, 2); + rb_define_module_function (ruby_mWeechat, "infolist_free", &weechat_ruby_api_infolist_free, 1); } diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index e3bc57056..ebb73ba15 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -814,6 +814,71 @@ script_api_buffer_close (struct t_weechat_plugin *weechat_plugin, } } +/* + * script_api_bar_item_new: add a new bar item + */ + +struct t_gui_bar_item * +script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + char *name, + char *(*build_callback)(void *data, + struct t_gui_bar_item *item, + struct t_gui_window *window, + int remaining_space), + char *function_build) +{ + struct t_script_callback *new_script_callback; + struct t_gui_bar_item *new_item; + + new_script_callback = script_callback_alloc (); + if (!new_script_callback) + return NULL; + + new_item = weechat_bar_item_new (name, + (function_build && function_build[0]) ? + build_callback : NULL, + (function_build && function_build[0]) ? + new_script_callback : NULL); + if (!new_item) + { + free (new_script_callback); + return NULL; + } + + new_script_callback->script = script; + new_script_callback->function = (function_build && function_build[0]) ? + strdup (function_build) : NULL; + new_script_callback->bar_item = new_item; + script_callback_add (script, new_script_callback); + + return new_item; +} + +/* + * script_api_bar_item_remove: remove a bar item + */ + +void +script_api_bar_item_remove (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_gui_bar_item *item) +{ + struct t_script_callback *ptr_script_callback; + + if (!weechat_plugin || !script || !item) + return; + + weechat_bar_item_remove (item); + + for (ptr_script_callback = script->callbacks; ptr_script_callback; + ptr_script_callback = ptr_script_callback->next_callback) + { + if (ptr_script_callback->bar_item == item) + script_callback_remove (script, ptr_script_callback); + } +} + /* * script_api_command: execute a command (simulate user entry) */ diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index 2081d9c99..5a7177bf6 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -151,6 +151,17 @@ extern void script_api_buffer_close (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, struct t_gui_buffer *buffer, int switch_to_another); +extern struct t_gui_bar_item *script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + char *name, + char *(*build_callback)(void *data, + struct t_gui_bar_item *item, + struct t_gui_window *window, + int remaining_space), + char *function_build); +extern void script_api_bar_item_remove (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + struct t_gui_bar_item *item); extern void script_api_command (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, struct t_gui_buffer *buffer, diff --git a/src/plugins/scripts/script-callback.c b/src/plugins/scripts/script-callback.c index 18b7039b7..537375820 100644 --- a/src/plugins/scripts/script-callback.c +++ b/src/plugins/scripts/script-callback.c @@ -46,6 +46,7 @@ script_callback_alloc () new_script_callback->config_option = NULL; new_script_callback->hook = NULL; new_script_callback->buffer = NULL; + new_script_callback->bar_item = NULL; return new_script_callback; } @@ -85,7 +86,7 @@ script_callback_remove (struct t_plugin_script *script, if (script->callbacks == script_callback) script->callbacks = script_callback->next_callback; - /* unhook and free data */ + /* free data */ if (script_callback->function) free (script_callback->function); @@ -117,8 +118,12 @@ script_callback_print_log (struct t_weechat_plugin *weechat_plugin, weechat_log_printf ("[callback (addr:0x%x)]", script_callback); weechat_log_printf (" script. . . . . . . : 0x%x", script_callback->script); weechat_log_printf (" function. . . . . . : '%s'", script_callback->function); + weechat_log_printf (" config_file . . . . : '%s'", script_callback->config_file); + weechat_log_printf (" config_section. . . : '%s'", script_callback->config_section); + weechat_log_printf (" config_option . . . : '%s'", script_callback->config_option); weechat_log_printf (" hook. . . . . . . . : 0x%x", script_callback->hook); weechat_log_printf (" buffer. . . . . . . : 0x%x", script_callback->buffer); + weechat_log_printf (" bar_item. . . . . . : 0x%x", script_callback->bar_item); weechat_log_printf (" prev_callback . . . : 0x%x", script_callback->prev_callback); weechat_log_printf (" next_callback . . . : 0x%x", script_callback->next_callback); } diff --git a/src/plugins/scripts/script-callback.h b/src/plugins/scripts/script-callback.h index 0ca67806b..a9db3db49 100644 --- a/src/plugins/scripts/script-callback.h +++ b/src/plugins/scripts/script-callback.h @@ -27,7 +27,8 @@ struct t_script_callback struct t_config_section *config_section; /* not NULL for config section */ struct t_config_option *config_option; /* not NULL for config option */ struct t_hook *hook; /* not NULL for hook */ - struct t_gui_buffer *buffer; /* not NULL for buffer callback*/ + struct t_gui_buffer *buffer; /* not NULL for buffer */ + struct t_gui_bar_item *bar_item; /* not NULL for bar item */ struct t_script_callback *prev_callback; /* link to next callback */ struct t_script_callback *next_callback; /* link to previous callback */ }; diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index 242132e7a..fb28a46b5 100644 --- a/src/plugins/scripts/script.c +++ b/src/plugins/scripts/script.c @@ -416,10 +416,12 @@ script_remove (struct t_weechat_plugin *weechat_plugin, for (ptr_script_callback = script->callbacks; ptr_script_callback; ptr_script_callback = ptr_script_callback->next_callback) { + /* unhook */ if (ptr_script_callback->hook) { weechat_unhook (ptr_script_callback->hook); } + /* free config file */ if (ptr_script_callback->config_file && !ptr_script_callback->config_section && !ptr_script_callback->config_option) @@ -428,6 +430,9 @@ script_remove (struct t_weechat_plugin *weechat_plugin, weechat_config_write (ptr_script_callback->config_file); weechat_config_free (ptr_script_callback->config_file); } + /* remove bar item */ + if (ptr_script_callback->bar_item) + weechat_bar_item_remove (ptr_script_callback->bar_item); } /* remove all callbacks created by this script */ diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 2e76818d9..e0c278623 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -23,7 +23,10 @@ #include +struct t_gui_window; struct t_gui_buffer; +struct t_gui_bar; +struct t_gui_bar_item; struct t_weelist; /* macros for defining plugin infos */ @@ -319,6 +322,24 @@ struct t_weechat_plugin struct t_gui_nick *nick); void (*nicklist_remove_all) (struct t_gui_buffer *buffer); + /* bars */ + struct t_gui_bar_item *(*bar_item_search) (char *name); + struct t_gui_bar_item *(*bar_item_new) (struct t_weechat_plugin *plugin, + char *name, + char *(*build_callback)(void *data, + struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width), + void *build_callback_data); + void (*bar_item_update) (char *name); + void (*bar_item_remove) (struct t_gui_bar_item *item); + struct t_gui_bar *(*bar_search) (char *name); + struct t_gui_bar *(*bar_new) (struct t_weechat_plugin *plugin, char *name, + char *type, char *position, int size, + int separator, char *items); + void (*bar_update) (char *name); + void (*bar_remove) (struct t_gui_bar *bar); + /* command */ void (*command) (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, char *command); @@ -629,6 +650,27 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); #define weechat_nicklist_remove_all(__buffer) \ weechat_plugin->nicklist_remove_all(__buffer) +/* bars */ +#define weechat_bar_item_search(__name) \ + weechat_plugin->bar_item_search(__name) +#define weechat_bar_item_new(__name, __build_callback, __data) \ + weechat_plugin->bar_item_new(weechat_plugin, __name, \ + __build_callback, __data) +#define weechat_bar_item_update(__name) \ + weechat_plugin->bar_item_update(__name) +#define weechat_bar_item_remove(__item) \ + weechat_plugin->bar_item_remove(__item) +#define weechat_bar_search(__name) \ + weechat_plugin->bar_search(__name) +#define weechat_bar_new(__name, __type, __position, __size, \ + __separator, __items) \ + weechat_plugin->bar_new(weechat_plugin, __name, __type, __position, \ + __size, __separator, __items) +#define weechat_bar_update(__name) \ + weechat_plugin->bar_update(__name) +#define weechat_bar_remove(__bar) \ + weechat_plugin->bar_remove(__bar) + /* command */ #define weechat_command(__buffer, __command) \ weechat_plugin->command(weechat_plugin, __buffer, __command)