File indexing completed on 2024-05-05 14:22:14
0001 /*************************************************************************** 0002 * Copyright (C) 2004 by Mario Bensi <nef@ipsquad.net> * 0003 * Copyright (C) 2004, 2008 by Pino Toscano <pino@kde.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 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 0021 #include "addalternatives.h" 0022 #include "altparser.h" 0023 #include "slavewidget.h" 0024 0025 #include <qdialogbuttonbox.h> 0026 #include <qboxlayout.h> 0027 0028 #include <klocalizedstring.h> 0029 #include <kseparator.h> 0030 0031 AddAlternatives::AddAlternatives(Item* item, QWidget *parent) 0032 : QDialog(parent), m_item(item), m_alternative(Q_NULLPTR) 0033 { 0034 QVBoxLayout* lay = new QVBoxLayout(this); 0035 QWidget* main = new QWidget(this); 0036 lay->addWidget(main); 0037 setupUi(main); 0038 main->layout()->setContentsMargins(0, 0, 0, 0); 0039 m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0040 lay->addWidget(m_buttons); 0041 0042 setWindowTitle(i18n("Add Alternative")); 0043 0044 m_Path->setWindowTitle( i18n( "Choose Alternative" ) ); 0045 m_Path->setFilter( i18n( "*|All Files" ) ); 0046 m_Path->setMode( KFile::File | KFile::LocalOnly ); 0047 0048 const int slaveCount = item->getSlaves()->count(); 0049 if (slaveCount > 0) 0050 { 0051 SlaveList *slaves = item->getSlaves(); 0052 0053 QWidget *w = new QWidget; 0054 QVBoxLayout *lay = new QVBoxLayout(w); 0055 for (int i = 0; i < slaveCount; ++i) 0056 { 0057 if (i > 0) 0058 lay->addWidget(new KSeparator(Qt::Horizontal, w)); 0059 SlaveWidget *sw = new SlaveWidget(slaves->at(i), w); 0060 lay->addWidget(sw); 0061 m_slaveWidgets.append(sw); 0062 connect(sw, SIGNAL(slaveChanged(QString)), this, SLOT(slotCheckSlaves())); 0063 } 0064 w->show(); 0065 m_slavesArea->setWidget(w); 0066 } 0067 else 0068 { 0069 m_slavesGroup->hide(); 0070 } 0071 0072 m_buttons->button(QDialogButtonBox::Ok)->setEnabled(false); 0073 connect(m_Path, SIGNAL(textChanged(QString)), this, SLOT(slotCheckSlaves())); 0074 connect(m_buttons, SIGNAL(accepted()), this, SLOT(slotOkClicked())); 0075 connect(m_buttons, SIGNAL(rejected()), this, SLOT(reject())); 0076 } 0077 0078 AddAlternatives::~AddAlternatives() 0079 { 0080 } 0081 0082 QSize AddAlternatives::sizeHint() const 0083 { 0084 return QSize(400, QDialog::sizeHint().height()); 0085 } 0086 0087 void AddAlternatives::slotCheckSlaves() 0088 { 0089 bool ok = !m_Path->url().isEmpty(); 0090 int i = 0; 0091 while ((i < m_slaveWidgets.count()) && ok) 0092 { 0093 ok = !m_slaveWidgets.at(i)->slavePath().isEmpty(); 0094 ++i; 0095 } 0096 0097 m_buttons->button(QDialogButtonBox::Ok)->setEnabled(ok); 0098 } 0099 0100 void AddAlternatives::slotOkClicked() 0101 { 0102 m_alternative = new Alternative(m_item); 0103 Q_ASSERT(!m_Path->url().toLocalFile().isEmpty()); 0104 m_alternative->setPath(m_Path->url().toLocalFile()); 0105 m_alternative->setPriority(m_Priority->value()); 0106 Q_FOREACH (SlaveWidget *sw, m_slaveWidgets) 0107 { 0108 Q_ASSERT(!sw->slavePath().isEmpty()); 0109 m_alternative->addSlave(sw->slavePath()); 0110 } 0111 0112 accept(); 0113 } 0114 0115 #include <addalternatives.moc>