selectdialog.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <kdeversion.h>
00024 #include <kbuttonbox.h>
00025 #include <klistbox.h>
00026 #include <klocale.h>
00027 #include <kmessagebox.h>
00028
00029 #include <qgroupbox.h>
00030 #include <qlayout.h>
00031 #include <qlabel.h>
00032
00033 #include "resourcecalendar.h"
00034 #include "incidence.h"
00035
00036 #include "selectdialog.h"
00037
00038 using namespace KCal;
00039
00040 SelectDialog::SelectDialog( QPtrList<ResourceCalendar> list,
00041 Incidence* incidence,
00042 QWidget *parent, const char *name )
00043 : KDialog( parent, name, true )
00044 {
00045 setCaption( i18n( "Resource Selection" ) );
00046 resize( 550, 350 );
00047
00048 QVBoxLayout *mainLayout = new QVBoxLayout( this );
00049 mainLayout->setMargin( marginHint() );
00050 mainLayout->setSpacing( 10 );
00051
00052
00053 QString text = "<b><font size=\"+1\">";
00054 if ( incidence->type() == "Event" )
00055 text += i18n( "Choose where you want to store this event" );
00056 else if ( incidence->type() == "Todo" )
00057 text += i18n( "Choose where you want to store this task" );
00058 else
00059 text += i18n( "Choose where you want to store this incidence" );
00060 text += "<font></b><br>";
00061 if ( !incidence->summary().isEmpty() )
00062 text += i18n( "<b>Summary:</b> %1" ).arg( incidence->summary() ) + "<br>";
00063 if ( !incidence->location().isEmpty() )
00064 text += i18n( "<b>Location:</b> %1" ).arg( incidence->location() );
00065 text += "<br>";
00066 if ( !incidence->doesFloat() )
00067 text += i18n( "<b>Start:</b> %1, %2" )
00068 .arg( incidence->dtStartDateStr(), incidence->dtStartTimeStr() );
00069 else
00070 text += i18n( "<b>Start:</b> %1" ).arg( incidence->dtStartDateStr() );
00071 text += "<br>";
00072 if ( incidence->type() == "Event" ) {
00073 Event* event = static_cast<Event*>( incidence );
00074 if ( event->hasEndDate() )
00075 if ( !event->doesFloat() )
00076 text += i18n( "<b>End:</b> %1, %2" )
00077 .arg( event->dtEndDateStr(), event->dtEndTimeStr() );
00078 else
00079 text += i18n( "<b>End:</b> %1" ).arg( event->dtEndDateStr() );
00080 text += "<br>";
00081 }
00082 QLabel *description = new QLabel( text, this, "Incidence description" );
00083 mainLayout->addWidget( description );
00084
00085 QGroupBox *groupBox = new QGroupBox( 2, Qt::Horizontal, this );
00086 groupBox->setTitle( i18n( "Resources" ) );
00087
00088 mResourceId = new KListBox( groupBox );
00089
00090 mainLayout->addWidget( groupBox );
00091
00092 mainLayout->addSpacing( 10 );
00093
00094 KButtonBox *buttonBox = new KButtonBox( this );
00095
00096 buttonBox->addStretch();
00097
00098 #if KDE_IS_VERSION(3,3,0)
00099 buttonBox->addButton( KStdGuiItem::ok(), this, SLOT( accept() ) );
00100 buttonBox->addButton( KStdGuiItem::cancel(), this, SLOT( reject() ) );
00101 #else
00102 buttonBox->addButton( KStdGuiItem::ok().text(), this, SLOT( accept() ) );
00103 buttonBox->addButton( KStdGuiItem::cancel().text(), this, SLOT( reject() ) );
00104 #endif
00105
00106 buttonBox->layout();
00107
00108 mainLayout->addWidget( buttonBox );
00109
00110
00111 uint counter = 0;
00112 for ( uint i = 0; i < list.count(); ++i ) {
00113 ResourceCalendar *resource = list.at( i );
00114 if ( resource && !resource->readOnly() ) {
00115 mResourceMap.insert( counter, resource );
00116 mResourceId->insertItem( resource->resourceName() );
00117 counter++;
00118 }
00119 }
00120
00121 mResourceId->setCurrentItem( 0 );
00122 connect( mResourceId, SIGNAL(returnPressed(QListBoxItem*)),
00123 SLOT(accept()) );
00124 connect( mResourceId, SIGNAL( executed( QListBoxItem* ) ),
00125 SLOT( accept() ) );
00126 }
00127
00128 ResourceCalendar *SelectDialog::resource()
00129 {
00130 if ( mResourceId->currentItem() != -1 )
00131 return mResourceMap[ mResourceId->currentItem() ];
00132 else
00133 return 0;
00134 }
00135
00136 ResourceCalendar *SelectDialog::getResource( QPtrList<ResourceCalendar> list,
00137 Incidence* incidence,
00138 QWidget *parent )
00139 {
00140 if ( list.count() == 0 ) {
00141 KMessageBox::error( parent, i18n( "There is no resource available!" ) );
00142 return 0;
00143 }
00144
00145 if ( list.count() == 1 ) return list.first();
00146
00147
00148
00149 ResourceCalendar *found = 0;
00150 ResourceCalendar *it = list.first();
00151 while ( it ) {
00152 if ( !it->readOnly() ) {
00153 if ( found ) {
00154 found = 0;
00155 break;
00156 } else
00157 found = it;
00158 }
00159 it = list.next();
00160 }
00161
00162 if ( found )
00163 return found;
00164
00165 SelectDialog dlg( list, incidence, parent );
00166 if ( dlg.exec() == KDialog::Accepted ) return dlg.resource();
00167 else return 0;
00168 }
This file is part of the documentation for libkcal Library Version 3.3.2.