Debian Codegraph @

src/af/xap/xp/xap_Dlg_Encoding.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "ut_string.h"
25 #include "ut_assert.h"
26 #include "ut_debugmsg.h"
27 #include "ut_Encoding.h"
28
29 #include "xap_Dlg_Encoding.h"
30
31 /*****************************************************************/
32
33 #if 0
34 static int s_compareQ(const void * a, const void * b)
35 {
36 const gchar ** A = static_cast<const gchar **>(a);
37 const gchar ** B = static_cast<const gchar **>(b);
38
39 return strcmp(*A,*B);
40 }
41 #endif
42
43 XAP_Dialog_Encoding::XAP_Dialog_Encoding(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id)
44 : XAP_Dialog_NonPersistent(pDlgFactory,id)
45 {
46 m_answer = a_CANCEL;
47 m_pDescription = NULL;
48 m_pEncoding = NULL;
49 m_pEncTable = new UT_Encoding;
50
51 UT_ASSERT(m_pEncTable);
52 m_iEncCount = m_pEncTable->getCount();
53 m_ppEncodings = new const gchar * [m_iEncCount];
54
55 // Build array of encoding names
56 for(UT_uint32 i = 0; i < m_iEncCount; i++)
57 m_ppEncodings[i] = m_pEncTable->getNthDescription(i);
58 }
59
60 XAP_Dialog_Encoding::~XAP_Dialog_Encoding(void)
61 {
62 DELETEP (m_pEncTable);
63 DELETEPV(m_ppEncodings);
64 }
65
66 // we will not use the value passed to us, but rather will reference
67 // ourselves into m_pEncTable; that way we do not have to worry about
68 // the string disappearing on us, nor do we need to clone it
69 void XAP_Dialog_Encoding::setEncoding(const gchar * pEncoding)
70 {
71 UT_return_if_fail(m_pEncTable);
72 m_iSelIndex = m_pEncTable->getIndxFromEncoding(pEncoding);
73 m_pDescription = m_pEncTable->getNthDescription(m_iSelIndex);
74 m_pEncoding = m_pEncTable->getNthEncoding(m_iSelIndex);
75 }
76
77 // in this case we do not need to worry about the lifespan of pDesc
78 // since we call it only internally, always referring back to m_pEncTable
79 void XAP_Dialog_Encoding::_setEncoding(const gchar * pDesc)
80 {
81 UT_return_if_fail(m_pEncTable);
82 m_pDescription = pDesc;
83 m_pEncoding = m_pEncTable->getEncodingFromDescription(pDesc);
84 }
85
86
87 XAP_Dialog_Encoding::tAnswer XAP_Dialog_Encoding::getAnswer(void) const
88 {
89 return m_answer;
90 }
91
92 const gchar * XAP_Dialog_Encoding::getEncoding() const
93 {
94 return m_pEncoding;
95 }