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
|
/***************************************************************************
teammembersdlg.cpp - description
-------------------
begin : Wed Jul 7 2004
copyright : (C) 2004 Andras Mantia <[email protected]>
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
//qt includes
#include <tqlabel.h>
//kde includes
#include <kcombobox.h>
#include <kdialogbase.h>
#include <klineedit.h>
#include <klistview.h>
#include <klocale.h>
#include <kmessagebox.h>
//app includes
#include "teammembersdlg.h"
#include "membereditdlg.h"
#include "project.h"
#define NAME_COL 0
#define NICKNAME_COL 1
#define EMAIL_COL 2
#define ROLE_COL 3
#define TASK_COL 4
#define SUBPROJECT_COL 5
extern TQString simpleMemberStr;
extern TQString taskLeaderStr;
extern TQString teamLeaderStr;
extern TQString subprojectLeaderStr;
TeamMembersDlg::TeamMembersDlg(TQWidget *parent, const char *name)
: TeamMembersDlgS(parent, name)
{
m_yourself = "";
}
TeamMembersDlg::~TeamMembersDlg()
{
}
void TeamMembersDlg::slotAddMember()
{
KDialogBase addDlg(this, "add_member", true, i18n("New Member"), KDialogBase::Ok | KDialogBase::Cancel);
MemberEditDlg memberDlg(&addDlg);
addDlg.setMainWidget(&memberDlg);
bool result;
do {
result = addDlg.exec();
if (result)
{
TQString name = memberDlg.nameCombo->currentText();
TQString role = memberDlg.roleCombo->currentText();
TQString task = memberDlg.taskEdit->text();
TQString subProject = memberDlg.subprojectCombo->currentText();
TQString nickName = memberDlg.nicknameEdit->text();
TQString email = memberDlg.emailEdit->text();
if (name.isEmpty())
{
KMessageBox::error(this, i18n("The member name cannot be empty."));
addDlg.show();
} else
if (nickName.isEmpty())
{
KMessageBox::error(this, i18n("The nickname cannot be empty as it is used as a unique identifier."));
addDlg.show();
} else
if (!checkDuplicates(0L, name, nickName, email, role, task, subProject))
{
addDlg.show();
} else
{
TQListViewItem *item = new TQListViewItem(membersListView, name, nickName, email, role, task);
if (memberDlg.subprojectCombo->isEnabled())
item->setText(SUBPROJECT_COL, subProject);
result = false;
}
}
} while (result);
}
void TeamMembersDlg::slotEditMember()
{
TQListViewItem *item =membersListView->currentItem();
if (!item) return;
KDialogBase editDlg(this, "edit_member", true, i18n("Edit Member"), KDialogBase::Ok | KDialogBase::Cancel);
MemberEditDlg memberDlg(&editDlg);
memberDlg.selectMember(item->text(NAME_COL));
memberDlg.nicknameEdit->setText(item->text(NICKNAME_COL));
memberDlg.emailEdit->setText(item->text(EMAIL_COL));
TQString role = item->text(ROLE_COL);
for (int i = 0; i < memberDlg.roleCombo->count(); i++)
{
if (memberDlg.roleCombo->text(i) == role)
{
memberDlg.roleCombo->setCurrentItem(i);
memberDlg.slotRoleSelected(role);
break;
}
}
memberDlg.taskEdit->setText(item->text(TASK_COL));
int idx = 0;
int subprojectIdx = 0;
TQValueList<SubProject> *subprojects = Project::ref()->subprojects();
for (TQValueList<SubProject>::ConstIterator it = subprojects->constBegin(); it != subprojects->constEnd(); ++it)
{
if (item->text(SUBPROJECT_COL) == (*it).name)
{
subprojectIdx = idx;
break;
}
idx++;
}
memberDlg.subprojectCombo->setCurrentItem(subprojectIdx);
editDlg.setMainWidget(&memberDlg);
bool result;
do {
result = editDlg.exec();
if (result)
{
TQString name = memberDlg.nameCombo->currentText();
TQString nickName = memberDlg.nicknameEdit->text();
TQString email = memberDlg.emailEdit->text();
TQString role = memberDlg.roleCombo->currentText();
TQString task = memberDlg.taskEdit->text();
TQString subProject = memberDlg.subprojectCombo->currentText();
if (name.isEmpty())
{
KMessageBox::error(this, i18n("The member name cannot be empty."));
editDlg.show();
} else
if (nickName.isEmpty())
{
KMessageBox::error(this, i18n("The nickname cannot be empty as it is used as a unique identifier."));
editDlg.show();
} else
if (!checkDuplicates(item, name, nickName, email, role, task, subProject))
{
editDlg.show();
} else
{
item->setText(NAME_COL, name);
item->setText(NICKNAME_COL, nickName);
item->setText(EMAIL_COL, email);
item->setText(ROLE_COL, role);
item->setText(TASK_COL, task);
if (memberDlg.subprojectCombo->isEnabled())
item->setText(SUBPROJECT_COL, subProject);
result = false;
}
}
} while (result);
}
void TeamMembersDlg::slotDeleteMember()
{
TQListViewItem *item =membersListView->currentItem();
if (!item) return;
bool deleteYourself = (item->text(NICKNAME_COL) == m_yourself);
TQListViewItemIterator it(membersListView);
while ( it.current() )
{
if (item != it.current() && it.current()->text(NICKNAME_COL) == m_yourself)
{
deleteYourself = false;
break;
}
++it;
}
if (deleteYourself)
{
if (KMessageBox::warningContinueCancel(this, i18n("<qt>Are you sure that you want to remove yourself (<b>%1</b>) from the project team?<br>If you do so, you should select another member as yourself.</qt>").arg(item->text(NAME_COL)), i18n("Delete Member"), KStdGuiItem::del()) == KMessageBox::Continue)
{
delete item;
setYourself("");
}
} else
if (KMessageBox::warningContinueCancel(this, i18n("<qt>Are you sure that you want to remove <b>%1</b> from the project team?</qt>").arg(item->text(NAME_COL)), i18n("Delete Member"), KStdGuiItem::del()) == KMessageBox::Continue)
{
delete item;
}
}
bool TeamMembersDlg::checkDuplicates(TQListViewItem *item, const TQString &name, const TQString &nickName, const TQString &email, const TQString &role, const TQString &task, const TQString &subProject)
{
TQString s;
TQString nick;
TQListViewItemIterator it(membersListView);
while ( it.current() )
{
s = it.current()->text(ROLE_COL);
nick = it.current()->text(NICKNAME_COL);
if (item != it.current() && s == role &&
(role == i18n(teamLeaderStr.utf8()) ||
(role == i18n(taskLeaderStr.utf8()) && it.current()->text(TASK_COL) == task) ||
(role == i18n(subprojectLeaderStr.utf8()) && it.current()->text(SUBPROJECT_COL) == subProject)
) )
{
if (KMessageBox::warningYesNo(this, i18n("<qt>The <b>%1</b> role is already assigned to <b>%2</b>. Do you want to reassign it to the current member?</qt>").arg(role).arg(it.current()->text(NAME_COL)), TQString(), i18n("Reassign"), i18n("Do Not Reassign")) == KMessageBox::Yes)
{
it.current()->setText(ROLE_COL, i18n(simpleMemberStr.utf8()));
return true;
}
else
return false;
} else
if (nick.lower() == nickName.lower() && it.current() != item && (it.current()->text(EMAIL_COL) != email || it.current()->text(NAME_COL) != name))
{
KMessageBox::error(this, i18n("<qt>The <b>%1</b> nickname is already assigned to <b>%2 <%3></b>.</qt>").arg(nickName).arg(it.current()->text(NAME_COL)).arg(it.current()->text(EMAIL_COL)));
return false;
}
++it;
}
return true;
}
void TeamMembersDlg::slotSetToYourself()
{
TQListViewItem *item =membersListView->currentItem();
if (!item) return;
yourselfLabel->setText(item->text(NAME_COL) + " <" + item->text(EMAIL_COL) + ">");
m_yourself = item->text(NICKNAME_COL);
}
void TeamMembersDlg::setYourself(const TQString &name)
{
m_yourself = name;
if (name.isEmpty())
{
yourselfLabel->setText(i18n("Please select your identity from the member list."));
return;
}
TQListViewItemIterator it(membersListView);
while ( it.current() )
{
if (it.current()->text(NICKNAME_COL).lower() == name.lower())
{
yourselfLabel->setText(it.current()->text(NAME_COL)+ " <" + it.current()->text(EMAIL_COL) + ">");
break;
}
++it;
}
}
#include "teammembersdlg.moc"
|