00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "resourceview.h"
00027 #include "koviewmanager.h"
00028 #include "multiagendaview.h"
00029
00030 #include <dcopref.h>
00031 #include <kcolordialog.h>
00032 #include <kdialog.h>
00033 #include <klistview.h>
00034 #include <klocale.h>
00035 #include <kdebug.h>
00036 #include <kglobal.h>
00037 #include <kmessagebox.h>
00038 #include <kinputdialog.h>
00039 #include <kiconloader.h>
00040 #include <kresources/resource.h>
00041 #include <kresources/configdialog.h>
00042 #include <libkcal/calendarresources.h>
00043 #include <kconfig.h>
00044
00045 #include <qhbox.h>
00046 #include <qheader.h>
00047 #include <qlayout.h>
00048 #include <qlabel.h>
00049 #include <qpainter.h>
00050 #include <qpushbutton.h>
00051 #include <qpopupmenu.h>
00052 #include <qregexp.h>
00053 #include <qtooltip.h>
00054 #include <qwhatsthis.h>
00055
00056 #include "koprefs.h"
00057
00058 using namespace KCal;
00059
00060 ResourceViewFactory::ResourceViewFactory( CalendarResources *calendar, CalendarView *view )
00061 : mCalendar( calendar ), mCalendarView( view ), mResourceView( 0 )
00062 {
00063 }
00064
00065 CalendarViewExtension *ResourceViewFactory::create( QWidget *parent )
00066 {
00067 mResourceView = new ResourceView( mCalendar, mCalendarView, parent );
00068
00069 QObject::connect( mResourceView, SIGNAL( resourcesChanged() ),
00070 mCalendarView, SLOT( resourcesChanged() ) );
00071 QObject::connect( mResourceView, SIGNAL( resourcesChanged() ),
00072 mCalendarView, SLOT( updateCategories() ) );
00073
00074 QObject::connect( mCalendar,
00075 SIGNAL( signalResourceAdded( ResourceCalendar * ) ),
00076 mResourceView,
00077 SLOT( addResourceItem( ResourceCalendar * ) ) );
00078 QObject::connect( mCalendar,
00079 SIGNAL( signalResourceModified( ResourceCalendar * ) ),
00080 mResourceView,
00081 SLOT( updateResourceItem( ResourceCalendar * ) ) );
00082 QObject::connect( mCalendar, SIGNAL( signalResourceAdded( ResourceCalendar * ) ),
00083 mCalendarView, SLOT( updateCategories() ) );
00084 QObject::connect( mCalendar, SIGNAL( signalResourceModified( ResourceCalendar * ) ),
00085 mCalendarView, SLOT( updateCategories() ) );
00086
00087 return mResourceView;
00088 }
00089
00090 ResourceView *ResourceViewFactory::resourceView() const
00091 {
00092 return mResourceView;
00093 }
00094
00095 ResourceItem::ResourceItem( ResourceCalendar *resource, ResourceView *view,
00096 KListView *parent )
00097 : QCheckListItem( parent, resource->resourceName(), CheckBox ),
00098 mResource( resource ), mResourceView( view ), mBlockStateChange( false ),
00099 mIsSubresource( false ), mResourceIdentifier( QString::null ),
00100 mSubItemsCreated( false ), mIsStandardResource( false )
00101 {
00102 mResourceColor = QColor();
00103 setGuiState();
00104
00105 if ( mResource->isActive() ) {
00106 createSubresourceItems();
00107 }
00108 }
00109
00110 void ResourceItem::createSubresourceItems()
00111 {
00112 const QStringList subresources = mResource->subresources();
00113 if ( !subresources.isEmpty() ) {
00114 setOpen( true );
00115 setExpandable( true );
00116
00117 QStringList::ConstIterator it;
00118 for ( it=subresources.begin(); it!=subresources.end(); ++it ) {
00119 ResourceItem *item = new ResourceItem( mResource, *it, mResource->labelForSubresource( *it ),
00120 mResourceView, this );
00121 QColor resourceColor = *KOPrefs::instance()->resourceColor( *it );
00122 item->setResourceColor( resourceColor );
00123 item->update();
00124 }
00125 }
00126 mSubItemsCreated = true;
00127 }
00128
00129 ResourceItem::ResourceItem( ResourceCalendar *resource, const QString &identifier,
00130 const QString &label, ResourceView *view, ResourceItem *parent )
00131 : QCheckListItem( parent, label, CheckBox ), mResource( resource ),
00132 mResourceView( view ), mBlockStateChange( false ), mIsSubresource( true ),
00133 mSubItemsCreated( false ), mIsStandardResource( false )
00134 {
00135 mResourceColor = QColor();
00136 mResourceIdentifier = identifier;
00137 setGuiState();
00138 }
00139
00140 void ResourceItem::setGuiState()
00141 {
00142 mBlockStateChange = true;
00143 if ( mIsSubresource )
00144 setOn( mResource->subresourceActive( mResourceIdentifier ) );
00145 else
00146 setOn( mResource->isActive() );
00147 mBlockStateChange = false;
00148 }
00149
00150 void ResourceItem::stateChange( bool active )
00151 {
00152 if ( mBlockStateChange ) return;
00153
00154 if ( mIsSubresource ) {
00155 mResource->setSubresourceActive( mResourceIdentifier, active );
00156 } else {
00157 if ( active ) {
00158 if ( mResource->load() ) {
00159 mResource->setActive( true );
00160 if ( !mSubItemsCreated )
00161 createSubresourceItems();
00162 }
00163 } else {
00164
00165
00166 mResourceView->requestClose( mResource );
00167 if ( mResource->save() ) {
00168 mResource->setActive( false );
00169 }
00170 }
00171
00172 setOpen( mResource->isActive() && childCount() > 0 );
00173
00174 setGuiState();
00175 }
00176
00177 mResourceView->emitResourcesChanged();
00178 }
00179
00180 void ResourceItem::update()
00181 {
00182 setGuiState();
00183 }
00184
00185 void ResourceItem::setResourceColor(QColor& color)
00186 {
00187 if ( color.isValid() ) {
00188 if ( mResourceColor != color ) {
00189 QPixmap px(height()-4,height()-4);
00190 mResourceColor = color;
00191 px.fill(color);
00192 setPixmap(0,px);
00193 }
00194 } else {
00195 mResourceColor = color ;
00196 setPixmap(0,0);
00197 }
00198 }
00199
00200 void ResourceItem::setStandardResource( bool std )
00201 {
00202 if ( mIsStandardResource != std ) {
00203 mIsStandardResource = std;
00204 repaint();
00205 }
00206 }
00207
00208 void ResourceItem::paintCell(QPainter *p, const QColorGroup &cg,
00209 int column, int width, int alignment)
00210 {
00211 QFont oldFont = p->font();
00212 QFont newFont = oldFont;
00213 newFont.setBold( mIsStandardResource && !mIsSubresource );
00214 p->setFont( newFont );
00215 QCheckListItem::paintCell( p, cg, column, width, alignment );
00216 p->setFont( oldFont );
00217
00218
00219
00220 }
00221
00222
00223 ResourceView::ResourceView( CalendarResources *calendar,
00224 CalendarView *view, QWidget *parent, const char *name )
00225 : CalendarViewExtension( parent, name ), mCalendar( calendar ), mCalendarView( view )
00226 {
00227 QBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
00228
00229 QHBoxLayout *buttonBox = new QHBoxLayout();
00230 buttonBox->setSpacing( KDialog::spacingHint() );
00231 topLayout->addLayout( buttonBox );
00232
00233 QLabel *calLabel = new QLabel( i18n( "Calendar" ), this );
00234 buttonBox->addWidget( calLabel );
00235 buttonBox->addStretch( 1 );
00236
00237 mAddButton = new QPushButton( this, "add" );
00238 mAddButton->setIconSet( SmallIconSet( "add" ) );
00239 buttonBox->addWidget( mAddButton );
00240 QToolTip::add( mAddButton, i18n( "Add calendar" ) );
00241 QWhatsThis::add( mAddButton,
00242 i18n( "<qt><p>Press this button to add a resource to "
00243 "KOrganizer.</p>"
00244 "<p>Events, journal entries and to-dos are retrieved "
00245 "and stored on resources. Available "
00246 "resources include groupware servers, local files, "
00247 "journal entries as blogs on a server, etc... </p>"
00248 "<p>If you have more than one active resource, "
00249 "when creating incidents you will either automatically "
00250 "use the default resource or be prompted "
00251 "to select the resource to use.</p></qt>" ) );
00252 mEditButton = new QPushButton( this, "edit" );
00253 mEditButton->setIconSet( SmallIconSet( "edit" ) );
00254 buttonBox->addWidget( mEditButton );
00255 QToolTip::add( mEditButton, i18n( "Edit calendar settings" ) );
00256 QWhatsThis::add( mEditButton,
00257 i18n( "Press this button to edit the resource currently "
00258 "selected on the KOrganizer resources list above." ) );
00259 mDeleteButton = new QPushButton( this, "del" );
00260 mDeleteButton->setIconSet( SmallIconSet( "remove" ) );
00261 buttonBox->addWidget( mDeleteButton );
00262 QToolTip::add( mDeleteButton, i18n( "Remove calendar" ) );
00263 QWhatsThis::add( mDeleteButton,
00264 i18n( "Press this button to delete the resource currently "
00265 "selected on the KOrganizer resources list above." ) );
00266 mDeleteButton->setDisabled( true );
00267 mEditButton->setDisabled( true );
00268
00269 mListView = new KListView( this );
00270 mListView->header()->hide();
00271 QWhatsThis::add( mListView,
00272 i18n( "<qt><p>Select on this list the active KOrganizer "
00273 "resources. Check the resource box to make it "
00274 "active. Press the \"Add...\" button below to add new "
00275 "resources to the list.</p>"
00276 "<p>Events, journal entries and to-dos are retrieved "
00277 "and stored on resources. Available "
00278 "resources include groupware servers, local files, "
00279 "journal entries as blogs on a server, etc...</p>"
00280 "<p>If you have more than one active resource, "
00281 "when creating incidents you will either automatically "
00282 "use the default resource or be prompted "
00283 "to select the resource to use.</p></qt>" ) );
00284 mListView->addColumn( i18n("Calendar") );
00285 mListView->setResizeMode( QListView::LastColumn );
00286 topLayout->addWidget( mListView );
00287
00288 connect( mListView, SIGNAL( clicked( QListViewItem * ) ),
00289 SLOT( currentChanged( QListViewItem * ) ) );
00290 connect( mAddButton, SIGNAL( clicked() ), SLOT( addResource() ) );
00291 connect( mDeleteButton, SIGNAL( clicked() ), SLOT( removeResource() ) );
00292 connect( mEditButton, SIGNAL( clicked() ), SLOT( editResource() ) );
00293 connect( mListView, SIGNAL( doubleClicked ( QListViewItem *, const QPoint &,
00294 int ) ),
00295 SLOT( editResource() ) );
00296 connect( mListView, SIGNAL( contextMenuRequested ( QListViewItem *,
00297 const QPoint &, int ) ),
00298 SLOT( contextMenuRequested( QListViewItem *, const QPoint &,
00299 int ) ) );
00300
00301 updateView();
00302 }
00303
00304 ResourceView::~ResourceView()
00305 {
00306 }
00307
00308 void ResourceView::updateView()
00309 {
00310 mListView->clear();
00311
00312 CalendarResourceManager *manager = mCalendar->resourceManager();
00313
00314 CalendarResourceManager::Iterator it;
00315 for( it = manager->begin(); it != manager->end(); ++it ) {
00316 addResourceItem( *it );
00317 }
00318 }
00319
00320 void ResourceView::emitResourcesChanged()
00321 {
00322 mCalendar->resourceManager()->writeConfig();
00323 emit resourcesChanged();
00324 }
00325
00326 void ResourceView::addResource()
00327 {
00328 bool ok = false;
00329 CalendarResourceManager *manager = mCalendar->resourceManager();
00330 ResourceItem *item = static_cast<ResourceItem*>( mListView->selectedItem() );
00331 if ( item && ( item->isSubresource() || item->resource()->canHaveSubresources() ) ) {
00332 const QString folderName =
00333 KInputDialog::getText( i18n( "Add Subresource" ),
00334 i18n( "Please enter a name for the new subresource" ), QString::null,
00335 &ok, this );
00336 if ( !ok )
00337 return;
00338 const QString parentId = item->isSubresource() ? item->resourceIdentifier() : QString:: null;
00339 if ( !item->resource()->addSubresource( folderName, parentId ) ) {
00340 KMessageBox::error(
00341 this,
00342 i18n( "<qt>Unable to create subresource <b>%1</b>.</qt>" ).arg( folderName ) );
00343 }
00344 return;
00345 }
00346
00347 QStringList types = manager->resourceTypeNames();
00348 QStringList descs = manager->resourceTypeDescriptions();
00349 QString desc =
00350 KInputDialog::getItem( i18n( "Resource Configuration" ),
00351 i18n( "Please select type of the new resource:" ),
00352 descs, 0, false, &ok, this );
00353 if ( !ok ) {
00354 return;
00355 }
00356
00357 QString type = types[ descs.findIndex( desc ) ];
00358
00359
00360 ResourceCalendar *resource = manager->createResource( type );
00361 if( !resource ) {
00362 KMessageBox::error(
00363 this,
00364 i18n( "<qt>Unable to create resource of type <b>%1</b>.</qt>" ).arg( type ) );
00365 return;
00366 }
00367
00368 KRES::ConfigDialog *dlg =
00369 new KRES::ConfigDialog( this, QString( "calendar" ), resource, "KRES::ConfigDialog" );
00370
00371 bool success = true;
00372 if ( !dlg || !dlg->exec() )
00373 success = false;
00374
00375 if ( success ) {
00376 resource->setTimeZoneId( KOPrefs::instance()->mTimeZoneId );
00377 if ( resource->isActive() && ( !resource->open() || !resource->load() ) ) {
00378
00379
00380 KMessageBox::error( this, i18n("Unable to create the resource.").arg( type ) );
00381 success = false;
00382 }
00383 }
00384
00385 if ( success ) {
00386 manager->add( resource );
00387
00388
00389
00390 mCalendar->resourceAdded( resource );
00391 }
00392
00393 if ( !success )
00394 delete resource;
00395
00396 delete dlg;
00397
00398
00399 emitResourcesChanged();
00400 }
00401
00402 void ResourceView::addResourceItem( ResourceCalendar *resource )
00403 {
00404
00405 ResourceItem *item=new ResourceItem( resource, this, mListView );
00406
00407
00408
00409 if ( !resource->canHaveSubresources() || resource->subresources().isEmpty() ) {
00410 QColor resourceColor = *KOPrefs::instance()->resourceColor(resource->identifier());
00411 item->setResourceColor(resourceColor);
00412 item->update();
00413 }
00414
00415 connect( resource, SIGNAL( signalSubresourceAdded( ResourceCalendar *,
00416 const QString &,
00417 const QString &,
00418 const QString & ) ),
00419 SLOT( slotSubresourceAdded( ResourceCalendar *, const QString &,
00420 const QString &, const QString & ) ) );
00421
00422 connect( resource, SIGNAL( signalSubresourceRemoved( ResourceCalendar *,
00423 const QString &,
00424 const QString & ) ),
00425 SLOT( slotSubresourceRemoved( ResourceCalendar *, const QString &,
00426 const QString & ) ) );
00427
00428 connect( resource, SIGNAL( resourceSaved( ResourceCalendar * ) ),
00429 SLOT( closeResource( ResourceCalendar * ) ) );
00430
00431 updateResourceList();
00432 emit resourcesChanged();
00433 }
00434
00435 static QString labelFromSubRes( ResourceCalendar *resource, const QString &subRes )
00436 {
00437
00438 DCOPRef ref( "kmail", "KMailICalIface" );
00439 DCOPReply reply = ref.call( "dimapAccounts" );
00440 if ( !reply.isValid() ) {
00441 kdDebug() << "DCOP Call dimapAccounts() failed " << endl;
00442 return QString();
00443 }
00444
00445 QString label;
00446 if ( (int)reply > 1 ) {
00447 if( resource && !resource->resourceName().isEmpty() ) {
00448 label = i18n( "My %1 (%2)" ).arg( subRes, resource->resourceName() );
00449 } else {
00450 label = i18n( "My %1" ).arg( subRes );
00451 }
00452 } else {
00453 label = i18n( "My %1" ).arg( subRes );
00454 }
00455 return label;
00456 }
00457
00458
00459 void ResourceView::slotSubresourceAdded( ResourceCalendar *resource,
00460 const QString &type,
00461 const QString &identifier,
00462 const QString &label )
00463 {
00464 Q_UNUSED( type );
00465
00466 QListViewItem *lvitem = mListView->findItem( resource->resourceName(), 0 );
00467 if ( !lvitem )
00468
00469 return;
00470
00471 if ( findItemByIdentifier( identifier ) ) return;
00472
00473 QString text = label;
00474 if ( identifier.contains( "/.INBOX.directory/" ) ) {
00475 text = identifier;
00476 text.remove( QRegExp( "^.*/\\.INBOX\\.directory/" ) );
00477 text = labelFromSubRes( resource, text );
00478 }
00479 ResourceItem *item = static_cast<ResourceItem *>( lvitem );
00480 ResourceItem *newItem = new ResourceItem( resource, identifier, text, this, item );
00481 QColor resourceColor = *KOPrefs::instance()->resourceColor( identifier );
00482 newItem->setResourceColor( resourceColor );
00483 }
00484
00485
00486 void ResourceView::slotSubresourceRemoved( ResourceCalendar *resource,
00487 const QString &type,
00488 const QString &identifier )
00489 {
00490 Q_UNUSED( resource );
00491 Q_UNUSED( type );
00492
00493 delete findItemByIdentifier( identifier );
00494 emit resourcesChanged();
00495 }
00496
00497 void ResourceView::closeResource( ResourceCalendar *resource )
00498 {
00499 if ( mResourcesToClose.find( resource ) >= 0 ) {
00500 resource->close();
00501 mResourcesToClose.remove( resource );
00502 }
00503 }
00504
00505 void ResourceView::updateResourceItem( ResourceCalendar *resource )
00506 {
00507 ResourceItem *item = findItem( resource );
00508 if ( item ) {
00509 item->update();
00510 }
00511 }
00512
00513 ResourceItem *ResourceView::currentItem()
00514 {
00515 QListViewItem *item = mListView->currentItem();
00516 ResourceItem *rItem = static_cast<ResourceItem *>( item );
00517 return rItem;
00518 }
00519
00520 void ResourceView::removeResource()
00521 {
00522 ResourceItem *item = currentItem();
00523 if ( !item ) return;
00524
00525
00526 if ( !item->isSubresource() ) {
00527 if ( item->resource() == mCalendar->resourceManager()->standardResource() ) {
00528 KMessageBox::sorry(
00529 this,
00530 i18n( "<qt>You may not delete your standard calendar resource.<p>"
00531 "You can change the standard calendar resource in the "
00532 "KDE Control Center using the KDE Resource settings under the "
00533 "KDE Components area.</qt>" ) );
00534 return;
00535 }
00536 }
00537
00538 QString moreInfo;
00539 if ( item->resource()->type() == "imap" || item->resource()->type() == "scalix" ) {
00540 moreInfo = i18n( "This is a groupware folder so you can always re-subscribe to the folder "
00541 "later as you desire." );
00542 } else {
00543 moreInfo = i18n( "The contents will not be removed so you can always re-add this calendar "
00544 "later as you desire." );
00545 }
00546
00547 int km =
00548 KMessageBox::warningContinueCancel(
00549 this,
00550 i18n( "<qt>Do you really want to remove the calendar <b>%1</b>?<p><b>Note:</b> %2</qt>" ).
00551 arg( item->text( 0 ), moreInfo ),
00552 "", KGuiItem( i18n( "&Remove" ) ) );
00553 if ( km == KMessageBox::Cancel ) {
00554 return;
00555 }
00556
00557 if ( item->isSubresource() ) {
00558 if ( !item->resource()->removeSubresource( item->resourceIdentifier() ) )
00559 KMessageBox::sorry(
00560 this,
00561 i18n ("<qt>Failed to remove the subresource <b>%1</b>. The "
00562 "reason could be that it is a built-in one which cannot "
00563 "be removed, or that the removal of the underlying storage "
00564 "folder failed.</qt>").arg( item->resource()->name() ) );
00565 return;
00566 } else {
00567 mCalendar->resourceManager()->remove( item->resource() );
00568 }
00569 mListView->takeItem( item );
00570 delete item;
00571
00572 updateResourceList();
00573 emit resourcesChanged();
00574 }
00575
00576 void ResourceView::editResource()
00577 {
00578 bool ok = false;
00579 ResourceItem *item = currentItem();
00580 if (!item) return;
00581 ResourceCalendar *resource = item->resource();
00582
00583 if ( item->isSubresource() ) {
00584 if ( resource->type() == "imap" || resource->type() == "scalix" ) {
00585 QString identifier = item->resourceIdentifier();
00586 if ( !identifier.contains( "/.INBOX.directory/" ) ) {
00587 KMessageBox::sorry(
00588 this,
00589 i18n( "Cannot rename someone else's calendar folder." ) );
00590 return;
00591 }
00592
00593 QString oldSubResourceName = identifier;
00594 oldSubResourceName.remove( QRegExp( "^.*/\\.INBOX\\.directory/" ) );
00595 QString newSubResourceName =
00596 KInputDialog::getText( i18n( "Rename Subresource" ),
00597 i18n( "Please enter a new name for the subresource" ),
00598 oldSubResourceName, &ok, this );
00599 if ( !ok ) {
00600 return;
00601 }
00602
00603 DCOPRef ref( "kmail", "KMailICalIface" );
00604 DCOPReply reply = ref.call( "changeResourceUIName", identifier, newSubResourceName );
00605 if ( !reply.isValid() ) {
00606 KMessageBox::sorry(
00607 this,
00608 i18n( "Communication with KMail failed when attempting to change the folder name." ) );
00609 return;
00610 }
00611
00612 item->setText( 0, labelFromSubRes( resource, newSubResourceName ) );
00613
00614 KOrg::BaseView *cV = mCalendarView->viewManager()->currentView();
00615 if ( cV && cV == mCalendarView->viewManager()->multiAgendaView() ) {
00616 mCalendarView->viewManager()->multiAgendaView()->deSelectAgendaView();
00617 }
00618 } else {
00619 KMessageBox::sorry(
00620 this,
00621 i18n ("<qt>Cannot edit the subresource <b>%1</b>.</qt>").arg( item->resource()->name() ) );
00622 }
00623 } else {
00624 KRES::ConfigDialog dlg( this, QString("calendar"), resource, "KRES::ConfigDialog" );
00625
00626 if ( dlg.exec() ) {
00627 item->setText( 0, resource->resourceName() );
00628 mCalendar->resourceManager()->change( resource );
00629 }
00630 }
00631 emitResourcesChanged();
00632 }
00633
00634 void ResourceView::currentChanged( QListViewItem *lvitem )
00635 {
00636 ResourceItem *item = currentItem();
00637 if ( !lvitem || item->isSubresource() ) {
00638 mDeleteButton->setEnabled( false );
00639 mEditButton->setEnabled( false );
00640 } else {
00641 mDeleteButton->setEnabled( true );
00642 mEditButton->setEnabled( true );
00643 }
00644 }
00645
00646 ResourceItem *ResourceView::findItem( ResourceCalendar *resource )
00647 {
00648 QListViewItem *lvitem;
00649 ResourceItem *item = 0;
00650 for( lvitem = mListView->firstChild(); lvitem; lvitem = lvitem->nextSibling() ) {
00651 item = static_cast<ResourceItem *>( lvitem );
00652 if ( item->resource() == resource ) break;
00653 }
00654 return item;
00655 }
00656
00657 ResourceItem *ResourceView::findItemByIdentifier( const QString &identifier )
00658 {
00659 QListViewItem *lvitem;
00660 ResourceItem *item = 0;
00661 for ( lvitem = mListView->firstChild(); lvitem; lvitem = lvitem->itemBelow() ) {
00662 item = static_cast<ResourceItem *>( lvitem );
00663 if ( item->resourceIdentifier() == identifier )
00664 return item;
00665 }
00666 return 0;
00667 }
00668
00669 void ResourceView::contextMenuRequested ( QListViewItem *lvitem, const QPoint &pos, int )
00670 {
00671 CalendarResourceManager *manager = mCalendar->resourceManager();
00672 ResourceItem *item = static_cast<ResourceItem *>( lvitem );
00673
00674 QPopupMenu *menu = new QPopupMenu( this );
00675 connect( menu, SIGNAL( aboutToHide() ), menu, SLOT( deleteLater() ) );
00676 if ( item ) {
00677 int reloadId = menu->insertItem( i18n("Re&load"), this,
00678 SLOT( reloadResource() ) );
00679 menu->setItemEnabled( reloadId, item->resource()->isActive() );
00680 int saveId = menu->insertItem( i18n("&Save"), this,
00681 SLOT( saveResource() ) );
00682 menu->setItemEnabled( saveId, item->resource()->isActive() );
00683 menu->insertSeparator();
00684
00685 menu->insertItem( i18n("Show &Info"), this, SLOT( showInfo() ) );
00686
00687 if ( KOPrefs::instance()->agendaViewColors() != KOPrefs::CategoryOnly ) {
00688 QPopupMenu *assignMenu= new QPopupMenu( menu );
00689 assignMenu->insertItem( i18n( "&Assign Color" ), this, SLOT( assignColor() ) );
00690 if ( item->resourceColor().isValid() )
00691 assignMenu->insertItem( i18n( "&Disable Color" ), this, SLOT( disableColor() ) );
00692 menu->insertItem( i18n( "Resources Colors" ), assignMenu );
00693 }
00694
00695 if ( item->isSubresource() &&
00696 ( item->resource()->type() == "imap" || item->resource()->type() == "scalix" ) ) {
00697 if ( item->resourceIdentifier().contains( "/.INBOX.directory/" ) ) {
00698 menu->insertItem( i18n("&Rename..."), this, SLOT( editResource() ) );
00699 }
00700 } else {
00701 menu->insertItem( i18n("&Edit..."), this, SLOT( editResource() ) );
00702 }
00703 menu->insertItem( i18n("&Remove"), this, SLOT( removeResource() ) );
00704 if ( item->resource() != manager->standardResource() ) {
00705 menu->insertSeparator();
00706 menu->insertItem( i18n("Use as &Default Calendar"), this,
00707 SLOT( setStandard() ) );
00708 }
00709
00710 menu->insertSeparator();
00711 }
00712 menu->insertItem( i18n("&Add..."), this, SLOT( addResource() ) );
00713
00714 menu->popup( pos );
00715 }
00716
00717 void ResourceView::assignColor()
00718 {
00719 ResourceItem *item = currentItem();
00720 if ( !item )
00721 return;
00722
00723 QColor myColor;
00724 ResourceCalendar *cal = item->resource();
00725
00726 QString identifier = cal->identifier();
00727 if ( item->isSubresource() )
00728 identifier = item->resourceIdentifier();
00729
00730 QColor defaultColor =*KOPrefs::instance()->resourceColor( identifier );
00731
00732 int result = KColorDialog::getColor( myColor,defaultColor);
00733
00734 if ( result == KColorDialog::Accepted ) {
00735 KOPrefs::instance()->setResourceColor( identifier, myColor );
00736 item->setResourceColor( myColor );
00737 item->update();
00738 emitResourcesChanged();
00739 }
00740 }
00741
00742 void ResourceView::disableColor()
00743 {
00744 ResourceItem *item = currentItem();
00745 if ( !item ) {
00746 return;
00747 }
00748
00749 QColor colorInvalid;
00750 ResourceCalendar *cal = item->resource();
00751 QString identifier = cal->identifier();
00752 if ( item->isSubresource() ) {
00753 identifier = item->resourceIdentifier();
00754 }
00755 KOPrefs::instance()->setResourceColor( identifier, colorInvalid );
00756 item->setResourceColor( colorInvalid );
00757 item->update();
00758 emitResourcesChanged();
00759 }
00760 void ResourceView::showInfo()
00761 {
00762 ResourceItem *item = currentItem();
00763 if ( !item ) return;
00764
00765 QString txt = "<qt>" + item->resource()->infoText() + "</qt>";
00766 KMessageBox::information( this, txt );
00767 }
00768
00769 void ResourceView::reloadResource()
00770 {
00771 ResourceItem *item = currentItem();
00772 if ( !item ) return;
00773
00774 ResourceCalendar *resource = item->resource();
00775 resource->load();
00776 }
00777
00778 void ResourceView::saveResource()
00779 {
00780 ResourceItem *item = currentItem();
00781 if ( !item ) return;
00782
00783 ResourceCalendar *resource = item->resource();
00784 resource->save();
00785 }
00786
00787 void ResourceView::setStandard()
00788 {
00789 ResourceItem *item = currentItem();
00790 if ( !item ) return;
00791
00792 ResourceCalendar *resource = item->resource();
00793 CalendarResourceManager *manager = mCalendar->resourceManager();
00794 manager->setStandardResource( resource );
00795 updateResourceList();
00796 }
00797
00798 void ResourceView::updateResourceList()
00799 {
00800 QListViewItemIterator it( mListView );
00801 ResourceCalendar* stdRes = mCalendar->resourceManager()->standardResource();
00802 while ( it.current() ) {
00803 ResourceItem *item = static_cast<ResourceItem *>( it.current() );
00804 item->setStandardResource( item->resource() == stdRes );
00805 ++it;
00806 }
00807 }
00808
00809 void ResourceView::showButtons( bool visible )
00810 {
00811 if ( visible ) {
00812 mAddButton->show();
00813 mDeleteButton->show();
00814 mEditButton->show();
00815 } else {
00816 mAddButton->hide();
00817 mDeleteButton->hide();
00818 mEditButton->hide();
00819 }
00820 }
00821
00822 void ResourceView::requestClose( ResourceCalendar *r )
00823 {
00824 mResourcesToClose.append( r );
00825 }
00826
00827 #include "resourceview.moc"