summaryrefslogtreecommitdiffstats
path: root/konversation/src/nicklistview.cpp
blob: edf7f4b42b8ee75c2835070490da6a27255d7b9a (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
*/

/*
  This is the class that shows the channel nick list
  begin:     Fre Jun 7 2002
  copyright: (C) 2002 by Dario Abatianni
  email:     eisfuchs@tigress.com
*/

#include "nicklistview.h"
#include "konversationapplication.h"
#include "images.h"
#include "linkaddressbook/addressbook.h"

#include <tdepopupmenu.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <tqtooltip.h>
#include <tqtimer.h>
#include <kiconloader.h>
#include <tqwhatsthis.h>
#include <tqdragobject.h>


NickListView::NickListView(TQWidget* parent, Channel *chan) :
TDEListView(parent)
{
    TDEListView::setSorting(-1);
    setWhatsThis();
    channel=chan;
    popup=new TDEPopupMenu(this,"nicklist_context_menu");
    modes=new TDEPopupMenu(this,"nicklist_modes_context_submenu");
    kickban=new TDEPopupMenu(this,"nicklist_kick_ban_context_submenu");
    addressbook= new TDEPopupMenu(this,"nicklist_addressbook_context_submenu");
    setAcceptDrops(true);
    setDropHighlighter(true);
    setDropVisualizer(false);

    if (popup)
    {
        popup->insertItem(i18n("&Whois"),Konversation::Whois);
        popup->insertItem(i18n("&Version"),Konversation::Version);
        popup->insertItem(i18n("&Ping"),Konversation::Ping);

        popup->insertSeparator();

        if (modes)
        {
            modes->insertItem(i18n("Give Op"),Konversation::GiveOp);
            modes->insertItem(i18n("Take Op"),Konversation::TakeOp);
            modes->insertItem(i18n("Give HalfOp"),Konversation::GiveHalfOp);
            modes->insertItem(i18n("Take HalfOp"),Konversation::TakeHalfOp);
            modes->insertItem(i18n("Give Voice"),Konversation::GiveVoice);
            modes->insertItem(i18n("Take Voice"),Konversation::TakeVoice);
            popup->insertItem(i18n("Modes"),modes,Konversation::ModesSub);
        }

        if (kickban)
        {

            kickban->insertItem(i18n("Kick"),Konversation::Kick);
            kickban->insertItem(i18n("Kickban"),Konversation::KickBan);
            kickban->insertItem(i18n("Ban Nickname"),Konversation::BanNick);
            kickban->insertSeparator();
            kickban->insertItem(i18n("Ban *!*@*.host"),Konversation::BanHost);
            kickban->insertItem(i18n("Ban *!*@domain"),Konversation::BanDomain);
            kickban->insertItem(i18n("Ban *!user@*.host"),Konversation::BanUserHost);
            kickban->insertItem(i18n("Ban *!user@domain"),Konversation::BanUserDomain);
            kickban->insertSeparator();
            kickban->insertItem(i18n("Kickban *!*@*.host"),Konversation::KickBanHost);
            kickban->insertItem(i18n("Kickban *!*@domain"),Konversation::KickBanDomain);
            kickban->insertItem(i18n("Kickban *!user@*.host"),Konversation::KickBanUserHost);
            kickban->insertItem(i18n("Kickban *!user@domain"),Konversation::KickBanUserDomain);
            popup->insertItem(i18n("Kick / Ban"),kickban,Konversation::KickBanSub);
        }

        popup->insertItem(i18n("Ignore"), Konversation::IgnoreNick);
        popup->insertItem(i18n("Unignore"), Konversation::UnignoreNick);

        popup->insertSeparator();

        int newitem;
        newitem = popup->insertItem(i18n("Open &Query"),Konversation::OpenQuery);
        popup->setWhatsThis(newitem, "<qt>Start a private chat between you and this person.<p/><em>Technical note:</em><br>The conversation between you and this person will be sent via the server.  This means that the conversation will be affected by server lag, server stability, and will be terminated when you disconnect from the server.</qt>");
        newitem = popup->insertItem(i18n("Open DCC &Chat"),Konversation::StartDccChat);
        popup->setWhatsThis(newitem, "<qt>Start a private <em>D</em>irect <em>C</em>lient <em>C</em>onnection chat between you and this person.<p/><em>Technical note:</em><br />The conversation between you and this person will be sent directly.  This means it is independent from the server - so if the server connection fails, or use disconnect, your DCC Chat will be unaffected.  It also means that no irc server admin can view or spy on this chat.</qt>");

        if (kapp->authorize("allow_downloading"))
        {
            newitem = popup->insertItem(SmallIcon("2rightarrow"),i18n("Send &File..."),Konversation::DccSend);
            popup->setWhatsThis(newitem, "<qt>Send a file to this person.  If you are having problem sending files, or they are sending slowly, see the Konversation Handbook and DCC preferences page.</qt>");
        }
        popup->insertItem(SmallIconSet("mail_generic"),i18n("&Send Email..."), Konversation::SendEmail);

        popup->insertSeparator();

        if (addressbook)
            popup->insertItem(i18n("Addressbook Associations"), addressbook, Konversation::AddressbookSub);

        popup->insertItem(i18n("Add to Watched Nicks"), Konversation::AddNotify);

        connect (popup, TQT_SIGNAL(activated(int)), this, TQT_SIGNAL(popupCommand(int)));
        connect (modes, TQT_SIGNAL(activated(int)), this, TQT_SIGNAL(popupCommand(int)));
        connect (kickban, TQT_SIGNAL(activated(int)), this, TQT_SIGNAL(popupCommand(int)));
        connect (addressbook, TQT_SIGNAL(activated(int)), this, TQT_SIGNAL(popupCommand(int)));

    }
    else
    {
        kdWarning() << "NickListView::NickListView(): Could not create popup!" << endl;
    }

    #if KDE_IS_VERSION(3,3,90)
    setShadeSortColumn(false);
    #endif

    // We have our own tooltips, don't use the default TQListView ones
    setShowToolTips(false);
    m_tooltip = new Konversation::KonversationNickListViewToolTip(viewport(), this);

    m_resortTimer = new TQTimer(this);
    connect(m_resortTimer, TQT_SIGNAL(timeout()), TQT_SLOT(resort()));
}

NickListView::~NickListView()
{
    delete m_tooltip;
    m_tooltip = 0;
}

void NickListView::setWhatsThis()
{
    Images* images = KonversationApplication::instance()->images();

    if(images->getNickIcon( Images::Normal, false).isNull())
    {
        TQWhatsThis::add(this, i18n("<qt>This shows all the people in the channel.  The nick for each person is shown.<br>Usually an icon is shown showing the status of each person, but you do not seem to have any icon theme installed.  See the Konversation settings - <i>Configure Konversation</i> under the <i>Settings</i> menu.  Then view the page for <i>Themes</i> under <i>Appearence</i>.</qt>"));
    }
    else
    {
        TQMimeSourceFactory::defaultFactory()->setImage( "admin", images->getNickIcon( Images::Admin, false ).convertToImage() );
        TQMimeSourceFactory::defaultFactory()->setImage( "owner", images->getNickIcon( Images::Owner, false ).convertToImage());
        TQMimeSourceFactory::defaultFactory()->setImage( "op", images->getNickIcon( Images::Op, false ).convertToImage() );
        TQMimeSourceFactory::defaultFactory()->setImage( "halfop", images->getNickIcon( Images::HalfOp, false ).convertToImage() );
        TQMimeSourceFactory::defaultFactory()->setImage( "voice", images->getNickIcon( Images::Voice, false ).convertToImage() );
        TQMimeSourceFactory::defaultFactory()->setImage( "normal", images->getNickIcon( Images::Normal, false ).convertToImage() );
        TQMimeSourceFactory::defaultFactory()->setImage( "normalaway", images->getNickIcon( Images::Normal, true).convertToImage() );

        TQWhatsThis::add(this, i18n("<qt>This shows all the people in the channel.  The nick for each person is shown, with a picture showing their status.<p>"
            "<table>"

            "<tr><th><img src=\"admin\"></th><td>This person has administrator privileges.</td></tr>"
            "<tr><th><img src=\"owner\"></th><td>This person is a channel owner.</td></tr>"
            "<tr><th><img src=\"op\"></th><td>This person is a channel operator.</td></tr>"
            "<tr><th><img src=\"halfop\"></th><td>This person is a channel half-operator.</td></tr>"
            "<tr><th><img src=\"voice\"></th><td>This person has voice, and can therefore talk in a moderated channel.</td></tr>"
            "<tr><th><img src=\"normal\"></th><td>This person does not have any special privileges.</td></tr>"
            "<tr><th><img src=\"normalaway\"></th><td>This indicates that this person is currently away.</td></tr>"
            "</table><p>"
            "The meaning of admin, owner and halfop varies between different IRC servers.<p>"
            "Hovering over any nick shows their current status, as well as any information in the addressbook for this person.  See the Konversation Handbook for more information."
            "</qt>"
            ));
    }

}

void NickListView::refresh()
{
    TQListViewItemIterator it(this);

    while (it.current())
    {
        static_cast<Nick*>(it.current())->refresh();
        ++it;
    }

    setWhatsThis();
}

void NickListView::startResortTimer()
{
    if(!m_resortTimer->isActive())
        m_resortTimer->start(3000, true /*single shot*/);
}

void NickListView::resort()
{
    TDEListView::setSorting(m_column, m_ascending);
    sort();
    TDEListView::setSorting(-1);
}

void NickListView::contextMenuEvent(TQContextMenuEvent* ce)
{
    ce->accept();

    if (selectedItems().count())
    {
        insertAssociationSubMenu();
        updateActions();
        popup->popup(ce->globalPos());
    }
}

void NickListView::updateActions()
{
    int ignoreCounter = 0;
    int unignoreCounter = 0;
    int notifyCounter = 0;

    int serverGroupId = -1;

    if (channel->getServer()->getServerGroup())
        serverGroupId = channel->getServer()->getServerGroup()->id();

    ChannelNickList nickList=channel->getSelectedChannelNicks();
    ChannelNickList::ConstIterator it;

    for (it = nickList.begin(); it != nickList.end(); ++it)
    {
        if (Preferences::isIgnored((*it)->getNickname()))
            ++unignoreCounter;
        else
            ++ignoreCounter;

        if (serverGroupId != -1 && Preferences::isNotify(serverGroupId, (*it)->getNickname()))
            ++notifyCounter;
    }

    if (ignoreCounter)
        popup->setItemVisible(Konversation::IgnoreNick, true);
    else
        popup->setItemVisible(Konversation::IgnoreNick, false);

    if (unignoreCounter)
        popup->setItemVisible(Konversation::UnignoreNick, true);
    else
        popup->setItemVisible(Konversation::UnignoreNick, false);

    if (notifyCounter || !Preferences::hasNotifyList(serverGroupId))
        popup->setItemEnabled(Konversation::AddNotify, false);
    else
        popup->setItemEnabled(Konversation::AddNotify, true);
}

void NickListView::insertAssociationSubMenu()
{

    bool existingAssociation = false;
    bool noAssociation = false;
    bool emailAddress = false;

    addressbook->clear();

    ChannelNickList nickList=channel->getSelectedChannelNicks();
    for(ChannelNickList::ConstIterator it=nickList.begin();it!=nickList.end();++it)
    {
        TDEABC::Addressee addr = (*it)->getNickInfo()->getAddressee();
        if(addr.isEmpty())
        {
            noAssociation=true;
            if(existingAssociation && emailAddress) break;
        }
        else
        {
            if(!emailAddress && !addr.preferredEmail().isEmpty())
                emailAddress = true;
            existingAssociation=true;
            if(noAssociation && emailAddress) break;
        }
    }

    if(!noAssociation && existingAssociation)
    {
        addressbook->insertItem(SmallIcon("contents"), i18n("Edit Contact..."), Konversation::AddressbookEdit);
        addressbook->insertSeparator();
    }

    if(noAssociation && existingAssociation)
        addressbook->insertItem(i18n("Choose/Change Associations..."), Konversation::AddressbookChange);
    else if(noAssociation)
        addressbook->insertItem(i18n("Choose Contact..."), Konversation::AddressbookChange);
    else
        addressbook->insertItem(i18n("Change Association..."), Konversation::AddressbookChange);

    if(noAssociation && !existingAssociation)
        addressbook->insertItem(i18n("Create New Contact..."), Konversation::AddressbookNew);

    if(existingAssociation)
        addressbook->insertItem(SmallIcon("edit-delete"), i18n("Delete Association"), Konversation::AddressbookDelete);

    if(!emailAddress)
        popup->setItemEnabled(Konversation::SendEmail, false);
    else
        popup->setItemEnabled(Konversation::SendEmail, true);

}

void NickListView::setSorting(int column, bool ascending)
{
    m_column = column;
    m_ascending = ascending;
}

bool NickListView::acceptDrag (TQDropEvent* event) const
{
    if (event->provides("text/uri-list"))
    {
        if (event->source())
        {
            TQStrList uris;

            if (TQUriDrag::decode(event,uris))
            {
                TQString first = uris.first();

                if (first.startsWith("irc://") || channel->getNickList().containsNick(first))
                    return false;
            }
            else
                return false;
        }

        return true;
    }
    else
        return false;
}

#include "nicklistview.moc"