Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Thank You for your continued support and contributions!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Contacts plugin written in LUA
« previous next »
  • Print
Pages: [1]

Author Topic: Contacts plugin written in LUA  (Read 1952 times)

Offline gbl08ma

  • Member
  • *
  • Posts: 249
    • My blog
Contacts plugin written in LUA
« on: February 26, 2011, 11:00:37 AM »
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: [Select]
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"]="",
},
}
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: [Select]
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"]="",
},
}
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...
* contacts.txt (3.41 kB - downloaded 115 times.)
* contacts.lua.txt (20.61 kB - downloaded 140 times.)
« Last Edit: March 03, 2011, 03:31:00 PM by gbl08ma »
Logged
http://gbl08ma.com | http://i.tny.im

Offline gbl08ma

  • Member
  • *
  • Posts: 249
    • My blog
Re: Help with contacts plugin written in LUA
« Reply #1 on: March 02, 2011, 06:02:37 PM »
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!
Logged
http://gbl08ma.com | http://i.tny.im

Offline Chronon

  • Rockbox Expert
  • Member
  • *
  • Posts: 4379
Re: Help with contacts plugin written in LUA
« Reply #2 on: March 03, 2011, 01:47:39 PM »
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.
Logged
Sansa e280, Gigabeat F40, Gigabeat S60, Sansa Clip+, iPod Mini 2g

Offline gbl08ma

  • Member
  • *
  • Posts: 249
    • My blog
Re: Help with contacts plugin written in LUA
« Reply #3 on: March 03, 2011, 02:37:49 PM »
Done :D
Please test and comment.
http://www.rockbox.org/tracker/task/11989
Logged
http://gbl08ma.com | http://i.tny.im

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Contacts plugin written in LUA
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.067 seconds with 15 queries.