Commit 5fa85fea authored by Laurent Montel's avatar Laurent Montel 😁

Save config. Allow to reload config

parent e5ed9bdb
......@@ -38,8 +38,6 @@ public:
public Q_SLOTS:
void configure( WId windowId );
private slots:
void reload();
private:
......
......@@ -81,7 +81,10 @@ void FollowUpReminderInfo::setId(Akonadi::Item::Id value)
bool FollowUpReminderInfo::isValid() const
{
return (mId != -1 && !mMessageId.isEmpty() && mFollowUpReminderDate.isValid() && !mTo.isEmpty());
return (mId != -1 &&
!mMessageId.isEmpty() &&
mFollowUpReminderDate.isValid() &&
!mTo.isEmpty());
}
QString FollowUpReminderInfo::messageId() const
......
......@@ -95,5 +95,5 @@ void FollowUpReminderInfoDialog::writeConfig()
void FollowUpReminderInfoDialog::slotSave()
{
//TODO
mWidget->save();
}
......@@ -27,6 +27,9 @@
#include <kmenu.h>
#include <KLocalizedString>
static QString followUpItemPattern = QLatin1String("FollowupReminderItem \\d+");
FollowUpReminderInfoItem::FollowUpReminderInfoItem(QTreeWidget *parent)
: QTreeWidgetItem(parent),
mInfo(0)
......@@ -48,9 +51,9 @@ FollowUpReminder::FollowUpReminderInfo* FollowUpReminderInfoItem::info() const
return mInfo;
}
FollowUpReminderInfoWidget::FollowUpReminderInfoWidget(QWidget *parent)
: QWidget(parent)
: QWidget(parent),
mChanged(false)
{
QHBoxLayout *hbox = new QHBoxLayout;
mTreeWidget = new QTreeWidget;
......@@ -89,6 +92,31 @@ void FollowUpReminderInfoWidget::setInfo(const QList<FollowUpReminder::FollowUpR
}
}
void FollowUpReminderInfoWidget::save()
{
if (!mChanged)
return;
KSharedConfig::Ptr config = KGlobal::config();
// first, delete all filter groups:
const QStringList filterGroups =config->groupList().filter( QRegExp( followUpItemPattern ) );
foreach ( const QString &group, filterGroups ) {
config->deleteGroup( group );
}
const int numberOfItem(mTreeWidget->topLevelItemCount());
for (int i = 0; i < numberOfItem; ++i) {
FollowUpReminderInfoItem *mailItem = static_cast<FollowUpReminderInfoItem *>(mTreeWidget->topLevelItem(i));
if (mailItem->info()) {
KConfigGroup group = config->group(QString::fromLatin1("FollowupReminderItem %1").arg(mailItem->info()->id()));
mailItem->info()->writeConfig(group);
}
}
config->sync();
config->reparseConfiguration();
}
void FollowUpReminderInfoWidget::customContextMenuRequested(const QPoint &pos)
{
const QList<QTreeWidgetItem *> listItems = mTreeWidget->selectedItems();
......@@ -103,6 +131,7 @@ void FollowUpReminderInfoWidget::slotRemoveItem()
{
if (mTreeWidget->currentItem()) {
delete mTreeWidget->currentItem();
mChanged = true;
}
}
......
......@@ -51,6 +51,9 @@ public:
void saveTreeWidgetHeader(KConfigGroup &group);
void setInfo(const QList<FollowUpReminder::FollowUpReminderInfo *> &infoList);
void save();
private slots:
void customContextMenuRequested(const QPoint &pos);
void slotRemoveItem();
......@@ -63,6 +66,7 @@ private:
DeadLine
};
QTreeWidget *mTreeWidget;
bool mChanged;
};
#endif // FOLLOWUPREMINDERINFOWIDGET_H
......@@ -13,5 +13,6 @@
<method name="printDebugInfo" >
<arg type="s" direction="out"/>
</method>
<method name="reload" />
</interface>
</node>
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