summaryrefslogtreecommitdiffstats
path: root/quanta/project/membereditdlg.cpp
blob: 1b27d35407464c0cb5d3d72ef88376b52ec152f0 (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
/***************************************************************************
                          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 <tqcheckbox.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"

TQString simpleMemberStr = I18N_NOOP("Simple Member");
TQString taskLeaderStr = I18N_NOOP("Task Leader");
TQString teamLeaderStr = I18N_NOOP("Team Leader");
TQString subprojectLeaderStr = I18N_NOOP("Subproject Leader");


MemberEditDlg::MemberEditDlg(TQWidget *parent, const char *name)
 : MemberEditDlgS(parent, name)
{
   TQValueList<SubProject> *subprojects = Project::ref()->subprojects();
   for (TQValueList<SubProject>::ConstIterator it = subprojects->constBegin(); it != subprojects->constEnd(); ++it)
     subprojectCombo->insertItem((*it).name);
   subprojectCombo->setEnabled(false);
   editSubprojectsButton->setEnabled(false);

  TQMap<TQString, TeamMember> members = Project::ref()->allMembers();
  TQStringList items;
  for (TQMap<TQString, TeamMember>::ConstIterator it = members.constBegin(); it != members.constEnd(); ++it)
  {
     nameCombo->insertItem(it.key());
  }
  nameCombo->insertItem(TQString::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 TQString &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);
   TQValueList<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())
   {
      TQString 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()
{
  TQString name = nameCombo->currentText();
  TQMap<TQString, TeamMember> members = Project::ref()->allMembers();
  if (members.contains(name))
  {
     emailEdit->setText(members[name].email);
  }
}

void MemberEditDlg::selectMember(const TQString &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()
{
  TQMap<TQString, TQString> uidMap;
  TQString name;
  TQStringList 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"