File indexing completed on 2024-12-22 05:00:57
0001 /* 0002 This file is part of KTnef. 0003 0004 SPDX-FileCopyrightText: 2003 Michael Goffioul <kdeprint@swing.be> 0005 SPDX-FileCopyrightText: 2012 Allen Winter <winter@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 0009 You should have received a copy of the GNU General Public License 0010 along with this program; if not, write to the Free Software Foundation, 0011 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 0012 */ 0013 0014 #include "messagepropertydialog.h" 0015 #include "attachpropertydialog.h" 0016 0017 #include <KTNEF/KTNEFMessage> 0018 0019 #include <KLocalizedString> 0020 #include <KStandardGuiItem> 0021 0022 #include <KConfigGroup> 0023 #include <KGuiItem> 0024 #include <KSharedConfig> 0025 #include <KWindowConfig> 0026 #include <QDialogButtonBox> 0027 #include <QHeaderView> 0028 #include <QPushButton> 0029 #include <QTreeWidget> 0030 #include <QWindow> 0031 namespace 0032 { 0033 static const char myMessagePropertyDialogGroupName[] = "MessagePropertyDialog"; 0034 } 0035 0036 MessagePropertyDialog::MessagePropertyDialog(QWidget *parent, KTNEFMessage *msg) 0037 : QDialog(parent) 0038 , mMessage(msg) 0039 , mListView(new QTreeWidget(this)) 0040 { 0041 auto mainLayout = new QVBoxLayout(this); 0042 setWindowTitle(i18nc("@title:window", "Message Properties")); 0043 mainLayout->addWidget(mListView); 0044 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0045 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0046 okButton->setDefault(true); 0047 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0048 connect(buttonBox, &QDialogButtonBox::accepted, this, &MessagePropertyDialog::accept); 0049 connect(buttonBox, &QDialogButtonBox::rejected, this, &MessagePropertyDialog::reject); 0050 mainLayout->addWidget(buttonBox); 0051 auto user1Button = new QPushButton; 0052 buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole); 0053 connect(user1Button, &QPushButton::clicked, this, &MessagePropertyDialog::slotSaveProperty); 0054 0055 const QStringList headerLabels = (QStringList(i18nc("@title:column property name", "Name")) << i18nc("@title:column property value", "Value")); 0056 mListView->setHeaderLabels(headerLabels); 0057 mListView->setAllColumnsShowFocus(true); 0058 mListView->setWordWrap(true); 0059 mListView->setAllColumnsShowFocus(true); 0060 mListView->setRootIsDecorated(false); 0061 0062 KGuiItem::assign(user1Button, KStandardGuiItem::save()); 0063 AttachPropertyDialog::formatPropertySet(mMessage, mListView); 0064 readConfig(); 0065 } 0066 0067 MessagePropertyDialog::~MessagePropertyDialog() 0068 { 0069 writeConfig(); 0070 } 0071 0072 void MessagePropertyDialog::slotSaveProperty() 0073 { 0074 AttachPropertyDialog::saveProperty(mListView, mMessage, this); 0075 } 0076 0077 void MessagePropertyDialog::readConfig() 0078 { 0079 create(); // ensure a window is created 0080 windowHandle()->resize(QSize(600, 400)); 0081 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myMessagePropertyDialogGroupName)); 0082 KWindowConfig::restoreWindowSize(windowHandle(), group); 0083 resize(windowHandle()->size()); // workaround for QTBUG-40584 0084 const QByteArray headerState = group.readEntry("HeaderState", QByteArray()); 0085 if (!headerState.isEmpty()) { 0086 mListView->header()->restoreState(headerState); 0087 } 0088 } 0089 0090 void MessagePropertyDialog::writeConfig() 0091 { 0092 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myMessagePropertyDialogGroupName)); 0093 KWindowConfig::saveWindowSize(windowHandle(), group); 0094 group.writeEntry("HeaderState", mListView->header()->saveState()); 0095 group.sync(); 0096 } 0097 0098 #include "moc_messagepropertydialog.cpp"