~ubuntu-branches/ubuntu/lucid/konversation/lucid-updates

« back to all changes in this revision

Viewing changes to src/notificationhandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-02-11 14:52:14 UTC
  • mto: This revision was merged to the branch mainline in revision 43.
  • Revision ID: james.westby@ubuntu.com-20100211145214-xsbd3hmrnu5fmb8f
Tags: upstream-1.2.2
ImportĀ upstreamĀ versionĀ 1.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    {
38
38
    }
39
39
 
 
40
    QString cleanMessage(QString message)
 
41
    {
 
42
        QString s = Qt::escape(Konversation::removeIrcMarkup(message));
 
43
        return s;
 
44
    }
 
45
 
40
46
    void NotificationHandler::message(ChatWindow* chatWin, const QString& fromNick, const QString& message)
41
47
    {
42
48
        if (!chatWin || !chatWin->notificationsEnabled())
45
51
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
46
52
            return;
47
53
 
48
 
        bool osd = Preferences::self()->oSDShowChannel() &&
49
 
            (!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView()));
50
 
 
51
 
        if (message.isEmpty())
52
 
        {
53
 
            KNotification::event(QString::fromLatin1("message"), QString("<html>&lt;%1&gt;</html>").arg(fromNick), QPixmap(), m_mainWindow);
54
 
 
55
 
            if (osd)
56
 
            {
57
 
                Application* konvApp = static_cast<Application*>(kapp);
58
 
 
59
 
                konvApp->osd->show('(' + chatWin->getName() + ") <" + fromNick + '>');
60
 
            }
61
 
        }
62
 
        else
