千辛万苦,我的系统设置模块终于搞定。
系统设置包括:
1、日志文件大小
2、开机是否自动运行
3、是否记录日志
4、没有规则匹配时的动作:放行/拒绝/通知用户,由用户来决定
实现:
用设置列表来实现,分别使用:
1、EAknCtIntegerEdwin :设置数字类型
2、EAknCtPopupSettingList :Yes/No两种选择
3、EAknCtPopupSettingList :Yes/No两种选择
4、EAknCtPopupSettingList :Enable/Disable/ToUser三种选择
资源代码:
存取文件代码:
关键代码:
必须要在SettingList类中重载EditItemL函数,使的编辑过的数据能够保存到CFirewallSettingData类的实例iData中:
void CFirewallSettingList::EditItemL(TInt aIndex, TBool aCalledFromMenu)
{
CAknSettingItemList::EditItemL(aIndex, aCalledFromMenu) ;
(*SettingItemArray())[aIndex]->StoreL() ;
}
系统设置包括:
1、日志文件大小
2、开机是否自动运行
3、是否记录日志
4、没有规则匹配时的动作:放行/拒绝/通知用户,由用户来决定
实现:
用设置列表来实现,分别使用:
1、EAknCtIntegerEdwin :设置数字类型
2、EAknCtPopupSettingList :Yes/No两种选择
3、EAknCtPopupSettingList :Yes/No两种选择
4、EAknCtPopupSettingList :Enable/Disable/ToUser三种选择
资源代码:
//-----------------------------------------------------------------------------
//
// r_firewall_setting_itemlist
// 防火墙设置列表
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_ITEM_LIST R_FIREWALL_SETTING_ITEMLIST
{
flags = EAknSettingItemNumberedStyle ;
title = SETTING_ITEM_LIST_TITLE ;
items =
{
AVKON_SETTING_ITEM
{
identifier = ESettingItemSizeLogFile ; //日志文件大小
setting_page_resource = R_FIREWALL_SETTING_PAGE_SIZE_LOGFILE ;
name = str_firewall_setting_title_size_logfile ;
},
AVKON_SETTING_ITEM
{
identifier = ESettingItemIsRecordLog ; //是否记录日志
setting_page_resource = R_FIREWALL_SETTING_PAGE_IS_RECORD_LOG ;
associated_resource = R_FIREWALL_SETTING_IS_RECORD_LOG_TEXTS;
name = str_firewall_setting_title_is_record_log ;
},
AVKON_SETTING_ITEM
{
identifier = ESettingItemIsAutostart ; //开机是否自启动
setting_page_resource = R_FIREWALL_SETTING_PAGE_IS_AUTOSTART ;
associated_resource = R_FIREWALL_SETTING_IS_AUTOSTART_TEXTS;
name = str_firewall_setting_title_is_autostart ;
},
AVKON_SETTING_ITEM
{
identifier = ESettingItemDefaultAction ; //无规则匹配动作
setting_page_resource = r_firewall_setting_page_default_action ;
associated_resource = r_firewall_setting_list_default_action ;
name = str_firewall_setting_title_default_action ;
}
};
}
//-----------------------------------------------------------------------------
//
// R_FIREWALL_SETTING_PAGE_SIZE_LOGFILE
// 防火墙设日志文件大小设置页
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_PAGE R_FIREWALL_SETTING_PAGE_SIZE_LOGFILE
{
number = 0;
label = str_firewall_setting_page_label_size_logfile;
type = EAknCtIntegerEdwin;
editor_resource_id = R_FIREWALL_SETTING_SIZE_LOGFILE_EDWIN;
}
RESOURCE AVKON_INTEGER_EDWIN R_FIREWALL_SETTING_SIZE_LOGFILE_EDWIN
{
min = KFirewallSettingSizeLogFileMin ;
max = KFirewallSettingSizeLogFileMax ;
}
//-----------------------------------------------------------------------------
//
// R_FIREWALL_SETTING_PAGE_IS_RECORD_LOG
// 防火墙是否记录日志设置页
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_PAGE R_FIREWALL_SETTING_PAGE_IS_RECORD_LOG
{
number= 0;
label= str_firewall_setting_page_label_is_record_log ;
type = EAknCtPopupSettingList;
//editor_resource_id = r_setting_app_on_off_popup_setting_list;
}
RESOURCE AVKON_POPUP_SETTING_TEXTS R_FIREWALL_SETTING_IS_RECORD_LOG_TEXTS
{
flags = 0;
setting_texts_resource = R_AKNEXSETTINGLIST_ON_OFF_TEXTS;
popped_up_texts_resource = R_AKNEXSETTINGLIST_POPPED_UP_ON_OFF_TEXTS;
}
RESOURCE ARRAY R_AKNEXSETTINGLIST_ON_OFF_TEXTS
{
items =
{
AVKON_ENUMERATED_TEXT { value=1; text = str_firewall_setting_is_record_log_on ; },
AVKON_ENUMERATED_TEXT { value=0; text = str_firewall_setting_is_record_log_off ; }
};
}
RESOURCE ARRAY R_AKNEXSETTINGLIST_POPPED_UP_ON_OFF_TEXTS
{
items =
{
LBUF { txt = str_firewall_setting_is_record_log_enabled; },
LBUF { txt = str_firewall_setting_is_record_log_disabled; }
};
}
//-----------------------------------------------------------------------------
//
// R_FIREWALL_SETTING_PAGE_IS_AUTOSTART
// 防火墙是否记录日志设置页
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_PAGE R_FIREWALL_SETTING_PAGE_IS_AUTOSTART
{
number= 0;
label= str_firewall_setting_page_label_is_autostart ;
type = EAknCtPopupSettingList;
//editor_resource_id = r_setting_app_on_off_popup_setting_list;
}
RESOURCE AVKON_POPUP_SETTING_TEXTS R_FIREWALL_SETTING_IS_AUTOSTART_TEXTS
{
flags = 0;
setting_texts_resource = R_AKNEXSETTINGLIST_ON_OFF_TEXTS;
popped_up_texts_resource = R_AKNEXSETTINGLIST_POPPED_UP_ON_OFF_TEXTS;
}
//-----------------------------------------------------------------------------
//
// R_FIREWALL_SETTING_PAGE_DEFAULT_ACTION
// 防火墙无匹配规则默认动作设置页
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_PAGE r_firewall_setting_page_default_action
{
number= 0;
label= str_firewall_setting_page_label_default_action ;
type = EAknCtPopupSettingList ;
editor_resource_id = r_firewall_setting_list_new_entry_default_action ;
}
RESOURCE POPUP_SETTING_LIST r_firewall_setting_list_new_entry_default_action
{
//flags = EAknPopupSettingListFlagAllowsUserDefinedEntry ;
flags = EAknPopupSettingListFlagInitialised ;
}
RESOURCE AVKON_POPUP_SETTING_TEXTS r_firewall_setting_list_default_action
{
setting_texts_resource = r_firewall_setting_texts_resource_default_action;
popped_up_texts_resource = r_firewall_setting_popped_up_texts_resource_default_action ;
}
RESOURCE ARRAY r_firewall_setting_texts_resource_default_action
{
items =
{
AVKON_ENUMERATED_TEXT
{
value = 0;
text = str_firewall_setting_default_action_0;
},
AVKON_ENUMERATED_TEXT
{
value = 1;
text = str_firewall_setting_default_action_1;
},
AVKON_ENUMERATED_TEXT
{
value = 2;
text = str_firewall_setting_default_action_2;
}
};
}
RESOURCE ARRAY r_firewall_setting_popped_up_texts_resource_default_action
{
items =
{
LBUF
{
txt = str_firewall_setting_default_action_0;
},
LBUF
{
txt = str_firewall_setting_default_action_1;
},
LBUF
{
txt = str_firewall_setting_default_action_2;
}
};
}
//
// r_firewall_setting_itemlist
// 防火墙设置列表
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_ITEM_LIST R_FIREWALL_SETTING_ITEMLIST
{
flags = EAknSettingItemNumberedStyle ;
title = SETTING_ITEM_LIST_TITLE ;
items =
{
AVKON_SETTING_ITEM
{
identifier = ESettingItemSizeLogFile ; //日志文件大小
setting_page_resource = R_FIREWALL_SETTING_PAGE_SIZE_LOGFILE ;
name = str_firewall_setting_title_size_logfile ;
},
AVKON_SETTING_ITEM
{
identifier = ESettingItemIsRecordLog ; //是否记录日志
setting_page_resource = R_FIREWALL_SETTING_PAGE_IS_RECORD_LOG ;
associated_resource = R_FIREWALL_SETTING_IS_RECORD_LOG_TEXTS;
name = str_firewall_setting_title_is_record_log ;
},
AVKON_SETTING_ITEM
{
identifier = ESettingItemIsAutostart ; //开机是否自启动
setting_page_resource = R_FIREWALL_SETTING_PAGE_IS_AUTOSTART ;
associated_resource = R_FIREWALL_SETTING_IS_AUTOSTART_TEXTS;
name = str_firewall_setting_title_is_autostart ;
},
AVKON_SETTING_ITEM
{
identifier = ESettingItemDefaultAction ; //无规则匹配动作
setting_page_resource = r_firewall_setting_page_default_action ;
associated_resource = r_firewall_setting_list_default_action ;
name = str_firewall_setting_title_default_action ;
}
};
}
//-----------------------------------------------------------------------------
//
// R_FIREWALL_SETTING_PAGE_SIZE_LOGFILE
// 防火墙设日志文件大小设置页
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_PAGE R_FIREWALL_SETTING_PAGE_SIZE_LOGFILE
{
number = 0;
label = str_firewall_setting_page_label_size_logfile;
type = EAknCtIntegerEdwin;
editor_resource_id = R_FIREWALL_SETTING_SIZE_LOGFILE_EDWIN;
}
RESOURCE AVKON_INTEGER_EDWIN R_FIREWALL_SETTING_SIZE_LOGFILE_EDWIN
{
min = KFirewallSettingSizeLogFileMin ;
max = KFirewallSettingSizeLogFileMax ;
}
//-----------------------------------------------------------------------------
//
// R_FIREWALL_SETTING_PAGE_IS_RECORD_LOG
// 防火墙是否记录日志设置页
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_PAGE R_FIREWALL_SETTING_PAGE_IS_RECORD_LOG
{
number= 0;
label= str_firewall_setting_page_label_is_record_log ;
type = EAknCtPopupSettingList;
//editor_resource_id = r_setting_app_on_off_popup_setting_list;
}
RESOURCE AVKON_POPUP_SETTING_TEXTS R_FIREWALL_SETTING_IS_RECORD_LOG_TEXTS
{
flags = 0;
setting_texts_resource = R_AKNEXSETTINGLIST_ON_OFF_TEXTS;
popped_up_texts_resource = R_AKNEXSETTINGLIST_POPPED_UP_ON_OFF_TEXTS;
}
RESOURCE ARRAY R_AKNEXSETTINGLIST_ON_OFF_TEXTS
{
items =
{
AVKON_ENUMERATED_TEXT { value=1; text = str_firewall_setting_is_record_log_on ; },
AVKON_ENUMERATED_TEXT { value=0; text = str_firewall_setting_is_record_log_off ; }
};
}
RESOURCE ARRAY R_AKNEXSETTINGLIST_POPPED_UP_ON_OFF_TEXTS
{
items =
{
LBUF { txt = str_firewall_setting_is_record_log_enabled; },
LBUF { txt = str_firewall_setting_is_record_log_disabled; }
};
}
//-----------------------------------------------------------------------------
//
// R_FIREWALL_SETTING_PAGE_IS_AUTOSTART
// 防火墙是否记录日志设置页
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_PAGE R_FIREWALL_SETTING_PAGE_IS_AUTOSTART
{
number= 0;
label= str_firewall_setting_page_label_is_autostart ;
type = EAknCtPopupSettingList;
//editor_resource_id = r_setting_app_on_off_popup_setting_list;
}
RESOURCE AVKON_POPUP_SETTING_TEXTS R_FIREWALL_SETTING_IS_AUTOSTART_TEXTS
{
flags = 0;
setting_texts_resource = R_AKNEXSETTINGLIST_ON_OFF_TEXTS;
popped_up_texts_resource = R_AKNEXSETTINGLIST_POPPED_UP_ON_OFF_TEXTS;
}
//-----------------------------------------------------------------------------
//
// R_FIREWALL_SETTING_PAGE_DEFAULT_ACTION
// 防火墙无匹配规则默认动作设置页
//
//-----------------------------------------------------------------------------
//
RESOURCE AVKON_SETTING_PAGE r_firewall_setting_page_default_action
{
number= 0;
label= str_firewall_setting_page_label_default_action ;
type = EAknCtPopupSettingList ;
editor_resource_id = r_firewall_setting_list_new_entry_default_action ;
}
RESOURCE POPUP_SETTING_LIST r_firewall_setting_list_new_entry_default_action
{
//flags = EAknPopupSettingListFlagAllowsUserDefinedEntry ;
flags = EAknPopupSettingListFlagInitialised ;
}
RESOURCE AVKON_POPUP_SETTING_TEXTS r_firewall_setting_list_default_action
{
setting_texts_resource = r_firewall_setting_texts_resource_default_action;
popped_up_texts_resource = r_firewall_setting_popped_up_texts_resource_default_action ;
}
RESOURCE ARRAY r_firewall_setting_texts_resource_default_action
{
items =
{
AVKON_ENUMERATED_TEXT
{
value = 0;
text = str_firewall_setting_default_action_0;
},
AVKON_ENUMERATED_TEXT
{
value = 1;
text = str_firewall_setting_default_action_1;
},
AVKON_ENUMERATED_TEXT
{
value = 2;
text = str_firewall_setting_default_action_2;
}
};
}
RESOURCE ARRAY r_firewall_setting_popped_up_texts_resource_default_action
{
items =
{
LBUF
{
txt = str_firewall_setting_default_action_0;
},
LBUF
{
txt = str_firewall_setting_default_action_1;
},
LBUF
{
txt = str_firewall_setting_default_action_2;
}
};
}
存取文件代码:
void CFirewallSettingData::SaveSettingL()
{
RFs iFs ;
User::LeaveIfError(iFs.Connect()) ;
RFileWriteStream writer;
writer.PushL();
User::LeaveIfError(writer.Replace(iFs, KFirewallSettingFileName, EFileWrite)); //����ݿ���д���
TInt32 len = 0;
writer.WriteInt32L(iSizeOfLogfile); //保存日志文件长度
writer.WriteInt32L(iDefaultAction); //保存无规则匹配动作
writer.WriteInt32L(iIsRecordLog); //保存是否记录日志
writer.WriteInt32L(iIsAutoStart); //保存开机是否自启动
writer.CommitL();
CleanupStack::PopAndDestroy();
iFs.Close() ;
}
void CFirewallSettingData::ReadSettingL()
{
RFs iFs ;
RFile iFile ;
User::LeaveIfError(iFs.Connect()) ;
User::LeaveIfError(iFile.Open(iFs, KFirewallSettingFileName, EFileRead));
TInt iSize = 0 ;
iFile.Size(iSize) ;
if(iSize <= 0)
{
iFs.Close() ;
SetDefaultValue() ; //如果文件为空则设置默认值
return ;
}
RFileReadStream reader;
reader.PushL() ;
reader.Attach(iFile) ;
iSizeOfLogfile = reader.ReadInt32L(); //读取日志文件长度
iDefaultAction = reader.ReadInt32L(); //读取无规则匹配动作
iIsRecordLog = reader.ReadInt32L(); //读取是否记录日志
iIsAutoStart = reader.ReadInt32L(); //读取开机是否自启动
if (!iSizeOfLogfile) //判断如果日志文件为0,用默认设置
{
SetDefaultValue() ;
}
CleanupStack::PopAndDestroy();
iFs.Close() ;
}
{
RFs iFs ;
User::LeaveIfError(iFs.Connect()) ;
RFileWriteStream writer;
writer.PushL();
User::LeaveIfError(writer.Replace(iFs, KFirewallSettingFileName, EFileWrite)); //����ݿ���д���
TInt32 len = 0;
writer.WriteInt32L(iSizeOfLogfile); //保存日志文件长度
writer.WriteInt32L(iDefaultAction); //保存无规则匹配动作
writer.WriteInt32L(iIsRecordLog); //保存是否记录日志
writer.WriteInt32L(iIsAutoStart); //保存开机是否自启动
writer.CommitL();
CleanupStack::PopAndDestroy();
iFs.Close() ;
}
void CFirewallSettingData::ReadSettingL()
{
RFs iFs ;
RFile iFile ;
User::LeaveIfError(iFs.Connect()) ;
User::LeaveIfError(iFile.Open(iFs, KFirewallSettingFileName, EFileRead));
TInt iSize = 0 ;
iFile.Size(iSize) ;
if(iSize <= 0)
{
iFs.Close() ;
SetDefaultValue() ; //如果文件为空则设置默认值
return ;
}
RFileReadStream reader;
reader.PushL() ;
reader.Attach(iFile) ;
iSizeOfLogfile = reader.ReadInt32L(); //读取日志文件长度
iDefaultAction = reader.ReadInt32L(); //读取无规则匹配动作
iIsRecordLog = reader.ReadInt32L(); //读取是否记录日志
iIsAutoStart = reader.ReadInt32L(); //读取开机是否自启动
if (!iSizeOfLogfile) //判断如果日志文件为0,用默认设置
{
SetDefaultValue() ;
}
CleanupStack::PopAndDestroy();
iFs.Close() ;
}
关键代码:
必须要在SettingList类中重载EditItemL函数,使的编辑过的数据能够保存到CFirewallSettingData类的实例iData中:
void CFirewallSettingList::EditItemL(TInt aIndex, TBool aCalledFromMenu)
{
CAknSettingItemList::EditItemL(aIndex, aCalledFromMenu) ;
(*SettingItemArray())[aIndex]->StoreL() ;
}