2 Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "storageservicelogdialog.h"
22 #include "kpimtextedit/richtexteditorwidget.h"
23 #include "kpimtextedit/richtexteditor.h"
24 #include "PimCommon/PimUtil"
26 #include <KLocalizedString>
27 #include <KConfigGroup>
28 #include <KSharedConfig>
29 #include <QDialogButtonBox>
30 #include <QPushButton>
31 #include <QVBoxLayout>
33 StorageServiceLogDialog::StorageServiceLogDialog(QWidget
*parent
)
36 setWindowTitle(i18n("Log"));
38 QDialogButtonBox
*buttonBox
= new QDialogButtonBox(QDialogButtonBox::Close
);
39 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
40 setLayout(mainLayout
);
41 mUser1Button
= new QPushButton
;
42 buttonBox
->addButton(mUser1Button
, QDialogButtonBox::ActionRole
);
43 mUser2Button
= new QPushButton
;
44 buttonBox
->addButton(mUser2Button
, QDialogButtonBox::ActionRole
);
45 connect(buttonBox
, &QDialogButtonBox::rejected
, this, &StorageServiceLogDialog::reject
);
46 mUser1Button
->setText(i18n("Clear Log"));
47 mUser2Button
->setText(i18n("Save As..."));
48 mLog
= new KPIMTextEdit::RichTextEditorWidget
;
49 mLog
->setReadOnly(true);
51 mainLayout
->addWidget(mLog
);
52 mainLayout
->addWidget(buttonBox
);
53 connect(mUser1Button
, &QPushButton::clicked
, this, &StorageServiceLogDialog::slotClearLog
);
54 connect(mUser2Button
, &QPushButton::clicked
, this, &StorageServiceLogDialog::slotSaveAs
);
55 connect(mLog
->editor(), &QTextEdit::textChanged
, this, &StorageServiceLogDialog::slotTextChanged
);
58 StorageServiceLogDialog::~StorageServiceLogDialog()
63 void StorageServiceLogDialog::slotTextChanged()
65 const bool status
= !mLog
->toPlainText().isEmpty();
66 mUser2Button
->setEnabled(status
);
67 mUser1Button
->setEnabled(status
);
70 void StorageServiceLogDialog::slotClearLog()
72 mLog
->editor()->clear();
77 void StorageServiceLogDialog::slotSaveAs()
79 const QString filter
= i18n("All Files (*)");
80 PimCommon::Util::saveTextAs(mLog
->toPlainText(), filter
, this, QUrl(),
81 i18nc("@title:window", "Save Log"));
84 void StorageServiceLogDialog::setLog(const QString
&log
)
89 void StorageServiceLogDialog::writeConfig()
91 KSharedConfig::Ptr config
= KSharedConfig::openConfig();
93 KConfigGroup group
= config
->group(QStringLiteral("StorageServiceLogDialog"));
94 group
.writeEntry("Size", size());
97 void StorageServiceLogDialog::readConfig()
99 KConfigGroup
group(KSharedConfig::openConfig(), "StorageServiceLogDialog");
100 const QSize size
= group
.readEntry("Size", QSize(600, 400));
101 if (size
.isValid()) {