File indexing completed on 2024-05-12 05:44:24

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2009 by Rajko Albrecht  ral@alwins-world.de        *
0003  *   https://kde.org/applications/development/org.kde.kdesvn               *
0004  *                                                                         *
0005  * This program is free software; you can redistribute it and/or           *
0006  * modify it under the terms of the GNU General Public              *
0007  * License as published by the Free Software Foundation; either            *
0008  * version 2.1 of the License, or (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 GNU       *
0013  * General Public License for more details.                         *
0014  *                                                                         *
0015  * You should have received a copy of the GNU General Public        *
0016  * License along with this program (in the file GPL.txt); if not,         *
0017  * write to the Free Software Foundation, Inc., 51 Franklin St,            *
0018  * Fifth Floor, Boston, MA  02110-1301  USA                                *
0019  *                                                                         *
0020  * This software consists of voluntary contributions made by many          *
0021  * individuals.  For exact contribution history, see the revision          *
0022  * history and logs, available at https://commits.kde.org/kdesvn.          *
0023  ***************************************************************************/
0024 #include "dboverview.h"
0025 #include "ui_dboverview.h"
0026 
0027 #include "dbsettings.h"
0028 #include "helpers/kdesvn_debug.h"
0029 #include "helpers/stringhelper.h"
0030 #include "svnqt/cache/DatabaseException.h"
0031 #include "svnqt/cache/LogCache.h"
0032 #include "svnqt/cache/ReposLog.h"
0033 #include "svnqt/client.h"
0034 
0035 #include <QItemSelectionModel>
0036 #include <QPointer>
0037 #include <QStringListModel>
0038 
0039 #include <KLocalizedString>
0040 #include <KMessageBox>
0041 #include <KMessageBox_KDESvnCompat>
0042 
0043 DbOverview::DbOverview(const svn::ClientP &aClient, QWidget *parent)
0044     : KSvnDialog(QLatin1String("db_overview_dlg"), parent)
0045     , m_clientP(aClient)
0046     , m_repo_model(new QStringListModel(this))
0047     , m_ui(new Ui::DBOverView)
0048 {
0049     m_ui->setupUi(this);
0050     setDefaultButton(m_ui->buttonBox->button(QDialogButtonBox::Close));
0051     connect(m_ui->buttonBox->button(QDialogButtonBox::Close), &QAbstractButton::clicked, this, &QDialog::accept);
0052 
0053     enableButtons(false);
0054 
0055     try {
0056         m_repo_model->setStringList(svn::cache::LogCache::self()->cachedRepositories());
0057     } catch (const svn::cache::DatabaseException &e) {
0058         qCDebug(KDESVN_LOG) << e.msg() << Qt::endl;
0059     }
0060 
0061     m_ui->m_ReposListView->setModel(m_repo_model);
0062     QItemSelectionModel *_sel = m_ui->m_ReposListView->selectionModel();
0063     if (_sel) {
0064         connect(_sel, &QItemSelectionModel::selectionChanged, this, &DbOverview::itemActivated);
0065     }
0066     connect(m_ui->m_DeleteCacheButton, &QAbstractButton::clicked, this, &DbOverview::deleteCacheItems);
0067     connect(m_ui->m_DeleteRepositoryButton, &QAbstractButton::clicked, this, &DbOverview::deleteRepository);
0068     connect(m_ui->m_SettingsButton, &QAbstractButton::clicked, this, &DbOverview::repositorySettings);
0069     m_ui->m_StatisticButton->setVisible(false);
0070     // t.b.d
0071     // connect(m_ui->m_StatisticButton, SIGNAL(clicked(bool)),
0072     //        this, SLOT(repositoryStatistics()));
0073 }
0074 
0075 DbOverview::~DbOverview()
0076 {
0077     delete m_ui;
0078 }
0079 
0080 void DbOverview::showDbOverview(const svn::ClientP &aClient, QWidget *parent)
0081 {
0082     //  i18n("Overview about cache database content")
0083     QPointer<DbOverview> dlg(new DbOverview(aClient, parent ? parent : QApplication::activeModalWidget()));
0084     dlg->exec();
0085     delete dlg;
0086 }
0087 
0088 void DbOverview::enableButtons(bool how)
0089 {
0090     m_ui->m_DeleteCacheButton->setEnabled(how);
0091     m_ui->m_DeleteRepositoryButton->setEnabled(how);
0092     m_ui->m_SettingsButton->setEnabled(how);
0093     m_ui->m_StatisticButton->setEnabled(how);
0094 }
0095 
0096 void DbOverview::itemActivated(const QItemSelection &indexes, const QItemSelection &deindexes)
0097 {
0098     Q_UNUSED(deindexes);
0099 
0100     enableButtons(false);
0101     QModelIndexList _indexes = indexes.indexes();
0102     if (_indexes.count() != 1) {
0103         qCDebug(KDESVN_LOG) << "Handle only with single selection" << Qt::endl;
0104         return;
0105     }
0106     genInfo(_indexes[0].data().toString());
0107     enableButtons(true);
0108 }
0109 
0110 void DbOverview::genInfo(const QString &repo)
0111 {
0112     svn::cache::ReposLog rl(m_clientP, repo);
0113     QString msg = i18n("Log cache holds %1 log entries and consumes %2 on disk.", rl.count(), helpers::ByteToString(rl.fileSize()));
0114     m_ui->m_RepostatusBrowser->setText(msg);
0115 }
0116 
0117 QString DbOverview::selectedRepository() const
0118 {
0119     const QModelIndexList _indexes = m_ui->m_ReposListView->selectionModel()->selectedIndexes();
0120     if (_indexes.size() != 1) {
0121         return QString();
0122     }
0123     return _indexes[0].data().toString();
0124 }
0125 
0126 void DbOverview::deleteCacheItems()
0127 {
0128     KMessageBox::ButtonCode i = KMessageBox::questionTwoActions(this,
0129                                                                 i18n("Really clean cache for repository\n%1?", selectedRepository()),
0130                                                                 i18n("Clean repository cache"),
0131                                                                 KGuiItem(i18nc("@action:button", "Delete Cache")),
0132                                                                 KStandardGuiItem::cancel());
0133     if (i != KMessageBox::PrimaryAction) {
0134         return;
0135     }
0136     try {
0137         svn::cache::ReposLog rl(m_clientP, selectedRepository());
0138         rl.cleanLogEntries();
0139     } catch (const svn::cache::DatabaseException &e) {
0140         qCDebug(KDESVN_LOG) << e.msg();
0141     }
0142     genInfo(selectedRepository());
0143 }
0144 
0145 void DbOverview::deleteRepository()
0146 {
0147     KMessageBox::ButtonCode i = KMessageBox::questionTwoActions(this,
0148                                                                 i18n("Really clean cache and data for repository\n%1?", selectedRepository()),
0149                                                                 i18n("Delete repository"),
0150                                                                 KGuiItem(i18nc("@action:button", "Delete Repository")),
0151                                                                 KStandardGuiItem::cancel());
0152     if (i != KMessageBox::PrimaryAction) {
0153         return;
0154     }
0155     try {
0156         svn::cache::LogCache::self()->deleteRepository(selectedRepository());
0157         m_repo_model->setStringList(svn::cache::LogCache::self()->cachedRepositories());
0158     } catch (const svn::cache::DatabaseException &e) {
0159         qCDebug(KDESVN_LOG) << e.msg() << Qt::endl;
0160     }
0161 }
0162 
0163 void DbOverview::repositorySettings()
0164 {
0165     DbSettings::showSettings(selectedRepository(), this);
0166 }
0167 
0168 #include "moc_dboverview.cpp"