File indexing completed on 2024-04-21 15:42:50

0001 /***************************************************************************
0002     Private helper class(es) for the profile manager.
0003                              -------------------
0004     begin                : Mi Aug 12 2014
0005     copyright            : (C) 2014-2019 by Alexander Reinholdt
0006     email                : alexander.reinholdt@kdemail.net
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *   This program is free software; you can redistribute it and/or modify  *
0011  *   it under the terms of the GNU General Public License as published by  *
0012  *   the Free Software Foundation; either version 2 of the License, or     *
0013  *   (at your option) any later version.                                   *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful, but   *
0016  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
0018  *   General Public License for more details.                              *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program; if not, write to the                         *
0022  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
0023  *   MA 02110-1335, USA                                                    *
0024  ***************************************************************************/
0025 
0026 #ifdef HAVE_CONFIG_H
0027 #include <config.h>
0028 #endif
0029 
0030 // application specific includes
0031 #include "smb4kprofilemanager_p.h"
0032 #include "smb4ksettings.h"
0033 
0034 // Qt includes
0035 #include <QVBoxLayout>
0036 #include <QHBoxLayout>
0037 #include <QGridLayout>
0038 #include <QLabel>
0039 #include <QDialogButtonBox>
0040 #include <QPixmap>
0041 #include <QWindow>
0042 
0043 // KDE includes
0044 #define TRANSLATION_DOMAIN "smb4k-core"
0045 #include <KI18n/KLocalizedString>
0046 #include <KIconThemes/KIconLoader>
0047 #include <KConfigGui/KWindowConfig>
0048 
0049 
0050 Smb4KProfileMigrationDialog::Smb4KProfileMigrationDialog(const QStringList& from, const QStringList& to, QWidget* parent)
0051 : QDialog(parent), m_from_list(from), m_to_list(to)
0052 {
0053   //
0054   // Set the window title
0055   // 
0056   setWindowTitle(i18n("Profile Migration Assistant"));
0057   
0058   //
0059   // Setup the view
0060   // 
0061   setupView();
0062   
0063   //
0064   // Set the dialog size
0065   // 
0066   create();
0067 
0068   KConfigGroup group(Smb4KSettings::self()->config(), "ProfileMigrationDialog");
0069   QSize dialogSize;
0070   
0071   if (group.exists())
0072   {
0073     KWindowConfig::restoreWindowSize(windowHandle(), group);
0074     dialogSize = windowHandle()->size();
0075   }
0076   else
0077   {
0078     dialogSize = sizeHint();
0079   }
0080   
0081   resize(dialogSize); // workaround for QTBUG-40584
0082 }
0083 
0084 
0085 Smb4KProfileMigrationDialog::~Smb4KProfileMigrationDialog()
0086 {
0087 }
0088 
0089 
0090 void Smb4KProfileMigrationDialog::setupView()
0091 {
0092   //
0093   // The layout
0094   // 
0095   QVBoxLayout *layout = new QVBoxLayout(this);
0096   layout->setSpacing(5);
0097   
0098   // 
0099   // The description
0100   // 
0101   QWidget *description = new QWidget(this);
0102 
0103   QHBoxLayout *desc_layout = new QHBoxLayout(description);
0104   desc_layout->setSpacing(5);
0105   desc_layout->setMargin(0);
0106 
0107   QLabel *pixmap = new QLabel(description);
0108   QPixmap pix = KDE::icon("format-list-unordered").pixmap(KIconLoader::SizeHuge);
0109   pixmap->setPixmap(pix);
0110   pixmap->setAlignment(Qt::AlignBottom);
0111 
0112   QLabel *label = new QLabel(i18n("Migrate all relevant settings of one profile to another."));
0113   label->setWordWrap(true);
0114   label->setAlignment(Qt::AlignBottom);
0115 
0116   desc_layout->addWidget(pixmap, 0);
0117   desc_layout->addWidget(label, Qt::AlignBottom);
0118   
0119   //
0120   // The input widgets
0121   // 
0122   QWidget *editors = new QWidget(this);
0123   
0124   QGridLayout *editors_layout = new QGridLayout(editors);
0125   editors_layout->setSpacing(5);
0126   editors_layout->setMargin(0);
0127   editors_layout->setColumnStretch(0, 0);
0128   editors_layout->setColumnStretch(1, 1);
0129   
0130   QLabel *from = new QLabel(i18n("Old Profile:"), editors);
0131   editors_layout->addWidget(from, 0, 0, 0);
0132   
0133   m_from_box = new KComboBox(editors);
0134   
0135   if (m_from_list.size() == 1 && m_from_list.first().isEmpty())
0136   {
0137     m_from_box->addItem(i18n("<Default Profile>"));
0138   }
0139   else
0140   {
0141     if (m_to_list.size() == 1 && m_to_list.first().isEmpty())
0142     {
0143       m_from_box->addItem(i18n("<All Profiles>"));
0144     }
0145     else
0146     {
0147       m_from_box->addItems(m_from_list);
0148     }
0149   }
0150   
0151   editors_layout->addWidget(m_from_box, 0, 1, 0);
0152   
0153   QLabel *to = new QLabel(i18n("New Profile:"), editors);
0154   editors_layout->addWidget(to, 1, 0, 0);
0155   
0156   m_to_box = new KComboBox(editors);
0157   
0158   if (m_to_list.size() == 1 && m_to_list.first().isEmpty())
0159   {
0160     m_to_box->addItem(i18n("<Default Profile>"));
0161   }
0162   else
0163   {
0164     m_to_box->addItems(m_to_list);
0165     m_to_box->setCurrentText(Smb4KProfileManager::self()->activeProfile());
0166   }
0167   
0168   editors_layout->addWidget(m_to_box, 1, 1, 0);
0169   
0170   QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
0171   m_ok_button = buttonBox->addButton(QDialogButtonBox::Ok);
0172   m_cancel_button = buttonBox->addButton(QDialogButtonBox::Cancel);
0173   
0174   m_ok_button->setShortcut(Qt::CTRL|Qt::Key_Return);
0175   m_cancel_button->setShortcut(Qt::Key_Escape);
0176   
0177   m_ok_button->setDefault(true);
0178   m_ok_button->setEnabled(!m_to_box->currentText().isEmpty());
0179   
0180   layout->addWidget(description, 0);
0181   layout->addWidget(editors, 0);
0182   layout->addWidget(buttonBox, 0);
0183   
0184   connect(m_ok_button, SIGNAL(clicked()), this, SLOT(slotOkClicked()));
0185   connect(m_cancel_button, SIGNAL(clicked()), this, SLOT(reject()));
0186 }
0187 
0188 
0189 QString Smb4KProfileMigrationDialog::from() const
0190 {
0191   if (m_from_box->currentText() == i18n("<Default Profile>"))
0192   {
0193     return QString();
0194   }
0195   
0196   return m_from_box->currentText();
0197 }
0198 
0199 
0200 QString Smb4KProfileMigrationDialog::to() const
0201 {
0202   if (m_to_box->currentText() == i18n("<Default Profile>"))
0203   {
0204     return QString();
0205   }
0206   
0207   return m_to_box->currentText();
0208 }
0209 
0210 
0211 void Smb4KProfileMigrationDialog::slotOkClicked()
0212 {
0213   KConfigGroup group(Smb4KSettings::self()->config(), "ProfileMigrationDialog");
0214   KWindowConfig::saveWindowSize(windowHandle(), group);
0215   accept();
0216 }
0217