summaryrefslogtreecommitdiff
path: root/noncore/securityplugins/notice/noticeConfigWidget.cpp
Unidiff
Diffstat (limited to 'noncore/securityplugins/notice/noticeConfigWidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/securityplugins/notice/noticeConfigWidget.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/noncore/securityplugins/notice/noticeConfigWidget.cpp b/noncore/securityplugins/notice/noticeConfigWidget.cpp
new file mode 100644
index 0000000..e2c2d83
--- a/dev/null
+++ b/noncore/securityplugins/notice/noticeConfigWidget.cpp
@@ -0,0 +1,81 @@
1#include "noticeConfigWidget.h"
2
3#include <opie2/odebug.h>
4
5#include <qwidget.h>
6#include <qlayout.h>
7#include <qlabel.h>
8#include <qregexp.h>
9#include <qgroupbox.h>
10
11/// constructs the widget, filling the noticeMLE QMultiLineEdit with the "noticeText" entry
12NoticeConfigWidget::NoticeConfigWidget(QWidget* parent = 0, const char* name = "Notice configuration widget") : MultiauthConfigWidget(parent, name)
13{
14 QVBoxLayout *baseLayout = new QVBoxLayout( this);
15 baseLayout->setSpacing(11);
16 baseLayout->setMargin(6);
17 baseLayout->setAlignment( Qt::AlignTop );
18
19 QGroupBox *configBox = new QGroupBox(0, Qt::Vertical, tr("Set the message the user must accept"), this);
20 baseLayout->addWidget(configBox);
21 QVBoxLayout *boxLayout = new QVBoxLayout( configBox->layout() );
22
23 QLabel * comment1 = new QLabel("<p><em>" + tr("You may want to consult your legal department for proper wording here.") + "</em></p>", configBox);
24 boxLayout->addWidget(comment1);
25
26 // Set the multilineedit box text to getNoticeText()
27 noticeMLE = new QMultiLineEdit(configBox, "notice text");
28 noticeMLE->setWordWrap(QMultiLineEdit::WidgetWidth);
29 noticeMLE->setFocus();
30 noticeMLE->setText(getNoticeText());
31 boxLayout->addWidget(noticeMLE);
32
33 resetNoticeButton = new QPushButton( tr("Reset notice to default"), configBox, "reset Notice Button" );
34 connect(resetNoticeButton, SIGNAL( clicked() ), this, SLOT( resetNotice() ));
35 boxLayout->addWidget(resetNoticeButton, 0, Qt::AlignHCenter);
36
37 QLabel * comment2 = new QLabel("<p>" + tr("Note: you can use HTML tags to improve its layout (example: text between &lt;em&gt; and &lt;/em&gt; will be <em>emphasized</em>)") + "</p>", configBox);
38 boxLayout->addWidget(comment2);
39
40}
41
42/// nothing to do
43NoticeConfigWidget::~NoticeConfigWidget()
44{}
45
46/// write the notice text in the multiauth.conf Config file
47void NoticeConfigWidget::writeConfig()
48{
49 if ( noticeMLE->edited() ) {
50 odebug << "writing new notice text in Security.conf" << oendl;
51 setNoticeText(noticeMLE->text());
52 }
53}
54
55/// reset the notice text to the hard-coded example defaultNoticeText
56void NoticeConfigWidget::resetNotice()
57{
58 noticeMLE->setText(defaultNoticeText);
59}
60
61/// get the notice text from the config file (with true new lines)
62/**
63 * if no text has been defined yet returns defaultNoticeText
64 */
65QString NoticeConfigWidget::getNoticeText() {
66 m_config = new Config("Security");
67 m_config->setGroup("NoticePlugin");
68 // Note: C++ processes '\' character, so we have to type \\\\ to mean \\ to QRegExp
69 QString noticeText = m_config->readEntry("noticeText", defaultNoticeText).replace( QRegExp("\\\\n"), "\n" );
70 delete m_config;
71 return noticeText;
72}
73
74/// set the notice text in our m_config config file (escaping new lines)
75void NoticeConfigWidget::setNoticeText(QString noticeText) {
76 m_config = new Config("Security");
77 m_config->setGroup("NoticePlugin");
78 // since Config files do not allow true newlines, we replace them with litteral "\n"
79 m_config->writeEntry("noticeText", noticeText.replace( QRegExp("\n"), "\\n" ));
80 delete m_config;
81}