Debian Codegraph @

src/af/xap/xp/xap_Dlg_History.cpp

raw
1 /* AbiWord
2 * Copyright (C) 2004 Tomas Frydrych <[email protected]>
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 "ut_uuid.h"
21
22 #include "xap_Dlg_History.h"
23 #include "xad_Document.h"
24 #include "xap_App.h"
25 #include "xap_Strings.h"
26
27 #include <locale.h>
28
29 XAP_Dialog_History::XAP_Dialog_History(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id):
30 XAP_Dialog_NonPersistent(pDlgFactory,id),
31 m_answer(a_CANCEL),
32 m_pDoc(NULL),
33 m_pSS(NULL),
34 m_iId(0)
35 {
36 m_pSS = XAP_App::getApp()->getStringSet();
37 }
38
39 const char * XAP_Dialog_History::getWindowLabel() const
40 {
41 UT_return_val_if_fail(m_pSS, NULL);
42 return m_pSS->getValue(XAP_STRING_ID_DLG_History_WindowLabel);
43 }
44
45 const char * XAP_Dialog_History::getListTitle() const
46 {
47 UT_return_val_if_fail(m_pSS, NULL);
48 return m_pSS->getValue(XAP_STRING_ID_DLG_History_List_Title);
49 }
50
51
52 const char * XAP_Dialog_History::getHeaderLabel(UT_uint32 indx) const
53 {
54 UT_return_val_if_fail(m_pSS, NULL);
55 switch(indx)
56 {
57 case 0: return m_pSS->getValue(XAP_STRING_ID_DLG_History_Path);
58 case 1: return m_pSS->getValue(XAP_STRING_ID_DLG_History_Version);
59 case 2: return m_pSS->getValue(XAP_STRING_ID_DLG_History_Created);
60 case 3: return m_pSS->getValue(XAP_STRING_ID_DLG_History_LastSaved);
61 case 4: return m_pSS->getValue(XAP_STRING_ID_DLG_History_EditTime);
62 case 5: return m_pSS->getValue(XAP_STRING_ID_DLG_History_Id);
63
64 default:;
65 }
66
67 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
68 return NULL;
69 }
70
71
72 char * XAP_Dialog_History::getHeaderValue(UT_uint32 indx) const
73 {
74 UT_return_val_if_fail(m_pDoc, NULL);
75
76 UT_String S;
77 time_t tT;
78 struct tm * tM;
79 char * s;
80
81 switch(indx)
82 {
83 case 0:
84 {
85 const char * pPath = m_pDoc->getFilename();
86 UT_return_val_if_fail(pPath, NULL);
87 UT_uint32 iPathLen = strlen(pPath);
88
89 if(iPathLen < 45)
90 {
91 UT_String_sprintf(S, "%s", pPath);
92 }
93 else
94 {
95 char * pP1 = g_strdup(pPath);
96 pP1[6] = 0;
97 const char * pP2 = pPath + iPathLen - 35;
98 UT_String_sprintf(S, "%s ... %s", pP1, pP2);
99 FREEP(pP1);
100 }
101
102 return g_strdup(S.c_str());
103 }
104
105 case 1:
106 UT_String_sprintf(S,"%d",m_pDoc->getDocVersion());
107 return g_strdup(S.c_str());
108
109 case 2:
110 {
111 const UT_UUID * pUUID = m_pDoc->getDocUUID();
112 UT_return_val_if_fail(pUUID, NULL);
113
114 tT = pUUID->getTime();
115 tM = localtime(&tT);
116 s = (char*)g_try_malloc(30);
117 if(!s)
118 return NULL;
119
120 size_t len = strftime(s,30,"%c",tM);
121 if(!len)
122 {
123 FREEP(s);
124 return NULL;
125 }
126
127 return s;
128 }
129
130 case 3:
131 {
132 tT = m_pDoc->getLastSavedTime();
133 tM = localtime(&tT);
134 s = (char*)g_try_malloc(30);
135 if(!s)
136 return NULL;
137
138 size_t len = strftime(s,30,"%c",tM);
139 if(!len)
140 {
141 FREEP(s);
142 return NULL;
143 }
144 return s;
145 }
146 case 4:
147 {
148 time_t iEditTime = m_pDoc->getEditTime();
149 time_t iHours = iEditTime / 3600;
150 time_t iMinutes = (iEditTime % 3600)/60;
151 time_t iSeconds = (iEditTime % 3600) % 60;
152
153 UT_String_sprintf(S,"%.2d:%.2d:%.2d", static_cast<UT_sint32>(iHours), static_cast<UT_sint32>(iMinutes), static_cast<UT_sint32>(iSeconds));
154 return g_strdup(S.c_str());
155 }
156
157 case 5:
158 return g_strdup(m_pDoc->getDocUUIDString());
159
160 default:;
161 }
162
163 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
164 return NULL;
165 }
166
167
168 const char * XAP_Dialog_History::getButtonLabel(UT_uint32 indx) const
169 {
170 UT_return_val_if_fail(m_pSS, NULL);
171
172 switch(indx)
173 {
174 case 0: return m_pSS->getValue(XAP_STRING_ID_DLG_Restore);
175 //case 1: return m_pSS->getValue(XAP_STRING_ID_DLG_Show);
176 case 1: return m_pSS->getValue(XAP_STRING_ID_DLG_Cancel);
177
178 default:;
179 }
180
181 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
182 return NULL;
183 }
184
185
186 const char * XAP_Dialog_History::getListHeader(UT_uint32 column) const
187 {
188 UT_return_val_if_fail(m_pSS, NULL);
189
190 switch(column)
191 {
192 case 0: return m_pSS->getValue(XAP_STRING_ID_DLG_History_Version_Version);
193 case 1: return m_pSS->getValue(XAP_STRING_ID_DLG_History_Version_Started);
194 case 2: return m_pSS->getValue(XAP_STRING_ID_DLG_History_Version_AutoRevisioned);
195
196 default:;
197 }
198
199 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
200 return NULL;
201 }
202
203 UT_uint32 XAP_Dialog_History::getListItemCount() const
204 {
205 UT_return_val_if_fail(m_pDoc, 0);
206 return m_pDoc->getHistoryCount();
207 }
208
209
210 char * XAP_Dialog_History::getListValue(UT_uint32 item, UT_uint32 column) const
211 {
212 UT_return_val_if_fail(m_pDoc, NULL);
213
214 UT_String S;
215 time_t tT;
216 struct tm * tM;
217 char * s;
218
219 switch(column)
220 {
221 case 0:
222 UT_String_sprintf(S,"%d",m_pDoc->getHistoryNthId(item));
223 return g_strdup(S.c_str());
224
225 case 1:
226 {
227 tT = m_pDoc->getHistoryNthTimeStarted(item);
228 tM = localtime(&tT);
229 s = (char*)g_try_malloc(30);
230 if(!s)
231 return NULL;
232
233 size_t len = strftime(s,30,"%c",tM);
234 if(!len)
235 {
236 FREEP(s);
237 return NULL;
238 }
239
240 return s;
241 }
242
243 case 2:
244 {
245 UT_return_val_if_fail(m_pSS, NULL);
246
247 const char * pszS;
248 if(m_pDoc->getHistoryNthAutoRevisioned(item))
249 pszS = m_pSS->getValue(XAP_STRING_ID_DLG_MB_Yes);
250 else
251 pszS = m_pSS->getValue(XAP_STRING_ID_DLG_MB_No);
252
253 UT_return_val_if_fail(pszS, NULL);
254
255 return g_strdup(pszS);
256 }
257
258 default:;
259 }
260
261 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
262 return NULL;
263 }
264
265
266 UT_uint32 XAP_Dialog_History::getListItemId(UT_uint32 item) const
267 {
268 UT_return_val_if_fail(m_pDoc, 0);
269 return m_pDoc->getHistoryNthId(item);
270 }
271