korganizer

resourceview.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include "resourceview.h"
00027 
00028 #include <kcolordialog.h>
00029 #include <kdialog.h>
00030 #include <klistview.h>
00031 #include <klocale.h>
00032 #include <kdebug.h>
00033 #include <kglobal.h>
00034 #include <kmessagebox.h>
00035 #include <kinputdialog.h>
00036 #include <kiconloader.h>
00037 #include <kresources/resource.h>
00038 #include <kresources/configdialog.h>
00039 #include <libkcal/calendarresources.h>
00040 
00041 #include <qhbox.h>
00042 #include <qheader.h>
00043 #include <qlayout.h>
00044 #include <qlabel.h>
00045 #include <qpainter.h>
00046 #include <qpushbutton.h>
00047 #include <qpopupmenu.h>
00048 #include <qtooltip.h>
00049 #include <qwhatsthis.h>
00050 
00051 #include "koprefs.h"
00052 
00053 using namespace KCal;
00054 
00055 ResourceViewFactory::ResourceViewFactory( KCal::CalendarResources *calendar,
00056                                           CalendarView *view )
00057   : mCalendar( calendar ), mView( view ), mResourceView( 0 )
00058 {
00059 }
00060 
00061 CalendarViewExtension *ResourceViewFactory::create( QWidget *parent )
00062 {
00063   mResourceView = new ResourceView( mCalendar, parent );
00064 
00065   QObject::connect( mResourceView, SIGNAL( resourcesChanged() ),
00066                     mView, SLOT( updateView() ) );
00067   QObject::connect( mResourceView, SIGNAL( resourcesChanged() ),
00068                     mView, SLOT( updateCategories() ) );
00069 
00070   QObject::connect( mCalendar,
00071                     SIGNAL( signalResourceAdded( ResourceCalendar * ) ),
00072                     mResourceView,
00073                     SLOT( addResourceItem( ResourceCalendar * ) ) );
00074   QObject::connect( mCalendar,
00075                     SIGNAL( signalResourceModified( ResourceCalendar * ) ),
00076                     mResourceView,
00077                     SLOT( updateResourceItem( ResourceCalendar * ) ) );
00078   QObject::connect( mCalendar, SIGNAL( signalResourceAdded( ResourceCalendar * ) ),
00079                     mView, SLOT( updateCategories() ) );
00080   QObject::connect( mCalendar, SIGNAL( signalResourceModified( ResourceCalendar * ) ),
00081                     mView, SLOT( updateCategories() ) );
00082 
00083   return mResourceView;
00084 }
00085 
00086 ResourceView *ResourceViewFactory::resourceView() const
00087 {
00088   return mResourceView;
00089 }
00090 
00091 ResourceItem::ResourceItem( ResourceCalendar *resource, ResourceView *view,
00092                             KListView *parent )
00093   : QCheckListItem( parent, resource->resourceName(), CheckBox ),
00094     mResource( resource ), mView( view ), mBlockStateChange( false ),
00095     mIsSubresource( false ), mResourceIdentifier( QString::null ),
00096     mSubItemsCreated( false ), mIsStandardResource( false )
00097 {
00098   mResourceColor = QColor();
00099   setGuiState();
00100 
00101   if ( mResource->isActive() ) {
00102     createSubresourceItems();
00103   }
00104 }
00105 
00106 void ResourceItem::createSubresourceItems()
00107 {
00108   const QStringList subresources = mResource->subresources();
00109   if ( !subresources.isEmpty() ) {
00110     setOpen( true );
00111     setExpandable( true );
00112     // This resource has subresources
00113     QStringList::ConstIterator it;
00114     for ( it=subresources.begin(); it!=subresources.end(); ++it ) {
00115       ResourceItem *item = new ResourceItem( mResource, *it, mResource->labelForSubresource( *it ),
00116                                              mView, this );
00117       QColor resourceColor = *KOPrefs::instance()->resourceColor( *it );
00118       item->setResourceColor( resourceColor );
00119       item->update();
00120     }
00121   }
00122   mSubItemsCreated = true;
00123 }
00124 
00125 ResourceItem::ResourceItem( KCal::ResourceCalendar *resource,
00126                             const QString& sub, const QString& label,
00127                             ResourceView *view, ResourceItem* parent )
00128 
00129   : QCheckListItem( parent, label, CheckBox ), mResource( resource ),
00130     mView( view ), mBlockStateChange( false ), mIsSubresource( true ),
00131     mSubItemsCreated( false ), mIsStandardResource( false )
00132 {
00133   mResourceColor = QColor();
00134   mResourceIdentifier = sub;
00135   setGuiState();
00136 }
00137 
00138 void ResourceItem::setGuiState()
00139 {
00140   mBlockStateChange = true;
00141   if ( mIsSubresource )
00142     setOn( mResource->subresourceActive( mResourceIdentifier ) );
00143   else
00144     setOn( mResource->isActive() );
00145   mBlockStateChange = false;
00146 }
00147 
00148 void ResourceItem::stateChange( bool active )
00149 {
00150   if ( mBlockStateChange ) return;
00151 
00152   if ( mIsSubresource ) {
00153     mResource->setSubresourceActive( mResourceIdentifier, active );
00154   } else {
00155     if ( active ) {
00156       if ( mResource->load() ) {
00157         mResource->setActive( true );
00158         if ( !mSubItemsCreated )
00159           createSubresourceItems();
00160       }
00161     } else {
00162       if ( mResource->save() ) mResource->setActive( false );
00163       mView->requestClose( mResource );
00164     }
00165 
00166     setOpen( mResource->isActive() && childCount() > 0 );
00167 
00168     setGuiState();
00169   }
00170 
00171   mView->emitResourcesChanged();
00172 }
00173 
00174 void ResourceItem::update()
00175 {
00176   setGuiState();
00177 }
00178 
00179 void ResourceItem::setResourceColor(QColor& color)
00180 {
00181   if ( color.isValid() ) {
00182     if ( mResourceColor != color ) {
00183       QPixmap px(height()-4,height()-4);
00184       mResourceColor = color;
00185       px.fill(color);
00186       setPixmap(0,px);
00187     }
00188   } else {
00189     mResourceColor = color ;
00190     setPixmap(0,0);
00191   }
00192 }
00193 
00194 void ResourceItem::setStandardResource( bool std )
00195 {
00196   if ( mIsStandardResource != std ) {
00197     mIsStandardResource = std;
00198     repaint();
00199   }
00200 }
00201 
00202 void ResourceItem::paintCell(QPainter *p, const QColorGroup &cg,
00203       int column, int width, int alignment)
00204 {
00205   QFont oldFont = p->font();
00206   QFont newFont = oldFont;
00207   newFont.setBold( mIsStandardResource && !mIsSubresource );
00208   p->setFont( newFont );
00209   QCheckListItem::paintCell( p, cg, column, width, alignment );
00210   p->setFont( oldFont );
00211 /*  QColorGroup _cg = cg;
00212   if(!mResource) return;
00213   _cg.setColor(QColorGroup::Base, getTextColor(mResourceColor));*/
00214 }
00215 
00216 
00217 ResourceView::ResourceView( KCal::CalendarResources *calendar,
00218                             QWidget *parent, const char *name )
00219   : CalendarViewExtension( parent, name ), mCalendar( calendar )
00220 {
00221   QBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
00222 
00223   QHBoxLayout *buttonBox = new QHBoxLayout();
00224   buttonBox->setSpacing( KDialog::spacingHint() );
00225   topLayout->addLayout( buttonBox );
00226 
00227   QLabel *calLabel = new QLabel( i18n( "Calendar" ), this );
00228   buttonBox->addWidget( calLabel );
00229   buttonBox->addStretch( 1 );
00230 
00231   mAddButton = new QPushButton( this, "add" );
00232   mAddButton->setIconSet( SmallIconSet( "add" ) );
00233   buttonBox->addWidget( mAddButton );
00234   QToolTip::add( mAddButton, i18n( "Add calendar" ) );
00235   QWhatsThis::add( mAddButton,
00236                    i18n( "<qt><p>Press this button to add a resource to "
00237                          "KOrganizer.</p>"
00238                          "<p>Events, journal entries and to-dos are retrieved "
00239                          "and stored on resources. Available "
00240                          "resources include groupware servers, local files, "
00241                          "journal entries as blogs on a server, etc... </p>"
00242                          "<p>If you have more than one active resource, "
00243                          "when creating incidents you will either automatically "
00244                          "use the default resource or be prompted "
00245                          "to select the resource to use.</p></qt>" ) );
00246   mEditButton = new QPushButton( this, "edit" );
00247   mEditButton->setIconSet( SmallIconSet( "edit" ) );
00248   buttonBox->addWidget( mEditButton );
00249   QToolTip::add( mEditButton, i18n( "Edit calendar settings" ) );
00250   QWhatsThis::add( mEditButton,
00251                    i18n( "Press this button to edit the resource currently "
00252                          "selected on the KOrganizer resources list above." ) );
00253   mDeleteButton = new QPushButton( this, "del" );
00254   mDeleteButton->setIconSet( SmallIconSet( "remove" ) );
00255   buttonBox->addWidget( mDeleteButton );
00256   QToolTip::add( mDeleteButton, i18n( "Remove calendar" ) );
00257   QWhatsThis::add( mDeleteButton,
00258                    i18n( "Press this button to delete the resource currently "
00259                          "selected on the KOrganizer resources list above." ) );
00260   mDeleteButton->setDisabled( true );
00261   mEditButton->setDisabled( true );
00262 
00263   mListView = new KListView( this );
00264   mListView->header()->hide();
00265   QWhatsThis::add( mListView,
00266                    i18n( "<qt><p>Select on this list the active KOrganizer "
00267                          "resources. Check the resource box to make it "
00268                          "active. Press the \"Add...\" button below to add new "
00269                          "resources to the list.</p>"
00270                          "<p>Events, journal entries and to-dos are retrieved "
00271                          "and stored on resources. Available "
00272                          "resources include groupware servers, local files, "
00273                          "journal entries as blogs on a server, etc...</p>"
00274                          "<p>If you have more than one active resource, "
00275                          "when creating incidents you will either automatically "
00276                          "use the default resource or be prompted "
00277                          "to select the resource to use.</p></qt>" ) );
00278   mListView->addColumn( i18n("Calendar") );
00279   mListView->setResizeMode( QListView::LastColumn );
00280   topLayout->addWidget( mListView );
00281 
00282   connect( mListView, SIGNAL( clicked( QListViewItem * ) ),
00283            SLOT( currentChanged( QListViewItem * ) ) );
00284   connect( mAddButton, SIGNAL( clicked() ), SLOT( addResource() ) );
00285   connect( mDeleteButton, SIGNAL( clicked() ), SLOT( removeResource() ) );
00286   connect( mEditButton, SIGNAL( clicked() ), SLOT( editResource() ) );
00287   connect( mListView, SIGNAL( doubleClicked ( QListViewItem *, const QPoint &,
00288                                               int ) ),
00289            SLOT( editResource() ) );
00290   connect( mListView, SIGNAL( contextMenuRequested ( QListViewItem *,
00291                                                      const QPoint &, int ) ),
00292            SLOT( contextMenuRequested( QListViewItem *, const QPoint &,
00293                                        int ) ) );
00294 
00295   updateView();
00296 }
00297 
00298 ResourceView::~ResourceView()
00299 {
00300 }
00301 
00302 void ResourceView::updateView()
00303 {
00304   mListView->clear();
00305 
00306   KCal::CalendarResourceManager *manager = mCalendar->resourceManager();
00307 
00308   KCal::CalendarResourceManager::Iterator it;
00309   for( it = manager->begin(); it != manager->end(); ++it ) {
00310     addResourceItem( *it );
00311   }
00312 }
00313 
00314 void ResourceView::emitResourcesChanged()
00315 {
00316   mCalendar->resourceManager()->writeConfig();
00317   emit resourcesChanged();
00318 }
00319 
00320 void ResourceView::addResource()
00321 {
00322   bool ok = false;
00323   KCal::CalendarResourceManager *manager = mCalendar->resourceManager();
00324   ResourceItem *i = static_cast<ResourceItem*>( mListView->selectedItem() );
00325   if ( i && ( i->isSubresource() || i->resource()->canHaveSubresources() ) ) {
00326     const QString folderName = KInputDialog::getText( i18n( "Add Subresource" ),
00327             i18n( "Please enter a name for the new subresource" ), QString::null,
00328             &ok, this );
00329     if ( !ok )
00330       return;
00331     const QString parentId = i->isSubresource() ? i->resourceIdentifier() : QString:: null;
00332     if ( !i->resource()->addSubresource( folderName, parentId ) ) {
00333       KMessageBox::error( this, i18n("<qt>Unable to create subresource <b>%1</b>.</qt>")
00334                                 .arg( folderName ) );
00335     }
00336     return;
00337   }
00338 
00339   QStringList types = manager->resourceTypeNames();
00340   QStringList descs = manager->resourceTypeDescriptions();
00341   QString desc = KInputDialog::getItem( i18n( "Resource Configuration" ),
00342       i18n( "Please select type of the new resource:" ), descs, 0, false, &ok,
00343             this );
00344   if ( !ok )
00345     return;
00346 
00347   QString type = types[ descs.findIndex( desc ) ];
00348 
00349   // Create new resource
00350   ResourceCalendar *resource = manager->createResource( type );
00351   if( !resource ) {
00352     KMessageBox::error( this, i18n("<qt>Unable to create resource of type <b>%1</b>.</qt>")
00353                               .arg( type ) );
00354     return;
00355   }
00356 
00357   resource->setResourceName( i18n("%1 resource").arg( type ) );
00358 
00359   KRES::ConfigDialog *dlg = new KRES::ConfigDialog( this, QString("calendar"), resource,
00360                           "KRES::ConfigDialog" );
00361 
00362   bool success = true;
00363   if ( !dlg || !dlg->exec() )
00364     success = false;
00365 
00366   if ( success ) {
00367     resource->setTimeZoneId( KOPrefs::instance()->mTimeZoneId );
00368     if ( resource->isActive() && ( !resource->open() || !resource->load() ) ) {
00369       // ### There is a resourceLoadError() signal declared in ResourceCalendar
00370       //     but no subclass seems to make use of it. We could do better.
00371       KMessageBox::error( this, i18n("Unable to create the resource.")
00372                                 .arg( type ) );
00373       success = false;
00374     }
00375   }
00376 
00377   if ( success ) {
00378     manager->add( resource );
00379     // we have to call resourceAdded manually, because for in-process changes
00380     // the dcop signals are not connected, so the resource's signals would not
00381     // be connected otherwise
00382     mCalendar->resourceAdded( resource );
00383   }
00384 
00385   if ( !success )
00386     delete resource;
00387 
00388   delete dlg;
00389 
00390   //### maybe only do this if ( success )
00391   emitResourcesChanged();
00392 }
00393 
00394 void ResourceView::addResourceItem( ResourceCalendar *resource )
00395 {
00396 
00397   ResourceItem *item=new ResourceItem( resource, this, mListView );
00398 
00399   // assign a color, but only if this is a resource that actually
00400   // hold items at top level
00401   if ( !resource->canHaveSubresources() || resource->subresources().isEmpty() ) {
00402       QColor resourceColor = *KOPrefs::instance()->resourceColor(resource->identifier());
00403       item->setResourceColor(resourceColor);
00404       item->update();
00405   }
00406 
00407   connect( resource, SIGNAL( signalSubresourceAdded( ResourceCalendar *,
00408                                                      const QString &,
00409                                                      const QString &,
00410                                                      const QString & ) ),
00411            SLOT( slotSubresourceAdded( ResourceCalendar *, const QString &,
00412                                        const QString &, const QString & ) ) );
00413 
00414   connect( resource, SIGNAL( signalSubresourceRemoved( ResourceCalendar *,
00415                                                        const QString &,
00416                                                        const QString & ) ),
00417            SLOT( slotSubresourceRemoved( ResourceCalendar *, const QString &,
00418                                          const QString & ) ) );
00419 
00420   connect( resource, SIGNAL( resourceSaved( ResourceCalendar * ) ),
00421            SLOT( closeResource( ResourceCalendar * ) ) );
00422 
00423   updateResourceList();
00424   emit resourcesChanged();
00425 }
00426 
00427 // Add a new entry
00428 void ResourceView::slotSubresourceAdded( ResourceCalendar *calendar,
00429                                          const QString& /*type*/,
00430                                          const QString& resource,
00431                                          const QString& label)
00432 {
00433   QListViewItem *i = mListView->findItem( calendar->resourceName(), 0 );
00434   if ( !i )
00435     // Not found
00436     return;
00437 
00438   if ( findItemByIdentifier( resource ) ) return;
00439 
00440   ResourceItem *item = static_cast<ResourceItem *>( i );
00441   ResourceItem *newItem = new ResourceItem( calendar, resource, label, this, item );
00442   QColor resourceColor = *KOPrefs::instance()->resourceColor( resource );
00443   newItem->setResourceColor( resourceColor );
00444 }
00445 
00446 // Remove an entry
00447 void ResourceView::slotSubresourceRemoved( ResourceCalendar * /*calendar*/,
00448                                            const QString &/*type*/,
00449                                            const QString &resource )
00450 {
00451   delete findItemByIdentifier( resource );
00452   emit resourcesChanged();
00453 }
00454 
00455 void ResourceView::closeResource( ResourceCalendar *r )
00456 {
00457   if ( mResourcesToClose.find( r ) >= 0 ) {
00458     r->close();
00459     mResourcesToClose.remove( r );
00460   }
00461 }
00462 
00463 void ResourceView::updateResourceItem( ResourceCalendar *resource )
00464 {
00465   ResourceItem *item = findItem( resource );
00466   if ( item ) {
00467     item->update();
00468   }
00469 }
00470 
00471 ResourceItem *ResourceView::currentItem()
00472 {
00473   QListViewItem *item = mListView->currentItem();
00474   ResourceItem *rItem = static_cast<ResourceItem *>( item );
00475   return rItem;
00476 }
00477 
00478 void ResourceView::removeResource()
00479 {
00480   ResourceItem *item = currentItem();
00481   if ( !item ) return;
00482 
00483   const QString warningMsg = item->isSubresource() ?
00484         i18n("<qt>Do you really want to remove the subresource <b>%1</b>? "
00485               "Note that its contents will be completely deleted. This "
00486               "operation cannot be undone. </qt>").arg( item->text( 0 ) ) :
00487         i18n("<qt>Do you really want to remove the resource <b>%1</b>?</qt>").arg( item->text( 0 ) );
00488 
00489   int km = KMessageBox::warningContinueCancel( this, warningMsg, "",
00490         KGuiItem( i18n("&Remove" ), "editdelete") );
00491   if ( km == KMessageBox::Cancel ) return;
00492 
00493 // Don't be so restricitve
00494 #if 0
00495   if ( item->resource() == mCalendar->resourceManager()->standardResource() ) {
00496     KMessageBox::sorry( this,
00497                         i18n( "You cannot delete your standard resource." ) );
00498     return;
00499   }
00500 #endif
00501   if ( item->isSubresource() ) {
00502     if ( !item->resource()->removeSubresource( item->resourceIdentifier() ) )
00503       KMessageBox::sorry( this,
00504               i18n ("<qt>Failed to remove the subresource <b>%1</b>. The "
00505                   "reason could be that it is a built-in one which cannot "
00506                   "be removed, or that the removal of the underlying storage "
00507                   "folder failed.</qt>").arg( item->resource()->name() ) );
00508       return;
00509   } else {
00510     mCalendar->resourceManager()->remove( item->resource() );
00511   }
00512     mListView->takeItem( item );
00513     delete item;
00514 
00515   updateResourceList();
00516   emit resourcesChanged();
00517 }
00518 
00519 void ResourceView::editResource()
00520 {
00521   ResourceItem *item = currentItem();
00522   if (!item) return;
00523   ResourceCalendar *resource = item->resource();
00524 
00525   KRES::ConfigDialog dlg( this, QString("calendar"), resource,
00526                           "KRES::ConfigDialog" );
00527 
00528   if ( dlg.exec() ) {
00529     item->setText( 0, resource->resourceName() );
00530 
00531     mCalendar->resourceManager()->change( resource );
00532   }
00533   emitResourcesChanged();
00534 }
00535 
00536 void ResourceView::currentChanged( QListViewItem *item )
00537 {
00538    ResourceItem *i = currentItem();
00539    if ( !item || i->isSubresource() ) {
00540      mDeleteButton->setEnabled( false );
00541      mEditButton->setEnabled( false );
00542    } else {
00543      mDeleteButton->setEnabled( true );
00544      mEditButton->setEnabled( true );
00545    }
00546 }
00547 
00548 ResourceItem *ResourceView::findItem( ResourceCalendar *r )
00549 {
00550   QListViewItem *item;
00551   ResourceItem *i = 0;
00552   for( item = mListView->firstChild(); item; item = item->nextSibling() ) {
00553     i = static_cast<ResourceItem *>( item );
00554     if ( i->resource() == r ) break;
00555   }
00556   return i;
00557 }
00558 
00559 ResourceItem *ResourceView::findItemByIdentifier( const QString& id )
00560 {
00561   QListViewItem *item;
00562   ResourceItem *i = 0;
00563   for( item = mListView->firstChild(); item; item = item->itemBelow() ) {
00564     i = static_cast<ResourceItem *>( item );
00565     if ( i->resourceIdentifier() == id )
00566        return i;
00567   }
00568   return 0;
00569 }
00570 
00571 
00572 void ResourceView::contextMenuRequested ( QListViewItem *i,
00573                                           const QPoint &pos, int )
00574 {
00575   KCal::CalendarResourceManager *manager = mCalendar->resourceManager();
00576   ResourceItem *item = static_cast<ResourceItem *>( i );
00577 
00578   QPopupMenu *menu = new QPopupMenu( this );
00579   connect( menu, SIGNAL( aboutToHide() ), menu, SLOT( deleteLater() ) );
00580   if ( item ) {
00581     int reloadId = menu->insertItem( i18n("Re&load"), this,
00582                                      SLOT( reloadResource() ) );
00583     menu->setItemEnabled( reloadId, item->resource()->isActive() );
00584     int saveId = menu->insertItem( i18n("&Save"), this,
00585                                    SLOT( saveResource() ) );
00586     menu->setItemEnabled( saveId, item->resource()->isActive() );
00587     menu->insertSeparator();
00588 
00589     menu->insertItem( i18n("Show &Info"), this, SLOT( showInfo() ) );
00590     //FIXME: This is better on the resource dialog
00591     if ( KOPrefs::instance()->agendaViewColors() != KOPrefs::CategoryOnly ) {
00592       QPopupMenu *assignMenu= new QPopupMenu( menu );
00593       assignMenu->insertItem( i18n( "&Assign Color" ), this, SLOT( assignColor() ) );
00594       if ( item->resourceColor().isValid() )
00595         assignMenu->insertItem( i18n( "&Disable Color" ), this, SLOT( disableColor() ) );
00596       menu->insertItem( i18n( "Resources Colors" ), assignMenu );
00597     }
00598 
00599     menu->insertItem( i18n("&Edit..."), this, SLOT( editResource() ) );
00600     menu->insertItem( i18n("&Remove"), this, SLOT( removeResource() ) );
00601     if ( item->resource() != manager->standardResource() ) {
00602       menu->insertSeparator();
00603       menu->insertItem( i18n("Use as &Default Calendar"), this,
00604                         SLOT( setStandard() ) );
00605     }
00606 
00607     menu->insertSeparator();
00608  }
00609   menu->insertItem( i18n("&Add..."), this, SLOT( addResource() ) );
00610 
00611   menu->popup( pos );
00612 }
00613 
00614 void ResourceView::assignColor()
00615 {
00616   ResourceItem *item = currentItem();
00617   if ( !item )
00618     return;
00619   // A color without initialized is a color invalid
00620   QColor myColor;
00621   KCal::ResourceCalendar *cal = item->resource();
00622 
00623   QString identifier = cal->identifier();
00624   if ( item->isSubresource() )
00625     identifier = item->resourceIdentifier();
00626 
00627   QColor defaultColor =*KOPrefs::instance()->resourceColor( identifier );
00628 
00629   int result = KColorDialog::getColor( myColor,defaultColor);
00630 
00631   if ( result == KColorDialog::Accepted ) {
00632     KOPrefs::instance()->setResourceColor( identifier, myColor );
00633     item->setResourceColor( myColor );
00634     item->update();
00635     emitResourcesChanged();
00636   }
00637 }
00638 
00639 void ResourceView::disableColor()
00640 {
00641   ResourceItem *item = currentItem();
00642   if ( !item )
00643     return;
00644   QColor colorInvalid;
00645   KCal::ResourceCalendar *cal = item->resource();
00646   QString identifier = cal->identifier();
00647   if ( item->isSubresource() )
00648     identifier = item->resourceIdentifier();
00649   KOPrefs::instance()->setResourceColor( identifier, colorInvalid );
00650   item->setResourceColor( colorInvalid );
00651   item->update();
00652   emitResourcesChanged();
00653 }
00654 void ResourceView::showInfo()
00655 {
00656   ResourceItem *item = currentItem();
00657   if ( !item ) return;
00658 
00659   QString txt = "<qt>" + item->resource()->infoText() + "</qt>";
00660   KMessageBox::information( this, txt );
00661 }
00662 
00663 void ResourceView::reloadResource()
00664 {
00665   ResourceItem *item = currentItem();
00666   if ( !item ) return;
00667 
00668   ResourceCalendar *r = item->resource();
00669   r->load();
00670 }
00671 
00672 void ResourceView::saveResource()
00673 {
00674   ResourceItem *item = currentItem();
00675   if ( !item ) return;
00676 
00677   ResourceCalendar *r = item->resource();
00678   r->save();
00679 }
00680 
00681 void ResourceView::setStandard()
00682 {
00683   ResourceItem *item = currentItem();
00684   if ( !item ) return;
00685 
00686   ResourceCalendar *r = item->resource();
00687   KCal::CalendarResourceManager *manager = mCalendar->resourceManager();
00688   manager->setStandardResource( r );
00689   updateResourceList();
00690 }
00691 
00692 void ResourceView::updateResourceList()
00693 {
00694   QListViewItemIterator it( mListView );
00695   ResourceCalendar* stdRes = mCalendar->resourceManager()->standardResource();
00696   while ( it.current() ) {
00697     ResourceItem *item = static_cast<ResourceItem *>( it.current() );
00698     item->setStandardResource( item->resource() == stdRes );
00699     ++it;
00700   }
00701 }
00702 
00703 void ResourceView::showButtons( bool visible )
00704 {
00705   if ( visible ) {
00706     mAddButton->show();
00707     mDeleteButton->show();
00708     mEditButton->show();
00709   } else {
00710     mAddButton->hide();
00711     mDeleteButton->hide();
00712     mEditButton->hide();
00713   }
00714 }
00715 
00716 void ResourceView::requestClose( ResourceCalendar *r )
00717 {
00718   mResourcesToClose.append( r );
00719 }
00720 
00721 #include "resourceview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys