F:/KPlato/koffice/kplato/kptresourcedialog.cc

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 - 2005 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 "kptresourcedialog.h"
00021 #include "kptcommand.h"
00022 #include "kptpart.h"
00023 #include "kptproject.h"
00024 #include "kptresource.h"
00025 #include "kptcalendar.h"
00026 
00027 #include <QPushButton>
00028 #include <QLabel>
00029 #include <QLineEdit>
00030 #include <QComboBox>
00031 #include <QSpinBox>
00032 #include <QList>
00033 #include <qstringlist.h>
00034 
00035 #include <kabc/addressee.h>
00036 #include <kabc/addresseedialog.h>
00037 
00038 #include <kcommand.h>
00039 #include <kdatetimewidget.h>
00040 #include <kmessagebox.h>
00041 #include <klocale.h>
00042 #include <kglobal.h>
00043 #include <kdebug.h>
00044 
00045 namespace KPlato
00046 {
00047 
00048 ResourceDialogImpl::ResourceDialogImpl (QWidget *parent)
00049     : QWidget(parent)
00050 {
00051     setupUi(this);
00052 
00053     connect(type, SIGNAL(activated(int)), SLOT(slotChanged()));
00054     connect(units, SIGNAL(valueChanged(int)), SLOT(slotChanged()));
00055     connect(nameEdit, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
00056     connect(initialsEdit, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
00057     connect(emailEdit, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
00058 
00059     connect(calendarList, SIGNAL(activated(int)), SLOT(slotChanged()));
00060 
00061     connect(rateEdit, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
00062     connect(overtimeEdit, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()));
00063 
00064     connect(chooseBtn, SIGNAL(clicked()), SLOT(slotChooseResource()));
00065 
00066     connect(availableFrom, SIGNAL(valueChanged(const QDateTime&)), SLOT(slotChanged()));
00067     connect(availableUntil, SIGNAL(valueChanged(const QDateTime&)), SLOT(slotChanged()));
00068     connect(availableFrom, SIGNAL(valueChanged(const QDateTime&)), SLOT(slotAvailableFromChanged(const QDateTime&)));
00069     connect(availableUntil, SIGNAL(valueChanged(const QDateTime&)), SLOT(slotAvailableUntilChanged(const QDateTime&)));
00070 }
00071 
00072 
00073 void ResourceDialogImpl::slotChanged() {
00074     emit changed();
00075 }
00076 
00077 void ResourceDialogImpl::slotAvailableFromChanged(const QDateTime&) {
00078     if (availableUntil->dateTime() < availableFrom->dateTime()) {
00079         disconnect(availableUntil, SIGNAL(valueChanged(const QDateTime&)), this,  SLOT(slotAvailableUntilChanged(const QDateTime&)));
00080         //kDebug()<<"From: "<<availableFrom->dateTime().toString()<<" until="<<availableUntil->dateTime().toString()<<endl;
00081         availableUntil->setDateTime(availableFrom->dateTime());
00082         connect(availableUntil, SIGNAL(valueChanged(const QDateTime&)), SLOT(slotAvailableUntilChanged(const QDateTime&)));
00083     }
00084 }
00085 
00086 void ResourceDialogImpl::slotAvailableUntilChanged(const QDateTime&) {
00087     if (availableFrom->dateTime() > availableUntil->dateTime()) {
00088         disconnect(availableFrom, SIGNAL(valueChanged(const QDateTime&)), this,  SLOT(slotAvailableFromChanged(const QDateTime&)));
00089         //kDebug()<<"Until: "<<availableUntil->dateTime().toString()<<" from="<<availableFrom->dateTime().toString()<<endl;
00090         availableFrom->setDateTime(availableUntil->dateTime());
00091         connect(availableFrom, SIGNAL(valueChanged(const QDateTime&)), SLOT(slotAvailableFromChanged(const QDateTime&)));
00092     }
00093 }
00094 
00095 void ResourceDialogImpl::slotCalculationNeeded(const QString&) {
00096     emit calculate();
00097     emit changed();
00098 }
00099 
00100 void ResourceDialogImpl::slotChooseResource()
00101 {
00102     KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00103     if (!a.isEmpty()) {
00104         nameEdit->setText(a.assembledName());
00105         emailEdit->setText(a.preferredEmail());
00106         QStringList l = QStringList::split(' ', a.assembledName());
00107         QString in;
00108         QStringList::Iterator it = l.begin();
00109         for (/*int i = 0*/; it != l.end(); ++it) {
00110             in += (*it)[0];
00111         }
00112         initialsEdit->setText(in);
00113     }
00114 }
00115 
00117 
00118 ResourceDialog::ResourceDialog(Project &project, Resource *resource, QWidget *parent, const char *name)
00119     : KDialog(parent),
00120       m_original(resource),
00121       m_resource(resource),
00122       m_calculationNeeded(false)
00123 {
00124     setObjectName(name);
00125     
00126     setCaption( i18n("Resource Settings") );
00127     setButtons( Ok|Cancel );
00128     setDefaultButton( Ok );
00129     showButtonSeparator( true );
00130     dia = new ResourceDialogImpl(this);
00131     setMainWidget(dia);
00132     KDialog::enableButtonOk(false);
00133 
00134     dia->nameEdit->setText(resource->name());
00135     dia->initialsEdit->setText(resource->initials());
00136     dia->emailEdit->setText(resource->email());
00137     dia->type->setCurrentIndex((int)resource->type()); // NOTE: must match enum
00138     dia->units->setValue(resource->units());
00139     dia->availableFrom->setDateTime(resource->availableFrom());
00140     dia->availableUntil->setDateTime(resource->availableUntil());
00141     dia->rateEdit->setText(KGlobal::locale()->formatMoney(resource->normalRate()));
00142     dia->overtimeEdit->setText(KGlobal::locale()->formatMoney(resource->overtimeRate()));
00143 
00144     int cal = 0;
00145     dia->calendarList->addItem(i18n("None"));
00146     m_calendars.insert(0, 0);
00147     QList<Calendar*> list = project.calendars();
00148     int i=1;
00149     foreach (Calendar *c, list) {
00150         dia->calendarList->insertItem(i, c->name());
00151         m_calendars.insert(i, c);
00152         if (c == resource->calendar())
00153             cal = i;
00154         ++i;
00155     }
00156     dia->calendarList->setCurrentIndex(cal);
00157 
00158     connect(this, SIGNAL(okClicked()), SLOT(slotOk()));
00159     connect(dia, SIGNAL(changed()), SLOT(enableButtonOk()));
00160     connect(dia, SIGNAL(calculate()), SLOT(slotCalculationNeeded()));
00161     connect(dia->calendarList, SIGNAL(activated(int)), SLOT(slotCalendarChanged(int)));
00162 
00163 }
00164 
00165 
00166 void ResourceDialog::enableButtonOk() {
00167                 KDialog::enableButtonOk(true);
00168 }
00169 
00170 void ResourceDialog::slotCalculationNeeded() {
00171     m_calculationNeeded = true;
00172 }
00173 
00174 void ResourceDialog::slotOk() {
00175     m_resource.setName(dia->nameEdit->text());
00176     m_resource.setInitials(dia->initialsEdit->text());
00177     m_resource.setEmail(dia->emailEdit->text());
00178     m_resource.setType((Resource::Type)(dia->type->currentIndex()));
00179     m_resource.setUnits(dia->units->value());
00180 
00181     m_resource.setNormalRate(KGlobal::locale()->readMoney(dia->rateEdit->text()));
00182     m_resource.setOvertimeRate(KGlobal::locale()->readMoney(dia->overtimeEdit->text()));
00183     m_resource.setCalendar(m_calendars[dia->calendarList->currentIndex()]);
00184     m_resource.setAvailableFrom(dia->availableFrom->dateTime());
00185     m_resource.setAvailableUntil(dia->availableUntil->dateTime());
00186     accept();
00187 }
00188 
00189 void ResourceDialog::slotCalendarChanged(int /*cal*/) {
00190 
00191 }
00192 
00193 KCommand *ResourceDialog::buildCommand(Part *part) {
00194     return buildCommand(m_original, m_resource, part);
00195 }
00196 
00197 // static
00198 KCommand *ResourceDialog::buildCommand(Resource *original, Resource &resource, Part *part) {
00199     KMacroCommand *m=0;
00200     QString n = i18n("Modify Resource");
00201     if (resource.name() != original->name()) {
00202         if (!m) m = new KMacroCommand(n);
00203         m->addCommand(new ModifyResourceNameCmd(part, original, resource.name()));
00204     }
00205     if (resource.initials() != original->initials()) {
00206         if (!m) m = new KMacroCommand(n);
00207         m->addCommand(new ModifyResourceInitialsCmd(part, original, resource.initials()));
00208     }
00209     if (resource.email() != original->email()) {
00210         if (!m) m = new KMacroCommand(n);
00211         m->addCommand(new ModifyResourceEmailCmd(part, original, resource.email()));
00212     }
00213     if (resource.type() != original->type()) {
00214         if (!m) m = new KMacroCommand(n);
00215         m->addCommand(new ModifyResourceTypeCmd(part, original, resource.type()));
00216     }
00217     if (resource.units() != original->units()) {
00218         if (!m) m = new KMacroCommand(n);
00219         m->addCommand(new ModifyResourceUnitsCmd(part, original, resource.units()));
00220     }
00221     if (resource.availableFrom() != original->availableFrom()) {
00222         if (!m) m = new KMacroCommand(n);
00223         m->addCommand(new ModifyResourceAvailableFromCmd(part, original, resource.availableFrom()));
00224     }
00225     if (resource.availableUntil() != original->availableUntil()) {
00226         if (!m) m = new KMacroCommand(n);
00227         m->addCommand(new ModifyResourceAvailableUntilCmd(part, original, resource.availableUntil()));
00228     }
00229     if (resource.normalRate() != original->normalRate()) {
00230         if (!m) m = new KMacroCommand(n);
00231         m->addCommand(new ModifyResourceNormalRateCmd(part, original, resource.normalRate()));
00232     }
00233     if (resource.overtimeRate() != original->overtimeRate()) {
00234         if (!m) m = new KMacroCommand(n);
00235         m->addCommand(new ModifyResourceOvertimeRateCmd(part, original, resource.overtimeRate()));
00236     }
00237     if (resource.calendar(true) != original->calendar(true)) {
00238         if (!m) m = new KMacroCommand(n);
00239         m->addCommand(new ModifyResourceCalendarCmd(part, original, resource.calendar(true)));
00240     }
00241     return m;
00242 }
00243 
00244 }  //KPlato namespace
00245 
00246 #include "kptresourcedialog.moc"

Généré le Wed Nov 22 23:40:57 2006 pour KPlato par  doxygen 1.5.1-p1