summaryrefslogtreecommitdiff
path: root/noncore/securityplugins/notice/noticeplugin.cpp
blob: d3dc7a424f985382e31468027802e8467e5b2806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "noticeplugin.h"

#include <opie2/oapplication.h>

#include <qmessagebox.h>
#include <qregexp.h>

using Opie::Security::MultiauthPluginObject;
using Opie::Security::MultiauthConfigWidget;

/// creates and initializes the m_config Config object
NoticePlugin::NoticePlugin() : MultiauthPluginObject(), m_noticeW(0) {
}

/// deletes the m_config Config object and noticeW if necessary
NoticePlugin::~NoticePlugin() {
    delete m_noticeW;
}

/// Simply return its name (Notice plugin)
QString NoticePlugin::pluginName() const {
    return "Notice plugin";
}

/// return the Notice widget configuration widget
/**
 * \return noticeW, the NoticeConfigWidget
 */
MultiauthConfigWidget * NoticePlugin::configWidget(QWidget * parent) {
    if (m_noticeW == 0)
        m_noticeW = new NoticeConfigWidget(parent, "Notice configuration widget");
    return m_noticeW;
}

/// return the path of the small tab icon
QString NoticePlugin::pixmapNameConfig() const {
    return "security/noticeplugin_small";
}

/// return the path of the big icon for the active/order checklist
QString NoticePlugin::pixmapNameWidget() const {
    return "security/noticeplugin";
}

/// Displays the configured message and an 'Accept' button
/**
 * \return the outcome code of this  authentication (can be only success)
 */
int NoticePlugin::authenticate() {
    QMessageBox noticeDialog("Notice plugin",
                            getNoticeText(),
                            QMessageBox::Warning,
                            QMessageBox::Yes,
                            0,
                            0,
                            0,
                            "notice plugin dialog",
                            true,
                            Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop);

    noticeDialog.setButtonText(QMessageBox::Yes, tr("I accept"));

    QRect desk = oApp->desktop()->geometry();
    noticeDialog.setGeometry( 0, 0, desk.width(), desk.height() );

    switch (noticeDialog.exec())
    {
        case QMessageBox::Yes:
            return MultiauthPluginObject::Success;
    }
    return 255; //should not be returned anyway
}

/// get the notice text from our m_config config file (with true new lines)
/**
 * if no text has been defined yet returns defaultNoticeText
 */
QString NoticePlugin::getNoticeText() {
      // Note: C++ processes '\' character, so we have to type \\\\ to mean \\ to QRegExp
    Config config("Security");
    config.setGroup("NoticePlugin");
    return config.readEntry("noticeText", QObject::tr(defaultNoticeText)).replace( QRegExp("\\\\n"), "\n" );
}