File indexing completed on 2024-12-01 04:37:05
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 "teamsearchroomdialog.h" 0008 #include "teamsearchroomwidget.h" 0009 0010 #include <KConfigGroup> 0011 #include <KLocalizedString> 0012 #include <KSharedConfig> 0013 #include <KWindowConfig> 0014 #include <QDialogButtonBox> 0015 #include <QVBoxLayout> 0016 #include <QWindow> 0017 namespace 0018 { 0019 const char myTeamSearchRoomDialogConfigGroupName[] = "TeamSearchRoomDialog"; 0020 } 0021 TeamSearchRoomDialog::TeamSearchRoomDialog(RocketChatAccount *account, QWidget *parent) 0022 : QDialog(parent) 0023 , mTeamSearchRoomWidget(new TeamSearchRoomWidget(account, this)) 0024 { 0025 setWindowTitle(i18nc("@title:window", "Search Rooms")); 0026 auto mainLayout = new QVBoxLayout(this); 0027 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0028 0029 mTeamSearchRoomWidget->setObjectName(QStringLiteral("mTeamSearchRoomWidget")); 0030 mainLayout->addWidget(mTeamSearchRoomWidget); 0031 0032 auto button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0033 button->setObjectName(QStringLiteral("button")); 0034 mainLayout->addWidget(button); 0035 connect(button, &QDialogButtonBox::rejected, this, &TeamSearchRoomDialog::reject); 0036 connect(button, &QDialogButtonBox::accepted, this, &TeamSearchRoomDialog::accept); 0037 readConfig(); 0038 } 0039 0040 TeamSearchRoomDialog::~TeamSearchRoomDialog() 0041 { 0042 writeConfig(); 0043 } 0044 0045 QStringList TeamSearchRoomDialog::roomIds() const 0046 { 0047 return mTeamSearchRoomWidget->roomIds(); 0048 } 0049 0050 void TeamSearchRoomDialog::readConfig() 0051 { 0052 create(); // ensure a window is created 0053 windowHandle()->resize(QSize(400, 300)); 0054 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myTeamSearchRoomDialogConfigGroupName)); 0055 KWindowConfig::restoreWindowSize(windowHandle(), group); 0056 resize(windowHandle()->size()); // workaround for QTBUG-40584 0057 } 0058 0059 void TeamSearchRoomDialog::writeConfig() 0060 { 0061 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myTeamSearchRoomDialogConfigGroupName)); 0062 KWindowConfig::saveWindowSize(windowHandle(), group); 0063 } 0064 0065 #include "moc_teamsearchroomdialog.cpp"