diff --git a/src/libkdepim/ldap/kcmldap.cpp b/src/libkdepim/ldap/kcmldap.cpp index e716726..c80328c 100644 --- a/src/libkdepim/ldap/kcmldap.cpp +++ b/src/libkdepim/ldap/kcmldap.cpp @@ -1,378 +1,378 @@ /* This file is part of libkldap. Copyright (c) 2002-2009 Tobias Koenig Copyright (C) 2013-2018 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kcmldap_p.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ldapclientsearch.h" #include "ldapclientsearchconfig.h" #include #include "addhostdialog.h" K_PLUGIN_CLASS_WITH_JSON(KCMLdap, "kcmldap.json") class LDAPItem : public QListWidgetItem { public: LDAPItem(QListWidget *parent, const KLDAP::LdapServer &server, bool isActive = false) : QListWidgetItem(parent, QListWidgetItem::UserType) , mIsActive(isActive) { setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); setCheckState(isActive ? Qt::Checked : Qt::Unchecked); setServer(server); } void setServer(const KLDAP::LdapServer &server) { mServer = server; setText(mServer.host()); } const KLDAP::LdapServer &server() const { return mServer; } void setIsActive(bool isActive) { mIsActive = isActive; } bool isActive() const { return mIsActive; } private: KLDAP::LdapServer mServer; bool mIsActive = false; }; KCMLdap::KCMLdap(QWidget *parent, const QVariantList &) : KCModule(parent) { setButtons(KCModule::Apply); KAboutData *about = new KAboutData(QStringLiteral("kcmldap"), i18n("kcmldap"), QString(), i18n("LDAP Server Settings"), KAboutLicense::LGPL, i18n("(c) 2009 - 2010 Tobias Koenig")); about->addAuthor(i18n("Tobias Koenig"), QString(), QStringLiteral("tokoe@kde.org")); setAboutData(about); mClientSearchConfig = new KLDAP::LdapClientSearchConfig; initGUI(); connect(mHostListView, &QListWidget::currentItemChanged, this, &KCMLdap::slotSelectionChanged); connect(mHostListView, &QListWidget::itemDoubleClicked, this, &KCMLdap::slotEditHost); connect(mHostListView, &QListWidget::itemClicked, this, &KCMLdap::slotItemClicked); connect(mUpButton, &QToolButton::clicked, this, &KCMLdap::slotMoveUp); connect(mDownButton, &QToolButton::clicked, this, &KCMLdap::slotMoveDown); } KCMLdap::~KCMLdap() { delete mClientSearchConfig; } void KCMLdap::slotSelectionChanged(QListWidgetItem *item) { bool state = (item != nullptr); mEditButton->setEnabled(state); mRemoveButton->setEnabled(state); mDownButton->setEnabled(item && (mHostListView->row(item) != (mHostListView->count() - 1))); mUpButton->setEnabled(item && (mHostListView->row(item) != 0)); } void KCMLdap::slotItemClicked(QListWidgetItem *item) { LDAPItem *ldapItem = dynamic_cast(item); if (!ldapItem) { return; } if ((ldapItem->checkState() == Qt::Checked) != ldapItem->isActive()) { Q_EMIT changed(true); ldapItem->setIsActive(ldapItem->checkState() == Qt::Checked); } } void KCMLdap::slotAddHost() { KLDAP::LdapServer server; KLDAP::AddHostDialog dlg(&server, dialogParent()); if (dlg.exec() && !server.host().trimmed().isEmpty()) { //krazy:exclude=crashy new LDAPItem(mHostListView, server); Q_EMIT changed(true); } } void KCMLdap::slotEditHost() { LDAPItem *item = dynamic_cast(mHostListView->currentItem()); if (!item) { return; } KLDAP::LdapServer server = item->server(); KLDAP::AddHostDialog dlg(&server, dialogParent()); dlg.setWindowTitle(i18n("Edit Host")); if (dlg.exec() && !server.host().isEmpty()) { //krazy:exclude=crashy item->setServer(server); Q_EMIT changed(true); } } void KCMLdap::slotRemoveHost() { QListWidgetItem *item = mHostListView->currentItem(); if (!item) { return; } LDAPItem *ldapItem = dynamic_cast(item); if (KMessageBox::No == KMessageBox::questionYesNo(this, i18n("Do you want to remove setting for host \"%1\"?", ldapItem->server().host()), i18n("Remove Host"))) { return; } delete mHostListView->takeItem(mHostListView->currentRow()); slotSelectionChanged(mHostListView->currentItem()); Q_EMIT changed(true); } static void swapItems(LDAPItem *item, LDAPItem *other) { KLDAP::LdapServer server = item->server(); bool isActive = item->isActive(); item->setServer(other->server()); item->setIsActive(other->isActive()); item->setCheckState(other->isActive() ? Qt::Checked : Qt::Unchecked); other->setServer(server); other->setIsActive(isActive); other->setCheckState(isActive ? Qt::Checked : Qt::Unchecked); } void KCMLdap::slotMoveUp() { const QList selectedItems = mHostListView->selectedItems(); if (selectedItems.isEmpty()) { return; } LDAPItem *item = static_cast(mHostListView->selectedItems().first()); if (!item) { return; } LDAPItem *above = static_cast(mHostListView->item(mHostListView->row(item) - 1)); if (!above) { return; } swapItems(item, above); mHostListView->setCurrentItem(above); above->setSelected(true); Q_EMIT changed(true); } void KCMLdap::slotMoveDown() { const QList selectedItems = mHostListView->selectedItems(); if (selectedItems.isEmpty()) { return; } LDAPItem *item = static_cast(mHostListView->selectedItems().first()); if (!item) { return; } LDAPItem *below = static_cast(mHostListView->item(mHostListView->row(item) + 1)); if (!below) { return; } swapItems(item, below); mHostListView->setCurrentItem(below); below->setSelected(true); Q_EMIT changed(true); } void KCMLdap::load() { mHostListView->clear(); KConfig *config = KLDAP::LdapClientSearchConfig::config(); KConfigGroup group(config, "LDAP"); - uint count = group.readEntry("NumSelectedHosts", 0); - for (uint i = 0; i < count; ++i) { + int count = group.readEntry("NumSelectedHosts", 0); + for (int i = 0; i < count; ++i) { KLDAP::LdapServer server; mClientSearchConfig->readConfig(server, group, i, true); LDAPItem *item = new LDAPItem(mHostListView, server, true); item->setCheckState(Qt::Checked); } count = group.readEntry("NumHosts", 0); - for (uint i = 0; i < count; ++i) { + for (int i = 0; i < count; ++i) { KLDAP::LdapServer server; mClientSearchConfig->readConfig(server, group, i, false); new LDAPItem(mHostListView, server); } Q_EMIT changed(false); } void KCMLdap::save() { mClientSearchConfig->clearWalletPassword(); KConfig *config = KLDAP::LdapClientSearchConfig::config(); config->deleteGroup("LDAP"); KConfigGroup group(config, "LDAP"); - uint selected = 0; - uint unselected = 0; + int selected = 0; + int unselected = 0; for (int i = 0; i < mHostListView->count(); ++i) { LDAPItem *item = dynamic_cast(mHostListView->item(i)); if (!item) { continue; } KLDAP::LdapServer server = item->server(); if (item->checkState() == Qt::Checked) { mClientSearchConfig->writeConfig(server, group, selected, true); selected++; } else { mClientSearchConfig->writeConfig(server, group, unselected, false); unselected++; } } group.writeEntry("NumSelectedHosts", selected); group.writeEntry("NumHosts", unselected); config->sync(); Q_EMIT changed(false); } void KCMLdap::initGUI() { QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(0); QGroupBox *groupBox = new QGroupBox(i18n("LDAP Servers"), this); QVBoxLayout *mainLayout = new QVBoxLayout(groupBox); // Contents of the QVGroupBox: label and hbox QLabel *label = new QLabel(i18n("Check all servers that should be used:")); mainLayout->addWidget(label); QWidget *hBox = new QWidget; QHBoxLayout *hBoxHBoxLayout = new QHBoxLayout(hBox); hBoxHBoxLayout->setMargin(0); hBoxHBoxLayout->setSpacing(6); mainLayout->addWidget(hBox); // Contents of the hbox: listview and up/down buttons on the right (vbox) mHostListView = new QListWidget(hBox); hBoxHBoxLayout->addWidget(mHostListView); mHostListView->setSortingEnabled(false); QWidget *upDownBox = new QWidget(hBox); QVBoxLayout *upDownBoxVBoxLayout = new QVBoxLayout(upDownBox); upDownBoxVBoxLayout->setMargin(0); hBoxHBoxLayout->addWidget(upDownBox); upDownBoxVBoxLayout->setSpacing(6); mUpButton = new QToolButton(upDownBox); upDownBoxVBoxLayout->addWidget(mUpButton); mUpButton->setIcon(QIcon::fromTheme(QStringLiteral("go-up"))); mUpButton->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mUpButton->setEnabled(false); // b/c no item is selected yet mDownButton = new QToolButton(upDownBox); upDownBoxVBoxLayout->addWidget(mDownButton); mDownButton->setIcon(QIcon::fromTheme(QStringLiteral("go-down"))); mDownButton->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall)); mDownButton->setEnabled(false); // b/c no item is selected yet QWidget *spacer = new QWidget(upDownBox); upDownBoxVBoxLayout->addWidget(spacer); upDownBoxVBoxLayout->setStretchFactor(spacer, 100); layout->addWidget(groupBox); QDialogButtonBox *buttons = new QDialogButtonBox(this); QPushButton *add = buttons->addButton(i18n("&Add Host..."), QDialogButtonBox::ActionRole); connect(add, &QPushButton::clicked, this, &KCMLdap::slotAddHost); mEditButton = buttons->addButton(i18n("&Edit Host..."), QDialogButtonBox::ActionRole); connect(mEditButton, &QPushButton::clicked, this, &KCMLdap::slotEditHost); mEditButton->setEnabled(false); mRemoveButton = buttons->addButton(i18n("&Remove Host"), QDialogButtonBox::ActionRole); connect(mRemoveButton, &QPushButton::clicked, this, &KCMLdap::slotRemoveHost); mRemoveButton->setEnabled(false); buttons->layout(); layout->addWidget(buttons); resize(QSize(460, 300).expandedTo(sizeHint())); } QWidget *KCMLdap::dialogParent() { return this; } #include "kcmldap.moc" diff --git a/src/libkdepim/prefs/kprefsdialog.h b/src/libkdepim/prefs/kprefsdialog.h index 80512e9..a0e6aea 100644 --- a/src/libkdepim/prefs/kprefsdialog.h +++ b/src/libkdepim/prefs/kprefsdialog.h @@ -1,813 +1,813 @@ /* This file is part of libkdepim. Copyright (c) 2001-2003 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer Copyright (C) 2005,2008,2011 Allen Winter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEPIM_KPREFSDIALOG_H #define KDEPIM_KPREFSDIALOG_H #include "kdepim_export.h" #include #include #include #include #include #include class KColorButton; class KComboBox; class KDateComboBox; class KTimeComboBox; class KUrlRequester; class QCheckBox; class QLabel; class QSpinBox; class QTimeEdit; class QButtonGroup; class QGroupBox; namespace KPIM { /** @short Base class for GUI control elements used by @ref KPrefsDialog. @author Cornelius Schumacher @see KPrefsDialog This class provides the interface for the GUI control elements used by KPrefsDialog. The control element consists of a set of widgets for handling a certain type of configuration information. */ class KDEPIM_EXPORT KPrefsWid : public QObject { Q_OBJECT public: /** This function is called to read value of the setting from the stored configuration and display it in the widget. */ virtual void readConfig() = 0; /** This function is called to write the current setting of the widget to the stored configuration. */ virtual void writeConfig() = 0; /** Return a list of widgets used by this control element. */ virtual QList widgets() const; Q_SIGNALS: /** Emitted when widget value has changed. */ void changed(); }; /** @short Widgets for bool settings in @ref KPrefsDialog. This class provides a control element for configuring bool values. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. */ class KDEPIM_EXPORT KPrefsWidBool : public KPrefsWid { Q_OBJECT public: /** Create a bool value control element consisting of a QCheckbox. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ explicit KPrefsWidBool(KConfigSkeleton::ItemBool *item, QWidget *parent = nullptr); /** Return the QCheckbox used by this control element. */ QCheckBox *checkBox(); void readConfig() override; void writeConfig() override; QList widgets() const override; private: KConfigSkeleton::ItemBool *mItem = nullptr; QCheckBox *mCheck = nullptr; }; /** @short Widgets for int settings in @ref KPrefsDialog. This class provides a control element for configuring integer values. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. */ class KDEPIM_EXPORT KPrefsWidInt : public KPrefsWid { Q_OBJECT public: /** Create a integer value control element consisting of a label and a spinbox. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ explicit KPrefsWidInt(KConfigSkeleton::ItemInt *item, QWidget *parent = nullptr); /** Return QLabel used by this control element. */ QLabel *label() const; /** Return the QSpinBox used by this control element. */ QSpinBox *spinBox(); void readConfig() override; void writeConfig() override; QList widgets() const override; private: KConfigSkeleton::ItemInt *mItem = nullptr; QLabel *mLabel = nullptr; QSpinBox *mSpin = nullptr; }; /** @short Widgets for time settings in @ref KPrefsDialog. This class provides a control element for configuring time values. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. */ class KDEPIM_EXPORT KPrefsWidTime : public KPrefsWid { Q_OBJECT public: /** Create a time value control element consisting of a label and a spinbox. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ explicit KPrefsWidTime(KConfigSkeleton::ItemDateTime *item, QWidget *parent = nullptr); /** Return QLabel used by this widget. */ QLabel *label(); /** Return KTimeComboBox used by this widget. */ KTimeComboBox *timeEdit(); void readConfig() override; void writeConfig() override; private: KConfigSkeleton::ItemDateTime *mItem = nullptr; QLabel *mLabel = nullptr; KTimeComboBox *mTimeEdit = nullptr; }; /** @short Widgets for duration settings in @ref KPrefsDialog. This class provides a control element for configuring duration values. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. */ class KDEPIM_EXPORT KPrefsWidDuration : public KPrefsWid { Q_OBJECT public: /** Create a duration value control element consisting of a label and a spinbox. @param item The KConfigSkeletonItem representing the preferences entry. @param format display format. default is "hh:mm:ss" @param parent Parent widget. */ explicit KPrefsWidDuration(KConfigSkeleton::ItemDateTime *item, const QString &format, QWidget *parent = nullptr); /** Return QLabel used by this widget. */ QLabel *label(); /** Return QSpinBox used by this widget. */ QTimeEdit *timeEdit(); void readConfig() override; void writeConfig() override; private: KConfigSkeleton::ItemDateTime *mItem = nullptr; QLabel *mLabel = nullptr; QTimeEdit *mTimeEdit = nullptr; }; /** @short Widgets for time settings in @ref KPrefsDialog. This class provides a control element for configuring date values. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. */ class KDEPIM_EXPORT KPrefsWidDate : public KPrefsWid { Q_OBJECT public: /** Create a time value control element consisting of a label and a date box. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ explicit KPrefsWidDate(KConfigSkeleton::ItemDateTime *item, QWidget *parent = nullptr); /** Return QLabel used by this widget. */ QLabel *label(); /** Return KDateComboBox used by this widget. */ KDateComboBox *dateEdit(); void readConfig() override; void writeConfig() override; private: KConfigSkeleton::ItemDateTime *mItem = nullptr; QLabel *mLabel = nullptr; KDateComboBox *mDateEdit = nullptr; }; /** @short Widgets for color settings in @ref KPrefsDialog. This class provides a control element for configuring color values. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. */ class KDEPIM_EXPORT KPrefsWidColor : public KPrefsWid { Q_OBJECT public: /** Create a color value control element consisting of a test field and a button for opening a color dialog. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ explicit KPrefsWidColor(KConfigSkeleton::ItemColor *item, QWidget *parent = nullptr); /** Destruct color setting widget. */ - ~KPrefsWidColor(); + ~KPrefsWidColor() override; /** Return QLabel for the button */ QLabel *label(); /** Return button opening the color dialog. */ KColorButton *button(); void readConfig() override; void writeConfig() override; private: KConfigSkeleton::ItemColor *mItem = nullptr; QLabel *mLabel = nullptr; KColorButton *mButton = nullptr; }; /** @short Widgets for font settings in @ref KPrefsDialog. This class provides a control element for configuring font values. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. */ class KDEPIM_EXPORT KPrefsWidFont : public KPrefsWid { Q_OBJECT public: /** Create a font value control element consisting of a test field and a button for opening a font dialog. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. @param sampleText Sample text for previewing the selected font. */ explicit KPrefsWidFont(KConfigSkeleton::ItemFont *item, QWidget *parent = nullptr, const QString &sampleText = QString()); /** Destruct font setting widget. */ - ~KPrefsWidFont(); + ~KPrefsWidFont() override; /** Return QLabel. */ QLabel *label(); /** Return QFrame used as preview field. */ QFrame *preview(); /** Return button opening the font dialog. */ QPushButton *button(); void readConfig() override; void writeConfig() override; protected Q_SLOTS: void selectFont(); private: KConfigSkeleton::ItemFont *mItem = nullptr; QLabel *mLabel = nullptr; QLabel *mPreview = nullptr; QPushButton *mButton = nullptr; }; /** @short Widgets for settings represented by a group of radio buttons in @ref KPrefsDialog. This class provides a control element for configuring selections. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. The setting is interpreted as an int value, corresponding to the position of the radio button. The position of the button is defined by the sequence of @ref addRadio() calls, starting with 0. */ class KDEPIM_EXPORT KPrefsWidRadios : public KPrefsWid { Q_OBJECT public: /** Create a control element for selection of an option. It consists of a box with several radio buttons. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ explicit KPrefsWidRadios(KConfigSkeleton::ItemEnum *item, QWidget *parent = nullptr); - virtual ~KPrefsWidRadios(); + ~KPrefsWidRadios() override; /** Add a radio button. @param value The enum value represented by this radio button. @param text Text of the button. @param toolTip ToolTip help for the button. @param whatsThis What's This help for the button. */ void addRadio(int value, const QString &text, const QString &toolTip = QString(), const QString &whatsThis = QString()); /** Return the box widget used by this widget. */ QGroupBox *groupBox() const; void readConfig() override; void writeConfig() override; QList widgets() const override; private: KConfigSkeleton::ItemEnum *mItem = nullptr; QGroupBox *mBox = nullptr; QButtonGroup *mGroup = nullptr; }; /** @short Widgets for settings represented by a combo box in @ref KPrefsDialog. This class provides a control element for configuring selections. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. The setting is interpreted as an int value, corresponding to the index in the combo box. */ class KDEPIM_EXPORT KPrefsWidCombo : public KPrefsWid { Q_OBJECT public: /** Create a control element for selection of an option. It consists of a combo box. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ explicit KPrefsWidCombo(KConfigSkeleton::ItemEnum *item, QWidget *parent); - virtual ~KPrefsWidCombo(); + ~KPrefsWidCombo() override; void readConfig() override; void writeConfig() override; KComboBox *comboBox(); QList widgets() const override; /** Return QLabel used by this control element. */ QLabel *label() const; private: KConfigSkeleton::ItemEnum *mItem = nullptr; KComboBox *mCombo = nullptr; QLabel *mLabel = nullptr; }; /** @short Widgets for string settings in @ref KPrefsDialog. This class provides a control element for configuring string values. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. */ class KDEPIM_EXPORT KPrefsWidString : public KPrefsWid { Q_OBJECT public: /** Create a string value control element consisting of a test label and a line edit. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. @param echomode Describes how a line edit should display its contents. */ explicit KPrefsWidString(KConfigSkeleton::ItemString *item, QWidget *parent = nullptr, KLineEdit::EchoMode echomode = KLineEdit::Normal); /** Destructor. */ - virtual ~KPrefsWidString(); + ~KPrefsWidString() override; /** Return QLabel used by this widget. */ QLabel *label(); /** Return KLineEdit used by this widget. */ KLineEdit *lineEdit(); void readConfig() override; void writeConfig() override; QList widgets() const override; private: KConfigSkeleton::ItemString *mItem = nullptr; QLabel *mLabel = nullptr; KLineEdit *mEdit = nullptr; }; /** @short Widgets for string settings in @ref KPrefsDialog. This class provides a control element for configuring string values. It is meant to be used by KPrefsDialog. The user is responsible for the layout management. */ class KDEPIM_EXPORT KPrefsWidPath : public KPrefsWid { Q_OBJECT public: /** Create a string value control element consisting of a test label and a line edit. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. @param filter URLRequester filter @param mode Describes how a line edit should display its contents. */ explicit KPrefsWidPath(KConfigSkeleton::ItemPath *item, QWidget *parent = nullptr, const QString &filter = QString(), KFile::Modes = KFile::File); /** Destructor. */ - virtual ~KPrefsWidPath(); + ~KPrefsWidPath() override; /** Return QLabel used by this widget. */ QLabel *label(); /** Return KUrlRequester used by this widget. */ KUrlRequester *urlRequester(); void readConfig() override; void writeConfig() override; QList widgets() const override; private: KConfigSkeleton::ItemPath *mItem = nullptr; QLabel *mLabel = nullptr; KUrlRequester *mURLRequester = nullptr; }; /** @short Class for managing KPrefsWid objects. This class manages standard configuration widgets provided bz the KPrefsWid subclasses. It handles creation, loading, saving and default values in a transparent way. The user has to add the widgets by the corresponding addWid functions and KPrefsWidManager handles the rest automatically. */ class KDEPIM_EXPORT KPrefsWidManager { public: /** Create a KPrefsWidManager object for a KPrefs object. @param prefs KPrefs object used to access te configuration. */ explicit KPrefsWidManager(KConfigSkeleton *prefs); /** Destructor. */ virtual ~KPrefsWidManager(); KConfigSkeleton *prefs() const { return mPrefs; } /** Register a custom KPrefsWid object. */ virtual void addWid(KPrefsWid *); /** Register a @ref KPrefsWidBool object. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ KPrefsWidBool *addWidBool(KConfigSkeleton::ItemBool *item, QWidget *parent = nullptr); /** Register a @ref KPrefsWidInt object. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ KPrefsWidInt *addWidInt(KConfigSkeleton::ItemInt *item, QWidget *parent = nullptr); /** Register a @ref KPrefsWidDate object. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ KPrefsWidDate *addWidDate(KConfigSkeleton::ItemDateTime *item, QWidget *parent = nullptr); /** Register a @ref KPrefsWidTime object. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ KPrefsWidTime *addWidTime(KConfigSkeleton::ItemDateTime *item, QWidget *parent = nullptr); /** Register a @ref KPrefsWidDuration object. @param item The KConfigSkeletonItem representing the preferences entry. @param format display format. default is "hh:mm:ss" @param parent Parent widget. */ KPrefsWidDuration *addWidDuration(KConfigSkeleton::ItemDateTime *item, const QString &format, QWidget *parent = nullptr); /** Register a @ref KPrefsWidColor object. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ KPrefsWidColor *addWidColor(KConfigSkeleton::ItemColor *item, QWidget *parent = nullptr); /** Register a @ref KPrefsWidRadios object. The choices represented by the given item object are automatically added as radio buttons. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ KPrefsWidRadios *addWidRadios(KConfigSkeleton::ItemEnum *item, QWidget *parent = nullptr); /** Register a @ref KPrefsWidCombo object. The choices represented by the given item object are automatically added to the combo box. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ KPrefsWidCombo *addWidCombo(KConfigSkeleton::ItemEnum *item, QWidget *parent = nullptr); /** Register a @ref KPrefsWidString object. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ KPrefsWidString *addWidString(KConfigSkeleton::ItemString *item, QWidget *parent = nullptr); /** Register a path @ref KPrefsWidPath object. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. @param filter URLRequester filter @param mode URLRequester mode */ KPrefsWidPath *addWidPath(KConfigSkeleton::ItemPath *item, QWidget *parent = nullptr, const QString &filter = QString(), KFile::Modes mode = KFile::File); /** Register a password @ref KPrefsWidString object, with echomode set to KLineEdit::Password. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. */ KPrefsWidString *addWidPassword(KConfigSkeleton::ItemString *item, QWidget *parent = nullptr); /** Register a @ref KPrefsWidFont object. @param item The KConfigSkeletonItem representing the preferences entry. @param parent Parent widget. @param sampleText Sample text for previewing the selected font. */ KPrefsWidFont *addWidFont(KConfigSkeleton::ItemFont *item, QWidget *parent = nullptr, const QString &sampleText = QString()); /** Set all widgets to default values. */ void setWidDefaults(); /** Read preferences from config file. */ void readWidConfig(); /** Write preferences to config file. */ void writeWidConfig(); private: KConfigSkeleton *mPrefs = nullptr; QList mPrefsWids; }; /** @short Base class for a preferences dialog. This class provides the framework for a preferences dialog. You have to subclass it and add the code to create the actual configuration widgets and do the layout management. KPrefsDialog provides functions to add subclasses of @ref KPrefsWid via KPrefsWidManager. For these widgets the reading, writing and setting to default values is handled automatically. Custom widgets have to be handled in the functions @ref usrReadConfig() and @ref usrWriteConfig(). */ class KDEPIM_EXPORT KPrefsDialog : public KPageDialog, public KPrefsWidManager { Q_OBJECT public: /** Create a KPrefsDialog for a KPrefs object. @param prefs KPrefs object used to access te configuration. @param parent Parent widget. @param name Widget name. @param modal true, if dialog has to be modal, false for non-modal. */ explicit KPrefsDialog(KConfigSkeleton *prefs, QWidget *parent = nullptr, bool modal = false); /** Destructor. */ virtual ~KPrefsDialog(); void autoCreate(); public Q_SLOTS: /** Set all widgets to default values. */ void setDefaults(); /** Read preferences from config file. */ void readConfig(); /** Write preferences to config file. */ void writeConfig(); Q_SIGNALS: /** Emitted when the a changed configuration has been stored. */ void configChanged(); protected Q_SLOTS: /** Apply changes to preferences */ void slotApply(); /** Accept changes to preferences and close dialog */ void slotOk(); /** Set preferences to default values */ void slotDefault(); protected: /** Implement this to read custom configuration widgets. */ virtual void usrReadConfig() { } /** Implement this to write custom configuration widgets. */ virtual void usrWriteConfig() { } }; class KDEPIM_EXPORT KPrefsModule : public KCModule, public KPrefsWidManager { Q_OBJECT public: KPrefsModule(KConfigSkeleton *, QWidget *parent = nullptr, const QVariantList &args = QVariantList()); void addWid(KPrefsWid *) override; void load() override; void save() override; void defaults() override; public Q_SLOTS: void slotWidChanged(); protected: /** Implement this to read custom configuration widgets. */ virtual void usrReadConfig() { } /** Implement this to write custom configuration widgets. */ virtual void usrWriteConfig() { } }; } #endif diff --git a/src/libkdepim/widgets/progressindicatorlabel.cpp b/src/libkdepim/widgets/progressindicatorlabel.cpp index c9dd60d..6a6ab78 100644 --- a/src/libkdepim/widgets/progressindicatorlabel.cpp +++ b/src/libkdepim/widgets/progressindicatorlabel.cpp @@ -1,101 +1,100 @@ /* Copyright (c) 2013-2018 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "progressindicatorlabel.h" #include "progressindicatorwidget.h" #include using namespace KPIM; class KPIM::ProgressIndicatorLabelPrivate { public: ProgressIndicatorLabelPrivate(const QString &_label, ProgressIndicatorLabel *qq) : labelStr(_label) , q(qq) { - QHBoxLayout *lay = new QHBoxLayout; + QHBoxLayout *lay = new QHBoxLayout(q); lay->setMargin(0); - q->setLayout(lay); indicator = new ProgressIndicatorWidget; lay->addWidget(indicator); label = new QLabel; lay->addWidget(label); } ~ProgressIndicatorLabelPrivate() { } void setActiveLabel(const QString &str) { if (indicator->isActive()) { label->setText(str); } } void start() { indicator->start(); label->setText(labelStr); } void stop() { indicator->stop(); label->clear(); } QString labelStr; QLabel *label = nullptr; ProgressIndicatorWidget *indicator = nullptr; ProgressIndicatorLabel *q; }; ProgressIndicatorLabel::ProgressIndicatorLabel(const QString &label, QWidget *parent) : QWidget(parent) , d(new ProgressIndicatorLabelPrivate(label, this)) { } ProgressIndicatorLabel::ProgressIndicatorLabel(QWidget *parent) : QWidget(parent) , d(new ProgressIndicatorLabelPrivate(QString(), this)) { } ProgressIndicatorLabel::~ProgressIndicatorLabel() { delete d; } void ProgressIndicatorLabel::start() { d->start(); } void ProgressIndicatorLabel::stop() { d->stop(); } void ProgressIndicatorLabel::setActiveLabel(const QString &label) { d->setActiveLabel(label); }