tagdlg.cpp 5.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/* 
 *  Copyright (C) 1999-2001 Bernd Gehrmann
 *                          bernd@physik.hu-berlin.de
 *
 * This program may be distributed under the terms of the Q Public
 * License as defined by Trolltech AS of Norway and appearing in the
 * file LICENSE.QPL included in the packaging of this file.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */


#include <qcheckbox.h>
#include <qcombobox.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qmessagebox.h>
#include <kapp.h>
#include <kbuttonbox.h>
#include <klineedit.h>
#include <klocale.h>

#include "cvsprogressdlg.h"
#include "misc.h"

#include "tagdlg.h"
#include "tagdlg.moc"


TagDialog::TagDialog(ActionType action, const QString &sbox, const QString &repo,
                     QWidget *parent, const char *name)
Bernd Gehrmann's avatar
Bernd Gehrmann committed
34
    : QDialog(parent, name, true), branchtag_button(0), forcetag_button(0)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
{
    setCaption( (action==Delete)? i18n("CVS Delete Tag") : i18n("CVS Tag") );

    QBoxLayout *layout = new QVBoxLayout(this, 10);

    if (action == Delete)
        {
            tag_combo = new QComboBox(true, this);
            tag_combo->setFocus();
            QFontMetrics fm(fontMetrics());
            tag_combo->setMinimumSize(fm.width("0")*30, tag_combo->sizeHint().height());
            
            QLabel *tag_label = new QLabel(tag_combo, i18n("&Name of tag:"), this);

            QPushButton *tag_button = new QPushButton("Fetch &list", this);
            tag_button->setMinimumWidth(tag_button->sizeHint().width());
            connect( tag_button, SIGNAL(clicked()),
                     this, SLOT(tagButtonClicked()) );
            
            QBoxLayout *tagedit_layout = new QHBoxLayout();
            layout->addLayout(tagedit_layout);
            tagedit_layout->addWidget(tag_label);
            tagedit_layout->addWidget(tag_combo);
            tagedit_layout->addWidget(tag_button);
        }
    else
        {
            tag_edit = new KLineEdit(this);
            tag_edit->setFocus();
            QFontMetrics fm(fontMetrics());
            tag_edit->setMinimumSize(fm.width("0")*30, tag_edit->sizeHint().height());
            
            QLabel *tag_label = new QLabel(tag_edit, i18n("&Name of tag:"), this);

            QBoxLayout *tagedit_layout = new QHBoxLayout();
            layout->addLayout(tagedit_layout);
            tagedit_layout->addWidget(tag_label);
            tagedit_layout->addWidget(tag_edit);

            branchtag_button = new QCheckBox(i18n("Create &branch with this tag"), this);
            layout->addWidget(branchtag_button);
Bernd Gehrmann's avatar
Bernd Gehrmann committed
76 77 78

            forcetag_button = new QCheckBox(i18n("&Force tag creation even if tag already exists"), this);
            layout->addWidget(forcetag_button);
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
	}
    
    QFrame *frame = new QFrame(this);
    frame->setFrameStyle(QFrame::HLine | QFrame::Sunken);
    frame->setMinimumHeight(frame->sizeHint().height());
    layout->addWidget(frame, 0);

    KButtonBox *buttonbox = new KButtonBox(this);
    buttonbox->addStretch();
    QPushButton *ok = buttonbox->addButton(i18n("OK"));
    QPushButton *cancel = buttonbox->addButton(i18n("Cancel"));
    ok->setDefault(true);
    connect( ok, SIGNAL(clicked()), this, SLOT(accept()) );
    connect( cancel, SIGNAL(clicked()), this, SLOT(reject()) );
    buttonbox->layout();
    layout->addWidget(buttonbox, 0);

    layout->activate();
    resize(sizeHint());

    act = action;
    sandbox = sbox;
    repository = repo;
}


void TagDialog::done(int r)
{
    if (r == Accepted)
        {
            QString str = tag();
            
            if (str.length() == 0)
                {
                    QMessageBox::information(this, "Cervisia",
                                             i18n("You must define a tag name."));
                    return;
                }

            if (!isValidTag(str))
                {
                    QMessageBox::information(this, "Cervisia",
                                             i18n("Tag must start with a letter and may contain"
                                                  "letters, digits and the characters '-' and '_'."));
                    return;
                }
        }
    
    QDialog::done(r);
}


void TagDialog::tagButtonClicked()
{
    QString cmdline = cvsClient(repository);
    cmdline += " status -v";

    CvsProgressDialog l("Status", this);
    l.setCaption("CVS Status");
    if (!l.execCommand(sandbox, repository, cmdline, ""))
        return;

    QStrList tags(true);
    QCString str;
    while (l.getOneLine(&str))
        {
            int pos1, pos2, pos3;
            if (str.length() < 1 || str[0] != '\t')
                continue;
            if ((pos1 = str.find(' ', 2)) == -1)
                continue;
            if ((pos2 = str.find('(', pos1+1)) == -1)
                continue;
            if ((pos3 = str.find(':', pos2+1)) == -1)
                continue;
            
            QString tag = str.mid(1, pos1-1);
            QString type = str.mid(pos2+1, pos3-pos2-1);
            if (type == QString::fromLatin1("revision") && !tags.contains(tag.latin1()))
                tags.inSort(tag.latin1());
        }

    tag_combo->clear();
    QStrListIterator it(tags);
    for (; it.current(); ++it)
        tag_combo->insertItem(*it);
}


// Local Variables:
// c-basic-offset: 4
// End: