Commit 904bd796 authored by Laurent Montel's avatar Laurent Montel 😁

Improve++

parent ce015267
......@@ -15,6 +15,7 @@ find_package(KF5 REQUIRED COMPONENTS
I18n
GuiAddons
IconThemes
WidgetsAddons
KIO)
include(FeatureSummary)
......
......@@ -5,6 +5,8 @@ set(full_source_file
../src/customdebugsettingspage.cpp
../src/kdeapplicationdebugsettingpage.cpp
../src/kdebugsettingsutil.cpp
../src/configurecustomsettingdialog.cpp
../src/configurecustomsettingwidget.cpp
)
# convenience macro to add qtest unit tests
......@@ -19,12 +21,13 @@ macro(add_unittest _source _additionalsource)
KF5::I18n
Qt5::Widgets
KF5::ConfigCore
KF5::WidgetsAddons
)
endmacro ()
add_unittest( kdebugsettingsdialogtest.cpp "${full_source_file}")
add_unittest( kdeapplicationdebugsettingpagetest.cpp "../src/kdeapplicationdebugsettingpage.cpp;../src/kdeapplicationlistwidget.cpp")
add_unittest( customdebugsettingspagetest.cpp "../src/customdebugsettingspage.cpp")
add_unittest( customdebugsettingspagetest.cpp "../src/customdebugsettingspage.cpp;../src/configurecustomsettingdialog.cpp;../src/configurecustomsettingwidget.cpp;../src/kdebugsettingsutil.cpp")
add_unittest( kdeapplicationlistwidgettest.cpp "../src/kdeapplicationlistwidget.cpp")
add_unittest( configurecustomsettingdialogtest.cpp "../src/configurecustomsettingdialog.cpp;../src/configurecustomsettingwidget.cpp;../src/kdebugsettingsutil.cpp")
add_unittest( configurecustomsettingwidgettest.cpp "../src/configurecustomsettingwidget.cpp;../src/kdebugsettingsutil.cpp")
......
......@@ -22,6 +22,7 @@
#include "../src/customdebugsettingspage.h"
#include <QLabel>
#include <QListWidget>
#include <QPushButton>
#include <qtest.h>
CustomDebugSettingsPageTest::CustomDebugSettingsPageTest(QObject *parent)
......@@ -45,6 +46,19 @@ void CustomDebugSettingsPageTest::shouldHaveDefaultValue()
QListWidget *listWidget = page.findChild<QListWidget *>(QStringLiteral("custom_listwidget"));
QVERIFY(listWidget);
QCOMPARE(listWidget->count(), 0);
QPushButton *addButton = page.findChild<QPushButton *>(QStringLiteral("add_rule"));
QVERIFY(addButton);
QVERIFY(addButton->isEnabled());
QPushButton *editButton = page.findChild<QPushButton *>(QStringLiteral("edit_rule"));
QVERIFY(editButton);
QVERIFY(!editButton->isEnabled());
QPushButton *removeButton = page.findChild<QPushButton *>(QStringLiteral("remove_rule"));
QVERIFY(removeButton);
QVERIFY(!removeButton->isEnabled());
}
QTEST_MAIN(CustomDebugSettingsPageTest)
# Format : logname<tab>description
# kdepim
log_sieveeditor kdepim (sieveeditor)
log_ldapclient kdepim (ldapclient)
log_libkdepim kdepim (libkdepim)
log_akonadinext kdepim (akonadinext)
log_mailimporter kdepim (mailimporter)
log_korganizer kdepim (korganizer)
log_libksieve kdepim (libksieve)
log_sendlateragent kdepim (sendlateragent)
log_archivemailagent kdepim (archivemailagent)
log_followupreminderagent kdepim (followupreminderagent)
log_mailcommon kdepim (mailcommon)
log_akregator kdepim (akregator)
log_messagecomposer kdepim (messagecomposer)
log_kwatchgnupg kdepim (kwatchgnupg)
log_templateparser kdepim (templateparser)
log_koalarmclient kdepim (koalarmclient)
log_blogilo kdepim (blogilo)
log_messagelist kdepim (messagelist
log_accountwizard kdepim (accountwizard)
log_kleo_ui kdepim (kleo_ui)
log_gpgme_backend kdepim (gpgme_backend)
log_storageservicemanager kdepim (storageservicemanager)
log_incidenceeditor kdepim (incidenceeditor)
log_calendarsupport kdepim (calendarsupport)
log_kpgp kdepim (kpgp)
log_vcard kdepim (vcard)
log_text_calendar kdepim (text_calendar)
log_ms_tnef kdepim (ms_tnef)
log_pimcommon kdepim (pimcommon)
log_knotes kdepim (knotes)
log_composereditorng kdepim (composereditorng)
log_akonadiconsole kdepim (akonadiconsole)
log_messacore kdepim (messacore)
log_kmail kdepim (kmail)
log_noteshared kdepim (noteshared)
log_kalarm kdepim (kalarm)
log_autostart_kalarm kdepim (autostart_kalarm)
log_calendarview kdepim (calendarview)
log_messageviewer kdepim (messageviewer)
log_pimsettingexporter kdepim (pimsettingexporter)
log_kaddressbook kdepim (kaddressbook)
log_importwizard kdepim (importwizard)
......@@ -11,7 +11,7 @@ set(kdebugsettings_SRCS
add_executable(kdebugsettings ${kdebugsettings_SRCS})
target_link_libraries(kdebugsettings Qt5::Widgets KF5::I18n KF5::DBusAddons KF5::CoreAddons KF5::ConfigCore)
target_link_libraries(kdebugsettings Qt5::Widgets KF5::I18n KF5::DBusAddons KF5::CoreAddons KF5::ConfigCore KF5::WidgetsAddons)
install(TARGETS kdebugsettings ${INSTALL_TARGETS_DEFAULT_ARGS} )
......
......@@ -19,11 +19,15 @@
*/
#include "customdebugsettingspage.h"
#include "configurecustomsettingdialog.h"
#include <KLocalizedString>
#include <KMessageBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QListWidget>
#include <QLabel>
#include <QPushButton>
#include <QPointer>
CustomDebugSettingsPage::CustomDebugSettingsPage(QWidget *parent)
: QWidget(parent)
......@@ -40,7 +44,29 @@ CustomDebugSettingsPage::CustomDebugSettingsPage(QWidget *parent)
mListWidget = new QListWidget;
mListWidget->setObjectName(QStringLiteral("custom_listwidget"));
connect(mListWidget, &QListWidget::itemSelectionChanged, this, &CustomDebugSettingsPage::updateButtons);
vbox->addWidget(mListWidget);
QVBoxLayout *buttonLayout = new QVBoxLayout;
mainLayout->addLayout(buttonLayout);
mAddRule = new QPushButton(i18n("Add..."));
mAddRule->setObjectName(QStringLiteral("add_rule"));
buttonLayout->addWidget(mAddRule);
connect(mAddRule, &QAbstractButton::clicked, this, &CustomDebugSettingsPage::slotAddRule);
mEditRule = new QPushButton(i18n("Edit..."));;
mEditRule->setObjectName(QStringLiteral("edit_rule"));
buttonLayout->addWidget(mEditRule);
connect(mEditRule, &QAbstractButton::clicked, this, &CustomDebugSettingsPage::slotEditRule);
mRemoveRule = new QPushButton(i18n("Remove..."));;
mRemoveRule->setObjectName(QStringLiteral("remove_rule"));
buttonLayout->addWidget(mRemoveRule);
buttonLayout->addStretch();
connect(mRemoveRule, &QAbstractButton::clicked, this, &CustomDebugSettingsPage::slotRemoveRule);
updateButtons();
}
CustomDebugSettingsPage::~CustomDebugSettingsPage()
......@@ -48,8 +74,57 @@ CustomDebugSettingsPage::~CustomDebugSettingsPage()
}
void CustomDebugSettingsPage::fillList()
void CustomDebugSettingsPage::updateButtons()
{
mEditRule->setEnabled(mListWidget->currentItem());
mRemoveRule->setEnabled(mListWidget->currentItem());
}
void CustomDebugSettingsPage::fillList(const Category::List &list)
{
//TODO
}
QStringList CustomDebugSettingsPage::rules()
{
QStringList lst;
for(int i = 0; i < mListWidget->count(); ++i) {
lst.append(mListWidget->item(i)->text());
}
return lst;
}
void CustomDebugSettingsPage::slotRemoveRule()
{
//TODO add MessageBox to avoid to remove it.
QListWidgetItem *item = mListWidget->currentItem();
delete item;
}
void CustomDebugSettingsPage::slotEditRule()
{
QListWidgetItem *item = mListWidget->currentItem();
if (item) {
QPointer<ConfigureCustomSettingDialog> dlg = new ConfigureCustomSettingDialog(this);
dlg->setRule(item->text());
if (dlg->exec()) {
const QString ruleStr = dlg->rule();
if (!ruleStr.isEmpty()) {
item->setText(dlg->rule());
}
}
delete dlg;
}
}
void CustomDebugSettingsPage::slotAddRule()
{
QPointer<ConfigureCustomSettingDialog> dlg = new ConfigureCustomSettingDialog(this);
if (dlg->exec()) {
const QString ruleStr = dlg->rule();
if (!ruleStr.isEmpty()) {
mListWidget->addItem(ruleStr);
}
}
delete dlg;
}
......@@ -22,6 +22,7 @@
#define CUSTOMDEBUGSETTINGSPAGE_H
#include <QWidget>
#include "kdebugsettingsdialog.h"
class QListWidget;
class QPushButton;
class CustomDebugSettingsPage : public QWidget
......@@ -31,9 +32,13 @@ public:
explicit CustomDebugSettingsPage(QWidget *parent = Q_NULLPTR);
~CustomDebugSettingsPage();
//TODO
void fillList();
void fillList(const Category::List &list);
QStringList rules();
private slots:
void slotRemoveRule();
void slotAddRule();
void slotEditRule();
void updateButtons();
private:
QListWidget *mListWidget;
QPushButton *mAddRule;
......
......@@ -68,3 +68,8 @@ void KDeApplicationDebugSettingPage::fillList(const Category::List &list)
{
mListWidget->fillList(list);
}
QStringList KDeApplicationDebugSettingPage::rules()
{
return mListWidget->rules();
}
......@@ -33,6 +33,7 @@ public:
explicit KDeApplicationDebugSettingPage(QWidget *parent = Q_NULLPTR);
~KDeApplicationDebugSettingPage();
void fillList(const Category::List &list);
QStringList rules();
private slots:
void slotSelectAll();
void slotDeselectAll();
......
......@@ -32,19 +32,35 @@ KDeApplicationListWidget::~KDeApplicationListWidget()
}
QStringList KDeApplicationListWidget::rules()
{
return QStringList();
}
void KDeApplicationListWidget::selectAllDebugCategories()
{
//TODO
for (int i = 0; i < count(); ++i) {
QListWidgetItem *itemWidget = item(i);
itemWidget->setCheckState(Qt::Checked);
}
}
void KDeApplicationListWidget::deSelectAllDebugCategories()
{
//TODO
for (int i = 0; i < count(); ++i) {
QListWidgetItem *itemWidget = item(i);
itemWidget->setCheckState(Qt::Unchecked);
}
}
void KDeApplicationListWidget::fillList(const Category::List &list)
{
//TODO
Q_FOREACH( const Category &cat, list) {
KDeApplicationListWidgetItem *item = new KDeApplicationListWidgetItem(this);
item->setText(cat.description);
item->setCategory(cat.logName);
item->setCheckState(cat.enabled ? Qt::Checked : Qt::Unchecked);
}
}
KDeApplicationListWidgetItem::KDeApplicationListWidgetItem(QListWidget *parent)
......
......@@ -44,6 +44,9 @@ public:
explicit KDeApplicationListWidget(QWidget *parent = Q_NULLPTR);
~KDeApplicationListWidget();
QStringList rules();
void deSelectAllDebugCategories();
void selectAllDebugCategories();
void fillList(const Category::List &list);
......
......@@ -50,7 +50,7 @@ KDebugSettingsDialog::KDebugSettingsDialog(QWidget *parent)
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
buttonBox->setObjectName(QStringLiteral("buttonbox"));
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::accepted, this, &KDebugSettingsDialog::slotAccepted);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
mainLayout->addWidget(buttonBox);
readConfig();
......@@ -86,8 +86,19 @@ void KDebugSettingsDialog::readCategoriesFiles()
// qt logging.ini
const QString envPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("QtProject/qtlogging.ini"));
const Category::List customCategories = KDebugSettingsUtil::readLoggingQtCategories(envPath);
if (!envPath.isEmpty()) {
const Category::List qtCategories = KDebugSettingsUtil::readLoggingQtCategories(envPath);
}
mKdeApplicationSettingsPage->fillList(categories);
//TODO
}
void KDebugSettingsDialog::slotAccepted()
{
//Save Rules
QStringList lstKde = mKdeApplicationSettingsPage->rules();
QStringList lstCustom = mCustomSettingsPage->rules();
//Save in files.
accept();
}
......@@ -58,6 +58,8 @@ public:
explicit KDebugSettingsDialog(QWidget *parent = Q_NULLPTR);
~KDebugSettingsDialog();
private slots:
void slotAccepted();
private:
void readCategoriesFiles();
void saveConfig();
......
......@@ -62,7 +62,8 @@ Category::List KDebugSettingsUtil::readLoggingCategories(const QString &filename
while (!ts.atEnd()) {
data = ts.readLine().simplified();
const Category category = parseLineKdeLoggingCategory(data);
categoriesList.append(category);
if (category.isValid())
categoriesList.append(category);
}
}
......
......@@ -46,5 +46,7 @@ int main(int argc, char **argv)
KDBusService service(KDBusService::Unique);
KDebugSettingsDialog *dialog = new KDebugSettingsDialog;
return dialog->exec();
int ret = dialog->exec();
delete dialog;
return ret;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment