libkdepim

prefsmodule.cpp

00001 
00022 #include "prefsmodule.h"
00023 
00024 #include <kaboutdata.h>
00025 #include <kdebug.h>
00026 #include <kcombobox.h>
00027 #include <klocale.h>
00028 #include <ktrader.h>
00029 
00030 #include <qlayout.h>
00031 #include <qlabel.h>
00032 #include <qbuttongroup.h>
00033 
00034 #include <kdepimmacros.h>
00035 
00036 extern "C"
00037 {
00038   KDE_EXPORT KCModule *create_komposerconfig( QWidget *parent, const char * ) {
00039     return new Komposer::PrefsModule( parent, "komposerprefs" );
00040   }
00041 }
00042 using namespace Komposer;
00043 
00044 PrefsModule::PrefsModule( QWidget *parent, const char *name )
00045   : KPrefsModule( Komposer::Prefs::self(), parent, name )
00046 {
00047   QVBoxLayout *topLayout = new QVBoxLayout( this );
00048 
00049   EditorSelection *editors = new EditorSelection( i18n( "Editors" ),
00050                                                   Komposer::Prefs::self()->m_activeEditor,
00051                                                   this );
00052   topLayout->addWidget( editors->groupBox() );
00053 
00054   addWid( editors );
00055 
00056   load();
00057 }
00058 
00059 const KAboutData*
00060 PrefsModule::aboutData() const
00061 {
00062   KAboutData *about = new KAboutData( I18N_NOOP( "komposerconfig" ),
00063                                       I18N_NOOP( "KDE Komposer" ),
00064                                       0, 0, KAboutData::License_LGPL,
00065                                       I18N_NOOP( "(c), 2003-2004 Zack Rusin" ) );
00066 
00067   about->addAuthor( "Zack Rusin", 0, "zack@kde.org" );;
00068 
00069   return about;
00070 }
00071 
00072 
00073 EditorSelection::EditorSelection( const QString &text, QString &reference,
00074                                   QWidget *parent )
00075   : m_reference( reference )
00076 {
00077   m_box = new QGroupBox( 0, Qt::Vertical, text, parent );
00078   QVBoxLayout *boxLayout = new QVBoxLayout( m_box->layout() );
00079   boxLayout->setAlignment( Qt::AlignTop );
00080 
00081   m_editorsCombo = new KComboBox( m_box );
00082   boxLayout->addWidget( m_editorsCombo );
00083 
00084   connect( m_editorsCombo, SIGNAL(activated(const QString&)),
00085            SLOT(slotActivated(const QString&)) );
00086 }
00087 
00088 EditorSelection::~EditorSelection()
00089 {
00090 }
00091 
00092 QGroupBox*
00093 EditorSelection::groupBox()  const
00094 {
00095   return m_box;
00096 }
00097 
00098 void
00099 EditorSelection::readConfig()
00100 {
00101   m_editorsCombo->clear();
00102 
00103   KTrader::OfferList editors = KTrader::self()->query(
00104     QString::fromLatin1( "Komposer/Editor" ) );
00105   KTrader::OfferList::ConstIterator it;
00106   int i = 0;
00107   for ( it = editors.begin(); it != editors.end(); ++it, ++i ) {
00108     if ( !(*it)->hasServiceType( QString::fromLatin1( "Komposer/Editor" ) ) )
00109       continue;
00110 
00111     QString name = (*it)->property( "X-KDE-KomposerIdentifier" ).toString();
00112     m_editorsCombo->insertItem( name );
00113     if ( m_reference.contains( name ) )
00114       m_editorsCombo->setCurrentItem( i );
00115   }
00116 }
00117 
00118 void EditorSelection::writeConfig()
00119 {
00120   m_reference =  m_services[ m_editorsCombo->currentText()]->
00121                  property( "X-KDE-KomposerIdentifier" ).toString();
00122 }
00123 
00124 void
00125 EditorSelection::slotActivated( const QString &editor )
00126 {
00127   if ( !editor.isEmpty() )
00128     emit changed();
00129 }
00130 
00131 void
00132 EditorSelection::setItem( const QString &str )
00133 {
00134   for ( int i = 0; i < m_editorsCombo->count(); ++i ) {
00135     if ( m_editorsCombo->text( i ) == str ) {
00136       m_editorsCombo->setCurrentItem( i );
00137       break;
00138     }
00139   }
00140 }
00141 
00142 #include "prefsmodule.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys