Warning, file /sdk/cervisia/addrepositorydialog.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  *  Copyright (c) 2002-2007 Christian Loose <christian.loose@kdemail.net>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0019  */
0020 
0021 #include "addrepositorydialog.h"
0022 
0023 #include <QLabel>
0024 #include <QVBoxLayout>
0025 #include <qcheckbox.h>
0026 
0027 #include <QDialogButtonBox>
0028 #include <QLineEdit>
0029 #include <QPushButton>
0030 #include <QSpinBox>
0031 
0032 #include <KConfig>
0033 #include <KConfigGroup>
0034 #include <KLocalizedString>
0035 
0036 AddRepositoryDialog::AddRepositoryDialog(KConfig &cfg, const QString &repo, QWidget *parent)
0037     : QDialog(parent)
0038     , partConfig(cfg)
0039 {
0040     setWindowTitle(i18n("Add Repository"));
0041     setModal(true);
0042 
0043     auto mainLayout = new QVBoxLayout;
0044     setLayout(mainLayout);
0045 
0046     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0047     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0048     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0049 
0050     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
0051     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
0052 
0053     auto repo_label = new QLabel(i18n("&Repository:"));
0054     mainLayout->addWidget(repo_label);
0055 
0056     repo_edit = new QLineEdit;
0057     mainLayout->addWidget(repo_edit);
0058 
0059     repo_edit->setFocus();
0060     repo_label->setBuddy(repo_edit);
0061     if (!repo.isNull()) {
0062         repo_edit->setText(repo);
0063         repo_edit->setEnabled(false);
0064     }
0065     mainLayout->addWidget(repo_edit);
0066 
0067     auto rsh_label = new QLabel(i18n("Use remote &shell (only for :ext: repositories):"));
0068     mainLayout->addWidget(rsh_label);
0069     mainLayout->addWidget(rsh_label);
0070 
0071     rsh_edit = new QLineEdit;
0072     mainLayout->addWidget(rsh_edit);
0073     rsh_label->setBuddy(rsh_edit);
0074     mainLayout->addWidget(rsh_edit);
0075 
0076     auto server_label = new QLabel(i18n("Invoke this program on the server side:"));
0077     mainLayout->addWidget(server_label);
0078 
0079     server_edit = new QLineEdit;
0080     mainLayout->addWidget(server_edit);
0081     server_label->setBuddy(server_edit);
0082     mainLayout->addWidget(server_edit);
0083 
0084     auto compressionBox = new QHBoxLayout;
0085     mainLayout->addLayout(compressionBox);
0086     m_useDifferentCompression = new QCheckBox(i18n("Use different &compression level:"));
0087 
0088     m_compressionLevel = new QSpinBox();
0089     m_compressionLevel->setRange(0, 9);
0090 
0091     compressionBox->addWidget(m_useDifferentCompression);
0092     compressionBox->addWidget(m_compressionLevel);
0093 
0094     m_retrieveCvsignoreFile = new QCheckBox(i18n("Download cvsignore file from server"));
0095     mainLayout->addWidget(m_retrieveCvsignoreFile);
0096 
0097     mainLayout->addWidget(buttonBox);
0098     okButton->setDefault(true);
0099 
0100     connect(repo_edit, SIGNAL(textChanged(QString)), this, SLOT(repoChanged()));
0101     connect(m_useDifferentCompression, SIGNAL(toggled(bool)), this, SLOT(compressionToggled(bool)));
0102 
0103     repoChanged();
0104 
0105     KConfigGroup cg(&partConfig, "AddRepositoryDialog");
0106     restoreGeometry(cg.readEntry<QByteArray>("geometry", QByteArray()));
0107 }
0108 
0109 AddRepositoryDialog::~AddRepositoryDialog()
0110 {
0111     KConfigGroup cg(&partConfig, "AddRepositoryDialog");
0112     cg.writeEntry("geometry", saveGeometry());
0113 }
0114 
0115 void AddRepositoryDialog::setRsh(const QString &rsh)
0116 {
0117     rsh_edit->setText(rsh);
0118 }
0119 
0120 void AddRepositoryDialog::setServer(const QString &server)
0121 {
0122     server_edit->setText(server);
0123 }
0124 
0125 void AddRepositoryDialog::setCompression(int compression)
0126 {
0127     if (compression < 0) {
0128         // TODO: use KConfigXT to retrieve default compression level
0129         m_compressionLevel->setValue(0);
0130         m_useDifferentCompression->setChecked(false);
0131     } else {
0132         m_useDifferentCompression->setChecked(true);
0133         m_compressionLevel->setValue(compression);
0134     }
0135 
0136     compressionToggled(m_useDifferentCompression->isChecked());
0137 }
0138 
0139 void AddRepositoryDialog::setRetrieveCvsignoreFile(bool enabled)
0140 {
0141     m_retrieveCvsignoreFile->setChecked(enabled);
0142 }
0143 
0144 QString AddRepositoryDialog::repository() const
0145 {
0146     return repo_edit->text();
0147 }
0148 
0149 QString AddRepositoryDialog::rsh() const
0150 {
0151     return rsh_edit->text();
0152 }
0153 
0154 QString AddRepositoryDialog::server() const
0155 {
0156     return server_edit->text();
0157 }
0158 
0159 int AddRepositoryDialog::compression() const
0160 {
0161     if (m_useDifferentCompression->isChecked())
0162         return m_compressionLevel->value();
0163     else
0164         return -1;
0165 }
0166 
0167 bool AddRepositoryDialog::retrieveCvsignoreFile() const
0168 {
0169     return m_retrieveCvsignoreFile->isChecked();
0170 }
0171 
0172 void AddRepositoryDialog::setRepository(const QString &repo)
0173 {
0174     setWindowTitle(i18n("Repository Settings"));
0175 
0176     repo_edit->setText(repo);
0177     repo_edit->setEnabled(false);
0178 }
0179 
0180 void AddRepositoryDialog::repoChanged()
0181 {
0182     QString repo = repository();
0183     rsh_edit->setEnabled((!repo.startsWith(QLatin1String(":pserver:"))) && repo.contains(":"));
0184     m_useDifferentCompression->setEnabled(repo.contains(":"));
0185     if (!repo.contains(":"))
0186         m_compressionLevel->setEnabled(false);
0187     else
0188         compressionToggled(m_useDifferentCompression->isChecked());
0189 }
0190 
0191 void AddRepositoryDialog::compressionToggled(bool checked)
0192 {
0193     m_compressionLevel->setEnabled(checked);
0194 }
0195 
0196 // Local Variables:
0197 // c-basic-offset: 4
0198 // End: