summaryrefslogtreecommitdiffstats
path: root/kmymoney2/dialogs/kgncimportoptionsdlg.cpp
blob: 9aaf5b6b814fa4c834e646b534af38ba876516fe (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
/***************************************************************************
                          kgncimportoptions.cpp
                             -------------------
    copyright            : (C) 2005 by Ace Jones
    author               : Tony Bloomfield
    email                : tonybloom@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

// ----------------------------------------------------------------------------
// QT Includes
#include <tqcheckbox.h>
#include <tqlineedit.h>
#include <tqlayout.h>
#include <tqapplication.h>
#include <tqcombobox.h>

// ----------------------------------------------------------------------------
// KDE Includes
#include <kapplication.h>
#include <kurlrequester.h>
#include <ktextbrowser.h>
#include <klocale.h>

// ----------------------------------------------------------------------------
// Project Includes
#include "kgncimportoptionsdlg.h"

// dialog constructor
KGncImportOptionsDlg::KGncImportOptionsDlg(TQWidget *tqparent, const char *name)
 : KGncImportOptionsDlgDecl(tqparent, name)
{
  buttonInvestGroup->setRadioButtonExclusive (true);
  buttonInvestGroup->setButton (0);
  checkFinanceQuote->setChecked(true);
  checkSchedules->setChecked (false);
  buildCodecList (); // build list of codecs and insert into combo box
  checkDecode->setChecked (false);
  comboDecode->setEnabled (false);
  checkTxNotes->setChecked (false);
  checkDebugGeneral->setChecked (false);
  checkDebugXML->setChecked (false);
  checkAnonymize->setChecked (false);

  connect (checkDecode, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotDecodeOptionChanged(bool)));
}

KGncImportOptionsDlg::~KGncImportOptionsDlg()
{
}

// enable the combo box for selection if required
void KGncImportOptionsDlg::slotDecodeOptionChanged(bool isOn) {
  if (isOn) {
    comboDecode->setEnabled (true);
    comboDecode->setCurrentItem (0);
  } else {
    comboDecode->setEnabled (false);
  }
}

// build a list of known codecs and sort it so that the locale codec is first
// try to get the others in some sort of order of likelihood
void KGncImportOptionsDlg::buildCodecList () {

  m_localeCodec = TQTextCodec::codecForLocale();
  m_codecList.setAutoDelete (true);
  // retrieve all codec pointers
  TQTextCodec *codec;
  unsigned int i;
  for (i = 0; (codec = TQTextCodec::codecForIndex(i)); i++) {
    int rank;
    if (codec == m_localeCodec) rank = 999; // ensure locale rank comes first
    else rank = codec->heuristicNameMatch(m_localeCodec->name());

    codecData *p = new codecData(rank, codec);
    m_codecList.append (p);
  }
  m_codecList.sort();
  for (i = 0; i < m_codecList.count(); i++) {
    TQString name (m_codecList.at(i)->second->name());
    comboDecode->insertItem (name);
  }
}

// this routine sorts the codec list on 1) rank descending 2) codec name ascending
int codecDataList::compareItems (void *a, void *b) {
  codecData *pa = reinterpret_cast<codecData *>(a);
  codecData *pb = reinterpret_cast<codecData *>(b);

  if (pa->first > pb->first) {
    return (-1); // greater rank is treated as less-than so gets sorted first
  } else { if (pb->first > pa->first)
        return (1);
  }
  // ranks are equal, sort on name, case insensitive
  TQString sa(pa->second->name());
  TQString sb(pb->second->name());
  if (sa.lower() > sb.lower()) {
    return (1);
  } else {
    return (-1);
  }
}

// return selected codec or 0
TQTextCodec* KGncImportOptionsDlg::decodeOption(void) {
  if (!checkDecode->isChecked()) {
    return (0);
  } else {
    return (m_codecList.at(comboDecode->currentItem())->second);
  }
}

void KGncImportOptionsDlg::slotHelp(void)
{
  kapp->invokeHelp ("details.impexp.gncoptions");
}

#include "kgncimportoptionsdlg.moc"