summaryrefslogtreecommitdiffstats
path: root/libkdepim/komposer/core/prefsmodule.cpp
blob: 1c088e9e8a8b442c4e2cc3d4afb23637ce988698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
 * prefsmodule.cpp
 *
 * Copyright (C)  2003-2004  Zack Rusin <zack@kde.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "prefsmodule.h"

#include <kaboutdata.h>
#include <kdebug.h>
#include <kcombobox.h>
#include <klocale.h>
#include <ktrader.h>

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqbuttongroup.h>

#include <kdepimmacros.h>

extern "C"
{
  KDE_EXPORT KCModule *create_komposerconfig( TQWidget *tqparent, const char * ) {
    return new Komposer::PrefsModule( tqparent, "komposerprefs" );
  }
}
using namespace Komposer;

PrefsModule::PrefsModule( TQWidget *tqparent, const char *name )
  : KPrefsModule( Komposer::Prefs::self(), tqparent, name )
{
  TQVBoxLayout *topLayout = new TQVBoxLayout( this );

  EditorSelection *editors = new EditorSelection( i18n( "Editors" ),
                                                  Komposer::Prefs::self()->m_activeEditor,
                                                  this );
  topLayout->addWidget( editors->groupBox() );

  addWid( editors );

  load();
}

const KAboutData*
PrefsModule::aboutData() const
{
  KAboutData *about = new KAboutData( I18N_NOOP( "komposerconfig" ),
                                      I18N_NOOP( "KDE Komposer" ),
                                      0, 0, KAboutData::License_LGPL,
                                      I18N_NOOP( "(c), 2003-2004 Zack Rusin" ) );

  about->addAuthor( "Zack Rusin", 0, "zack@kde.org" );;

  return about;
}


EditorSelection::EditorSelection( const TQString &text, TQString &reference,
                                  TQWidget *tqparent )
  : m_reference( reference )
{
  m_box = new TQGroupBox( 0, TQt::Vertical, text, tqparent );
  TQVBoxLayout *boxLayout = new TQVBoxLayout( m_box->tqlayout() );
  boxLayout->tqsetAlignment( TQt::AlignTop );

  m_editorsCombo = new KComboBox( m_box );
  boxLayout->addWidget( m_editorsCombo );

  connect( m_editorsCombo, TQT_SIGNAL(activated(const TQString&)),
           TQT_SLOT(slotActivated(const TQString&)) );
}

EditorSelection::~EditorSelection()
{
}

TQGroupBox*
EditorSelection::groupBox()  const
{
  return m_box;
}

void
EditorSelection::readConfig()
{
  m_editorsCombo->clear();

  KTrader::OfferList editors = KTrader::self()->query(
    TQString::tqfromLatin1( "Komposer/Editor" ) );
  KTrader::OfferList::ConstIterator it;
  int i = 0;
  for ( it = editors.begin(); it != editors.end(); ++it, ++i ) {
    if ( !(*it)->hasServiceType( TQString::tqfromLatin1( "Komposer/Editor" ) ) )
      continue;

    TQString name = (*it)->property( "X-KDE-KomposerIdentifier" ).toString();
    m_editorsCombo->insertItem( name );
    if ( m_reference.tqcontains( name ) )
      m_editorsCombo->setCurrentItem( i );
  }
}

void EditorSelection::writeConfig()
{
  m_reference =  m_services[ m_editorsCombo->currentText()]->
                 property( "X-KDE-KomposerIdentifier" ).toString();
}

void
EditorSelection::slotActivated( const TQString &editor )
{
  if ( !editor.isEmpty() )
    emit changed();
}

void
EditorSelection::setItem( const TQString &str )
{
  for ( int i = 0; i < m_editorsCombo->count(); ++i ) {
    if ( m_editorsCombo->text( i ) == str ) {
      m_editorsCombo->setCurrentItem( i );
      break;
    }
  }
}

#include "prefsmodule.moc"