Commit fa624341 authored by Bernd Gehrmann's avatar Bernd Gehrmann
Browse files

Rewritten repository settings dialog; its

functionality now comprises that of the former
dialog and the former add repository dialog

svn path=/trunk/kdesdk/cervisia/; revision=163103
parent 4c38dc23
......@@ -15,19 +15,91 @@
#include "repositorydlg.h"
#include <stdlib.h>
#include <qhbuttongroup.h>
#include <qdir.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qtextstream.h>
#include <kapplication.h>
#include <kbuttonbox.h>
#include <kconfig.h>
#include <klocale.h>
#include <kmessagebox.h>
#include "repositories.h"
#include "listview.h"
#include "repositorysettingsdlg.h"
#include "cervisiapart.h"
class RepositoryListItem : public QListViewItem
{
public:
RepositoryListItem(QListView *parent, const QString &repo, bool loggedin);
void setRsh(const QString &rsh);
void setCompression(int compression);
QString repository() const
{
return text(0);
}
QString rsh() const
{
QString str = text(1);
return (str.left(5) == "ext (")? str.mid(5, str.length()-6) : QString::null;
}
int compression() const
{
bool ok; int n = text(2).toInt(&ok); return ok? n : -1;
}
};
RepositoryListItem::RepositoryListItem(QListView *parent, const QString &repo, bool loggedin)
: QListViewItem(parent)
{
setText(0, repo);
QString status;
if (repo.left(9) == ":pserver:")
status = loggedin? i18n("Logged in") : i18n("Not logged in");
else
status = i18n("No login required");
setText(3, status);
}
void RepositoryListItem::setRsh(const QString &rsh)
{
QString repo = repository();
QString method;
if (repo.left(9) == ":pserver:")
method = "pserver";
else if (repo.contains(':'))
{
method = "ext";
if (!rsh.isEmpty())
{
method += " (";
method += rsh;
method += ")";
}
}
else
method = "local";
setText(1, method);
}
void RepositoryListItem::setCompression(int compression)
{
QString compressionStr = (compression >= 0)?
QString::number(compression) : i18n("Default");
setText(2, compressionStr);
}
RepositoryDialog::Options *RepositoryDialog::options = 0;
......@@ -37,7 +109,7 @@ AddRepositoryDialog::Options *AddRepositoryDialog::options = 0;
RepositoryDialog::RepositoryDialog(QWidget *parent, const char *name)
: QDialog(parent, name, true)
{
setCaption( i18n("Configure Access to Repositories") );
setCaption(i18n("Configure access to repositories"));
QBoxLayout *layout = new QVBoxLayout(this, 10);
......@@ -51,22 +123,17 @@ RepositoryDialog::RepositoryDialog(QWidget *parent, const char *name)
repolist->setMinimumHeight(repolist->sizeHint().height());
repolist->setAllColumnsShowFocus(true);
repolist->setPreferredColumn(0);
repolist->addColumn("Repository");
repolist->addColumn("Method");
repolist->addColumn("Status");
repolist->addColumn(i18n("Repository"));
repolist->addColumn(i18n("Method"));
repolist->addColumn(i18n("Compression"));
repolist->addColumn(i18n("Status"));
repolist->setFocus();
connect(repolist,SIGNAL(selectionChanged ()),
this,SLOT(slotSelectionChanged()));
connect(repolist,SIGNAL(doubleClicked ( QListViewItem * )),
this,SLOT(slotDoubleClicked(QListViewItem *)));
KButtonBox *actionbox = new KButtonBox(this, KButtonBox::Vertical);
actionbox->addStretch();
QPushButton *addbutton = actionbox->addButton(i18n("&Add..."));
removebutton = actionbox->addButton(i18n("&Remove"));
settingsbutton = actionbox->addButton(i18n("&Settings..."));
QPushButton *removebutton = actionbox->addButton(i18n("&Remove"));
QPushButton *settingsbutton = actionbox->addButton(i18n("&Settings..."));
#if 0
actionbox->addStretch();
QPushButton *loginbutton = actionbox->addButton(i18n("Login..."));
......@@ -92,7 +159,7 @@ RepositoryDialog::RepositoryDialog(QWidget *parent, const char *name)
readCvsPassFile();
readConfigFile();
QFrame *frame = new QFrame(this);
frame->setFrameStyle(QFrame::HLine | QFrame::Sunken);
frame->setMinimumHeight(frame->sizeHint().height());
......@@ -112,24 +179,11 @@ RepositoryDialog::RepositoryDialog(QWidget *parent, const char *name)
layout->activate();
resize(sizeHint());
if (options)
resize(options->size);
slotSelectionChanged();
}
void RepositoryDialog::slotDoubleClicked(QListViewItem *item)
{
if(item)
slotSettingsClicked();
}
void RepositoryDialog::slotSelectionChanged()
{
bool state=(repolist->currentItem()!=0);
removebutton->setEnabled(state);
settingsbutton->setEnabled(state);
}
void RepositoryDialog::done(int r)
{
......@@ -141,21 +195,19 @@ void RepositoryDialog::done(int r)
for (item = repolist->firstChild(); item; item = item->nextSibling())
list.append(item->text(0).latin1());
KConfig *config = kapp->config();
KConfig *config = CervisiaPart::config();
config->setGroup("Repositories");
config->writeEntry("Repos", list);
for (item = repolist->firstChild(); item; item = item->nextSibling())
{
QString str = item->text(1);
if (str.left(5) != "ext (")
continue;
config->setGroup(QString("Repository-") + item->text(0));
config->writeEntry("rsh", str.mid(5,str.length()-6));
RepositoryListItem *ritem = static_cast<RepositoryListItem*>(item);
config->setGroup(QString("Repository-") + ritem->repository());
config->writeEntry("rsh", ritem->rsh());
config->writeEntry("Compression", ritem->compression());
}
}
if (!options)
options = new Options;
options->size = size();
......@@ -177,7 +229,7 @@ void RepositoryDialog::saveOptions(KConfig *config)
{
if (!options)
return;
config->writeEntry("Customized", true);
config->writeEntry("Size", options->size);
}
......@@ -185,104 +237,69 @@ void RepositoryDialog::saveOptions(KConfig *config)
void RepositoryDialog::readCvsPassFile()
{
QStrList list1;
Repositories::readCvsPassFile(&list1);
QStrListIterator it1(list1);
for (; it1.current(); ++it1)
new QListViewItem(repolist, it1.current(), "pserver", i18n("Logged in"));
QStringList list = Repositories::readCvsPassFile();
QStringList::ConstIterator it;
for (it = list.begin(); it != list.end(); ++it)
(void) new RepositoryListItem(repolist, (*it), true);
}
void RepositoryDialog::readConfigFile()
{
QStrList list;
Repositories::readConfigFile(&list);
QStringList list = Repositories::readConfigFile();
// Sort out all list elements which are already in the list view
QListViewItem *item = repolist->firstChild();
for ( ; item; item = item->nextSibling())
list.remove(item->text(0).latin1());
list.remove(item->text(0));
QStringList::ConstIterator it;
for (it = list.begin(); it != list.end(); ++it)
new RepositoryListItem(repolist, *it, false);
// Now look for the used methods
QStrListIterator it(list);
for (; it.current(); ++it)
item = repolist->firstChild();
for (; item; item = item->nextSibling())
{
QString repo = it.current();
QString method;
QString status;
if (repo.left(9) == ":pserver:")
{
status = i18n("Not logged in");
method = "pserver";
}
else
{
status = i18n("No login required");
if (repo.contains(':'))
{
method = "ext";
KConfig *config = kapp->config();
config->setGroup("Repository-" + repo);
QString rsh = config->readEntry("rsh");
if (!rsh.isEmpty())
{
method += " (";
method += rsh;
method += ")";
}
}
else
method = "local";
}
RepositoryListItem *ritem = static_cast<RepositoryListItem*>(item);
KConfig *config = CervisiaPart::config();
config->setGroup(QString("Repository-") + ritem->repository());
QString rsh = config->readEntry("rsh", QString());
int compression = config->readNumEntry("Compression", -1);
new QListViewItem(repolist, repo, method, status);
ritem->setRsh(rsh);
ritem->setCompression(compression);
}
}
void RepositoryDialog::slotAddClicked()
{
AddRepositoryDialog dlg(this);
if (dlg.exec() == QDialog::Accepted)
AddRepositoryDialog dlg(QString::null, this);
if (dlg.exec())
{
QString repo = dlg.repository();
QString rsh = dlg.rsh();
int compression = dlg.compression();
QListViewItem *item = repolist->firstChild();
for ( ; item; item = item->nextSibling())
if (item->text(0) == repo)
{
KMessageBox::information(this,
i18n("This repository is already known."),
"Cervisia");
QMessageBox::information(this, "Cervisia",
i18n("This repository is already known."));
return;
}
QString method;
QString status;
if (repo.left(9) == ":pserver:")
{
status = i18n("Not logged in");
method = "pserver";
}
else
{
status = i18n("No login required");
if (repo.contains(':'))
{
method = "ext";
if (!dlg.rsh().isEmpty())
{
method += " (";
method += dlg.rsh();
method += ")";
}
}
else
method = "local";
}
new QListViewItem(repolist, repo, method, status);
RepositoryListItem *ritem = new RepositoryListItem(repolist, repo, false);
ritem->setRsh(rsh);
ritem->setCompression(compression);
KConfig *config = CervisiaPart::config();
config->setGroup(QString("Repository-") + repo);
config->writeEntry("rsh", rsh);
config->writeEntry("Compression", compression);
}
}
......@@ -290,23 +307,42 @@ void RepositoryDialog::slotAddClicked()
void RepositoryDialog::slotRemoveClicked()
{
delete repolist->currentItem();
slotSelectionChanged();
}
void RepositoryDialog::slotSettingsClicked()
void RepositoryDialog::slotDoubleClicked(QListViewItem *item)
{
QListViewItem* item = repolist->currentItem();
if (!item)
return;
if (item)
RepositoryListItem *ritem = static_cast<RepositoryListItem*>(item);
QString repo = ritem->repository();
QString rsh = ritem->rsh();
int compression = ritem->compression();
AddRepositoryDialog dlg(repo, this);
dlg.setRepository(repo);
dlg.setRsh(rsh);
dlg.setCompression(compression);
if (dlg.exec())
{
// create a repository settings dialog for the chosen repository
RepositorySettingsDialog dlg(this);
dlg.setRepository(item->text(0));
dlg.exec();
ritem->setRsh(dlg.rsh());
ritem->setCompression(dlg.compression());
KConfig *config = CervisiaPart::config();
config->setGroup(QString("Repository-") + repo);
config->writeEntry("rsh", dlg.rsh());
config->writeEntry("Compression", dlg.compression());
}
}
void RepositoryDialog::slotSettingsClicked()
{
slotDoubleClicked(repolist->currentItem());
}
void RepositoryDialog::slotLoginClicked()
{
}
......@@ -317,40 +353,45 @@ void RepositoryDialog::slotLogoutClicked()
}
AddRepositoryDialog::AddRepositoryDialog(QWidget *parent, const char *name)
AddRepositoryDialog::AddRepositoryDialog(const QString &repo, QWidget *parent, const char *name)
: QDialog(parent, name, true)
{
setCaption( i18n("Add Repository") );
setCaption(i18n("Add Repository"));
QBoxLayout *layout = new QVBoxLayout(this, 10);
QLabel *repo_label = new QLabel(i18n("&Repository:"), this);
repo_label->setMinimumSize(repo_label->sizeHint());
layout->addWidget(repo_label);
repo_edit = new KLineEdit(this);
repo_edit->setFocus();
repo_label->setBuddy(repo_edit);
repo_edit->setMinimumSize(repo_edit->sizeHint());
if (!repo.isNull())
{
repo_edit->setText(repo);
repo_edit->setEnabled(false);
}
layout->addWidget(repo_edit);
QLabel *rsh_label = new QLabel(i18n("Use remote &shell: (only for :ext: repositories)"), this);
rsh_label->setMinimumSize(rsh_label->sizeHint());
layout->addWidget(rsh_label);
rsh_edit = new KLineEdit(this);
rsh_label->setBuddy(rsh_edit);
rsh_edit->setMinimumSize(rsh_edit->sizeHint());
layout->addWidget(rsh_edit);
QFrame *frame = new QFrame(this);
frame->setFrameStyle(QFrame::HLine | QFrame::Sunken);
frame->setMinimumHeight(frame->sizeHint().height());
layout->addWidget(frame, 0);
compression_group = new QHButtonGroup(i18n("&Compression Level:"), this);
layout->addWidget(compression_group);
(void) new QRadioButton(i18n("Default"), compression_group);
(void) new QRadioButton(i18n("0"), compression_group);
(void) new QRadioButton(i18n("1"), compression_group);
(void) new QRadioButton(i18n("2"), compression_group);
(void) new QRadioButton(i18n("3"), compression_group);
KButtonBox *buttonbox = new KButtonBox(this);
buttonbox->addStretch();
ok = buttonbox->addButton(i18n("OK"));
QPushButton *ok = buttonbox->addButton(i18n("OK"));
QPushButton *cancel = buttonbox->addButton(i18n("Cancel"));
ok->setDefault(true);
connect( ok, SIGNAL(clicked()), this, SLOT(accept()) );
......@@ -368,7 +409,6 @@ AddRepositoryDialog::AddRepositoryDialog(QWidget *parent, const char *name)
if (options)
resize(options->size);
ok->setEnabled(!repo_edit->text().isEmpty());
}
......@@ -395,18 +435,33 @@ void AddRepositoryDialog::saveOptions(KConfig *config)
{
if (!options)
return;
config->writeEntry("Customized", true);
config->writeEntry("Size", options->size);
}
void AddRepositoryDialog::setRepository(const QString &repo)
{
setCaption(i18n("Repository settings"));
repo_edit->setText(repo);
repo_edit->setEnabled(false);
}
void AddRepositoryDialog::repoChanged()
{
QString repo = repository();
rsh_edit->setEnabled(repo.left(9) != ":pserver:"
&& repo.contains(":"));
ok->setEnabled(!repo.isEmpty());
compression_group->setEnabled(repo.contains(":"));
KConfig *config = CervisiaPart::config();
config->setGroup(QString("Repository-") + repo);
int n = config->readNumEntry("Compression", -1);
compression_group->setButton(n+1);
}
#include "repositorydlg.moc"
......@@ -415,5 +470,3 @@ void AddRepositoryDialog::repoChanged()
// Local Variables:
// c-basic-offset: 4
// End:
/*
/*
* Copyright (C) 1999-2002 Bernd Gehrmann
* bernd@physik.hu-berlin.de
*
......@@ -16,11 +16,11 @@
#define REPOSITORYDLG_H
#include <qdialog.h>
#include <kconfig.h>
#include <qbuttongroup.h>
#include <klineedit.h>
class QPushButton;
class QListViewItem;
class KConfig;
class ListView;
......@@ -29,7 +29,6 @@ class RepositoryDialog : public QDialog
Q_OBJECT
public:
RepositoryDialog( QWidget *parent=0, const char *name=0 );
void readConfigFile();
......@@ -44,11 +43,10 @@ protected:
private slots:
void slotAddClicked();
void slotRemoveClicked();
void slotDoubleClicked(QListViewItem *item);
void slotSettingsClicked();
void slotLoginClicked();
void slotLogoutClicked();
void slotSelectionChanged();
void slotDoubleClicked(QListViewItem *);
private:
struct Options {
......@@ -57,7 +55,6 @@ private:
static Options *options;
ListView *repolist;
QPushButton *removebutton,*settingsbutton ;
};
......@@ -66,13 +63,19 @@ class AddRepositoryDialog : public QDialog
Q_OBJECT
public:
AddRepositoryDialog( QWidget *parent=0, const char *name=0 );
AddRepositoryDialog( const QString &repo, QWidget *parent=0, const char *name=0 );
void setRepository(const QString &repo);
void setRsh(const QString &rsh)
{ rsh_edit->setText(rsh); }
void setCompression(int compression)
{ compression_group->setButton(compression+1); }
QString repository() const
{ return repo_edit->text(); }
QString rsh() const
{ return rsh_edit->text(); }
int compression() const
{ return compression_group->id(compression_group->selected())-1; }
static void loadOptions(KConfig *config);
static void saveOptions(KConfig *config);
......@@ -91,7 +94,7 @@ private:
KLineEdit *repo_edit;
KLineEdit *rsh_edit;
QPushButton *ok;
QButtonGroup *compression_group;
};
#endif
......
/*
* Copyright (C) 2001 Colin MacLeod
* colin.macleod@ivata.com
*
* 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 "repositorysettingsdlg.h"
#include <qhbuttongroup.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <kapplication.h>
#include <kconfig.h>
#include <klocale.h>
#include <kbuttonbox.h>
#include "cervisiapart.h"
#include "repositorysettingsdlg.moc"
RepositorySettingsDialog::RepositorySettingsDialog(QWidget* parent, const char* name)
: QDialog(parent, name, true)
{
if (!name)
setName("RepositorySettingsDialog");
setCaption(i18n("Repository Settings"));
RepositorySettingsDialogLayout = new QVBoxLayout(this);
RepositorySettingsDialogLayout->setSpacing(6);
RepositorySettingsDialogLayout->setMargin(11);
QVBoxLayout* Layout1 = new QVBoxLayout;
Layout1->setSpacing(6);
Layout1->setMargin(0);
// set up a group for all the radio buttons
groupCompression = new QHButtonGroup(i18n("Compression Level"), this);
groupCompression->insert(radioCompressionDefault = new QRadioButton(i18n("Default"), groupCompression), -2);