libkcal Library API Documentation

selectdialog.cpp

00001 /*
00002     This file is part of libkresources.
00003 
00004     Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
00005     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00006     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021     Boston, MA 02111-1307, USA.
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   // Add a description of the incidence
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   // setup listbox
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   // the following lines will return a writeable resource if only _one_ writeable
00148   // resource exists
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 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:18:41 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003