2 ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
3 Copyright (C) 2004 beunited.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "IconMenuItem.h"
23 #include "ProcessController.h"
30 class QuitMenuItem
: public IconMenuItem
{
32 QuitMenuItem(team_id team
, BBitmap
* icon
, const char* title
,
33 BMessage
* m
, bool purge
= false);
34 team_id
Team() { return fTeam
; }
41 QuitMenuItem::QuitMenuItem(team_id team
, BBitmap
* icon
, const char* title
,
42 BMessage
* m
, bool purge
)
44 IconMenuItem(icon
, title
, m
, true, purge
), fTeam(team
)
52 QuitMenu::QuitMenu(const char* title
, info_pack
* infos
, int infosCount
)
55 fInfosCount(infosCount
),
58 SetTargetForItems(gPCView
);
63 QuitMenu::AttachedToWindow()
66 fMe
= new BMessenger(this);
68 be_roster
->StartWatching(*fMe
, B_REQUEST_LAUNCHED
| B_REQUEST_QUIT
);
71 be_roster
->GetAppList(&apps
);
72 for (int t
= CountItems() - 1; t
>= 0; t
--) {
73 QuitMenuItem
* item
= (QuitMenuItem
*)ItemAt(t
);
75 for (int a
= 0; !found
&& (tmid
= (team_id
)(addr_t
)apps
.ItemAt(a
)) != 0; a
++)
76 if (item
->Team() == tmid
)
81 for (int a
= 0; (tmid
= (team_id
)(addr_t
) apps
.ItemAt(a
)) != 0; a
++) {
85 BMenu::AttachedToWindow();
90 QuitMenu::DetachedFromWindow()
92 BMenu::DetachedFromWindow();
93 be_roster
->StopWatching(*fMe
);
100 QuitMenu::AddTeam(team_id tmid
)
104 while ((item
= (QuitMenuItem
*) ItemAt(t
++)) != NULL
) {
105 if (item
->Team() == tmid
)
110 while (t
< fInfosCount
&& tmid
!= fInfos
[t
].team_info
.team
) {
114 BMessage
* message
= new BMessage ('QtTm');
115 message
->AddInt32 ("team", tmid
);
118 item
= new QuitMenuItem(tmid
, fInfos
[t
].team_icon
, fInfos
[t
].team_name
,
122 if (get_team_info(tmid
, &infos
.team_info
) == B_OK
123 && get_team_name_and_icon(infos
, true))
124 item
= new QuitMenuItem(tmid
, infos
.team_icon
, infos
.team_name
,
128 item
->SetTarget(gPCView
);
136 QuitMenu::MessageReceived(BMessage
*msg
)
139 case B_SOME_APP_LAUNCHED
:
142 if (msg
->FindInt32("be:team", &tmid
) == B_OK
)
146 case B_SOME_APP_QUIT
:
149 if (msg
->FindInt32("be:team", &tmid
) == B_OK
) {
152 while ((item
= (QuitMenuItem
*) ItemAt(t
++)) != NULL
) {
153 if (item
->Team() == tmid
) {
154 delete RemoveItem(--t
);
163 BMenu::MessageReceived(msg
);