about summary refs log tree commit diff stats
path: root/src/command/cmd_defs.c
diff options
context:
space:
mode:
authorMarouane L <techmetx11@disroot.org>2022-09-06 17:29:07 +0100
committerMarouane L <techmetx11@disroot.org>2022-10-18 23:24:30 +0100
commitf934c5b59f2fe2c3c00a50135add4aec55ac4024 (patch)
tree730d135fb92cb15b68717da1f5248c8bc6525019 /src/command/cmd_defs.c
parentfc8455ba34fdb467cc2702e4e071e850eaaf9be7 (diff)
downloadprofani-tty-f934c5b59f2fe2c3c00a50135add4aec55ac4024.tar.gz
Add vCard support
Only nicknames, photos, birthdays, addresses, telephone numbers, emails,
JIDs, titles, roles, notes, and URLs are supported

Due to the synopsis array not having enough space, `/vcard photo
open-self` and `/vcard photo save-self` are not documented properly in
the synopsis section of the `/vcard` command, but they are documented in
the arguments section

Fixed memory leak in vcard autocomplete (thanks to debXwoody)
Diffstat (limited to 'src/command/cmd_defs.c')
-rw-r--r--src/command/cmd_defs.c136
1 files changed, 131 insertions, 5 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 91346fce..4263ac22 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -1268,7 +1268,8 @@ static struct cmd_t command_defs[] = {
               "/time all|console|chat|muc|config|private|xml off",
               "/time statusbar set <format>",
               "/time statusbar off",
-              "/time lastactivity set <format>")
+              "/time lastactivity set <format>",
+              "/time vcard set <format>")
       CMD_DESC(
               "Configure time display preferences. "
               "Time formats are strings supported by g_date_time_format. "
@@ -1291,7 +1292,8 @@ static struct cmd_t command_defs[] = {
               { "statusbar set <format>", "Change time format in statusbar." },
               { "statusbar off", "Do not show time in status bar." },
               { "lastactivity set <format>", "Change time format for last activity." },
-              { "all set <format>", "Set time for: console, chat, muc, config, private and xml windows." },
+              { "vcard set <format>", "Change the time format used to display time/dates in vCard (such as birthdays)" },
+              { "all set <format>", "Set time for: console, chat, muc, config, private, and xml windows." },
               { "all off", "Do not show time for: console, chat, muc, config, private and xml windows." })
       CMD_EXAMPLES(
               "/time console set %H:%M:%S",
@@ -1582,6 +1584,124 @@ static struct cmd_t command_defs[] = {
               "/autoconnect off")
     },
 
+    { "/vcard",
+      parse_args, 0, 7, NULL,
+      CMD_SUBFUNCS(
+              {"add", cmd_vcard_add},
+              {"remove", cmd_vcard_remove},
+              {"get", cmd_vcard_get},
+              {"set", cmd_vcard_set},
+              {"photo", cmd_vcard_photo},
+              {"refresh", cmd_vcard_refresh},
+              {"save", cmd_vcard_save})
+      CMD_MAINFUNC(cmd_vcard)
+      CMD_TAGS(
+              CMD_TAG_CHAT,
+              CMD_TAG_GROUPCHAT)
+      CMD_SYN(
+              "/vcard get [<nick|contact>]",
+              "/vcard photo open <nick|contact> [<index>]",
+              "/vcard photo save <nick|contact> [output <filepath>] [index <index>]",
+              "/vcard set fullname <fullname>",
+              "/vcard set name family <family>",
+              "/vcard set name given <given>",
+              "/vcard set name middle <middle>",
+              "/vcard set name prefix <prefix>",
+              "/vcard set name suffix <suffix>",
+              "/vcard set <index> [<value>]",
+              "/vcard set <index> pobox <value>",
+              "/vcard set <index> extaddr <value>",
+              "/vcard set <index> street <value>",
+              "/vcard set <index> locality <value>",
+              "/vcard set <index> region <value>",
+              "/vcard set <index> pocode <value>",
+              "/vcard set <index> country <value>",
+              "/vcard set <index> type domestic|international",
+              "/vcard set <index> home on|off",
+              "/vcard set <index> work on|off",
+              "/vcard set <index> voice on|off",
+              "/vcard set <index> fax on|off",
+              "/vcard set <index> pager on|off",
+              "/vcard set <index> msg on|off",
+              "/vcard set <index> cell on|off",
+              "/vcard set <index> video on|off",
+              "/vcard set <index> bbs on|off",
+              "/vcard set <index> modem on|off",
+              "/vcard set <index> isdn on|off",
+              "/vcard set <index> pcs on|off",
+              "/vcard set <index> preferred on|off",
+              "/vcard set <index> parcel on|off",
+              "/vcard set <index> postal on|off",
+              "/vcard set <index> internet on|off",
+              "/vcard set <index> x400 on|off",
+              "/vcard add nickname <nickname>",
+              "/vcard add birthday <date>",
+              "/vcard add address",
+              "/vcard add tel <number>",
+              "/vcard add email <userid>",
+              "/vcard add jid <jid>",
+              "/vcard add title <title>",
+              "/vcard add role <role>",
+              "/vcard add note <note>",
+              "/vcard add url <url>",
+              "/vcard remove <index>",
+              "/vcard refresh",
+              "/vcard save")
+      CMD_DESC(
+              "Read your vCard or a user's vCard, get a user's avatar via their vCard, or modify your vCard. If no arguments are given, your vCard will be displayed in a new window, or an existing vCard window.")
+      CMD_ARGS(
+              { "get [<nick|contact>]", "Get your vCard, if a nickname/contact is provided, get that user's vCard" },
+              { "photo open <nick|contact> [<index>]", "Download a user's photo from their vCard to a file, and open it. If index is not specified, download the first photo (usually avatar) from their vCard" },
+              { "photo save <nick|contact>", "Download a user's photo from their vCard to a file. If index is not specified, download the first photo (usually avatar) from their vCard. If output is not specified, download the photo to profanity's photos directory." },
+              { "photo open-self [<index>]", "Download a photo from your vCard to a file, and open it. If index is not specified, download the first photo (usually avatar) from your vCard" },
+              { "photo save-self", "Download a photo from your vCard to a file. If index is not specified, download the first photo (usually avatar) from your vCard. If output is not specified, download the photo to profanity's photos directory. Same arguments as `photo open`" },
+              { "set fullname <fullname>", "Set your vCard's fullname to the specified value" },
+              { "set name family <family>", "Set your vCard's family name to the specified value" },
+              { "set name given <given>", "Set your vCard's given name to the specified value" },
+              { "set name middle <middle>", "Set your vCard's middle name to the specified value" },
+              { "set name prefix <prefix>", "Set your vCard's prefix name to the specified value" },
+              { "set name suffix <suffix>", "Set your vCard's suffix name to the specified value" },
+              { "set <index> [<value>]", "Set the main field in a element in your vCard to the specified value, or if no value was specified, modify the field in an editor, This only works in elements that have one field." },
+              { "set <index> pobox <value>", "Set the P.O. box in an address element in your vCard to the specified value." },
+              { "set <index> extaddr <value>", "Set the extended address in an address element in your vCard to the specified value." },
+              { "set <index> street <value>", "Set the street in an address element in your vCard to the specified value." },
+              { "set <index> locality <value>", "Set the locality in an address element in your vCard to the specified value." },
+              { "set <index> region <value>", "Set the region in an address element in your vCard to the specified value." },
+              { "set <index> pocode <value>", "Set the P.O. code in an address element in your vCard to the specified value." },
+              { "set <index> type domestic|international", "Set the type in an address element in your vCard to either domestic or international." },
+              { "set <index> home on|off", "Set the home option in an element in your vCard. (address, telephone, e-mail only)" },
+              { "set <index> work on|off", "Set the work option in an element in your vCard. (address, telephone, e-mail only)" },
+              { "set <index> voice on|off", "Set the voice option in a telephone element in your vCard." },
+              { "set <index> fax on|off", "Set the fax option in a telephone element in your vCard." },
+              { "set <index> pager on|off", "Set the pager option in a telephone element in your vCard." },
+              { "set <index> msg on|off", "Set the message option in a telephone element in your vCard." },
+              { "set <index> cell on|off", "Set the cellphone option in a telephone element in your vCard." },
+              { "set <index> video on|off", "Set the video option in a telephone element in your vCard." },
+              { "set <index> bbs on|off", "Set the BBS option in a telephone element in your vCard." },
+              { "set <index> modem on|off", "Set the modem option in a telephone element in your vCard." },
+              { "set <index> isdn on|off", "Set the ISDN option in a telephone element in your vCard." },
+              { "set <index> pcs on|off", "Set the PCS option in a telephone element in your vCard." },
+              { "set <index> preferred on|off", "Set the preferred option in an element in your vCard. (address, telephone, e-mail only)" },
+              { "set <index> parcel on|off", "Set the parcel option in an address element in your vCard." },
+              { "set <index> postal on|off", "Set the postal option in an address element in your vCard." },
+              { "set <index> internet on|off", "Set the internet option in an e-mail address in your vCard." },
+              { "set <index> x400 on|off", "Set the X400 option in an e-mail address in your vCard." },
+              { "add nickname <nickname>", "Add a nickname to your vCard" },
+              { "add birthday <date>", "Add a birthday date to your vCard" },
+              { "add address", "Add an address to your vCard" },
+              { "add tel <number>", "Add a telephone number to your vCard" },
+              { "add email <userid>", "Add an e-mail address to your vCard" },
+              { "add jid <jid>", "Add a Jabber ID to your vCard" },
+              { "add title <title>", "Add a title to your vCard" },
+              { "add role <role>", "Add a role to your vCard" },
+              { "add note <note>", "Add a note to your vCard" },
+              { "add url <url>", "Add a URL to your vCard" },
+              { "remove <index>", "Remove a element in your vCard by index" },
+              { "refresh", "Refreshes the local copy of the current account's vCard (undoes all your unpublished modifications)" },
+              { "save", "Save changes to the server" })
+      CMD_NOEXAMPLES
+    },
+
     { "/vercheck",
       parse_args, 0, 1, NULL,
       CMD_NOSUBFUNCS
@@ -2559,7 +2679,8 @@ static struct cmd_t command_defs[] = {
               { "avatar",  cmd_executable_avatar },
               { "urlopen", cmd_executable_urlopen },
               { "urlsave", cmd_executable_urlsave },
-              { "editor", cmd_executable_editor })
+              { "editor", cmd_executable_editor },
+              { "vcard_photo", cmd_executable_vcard_photo })
       CMD_NOMAINFUNC
       CMD_TAGS(
               CMD_TAG_DISCOVERY)
@@ -2568,7 +2689,9 @@ static struct cmd_t command_defs[] = {
               "/executable urlopen set <cmdtemplate>",
               "/executable urlopen default",
               "/executable urlsave set <cmdtemplate>",
-              "/executable urlsave default")
+              "/executable urlsave default",
+              "/executable vcard_photo set <cmdtemplate>",
+              "/executable vcard_photo default")
       CMD_DESC(
               "Configure executable that should be called upon a certain command.")
       CMD_ARGS(
@@ -2577,7 +2700,9 @@ static struct cmd_t command_defs[] = {
               { "urlopen default", "Restore to default settings." },
               { "urlsave set", "Set executable that is run by /url save. Takes a command template that replaces %u and %p with the URL and path respectively." },
               { "urlsave default", "Use the built-in download method for saving." },
-              { "editor set", "Set editor to be used with /editor. Needs a terminal editor or a script to run a graphical editor." })
+              { "editor set", "Set editor to be used with /editor. Needs a terminal editor or a script to run a graphical editor." },
+              { "vcard_photo set", "Set executable that is run by /vcard photo open. Takes a command template that replaces %p with the path" },
+              { "vcard_photo default", "Restore to default settings." })
       CMD_EXAMPLES(
               "/executable avatar xdg-open",
               "/executable urlopen set \"xdg-open %u\"",
@@ -2586,6 +2711,7 @@ static struct cmd_t command_defs[] = {
               "/executable urlsave set \"wget %u -O %p\"",
               "/executable urlsave set \"curl %u -o %p\"",
               "/executable urlsave default",
+              "/executable vcard_photo set \"feh %p\"",
               "/executable editor set vim")
     },