kplato

kptsummarytaskgeneralpanel.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 - 2006 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation;
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kptsummarytaskgeneralpanel.h"
21#include "kptsummarytaskdialog.h"
22#include "kpttask.h"
23#include "kptcommand.h"
24#include "kptconfig.h"
25#include "kptpart.h"
26
27#include <tdemessagebox.h>
28#include <klineedit.h>
29#include <ktextedit.h>
30#include <kcombobox.h>
31#include <kdatetimewidget.h>
32#include <tdelocale.h>
33#include <kcommand.h>
34#include <tdeabc/addressee.h>
35#include <tdeabc/addresseedialog.h>
36
37#include <tqpushbutton.h>
38#include <tqlayout.h>
39#include <tqlabel.h>
40#include <tqdatetime.h>
41#include <tqdatetimeedit.h>
42#include <tqgroupbox.h>
43#include <kdebug.h>
44
45namespace KPlato
46{
47
48SummaryTaskGeneralPanel::SummaryTaskGeneralPanel(Task &task, TQWidget *p, const char *n)
49 : SummaryTaskGeneralPanelBase(p, n),
50 m_task(task)
51{
52 setStartValues(task);
53
54 connect(namefield, TQ_SIGNAL(textChanged(const TQString&)), TQ_SLOT(slotObligatedFieldsFilled()));
55 connect(leaderfield, TQ_SIGNAL(textChanged(const TQString&)), TQ_SLOT(slotObligatedFieldsFilled()));
56 connect(idfield, TQ_SIGNAL(textChanged(const TQString&)), TQ_SLOT(slotObligatedFieldsFilled()));
57 connect(descriptionfield, TQ_SIGNAL(textChanged()), TQ_SLOT(slotObligatedFieldsFilled()));
58
59 connect(chooseLeader, TQ_SIGNAL(clicked()), TQ_SLOT(slotChooseResponsible()));
60
61}
62
63void SummaryTaskGeneralPanel::setStartValues(Task &task) {
64 namefield->setText(task.name());
65 leaderfield->setText(task.leader());
66 descriptionfield->setText(task.description());
67 idfield->setText(task.id());
68 wbsfield->setText(task.wbs());
69
70 namefield->setFocus();
71
72}
73
74void SummaryTaskGeneralPanel::slotObligatedFieldsFilled() {
75 emit obligatedFieldsFilled(!namefield->text().isEmpty() && !idfield->text().isEmpty());
76}
77
78KMacroCommand *SummaryTaskGeneralPanel::buildCommand(Part *part) {
79 KMacroCommand *cmd = new KMacroCommand(i18n("Modify Task"));
80 bool modified = false;
81
82 if (!namefield->isHidden() && m_task.name() != namefield->text()) {
83 cmd->addCommand(new NodeModifyNameCmd(part, m_task, namefield->text()));
84 modified = true;
85 }
86 if (!leaderfield->isHidden() && m_task.leader() != leaderfield->text()) {
87 cmd->addCommand(new NodeModifyLeaderCmd(part, m_task, leaderfield->text()));
88 modified = true;
89 }
90 if (!descriptionfield->isHidden() &&
91 m_task.description() != descriptionfield->text()) {
92 cmd->addCommand(new NodeModifyDescriptionCmd(part, m_task, descriptionfield->text()));
93 modified = true;
94 }
95 if (!idfield->isHidden() && idfield->text() != m_task.id()) {
96 cmd->addCommand(new NodeModifyIdCmd(part, m_task, idfield->text()));
97 modified = true;
98 }
99 if (!modified) {
100 delete cmd;
101 return 0;
102 }
103 return cmd;
104}
105
106bool SummaryTaskGeneralPanel::ok() {
107 if (idfield->text() != m_task.id() && m_task.findNode(idfield->text())) {
108 KMessageBox::sorry(this, i18n("Task id must be unique"));
109 idfield->setFocus();
110 return false;
111 }
112 return true;
113}
114
115void SummaryTaskGeneralPanel::slotChooseResponsible() {
116 TDEABC::Addressee a = TDEABC::AddresseeDialog::getAddressee(this);
117 if (!a.isEmpty()) {
118 leaderfield->setText(a.fullEmail());
119 leaderfield->setFocus();
120 }
121}
122
123
124} //KPlato namespace
125
126#include "kptsummarytaskgeneralpanel.moc"