File indexing completed on 2024-06-16 11:34:31

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #include "programmerdlg.h"
0012 #include "ktlconfig.h"
0013 #include "language.h"
0014 #include "microselectwidget.h"
0015 #include "picprogrammer.h"
0016 #include "port.h"
0017 #include "ui_programmerwidget.h"
0018 
0019 #include <QComboBox>
0020 #include <QDialogButtonBox>
0021 #include <QPushButton>
0022 #include <QVBoxLayout>
0023 
0024 #include <KLocalizedString>
0025 
0026 class ProgrammerWidget : public QWidget, public Ui::ProgrammerWidget
0027 {
0028 public:
0029     ProgrammerWidget(QWidget *parent)
0030         : QWidget(parent)
0031     {
0032         setupUi(this);
0033     }
0034 };
0035 
0036 ProgrammerDlg::ProgrammerDlg(const QString &picID, QWidget *parent)
0037     : QDialog(parent)
0038 {
0039     setModal(true);
0040     setWindowTitle(i18n("PIC Programmer"));
0041 
0042     QVBoxLayout *mainLayout = new QVBoxLayout;
0043     setLayout(mainLayout);
0044 
0045     m_pProgrammerWidget = new ProgrammerWidget(this);
0046     m_pProgrammerSettings = new PicProgrammerSettings;
0047 
0048     // Setup the list of programmers
0049     QComboBox *programmerCombo = m_pProgrammerWidget->m_pProgrammerProgram;
0050     QStringList programmerNames = m_pProgrammerSettings->configNames(false);
0051     programmerCombo->insertItems(programmerCombo->count(), programmerNames);
0052     // programmerCombo->setSizeLimit( programmerNames.size() );
0053     programmerCombo->setMaxCount(programmerNames.size());
0054     // programmerCombo->setCurrentText( KTLConfig::picProgrammerProgram() ); // 2018.12.07
0055     {
0056         QComboBox *c = programmerCombo;
0057         QString text = KTLConfig::picProgrammerProgram();
0058         int i = c->findText(text);
0059         if (i != -1)
0060             c->setCurrentIndex(i);
0061         else if (c->isEditable())
0062             c->setEditText(text);
0063         else
0064             c->setItemText(c->currentIndex(), text);
0065     }
0066     // Sets up the list of ports
0067     m_pProgrammerWidget->m_pPicProgrammerPort->insertItems(m_pProgrammerWidget->m_pPicProgrammerPort->count(), Port::ports());
0068     // m_pProgrammerWidget->m_pPicProgrammerPort->setCurrentText( KTLConfig::picProgrammerPort() ); // 2018.12.07
0069     {
0070         QComboBox *c = m_pProgrammerWidget->m_pPicProgrammerPort;
0071         QString text = KTLConfig::picProgrammerPort();
0072         int i = c->findText(text);
0073         if (i != -1)
0074             c->setCurrentIndex(i);
0075         else if (c->isEditable())
0076             c->setEditText(text);
0077         else
0078             c->setItemText(c->currentIndex(), text);
0079     }
0080 
0081     // Set the pic type to the one requested
0082     if (!picID.isEmpty())
0083         m_pProgrammerWidget->m_pMicroSelect->setMicro(picID);
0084 
0085     mainLayout->addWidget(m_pProgrammerWidget);
0086 
0087     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel);
0088     QPushButton *burnButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-ok")), i18n("Burn"), buttonBox);
0089     buttonBox->addButton(burnButton, QDialogButtonBox::AcceptRole);
0090     burnButton->setDefault(true);
0091     burnButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0092     mainLayout->addWidget(buttonBox);
0093     connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0094     connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0095 }
0096 
0097 ProgrammerDlg::~ProgrammerDlg()
0098 {
0099 }
0100 
0101 void ProgrammerDlg::initOptions(ProcessOptions *options)
0102 {
0103     if (!options)
0104         return;
0105 
0106     options->m_picID = m_pProgrammerWidget->m_pMicroSelect->micro();
0107     options->m_port = m_pProgrammerWidget->m_pPicProgrammerPort->currentText();
0108     options->m_program = m_pProgrammerWidget->m_pProgrammerProgram->currentText();
0109 }
0110 
0111 MicroSelectWidget *ProgrammerDlg::microSelect() const
0112 {
0113     return m_pProgrammerWidget->m_pMicroSelect;
0114 }
0115 
0116 #include "moc_programmerdlg.cpp"