1 /*
2 * $Id: proto_profile.cpp,v 1.2 2005/03/24 00:08:12 bozo Exp $
3 *
4 * G N A P P L E T
5 *
6 * gnapplet is a gnbus protocol driver for symbian phones.
7 *
8 * This file is part of gnokii.
9 *
10 * Gnokii is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * Gnokii is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with gnokii; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * Copyright (C) 2004 BORBELY Zoltan
25 *
26 * This file contains the profile message handler.
27 *
28 */
29
30 #include "proto.h"
31
32
ReadProfileL(PktBuf & in,PktBuf & out)33 static void ReadProfileL(PktBuf &in, PktBuf &out)
34 {
35 TUint16 id;
36 TBuf<256> ringtone1, ringtone2;
37 int call_alert, volume, vibra, key_tone, i;
38
39 g->InitProfileL();
40
41 in >> id;
42 in.FinishL();
43
44 if (id >= 5) {
45 out << (TUint16)GNAPPLET_MSG_PROFILE_READ_RESP;
46 out << (TUint16)GN_ERR_INVALIDLOCATION;
47 return;
48 }
49
50 int i5;
51 CArrayFixFlat<TContactItemId> *foo = new (ELeave)CArrayFixFlat<long>(10);
52 g->profile->GetProfileMultiData(ringtone1, ringtone2, call_alert, volume, vibra, key_tone, foo, i5, id);
53 delete foo;
54 //Debug(_L("%S|%S|%d|%d|%d|%d|%d"), &ringtone1, &ringtone2, call_alert, volume, vibra, key_tone, i5);
55
56 CPermanentFileStore *fstore = CPermanentFileStore::OpenLC(
57 *g->profilefs,
58 _L("c:\\system\\Apps\\profileApp\\dbProfile.db"),
59 EFileRead | EFileWrite);
60 RDbStoreDatabase database;
61 database.OpenL(fstore, fstore->Root());
62 RDbTable table;
63 // tableId, profileName, profileUID, remove, modify, active, visible, rename
64 table.Open(database, _L("ProfileLookup"));
65 table.FirstL();
66 for (i = 0; i < id; i++)
67 table.NextL();
68 table.GetL();
69 TBuf<16> name = table.ColDes16(2);
70 table.Close();
71 database.Close();
72 CleanupStack::PopAndDestroy(fstore);
73
74 out << (TUint16)GNAPPLET_MSG_PROFILE_READ_RESP;
75 out << (TUint16)GN_ERR_NONE;
76 out << id;
77 if (name.Length() == 0 || name == _L(" ")) {
78 switch (id) {
79 case 0: out << _L("General"); break;
80 case 1: out << _L("Silent"); break;
81 case 2: out << _L("Meeting"); break;
82 case 3: out << _L("Outdoor"); break;
83 case 4: out << _L("Pager"); break;
84 }
85 out << (TUint16)id;
86 } else {
87 out << name;
88 out << (TUint16)0xffff;
89 }
90 switch (key_tone) {
91 case 0x00: out << (TUint8)GN_PROFILE_KEYVOL_Off; break;
92 case 0x01: out << (TUint8)GN_PROFILE_KEYVOL_Level1; break;
93 case 0x02: out << (TUint8)GN_PROFILE_KEYVOL_Level2; break;
94 case 0x03: out << (TUint8)GN_PROFILE_KEYVOL_Level3; break;
95 default: User::Leave(1);
96 }
97 // lights
98 switch (call_alert) {
99 case 0x00: out << (TUint8)GN_PROFILE_CALLALERT_Ringing; break;
100 case 0x01: out << (TUint8)GN_PROFILE_CALLALERT_Ascending; break;
101 case 0x02: out << (TUint8)GN_PROFILE_CALLALERT_RingOnce; break;
102 case 0x03: out << (TUint8)GN_PROFILE_CALLALERT_BeepOnce; break;
103 case 0x04: out << (TUint8)GN_PROFILE_CALLALERT_Off; break;
104 default: User::Leave(1);
105 }
106 //out << ringtone; // ringtone
107 out << (TUint8)volume;
108 // message tone FIXME: mar nem enum!!!
109 out << (TUint8)GN_PROFILE_WARNING_On; // warning tone
110 out << (TUint8)(vibra ? GN_PROFILE_VIBRATION_On : GN_PROFILE_VIBRATION_Off);
111 // caller groups
112 // automatic answer
113 }
114
115
GetActiveProfileL(PktBuf & in,PktBuf & out)116 static void GetActiveProfileL(PktBuf &in, PktBuf &out)
117 {
118 int id;
119
120 g->InitProfileL();
121
122 in.FinishL();
123
124 CPermanentFileStore *fstore = CPermanentFileStore::OpenLC(
125 *g->profilefs,
126 _L("c:\\system\\Apps\\profileApp\\dbProfile.db"),
127 EFileRead | EFileWrite);
128 RDbStoreDatabase database;
129 database.OpenL(fstore, fstore->Root());
130 RDbTable table;
131 // tableId, profileName, profileUID, remove, modify, active, visible, rename
132 table.Open(database, _L("ProfileLookup"));
133 table.FirstL();
134 for (id = 0; table.AtRow(); id++) {
135 table.GetL();
136 if (table.ColInt(6) != 0) break;
137 table.NextL();
138 }
139 table.Close();
140 database.Close();
141 CleanupStack::PopAndDestroy(fstore);
142
143 out << (TUint16)GNAPPLET_MSG_PROFILE_GET_ACTIVE_RESP;
144 out << (TUint16)GN_ERR_NONE;
145 out << (TUint16)id;
146 }
147
148
HandleProfileMsg(PktBuf & in,PktBuf & out)149 void HandleProfileMsg(PktBuf &in, PktBuf &out)
150 {
151 TUint16 code;
152
153 in >> code;
154 switch (code) {
155 case GNAPPLET_MSG_PROFILE_READ_REQ:
156 ReadProfileL(in, out);
157 break;
158
159 case GNAPPLET_MSG_PROFILE_GET_ACTIVE_REQ:
160 GetActiveProfileL(in, out);
161 break;
162
163 case GNAPPLET_MSG_PROFILE_WRITE_REQ:
164 case GNAPPLET_MSG_PROFILE_SET_ACTIVE_REQ:
165 default:
166 out << (TUint16)((code + 1) & ~1);
167 out << (TUint16)GN_ERR_NOTSUPPORTED;
168 break;
169 }
170 }
171