Warning, file /sdk/cervisia/tagdialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (C) 1999-2002 Bernd Gehrmann
0003  *                          bernd@mail.berlios.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 Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 #include "tagdialog.h"
0021 
0022 #include <KComboBox>
0023 #include <KHelpClient>
0024 #include <KLocalizedString>
0025 #include <kmessagebox.h>
0026 
0027 #include <QCheckBox>
0028 #include <QDialogButtonBox>
0029 #include <QHBoxLayout>
0030 #include <QLabel>
0031 #include <QLineEdit>
0032 #include <QPushButton>
0033 #include <QVBoxLayout>
0034 
0035 #include "cvsserviceinterface.h"
0036 #include "misc.h"
0037 
0038 using Cervisia::TagDialog;
0039 
0040 TagDialog::TagDialog(ActionType action, OrgKdeCervisia5CvsserviceCvsserviceInterface *service, QWidget *parent)
0041     : QDialog(parent)
0042     , act(action)
0043     , cvsService(service)
0044     , branchtag_button(0)
0045     , forcetag_button(0)
0046 {
0047     setModal(true);
0048     setWindowTitle((action == Delete) ? i18n("CVS Delete Tag") : i18n("CVS Tag"));
0049 
0050     auto mainLayout = new QVBoxLayout;
0051     setLayout(mainLayout);
0052 
0053     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
0054     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0055     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0056     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
0057     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
0058     connect(buttonBox, &QDialogButtonBox::helpRequested, this, &TagDialog::slotHelp);
0059 
0060     if (action == Delete) {
0061         tag_combo = new KComboBox;
0062         mainLayout->addWidget(tag_combo);
0063         tag_combo->setEditable(true);
0064         tag_combo->setFocus();
0065         tag_combo->setMinimumWidth(fontMetrics().width('0') * 30);
0066 
0067         auto tag_label = new QLabel(i18n("&Name of tag:"));
0068         mainLayout->addWidget(tag_label);
0069         tag_label->setBuddy(tag_combo);
0070 
0071         auto tag_button = new QPushButton(i18n("Fetch &List"));
0072         mainLayout->addWidget(tag_button);
0073         connect(tag_button, SIGNAL(clicked()), this, SLOT(tagButtonClicked()));
0074 
0075         QBoxLayout *tagedit_layout = new QHBoxLayout();
0076         mainLayout->addLayout(tagedit_layout);
0077         tagedit_layout->addWidget(tag_label);
0078         tagedit_layout->addWidget(tag_combo);
0079         tagedit_layout->addWidget(tag_button);
0080     } else {
0081         tag_edit = new QLineEdit;
0082         mainLayout->addWidget(tag_edit);
0083         tag_edit->setFocus();
0084         tag_edit->setMinimumWidth(fontMetrics().width('0') * 30);
0085 
0086         auto tag_label = new QLabel(i18n("&Name of tag:"));
0087         mainLayout->addWidget(tag_label);
0088         tag_label->setBuddy(tag_edit);
0089 
0090         QBoxLayout *tagedit_layout = new QHBoxLayout();
0091         mainLayout->addLayout(tagedit_layout);
0092         tagedit_layout->addWidget(tag_label);
0093         tagedit_layout->addWidget(tag_edit);
0094 
0095         branchtag_button = new QCheckBox(i18n("Create &branch with this tag"));
0096         mainLayout->addWidget(branchtag_button);
0097         mainLayout->addWidget(branchtag_button);
0098 
0099         forcetag_button = new QCheckBox(i18n("&Force tag creation even if tag already exists"));
0100         mainLayout->addWidget(forcetag_button);
0101         mainLayout->addWidget(forcetag_button);
0102     }
0103 
0104     connect(okButton, SIGNAL(clicked()), this, SLOT(slotOk()));
0105 
0106     mainLayout->addWidget(buttonBox);
0107 }
0108 
0109 bool TagDialog::branchTag() const
0110 {
0111     return branchtag_button && branchtag_button->isChecked();
0112 }
0113 
0114 bool TagDialog::forceTag() const
0115 {
0116     return forcetag_button && forcetag_button->isChecked();
0117 }
0118 
0119 QString TagDialog::tag() const
0120 {
0121     return act == Delete ? tag_combo->currentText() : tag_edit->text();
0122 }
0123 
0124 void TagDialog::slotHelp()
0125 {
0126     KHelpClient::invokeHelp(QLatin1String("taggingbranching"));
0127 }
0128 
0129 void TagDialog::slotOk()
0130 {
0131     QString const str(tag());
0132 
0133     if (str.isEmpty()) {
0134         KMessageBox::error(this, i18n("You must define a tag name."), "Cervisia");
0135         return;
0136     }
0137 
0138     if (!Cervisia::IsValidTag(str)) {
0139         KMessageBox::error(this,
0140                            i18n("Tag must start with a letter and may contain "
0141                                 "letters, digits and the characters '-' and '_'."),
0142                            "Cervisia");
0143         return;
0144     }
0145 
0146     QDialog::accept();
0147 }
0148 
0149 void TagDialog::tagButtonClicked()
0150 {
0151     tag_combo->clear();
0152     tag_combo->addItems(::fetchTags(cvsService, this));
0153 }
0154 
0155 // Local Variables:
0156 // c-basic-offset: 4
0157 // End: