File indexing completed on 2024-05-19 08:56:10
0001 /************************************************************************** 0002 * Copyright (C) 2007 by Michel Ludwig (michel.ludwig@kdemail.net) * 0003 ***************************************************************************/ 0004 0005 /************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (at your option) any later version. * 0011 * * 0012 ***************************************************************************/ 0013 0014 #include "dialogs/newtoolwizard.h" 0015 #include "kiletoolmanager.h" 0016 #include <KSharedConfig> 0017 #include <QPushButton> 0018 0019 NewToolWizard::NewToolWizard(QWidget *parent, Qt::WindowFlags fl) : KAssistantDialog(parent, fl) 0020 { 0021 QWidget *toolNameWidget = new QWidget(this); 0022 Ui::NewToolWizardToolNamePage::setupUi(toolNameWidget); 0023 toolNamePage = new KPageWidgetItem(toolNameWidget, i18n("Tool Name")); 0024 0025 QWidget *classWidget = new QWidget(this); 0026 Ui::NewToolWizardClassPage::setupUi(classWidget); 0027 classPage = new KPageWidgetItem(classWidget, i18n("Class")); 0028 0029 addPage(toolNamePage); 0030 addPage(classPage); 0031 0032 m_toolList = KileTool::toolList(KSharedConfig::openConfig().data(), false); 0033 0034 buttonBox()->button(QDialogButtonBox::Help)->setVisible(false); 0035 0036 connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(slotCurrentPageChanged(KPageWidgetItem*,KPageWidgetItem*))); 0037 connect(m_leName, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); 0038 setValid(toolNamePage, false); 0039 0040 //setup the Behavior page (page 1) 0041 m_cbTools->addItem(customTool()); 0042 m_cbTools->addItems(m_toolList); 0043 } 0044 0045 QString NewToolWizard::customTool() 0046 { 0047 return i18n("<Custom>"); 0048 } 0049 0050 QString NewToolWizard::toolName() 0051 { 0052 return m_leName->text(); 0053 } 0054 0055 QString NewToolWizard::parentTool() 0056 { 0057 return m_cbTools->currentText(); 0058 } 0059 0060 void NewToolWizard::nameChanged(const QString &name) 0061 { 0062 static QRegExp reBracket = QRegExp("\\(|\\)|\\[|\\]"); 0063 bool ok = true; 0064 0065 if(m_toolList.contains(name)) { 0066 m_lbWarning->setText(i18n( "Error: A tool by this name exists already." )); 0067 ok = false; 0068 } 0069 else if(name.indexOf("/") != -1) { 0070 m_lbWarning->setText(i18n( "Error: The name may not contain a slash '/'." )); 0071 ok = false; 0072 } 0073 else if(name.indexOf(reBracket) != -1) { 0074 m_lbWarning->setText(i18n("Error: The name may not contain a (, ), [, or ].")); 0075 ok = false; 0076 } 0077 else { 0078 m_lbWarning->setText(""); 0079 } 0080 setValid(toolNamePage, ok); 0081 } 0082 0083 void NewToolWizard::slotCurrentPageChanged(KPageWidgetItem* current, KPageWidgetItem* /* before */) 0084 { 0085 if (current == toolNamePage) { 0086 m_leName->setFocus(); 0087 } 0088 else if (current == classPage) { 0089 m_cbTools->setFocus(); 0090 } 0091 } 0092