this is my first attempt to implement OOP. IS this class ok?(in terms of structure)
AND another Question:
there are some folders in message application in Symbian phones
and sometimes there are up to 1000 messages in each folders.
I do itterate over all messages for gathering their info about sender/reciever/etc
but its very slow to use this clas for every folder.
how can I make a class that prevents me from itteratin over and over?
some info:
a messaging folder accessed from python returns a list of IDs from all of messages
for every ID there is a dict that contains info about that message.
#-------------------------------------------------------------------------------
# Name: DelSMS
# Purpose: Application for deleting SMS messages in Nokia Symbian Phones
# Author: M.S.
# Created: 22/09/2012
# Copyright: (c) Mohsen Sarhady 2012
# Python Version: PyS60 v1.45(Python 2.2.2)
#-------------------------------------------------------------------------------
# -*- coding: utf-8 -*-
import inbox
class DelSMS:
"""Class for deleting SMS messages with diferent possibilities:
-Dlete Messages in different folders
-Delete Messages for a contact in different folders
-Delete messages that contain a search keyword"""
def __init__(self, folder):
self.folder=folder
self.m=folder.sms_messages()
def contacts_by_folder(self):
"""Returns the list of contacts in the given folder."""
contacts = []
if len(self.m) != 0:
for idx in self.m:
address = self.folder.address(idx)
if address not in contacts:
contacts.append(address)
contacts.sort()
return contacts
def del_by_folder(self):
"""Deletes messages in the given folder."""
if len(self.m) != 0:
for idx in self.m:
self.folder.delete(idx)
def del_by_contact(self, contact):
"""Deletes Messages by Contact in the given folder."""
if len(self.m) != 0:
for idx in self.m:
address = self.folder.address(idx)
if address == contact:
folder.delete(idx)
def del_by_keyword(self, keyword):
"""Deletes messages that contain a given search term"""
#It is a TO DO
pass
if __name__ == '__main__':
#Test:
delsms = DelSMS(inbox.Inbox(inbox.ESent))
contacts = delsms.contacts()
print contacts