summaryrefslogtreecommitdiffstats
path: root/konversation/src/nicksonline.h
blob: 414c7745b7410ddbb8a0e03448bbc7b9b58dc82d (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
/*
  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.
*/

/*
  shows a user tree of friends per server
  begin:     Sam Aug 31 2002
  copyright: (C) 2002 by Dario Abatianni
  email:     eisfuchs@tigress.com
*/

#ifndef NICKSONLINE_H
#define NICKSONLINE_H

#include "nickinfo.h"
#include "nicksonlineitem.h"
#include "chatwindow.h"
#include "linkaddressbook/nicksonlinetooltip.h"

#include <tqvbox.h>
#include <tqiconset.h>
#include <tqpair.h>


class TDEListView;
class TQPushButton;
class TQPopupMenu;

class ChatWindow;

class NicksOnline : public ChatWindow
{
    Q_OBJECT
  

    public:
        // Columns of the NickListView.
        enum NickListViewColumn
        {
            nlvcNetworkNickChannel = 0,
            nlvcNetwork = 0,
            nlvcNick = 0,
            nlvcChannel = 0,
            nlvcKabc = 1,
            nlvcAdditionalInfo = 1,
            nlvcServerName = 2                     // hidden
        };
        // Ids associated with menu/button commands.
        enum CommandIDs
        {
            ciAddressbookChange, ciAddressbookNew, ciAddressbookDelete, ciAddressbookEdit,
            ciSendEmail, ciWhois, ciJoinChannel, ciOpenQuery
        };
        enum NickState
        {
            nsNotANick = 0,                       // User didn't click on a nickname.
            nsNoAddress = 1,                      // Nick does not have an addressbook association.
            nsHasAddress = 2                      // Nick has an associated addressbook entry.
        };

        explicit NicksOnline(TQWidget* parent);
        ~NicksOnline();

        // These are here for the benefit of NicksOnlineTooltip.
        TDEListView* getNickListView();
        NickInfoPtr getNickInfo(const TQListViewItem* item);

        virtual bool canBeFrontView()   { return true; }

        signals:
        /**
         * Emitted when user clicks Edit Watch List button.
         */
        void editClicked();
        /**
         * Emitted whenever user double-clicks a nick in the Nicks Online tab.
         */
        void doubleClicked(const TQString& server,const TQString& nick);

        void showView(ChatWindow* view);

    public slots:

        /**
         * Refresh the nicklistview for a single server.
         * @param server            The server to be refreshed.
         */
        void updateServerOnlineList(Server* server);

    protected slots:
        /**
         * When a user double-clicks a nickname in the nicklistview, let server know so that
         * it can perform the user's chosen default action for that.
         */
        void processDoubleClick(TQListViewItem* item);
        /**
         * Timer used to refresh display.
         */
        void timerFired();
        /**
         * Received when user clicks the Edit Contact (or New Contact) button.
         */
        void slotEditContactButton_Clicked();
        /**
         * Received when user clicks the Change Association button.
         */
        void slotChangeAssociationButton_Clicked();
        /**
         * Received when user clicks the Delete Association button.
         */
        void slotDeleteAssociationButton_Clicked();
        /**
         * Received when user selects a different item in the nicklistview.
         */
        void slotNickListView_SelectionChanged();
        /**
         * Received when right-clicking an item in the NickListView.
         */
        void slotNickListView_RightButtonClicked(TQListViewItem* item, const TQPoint& pt);
        /**
         * Received from server when a NickInfo changes its information.
         */
        void slotNickInfoChanged(Server* server, const NickInfoPtr nickInfo);
        /**
         * Received from popup menu when user chooses something.
         */
        void slotPopupMenu_Activated(int id);

    protected:
        /** Called from ChatWindow adjustFocus */
        virtual void childAdjustFocus();

    private:
        /**
        * Returns the named child of parent item in a NicksOnlineItem
        * @param parent            Pointer to a NicksOnlineItem.
        * @param name              The name in the desired child TQListViewItem, must be in column 0.
        * @param type              The type of entry to be found
        * @return                  Pointer to the child TQListViewItem or 0 if not found.
        */
        TQListViewItem* findItemChild(const TQListViewItem* parent, const TQString& name, NicksOnlineItem::NickListViewColumn type);
        /**
        * Returns the first occurrence of a child item of a given type in a NicksOnlineItem
        * @param parent            Pointer to a NicksOnlineItem.
        * @param type              The type of entry to be found
        * @return                  Pointer to the child TQListViewItem or 0 if not found.
        */
        TQListViewItem* findItemType(const TQListViewItem* parent, NicksOnlineItem::NickListViewColumn type);
        /**
         * Returns a pointer to the network TQListViewItem with the given name.
         * @param name              The name of the network, assumed to be in column 0 of the item.
         * @return                  Pointer to the TQListViewItem or 0 if not found.
         */
        TQListViewItem* findNetworkRoot(const TQString& name);
        /**
         * Refresh the nicklistview for all servers.
         */
        void refreshAllServerOnlineLists();
        /**
         * Refreshes the information for the given item in the list.
         * @param item               Pointer to listview item.
         */
        void refreshItem(TQListViewItem* item);
        /**
         * Return a string containing formatted additional information about a nick.
         * @param nickInfo          A pointer to NickInfo structure for the nick.
         * @return                  A string formatted for display containing the information
         *                          about the nick.
         * @return needWhois        True if a WHOIS needs to be performed on the nick
         *                          to get additional information.
         */
        TQString getNickAdditionalInfo(NickInfoPtr nickInfo, TDEABC::Addressee addressee,
            bool& needWhois);
        /**
         * Invokes the KAddressBook contact editor for the specified contact id.
         * @param uid               Id of the contact.
         * @return                  False if unable to invoke the Contact editor.
         */
        bool editAddressee(const TQString &uid);
        /**
         * Returns the server name and nickname of the specified nicklistview item.
         * @param item              The nicklistview item.
         * @return serverName       Name of the server for the nick at the item, or Null if not a nick.
         * @return nickname         The nickname at the item.
         */
        bool getItemServerAndNick(const TQListViewItem* item, TQString& serverName, TQString& nickname);
        /**
         * Given a server name and nickname, returns the item in the Nick List View displaying
         * the nick.
         * @param serverName        Name of server.Server
         * @param nickname          Nick name.
         * @return                  Pointer to TQListViewItem displaying the nick, or 0 if not found.
         *
         * @see getItemServerAndNick
         */
        TQListViewItem* getServerAndNickItem(const TQString& serverName, const TQString& nickname);
        /**
         * Perform an addressbook command (edit contact, create new contact,
         * change/delete association.)
         * @param id                The command id.  @ref CommandIDs.
         *
         * The operation is performed on the nickname at the currently-selected item in
         * the nicklistview.
         *
         * Also refreshes the nicklistview display to reflect the new addressbook state
         * for the nick.
         */
        void doCommand(int id);
        /**
         * Get the addressbook state of the nickname at the specified nicklistview item.
         * @param item              Item of the nicklistview.
         * @return                  Addressbook state.
         * 0 = not a nick, 1 = nick has no addressbook association, 2 = nick has association
         */
        int getNickAddressbookState(TQListViewItem* item);
        /**
         * Sets the enabled/disabled state and labels of the addressbook buttons
         * based on the given nick addressbook state.
         * @param nickState         The state of the nick. 1 = not associated with addressbook,
         *                          2 = associated with addressbook.  @ref getNickAddressbookState.
         */
        void setupAddressbookButtons(int nickState);
        /**
         * Determines if a nick is online in any of the servers in a network and returns
         * a NickInfo if found, otherwise 0.
         * @param networkName        Server network name.
         * @param nickname           Nick name.
         * @return                   NickInfo if nick is online in any server, otherwise 0.
         */
        NickInfoPtr getOnlineNickInfo(TQString& networkName, TQString& nickname);
        /**
         * Requests a WHOIS for a specified server network and nickname.
         * The request is sent to the first server found in the network.
         * @param groupName          Server group name.
         * @param nickname           Nick name.
         */
        void requestWhois(TQString& networkName, TQString& nickname);

        // The main display of networks, nicks, and channels.
        TDEListView* m_nickListView;
        // Buttons on screen.
        TQPushButton* m_editContactButton;
        TQPushButton* m_changeAssociationButton;
        TQPushButton* m_deleteAssociationButton;
        // Context menu when right-clicking a nick.
        TQPopupMenu* m_popupMenu;
        // Helper to display tooltip information for nicks.
        Konversation::KonversationNicksOnlineToolTip *m_tooltip;
        // A string containing the identifier for the "Offline" listview item
        TQString c_offline;
        // Timer for refreshing display and generating WHOISes.
        TQTimer* m_timer;
        // Addressbook icon.
        TQIconSet m_tdeabcIconSet;
        /* Set to False every 8 seconds so that we generate a WHOIS on watch nicks that
           lack information.*/
        bool m_whoisRequested;
};
#endif