Esempio n. 1
0
void ResourceView::addResource()
{
  bool ok = false;
  KCal::CalendarResourceManager *manager = mCalendar->resourceManager();
  ResourceItem *i = static_cast<ResourceItem*>( mListView->selectedItem() );
  if ( i && ( i->isSubresource() || i->resource()->canHaveSubresources() ) ) {
    const QString folderName = KInputDialog::getText( i18n( "Add Subresource" ),
            i18n( "Please enter a name for the new subresource" ), QString::null,
            &ok, this );
    if ( !ok )
      return;
    const QString parentId = i->isSubresource() ? i->resourceIdentifier() : QString:: null;
    if ( !i->resource()->addSubresource( folderName, parentId ) ) {
      KMessageBox::error( this, i18n("<qt>Unable to create subresource <b>%1</b>.</qt>")
                                .arg( folderName ) );
    }
    return;
  }

  QStringList types = manager->resourceTypeNames();
  QStringList descs = manager->resourceTypeDescriptions();
  QString desc = KInputDialog::getItem( i18n( "Resource Configuration" ),
      i18n( "Please select type of the new resource:" ), descs, 0, false, &ok,
            this );
  if ( !ok )
    return;

  QString type = types[ descs.findIndex( desc ) ];

  // Create new resource
  ResourceCalendar *resource = manager->createResource( type );
  if( !resource ) {
    KMessageBox::error( this, i18n("<qt>Unable to create resource of type <b>%1</b>.</qt>")
                              .arg( type ) );
    return;
  }

  resource->setResourceName( i18n("%1 resource").arg( type ) );

  KRES::ConfigDialog *dlg = new KRES::ConfigDialog( this, QString("calendar"), resource,
                          "KRES::ConfigDialog" );

  if ( dlg && dlg->exec() ) {
    resource->setTimeZoneId( KOPrefs::instance()->mTimeZoneId );
    if ( resource->isActive() ) {
      resource->open();
      resource->load();
    }
    manager->add( resource );
    // we have to call resourceAdded manually, because for in-process changes
    // the dcop signals are not connected, so the resource's signals would not
    // be connected otherwise
    mCalendar->resourceAdded( resource );
  } else {
    delete resource;
    resource = 0;
  }
  if ( dlg ) delete dlg;
  emitResourcesChanged();
}
Esempio n. 2
0
void ResourceView::setStandard()
{
  ResourceItem *item = currentItem();
  if ( !item ) return;

  ResourceCalendar *r = item->resource();
  KCal::CalendarResourceManager *manager = mCalendar->resourceManager();
  manager->setStandardResource( r );
  updateResourceList();
}
Esempio n. 3
0
void ResourceView::updateView()
{
  mListView->clear();

  KCal::CalendarResourceManager *manager = mCalendar->resourceManager();

  KCal::CalendarResourceManager::Iterator it;
  for( it = manager->begin(); it != manager->end(); ++it ) {
    addResourceItem( *it );
  }
}
void ResourceView::updateView()
{
  mListView->clear();

  KCal::CalendarResourceManager *manager = mCalendar->resourceManager();

  KCal::CalendarResourceManager::Iterator it;
  for ( it = manager->begin(); it != manager->end(); ++it ) {
    addResourceItem( *it, false );
  }

  mListView->sortItems( 0, Qt::AscendingOrder );

  emit emitResourcesChanged();
}
Esempio n. 5
0
void ResourceView::contextMenuRequested(QListViewItem *i,
                                        const QPoint &pos, int)
{
    KCal::CalendarResourceManager *manager = mCalendar->resourceManager();
    ResourceItem *item = static_cast<ResourceItem *>(i);

    QPopupMenu *menu = new QPopupMenu(this);
    connect(menu, SIGNAL(aboutToHide()), menu, SLOT(deleteLater()));
    if(item)
    {
        int reloadId = menu->insertItem(i18n("Re&load"), this,
                                        SLOT(reloadResource()));
        menu->setItemEnabled(reloadId, item->resource()->isActive());
        int saveId = menu->insertItem(i18n("&Save"), this,
                                      SLOT(saveResource()));
        menu->setItemEnabled(saveId, item->resource()->isActive());
        menu->insertSeparator();

        menu->insertItem(i18n("Show &Info"), this, SLOT(showInfo()));
        //FIXME: This is better on the resource dialog
        if(KOPrefs::instance()->agendaViewColors() != KOPrefs::CategoryOnly)
        {
            QPopupMenu *assignMenu = new QPopupMenu(menu);
            assignMenu->insertItem(i18n("&Assign Color"), this, SLOT(assignColor()));
            if(item->resourceColor().isValid())
                assignMenu->insertItem(i18n("&Disable Color"), this, SLOT(disableColor()));
            menu->insertItem(i18n("Resources Colors"), assignMenu);
        }

        menu->insertItem(i18n("&Edit..."), this, SLOT(editResource()));
        menu->insertItem(i18n("&Remove"), this, SLOT(removeResource()));
        if(item->resource() != manager->standardResource())
        {
            menu->insertSeparator();
            menu->insertItem(i18n("Use as &Default Calendar"), this,
                             SLOT(setStandard()));
        }

        menu->insertSeparator();
    }
    menu->insertItem(i18n("&Add..."), this, SLOT(addResource()));

    menu->popup(pos);
}
void ResourceView::addResource()
{
  bool ok = false;
  KCal::CalendarResourceManager *manager = mCalendar->resourceManager();
  ResourceItem *i = mSelectedParent;

  if ( i && ( i->isSubresource() || i->resource()->canHaveSubresources() ) ) {
    const QString folderName =
      KInputDialog::getText( i18n( "Add Calendar Folder" ),
                             i18n( "Please enter a name for the new calendar folder" ),
                             QString(), &ok, this );
    if ( !ok ) {
      return;
    }

    const QString parentId = i->isSubresource() ? i->resourceIdentifier() : QString();
    if ( !i->resource()->addSubresource( folderName, parentId ) ) {
      KMessageBox::error(
        this,
        i18n( "<qt>Unable to create the calendar folder <b>%1</b>.</qt>",
              folderName ) );
    }
    return;
  }

  QStringList types = manager->resourceTypeNames();
  QStringList descs = manager->resourceTypeDescriptions();
  QString desc =
    KInputDialog::getItem( i18n( "Calendar Configuration" ),
                           i18n( "Please select the type of the new calendar:" ),
                           descs, 0, false, &ok, this );
  if ( !ok ) {
    return;
  }

  QString type = types.at( descs.indexOf( desc ) );

  // Create new resource
  ResourceCalendar *resource = manager->createResource( type );
  if( !resource ) {
    KMessageBox::error( this,
                        i18n( "<qt>Unable to create a calendar of type <b>%1</b>.</qt>", type ) );
    return;
  }

  resource->setResourceName( i18n( "%1 calendar", type ) );

  // TODO: Add a fallback (KColorCollection::setName() broken?)
  KColorCollection collection( "Oxygen.colors" );
  // TODO: Be smarter than this
  int rand = ( KRandom::random() % collection.count() ) + 1;
  QColor color = collection.color( rand );

  KOPrefs::instance()->setResourceColor( resource->identifier(), color );

  bool success = true;
  QPointer<KRES::ConfigDialog> dlg =
    new KRES::ConfigDialog( this, QString( "calendar" ), resource );

  if ( dlg->exec() != QDialog::Accepted ) {
    success = false;
  }
  delete dlg;

  if ( success ) {
    resource->setTimeSpec( KOPrefs::instance()->timeSpec() );
    if ( resource->isActive() && ( !resource->open() || !resource->load() ) ) {
      // ### There is a resourceLoadError() signal declared in ResourceCalendar
      //     but no subclass seems to make use of it. We could do better.
      KMessageBox::error( this, i18n( "Unable to create the calendar." ) );
      success = false;
    }
  }

  if ( success ) {
    manager->add( resource );
    // we have to call resourceAdded manually, because for in-process changes
    // the dcop signals are not connected, so the resource's signals would not
    // be connected otherwise
    mCalendar->resourceAdded( resource );
  }

  if ( !success ) {
    delete resource;
    resource = 0;
  }

  //### maybe only do this if ( success )
  emitResourcesChanged();
}