kplato

kptsummarytaskgeneralpanel.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 - 2006 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kptsummarytaskgeneralpanel.h"
00021 #include "kptsummarytaskdialog.h"
00022 #include "kpttask.h"
00023 #include "kptcommand.h"
00024 #include "kptconfig.h"
00025 #include "kptpart.h"
00026 
00027 #include <kmessagebox.h>
00028 #include <klineedit.h>
00029 #include <ktextedit.h>
00030 #include <kcombobox.h>
00031 #include <kdatetimewidget.h>
00032 #include <klocale.h>
00033 #include <kcommand.h>
00034 #include <kabc/addressee.h>
00035 #include <kabc/addresseedialog.h>
00036 
00037 #include <qpushbutton.h>
00038 #include <qlayout.h>
00039 #include <qlabel.h>
00040 #include <qdatetime.h> 
00041 #include <qdatetimeedit.h> 
00042 #include <qgroupbox.h> 
00043 #include <kdebug.h>
00044 
00045 namespace KPlato
00046 {
00047 
00048 SummaryTaskGeneralPanel::SummaryTaskGeneralPanel(Task &task, QWidget *p, const char *n)
00049     : SummaryTaskGeneralPanelBase(p, n),
00050       m_task(task)
00051 {
00052     setStartValues(task);
00053     
00054     connect(namefield, SIGNAL(textChanged(const QString&)), SLOT(slotObligatedFieldsFilled()));
00055     connect(leaderfield, SIGNAL(textChanged(const QString&)), SLOT(slotObligatedFieldsFilled()));
00056     connect(idfield, SIGNAL(textChanged(const QString&)), SLOT(slotObligatedFieldsFilled()));
00057     connect(descriptionfield, SIGNAL(textChanged()), SLOT(slotObligatedFieldsFilled()));
00058     
00059     connect(chooseLeader, SIGNAL(clicked()), SLOT(slotChooseResponsible()));
00060 
00061 }
00062 
00063 void SummaryTaskGeneralPanel::setStartValues(Task &task) {
00064     namefield->setText(task.name());
00065     leaderfield->setText(task.leader());
00066     descriptionfield->setText(task.description());
00067     idfield->setText(task.id());
00068     wbsfield->setText(task.wbs());
00069     
00070     namefield->setFocus();
00071     
00072 }
00073 
00074 void SummaryTaskGeneralPanel::slotObligatedFieldsFilled() {
00075     emit obligatedFieldsFilled(!namefield->text().isEmpty() && !idfield->text().isEmpty());
00076 }
00077 
00078 KMacroCommand *SummaryTaskGeneralPanel::buildCommand(Part *part) {
00079     KMacroCommand *cmd = new KMacroCommand(i18n("Modify Task"));
00080     bool modified = false;
00081 
00082     if (!namefield->isHidden() && m_task.name() != namefield->text()) {
00083         cmd->addCommand(new NodeModifyNameCmd(part, m_task, namefield->text()));
00084         modified = true;
00085     }
00086     if (!leaderfield->isHidden() && m_task.leader() != leaderfield->text()) {
00087         cmd->addCommand(new NodeModifyLeaderCmd(part, m_task, leaderfield->text()));
00088         modified = true;
00089     }
00090     if (!descriptionfield->isHidden() && 
00091         m_task.description() != descriptionfield->text()) {
00092         cmd->addCommand(new NodeModifyDescriptionCmd(part, m_task, descriptionfield->text()));
00093         modified = true;
00094     }
00095     if (!idfield->isHidden() && idfield->text() != m_task.id()) {
00096         cmd->addCommand(new NodeModifyIdCmd(part, m_task, idfield->text()));
00097         modified = true;
00098     }
00099     if (!modified) {
00100         delete cmd;
00101         return 0;
00102     }
00103     return cmd;
00104 }
00105 
00106 bool SummaryTaskGeneralPanel::ok() {
00107     if (idfield->text() != m_task.id() && m_task.findNode(idfield->text())) {
00108         KMessageBox::sorry(this, i18n("Task id must be unique"));
00109         idfield->setFocus();
00110         return false;
00111     }
00112     return true;
00113 }
00114 
00115 void SummaryTaskGeneralPanel::slotChooseResponsible() {
00116     KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00117     if (!a.isEmpty()) {
00118         leaderfield->setText(a.fullEmail());
00119         leaderfield->setFocus();
00120     }
00121 }
00122 
00123 
00124 }  //KPlato namespace
00125 
00126 #include "kptsummarytaskgeneralpanel.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys