示例#1
0
void KWatchGnuPGMainWindow::setGnuPGConfig()
{
  QStringList logclients;
  // Get config object
  Kleo::CryptoConfig* cconfig = Kleo::CryptoBackendFactory::instance()->config();
  if ( !cconfig )
    return;
  //Q_ASSERT( cconfig );
  KConfig* config = kapp->config();
  config->setGroup("WatchGnuPG");
  QStringList comps = cconfig->componentList();
  for( QStringList::const_iterator it = comps.begin(); it != comps.end(); ++it ) {
	Kleo::CryptoConfigComponent* comp = cconfig->component( *it );
	Q_ASSERT(comp);
	// Look for log-file entry in Debug group
	Kleo::CryptoConfigGroup* group = comp->group("Debug");
	if( group ) {
	  Kleo::CryptoConfigEntry* entry = group->entry("log-file");
	  if( entry ) {
		entry->setStringValue( QString("socket://")+
							   config->readEntry("Socket",
												 WATCHGNUPGSOCKET ));
		logclients << QString("%1 (%2)").arg(*it).arg(comp->description());
	  }
	  entry = group->entry("debug-level");
	  if( entry ) {
		entry->setStringValue( config->readEntry("LogLevel", "basic") );
	  }
	}
  }
  cconfig->sync(true);
  if( logclients.isEmpty() ) {
	KMessageBox::sorry( 0, i18n("There are no components available that support logging." ) );
  }
}
void Kleo::CryptoConfigModule::init( Layout layout ) {
  Kleo::CryptoConfig * const config = mConfig;
  const KPageView::FaceType type=determineJanusFace( config, layout );
  setFaceType(type);
  QVBoxLayout * vlay = 0;
  QWidget * vbox = 0;
  if ( type == Plain ) {
    vbox = new QWidget(this);
    vlay = new QVBoxLayout( vbox );
    vlay->setSpacing( KDialog::spacingHint() );
    vlay->setMargin( 0 );
    addPage( vbox, i18n("GpgConf Error") );
  }

  const QStringList components = config->componentList();
  for ( QStringList::const_iterator it = components.begin(); it != components.end(); ++it ) {
    //kDebug(5150) <<"Component" << (*it).toLocal8Bit() <<":";
    Kleo::CryptoConfigComponent* comp = config->component( *it );
    Q_ASSERT( comp );
    if ( comp->groupList().empty() )
      continue;
    if ( type != Plain ) {
      vbox = new QWidget(this);
      vlay = new QVBoxLayout( vbox );
      vlay->setSpacing( KDialog::spacingHint() );
      vlay->setMargin( 0 );
      KPageWidgetItem *pageItem = new KPageWidgetItem( vbox, comp->description() );
      if ( type != Tabbed )
          pageItem->setIcon( loadIcon( comp->iconName() ) );
      addPage(pageItem);
    }

    QScrollArea* scrollArea = type == Tabbed ? new QScrollArea( this ) : new ScrollArea( this );
    scrollArea->setWidgetResizable( true );

    vlay->addWidget( scrollArea );

    CryptoConfigComponentGUI* compGUI =
      new CryptoConfigComponentGUI( this, comp, scrollArea );
    compGUI->setObjectName( *it );
    scrollArea->setWidget( compGUI );
    scrollArea->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
    // KJanusWidget doesn't seem to have iterators, so we store a copy...
    mComponentGUIs.append( compGUI );

    // Set a nice startup size
    const int deskHeight = QApplication::desktop()->height();
    int dialogHeight;
    if (deskHeight > 1000) // very big desktop ?
      dialogHeight = 800;
    else if (deskHeight > 650) // big desktop ?
      dialogHeight = 500;
    else // small (800x600, 640x480) desktop
      dialogHeight = 400;
    assert( scrollArea->widget() );
    if ( type != Tabbed )
        scrollArea->setMinimumHeight( qMin( compGUI->sizeHint().height(), dialogHeight ) );
  }
  if ( mComponentGUIs.empty() ) {
      const QString msg = i18n("The gpgconf tool used to provide the information "
                               "for this dialog does not seem to be installed "
                               "properly. It did not return any components. "
                               "Try running \"%1\" on the command line for more "
                               "information.",
                               components.empty() ? "gpgconf --list-components" : "gpgconf --list-options gpg" );
      QLabel * label = new QLabel( msg, vbox );
      label->setWordWrap( true);
      label->setMinimumHeight( fontMetrics().lineSpacing() * 5 );
      vlay->addWidget( label );
  }
}