Rockbox Development > Starting Development and Compiling
Contacts plugin written in LUA
(1/1)
gbl08ma:
This is a thread about the development of a contacts plugin written in LUA, FS#11989.
The following post was a previous help request over a problem I solved myself (my programming skills are very good as you can think) and its original content is kept here just for reference.
Hi everyone!
I'm writing a contacts plugin in LUA for Rockbox. I already have lots of code (with the current code, the plugin should be able to view the contacts on its database, add contacts to its DB, save and load the DB from a file), but not I ran into a problem I can't solve so I'm asking here for help...
The problem is as follows: With an earlier version of the plugin, which the only thing it did was automatically add some example contacts to the database and save it, I added some contacts to my debug DB (located at the root of the player, named contacts.txt). These contacts created by the old code were stores on the database file as follows:
--- Code: ---return {
-- Table: {1}
{
{2},
{3},
{4},
{5}
},
-- Table: {2}
{
["department"]="",
["last"]="Last Name",
["company"]="SC, Co.",
["worktel"]="40304399",
["first"]="Joe",
["middle"]="Middle",
["jobtitle"]="",
},
-- Table: {3}
{
["department"]="",
["last"]="last",
["company"]="a company",
["worktel"]="9845641254",
["first"]="some first",
["middle"]="",
["jobtitle"]="dr.",
},
-- Table: {4}
{
["department"]="",
["last"]="test last",
["company"]="companiiis",
["worktel"]="53981330",
["first"]="test first",
["middle"]="test middle",
["jobtitle"]="",
},
-- Table: {5}
{
["department"]="",
["last"]="Exex",
["company"]="Mirdalha",
["worktel"]="560928028",
["first"]="Joe",
["middle"]="Coco",
["jobtitle"]="",
},
}
--- End code ---
And these ones are successfully loaded into the actual plugin when it opens (successfully means they are added to the entry count and their first, middle and last names are displayed in the menu).
However (and here comes the problem), I don't know what changes I made to the function that adds a contact to the DB, I just added code to be able to identify each table entry by a "unique ID", that in this case is the first name, plus the middle and last name, without spaces in between. Now, contacts are stored this way:
--- Code: ---return {
-- Table: {1}
{
[98989]={2},
["aabbbcccc"]={3},
},
-- Table: {2}
{
["department"]="",
["last"]="HHH",
["company"]="",
["worktel"]="",
["first"]="dddggg",
["email"]="",
["workfax"]="",
["im"]="",
["jobtitle"]="",
["workaddr"]="",
["middle"]="vvv",
["mobiletel"]="",
},
-- Table: {3}
{
["department"]="",
["last"]="cccc",
["company"]="",
["worktel"]="",
["first"]="aa",
["email"]="",
["workfax"]="",
["im"]="",
["jobtitle"]="",
["workaddr"]="",
["middle"]="bbb",
["mobiletel"]="",
},
}
--- End code ---
And these new ones, with " ["aabbbcccc"]={3}" instead of just " {3}" are not recognized. I mean, they are added to the total entry count (that means the "for" loop "sees" them), but their names are not shown in the main menu. On the simpler ones, without the unique ID, are still displayed.
Sorry for all this ramble, perhaps if you understand LUA it's easier to look at the code and run on your player to understand what happens. The script file goes attached as "contacts.lua.txt" (change its name to "contacts.lua") and an example database with both of the "modern" and "old" contact table formats is attached as "contacts.txt" (put it on the root of your player).
The code is well commented (at least in my opinion), if you have more questions feel free to ask.
Any suggestion you may give is useful ;)
A contacts plugin is something I sometimes miss on Rockbox, and I think it's something simple enough to code in LUA (no need to have another C plugin). I have thought of features like exporting and importing vCards as well as contact photo, which I'll try to implement when (if) I complete the basic part of the plugin.
PS: perhaps it's a very obvious bug, but I've looked at the code for three days and tried different configurations and no result. So I came here...
gbl08ma:
I ended up fixing this by myself by using table.insert on the function to add a contact to DB.
I have an almost complete (according to my "first milestone" goals) plugin, where I can add, delete and view contacts (and every field manually). The very next thing to do is coding the screen for editing a contact.
Future features (for other "milestones") include ordering and showing contacts by their category, allow to change the order names are displayed (First-Middle-Last, Last-First-Middle or Last-middle-First) and allow to search for contacts by their name or any of the fields (phone, email, etc.).
Ultimately, it'd also be good to have the plugin import and export contacts as vCards, as this is the most common format for contact card sharing and backup. This last step has an additional work to be done, which is writing a library for working with vCards in Lua (I don't think there exists any under GNU GPL v2, much less compatible with the limitations of Lua specific to Rockbox, like the lack of the math library - not that it would be needed in a vCard parsing program, but anyways...) and only then integrating it into my contacts program.
Stay on touch for more information and the release of the plugin!
Chronon:
It sounds like you are making good progress. :)
It would be good to create a task on the tracker to keep track of your work.
gbl08ma:
Done :D
Please test and comment.
http://www.rockbox.org/tracker/task/11989
Navigation
[0] Message Index
Go to full version