File indexing completed on 2024-11-17 04:45:09
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 0006 */ 0007 0008 #include "serverinfodialog.h" 0009 #include "imapresource.h" 0010 0011 #include <KConfigGroup> 0012 #include <KLocalizedString> 0013 #include <KSharedConfig> 0014 #include <KWindowConfig> 0015 #include <QDialogButtonBox> 0016 #include <QPainter> 0017 #include <QPushButton> 0018 #include <QVBoxLayout> 0019 #include <QWindow> 0020 0021 namespace 0022 { 0023 static const char myServerInfoDialogConfigGroupName[] = "ServerInfoDialog"; 0024 } 0025 ServerInfoDialog::ServerInfoDialog(ImapResourceBase *parentResource, QWidget *parent) 0026 : QDialog(parent) 0027 , mTextBrowser(new ServerInfoTextBrowser(this)) 0028 { 0029 setWindowTitle(i18nc("@title:window Dialog title for dialog showing information about a server", "Server Info")); 0030 auto mainLayout = new QVBoxLayout(this); 0031 setAttribute(Qt::WA_DeleteOnClose); 0032 0033 mTextBrowser->setPlainText(parentResource->serverCapabilities().join(QLatin1Char('\n'))); 0034 mainLayout->addWidget(mTextBrowser); 0035 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this); 0036 connect(buttonBox, &QDialogButtonBox::accepted, this, &ServerInfoDialog::accept); 0037 connect(buttonBox, &QDialogButtonBox::rejected, this, &ServerInfoDialog::reject); 0038 mainLayout->addWidget(buttonBox); 0039 readConfig(); 0040 } 0041 0042 ServerInfoDialog::~ServerInfoDialog() 0043 { 0044 writeConfig(); 0045 } 0046 0047 void ServerInfoDialog::writeConfig() 0048 { 0049 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myServerInfoDialogConfigGroupName)); 0050 KWindowConfig::saveWindowSize(windowHandle(), group); 0051 } 0052 0053 void ServerInfoDialog::readConfig() 0054 { 0055 create(); // ensure a window is created 0056 windowHandle()->resize(QSize(500, 300)); 0057 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myServerInfoDialogConfigGroupName)); 0058 KWindowConfig::restoreWindowSize(windowHandle(), group); 0059 resize(windowHandle()->size()); // workaround for QTBUG-40584 0060 } 0061 0062 ServerInfoTextBrowser::ServerInfoTextBrowser(QWidget *parent) 0063 : QTextBrowser(parent) 0064 { 0065 } 0066 0067 ServerInfoTextBrowser::~ServerInfoTextBrowser() = default; 0068 0069 void ServerInfoTextBrowser::paintEvent(QPaintEvent *event) 0070 { 0071 if (document()->isEmpty()) { 0072 QPainter p(viewport()); 0073 0074 QFont font = p.font(); 0075 font.setItalic(true); 0076 p.setFont(font); 0077 0078 const QPalette palette = viewport()->palette(); 0079 QColor color = palette.text().color(); 0080 color.setAlpha(128); 0081 p.setPen(color); 0082 0083 p.drawText(QRect(0, 0, width(), height()), Qt::AlignCenter, i18n("Resource not synchronized yet.")); 0084 } else { 0085 QTextBrowser::paintEvent(event); 0086 } 0087 } 0088 0089 #include "moc_serverinfodialog.cpp"