📄 gnuboxcontainer.cpp
字号:
//// gnuboxContainer.cpp - Gnubox main AppUi container cpp file.//// Gnubox 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.//// Gnubox is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with Gnubox; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//// Copyright (C) 2002 Mal Minhas.//// Revision history:// =================// 28/08/02: First version of Gnubox started.#include "gnuboxContainer.h"#include "debug.h"#include <eiklabel.h> // for example label control#include <coemain.h> // for iCoeEnv definition#include <coecntrl.h> // for ControlEnv() inline#include <btextnotifiers.h> // for Bluetooth notifier#include <btregistry.h> // for accessing BT registry#include <btmanclient.h>/** Information about CommDb ======================== CommDb provides system-wide storage for communications-related settings. It holds information about Internet Access Providers (IAPs), Internet Service Providers (ISPs), GPRS, modems, locations, charge-cards, proxies and WAP settings CommDb stores the settings in a series of tables in a relational database, using the DBMS architecture. DBMS is a client/server architecture and provides for safe access by multiple clients. The CommDb API has two key concepts: <b>communications database</b>, and <b>table view</b>. The communications database interface allows clients to access the database, open its tables, and perform transactions. It is provided by CCommsDatabase and its base class CCommsDatabaseBase. Most database settings are read and written to by opening the appropriate table. Table access is provided by CCommsDbTableView. It is possible for several instances of most of the tables (e.g. where multiple IAPs have been set up) to exist in the database. The Connected preferences table sets a ranking by which such records are used. That table is accessed through its own view class CCommsDbConnectionPrefTableView. A view is simply a subset of the records (or rows) within a table, selected according to defined criteria. Tables, records, rows, columns, and so on, are DBMS concepts. Note that you can open two kinds of CCommsDatabase in 6.0 - EDatabaseTypeIAP and EDatabaseTypeISP. The latter is deprecated in 6.1. For a database of type EDatabaseTypeIAP, tables are arranged as follows (from /commdb/scdb/cdbdata.cpp): LOCAL_D TTable const KTableList[]= { {IAP, KIAPTable}, {DIAL_OUT_ISP, KDialOutISPTable}, {DIAL_IN_ISP, KDialInISPTable}, {WAP_ACCESS_POINT, KWAPAccessPointTable}, {WAP_IP_BEARER, KWAPIPBearerTable}, {WAP_SMS_BEARER, KWAPSMSBearerTable}, {OUTGOING_GPRS, KGPRSTable}, {INCOMING_GPRS, KGPRSTable}, {MODEM, KModemTable}, {LOCATION, KLocationTable}, {CHARGECARD, KChargecardTable}, {PROXIES, KProxiesTable}, {CONNECTION_PREFERENCES, KConnectionPreferencesTable}, {AGENT, KAgentTable}, {GLOBAL_SETTINGS, KGlobalSettings}, {BT_DEVICE_TABLE, KCBTDeviceTable}, {BT_DEFAULT_TABLE, KCBTDefaultServiceTable}, {DEFAULT_GPRS, KDefaultGPRSTable}, {BT_SECURITY_TABLE, KCBTSecurityTable}, {ACCESS_TYPE_TABLE, KAccessTypeTable}, {0} }; Note that the various defines here are in /commdb/inc/cdbcols.h: // tables... #define IAP _S("IAP") #define DIAL_OUT_ISP _S("DialOutISP") #define MODEM _S("Modem") ... // DIAL_OUT_ISP table columns #define ISP_DESCRIPTION _S("Description") // text field for app to use to describe ISP #define ISP_TYPE _S("Type") #define ISP_DEFAULT_TEL_NUM _S("DefaultTelNum") ... // modem table columns #define MODEM_PORT_NAME _S("PortName") #define MODEM_TSY_NAME _S("TSYName") #define MODEM_CSY_NAME _S("CSYName") #define MODEM_HANDSHAKING _S("Handshaking") ... // Bluetooth table columns #define BT_DEV_ADD _S("DeviceAddress") #define BT_DEV_DFLT_NAME _S("DeviceDefaultName") #define BT_DEV_FRIENDLY_NAME _S("DeviceFriendlyName") #define BT_DEVICE_CLASS _S("DeviceClass") #define BT_LINKKEY_SIZE _S("DeviceLinkKeySize") #define BT_LINKKEY _S("DeviceLinkKey") #define BT_DEV_STATE _S("DeviceStatus") #define BT_DEVICE_GLOBAL_SECURITY _S("DeviceGlobalSecurity") // #define BT_DFLT_SER_NAME _S("DefaultServicename") #define BT_DFLT_SER_UUID _S("DefaultServiceUID") #define BT_DFLT_DEV_ADD _S("DefaultDeviceAddress") #define BT_SEC_UID _S("BTSecurityUID") #define BT_SEC_DEVICE_SECURITY _S("BTSecurityDevice") #define BT_DFLT_VIRTUAL_PORT _S("DefaultVirtualPort") #define BT_DFLT_SECURITY_LEVEL _S("DefaultSecurityLevel") Tables we are interested in are DIAL_OUT_ISP () and MODEM (). From (from /commdb/scdb/cdbdata.cpp): LOCAL_D TColumn const KDialOutISPTable[]= { {ISP_DESCRIPTION,EDbColText,0}, ... {ISP_DEFAULT_TEL_NUM,EDbColText,0}, ... {ISP_TYPE,EDbColUint32,0} ... {ISP_IF_NAME,EDbColText,TDbCol::ENotNull}, ... }; LOCAL_D TColumn const KModemTable[]= { ... {MODEM_PORT_NAME,EDbColText,0}, {MODEM_TSY_NAME,EDbColText,0}, {MODEM_CSY_NAME,EDbColText,0}, ... {MODEM_HANDSHAKING,EDbColUint32,0}, ... }; LOCAL_D TColumn const KCBTDeviceTable[]= { ... {BT_DEV_ADD,EDbColText8,TDbCol::ENotNull}, {BT_DEV_DFLT_NAME,EDbColLongText16,0}, {BT_DEV_FRIENDLY_NAME,EDbColLongText16,0}, {BT_DEVICE_CLASS,EDbColUint32,0}, {BT_LINKKEY,EDbColText8,0}, {BT_DEVICE_GLOBAL_SECURITY, EDbColUint32,0}, {BT_DEV_STATE, EDbColUint32, TDbCol::ENotNull}, ... }; LOCAL_D TColumn const KCBTDefaultServiceTable[]= { ... {BT_DFLT_SER_NAME,EDbColText16,0}, {BT_DFLT_SER_UUID,EDbColText8,TDbCol::ENotNull}, {BT_DFLT_VIRTUAL_PORT,EDbColUint32,TDbCol::ENotNull}, {BT_DFLT_DEV_ADD,EDbColText8,TDbCol::ENotNull}, {BT_DFLT_SECURITY_LEVEL,EDbColUint8,0}, ... }; LOCAL_D TColumn const KCBTSecurityTable[]= { ... {BT_DEV_ADD,EDbColText8,TDbCol::ENotNull}, {BT_SEC_DEVICE_SECURITY,EDbColUint32,0}, {BT_SEC_UID,EDbColUint32,0}, ... }; Note that you don't actually directly manipulate the BT fields in CommDB. The BTRegistry is your friend in this regard. It acts as a facade over the CommDB. Fine sentiment. Now all we need is someone to do the same thing for the networking bits ;-) @TODO: Add more comments here on use cases for each option and IOP/testing.*/void CGnuboxContainer::ConstructL(const TRect& aRect, CGnuboxAppUi* aParent)/** CGnuboxContainer::ConstructL(const TRect& aRect) EPOC two phased constructor. Initialise to default settings.*/ { FLOG(_L("CGnuboxContainer::ConstructL")); CreateWindowL(); iParent = aParent; // This will add further text but it might take time so // we've hived it off to a separate active object... iLoader = CGnuboxAOLoader::NewL(this); iLabel = new (ELeave) CEikLabel; iLabel->SetContainerWindowL(*this); // Set up the screen text with whatever the default bearer is...
SetAndDrawScreenTextL(iParent->GetMode()); // MALM
SetRect(aRect);
ActivateL(); }CGnuboxContainer::~CGnuboxContainer()/** Destructor*/ { FLOG(_L("CGnuboxContainer::~CGnuboxContainer")); delete iLabel; iTextLines.Close(); delete iLoader; }void CGnuboxContainer::SizeChanged()/** CGnuboxContainer::SizeChanged() Called by framework when the view size is changed. @TODO: Add control resize code etc here needed to resize label properly*/ { FLOG(_L("CGnuboxContainer::SizeChanged")); iLabel->SetExtent(TPoint(10,5),iLabel->MinimumSize()); }TInt CGnuboxContainer::CountComponentControls() const/** CGnuboxContainer::CountComponentControls() const*/ { return 1; // return nbr of controls inside this container }CCoeControl* CGnuboxContainer::ComponentControl(TInt aIndex) const/** CGnuboxContainer::ComponentControl(TInt aIndex) const*/ { switch ( aIndex ) { case 0: return iLabel; default: return NULL; } }void CGnuboxContainer::Draw(const TRect& aRect) const/** CGnuboxContainer::Draw(const TRect& aRect) const Note that this redraws itself in different ways depending on what the current bearer is.*/ { FLOG(_L("CGnuboxContainer::Draw")); DrawControls(aRect); }void CGnuboxContainer::HandleControlEventL( CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)/** CGnuboxContainer::HandleControlEventL( CCoeControl* aControl,TCoeEvent aEventType) We are not interested in handling control events in this program (?).*/ { // TODO: Add your control event handler code here FLOG(_L("CGnuboxContainer::HandleControlEventL")); }void CGnuboxContainer::SwitchModeL(TConnectionMode aMode)/** CGnuboxContainer::SwitchModeL(TConnectionMode aMode) Invoked whenever the user has decided to switch from one underlying connection mode to another. Currently there are five options: 1) Direct PPP connection over Infrared 2) Direct PPP connection over Bluetooth 3) Dialup PPP connection over Infrared 4) Dialup PPP connection over Bluetooth 5) Default PPP over CSD/GPRS phone stack*/ { switch (aMode) { case EInfraredDirect: // First change the relevant CommDB settings iEikonEnv->InfoMsg(_L("Infrared Access Point")); break; case EInfraredDialup: // First change the relevant CommDB settings iEikonEnv->InfoMsg(_L("Infrared Phone")); break; case EBluetoothDirect: // First change the relevant CommDB settings iEikonEnv->InfoMsg(_L("Bluetooth LANP")); break; case EBluetoothDialup: // First change the relevant CommDB settings iEikonEnv->InfoMsg(_L("Bluetooth DUNP")); break; default: // First change the relevant CommDB settings iEikonEnv->InfoMsg(_L("1 box smartphone")); break; } TBool okToUpdate=UpdateCommDbL(aMode);
if (okToUpdate)
{// we are ok to switch mode
iParent->SetMode(aMode);
////Don't do the StoreRecord here - do it in Loader RunL
// Then change the container control text strings to // ensure their correct updating on redraw SetAndDrawScreenTextL(aMode);
} }void CGnuboxContainer::DrawControls(const TRect& aRect) const/** CGnuboxContainer::DrawControls() const Main point at which AppUi controls are drawn Note that for 7650 width=176 and height=144 @TODO: Need to scale the drawing of controls.*/ { CWindowGc& gc = SystemGc(); gc.SetPenStyle(CGraphicsContext::ENullPen); switch (iParent->GetMode()) { case EBluetoothDirect: case EBluetoothDialup: { TRgb bluish(210,210,255); // appears as pale bluish color gc.SetBrushColor(bluish); break; } case EInfraredDirect: case EInfraredDialup: { TRgb reddish(255,200,200); // appears as pale reddish color gc.SetBrushColor(reddish); break; } default: gc.SetBrushColor(KRgbWhite); break; } gc.SetBrushStyle(CGraphicsContext::ESolidBrush); gc.DrawRect(aRect); // Now we can draw screen elements //TPoint startpoint(0,iH*KHeightScalingFactor*3/5-40); TPoint startpoint(KXOffset,20); //TPoint endpoint(iW*KWidthScalingFactor,iH*KHeightScalingFactor*3/5-40); TPoint endpoint((KWidth-KXOffset),20); gc.SetPenStyle(CGraphicsContext::ESolidPen); TSize penSizeThicker(1,1); gc.SetPenSize(penSizeThicker); gc.SetPenColor(KRgbBlack); gc.DrawLine(startpoint,endpoint); //TFontSpec fs(_L("Arial"),20*7); // 9pt Arial TFontSpec fs(_L("Arial"),20*4); // 8pt Arial //TFontSpec fs(_L("Arial"),20*11); // 11pt Arial //TFontSpec fs(_L("Arial"),20*24); // 24pt Arial fs.iFontStyle= TFontStyle(EPostureItalic,EStrokeWeightNormal,EPrintPosNormal); CFont* fontUsed=ControlEnv()->CreateScreenFontL(fs); gc.UseFont(fontUsed); TRect textRect(KXOffset,23,(KWidth-KXOffset),KHeight); gc.DrawRect(textRect); // just to see our limits... // Now draw the lines of text - you must do this per redraw for(TInt count = 0; count < iTextLines.Count(); count++) gc.DrawText(iTextLines[count],TPoint(KTextOffset,35+(count*KLineGap))); gc.DiscardFont(); ControlEnv()->ReleaseScreenFont(fontUsed); // gc.SetBrushStyle(CGraphicsContext::ENullBrush); }void CGnuboxContainer::SetAndDrawScreenTextL(const TConnectionMode aMode)/** CGnubox::SetAndDrawScreenTextL(TConnectionMode aMode) This function does two things: 1) Changes the main label text 2) Updates screen with new CommDb settings To do the latter, it invokes the iLoader active object.*/ { FLOG(_L("CGnuboxContainer::SetScreenTextL"));
TBuf<22> txtBuf;
txtBuf.FillZ();
switch (aMode) { case EInfraredDirect:
txtBuf=KDirectOverIRTxt;
txtBuf.SetMax();
iLabel->SetTextL(txtBuf); iTextLines.Close(); User::LeaveIfError(iTextLines.Append(_L("Loading CommDb"))); User::LeaveIfError(iTextLines.Append(_L("Infrared settings..."))); iLoader->Fire(); break; case EInfraredDialup:
txtBuf=KDialupOverIRTxt;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -