File indexing completed on 2024-05-12 15:27:45
0001 /*************************************************************************** 0002 File : DatabaseManagerDialog.cc 0003 Project : LabPlot 0004 Description : dialog for managing database connections 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2016-2019 Alexander Semke (alexander.semke@web.de) 0007 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 0029 #include "DatabaseManagerDialog.h" 0030 #include "DatabaseManagerWidget.h" 0031 0032 #include <KLocalizedString> 0033 #include <KSharedConfig> 0034 #include <KWindowConfig> 0035 0036 #include <QDialogButtonBox> 0037 #include <QWindow> 0038 0039 /*! 0040 \class DatabaseManagerDialog 0041 \brief dialog for managing database connections 0042 0043 \ingroup kdefrontend 0044 */ 0045 DatabaseManagerDialog::DatabaseManagerDialog(QWidget* parent, const QString& conn) : QDialog(parent), 0046 mainWidget(new DatabaseManagerWidget(this, conn)) { 0047 0048 setWindowIcon(QIcon::fromTheme("network-server-database")); 0049 setWindowTitle(i18nc("@title:window", "SQL Database Connections")); 0050 0051 auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0052 0053 auto* layout = new QVBoxLayout(this); 0054 layout->addWidget(mainWidget); 0055 layout->addWidget(buttonBox); 0056 0057 connect(mainWidget, &DatabaseManagerWidget::changed, this, &DatabaseManagerDialog::changed); 0058 connect(buttonBox->button(QDialogButtonBox::Ok),&QPushButton::clicked, this, &DatabaseManagerDialog::save); 0059 connect(buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &DatabaseManagerDialog::close); 0060 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0061 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0062 0063 //restore saved settings if available 0064 create(); // ensure there's a window created 0065 KConfigGroup conf(KSharedConfig::openConfig(), "DatabaseManagerDialog"); 0066 if (conf.exists()) { 0067 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0068 resize(windowHandle()->size()); // workaround for QTBUG-40584 0069 } else 0070 resize(QSize(0, 0).expandedTo(minimumSize())); 0071 } 0072 0073 QString DatabaseManagerDialog::connection() const { 0074 return mainWidget->connection(); 0075 } 0076 0077 DatabaseManagerDialog::~DatabaseManagerDialog() { 0078 //save current settings 0079 KConfigGroup conf(KSharedConfig::openConfig(), "DatabaseManagerDialog"); 0080 KWindowConfig::saveWindowSize(windowHandle(), conf); 0081 } 0082 0083 void DatabaseManagerDialog::changed() { 0084 setWindowTitle(i18nc("@title:window", "SQL Database Connections [Changed]")); 0085 m_changed = true; 0086 } 0087 0088 void DatabaseManagerDialog::save() { 0089 //ok-button was clicked, save the connections if they were changed 0090 if (m_changed) 0091 mainWidget->saveConnections(); 0092 }