File indexing completed on 2024-05-12 17:16:11

0001 /***************************************************************************
0002  *   Copyright (C) 2005-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 #include "editpropsdlg.h"
0021 #include "ui_editpropsdlg.h"
0022 
0023 #include <QWhatsThis>
0024 
0025 EditPropsDlg::EditPropsDlg(bool bAddMode, QWidget *parent)
0026     : KSvnDialog(QLatin1String("modify_properties"), parent)
0027     , m_isDir(false)
0028     , m_ui(new Ui::EditPropsDlg)
0029 {
0030     m_ui->setupUi(this);
0031     if (bAddMode) {
0032         setWindowTitle(i18nc("@title:window", "Add Property"));
0033     }
0034     connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0035     connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0036     connect(m_ui->helpButton, &QAbstractButton::clicked, this, &EditPropsDlg::showHelp);
0037     m_ui->helpButton->setIcon(QIcon::fromTheme(QStringLiteral("help-hint")));
0038 
0039 
0040     /// @TODO Read these values from a text or config file
0041     fileProperties += QStringLiteral("svn:eol-style");
0042     fileProperties += QStringLiteral("svn:executable");
0043     fileProperties += QStringLiteral("svn:keywords");
0044     fileProperties += QStringLiteral("svn:needs-lock");
0045     fileProperties += QStringLiteral("svn:mime-type");
0046 
0047     fileComments += i18n("One of <b>'native'</b>, <b>'LF'</b>, <b>'CR'</b>, <b>'CRLF'</b>.");
0048     fileComments += i18n("If present, make the file executable.<br/>"
0049                          "This property can not be set on a directory. "
0050                          "A non-recursive attempt will fail, and a recursive attempt "
0051                          "will set the property only on the file children of the folder.");
0052     fileComments += i18n("Keywords to be expanded into the contents of a file.<br/>"
0053                          "They can be inserted into documents by placing a keyword anchor "
0054                          "which is formatted as $KeywordName$.<br/>"
0055                          "Valid keywords are:<br/>"
0056                          "<b>URL/HeadURL</b> The URL for the head revision of the project.<br/>"
0057                          "<b>Author/LastChangedBy</b> The last person to change the file.<br/>"
0058                          "<b>Date/LastChangedDate</b> The date/time the object was last modified.<br/>"
0059                          "<b>Revision/Rev/LastChangedRevision</b> The last revision the object changed.<br/>"
0060                          "<b>Id</b> A compressed summary of the previous 4 keywords.");
0061     fileComments += i18n("Set this to any value (e.g. <b>'*'</b>) to enforce locking for this file.<br/>"
0062                          "The file will be set read-only when checked out or updated, "
0063                          "indicating that a user must acquire a lock on the file before "
0064                          "they can edit and commit changes.");
0065     fileComments += i18n("The mimetype of the file. Used to determine "
0066                          "whether to merge the file and how to serve it from "
0067                          "Apache. A mimetype beginning with <b>'text/'</b> (or an absent "
0068                          "mimetype) is treated as text. Anything else is treated as binary.");
0069 
0070     dirProperties += QStringLiteral("svn:eol-style");
0071     dirProperties += QStringLiteral("svn:executable");
0072     dirProperties += QStringLiteral("svn:externals");
0073     dirProperties += QStringLiteral("svn:ignore");
0074     dirProperties += QStringLiteral("svn:mime-type");
0075     dirProperties += QStringLiteral("bugtraq:label");
0076     dirProperties += QStringLiteral("bugtraq:url");
0077     dirProperties += QStringLiteral("bugtraq:message");
0078     dirProperties += QStringLiteral("bugtraq:warnifnoissue");
0079     dirProperties += QStringLiteral("bugtraq:number");
0080     dirProperties += QStringLiteral("bugtraq:append");
0081     dirProperties += QStringLiteral("bugtraq:logregex");
0082 
0083     dirComments += i18n("One of <b>'native'</b>, <b>'LF'</b>, <b>'CR'</b>, <b>'CRLF'</b>.");
0084     dirComments += i18n("If present, make the file executable.<br/>"
0085                         "This property can not be set on a directory. "
0086                         "A non-recursive attempt will fail, and a recursive attempt "
0087                         "will set the property only on the file children of the folder.");
0088     /* TRANSLATORS: Do not translate "example" in the URL because this is according
0089        TRANSLATORS: to http://www.rfc-editor.org/rfc/rfc2606.txt a reserved URL.*/
0090     dirComments += i18n("A newline separated list of module specifiers, each "
0091                         "consisting of a relative directory path, optional revision "
0092                         "flags, and a URL. For example:<br/>"
0093                         "<nobr><b>foo http://example.com/repos/projectA</b></nobr><br/>"
0094                         "<nobr><b>foo/bar -r 1234 http://example.com/repos/projectB</b></nobr>");
0095     dirComments += i18n("A newline separated list of file patterns to ignore.");
0096     dirComments += i18n("The mimetype of the file. Used to determine "
0097                         "whether to merge the file and how to serve it from "
0098                         "Apache. A mimetype beginning with <b>'text/'</b> (or an absent "
0099                         "mimetype) is treated as text. Anything else is treated as binary.");
0100     dirComments += i18n("Label text to show for the edit box where the user enters the issue number.");
0101     /* TRANSLATORS: Do not translate "example" in the URL because this is according
0102        TRANSLATORS: to http://www.rfc-editor.org/rfc/rfc2606.txt a reserved URL.*/
0103     dirComments += i18n("URL pointing to the issue tracker. It must contain "
0104                         "<b>%BUGID%</b> which gets replaced with the bug issue number. Example:<br/>"
0105                         "<nobr><b>http://example.com/mantis/view.php?id=%BUGID%</b></nobr>");
0106     dirComments += i18n("String which is appended to a log message when an issue "
0107                         "number is entered. The string must contain <b>%BUGID%</b> "
0108                         "which gets replaced with the bug issue number.");
0109     dirComments += i18n("Set to <b>'yes'</b> if a warning shall be shown when "
0110                         "no issue is entered in the commit dialog. Possible values:<br/>"
0111                         "<b>'true'</b>/<b>'yes'</b> or <b>'false'</b>/<b>'no'</b>.");
0112     dirComments += i18n("Set to <b>'false'</b> if your bugtracking system has "
0113                         "issues which are referenced not by numbers.<br/>"
0114                         "Possible values: <b>'true'</b> or <b>'false'</b>.");
0115     dirComments += i18n("Set to <b>'false'</b> if you want the bugtracking ID "
0116                         "to be inserted at the top of the log message. The "
0117                         "default is <b>'true'</b> which means the bugtracking "
0118                         "ID is appended to the log message.");
0119     dirComments += i18n("Two regular expressions separated by a newline.<br/>"
0120                         "The first expression is used to find a string referring to an issue, the "
0121                         "second expression is used to extract the bare bug ID from that string.");
0122 
0123     m_ui->m_NameEdit->setCompletionMode(KCompletion::CompletionPopupAuto);
0124     m_ui->m_NameEdit->setHistoryItems(fileProperties, true);
0125 
0126     m_ui->m_NameEdit->setToolTip(i18n("Select or enter new property"));
0127     connect(m_ui->m_NameEdit, QOverload<const QString &>::of(&KHistoryComboBox::activated),
0128             this, &EditPropsDlg::updateToolTip);
0129 }
0130 
0131 EditPropsDlg::~EditPropsDlg()
0132 {
0133     delete m_ui;
0134 }
0135 
0136 void EditPropsDlg::updateToolTip(const QString &selection)
0137 {
0138     QString comment;
0139     if (m_isDir) {
0140         int i = dirProperties.indexOf(selection);
0141         if (i >= 0) {
0142             comment = dirComments.at(i);
0143         }
0144     } else {
0145         int i = fileProperties.indexOf(selection);
0146         if (i >= 0) {
0147             comment = fileComments.at(i);
0148         }
0149     }
0150     if (comment.isEmpty()) {
0151         comment = i18n("No help for this property available");
0152     }
0153     m_ui->m_NameEdit->setToolTip(comment);
0154 }
0155 
0156 void EditPropsDlg::setDir(bool dir)
0157 {
0158     if (dir == m_isDir) {
0159         // Change not necessary
0160         return;
0161     }
0162     m_ui->m_NameEdit->setHistoryItems(dir ? dirProperties : fileProperties, true);
0163 
0164     m_isDir = dir;
0165 }
0166 
0167 QString EditPropsDlg::propName()const
0168 {
0169     return m_ui->m_NameEdit->currentText();
0170 }
0171 
0172 QString EditPropsDlg::propValue()const
0173 {
0174     return m_ui->m_ValueEdit->toPlainText();
0175 }
0176 
0177 void EditPropsDlg::setPropName(const QString &n)
0178 {
0179     m_ui->m_NameEdit->addToHistory(n);
0180     m_ui->m_NameEdit->setCurrentItem(n);
0181     updateToolTip(n);
0182 }
0183 
0184 void EditPropsDlg::setPropValue(const QString &v)
0185 {
0186     m_ui->m_ValueEdit->setText(v);
0187 }
0188 
0189 void EditPropsDlg::showHelp()
0190 {
0191     QPoint pos = m_ui->m_ValueEdit->pos();
0192     pos.setX(pos.x() + m_ui->m_ValueEdit->width() / 2);
0193     pos.setY(pos.y() + m_ui->m_ValueEdit->height() / 4);
0194     QWhatsThis::showText(mapToGlobal(pos), m_ui->m_NameEdit->toolTip());
0195 }