File indexing completed on 2024-12-08 04:34:20
0001 /* 0002 SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "directorydialog.h" 0008 #include "directorytabwidget.h" 0009 #include "rocketchataccount.h" 0010 0011 #include <KConfigGroup> 0012 #include <KLocalizedString> 0013 #include <KSharedConfig> 0014 #include <KWindowConfig> 0015 #include <QDialogButtonBox> 0016 #include <QVBoxLayout> 0017 #include <QWindow> 0018 0019 namespace 0020 { 0021 const char myDirectoryDialog[] = "DirectoryDialog"; 0022 } 0023 DirectoryDialog::DirectoryDialog(RocketChatAccount *account, QWidget *parent) 0024 : QDialog(parent) 0025 , mDirectoryTabWidget(new DirectoryTabWidget(account, this)) 0026 { 0027 setWindowTitle(i18nc("@title:window", "Directory - %1", account ? account->accountName() : QStringLiteral("account"))); 0028 auto mainLayout = new QVBoxLayout(this); 0029 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0030 0031 mDirectoryTabWidget->setObjectName(QStringLiteral("mDirectoryTabWidget")); 0032 mainLayout->addWidget(mDirectoryTabWidget); 0033 0034 auto button = new QDialogButtonBox(QDialogButtonBox::Close, this); 0035 button->setObjectName(QStringLiteral("button")); 0036 mainLayout->addWidget(button); 0037 connect(button, &QDialogButtonBox::rejected, this, &DirectoryDialog::reject); 0038 connect(button, &QDialogButtonBox::accepted, this, &DirectoryDialog::accept); 0039 0040 readConfig(); 0041 setAttribute(Qt::WA_DeleteOnClose); 0042 } 0043 0044 DirectoryDialog::~DirectoryDialog() 0045 { 0046 writeConfig(); 0047 } 0048 0049 void DirectoryDialog::fillTabs() 0050 { 0051 mDirectoryTabWidget->fillTabs(); 0052 } 0053 0054 void DirectoryDialog::readConfig() 0055 { 0056 create(); // ensure a window is created 0057 resize(QSize(1024, 768)); 0058 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myDirectoryDialog)); 0059 KWindowConfig::restoreWindowSize(windowHandle(), group); 0060 resize(windowHandle()->size()); // workaround for QTBUG-40584 0061 } 0062 0063 void DirectoryDialog::writeConfig() 0064 { 0065 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myDirectoryDialog)); 0066 KWindowConfig::saveWindowSize(windowHandle(), group); 0067 } 0068 0069 #include "moc_directorydialog.cpp"