Warning, /plasma-mobile/raven/src/contents/ui/FolderView.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
0003 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0004 
0005 import QtQuick 2.15
0006 import QtQuick.Layouts 1.15
0007 import QtQuick.Controls 2.15 as QQC2
0008 
0009 import org.kde.raven 1.0
0010 import org.kde.kirigami 2.19 as Kirigami
0011 import org.kde.kitemmodels 1.0 as KItemModels
0012 
0013 Kirigami.ScrollablePage {
0014     id: folderView
0015     title: MailManager.selectedFolderName
0016     
0017     Component {
0018         id: contextMenu
0019         QQC2.Menu {
0020             property int row
0021             property var status
0022 
0023             QQC2.Menu {
0024                 title: i18nc("@action:menu", "Mark Message")
0025                 QQC2.MenuItem {
0026                     text: i18n("Mark Message as Read")
0027                 }
0028                 QQC2.MenuItem {
0029                     text: i18n("Mark Message as Unread")
0030                 }
0031 
0032                 QQC2.MenuSeparator {}
0033 
0034                 QQC2.MenuItem {
0035                     text: status.isImportant ? i18n("Don't Mark as Important") : i18n("Mark as Important")
0036                 }
0037             }
0038 
0039             QQC2.MenuItem {
0040                 icon.name: 'delete'
0041                 text: i18n("Move to trash")
0042             }
0043 
0044             QQC2.MenuItem {
0045                 icon.name: 'edit-move'
0046                 text: i18n("Move Message to...")
0047             }
0048 
0049             QQC2.MenuItem {
0050                 icon.name: 'edit-copy'
0051                 text: i18n("Copy Message to...")
0052             }
0053 
0054             QQC2.MenuItem {
0055                 icon.name: 'edit-copy'
0056                 text: i18n("Add Followup Reminder")
0057             }
0058         }
0059     }
0060 
0061     ListView {
0062         id: mails
0063         model: MailManager.folderModel
0064         currentIndex: -1
0065         
0066         Connections {
0067             target: MailManager
0068             
0069             function onFolderModelChanged() {
0070                 mails.currentIndex = -1;
0071             }
0072         }
0073         
0074         Kirigami.PlaceholderMessage {
0075             id: mailboxSelected
0076             anchors.centerIn: parent
0077             visible: MailManager.selectedFolderName === ""
0078             text: i18n("No mailbox selected")
0079             explanation: i18n("Select a mailbox from the sidebar.")
0080             icon.name: "mail-unread"
0081         }
0082         
0083         Kirigami.PlaceholderMessage {
0084             anchors.centerIn: parent
0085             visible: mails.count === 0 && !mailboxSelected.visible
0086             text: i18n("Mailbox is empty")
0087             icon.name: "mail-folder-inbox"
0088         }
0089         
0090         delegate: MailDelegate {
0091             showSeparator: model.index !== folderView.count - 1
0092             
0093             datetime: model.datetime.toLocaleTimeString(Qt.locale(), Locale.ShortFormat) // TODO this is not showing date !
0094             author: model.from
0095             title: model.title
0096             contentPreview: "This is a test of the message content........." // model.content
0097             
0098             isRead: !model.status || model.status.isRead
0099             
0100             onOpenMailRequested: {
0101                 applicationWindow().pageStack.push(Qt.resolvedUrl('ConversationViewer.qml'), {
0102                     item: model.item,
0103                     props: model,
0104                 });
0105 
0106                 if (!model.status.isRead) {
0107                     const status = MailManager.folderModel.copyMessageStatus(model.status);
0108                     status.isRead = true;
0109                     MailManager.folderModel.updateMessageStatus(index, status)
0110                 }
0111             }
0112             
0113             onStarMailRequested: {
0114                 const status = MailManager.folderModel.copyMessageStatus(model.status);
0115                 status.isImportant = !status.isImportant;
0116                 MailManager.folderModel.updateMessageStatus(index, status)
0117             }
0118             
0119             onContextMenuRequested: {
0120                 const menu = contextMenu.createObject(folderView, {
0121                     row: index,
0122                     status: MailManager.folderModel.copyMessageStatus(model.status),
0123                 });
0124                 menu.popup();
0125             }
0126         }
0127     }
0128 }
0129