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
|
/***************************************************************************
membereditdlg.cpp - description
-------------------
begin : Wed Jul 7 2004
copyright : (C) 2004 Andras Mantia <amantia@kde.org>
***************************************************************************/
/***************************************************************************
* *
* 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 <qcheckbox.h>
//kde includes
#include <kcombobox.h>
#include <kdialogbase.h>
#include <kinputdialog.h>
#include <klineedit.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kpushbutton.h>
#include <kabc/stdaddressbook.h>
//app includes
#include "listdlg.h"
#include "membereditdlg.h"
#include "subprojecteditdlgs.h"
#include "project.h"
QString simpleMemberStr = I18N_NOOP("Simple Member");
QString taskLeaderStr = I18N_NOOP("Task Leader");
QString teamLeaderStr = I18N_NOOP("Team Leader");
QString subprojectLeaderStr = I18N_NOOP("Subproject Leader");
MemberEditDlg::MemberEditDlg(QWidget *parent, const char *name)
: MemberEditDlgS(parent, name)
{
QValueList<SubProject> *subprojects = Project::ref()->subprojects();
for (QValueList<SubProject>::ConstIterator it = subprojects->constBegin(); it != subprojects->constEnd(); ++it)
subprojectCombo->insertItem((*it).name);
subprojectCombo->setEnabled(false);
editSubprojectsButton->setEnabled(false);
QMap<QString, TeamMember> members = Project::ref()->allMembers();
QStringList items;
for (QMap<QString, TeamMember>::ConstIterator it = members.constBegin(); it != members.constEnd(); ++it)
{
nameCombo->insertItem(it.key());
}
nameCombo->insertItem(QString::null, 0);
roleCombo->insertItem(i18n(teamLeaderStr.utf8()));
roleCombo->insertItem(i18n(subprojectLeaderStr.utf8()));
roleCombo->insertItem(i18n(taskLeaderStr.utf8()));
roleCombo->insertItem(i18n(simpleMemberStr.utf8()));
roleCombo->setCurrentItem(3);
}
MemberEditDlg::~MemberEditDlg()
{
}
void MemberEditDlg::slotRoleSelected(const QString &roleName)
{
if (roleName != i18n(subprojectLeaderStr.utf8()))
{
subprojectCombo->setEnabled(false);
editSubprojectsButton->setEnabled(false);
} else
{
subprojectCombo->setEnabled(true);
editSubprojectsButton->setEnabled(true);
}
}
void MemberEditDlg::slotEditSubprojects()
{
KDialogBase editDlg(this, "edit_subprojects", true, i18n("Edit Subprojects"), KDialogBase::Ok | KDialogBase::Cancel);
SubprojectEditDlgS subprojectDlg(&editDlg);
editDlg.setMainWidget(&subprojectDlg);
QValueList<SubProject> *subprojects = Project::ref()->subprojects();
int idx = 0;
SubProject subProject;
for (uint i = 0; i < subprojects->count(); i++)
{
subProject = (*subprojects)[i];
if (subprojectCombo->currentText() == subProject.name)
{
subprojectDlg.nameEdit->setText(subProject.name);
subprojectDlg.locationEdit->setText(subProject.location);
idx = i;
break;
}
}
if (subprojects->count() == 0)
subprojectDlg.createNew->setChecked(true);
if (editDlg.exec())
{
QString oldName = subProject.name;
subProject.name = subprojectDlg.nameEdit->text();
subProject.location = subprojectDlg.locationEdit->text();
if (subprojectDlg.createNew->isChecked() && (subProject.name != oldName))
{
subprojects->append(subProject);
subprojectCombo->insertItem(subProject.name);
subprojectCombo->setCurrentItem(subprojectCombo->count() - 1);
} else
{
(*subprojects)[idx] = subProject;
subprojectCombo->setCurrentText(subProject.name);
}
}
}
void MemberEditDlg::slotMemberSelected()
{
QString name = nameCombo->currentText();
QMap<QString, TeamMember> members = Project::ref()->allMembers();
if (members.contains(name))
{
emailEdit->setText(members[name].email);
}
}
void MemberEditDlg::selectMember(const QString &name)
{
bool found = false;
for (int i = 0; i < nameCombo->count(); i++)
{
if (nameCombo->text(i) == name)
{
nameCombo->setCurrentItem(i);
found = true;
break;
}
}
if (!found)
{
nameCombo->insertItem(name, 1);
nameCombo->setCurrentItem(1);
}
}
void MemberEditDlg::slotSelectFromAddrBook()
{
QMap<QString, QString> uidMap;
QString name;
QStringList result;
KABC::AddressBook *addressBook = KABC::StdAddressBook::self();
KABC::AddressBook::ConstIterator it;
KABC::AddressBook::ConstIterator end = addressBook->end();
for( it = addressBook->begin(); it != end; ++it )
{
result.append((*it).assembledName());
uidMap.insert((*it).assembledName(), (*it).uid());
}
result.sort();
if ( result.count() > 0 )
{
ListDlg listDlg(result);
listDlg.setCaption(i18n("Select Member"));
if (!listDlg.exec()) return;
name = listDlg.getEntry();
KABC::Addressee entry = addressBook->findByUid(uidMap[name]);
nameCombo->insertItem(name, 1);
nameCombo->setCurrentItem(1);
emailEdit->setText(entry.emails()[0]);
nicknameEdit->setText(entry.nickName());
} else
{
KMessageBox::error(this,i18n("No entries found in the addressbook."));
}
}
#include "membereditdlg.moc"
|