summaryrefslogtreecommitdiffstats
path: root/kcontrol/locale/localeother.cpp
blob: 33b039c6e0f05c9f17b11fa24940eeb5af9aa0f5 (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
/*
 * localeother.cpp
 *
 * Copyright (c) 2001-2003 Hans Petter Bieker <bieker@kde.org>
 *
 * Requires the Qt widget libraries, available at no cost at
 * http://www.troll.no/
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <tqcombobox.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqprinter.h>

#include <kdialog.h>
#include <klocale.h>
#include <ksimpleconfig.h>
#include <kstandarddirs.h>

#include "localeother.h"
#include "localeother.moc"


KLocaleConfigOther::KLocaleConfigOther(KLocale *locale,
                                       TQWidget *parent, const char*name)
  : TQWidget(parent, name),
    m_locale(locale)
{
  // Other
  TQGridLayout *lay = new TQGridLayout(this, 3, 2,
                                     KDialog::marginHint(),
                                     KDialog::spacingHint());

  m_labPageSize = new TQLabel(this, I18N_NOOP("Paper format:"));
  lay->addWidget(m_labPageSize, 0, 0);
  m_combPageSize = new TQComboBox(this);
  lay->addWidget(m_combPageSize, 0, 1);
  connect( m_combPageSize, TQT_SIGNAL( activated(int) ),
           TQT_SLOT( slotPageSizeChanged(int) ) );

  m_labMeasureSystem = new TQLabel(this, I18N_NOOP("Measure system:"));
  lay->addWidget(m_labMeasureSystem, 1, 0);
  m_combMeasureSystem = new TQComboBox(this);
  lay->addWidget(m_combMeasureSystem, 1, 1);
  connect( m_combMeasureSystem, TQT_SIGNAL( activated(int) ),
           TQT_SLOT( slotMeasureSystemChanged(int) ) );

  m_combPageSize->insertItem(TQString::null);
  m_combPageSize->insertItem(TQString::null);
  m_combMeasureSystem->insertItem(TQString::null);
  m_combMeasureSystem->insertItem(TQString::null);

  lay->setColStretch(1, 1);
  lay->addRowSpacing(2, 0);

  adjustSize();
}

KLocaleConfigOther::~KLocaleConfigOther()
{
}

void KLocaleConfigOther::save()
{
  KConfig *config = KGlobal::config();
  KConfigGroupSaver saver(config, "Locale");

  KSimpleConfig ent(locate("locale",
                           TQString::tqfromLatin1("l10n/%1/entry.desktop")
                           .arg(m_locale->country())), true);
  ent.setGroup("KCM Locale");

  // ### HPB: Add code here
  int i;
  i = ent.readNumEntry("PageSize", (int)TQPrinter::A4);
  config->deleteEntry("PageSize", false, true);
  if (i != m_locale->pageSize())
    config->writeEntry("PageSize",
                       m_locale->pageSize(), true, true);

  i = ent.readNumEntry("MeasureSystem", (int)KLocale::Metric);
  config->deleteEntry("MeasureSystem", false, true);
  if (i != m_locale->measureSystem())
    config->writeEntry("MeasureSystem",
                       m_locale->measureSystem(), true, true);

  config->sync();
}

void KLocaleConfigOther::slotLocaleChanged()
{
  m_combMeasureSystem->setCurrentItem(m_locale->measureSystem());

  int pageSize = m_locale->pageSize();

  int i = 0; // default to A4
  if ( pageSize == (int)TQPrinter::Letter )
    i = 1;
  m_combPageSize->setCurrentItem(i);
}

void KLocaleConfigOther::slotTranslate()
{
  m_combMeasureSystem->changeItem( m_locale->translate("The Metric System",
                                                       "Metric"), 0 );
  m_combMeasureSystem->changeItem( m_locale->translate("The Imperial System",
                                                       "Imperial"), 1 );

  m_combPageSize->changeItem( m_locale->translate("A4"), 0 );
  m_combPageSize->changeItem( m_locale->translate("US Letter"), 1 );
}

void KLocaleConfigOther::slotPageSizeChanged(int i)
{
  TQPrinter::PageSize pageSize = TQPrinter::A4;

  if ( i == 1 )
    pageSize = TQPrinter::Letter;

  m_locale->setPageSize((int)pageSize);
  emit localeChanged();
}

void KLocaleConfigOther::slotMeasureSystemChanged(int i)
{
  m_locale->setMeasureSystem((KLocale::MeasureSystem)i);
  emit localeChanged();
}