|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // ipadm.cpp - IP administration tool main module |
|
15 // |
|
16 |
|
17 #include <techview/eikfnlab.h> |
|
18 #ifndef CALYPSO |
|
19 #include <techview/eikfontd.h> |
|
20 #endif |
|
21 |
|
22 #if EPOC_SDK < 0x06000000 |
|
23 #include <e32keys.h> |
|
24 #include <coemain.h> |
|
25 |
|
26 #include <eikenv.h> |
|
27 #include <eikdef.h> |
|
28 #include <eikcmds.hrh> |
|
29 #include <techview/eikon.rsg> |
|
30 #include <techview/eiklabel.h> |
|
31 |
|
32 #include <techview/eiktbar.h> |
|
33 #include <techview/eikchlst.h> |
|
34 #include <techview/eikpgsel.h> |
|
35 |
|
36 #include <techview/eiklabel.h> |
|
37 #endif |
|
38 |
|
39 #ifdef MAKE_EXE_APPLICATION |
|
40 #include <eikstart.h> |
|
41 #endif |
|
42 |
|
43 #include "ipadm.h" |
|
44 #include "engine.h" |
|
45 |
|
46 // |
|
47 // CConsoleControl |
|
48 // |
|
49 CConsoleControl::~CConsoleControl() |
|
50 { |
|
51 delete iConsole; |
|
52 } |
|
53 |
|
54 void CConsoleControl::ConstructL(const TPoint& aTopLeft, const TSize& aSize, TInt aFlags) |
|
55 { |
|
56 TRect rect(aTopLeft,aTopLeft + aSize.AsPoint()); |
|
57 #if EPOC_SDK >= 0x06000000 |
|
58 SetRect(rect); |
|
59 #else |
|
60 SetRectL(rect); |
|
61 #endif |
|
62 iConsole= new (ELeave) CEikConsoleScreen; |
|
63 iConsole->ConstructL(_L("TEST"),aTopLeft,aSize,aFlags,EEikConsWinInPixels); |
|
64 iConsole->SetHistorySizeL(200,0); |
|
65 //iConsole->SetAllPrintable(ETrue); |
|
66 iHistory=200; |
|
67 } |
|
68 |
|
69 void CConsoleControl::ActivateL() |
|
70 { |
|
71 CCoeControl::ActivateL(); |
|
72 iConsole->SetKeepCursorInSight(TRUE); |
|
73 iConsole->DrawCursor(); |
|
74 iConsole->SetAtt(ATT_NORMAL); |
|
75 } |
|
76 |
|
77 void CConsoleControl::HandleCommandL(TInt aCommand) |
|
78 { |
|
79 switch (aCommand) |
|
80 { |
|
81 case EConsolFontDialog: |
|
82 #if EPOC_SDK >= 0x06000000 |
|
83 { |
|
84 #ifndef CALYPSO |
|
85 TCharFormat charFormat; |
|
86 charFormat.iFontSpec = iConsole->Font(); |
|
87 TCharFormatMask dummy; |
|
88 if (CEikFontDialog::RunDlgLD(charFormat, dummy)) |
|
89 { |
|
90 //charFormat.iFontSpec.iTypeface.SetIsProportional(EFalse); |
|
91 iConsole->SetFontL(charFormat.iFontSpec); |
|
92 } |
|
93 #endif |
|
94 } |
|
95 #else |
|
96 { |
|
97 TCharFormat charFormat; |
|
98 charFormat.iFontSpec = iConsole->Font(); |
|
99 TCharFormatMask dummy; |
|
100 CEikFontDialog* dialog=new(ELeave) CEikFontDialog(charFormat,dummy); |
|
101 if (dialog->ExecuteLD(R_EIK_DIALOG_FONT)) |
|
102 { |
|
103 //charFormat.iFontSpec.iTypeface.SetIsProportional(EFalse); |
|
104 iConsole->SetFontL(charFormat.iFontSpec); |
|
105 } |
|
106 } |
|
107 #endif |
|
108 break; |
|
109 #if 0 |
|
110 case EConsolHistory: |
|
111 { |
|
112 CHistoryDialog* dialog2 = new(ELeave) CHistoryDialog(&iHistory); |
|
113 if (dialog2->ExecuteLD(R_KMD_HISTORY_DIALOG)) |
|
114 iConsole->SetHistorySizeL(iHistory,0); |
|
115 } |
|
116 break; |
|
117 #endif |
|
118 case EConsolScrollNone: |
|
119 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOff); |
|
120 break; |
|
121 case EConsolScrollHor: |
|
122 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto,CEikScrollBarFrame::EOff); |
|
123 break; |
|
124 case EConsolScrollVert: |
|
125 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto); |
|
126 break; |
|
127 case EConsolScrollBoth: |
|
128 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto,CEikScrollBarFrame::EAuto); |
|
129 break; |
|
130 default: |
|
131 break; |
|
132 } |
|
133 } |
|
134 |
|
135 void CConsoleControl::FocusChanged(TDrawNow aDrawNow) |
|
136 { |
|
137 iConsole->ConsoleControl()->SetFocus(IsFocused(), aDrawNow); |
|
138 } |
|
139 |
|
140 void CConsoleControl::ToggleFontStyleAndRedrawL(TMessageControlFontStyle aStyleElement) |
|
141 { |
|
142 switch (aStyleElement) |
|
143 { |
|
144 case EStyleElementColor: |
|
145 if ( iConsole->Att() & ATT_COLORMASK ) // color? |
|
146 iConsole->SetAtt(ATT_NORMAL); // then set normal |
|
147 else // else |
|
148 iConsole->SetAtt(4,11); // set 4 (darkgray) on 11 (lightgray) |
|
149 break; |
|
150 case EStyleElementBold: |
|
151 // clear color flag (just to be sure) and switch bold flag |
|
152 iConsole->SetAtt( (iConsole->Att()&(~ATT_COLORMASK)) ^ ATT_BOLD ); |
|
153 break; |
|
154 case EStyleElementItalic: |
|
155 // clear color flag (just to be sure) and switch italic flag |
|
156 iConsole->SetAtt( (iConsole->Att()&(~ATT_COLORMASK)) ^ ATT_ITALIC ); |
|
157 break; |
|
158 case EStyleElementInverse: |
|
159 // clear color flag (just to be sure) and switch inverse flag |
|
160 iConsole->SetAtt( (iConsole->Att()&(~ATT_COLORMASK)) ^ ATT_INVERSE ); |
|
161 break; |
|
162 case EStyleElementUnderline: |
|
163 // clear color flag (just to be sure) and switch underline flag |
|
164 iConsole->SetAtt( (iConsole->Att()&(~ATT_COLORMASK)) ^ ATT_UNDERLINE ); |
|
165 break; |
|
166 } |
|
167 } |
|
168 |
|
169 void CConsoleControl::SetScrollBarVisibilityL(CEikScrollBarFrame::TScrollBarVisibility aHBarVisibility, CEikScrollBarFrame::TScrollBarVisibility aVBarVisibility) |
|
170 { |
|
171 iConsole->SetScrollBarVisibilityL(aHBarVisibility,aVBarVisibility); |
|
172 iConsole->ConsoleControl()->UpdateArea(); |
|
173 iConsole->UpdateScrollBars(); |
|
174 iConsole->ConsoleControl()->UpdateArea(); |
|
175 //TBool b=iConsole->RecalculateSize(); |
|
176 } |
|
177 |
|
178 |
|
179 void CConsoleControl::DrawCursor() |
|
180 { |
|
181 iConsole->DrawCursor(); |
|
182 } |
|
183 |
|
184 |
|
185 void CConsoleControl::Write(const TDesC &aMsg) |
|
186 { |
|
187 iConsole->Write(aMsg); |
|
188 iConsole->FlushChars(); |
|
189 } |
|
190 |
|
191 CEikConsoleControl *CConsoleControl::ConsoleControl() const |
|
192 { |
|
193 return iConsole->ConsoleControl(); |
|
194 } |
|
195 |
|
196 TBool CConsoleControl::UpdateScrollBars() |
|
197 { |
|
198 return iConsole->UpdateScrollBars(); |
|
199 } |
|
200 |
|
201 void CConsoleControl::ClearScreen() |
|
202 { |
|
203 iConsole->ClearScreen(); |
|
204 } |
|
205 |
|
206 |
|
207 void CConsoleControl::Redraw(const TRect &aRect) |
|
208 { |
|
209 iConsole->Redraw(aRect); |
|
210 } |
|
211 |
|
212 void CConsoleControl::Lf() |
|
213 { |
|
214 iConsole->Lf(); |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 // **************** |
|
220 // APPLICATION VIEW |
|
221 // **************** |
|
222 // |
|
223 void CIpAdmView::ConstructL(const TRect& aRect) |
|
224 { |
|
225 CreateWindowL(); |
|
226 #if EPOC_SDK >= 0x06000000 |
|
227 SetRect(aRect); |
|
228 #else |
|
229 SetRectL(aRect); |
|
230 #endif |
|
231 iContext = this; |
|
232 iBrushStyle = CGraphicsContext::ESolidBrush; |
|
233 iBrushColor = KRgbWhite; |
|
234 CreateBigConsoleL(CEikConsoleScreen::ENoInitialCursor); |
|
235 |
|
236 StartL(); |
|
237 |
|
238 ActivateL(); |
|
239 } |
|
240 |
|
241 void CIpAdmView::CreateBigConsoleL(TInt aFlags) |
|
242 { |
|
243 iConsole =new(ELeave) CConsoleControl; |
|
244 // TRect rect=Rect(); |
|
245 // rect.Shrink(3,3); |
|
246 iConsole->ConstructL(Position(),Rect().Size(),aFlags); |
|
247 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto); |
|
248 |
|
249 } |
|
250 |
|
251 CIpAdmView::~CIpAdmView() |
|
252 { |
|
253 delete iConsole; |
|
254 delete iModel; |
|
255 } |
|
256 |
|
257 TInt CIpAdmView::CountComponentControls() const |
|
258 { |
|
259 return 1; |
|
260 } |
|
261 |
|
262 CCoeControl* CIpAdmView::ComponentControl(TInt aIndex) const |
|
263 { |
|
264 switch (aIndex) |
|
265 { |
|
266 case 0: |
|
267 return iConsole; |
|
268 default: |
|
269 return 0; |
|
270 } |
|
271 } |
|
272 |
|
273 void CIpAdmView::Draw(const TRect& /*aRect*/) const |
|
274 { |
|
275 #if 0 |
|
276 CWindowGc& gc = SystemGc(); |
|
277 |
|
278 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
279 TSize penSizeBold(3,3); |
|
280 gc.SetPenSize(penSizeBold); |
|
281 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
282 |
|
283 TRect rect=iConsole->Rect(); //Lines around the Console |
|
284 rect.Grow(3,3); |
|
285 gc.DrawRect(rect); |
|
286 #endif |
|
287 } |
|
288 |
|
289 void CIpAdmView::StartL() |
|
290 { |
|
291 TInt err; |
|
292 |
|
293 if (!iModel) |
|
294 { |
|
295 iModel = new CIpAdmEngine(this); |
|
296 CEikonEnv::Static()->BusyMsgL(R_BUSY); |
|
297 TRAP(err, iModel->ConstructL()); |
|
298 CEikonEnv::Static()->BusyMsgCancel(); |
|
299 if (err!=KErrNone) |
|
300 { |
|
301 TBuf<50> msg; |
|
302 msg.Format(_L("Error initializing: %d"), err); |
|
303 ShowError(msg); |
|
304 StopL(); |
|
305 } |
|
306 } |
|
307 else |
|
308 CEikonEnv::Static()->InfoMsg(_L("Already Running!")); |
|
309 } |
|
310 |
|
311 |
|
312 void CIpAdmView::Write(const TDesC &aMsg) |
|
313 { |
|
314 iConsole->Write(aMsg); |
|
315 iConsole->Write(_L("\n")); |
|
316 } |
|
317 |
|
318 void CIpAdmView::ShowError(TInt aId) |
|
319 { |
|
320 iEikonEnv->InfoMsg(aId); |
|
321 } |
|
322 |
|
323 void CIpAdmView::ShowError(const TDes &msg) |
|
324 { |
|
325 iEikonEnv->InfoMsg(msg); |
|
326 } |
|
327 |
|
328 void CIpAdmView::ShowError(const TDes &msg, TInt aErr) |
|
329 { |
|
330 TBuf<100> txt; |
|
331 TBuf<100> txt2; |
|
332 |
|
333 txt.Format(msg); |
|
334 iEikonEnv->GetErrorText(txt2,aErr); |
|
335 txt.AppendFormat(txt2); |
|
336 iEikonEnv->InfoMsg(txt); |
|
337 } |
|
338 |
|
339 void CIpAdmView::StopL() |
|
340 { |
|
341 if (iModel) |
|
342 { |
|
343 CEikonEnv::Static()->BusyMsgL(R_BUSY); |
|
344 delete iModel; |
|
345 CEikonEnv::Static()->BusyMsgCancel(); |
|
346 Write(_L("*Stopped*")); |
|
347 } |
|
348 else |
|
349 CEikonEnv::Static()->InfoMsg(_L("Not running!")); |
|
350 iModel = NULL; |
|
351 } |
|
352 |
|
353 |
|
354 void CIpAdmView::ClearScreenL() |
|
355 { |
|
356 delete iConsole; |
|
357 iConsole = NULL; |
|
358 CreateBigConsoleL(CEikConsoleScreen::ENoInitialCursor); |
|
359 } |
|
360 |
|
361 void CIpAdmView::HandleCommandL(TInt aCommand) |
|
362 { |
|
363 switch (aCommand) |
|
364 { |
|
365 case EIpAdmClearScreen: |
|
366 ClearScreenL(); |
|
367 break; |
|
368 |
|
369 default: |
|
370 ASSERT(iConsole != NULL); |
|
371 iConsole->HandleCommandL(aCommand); |
|
372 if (iModel) |
|
373 iModel->HandleCommandL(aCommand); |
|
374 break; |
|
375 } |
|
376 } |
|
377 |
|
378 // ************** |
|
379 // APPLICATION UI |
|
380 // ************** |
|
381 // |
|
382 void CIpAdmAppUi::ConstructL() |
|
383 { |
|
384 BaseConstructL(); |
|
385 |
|
386 iAppView= new (ELeave) CIpAdmView; |
|
387 iAppView->ConstructL(ClientRect()); |
|
388 |
|
389 #if EPOC_SDK < 0x06000000 |
|
390 CEikFileNameLabel* filenameLabel=STATIC_CAST(CEikFileNameLabel*, iToolBar->ControlById(EIpAdmFilename)); |
|
391 filenameLabel->UpdateL(); |
|
392 #endif |
|
393 } |
|
394 |
|
395 void CIpAdmAppUi::HandleCommandL(TInt aCommand) |
|
396 { |
|
397 switch (aCommand) |
|
398 { |
|
399 case EEikCmdExit: |
|
400 Exit(); |
|
401 return; |
|
402 default: |
|
403 iAppView->HandleCommandL(aCommand); |
|
404 } |
|
405 } |
|
406 |
|
407 CIpAdmAppUi::~CIpAdmAppUi() |
|
408 { |
|
409 #ifndef CALYPSO |
|
410 RemoveFromStack(iAppView); |
|
411 #endif |
|
412 delete iAppView; |
|
413 } |
|
414 |
|
415 // ******** |
|
416 // DOCUMENT |
|
417 // ******** |
|
418 CIpAdmDocument::CIpAdmDocument(CEikApplication& aApp) |
|
419 : CEikDocument(aApp) |
|
420 { |
|
421 } |
|
422 |
|
423 CEikAppUi* CIpAdmDocument::CreateAppUiL() |
|
424 { |
|
425 return new (ELeave) CIpAdmAppUi; |
|
426 } |
|
427 |
|
428 // *********** |
|
429 // APPLICATION |
|
430 // *********** |
|
431 // |
|
432 TUid CIpAdmApplication::AppDllUid() const |
|
433 { |
|
434 return KUidIpAdmApp; |
|
435 } |
|
436 |
|
437 CApaDocument* CIpAdmApplication::CreateDocumentL() |
|
438 { |
|
439 return new(ELeave) CIpAdmDocument(*this); |
|
440 } |
|
441 |
|
442 // **** |
|
443 // MAIN |
|
444 // **** |
|
445 // |
|
446 EXPORT_C CApaApplication* NewApplication() |
|
447 { |
|
448 return new CIpAdmApplication; |
|
449 } |
|
450 |
|
451 |
|
452 #ifdef MAKE_EXE_APPLICATION |
|
453 |
|
454 GLDEF_C TInt E32Main() |
|
455 { |
|
456 return EikStart::RunApplication(NewApplication); |
|
457 } |
|
458 |
|
459 #else |
|
460 |
|
461 #ifndef EKA2 |
|
462 GLDEF_C TInt E32Dll(TDllReason /*aReason*/) |
|
463 { |
|
464 return KErrNone; |
|
465 } |
|
466 #endif |
|
467 |
|
468 #endif // MAKE_EXE_APPLICATION |