def reload_contacts(self): self.parent.main_window.setAttribute( QtCore.Qt.WA_Maemo5ShowProgressIndicator, True) # Read last bonjour_contact used last_authorized_bonjour_contact = config.read_last_authorized_bonjour_contact() self.parent.main_window.repaint() banner_notification(self.tr("Looking for Bonjour contacts ...")) self.parent.bonjour_users = list_presence_users() self.bonjour_users.clear() if len(self.parent.bonjour_users) == 0: banner_notification(self.tr("No Bonjour contacts found !")) else: node_friend_list = [f.node for f in self.parent.scheduler.friend_list] for bonjour_user, info in self.parent.bonjour_users.items(): # if the contact was create by heysms # we don't want to see it in the list bonjour_user = bonjour_user.decode('utf-8') if bonjour_user in node_friend_list: continue self.bonjour_users.addItem(bonjour_user) # Search in list last bonjour_contact used index = self.bonjour_users.findText(last_authorized_bonjour_contact) if index != -1: # Select last bonjour_contact used logger.debug("Last Bonjour contact found: %s, we select it" % last_authorized_bonjour_contact) self.bonjour_users.setCurrentIndex(index) banner_notification(self.tr("Bonjour contacts loaded !")) self.parent.main_window.setAttribute( QtCore.Qt.WA_Maemo5ShowProgressIndicator, False)
def exit(): logger.debug("Stopping active friends") for f in ui.friend_list: f.close() logger.debug("Shutdown scheduler") ui.scheduler.must_run = False while ui.scheduler.isRunning(): logger.debug("Waiting scheduler") if ui.scheduler.waiting_authorized_contact == True: break sleep(0.1) logger.debug("Restore profile") config.restore_profile() if config.useusb == QtCore.Qt.Checked: logger.debug("Restore USB") config.restore_useusb()
def main(): def exit(): logger.debug("Stopping active friends") for f in ui.friend_list: f.close() logger.debug("Shutdown scheduler") ui.scheduler.must_run = False while ui.scheduler.isRunning(): logger.debug("Waiting scheduler") if ui.scheduler.waiting_authorized_contact == True: break sleep(0.1) logger.debug("Restore profile") config.restore_profile() if config.useusb == QtCore.Qt.Checked: logger.debug("Restore USB") config.restore_useusb() opt_parser = OptionParser() opt_parser.add_option("-d", "--debug", dest="debug_mode", action="store_true", default='False', help="Debug mode") app = QtGui.QApplication(sys.argv) # app.setOrganizationName("HeySms") # app.setOrganizationDomain("HeySms") app.setApplicationName("HeySms") (options, args) = opt_parser.parse_args([str(i) for i in app.arguments()]) logger.set_debug(options.debug_mode) main_window = QtGui.QMainWindow() ui = Ui_MainWindow(app) ui.setupUi(main_window) config.parent = ui ui.call_listener = Call_listener(ui) ui.call_listener.start() logger.debug("Call_listener started") ui.sms_listener = Sms_listener(ui) ui.sms_listener.start() logger.debug("Sms_listener started") ui.scheduler = Scheduler(ui) ui.scheduler.start() logger.debug("Scheduler started") main_window.setWindowTitle("HeySms") main_window.setAttribute(QtCore.Qt.WA_Maemo5AutoOrientation, True) main_window.show() main_window.repaint() ui.central_widget.repaint() ui.central_widget.reload_contacts() QtCore.QObject.connect(app, QtCore.SIGNAL("aboutToQuit()"), exit) sys.exit(app.exec_())
def reload_contacts(self): self.parent.main_window.setAttribute( QtCore.Qt.WA_Maemo5ShowProgressIndicator, True) # Read last bonjour_contact used last_authorized_bonjour_contact = config.read_last_authorized_bonjour_contact( ) self.parent.main_window.repaint() banner_notification("Looking for Bonjour contacts ...") self.parent.bonjour_users = list_presence_users() self.bonjour_users.clear() if len(self.parent.bonjour_users) == 0: banner_notification("No Bonjour contacts found !") else: node_friend_list = [ f.node for f in self.parent.scheduler.friend_list ] for bonjour_user, info in self.parent.bonjour_users.items(): # if the contact was create by heysms # we don't want to see it in the list bonjour_user = bonjour_user.decode('utf-8') if bonjour_user in node_friend_list: continue self.bonjour_users.addItem(bonjour_user) # Search in list last bonjour_contact used index = self.bonjour_users.findText( last_authorized_bonjour_contact) if index != -1: # Select last bonjour_contact used logger.debug("Last Bonjour contact found: %s, we select it" % last_authorized_bonjour_contact) self.bonjour_users.setCurrentIndex(index) banner_notification("Bonjour contacts loaded !") self.parent.main_window.setAttribute( QtCore.Qt.WA_Maemo5ShowProgressIndicator, False)
def add_friend(self): friends_dialog = QtGui.QInputDialog(self.main_window) friends_dialog.setComboBoxEditable(0) db = bsddb.hashopen('/home/user/.osso-abook/db/addressbook.db', 'r') friend_list = {} old_friend_list = [f.fullname for f in self.scheduler.friend_list] q_friend_dict = {} for contact in db.values(): # logger.debug("Trying to find name and " # "cell number in: %s" % contact.split('\n')) reg = re.compile('FN:(.*?)\\r', re.S | re.M) numbers = re.findall("TEL;TYPE=.*?CELL.*?:(.[0-9]*)\r\n", contact) m = re.search(reg, contact) if m is None: logger.debug("No name in contact") continue elif not numbers: logger.debug("No cell phone found") continue name = m.group(1).decode('utf-8') for num in numbers: logger.debug("Found : %s - %s" % (name, num)) if name in old_friend_list: logger.debug("Friend already in list: %s" % name) continue i = 1 while name in friend_list: name = name + " (%s)" % str(i) i = i + 1 # Prepare lists friend_list[num] = name q_friend_dict["%s - %s" % (name, num)] = num q_friend_list = QtCore.QStringList(sorted(q_friend_dict.keys())) friends_dialog.setComboBoxItems(q_friend_list) friends_dialog.setWindowTitle("Add a friend") friends_dialog.setLabelText("Select a friend") ret = friends_dialog.exec_() if ret == 0: logger.debug("Dialog not confirmed") return raw_name = str(friends_dialog.textValue()) number = q_friend_dict[raw_name] select_friend = friend_list[number] bonjour_auth_username = str(self.bonjour_auth_user) auth_user = { bonjour_auth_username: self.bonjour_users[bonjour_auth_username] } # Check if friend is already in friend list if select_friend in old_friend_list: logger.debug("Selected friend already in list: %s" % select_friend) return new_friend = Friend(select_friend, number, auth_user) # Add to friend list in table model self.central_widget.friends_list.emit(QtCore.SIGNAL("add_friend"), new_friend) # append to scheduler friend list self.scheduler.friend_list.append(new_friend) # Register it on bonjour new_friend.start()
def add_friend(self): friends_dialog = QtGui.QInputDialog(self.main_window) friends_dialog.setComboBoxEditable(0) friends_dialog.setOkButtonText(self.tr("Done")) db = bsddb.hashopen('/home/user/.osso-abook/db/addressbook.db', 'r') friend_list = {} old_friend_list = [f.fullname for f in self.scheduler.friend_list] q_friend_dict = {} for contact in db.values(): # logger.debug("Trying to find name and " # "cell number in: %s" % contact.split('\n')) reg = re.compile('FN:(.*?)\\r', re.S|re.M) numbers = re.findall("TEL;TYPE=.*?CELL.*?:(.[0-9]*)\r\n", contact) m = re.search(reg, contact) if m is None: logger.debug("No name in contact") continue elif not numbers: logger.debug("No cell phone found") continue name = m.group(1).decode('utf-8') for num in numbers: logger.debug("Found : %s - %s" % (name, num)) if name in old_friend_list: logger.debug("Friend already in list: %s" % name) continue i = 1 while name in friend_list: name = name + " (%s)" % str(i) i = i + 1 # Prepare lists friend_list[num] = name q_friend_dict["%s - %s" % (name, num)] = num q_friend_list = QtCore.QStringList(sorted(q_friend_dict.keys())) friends_dialog.setComboBoxItems(q_friend_list) friends_dialog.setWindowTitle(self.tr("Add a friend")) friends_dialog.setLabelText(self.tr("Select a friend")) ret = friends_dialog.exec_() if ret == 0: logger.debug("Dialog not confirmed") return raw_name = unicode(friends_dialog.textValue()) number = q_friend_dict[raw_name] select_friend = friend_list[number] bonjour_auth_username = str(self.bonjour_auth_user) auth_user = {bonjour_auth_username: self.bonjour_users[bonjour_auth_username]} # Check if friend is already in friend list if select_friend in old_friend_list: logger.debug("Selected friend already in list: %s" % select_friend) return new_friend = Friend(select_friend, number, auth_user) # Add to friend list in table model self.central_widget.friends_list.emit(QtCore.SIGNAL("add_friend"), new_friend) # append to scheduler friend list self.scheduler.friend_list.append(new_friend) # Register it on bonjour new_friend.start()