63
 
        {
64
 
            QString cleanedMessage = removeIrcMarkup(message);
65
 
            QString forKNotify = Qt::escape(cleanedMessage);
66
 
 
67
 
            KNotification::event(QString::fromLatin1("message"), QString("<html>&lt;%1&gt; %2</html>").arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
68
 
 
69
 
            if (osd)
70
 
            {
71
 
                Application* konvApp = static_cast<Application*>(kapp);
72
 
 
73
 
                konvApp->osd->show('(' + chatWin->getName() + ") <" + fromNick + "> " + cleanedMessage);
74
 
            }
75
 
        }
76
 
 
77
 
        if (!Preferences::self()->trayNotifyOnlyOwnNick())
 
54
        QString cleanedMessage = cleanMessage(message);
 
55
        QString cutup = addLineBreaks(cleanedMessage);
 
56
 
 
57
        KNotification::event(QString::fromLatin1("message"), QString("<qt>&lt;%1&gt; %2</qt>").arg(fromNick).arg(cutup), QPixmap(), m_mainWindow);
 
58
 
 
59
        if(!Preferences::self()->trayNotifyOnlyOwnNick())
78
60
        {
79
61
            startTrayNotification(chatWin);
80
62
        }
 
63
 
 
64
 
 
65
        if(Preferences::self()->oSDShowChannel() &&
 
66
            (!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
 
67
        {
 
68
            Application* konvApp = static_cast<Application*>(kapp);
 
69
            konvApp->osd->show('(' + chatWin->getName() + ") <" + fromNick + "> " + cleanedMessage);
 
70
        }
 
71
 
81
72
    }
82
73
 
83
74
    void NotificationHandler::nick(ChatWindow* chatWin, const QString& fromNick, const QString& message)
88
79
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
89
80
            return;
90
81
 
91
 
        bool osd = (Preferences::self()->oSDShowChannel() || Preferences::self()->oSDShowOwnNick()) &&
 
82
        QString cleanedMessage = cleanMessage(message);
 
83
        QString cutup = addLineBreaks(cleanedMessage);
 
84
 
 
85
        KNotification::event(QString::fromLatin1("nick"), QString("<qt>&lt;%1&gt; %2</qt>").arg(fromNick).arg(cutup), QPixmap(), m_mainWindow);
 
86
 
 
87
        startTrayNotification(chatWin);
 
88
 
 
89
        Application* konvApp = static_cast<Application*>(kapp);
 
90
 
 
91
        if((Preferences::self()->oSDShowChannel() || Preferences::self()->oSDShowOwnNick()) &&
92
92
            (!m_mainWindow->isActiveWindow() ||
93
 
            (chatWin != m_mainWindow->getViewContainer()->getFrontView()));
94
 
 
95
 
        if (message.isEmpty())
96
 
        {
97
 
            KNotification::event(QString::fromLatin1("nick"), QString("<html>&lt;%1&gt;</html>").arg(fromNick), QPixmap(), m_mainWindow);
98
 
 
99
 
            if (osd)
100
 
            {
101
 
                Application* konvApp = static_cast<Application*>(kapp);
102
 
 
103
 
                konvApp->osd->show(i18n("[HighLight] (%1) &lt;%2&gt;", chatWin->getName(), fromNick));
104
 
            }
105
 
        }
106
 
        else
107
 
        {
108
 
            QString cleanedMessage = removeIrcMarkup(message);
109
 
            QString forKNotify = Qt::escape(cleanedMessage);
110
 
 
111
 
            KNotification::event(QString::fromLatin1("nick"), QString("<html>&lt;%1&gt; %2</html>").arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
112
 
 
113
 
            if (osd)
114
 
            {
115
 
                Application* konvApp = static_cast<Application*>(kapp);
116
 
 
117
 
                konvApp->osd->show(i18n("[HighLight] (%1) &lt;%2&gt; %3", chatWin->getName(), fromNick, cleanedMessage));
118
 
            }
119
 
        }
120
 
 
121
 
        startTrayNotification(chatWin);
 
93
            (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
 
94
        {
 
95
            konvApp->osd->show(i18n("[HighLight] (%1) &lt;%2&gt; %3",chatWin->getName(),fromNick,cleanedMessage));
 
96
        }
122
97
    }
123
98
 
124
99
    void NotificationHandler::queryMessage(ChatWindow* chatWin,
130
105
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
131
106
            return;
132
107
 
133
 
        bool osd = Preferences::self()->oSDShowQuery() && (!m_mainWindow->isActiveWindow() ||
134
 
            (chatWin != m_mainWindow->getViewContainer()->getFrontView()));
135
 
 
136
 
        if (message.isEmpty())
137
 
        {
138
 
            KNotification::event(QString::fromLatin1("queryMessage"), QString("<html>&lt;%1&gt;</html>").arg(fromNick), QPixmap(), m_mainWindow);
139
 
 
140
 
            if (osd)
141
 
            {
142
 
                Application* konvApp = static_cast<Application*>(kapp);
143
 
 
144
 
                konvApp->osd->show(i18n("[Query] &lt;%1&gt;", fromNick));
145
 
            }
146
 
        }
147
 
        else
148
 
        {
149
 
            QString cleanedMessage = removeIrcMarkup(message);
150
 
            QString forKNotify = Qt::escape(cleanedMessage);
151
 
 
152
 
            KNotification::event(QString::fromLatin1("queryMessage"), QString("<html>&lt;%1&gt; %2</html>").arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
153
 
 
154
 
            if (osd)
155
 
            {
156
 
                Application* konvApp = static_cast<Application*>(kapp);
157
 
 
158
 
                konvApp->osd->show(i18n("[Query] &lt;%1&gt; %2", fromNick, cleanedMessage));
159
 
            }
160
 
        }
 
108
        QString cleanedMessage = cleanMessage(message);
 
109
        QString cutup = addLineBreaks(cleanedMessage);
 
110
 
 
111
        KNotification::event(QString::fromLatin1("queryMessage"), QString("<qt>&lt;%1&gt; %2</qt>").arg(fromNick).arg(cutup), QPixmap(), m_mainWindow);
161
112
 
162
113
        startTrayNotification(chatWin);
 
114
 
 
115
        Application* konvApp = static_cast<Application*>(kapp);
 
116
 
 
117
        if(Preferences::self()->oSDShowQuery() && (!m_mainWindow->isActiveWindow() ||
 
118
           (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
 
119
        {
 
120
            konvApp->osd->show(i18n("[Query] &lt;%1&gt; %2",fromNick,cleanedMessage));
 
121
        }
163
122
    }
164
123
 
165
124
    void NotificationHandler::startTrayNotification(ChatWindow* chatWin)
254
213
        if (Preferences::self()->disableNotifyWhileAway() && chatWin->getServer() && chatWin->getServer()->isAway())
255
214
            return;
256
215
 
257
 
        KNotification::event(QString::fromLatin1("dcc_error"), i18n("An error has occurred in a DCC transfer: %1",error), QPixmap(), m_mainWindow);
 
216
        KNotification::event(QString::fromLatin1("dcc_error"), i18n("An Error has occurred in a DCC transfer: %1",error), QPixmap(), m_mainWindow);
258
217
    }
259
218
 
260
219
    void NotificationHandler::dccTransferDone(ChatWindow* chatWin, const QString& file)
346
305
            return;
347
306
 
348
307
        KNotification *ev=new KNotification("dccChat", m_mainWindow);
349
 
        ev->setText(i18n("%1 started a DCC chat with you", nick));
 
308
        ev->setText(i18n("%1 started a dcc chat with you", nick));
350
309
        ev->sendEvent();
351
310
 
352
311
    }
361
320
 
362
321
        startTrayNotification(chatWin);
363
322
 
364
 
        QString cleanedMessage = removeIrcMarkup(message);
365
 
        QString forKNotify = Qt::escape(cleanedMessage);
 
323
        QString cleanedMessage = cleanMessage(message);
 
324
        QString cutup = addLineBreaks(cleanedMessage);
366
325
 
367
326
        if(fromNick.isEmpty())
368
 
            KNotification::event(QString::fromLatin1("highlight"), QString("<html>(%1) *** %2</html>").arg(chatWin->getName()).arg(forKNotify), QPixmap(), m_mainWindow);
 
327
            KNotification::event(QString::fromLatin1("highlight"), QString("<qt>(%1) *** %2</qt>").arg(chatWin->getName()).arg(cutup), QPixmap(), m_mainWindow);
369
328
        else
370
 
            KNotification::event(QString::fromLatin1("highlight"), QString("<html>(%1) &lt;%2&gt; %3</html>").arg(chatWin->getName()).arg(fromNick).arg(forKNotify), QPixmap(), m_mainWindow);
 
329
            KNotification::event(QString::fromLatin1("highlight"), QString("<qt>(%1) &lt;%2&gt; %3</qt>").arg(chatWin->getName()).arg(fromNick).arg(cutup), QPixmap(), m_mainWindow);
371
330
 
372
331
        if(Preferences::self()->oSDShowOwnNick() &&
373
332
            (!m_mainWindow->isActiveWindow() || (chatWin != m_mainWindow->getViewContainer()->getFrontView())))
376
335
            // if there was no nick associated, this must be a command message, so don't try displaying
377
336
            // an empty nick in <>
378
337
            if(fromNick.isEmpty())
379
 
                konvApp->osd->show(i18n("[HighLight] (%1) *** %2",chatWin->getName(),cleanedMessage));
 
338
                konvApp->osd->show(i18n("[HighLight] (%1) *** %2",chatWin->getName(),message));
380
339
            // normal highlight message
381
340
            else
382
 
                konvApp->osd->show(i18n("[HighLight] (%1) &lt;%2&gt; %3",chatWin->getName(),fromNick,cleanedMessage));
 
341
                konvApp->osd->show(i18n("[HighLight] (%1) &lt;%2&gt; %3",chatWin->getName(),fromNick,message));
383
342
        }
384
343
    }
385
344
 
405
364
        KNotification::event(QString::fromLatin1("channelJoin"), i18n("You have joined %1.",channel), QPixmap(), m_mainWindow);
406
365
    }
407
366
 
 
367
    QString NotificationHandler::addLineBreaks(const QString& string)
 
368
    {
 
369
        QString cutup = string;
 
370
        int offset = 0;
 
371
 
 
372
        for(int i = 0; i < string.length(); i += 50)
 
373
        {
 
374
            cutup.insert(i + (offset * 4), "<br>");
 
375
            ++offset;
 
376
        }
 
377
 
 
378
        return cutup;
 
379
    }
 
380
 
408
381
}
409
382
 
410
383
#include "notificationhandler.moc"