File indexing completed on 2024-04-28 05:42:02
0001 /*************************************************************************** 0002 * Copyright (C) 2006-2009 by Rajko Albrecht * 0003 * ral@alwins-world.de * 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 0021 #include "propertiesdlg.h" 0022 #include "ui_propertiesdlg.h" 0023 0024 #include "editpropsdlg.h" 0025 #include "svnfrontend/fronthelpers/propertyitem.h" 0026 #include "svnfrontend/fronthelpers/propertylist.h" 0027 #include "svnitem.h" 0028 #include "svnqt/client.h" 0029 0030 #include <KLocalizedString> 0031 #include <KMessageBox> 0032 0033 PropertiesDlg::PropertiesDlg(SvnItem *which, const svn::ClientP &aClient, const svn::Revision &aRev, QWidget *parent) 0034 : KSvnDialog(QLatin1String("properties_dlg"), parent) 0035 , m_Item(which) 0036 , m_Client(aClient) 0037 , m_Rev(aRev) 0038 , m_ui(new Ui::PropertiesDlg) 0039 { 0040 m_ui->setupUi(this); 0041 setDefaultButton(m_ui->buttonBox->button(QDialogButtonBox::Ok)); 0042 connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0043 connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0044 0045 m_ui->tvPropertyList->setAllColumnsShowFocus(true); 0046 m_ui->tvPropertyList->setCommitchanges(false); 0047 0048 // signals and slots connections 0049 connect(m_ui->pbAdd, &QAbstractButton::clicked, this, &PropertiesDlg::slotAdd); 0050 connect(m_ui->pbModify, &QAbstractButton::clicked, this, &PropertiesDlg::slotModify); 0051 connect(m_ui->pbDelete, &QAbstractButton::clicked, this, &PropertiesDlg::slotDelete); 0052 0053 connect(m_ui->tvPropertyList, &QTreeWidget::currentItemChanged, this, &PropertiesDlg::slotCurrentItemChanged); 0054 if (!m_Client) { 0055 m_ui->tvPropertyList->setEnabled(false); 0056 } 0057 slotCurrentItemChanged(nullptr); 0058 initItem(); 0059 } 0060 0061 PropertiesDlg::~PropertiesDlg() 0062 { 0063 delete m_ui; 0064 } 0065 0066 void PropertiesDlg::slotCurrentItemChanged(QTreeWidgetItem *item) 0067 { 0068 m_ui->pbDelete->setEnabled(item != nullptr); 0069 m_ui->pbModify->setEnabled(item != nullptr); 0070 if (!item || item->type() != PropertyListViewItem::_RTTI_) { 0071 return; 0072 } 0073 PropertyListViewItem *ki = static_cast<PropertyListViewItem *>(item); 0074 if (PropertyListViewItem::protected_Property(ki->currentName())) { 0075 m_ui->pbDelete->setEnabled(false); 0076 m_ui->pbModify->setEnabled(false); 0077 return; 0078 } 0079 if (ki->deleted()) { 0080 m_ui->pbDelete->setText(i18n("Undelete property")); 0081 } else { 0082 m_ui->pbDelete->setText(i18n("Delete property")); 0083 } 0084 } 0085 0086 void PropertiesDlg::initItem() 0087 { 0088 if (!m_Client) { 0089 QString ex = i18n("Missing SVN link"); 0090 emit clientException(ex); 0091 return; 0092 } 0093 svn::Path what(m_Item->fullName()); 0094 svn::PathPropertiesMapListPtr propList; 0095 try { 0096 propList = m_Client->proplist(what, m_Rev, m_Rev); 0097 } catch (const svn::ClientException &e) { 0098 emit clientException(e.msg()); 0099 return; 0100 } 0101 m_ui->tvPropertyList->displayList(propList, true, m_Item->isDir(), m_Item->fullName()); 0102 } 0103 0104 void PropertiesDlg::slotAdd() 0105 { 0106 QPointer<EditPropsDlg> dlg(new EditPropsDlg(true, this)); 0107 dlg->setDir(m_Item->isDir()); 0108 0109 if (dlg->exec() == QDialog::Accepted) { 0110 if (PropertyListViewItem::protected_Property(dlg->propName())) { 0111 KMessageBox::error(this, i18n("This property may not set by users.\nRejecting it."), i18n("Protected property")); 0112 return; 0113 } 0114 if (m_ui->tvPropertyList->checkExisting(dlg->propName())) { 0115 KMessageBox::error(this, i18n("A property with that name exists.\nRejecting it."), i18n("Double property")); 0116 return; 0117 } 0118 if (!dlg->propName().isEmpty()) { 0119 PropertyListViewItem *item = new PropertyListViewItem(m_ui->tvPropertyList); 0120 item->setName(dlg->propName()); 0121 item->setValue(dlg->propValue()); 0122 } 0123 } 0124 delete dlg; 0125 } 0126 0127 void PropertiesDlg::slotDelete() 0128 { 0129 QTreeWidgetItem *qi = m_ui->tvPropertyList->currentItem(); 0130 if (!qi) { 0131 return; 0132 } 0133 PropertyListViewItem *ki = static_cast<PropertyListViewItem *>(qi); 0134 if (PropertyListViewItem::protected_Property(ki->currentName())) { 0135 return; 0136 } 0137 if (ki->deleted()) { 0138 ki->unDeleteIt(); 0139 } else { 0140 ki->deleteIt(); 0141 } 0142 slotCurrentItemChanged(qi); 0143 } 0144 0145 void PropertiesDlg::slotModify() 0146 { 0147 QTreeWidgetItem *qi = m_ui->tvPropertyList->currentItem(); 0148 if (!qi) { 0149 return; 0150 } 0151 PropertyListViewItem *ki = static_cast<PropertyListViewItem *>(qi); 0152 if (PropertyListViewItem::protected_Property(ki->currentName())) { 0153 return; 0154 } 0155 QPointer<EditPropsDlg> dlg(new EditPropsDlg(false, this)); 0156 dlg->setDir(m_Item->isDir()); 0157 dlg->setPropName(ki->currentName()); 0158 dlg->setPropValue(ki->currentValue()); 0159 0160 if (dlg->exec() == QDialog::Accepted) { 0161 if (PropertyListViewItem::protected_Property(dlg->propName())) { 0162 KMessageBox::error(this, i18n("This property may not set by users.\nRejecting it."), i18n("Protected property")); 0163 return; 0164 } 0165 if (m_ui->tvPropertyList->checkExisting(dlg->propName(), qi)) { 0166 KMessageBox::error(this, i18n("A property with that name exists.\nRejecting it."), i18n("Double property")); 0167 return; 0168 } 0169 ki->setName(dlg->propName()); 0170 ki->setValue(dlg->propValue()); 0171 } 0172 delete dlg; 0173 } 0174 0175 void PropertiesDlg::changedItems(svn::PropertiesMap &toSet, QStringList &toDelete) 0176 { 0177 toSet.clear(); 0178 toDelete.clear(); 0179 QTreeWidgetItemIterator iter(m_ui->tvPropertyList); 0180 while (*iter) { 0181 PropertyListViewItem *ki = static_cast<PropertyListViewItem *>((*iter)); 0182 ++iter; 0183 if (PropertyListViewItem::protected_Property(ki->currentName()) || PropertyListViewItem::protected_Property(ki->startName())) { 0184 continue; 0185 } 0186 if (ki->deleted()) { 0187 toDelete.push_back(ki->currentName()); 0188 } else if (ki->currentName() != ki->startName()) { 0189 toDelete.push_back(ki->startName()); 0190 toSet[ki->currentName()] = ki->currentValue(); 0191 } else if (ki->currentValue() != ki->startValue()) { 0192 toSet[ki->currentName()] = ki->currentValue(); 0193 } 0194 } 0195 } 0196 0197 #include "moc_propertiesdlg.cpp"