1 /* AbiWord
2 * Copyright (C) 2002 Tomas Frydrych <tomas@frydrych.uklinux.net>
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
21 #include "ap_Features.h"
22
23 #include "ut_string.h"
24
25 #include "xap_App.h"
26 #include "xap_Dialog_Id.h"
27 #include "xap_DialogFactory.h"
28
29 #include "ap_Dialog_MarkRevisions.h"
30 #include "ap_Strings.h"
31
AP_Dialog_MarkRevisions(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id id)32 AP_Dialog_MarkRevisions::AP_Dialog_MarkRevisions(XAP_DialogFactory * pDlgFactory,
33 XAP_Dialog_Id id)
34 : XAP_Dialog_NonPersistent(pDlgFactory,id, "interface/dialogmarkrevisions"), m_answer(a_CANCEL),
35 m_pDoc(NULL), m_pComment2(NULL),m_pRev(NULL),m_bForceNew(false)
36 {
37 m_pSS = XAP_App::getApp()->getStringSet();
38 }
39
~AP_Dialog_MarkRevisions(void)40 AP_Dialog_MarkRevisions::~AP_Dialog_MarkRevisions(void)
41 {
42 DELETEP(m_pComment2);
43 }
44
setAnswer(AP_Dialog_MarkRevisions::tAnswer a)45 void AP_Dialog_MarkRevisions::setAnswer(AP_Dialog_MarkRevisions::tAnswer a)
46 {
47 m_answer = a;
48 }
49
_initRevision()50 void AP_Dialog_MarkRevisions::_initRevision()
51 {
52 if(!m_pRev)
53 {
54 UT_return_if_fail(m_pDoc);
55
56 m_pRev = m_pDoc->getHighestRevision();
57 }
58 }
59
getTitle()60 const char * AP_Dialog_MarkRevisions::getTitle()
61 {
62 UT_return_val_if_fail(m_pSS,NULL);
63 return m_pSS->getValue(AP_STRING_ID_DLG_MarkRevisions_Title);
64 }
65
getComment2Label()66 const char * AP_Dialog_MarkRevisions::getComment2Label()
67 {
68 UT_return_val_if_fail(m_pSS,NULL);
69 return m_pSS->getValue(AP_STRING_ID_DLG_MarkRevisions_Comment2Label);
70 }
71
getRadio1Label()72 char * AP_Dialog_MarkRevisions::getRadio1Label()
73 {
74 _initRevision();
75
76 if(!m_pRev || m_bForceNew)
77 return NULL;
78
79 UT_return_val_if_fail(m_pSS,NULL);
80 const char * pLabel = m_pSS->getValue(AP_STRING_ID_DLG_MarkRevisions_Check1Label);
81
82 UT_return_val_if_fail(pLabel,NULL);
83 char * pBuff = (char*)UT_calloc(strlen(pLabel) + 35, sizeof(char));
84
85
86 sprintf(pBuff, pLabel, m_pRev->getId());
87
88 return pBuff;
89 }
90
getRadio2Label()91 const char * AP_Dialog_MarkRevisions::getRadio2Label()
92 {
93 UT_return_val_if_fail(m_pSS,NULL);
94 return m_pSS->getValue(AP_STRING_ID_DLG_MarkRevisions_Check2Label);
95 }
96
getComment1(bool utf8)97 char * AP_Dialog_MarkRevisions::getComment1(bool utf8)
98 {
99 _initRevision();
100
101 if(!m_pRev || m_bForceNew)
102 return NULL;
103
104 bool bFree = false;
105
106 const UT_UCS4Char * pC = m_pRev->getDescription();
107
108 if(!pC)
109 return NULL;
110
111 // now we run this string through fribidi
112 if(XAP_App::getApp()->theOSHasBidiSupport() == XAP_App::BIDI_SUPPORT_NONE)
113 {
114 UT_UCS4Char *pStr2 = 0;
115 UT_uint32 iLen = UT_UCS4_strlen(pC);
116
117 pStr2 = (UT_UCS4Char *)UT_calloc( iLen + 1, sizeof(UT_UCS4Char));
118 UT_return_val_if_fail(pStr2,NULL);
119 bFree = true;
120
121 UT_BidiCharType iDomDir = UT_bidiGetCharType(pC[0]);
122
123 UT_bidiReorderString(pC, iLen, iDomDir, pStr2);
124 pC = pStr2;
125
126 }
127
128 char * pComment;
129
130 if (utf8)
131 {
132 UT_UTF8String comment(pC);
133 pComment = (char *)UT_calloc(comment.byteLength() + 1, sizeof(char));
134 UT_return_val_if_fail(pComment,NULL);
135 pComment = strcpy(pComment, comment.utf8_str());
136 }
137 else
138 {
139 pComment = (char *)UT_calloc(UT_UCS4_strlen(pC) + 1, sizeof(char));
140 UT_return_val_if_fail(pComment,NULL);
141 UT_UCS4_strcpy_to_char(pComment,pC);
142 }
143
144 if(bFree)
145 {
146 FREEP(pC);
147 }
148
149 return pComment;
150 }
151
setComment2(const char * pszComment)152 void AP_Dialog_MarkRevisions::setComment2(const char * pszComment)
153 {
154 DELETEP(m_pComment2);
155 m_pComment2 = new UT_UTF8String(pszComment);
156 }
157
158
getAnswer(void) const159 AP_Dialog_MarkRevisions::tAnswer AP_Dialog_MarkRevisions::getAnswer(void) const
160 {
161 return m_answer;
162 }
163
isRev(void)164 bool AP_Dialog_MarkRevisions::isRev(void)
165 {
166 if(!m_pRev)
167 return false;
168 return true;
169 }
170
addRevision()171 void AP_Dialog_MarkRevisions::addRevision()
172 {
173 UT_return_if_fail(m_pDoc);
174
175 if (!m_pComment2)
176 return;
177
178 _initRevision();
179
180 UT_uint32 iId = 1;
181
182 if(m_pRev)
183 iId = m_pRev->getId() + 1;
184
185 time_t tStart = time(NULL);
186 m_pDoc->addRevision(iId, m_pComment2->ucs4_str().ucs4_str(), UT_UCS4_strlen(m_pComment2->ucs4_str().ucs4_str()), tStart, 0, true);
187 m_pRev = NULL;
188 }
189
190