File: updatedialog.cpp

package info (click to toggle)
cervisia 4:17.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,548 kB
  • sloc: cpp: 14,364; xml: 393; makefile: 3; sh: 3
file content (180 lines) | stat: -rw-r--r-- 5,326 bytes parent folder | download | duplicates (2)
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
34
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
76
77
78
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
173
174
175
176
177
178
179
180
/*
 *  Copyright (C) 1999-2002 Bernd Gehrmann
 *                          bernd@mail.berlios.de
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */


#include "updatedialog.h"

#include <qbuttongroup.h>
#include <KComboBox>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qstyle.h>
#include <QBoxLayout>
#include <QLineEdit>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>

#include <KConfigGroup>
#include <KLocalizedString>

#include "misc.h"
#include "cvsserviceinterface.h"


UpdateDialog::UpdateDialog(OrgKdeCervisia5CvsserviceCvsserviceInterface* service,
                           QWidget *parent)
    : QDialog(parent),
      cvsService(service)
{
    setWindowTitle(i18n("CVS Update"));
    setModal(true);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    setLayout(mainLayout);

    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
    QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
    okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

    const int iComboBoxMinWidth(40 * fontMetrics().width('0'));
    const int iWidgetIndent(style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth) + 6);

    bybranch_button = new QRadioButton(i18n("Update to &branch: "));
    mainLayout->addWidget(bybranch_button);
    bybranch_button->setChecked(true);

    branch_combo = new KComboBox;
    mainLayout->addWidget(branch_combo);
    branch_combo->setEditable(true);
    branch_combo->setMinimumWidth(iComboBoxMinWidth);
    
    branch_button = new QPushButton(i18n("Fetch &List"));
    mainLayout->addWidget(branch_button);
    connect(branch_button, SIGNAL(clicked()), this, SLOT(branchButtonClicked()));
            
    QBoxLayout *branchedit_layout = new QHBoxLayout;
    branchedit_layout->addSpacing(iWidgetIndent);
    branchedit_layout->addWidget(branch_combo);
    branchedit_layout->addWidget(branch_button);
    mainLayout->addLayout(branchedit_layout);
    
    bytag_button = new QRadioButton(i18n("Update to &tag: "));
    mainLayout->addWidget(bytag_button);

    tag_combo = new KComboBox;
    tag_combo->setEditable(true);
    tag_combo->setMinimumWidth(iComboBoxMinWidth);
    mainLayout->addWidget(tag_combo);
    
    tag_button = new QPushButton(i18n("Fetch L&ist"));
    mainLayout->addWidget(tag_button);
    connect(tag_button, SIGNAL(clicked()), this, SLOT(tagButtonClicked()));
            
    QBoxLayout *tagedit_layout = new QHBoxLayout();
    tagedit_layout->addSpacing(iWidgetIndent);
    tagedit_layout->addWidget(tag_combo);
    tagedit_layout->addWidget(tag_button);
    mainLayout->addLayout(tagedit_layout);
    
    bydate_button = new QRadioButton(i18n("Update to &date ('yyyy-mm-dd'):"));
    mainLayout->addWidget(bydate_button);

    date_edit = new QLineEdit;
    mainLayout->addWidget(date_edit);

    QBoxLayout *dateedit_layout = new QHBoxLayout;
    dateedit_layout->addSpacing(iWidgetIndent);
    dateedit_layout->addWidget(date_edit);
    mainLayout->addLayout(dateedit_layout);

    QButtonGroup* group = new QButtonGroup(this);
    group->addButton(bytag_button);
    group->addButton(bybranch_button);
    group->addButton(bydate_button);
    connect(group, SIGNAL(buttonClicked(int)), this, SLOT(toggled()));

    mainLayout->addWidget(buttonBox);

    // dis-/enable the widgets
    toggled();
}


bool UpdateDialog::byTag() const
{
    return bybranch_button->isChecked() || bytag_button->isChecked();
}


QString UpdateDialog::tag() const
{
    return bybranch_button->isChecked()
        ? branch_combo->currentText()
        : tag_combo->currentText();
}


QString UpdateDialog::date() const
{
    return date_edit->text();
}


void UpdateDialog::tagButtonClicked()
{
    tag_combo->clear();
    tag_combo->addItems(::fetchTags(cvsService, this));
}


void UpdateDialog::branchButtonClicked()
{
    branch_combo->clear();
    branch_combo->addItems(::fetchBranches(cvsService, this));
}


void UpdateDialog::toggled()
{
    bool bytag = bytag_button->isChecked();
    tag_combo->setEnabled(bytag);
    tag_button->setEnabled(bytag);
    if (bytag)
        tag_combo->setFocus();

    bool bybranch = bybranch_button->isChecked();
    branch_combo->setEnabled(bybranch);
    branch_button->setEnabled(bybranch);
    if (bybranch)
        branch_combo->setFocus();

    bool bydate = bydate_button->isChecked();
    date_edit->setEnabled(bydate);
    if (bydate)
        date_edit->setFocus();
}



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