Gravatar

gravatarconfiguresettingswidget.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "gravatarconfiguresettingswidget.h"
8using namespace Qt::Literals::StringLiterals;
9
10#include "gravatarsettings.h"
11#include <Gravatar/GravatarCache>
12#include <KConfigDialogManager>
13#include <KLocalization>
14#include <KLocalizedString>
15#include <KSeparator>
16#include <QCheckBox>
17#include <QHBoxLayout>
18#include <QLabel>
19#include <QPushButton>
20#include <QSpinBox>
21#include <QVBoxLayout>
22
23using namespace Gravatar;
24
25GravatarConfigureSettingsWidget::GravatarConfigureSettingsWidget(QWidget *parent)
26 : QWidget(parent)
27{
28 auto topLayout = new QVBoxLayout(this);
29 topLayout->setObjectName("mainlayout"_L1);
30 topLayout->setContentsMargins(0, 0, 0, 0);
31 mUseDefaultPixmap = new QCheckBox(i18nc("@option:check", "Use Default Image"), this);
32 mUseDefaultPixmap->setObjectName("kcfg_GravatarUseDefaultImage"_L1);
33 topLayout->addWidget(mUseDefaultPixmap);
34
35 mUseLibravatar = new QCheckBox(i18nc("@option:check", "Use Libravatar"), this);
36 mUseLibravatar->setObjectName("kcfg_LibravatarSupportEnabled"_L1);
37 topLayout->addWidget(mUseLibravatar);
38
39 mFallbackGravatar = new QCheckBox(i18nc("@option:check", "Fallback to Gravatar"), this);
40 mFallbackGravatar->setObjectName("kcfg_FallbackToGravatar"_L1);
41 topLayout->addWidget(mFallbackGravatar);
42 connect(mUseLibravatar, &QCheckBox::toggled, mFallbackGravatar, &QCheckBox::setEnabled);
43 mFallbackGravatar->setEnabled(false);
44
45 auto cacheSizeLayout = new QHBoxLayout;
46 topLayout->addLayout(cacheSizeLayout);
47 auto lab = new QLabel(i18nc("@label:textbox", "Gravatar Cache Size:"), this);
48 lab->setObjectName("gravatarcachesizelabel"_L1);
49 cacheSizeLayout->addWidget(lab);
50
51 mGravatarCacheSize = new QSpinBox(this);
52 mGravatarCacheSize->setMinimum(1);
53 mGravatarCacheSize->setMaximum(9999);
54 KLocalization::setupSpinBoxFormatString(mGravatarCacheSize, ki18ncp("add space before image", "%v image", "%v images"));
55 mGravatarCacheSize->setObjectName("kcfg_GravatarCacheSize"_L1);
56 cacheSizeLayout->addWidget(mGravatarCacheSize);
57 cacheSizeLayout->addStretch();
58
59 auto separator = new KSeparator(this);
60 separator->setObjectName("separator"_L1);
61 topLayout->addWidget(separator);
62
63 auto buttonLayout = new QHBoxLayout;
64 topLayout->addLayout(buttonLayout);
65 mClearGravatarCache = new QPushButton(i18nc("@action:button", "Clear Gravatar Cache"), this);
66 mClearGravatarCache->setObjectName("cleargravatarcachebutton"_L1);
67 buttonLayout->addWidget(mClearGravatarCache);
68 buttonLayout->addStretch();
69
70 separator = new KSeparator(this);
71 separator->setObjectName("separator2"_L1);
72 topLayout->addWidget(separator);
73
74 connect(mClearGravatarCache, &QAbstractButton::clicked, this, &GravatarConfigureSettingsWidget::slotClearGravatarCache);
75
76 m_configDialogManager = new KConfigDialogManager(this, GravatarSettings::self());
77}
78
79GravatarConfigureSettingsWidget::~GravatarConfigureSettingsWidget() = default;
80
81void GravatarConfigureSettingsWidget::slotClearGravatarCache()
82{
83 Gravatar::GravatarCache::self()->clearAllCache();
84}
85
86void GravatarConfigureSettingsWidget::slotRestoreDefault()
87{
88 m_configDialogManager->updateWidgetsDefault();
89}
90
91void GravatarConfigureSettingsWidget::save()
92{
93 m_configDialogManager->updateSettings();
94}
95
96void GravatarConfigureSettingsWidget::load()
97{
98 m_configDialogManager->updateWidgets();
99}
100
101#include "moc_gravatarconfiguresettingswidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KLocalizedString KI18N_EXPORT ki18ncp(const char *context, const char *singular, const char *plural)
void setupSpinBoxFormatString(T *spinBox, const KLocalizedString &formatString)
void clicked(bool checked)
void toggled(bool checked)
void addLayout(QLayout *layout, int stretch)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.