File indexing completed on 2024-04-28 16:44:27

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org>
0003    SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org>
0004 
0005    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
0006 */
0007 
0008 // Own
0009 #include "newtypedlg.h"
0010 
0011 // Qt
0012 #include <QComboBox>
0013 #include <QDialogButtonBox>
0014 #include <QFormLayout>
0015 #include <QLabel>
0016 
0017 // KDE
0018 #include <klineedit.h>
0019 #include <klocalizedstring.h>
0020 
0021 NewTypeDialog::NewTypeDialog(const QStringList &groups, QWidget *parent)
0022     : QDialog(parent)
0023 {
0024     setModal(true);
0025     setWindowTitle(i18n("Create New File Type"));
0026 
0027     QVBoxLayout *mainLayout = new QVBoxLayout(this);
0028     QFormLayout *formLayout = new QFormLayout;
0029 
0030     QLabel *l = new QLabel(i18n("Group:"));
0031 
0032     m_groupCombo = new QComboBox;
0033     m_groupCombo->setEditable(true);
0034     m_groupCombo->addItems(groups);
0035     m_groupCombo->setCurrentIndex(m_groupCombo->findText(QStringLiteral("application"))); // certainly a better default than "all"
0036     formLayout->addRow(l, m_groupCombo);
0037 
0038     m_groupCombo->setWhatsThis(
0039         i18n("Select the category under which"
0040              " the new file type should be added."));
0041 
0042     // Line 1: mimetype name
0043 
0044     l = new QLabel(i18n("Type name:"));
0045 
0046     m_typeEd = new KLineEdit;
0047     formLayout->addRow(l, m_typeEd);
0048 
0049     m_typeEd->setWhatsThis(
0050         i18n("Type the name of the file type. For instance, if you selected 'image' as category and you type 'custom' here, the file type 'image/custom' will "
0051              "be created."));
0052 
0053     m_typeEd->setFocus();
0054 
0055     m_buttonBox = new QDialogButtonBox;
0056     m_buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0057 
0058     mainLayout->addLayout(formLayout);
0059     mainLayout->addWidget(m_buttonBox);
0060 
0061     connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0062     connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0063 
0064     // Set a minimum width so that caption is not half-hidden
0065     setMinimumWidth(300);
0066 }
0067 
0068 QString NewTypeDialog::group() const
0069 {
0070     return m_groupCombo->currentText();
0071 }
0072 
0073 QString NewTypeDialog::text() const
0074 {
0075     return m_typeEd->text();
0076 }