2023-10-19 17:49:54 +02:00
|
|
|
;; tinmop: a multiprotocol client
|
2023-10-19 17:46:22 +02:00
|
|
|
;; Copyright © cage
|
2020-05-08 15:45:43 +02:00
|
|
|
|
|
|
|
;; 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(in-package :sending-message)
|
|
|
|
|
2023-11-14 23:06:44 +01:00
|
|
|
(define-constant +header-send-window-height+ 6 :test #'=)
|
2020-05-08 15:45:43 +02:00
|
|
|
|
|
|
|
(defclass message-ready-to-send ()
|
2023-09-13 15:00:31 +02:00
|
|
|
((language
|
|
|
|
:initform nil
|
|
|
|
:initarg :language
|
|
|
|
:accessor language)
|
|
|
|
(subject
|
2020-05-08 15:45:43 +02:00
|
|
|
:initform nil
|
|
|
|
:initarg :subject
|
|
|
|
:accessor subject)
|
|
|
|
(attachments
|
|
|
|
:initform ()
|
|
|
|
:initarg :attachments
|
|
|
|
:accessor attachments)
|
|
|
|
(reply-to
|
|
|
|
:initform ()
|
|
|
|
:initarg :reply-to
|
|
|
|
:accessor reply-to
|
|
|
|
:documentation "The id of table 'status' you are replying to.")
|
2020-09-18 16:32:04 +02:00
|
|
|
(mentions
|
|
|
|
:initform ""
|
|
|
|
:initarg :mentions
|
|
|
|
:accessor mentions)
|
2020-05-08 15:45:43 +02:00
|
|
|
(visibility
|
|
|
|
:initform +status-public-visibility+
|
|
|
|
:initarg :visibility
|
|
|
|
:accessor visibility
|
|
|
|
:documentation "One of swconf:*allowed-status-visibility*.")
|
|
|
|
(body
|
|
|
|
:initform nil
|
|
|
|
:initarg :body
|
|
|
|
:accessor body)))
|
|
|
|
|
|
|
|
(defmethod print-object ((object message-ready-to-send) stream)
|
|
|
|
(print-unreadable-object (object stream :type t)
|
|
|
|
(with-accessors ((subject subject)
|
|
|
|
(attachments attachments)
|
|
|
|
(reply-to reply-to)
|
|
|
|
(body body)) object
|
|
|
|
(format stream
|
|
|
|
"~@[subj: ~a ~] ~@[reply-to: ~a ~] ~@[attach: ~a ~] ~a"
|
|
|
|
subject reply-to attachments body))))
|
|
|
|
|
|
|
|
(defclass confirm-sending-window (focus-marked-window simple-line-navigation-window)
|
|
|
|
((screen
|
|
|
|
:initarg :screen
|
|
|
|
:initform nil
|
|
|
|
:accessor screen)
|
|
|
|
(message-data
|
|
|
|
:initarg :message-data
|
|
|
|
:initform (make-instance 'message-ready-to-send)
|
|
|
|
:accessor message-data
|
|
|
|
:type message-ready-to-send)
|
|
|
|
(style
|
|
|
|
:initarg :style
|
|
|
|
:initform nil
|
|
|
|
:accessor style)))
|
|
|
|
|
|
|
|
(defmethod refresh-config :after ((object confirm-sending-window))
|
|
|
|
(with-accessors ((screen screen)
|
|
|
|
(croatoan-window croatoan-window)
|
|
|
|
(bgcolor bgcolor)
|
|
|
|
(fgcolor fgcolor)
|
|
|
|
(top-row-padding top-row-padding)
|
|
|
|
(style style)) object
|
|
|
|
(let* ((theme-style (swconf:form-style swconf:+key-input-dialog+))
|
|
|
|
(fg (swconf:foreground theme-style))
|
|
|
|
(bg (swconf:background theme-style))
|
|
|
|
(width (truncate (/ (win-width screen)
|
|
|
|
2)))
|
|
|
|
(height (truncate (/ (win-height screen)
|
|
|
|
2)))
|
|
|
|
(y (truncate (- (/ (win-height screen) 2)
|
|
|
|
(/ height 2))))
|
|
|
|
(x (truncate (- (/ (win-width screen) 2)
|
|
|
|
(/ width 2))))
|
|
|
|
(attach-y-start +header-send-window-height+))
|
2022-03-21 21:42:50 +01:00
|
|
|
(setf (c:background croatoan-window) (tui:make-win-background bg))
|
|
|
|
(setf (c:bgcolor croatoan-window) bg)
|
|
|
|
(setf (c:fgcolor croatoan-window) fg)
|
2020-05-08 15:45:43 +02:00
|
|
|
(setf style theme-style)
|
|
|
|
(win-resize object width height)
|
|
|
|
(win-move object x y)
|
|
|
|
(setf (top-row-padding object) attach-y-start)
|
|
|
|
object)))
|
|
|
|
|
|
|
|
(defmethod draw :after ((object confirm-sending-window))
|
|
|
|
(with-accessors ((message-data message-data)
|
|
|
|
(style style)) object
|
|
|
|
(with-accessors ((reply-to reply-to)
|
|
|
|
(attachments attachments)
|
|
|
|
(body body)
|
|
|
|
(subject subject)
|
2020-09-18 16:32:04 +02:00
|
|
|
(mentions mentions)
|
2023-09-13 15:00:31 +02:00
|
|
|
(visibility visibility)
|
|
|
|
(language language)) message-data
|
2020-05-08 15:45:43 +02:00
|
|
|
(with-croatoan-window (croatoan-window object)
|
2022-03-21 21:42:50 +01:00
|
|
|
(let* ((bgcolor (c:bgcolor croatoan-window))
|
|
|
|
(fgcolor (c:fgcolor croatoan-window))
|
2020-05-08 15:45:43 +02:00
|
|
|
(input-bg (swconf:input-background style))
|
|
|
|
(input-fg (swconf:input-foreground style))
|
|
|
|
(user (if reply-to
|
|
|
|
(db:status-id->username reply-to)
|
|
|
|
(_ "none")))
|
|
|
|
(label-reply-raw (_ "Reply to: "))
|
2020-09-18 16:32:04 +02:00
|
|
|
(label-mentions-raw (_ "Mentions: "))
|
|
|
|
(label-subject-raw (_ "Subject: "))
|
|
|
|
(label-visibility-raw (_ "Visibility: "))
|
2023-09-13 15:00:31 +02:00
|
|
|
(label-language-raw (_ "Language: "))
|
2020-05-08 15:45:43 +02:00
|
|
|
(label-reply-length-raw (length label-reply-raw))
|
2022-12-08 19:23:41 +01:00
|
|
|
(label-mentions-length-raw (length label-mentions-raw))
|
2020-05-08 15:45:43 +02:00
|
|
|
(label-subject-raw-length (length label-subject-raw))
|
|
|
|
(label-visibility-raw-length (length label-visibility-raw))
|
2023-09-13 15:00:31 +02:00
|
|
|
(label-language-raw-length (length label-language-raw))
|
2020-05-08 15:45:43 +02:00
|
|
|
(max-field-length (max label-reply-length-raw
|
2020-09-18 16:32:04 +02:00
|
|
|
label-mentions-length-raw
|
2020-05-08 15:45:43 +02:00
|
|
|
label-subject-raw-length
|
2023-09-13 15:00:31 +02:00
|
|
|
label-visibility-raw-length
|
|
|
|
label-language-raw-length))
|
2020-05-08 15:45:43 +02:00
|
|
|
(label-subject (text-utils:right-padding label-subject-raw
|
|
|
|
max-field-length))
|
|
|
|
(label-reply (text-utils:right-padding label-reply-raw
|
|
|
|
max-field-length))
|
2020-09-18 16:32:04 +02:00
|
|
|
(label-mentions (text-utils:right-padding label-mentions-raw
|
|
|
|
max-field-length))
|
2020-05-08 15:45:43 +02:00
|
|
|
(label-visibility (text-utils:right-padding label-visibility-raw
|
|
|
|
max-field-length))
|
2023-09-13 15:00:31 +02:00
|
|
|
(label-language (text-utils:right-padding label-language-raw
|
|
|
|
max-field-length))
|
2020-05-08 15:45:43 +02:00
|
|
|
(value-max-length (- (win-width-no-border object)
|
|
|
|
max-field-length))
|
|
|
|
(label-attachments (_ "Attachments")))
|
|
|
|
(flet ((print-field (text x y bg fg &key (inverse nil))
|
|
|
|
(print-text object text x y
|
|
|
|
:bgcolor (if inverse
|
|
|
|
fg
|
|
|
|
bg)
|
|
|
|
:fgcolor (if inverse
|
|
|
|
bg
|
|
|
|
fg))))
|
|
|
|
(print-field label-reply 1 1 bgcolor fgcolor)
|
|
|
|
(print-field (right-padding user
|
|
|
|
value-max-length)
|
|
|
|
max-field-length
|
|
|
|
1
|
|
|
|
input-bg input-fg)
|
2020-09-18 16:32:04 +02:00
|
|
|
(print-field label-mentions 1 2 bgcolor fgcolor)
|
|
|
|
(print-field (right-padding mentions
|
2020-05-08 15:45:43 +02:00
|
|
|
value-max-length)
|
|
|
|
max-field-length
|
|
|
|
2
|
|
|
|
input-bg input-fg)
|
2020-09-18 16:32:04 +02:00
|
|
|
(print-field label-subject 1 3 bgcolor fgcolor)
|
|
|
|
(print-field (right-padding subject
|
2020-05-08 15:45:43 +02:00
|
|
|
value-max-length)
|
|
|
|
max-field-length
|
|
|
|
3
|
|
|
|
input-bg input-fg)
|
2020-09-18 16:32:04 +02:00
|
|
|
(print-field label-visibility 1 4 bgcolor fgcolor)
|
|
|
|
(print-field (right-padding visibility
|
|
|
|
value-max-length)
|
|
|
|
max-field-length
|
|
|
|
4
|
|
|
|
input-bg input-fg)
|
2023-09-13 15:00:31 +02:00
|
|
|
(print-field label-language 1 5 bgcolor fgcolor)
|
|
|
|
(print-field (right-padding language
|
|
|
|
value-max-length)
|
|
|
|
max-field-length
|
|
|
|
5
|
|
|
|
input-bg input-fg)
|
2020-08-14 20:15:30 +02:00
|
|
|
(print-field (right-padding (text-ellipsis label-attachments
|
|
|
|
(win-width-no-border object))
|
2020-05-08 15:45:43 +02:00
|
|
|
(win-width-no-border object))
|
|
|
|
1
|
2023-09-13 15:00:31 +02:00
|
|
|
6
|
2020-05-08 15:45:43 +02:00
|
|
|
bgcolor fgcolor
|
|
|
|
:inverse t)))))))
|
|
|
|
|
|
|
|
(defun init (message-data screen)
|
|
|
|
(flet ((make-rows (data bg fg)
|
|
|
|
(mapcar #'(lambda (a)
|
|
|
|
(make-instance 'line
|
|
|
|
:normal-text a
|
|
|
|
:selected-text a
|
|
|
|
:normal-bg bg
|
|
|
|
:normal-fg fg
|
|
|
|
:selected-bg fg
|
|
|
|
:selected-fg bg))
|
|
|
|
data)))
|
|
|
|
(let* ((low-level-window (make-croatoan-window :enable-function-keys t)))
|
|
|
|
(setf *send-message-window*
|
|
|
|
(make-instance 'confirm-sending-window
|
|
|
|
:uses-border-p t
|
|
|
|
:screen screen
|
|
|
|
:keybindings keybindings:*send-message-keymap*
|
|
|
|
:croatoan-window low-level-window
|
|
|
|
:message-data message-data))
|
|
|
|
(refresh-config *send-message-window*)
|
2021-04-08 15:13:31 +02:00
|
|
|
(line-oriented-window:update-all-rows *send-message-window*
|
|
|
|
(make-rows (attachments message-data)
|
2022-03-21 21:42:50 +01:00
|
|
|
(c:bgcolor low-level-window)
|
|
|
|
(c:fgcolor low-level-window)))
|
2020-05-08 15:45:43 +02:00
|
|
|
(setf (row-selected-index *send-message-window*) 0)
|
|
|
|
*send-message-window*)))
|