File indexing completed on 2025-11-02 03:43:14
0001 /* 0002 File : DatabaseManagerDialog.cc 0003 Project : LabPlot 0004 Description : dialog for managing database connections 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2016-2019 Alexander Semke <alexander.semke@web.de> 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "DatabaseManagerDialog.h" 0011 #include "DatabaseManagerWidget.h" 0012 #include "backend/core/Settings.h" 0013 0014 #include <KLocalizedString> 0015 0016 #include <KWindowConfig> 0017 0018 #include <QDialogButtonBox> 0019 #include <QWindow> 0020 0021 /*! 0022 \class DatabaseManagerDialog 0023 \brief dialog for managing database connections 0024 0025 \ingroup kdefrontend 0026 */ 0027 DatabaseManagerDialog::DatabaseManagerDialog(QWidget* parent, const QString& conn) 0028 : QDialog(parent) 0029 , mainWidget(new DatabaseManagerWidget(this, conn)) { 0030 setWindowIcon(QIcon::fromTheme(QStringLiteral("network-server-database"))); 0031 setWindowTitle(i18nc("@title:window", "SQL Database Connections")); 0032 0033 auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0034 0035 auto* layout = new QVBoxLayout(this); 0036 layout->addWidget(mainWidget); 0037 layout->addWidget(buttonBox); 0038 0039 connect(mainWidget, &DatabaseManagerWidget::changed, this, &DatabaseManagerDialog::changed); 0040 connect(buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &DatabaseManagerDialog::save); 0041 connect(buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &DatabaseManagerDialog::close); 0042 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0043 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0044 0045 // restore saved settings if available 0046 create(); // ensure there's a window created 0047 KConfigGroup conf = Settings::group(QStringLiteral("DatabaseManagerDialog")); 0048 if (conf.exists()) { 0049 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0050 resize(windowHandle()->size()); // workaround for QTBUG-40584 0051 } else 0052 resize(QSize(0, 0).expandedTo(minimumSize())); 0053 } 0054 0055 QString DatabaseManagerDialog::connection() const { 0056 return mainWidget->connection(); 0057 } 0058 0059 DatabaseManagerDialog::~DatabaseManagerDialog() { 0060 // save current settings 0061 KConfigGroup conf = Settings::group(QStringLiteral("DatabaseManagerDialog")); 0062 KWindowConfig::saveWindowSize(windowHandle(), conf); 0063 } 0064 0065 void DatabaseManagerDialog::changed() { 0066 setWindowTitle(i18nc("@title:window", "SQL Database Connections [Changed]")); 0067 m_changed = true; 0068 } 0069 0070 void DatabaseManagerDialog::save() { 0071 // ok-button was clicked, save the connections if they were changed 0072 if (m_changed) 0073 mainWidget->saveConnections(); 0074 }